
This project explores ray tracing in OpenGL by implementing a recursive ray tracer with Phong shading, shadows, reflections, and texture mapping. The goal is to render realistic lighting and materials using GPU-based ray tracing.
Ray tracing simulates how light interacts with objects in a scene. Instead of rasterizing triangles, we trace rays from the camera into the scene, checking for intersections with objects and computing lighting based on material properties.
1. Ray-Object Intersections
The shader implements ray-plane and ray-sphere intersection tests to determine where each ray hits an object.
• Planes use a simple dot product check.
• Spheres solve a quadratic equation to find intersections.
2. Phong Shading
Once a ray intersects an object, we calculate its Phong reflection model, which includes:
• Ambient lighting (constant background light)
• Diffuse lighting (light reflecting based on angle)
• Specular highlights (shininess of the surface)
3. Shadows
To check if a point is in shadow, we trace a shadow ray from the hit point toward the light source.
• If an object blocks this ray, the point is in shadow.
• If the ray reaches the light, it is lit.
4. Texture Mapping
Textures are applied based on the object’s UV coordinates.
• The ground plane uses a marble texture.
• The spheres use colorful texture mapping based on their spherical coordinates.
5. Recursive Reflections
To achieve mirror-like reflections, we recursively trace reflected rays.
• At each bounce, the ray’s intensity is multiplied by the surface’s reflectivity coefficient (kr).
• The recursion depth is set to 50, allowing multiple reflections.
6. Temporal Anti-Aliasing
To smooth out jagged edges and reduce noise, Temporal AA blends the current frame with previous frames.
This project serves as a foundation for GPU-based ray tracing, combining physically-based rendering techniques with OpenGL shaders for real-time visuals.
Leave a comment