Jump to content
  • Advertisement
Sign in to follow this  
matthughson

[XNA] XSI Light Being Applied BEFORE World/Model Transforms [SOLVED]

This topic is 3040 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I recently noticed an issue with my renderer. I am using the XSI run-time to render skinned meshes in my XNA game. When I apply a rotation to my model via the the world transformation the lighting seems to get applied before the model is rotated by the world transforms. Meaning, I place a cube in the world with a light directly in front of it. The front of the cube is fully lit, and the back is in complete darkness. I then rotate the cube with the world transform. I have not moved the light. However, the front is now in complete darkness with the back now fully lit. It should not have changed. I'm not even sure it is apply to bone transformations either, but I haven't been able to get a simple test up and running yet. I am using the basic Phong.fx shader that comes with XSI|Mod Tool. Has anyone experienced this before and found a solution? Here is most of my rendering code.
foreach (ModelMesh mesh in mModel.Meshes) 
{ 
    foreach (Effect effect in mesh.Effects) 
    { 
        if (effect.GetType() == typeof(BasicEffect)) 
        { 
            throw new ArgumentException("A model inside " + mFileName + " does not have a shader assigned to it."); 
        } 
        else 
        { 
            bool isSkinned = (bones.GetLength(0) > 0); 
            // set the technique 
            if (isSkinned && (effect.Techniques["Skinned"] != null)) 
            { 
                effect.CurrentTechnique = effect.Techniques["Skinned"]; 
            } 
            else 
            { 
                if (effect.Techniques["Static"] != null) 
                { 
                    effect.CurrentTechnique = effect.Techniques["Static"]; 
                } 
                else 
                { 
                    effect.CurrentTechnique = effect.Techniques[0]; 
                } 
            } 

            // bind bones 
            if ((effect.Parameters["Bones"] != null) && isSkinned) 
                effect.Parameters["Bones"].SetValue(bones); 


            //Set paramaters 
            effect.Parameters["Model"].SetValue(transforms[mesh.ParentBone.Index] * world); 
            effect.Parameters["View"].SetValue(CameraManager.pInstance.pCameraViewMatrix); 
            effect.Parameters["Projection"].SetValue(CameraManager.pInstance.pCameraProjectionMatrix); 

            effect.Parameters["lightpos0"].SetValue(LightingManager.pInstance.GetLight(0).mPosition); 
            effect.Parameters["lightpos1"].SetValue(LightingManager.pInstance.GetLight(1).mPosition); 
            effect.Parameters["lightpos2"].SetValue(LightingManager.pInstance.GetLight(2).mPosition); 

            effect.Parameters["lightcol0"].SetValue(LightingManager.pInstance.GetLight(0).mColor); 
            effect.Parameters["lightcol1"].SetValue(LightingManager.pInstance.GetLight(1).mColor); 
            effect.Parameters["lightcol2"].SetValue(LightingManager.pInstance.GetLight(2).mColor); 
        } 
    } 

    mesh.Draw(); 
} 



[Edited by - matthughson on February 19, 2010 6:34:16 PM]

Share this post


Link to post
Share on other sites
Advertisement
I was able to come up with a solution, detailed here: http://forums.xna.com/forums/t/43035.aspx

It came down to the fact that the default skinned vertex shader that comes with XSI does not transform the Normals with the World/Model matrix. You have to add that functionality to the shader. This is also true for the position of verts, but I had fixed that already.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!