From 0b930fe394c42ac0332a478c0b352191c159d1b4 Mon Sep 17 00:00:00 2001 From: TheRedShip Date: Sat, 1 Feb 2025 14:56:45 +0100 Subject: [PATCH] ~ | Small tweaks --- scenes/dragon.rt | 4 ++-- scenes/lambo.rt | 2 +- scenes/sponza.rt | 6 +++--- scenes/test.rt | 13 ++++--------- scenes/volumetric.rt | 40 ++++++++++++++++++++++++++++++++++++++++ scenes/window2.rt | 2 +- shaders/intersect.glsl | 7 +++++-- shaders/light.glsl | 4 ++-- srcs/RT.cpp | 1 + 9 files changed, 59 insertions(+), 20 deletions(-) create mode 100644 scenes/volumetric.rt diff --git a/scenes/dragon.rt b/scenes/dragon.rt index bb191c4..93963d9 100644 --- a/scenes/dragon.rt +++ b/scenes/dragon.rt @@ -24,8 +24,8 @@ pl 0 -2 0 0 1 0 2 // floor qu -1 1.999 -1 2 0 0 0 0 2 6 -OBJ obj/Dragon_800K.obj -0.5 0 0.55 5 0 90 0 -OBJ obj/Dragon_800K.obj 0.5 0 -0.55 5 0 -90 0 +OBJ scenes/obj/Dragon_800K.obj -0.5 0 0.55 5 0 90 0 +OBJ scenes/obj/Dragon_800K.obj 0.5 0 -0.55 5 0 -90 0 po -1.99 -0.5 -0.5 0 1 0 0 0 1 1 4 po 1.99 -0.5 -0.5 0 1 0 0 0 1 0 4 diff --git a/scenes/lambo.rt b/scenes/lambo.rt index 3bc0817..bc083a1 100644 --- a/scenes/lambo.rt +++ b/scenes/lambo.rt @@ -19,7 +19,7 @@ cu 0 10 0 5 5 5 3 sp 0 10 0 1 4 -OBJ obj/lambo.obj 0 1.5 0 1 0 0 0 +OBJ scenes/obj/lambo.obj 0 1.5 0 1 0 0 0 diff --git a/scenes/sponza.rt b/scenes/sponza.rt index df08f4d..87b4e93 100644 --- a/scenes/sponza.rt +++ b/scenes/sponza.rt @@ -7,8 +7,8 @@ MAT 255 220 50 0.0 1.0 0.5 // dragon 1 MAT 255 255 255 5.0 0.0 0.0 // light 2 sp 0 50 0 25 2 -OBJ obj/sponza.obj 0 0 0 0.025 +OBJ scenes/obj/sponza.obj 0 0 0 0.025 -OBJ obj/Dragon_80K.obj 7 2.5 0 9 0 140 0 0 -OBJ obj/Dragon_80K.obj 9 1.35 -3.5 5 0 40 0 1 +OBJ scenes/obj/Dragon_80K.obj 7 2.5 0 9 0 140 0 0 +OBJ scenes/obj/Dragon_80K.obj 9 1.35 -3.5 5 0 40 0 1 diff --git a/scenes/test.rt b/scenes/test.rt index c9d32ef..75f70ca 100644 --- a/scenes/test.rt +++ b/scenes/test.rt @@ -1,11 +1,6 @@ -CAM -2.41462 2.57199 4.09049 -1.80012 -50.2012 0.02 2.973 45.75 5 +CAM 0 0 -5 -MAT 20 20 20 0. 0.9 0.5 // 0 gray -# pl 0 -0.5 0 0 -1 0 0 // floor +MAT 255 255 255 10.0 1.0 0.0 //white +# sp 0 0 0 1 0 - -MAT 0 0 0 0. 0 0 // 1 black -MAT 255 255 255 0. 1.5 0 DIE -1 // 2 blackhole - -sp 0 0 0 5 1 -sp 0 0 0 15 2 +OBJ scenes/obj/room.obj 0 0 0 1 diff --git a/scenes/volumetric.rt b/scenes/volumetric.rt new file mode 100644 index 0000000..6514a96 --- /dev/null +++ b/scenes/volumetric.rt @@ -0,0 +1,40 @@ +CAM 1.61759 3.23371 -7.26417 -4.0001 105.199 0 2.973 45.75 5 + +MAT 255 255 255 2.0 1.0 0.0 // 0 white light +# sp -3.5 2.7 0.5 0.2 0 +qu -4 2.375 0 0 0.25 0 0 0 0.25 0 + +MAT 250 250 250 0. 1.0 0.0 // 1 white +MAT 250 100 100 0. 1.0 0.0 // 2 red +MAT 100 100 250 0. 1.0 0.0 // 3 blue + +MAT 250 250 250 0. 1.0 0.05 // 1 white tomato +MAT 250 250 250 0. 1.3 0. DIE -1 // 1 white dielectric + +qu 2.5 0 -2.5 0 5 0 0 0 5 1 +qu -2.5 0 2.5 0 5 0 5 0 0 2 +qu -2.5 0 -2.5 0 0 5 5 0 0 1 + +qu -2.5 0 -2.5 0 2.375 0 0 0 5 3 +qu -2.5 2.6275 -2.5 0 2.375 0 0 0 5 3 + +qu -2.5 2 0.25 0 1 0 0 0 2.75 3 +qu -2.5 2 -2.5 0 1 0 0 0 2.5 3 + + +sp 1.25 1 -1 1.5 4 +sp 0 2.5 0 0.5 5 + + + +# MAT 20 20 20 0. 0.9 0.5 // 0 gray +# # pl 0 -0.5 0 0 -1 0 0 // floor + + +# MAT 0 0 0 0. 0 0 // 1 black +# MAT 255 255 255 0. 1.5 0 DIE -1 // 2 blackhole + +# sp 0 0 0 5 1 +# sp 0 0 0 15 2 + +# OBJ scenes/obj/jinx.obj 0 0 -15 \ No newline at end of file diff --git a/scenes/window2.rt b/scenes/window2.rt index 7fcc991..2369d7e 100644 --- a/scenes/window2.rt +++ b/scenes/window2.rt @@ -3,7 +3,7 @@ CAM 0 2 -2 0 90 MAT 255 255 255 0.0 1.0 0.0 //white MAT 150 150 150 0.0 1.0 0.0 //grey -MAT 255 255 255 10.0 0.0 0.0 //light +MAT 255 255 255 1.0 0.0 0.0 //light sp -5 5 0 1 2 diff --git a/shaders/intersect.glsl b/shaders/intersect.glsl index b57f50b..6dea610 100644 --- a/shaders/intersect.glsl +++ b/shaders/intersect.glsl @@ -74,6 +74,10 @@ bool intersectTriangle(Ray ray, GPUTriangle obj, out hitInfo hit) vec3 pvec = cross(ray.direction, vertex2); float det = dot(vertex1, pvec); + + if (abs(det) < 1e-8) + return (false); + vec3 tvec = ray.origin - obj.position; float invDet = 1.0 / det; @@ -82,8 +86,7 @@ bool intersectTriangle(Ray ray, GPUTriangle obj, out hitInfo hit) float v = dot(ray.direction, qvec) * invDet; float t = dot(vertex2, qvec) * invDet; - bool valid = abs(det) > 1e-8 && - u >= 0.0 && u <= 1.0 && + bool valid = u >= 0.0 && u <= 1.0 && v >= 0.0 && (u + v) <= 1.0 && t > 0.0; diff --git a/shaders/light.glsl b/shaders/light.glsl index 4a0d765..62ae06e 100644 --- a/shaders/light.glsl +++ b/shaders/light.glsl @@ -41,7 +41,7 @@ vec3 sampleSphereLight(vec3 position, GPUObject obj, int light_index, GPUMateria return vec3(0.0); float cos_theta = max(0.0, -dot(light_dir, normalize(sample_point - obj.position))); - return mat.emission * mat.color / (light_dist); // * cos_theta / (4.0 * M_PI * (obj.radius / 2.0) * (obj.radius / 2.0)); + return mat.emission * mat.color / (light_dist * light_dist) * cos_theta / (4.0 * M_PI * (obj.radius / 2.0) * (obj.radius / 2.0)); } vec3 sampleQuadLight(vec3 position, GPUObject obj, int light_index, GPUMaterial mat, inout uint rng_state) @@ -65,7 +65,7 @@ vec3 sampleQuadLight(vec3 position, GPUObject obj, int light_index, GPUMaterial vec3 normal = normalize(crossQuad); float cos_theta = max(0.0, dot(normal, -light_dir)); - return mat.emission * mat.color / (light_dist); // * cos_theta / pdf; + return mat.emission * mat.color / (light_dist); } vec3 sampleLights(vec3 position, inout uint rng_state) diff --git a/srcs/RT.cpp b/srcs/RT.cpp index 3bf92e1..a20d205 100644 --- a/srcs/RT.cpp +++ b/srcs/RT.cpp @@ -142,6 +142,7 @@ int main(int argc, char **argv) shader.set_textures(scene.getTextureIDs()); glDispatchCompute((WIDTH + 15) / 16, (HEIGHT + 15) / 16, 1); + glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT); glClear(GL_COLOR_BUFFER_BIT);