# Deferred rendering with both Clockwise and CounterClockwise culling

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
game.GraphicsDevice.SetRenderTarget(lightMap);

// Clear the render target to (0, 0, 0, 0)
game.GraphicsDevice.Clear(Color.Transparent);

// Set the render states
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
BaseLight.SetCameraProperties(game.ActiveCamera);

// 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
game.GraphicsDevice.SetRenderTarget(null);
}


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.