Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

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.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
        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.

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
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. :) –  user1423893 Jul 10 '12 at 0:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.