Objective
The objective of this challenge is to evaluate the candidate's ability to implement a Bounding Volume Hierarchy (BVH) for efficient spatial partitioning and a ray tracer for rendering using Babylon.js, TypeScript, and GLSL/WGSL. This involves creating and optimizing data structures and algorithms to enhance the rendering performance and quality of a 3D scene.
Challenge Description
You are tasked with implementing a BVH (Bounding Volume Hierarchy) for efficient spatial partitioning and a ray tracer for realistic rendering of a 3D scene. The goal is to optimize the performance of ray tracing by using the BVH structure to minimize the number of ray-primitive intersection tests.
Technical Requirements
- Setup and Environment
- Use Babylon.js as the 3D engine.
- Use TypeScript for all application logic.
- Use GLSL or WGSL for custom shaders.
- Bounding Volume Hierarchy (BVH)
- Data Structure:
- Each node in the BVH should represent an axis-aligned bounding box (AABB) that encloses a set of primitives (triangles, meshes).
- Each internal node should have two child nodes (binary tree structure).
- Leaf nodes should contain references to the primitives they enclose.
- Construction Algorithm:
- Top-Down Construction:
- Start with a single node that contains all primitives.
- Recursively split the node into two child nodes based on a chosen splitting heuristic (e.g., Surface Area Heuristic (SAH), median split).
- Continue splitting until each leaf node contains a small number of primitives (or a single primitive).
- Bottom-Up Construction:
- Start with each primitive as a leaf node.
- Iteratively merge pairs of nodes based on a chosen merging heuristic until a single root node is formed.
- Ray Tracer
- Ray Tracing Algorithm:
- Implement the ray tracing algorithm using GLSL or WGSL shaders.
- Use the BVH to accelerate ray-primitive intersection tests.
- The ray tracing algorithm should support:
- Primary Rays: Cast from the camera to determine visible surfaces.
- Shadow Rays: Cast from surfaces to light sources to determine shadows.
- Reflection Rays: Cast to simulate reflective surfaces.
- Optimize the ray tracing process by minimizing the number of intersection tests using the BVH.
- Scene and Objects
- Create a 3D scene with multiple objects of varying complexity.
- Ensure the scene contains elements that benefit from ray tracing, such as reflective surfaces and shadowed areas.
- Performance Metrics
- Measure and report the performance of the ray tracer with and without the BVH.
- Provide detailed profiling of the rendering performance, highlighting the improvements achieved by using the BVH.
- Documentation
- Provide clear documentation of the BVH and ray tracer implementation.
- Include comments in the code to explain the logic and optimization techniques used.
- Submission Requirements
- A GitHub repository containing the complete source code.
- A README file explaining how to set up and run the project, along with a summary of the BVH and ray tracing implementation.
Evaluation Criteria
- Technical Proficiency
- Correctness and efficiency of the BVH implementation.
- Effectiveness of the ray tracer, particularly its integration with the BVH.
- Proficiency in Babylon.js, TypeScript, and GLSL/WGSL.
- Code Quality
- Cleanliness and maintainability of the code.
- Proper use of TypeScript features and best practices.
- Performance Improvement
- Quantifiable performance gains with the BVH-integrated ray tracer.
- Effective use of profiling tools to identify and address bottlenecks.
- Documentation and Presentation
- Clarity and completeness of the documentation.
- Quality and thoroughness of the video presentation.
Challenge Implementation Steps
- Initial Setup
- Create a basic Babylon.js scene with multiple meshes.
- Establish a baseline performance metric (e.g., ray tracing without BVH).
- Implement BVH
- Data Structure:
- Create a class
BVHNode
representing each node in the BVH.
- Include properties for AABB, child nodes, and enclosed primitives.
- Construction Algorithm:
- Implement a function to construct the BVH using the top-down or bottom-up approach.
- Use a heuristic such as SAH or median split to determine how to split nodes.