mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
~ | Even more optimizing
This commit is contained in:
@ -123,6 +123,7 @@ struct Ray
|
||||
{
|
||||
vec3 origin;
|
||||
vec3 direction;
|
||||
vec3 inv_direction;
|
||||
};
|
||||
|
||||
struct hitInfo
|
||||
@ -211,7 +212,7 @@ Ray initRay(vec2 uv, inout uint rng_state)
|
||||
origin += right * lens_point.x + up * lens_point.y;
|
||||
ray_direction = normalize(focal_point - origin);
|
||||
|
||||
return (Ray(origin, ray_direction));
|
||||
return (Ray(origin, ray_direction, 1.0 / ray_direction));
|
||||
}
|
||||
|
||||
void main()
|
||||
|
@ -207,7 +207,7 @@ Ray initRay(vec2 uv)
|
||||
vec3 view_space_ray = normalize(vec3(uv.x, uv.y, -focal_length));
|
||||
vec3 ray_direction = normalize((inverse(camera.view_matrix) * vec4(view_space_ray, 0.0)).xyz);
|
||||
|
||||
return (Ray(origin, ray_direction));
|
||||
return (Ray(origin, ray_direction, (1.0 / ray_direction)));
|
||||
}
|
||||
|
||||
vec3 debugColor(vec2 uv)
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -34,7 +34,7 @@ vec3 sampleSphereLight(vec3 position, GPUObject obj, int light_index, GPUMateria
|
||||
vec3 light_dir = normalize(sample_point - position);
|
||||
float light_dist = length(sample_point - position);
|
||||
|
||||
Ray shadow_ray = Ray(position + light_dir * 0.001, light_dir);
|
||||
Ray shadow_ray = Ray(position + light_dir * 0.001, light_dir, (1.0 / light_dir));
|
||||
hitInfo shadow_hit = traceRay(shadow_ray);
|
||||
|
||||
if (shadow_hit.obj_index != light_index)
|
||||
@ -53,7 +53,7 @@ vec3 sampleQuadLight(vec3 position, GPUObject obj, int light_index, GPUMaterial
|
||||
vec3 light_dir = normalize(sample_point - position);
|
||||
float light_dist = length(sample_point - position);
|
||||
|
||||
Ray shadow_ray = Ray(position + light_dir * 0.001, light_dir);
|
||||
Ray shadow_ray = Ray(position + light_dir * 0.001, light_dir, (1.0 / light_dir));
|
||||
hitInfo shadow_hit = traceRay(shadow_ray);
|
||||
|
||||
if (shadow_hit.obj_index != light_index)
|
||||
@ -82,7 +82,7 @@ vec3 sampleLights(vec3 position, inout uint rng_state)
|
||||
vec3 light_dir = normalize(obj.position - position);
|
||||
float light_dist = length(obj.position - position);
|
||||
|
||||
Ray shadow_ray = Ray(position + light_dir * 0.01, light_dir);
|
||||
Ray shadow_ray = Ray(position + light_dir * 0.01, light_dir, (1.0 / light_dir));
|
||||
hitInfo shadow_hit = traceRay(shadow_ray);
|
||||
|
||||
if (shadow_hit.obj_index == light_index)
|
||||
|
@ -64,7 +64,7 @@ hitInfo traceBVH(Ray ray)
|
||||
int stack[32];
|
||||
int stack_ptr = 0;
|
||||
stack[0] = 0;
|
||||
|
||||
|
||||
while (stack_ptr >= 0)
|
||||
{
|
||||
int current_index = stack[stack_ptr--];
|
||||
|
Reference in New Issue
Block a user