Search Issue Tracker
By Design
Votes
1
Found in
2022.3.61f1
6000.0.46f1
6000.1.0b15
6000.2.0a9
Issue ID
UUM-102985
Regression
No
GetMainLight() returns incorrect distanceAttenuation value for a Custom Shader when URP Forward+ Rendering Path is used
Reproduction steps:
1. Open the attached “IN-99023.zip” project
2. Open the “SampleScene”
3. Enter Play mode
4. Observe the Sprite in the Game view
Expected result: The Sprite is rendered lit/white (like with “Forward” rendering path)
Actual result: The Sprite is rendered gray/unlit
Reproducible with: 2022.2.0b16, 2022.3.61f1, 6000.0.46f1, 6000.1.0b15, 6000.2.0a9
Reproduced on: Windows 11
Not reproducible on: No other environment tested
Workarounds:
- Using the standard "Forward" Rendering Path
- Toggling Forward+ -> Forward -> Forward+ in the Editor (fixes it only for that Editor session and does not fix builds)
Notes:
- Debugging via visualizing intermediate shader values confirmed that vertex shader outputs (world position, Y-locked normals/tangents) and fragment shader inputs (final calculated world normal, albedo) appear numerically valid during the failure state
- A simplified fragment shader calculating only the main light contribution (Albedo * LightColor * NdotL * ShadowAtten * DistAtten) also rendered black during the failure state
- Disabling GPU Instancing on the material did not resolve the issue.
- Using standard world position for shadow coordinates did not resolve the issue
- Forcing mainLight.distanceAttenuation = 1.0 in the simplified fragment shader allowed the object to render correctly (with main light only) during the failure state
- The root cause appears to be an incorrect distanceAttenuation value (0 instead of 1 for a directional light) returned by GetMainLight(), specifically during the initial startup/build phase when the Forward+ rendering path is active by default. This faulty value prevents correct lighting calculations downstream, including within UniversalFragmentPBR
- Also reproducible in the Player
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
- Freeze/Crash with multiple StackTraces when opening a specific project
- CaptureScreenshotAsTexture fails when VR headset is connected and is inactive during Play Mode
- "NullReferenceException" thrown and scene corrupted when build is canceled with changes in the scene
- [Android] The calculation results differ on some devices when the code uses half-precision variables and/or has an if statement with branching
- "Maximum Shadows on Screen" can be set to a negative number
Resolution Note:
Hello.
Please verify that you are using the correct keyword for Forward+, it looks like in your shader that you might be using a deprecated keyword '_CLUSTERED_RENDERING'.
You should take a look at the URP Lit shader's keywords for reference, as the correct keyword for Forward+ variant may have changed from a previous version of Unity.