From 97277e74a9d966ed441e51f844f9012f55cca3dc Mon Sep 17 00:00:00 2001 From: Jonathan Goodman Date: Mon, 14 Nov 2022 18:12:22 +0000 Subject: Merged in SL-18332 (pull request #1194) First pass of Screen Space Reflections Approved-by: Dave Parks --- .../class1/deferred/screenSpaceReflUtil.glsl | 120 +++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl (limited to 'indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl new file mode 100644 index 0000000000..6dfc89a6c6 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl @@ -0,0 +1,120 @@ +/** + * @file class3/deferred/screenSpaceReflUtil.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +uniform sampler2D depthMap; +uniform sampler2D normalMap; +uniform sampler2D sceneMap; +uniform vec2 screen_res; +uniform mat4 projection_matrix; + +// Shamelessly taken from http://casual-effects.blogspot.com/2014/08/screen-space-ray-tracing.html +// Original paper: https://jcgt.org/published/0003/04/04/ +// By Morgan McGuire and Michael Mara at Williams College 2014 +// Released as open source under the BSD 2-Clause License +// http://opensource.org/licenses/BSD-2-Clause + +float distanceSquared(vec2 a, vec2 b) { a -= b; return dot(a, a); } + +bool traceScreenSpaceRay1(vec3 csOrig, vec3 csDir, mat4 proj, float zThickness, + float nearPlaneZ, float stride, float jitter, const float maxSteps, float maxDistance, + out vec2 hitPixel, out vec3 hitPoint) +{ + + // Clip to the near plane + float rayLength = ((csOrig.z + csDir.z * maxDistance) > nearPlaneZ) ? + (nearPlaneZ - csOrig.z) / csDir.z : maxDistance; + vec3 csEndPoint = csOrig + csDir * rayLength; + + // Project into homogeneous clip space + vec4 H0 = proj * vec4(csOrig, 1.0); + vec4 H1 = proj * vec4(csEndPoint, 1.0); + float k0 = 1.0 / H0.w, k1 = 1.0 / H1.w; + + // The interpolated homogeneous version of the camera-space points + vec3 Q0 = csOrig * k0, Q1 = csEndPoint * k1; + + // Screen-space endpoints + vec2 P0 = H0.xy * k0, P1 = H1.xy * k1; + + // If the line is degenerate, make it cover at least one pixel + // to avoid handling zero-pixel extent as a special case later + P1 += vec2((distanceSquared(P0, P1) < 0.0001) ? 0.01 : 0.0); + vec2 delta = P1 - P0; + + // Permute so that the primary iteration is in x to collapse + // all quadrant-specific DDA cases later + bool permute = false; + if (abs(delta.x) < abs(delta.y)) { + // This is a more-vertical line + permute = true; delta = delta.yx; P0 = P0.yx; P1 = P1.yx; + } + + float stepDir = sign(delta.x); + float invdx = stepDir / delta.x; + + // Track the derivatives of Q and k + vec3 dQ = (Q1 - Q0) * invdx; + float dk = (k1 - k0) * invdx; + vec2 dP = vec2(stepDir, delta.y * invdx); + + // Scale derivatives by the desired pixel stride and then + // offset the starting values by the jitter fraction + dP *= stride; dQ *= stride; dk *= stride; + P0 += dP * jitter; Q0 += dQ * jitter; k0 += dk * jitter; + + // Slide P from P0 to P1, (now-homogeneous) Q from Q0 to Q1, k from k0 to k1 + vec3 Q = Q0; + + // Adjust end condition for iteration direction + float end = P1.x * stepDir; + + float k = k0, stepCount = 0.0, prevZMaxEstimate = csOrig.z; + float rayZMin = prevZMaxEstimate, rayZMax = prevZMaxEstimate; + float sceneZMax = rayZMax + 100; + for (vec2 P = P0; + ((P.x * stepDir) <= end) && (stepCount < maxSteps) && + ((rayZMax < sceneZMax - zThickness) || (rayZMin > sceneZMax)) && + (sceneZMax != 0); + P += dP, Q.z += dQ.z, k += dk, ++stepCount) { + + rayZMin = prevZMaxEstimate; + rayZMax = (dQ.z * 0.5 + Q.z) / (dk * 0.5 + k); + prevZMaxEstimate = rayZMax; + if (rayZMin > rayZMax) { + float t = rayZMin; rayZMin = rayZMax; rayZMax = t; + } + + hitPixel = permute ? P.yx : P; + hitPixel.y = screen_res.y - hitPixel.y; + // You may need hitPixel.y = screen_res.y - hitPixel.y; here if your vertical axis + // is different than ours in screen space + sceneZMax = texelFetch(depthMap, ivec2(hitPixel)).r; + } + + // Advance Q based on the number of steps + Q.xy += dQ.xy * stepCount; + hitPoint = Q * (1.0 / k); + return (rayZMax >= sceneZMax - zThickness) && (rayZMin < sceneZMax); +} -- cgit v1.2.3 From 3ef31cb9b28f7b026e109eab69d383dddc922850 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Fri, 27 Jan 2023 17:24:22 -0600 Subject: SL-19203 et al -- Integrate SSR with reflection probes, tweak probe blending. (#63) * SL-19203 WIP -- Integrate SSR with reflection probes. Decruft LLRenderTarget. * SL-19203 WIP -- Re-integrate SSR. Incidental decruft. * SL-19203 WIP -- SSR frame delta correction (still broken for Z) * SL-19203 WIP -- SSR frame delta Z fix * SL-19203 WIP -- Make SSR toggleable again and disable SSR in cube snapshots. * SL-19203 WIP -- Soften sphere probe transitions and fix reflections on void water (make fallback probe a simple terrain+water+sky probe). Remove parallax correction for automatic probes to reduce artifacts. * SL-19203 Tune probe blending. * SL-19203 Cleanup. --- .../class1/deferred/screenSpaceReflUtil.glsl | 101 ++------------------- 1 file changed, 9 insertions(+), 92 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl index 6dfc89a6c6..b3da216b81 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl @@ -23,98 +23,15 @@ * $/LicenseInfo$ */ -uniform sampler2D depthMap; -uniform sampler2D normalMap; -uniform sampler2D sceneMap; -uniform vec2 screen_res; -uniform mat4 projection_matrix; +// debug stub -// Shamelessly taken from http://casual-effects.blogspot.com/2014/08/screen-space-ray-tracing.html -// Original paper: https://jcgt.org/published/0003/04/04/ -// By Morgan McGuire and Michael Mara at Williams College 2014 -// Released as open source under the BSD 2-Clause License -// http://opensource.org/licenses/BSD-2-Clause - -float distanceSquared(vec2 a, vec2 b) { a -= b; return dot(a, a); } - -bool traceScreenSpaceRay1(vec3 csOrig, vec3 csDir, mat4 proj, float zThickness, - float nearPlaneZ, float stride, float jitter, const float maxSteps, float maxDistance, - out vec2 hitPixel, out vec3 hitPoint) +float random (vec2 uv) { - - // Clip to the near plane - float rayLength = ((csOrig.z + csDir.z * maxDistance) > nearPlaneZ) ? - (nearPlaneZ - csOrig.z) / csDir.z : maxDistance; - vec3 csEndPoint = csOrig + csDir * rayLength; - - // Project into homogeneous clip space - vec4 H0 = proj * vec4(csOrig, 1.0); - vec4 H1 = proj * vec4(csEndPoint, 1.0); - float k0 = 1.0 / H0.w, k1 = 1.0 / H1.w; - - // The interpolated homogeneous version of the camera-space points - vec3 Q0 = csOrig * k0, Q1 = csEndPoint * k1; - - // Screen-space endpoints - vec2 P0 = H0.xy * k0, P1 = H1.xy * k1; - - // If the line is degenerate, make it cover at least one pixel - // to avoid handling zero-pixel extent as a special case later - P1 += vec2((distanceSquared(P0, P1) < 0.0001) ? 0.01 : 0.0); - vec2 delta = P1 - P0; - - // Permute so that the primary iteration is in x to collapse - // all quadrant-specific DDA cases later - bool permute = false; - if (abs(delta.x) < abs(delta.y)) { - // This is a more-vertical line - permute = true; delta = delta.yx; P0 = P0.yx; P1 = P1.yx; - } - - float stepDir = sign(delta.x); - float invdx = stepDir / delta.x; - - // Track the derivatives of Q and k - vec3 dQ = (Q1 - Q0) * invdx; - float dk = (k1 - k0) * invdx; - vec2 dP = vec2(stepDir, delta.y * invdx); - - // Scale derivatives by the desired pixel stride and then - // offset the starting values by the jitter fraction - dP *= stride; dQ *= stride; dk *= stride; - P0 += dP * jitter; Q0 += dQ * jitter; k0 += dk * jitter; - - // Slide P from P0 to P1, (now-homogeneous) Q from Q0 to Q1, k from k0 to k1 - vec3 Q = Q0; - - // Adjust end condition for iteration direction - float end = P1.x * stepDir; - - float k = k0, stepCount = 0.0, prevZMaxEstimate = csOrig.z; - float rayZMin = prevZMaxEstimate, rayZMax = prevZMaxEstimate; - float sceneZMax = rayZMax + 100; - for (vec2 P = P0; - ((P.x * stepDir) <= end) && (stepCount < maxSteps) && - ((rayZMax < sceneZMax - zThickness) || (rayZMin > sceneZMax)) && - (sceneZMax != 0); - P += dP, Q.z += dQ.z, k += dk, ++stepCount) { - - rayZMin = prevZMaxEstimate; - rayZMax = (dQ.z * 0.5 + Q.z) / (dk * 0.5 + k); - prevZMaxEstimate = rayZMax; - if (rayZMin > rayZMax) { - float t = rayZMin; rayZMin = rayZMax; rayZMax = t; - } - - hitPixel = permute ? P.yx : P; - hitPixel.y = screen_res.y - hitPixel.y; - // You may need hitPixel.y = screen_res.y - hitPixel.y; here if your vertical axis - // is different than ours in screen space - sceneZMax = texelFetch(depthMap, ivec2(hitPixel)).r; - } - - // Advance Q based on the number of steps - Q.xy += dQ.xy * stepCount; - hitPoint = Q * (1.0 / k); - return (rayZMax >= sceneZMax - zThickness) && (rayZMin < sceneZMax); + return 0; } + +float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source) +{ + collectedColor = vec4(0); + return 0; +} \ No newline at end of file -- cgit v1.2.3 From 12afbacd83f07f5df11e15996b8f6357fb49b9b2 Mon Sep 17 00:00:00 2001 From: Brad Linden Date: Mon, 30 Jan 2023 10:09:04 -0800 Subject: Fix DRTVWR-559 EOL at EOF to pass coding policy checks --- .../app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl index b3da216b81..d054305767 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl @@ -34,4 +34,4 @@ float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, { collectedColor = vec4(0); return 0; -} \ No newline at end of file +} -- cgit v1.2.3 From 339e02ef3311ad5c1197dfca2955a0c202b7c408 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Thu, 11 May 2023 21:19:58 -0700 Subject: Finally get glossy SSR up. DRTVWR-583 --- .../app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl index d054305767..1a85d70256 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl @@ -30,7 +30,7 @@ float random (vec2 uv) return 0; } -float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source) +float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source, float glossiness) { collectedColor = vec4(0); return 0; -- cgit v1.2.3