diff --git a/src/main.odin b/src/main.odin new file mode 100644 index 0000000..e6e01c0 --- /dev/null +++ b/src/main.odin @@ -0,0 +1,66 @@ +package main + +import rl "vendor:raylib" +import "core:fmt" + + +WINDOW_WIDTH :: 1280 +WINDOW_HEIGHT :: 720 + +rl_window_loop :: proc() { + rl.InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Rayt"); + defer rl.CloseWindow() + + + rl_image := rl.Image { + data = raw_data(pixelbuffer_rgb), + width = cast(i32)image.width, + height = cast(i32)image.height, + mipmaps = 1, + format = .UNCOMPRESSED_R8G8B8 + } + defer rl.UnloadImage(rl_image) + fmt.println("Created raylib image from rgb data") + + + texture := rl.LoadTextureFromImage(rl_image) + defer rl.UnloadTexture(texture) + fmt.println("Loaded texture from image") + //rl_window_loop(texture) + + + + + for !rl.WindowShouldClose() { + + + rl.BeginDrawing() + rl.ClearBackground(rl.BLUE) + + rl.DrawTexture(texture, 0, 0, rl.WHITE) + + rl.DrawCircle(400, 300, 50, rl.GREEN) + rl.DrawLine(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, rl.BLUE) + + + rl.DrawCircle(100, 100, 120, rl.RED) + + + rl.EndDrawing() + + } + + + + +} + +main :: proc() { + + // Fill pixelbuffer with raytraced image. + rayt_cpu_main() + + fmt.println("Finished raytracing, launching Raylib window") + + rl_window_loop() +} diff --git a/src/base_core.cu b/src/old_cuda_c_src/old_base_core.cu similarity index 100% rename from src/base_core.cu rename to src/old_cuda_c_src/old_base_core.cu diff --git a/src/base_core.cuh b/src/old_cuda_c_src/old_base_core.cuh similarity index 100% rename from src/base_core.cuh rename to src/old_cuda_c_src/old_base_core.cuh diff --git a/src/base_math.cu b/src/old_cuda_c_src/old_base_math.cu similarity index 100% rename from src/base_math.cu rename to src/old_cuda_c_src/old_base_math.cu diff --git a/src/base_math.cuh b/src/old_cuda_c_src/old_base_math.cuh similarity index 100% rename from src/base_math.cuh rename to src/old_cuda_c_src/old_base_math.cuh diff --git a/src/main.cu b/src/old_cuda_c_src/old_cuda_main.cu similarity index 100% rename from src/main.cu rename to src/old_cuda_c_src/old_cuda_main.cu diff --git a/src/rayt_bvh.cu b/src/old_cuda_c_src/old_rayt_bvh.cu similarity index 100% rename from src/rayt_bvh.cu rename to src/old_cuda_c_src/old_rayt_bvh.cu diff --git a/src/rayt_bvh.cuh b/src/old_cuda_c_src/old_rayt_bvh.cuh similarity index 100% rename from src/rayt_bvh.cuh rename to src/old_cuda_c_src/old_rayt_bvh.cuh diff --git a/src/rayt_core.cu b/src/old_cuda_c_src/old_rayt_core.cu similarity index 100% rename from src/rayt_core.cu rename to src/old_cuda_c_src/old_rayt_core.cu diff --git a/src/rayt_core.cuh b/src/old_cuda_c_src/old_rayt_core.cuh similarity index 100% rename from src/rayt_core.cuh rename to src/old_cuda_c_src/old_rayt_core.cuh diff --git a/src/rayt_base.odin b/src/rayt_base.odin new file mode 100644 index 0000000..7b83ab5 --- /dev/null +++ b/src/rayt_base.odin @@ -0,0 +1,166 @@ +package main + +import "core:fmt" +import "core:math/rand" + +RAND_SEED :: 1984 + +// Global program parameters +IMAGE_WIDTH :: 1280 +ASPECT_RATIO :: 1.7778 // 16:9 + +MAX_NUM_ENTITIES :: 64 + +Vec3 :: distinct [3]f32 + +Image :: struct { + width : u32, + height : u32, + aspect_ratio : f32 +} +image: Image + + +Camera :: struct { + center : Vec3, + up : Vec3, + focal_length : f32, +} +camera: Camera + +Viewport :: struct { + width : f32, + height : f32, + aspect_ratio : f32, + u : Vec3, + v : Vec3, + upper_left : Vec3, + pixel_origin : Vec3, + pixel_delta_u : Vec3, + pixel_delta_v : Vec3, +} +viewport: Viewport + +HitRecord :: struct { + point : Vec3, + normal : Vec3, + t : f32, + hit : b32, + front_face : b32, +} + +EntityKind :: enum { + Tri +} + +Entity :: struct { + kind: EntityKind, + center: Vec3, + v0: Vec3, + v1: Vec3, + v2: Vec3, +} +entities: [MAX_NUM_ENTITIES]Entity + +pixelbuffer: []Vec3 +pixelbuffer_rgb: []u8 + +vec3_rand_uniform :: proc() -> Vec3 { + return Vec3{rand.float32(), rand.float32(), rand.float32()} +} + +rayt_cpu_main :: proc() { + rand.reset(RAND_SEED) + + // Random triangles + { + center_shift := Vec3{5.0, 5.0, 5.0} + // Generate triangles inside a box + for i in 0..