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

Metal

-

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

  1. 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.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.