Skip to content

djonte/haskell-raytracer

Repository files navigation

Haskell Raytracer

The goal is to follow the "Ray Tracing in One Weekend" guide by Peter Shirley, Trevor David Black and Steve Hollasch with a twist. I'll make it with Haskell. This poses several challenges as my knowledge in Haskell is severely limited (mostly from IndaPlus {first year in KTH} and DD1366 Programmeringsparadigm, where the latter contains a few projects in the language). Another challenge is to convert the thinking of an imperative solution (in which the tutorial is written) to a functional paradigm.

To furthermore make the project fairly unique, I will make sure that my images are different scenes.

Images generated so far

A gradient image

image image

A gradient image generated using y-pos of ray

raytracing-gradient

A circle generated using ray tracing against hardcoded sphere

image

Visualizing sphere's outward normals

Red as a function of x

image

Green as a function of y

image

Blue as a function of z

image

Comment: It should be noted that it is not quite possible to see any substantial change in color in the sphere with the human eye, however upon analysis with Paint it is noticable as a slight decrease in the amount of blue moving towards the edges of the picture, in accordance with expectations. To make this easier to demonstrate I made a modification where I let the blue and green be dependant on the z coordinate of the normalized outer normals of the sphere raised to the power 8. This increases the color change per z coordinate change drastically, see below. image

Red, green and blue as a function of x, y and z respectively

image

2 spheres, both with green and blue as a function of y

image

World and antialiasing

Sphere with visualized normals, and ground

image

Above but with antialiasing (see edges)

image

A diffuse sphere

One sphere

image

Two spheres

image

Three spheres

image

Four spheres

image

How to run the project

  1. Clone the repository

    Open your terminal and run the following command:

    git clone https://github.com/djonte/haskell-raytracer.git
  2. Navigate to the project directory

    cd haskell-raytracer
  3. Install the dependancies

    stack install
  4. Build and run the project

    stack run

Implementation

The solution will be implemented using Haskell.

Resolver

lts-20.26

Image generation

Haskell Image Processing Library (HIP)

3d vectors

Linear

About

Haskell Raytracer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors