In a custom HLSL material, the view’s directional light can go black when switching directional lights. I’m not sure if this is by design, but it seems we can’t trust the shader parameter values `DirectionalLightDirection` and `DirectionalLightColor` in the view. We have only one active directional light at a time, one for the moon and one for the sun, but at some point when we swap them this bug kicks in and the materials that depend on those shader parameter values break. The rest of the lighting seems fine.
Is this a bug, or is it by design? If it’s by design, what should we use instead of `ResolvedView.DirectionalLightColor`?
Steps to Reproduce
In a custom HLSL material, the view’s directional light can go black when switching directional lights.
On a default project with the default settings, from Epic Games Launcher UE 5.8:
1. Create a Directional Light and set its color to blue.
2. Add a cube to the scene with an Unlit material with a custom HLSL node that returns `ResolvedView.DirectionalLightColor.rgb` (or `DirectionalLightDirection`), and plug it to the emissive.
3. Create another Directional Light and set its color to red. The cube stays blue, no matter the intensity of this 2nd directional light.
4. Hide the 1st Directional Light. The cube is now black. In `SceneRendering.cpp`, it sets both Direction and Color to black when `SimpleDirectionalLight` is null. Perhaps when there are 2 directional lights, the lighting is not “Simple”, that’s why I thought it could be by design. But isn’t it back to simple now that I’ve hidden one of the lights? Also, when there are 2 directional lights, these values seem to be set to the first light to be enabled, regardless of priority or intensity.
5. Hide the 2nd Directional Light. The whole scene goes black. Reenable the 2nd Directional light. Now the cube goes red.
6. Reenable the 1st Directional Light. The cube stays red.
7. Disable the 2nd Directional light. The cube goes black, the scene goes blue.
Thanks for reaching out about this issue. I was able to confirm that the resolved view is not properly picking the shader parameters and filed a ticket with the development team to fix it: https://issues.unrealengine.com/issue/UE\-399013\. Once the link is live, you should be able to see updates on the fix’s progress. If you have any further questions, please let me know.