Skip to content

Instantly share code, notes, and snippets.

@nbhasin2
Last active April 2, 2025 06:48
Show Gist options
  • Save nbhasin2/8a497a4073774c05f75f7beab0a3158c to your computer and use it in GitHub Desktop.
Save nbhasin2/8a497a4073774c05f75f7beab0a3158c to your computer and use it in GitHub Desktop.
Shaders_Step2.metal
#include <metal_stdlib>
using namespace metal;
struct VertexOut {
float4 position [[position]];
float2 texCoords;
};
vertex VertexOut circle_vertex(uint vertexID [[vertex_id]]) {
float2 positions[4] = {
float2(-1.0, -1.0), float2(1.0, -1.0),
float2(-1.0, 1.0), float2(1.0, 1.0)
};
VertexOut out;
out.position = float4(positions[vertexID], 0.0, 1.0);
out.texCoords = float2((positions[vertexID].x + 1.0) / 2.0, (1.0 - positions[vertexID].y) / 2.0);
return out;
}
fragment half4 circle_fragment(VertexOut in [[stage_in]]) {
float2 center = float2(0.5, 0.5);
float dist = distance(in.texCoords, center);
if (dist < 0.25) {
return half4(1.0, 0.5, 0.2, 1.0); // Orange
} else {
return half4(0.1, 0.1, 0.1, 1.0); // Dark Gray
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment