Parade
Project Overview
“Parade” is an ongoing project that focuses on rendering and staging scenes using signed distance functions (SDFs). Currently developed in OpenGL, this project provides a foundational platform for experimenting with various rendering techniques and lighting models.
The initial implementation of “Parade” includes several SDF primitives and employs a simple Blinn-Phong lighting model. As I continue to develop this project, I plan to enhance its capabilities significantly, making it a versatile tool for graphics rendering.
Current Features
- SDF Primitives: “Parade” supports a range of SDF primitives, providing a flexible basis for constructing complex 3D shapes and scenes.
- Blinn-Phong Lighting Model: The renderer uses the Blinn-Phong model for basic lighting effects, offering a straightforward approach to simulating light reflection.
Ray Marching and Normal Calculation
One of the core components of “Parade” is the implementation of a ray marching loop to render signed distance functions (SDFs) and calculate normals for realistic lighting. These algorithms are essential for achieving high-quality rendering and play a crucial role in the visual output of the project.
Ray Marching Loop
The ray marching algorithm is used to determine the intersection of rays with the SDF-defined surfaces. By iteratively advancing along the ray’s direction and checking distances, we efficiently render complex shapes.
// Ray Marchning Loop
vec3 ray_origin = cam_position;
vec3 ray_direction = normalize(inverse_view_matrix * cam_direction);
float total_distance = 0.0;
int steps = 0;
while (total_distance < MAX_DISTANCE && steps < MAX_STEPS) {
vec3 current_position = ray_origin + ray_direction * total_distance;
float distance = DistanceEstimate(current_position);
if (distance <= EPSILON) {
// ray hit surface
break;
}
total_dist += distance;
steps++;
}
- Initialization: The ray is initialized from the camera position towards the pixel position.
- Iteration: The loop iteratively calculates the distance from the current position to the nearest surface using the SDF.
- Termination: The loop breaks once the surface is reached, allowing for shading and lighting calculations.
Normal Calculation
Normals are crucial for lighting as they define how light interacts with the surface. We approximate the normal at any point on the SDF surface using a finite difference method:
// Normal Calculation Function
vec3 normal = normalize(vec3(
DistanceEstimate(current_position + vec3(EPSILON, 0, 0)) - sdf(current_position - vec3(EPSILON, 0, 0)),
DistanceEstimate(current_position + vec3(0, EPSILON, 0)) - sdf(current_position - vec3(0, EPSILON, 0)),
DistanceEstimate(current_position + vec3(0, 0, EPSILON)) - sdf(current_position - vec3(0, 0, EPSILON))
};
- Finite Differences: We sample the SDF at points slightly offset from the current position to calculate the gradient.
- Normalization: The resulting vector is normalized to yield the surface normal, which is used in lighting calculations.
These techniques are fundamental to rendering detailed and realistic images in “Parade,” and their implementation demonstrates the effectiveness of ray marching and normal calculation in modern graphics rendering.
Future Plans
Transition to Vulkan and RTX:
- Vulkan Integration: I plan to rewrite the renderer in Vulkan, allowing for better performance and more advanced features like ray tracing (RTX).
- Ray Tracing Support: By leveraging RTX, “Parade” will be able to produce more realistic lighting effects and reflections, elevating the visual quality.
Lighting Model Enhancement:
- Disney BRDF Model: The current Blinn-Phong model will be replaced with the Disney BRDF model, offering more realistic and physically-based rendering of materials.
Shader Architecture Improvements:
- Multi-Pass Rendering: Transitioning from a single shader pass to a multi-pass architecture will enable advanced features such as post-processing effects and mouse selection, enhancing interactivity and visual appeal.
Technical Highlights
OpenGL Rendering: Currently written in OpenGL, “Parade” provides a platform for exploring traditional rendering techniques with modern hardware capabilities.
Real-Time Performance: The use of SDFs allows for efficient rendering of complex shapes in real-time, providing immediate visual feedback during development.
Reflections and Learnings
This project has been instrumental in deepening my understanding of SDF rendering and lighting models. As I move forward with “Parade,” I aim to create a robust and feature-rich renderer that can be utilized in various graphics applications. The transition to Vulkan and the introduction of advanced lighting models and techniques will significantly expand the project’s potential.