Megalights and First Person Self Shadow - not compatible?

We’re currently upgrading to Unreal 5.6, and we’re looking at the new First Person Self Shadowing feature. From our tests and a look at the code, it seems that this is not available when using Megalights lighting.

Is this a bug, or an expected limitation? If it’s a limitation, is support for this feature under Megalights planned?

Thanks!

Steps to Reproduce
Set up a scene using First Person Rendering. Enable both Megalights and FP Self Shadow. Observe that FP self shadowing is not enabled while Megalights is enabled.

Hi James,

Thanks for reaching out about this. From what I know, the FP Self Shadowing feature should be disabled when Megalights is enabled, as you might have seen from your code analysis. However, Megalights should be providing some form of shadowing at that time, so you are not receiving any shadowing. Could you send us a repro project so we can look into this issue more in-depth?

Cheers,

Tim

Hi James,

Thanks for the update. Just for my own clarification, with the Cvar change, are you now able to use FP Self Shadowing while using Megalights? I also found out that although Megalights and FP Self Shadowing should work in tandem, we have not done too much testing yet, as we are still trying to get Megalights into full production readiness. Having to make some changes to the default settings would confirm that. I will also consider your request and file a Jira with the developer to see if it’s possible.

Cheers,

Tim

Hi James,

Let me check with the team to see how they want to handle this. They are a bit preoccupied with some other projects at the moment, so I leave it up to their discretion to discuss your proposed changes. Do you already have some code available on your end that you would be willing to share?

Cheers,

Tim

Hi James,

Thanks for the suggestion. I have relayed the information, and I hope that the devs will take it into account. Please let me know if you have any further suggestions; otherwise, I will consider this case closed for now.

If you can share the code publicly, you can make a pull request via GitHub. That is the most straightforward way to integrate the changes into our codebase. Would that be an acceptable solution?

Ok, sounds good! Looking forward to that PR then

For reference if anyone else is looking at this, integrating CL 43423143 (https://github.com/EpicGames/UnrealEngine/commit/9a3affeb767d1d94c26198634616499a461bf5e2\) gives more control over the screen trace thickness for meshes not in the RT scene - not quite the same as specifically First Person meshes, but can solve some of the same problems.

Thanks for pointing that out, CL, James. I was not aware that we already have this capability in the engine

Hi Tim,

I’ve actually been taking a look at that, in case we needed another solution if FPSS wasn’t available. Megalights is already doing a screen space HZB trace, so I was curious why we weren’t seeing correct shadowing on player hand and weapons (when we did see the improvements with FPSS, if Megalights was disabled).

It looks like it mostly comes down to the default value of `r.MegaLights.ScreenTraces.RelativeDepthThickness`, vs `r.FirstPerson.SelfShadow.RelativeDepthThickness`. This is passed into the TraceHZB in the shader in both cases, but for FPSS is set to 0.2 vs the 0.005 for Megalights. Turning that parameter up to ~0.1 gave us effective self shadowing on the hands under Megalights, but obviously has impact elsewhere in the scene with potentially more shadow artefacts. This might be an acceptable solution for us, but we’ll need to evaluate the impact on the rest of the game’s lighting in more detail.

If I could suggest a feature, it might be a good idea to provide the option for a separate `RelativeDepthThickness` value in Megalights that is only used for pixels rendered with First Person rendering (and select between the two based on the First Person Rendering bit in the G buffer). That would let us get the more pronounced screen space shadowing that we want on the player hands, without introducing more artefacts elsewhere in the frame.

Thanks!

James

Hi Tim,

No, FP Self Shadowing still does not work with Megalights - but I am able to achieve a similar effect within Megalights with that CVar. (FP Self Shadowing is fundamentally a HZB screen trace towards the light source, which is already done as part of Megalights’ screen space pass, just with different configuration.) The downside is that it affects all pixels in the frame, not just the FP rendered ones, and ideally I would isolate the change to the FP meshes.

Providing a mechanism to tune the HZB trace parameters for FP pixels within megalights, without using the full separate FPSS system, would actually be much better than enabling FPSS with Megalights. It avoids executing costly HZB traces twice, and better fit within the existing Megalights sampling framework (with spatial and temporal denoisers etc). I’d be happy to discuss with the relevant developer if that would be helpful! (Apologies for the lack of screenshots on this one, we didn’t want to use up one of our Confidential tickets.)

Thanks,

James

Hi Tim,

Sorry for the slow reply! No, we don’t have any internal code changes yet. I’ve taken an initial look at the feasibility, and it seems like the main tricky part would be finding a bit to use in the packed data structure in PackLightSampleRay - given we’re already sampling the GBuffer in GenerateLightSamplesCS , it would be ideal to test for the IS_FIRST_PERSON_MASK bit there, and then pass that through in the packed data to the rest of the Megalights shaders (in this case, ScreenSpaceRayTraceLightSamplesCS).

Cheers,

James

Okay, fair enough! If we do make the shader modifications ourselves, what’s the best way to share that change with yourselves? (I would open a Confidential ticket, but I don’t want to use up our limited budget…)

That should be okay- if we make the modification I’ll try to submit a pull request. Thanks!