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

Started by
3 comments, last by matthughson 14 years, 1 month ago
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]
__________________________________[ Website ] [ Résumé ] [ [email=contact[at]matthughson[dot]com]Contact[/email] ][ Have I been Helpful? Hook me up! ]
Advertisement
Could you post the code for your shaders, please?
Sorry for all the empty replies... gamedev.net is acting very strange for me. Trying to get it figured out so I can post the shader code.
__________________________________[ Website ] [ Résumé ] [ [email=contact[at]matthughson[dot]com]Contact[/email] ][ Have I been Helpful? Hook me up! ]
Ok, I am unable to post the code in a reply for some reason, so the best I can do is link to the files:

Phong.fx

xsi_defaultvs.hlsl

xsi_include9.hlsl

xsi_lightdef9.hlsl

Hope this is enough to help me out with this. Again, sorry if you were being spammed with e-mails about my empty replies earlier. Seems like GameDev is having issues.

Thanks!
__________________________________[ Website ] [ Résumé ] [ [email=contact[at]matthughson[dot]com]Contact[/email] ][ Have I been Helpful? Hook me up! ]
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.
__________________________________[ Website ] [ Résumé ] [ [email=contact[at]matthughson[dot]com]Contact[/email] ][ Have I been Helpful? Hook me up! ]

This topic is closed to new replies.

Advertisement