Deferred Lightning

Developer
Jun 17, 2012 at 1:05 AM
Edited Jun 17, 2012 at 1:08 AM

So when I render deferred lightning, do I need to have one DeferredEffect and one GraphicsBuffer for each object?

I am trying to use a skinned model, but it dont looks to apply the light to the model.

I dont know much about lightning but would like to know more.

Coordinator
Jun 17, 2012 at 2:32 AM

You just need a single global GraphicsBuffer, and a DeferredEffect for each object that uses deferred lighting.

Are you able to apply deferred lighting to a static model in the first place?

Developer
Jun 17, 2012 at 11:37 AM

Yes, I am able to apply to a DrawableSurface.

 

But I dont know how to put it all together , now I just get the error:

"The current vertex declaration does not include all the elements required by the current vertex shader. BlendWeight0 is missing."

 

graphicsBuffer.Begin();
            {
                DrawTerrain(graphicsBuffer.Effect);
            }
            {
                modelBatch.Begin(View, Proj);
                modelBatch.DrawSkinned(Model,
                    Matrix.CreateScale(0.05f) *
                    PlayerMatrix, skeleton.GetSkinTransforms(), graphicsBuffer.Effect);
                modelBatch.End();
            }
            graphicsBuffer.End();
            graphicsBuffer.DrawLights(View, Proj, lights);

            GraphicsDevice.Clear(Color.Black);

            deferredEffect2.LightTexture = graphicsBuffer.LightBuffer;
            modelBatch.Begin(View, Proj);
            BoneAnimation animation = (BoneAnimation)(animations.Current);
            modelBatch.DrawSkinned(Model,
                Matrix.CreateScale(0.05f) *
                PlayerMatrix, skeleton.GetSkinTransforms(), deferredEffect2);
            modelBatch.End();

            deferredEffect.LightTexture = graphicsBuffer.LightBuffer;
            DrawTerrain(deferredEffect);

private void DrawTerrain(Effect effect)
        {
            BoundingFrustum frustum = new BoundingFrustum(TopDownCamera.View * TopDownCamera.Projection);

            foreach (var patch in terrain.Patches)
            {
                if (frustum.Contains(patch.BoundingBox) != ContainmentType.Disjoint)
                {
                    IEffectMatrices matrices = effect as IEffectMatrices;
                    if (matrices != null)
                    {
                        matrices.World = patch.Transform;
                        matrices.View = TopDownCamera.View;
                        matrices.Projection = TopDownCamera.Projection;
                    }
                    patch.Draw(effect);
                }
            }
        }

Coordinator
Jun 17, 2012 at 12:05 PM

The error indicates that your model is not a skinned model, try draw the model using ModelBatch.Draw instead of DrawSkinned.
Developer
Jun 17, 2012 at 2:04 PM
Edited Jun 17, 2012 at 4:24 PM

Now when I look at the model it looks like there is a little bit light applied to the model but not much. But on the terrain it it allot. 

 

EDIT:

Nope, there is no light it is my screen making a blend.

 

EDIT:

LightBuffer:

http://img641.imageshack.us/img641/7562/lightbuffer.png

 

 

graphicsBuffer.Begin();
            {
                DrawTerrain(graphicsBuffer.Effect);

                modelBatch.Begin(View, Proj);
                modelBatch.Draw(Model, PlayerMatrix, graphicsBuffer.Effect);
                modelBatch.End();

            }
            graphicsBuffer.End();
            graphicsBuffer.DrawLights(View, Proj, lights);

            GraphicsDevice.Clear(Color.Black);

            deferredEffect.LightTexture = graphicsBuffer.LightBuffer;
            DrawTerrain(deferredEffect);

            deferredEffect2.LightTexture = graphicsBuffer.LightBuffer;
            modelBatch.Begin(View, Proj);
            modelBatch.Draw(Model, PlayerMatrix, deferredEffect2);
            modelBatch.End();

 

EDIT:

So I just imported a UV Wrapped Box and rendered it instead:

http://img803.imageshack.us/img803/7562/lightbuffer.png

Developer
Jun 17, 2012 at 4:24 PM
Edited Jun 17, 2012 at 4:42 PM

 

http://img713.imageshack.us/img713/7562/lightbuffer.png

Looks like the light don't like to be on the sides/edges of the model. This can be the issue :P

 

http://imageshack.us/photo/my-images/6/normalhh.png/

http://imageshack.us/photo/my-images/703/lightbuffer.png/

HD: http://img703.imageshack.us/img703/7562/lightbuffer.png