I have a deferred rendering system that works well with objects that appear solid and drawn using CounterClockwise culling.

I have a problem with Clockwise culled objects that are supposed to represent hollow that display their inside faces only.

The image below shows a CounterClockwise culled object (left) Clockwise culled object (right).

Deferred Rendering CullMode http://rhysperkins.com/XNA/CullModeDeferred.png

The Clockwise culled object faces display what would be displayed on the CounterClockwise face. How can I get the lighting to light the inner faces for Clockwise culled objects and continue lighting the outer CounterClockwise faces as normal?

My lighting method is below

    private void DeferredLighting(GameTime gameTime)
        // Set the render target for the lights

        // Clear the render target to (0, 0, 0, 0)

        // Set the render states
        game.GraphicsDevice.BlendState = BlendState.Additive;
        game.GraphicsDevice.DepthStencilState = DepthStencilState.None;
        game.GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;

        // Set sampler state to Point as the Surface type requires it in XNA 4.0
        game.GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;

        // Set the camera properties for all lights

        // Draw the lights
        int numLights = lights.Count;

        for (int i = 0; i < numLights; ++i)
            if (lights[i].Diffuse.W > 0f)
                lights[i].Render(gameTime, ref normalMap, ref depthMap, ref sgrMap);

        // Resolve the render target

I have tried adjusting the render states but no combination works for both objects.


My guess is that when you draw the inside-out objects into your G-buffer, you have to reverse the normal vectors. If you don't do this, it will have the effect of making the faces look like they're lit from behind. You can do this using the VFACE semantic in the pixel shader (see MSDN); it will be +1.0 for front-facing and -1.0 for back-facing primitives, so multiplying your normal by it should have the desired effect.

  • \$\begingroup\$ Excellent, thank you. I would vote this up if I could. I'll try and implement this tomorrow and see if there are any further problems but it sounds like this will solve the original one. :) \$\endgroup\$ Jul 10 '12 at 0:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .