Skip to content

Instantly share code, notes, and snippets.

@patskovn
Created March 3, 2024 20:23
Show Gist options
  • Save patskovn/37752cf12983b029ee1c957ed9db10c0 to your computer and use it in GitHub Desktop.
Save patskovn/37752cf12983b029ee1c957ed9db10c0 to your computer and use it in GitHub Desktop.
AddZColorShader.metal
struct SceneConstants {
...
float3 bottomColor;
float bottomColorBorder;
};
vertex VertexOut vertex_main(uint vertexID [[vertex_id]],
constant VertexIn *vertices [[buffer(0)]],
constant ModelConstants &modelConstants [[buffer(1)]],
constant SceneConstants &sceneConstants [[buffer(2)]]) {
...
out.color = in.color;
if (distorted_pos.z < 0) {
float4 diff = sceneConstants.bottomColor - in.color;
float d = saturate(distorted_pos.z / sceneConstants.bottomColorBorder);
float4 b = diff * d;
out.color = in.color + b;
}
...
return out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment