8000 GitHub - omeldar/raytracer: A simple raytracer built with haskell
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

omeldar/raytracer

Repository files navigation

Raytracer

A raytracer built in Haskell.

🚀 Usage

Run the raytracer with:

cabal run raytracer <config-file.json> +RTS -N -qg -A32M -RTS

The config file lets you customize:

  • Resolution & sampling
  • Camera & scene setup
  • Lighting
  • Raytracer settings (e.g. BVH)

📚 Chapters

This project is documented as a progressive journey. The steps are grouped in own files:

  1. Creating the Image - Basic PPM output & gradients
  2. Progress Bar - Rendering feedback & performance tracking
  3. Vec3 Module - First vector operations and math foundations
  4. Drawing a Circle - First shape before proper ray-sphere logic
  5. The Ray Module - Definition of rays and ray evaluation
  6. Adding a Camera - Camera and background gradient
  7. Sphere Intersection - Algebra and rendering a sphere
  8. Surface Normals & Perspective Projection - Visualization of normals and perspective
  9. Ray-Sphere Simplification & Profiling - Simplyfing the ray-sphere intersection and profiling the Raytracer
  10. Hittable Abstraction - Polymorphism for objects
  11. Multiple Objects - Scene with many spheres
  12. Fixing Perspective - Distortion & focal length
  13. Front vs Back Faces - Handling ray-side normal direction
  14. Anti-Aliasing - Reducing jagged edges
  15. Diffuse Materials - (WIP) Lambertian surfaces
  16. Buffered Writing - Optimizing memory usage
  17. Config Files - Switching from CLI args to JSON configs
  18. Optimizations - Russian Roulette, .OBJ import
  19. Monkey Render - Rendering Blender monkey with triangles
  20. BVH (Bounding Volume Hierarchy) - Huge speedup via spatial acceleration

🖼️ Render Gallery

You can check out my complete gallery on raytracing.omeldar.com

Some of my favorites are:

Spheres, Lights, Shadows
Spheres with lights and shadows. High res and high Anti-Aliasing.
988 triangles scene
Shadows in a 988 triangles scene. 1920x1080, AA-50
63k triangles scene
Shadows in a 63,432 triangles scene. 1920x1080, AA-100

✨ Planned Features and Improvements

🌆 Lighting & Shadows

  • Soft Shadows via Multi-Light Sampling
    Implement soft shadows by spawning multiple sample lights per light source. The number of samples will be configurable through the config file.

  • Light Intensity Control
    Clamp or scale light intensity per light source to avoid overexposed surfaces (e.g., fully white patches).

  • Distance-based lighting
    Light should take less effect when its further away.

🔷 Geometry & Shading

  • Smooth Shading for Triangles
    Add support for smooth shading using vertex normals (3 normals per triangle), enabling smooth transitions between adjacent triangle surfaces.

🚀 Performance

  • Function Profiling and Optimization
    Use GHC’s profiler (+RTS -p) to identify hotspots. Refactor small bottleneck functions (e.g., dot, normalize, hit checks).

  • Memoization of Expensive Calculations
    Cache repeated computations like material scattering, vector math, or normalized directions. Anti-Aliasing can be improved as well by caching pixels in active computation areas (careful because of RAM).

  • Adaptive Sampling Improvements
    Adjust per-pixel sample count based on variance in early samples to save render time.

✨ Materials

  • Caustics and Colored Shadows
    Allow materials to bend light causting colored / caustic shadows.

  • Configurable absorption for materials
    Implement configurable absorption per object for exponential falloff in dielectric objects.

  • Material Assignment and Parsing
    Allow materials to be assigned per object, including support for .mtl file parsing from .obj models. Optionally, override all materials via the config for batch control.

🖼️ Texture Mapping & Image-Based Assets

  • UV Parsing from OBJ Files
    Extend obj parser to support vt texture coordinates and f face triples (v/vt/vn).

  • Textured Triangles
    Interpolate UVs using barycentric coordinates per hit. Sample from image texture.

  • Image Texture Loader
    Use JuicyPixels to load .jpg/.png into a Texture data structure.

  • Skydome from Blender
    Import a textured inverted sphere from Blender as a background. Ensure correct UVs are used.

📚 Implemented, but missing documentation

  • Lighting system & shadows
    Objects cast shadows onto other objects by checking if light source is blocked.

  • Material system
    Objects can have material which cause them to react differently to light.

  • Reflections (Metallic Surfaces)
    Implement reflective behavior for metallic surfaces using the material system.

  • Refractions (Glass-like Materials)
    Add support for transparent, refractive materials with configurable IOR (index of refraction).

  • Support for Multithreading
    Split scanlines or pixel blocks across threads using Haskell’s parallel strategies or async/parMap. Improve core utilization.

About

A simple raytracer built with haskell

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0