Better readme

This commit is contained in:
Adrien Bouvais 2024-08-22 15:53:15 +02:00
parent ff28d1d0c4
commit 5a0393115e
2 changed files with 49 additions and 12 deletions

View File

@ -1,6 +1,38 @@
# Simple raytracer using zig
I did that to learn zig and ray tracing as it looked fun.
Greatly inspired by [Ray Tracing in a Weekend](https://raytracing.github.io/books/RayTracingInOneWeekend.html)
Project used to introduce me to Zig.
Greatly inspired by [Ray Tracing in a Weekend](https://raytracing.github.io/books/RayTracingInOneWeekend.html).
Added multi-thread and other stuffs.
![alt text](https://github.com/MrBounty/zig-multi-thread-raytracer/blob/main/image%20fullhd.png)
***Generated in 4200s on a Qualcomm X Elite 80.***
# Parameters
They are all in `camera.zig`.
```zig
// Resolution
const aspect_ratio: f64 = 16.0 / 9.0;
const image_width: usize = 2560; // Possible 128, 256, 512, 1024, 1280, 1920, 2560, 3840, 7680
const image_height: usize = image_width / aspect_ratio;
// Ray precision
const samples_per_pixel = 500;
const max_depth = 50;
// Camera lenses
const defocus_angle = 0.6;
const focus_dist = 10;
const vfov = 20;
// Camera position
const lookfrom = vec3{ 13, 2, 3 };
const lookat = vec3{ 0, 0, 0 };
const vup = vec3{ 0, 1, 0 };
// Number of thread to use
const n_threads_to_spawn = 100;
```

View File

@ -32,20 +32,33 @@ const ThreadInfo = struct {
semaphore_ptr: *Semaphore,
};
// Resolution parameters
// Resolution
const aspect_ratio: f64 = 16.0 / 9.0;
const image_width: usize = 2560; // Possible 128, 256, 512, 1024, 1280, 1920, 2560, 3840, 7680
const image_height: usize = image_width / aspect_ratio;
// Ray precision
const samples_per_pixel = 500;
const max_depth = 50;
// Camera lenses
const defocus_angle = 0.6;
const focus_dist = 10;
const vfov = 20;
// Camera position
const lookfrom = vec3{ 13, 2, 3 };
const lookat = vec3{ 0, 0, 0 };
const vup = vec3{ 0, 1, 0 };
// Number of thread to use
const n_threads_to_spawn = 100;
// Global var for multi-thread
var completion_count: usize = 0;
var next_entry_to_do: usize = 0;
var entry_count: usize = 0;
var entry_buffer: [image_width * image_height]Pixel = undefined;
var _camera: *const Camera = undefined;
fn addWork(semaphore_ptr: *Semaphore) void {
@ -166,14 +179,6 @@ pub const Camera = struct {
}
pub fn new(world: *const HittableList) Camera {
const vfov = 20;
const lookfrom = vec3{ 13, 2, 3 };
const lookat = vec3{ 0, 0, 0 };
const vup = vec3{ 0, 1, 0 };
const defocus_angle = 0.6;
const focus_dist = 10;
const camera_center = lookfrom;
const pixel_samples_scale = 1.0 / @as(f64, @floatFromInt(samples_per_pixel));