Download

Control the Shadow Color with Deferred Shading

Update:

Original:

I want to make a shading model that has full control over the shadow color of a material, similar to this project: https://forums.unrealengine.com/deve…-shading-model
This project uses Forward Shading but I want to recreate this in Deferred Shading.

I started experimenting with the code of a similar project (https://forums.unrealengine.com/deve…ng-experiments) that uses deferred shading, but I couldn’t figure out how to make it so the shadow color isn’t affected at all by the base color.
The files I tried editing are ShadingModels.ush, BasePassPixelShader.usf, DeferredLightingCommon.ush

Does anyone know how to do this?

Hey, author of that shading model here. I’ve tried to figure out how to do that too, and as far as I can tell putting together the shadow output of DeferredLightingCommon is done somewhere on the C++ side, but I just could not figure out where.

Try starting by looking at LightRendering.cpp and ShadowRendering.cpp.

Thanks for the help. SetBlendStateForProjection in ShadowRendering.cpp might have something to do with this.

I tried going over the HLSL files again and found this line in BasePassPixelShader.usf:


DiffuseColor += (DiffuseIndirectLighting * DiffuseColorForIndirect + SubsurfaceIndirectLighting * SubsurfaceColor) * AOMultiBounce( GBuffer.BaseColor, DiffOcclusion );

Removing it allowed me to change the shadow color and the base color separately (with a few modifications to ToonBxDF and DeferredLightingCommon.cpp):

Original Shader: https://forums.unrealengine.com/deve…ng-experiments
My Version:

Since doomfest’s shading model doesn’t fit my project, I’ll start making my own one from scratch. Once I finish it, I’ll upload the code to GitHub and send the link.

It’s pretty straight forward to do it with one light in deferred, but you’re going to run into shades inbetween because of the additive blending affecting areas that are shadowed by one light but not others, but if that’s what you want then you’re all set :>

Looks like I’ll need to revive this thread. I almost finished making a new shading model from scratch, but I still can’t figure out how to separate the shadow color. Just like you said, my solution only works with 1 light, but I want to make it work with multiple lights too. This is what I’ve got so far:

  • In BasePassPixelShader, I output the material’s shadow color
  • In DeferredLightPixelShader, I output the light’s color mixed with the base color

I somehow need to figure out how to blend the two shaders in a way that will only display the output from BasePassPixelShader in places without any light.
I found a function called FDeferredShadingSceneRenderer::RenderLight which has a TStaticBlendState that controls how a light merges with other lights (that’s what I understood from experimenting with it), but I still couldn’t find the code that merges BasePassPixelShader with the final output of all of the lights.

Does anyone have any ideas on how to do this or on where the blend code is?