~ | 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

5208
fps.txt

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
CAM -1 40 40 0 -90 0 1 90 5
CAM -1 40 19 0 -90 0 1 90 5
MAT 255 255 255 0.0 1. 1. // white 0

View File

@ -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()

View File

@ -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)

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);
}

View File

@ -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)

View File

@ -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--];

View File

@ -128,8 +128,8 @@ int main(int argc, char **argv)
recorded_fps.push_back((int)window.getFps());
float y_offset = 0;
float dist_to_obj = 2;
float y_offset = 35;
float dist_to_obj = 55;
float speed = 0.5;
camera->setPosition(glm::vec3(