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
- Crash on mecanim::SetValueWeight when switching the AnimationMixerPlayable connection with Animator's UpdateMode set to "Animate Physics"
- The "StringComparer.InvariantCultureIgnoreCase.GetHashCode()" returns different Hash Codes for the same word with the only difference being case sensitivity in WebGL
- 2D Light Textures show the lights of any 'blend style' index higher than theirs (if present) when they aren't visible by the Camera using Render Graph
- [SpeedTree] Wireframe mode not rendering correctly ST assets
- Light2D affecting only the Default Sorting Layer will also affect any Custom Lit Sprite not on that Layer when using Render Graph
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.