Problem with glsl setUniform

Hello,



I hope  that this post is not misplaced in troubleshooting, please move if so.



I try to make a really simple shader with JME from SVN (from last week). I am a beginner so its possible i made something wrong.



Ok, here is my Problem:



My Shaders:



noise.vert

uniform vec3 LP;
uniform vec3 LightPosition;
uniform vec3 SurfaceColor;
uniform float ScaleIn;
uniform float ScaleOut;
varying vec4 Color;
void main() {
   vec3 normal = gl_Normal;
   vec3 vertex = gl_Vertex.xyz + noise3(LP + gl_Vertex.xyz * ScaleIn ) * ScaleOut;
             
   normal = normalize(gl_NormalMatrix * normal);
   vec3 position = vec3(gl_ModelViewMatrix * vec4(vertex,1.0));
   vec3 lightVec = normalize(LightPosition - position);
   float diffuse = max(dot(lightVec, normal), 0.0);
   
   if (diffuse < 0.125)
       diffuse = 0.125;
   
   Color = vec4(SurfaceColor * diffuse, 1.0);
   gl_Position = gl_ModelViewProjectionMatrix * vec4(vertex,1.0);
}



noise.frag

varying vec4 Color;

void main () {
   //gl_FragColor = vec4(1,0,0,1);
   gl_FragColor = Color;
}



My workaround is made like the examples, and if i set gl_FragColor = vec4(1,0,0,1); in fragment shader my sphere in the scene is red. That proofs the shader are ok and work on my nvidia.

But when i want to set the uniform vars in my doRender(Renderer r) Method:

      glslShader.setUniform("LP", this.offset);
      glslShader.setUniform("SurfaceColor",new Vector3f(1,0,0));
      glslShader.setUniform("LightPosition",new Vector3f(10,10,10));
      glslShader.setUniform("ScaleIn",5f);
      glslShader.setUniform("ScaleOut",15f);
r.draw(myNode);



i got that error on and on in my console log:

SCHWERWIEGEND: Shader uniform [LP] could not be located in shader
06.05.2008 22:52:24 com.jme.scene.state.lwjgl.shader.LWJGLShaderUtil updateUniformLocation
SCHWERWIEGEND: Shader uniform [ScaleIn] could not be located in shader
06.05.2008 22:52:24 com.jme.scene.state.lwjgl.shader.LWJGLShaderUtil updateUniformLocation
SCHWERWIEGEND: Shader uniform [ScaleOut] could not be located in shader


(SCHWERWIEGEND is german and means a serious matter or error in english)
I double-proofed every single character and don't understand why SurfaceColor and LightPosition make no problem and the other three uniform vars cannot be found ?

what do i wrong ? What can i do ?

If needed i will post more of my code, but thats the code parts that matters in my opinion, the shader itself compiles and works on my sphere node in my scene. The scene contains just a sphere from jme and a standard light. There is not much i can do wrong.

any suggestions ?

thanks
Sebastian

I just tried this shader code in RenderMonkey and I got the same issue as you. It seems to completely ignore the ScaleIn/Out variables. I think the reason is that the noise3 function is not supported by video cards yet so they ignore it when they compile the shader code.

Try using a pre-generated noise texture instead, that's what most people are doing anyway.

I just tried this shader code in RenderMonkey and I got the same issue as you.

Thanks, good to know !

I think the reason is that the noise3 function is not supported by video cards yet so they ignore it when they compile the shader code.
Try using a pre-generated noise texture instead, that's what most people are doing anyway. 

thanks for that hint. I will try . . .

Hey, just to follow up did you ever get this sorted? Because I have the same problem!

What is there to be sorted out? The noise* functions are not supported by any video cards. See this page for info: http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=238459&fpart=1

yeah it ignores it and removes those uniforms which ends up with the error when it doesnt find a uniform to set. you need to use a texture with pregenerated noise or similar.

Okay so the problem is that something is wrong with the uniform? Because I had a "couldnt find uniform (name) in shader" too and thought i didnt set it right or something…

another scenario is if a uniform is not used in the shader(or doesnt contribute to the end result in any way), then the compiler might optimize it away and you'll get that result…

If you're having issues with your shader, post it on the forum in a new thread :slight_smile: