Advertisement

Water DuDV Maps, not mapping correctly

Started by January 06, 2019 02:54 AM
0 comments, last by Morrison Din 6 years, 1 month ago

Hello all,

I need some help with distorting a water quad using a DuDv map. I have been following ThinMatrix's Water tutorials, for the most part successfully. For my particular problem, I followed this tutorial: https://www.youtube.com/watch?v=6B7IF6GOu7s.

Upon using a DuDv map to distort my water quad, all seems fine, except that there is a small problem. There are line seams across the water quad.

The attached image illustrates the issue.Seam.png.97baebdd246a97ab95a532e22663b2b9.png

This is my code:

water.vertexshader
 


// The coordinates to sample the dudv map with

layout(location = 0) in vec3 vertex;

void main(){

texCoords = vec2(vertex.x/2.0 + 0.5, vertex.z/2.0 + 0.5) * 0.24; // vertex is a read-in coordinate from a blender exported mesh file

}

water.fragmentshader
 


uniform sampler2D waterDuDv;

uniform float in_time;

void main(){

vec2 distortion = texture(waterDuDv, vec2(texCoords.x + in_time, texCoords.y)).rg * 0.1;
distortion = texCoords + vec2(distortion.x, distortion.y + in_time);
vec2 totalDistortion = (texture(waterDuDv, distortion).rg * 2.0 - 1.0) * 0.02;

// Projectively map the reflection texture
vec2 clipProj = ((clipSpace.xy / clipSpace.w) / 2.0 + 0.5);

clipProj.y *= -1.0f;

// Distort sampled texture with dudv map
clipProj += totalDistortion;

clipProj.x = clamp(clipProj.x, 0.001, 0.999);
clipProj.y = clamp(clipProj.y, -0.999, -0.001);

finalVec = vec4(texture(waterTexture, clipProj).rgb, 1.0); // waterTexture is a Render to Texture reflection image of the scene


}

If anyone could point out what's wrong or point me in the right direction, I would appreciate it.

Thank you in advance!

This topic is closed to new replies.

Advertisement