Skip to content

Instantly share code, notes, and snippets.

@nbhasin2
Last active April 2, 2025 06:50
Show Gist options
  • Save nbhasin2/548fc6f6696c8c44069b3e4f7315bffc to your computer and use it in GitHub Desktop.
Save nbhasin2/548fc6f6696c8c44069b3e4f7315bffc to your computer and use it in GitHub Desktop.
Shaders_Step4.metal
// Shaders.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]], constant float &time [[buffer(0)]]) {
float2 center = float2(
0.5 + 0.2 * sin(time * 0.8),
0.5 + 0.2 * cos(time * 0.8)
);
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 circleColor = half4(1.0, 0.5, 0.2, 1.0);
half4 backgroundColor = half4(0.1, 0.1, 0.1, 1.0);
half4 finalColor = mix(backgroundColor, circleColor, influence);
return finalColor;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment