PDA

View Full Version : glsl if statment issue



borcha
05-12-2015, 06:01 AM
Hello!
Im trying to implement cascaded shadowmaps into my game

Here is part of my fragment shader code:

float shadow(float bias)
{
float visibility = 0;
int index=1;
if(gl_FragCoord.z<1.0){ //1.0 is just for testing purposes, so it is always true
index=0; //when i change index here
}
vec4 shadowCoord=depthPV*vPos;

//and try to use it here, i get white triangles on screen, when i manualy change it to shadowMap[0] 1 or 2 it works as expected
if ( texture(shadowMap[index], shadowCoord.xy).z < shadowCoord.z+bias){
visibility = -1;
}

return visibility;
}

GClements
05-12-2015, 08:16 PM
You're declaring the variable index inside of a block, so it doesn't exist outside of that block.

If you check the shader's compile status with glGetShaderiv() and retrieve the info log with glGetShaderInfoLog(), you should find that it failed to compile because of a reference to an undefined variable named index.

The net result is that the program is invalid and glUseProgram() fails, meaning that no program object is in use when you perform rendering; in a compatibility profile, you'll get the behaviour of the fixed-function pipeline which, with default states (no lighting, no texturing, etc), will result in everything being rendered in solid white.