Renderers
This section describes the renderers available in RayTracer.jl
RayTracer.convert2raster
RayTracer.edge_function
RayTracer.edge_function_vector
RayTracer.fseelight
RayTracer.light
RayTracer.rasterize
RayTracer.raytrace
RayTracer.reducehcat
Documentation
RayTracer.raytrace
— Method.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.
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.
None of the parameters (except global_illumination) in the keyword argument version of raytrace
is optional. It is just present for convenience.
RayTracer.rasterize
— Method.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.
RayTracer.fseelight
— Method.fseelight(n::Int, light_distances)
Checks if the $n^{th}$ object in the scene list can see the light source.
RayTracer.light
— Method.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.
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.
RayTracer.reducehcat
— Method.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.
RayTracer.convert2raster
— Method.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:
RayTracer.edge_function
— Method.edge_function(pt1::Vec3, pt2::Vec3, point::Vec3)
Checks on which side of the line formed by pt1
and pt2
does point
lie.
RayTracer.edge_function_vector
— Method.edge_function_vector(pt1::Vec3, pt2::Vec3, point::Vec3)
Vectoried form of the edge_function