I’ve managed to get vertex, geometry, and fragment shaders working using GLSL. Vertices and colors are processed correctly through my rendering pipeline, but the problem is I can’t seem to access the vertex color input from the vertex shader. I have tried every variant of a vertex shader that I could find here and elsewhere on the web, but nothing lets me get the initial vertex color. My model ends up being rendered all white except for a bit of yellow and cyan mixed in. What is the correct way to access the vertex color in a GLSL vertex shader?
#version 330
in vec3 vertex;
in vec4 color;
out vec4 vColorVS;
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * vec4(vertex, 1.0);
vColorVS = color;
}
If I change the last line of the shader to:
vColorVS = vec4(1.0, 0.0, 0.0, 1.0);
then the model is correctly drawn red, so I know the problem is just getting the vertex color.
(my card doesn’t support newer shaders, so I can’t say anything about GLSL 3.3)
You cannot use the old gl_ModelViewProjectionMatrix on newer versions of GLSL.
The syntax with just “vertex” and “color” is supposed to work as well, but due to a bug, it only works on some models (presumably those that actually have vertex colours). I’ll investigate.
My investigation seems to have uncovered a bug in Panda, but it only appears when one of the attributes is actually missing. Is it perhaps the case that the model you are applying it on doesn’t actually have vertex colours?
I am creating my geometry procedurally using GeomVertexFormat.getV3c4() as my vertex format, so I’m positive the vertices have colors. If I don’t apply the shaders, the colors come through as expected.
I’m new to shader programming so various versions and syntax have been a nightmare. For your code, doesn’t the color also have to be assigned:
I’ve tried mixing GLSL version 1.2 and 3.3 shaders, but this often results in a “program not responding” crash even though the shaders compile successfully.