diff options
| author | ladevieq <ladevie.quentin@gmail.com> | 2021-03-18 23:28:20 +0100 |
|---|---|---|
| committer | ladevieq <ladevie.quentin@gmail.com> | 2021-03-18 23:28:20 +0100 |
| commit | bc1073a020c99ed89967a6b00a9eeb4ab2e160dc (patch) | |
| tree | 544497c811d3f47217995b0833c25691cdac8d41 /shaders | |
| parent | 6c151c00ef2e4f56eedf239341bf320079e1f482 (diff) | |
Display frame time & add aabb ray hit function for future BVH
implementation
Diffstat (limited to 'shaders')
| -rw-r--r-- | shaders/compute.comp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/shaders/compute.comp b/shaders/compute.comp index b70b021..3510d52 100644 --- a/shaders/compute.comp +++ b/shaders/compute.comp @@ -34,6 +34,11 @@ struct sphere { float[3] padding; }; +struct aabb { + vec4 min; + vec4 max; +}; + struct camera { vec4 position; @@ -88,6 +93,29 @@ float rand(vec2 co) { return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); } +bool hit_aabb(aabb b, ray r, float min_t, float max_t) { + for (int axis_index = 0; axis_index < 3; axis_index++) { + float inv_dir = 1.f / r.direction[axis_index]; + float t0 = (b.min[axis_index] - r.origin[axis_index]) * inv_dir; + float t1 = (b.max[axis_index] - r.origin[axis_index]) * inv_dir; + + if (inv_dir < 0.f) { + float temp = t0; + t0 = t1; + t1 = t0; + } + + min_t = max(t0, min_t); + max_t = min(t1, max_t); + + if (max_t < min_t) { + return false; + } + } + + return true; +} + bool hit_sphere(sphere s, ray r, float min_t, float max_t, out hit_info info) { vec3 origin_center = r.origin - s.position.xyz; |
