Author Topic: Help with setUniform  (Read 884 times)

Offline Raswr

  • byte
  • *
  • Posts: 13
    • View Profile
Help with setUniform
« on: January 09, 2013, 03:03:36 pm »
Hi!

I'm trying to make a fragment shader that displaces 2 textures (normal maps) on one of its coordinates using a uniform timer. I have a small static class that manages this with an update method called on each frame that increases the timer. The shader is linked to an object3D and works well except that the textures don't get displaced, as if the uniform timer didn't get updated.

This is a simplified version of what my java class does to the shader:

Code: [Select]
public class myShaderManager{
public static int timer=0;
static GLSLShader myShader;

    public static void update()
    {
        timer=timer+1;
        myShader.setUniform("timer", (float)timer);
    }
}

Am I doing the set uniform part wrong?. For some reason I'm using the exact same shader on another project (openGLES2 only, shaders only differ in naming) and it works well so i'm getting a bit confused and just decided to ask here as I've learned a lot of things in these forums  :)  I can also provide some shader code if needed.


Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Help with setUniform
« Reply #1 on: January 09, 2013, 03:26:47 pm »
Texture coordinates are from 0 to 1, maybe you want something like this?

Code: [Select]
public class myShaderManager{
public static float timer = 0;
static GLSLShader myShader;

    public static void update()
    {
        timer += 0.01f;
        if (timer > 1)
           timer = 0;
        myShader.setUniform("timer", timer);
    }
}

Offline Raswr

  • byte
  • *
  • Posts: 13
    • View Profile
Re: Help with setUniform
« Reply #2 on: January 09, 2013, 03:40:34 pm »
Texture coordinates are from 0 to 1, maybe you want something like this?

Code: [Select]
public class myShaderManager{
public static float timer = 0;
static GLSLShader myShader;

    public static void update()
    {
        timer += 0.01f;
        if (timer > 1)
           timer = 0;
        myShader.setUniform("timer", timer);
    }
}


That was it! Sometimes I feel stupid :D, in the other version I had that timer multiplied by 0.01 before passing it and that's why it worked, and I completely ignored that in this version so i was just adding 1 to the texcoord leaving it in the same position  :-[ Thanks a lot!
« Last Edit: January 09, 2013, 03:43:22 pm by Raswr »