Position in fragment shader [SOLVED]

Hi all!

I’m trying to pass a position as a fragment shader input and I’ve read this http://www.panda3d.org/manual/index.php/List_of_Possible_Shader_Inputs, particularly the part that says:

So I wrote the following shader as a test:

//Cg

void vshader(uniform float4x4 mat_modelproj,
             in float4 vtx_position : POSITION,
             out float4 l_position : POSITION)
{

    l_position = mul(mat_modelproj, vtx_position);
}
 
void fshader(in float4 l_position: POSITION,
             out float4 o_color : COLOR0) 
{

    o_color = l_position;
}

When I run my game, I get the following error in the output:

I’ve set “basic-shaders-only #f” in my config file, but I’m still getting the same error. Is it possible to access an interpolated position in a fragment shader?

Thanks!

the “out float4 l_position : POSITION” is consumed by the graphics card, so you cant access it your fshader. So just return it twice, once graphics card and once for your needs. Another note you can’t do much with a mul(mat_modelproj, vtx_position) position any ways because it has that stupid matrix applied unless its a screen space shader.

in my shaders i do:

void vshader(
...
out float4 l_vertPos   : TEXCOORD6,
...
l_position=mul(mat_modelproj, vtx_position);
l_vertPos = vtx_position;
...
void fshader(
in  float4 l_vertPos   : TEXCOORD6,
...
 lightvec = normalize((float3)mspos_sun - l_vertPos); // use it in like light stuff
...

Note that the actual names of l_ and o_ parameters do not matter - they are handled by Cg per semantic string.

Also, if you hate having an extra output, you can use return values (and in 1.7.0, you can use structs too):

//Cg

float4 vshader(uniform float4x4 mat_modelproj,
             in float4 vtx_position : POSITION,
             out float4 l_position : TEXCOORD0) : POSITION
{

    l_position = mul(mat_modelproj, vtx_position);
    return l_position;
}
 
void fshader(in float4 l_position: POSITION,
             out float4 o_color : COLOR0)
{

    o_color = l_position;
} 

Great!

So that means that I can use any available TEXCOORDX semantic for passing any additional information to my fragment shader?

(Sorry about the noob questions, but I don’t have much shader experience…)

Yes, I’m sure you can use other semantics for it too, I guess that’s a matter of trying out.
In Cg/cg_bindlocations.h you can find a list:

code.google.com/p/dolphin-emu/so … ocations.h

Excellent! Thank you very much for your clarifications!