From 066ff6f74acacb9f37b50c5a3811b61c1296cab1 Mon Sep 17 00:00:00 2001 From: prushton2 Date: Tue, 7 Apr 2026 11:29:59 -0400 Subject: [PATCH 1/2] readme --- README.md | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6c99a3a..8380c43 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,16 @@ This is a custom render engine written in rust and WGSL. ## Features -This render engine provides rendering spheres and quads. These come with a material that takes three parameters: color, reflectivity, and translucency. The material allows you to combine properties in one material. Spheres can be rendered from inside, so feel free to go inside the sphere on the right for a weird experience. Note that a ray can only be recast 4 times before it returns the color of the material it hits instead of casting further. +### Shapes +The render engine provides quads and spheres for rendering. + +### Materials +A Material will let you determine either a solid color or a source texture (only on quads), and also define how translucent and reflective the material is. + +When using textures, you must include the paths of your textures in `GpuHandler::init`. When referencing the texture, the `texture_id` of any texture is the order they are listed in `GpuHandler::init`. + +### GPU Rendering +The `wgpu_handler.rs` file provides heavy abstractions for handling rendering on the gpu. ## Running @@ -19,10 +28,4 @@ $ cargo run --release ### Movement -In the window, you can use WASD to move and your mouse or the arrow keys to look around. Space and LCtrl make you move up and down respectively. - -## Expansion - -Expansion upon this isnt very well supported currently. I have some refactoring to do to make it more manageable. The main issue is once you start dealing with sending stuff to the gpu, where dynamic dispatching doesnt exist. - -If you really want to add a new renderable object, you must implement Renderable and ToGpu for your object. See `src/objects/sphere.rs` for an example. Next, create a buffer in `main.rs` for the GPU version of your object to be sent to the GPU. You must create a field in App for the buffer, instantiate, and bind the buffer. In WGSL, add intersection in `intersection.wgsl`, and in `material.wgsl`, add a dereference for the material. \ No newline at end of file +In the window, you can use WASD to move and your mouse or the arrow keys to look around. Space and LCtrl make you move up and down respectively. \ No newline at end of file From f3afef9ceedb92d615acb78799a1abbd9bddbbce Mon Sep 17 00:00:00 2001 From: prushton2 Date: Wed, 8 Apr 2026 13:28:47 -0400 Subject: [PATCH 2/2] fixed bug where textures were incorrectly applied to quads who didnt have a u/v length of 1 --- src/main.rs | 2 ++ src/shaders/material.wgsl | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index acd1690..8e5540f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -320,6 +320,8 @@ fn main() { Box::new(object::Quad::new(&ds::Vector3::new(1.0, 1.0, 5.0), &ds::Vector3::new(1.0, 0.0, 0.0), &ds::Vector3::new(0.0, 0.0, 1.0), GpuMaterial::texture(2, 0, 0))), Box::new(object::Quad::new(&ds::Vector3::new(1.0, 0.0, 5.0), &ds::Vector3::new(1.0, 0.0, 0.0), &ds::Vector3::new(0.0, 0.0, 1.0), GpuMaterial::texture(0, 0, 0))), + Box::new(object::Quad::new(&ds::Vector3::new(10.0, 2.0, 7.0), &ds::Vector3::new(0.5, 1.0, 0.5), &ds::Vector3::new(1.0, 0.5, 0.0), GpuMaterial::texture(0, 0, 0))), + ]; let event_loop = EventLoop::new().expect("Failed to create event loop"); diff --git a/src/shaders/material.wgsl b/src/shaders/material.wgsl index 3beee88..3ab8cfc 100644 --- a/src/shaders/material.wgsl +++ b/src/shaders/material.wgsl @@ -145,8 +145,10 @@ fn get_texture_color(record: HitRecord) -> vec3 { default: {} } - let pct_across = u32(abs((dot(cross(quad.v, record.normal), record.position - quad.q))*16 / length(quad.v))); - let pct_up = u32(abs((dot(cross(quad.u, record.normal), record.position - quad.q))*16 / length(quad.u))); + let offset = record.position - quad.q; - return textureLoad(textures, vec2u((15-pct_across), (15-pct_up) + 16 * u32(material.texture_id)), 0).rgb * 255.0; + let pct_across = abs(dot(offset, quad.u) / dot(quad.u, quad.u)) * 16.0; + let pct_up = abs(dot(offset, quad.v) / dot(quad.v, quad.v)) * 16.0; + + return textureLoad(textures, vec2u((15-u32(pct_across)), (15-u32(pct_up)) + 16 * u32(material.texture_id)), 0).rgb * 255.0; } \ No newline at end of file