1
\$\begingroup\$

I started to learn Cg shader programming, following the Panda3d shader tutorials. Having a scene with only a cube shown, each vertex of the model with a different color, I can successfully use the following shader:

void vshader(
    uniform float4x4 mat_modelproj,
    in float4 vtx_position : POSITION,
    in float4 vtx_color : COLOR,
    out float4 l_color : COLOR,
    out float4 l_position : POSITION)
{
    l_position = mul(mat_modelproj, vtx_position);
    l_color = vtx_color;
}

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

This works fine, I can see the colors on the cube interpolated between the vertices, based on the color values of the vertices set in to the cube model.

Now I changed that shader a bit to the following:

void vshader(
    uniform float4x4 mat_modelproj,
    in float4 vtx_position : POSITION,
    in float4 vtx_color : COLOR,
    out float4 l_my : TEXCOORD0,
    out float4 l_position : POSITION)
{
    l_position = mul(mat_modelproj, vtx_position);
    l_my = vtx_color;
}

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

However, using this custom variable l_my the coloring of the cube does not work correctly any more. Instead of the interpolated vertices colors I only see the default gray-ish color on the whole cube.

I understand that in the second example l_my is a TEXCOORD0 instead of a COLOR, but isn't it still a normal float4 value?

PS: it works again fine if I change l_my to COLOR -- but why does that solve the problem, if in both cases its of type float4?

\$\endgroup\$

closed as off-topic by Josh Dec 22 '14 at 21:30

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about debugging a problem in your project must present a concise selection of code and context so as to allow a reader to diagnose the issue without needing to read all of your code or to engage in extensive back-and-forth dialog. For more information, see this meta thread." – Josh
If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ Can you change the title to represent the actual issue you're facing? \$\endgroup\$ – MichaelHouse Jul 22 '13 at 13:54
  • 1
    \$\begingroup\$ Changing COLOR to TEXCOORD0 shouldn't have any effect, except that (IIRC) COLOR is clamped to [0, 1] before interpolation, and TEXCOORD0 isn't. \$\endgroup\$ – Nathan Reed Jul 22 '13 at 17:29
  • \$\begingroup\$ Well, there is no longer any vertex color output at all. Your cube may be uncolored (colored black). Try outputting a constant white COLOR from the vertex shader and see if that helps. \$\endgroup\$ – bobobobo Jul 22 '13 at 18:47
  • \$\begingroup\$ @bobobobo But he's reading the color from TEXCOORD0 in the fragment shader. \$\endgroup\$ – Nathan Reed Jul 22 '13 at 19:14
  • \$\begingroup\$ I know, but I'm concerned not outputting a vertex color from the vertex shader somewhere along the way says "this vertex has no color" and possibly just sets it black (either multiplying the output of the pixel shader by black, or not even evaluating the :COLOR output of the fragment shader). \$\endgroup\$ – bobobobo Jul 22 '13 at 20:03

Browse other questions tagged or ask your own question.