Texture negative values

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.

Normalize your output data to 0-1 range.

Have you tried what nenad said?

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

Best Regads.

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.

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.

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.