1
\$\begingroup\$

I have a simple fragment shader to simulate "falling water". I'm using Ogre3D and opengles2, this is my code:

#version 130

uniform sampler2D valveTex;
uniform sampler2D noiseTex;
uniform float time;

uniform vec3 sprayColor;

varying vec2 uv;
varying float rand;

    void main()
    {
        gl_FragColor.w = texture2D(valveTex, uv).w;
        float noiseW = texture2D(noiseTex, uv + vec2(rand, -time)).x;
        gl_FragColor.w *= noiseW + noiseW;
        gl_FragColor.xyz = sprayColor;
    }

The shader works well and I see the animation happening, but after some time running the animation stops like if the variable time stopped updating, and the water stream looks still. What can be causing this?

Edit1: variable time is derived from Ogre's time_0_1.

\$\endgroup\$
  • \$\begingroup\$ Can you confirm what wrapping mode you've configured for your noiseTex? \$\endgroup\$ – DMGregory Jun 8 '18 at 19:48
  • \$\begingroup\$ On my material file noiseTex is tex_address_mode wrap wrap \$\endgroup\$ – EzeEst Jun 11 '18 at 13:10
  • \$\begingroup\$ Hm, then we'll need to do some more troubleshooting. Can you print some values of time before and after the animation stops? \$\endgroup\$ – DMGregory Jun 11 '18 at 13:16
  • \$\begingroup\$ Ok, I'll try since it's quite random, sometimes the animation breaks after 15 minutes or so and on other cases it takes several hours, I have one test running since last Friday and it still works. \$\endgroup\$ – EzeEst Jun 11 '18 at 13:23
  • \$\begingroup\$ Hm. Sounds like the root cause is unlikely to be your shader code, then. Maybe something's going awry CPU-side where you update the uniform? \$\endgroup\$ – DMGregory Jun 11 '18 at 13:26
2
\$\begingroup\$

It sounds like your noiseTex you're looking up into might be configured with wrapping mode CLAMP_TO_EDGE - once your time uniform gets large enough to take it outside the [0, 1] texture coordinate range, texture samples start just repeating the same values they had at the edge of the texture.

Ensure your texture is a power of two in size and configured with wrapping mode REPEAT.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.