I am working with an nVIDIA GeForce FX 5900 Ultra and have run into the
following behavior.
I want to write a vertex/fragment shader pair which mimics OpenGL’s
lighting, but at the fragment shader level. What this will mean is per-fragment
lighting which will produce superior spotlight effects.
What I ran into is that much of the OpenGL state data appears inconsistent
to the fragment shader. I conducted the following experiment.
First, I used this simple vertex shader:
void main(void)
{
gl_FrontColor = gl_FrontMaterial.ambient;
gl_BackColor = gl_FrontColor;
gl_Position = ftransform();
}
With this simple fragment shader:
void main(void)
{
gl_FragColor = gl_Color;
}
and everything worked as I expected.
Next I used this simple vertex shader:
void main(void)
{
gl_Position = ftransform();
}
With this simple fragment shader:
void main(void)
{
gl_FragColor = gl_FrontMaterial.ambient;
}
and the results were inconsistent (sometimes brown, sometimes yellow, then
white) and never what I expected.
This leads me to ask, does a fragment shader have access to the OpenGL
state? If not, where was my compiler error? If so, is this a hardware
problem?
I realize that I can pass a lot of information down to the fragment shader
to circumvent the problem if necessary, but I am not sure how to pass an
array like gl_LightSource. Does anyone know?
Thanks,
- Moe -