A simple and elegant ray tracer built with pure JavaScript. This project implements a basic ray tracing engine that renders 3D scenes directly in your browser.
- Pure JavaScript implementation with no rendering dependencies
- Vector math utilities with memoization for performance
- Ray-sphere intersection calculations
- Camera with adjustable parameters
- Anti-aliasing through multi-sampling
- Real-time rendering to HTML canvas
- Node.js (latest stable version recommended)
- npm or yarn
-
Clone the repository:
git clone [repository-url] cd raytracer -
Install dependencies:
npm install
-
Start the development server:
npm run dev
-
Open your browser and navigate to the local development server (usually http://localhost:1234)
The ray tracer works by simulating the physical behavior of light. For each pixel:
- Rays are cast from a virtual camera through the pixel
- Intersections with objects in the scene are calculated
- Lighting calculations determine the color of each pixel
- The final image is rendered to an HTML canvas
src/vector.js- Vector math operations with memoizationsrc/ray.js- Ray representation and ray-color calculationssrc/camera.js- Camera model and rendering pipelinesrc/sphere.js- Sphere geometry and intersection logicsrc/hittable.js- Abstract interface for scene objectssrc/functional.js- Functional programming utilitiessrc/interval.js- Range checking utilitiessrc/index.js- Main application and scene setup
- Materials and textures
- Additional geometric primitives
- Global illumination
- Reflection and refraction
- Multi-threading with Web Workers
- Scene file loading
This project is licensed under the ISC License - see the package.json file for details.
A project exploring the beauty of computer graphics and the elegance of ray tracing algorithms.