Writing and reading from registers (Cg programming)

Started by
2 comments, last by clb 15 years, 5 months ago
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?
Advertisement
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.
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.
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.

This topic is closed to new replies.

Advertisement