Scene Configuration

This page provides the details about how to configure the parameters of the scene. For a more hands on tutorial see Introduction to rendering using RayTracer.jl.

Camera

RayTracer.CameraType
Camera

The Perspective View Camera Model

Fields:

  • lookfrom - Position of the Camera in 3D World Space
  • lookat - Point in the 3D World Space where the Camera is Pointing
  • vfov - Field of View of the Camera
  • focus - The focal length of the Camera
  • fixedparams - An instance of FixedCameraParams

Available Constructors:

  • Camera(;lookfrom = Vec3(0.0f0), lookat = Vec3(0.0f0), vup = Vec3(0.0f0, 1.0f0, 0.0f0), vfov = 90.0f0, focus = 1.0f0, width = 128, height = 128)
  • Camera(lookfrom::Vec3{T}, lookat::Vec3{T}, vup::Vec3{T}, vfov::R, focus::R, width::Int, height::Int) where {T<:AbstractArray, R<:Real}
source
RayTracer.FixedCameraParamsType
FixedCameraParams

The Parameters of the Camera which should not be updated in inverse rendering are wrapped into this object.

Fields:

  • vup - Stores the World UP Vector (In most cases this is the Y-Axis Vec3(0.0, 1.0, 0.0))
  • width - Width of the image to be rendered
  • height - Height of the image to be rendered
source
RayTracer.compute_screen_coordinatesFunction
compute_screen_coordinates(c::Camera, film_aperture::Tuple,
                           inch_to_mm::Real = 25.4)

Computes the coordinates of the 4 corners of the screen and returns top, right, bottom, and left.

source
RayTracer.get_primary_raysMethod
get_primary_rays(c::Camera)

Takes the configuration of the camera and returns the origin and the direction of the primary rays.

source
RayTracer.get_transformation_matrixMethod
get_transformation_matrix(c::Camera)

Returns the camera_to_world transformation matrix. This is used for transforming the coordinates of a Point in 3D Camera Space to 3D World Space using the camera2world function.

source

Light

RayTracer.DistantLightType
DistantLight

A source of light that is present at infinity as such the rays from it are in a constant direction. The intensity for this light source always remains constant. This is extremely useful when we are trying to render a large scene like a city.

Fields:

  • color - Color of the Light Rays emitted from the Source.
  • intensity - Intensity of the Light Source.
  • direction - Direction of the Light Rays emitted by the Source.

Available Constructors:

  • DistantLight(;color = Vec3(1.0f0), intensity::Real = 1.0f0, direction = Vec3(0.0f0, 1.0f0, 0.0f0))
  • DistantLight(color, intensity::Real, direction)
source
RayTracer.LightType
Light

All objects emitting light should be a subtype of this. To add a custom light source, two only two functions need to be defined.

  • get_direction(l::MyCustomLightSource, pt::Vec3) - pt is the point receiving the light from this source
  • get_intensity(l::MyCustomLightSource, pt::Vec3, dist::Array) - dist is the array representing the distance of the point from the light source
source
RayTracer.PointLightType
PointLight

A source of light which emits light rays from a point in 3D space. The intensity for this light source diminishes as inverse square of the distance from the point.

Fields:

  • color - Color of the Light Rays emitted from the source.
  • intensity - Intensity of the Light Source. This decreases as $\frac{1}{r^2}$ where $r$ is the distance of the point from the light source.
  • position - Location of the light source in 3D world space.

Available Constructors:

  • PointLight(;color = Vec3(1.0f0), intensity::Real = 100.0f0, position = Vec3(0.0f0))
  • PointLight(color, intensity::Real, position)
source
RayTracer.get_shading_infoMethod
get_shading_info(l::Light, pt::Vec3)

Returns the direction of light incident from the light source onto that Point and the intensity of that light ray. It computes these by internally calling the get_direction and get_intensity functions and hence this function never has to be modified for any Light subtype.

Arguments:

  • l - The Object of the Light subtype
  • pt - The Point in 3D Space for which the shading information is queried
source

Materials

RayTracer.MaterialType
Material

This Type stores information about the material of an Object. We compute the color of a point by dispatching on the type of the material. That is why we store nothing when a particular field is absent.

Note

texture_* and uv_coordinates fields are applicable only if the object used is a Triangle. If any of the texture fields are present, uv_coordinates must be present.

Fields:

  • color_ambient - The Ambient Color of the Material.
  • color_diffuse - The Diffuse Color of the Material.
  • color_specular - The Specular Color of the Material.
  • specular_exponent - Specular Exponent of the Material.
  • reflection - The reflection coefficient of the material.
  • texture_ambient - Stores the ambient texture image (if present) in Vec3 format.
  • texture_diffuse - Stores the diffuse texture image (if present) in Vec3 format.
  • texture_specular - Stores the specular texture image (if present) in VEc3 format.
  • uv_coordinates - The uv coordinates are stored as a vector (of length 3) of tuples.

Available Constructors

Material(;color_ambient = Vec3(1.0f0), color_diffuse = Vec3(1.0f0),
          color_specular = Vec3(1.0f0), specular_exponent::Real = 50.0f0,
          reflection::Real = 0.5f0, texture_ambient = nothing, 
          texture_diffuse = nothing, texture_specular = nothing,
          uv_coordinates = nothing)
source
RayTracer.get_colorMethod
get_color(m::Material, pt::Vec3, ::Val{T}, obj::Object)

Returns the color at the point pt. We use T and the type of the Material m for efficiently dispatching to the right function. The right function is determined by the presence/absence of the texture field. The possible values of T are :ambient, :diffuse, and :specular.

source

Objects

RayTracer.SphereType
Sphere

Sphere is a primitive object.

Fields:

  • center - Center of the Sphere in 3D world space
  • radius - Radius of the Sphere
  • material - Material of the Sphere
source
RayTracer.TriangleType
Triangle

Triangle is a primitive object. Any complex object can be represented as a mesh of Triangles.

Fields:

  • v1 - Vertex 1
  • v2 - Vertex 2
  • v3 - Vertex 3
  • material - Material of the Triangle
source
RayTracer.load_objMethod
load_obj(file; outtype = Float32)

Parser for obj file. It returns a set of Triangles that make up the scene.

Only the following things are parsed as of now: v, vt, vn, f, usemtl and mtllib.

source
RayTracer.parse_mtllib!Method
parse_mtllib!(file, material_map, outtype)

Parses .mtl file and creates a map from the material name to Material objects.

Not all fields of the mtl file are parsed. We only parse : newmtl, Ka, Kd, Ks, Ns, d, Tr, map_Kd, map_Ks, and map_Ka.

source
RayTracer.triangulate_facesMethod
triangulate_faces(vertices::Vector, texture_coordinates::Vector,
                  faces::Vector, material_map::Dict)

Triangulates the faces and converts it into valid Triangle objects.

Warning

Avoid using this function in itself. It is designed to be used internally by the load_obj function.

source
Base.intersectMethod
intersect(obj::Object, origin, direction)

Computes the intersection of the light ray with the object. This function returns the $t$ value where $intersection\_point = origin + t \times direction$. In case the ray does not intersect with the object Inf is returned.

source
RayTracer.get_colorMethod
get_color(obj::Object, pt::Vec3, sym::Val)

Computes the color at the point pt of the Object obj by dispatching to the correct get_color(obj.material, pt, sym, obj) method.

source