Search Issue Tracker
By Design
Votes
0
Found in
2019.4
2020.3
2020.3.18f1
2021.1
2021.2
2022.1
Issue ID
1370308
Regression
No
Custom Shader not rendered correctly when no opaque objects are in the scene
How to reproduce:
1. Open the "UnityShaderBug.zip" project
2. Go to File>Build Settings
3. Choose iOS and build
4. Open the built project in the Xcode and build to the iPhone
5. Observe that GameObjects are not visible
6. Go back to the Unity
7. In the Hierarchy window select "OpaqueCube" and enable it
8. Build for iOS
9. Open the built project in the Xcode and build to the iPhone
10. Now GameObjects are visible
Expected results: GameObjects are visible after build
Actual results: GameObjects are not visible when no opaque objects are in the scene
Reproducible with: 2019.4.30f1, 2020.3.18f1, 2021.1.22f1, 2021.2.0b13, 2022.1.0a10
Tested with: iPhone 12, 14.1
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
- "Shader warning in 'Hidden/Light2D': implicit truncation of vector type" is thrown when building Universal 2D template
- AI Assistant breaks compilation of packages using System.Runtime.CompilerServices.Unsafe via auto-referencing
- Unity Hub checks the "Documentation" module by default on the 6.4 and 6.5 streams despite that it was unchecked with the previous installs
- Shortcut that toggles between Dopesheet and Curves Views in the Animation Window's Timeline is mislabed
- Property List Items Overlap onto the Property List's top edge when scrolling through a long Property List
Resolution Note:
The problem why custom shader didn't work correctly was because of missing proper Pass Tags to indicate that shader does lighting.
Since Pass Tags weren't defined in shader, the default is "Always" pass tag which doesn't apply any lighting.
Therefore the result of the lighting calculations was that objects were invisible as _WorldSpaceLightPos0 had value of (0.f, 0.f, 0.f, 0.f).
Adding Pass Tag "LightMode" = "ForwardBase" as denoted by https://docs.unity3d.com/Manual/SL-UnityShaderVariables.html fixes the problem with zeroed _WorldSpaceLightPos0 constant value and shader works as expected.