Matrix Problem

Started by
27 comments, last by wasd 18 years, 6 months ago
That is the identity matrix. This makes the shading relative to my camera position, not the position between the light and the mesh.
Advertisement
So I guess that means you actually do need to apply a transform then.
Normally the world matrix is created by using a few basic transform matrices, such as the translation matrix, rotation matrix, and the scaling matrix. The translation matrix simply moves all the vertices alike, thus translating the object from one point to another without changing its direction or form.
http://www.programmersheaven.com/2/world-view

So the translation matrix, rotation matrix, and the scaling matrix multiplied together will provide the worldMatrix.

How exactly?
They're multiplied together:

World = Identity;
World *= Scaling;
World *= Rotation;
World *= Translation;
Something like this:

worldFix = Matrix.Identity
worldFix *= Matrix.Translation(-center);
worldFix *= Matrix.RotationY(Geometry.DegreeToRadian(360.0f));
worldFix *= Matrix.RotationX(Geometry.DegreeToRadian(360.0f));

So, what do I use for scale that will keep the matrix the same?
You can omit a transform if you don't need it. So just ignore the scaling step.
Quote:Something like this:

worldFix = Matrix.Identity
worldFix *= Matrix.Translation(-center);
worldFix *= Matrix.RotationY(Geometry.DegreeToRadian(360.0f));
worldFix *= Matrix.RotationX(Geometry.DegreeToRadian(360.0f));

So, what do I use for scale that will keep the matrix the same?
The scale matrix that leaves the object unscaled is the identity matrix. Anytime you multiply by the identity matrix the original matrix is unchanged, so you never need to perform that operation. Note also that both of your rotation matrices above are the identity matrix as well. The only non-identity operation you have is the translation, so that is the only transform that you need to incorporate into your matrix directly. In other words, only the first two lines of your above code are necessary to set up the desired transform.

In fact, even that multiplication is unnecessary. It can just be:

world = Matrix.Translation(-center);
Thanks very much guys,

I'm having a problem now that shading effect is connected to the camera. When I move the camera, the shading effect alters. I think this problem is in my shader code.

I have tried the following changes:

float4 Lite2 = normalize(Lite - Out.Pos); //Connected to Camera
float4 Lite2 = normalize(Lite); //shading effect, but light projects from 1 point only.
float4 Lite2 = normalize(Lite - Pos); //Loss of ambient color, light source could be anywhere

Out.Pos = mul( Pos, worldMatrix ); //Black screen


Here is a snippit of the code:

//Vertex Shader Routine
VS_OUTPUT VertScene( float4 Pos : POSITION, float2 Tex : TEXCOORD0, float3 Normal : Normal )
{
VS_OUTPUT Out = (VS_OUTPUT)0;
Out.Pos = mul( Pos, worldViewProjection );
float4 Lite = (0.20, -0.76, -0.62, 0.99); //static test output light vector
float4 Lite2 = normalize(Lite - Out.Pos);
Out.Light = Lite2;
Out.Norm = normalize(mul(Normal, worldMatrix));
Out.Tex = Tex;

return Out;
}
That's because you're using the output position in your lighting calculations. This is the transformed position. You should use the either the input position transformed into world space or the light position transformed into object space.

This topic is closed to new replies.

Advertisement