Jump to content
  • Advertisement
Sign in to follow this  
greenwire

mdx shadowmap woes

This topic is 4675 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'm trying to implement the shadowmapping tutorial into my simple one mesh scene. It all compiles fine, the shadowmap.fx loads ok, and all the buffers are created ok. I'm pretty sure i'm setting all of the shader variables correctly. It even renders my scene from the correct viewpoint. The problem is, it renders my mesh completely white. Here's my render function:
private void RenderFrame(Device device, float elapsedTime)
        {
            /////create shadow map/////
            
            //store old render target
            Surface pOldRT = null;
            pOldRT = device.GetRenderTarget(0);

            //store old depth stencil surface
            Surface pOldDS;
            pOldDS = device.DepthStencilSurface;

            //set shadowmap target
            Surface tempSurface = shadowmap.GetSurfaceLevel(0);
            device.SetRenderTarget(0, tempSurface);
            device.DepthStencilSurface = ShadowStencil;

            /////render shadow map/////

            Matrix shadowProj = Matrix.PerspectiveFovLH(m_lcamera.FOV, 1, 0.01f, 100.0f);
            effect.SetValue("g_mProj", shadowProj);
            effect.SetValue("g_vLightPos", new Vector4(m_lcamera.Position.X, m_lcamera.Position.Y, m_lcamera.Position.Z,1.0f));
            effect.SetValue("g_vLightDir", new Vector4(device.Lights[0].Direction.X, device.Lights[0].Direction.Y, device.Lights[0].Direction.X, 1.0f));
            effect.Technique = "RenderShadow";
            
            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.SkyBlue, 1.0f, 0);
            device.BeginScene();

            Matrix tempMatrix = worldMatrix * m_lcamera.View;
            effect.SetValue("g_mWorldView", tempMatrix);

            effect.Begin(0);
            effect.BeginPass(0);
            
            m_mesh = m_temple[0].m_mesh;
            for (int i = 0; i < m_mesh.Materials.Length; i++)
            {
                // Set the material and texture for this subset.
                
                effect.SetValue("g_vMaterial", new Vector4(m_mesh.Materials.Diffuse.R,
                                               m_mesh.Materials.Diffuse.G,
                                               m_mesh.Materials.Diffuse.B,
                                               m_mesh.Materials.Diffuse.A));

                if (m_mesh.Textures != null)
                    effect.SetValue("g_txScene", m_mesh.Textures);

                effect.CommitChanges();
                m_mesh.SourceMesh.DrawSubset(i);
            }
            effect.EndPass();
            effect.End();

            device.EndScene();


            ///// pass2 - got the shadow map, so render scene /////

            //restore old surfaces
            device.DepthStencilSurface = pOldDS;
            pOldDS.Dispose();
            device.SetRenderTarget(0, pOldRT);
            pOldRT.Dispose();

            effect.SetValue("g_txShadow", shadowmap);

            // Compute the matrix to transform from view space to
            // light projection space.  This consists of
            // the inverse of view matrix * view matrix of light * light projection matrix
            viewMatrix = Matrix.Invert(m_camera.View);
            Matrix mViewToLightProj = viewMatrix * m_lcamera.View * m_lcamera.Projection;
            
            effect.SetValue("g_mViewToLightProj", mViewToLightProj);
            effect.SetValue("g_mProj", m_camera.Projection);
            effect.SetValue("g_vLightPos", new Vector4(m_lcamera.Position.X, m_lcamera.Position.Y, m_lcamera.Position.Z, 1.0f));
            effect.SetValue("g_vLightDir", new Vector4(device.Lights[0].Direction.X, device.Lights[0].Direction.Y,
                                                        device.Lights[0].Direction.Z, 1.0f));
            effect.Technique = "RenderScene";

            device.BeginScene();
            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.SkyBlue, 1.0f, 0);

            tempMatrix = worldMatrix * m_camera.View;
            effect.SetValue("g_mWorldView", tempMatrix);

            effect.Begin(0);
            effect.BeginPass(0);

            m_mesh = m_temple[0].m_mesh;
            for (int i = 0; i < m_mesh.Materials.Length; i++)
            {
                // Set the material and texture for this subset.

                effect.SetValue("g_vMaterial", new Vector4(m_mesh.Materials.Diffuse.R,
                                               m_mesh.Materials.Diffuse.G,
                                               m_mesh.Materials.Diffuse.B,
                                               m_mesh.Materials.Diffuse.A));

                if (m_mesh.Textures != null)
                    effect.SetValue("g_txScene", m_mesh.Textures);

                effect.CommitChanges();
                m_mesh.SourceMesh.DrawSubset(i);
            }
            effect.EndPass();
            effect.End();


            m_gui.Render(elapsedTime);

            // Display text
            m_textSprite.Begin(SpriteFlags.AlphaBlend | SpriteFlags.SortTexture);
            m_font.Print(m_textSprite, "FPS: " + m_framework.FPS.ToString("f2"), 5, 5, 0, 0, Color.Red.ToArgb(), Font.Alignment.Left);
            m_textSprite.End();

            device.EndScene();
            device.Present();
        }


In fact, if I completely remove the first render pass, it makes absolutely no difference. I've run out of ideas on this one, any suggestions as to what the hell is going on would be appreciated. N.

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!