Archived

This topic is now archived and is closed to further replies.

Vertex Shaders

This topic is 5503 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

I am just starting out with vertex shaders and before I used to just let directX do everything with the matrices and it worked fine. Now that I am using vertex shaders I need to do matrix stuff myself. I just want to render a triangle with a diffuse colour. Sounds easy, right? Right. Here is my vertex shader. Straight outta the DX help file: vs.1.1 ; Vertex shader version 1.1.\n\ dp4 oPos.x, v0, c0 \n\ dp4 oPos.y, v0, c1 \n\ dp4 oPos.z, v0, c2 \n\ dp4 oPos.w, v0, c3 \n\ mov oD0, v1 ; The variable color.\n" I edited it to get the diffuse colour from the vertex instead of a constant. The triangle renders fine except I don''t know what matrix to pass the vertex shader. I am not quite sure what it is I am doing. I tried passing it the transposed View matrix but that only rendered it (half) correctly when the z was within 1 unit from it. I tried not transposing the matrix and when you move left to right the triangle gets skewed towards you in the opposite direction than you were moving. Any advice would be great. Thanks. -Greg Koreman

Share this post


Link to post
Share on other sites
from my book:

//Create the complete matrix
D3DXMATRIX ShaderMatrix = m_WorldMatrix * m_ViewMatrix * m_ProjectionMatrix;

//Get the transpose
D3DXMatrixTranspose(&ShaderMatrix, &ShaderMatrix);

//Pass the transposed matrix to the shader
m_pD3DDevice->SetVertexShaderConstant(0, &ShaderMatrix, 4);


Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces"

Share this post


Link to post
Share on other sites
I don''t think I have a say in the matter (re: chapters on the web). If you want, you can get a trial subscription to books24x7.com and see snippets of the book there. I also have an article on 2D here at gamedev if you want to take a look.

Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces"

Share this post


Link to post
Share on other sites