fix: separate Toon shadow attenuation - #62
Conversation
- Add fixed-host and runtime contracts for independent Toon shadow visibility. - Validate expected RED product behavior and GREEN non-Toon/light-kind controls.
- Separate BIRP non-shadow attenuation from Toon phase visibility. - Validate focused lighting, Cookie, and shader variant contracts.
- Document the split between Toon non-shadow attenuation and Unity visibility. - Validate focused lighting and static-lightmap compatibility checks.
- Render mode readbacks in a dedicated preview scene and culling mask. - Verify Cutout and Transparent numeric contracts with active-scene contamination.
- Run the canonical pixel baseline only in a clean batch scene lifecycle and preserve interactive Editor state. - Require explicit passed NUnit evidence for the strict baseline testcase and verify focused Unity and runner checks. Co-authored-by: Copilot <copilot@github.com>
Up to standards ✅🟢 Issues
|
| Category | Results |
|---|---|
| Complexity | 1 minor |
🟢 Metrics 141 complexity · 4 duplication
Metric Results Complexity 141 Duplication 4
AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ddea233949
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull Request Overview
This PR successfully separates direct-light color attenuation from Unity shadow visibility for the Toon shader model, fulfilling the intent of allowing independent control over lighting and shadowing. All required test scenarios for numerical correctness and contract preservation (PBR, Hybrid, and Unlit) have been found in the implementation.
However, the PR is currently 'not up to standards' according to Codacy, primarily due to the introduction of 30 new quality issues and a substantial increase in complexity within the test suites. Specifically, PureBaseToonLightingContractTests.Runtime.cs has seen a complexity delta of 70, with several methods exceeding length and parameter count thresholds. These maintainability issues should be addressed to ensure the new diagnostic and regression tests remain manageable.
About this PR
- The test infrastructure introduced in this PR, while functional, has resulted in high complexity scores and file bloat. Systemic patterns of overly long methods and high parameter counts suggest that the test utility logic should be decoupled from the test definitions.
2 comments outside of the diff
Tests/Daily/Editor/PureBaseToonLightingContractTests.Runtime.cs
line 1🔴 HIGH RISK
PureBaseToonLightingContractTests.Runtime.cs has exceeded 1000 lines. Since this is already a partial class, consider refactoring it by moving the nested 'ToonLightingCaptureRuntimeScope', 'LightVariantRequest', or 'ShadowReceiverObservation' into separate files to improve modularity and maintainability.
Tests/Regeneration/Editor/PureBaseValidationLightingSettingsGenerator.cs
line 611🔴 HIGH RISK
The Validate method is too long and complex. Decompose this method by extracting the validation logic for the root camera (LegacyBaselineCameraName), baked directional lights, and static renderers into dedicated private validation methods.
Test suggestions
- Verify numerical separation logic for Toon shadow attenuation
- Verify Point and Spot non-shadow attenuation affects radiance and aggregate direction weighting
- Regression test for shadow visibility publishing in None, Hard, and Soft shadow modes
- Verification of PBR/Hybrid retention of full attenuation visibility
- Verification of Unlit shadow-invariance contract
- Deterministic readback isolation test using preview scenes
- Verification of directional and cubemap cookie attenuation support
TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback
There was a problem hiding this comment.
Pull request overview
This PR updates the BIRP host/light plumbing so Toon can expose Unity’s effective shadow visibility separately from non-shadow attenuation (distance/cone/cookie), while keeping PBR/Hybrid/Unlit contracts intact. It also adds a dedicated ToonShadow Shader-Core test host plus targeted regression coverage, and tightens Daily/batch validation determinism.
Changes:
- Split main-light attenuation into non-shadow attenuation + effective visibility, publishing visibility via
sd.shadowfor Toon while preserving full attenuation for PBR/Hybrid and neutral behavior for Unlit. - Add a fixed ToonShadow Shader-Core host fixture and new Daily tests covering lighting/shadows/rendering-mode isolation and deterministic baseline evidence.
- Strengthen regression runner validation to require strict canonical baseline testcase presence and pass status in NUnit evidence.
Reviewed changes
Copilot reviewed 27 out of 35 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/Run-PureBaseRegression.ps1 | Enforces presence/pass result for the strict canonical baseline testcase in NUnit evidence and extends smoke validation. |
| Tests/Regeneration/Editor/PureBaseValidationLightingSettingsGenerator.cs | Tightens canonical scene validation (baseline camera contract) and factors fixture camera naming. |
| Tests/Fixtures/Hosts/ToonShadow.meta | Adds Unity folder metadata for the new ToonShadow host fixture. |
| Tests/Fixtures/Hosts/ToonShadow/sc_common.hlsl | Host-local include that routes Shader-Core common include through Toon model setup. |
| Tests/Fixtures/Hosts/ToonShadow/sc_common.hlsl.meta | Unity importer metadata for the ToonShadow host include. |
| Tests/Fixtures/Hosts/ToonShadow/PureBaseTestToonShadow.scshader | New fixed Shader-Core host shader for phase-local shadow visibility diagnostics. |
| Tests/Fixtures/Hosts/ToonShadow/PureBaseTestToonShadow.scshader.meta | Unity importer metadata for the new ToonShadow host shader asset. |
| Tests/Fixtures/Hosts/ToonShadow/PureBaseTestToonShadow_properties.hlsl | New host property declarations for the ToonShadow fixed host. |
| Tests/Fixtures/Hosts/ToonShadow/PureBaseTestToonShadow_properties.hlsl.meta | Unity importer metadata for the ToonShadow properties include. |
| Tests/Fixtures/Hosts/ToonShadow/phase_light.hlsl | New phase include publishing light-phase visibility to red channel. |
| Tests/Fixtures/Hosts/ToonShadow/phase_light.hlsl.meta | Unity importer metadata for ToonShadow phase include. |
| Tests/Fixtures/Hosts/ToonShadow/phase_modifylight.hlsl | New phase include publishing modifylight-phase visibility to green channel. |
| Tests/Fixtures/Hosts/ToonShadow/phase_modifylight.hlsl.meta | Unity importer metadata for ToonShadow phase include. |
| Tests/Fixtures/Hosts/ToonShadow/phase_shade.hlsl | New phase include publishing shade-phase visibility to blue channel and finalizing diagnostic output. |
| Tests/Fixtures/Hosts/ToonShadow/phase_shade.hlsl.meta | Unity importer metadata for ToonShadow phase include. |
| Tests/Fixtures/Hosts/ToonShadow/jp.penguin.purebase.tests.shadercore.toonshadow.scmodule | New Shader-Core module identity for the ToonShadow fixed host fixture. |
| Tests/Fixtures/Hosts/ToonShadow/jp.penguin.purebase.tests.shadercore.toonshadow.scmodule.meta | Unity importer metadata for the ToonShadow scmodule asset. |
| Tests/Daily/Editor/ShaderCoreTestHostManifestTests.cs | Expands host manifest expectations to include ToonShadow runtime evidence contract. |
| Tests/Daily/Editor/PureBaseValidationSceneRegressionTests.cs | Makes strict baseline capture batch-only and enforces tighter camera/scene isolation and diagnostics. |
| Tests/Daily/Editor/PureBaseToonLightingContractTests.Shadow.cs | Adds Toon-focused numerical and runtime rendering contracts for shadow attenuation separation and host diagnostics. |
| Tests/Daily/Editor/PureBaseToonLightingContractTests.Shadow.cs.meta | Unity metadata for the new Daily test partial file. |
| Tests/Daily/Editor/PureBaseToonLightingContractTests.Runtime.cs | Extends runtime capture utilities (cookies, shadow receiver readback, warmup variants) and adds temporary host selection scope with non-persistence checks. |
| Tests/Daily/Editor/PureBaseRenderingModeRenderingTests.SourceContracts.cs | Adds source-level assertions for the new attenuation helper + Toon visibility split ownership. |
| Tests/Daily/Editor/PureBaseRenderingModeRenderingTests.FrameReadbacks.cs | Adds active-scene contaminant setup to assert readback isolation determinism. |
| Tests/Daily/Editor/PureBaseRenderingModeRenderingTests.cs | Moves readbacks into preview scenes and constrains rendering via layer + scene culling masks for deterministic isolation. |
| Tests/Config/shader-core-test-hosts.json | Adds the ToonShadow host entry, sentinel expectations, and runtime evidence contract. |
| Shaders/Models/unlit.hlsl | Updates Unlit model API to the new SCModelPrepareMainLight callback while preserving behavior. |
| Shaders/Models/toon.hlsl | Implements Toon main-light preparation: non-shadow attenuation in light.color, visibility in sd.shadow. |
| Shaders/Models/pbr.hlsl | Implements PBR main-light preparation to preserve full attenuation ownership for Standard GI/direct. |
| Shaders/Common/birp_light_attenuation.hlsl | New helper evaluating non-shadow attenuation terms per Unity BIRP light-kind branch. |
| Shaders/Common/birp_light_attenuation.hlsl.meta | Unity importer metadata for the new attenuation helper include. |
| Shaders/Common/birp_host.hlsl | Uses UNITY_SHADOW_ATTENUATION + new helper to split attenuation and routes model-specific main-light prep via SCModelPrepareMainLight. |
| Docs/technical-information.md | Documents the Toon direct-light visibility contract and ownership boundaries. |
| Docs/technical-information.ja.md | Japanese documentation update for the Toon visibility contract. |
| Docs/pure-base-shader-contract.md | Shader contract documentation update describing Toon visibility split and phase expectations. |
Files not reviewed (8)
- Shaders/Common/birp_light_attenuation.hlsl.meta: Generated file
- Tests/Daily/Editor/PureBaseToonLightingContractTests.Shadow.cs.meta: Generated file
- Tests/Fixtures/Hosts/ToonShadow.meta: Generated file
- Tests/Fixtures/Hosts/ToonShadow/PureBaseTestToonShadow.scshader.meta: Generated file
- Tests/Fixtures/Hosts/ToonShadow/PureBaseTestToonShadow_properties.hlsl.meta: Generated file
- Tests/Fixtures/Hosts/ToonShadow/jp.penguin.purebase.tests.shadercore.toonshadow.scmodule.meta: Generated file
- Tests/Fixtures/Hosts/ToonShadow/phase_light.hlsl.meta: Generated file
- Tests/Fixtures/Hosts/ToonShadow/phase_modifylight.hlsl.meta: Generated file
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Suppress false positives at required Unity JSON and private test-contract boundaries. - Preserve field null semantics and avoid artificial equality APIs; verify focused Daily tests.
- Split Daily test rendering and assertion helpers into cohesive private operations. - Preserve cleanup order and validate focused Unity tests plus local analyzer output.
- Initialize transient cookies through light-capture requests and formalize restore-row equality contracts. - Verify focused cookie and ToonShadow restoration tests with zero Unity Console errors.
- Consume effective visibility once in Toon direct-light accumulation and clarify the test-host stencil state. - Verify ToonShadow import plus focused fixed-host and non-Toon shadow controls.
- Require module-free Toon direct receiver shadow response while preserving indirect-light ownership. - Guard the single visibility use and read-only ForwardAdd stencil through focused Daily contracts.
- Define the one-time Toon direct-light visibility rule and module double-attenuation migration constraint. - Synchronize English and Japanese shader contract guidance with tested HLSL behavior.
Summary
Validation
PureBase.Tests.Daily:78 total,77 passed,0 failed,1 intentional strict-baseline ignoreTests/Run-PureBaseRegression.ps1 -Mode Daily:78 passed,0 failed,0 skipped,0 inconclusive12623Notes