Skip to content

t1k:unity:rendering:shadow-optimization

FieldValue
Modulerendering
Version3.1.7
Efforthigh
Tools

Keywords: optimization, rendering, shadows, unity

/t1k:unity:rendering:shadow-optimization

  • shadow, shadow map, shadow resolution, cascade, soft shadows
  • light probe, light probe group, probe placement
  • baked indirect, mixed lighting, lightmap bake
  • shadow acne, shadow bias, shadow distance
  • ShadowCastingMode, shadow casting
m_MainLightShadowmapResolution: 1024 # 256/512/1024/2048/4096
m_ShadowDistance: 30 # Max shadow render distance (meters)
m_ShadowCascadeCount: 2 # 1-4 cascades
m_Cascade2Split: 0.3 # % of distance for near cascade
m_SoftShadowsSupported: 1 # 0=off, 1=on
m_SoftShadowQuality: 2 # 0=Low, 1=Medium, 2=High
m_ShadowDepthBias: 2 # Reduce shadow acne (1-3)
m_ShadowNormalBias: 2 # Reduce shadow acne (1-3)
ArenaResolutionDistanceCascadesSplit
Small (20×20)512201
Medium (40×40)10243020.3
Large (80×80)20485030.1/0.3
Open world4096100+40.067/0.2/0.467
  • 1 cascade: Uniform texel density — ok for small arenas
  • 2 cascades: Near cascade (30% distance) gets 4× texel density — best for fixed-camera arenas
  • 3-4 cascades: Needed for large worlds with close-up + distant shadows
renderer.shadowCastingMode = ShadowCastingMode.Off; // No shadow
renderer.shadowCastingMode = ShadowCastingMode.On; // Normal shadow
renderer.shadowCastingMode = ShadowCastingMode.TwoSided; // Both faces cast
renderer.shadowCastingMode = ShadowCastingMode.ShadowsOnly; // Invisible, shadow only
Entity TypeShadowReason
Units (characters)ONVisual grounding
Trees/obstaclesONEnvironment grounding
Boundary wallsONArena structure
TerrainReceive onlyGround plane
Arrows/projectilesOFFToo fast, invisible
AOE/VFX (transparent)OFFNo meaningful shadow
ParticlesOFFPerformance waste
UI elementsOFF2D overlay
const float probeSpacing = 2f; // 2m grid
const float groundOffset = 0.5f; // Near ground
const float upperHeight = 3f; // Captures tree canopy shadows
// 2-layer grid: ground + upper
for (z) for (x) {
positions.Add(new Vector3(px, groundOffset, pz));
positions.Add(new Vector3(px, upperHeight, pz));
}
  • (ArenaWidth/spacing + 1) × (ArenaDepth/spacing + 1) × 2 layers
  • 40×40 arena, 2m spacing → 21×21×2 = 882 probes
  • Entities Graphics auto-samples light probes — NO extra components needed
  • Probes must be in main scene (not SubScene)
  • Zero runtime cost — probes are baked SH coefficients
  1. Directional Light → lightmapBakeType = LightmapBakeType.Mixed
  2. URP Asset → m_MixedLightingSupported: 1 (default)
  3. Static flags on all arena objects (isStatic = true)
  4. Window → Rendering → Lighting → “Generate Lighting” (manual bake)
  • Realtime shadows for ALL objects (static + dynamic)
  • Baked indirect bounce for static geometry only
  • Units auto-sample light probes for ambient variation
  1. Shadowmask NOT supported by Entities Graphics — use Baked Indirect only
  2. SubScene = 1 lightmap per SubScene — ok for single SubScene
  3. Auto-generate lighting DISABLED with Entities Graphics installed — must bake manually
  4. GPU Resident Drawer “OnDemand” shadow bug — use “EveryFrame” mode if shadows flicker (note: invisible entities are more likely ChunkWorldRenderBounds NaN corruption — see #9)
  5. Bias too low → shadow acne (striping). Bias too high → peter-panning (shadows detach)
  6. Shadow distance > arena diagonal wastes texels on empty space
  7. Soft shadows add ~0.1ms GPU cost — negligible on modern GPUs
  8. Forward+ has no GBuffer pass — affects impostor baking, not shadows

→ See references/shadow-safety-guide.md for Safe vs Unsafe shadow change table, CRITICAL lighting corruption gotchas, and Rendering Debugger workflow.