0
votes

Currently making a game and I want to add nice shader effect like water distortion. I am rendering the scene to a FBO then apply a heightmap distortion shader on it. The distortion is applied by the fragment shader. normalMapPosition is the color vector at the current position of the normal map.

vec2 normalCoord = v_texCoord0;
vec4 normalMapPosition = 2 * texture2D(u_normals, v_texCoord0);
vec2 distortedCoord = normalCoord + (normalMapPosition.xz * 0.05);

then render it to the screen and I obtain the following result

diagonal artifact on shader effect

The problem is that there is a diagonal artefact traversing the whole image. I think this is due to the treatment by openGL of the texture as two triangles. Is there a nice way to handle this kind of issue?

1

1 Answers

0
votes

I finaly found the solution, the problem came from the utilisation of the same FBO to draw the scene and then to render the shader like:

batch.setShader(waterfallShaderProgram)
fbo.begin();
batch.begin();
// here is the problem, fbo is started and used to 
// draw at the same time
batch.draw(fbo.getColorBufferTexture());
batch.end()
fbo.end();

the scene is rendered to the FBO fbo in order to apply other effect on top. Introducing a new FBO fbo2 solved the issue.

batch.setShader(waterfallShaderProgram)
fbo2.begin();
batch.begin();
batch.draw(fbo.getColorBufferTexture());
batch.end()
fbo2.end();