mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
+ | Some change
This commit is contained in:
@ -107,7 +107,7 @@ hitInfo traceRay(Ray ray)
|
||||
{
|
||||
hitInfo hit;
|
||||
|
||||
for (int p = 0; p < 5; p++) //portals
|
||||
for (int p = 0; p < 25; p++) //portals
|
||||
{
|
||||
hit.t = 1e30;
|
||||
hit.obj_index = -1;
|
||||
@ -117,7 +117,7 @@ hitInfo traceRay(Ray ray)
|
||||
GPUObject obj = objects[i];
|
||||
|
||||
hitInfo temp_hit;
|
||||
if (intersect(ray, obj, temp_hit) && temp_hit.t > 0.0f && temp_hit.t < hit.t)
|
||||
if (intersect(ray, obj, temp_hit) && temp_hit.t > 0.0f && temp_hit.t < hit.t + 0.0001)
|
||||
{
|
||||
hit.t = temp_hit.t;
|
||||
hit.obj_index = i;
|
||||
@ -205,7 +205,7 @@ void main()
|
||||
uint rng_state = uint(u_resolution.x) * uint(pixel_coords.y) + pixel_coords.x;
|
||||
rng_state = rng_state + u_frameCount * 719393;
|
||||
|
||||
vec2 jitter = randomPointInCircle(rng_state);
|
||||
vec2 jitter = randomPointInCircle(rng_state) * 1;
|
||||
|
||||
vec2 uv = ((vec2(pixel_coords) + jitter) / u_resolution) * 2.0 - 1.0;;
|
||||
uv.x *= u_resolution.x / u_resolution.y;
|
||||
|
@ -58,60 +58,60 @@ bool intersectQuad(Ray ray, GPUObject obj, out hitInfo hit)
|
||||
|
||||
return (inside);
|
||||
}
|
||||
intersectTriangle(Ray ray, GPUObject obj, out hitInfo hit)
|
||||
{
|
||||
vec3 pvec = cross(ray.direction, obj.vertex2);
|
||||
float det = dot(obj.vertex1, pvec);
|
||||
vec3 tvec = ray.origin - obj.position;
|
||||
|
||||
float invDet = 1.0 / det;
|
||||
float u = dot(tvec, pvec) * invDet;
|
||||
vec3 qvec = cross(tvec, obj.vertex1);
|
||||
float v = dot(ray.direction, qvec) * invDet;
|
||||
float t = dot(obj.vertex2, qvec) * invDet;
|
||||
|
||||
bool valid = abs(det) > 1e-8 &&
|
||||
u >= 0.0 && u <= 1.0 &&
|
||||
v >= 0.0 && (u + v) <= 1.0 &&
|
||||
t > 0.0;
|
||||
|
||||
hit.t = t;
|
||||
hit.position = ray.origin + ray.direction * t;
|
||||
hit.normal = obj.normal * sign(-dot(ray.direction, obj.normal));
|
||||
|
||||
return (valid);
|
||||
}
|
||||
bool
|
||||
|
||||
// bool intersectTriangle(Ray ray, GPUObject obj, out hitInfo hit)
|
||||
// {
|
||||
// vec3 pvec = cross(ray.direction, obj.vertex2);
|
||||
// float det = dot(obj.vertex1, pvec);
|
||||
// vec3 tvec = ray.origin - obj.position;
|
||||
|
||||
// if (abs(det) < 1e-8) return (false); // det < 0.0
|
||||
|
||||
// float invDet = 1.0 / det;
|
||||
|
||||
// vec3 tvec = ray.origin - obj.position;
|
||||
|
||||
// float u = dot(tvec, pvec) * invDet;
|
||||
// if (u < 0.0 || u > 1.0) return (false);
|
||||
|
||||
// vec3 qvec = cross(tvec, obj.vertex1);
|
||||
// float v = dot(ray.direction, qvec) * invDet;
|
||||
// float t = dot(obj.vertex2, qvec) * invDet;
|
||||
// if (v < 0.0 || u + v > 1.0) return (false);
|
||||
|
||||
// bool valid = abs(det) > 1e-8 &&
|
||||
// u >= 0.0 && u <= 1.0 &&
|
||||
// v >= 0.0 && (u + v) <= 1.0 &&
|
||||
// t > 0.0;
|
||||
// float t = dot(obj.vertex2, qvec) * invDet;
|
||||
// if (t <= 0.0) return (false);
|
||||
|
||||
// hit.t = t;
|
||||
// hit.position = ray.origin + ray.direction * t;
|
||||
// hit.normal = obj.normal * sign(-dot(ray.direction, obj.normal));
|
||||
|
||||
// return (valid);
|
||||
// }
|
||||
|
||||
bool intersectTriangle(Ray ray, GPUObject obj, out hitInfo hit)
|
||||
{
|
||||
vec3 pvec = cross(ray.direction, obj.vertex2);
|
||||
float det = dot(obj.vertex1, pvec);
|
||||
|
||||
if (abs(det) < 1e-8) return (false); // det < 0.0
|
||||
|
||||
float invDet = 1.0 / det;
|
||||
|
||||
vec3 tvec = ray.origin - obj.position;
|
||||
|
||||
float u = dot(tvec, pvec) * invDet;
|
||||
if (u < 0.0 || u > 1.0) return (false);
|
||||
|
||||
vec3 qvec = cross(tvec, obj.vertex1);
|
||||
float v = dot(ray.direction, qvec) * invDet;
|
||||
if (v < 0.0 || u + v > 1.0) return (false);
|
||||
|
||||
float t = dot(obj.vertex2, qvec) * invDet;
|
||||
if (t <= 0.0) return (false);
|
||||
|
||||
hit.t = t;
|
||||
hit.position = ray.origin + ray.direction * t;
|
||||
|
||||
vec3 normal = obj.normal;
|
||||
hit.normal = dot(ray.direction, normal) < 0.0 ? normal : -normal;
|
||||
// vec3 normal = obj.normal;
|
||||
// hit.normal = dot(ray.direction, normal) < 0.0 ? normal : -normal;
|
||||
|
||||
return (true);
|
||||
}
|
||||
// return (true);
|
||||
// }
|
||||
|
||||
bool intersectCube(Ray ray, GPUObject obj, out hitInfo hit)
|
||||
{
|
||||
|
Reference in New Issue
Block a user