PDA

View Full Version : Wrong mipmap level when texture coordinates are discontinuous



Baptiste
10-25-2016, 07:55 AM
Hi,

I'm having issues with a line when I put reflection on my truck. hpics.li/136d5b2 (I remove the http)

I calculate reflected vectors with normals (which become also texture coordinates after a small function), I investigated the bug and I found that the texture coordinates (my reflected vector) go from 0 through 1 exactly on this line hpics.li/700e682 (you see the tex coord). It's not a problem of GL_CLAMP or anything like this(GL_NEAREST ...). The problem is more complex : because of the texture coordinates discontinuity, when I call the function "texture" the length of the derivative vector is huge so OpenGl choose the smaller mipmaps for this frament which is a 1*1 pixel , and I so the final result is a line.
The first solution is to fix the GL_TEXTURE_MAX_LEVEL to a small number like 3 or 4 with a 2000*1000 texture (the sky) but this is a ugly solution cause it causes some glittering.

Does anyone have an idea for me ?

Thank you to all of those who read my message and I hope there is a solution.

Baptiste

GClements
10-25-2016, 09:56 AM
Does anyone have an idea for me ?

Use textureGrad() or textureLod() rather than using the implicit gradient calculation within texture().

E.g. if you were doing something like this:


vec4 color = texture(tex, fract(uv));

then do this instead:


vec4 color = textureGrad(tex, fract(uv), dFdx(uv), dFdy(uv));

Baptiste
10-26-2016, 01:04 AM
Use textureGrad() or textureLod() rather than using the implicit gradient calculation within texture().

E.g. if you were doing something like this:


vec4 color = texture(tex, fract(uv));

then do this instead:


vec4 color = textureGrad(tex, fract(uv), dFdx(uv), dFdy(uv));


Well, thank you for your answer !
I found a solution based on your idea. I put an offset on my Reflect2D which go from 0 to 1. I did somthing like that :

EnvMapColor = textureGrad(EnvironmentMap2D, Reflect2D, dFdx(abs(Reflect2D - vec2(0.5, 0.5))), dFdy(abs(Reflect2D - vec2(0.5, 0.5))));


This solution works cause there is no discontinuity in the Reflect2D.
I do not know if performances are the same withe textureGrad ...
What do you think about this solution ?

Thank you all,

Baptiste