mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 10:48:34 +02:00
~ | Even more optimizing
This commit is contained in:
@ -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
|
MAT 255 255 255 0.0 1. 1. // white 0
|
||||||
|
|
||||||
|
@ -123,6 +123,7 @@ struct Ray
|
|||||||
{
|
{
|
||||||
vec3 origin;
|
vec3 origin;
|
||||||
vec3 direction;
|
vec3 direction;
|
||||||
|
vec3 inv_direction;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct hitInfo
|
struct hitInfo
|
||||||
@ -211,7 +212,7 @@ Ray initRay(vec2 uv, inout uint rng_state)
|
|||||||
origin += right * lens_point.x + up * lens_point.y;
|
origin += right * lens_point.x + up * lens_point.y;
|
||||||
ray_direction = normalize(focal_point - origin);
|
ray_direction = normalize(focal_point - origin);
|
||||||
|
|
||||||
return (Ray(origin, ray_direction));
|
return (Ray(origin, ray_direction, 1.0 / ray_direction));
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
|
@ -207,7 +207,7 @@ Ray initRay(vec2 uv)
|
|||||||
vec3 view_space_ray = normalize(vec3(uv.x, uv.y, -focal_length));
|
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);
|
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)
|
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)
|
bool intersectRayBVH(Ray ray, GPUBvh node, inout hitInfo hit)
|
||||||
{
|
{
|
||||||
vec3 invDir = 1.0 / ray.direction;
|
// vec3 inv_direction = 1.0 / ray.direction;
|
||||||
|
|
||||||
vec3 t1 = (node.min - ray.origin) * invDir;
|
vec3 t1 = (node.min - ray.origin) * ray.inv_direction;
|
||||||
vec3 t2 = (node.max - ray.origin) * invDir;
|
vec3 t2 = (node.max - ray.origin) * ray.inv_direction;
|
||||||
|
|
||||||
vec3 tMin = min(t1, t2);
|
vec3 tMin = min(t1, t2);
|
||||||
vec3 tMax = max(t1, t2);
|
vec3 tMax = max(t1, t2);
|
||||||
|
|
||||||
hit.t = max(max(tMin.x, tMin.y), tMin.z);
|
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);
|
vec3 light_dir = normalize(sample_point - position);
|
||||||
float light_dist = length(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);
|
hitInfo shadow_hit = traceRay(shadow_ray);
|
||||||
|
|
||||||
if (shadow_hit.obj_index != light_index)
|
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);
|
vec3 light_dir = normalize(sample_point - position);
|
||||||
float light_dist = length(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);
|
hitInfo shadow_hit = traceRay(shadow_ray);
|
||||||
|
|
||||||
if (shadow_hit.obj_index != light_index)
|
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);
|
vec3 light_dir = normalize(obj.position - position);
|
||||||
float light_dist = length(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);
|
hitInfo shadow_hit = traceRay(shadow_ray);
|
||||||
|
|
||||||
if (shadow_hit.obj_index == light_index)
|
if (shadow_hit.obj_index == light_index)
|
||||||
|
@ -64,7 +64,7 @@ hitInfo traceBVH(Ray ray)
|
|||||||
int stack[32];
|
int stack[32];
|
||||||
int stack_ptr = 0;
|
int stack_ptr = 0;
|
||||||
stack[0] = 0;
|
stack[0] = 0;
|
||||||
|
|
||||||
while (stack_ptr >= 0)
|
while (stack_ptr >= 0)
|
||||||
{
|
{
|
||||||
int current_index = stack[stack_ptr--];
|
int current_index = stack[stack_ptr--];
|
||||||
|
@ -128,8 +128,8 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
recorded_fps.push_back((int)window.getFps());
|
recorded_fps.push_back((int)window.getFps());
|
||||||
|
|
||||||
float y_offset = 0;
|
float y_offset = 35;
|
||||||
float dist_to_obj = 2;
|
float dist_to_obj = 55;
|
||||||
float speed = 0.5;
|
float speed = 0.5;
|
||||||
|
|
||||||
camera->setPosition(glm::vec3(
|
camera->setPosition(glm::vec3(
|
||||||
|
Reference in New Issue
Block a user