Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
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.
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
8 changes: 5 additions & 3 deletions src/shaders/material.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ fn get_texture_color(record: HitRecord) -> vec3<f32> {
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;
}
Loading