Render SSAO on top of emissive materials

I’ve noticed that SSAO does not apply on top of emissive materials, which is realistic, but I need to change that for getting the look I want to get in my game.

I’ve searched in the engine to see where I could change that behavior:

In *GetDynamicLighting *in DeferredLightingCommon.usf the SSAO is applied to the lighting. The output of a material is calculated in *FPixelShaderInOut_MainPS *in BasePassPixelShader.usf, and if I understand it correctly the lighting is calculated first, and then based on that the material pixel shader runs. Then its just doing Color += Emissive to add the emissive color to the color of that pixel.

So no matter what the result of the lighting was, it adds the emissive value to the color of that pixel. If SSAO made the pixel black before, the value is offset by the emissive color and its no longer black. As far as I understand it, in FPixelShaderInOut_MainPS() I can no longer access the screen space data, so I can’t just multiply the emissive by the SSAO there, which would fix my problem. I basically just need to do *Emissive = ScreenSpaceData.AmbientOcclusion somewhere to get what I want, but I don’t know where that would be possible.

I don’t want to change anything else, so regular shadows should still not affect the emissive material, only SSAO should be added on top of that.

Any ideas how this could be done? :slight_smile:

What is the use case that you need AO on emissive? It might be easier to do a work around in the material instead of changing engine code.

I have already modified the engine to also show SSAO in directly lit areas, so I want to have a constant look in the game. SSAO should be everywhere, and the only thing where it is not are emissive materials at the moment, so that looks wrong. Its just about the look I want the game to have :slight_smile:

Any ideas?

Still haven’t found a way to do this… Would this be easier to do when using the forward renderer?

Try making a post process material like this:

Plug it into blendables area of your post process volume, should work. (Make sure you actually have SSAO enabled)

Thanks, but doing it in a PP material won’t work due to the PP material being rendered on top of things like fog, also a PP material is quite expensive and I don’t want to have that extra cost.

I need a solution just based on editing the shader files :slight_smile: