Jump to content
  • Advertisement
Sign in to follow this  
mlt

Writing and reading from registers (Cg programming)

This topic is 3538 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!