+ | Some change

This commit is contained in:
RedShip
2025-01-09 18:54:00 +01:00
parent ec765f9e73
commit 0ece075f1a
5 changed files with 46 additions and 44 deletions

View File

@ -1,3 +1,4 @@
CAM 0.361576 0.0380219 0.276604 -78.8 231.6 0 1
MAT 255 255 255 0.0 0.0 0.0
MAT 255 255 255 3.0 0.0 0.0

View File

@ -1,8 +1,8 @@
CAM -7 10 6
CAM -7 10 6 -19.4 -50 0 1
MAT 255 255 255 2.0 0.0 0.0 //white light
# sp -10 100 10 50 0
sp -10 100 10 50 0
qu -2.5 15 -9 7 0 0 0 0 7 0

View File

@ -1,4 +1,5 @@
CAM 0.576905 1.29122 1.46329 -6.8 -128 0.1 2
CAM -0.0970577 1.63916 1.69444 -13.6 -84 0 1
MAT 200 200 200 0.0 0.0 0.0 //white
MAT 255 50 50 0.0 0.0 0.0 //red

View File

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

View File

@ -58,61 +58,61 @@ 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);
// vec3 normal = obj.normal;
// hit.normal = dot(ray.direction, normal) < 0.0 ? normal : -normal;
// return (true);
// }
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;
return (true);
}
bool intersectCube(Ray ray, GPUObject obj, out hitInfo hit)
{
vec3 halfSize = obj.vertex1 * 0.5;