Skip to content

sample: add additional lights in KageBall #732

Open
sindharta wants to merge 4 commits intomasterfrom
light-shadow-scene
Open

sample: add additional lights in KageBall #732
sindharta wants to merge 4 commits intomasterfrom
light-shadow-scene

Conversation

@sindharta
Copy link
Collaborator

No description provided.

@sindharta sindharta changed the title Light shadow scene [DONOTMERGEYET] Light shadow scene Feb 4, 2026
@sindharta sindharta changed the title [DONOTMERGEYET] Light shadow scene [NEEDCLEANUP] Light shadow scene Feb 25, 2026
@sindharta sindharta changed the title [NEEDCLEANUP] Light shadow scene [NEEDCLEANUP] shadow of additional lights Feb 25, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the URP toon shader’s shadow “tweak” computation to use a shared helper function, and adjusts the KageBall sample scene lighting by grouping lights under a new root and adding a shadow-casting point light.

Changes:

  • Add a TweakShadow(...) helper and replace duplicated _SystemShadowsLevel_var logic with calls to it.
  • Update additional-light shadow handling in the shading grade map path (Forward+ path updated; non-Forward+ path partially updated).
  • Update the KageBall sample scene hierarchy by adding a Lights root and adding a Point Light.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
com.unity.toonshader/Samples~/URP/Scenes/KageBall/KageBall.unity Adds a Lights parent object and a new point light in the sample scene.
com.unity.toonshader/Runtime/UniversalRP/Shaders/UniversalToonBodyShadingGradeMap.hlsl Refactors shadow tweak calculation to use TweakShadow (but leaves one additional-light path inconsistent).
com.unity.toonshader/Runtime/UniversalRP/Shaders/UniversalToonBodyDoubleShadeWithFeather.hlsl Refactors shadow tweak calculation to use TweakShadow consistently for main/additional lights.
com.unity.toonshader/Runtime/UniversalRP/Shaders/UniversalToonBody.hlsl Adds TweakShadow and updates additional light retrieval to use the 3-arg GetAdditionalLight overload.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

float lightIntensity = _LightIntensity;
float tweakShadows = 1.0 + _Tweak_SystemShadowsLevel;

float tweakShadows = additionalLight.shadowAttenuation;
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the non-Forward+ additional lights loop, tweakShadows is set to additionalLight.shadowAttenuation directly, while the Forward+ path (and main light) now uses TweakShadow(...). This makes shadow response differ depending on whether Forward+ is enabled. Use the same TweakShadow(additionalLight.shadowAttenuation) logic here as well (or intentionally keep raw attenuation in both paths).

Suggested change
float tweakShadows = additionalLight.shadowAttenuation;
float tweakShadows = TweakShadow(additionalLight.shadowAttenuation);

Copilot uses AI. Check for mistakes.
}

inline float TweakShadow(float shadow) {
return max((shadow * 0.5) + 0.5 + _Tweak_SystemShadowsLevel, 0.001);
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TweakShadow is replacing the previous inline _SystemShadowsLevel_var calculation, but it is not equivalent: the old logic clamped values <= 0.001 down to 0.0001, while max(..., 0.001) clamps them up to 0.001. If the goal is a refactor without changing visual output, update TweakShadow to preserve the prior threshold/floor behavior (or document that the minimum shadow tweak has changed).

Suggested change
return max((shadow * 0.5) + 0.5 + _Tweak_SystemShadowsLevel, 0.001);
float tweakedShadow = (shadow * 0.5) + 0.5 + _Tweak_SystemShadowsLevel;
return (tweakedShadow <= 0.001) ? 0.0001 : tweakedShadow;

Copilot uses AI. Check for mistakes.
// index to a perObjectLightIndex
UtsLight GetAdditionalUtsLight(uint i, float3 positionWS) {
Light light = GetAdditionalLight(i, positionWS);
const float shadowMask = 1;
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shadowMask is introduced to call the 3-arg GetAdditionalLight overload, but it’s declared as a scalar float. URP’s API commonly expects a half4 shadow mask (from baked GI / shadowmask mixing), and using a scalar here relies on implicit splat conversion and makes it harder to later thread through a real shadow mask. Consider changing this to a half4 (e.g., all-ones) and/or plumbing the actual shadow mask from InputData where available.

Suggested change
const float shadowMask = 1;
const half4 shadowMask = half4(1.0h, 1.0h, 1.0h, 1.0h);

Copilot uses AI. Check for mistakes.
@sindharta sindharta force-pushed the light-shadow-scene branch from 9ec683d to 969305f Compare March 2, 2026 14:14
@sindharta sindharta changed the title [NEEDCLEANUP] shadow of additional lights shadow of additional lights Mar 2, 2026
@sindharta sindharta changed the title shadow of additional lights sample: add additional lights in KageBall Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants