Skip to content

Instantly share code, notes, and snippets.

@Exey
Created March 31, 2020 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Exey/85a681936c3db0232396bf55d784495c to your computer and use it in GitHub Desktop.
Save Exey/85a681936c3db0232396bf55d784495c to your computer and use it in GitHub Desktop.
#include <metal_stdlib>
using namespace metal;
struct VertexIn {
float3 position [[attribute(0)]];
float2 texCoords [[attribute(1)]];
};
struct VertexOut {
float4 position [[position]];
float2 texCoords;
};
struct Uniforms {
float4x4 modelViewMatrix;
float4x4 projectionMatrix;
};
constexpr sampler textureSampler (mag_filter::linear, min_filter::linear);
vertex VertexOut tex_vertex(VertexIn vertexIn [[stage_in]],
constant Uniforms &uniforms [[buffer(1)]])
{
VertexOut vertexOut;
vertexOut.position = uniforms.projectionMatrix * uniforms.modelViewMatrix * float4(vertexIn.position, 1);
vertexOut.texCoords = vertexIn.texCoords;
return vertexOut;
}
fragment float4 tex_fragment(VertexOut fragmentIn [[stage_in]],
texture2d<float, access::sample> texture [[texture(0)]]) {
return texture.sample(textureSampler, fragmentIn.texCoords);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment