A high-performance, modular 3D rendering engine built from scratch in Rust using modern OpenGL. This project serves as a showcase of advanced graphics programming techniques, including real-time dynamic lighting, shadow mapping, and a custom ECS-inspired scene architecture.
- Dynamic Lighting System:
- Directional Lights: Simulates sun/moon light with parallel rays.
- Point Lights: Omnidirectional lights with quadratic attenuation (e.g., light bulbs, fire).
- Spot Lights: Cone-shaped lights with soft edges (flashlight effect).
- High-Fidelity Shadows:
- Directional Shadows: Implemented using high-res depth maps and PCF (Percentage-Closer Filtering) 3x3 sampling for soft shadow edges.
- Omnidirectional Shadows: Point lights cast shadows in all directions using Dynamic Geometry Shader Cubemaps.
- Material System:
- Blinn-Phong Shading: Realistic specular highlights.
- Texture Support: Diffuse maps, UV tiling, and scaling.
- Materials: Support for
Gold,Emerald,Obsidian, etc., via a preset factory.
- Skybox: Seamless cubemap rendering for immersive backgrounds.
- Asset Management:
- Resource counting references (
Rc) for efficient memory usage. - Automatic caching of Shaders, Textures, and Models (OBJ) to prevent duplicate loading.
- Resource counting references (
- Scene Graph:
- Transform Hierarchy: Position, Rotation (Quaternions), and Scale.
- Component System: Objects can have attached
Colliders,Controllers(scripts), andMaterials.
- Input Handling:
- Event-driven input system wrapping
GLFWevents. - Raycasting for 3D object selection from screen space.
- Event-driven input system wrapping
- Orbit Camera: Professional CAD-like camera controls (Pan, Zoom, Orbit).
- Physics Lite: Simple AABB and Sphere collision primitives.
- UI System: Custom text rendering engine and batch-rendered 2D UI elements (buttons, panels).
- Logic Controllers:
OrbitController: For planetary motion.FloatingController: For "breathing" idle animations.RotationController: For constant spinning objects.
The codebase is organized into modular distinct crates/modules:
src/
├── assets/ # Asset Manager (Loaders for OBJ, PNG, GLSL)
├── config.rs # Global Configuration (Window size, Light limits, Constants)
├── game/ # Core Game Loop & Scene Composition
├── input/ # Input State Management
├── light/ # Light Components (Directional, Point, Spot)
├── logic/ # Game Logic & Object Behaviours (Controllers)
├── math/ # Raycasting & Math Utilities
├── primitives/ # Procedural Mesh Generation (Cube, Sphere, Capsule, Plane)
├── renderer/ # Render Passes (Shadow Pass, Geometry Pass, Skybox Pass)
├── scene/ # Scene Graph, Objects, Materials
├── shaders/ # GLSL Shader Compilation & Linking
├── shapes/ # 2D Shapes
├── ui/ # User Interface (Text, Buttons)
└── window/ # Window Creation & Context Management- Rust Toolchain: Install Rust
- C Compiler: Required for compiling
glfw-sys.- Windows: Install Visual Studio C++ Build Tools.
- Linux:
sudo apt install build-essential cmake
- CMake: Required for building GLFW.
- Windows: Download CMake and add to PATH.
-
Clone the repository:
git clone https://github.com/Hakkology/OpenGL-Renderer-Rust.git cd OpenGL-Renderer-Rust -
Run in release mode for best performance:
cargo run --release
Note: First compilation might take a few minutes as it compiles dependencies like
glfwandimagecrates.
| Context | Input | Action |
|---|---|---|
| Camera | LMB + Drag | Orbit around the center |
| Camera | Scroll | Zoom In / Out |
| Interaction | LMB Click | Select Object (Raycast) |
| Interaction | Pause Button | Pause/Resume Object Animations |
| System | Esc | Close Application |
You can tweak engine parameters in src/config.rs without touching core logic:
window: Resolution, Title, VSync.camera: FOV, Sensitivity, Zoom Limits.rendering: Shadow Map Resolution (Default: 2048), Max Lights.
This project is licensed under the MIT License.
*Made by Hakkology
