A comprehensive Unity-based computer graphics learning project focused on Procedural Content Generation (PCG), advanced rendering techniques, and AI implementations. This project demonstrates various computer graphics concepts including terrain generation, GPU instancing, particle systems, volumetric effects, and NPC AI behaviors.
This is an educational project designed to explore and implement fundamental and advanced computer graphics techniques in Unity. The project showcases:
- Procedural Terrain Generation using Perlin noise with multiple octaves
- GPU Instancing for high-performance object rendering
- Custom Particle Systems built from scratch
- Volumetric Cloud Generation using Cellular Automata
- NPC AI System with state machine-based behavior
- Advanced Collision Detection with multi-layer sphere-line intersection
- Dynamic Day/Night Cycle with atmospheric lighting
- Water Detection & Rendering with shader graphs
- Performance Optimization techniques including frustum culling and chunk-based loading
- Multi-octave Perlin noise implementation for realistic terrain
- Island generation modes (Real Center, Multi-Center)
- Configurable height redistribution for valley and peak shaping
- Real-time terrain regeneration capabilities
- Automatic texture painting based on height values
- High-performance object spawning using GPU instancing
- Frustum culling for optimized rendering
- Chunk-based spatial partitioning
- Blue noise distribution for natural placement
- Support for thousands of objects with minimal performance impact
- Runtime texture generation using algorithmic methods
- Sand texture generator with Voronoi grain distribution
- Dirt texture generator with multi-layer composition (soil, pebbles, moisture, organic matter)
- Perlin noise for natural variation
- Tileable textures for seamless material application
- Resolution-independent generation
- Custom-built particle system from scratch (no Unity ParticleSystem)
- CPU-based particle simulation with gravity and velocity
- Color gradient transitions over particle lifetime
- Configurable emission rates and spawn areas
- Billboard rendering for camera-facing particles
- 3D Cellular Automata algorithm for cloud generation
- Configurable birth/death thresholds for realistic cloud formations
- Voxel-based cloud representation
- Procedural cloud density control
- State machine architecture (Idle, Patrol, Chase, Attack)
- Vision cone detection with angle and range checks
- NavMesh-based pathfinding
- Line-of-sight obstacle detection
- Smooth animation blending with velocity-based transitions
- Multi-layer sphere collision detection
- Mathematical sphere-line segment intersection
- Visualization tools for debugging collision boundaries
- Weapon hit detection system
- Grid-based water body detection on terrain
- Cluster analysis using flood-fill algorithm
- Dynamic water plane placement
- Custom water shader with animated waves
- Dynamic day/night cycle with sun rotation
- Temperature-based light color transitions
- Fog chunk spawning system
- Performance monitoring and FPS counter
Computer-Graphics-Simulation/
├── Assets/
│ ├── Scripts/
│ │ ├── Terrain/
│ │ │ ├── PerlinNoiseTerrainGenerator.cs # Core terrain generation
│ │ │ ├── TerrainTexturePainter.cs # Automatic texture painting
│ │ │ ├── InnerTerrainWaterDitection.cs # Water body detection
│ │ │ └── Object Spawn/
│ │ │ ├── ProceduralObjectSpawnerGPU.cs # GPU instancing spawner
│ │ │ ├── ProceduralObjectSpawnerGPUMaster.cs # Master controller
│ │ │ ├── FogChunkSpawner.cs # Fog system
│ │ │ └── TerrainObjectSpawner.cs # Object placement logic
│ │ ├── NPC/
│ │ │ ├── NPC_Controller.cs # AI state machine
│ │ │ ├── NPC_HealthManager.cs # Health system
│ │ │ └── NPC_WeponHandeller.cs # Weapon handling
│ │ ├── Textures/
│ │ │ ├── TextureGenerator_Sand.cs # Procedural sand texture
│ │ │ └── TextureGenerator_Dirt.cs # Procedural dirt texture
│ │ ├── Player/
│ │ │ ├── Player_HitCollisionManager.cs # Collision detection
│ │ │ ├── Mng_PlayerHelthStaminaManager.cs # Health/stamina system
│ │ │ └── Player_Weapon_LongSword.cs # Player weapon
│ │ ├── Effects/
│ │ │ └── VFX_ParticalSystem.cs # Custom particle system
│ │ ├── CloudSystem/
│ │ │ └── VolumetricClouds.cs # Cellular automata clouds
│ │ ├── Managers/
│ │ │ ├── Mng_DayAndNightCycle.cs # Day/night system
│ │ │ ├── Mng_GlobalReferences.cs # Global reference manager
│ │ │ └── Mng_FpsCounter.cs # Performance monitoring
│ │ └── Helpers/
│ │ ├── MathUtils.cs # Mathematical utilities
│ │ └── Bilboard.cs # Billboard effect
│ ├── Shaders/
│ │ ├── Water/ # Water shader graphs
│ │ ├── Fog/ # Fog shader graphs
│ │ ├── Bush/ # Vegetation shaders
│ │ └── Pine Trees/ # Tree shaders
│ ├── Scenes/
│ │ ├── PCG - Terrain Generation.unity # Main terrain scene
│ │ ├── NPC AI Module.unity # AI testing scene
│ │ └── Testing Area.unity # Experimentation scene
│ └── Prefabs/ # Reusable game objects
├── DOCUMENTATION.md # Detailed technical documentation
└── README.md # This file
- Unity 6 (6000.0.58f2 or newer)
- High Definition Render Pipeline (HDRP) package
- TextMeshPro package
- NavMesh Components (for NPC AI)
- Minimum 8GB RAM recommended for complex terrain generation
- Clone or download this repository
- Open the project in Unity Hub
- Wait for Unity to import all assets
- Open the scene:
Assets/Scenes/PCG - Terrain Generation.unity - Press Play to see the procedural terrain generation in action
-
Generate Terrain:
- Select the Terrain GameObject in the hierarchy
- In the Inspector, find
PerlinNoiseTerrainGeneratorcomponent - Adjust parameters like
noiseScale,octaves, andyRange - Click "Generate New Terrain" button or press Play
-
Spawn Objects:
- The GPU instancing system automatically spawns objects around the player
- Adjust
objectDensityandchunksToRenderinProceduralObjectSpawnerGPU
-
Test NPC AI:
- Open
NPC AI Module.unityscene - Press Play and observe NPC patrol, detection, and chase behaviors
- Open
- WASD - Move player
- Mouse - Look around
- Shift - Sprint (consumes stamina)
- Left Click - Attack (when weapon equipped)
- ESC - Pause/Menu
The terrain generation uses a sophisticated multi-pass approach:
-
First Pass: Generate base Perlin noise with multiple octaves
- Each octave adds detail at different scales
- Octave frequency doubles each iteration
- Amplitude halves each iteration
-
Second Pass: Normalize and apply island masking
- Height redistribution using power function
- Island shape generation (single or multi-center)
- Smooth edge falloff using SmoothStep
-
Third Pass: Final normalization
- Ensures all heights are in valid range [0, 1]
- Maintains relative height differences
The GPU instancing system achieves high performance through:
- Chunk-based spatial partitioning: Divides world into manageable chunks
- Frustum culling: Only renders objects in camera view
- Distance-based culling: Removes distant objects
- Blue noise distribution: Natural-looking object placement
- Material property blocks: Efficient per-instance properties
- Matrix batching: Renders up to 1023 instances per draw call
The sphere-line intersection algorithm uses parametric line equations:
- Line: P(t) = A + t(B - A), where t ∈ [0, 1]
- Sphere: ||P - C||² = r²
- Solving the quadratic equation to find intersection points
- See
MathUtils.csfor complete derivation
The project implements several optimization techniques:
- Spatial Partitioning: Chunk-based world division
- Frustum Culling: Only render visible objects
- GPU Instancing: Batch rendering for identical objects
- Event-Driven Updates: Only update when player moves to new chunk
- Object Pooling: Reuse particle instances
- LOD System Ready: Structure supports Level of Detail implementation
Performance Metrics (on mid-range hardware):
- 10,000+ grass instances: 60+ FPS
- Terrain resolution 256x256: < 500ms generation time
- NPC AI updates: < 1ms per NPC
- Animated wave displacement using sine functions
- Normal mapping for surface detail
- Refraction and reflection effects
- Foam generation at shorelines
- Volumetric fog rendering
- Height-based density falloff
- Distance fade effects
- PCG - Terrain Generation: Main procedural generation showcase
- Procedural Generation Algorithms: Perlin noise, Cellular Automata, Voronoi diagrams
- Procedural Texturing: Runtime texture generation with multi-layer composition
- NPC AI Module: NPC behavior testing environment
- Testing Area: Sandbox for experimentation
- Testing Cellular Automata Cloud: Cloud generation testing
This project demonstrates proficiency in:
- Procedural Generation Algorithms: Perlin noise, Cellular Automata
- GPU Programming: Instancing, draw call optimization
- Game AI: State machines, pathfinding, perception systems
- Physics & Mathematics: Vector math, collision detection, trigonometry
- Shader Programming: Shader Graph usage, custom materials
- Unity Engine: Component architecture, serialization, editor tools
- Performance Optimization: Profiling, culling, spatial partitioning
- Software Architecture: Modular design, event systems, separation of concerns
// In PerlinNoiseTerrainGenerator.cs
[SerializeField] private float noiseScale = 20f; // Larger = smoother terrain
[SerializeField] private int octaves = 4; // More = more detail
[SerializeField] private float redistributionExponent = 1.5f; // Higher = steeper peaks// In ProceduralObjectSpawnerGPU.cs
public float objectDensity = 100f; // Objects per chunk
public int maxObjectsPerChunk = 1000; // Performance limit
public float noiseThreshold = 0.3f; // Higher = fewer objects// In NPC_Controller.cs
[SerializeField] private float detectionRange = 5f; // How far NPC can see
[SerializeField] private float visionAngle = 60f; // Field of view
[SerializeField] private float chaseSpeed = 5f; // Chase speed- Water detection may require manual adjustment for complex terrains
- Very high object density (>500 per chunk) may impact performance
- Cellular automata clouds are CPU-intensive for large volumes
- Compute shader integration for terrain generation
- Biome system with multiple terrain types
- Advanced weather system
- Multiplayer networking support
- Save/load system for generated worlds
- Procedural cave generation
- Advanced vegetation system with wind animation
For detailed technical documentation, see DOCUMENTATION.md
- Perlin noise and coherent noise functions
- GPU instancing and draw call batching
- Spatial data structures (grids, chunks)
- AI state machines and behavior trees
- Collision detection algorithms
- Shader programming fundamentals
This is a learning project, but suggestions and improvements are welcome! Feel free to:
- Report bugs or issues
- Suggest new features
- Share improvements or optimizations
- Use this project for your own learning
This project is open source and available under the MIT License.
Created as a computer graphics learning project to explore procedural generation, GPU optimization, and game AI systems in Unity.
- Unity Technologies for the game engine and HDRP
- Sebastian Lague for terrain generation inspiration
- Brackeys for Unity tutorials
- The game development community for shared knowledge
Last Updated: October 25, 2025 Unity Version: 6000.0.58f2 (Unity 6)
Last Updated: October 25, 2025 Unity Version: 6000.0.58f2 (Unity 6)
- Open an issue on the repository
- Check the DOCUMENTATION.md for technical details
Happy Learning! 🚀
Last Updated: October 25, 2025 Unity Version: 6000.0.58f2 (Unity 6)
