Skip to content

Instantly share code, notes, and snippets.

@andijakl
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
Embed
What would you like to do?
Part of the AR Foundation DepthGradient shader for Unity
fragment_output frag (v2f i)
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(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