Sign in to follow this  

Deferred Lighting problem

Recommended Posts

Hello, I'm attempting a deferred renderer and at the moment I'm trying to figure out multiple lights.

I render each light into it's own buffer, these are shown in dx1.png and dx2.png ( both different lights ). The lighting shader only does the diffuse and specular shading, no ambient light is calculated.

I then add the buffers together in a full screen quad as shown in dx3.png. What have I done wrong? How come the result is such a bright image?

float4 outputcolour = float4(0,0,0,0);
float4 L1 = Light1.Sample(linearSampler, input.t).xyzw;
float4 L2 = Light2.Sample(linearSampler, input.t).xyzw;
outputcolour = L1 + L2;

This is the HLSL code I use to add the buffers together.

I apologise in advance if it is blatantly obvious and I'm missing something simple!


Share this post

Link to post
Share on other sites
While it may not be the only contributing issue, you should read up on gamma correct lighting (aka linear light blending). In most multipass additive lighting solutions it is the cause of overbrightening.

Here are some links to kick start you:

Share this post

Link to post
Share on other sites
As wanderingbort has already mentioned, you forgot to calculate your lighting in linear space. sRGB basically is a non-linear space that is used to save colors efficiently, especially when they are just using 8 bit's per color channel. Otherwise banding artifacts might occur. You could convert them into linear space by applying pow(x, 2.2). But it's better to configure your samplers and the rasterizer.
Also don't forget that you have to convert the resulting lighting back into gamma space (with e.g. pow(x, 1/2.2)).

John Hable's blog also contains important information about that topic:
[url=""]Filmic Games[/url]

But that's not the problem. It won't get any darker. The thing is that it's HDR. It basically features colors that are brighter than what your screen is able to display. Now it's time to implement a tone mapper.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this