I am currently implementing a deferred renderer in DX11.1. Right now I am having a problem that I can't seem to crack with specular highlights when I have multiple light sources.

I keep a vector of lights for each scene and the last light rendered has proper spec, but all lights before it are "bad". I think the problem is caused by an improper blend state setting, but I'm not sure. Currently my blend state when rendering lights is

blendDesc.RenderTarget[0].SrcBlend       = D3D11_BLEND_ONE;
blendDesc.RenderTarget[0].DestBlend      = D3D11_BLEND_INV_SRC_ALPHA;
blendDesc.RenderTarget[0].SrcBlendAlpha  = D3D11_BLEND_ONE;
blendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;

blendDesc.RenderTarget[0].BlendOp = blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;

blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;

In my G buffer generation I write specular to the G buffer's color map's alpha channel. In hlsl...

output.color.a = _specEm.Sample(linearClamp, input.texcoord).a;

Then in the light accumulator

float4 diffuse = _diffuse.Sample(pointClamp, input.texcoord);

// Lighting calculations for diffuse and normal, all good
// ...

float speci = diffuse.a;
float specularLight = speci * pow(saturate(dot(reflectionVector, directionToCamera)), specp);

return float4(diffuseLight.rgb, specularLight);

In this scene there are two lights, the first image shows the specular highlight created by the second light rendered

enter image description here

The second image is of the first light rendered in this scene where you can see the spec "badness" (a dim highlight with a darker spot in the middle), in it you can also see the position of the other light

enter image description here

Never mind the light on the boxes, they aren't fully interacting with light at the moment.

Its worth noting that more lights in the scene will have the same effect, all will have the "bad" spec and the last one will have the "good" spec.

I suspect that I am missing something fundamental about how blend states work and losing some of the color that I am writing into the alpha channel, but if anyone out there can see the problem and suggest a fix, I would appreciate it.

  • 1
    \$\begingroup\$ Usually when accumulating light values you want to us additive blending - i.e. D3D11_BLEND_ONE for source and destination factors. \$\endgroup\$ – GuyRT Jul 28 '14 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.