Post Closed as "Off-topic" by Josh
3 added PS line
source | link

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?

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?

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?

2 edited title
| link

Need help with TEXCOORD0 vs COLOR in a Cg shader example

1
source | link

Need help with Cg shader example

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?