~ | Even more optimizing

This commit is contained in:
TheRedShip
2025-01-19 15:30:27 +01:00
parent 8f70e282b3
commit d0d67b8bd7
8 changed files with 2862 additions and 2377 deletions

View File

@ -227,18 +227,18 @@ bool intersect(Ray ray, GPUObject obj, out hitInfo hit)
bool intersectRayBVH(Ray ray, GPUBvh node, inout hitInfo hit)
{
vec3 invDir = 1.0 / ray.direction;
vec3 t1 = (node.min - ray.origin) * invDir;
vec3 t2 = (node.max - ray.origin) * invDir;
// vec3 inv_direction = 1.0 / ray.direction;
vec3 t1 = (node.min - ray.origin) * ray.inv_direction;
vec3 t2 = (node.max - ray.origin) * ray.inv_direction;
vec3 tMin = min(t1, t2);
vec3 tMax = max(t1, t2);
hit.t = max(max(tMin.x, tMin.y), tMin.z);
hit.last_t = min(min(tMax.x, tMax.y), tMax.z);
float last_t = min(min(tMax.x, tMax.y), tMax.z);
return hit.t <= hit.last_t && hit.last_t >= 0.0;
return (hit.t <= last_t && last_t >= 0.0);
}