Skip to content

Commit

Permalink
fix(/wiki/raycasting): smol stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Longor1996 committed Dec 9, 2023
1 parent 5dc069e commit f1a943f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
15 changes: 10 additions & 5 deletions content/wiki/raycasting/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,27 @@ adapted to 3D, is *exactly* the thing one needs to travel along a line (or a ray
<!-- more -->

{{ stub_notice() }}
## Implementation:
## Implementation

### Ray Generation
With raycasting, we need to construct a ray for each pixel on the screen, represented by the camera. The following implementation is based on [this library](https://github.com/dps/rust-raytracer/tree/main/raytracer). It should be noted that this is mostly for demonstration pourposes, and its probably not going to be that fast in comparison to other ray generation algorithms.
To raycast, we first need to construct a ray for each pixel on the screen, as represented by a camera.

{% info_notice() %}
The following implementation, based on [this library](https://github.com/dps/rust-raytracer/tree/main/raytracer), is for demonstration purposes and as such isn't particularly fast.
{% end %}

{{ embed_text(file="ray_building.glsl", lang="glsl") }}
{{ embed_text(file="ray_build.glsl", lang="glsl") }}

### Casting Rays
Once a ray is generated, it has to be cast into a voxel volume.
The following algorithm is a 3D implementation of the DDA algorithm published in [this paper](http://www.cse.yorku.ca/~amana/research/grid.pdf).
The following implementation is based on the algorithm published in [the original paper](#paper).

{{ embed_text(file="dda.glsl", lang="glsl") }}

## References

- [Wikipedia](https://en.wikipedia.org/wiki/Digital_differential_analyzer_(graphics_algorithm))
- Paper: [A Fast Voxel Traversal Algorithm for Ray Tracing (1987)](http://www.cse.yorku.ca/~amana/research/grid.pdf)
- <span id=paper>Original Paper:</span> [A Fast Voxel Traversal Algorithm for Ray Tracing (1987)](http://www.cse.yorku.ca/~amana/research/grid.pdf)
- [Voxel Rendering Using Discrete Ray Tracing](https://castingrays.blogspot.com/2014/01/voxel-rendering-using-discrete-ray.html)
- [Cast ray to select block in voxel game](https://gamedev.stackexchange.com/a/49423)
- [Lode's Raycasting Tutorial](https://lodev.org/cgtutor/raycasting.html)
Expand Down
15 changes: 6 additions & 9 deletions content/wiki/raycasting/ray_build.glsl
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
struct Camera
{
struct Camera {
vec3 eye;
vec3 target;
float fov;
};
}

struct Ray
{
struct Ray {
vec3 origin;
vec3 dir;
};
}

Ray create_ray(uint x, uint y, uint width, uint height, Camera camera)
{
Ray create_ray(uint x, uint y, uint width, uint height, Camera camera) {
float aspect = float(width) / float(height); // get the aspect ratio of the image
float theta = radians(camera.fov);
float half_height = tan(theta / 2.0);
Expand All @@ -32,4 +29,4 @@ Ray create_ray(uint x, uint y, uint width, uint height, Camera camera)
vec3 dir = normalize(lower_left_corner + (horizontal * xu) + (vertical * yv) - origin);

return Ray(origin, dir);
}
}

0 comments on commit f1a943f

Please sign in to comment.