Sign in to follow this  
ufinii

Question about Vertex Shaders

Recommended Posts

I am reading the chapter about Vetex Shaders on the book: "Introduction to 3D Game Programming with DirectX 9.0". Here you can see a piece of code taken from the samples (the language is HLSL):
// transform vertex position to homogenous clip space
output.position = mul(input.position, WorldViewProjMatrix);
I have a question... Why in the samples they usually transform the vertices inside the shader? It's for performance reason? If we do that, the application won't transform the point again messing up the scene?

Share this post


Link to post
Share on other sites
Enabling a Vertex Shader disables the Vertex Processing part of the Fixed-Function Pipeline. This means that when you're using a Vertex Shader, you are taking the responsibility of transforming vertices, as well as a few other things. If you wouldn't transform them in the Vertex Shader, they won't be transformed at all.

This means that when using a Vertex Shader, the D3DTS_WORLD, D3DTS_VIEW, and D3DTS_PROJECTION values are completely ignored, since your Vertex Shader is running, instead of that portion of the pipeline.

Hope this helps.

Share this post


Link to post
Share on other sites
Hmmm maybe I'm getting something wrong but why during the Vertex Declaration the book says:

Quote:

A vertex declaration with a D3DDECLUSAGE_
POSITIONT member implies that the vertex has already been
transformed, which instructs the graphics card to not send this vertex
through the vertex processing stages (transformation and
lighting).


Shouldn't this mean that only such vertices won't be processed?

Share this post


Link to post
Share on other sites
D3DDECLUSAGE_POSITIONT is a completely another cup of coffe, it says to the driver that the incoming vertex has already been transformed on the CPU,read the whole vertex shader processing had been done on the CPU so it is skipped by the GPU and only pixel processing gets done.
It's similar to the RHW modifier in the fixed-function pipeline

Share this post


Link to post
Share on other sites
D3DDECLUSAGE_POSITIONT tell DirectX that the vertex placed in the Vertex Buffer has already been Transformed and Lit. Vertices that use the D3DDECLUSAGE_POSITIONT, run neither the Vertex Processing Stage nor the Vertex Shader. A vertex used with D3DDECLUSAGE_POSITIONT is assumed to have already been transformed into clip-space prior to being placed in the Vertex Buffer. So, when you draw vertices using D3DDECLUSAGE_POSITIONT, the data in the Vertex Buffer is assumed to be what is normally output from the Vertex Shader -- transformed and lit.

When drawing vertices with D3DDECLUSAGE_POSITION (No T), only the Vertex Processing stage of the FFP, OR the Vertex Shader, is active at any given time.

Hope this clears it up some more :).

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