diff options
author | Dave Parks <davep@lindenlab.com> | 2023-01-24 14:02:53 -0600 |
---|---|---|
committer | Dave Parks <davep@lindenlab.com> | 2023-01-24 14:02:53 -0600 |
commit | fea731ecb3fbe0472777bfafa98156ebe75a5049 (patch) | |
tree | 09ca2a2e27f63393a207a1697fd608726b941176 /indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl | |
parent | a851aa83e705fa4a1c78919cfcac6709cfb1a875 (diff) |
SL-19023 Reformat SSR shaders to match style standard.
Diffstat (limited to 'indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl')
-rw-r--r-- | indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl | 162 |
1 files changed, 88 insertions, 74 deletions
diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl index f8c6e5701a..b6c789ad40 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl @@ -37,17 +37,19 @@ float linearDepth(float depth, float near, float far); float getDepth(vec2 pos_screen); float linearDepth01(float d, float znear, float zfar); -float random (vec2 uv) { - return fract(sin(dot(uv, vec2(12.9898, 78.233))) * 43758.5453123); //simple random function +float random (vec2 uv) +{ + return fract(sin(dot(uv, vec2(12.9898, 78.233))) * 43758.5453123); //simple random function } // Based off of https://github.com/RoundedGlint585/ScreenSpaceReflection/ // A few tweaks here and there to suit our needs. -vec2 generateProjectedPosition(vec3 pos){ - vec4 samplePosition = projection_matrix * vec4(pos, 1.f); - samplePosition.xy = (samplePosition.xy / samplePosition.w) * 0.5 + 0.5; - return samplePosition.xy; +vec2 generateProjectedPosition(vec3 pos) +{ + vec4 samplePosition = projection_matrix * vec4(pos, 1.f); + samplePosition.xy = (samplePosition.xy / samplePosition.w) * 0.5 + 0.5; + return samplePosition.xy; } bool isBinarySearchEnabled = true; @@ -60,79 +62,91 @@ float distanceBias = 0.02; float depthRejectBias = 0.001; float epsilon = 0.1; -bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float hitDepth, float depth, sampler2D textureFrame) { - vec3 step = rayStep * reflection; - vec3 marchingPosition = position + step; - float delta; - float depthFromScreen; - vec2 screenPosition; +bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float hitDepth, float depth, sampler2D textureFrame) +{ + vec3 step = rayStep * reflection; + vec3 marchingPosition = position + step; + float delta; + float depthFromScreen; + vec2 screenPosition; bool hit = false; hitColor = vec4(0); - - int i = 0; - if (depth > depthRejectBias) { - for (; i < iterationCount && !hit; i++) { - screenPosition = generateProjectedPosition(marchingPosition); - depthFromScreen = linearDepth(getDepth(screenPosition), zNear, zFar); - delta = abs(marchingPosition.z) - depthFromScreen; - - if (depth < depthFromScreen + epsilon && depth > depthFromScreen - epsilon) { - break; - } + + int i = 0; + if (depth > depthRejectBias) + { + for (; i < iterationCount && !hit; i++) + { + screenPosition = generateProjectedPosition(marchingPosition); + depthFromScreen = linearDepth(getDepth(screenPosition), zNear, zFar); + delta = abs(marchingPosition.z) - depthFromScreen; + + if (depth < depthFromScreen + epsilon && depth > depthFromScreen - epsilon) + { + break; + } - if (abs(delta) < distanceBias) { - vec4 color = vec4(1); - if(debugDraw) - color = vec4( 0.5+ sign(delta)/2,0.3,0.5- sign(delta)/2, 0); - hitColor = texture(textureFrame, screenPosition) * color; - hitDepth = depthFromScreen; - hit = true; - break; - } - if (isBinarySearchEnabled && delta > 0) { - break; - } - if (isAdaptiveStepEnabled){ - float directionSign = sign(abs(marchingPosition.z) - depthFromScreen); - //this is sort of adapting step, should prevent lining reflection by doing sort of iterative converging - //some implementation doing it by binary search, but I found this idea more cheaty and way easier to implement - step = step * (1.0 - rayStep * max(directionSign, 0.0)); - marchingPosition += step * (-directionSign); - } - else { - marchingPosition += step; - } + if (abs(delta) < distanceBias) + { + vec4 color = vec4(1); + if(debugDraw) + color = vec4( 0.5+ sign(delta)/2,0.3,0.5- sign(delta)/2, 0); + hitColor = texture(textureFrame, screenPosition) * color; + hitDepth = depthFromScreen; + hit = true; + break; + } + if (isBinarySearchEnabled && delta > 0) + { + break; + } + if (isAdaptiveStepEnabled) + { + float directionSign = sign(abs(marchingPosition.z) - depthFromScreen); + //this is sort of adapting step, should prevent lining reflection by doing sort of iterative converging + //some implementation doing it by binary search, but I found this idea more cheaty and way easier to implement + step = step * (1.0 - rayStep * max(directionSign, 0.0)); + marchingPosition += step * (-directionSign); + } + else + { + marchingPosition += step; + } - if (isExponentialStepEnabled){ - step *= 1.05; - } - } - if(isBinarySearchEnabled){ - for(; i < iterationCount && !hit; i++){ - - step *= 0.5; - marchingPosition = marchingPosition - step * sign(delta); - - screenPosition = generateProjectedPosition(marchingPosition); - depthFromScreen = linearDepth(getDepth(screenPosition), zNear, zFar); - delta = abs(marchingPosition.z) - depthFromScreen; + if (isExponentialStepEnabled) + { + step *= 1.05; + } + } + if(isBinarySearchEnabled) + { + for(; i < iterationCount && !hit; i++) + { + step *= 0.5; + marchingPosition = marchingPosition - step * sign(delta); + + screenPosition = generateProjectedPosition(marchingPosition); + depthFromScreen = linearDepth(getDepth(screenPosition), zNear, zFar); + delta = abs(marchingPosition.z) - depthFromScreen; - if (depth < depthFromScreen + epsilon && depth > depthFromScreen - epsilon) { - break; - } + if (depth < depthFromScreen + epsilon && depth > depthFromScreen - epsilon) + { + break; + } - if (abs(delta) < distanceBias && depthFromScreen != (depth - distanceBias)) { - vec4 color = vec4(1); - if(debugDraw) - color = vec4( 0.5+ sign(delta)/2,0.3,0.5- sign(delta)/2, 0); - hitColor = texture(textureFrame, screenPosition) * color; - hitDepth = depthFromScreen; - hit = true; - break; - } - } - } - } - + if (abs(delta) < distanceBias && depthFromScreen != (depth - distanceBias)) + { + vec4 color = vec4(1); + if(debugDraw) + color = vec4( 0.5+ sign(delta)/2,0.3,0.5- sign(delta)/2, 0); + hitColor = texture(textureFrame, screenPosition) * color; + hitDepth = depthFromScreen; + hit = true; + break; + } + } + } + } + return hit; } |