Sign in to follow this  
mlt

Writing and reading from registers (Cg programming)

Recommended Posts

From the Cg tutorial the following vertex and fragment programs for per-fragment shading are defined as:
void C5E2v_fragmentLighting(float4 position    : POSITION,
                            float3 normal      : NORMAL,

                          out float4 oPosition : POSITION, 
                          out float3 objectPos : TEXCOORD0,
                          out float3 oNormal   : TEXCOORD1,

                         uniform float4x4 modelViewProj)

As can be seen it read from the two registers POSITION and NORMAL. At the end of the program it writes to the three registers POSITION, TEXCOORD0 and TEXCOORD1. But the following fragmentprogram only read from last two registers: TEXCOORD0, TEXCOORD1 as can be seen below:
void C5E3f_basicLight(float4 position    : TEXCOORD0,
                      float3 normal      : TEXCOORD1,

                          out float4 color : COLOR,
                          ...

Why does the vertex program write to a register (POSITION) that the following fragment program does not read from?

Share this post


Link to post
Share on other sites
The POSITION semantic is a bit of a special case, as the vertex program outputted POSITION data is used by the rasterizer to convert the post-projected triangles to shadeable pixel fragments.

So, apart from the POSITION output parameter, all data you output from the vertex program can be read in the fragment program code.

Share this post


Link to post
Share on other sites
Ok but all output (Position, color, normal) from a Vertex Program enters the Rasterizer before entering the fragment program right? Then its just a matter what the fragmentprogram needs to read.

Share this post


Link to post
Share on other sites
Yes, the rasterizer also interpolates all the vertex attributes you passed as output from the vertex program in the same process when it rasterizes a triangle into shadeable fragments. Then all the interpolated attributes other than POSITION will be presented as an input to the fragment program.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this