Skip to content

Miou-zora/Zaytracer

Repository files navigation

Zaytracer (Raytracer in zig)

Rendered image of the raytracer

📑 Requirements

Important

You will need to enable nix-command and flakesexperimental features If you get an error about it, consider this command: mkdir -p ~/.config/nix && echo "experimental-features = nix-command flakes" | tee ~/.config/nix/nix.conf

Usage

🔧 Setup

Clone this repository and run nix develop to enter the development environment

git clone https://github.com/Miou-zora/Zaytracer.git
cd Zaytracer
nix develop

👷 Building

Release

zig build -Doptimize=ReleaseFast
# or
nix build

Debug

zig build

🚀 Running

With zig build or zig build -Doptimize=ReleaseFast

# It will build the project and run it. (do nothing if the project is already built)
zig build run
# or you can run the executable directly
./zig-out/bin/Zaytracer

With nix build

./result/bin/Zaytracer

Using direnv

You may load the devShell automatically using direnv shell integration.

echo "use flake" | tee .envrc
direnv allow

Coding with codespace

If you want to works on the project using codespace, follow these instructions:

I. Create a codespace with current configuration

II. Execute mkdir -p ~/.config/nix && echo "experimental-features = nix-command flakes" | tee ~/.config/nix/nix.conf

III. Execute eval "$(direnv hook bash)" for bash or you can find your hook command here

IV. Execute:

echo "use flake" | tee .envrc
direnv allow

Perf

Performance measures

To take performance measures you can use th perf tool like this:

perf record -g ./Zaytracer
perf report -g 'graph,0.5,caller'

You will need a debug build for that, else you won't have debug symbols.

Time measures

You can use the hyperfine tool to measure the time of execution of the program.

If you use nix build:

hyperfine "./result/bin/Zaytracer" --warmup 10

or if you use zig build -Doptimize=ReleaseFast:

hyperfine "./zig-out/bin/Zaytracer" --warmup 10