light ignores sprite's rotation
by Steve Wigmore · in Torque X 2D · 05/20/2009 (4:20 pm) · 6 replies
Hey Guys,
I'm not sure if this is a bug or not, but whenever I rotate a sprite (with attached normal map) the lighting on it doesn't reflect it's new rotation. Instead, it remains lit as tho it were never rotated.
Anyone have any thoughts on this? Cause I've been running through the source code and can't find any kind of solution aside from placing the light in an inverse parent matrix of sorts, relative to the new orientation of the sprite to fake the lighting... but this would have to be done for each object I want to light. :(
I'm not sure if this is a bug or not, but whenever I rotate a sprite (with attached normal map) the lighting on it doesn't reflect it's new rotation. Instead, it remains lit as tho it were never rotated.
Anyone have any thoughts on this? Cause I've been running through the source code and can't find any kind of solution aside from placing the light in an inverse parent matrix of sorts, relative to the new orientation of the sprite to fake the lighting... but this would have to be done for each object I want to light. :(
About the author
#2
_sceneObject.Rotation = T2DVectorUtil.AngleFromVector(new Vector2(move.Sticks[0].X * 20.0f, -move.Sticks[0].Y * 20.0f));
Any suggestions would be greatly appreciated.
Thanks
05/21/2009 (6:42 am)
What I have is all really basic. Place the material with the normal map on it. Place a light. I use this code to rotate the sprite._sceneObject.Rotation = T2DVectorUtil.AngleFromVector(new Vector2(move.Sticks[0].X * 20.0f, -move.Sticks[0].Y * 20.0f));
Any suggestions would be greatly appreciated.
Thanks
#4
the LightingEffect3D shader does this, but the LightingEffect2D shader does not. And, if I switch to the 3d shader for this asset, instead of not rotating the normal map at all... I get a double rotation.
09/10/2009 (12:56 am)
I've done some more digging around, and found out that the shader isn't rotating the normal map in tangent space.the LightingEffect3D shader does this, but the LightingEffect2D shader does not. And, if I switch to the 3d shader for this asset, instead of not rotating the normal map at all... I get a double rotation.
#5
It's so small I just let it go. I will hav to investigate as well as I am playing with fx files now.
09/10/2009 (8:51 pm)
That is funny, in my game I have lightmaps on all the player objects and the enmies and they seem to work pretty good, except one. All the lightmaps that do work are on objects created in the 2D editor. Later as an upgrade I add a turret to my base by attaching a template, the templated turret seems to have it's lightmap frozen on it, the light stays the same as the turret rotates. It's so small I just let it go. I will hav to investigate as well as I am playing with fx files now.
#6
but it isn't pretty.
essentially, u have to use the lightingEffect3d.fx file instead of 2d. but, since the builder ALWAYS saves a level file with a lightingEffect2d.fx file set as the one to use, it's really just easier to rename lightingEffect3d to lightingEffect2d, and vice verca.
at this point the normal will now be rotated with the image, but the normal will also be rotated on it's own. so you have to set one of the matrices to take that into account. Finally, tx2d's camera and other objects are set for a different orientation than the 3d lighting shader is tuned for. what the builder assumes is Y, the shader treats as Z. So the _worldviewprojectionmatrix has to be used in one or two calculations instead of the _worldMatrix.
I'll post a more detailed work out when I get back home.
09/11/2009 (5:00 pm)
so i found a simple hack fix to get this sort of thing working.but it isn't pretty.
essentially, u have to use the lightingEffect3d.fx file instead of 2d. but, since the builder ALWAYS saves a level file with a lightingEffect2d.fx file set as the one to use, it's really just easier to rename lightingEffect3d to lightingEffect2d, and vice verca.
at this point the normal will now be rotated with the image, but the normal will also be rotated on it's own. so you have to set one of the matrices to take that into account. Finally, tx2d's camera and other objects are set for a different orientation than the 3d lighting shader is tuned for. what the builder assumes is Y, the shader treats as Z. So the _worldviewprojectionmatrix has to be used in one or two calculations instead of the _worldMatrix.
I'll post a more detailed work out when I get back home.
Associate John Kanalakis
EnvyGames
John K.
www.envygames.com