Advertisement
Guest User

Untitled

a guest
Oct 7th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <metal_stdlib>
  2. #include <simd/simd.h>
  3.  
  4. // Including header shared between this Metal shader code and Swift/C code executing Metal API commands
  5. #import "ShaderTypes.h"
  6.  
  7. using namespace metal;
  8.  
  9. typedef struct
  10. {
  11.     float3 position [[attribute(VertexAttributePosition)]];
  12.     float2 texCoord [[attribute(VertexAttributeTexcoord)]];
  13. } Vertex;
  14.  
  15. typedef struct
  16. {
  17.     float4 position [[position]];
  18.     float2 texCoord;
  19. } ColorInOut;
  20.  
  21. vertex ColorInOut vertexShader(Vertex in [[stage_in]],
  22.                                constant Uniforms & uniforms [[ buffer(BufferIndexUniforms) ]])
  23. {
  24.     ColorInOut out;
  25.     float4 position = float4(in.position, 1.0);
  26.     out.position = uniforms.projectionMatrix * uniforms.modelViewMatrix * position;
  27.     out.texCoord = in.texCoord;
  28.     return out;
  29. }
  30.  
  31. fragment float4 fragmentShader(ColorInOut in [[stage_in]],
  32.                                constant Uniforms & uniforms [[ buffer(BufferIndexUniforms) ]],
  33.                                texture2d<half> colorMap     [[ texture(TextureIndexColor) ]])
  34. {
  35.     constexpr sampler colorSampler(mip_filter::linear,
  36.                                    mag_filter::linear,
  37.                                    min_filter::linear);
  38.     return float4(colorMap.sample(colorSampler, in.texCoord.xy));
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement