Skip to main content
GameDev.net gamedev.net
🔒 Locked

understanding shaders

Started by vidalsasoon Mar 25, 2005 at 9:45 PM 2 replies 850+ views
Original Post
vidalsasoon
vidalsasoon
OK, I got a very basic shader working in my app... problem is the mesh with the shader applied to it keeps on following my camera... it should be staying at the origin (identity matrix). According to my effectinstance my shader is only expecting the WorldViewProjection matrix. I feed it "identity * view * projection" matrix. Why does it behave like this? In my fx file that I posted below there's a variable that confuses me. "POSITION". My shader isn't expecting this from "SetTransform" as far as I know. Is it being read off some pipeline and causing the problem with my mesh? btw, my fx file simply turns my mesh purple and SHOULD stay put. //------------------------------------ float4x4 matWVP : WorldViewProjection; //------------------------------------ struct vertexInput { float3 Position : POSITION; }; struct vertexOutput { float4 HPosition : POSITION; float4 Diffuse : COLOR0; }; //------------------------------------ vertexOutput VS_TransformDiffuse(vertexInput IN) { vertexOutput OUT; OUT.HPosition = mul( float4(IN.Position.xyz , 1.0) , matWVP); OUT.Diffuse = float4(1.0f, 0.0f,1.0f,0.0f); return OUT; } //----------------------------------- technique textured { pass p0 { VertexShader = compile vs_1_1 VS_TransformDiffuse(); // Just use the color ColorArg1[0] = Diffuse; AlphaArg1[0] = Diffuse; ColorOp[0] = SelectArg1; AlphaOp[1] = SelectArg1; } }
sirob
sirob
Could you show us the code to setting the matrices? do you update them every frame, or just once at the start? The fx shader looks fine.
Sirob Yes.» - status: Work-O-Rama.
neneboricua19
neneboricua19
Quote:
Original post by vidalsasoon
In my fx file that I posted below there's a variable that confuses me. "POSITION". My shader isn't expecting this from "SetTransform" as far as I know. Is it being read off some pipeline and causing the problem with my mesh?

The position variable comes from your actual mesh. The input to your vertex shader should be the vertices of your geometry. These vertices are often made of a bunch of different components (position, normal, texture coordinates, etc...) but in your case, your shader is only dealing with the position, which is perfectly fine.

In the shader you have posted, the shader accepts as input the position of a vertex from the mesh. It then applies the World*View*Projection matrix to this vertex and outputs this value. It also outputs a solid color for each vertex.

The shader is pretty simple and I don't see anything wrong with it either. As sirob has suggested, post a little bit about how you set up the matrices and pass them to the shader.

neneboricua

[Edited by - neneboricua19 on March 26, 2005 11:36:09 PM]
vidalsasoon
vidalsasoon
Fixed it.

I ended up making a global semantics class to handle the more common types. Saw that my view matrix was only being updated after my camera... BAD DATA.

Info was very helpful btw. thanks.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.