CG Shader Bug?

I’m using a CG shader to render textures. For testing purposes I made this shader:

//Cg

void vshader(
    uniform float4x4 mat_modelproj,
    in float4 vtx_position: POSITION,
    in float2 vtx_texcoord0 : TEXCOORD0,
    in float4 vtx_color: COLOR,
    out float4 l_position: POSITION,
    out float2 l_texcoord0,
    out float4 l_pos)
{
    l_pos=vtx_position;
    l_position.x=vtx_texcoord0.x*2-1;
    l_position.y=vtx_texcoord0.y*2-1;
    l_position.z=0.0;
    l_texcoord0=vtx_texcoord0;
}



void fshader(
    in float4 l_pos,
    sampler2D tex_0,
    in float2 l_texcoord0,
    out float4 o_color: COLOR)
{
    float4 c=tex2D(tex_0,l_texcoord0);
    float v=0;
    v=l_pos.x;//This line breaks it! Take it out and it works fine.
    c.b=v;
    o_color=c;
}

Below is a screenshot with the buffer viewer up showing (on the left) tex_0 (made my another similar shader), and on the right, the result of my shader. It seems that l_texcoord0 is corrupted in some way by referencing l_pos. Can any one explain this and/or suggest possible ways to avoid/fix it?

The line is question is " v=l_pos.x"
It seems that referencing l_pos causes a major change in the result of my shader.

Here is with the line commented out:

And here is with the line enabled:

Thanks!

That’s very weird indeed. Driver bug, perhaps?

Could you send me a full working sample program so I can take a look at it myself?

try:

//Cg

void vshader(
    in uniform float4x4 mat_modelproj,
    in float4 vtx_position: POSITION,
    in float2 vtx_texcoord0 : TEXCOORD0,
    in float4 vtx_color: COLOR,
    out float4 l_position: POSITION,
    out float2 l_texcoord0: TEXCOORD0,
    out float4 l_pos: TEXCOORD1)
{
    l_pos=vtx_position;
    l_position.x=vtx_texcoord0.x*2-1;
    l_position.y=vtx_texcoord0.y*2-1;
    l_position.z=0.0;
    l_texcoord0=vtx_texcoord0;
}



void fshader(
    in uniform sampler2D tex_0: TEXUNIT0,
    in float2 l_texcoord0: TEXCOORD0,
    in float4 l_pos: TEXCOORD1,
    out float4 o_color: COLOR)
{
    float4 c=tex2D(tex_0,l_texcoord0);
    float v=0;
    v=l_pos.x;//This line breaks it! Take it out and it works fine.
    c.b=v;
    o_color=c;
}

but yeah full program would be helpful.

treeform, that fixed it. Thanks!

If any one would like a full working sample demonstrating the issue, I can still provide one, but I’m pretty sure is was simply not specifying enough stuff in the shader.

Yeah, Cg can do weird stuff if you don’t apply semantic strings to parameters. That’s exactly why I prefer GLSL.