Vertex Shaders

Started by
4 comments, last by Greg K 21 years, 5 months ago
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
Advertisement
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"
Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials
I am seriously thinking about buying your book. Thanks.
p.s. (You should put a chapter or two online so people can evaluate your writing style)
-Greg
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"
Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials
Ok, thanks. I will check it out.
-Greg
Recomendation here!

This topic is closed to new replies.

Advertisement