Sign in to follow this  
jdaniel

Vertex / Fragment Shader - Graphics Pipeline Question

Recommended Posts

Hi, I have a couple of questions regarding vertex and fragment programs and how they relate to the fixed function graphics pipeline in general. The first question is this: Is the Interpolator & Rasterizer expecting normalized device coordinates from the vertex shader. Stated differently, in a vertex shader that is mimicking the fixed function vertex path, should I be doing the perspective division inside the vertex shader or does the Interpolator take care of this? Here I do the perpective division in the vertex shader:
Out.Pos = mul( float4 (inPos, 1.f ), g_mWorldViewProj );
Out.Pos /= Out.Pos.w;
return Out;

Here I pass along the position without applying perspective divide:
Out.Pos = mul( float4 (inPos, 1.f ), g_mWorldViewProj );
return Out;

Which appropriately mimics the fixed function path? The second question has to do with the fragment shaders. Simply stated, is there an implicit depth value associated with a color output? What if I am using the default LESS_THAN depth test and I am only returning :COLOR in my shader? How does the raster operator update the pixel in the framebuffer? What depth would it use? for example, say I have depth testing turned on and I have a simple passthrough fragment shader:
void passthrough(float4 color : COLOR, out float4 ocolor: COLOR)
{
ocolor = color;
}   

What if there is already a pixel in the framebuffer with an associated depth? What happens to my depth test? Is there an implicit depth associated with fragments output from the fragment shader or must the programmer always explicitly output depth information along with fragment? Thanks.

Share this post


Link to post
Share on other sites
1. The perspective divide is done for you.

2. Fragments can drive the depth test (ps1.4 upwards). If you do not output a depth from your shader program the already calculated depth will be used.

Hope that helps.

You can find out more with a simple google for 'shader pipeline'.

- Al

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