Lighting messed up in UE 4.11.2 when setting "SelectiveBasePassOutputs"

Objects that are fully in shadow seem to no shadow when SelectiveBasePassOutputs is on:

I have a static skylight and a stationary directional light.

Here’s what it looks like with the new SelectiveBasePassOutputs option turned on (Project Settings: Rendering: Optimizations: Selectively output to the GBuffer rendertargets):

And here it is with the option off:

It looks like any object that is fully shadowed ends up not shadowed at all.

I was searching the code for SelectiveBasePassOutputs and a lot of it seems to do checks around is it enabled or is the object using fully static lighting. Based on this I think there must be a bug in one of the checks. These objects being fully in shadow might be considered fully static.

Hey muchcharles,

Would you happen to be able to reproduce this issue in a blank project using some simple steps and assets?

Also, is the object in question set as a ‘Static’ or ‘Movable’ object?

I am not too familiar with this setting, so I am going to need to read up on its functionality in order to understand the bug in question.

Thank you,

I’m going to try and reproduce in a simpler project; thing to note in the image above is the tower is composed of two pieces, the part at the top that is partially in shadow is fine, the lower part that is fully in shadow is glitched.

Ok, I was able to reproduce with a very simple project. Create a new project, check "Selectively output to the GBuffer rendertargets in edit:project settings: rendering: optimizations. You’ll need to relaunch to recompile shaders at that point. Then add a cube and stretch it out so it casts a big shadow. Put a smaller cube completely within the shadow. Rebuild lighting. The smaller cube will be getting light instead of being in shadow.

Here’s a picture:

(and if you then scale the smaller cube up so that it is only partially shadowed, and rebuild lighting, it will again get the appropriate shadowing)

Hey muchcharles,

I had to gather some more information on what the setting does in order to determine if what you were seeing or not was in fact a bug. So what you are seeing is definitely a bug, but the engineers believe the issue to be fixed after modifying a typo within the code for this setting. This fix should be integrated into an upcoming full engine release, preview, or hotfix but has not been marked for a specific version as of yet.

In regards to your question on the forums as to what this setting does, I was able to gather that information as well. This feature is an optimization to save bandwidth when reading and writing the gbuffer.
The implementation uses some GBufferB.a bits as flags to encode predefined values for other rendertargets.

For instance, if the base passpixelshader is guarantied to not output any precomputed shadow factors,
instead of exporting (0,0,0,0) to GBufferE , it does not export to it (saving bandwith) and rather sets the flag ZERO_PRECSHADOW_MASK

BasePassPixelShader.usf

if WRITES_PRECSHADOWFACTOR_TO_ZERO

if WRITES_PRECSHADOWFACTOR_ZERO

which was the typo.

That bug prevented to set the zero mask to shadow factors. That would explain why some primitives that should be fully shadowed end up not shadowed at all.

Let me know if you have further questions or need additional assistance.

Thank you,