GLSL problem

This is part of the fragment shader from the Orange Book [shadow shader]. Lwjgl (or Jme) is throwing an error when I run this.

when I run this in RenderMonkey, it works just fine. (pg344-345 in the book)

Vertex - Works Fine

attribute float Accessibility;

varying vec4 ShadowCoord;

const float As = 1.0/1.5;
const float Ds = 1.0/3.0;

void main(){
   vec4 ecPosition = gl_ModelViewMatrix*gl_Vertex;
   vec3 ecPosition3 = (vec3(ecPosition))/ecPosition.w;
   vec3 VP = vec3(gl_LightSource[0].position)-ecPosition3;
   VP = normalize(VP);
   vec3 normal = normalize(gl_NormalMatrix * gl_Normal);
   float diffuse = max(0.0,dot(normal,VP));
  float scale = min(1.0,Accessibility * As + diffuse * Ds);
   vec4 texCoord = gl_TextureMatrix[1] * gl_Vertex;
   ShadowCoord = texCoord / texCoord.w;
   gl_FrontColor = vec4(scale * gl_Color.rgb,gl_Color.a);
   gl_Position = ftransform();
}



Fragment- LookUp function throws lwjgl error

uniform sampler2DShadow ShadowMap;
uniform float Epsilon;
uniform bool SelfShadowed;
uniform float SelfShadowedVal;
uniform float NonSelfShadowedVal;

varying vec4 ShadowCoord;

float Illumination;

float lookup(float x, float y)
{
   float depth = shadow2D(ShadowMap,
      ShadowCoord.wxy + vec3(x,y,0) * Epsilon).x;
   return depth != 1.0 ? Illumination : 1.0;

}
void main(void)
{
   Illumination = SelfShadowed ? SelfShadowedVal: NonSelfShadowedVal;
  // vec2 o = mod(floor(gl_FragCoord.xy),2.0);
   float sum = 0.0;
  
   //sum += lookup(vec2(-1.5,1.5)  + o);
  // sum += lookup(vec2(0.5,1.5)   + o);
  // sum += lookup(vec2(-1.5,-0.5) + o);
  // sum += lookup(vec2(0.5,-0.5)  + o);

   sum += lookup(-0.5,-0.5);
   sum += lookup(0.5,-0.5);
   sum += lookup(-0.5,0.5);
   sum += lookup(0.5,0.5);
  
   gl_FragColor = vec4(sum*0.25*gl_Color.rgb,gl_Color.a);
}

can't test until i get home, but you could try changing vec3(x,y,0) to vec3(x,y,0.0)…it might not like float,float,int

Nope, I still just get a org.lwjgl.opengl.OpenGLException: Invalid operation (1282) when I change it to a float.

It only works in jME if I remove the lookup method in the code. There is nothing wrong in my implementation in jME, because again, the code works if I remove the lookup stuff.

I seem to get this error also, Im pretty sure the += operator is cusing the problem.

  sum += lookup(-0.5f,-0.5f);

  sum += lookup(0.5f,-0.5f);

  sum += lookup(-0.5f,0.5f);

  sum += lookup(0.5f,0.5f);



floats in java require an "f" at the end IF  there is a decimal place… otherwise java considers it a double.



thx,



timo

its not java though its glsl code  :wink:

my bad :P  I was reading the small section of lines and not the whole thing.

Dansas said:

This is part of the fragment shader from the Orange Book [shadow shader]. Lwjgl (or Jme) is throwing an error when I run this.
when I run this in RenderMonkey, it works just fine. (pg344-345 in the book)


RenderMonkey and JME are separate applications.

What has pointed you to believe that JME might be the culprit?

What is the error you received (StackTrace)?

gerbildrop said:

Dansas said:

This is part of the fragment shader from the Orange Book [shadow shader]. Lwjgl (or Jme) is throwing an error when I run this.
when I run this in RenderMonkey, it works just fine. (pg344-345 in the book)


RenderMonkey and JME are separate applications.

What has pointed you to believe that JME might be the culprit?

What is the error you received (StackTrace)?


again, you might wanna read the post again :)
since it works in rendermonkey and not in jme you could draw the conclusion that something is messed up(or more picky) in jme/lwjgl and it's shaderhandling/compilation or so.
the error he got was OpenGLException: Invalid operation (1282)
MrCoder said:

again, you might wanna read the post again :)


man that's a bad day for me reading :roll:

I would agree with Mr Coder that there is something "off" with the JME/LWJGL handling/compilation...

I had to do a little research, since I haven't used GLSL I didn't know that we could use glsl code "directly".

I'll do some more looking at this.

hehe i have those days all the time!  :smiley:



i'm gonna try to find time to run the stuff myself today, so i might have a solution later…