GLSL drives me insane!

Started by
3 comments, last by mikeman 19 years, 7 months ago
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);
}


Fragment shader:

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?
Advertisement
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.

Add this key:
HKEY_LOCAL_MACHINE\SOFTWARE\NVIDIA Corporation\Global\OpenGL\Debug

then add a dword value called ShaderObjects and set it's value to 1.
---When I'm in command, every mission's a suicide mission!
Thanks for the reply,but I know all that.I get support for GLSL,I just get this bug in the situation I described.
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.
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.

This topic is closed to new replies.

Advertisement