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
- “[Worker0] Could not generate preview image“ error when opening macOS native plugin in the Inspector with Architecture to build for set to ARM 64-bit
- [iOS] Application.absoluteURL is empty on Awake/Start when opening via deep link with Splash Screen disabled
- Crash on MemoryManager::Deallocate when rapidly calling Addressables.LoadAssetAsync
- Crash on physx::shdfnd::atomicIncrement when adjusting values on a character controller component after entering Play mode in Prefab edit mode
- [Rendering Debugger] [NewInputSystem] Debug Overlays in Play mode throws InvalidOperationException when using New Input System
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.