Skip to content

Instantly share code, notes, and snippets.

@nbhasin2
Last active April 2, 2025 06:54
Show Gist options
  • Save nbhasin2/8d53b6e8aca6ff0994a42208e4e18370 to your computer and use it in GitHub Desktop.
Save nbhasin2/8d53b6e8aca6ff0994a42208e4e18370 to your computer and use it in GitHub Desktop.
Shaders_Step3.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);
float maxDist = 0.25;
float influence = 1.0 - min(dist / maxDist, 1.0);
influence = pow(max(influence, 0.0), 2.0);
half4 color = mix(half4(0.1, 0.1, 0.1, 1.0), half4(1.0, 0.5, 0.2, 1.0), influence);
return color;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment