Skip to content

SaiCharanMarrivada/ray-tracing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Code Style: Blue

ray-tracing

A simple pure Julia implementation of the book Ray Tracing in One Weekend.

Running the code

The code has no dependencies other than StaticArrays, which is used for various structs. The ray-traced image can be generated by running the following command.

# Generate the ray-traced image
julia -t<nthreads> --optimize=3 -C native main.jl > image.ppm

The generated image can be viewed with any image viewer.

Implementation details

Vector4 (an alias for SVector{4}) is used instead of SVector{3}, with the fourth component being ignored. All operations on Vector4s require fewer instructions compared to operations on Vector3s, at the expense of slightly more memory usage.

Example

v = Vector4{Float64}(ones(4))
w = Vector4{Float64}(ones(4))

@code_native v .* w

Assembly output for element-wise product of Vector4s:

mov rax, rdi
vmovupd ymm0, ymmword ptr [rsi]
vmulpd ymm0, ymm0, ymmword ptr [rdx]
vmovupd	ymmword ptr [rdi], ymm0
vzeroupper
ret
v = Vector3{Float64}(ones(3))
w = Vector3{Float64}(ones(3))

@code_native v .* w

Assembly output for element-wise product of Vector3s:

mov rax, rdi
vmovsd xmm0, qword ptr [rsi + 16]
vmulsd xmm0, xmm0, qword ptr [rdx + 16]
vmovupd	xmm1, xmmword ptr [rsi]
vmulpd xmm1, xmm1, xmmword ptr [rdx]
vmovupd	xmmword ptr [rdi], xmm1
vmovsd qword ptr [rdi + 16], xmm0
ret

About

A simple julia implementation of Ray Tracing in One Weekend.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages