diff options
Diffstat (limited to 'indra/newview/app_settings/shaders')
13 files changed, 242 insertions, 252 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class1/deferred/reflectionProbeF.glsl index 95abd4d932..2ffe688524 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/reflectionProbeF.glsl @@ -25,14 +25,14 @@ // fallback stub -- will be used if actual reflection probe shader failed to load (output pink so it's obvious) void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec3 pos, vec3 norm, float glossiness, bool errorCorrect) + vec2 tc, vec3 pos, vec3 norm, float glossiness, bool errorCorrect) { ambenv = vec3(1,0,1); glossenv = vec3(1,0,1); } void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec3 pos, vec3 norm, float glossiness) + vec2 tc, vec3 pos, vec3 norm, float glossiness) { sampleReflectionProbes(ambenv, glossenv, pos, norm, glossiness, false); diff --git a/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflPostF.glsl b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflPostF.glsl index 8373567bb0..df16e7f0e7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflPostF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflPostF.glsl @@ -23,35 +23,11 @@ * $/LicenseInfo$ */ -#extension GL_ARB_texture_rectangle : enable + // debug stub -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -uniform vec2 screen_res; -uniform mat4 projection_matrix; -uniform mat4 inv_proj; -uniform float zNear; -uniform float zFar; - -VARYING vec2 vary_fragcoord; - -uniform sampler2D depthMap; -uniform sampler2D normalMap; -uniform sampler2D sceneMap; -uniform sampler2D diffuseRect; - -vec3 getNorm(vec2 screenpos); -float getDepth(vec2 pos_screen); -float linearDepth(float d, float znear, float zfar); -void main() { - vec2 tc = vary_fragcoord.xy; - vec4 pos = getPositionWithDepth(tc, getDepth(tc)); - frag_color = pos; +void main() +{ + frag_color = vec4(0.5, 0.4, 0.1, 0); } 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 diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl index 076b976dc4..7435f1c0e1 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl @@ -90,8 +90,8 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); float getAmbientClamp(); -void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, - vec3 pos, vec3 norm, float glossiness, float envIntensity); +void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, + vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity); vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, float ambiance) { @@ -253,7 +253,7 @@ void main() vec3 irradiance; vec3 glossenv; vec3 legacyenv; - sampleReflectionProbesLegacy(irradiance, glossenv, legacyenv, pos.xyz, norm.xyz, 0.0, 0.0); + sampleReflectionProbesLegacy(irradiance, glossenv, legacyenv, frag, pos.xyz, norm.xyz, 0.0, 0.0); float da = dot(norm.xyz, light_dir.xyz); diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index d81102991e..ccf20942e3 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -84,7 +84,7 @@ void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float float calcLegacyDistanceAttenuation(float distance, float falloff); float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec3 pos, vec3 norm, float glossiness); + vec2 tc, vec3 pos, vec3 norm, float glossiness); void waterClip(vec3 pos); @@ -207,7 +207,7 @@ void main() float gloss = 1.0 - perceptualRoughness; vec3 irradiance = vec3(0); vec3 radiance = vec3(0); - sampleReflectionProbes(irradiance, radiance, pos.xyz, norm.xyz, gloss); + sampleReflectionProbes(irradiance, radiance, vec2(0), pos.xyz, norm.xyz, gloss); // Take maximium of legacy ambient vs irradiance sample as irradiance // NOTE: ao is applied in pbrIbl (see pbrBaseLight), do not apply here irradiance = max(amblit,irradiance); diff --git a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl index af43c7b4e3..f1ee4b4681 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl @@ -34,7 +34,7 @@ uniform mat3 env_mat; vec3 srgb_to_linear(vec3 c); void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec3 pos, vec3 norm, float glossiness, bool errorCorrect) + vec2 tc, vec3 pos, vec3 norm, float glossiness, bool errorCorrect) { ambenv = vec3(reflection_probe_ambiance * 0.25); @@ -44,10 +44,10 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, } void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec3 pos, vec3 norm, float glossiness) + vec2 tc, vec3 pos, vec3 norm, float glossiness) { sampleReflectionProbes(ambenv, glossenv, - pos, norm, glossiness, false); + tc, pos, norm, glossiness, false); } vec4 sampleReflectionProbesDebug(vec3 pos) @@ -56,8 +56,8 @@ vec4 sampleReflectionProbesDebug(vec3 pos) return vec4(0, 0, 0, 0); } -void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, - vec3 pos, vec3 norm, float glossiness, float envIntensity) +void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, + vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity) { ambenv = vec3(reflection_probe_ambiance * 0.25); diff --git a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl index c0a1491446..160d360256 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl @@ -56,8 +56,9 @@ vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); // reflection probe interface -void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyEnv, - vec3 pos, vec3 norm, float glossiness, float envIntensity); +void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, + vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity); + void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 norm); void applyLegacyEnv(inout vec3 color, vec3 legacyenv, vec4 spec, vec3 pos, vec3 norm, float envIntensity); @@ -91,7 +92,7 @@ void main() vec3 legacyenv; vec3 norm = normalize(vary_texcoord1.xyz); vec4 spec = vec4(0,0,0,0); - sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, env_intensity); + sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, vec2(0), pos.xyz, norm.xyz, spec.a, env_intensity); applyLegacyEnv(color.rgb, legacyenv, spec, pos, norm, env_intensity); color.rgb = fullbrightAtmosTransportFrag(color.rgb, additive, atten); diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index 8016022d78..8d2a65d4a9 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -61,8 +61,8 @@ out vec4 frag_color; float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); #endif -void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, - vec3 pos, vec3 norm, float glossiness, float envIntensity); +void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, + vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity); void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 norm); void applyLegacyEnv(inout vec3 color, vec3 legacyenv, vec4 spec, vec3 pos, vec3 norm, float envIntensity); @@ -310,7 +310,7 @@ void main() vec3 ambenv; vec3 glossenv; vec3 legacyenv; - sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, final_specular.a, env_intensity); + sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos_screen, pos.xyz, norm.xyz, final_specular.a, env_intensity); // use sky settings ambient or irradiance map sample, whichever is brighter color = max(amblit, ambenv); diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 0cb966296a..9793ab13de 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -25,11 +25,17 @@ #define FLT_MAX 3.402823466e+38 +#if defined(SSR) +float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source); +#endif + #define REFMAP_COUNT 256 #define REF_SAMPLE_COUNT 64 //maximum number of samples to consider uniform samplerCubeArray reflectionProbes; uniform samplerCubeArray irradianceProbes; +uniform sampler2D sceneMap; +uniform int cube_snapshot; layout (std140) uniform ReflectionProbes { @@ -92,14 +98,17 @@ bool shouldSampleProbe(int i, vec3 pos) } else { - vec3 delta = pos.xyz - refSphere[i].xyz; - float d = dot(delta, delta); - float r2 = refSphere[i].w; - r2 *= r2; - - if (d > r2) - { //outside bounding sphere - return false; + if (refSphere[i].w > 0.0) // zero is special indicator to always sample this probe + { + vec3 delta = pos.xyz - refSphere[i].xyz; + float d = dot(delta, delta); + float r2 = refSphere[i].w; + r2 *= r2; + + if (d > r2) + { //outside bounding sphere + return false; + } } max_priority = max(max_priority, refIndex[i].w); @@ -138,13 +147,13 @@ void preProbeSample(vec3 pos) probeIndex[probeInfluences++] = idx; if (probeInfluences == REF_SAMPLE_COUNT) { - return; + break; } } count++; if (count == neighborCount) { - return; + break; } idx = refNeighbor[neighborIdx].y; @@ -153,13 +162,13 @@ void preProbeSample(vec3 pos) probeIndex[probeInfluences++] = idx; if (probeInfluences == REF_SAMPLE_COUNT) { - return; + break; } } count++; if (count == neighborCount) { - return; + break; } idx = refNeighbor[neighborIdx].z; @@ -168,13 +177,13 @@ void preProbeSample(vec3 pos) probeIndex[probeInfluences++] = idx; if (probeInfluences == REF_SAMPLE_COUNT) { - return; + break; } } count++; if (count == neighborCount) { - return; + break; } idx = refNeighbor[neighborIdx].w; @@ -183,27 +192,26 @@ void preProbeSample(vec3 pos) probeIndex[probeInfluences++] = idx; if (probeInfluences == REF_SAMPLE_COUNT) { - return; + break; } } count++; if (count == neighborCount) { - return; + break; } ++neighborIdx; } - return; + break; } } } - if (probeInfluences == 0) - { // probe at index 0 is a special fallback probe - probeIndex[0] = 0; - probeInfluences = 1; + if (max_priority <= 1) + { // probe at index 0 is a special probe for smoothing out automatic probes + probeIndex[probeInfluences++] = 0; } } @@ -330,7 +338,8 @@ return texCUBE(envMap, ReflDirectionWS); // origin - ray origin in clip space // dir - ray direction in clip space // i - probe index in refBox/refSphere -vec3 boxIntersect(vec3 origin, vec3 dir, int i) +// d - distance to nearest wall in clip space +vec3 boxIntersect(vec3 origin, vec3 dir, int i, out float d) { // Intersection with OBB convertto unit box space // Transform in local unit parallax cube space (scaled and rotated) @@ -339,6 +348,8 @@ vec3 boxIntersect(vec3 origin, vec3 dir, int i) vec3 RayLS = mat3(clipToLocal) * dir; vec3 PositionLS = (clipToLocal * vec4(origin, 1.0)).xyz; + d = 1.0-max(max(abs(PositionLS.x), abs(PositionLS.y)), abs(PositionLS.z)); + vec3 Unitary = vec3(1.0f, 1.0f, 1.0f); vec3 FirstPlaneIntersect = (Unitary - PositionLS) / RayLS; vec3 SecondPlaneIntersect = (-Unitary - PositionLS) / RayLS; @@ -413,6 +424,29 @@ void boxIntersectDebug(vec3 origin, vec3 pos, int i, inout vec4 col) } +// get the weight of a sphere probe +// pos - position to be weighted +// dir - normal to be weighted +// origin - center of sphere probe +// r - radius of probe influence volume +// min_da - minimum angular attenuation coefficient +float sphereWeight(vec3 pos, vec3 dir, vec3 origin, float r, float min_da) +{ + float r1 = r * 0.5; // 50% of radius (outer sphere to start interpolating down) + vec3 delta = pos.xyz - origin; + float d2 = max(length(delta), 0.001); + float r2 = r1; //r1 * r1; + + //float atten = 1.0 - max(d2 - r2, 0.0) / max((rr - r2), 0.001); + float atten = 1.0 - max(d2 - r2, 0.0) / max((r - r2), 0.001); + + atten *= max(dot(normalize(-delta), dir), min_da); + float w = 1.0 / d2; + w *= atten; + + return w; +} + // Tap a reflection probe // pos - position of pixel // dir - pixel normal @@ -431,27 +465,21 @@ vec3 tapRefMap(vec3 pos, vec3 dir, out float w, out vec3 vi, out vec3 wi, float if (refIndex[i].w < 0) { - v = boxIntersect(pos, dir, i); - w = 1.0; + float d = 0; + v = boxIntersect(pos, dir, i, d); + + w = max(d, 0.001); } else { float r = refSphere[i].w; // radius of sphere volume float rr = r * r; // radius squared - v = sphereIntersect(pos, dir, c, rr); - - float p = float(abs(refIndex[i].w)); // priority - - float r1 = r * 0.1; // 90% of radius (outer sphere to start interpolating down) - vec3 delta = pos.xyz - refSphere[i].xyz; - float d2 = max(dot(delta, delta), 0.001); - float r2 = r1 * r1; + v = sphereIntersect(pos, dir, c, + refIndex[i].w <= 1 ? 4096.0*4096.0 : // <== effectively disable parallax correction for automatically placed probes to keep from bombing the world with obvious spheres + rr); - float atten = 1.0 - max(d2 - r2, 0.0) / max((rr - r2), 0.001); - - w = 1.0 / d2; - w *= atten; + w = sphereWeight(pos, dir, refSphere[i].xyz, r, 0.25); } vi = v; @@ -480,8 +508,9 @@ vec3 tapIrradianceMap(vec3 pos, vec3 dir, out float w, vec3 c, int i) vec3 v; if (refIndex[i].w < 0) { - v = boxIntersect(pos, dir, i); - w = 1.0; + float d = 0.0; + v = boxIntersect(pos, dir, i, d); + w = max(d, 0.001); } else { @@ -489,17 +518,11 @@ vec3 tapIrradianceMap(vec3 pos, vec3 dir, out float w, vec3 c, int i) float p = float(abs(refIndex[i].w)); // priority float rr = r * r; // radius squred - v = sphereIntersect(pos, dir, c, rr); - - float r1 = r * 0.1; // 75% of radius (outer sphere to start interpolating down) - vec3 delta = pos.xyz - refSphere[i].xyz; - float d2 = dot(delta, delta); - float r2 = r1 * r1; + v = sphereIntersect(pos, dir, c, + refIndex[i].w <= 1 ? 4096.0*4096.0 : // <== effectively disable parallax correction for automatically placed probes to keep from bombing the world with obvious spheres + rr); - w = 1.0 / d2; - - float atten = 1.0 - max(d2 - r2, 0.0) / (rr - r2); - w *= atten; + w = sphereWeight(pos, dir, refSphere[i].xyz, r, 0.001); } v -= c; @@ -605,7 +628,7 @@ vec3 sampleProbeAmbient(vec3 pos, vec3 dir) } void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec3 pos, vec3 norm, float glossiness, bool errorCorrect) + vec2 tc, vec3 pos, vec3 norm, float glossiness, bool errorCorrect) { // TODO - don't hard code lods float reflection_lods = 6; @@ -617,6 +640,17 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, float lod = (1.0-glossiness)*reflection_lods; glossenv = sampleProbes(pos, normalize(refnormpersp), lod, errorCorrect); + +#if defined(SSR) + if (cube_snapshot != 1) + { + vec4 ssr = vec4(0); + //float w = tapScreenSpaceReflection(errorCorrect ? 1 : 4, tc, pos, norm, ssr, sceneMap); + float w = tapScreenSpaceReflection(1, tc, pos, norm, ssr, sceneMap); + + glossenv = mix(glossenv, ssr.rgb, w); + } +#endif } void debugTapRefMap(vec3 pos, vec3 dir, float depth, int i, inout vec4 col) @@ -660,15 +694,15 @@ vec4 sampleReflectionProbesDebug(vec3 pos) } void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec3 pos, vec3 norm, float glossiness) + vec2 tc, vec3 pos, vec3 norm, float glossiness) { sampleReflectionProbes(ambenv, glossenv, - pos, norm, glossiness, false); + tc, pos, norm, glossiness, false); } void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, - vec3 pos, vec3 norm, float glossiness, float envIntensity) + vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity) { // TODO - don't hard code lods float reflection_lods = 7; @@ -676,7 +710,6 @@ void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 refnormpersp = reflect(pos.xyz, norm.xyz); - ambenv = sampleProbeAmbient(pos, norm); if (glossiness > 0.0) @@ -689,6 +722,17 @@ void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout { legacyenv = sampleProbes(pos, normalize(refnormpersp), 0.0, false); } + +#if defined(SSR) + if (cube_snapshot != 1) + { + vec4 ssr = vec4(0); + float w = tapScreenSpaceReflection(1, tc, pos, norm, ssr, sceneMap); + + glossenv = mix(glossenv, ssr.rgb, w); + legacyenv = mix(legacyenv, ssr.rgb, w); + } +#endif } void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 norm) diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl index 4813e6c2d9..742f528cb1 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl @@ -42,10 +42,7 @@ uniform float zFar; VARYING vec2 vary_fragcoord; VARYING vec3 camera_ray; -uniform sampler2D depthMap; -uniform sampler2D normalMap; uniform sampler2D specularRect; -uniform sampler2D sceneMap; uniform sampler2D diffuseRect; uniform sampler2D diffuseMap; @@ -57,27 +54,27 @@ float linearDepth01(float d, float znear, float zfar); vec4 getPositionWithDepth(vec2 pos_screen, float depth); vec4 getPosition(vec2 pos_screen); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); -bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float hitDepth, float depth, sampler2D textureFrame); float random (vec2 uv); +float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source); void main() { vec2 tc = vary_fragcoord.xy; float depth = linearDepth01(getDepth(tc), zNear, zFar); - vec3 n = vec3(0, 0, 1); float envIntensity; + vec3 n; vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); // need `norm.w` for GET_GBUFFER_FLAG() vec3 pos = getPositionWithDepth(tc, getDepth(tc)).xyz; vec4 spec = texture2D(specularRect, tc); - vec3 viewPos = camera_ray * depth; - vec3 rayDirection = normalize(reflect(normalize(viewPos), n)) * -viewPos.z; vec2 hitpixel; - vec4 hitpoint; + vec4 diffuse = texture2D(diffuseRect, tc); vec3 specCol = spec.rgb; + frag_color = texture(diffuseMap, tc); + if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { vec3 orm = specCol.rgb; @@ -85,44 +82,17 @@ void main() float metallic = orm.b; vec3 f0 = vec3(0.04); vec3 baseColor = diffuse.rgb; - + vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0); specCol = mix(f0, baseColor.rgb, metallic); } - vec2 uv2 = tc * screen_res; - float c = (uv2.x + uv2.y) * 0.125; - float jitter = mod( c, 1.0); + vec4 collectedColor = vec4(0); - vec3 firstBasis = normalize(cross(vec3(1.f, 1.f, 1.f), rayDirection)); - vec3 secondBasis = normalize(cross(rayDirection, firstBasis)); - - frag_color = texture(diffuseMap, tc); - vec4 collectedColor; - - vec2 screenpos = 1 - abs(tc * 2 - 1); - float vignette = clamp((screenpos.x * screenpos.y) * 16,0, 1); - vignette *= clamp((dot(normalize(viewPos), n) * 0.5 + 0.5 - 0.2) * 8, 0, 1); - vignette *= min(linearDepth(getDepth(tc), zNear, zFar) / zFar, 1); - - int totalSamples = 4; - - for (int i = 0; i < totalSamples; i++) - { - vec2 coeffs = vec2(random(tc + vec2(0, i)) + random(tc + vec2(i, 0))); - vec3 reflectionDirectionRandomized = rayDirection + firstBasis * coeffs.x + secondBasis * coeffs.y; - - bool hit = traceScreenRay(pos, reflectionDirectionRandomized, hitpoint, depth, depth, diffuseMap); - - if (hit) - { - collectedColor += hitpoint; - collectedColor.rgb *= specCol.rgb; - } - } + float w = tapScreenSpaceReflection(4, tc, pos, n, collectedColor, diffuseMap); - collectedColor *= vignette; + collectedColor.rgb *= specCol.rgb; - frag_color += collectedColor; + frag_color += collectedColor * w; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl index b6c789ad40..570235a816 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl @@ -23,19 +23,18 @@ * $/LicenseInfo$ */ -uniform sampler2D depthMap; -uniform sampler2D normalMap; uniform sampler2D sceneMap; +uniform sampler2D sceneDepth; + uniform vec2 screen_res; uniform mat4 projection_matrix; -uniform float zNear; -uniform float zFar; +//uniform float zNear; +//uniform float zFar; uniform mat4 inv_proj; +uniform mat4 modelview_delta; // should be transform from last camera space to current camera space +uniform mat4 inv_modelview_delta; vec4 getPositionWithDepth(vec2 pos_screen, float depth); -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) { @@ -62,8 +61,25 @@ float distanceBias = 0.02; float depthRejectBias = 0.001; float epsilon = 0.1; +float getLinearDepth(vec2 tc) +{ + float depth = texture(sceneDepth, tc).r; + + vec4 pos = getPositionWithDepth(tc, depth); + + return -pos.z; +} + bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float hitDepth, float depth, sampler2D textureFrame) { + // transform position and reflection into same coordinate frame as the sceneMap and sceneDepth + reflection += position; + position = (inv_modelview_delta * vec4(position, 1)).xyz; + reflection = (inv_modelview_delta * vec4(reflection, 1)).xyz; + reflection -= position; + + depth = -position.z; + vec3 step = rayStep * reflection; vec3 marchingPosition = position + step; float delta; @@ -72,13 +88,14 @@ bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float 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); + depthFromScreen = getLinearDepth(screenPosition); delta = abs(marchingPosition.z) - depthFromScreen; if (depth < depthFromScreen + epsilon && depth > depthFromScreen - epsilon) @@ -91,7 +108,7 @@ bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float 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; + hitColor = texture(sceneMap, screenPosition) * color; hitDepth = depthFromScreen; hit = true; break; @@ -126,7 +143,7 @@ bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float marchingPosition = marchingPosition - step * sign(delta); screenPosition = generateProjectedPosition(marchingPosition); - depthFromScreen = linearDepth(getDepth(screenPosition), zNear, zFar); + depthFromScreen = getLinearDepth(screenPosition); delta = abs(marchingPosition.z) - depthFromScreen; if (depth < depthFromScreen + epsilon && depth > depthFromScreen - epsilon) @@ -139,7 +156,7 @@ bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float 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; + hitColor = texture(sceneMap, screenPosition) * color; hitDepth = depthFromScreen; hit = true; break; @@ -150,3 +167,68 @@ bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float return hit; } + +float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source) +{ + collectedColor = vec4(0); + int hits = 0; + + float depth = -viewPos.z; + + vec3 rayDirection = normalize(reflect(viewPos, normalize(n))); + + vec2 uv2 = tc * screen_res; + float c = (uv2.x + uv2.y) * 0.125; + float jitter = mod( c, 1.0); + + vec3 firstBasis = normalize(cross(vec3(1,1,1), rayDirection)); + vec3 secondBasis = normalize(cross(rayDirection, firstBasis)); + + vec2 screenpos = 1 - abs(tc * 2 - 1); + float vignette = clamp((screenpos.x * screenpos.y) * 16,0, 1); + vignette *= clamp((dot(normalize(viewPos), n) * 0.5 + 0.5 - 0.2) * 8, 0, 1); + float zFar = 64.0; + vignette *= clamp(1.0+(viewPos.z/zFar), 0.0, 1.0); + //vignette *= min(linearDepth(getDepth(tc), zNear, zFar) / zFar, 1); + + vec4 hitpoint; + + if (totalSamples > 1) + { + for (int i = 0; i < totalSamples; i++) + { + vec2 coeffs = vec2(random(tc + vec2(0, i)) + random(tc + vec2(i, 0))); + vec3 reflectionDirectionRandomized = rayDirection + firstBasis * coeffs.x + secondBasis * coeffs.y; + + //float hitDepth; + + bool hit = traceScreenRay(viewPos, normalize(reflectionDirectionRandomized), hitpoint, depth, depth, source); + + if (hit) + { + ++hits; + collectedColor += hitpoint; + } + } + } + else + { + bool hit = traceScreenRay(viewPos, normalize(rayDirection), hitpoint, depth, depth, source); + if (hit) + { + ++hits; + collectedColor += hitpoint; + } + } + + if (hits > 0) + { + collectedColor /= hits; + } + else + { + collectedColor = vec4(0); + } + + return min(float(hits), 1.0) * vignette; +}
\ No newline at end of file diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 8e4197ae77..8d48e6f596 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -75,9 +75,9 @@ vec3 fullbrightAtmosTransportFragLinear(vec3 light, vec3 additive, vec3 atten); // reflection probe interface void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec3 pos, vec3 norm, float glossiness); -void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyEnv, - vec3 pos, vec3 norm, float glossiness, float envIntensity); + vec2 tc, vec3 pos, vec3 norm, float glossiness); +void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, + vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity); void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 norm); void applyLegacyEnv(inout vec3 color, vec3 legacyenv, vec4 spec, vec3 pos, vec3 norm, float envIntensity); float getDepth(vec2 pos_screen); @@ -166,7 +166,7 @@ void main() float gloss = 1.0 - perceptualRoughness; vec3 irradiance = vec3(0); vec3 radiance = vec3(0); - sampleReflectionProbes(irradiance, radiance, pos.xyz, norm.xyz, gloss); + sampleReflectionProbes(irradiance, radiance, tc, pos.xyz, norm.xyz, gloss); // Take maximium of legacy ambient vs irradiance sample as irradiance // NOTE: ao is applied in pbrIbl (see pbrBaseLight), do not apply here @@ -196,7 +196,7 @@ void main() vec3 glossenv = vec3(0); vec3 legacyenv = vec3(0); - sampleReflectionProbesLegacy(irradiance, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); + sampleReflectionProbesLegacy(irradiance, glossenv, legacyenv, tc, pos.xyz, norm.xyz, spec.a, envIntensity); // use sky settings ambient or irradiance map sample, whichever is brighter irradiance = max(amblit, irradiance); diff --git a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl index 85c3f42801..b792feee2a 100644 --- a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl @@ -95,9 +95,6 @@ vec3 BlendNormal(vec3 bump1, vec3 bump2) vec3 srgb_to_linear(vec3 col); -void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, - vec3 pos, vec3 norm, float glossiness, float envIntensity); - vec3 vN, vT, vB; vec3 transform_normal(vec3 vNt) @@ -106,7 +103,10 @@ vec3 transform_normal(vec3 vNt) } void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec3 pos, vec3 norm, float glossiness, bool errorCorrect); + vec2 tc, vec3 pos, vec3 norm, float glossiness); + +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, + vec2 tc, vec3 pos, vec3 norm, float glossiness, bool errorCorrect); vec3 getPositionWithNDC(vec3 ndc); @@ -225,7 +225,7 @@ void main() vec3 irradiance = vec3(0); vec3 radiance = vec3(0); - sampleReflectionProbes(irradiance, radiance, pos, refnorm, gloss, true); + sampleReflectionProbes(irradiance, radiance, distort, pos, refnorm, gloss, true); radiance *= 0.5; irradiance = fb.rgb; |