vtx_color shader input not working?

Hi,

Is the vertex color shader input, vtx_color, broken? I’m using opengl, but no matter what happens, vtx_color is always white when accessed from a shader.

//Cg
//
//Cg profile arbvp1 arbfp1

void vshader(
   in uniform float4x4 mat_modelproj,
   float4 vtx_position : POSITION,
   in float4 vtx_color : COLOR,

   out float4 l_color : TEXCOORD0,
   out float4 l_position : POSITION )
{
   l_position = mul(mat_modelproj, vtx_position );
   l_color = vtx_color;
}

void fshader(
   in float4 l_color : TEXCOORD0,
   out float4 o_color : COLOR)
{
   o_color = l_color;
} 

I tried your example shader and it works in the current release of 1.7. I also verified that it works using COLOR as the semantic for l_color.

You’ll want to double-check that your model has valid vertex colors, and that they’re not e.g. " { 1 1 1 1 }".

Thanks for double checking for me.

I figured out the problem (and I still think it’s a bug!) But if the vertex colors are the same for every vertex, the shader input does not get the correct data and is only passed vtx_color = 1,1,1,1.

My test case had set the vertex colors to all red:
Vertex 1 { …
{ 1 0 0 1 } }

Vertex 2 {…
{ 1 0 0 1 } }

With this egg model, the shader input vtx_color = 1,1,1,1 regardless of what is stated in the eggfile.

If one of the vertex colors, (I only changed the first one), is set to something slightly different {0.9999, 0, 0, 1} ), then the correct values are passed to the shader.

So it seems that part of the egg loading process/shader process is optimizing out the vertex colors if they all are the same.

Your guess is right, this is part of the optimization when loading EGGs. If all verts are the same colour then they get converted to an “object colour” which I think is the same as using node.setColor(blah). You might be able to get access to this colour with:

in uniform float4 attr_color

If this works, you can multiply the vertex colour with this “object colour” to get the same colour that is in the EGG file regardless if the vertex colours got optimized away or not, since one of the two will be white.
Of course changing the colour of one vert is also a valid fix and is what I’ve done with my own tools. :slight_smile:

It turns out you can globally disable this optimization at egg-load time by setting the configuration variable:

egg-flat-colors  #f

Unfortunately this variable isn’t listed in the current List of All Config Variables, probably since that hasn’t been updated in quite a while.

The description from the source is:

–jonah