PDA

View Full Version : Vertex colors in the shader



Leadwerks
03-16-2007, 10:58 AM
Vertex colors don't seem to show up in my fragment shader:

void main (void)
{
gl_FragColor=gl_Color;
}

Is there anything else I have to do? They show up fine in non-shader mode.

zeoverlord
03-16-2007, 11:42 AM
That's because they are only available from the vertex shader, to get the vertex colors in the fragment shader you must pass it to the fragment shader using an varying variable.

But if you want you can add
gl_FrontColor=gl_Color;
in the vertex shader and it should work (it actually does the same thing but with built in variables).

Leadwerks
03-16-2007, 01:35 PM
I actually already had that, and it didn't see to do anything.

So would it be like this?:

vert:
void main (void)
{
gl_FragColor=gl_Color;
}

frag:
void main (void)
{
gl_FragColor=gl_Color;
}

This is what it was before, and it doesn't work. It just draws dark gray (32,32,32).

Leadwerks
03-16-2007, 10:39 PM
How odd. I removed some unrelated code and now it works fine. One of those ghost bugs that happen so often in shaders.

Vexator
03-17-2007, 08:35 AM
does it make sense to write to gl_FragColor in a vertex shader?

Leadwerks
03-17-2007, 04:54 PM
No, but that was just s typo (only in my forum post). I meant gl_FrontColor.