# 7. Toon Shading Pitfalls Part of [[Stylized Toon and Outline Shading]]. Prev: [[6. Worked Example Toon Character and Level]]. > [!warning] Code not compiled > Fixes refer to the shaders and scripts in this series, which were not compiled. See the hub's open questions. ## Cel lighting | Symptom | Cause | Fix | |---|---|---| | Band edge crawls / shimmers when the camera moves | Hard `step` with no anti-aliasing | `Band Softness` 0.01-0.03; MSAA or SMAA/TAA on the camera | | Speckled shadow band ("acne") on lit surfaces | Shadow map precision; banding amplifies small shadow noise | Increase *Depth/Normal Bias* on the light, shorten Shadow Distance, use cascades; soft shadows | | Cast shadows look like a different color than self-shadow | Shadow attenuation not fed into the band input | Band `halfLambert * shadowAttenuation` (parts 2-3), not `halfLambert` then multiply shadow afterwards | | Point lights do nothing | `_ADDITIONAL_LIGHTS` path not compiled, *Additional Lights* set to Disabled/Per Vertex, or (Shader Graph) Keep Lighting Variants off | URP Asset: Additional Lights **Per Pixel**; Graph Settings: **Keep Lighting Variants** on | | Additional lights work in Forward but not Forward+ | Loop uses `GetAdditionalLightsCount()` only (always 0 in Forward+) or missing `_CLUSTER_LIGHT_LOOP` | Use the manual's pattern: `#pragma multi_compile _ _CLUSTER_LIGHT_LOOP`, the `URP_FP_DIRECTIONAL_LIGHTS_COUNT` loop, `LIGHT_LOOP_BEGIN` with `inputData` | | Old tutorials' `_FORWARD_PLUS` keyword does nothing | Renamed; 6000.5 uses `_CLUSTER_LIGHT_LOOP` (also noted in [[URP Shaders and Shader Graph]]) | Replace the keyword | | Custom Function node preview is black or errors | URP light functions do not exist in node previews | Guard with `#ifdef SHADERGRAPH_PREVIEW` and return fake values (part 2) | | `ToonMainLight_float` not found | Node *Name* includes the suffix, or graph precision is Half | Name `ToonMainLight`; graph precision **Single** (or add `_half` versions) | | Shadows missing with *Screen Space Shadows* renderer feature | `_MAIN_LIGHT_SHADOWS_SCREEN` expects screen-space coordinates | Remove that renderer feature for toon scenes, or test (hub open question) | | Ramp: brightest pixels show the shadow color | Ramp texture Wrap Mode *Repeat* | Clamp, no mipmaps, uncompressed (part 3 baker sets these) | | Everything looks flat and gray | Ambient too strong or tonemapping compressing bands | Ambient 0.3-0.5; Tonemapping Neutral or off; check the squint test | | SSAO darkens bands with soft blobs | SSAO adds gradients | Disable *Default SSAO* in Graph Settings / SSAO renderer feature for toon scenes | ## Inverted hull outlines | Symptom | Cause | Fix | |---|---|---| | Gaps at hard edges | Split vertex normals | Smoothed normals in tangents (postprocessor, part 4) | | Outline on animated limbs points the wrong way | Smoothed normals stored in a UV channel (not skinned) | Store in tangents (skinned); accept no normal maps on that mesh | | Normal maps look broken on outlined meshes | Tangents overwritten with smoothed normals | Exclude normal-mapped meshes from `_Toon` naming, or use screen-space edges for them | | Outline swims inside the object / z-fights | Width 0 or front faces culled instead of back | `Cull Front`; keep `ZWrite On`; width > 0 | | Lines huge on close-up cinematics | Constant pixel width at extreme FOV / resolution | Clamp width or scale by distance for cutscenes | | Outline missing on Shader Graph objects | Graphs cannot add passes | Use Render Objects layer outline (part 4 option B) | | Highlighted object stops colliding / raycasts miss | Layer change affected physics | Renderers on child objects, or collision matrix for `Outlined` (part 6) | | Renderer feature disabled after Play mode | Script changed the feature asset and did not restore it | Restore in `OnDisable` (part 6 `ToonFeatureToggle`) | ## Screen-space edges | Symptom | Cause | Fix | |---|---|---| | No lines at all | Full Screen Pass missing Depth/Normal requirements, or wrong Pass Material | Requirements **Depth + Normal**, Fetch Color Buffer on | | Silhouettes but no creases on some objects | Their shader has no DepthNormals pass | Shader Graph / URP Lit have it; hand-written shaders need one (`UsePass ... DepthNormals`) | | Floors and slopes fill with lines at distance | Grazing angles | Raise Grazing Correction, relative depth threshold, distance fade | | Grass, foliage and normal-mapped walls become noise | High-frequency normals | Raise Normal Threshold; exclude via materials or use hull outlines only | | Lines offset by a pixel or doubled | Thickness > 2, or render scale / dynamic resolution vs `_ScreenSize` | Thickness 1; test with Render Scale 1 (hub open question) | | Transparent objects and particles not outlined | Not in depth/normals textures | Expected; use hull outlines or none | | Effect missing in Scene view or in a second camera | Renderer feature applies per renderer/camera setup | Check which Renderer Data each camera uses | ## Performance and platforms - **SRP Batcher**: `UsePass` from URP Lit (part 3) makes the hand-written shader incompatible with the SRP Batcher (same caveat as the existing *URP Simple Lit* example). For many objects, prefer the Shader Graph toon + Render Objects outlines, or port URP's ShadowCaster/DepthOnly/DepthNormals passes into your shader. - **Draw calls**: every hull outline doubles the draws of outlined objects. Outline only what the style sheet's ranks require. - **Full-screen edges** need a DepthNormals pre-pass (all opaque geometry drawn again) plus a full-screen pass. On Meta Quest 2 that is a big cost; prefer hull outlines on key objects there ([[5.Quest 2 Performance and Rendering]]). - **Variants**: `Keep Lighting Variants` and the multi_compile lines add shader variants; build times and memory grow. Strip unused features in the URP Asset (e.g. disable additional light shadows if unused). - Check costs with the Frame Debugger and Profiler ([[4. Frame Debugger and GPU]], [[Profiling and Optimization]]). ## Design pitfalls (Level Up! lens) - **Outlining everything** destroys hierarchy - Level 8 clarity is about contrast between important and unimportant (part 1 ranks). - **Reserved colors used for decoration** - if "interactable yellow" appears on a wall poster, players will try to use the wall. - **Losing the weenie** - toon flatness can hide the landmark if it shares values with the background; give it the strongest contrast ([[3. Weenies Landmarks and Lighting as Wayfinding]]). ## Sources - Render additional lights in Forward and Forward+ (6000.5): https://docs.unity.com/en-us/engine/6000.5/manual/lighting-overview/lighting/custom-lighting/use-built-in-shader-methods-additional-lights-fplus - Use shadows in a custom URP shader (6000.5): https://docs.unity.com/en-us/engine/6000.5/manual/materials-and-shaders/shaders/writing-custom-shaders-urp/use-built-in-shader-methods/shadows - Full Screen Pass Renderer Feature reference (6000.5): https://docs.unity.com/en-us/engine/6000.5/manual/post-processing-and-full-screen-effects/urp/custom-post-processing/renderer-feature-full-screen-pass - Custom Lighting sample - get started (Shader Graph 17.5): https://docs.unity3d.com/Packages/[email protected]/manual/Shader-Graph-Sample-Custom-Lighting-Get-Started.html - Related: [[Custom URP Renderer Features]], [[6. Renderer Feature Pitfalls]], [[Lighting and Baking]]