Skip to main content
Tweeted twitter.com/StackGameDev/status/657699438828331008
More descriptive title. Proofread text. Removed request for code review—that's a separate matter.
Source Link
Anko
  • 13.5k
  • 10
  • 56
  • 82

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

I have found strange behavior programming perlin noise asthis correctly-working OpenGL shader. Code producing Perlin noise:

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

produces desired effect. After changing it toThen I tried plugging the definitions of right and left into result:

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

(I only plugged right and left definitions into result)

code Surprisingly, this behaves completely different and there aredifferently, giving visible edges in my perlinPerlin noise. Below are both results:   

enter image description here

The woleMy whole 30-line shader(30 lines) is here. I dont want to make this mistake again but still I dont know what

What is the difference beetweenbetween those. Can anybody give me a hint?

By the way I will be happy to hear any remarks on my code as I am new to shader and OpenGL graphics.

Thanks!

Strange shader behavior OPENGL

I have found strange behavior programming perlin noise as OpenGL shader. Code

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

produces desired effect. After changing it to

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

(I only plugged right and left definitions into result)

code behaves completely different and there are visible edges in my perlin noise. Below both results:  enter image description here

The wole shader(30 lines) is here. I dont want to make this mistake again but still I dont know what is the difference beetween those. Can anybody give me a hint?

By the way I will be happy to hear any remarks on my code as I am new to shader and OpenGL graphics.

Thanks!

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),
                    lerp(fade(v), downleft,  topleft),
                    lerp(fade(v), downright, topright));

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

enter image description here

My whole 30-line shader is here.

What is the difference between those?

Source Link

Strange shader behavior OPENGL

I have found strange behavior programming perlin noise as OpenGL shader. Code

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

produces desired effect. After changing it to

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

(I only plugged right and left definitions into result)

code behaves completely different and there are visible edges in my perlin noise. Below both results: enter image description here

The wole shader(30 lines) is here. I dont want to make this mistake again but still I dont know what is the difference beetween those. Can anybody give me a hint?

By the way I will be happy to hear any remarks on my code as I am new to shader and OpenGL graphics.

Thanks!