Lod occlusion culling

From nlelouche/Unity-SkillForge · View interactive version

Lod occlusion culling is an AI agent skill from the GitHub repository nlelouche/Unity-SkillForge. LOD Groups and Occlusion Culling for rendering optimization in 3D environments.

How to use this skill

Skill file

LOD & Occlusion Culling

Overview

Level of Detail (LOD) and Occlusion Culling for rendering optimization. Essential for 3D games with complex environments.

When to Use

Culling Hierarchy

┌─────────────────────────────────────────────────────────────┐
│                    CULLING PIPELINE                         │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  ALL OBJECTS                                                │
│       │                                                     │
│       ▼                                                     │
│  ┌─────────────┐                                            │
│  │ FRUSTUM     │── Objects outside camera view → CULLED    │
│  │ CULLING     │                                            │
│  └──────┬──────┘                                            │
│         │                                                   │
│         ▼                                                   │
│  ┌─────────────┐                                            │
│  │ OCCLUSION   │── Objects behind walls → CULLED           │
│  │ CULLING     │                                            │
│  └──────┬──────┘                                            │
│         │                                                   │
│         ▼                                                   │
│  ┌─────────────┐                                            │
│  │ LOD         │── Distant objects → SIMPLIFIED            │
│  │ SELECTION   │                                            │
│  └──────┬──────┘                                            │
│         ▼                                                   │
│     RENDERED                                                │
│                                                             │
└─────────────────────────────────────────────────────────────┘

LOD Levels

| Level | Distance | Poly Reduction |

|:-----:|:--------:|:--------------:|

| LOD0 | 0-10m | 100% (original) |

| LOD1 | 10-30m | 50% |

| LOD2 | 30-60m | 25% |

| LOD3 | 60m+ | 10% |

| Culled | Far | 0% |

Culling Types

| Type | Description | Setup |

|------|-------------|-------|

| Frustum | Outside camera | Automatic |

| Occlusion | Behind occluders | Bake |

| Distance | Beyond range | LOD Cull |

| Layer | Camera layer mask | Manual |

Best Practices

Few-Shot Examples

Example 1: LOD Group Setup

User: "Set up LOD for prop."

Agent:

Unity Setup:
1. Parent object → Add Component → LOD Group
2. Add mesh renderers to each LOD level:
   - LOD0: Full quality mesh
   - LOD1: 50% poly mesh
   - LOD2: 25% poly mesh
   - Culled: Shows nothing

3. Adjust transition percentages:
   - LOD0: 60-100%
   - LOD1: 30-60%
   - LOD2: 10-30%
   - Culled: 0-10%

4. Enable Cross Fade for smooth transitions

Example 2: Occlusion Baking

User: "Set up occlusion culling."

Agent:

Baking workflow:
1. Mark static geometry:
   - Walls, floors → Occluder Static + Occludee Static
   - Props → Occludee Static only
   - Dynamic objects → No static flags

2. Window → Rendering → Occlusion Culling
3. Set parameters:
   - Smallest Occluder: 5 (wall thickness)
   - Smallest Hole: 0.25 (visibility gaps)
   - Backface Threshold: 100

4. Click "Bake"
5. Test with Occlusion visualization

Example 3: Dynamic LOD Controller

User: "Adjust LOD bias at runtime."

Agent:

public class LODController : MonoBehaviour
{
    [SerializeField] private float _highEndBias = 1.0f;
    [SerializeField] private float _lowEndBias = 2.0f;
    
    public void SetQuality(bool highQuality)
    {
        // Higher bias = show lower LODs sooner
        QualitySettings.lodBias = highQuality ? _highEndBias : _lowEndBias;
    }
    
    public void SetMaxLOD(int maxLevel)
    {
        // 0 = show all LODs, 1 = skip LOD0, etc.
        QualitySettings.maximumLODLevel = maxLevel;
    }
}

Occlusion Tips

Performance Gains

| Technique | Typical Savings |

|-----------|:---------------:|

| Frustum Culling | 30-50% |

| Occlusion Culling | 20-40% |

| LOD (3 levels) | 50-80% distant |


TDD Contract

⚠️ Legacy Skill — Refactor Pending

Este skill NO tiene tests automatizados aún. El siguiente boilerplate es un punto de partida.

// Escribe estos tests ANTES de implementar:

// Test 1: should [expected behavior] when [condition]
[Test]
public void LodOcclusionCulling_Should{ExpectedBehavior}_When{Condition}()
{{
    // Arrange
    // TODO: Setup test fixtures
    
    // Act
    // TODO: Execute system under test
    
    // Assert
    Assert.Fail("Not implemented — write test first");
}}

// Test 2: should handle [edge case]
[Test]
public void LodOcclusionCulling_ShouldHandle{EdgeCase}()
{{
    // Arrange
    // TODO: Setup edge case scenario
    
    // Act
    // TODO: Execute
    
    // Assert
    Assert.Fail("Not implemented");
}}

// Test 3: should throw when [invalid input]
[Test]
public void LodOcclusionCulling_ShouldThrow_When{InvalidInput}()
{{
    // Arrange
    var invalidInput = default;
    
    // Act & Assert
    Assert.Throws<Exception>(() => {{ /* execute */ }});
}}

Pasos para completar el TDD:

  1. Descomenta los tests above
  2. Implementa la funcionalidad mínima para que compile
  3. Ejecuta los tests — deben fallar (RED)
  4. Implementa la funcionalidad real
  5. Verifica que los tests pasen (GREEN)
  6. Refactorea manteniendo los tests verdes

Nota: Este skill fue marcado como tdd_first: false durante la auditoría v2.0.1. La sección TDD fue agregada automáticamente pero requiere customización manual para reflejar el comportamiento real del skill.

Related Skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.