# GLSL drives me insane!

This topic is 4910 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm working on a GFX5200,and using GLSL.Long story short,here is a very simple piece of code: Vertex shader:
varying vec4 col;

void main()
{vec4 lpos;

lpos=gl_LightSource[0].position;

gl_Position=ftransform();
col=vec4(1,0,0,0);
}


varying vec4 col;
void main()
{
gl_FragColor=col;
}


This is not my actual shaders,but a simple example demonstrating the problem(or should I say driver bug?) The objects should all be colored red,right?Wrong!The colors are completely incorrect,and they even change when I rotate or move the camera.Now,if I comment out the line that accesses the lightsource position,all is fine.Bottom line,if lightsource parameters are present in the code,the varying varables mapping is somehow affected,and the results are incorrect.I downloaded the latest NVidia drivers(61.77),but it didn't help.So,what's the deal here?

##### Share on other sites
I had a problem with my GF5200, it turns out that the drivers don't activate GLSL by default, you need to edit the registry to activate it manually. Have you done this? if not, this is what I did.

HKEY_LOCAL_MACHINE\SOFTWARE\NVIDIA Corporation\Global\OpenGL\Debug

then add a dword value called ShaderObjects and set it's value to 1.

##### Share on other sites
Thanks for the reply,but I know all that.I get support for GLSL,I just get this bug in the situation I described.

##### Share on other sites
I plugged the example code you gave into TyphoonLabs ShaderDesigner (Link), and discovered that this occurs for me, too (HW : GeForceFX 5700). Including the "lpos=gl_LightSource[0].position;" line creates the effect you described, commenting it out made the colour a solid red.

For the sake of interest, I started messing around with the code, trying to understand why the problem occurs. I discovered that if I declared the lpos variable outside the main loop, the problem disappears...

varying vec4 col;varying vec4 lpos;void main(){lpos=gl_LightSource[0].position;gl_Position=ftransform();col=vec4(1,0,0,1);}

Even if this variable is not declared in the fragment shader, simply declaring it in the vertex shader makes the problem go away. Most odd..

If you're after a reason WHY this happens, I can't help you at all... but if you just need something to work, this information may help you.

I'd be interested to know the reason, myself...

Good luck!

Hew T.

##### Share on other sites
Hew,thanks very much,I tried that and it solved the problem.And this happens for any lightsource parameter.If I use gl_LightSource.diffuse,I have to put it in a varying variable,too.I think that probably it's a bug in the drivers.