PDA

View Full Version : Texture negative values



Azar92
01-27-2014, 07:40 AM
Hello! I'm trying to implement fluid dynamics on GPU, and each step of the algorithm is implemented by pair of shaders. Unfortunately, I faced a problem, which I don't know how to deal with. When Fragment Shader 1 renders to texture, I get an image with different values, negative and positive. But when I try to pass this texture to the next shader as uniform sampler2D, all values in this texture become positive. For example, as output of Fragment Shader 1 I have an RGBA pixel (-1.0, 1.0, -1.0, 1.0), in sampler2D I have (1.0, 1.0, 1.0, 1.0). I really don't know how to solve this, and I would be grateful, if someone helped me.

nenad*
01-27-2014, 08:18 AM
Normalize your output data to 0-1 range.

GraphicDesign
01-27-2014, 02:54 PM
Have you tried what nenad said?

I am wondering about that myself, did not work here.

Best Regads.

nenad*
01-27-2014, 04:10 PM
You'd of course need to de-normalize it back to original range in the next shader, or even better keep all your calculations across the shaders in the normalized range.

arekkusu
01-27-2014, 04:16 PM
Or use a texture format that can represent negative values. Like any _SNORM format, or any float format.

Pick a texture format that matches the precision and range needs of your algorithm.

Azar92
01-27-2014, 06:10 PM
Thank you very much for replies! As it turned out, it was not a problem with a texture, but with my algorithm, and somehow the problem disappeared, and now I'm trying to find out, why did it happen. I use GL_FLOAT format, and, of course, it must represent negative values.