hashbrown

06-18-2017, 03:11 PM

I'm attempting to create water using a dudv map, but having trouble with the waving effect. I managed to create the effect but as time goes by, the wave effect moves to the left of the quad until disappearing. I'll show you an example and if you look a carefully, you'll see what I'm talking about, here's a screen cap:

http://recordit.co/F0dt7H63px

I'm learning how to make water so please excuse me. I'm suspecting this has to do with the refractionTexCoords += totalDistortion.xy line, but I'm not sure how to avoid this visual bug. I'll share the portion of the frag shader that is in charge with movig the water. Thanks in advance!

// Oh and this is how I compute the clipSpace in the vertex shader: clipSpace = mvp * a_position;

vec2 ndc = (clipSpace.xy/clipSpace.w) / 2.0 + 0.5;

vec2 reflectionTexCoords = vec2(ndc.x, -ndc.y);

vec2 refractionTexCoords = vec2(ndc.x, ndc.y);

vec4 distortion1 = (texture2D(dudv, vec2(newTexCoords.x + moveFactor, newTexCoords.y).rg * 2.0 - 1.0)) * waveStr;

vec4 distortion2 = (texture2D(dudv, vec2(-newTexCoords.x + moveFactor, newTexCoords.y + moveFactor).rg * 2.0 - 1.0)) * waveStr;

vec4 totalDistortion = distortion1 + distortion2;

refractionTexCoords += totalDistortion.xy;

refractionTexCoords = clamp(refractionTexCoords, 0.001, 0.999);

reflectionTexCoords += totalDistortion.xy;

reflectionTexCoords.x = clamp(reflectionTexCoords.x, 0.001, 0.999);

reflectionTexCoords.y = clamp(reflectionTexCoords.y, -0.999, -0.001);

vec4 reflectionTex = texture2D(reflection, reflectionTexCoords);

vec4 refractionTex = texture2D(refraction, refractionTexCoords);

vec4 finalColor = mix(refractionTex, reflectionTex, 0.5);

finalColor = mix(finalColor, vec4(0.0, 0.3, 0.2, 1.0), 0.5);

gl_FragColor = finalColor;

Update:

I recorded another video but without the waving effect, if you notice the borders of the water texture tile moves, but initially matched. I'm starting to think I have two problems here :/

http://recordit.co/BqftsO0FCu

http://recordit.co/F0dt7H63px

I'm learning how to make water so please excuse me. I'm suspecting this has to do with the refractionTexCoords += totalDistortion.xy line, but I'm not sure how to avoid this visual bug. I'll share the portion of the frag shader that is in charge with movig the water. Thanks in advance!

// Oh and this is how I compute the clipSpace in the vertex shader: clipSpace = mvp * a_position;

vec2 ndc = (clipSpace.xy/clipSpace.w) / 2.0 + 0.5;

vec2 reflectionTexCoords = vec2(ndc.x, -ndc.y);

vec2 refractionTexCoords = vec2(ndc.x, ndc.y);

vec4 distortion1 = (texture2D(dudv, vec2(newTexCoords.x + moveFactor, newTexCoords.y).rg * 2.0 - 1.0)) * waveStr;

vec4 distortion2 = (texture2D(dudv, vec2(-newTexCoords.x + moveFactor, newTexCoords.y + moveFactor).rg * 2.0 - 1.0)) * waveStr;

vec4 totalDistortion = distortion1 + distortion2;

refractionTexCoords += totalDistortion.xy;

refractionTexCoords = clamp(refractionTexCoords, 0.001, 0.999);

reflectionTexCoords += totalDistortion.xy;

reflectionTexCoords.x = clamp(reflectionTexCoords.x, 0.001, 0.999);

reflectionTexCoords.y = clamp(reflectionTexCoords.y, -0.999, -0.001);

vec4 reflectionTex = texture2D(reflection, reflectionTexCoords);

vec4 refractionTex = texture2D(refraction, refractionTexCoords);

vec4 finalColor = mix(refractionTex, reflectionTex, 0.5);

finalColor = mix(finalColor, vec4(0.0, 0.3, 0.2, 1.0), 0.5);

gl_FragColor = finalColor;

Update:

I recorded another video but without the waving effect, if you notice the borders of the water texture tile moves, but initially matched. I'm starting to think I have two problems here :/

http://recordit.co/BqftsO0FCu