1
\$\begingroup\$

I don't understand the lerp example in this code :

if(dot(WorldNormalVector(IN, o.Normal), _SnowDirection.xyz)>=lerp(1,-1,_Snow))
                o.Albedo = _SnowColor.rgb;
            else

(Snow is in the range 0..1)

The article says :
We then compare the dot value with a lerp - if our Snow level is 0 (no snow) this returns 1 and if the Snow level is 1 it will return -1 (the entire rock is covered). It's quite normal to only vary the snow level between 0..0.5 when we use this shader so that we only have snow on surfaces that actually face the snow direction.

Why does it return 1 (with Snow at 0) and -1 (with Snow at 1) ?

(source: http://unitygems.com/noobs-guide-shaders-2/ )

Thanks

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Are you asking about the definition of the lerp function? If so, see here: msdn.microsoft.com/en-us/library/windows/desktop/bb509618.aspx \$\endgroup\$ Commented Apr 17, 2013 at 22:23
  • \$\begingroup\$ @NathanReed Thanks, actually I don't understand it, why using "lerp" (an interpolation..?) to compare _Snow with the dot product? What does actually return lerp here: a different number between the frames? Or the same number, in this case, why not just put _Snow? \$\endgroup\$
    – Paul
    Commented Apr 17, 2013 at 23:41

1 Answer 1

1
\$\begingroup\$

_Snow is in the range 0 to 1. The dot product returns a value from -1 to 1. The lerp is being used to convert _Snow to the -1 to 1 range for comparison with the dot product. When _Snow is zero, no snow is desired, so the comparison becomes "dot product >= 1", which will never be true (well, except at points exactly facing the snow direction). Conversely, when _Snow is 1, the comparison becomes "dot product >= -1", which will always be true, so you'll get snow everywhere. Intermediate values of _Snow should generate intermediate values to compare the dot product against, hence the interpolation.

\$\endgroup\$
1
  • \$\begingroup\$ Supplemental: lerp(1, -1, _Snow) == (1 - (_Snow * 2)) \$\endgroup\$
    – Jon
    Commented Feb 12, 2015 at 1:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .