Sign in to follow this  
jalpeshk

[XNA] Model Rotation & Lighting

Recommended Posts

[img]http://i.imgur.com/pYZoA.jpg[/img]


All the blocks shown are rendered from the same model, with a few of them being rotated by 90 degrees. I'm using a shader to get the lighting, but the models that are rotated also have their lighting shifted. It seems as if the models are rotated after the shader effects are applied? My shader can be found here: [url="http://pastebin.ca/2066327"]http://pastebin.ca/2066327[/url]

[b]How can I get the rotated models to have the same lighting?[/b] The rotation values are passed in the World matrix.

Here is the rendering code:
[code]
foreach (ModelMesh mesh in model.Meshes)
{
foreach (Effect effect in mesh.Effects)
{
...

effect.Parameters["World"].SetValue(gameModel.Transforms[mesh.ParentBone.Index] * gameModel.World);
effect.Parameters["View"].SetValue(gameModel.View);
effect.Parameters["Projection"].SetValue(gameModel.Projection);
}

mesh.Draw();
}[/code]


I set each objects World before it is rendered to a matrix that create the horizontal shear effect off the models.

Here is the code for each objects World Matrix:
[code]
public Matrix World
{
get { return _world; }
set
{
Matrix scale = Matrix.CreateScale(_scale);
Matrix rotation = Matrix.CreateRotationX(MathHelper.ToRadians(_rotate.X)) * Matrix.CreateRotationY(MathHelper.ToRadians(_rotate.Y)) * Matrix.CreateRotationZ(MathHelper.ToRadians(_rotate.Z));
Matrix translation = Matrix.CreateTranslation(_translate);

_world = translation * scale * rotation * value;
}
}[/code]

Share this post


Link to post
Share on other sites
[quote name='kulzada' timestamp='1306005579' post='4813932']
_world = translation * scale * rotation * value;
[/quote]

I think your matrix order is backwards. It should be:

world = scale * rotation * translation;

See if that fixes it.


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