# In a shader, why does substituting a variable with the expression producing it cause different behaviour?

I have this correctly-working OpenGL shader producing Perlin noise:

 float left = lerp(fade(v),  downleft,  topleft);
float right = lerp(fade(v), downright, topright);
float result = lerp(fade(u), left, right);


Then I tried plugging the definitions of right and left into result:

float result = lerp(fade(u),


Surprisingly, this behaves completely differently, giving visible edges in my Perlin noise. Below are both results:

My whole 30-line shader is here.

What is the difference between those?

• Some trivia notes -- your lerp() is equivalent to the built-in function mix(). And, it may be handy to put your shader into ShaderToy, as a convenient way for others to easily run/debug it. (That all said, I'm so far mystified why the substitution would do what it seems to be doing.) Oct 23 '15 at 18:47
• I bet that you're taking coordinates from each render in one of them and screen in the other. Nov 1 '15 at 10:43
• @Lolums 34 can you rephrase? I did not quite get you. Nov 1 '15 at 11:20
• @hungry91 ignore that comment, it's invalid. I'll try to answer the question later though when I get some time :) Nov 1 '15 at 14:53
• I'm unable to recreate this. Are you sure you didn't accidentally plug left in twice or something? Nov 24 '15 at 22:00