Skip to content

Instantly share code, notes, and snippets.

Created November 27, 2020 08:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save andijakl/736a189c1e4be3cd63ea39cfba48a1e8 to your computer and use it in GitHub Desktop.
Part of the AR Foundation DepthGradient shader for Unity
fragment_output frag (v2f i)
// Sample the environment depth (in meters).
float envDistance = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord).r;
real lerpFactor = (envDistance - _MinDistance) / (_MaxDistance - _MinDistance);
real hue = lerp(0.70h, -0.15h, saturate(lerpFactor));
if (hue < 0.0h)
hue += 1.0h;
real3 color = real3(hue, 0.9h, 0.6h);
fragment_output o;
o.color = real4(HSVtoRGB(color), 1.0h);
return o;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment