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
- Fixing Message Loss in UMPE During Domain Reload
- The Editor freezes when ScheduleReadOnly of IJobParallelForTransform with dependency is used
- Text is truncated in the Inspector when the display scale is set to 150%
- CancellationTokenSource(<timeout>) has incorrect cancellation status when used in WebGL Player
- VFX property value names are cut off when properties with 'Arc' are viewed in the VFX Blackboard
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.