summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings/shaders/class3
diff options
context:
space:
mode:
authorRunitaiLinden <davep@lindenlab.com>2023-01-27 17:24:22 -0600
committerGitHub <noreply@github.com>2023-01-27 17:24:22 -0600
commit3ef31cb9b28f7b026e109eab69d383dddc922850 (patch)
treeeb4034470bbc59bba139a66b053583bb05e3d7c1 /indra/newview/app_settings/shaders/class3
parent503e18fc646c6d88cd8006ad2210a8afd0bced83 (diff)
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.
Diffstat (limited to 'indra/newview/app_settings/shaders/class3')
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl7
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/materialF.glsl6
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl150
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl50
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl104
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl10
-rw-r--r--indra/newview/app_settings/shaders/class3/environment/waterF.glsl10
7 files changed, 217 insertions, 120 deletions
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;