Search Issue Tracker
By Design
Votes
0
Found in
2019.4
2020.3
2020.3.30f1
2021.3
2022.1
2022.2
Issue ID
1418247
Regression
No
UnityWorldSpaceLightDir does not work when the Directional Light has a Cookie assigned
How to reproduce:
1. Open the user's attached project
2. Open scene Scenes/SampleScene
3. Observe the Directional Light and the Cube in the Scene view
4. Rotate the Directional Light
Expected result: the Cube shows changing colors when the Directional Light is rotated
Actual result: the Cube is entirely black
Reproducible with: 2019.4.38f1, 2020.3.34f1, 2021.3.1f1, 2022.1.0f1, 2022.2.0a11
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Articulation Body with 'Revolute' Joint Type has erratic behavior when Upper Limit is set to above 360
- WebGL Player fails to render Scene when Terrain with Detail Mesh is added and WebGPU Graphics API is used
- Inconsistent errors are logged when different types are passed into the Query "Q<>" method in UIToolkit and the ancestor VisualElement is null
- Crash on GetMaterialPropertyByIndex when opening a specific Scene
- Discrepancies in the styling are present when using a TSS file instead of a USS file in custom EditorWindow
Resolution Note (2022.2.X):
There's two independent issues here:
- The shader declares "noforwardadd ". Lights with cookies are not run through the regular forward pass, but instead through the forward add pass. In this case there is no main light and hence "_MainLightPosition" is zero.
- The shader always normalizes the result of UnityWorldSpaceLightDir. Since there is no main light, the result is zero and a normalization of a zero vector produces invalid values (nan) that corrupt the rest of the values.
If you inspect the generated code from surface shaders, it emits something akin to:
#ifndef USING_DIRECTIONAL_LIGHT
fixed3 lightDir = normalize(UnityWorldSpaceLightDir(worldPos));
#else
fixed3 lightDir = _WorldSpaceLightPos0.xyz;
#endif
so it doesn't normalize when there is no main light.