raytrace: Ray tracing library

[ bsd3, graphics, library ] [ Propose Tags ] [ Report a vulnerability ]

A Haskell ray tracing library. Largely based on the books Ray Tracing in One Weekend and Ray Tracing: The Next Week by Peter Shirley.

See README.md for more information.


[Skip to Readme]

Modules

  • Graphics
    • Graphics.Ray
      • Graphics.Ray.Core
      • Graphics.Ray.Geometry
      • Graphics.Ray.Material
      • Graphics.Ray.Noise
      • Graphics.Ray.Texture

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Change log CHANGELOG.md
Dependencies base (>=4.17.2.1 && <5), Color (>=0.4.0 && <0.5), linear (>=1.23.2 && <1.24), massiv (>=1.0.5 && <1.1), massiv-io (>=1.0.0 && <1.1), mtl (>=2.2.2 && <2.3), random (>=1.3.0 && <1.4) [details]
License BSD-3-Clause
Author Owen Bechtel
Maintainer ombspring@gmail.com
Category Graphics
Uploaded by OwenBechtel at 2025-07-19T03:44:54Z
Distributions
Downloads 3 total (3 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
All reported builds failed as of 2025-07-19 [all 2 reports]

Readme for raytrace-0.1.0.0

[back to package description]

raytrace

A Haskell ray tracing library. Largely based on the books Ray Tracing in One Weekend and Ray Tracing: The Next Week by Peter Shirley.

Features:

  • Spheres, parallelograms, and boxes (you can define your own shapes in addition to these)
  • Volumes (fog and the like)
  • A variety of materials, with behaviors including light emission and refraction
  • Texture mapping
  • Perlin noise for procedurally generated textures
  • Parallel computation of pixels
  • Bounding volume hierarchies
  • Affine transformations (rotation, translation, and so on)
  • Optional defocusing to simulate a real camera lens

Possible future additions:

  • Motion blur
  • Triangular meshes
  • Less noise in scenes with small light sources

Example

The image above, with 405 million top-level rays, was generated on my laptop in about 8 minutes. The blurriness in the foreground and background is due to defocusing, wherein only a single plane is in focus. The following image demonstrates texture mapping, light sources, and fog:

Example

(The code for both of these images was based on code in the aforementioned books.)

Example Usage

module Main where

import Graphics.Ray
import Linear (V3(V3))
import System.Random (newStdGen)
import Data.Functor.Identity (Identity)

world :: Geometry Identity Material
world = group
  [ lambertian (checkerTexture 20 10 0.2 0.8) <$ sphere (V3 0 0 0) 1
  , lambertian (constantTexture (V3 0 0.2 0.5)) <$ sphere (V3 0 (-1000) 0) 999
  , mirror (constantTexture 0.8) <$ parallelogram (V3 (-3.25) (-1) (-0.75)) (V3 1.25 0 (-1.25)) (V3 0 2 0)
  ]

settings :: CameraSettings
settings = defaultCameraSettings
  { cs_center = V3 (-0.75) 0 2
  , cs_lookAt = V3 0 0 (-1)
  , cs_aspectRatio = 16 / 9
  , cs_imageWidth = 600
  , cs_samplesPerPixel = 50
  }

main :: IO ()
main = do
  seed <- newStdGen
  writeImage "example_image.png" (raytrace settings world seed)

This produces the following image:

Example