From dbdd08f3eca628121d6386de14d0952dba404797 Mon Sep 17 00:00:00 2001 From: TheRedShip Date: Thu, 9 Jan 2025 00:03:33 +0100 Subject: [PATCH] + | Small tweaks --- scenes/portalrotation.rt | 1 + shaders/compute.glsl | 8 ++++++-- shaders/intersect.glsl | 3 +-- shaders/random.glsl | 32 ++++++++++++++++---------------- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/scenes/portalrotation.rt b/scenes/portalrotation.rt index 36abe97..de8c22c 100644 --- a/scenes/portalrotation.rt +++ b/scenes/portalrotation.rt @@ -1,4 +1,5 @@ +TEX checker MAT 255 255 255 4.0 0.0 0.0 //light MAT 255 255 255 0.0 0.0 0.0 //white diff --git a/shaders/compute.glsl b/shaders/compute.glsl index a6d7618..c5e59eb 100644 --- a/shaders/compute.glsl +++ b/shaders/compute.glsl @@ -19,6 +19,9 @@ struct GPUObject { int mat_index; // 4 int type; // 4 + + vec3 cube_size() { return (vertex1); } + int portal_index() { return (int(radius)); } }; struct GPUMaterial @@ -28,6 +31,7 @@ struct GPUMaterial float roughness; // 4 float metallic; // 4 int type; // 4 + int texture_index; // 4 }; layout(std430, binding = 1) buffer ObjectBuffer @@ -72,7 +76,7 @@ Ray portalRay(Ray ray, hitInfo hit) vec3 relative; portal_1 = objects[hit.obj_index]; - portal_2 = objects[int(portal_1.radius)]; // saving memory radius = portal_index + portal_2 = objects[portal_1.portal_index()]; // saving memory radius = portal_index relative = hit.position - portal_1.position; @@ -171,7 +175,7 @@ Ray initRay(vec2 uv, inout uint rng_state) vec3 ray_direction = normalize((inverse(u_viewMatrix) * vec4(view_space_ray, 0.0)).xyz); float focus_distance = 4.5; - float aperture = 0; + float aperture = 0.1; vec3 right = vec3(u_viewMatrix[0][0], u_viewMatrix[1][0], u_viewMatrix[2][0]); vec3 up = vec3(u_viewMatrix[0][1], u_viewMatrix[1][1], u_viewMatrix[2][1]); diff --git a/shaders/intersect.glsl b/shaders/intersect.glsl index c200c1f..972456f 100644 --- a/shaders/intersect.glsl +++ b/shaders/intersect.glsl @@ -115,8 +115,7 @@ bool intersectTriangle(Ray ray, GPUObject obj, out hitInfo hit) bool intersectCube(Ray ray, GPUObject obj, out hitInfo hit) { - vec3 obj_size = obj.vertex1; - vec3 halfSize = obj_size * 0.5; + vec3 halfSize = obj.cube_size() * 0.5; vec3 rayOriginLocal = ray.origin - obj.position; vec3 invDir = 1.0 / ray.direction; diff --git a/shaders/random.glsl b/shaders/random.glsl index c6a37c9..f6abca6 100644 --- a/shaders/random.glsl +++ b/shaders/random.glsl @@ -36,21 +36,21 @@ vec3 randomHemisphereDirection(vec3 normal, inout uint rng_state) return (direction * sign(dot(normal, direction))); } -// vec3 GetEnvironmentLight(Ray ray) -// { -// vec3 sun_pos = vec3(-0.5, 0.5, 0.5); -// float SunFocus = 1.5; -// float SunIntensity = 1; +vec3 GetEnvironmentLight(Ray ray) +{ + vec3 sun_pos = vec3(-0.5, 0.5, 0.5); + float SunFocus = 1.5; + float SunIntensity = 1; -// vec3 GroundColour = vec3(0.5, 0.5, 0.5); -// vec3 SkyColourHorizon = vec3(135 / 255.0f, 206 / 255.0f, 235 / 255.0f); -// vec3 SkyColourZenith = SkyColourHorizon / 2.0; + vec3 GroundColour = vec3(0.5, 0.5, 0.5); + vec3 SkyColourHorizon = vec3(135 / 255.0f, 206 / 255.0f, 235 / 255.0f); + vec3 SkyColourZenith = SkyColourHorizon / 2.0; -// float skyGradientT = pow(smoothstep(0, 0.4, ray.direction.y), 0.35); -// float groundToSkyT = smoothstep(-0.01, 0, ray.direction.y); -// vec3 skyGradient = mix(SkyColourHorizon, SkyColourZenith, skyGradientT); -// float sun = pow(max(0, dot(ray.direction, sun_pos.xyz)), SunFocus) * SunIntensity; -// // Combine ground, sky, and sun -// vec3 composite = mix(GroundColour, skyGradient, groundToSkyT) + sun * int(groundToSkyT >= 1); -// return composite; -// } \ No newline at end of file + float skyGradientT = pow(smoothstep(0.0, 0.4, ray.direction.y), 0.35); + float groundToSkyT = smoothstep(-0.01, 0.0, ray.direction.y); + vec3 skyGradient = mix(SkyColourHorizon, SkyColourZenith, skyGradientT); + float sun = pow(max(0, dot(ray.direction, sun_pos.xyz)), SunFocus) * SunIntensity; + // Combine ground, sky, and sun + vec3 composite = mix(GroundColour, skyGradient, groundToSkyT) + sun * int(groundToSkyT >= 1); + return composite; +} \ No newline at end of file