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
- [Android][iOS] The keyboard closes and re-opens when consecutive input fields are selected
- Complex Sub Graph connected to a Voronoi node is ignored when the shader gets applied as a Material
- Compute Shader property not set error when entering play mode with path tracing and PBR sky
- "WebGL Publish" detects WebGL module and allows building when it is installed without restarting the project
- Editor is non-responsive and flickers when multiple Water System instances are enabled
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.