Renderers

Renderers

This section describes the renderers available in RayTracer.jl

Documentation

RayTracer.raytraceMethod.
raytrace(origin::Vec3, direction::Vec3, scene::Vector, lgt::Light,
         eye_pos::Vec3, bounce::Int)
raytrace(origin::Vec3, direction::Vec3, scene, lgt::Vector{Light},
         eye_pos::Vec3, bounce::Int)
raytrace(origin::Vec3, direction::Vec3, scene::BoundingVolumeHierarchy,
         lgt::Light, eye_pos::Vec3, bounce::Int)
raytrace(;origin = nothing, direction = nothing, scene = nothing,
          light_source = nothing, global_illumination = false)

Computes the color contribution to every pixel by tracing every single ray. Internally it calls the light function which implements Blinn Phong Rendering and adds up the color contribution for each object.

The eye_pos is simply the origin when called by the user. However, the origin keeps changing across the recursive calls to this function and hence it is necessary to keep track of the eye_pos separately.

The bounce parameter allows the configuration of global illumination. To turn off global illumination set the bounce parameter to >= 2. As expected rendering is much faster if global illumination is off but at the same time is much less photorealistic.

Note

The support for multiple lights is primitive as we loop over the lights. Even though it is done in a parallel fashion, it is not the best way to do so. Nevertheless it exists just for the sake of experimentation.

Note

None of the parameters (except global_illumination) in the keyword argument version of raytrace is optional. It is just present for convenience.

source

rasterize(cam::Camera, scene::Vector) rasterize(cam::Camera, scene::Vector, cameratoworld, worldtocamera, top, right, bottom, left)

Implements the raterization algorithm. This is extremely fast when compared to the raytrace function. However, the image generated is much less photorealistic with no lighting effects.

source
fseelight(n::Int, light_distances)

Checks if the $n^{th}$ object in the scene list can see the light source.

source
RayTracer.lightMethod.
light(s::Object, origin, direction, dist, lgt::Light, eye_pos, scene, obj_num, bounce)

Implements the Blinn Phong rendering algorithm. This function is merely for internal usage and should in no case be called by the user. This function is quite general and supports user defined Objects. For support of custom Objects have a look at the examples.

Warning

Don't try to use this function by itself. But if you are a person who likes to ignore warnings look into the way raytrace calls this.

source
reducehcat(x)

This is simply reduce(hcat(x)). The version of Zygote we are currently using can't differentiate through this function. So we define a custom adjoint for this.

source
convert2raster(vertex_world::Vec3, world_to_camera, left::Real, right::Real,
               top::Real, bottom::Real, width::Int, height::Int)
convert2raster(vertex_camera::Vec3{T}, left::Real, right::Real, top::Real, bottom::Real,
               width::Int, height::Int) where {T}

Converts a Point in 3D world space to the 3D raster space. The conversion is done by the following steps:

\[V_{camera} = World2CameraTransform(V_{world})\]
\[V_{screen_x} = -\frac{V_{camera_x}}{V_{camera_z}}\]
\[V_{screen_y} = -\frac{V_{camera_y}}{V_{camera_z}}\]
\[V_{NDC_x} = \frac{2 \times V_{screen_x} - right - left}{right - left}\]
\[V_{NDC_y} = \frac{2 \times V_{screen_y} - top - bottom}{top - bottom}\]
\[V_{raster_x} = \frac{V_{NDC_x} + 1}{2 \times width}\]
\[V_{raster_y} = \frac{1 - V_{NDC_y}}{2 \times height}\]
\[V_{raster_z} = - V_{camera_z}\]
source
edge_function(pt1::Vec3, pt2::Vec3, point::Vec3)

Checks on which side of the line formed by pt1 and pt2 does point lie.

source
edge_function_vector(pt1::Vec3, pt2::Vec3, point::Vec3)

Vectoried form of the edge_function

source