Sign in to follow this  

GLSL drives me insane!

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

If you intended to correct an error in the post then please contact us.

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);
}


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?

Share this post


Link to post
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.

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.

Share this post


Link to post
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 this post


Link to post
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[i].diffuse,I have to put it in a varying variable,too.I think that probably it's a bug in the drivers.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this