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.
RayTracer.Camera
RayTracer.DistantLight
RayTracer.FixedCameraParams
RayTracer.Light
RayTracer.Material
RayTracer.Object
RayTracer.PointLight
RayTracer.Sphere
RayTracer.Triangle
Base.intersect
RayTracer.compute_screen_coordinates
RayTracer.get_color
RayTracer.get_color
RayTracer.get_direction
RayTracer.get_intensity
RayTracer.get_normal
RayTracer.get_primary_rays
RayTracer.get_shading_info
RayTracer.get_transformation_matrix
RayTracer.load_obj
RayTracer.parse_mtllib!
RayTracer.reflection
RayTracer.reflection
RayTracer.specular_exponent
RayTracer.specular_exponent
RayTracer.triangulate_faces
Camera
RayTracer.Camera
— Type.Camera
The Perspective View Camera Model
Fields:
lookfrom
- Position of the Camera in 3D World Spacelookat
- Point in the 3D World Space where the Camera is Pointingvfov
- Field of View of the Camerafocus
- The focal length of the Camerafixedparams
- An instance ofFixedCameraParams
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}
RayTracer.get_primary_rays
— Method.get_primary_rays(c::Camera)
Takes the configuration of the camera and returns the origin and the direction of the primary rays.
RayTracer.FixedCameraParams
— Type.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 renderedheight
- Height of the image to be rendered
RayTracer.compute_screen_coordinates
— Function.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
.
RayTracer.get_transformation_matrix
— Method.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.
Light
RayTracer.DistantLight
— Type.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)
RayTracer.PointLight
— Type.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)
RayTracer.Light
— Type.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 sourceget_intensity(l::MyCustomLightSource, pt::Vec3, dist::Array)
-dist
is the array representing the distance of the point from the light source
RayTracer.get_direction
— Method.get_direction(l::Light, pt::Vec3)
Returns the direction of light incident from the light source to pt
.
RayTracer.get_intensity
— Method.get_intensity(l::Light, pt::Vec3, dist::Array)
Computed the intensity of the light ray incident at pt
.
RayTracer.get_shading_info
— Method.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 theLight
subtypept
- The Point in 3D Space for which the shading information is queried
Materials
RayTracer.Material
— Type.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.
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)
RayTracer.get_color
— Method.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
.
RayTracer.reflection
— Method.reflection(m::Material)
Returns the reflection coefficient
of the Material m
.
RayTracer.specular_exponent
— Method.specular_exponent(m::Material)
Returns the specular_exponent
of the Material m
.
Objects
RayTracer.Sphere
— Type.Sphere
Sphere is a primitive object.
Fields:
center
- Center of the Sphere in 3D world spaceradius
- Radius of the Spherematerial
- Material of the Sphere
RayTracer.Triangle
— Type.Triangle
Triangle is a primitive object. Any complex object can be represented as a mesh of Triangles.
Fields:
v1
- Vertex 1v2
- Vertex 2v3
- Vertex 3material
- Material of the Triangle
RayTracer.load_obj
— Method.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
.
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
.
RayTracer.triangulate_faces
— Method.RayTracer.Object
— Type.Object
All primitive objects must be a subtype of this. Currently there are two primitive objects present, Triangle
and Sphere
. To add support for custom primitive type, two functions need to be defined - intersect
and get_normal
.
Base.intersect
— Method.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.
RayTracer.get_color
— Method.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.
RayTracer.get_normal
— Method.get_normal(obj::Object, pt, direction)
Returns the normal at the Point pt
of the Object obj
.
RayTracer.reflection
— Method.reflection(obj::Object)
Returns the reflection coefficient
of the material of the Object.
RayTracer.specular_exponent
— Method.specular_exponent(obj::Object)
Returns the specular_exponent
of the material of the Object.