Skip to content

craqvfx/ray-tracer

Repository files navigation

Ray tracer

Major TO-DOs:

  • Add GUI
  • Output to PNG or similar format instead of PPM

Disclosure

This project was made using the help of the Ray Tracing in One Weekend Book Series. While much of the code is provided in the afore-linked github repository, I typed everything by hand and have implemented features of my own, as is hopefully demonstrated by the commit history.

Code

vec3.h

Defines class for storing 3D vectors. Can be used for locations, colours, directions, offsets, etc.
Describes relevant operators for operations between both scalars and other vector operands.e.g. +=, *=, +, -, etc.
Stores each value as a double
Has alias point3

color.h

Takes a pixel and writes its rgb values in PPM format, converting from linear to gamma 2.

ray.h

Defines ray class that stores information about the ray and has an at(t) function to give the position along that ray at a given time/offset.

Stores the following information about a ray:

  • Origin
  • Direction

at(t) function explained

Position along the ray at a given time/offset can be given as:
Position(time) = origin + (time * direction)
Where origin is a 3D vector representing position, direction is a 3D unit vector, and time is a real value.

camera.h

Defines a class that contains information about the camera all the functionality of the camera.
It should be constructed with no arguments, then the owning code will modify the camera's public variables through simple assignment, then the owning code should call the render function, passing in a world.
This pattern is chosen instead of the owner calling a constructor with a ton of parameters or by defining and calling a bunch of setter methods. Instead, the owning code only needs to set what it explicitly cares about.

Stores the following information about a camera:

public:
  • Aspect ratio
  • Image width
  • Samples per pixel
  • Max depth of ray bounces
  • Vertical view angle (vertical field of view)
  • Point camera is looking from
  • Point camera is looking at
  • Camera-relative "up" direction
private:
  • Image height
  • Color scale factor for a sum of pixels (pixel_samples_scale - To facilitate multiple samples, we add the full color from each sample, and then divide by the number of samples)
  • Camera center
  • Location of pixel (0, 0)
  • Offset to pixel to the right (delta u)
  • Offset to pixel below (delta v)
  • Camera frame basis vectors (u, v, w)
  • Defocus disk horizontal radius
  • Defocus disk vertical radius

Has the following procedures:

public:
  • Render
private:
  • Initialize (run at the beginning of every render)
  • Get ray (Construct a camera ray originating from the defocus disk and directed at randomly sampled point around the pixel location i, j.)
  • Sample square (Returns the vector to a random point in the [-.5,-.5]-[+.5,+.5] unit square.)
  • Defocus disk sample (Returns a random point in the camera defocus disk.)
  • Ray color (Returns color of a ray)

hittable.h

hittable abstract class

Defines abstract class for all objects which should be hittable to inherit from.

hit_record class

Stores the following information about a hit:

  • Point
  • Normal
  • t (time/offset at which ray intersects object)
  • Whether it is a front face

hittable_list.h

Stores a list of hittable objects. Uses shared_ptr to allow for instances and easier memory management.

Has the following public procedures:

  • Add (an object)
  • Hit (whether a ray hits anything)

sphere.h

Defines sphere class that inherets from hittable.h

interval.h

Defines interval class that stores information about a real-valued interval and has procedures to get information about that data.

Stores the following information about an interval:

  • Min point
  • Max point

Has the following public procedures:

  • Size
  • Contains
  • Surrounds

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages