From ced2bd5ed4386d50231edfd1ebec01561f9b4465 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Mon, 12 Apr 2021 16:58:18 -0700 Subject: SL-14113 Fix moon haze --- indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl index fa928d993e..d89cc69d71 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl @@ -127,5 +127,11 @@ void main() /// Gamma correct for WL (soft clip effect). frag_color = vec4(color.rgb, alpha1); + + // SL-14113 Moon Haze -- When the camera is underwater fix clouds clipping into moon + // camera above water: class1\defered\cloudsF.glsl + // camera below water: class2\windlight\coudsV.glsl + // See: starsV.glsl, cloudsV.glsl, moonF.glsl + gl_FragDepth = 0.999985; } -- cgit v1.2.3 From 290c66ebf476cb1e6e7141889d1e6faf26dba3ce Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 13 Apr 2021 10:54:02 -0700 Subject: SL-14113 Cleanup typo and cross reference --- indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl index d89cc69d71..1c592402d4 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl @@ -129,7 +129,7 @@ void main() frag_color = vec4(color.rgb, alpha1); // SL-14113 Moon Haze -- When the camera is underwater fix clouds clipping into moon - // camera above water: class1\defered\cloudsF.glsl + // camera above water: class1\deferred\cloudsF.glsl // camera below water: class2\windlight\coudsV.glsl // See: starsV.glsl, cloudsV.glsl, moonF.glsl gl_FragDepth = 0.999985; -- cgit v1.2.3 From e371fdbf311e450ac0cc7f4d3fdacc938b489d92 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 29 Apr 2021 08:41:50 -0700 Subject: SL-14113: Remove magic numbers. Take advantage of existing shader #defines injection by extending shader loading to make use of addConstant() instead of hard-coding magic number constants in each GLSL file. --- indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl index 1c592402d4..ec53ae75f9 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl @@ -132,6 +132,6 @@ void main() // camera above water: class1\deferred\cloudsF.glsl // camera below water: class2\windlight\coudsV.glsl // See: starsV.glsl, cloudsV.glsl, moonF.glsl - gl_FragDepth = 0.999985; + gl_FragDepth = LL_SHADER_CONST_CLOUD_DEPTH; } -- cgit v1.2.3 From 3f4b8423a46bae4736ebcc28082ee1a9d5b71d6b Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 29 Apr 2021 10:27:09 -0700 Subject: SL-14113: Merge duplicate shader constant for clarity. --- indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl index ec53ae75f9..490fde7cf6 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl @@ -132,6 +132,6 @@ void main() // camera above water: class1\deferred\cloudsF.glsl // camera below water: class2\windlight\coudsV.glsl // See: starsV.glsl, cloudsV.glsl, moonF.glsl - gl_FragDepth = LL_SHADER_CONST_CLOUD_DEPTH; + gl_FragDepth = LL_SHADER_CONST_CLOUD_MOON_DEPTH; } -- cgit v1.2.3 From 93a025966649e281ceff8d1471bc983cc036bc17 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 29 Apr 2022 13:51:11 +0000 Subject: SL-17282 prototype mixing of reflection map into legacy materials --- .../shaders/class2/deferred/softenLightF.glsl | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 7700d16007..6958841d05 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -40,6 +40,7 @@ uniform sampler2DRect normalMap; uniform sampler2DRect lightMap; uniform sampler2DRect depthMap; uniform samplerCube environmentMap; +uniform samplerCube reflectionMap; uniform sampler2D lightFunc; uniform float blur_size; @@ -119,6 +120,8 @@ void main() vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + vec3 env_vec = env_mat * refnormpersp; + if (spec.a > 0.0) // specular reflection { float sa = dot(refnormpersp, light_dir.xyz); @@ -128,13 +131,28 @@ void main() vec3 spec_contrib = dumbshiny * spec.rgb; bloom = dot(spec_contrib, spec_contrib) / 6; color.rgb += spec_contrib; + + // add reflection map - EXPERIMENTAL WORK IN PROGRESS + float reflection_lods = 11; // TODO -- base this on resolution of reflection map instead of hard coding + float min_lod = textureQueryLod(reflectionMap,env_vec).y; // lower is higher res + + //vec3 reflected_color = texture(reflectionMap, env_vec, (1.0-spec.a)*reflection_lod).rgb; + vec3 reflected_color = textureLod(reflectionMap, env_vec, max(min_lod, (1.0-spec.a)*reflection_lods)).rgb; + //vec3 reflected_color = texture(reflectionMap, env_vec).rgb; + //vec3 reflected_color = normalize(env_vec)*0.5+0.5; + reflected_color *= spec.rgb; + vec3 mixer = clamp(color.rgb + vec3(1,1,1) - spec.rgb, vec3(0,0,0), vec3(1,1,1)); + + color.rgb = mix(reflected_color*sqrt(spec.a*0.8), color, mixer); + + //color.rgb = mix(reflected_color * spec.rgb * sqrt(spec.a*0.8), color.rgb, color.rgb); + //color.rgb += reflected_color * spec.rgb; // * sqrt(spec.a*0.8), color.rgb, color.rgb); } color.rgb = mix(color.rgb, diffuse.rgb, diffuse.a); if (envIntensity > 0.0) { // add environmentmap - vec3 env_vec = env_mat * refnormpersp; vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; color = mix(color.rgb, reflected_color, envIntensity); } @@ -154,5 +172,6 @@ void main() // convert to linear as fullscreen lights need to sum in linear colorspace // and will be gamma (re)corrected downstream... frag_color.rgb = srgb_to_linear(color.rgb); + //frag_color.r = 1.0; frag_color.a = bloom; } -- cgit v1.2.3 From 93260cfeff2382dd1ffeecaef208d37bf21c2a01 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 4 May 2022 16:07:50 +0000 Subject: SL-17283 LLReflectionMapManager prototype. Remove snapshot code related overhead from reflection map renders. Add parallax correction and support for multiple reflection maps. --- .../shaders/class2/deferred/softenLightF.glsl | 190 ++++++++++++++++++--- 1 file changed, 164 insertions(+), 26 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 6958841d05..5bb64e18a7 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -28,6 +28,8 @@ /*[EXTRA_CODE_HERE]*/ +#define REFMAP_COUNT 8 + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else @@ -40,9 +42,13 @@ uniform sampler2DRect normalMap; uniform sampler2DRect lightMap; uniform sampler2DRect depthMap; uniform samplerCube environmentMap; -uniform samplerCube reflectionMap; +uniform samplerCube reflectionMap[REFMAP_COUNT]; uniform sampler2D lightFunc; +uniform int refmapCount; + +uniform vec3 refOrigin[REFMAP_COUNT]; + uniform float blur_size; uniform float blur_fidelity; @@ -74,8 +80,136 @@ vec3 srgb_to_linear(vec3 c); vec4 applyWaterFogView(vec3 pos, vec4 color); #endif + + +// from https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-sphere-intersection + +// original reference implementation: +/* +bool intersect(const Ray &ray) const +{ + float t0, t1; // solutions for t if the ray intersects +#if 0 + // geometric solution + Vec3f L = center - orig; + float tca = L.dotProduct(dir); + // if (tca < 0) return false; + float d2 = L.dotProduct(L) - tca * tca; + if (d2 > radius2) return false; + float thc = sqrt(radius2 - d2); + t0 = tca - thc; + t1 = tca + thc; +#else + // analytic solution + Vec3f L = orig - center; + float a = dir.dotProduct(dir); + float b = 2 * dir.dotProduct(L); + float c = L.dotProduct(L) - radius2; + if (!solveQuadratic(a, b, c, t0, t1)) return false; +#endif + if (t0 > t1) std::swap(t0, t1); + + if (t0 < 0) { + t0 = t1; // if t0 is negative, let's use t1 instead + if (t0 < 0) return false; // both t0 and t1 are negative + } + + t = t0; + + return true; +} */ + +// adapted -- assume that origin is inside sphere, return distance from origin to edge of sphere +float sphereIntersect(vec3 origin, vec3 dir, vec4 sph ) +{ + float t0, t1; // solutions for t if the ray intersects + + vec3 center = sph.xyz; + float radius2 = sph.w * sph.w; + + vec3 L = center - origin; + float tca = dot(L,dir); + + float d2 = dot(L,L) - tca * tca; + + float thc = sqrt(radius2 - d2); + t0 = tca - thc; + t1 = tca + thc; + + return t1; +} + +vec3 sampleRefMap(vec3 pos, vec3 dir, float lod) +{ + float wsum = 0.0; + + vec3 col = vec3(0,0,0); + + for (int i = 0; i < refmapCount; ++i) + //int i = 0; + { + float r = 16.0; + vec3 delta = pos.xyz-refOrigin[i].xyz; + if (length(delta) < r) + { + float w = 1.0/max(dot(delta, delta), r); + w *= w; + w *= w; + + // parallax adjustment + float d = sphereIntersect(pos, dir, vec4(refOrigin[i].xyz, r)); + + { + vec3 v = pos + dir * d; + v -= refOrigin[i].xyz; + v = env_mat * v; + + float min_lod = textureQueryLod(reflectionMap[i],v).y; // lower is higher res + col += textureLod(reflectionMap[i], v, max(min_lod, lod)).rgb*w; + wsum += w; + } + } + } + + if (wsum > 0.0) + { + col *= 1.0/wsum; + } + else + { + // this pixel not covered by a probe, fallback to "full scene" environment map + vec3 v = env_mat * dir; + float min_lod = textureQueryLod(environmentMap, v).y; // lower is higher res + col = textureLod(environmentMap, v, max(min_lod, lod)).rgb; + } + + return col; +} + +vec3 sampleAmbient(vec3 pos, vec3 dir, float lod) +{ + vec3 col = sampleRefMap(pos, dir, lod); + + //desaturate + vec3 hcol = col *0.5; + + col *= 2.0; + col = vec3( + col.r + hcol.g + hcol.b, + col.g + hcol.r + hcol.b, + col.b + hcol.r + hcol.g + ); + + col *= 0.333333; + + return col*0.6; // fudge darker + +} + void main() { + float reflection_lods = 11; // TODO -- base this on resolution of reflection map instead of hard coding + vec2 tc = vary_fragcoord.xy; float depth = texture2DRect(depthMap, tc.xy).r; vec4 pos = getPositionWithDepth(tc, depth); @@ -106,25 +240,29 @@ void main() vec3 atten; calcAtmosphericVars(pos.xyz, light_dir, ambocc, sunlit, amblit, additive, atten, true); + //vec3 amb_vec = env_mat * norm.xyz; + + vec3 ambenv = sampleAmbient(pos.xyz, norm.xyz, reflection_lods-1); + amblit = mix(ambenv, amblit, amblit); color.rgb = amblit; + - float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0 - ambient); - color.rgb *= ambient; + //float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); + //ambient *= 0.5; + //ambient *= ambient; + //ambient = (1.0 - ambient); + //color.rgb *= ambient; vec3 sun_contrib = min(da, scol) * sunlit; color.rgb += sun_contrib; color.rgb *= diffuse.rgb; - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + vec3 refnormpersp = reflect(pos.xyz, norm.xyz); vec3 env_vec = env_mat * refnormpersp; - if (spec.a > 0.0) // specular reflection { - float sa = dot(refnormpersp, light_dir.xyz); + float sa = dot(normalize(refnormpersp), light_dir.xyz); vec3 dumbshiny = sunlit * scol * (texture2D(lightFunc, vec2(sa, spec.a)).r); // add the two types of shiny together @@ -133,28 +271,30 @@ void main() color.rgb += spec_contrib; // add reflection map - EXPERIMENTAL WORK IN PROGRESS - float reflection_lods = 11; // TODO -- base this on resolution of reflection map instead of hard coding - float min_lod = textureQueryLod(reflectionMap,env_vec).y; // lower is higher res - - //vec3 reflected_color = texture(reflectionMap, env_vec, (1.0-spec.a)*reflection_lod).rgb; - vec3 reflected_color = textureLod(reflectionMap, env_vec, max(min_lod, (1.0-spec.a)*reflection_lods)).rgb; - //vec3 reflected_color = texture(reflectionMap, env_vec).rgb; - //vec3 reflected_color = normalize(env_vec)*0.5+0.5; - reflected_color *= spec.rgb; + + float lod = (1.0-spec.a)*reflection_lods; + vec3 reflected_color = sampleRefMap(pos.xyz, normalize(refnormpersp), lod); + reflected_color *= 0.5; // fudge darker, not sure where there's a multiply by two and it's late + float fresnel = 1.0+dot(normalize(pos.xyz), norm.xyz); + fresnel += spec.a; + fresnel *= fresnel; + //fresnel *= spec.a; + reflected_color *= spec.rgb*min(fresnel, 1.0); + //reflected_color = srgb_to_linear(reflected_color); vec3 mixer = clamp(color.rgb + vec3(1,1,1) - spec.rgb, vec3(0,0,0), vec3(1,1,1)); - - color.rgb = mix(reflected_color*sqrt(spec.a*0.8), color, mixer); - - //color.rgb = mix(reflected_color * spec.rgb * sqrt(spec.a*0.8), color.rgb, color.rgb); - //color.rgb += reflected_color * spec.rgb; // * sqrt(spec.a*0.8), color.rgb, color.rgb); + color.rgb = mix(reflected_color, color, mixer); } color.rgb = mix(color.rgb, diffuse.rgb, diffuse.a); if (envIntensity > 0.0) { // add environmentmap - vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; - color = mix(color.rgb, reflected_color, envIntensity); + vec3 reflected_color = sampleRefMap(pos.xyz, normalize(refnormpersp), 0.0); + float fresnel = 1.0+dot(normalize(pos.xyz), norm.xyz); + fresnel *= fresnel; + fresnel = fresnel * 0.95 + 0.05; + reflected_color *= fresnel; + color = mix(color.rgb, reflected_color, envIntensity); } if (norm.w < 0.5) @@ -172,6 +312,4 @@ void main() // convert to linear as fullscreen lights need to sum in linear colorspace // and will be gamma (re)corrected downstream... frag_color.rgb = srgb_to_linear(color.rgb); - //frag_color.r = 1.0; - frag_color.a = bloom; } -- cgit v1.2.3 From 3400e5fd302c0d9dea6386c4d5bf38876f2cc287 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 16 May 2022 17:21:08 +0000 Subject: SL-17284 Reflection probe tuning and optimization take 1 --- .../shaders/class2/deferred/softenLightF.glsl | 274 +++++++++++++++++---- 1 file changed, 224 insertions(+), 50 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 5bb64e18a7..3a1287e910 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -26,9 +26,10 @@ #extension GL_ARB_texture_rectangle : enable #extension GL_ARB_shader_texture_lod : enable -/*[EXTRA_CODE_HERE]*/ +#define FLT_MAX 3.402823466e+38 -#define REFMAP_COUNT 8 +#define REFMAP_COUNT 256 +#define REF_SAMPLE_COUNT 64 //maximum number of samples to consider #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; @@ -42,12 +43,26 @@ uniform sampler2DRect normalMap; uniform sampler2DRect lightMap; uniform sampler2DRect depthMap; uniform samplerCube environmentMap; -uniform samplerCube reflectionMap[REFMAP_COUNT]; +uniform samplerCubeArray reflectionProbes; uniform sampler2D lightFunc; -uniform int refmapCount; - -uniform vec3 refOrigin[REFMAP_COUNT]; +layout (std140, binding = 1) uniform ReflectionProbes +{ + // list of sphere based reflection probes sorted by distance to camera (closest first) + vec4 refSphere[REFMAP_COUNT]; + // index of cube map in reflectionProbes for a corresponding reflection probe + // e.g. cube map channel of refSphere[2] is stored in refIndex[2] + // refIndex.x - cubemap channel in reflectionProbes + // refIndex.y - index in refNeighbor of neighbor list (index is ivec4 index, not int index) + // refIndex.z - number of neighbors + ivec4 refIndex[REFMAP_COUNT]; + + // neighbor list data (refSphere indices, not cubemap array layer) + ivec4 refNeighbor[1024]; + + // number of reflection probes present in refSphere + int refmapCount; +}; uniform float blur_size; uniform float blur_fidelity; @@ -80,7 +95,116 @@ vec3 srgb_to_linear(vec3 c); vec4 applyWaterFogView(vec3 pos, vec4 color); #endif +// list of probeIndexes shader will actually use after "getRefIndex" is called +// (stores refIndex/refSphere indices, NOT rerflectionProbes layer) +int probeIndex[REF_SAMPLE_COUNT]; + +// number of probes stored in probeIndex +int probeInfluences = 0; + + +// return true if probe at index i influences position pos +bool shouldSampleProbe(int i, vec3 pos) +{ + vec3 delta = pos.xyz - refSphere[i].xyz; + float d = dot(delta, delta); + float r2 = refSphere[i].w; + r2 *= r2; + return d < r2; +} + +// populate "probeIndex" with N probe indices that influence pos where N is REF_SAMPLE_COUNT +// overall algorithm -- +void getRefIndex(vec3 pos) +{ + // TODO: make some sort of structure that reduces the number of distance checks + for (int i = 0; i < refmapCount; ++i) + { + // found an influencing probe + if (shouldSampleProbe(i, pos)) + { + probeIndex[probeInfluences] = i; + ++probeInfluences; + + int neighborIdx = refIndex[i].y; + if (neighborIdx != -1) + { + int neighborCount = min(refIndex[i].z, REF_SAMPLE_COUNT-1); + + int count = 0; + while (count < neighborCount) + { + // check up to REF_SAMPLE_COUNT-1 neighbors (neighborIdx is ivec4 index) + + int idx = refNeighbor[neighborIdx].x; + if (shouldSampleProbe(idx, pos)) + { + probeIndex[probeInfluences++] = idx; + if (probeInfluences == REF_SAMPLE_COUNT) + { + return; + } + } + count++; + if (count == neighborCount) + { + return; + } + + idx = refNeighbor[neighborIdx].y; + if (shouldSampleProbe(idx, pos)) + { + probeIndex[probeInfluences++] = idx; + if (probeInfluences == REF_SAMPLE_COUNT) + { + return; + } + } + count++; + if (count == neighborCount) + { + return; + } + + idx = refNeighbor[neighborIdx].z; + if (shouldSampleProbe(idx, pos)) + { + probeIndex[probeInfluences++] = idx; + if (probeInfluences == REF_SAMPLE_COUNT) + { + return; + } + } + count++; + if (count == neighborCount) + { + return; + } + + idx = refNeighbor[neighborIdx].w; + if (shouldSampleProbe(idx, pos)) + { + probeIndex[probeInfluences++] = idx; + if (probeInfluences == REF_SAMPLE_COUNT) + { + return; + } + } + count++; + if (count == neighborCount) + { + return; + } + + ++neighborIdx; + } + + return; + } + } + } +} // from https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-sphere-intersection @@ -120,13 +244,10 @@ bool intersect(const Ray &ray) const } */ // adapted -- assume that origin is inside sphere, return distance from origin to edge of sphere -float sphereIntersect(vec3 origin, vec3 dir, vec4 sph ) +float sphereIntersect(vec3 origin, vec3 dir, vec3 center, float radius2) { float t0, t1; // solutions for t if the ray intersects - vec3 center = sph.xyz; - float radius2 = sph.w * sph.w; - vec3 L = center - origin; float tca = dot(L,dir); @@ -139,33 +260,78 @@ float sphereIntersect(vec3 origin, vec3 dir, vec4 sph ) return t1; } +// Tap a sphere based reflection probe +// pos - position of pixel +// dir - pixel normal +// lod - which mip to bias towards (lower is higher res, sharper reflections) +// c - center of probe +// r2 - radius of probe squared +// i - index of probe +// vi - point at which reflection vector struck the influence volume, in clip space +vec3 tapRefMap(vec3 pos, vec3 dir, float lod, vec3 c, float r2, int i, out vec3 vi) +{ + //lod = max(lod, 1); +// parallax adjustment + float d = sphereIntersect(pos, dir, c, r2); + + { + vec3 v = pos + dir * d; + vi = v; + v -= c.xyz; + v = env_mat * v; + + float min_lod = textureQueryLod(reflectionProbes,v).y; // lower is higher res + return textureLod(reflectionProbes, vec4(v.xyz, refIndex[i].x), max(min_lod, lod)).rgb; + //return texture(reflectionProbes, vec4(v.xyz, refIndex[i].x)).rgb; + } +} + vec3 sampleRefMap(vec3 pos, vec3 dir, float lod) { float wsum = 0.0; - vec3 col = vec3(0,0,0); + float vd2 = dot(pos,pos); // view distance squared - for (int i = 0; i < refmapCount; ++i) - //int i = 0; + for (int idx = 0; idx < probeInfluences; ++idx) { - float r = 16.0; - vec3 delta = pos.xyz-refOrigin[i].xyz; - if (length(delta) < r) + int i = probeIndex[idx]; + float r = refSphere[i].w; // radius of sphere volume + float rr = r*r; // radius squred + 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; + { - float w = 1.0/max(dot(delta, delta), r); - w *= w; - w *= w; + vec3 vi; + vec3 refcol = tapRefMap(pos, dir, lod, refSphere[i].xyz, rr, i, vi); + + float w = 1.0/d2; - // parallax adjustment - float d = sphereIntersect(pos, dir, vec4(refOrigin[i].xyz, r)); + float atten = 1.0-max(d2-r2, 0.0)/(rr-r2); + w *= atten; - { - vec3 v = pos + dir * d; - v -= refOrigin[i].xyz; - v = env_mat * v; + col += refcol*w; + + wsum += w; + } + } - float min_lod = textureQueryLod(reflectionMap[i],v).y; // lower is higher res - col += textureLod(reflectionMap[i], v, max(min_lod, lod)).rgb*w; + if (probeInfluences <= 1) + { //edge-of-scene probe or no probe influence, mix in with embiggened version of probes closest to camera + for (int idx = 0; idx < 8; ++idx) + { + int i = idx; + vec3 delta = pos.xyz-refSphere[i].xyz; + float d2 = dot(delta,delta); + + { + vec3 vi; + vec3 refcol = tapRefMap(pos, dir, lod, refSphere[i].xyz, d2, i, vi); + + float w = 1.0/d2; + w *= w; + col += refcol*w; wsum += w; } } @@ -175,13 +341,6 @@ vec3 sampleRefMap(vec3 pos, vec3 dir, float lod) { col *= 1.0/wsum; } - else - { - // this pixel not covered by a probe, fallback to "full scene" environment map - vec3 v = env_mat * dir; - float min_lod = textureQueryLod(environmentMap, v).y; // lower is higher res - col = textureLod(environmentMap, v, max(min_lod, lod)).rgb; - } return col; } @@ -202,13 +361,26 @@ vec3 sampleAmbient(vec3 pos, vec3 dir, float lod) col *= 0.333333; - return col*0.6; // fudge darker + return col*0.8; // fudge darker } +// brighten a color so that at least one component is 1 +vec3 brighten(vec3 c) +{ + float m = max(max(c.r, c.g), c.b); + + if (m == 0) + { + return vec3(1,1,1); + } + + return c * 1.0/m; +} + void main() { - float reflection_lods = 11; // TODO -- base this on resolution of reflection map instead of hard coding + float reflection_lods = 8; // TODO -- base this on resolution of reflection map instead of hard coding vec2 tc = vary_fragcoord.xy; float depth = texture2DRect(depthMap, tc.xy).r; @@ -238,14 +410,16 @@ void main() vec3 amblit; vec3 additive; vec3 atten; + + getRefIndex(pos.xyz); + calcAtmosphericVars(pos.xyz, light_dir, ambocc, sunlit, amblit, additive, atten, true); //vec3 amb_vec = env_mat * norm.xyz; - vec3 ambenv = sampleAmbient(pos.xyz, norm.xyz, reflection_lods-1); - amblit = mix(ambenv, amblit, amblit); - color.rgb = amblit; - + vec3 ambenv = sampleAmbient(pos.xyz, norm.xyz, reflection_lods); + amblit = max(ambenv, amblit); + color.rgb = amblit*ambocc; //float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); //ambient *= 0.5; @@ -255,6 +429,7 @@ void main() vec3 sun_contrib = min(da, scol) * sunlit; color.rgb += sun_contrib; + color.rgb = min(color.rgb, vec3(1,1,1)); color.rgb *= diffuse.rgb; vec3 refnormpersp = reflect(pos.xyz, norm.xyz); @@ -274,26 +449,23 @@ void main() float lod = (1.0-spec.a)*reflection_lods; vec3 reflected_color = sampleRefMap(pos.xyz, normalize(refnormpersp), lod); - reflected_color *= 0.5; // fudge darker, not sure where there's a multiply by two and it's late + reflected_color *= 0.35; // fudge darker float fresnel = 1.0+dot(normalize(pos.xyz), norm.xyz); - fresnel += spec.a; - fresnel *= fresnel; - //fresnel *= spec.a; + float minf = spec.a * 0.1; + fresnel = fresnel * (1.0-minf) + minf; reflected_color *= spec.rgb*min(fresnel, 1.0); - //reflected_color = srgb_to_linear(reflected_color); - vec3 mixer = clamp(color.rgb + vec3(1,1,1) - spec.rgb, vec3(0,0,0), vec3(1,1,1)); - color.rgb = mix(reflected_color, color, mixer); + color.rgb += reflected_color; } color.rgb = mix(color.rgb, diffuse.rgb, diffuse.a); if (envIntensity > 0.0) { // add environmentmap - vec3 reflected_color = sampleRefMap(pos.xyz, normalize(refnormpersp), 0.0); + vec3 reflected_color = sampleRefMap(pos.xyz, normalize(refnormpersp), 0.0)*0.5; //fudge darker float fresnel = 1.0+dot(normalize(pos.xyz), norm.xyz); fresnel *= fresnel; - fresnel = fresnel * 0.95 + 0.05; - reflected_color *= fresnel; + fresnel = min(fresnel+envIntensity, 1.0); + reflected_color *= (envIntensity*fresnel)*brighten(spec.rgb); color = mix(color.rgb, reflected_color, envIntensity); } @@ -311,5 +483,7 @@ void main() // convert to linear as fullscreen lights need to sum in linear colorspace // and will be gamma (re)corrected downstream... + //color = vec3(ambocc); + //color = ambenv; frag_color.rgb = srgb_to_linear(color.rgb); } -- cgit v1.2.3 From 53c692c9597551c9a1ba8eee346432de51d9d22d Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 17 May 2022 14:32:07 -0500 Subject: SL-17416 Quick 'n dirty reflection probe override hack. --- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 3a1287e910..3607c325a4 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -55,6 +55,7 @@ layout (std140, binding = 1) uniform ReflectionProbes // refIndex.x - cubemap channel in reflectionProbes // refIndex.y - index in refNeighbor of neighbor list (index is ivec4 index, not int index) // refIndex.z - number of neighbors + // refIndex.w - priority ivec4 refIndex[REFMAP_COUNT]; // neighbor list data (refSphere indices, not cubemap array layer) @@ -296,6 +297,7 @@ vec3 sampleRefMap(vec3 pos, vec3 dir, float lod) { int i = probeIndex[idx]; float r = refSphere[i].w; // radius of sphere volume + float p = float(refIndex[i].w); // priority float rr = r*r; // radius squred float r1 = r * 0.1; // 75% of radius (outer sphere to start interpolating down) vec3 delta = pos.xyz-refSphere[i].xyz; @@ -310,7 +312,7 @@ vec3 sampleRefMap(vec3 pos, vec3 dir, float lod) float atten = 1.0-max(d2-r2, 0.0)/(rr-r2); w *= atten; - + w *= p; // boost weight based on priority col += refcol*w; wsum += w; -- cgit v1.2.3 From 63878a60eb8ab6884ed3aeec63a28e5089636092 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 18 May 2022 23:09:57 -0500 Subject: SL-17416 Box reflection probe influence volumes --- .../shaders/class2/deferred/softenLightF.glsl | 130 +++++++++++++++++---- 1 file changed, 109 insertions(+), 21 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 3607c325a4..d188233a8d 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -48,14 +48,20 @@ uniform sampler2D lightFunc; layout (std140, binding = 1) uniform ReflectionProbes { - // list of sphere based reflection probes sorted by distance to camera (closest first) + // list of OBBs for user override probes + // box is a set of 3 planes outward facing planes and the depth of the box along that plane + // for each box refBox[i]... + /// box[0..2] - plane 0 .. 2 in [A,B,C,D] notation + // box[3][0..2] - plane thickness + mat4 refBox[REFMAP_COUNT]; + // list of bounding spheres for reflection probes sorted by distance to camera (closest first) vec4 refSphere[REFMAP_COUNT]; // index of cube map in reflectionProbes for a corresponding reflection probe // e.g. cube map channel of refSphere[2] is stored in refIndex[2] // refIndex.x - cubemap channel in reflectionProbes // refIndex.y - index in refNeighbor of neighbor list (index is ivec4 index, not int index) // refIndex.z - number of neighbors - // refIndex.w - priority + // refIndex.w - priority, if negative, this probe has a box influence ivec4 refIndex[REFMAP_COUNT]; // neighbor list data (refSphere indices, not cubemap array layer) @@ -103,15 +109,38 @@ int probeIndex[REF_SAMPLE_COUNT]; // number of probes stored in probeIndex int probeInfluences = 0; +bool isAbove(vec3 pos, vec4 plane) +{ + return (dot(plane.xyz, pos) + plane.w) > 0; +} // return true if probe at index i influences position pos bool shouldSampleProbe(int i, vec3 pos) { - vec3 delta = pos.xyz - refSphere[i].xyz; - float d = dot(delta, delta); - float r2 = refSphere[i].w; - r2 *= r2; - return d < r2; + if (refIndex[i].w < 0) + { + vec4 v = refBox[i] * vec4(pos, 1.0); + if (abs(v.x) > 1 || + abs(v.y) > 1 || + abs(v.z) > 1) + { + return false; + } + } + 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; + } + } + + return true; } // populate "probeIndex" with N probe indices that influence pos where N is REF_SAMPLE_COUNT @@ -245,7 +274,7 @@ bool intersect(const Ray &ray) const } */ // adapted -- assume that origin is inside sphere, return distance from origin to edge of sphere -float sphereIntersect(vec3 origin, vec3 dir, vec3 center, float radius2) +vec3 sphereIntersect(vec3 origin, vec3 dir, vec3 center, float radius2) { float t0, t1; // solutions for t if the ray intersects @@ -258,9 +287,60 @@ float sphereIntersect(vec3 origin, vec3 dir, vec3 center, float radius2) t0 = tca - thc; t1 = tca + thc; - return t1; + vec3 v = origin + dir * t1; + return v; } +// from https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/ +/* +vec3 DirectionWS = normalize(PositionWS - CameraWS); +vec3 ReflDirectionWS = reflect(DirectionWS, NormalWS); + +// Intersection with OBB convertto unit box space +// Transform in local unit parallax cube space (scaled and rotated) +vec3 RayLS = MulMatrix( float(3x3)WorldToLocal, ReflDirectionWS); +vec3 PositionLS = MulMatrix( WorldToLocal, PositionWS); + +vec3 Unitary = vec3(1.0f, 1.0f, 1.0f); +vec3 FirstPlaneIntersect = (Unitary - PositionLS) / RayLS; +vec3 SecondPlaneIntersect = (-Unitary - PositionLS) / RayLS; +vec3 FurthestPlane = max(FirstPlaneIntersect, SecondPlaneIntersect); +float Distance = min(FurthestPlane.x, min(FurthestPlane.y, FurthestPlane.z)); + +// Use Distance in WS directly to recover intersection +vec3 IntersectPositionWS = PositionWS + ReflDirectionWS * Distance; +vec3 ReflDirectionWS = IntersectPositionWS - CubemapPositionWS; + +return texCUBE(envMap, ReflDirectionWS); +*/ + +// get point of intersection with given probe's box influence volume +// 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) +{ + // Intersection with OBB convertto unit box space + // Transform in local unit parallax cube space (scaled and rotated) + mat4 clipToLocal = refBox[i]; + + vec3 RayLS = mat3(clipToLocal) * dir; + vec3 PositionLS = (clipToLocal * vec4(origin, 1.0)).xyz; + + vec3 Unitary = vec3(1.0f, 1.0f, 1.0f); + vec3 FirstPlaneIntersect = (Unitary - PositionLS) / RayLS; + vec3 SecondPlaneIntersect = (-Unitary - PositionLS) / RayLS; + vec3 FurthestPlane = max(FirstPlaneIntersect, SecondPlaneIntersect); + float Distance = min(FurthestPlane.x, min(FurthestPlane.y, FurthestPlane.z)); + + // Use Distance in CS directly to recover intersection + vec3 IntersectPositionCS = origin + dir * Distance; + + return IntersectPositionCS; +} + + + // Tap a sphere based reflection probe // pos - position of pixel // dir - pixel normal @@ -269,18 +349,24 @@ float sphereIntersect(vec3 origin, vec3 dir, vec3 center, float radius2) // r2 - radius of probe squared // i - index of probe // vi - point at which reflection vector struck the influence volume, in clip space -vec3 tapRefMap(vec3 pos, vec3 dir, float lod, vec3 c, float r2, int i, out vec3 vi) +vec3 tapRefMap(vec3 pos, vec3 dir, float lod, vec3 c, float r2, int i) { //lod = max(lod, 1); -// parallax adjustment - float d = sphereIntersect(pos, dir, c, r2); + // parallax adjustment + vec3 v; + if (refIndex[i].w < 0) + { + v = boxIntersect(pos, dir, i); + } + else { - vec3 v = pos + dir * d; - vi = v; - v -= c.xyz; - v = env_mat * v; + v = sphereIntersect(pos, dir, c, r2); + } + v -= c; + v = env_mat * v; + { float min_lod = textureQueryLod(reflectionProbes,v).y; // lower is higher res return textureLod(reflectionProbes, vec4(v.xyz, refIndex[i].x), max(min_lod, lod)).rgb; //return texture(reflectionProbes, vec4(v.xyz, refIndex[i].x)).rgb; @@ -297,7 +383,7 @@ vec3 sampleRefMap(vec3 pos, vec3 dir, float lod) { int i = probeIndex[idx]; float r = refSphere[i].w; // radius of sphere volume - float p = float(refIndex[i].w); // priority + float p = float(abs(refIndex[i].w)); // priority float rr = r*r; // radius squred float r1 = r * 0.1; // 75% of radius (outer sphere to start interpolating down) vec3 delta = pos.xyz-refSphere[i].xyz; @@ -305,8 +391,7 @@ vec3 sampleRefMap(vec3 pos, vec3 dir, float lod) float r2 = r1*r1; { - vec3 vi; - vec3 refcol = tapRefMap(pos, dir, lod, refSphere[i].xyz, rr, i, vi); + vec3 refcol = tapRefMap(pos, dir, lod, refSphere[i].xyz, rr, i); float w = 1.0/d2; @@ -323,13 +408,16 @@ vec3 sampleRefMap(vec3 pos, vec3 dir, float lod) { //edge-of-scene probe or no probe influence, mix in with embiggened version of probes closest to camera for (int idx = 0; idx < 8; ++idx) { + if (refIndex[idx].w < 0) + { // don't fallback to box probes, they are *very* specific + continue; + } int i = idx; vec3 delta = pos.xyz-refSphere[i].xyz; float d2 = dot(delta,delta); { - vec3 vi; - vec3 refcol = tapRefMap(pos, dir, lod, refSphere[i].xyz, d2, i, vi); + vec3 refcol = tapRefMap(pos, dir, lod, refSphere[i].xyz, d2, i); float w = 1.0/d2; w *= w; -- cgit v1.2.3 From 02fb1bd6103cad5538fc170e015f4329f3545542 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 18 May 2022 23:51:06 -0500 Subject: Make reflection probe ambiance controllable by a saved setting --- .../newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index d188233a8d..d6b173b89d 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -69,6 +69,9 @@ layout (std140, binding = 1) uniform ReflectionProbes // number of reflection probes present in refSphere int refmapCount; + + // intensity of ambient light from reflection probes + float reflectionAmbiance; }; uniform float blur_size; @@ -451,7 +454,7 @@ vec3 sampleAmbient(vec3 pos, vec3 dir, float lod) col *= 0.333333; - return col*0.8; // fudge darker + return col*reflectionAmbiance; } @@ -507,7 +510,7 @@ void main() //vec3 amb_vec = env_mat * norm.xyz; - vec3 ambenv = sampleAmbient(pos.xyz, norm.xyz, reflection_lods); + vec3 ambenv = sampleAmbient(pos.xyz, norm.xyz, reflection_lods-1); amblit = max(ambenv, amblit); color.rgb = amblit*ambocc; -- cgit v1.2.3 From 3564b24e2a90e0772c37185cc5dcedca29d62ab8 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 19 May 2022 22:24:41 -0500 Subject: SL-17286 Reflection probe alpha/fullbright support. --- .../shaders/class2/deferred/reflectionProbeF.glsl | 476 +++++++++++++++++++++ .../shaders/class2/deferred/softenLightF.glsl | 436 +------------------ 2 files changed, 494 insertions(+), 418 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl new file mode 100644 index 0000000000..8c1323ba1a --- /dev/null +++ b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl @@ -0,0 +1,476 @@ +/** + * @file class2/deferred/reflectionProbeF.glsl + * + * $LicenseInfo:firstyear=2022&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2022, 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$ + */ + +#extension GL_ARB_shader_texture_lod : enable + +#define FLT_MAX 3.402823466e+38 + +#define REFMAP_COUNT 256 +#define REF_SAMPLE_COUNT 64 //maximum number of samples to consider + +uniform samplerCubeArray reflectionProbes; + +layout (std140, binding = 1) uniform ReflectionProbes +{ + // list of OBBs for user override probes + // box is a set of 3 planes outward facing planes and the depth of the box along that plane + // for each box refBox[i]... + /// box[0..2] - plane 0 .. 2 in [A,B,C,D] notation + // box[3][0..2] - plane thickness + mat4 refBox[REFMAP_COUNT]; + // list of bounding spheres for reflection probes sorted by distance to camera (closest first) + vec4 refSphere[REFMAP_COUNT]; + // index of cube map in reflectionProbes for a corresponding reflection probe + // e.g. cube map channel of refSphere[2] is stored in refIndex[2] + // refIndex.x - cubemap channel in reflectionProbes + // refIndex.y - index in refNeighbor of neighbor list (index is ivec4 index, not int index) + // refIndex.z - number of neighbors + // refIndex.w - priority, if negative, this probe has a box influence + ivec4 refIndex[REFMAP_COUNT]; + + // neighbor list data (refSphere indices, not cubemap array layer) + ivec4 refNeighbor[1024]; + + // number of reflection probes present in refSphere + int refmapCount; + + // intensity of ambient light from reflection probes + float reflectionAmbiance; +}; + +// Inputs +uniform mat3 env_mat; + +// list of probeIndexes shader will actually use after "getRefIndex" is called +// (stores refIndex/refSphere indices, NOT rerflectionProbes layer) +int probeIndex[REF_SAMPLE_COUNT]; + +// number of probes stored in probeIndex +int probeInfluences = 0; + +bool isAbove(vec3 pos, vec4 plane) +{ + return (dot(plane.xyz, pos) + plane.w) > 0; +} + +// return true if probe at index i influences position pos +bool shouldSampleProbe(int i, vec3 pos) +{ + if (refIndex[i].w < 0) + { + vec4 v = refBox[i] * vec4(pos, 1.0); + if (abs(v.x) > 1 || + abs(v.y) > 1 || + abs(v.z) > 1) + { + return false; + } + } + 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; + } + } + + return true; +} + +// call before sampleRef +// populate "probeIndex" with N probe indices that influence pos where N is REF_SAMPLE_COUNT +// overall algorithm -- +void preProbeSample(vec3 pos) +{ + // TODO: make some sort of structure that reduces the number of distance checks + + for (int i = 0; i < refmapCount; ++i) + { + // found an influencing probe + if (shouldSampleProbe(i, pos)) + { + probeIndex[probeInfluences] = i; + ++probeInfluences; + + int neighborIdx = refIndex[i].y; + if (neighborIdx != -1) + { + int neighborCount = min(refIndex[i].z, REF_SAMPLE_COUNT-1); + + int count = 0; + while (count < neighborCount) + { + // check up to REF_SAMPLE_COUNT-1 neighbors (neighborIdx is ivec4 index) + + int idx = refNeighbor[neighborIdx].x; + if (shouldSampleProbe(idx, pos)) + { + probeIndex[probeInfluences++] = idx; + if (probeInfluences == REF_SAMPLE_COUNT) + { + return; + } + } + count++; + if (count == neighborCount) + { + return; + } + + idx = refNeighbor[neighborIdx].y; + if (shouldSampleProbe(idx, pos)) + { + probeIndex[probeInfluences++] = idx; + if (probeInfluences == REF_SAMPLE_COUNT) + { + return; + } + } + count++; + if (count == neighborCount) + { + return; + } + + idx = refNeighbor[neighborIdx].z; + if (shouldSampleProbe(idx, pos)) + { + probeIndex[probeInfluences++] = idx; + if (probeInfluences == REF_SAMPLE_COUNT) + { + return; + } + } + count++; + if (count == neighborCount) + { + return; + } + + idx = refNeighbor[neighborIdx].w; + if (shouldSampleProbe(idx, pos)) + { + probeIndex[probeInfluences++] = idx; + if (probeInfluences == REF_SAMPLE_COUNT) + { + return; + } + } + count++; + if (count == neighborCount) + { + return; + } + + ++neighborIdx; + } + + return; + } + } + } +} + +// from https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-sphere-intersection + +// original reference implementation: +/* +bool intersect(const Ray &ray) const +{ + float t0, t1; // solutions for t if the ray intersects +#if 0 + // geometric solution + Vec3f L = center - orig; + float tca = L.dotProduct(dir); + // if (tca < 0) return false; + float d2 = L.dotProduct(L) - tca * tca; + if (d2 > radius2) return false; + float thc = sqrt(radius2 - d2); + t0 = tca - thc; + t1 = tca + thc; +#else + // analytic solution + Vec3f L = orig - center; + float a = dir.dotProduct(dir); + float b = 2 * dir.dotProduct(L); + float c = L.dotProduct(L) - radius2; + if (!solveQuadratic(a, b, c, t0, t1)) return false; +#endif + if (t0 > t1) std::swap(t0, t1); + + if (t0 < 0) { + t0 = t1; // if t0 is negative, let's use t1 instead + if (t0 < 0) return false; // both t0 and t1 are negative + } + + t = t0; + + return true; +} */ + +// adapted -- assume that origin is inside sphere, return distance from origin to edge of sphere +vec3 sphereIntersect(vec3 origin, vec3 dir, vec3 center, float radius2) +{ + float t0, t1; // solutions for t if the ray intersects + + vec3 L = center - origin; + float tca = dot(L,dir); + + float d2 = dot(L,L) - tca * tca; + + float thc = sqrt(radius2 - d2); + t0 = tca - thc; + t1 = tca + thc; + + vec3 v = origin + dir * t1; + return v; +} + +// from https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/ +/* +vec3 DirectionWS = normalize(PositionWS - CameraWS); +vec3 ReflDirectionWS = reflect(DirectionWS, NormalWS); + +// Intersection with OBB convertto unit box space +// Transform in local unit parallax cube space (scaled and rotated) +vec3 RayLS = MulMatrix( float(3x3)WorldToLocal, ReflDirectionWS); +vec3 PositionLS = MulMatrix( WorldToLocal, PositionWS); + +vec3 Unitary = vec3(1.0f, 1.0f, 1.0f); +vec3 FirstPlaneIntersect = (Unitary - PositionLS) / RayLS; +vec3 SecondPlaneIntersect = (-Unitary - PositionLS) / RayLS; +vec3 FurthestPlane = max(FirstPlaneIntersect, SecondPlaneIntersect); +float Distance = min(FurthestPlane.x, min(FurthestPlane.y, FurthestPlane.z)); + +// Use Distance in WS directly to recover intersection +vec3 IntersectPositionWS = PositionWS + ReflDirectionWS * Distance; +vec3 ReflDirectionWS = IntersectPositionWS - CubemapPositionWS; + +return texCUBE(envMap, ReflDirectionWS); +*/ + +// get point of intersection with given probe's box influence volume +// 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) +{ + // Intersection with OBB convertto unit box space + // Transform in local unit parallax cube space (scaled and rotated) + mat4 clipToLocal = refBox[i]; + + vec3 RayLS = mat3(clipToLocal) * dir; + vec3 PositionLS = (clipToLocal * vec4(origin, 1.0)).xyz; + + vec3 Unitary = vec3(1.0f, 1.0f, 1.0f); + vec3 FirstPlaneIntersect = (Unitary - PositionLS) / RayLS; + vec3 SecondPlaneIntersect = (-Unitary - PositionLS) / RayLS; + vec3 FurthestPlane = max(FirstPlaneIntersect, SecondPlaneIntersect); + float Distance = min(FurthestPlane.x, min(FurthestPlane.y, FurthestPlane.z)); + + // Use Distance in CS directly to recover intersection + vec3 IntersectPositionCS = origin + dir * Distance; + + return IntersectPositionCS; +} + + + +// Tap a sphere based reflection probe +// pos - position of pixel +// dir - pixel normal +// lod - which mip to bias towards (lower is higher res, sharper reflections) +// c - center of probe +// r2 - radius of probe squared +// i - index of probe +// vi - point at which reflection vector struck the influence volume, in clip space +vec3 tapRefMap(vec3 pos, vec3 dir, float lod, vec3 c, float r2, int i) +{ + //lod = max(lod, 1); + // parallax adjustment + + vec3 v; + if (refIndex[i].w < 0) + { + v = boxIntersect(pos, dir, i); + } + else + { + v = sphereIntersect(pos, dir, c, r2); + } + + v -= c; + v = env_mat * v; + { + float min_lod = textureQueryLod(reflectionProbes,v).y; // lower is higher res + return textureLod(reflectionProbes, vec4(v.xyz, refIndex[i].x), max(min_lod, lod)).rgb; + //return texture(reflectionProbes, vec4(v.xyz, refIndex[i].x)).rgb; + } +} + +vec3 sampleProbes(vec3 pos, vec3 dir, float lod) +{ + float wsum = 0.0; + vec3 col = vec3(0,0,0); + float vd2 = dot(pos,pos); // view distance squared + + for (int idx = 0; idx < probeInfluences; ++idx) + { + int i = probeIndex[idx]; + float r = refSphere[i].w; // radius of sphere volume + float p = float(abs(refIndex[i].w)); // priority + float rr = r*r; // radius squred + 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; + + { + vec3 refcol = tapRefMap(pos, dir, lod, refSphere[i].xyz, rr, i); + + float w = 1.0/d2; + + float atten = 1.0-max(d2-r2, 0.0)/(rr-r2); + w *= atten; + w *= p; // boost weight based on priority + col += refcol*w; + + wsum += w; + } + } + + if (probeInfluences <= 1) + { //edge-of-scene probe or no probe influence, mix in with embiggened version of probes closest to camera + for (int idx = 0; idx < 8; ++idx) + { + if (refIndex[idx].w < 0) + { // don't fallback to box probes, they are *very* specific + continue; + } + int i = idx; + vec3 delta = pos.xyz-refSphere[i].xyz; + float d2 = dot(delta,delta); + + { + vec3 refcol = tapRefMap(pos, dir, lod, refSphere[i].xyz, d2, i); + + float w = 1.0/d2; + w *= w; + col += refcol*w; + wsum += w; + } + } + } + + if (wsum > 0.0) + { + col *= 1.0/wsum; + } + + return col; +} + +vec3 sampleProbeAmbient(vec3 pos, vec3 dir, float lod) +{ + vec3 col = sampleProbes(pos, dir, lod); + + //desaturate + vec3 hcol = col *0.5; + + col *= 2.0; + col = vec3( + col.r + hcol.g + hcol.b, + col.g + hcol.r + hcol.b, + col.b + hcol.r + hcol.g + ); + + col *= 0.333333; + + return col*reflectionAmbiance; + +} + +// brighten a color so that at least one component is 1 +vec3 brighten(vec3 c) +{ + float m = max(max(c.r, c.g), c.b); + + if (m == 0) + { + return vec3(1,1,1); + } + + return c * 1.0/m; +} + + +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, + vec3 pos, vec3 norm, float glossiness, float envIntensity) +{ + // TODO - don't hard code lods + float reflection_lods = 8; + preProbeSample(pos); + + vec3 refnormpersp = reflect(pos.xyz, norm.xyz); + + ambenv = sampleProbeAmbient(pos, norm, reflection_lods-1); + + if (glossiness > 0.0) + { + float lod = (1.0-glossiness)*reflection_lods; + glossenv = sampleProbes(pos, normalize(refnormpersp), lod); + } + + if (envIntensity > 0.0) + { + legacyenv = sampleProbes(pos, normalize(refnormpersp), 0.0); + } +} + +void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 norm) +{ + glossenv *= 0.35; // fudge darker + float fresnel = 1.0+dot(normalize(pos.xyz), norm.xyz); + float minf = spec.a * 0.1; + fresnel = fresnel * (1.0-minf) + minf; + glossenv *= spec.rgb*min(fresnel, 1.0); + color.rgb += glossenv; +} + + void applyLegacyEnv(inout vec3 color, vec3 legacyenv, vec4 spec, vec3 pos, vec3 norm, float envIntensity) + { + vec3 reflected_color = legacyenv; //*0.5; //fudge darker + vec3 lookAt = normalize(pos); + float fresnel = 1.0+dot(lookAt, norm.xyz); + fresnel *= fresnel; + fresnel = min(fresnel+envIntensity, 1.0); + reflected_color *= (envIntensity*fresnel)*brighten(spec.rgb); + color = mix(color.rgb, reflected_color, envIntensity); + } \ No newline at end of file diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index d6b173b89d..d88400dddb 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -42,38 +42,8 @@ uniform sampler2DRect specularRect; uniform sampler2DRect normalMap; uniform sampler2DRect lightMap; uniform sampler2DRect depthMap; -uniform samplerCube environmentMap; -uniform samplerCubeArray reflectionProbes; uniform sampler2D lightFunc; -layout (std140, binding = 1) uniform ReflectionProbes -{ - // list of OBBs for user override probes - // box is a set of 3 planes outward facing planes and the depth of the box along that plane - // for each box refBox[i]... - /// box[0..2] - plane 0 .. 2 in [A,B,C,D] notation - // box[3][0..2] - plane thickness - mat4 refBox[REFMAP_COUNT]; - // list of bounding spheres for reflection probes sorted by distance to camera (closest first) - vec4 refSphere[REFMAP_COUNT]; - // index of cube map in reflectionProbes for a corresponding reflection probe - // e.g. cube map channel of refSphere[2] is stored in refIndex[2] - // refIndex.x - cubemap channel in reflectionProbes - // refIndex.y - index in refNeighbor of neighbor list (index is ivec4 index, not int index) - // refIndex.z - number of neighbors - // refIndex.w - priority, if negative, this probe has a box influence - ivec4 refIndex[REFMAP_COUNT]; - - // neighbor list data (refSphere indices, not cubemap array layer) - ivec4 refNeighbor[1024]; - - // number of reflection probes present in refSphere - int refmapCount; - - // intensity of ambient light from reflection probes - float reflectionAmbiance; -}; - uniform float blur_size; uniform float blur_fidelity; @@ -98,6 +68,12 @@ vec3 scaleSoftClipFrag(vec3 l); vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); vec3 fullbrightScaleSoftClip(vec3 light); +// reflection probe interface +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyEnv, + 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); + vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); @@ -105,376 +81,8 @@ vec3 srgb_to_linear(vec3 c); vec4 applyWaterFogView(vec3 pos, vec4 color); #endif -// list of probeIndexes shader will actually use after "getRefIndex" is called -// (stores refIndex/refSphere indices, NOT rerflectionProbes layer) -int probeIndex[REF_SAMPLE_COUNT]; - -// number of probes stored in probeIndex -int probeInfluences = 0; - -bool isAbove(vec3 pos, vec4 plane) -{ - return (dot(plane.xyz, pos) + plane.w) > 0; -} - -// return true if probe at index i influences position pos -bool shouldSampleProbe(int i, vec3 pos) -{ - if (refIndex[i].w < 0) - { - vec4 v = refBox[i] * vec4(pos, 1.0); - if (abs(v.x) > 1 || - abs(v.y) > 1 || - abs(v.z) > 1) - { - return false; - } - } - 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; - } - } - - return true; -} - -// populate "probeIndex" with N probe indices that influence pos where N is REF_SAMPLE_COUNT -// overall algorithm -- -void getRefIndex(vec3 pos) -{ - // TODO: make some sort of structure that reduces the number of distance checks - - for (int i = 0; i < refmapCount; ++i) - { - // found an influencing probe - if (shouldSampleProbe(i, pos)) - { - probeIndex[probeInfluences] = i; - ++probeInfluences; - - int neighborIdx = refIndex[i].y; - if (neighborIdx != -1) - { - int neighborCount = min(refIndex[i].z, REF_SAMPLE_COUNT-1); - - int count = 0; - while (count < neighborCount) - { - // check up to REF_SAMPLE_COUNT-1 neighbors (neighborIdx is ivec4 index) - - int idx = refNeighbor[neighborIdx].x; - if (shouldSampleProbe(idx, pos)) - { - probeIndex[probeInfluences++] = idx; - if (probeInfluences == REF_SAMPLE_COUNT) - { - return; - } - } - count++; - if (count == neighborCount) - { - return; - } - - idx = refNeighbor[neighborIdx].y; - if (shouldSampleProbe(idx, pos)) - { - probeIndex[probeInfluences++] = idx; - if (probeInfluences == REF_SAMPLE_COUNT) - { - return; - } - } - count++; - if (count == neighborCount) - { - return; - } - - idx = refNeighbor[neighborIdx].z; - if (shouldSampleProbe(idx, pos)) - { - probeIndex[probeInfluences++] = idx; - if (probeInfluences == REF_SAMPLE_COUNT) - { - return; - } - } - count++; - if (count == neighborCount) - { - return; - } - - idx = refNeighbor[neighborIdx].w; - if (shouldSampleProbe(idx, pos)) - { - probeIndex[probeInfluences++] = idx; - if (probeInfluences == REF_SAMPLE_COUNT) - { - return; - } - } - count++; - if (count == neighborCount) - { - return; - } - - ++neighborIdx; - } - - return; - } - } - } -} - -// from https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-sphere-intersection - -// original reference implementation: -/* -bool intersect(const Ray &ray) const -{ - float t0, t1; // solutions for t if the ray intersects -#if 0 - // geometric solution - Vec3f L = center - orig; - float tca = L.dotProduct(dir); - // if (tca < 0) return false; - float d2 = L.dotProduct(L) - tca * tca; - if (d2 > radius2) return false; - float thc = sqrt(radius2 - d2); - t0 = tca - thc; - t1 = tca + thc; -#else - // analytic solution - Vec3f L = orig - center; - float a = dir.dotProduct(dir); - float b = 2 * dir.dotProduct(L); - float c = L.dotProduct(L) - radius2; - if (!solveQuadratic(a, b, c, t0, t1)) return false; -#endif - if (t0 > t1) std::swap(t0, t1); - - if (t0 < 0) { - t0 = t1; // if t0 is negative, let's use t1 instead - if (t0 < 0) return false; // both t0 and t1 are negative - } - - t = t0; - - return true; -} */ - -// adapted -- assume that origin is inside sphere, return distance from origin to edge of sphere -vec3 sphereIntersect(vec3 origin, vec3 dir, vec3 center, float radius2) -{ - float t0, t1; // solutions for t if the ray intersects - - vec3 L = center - origin; - float tca = dot(L,dir); - - float d2 = dot(L,L) - tca * tca; - - float thc = sqrt(radius2 - d2); - t0 = tca - thc; - t1 = tca + thc; - - vec3 v = origin + dir * t1; - return v; -} - -// from https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/ -/* -vec3 DirectionWS = normalize(PositionWS - CameraWS); -vec3 ReflDirectionWS = reflect(DirectionWS, NormalWS); - -// Intersection with OBB convertto unit box space -// Transform in local unit parallax cube space (scaled and rotated) -vec3 RayLS = MulMatrix( float(3x3)WorldToLocal, ReflDirectionWS); -vec3 PositionLS = MulMatrix( WorldToLocal, PositionWS); - -vec3 Unitary = vec3(1.0f, 1.0f, 1.0f); -vec3 FirstPlaneIntersect = (Unitary - PositionLS) / RayLS; -vec3 SecondPlaneIntersect = (-Unitary - PositionLS) / RayLS; -vec3 FurthestPlane = max(FirstPlaneIntersect, SecondPlaneIntersect); -float Distance = min(FurthestPlane.x, min(FurthestPlane.y, FurthestPlane.z)); - -// Use Distance in WS directly to recover intersection -vec3 IntersectPositionWS = PositionWS + ReflDirectionWS * Distance; -vec3 ReflDirectionWS = IntersectPositionWS - CubemapPositionWS; - -return texCUBE(envMap, ReflDirectionWS); -*/ - -// get point of intersection with given probe's box influence volume -// 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) -{ - // Intersection with OBB convertto unit box space - // Transform in local unit parallax cube space (scaled and rotated) - mat4 clipToLocal = refBox[i]; - - vec3 RayLS = mat3(clipToLocal) * dir; - vec3 PositionLS = (clipToLocal * vec4(origin, 1.0)).xyz; - - vec3 Unitary = vec3(1.0f, 1.0f, 1.0f); - vec3 FirstPlaneIntersect = (Unitary - PositionLS) / RayLS; - vec3 SecondPlaneIntersect = (-Unitary - PositionLS) / RayLS; - vec3 FurthestPlane = max(FirstPlaneIntersect, SecondPlaneIntersect); - float Distance = min(FurthestPlane.x, min(FurthestPlane.y, FurthestPlane.z)); - - // Use Distance in CS directly to recover intersection - vec3 IntersectPositionCS = origin + dir * Distance; - - return IntersectPositionCS; -} - - - -// Tap a sphere based reflection probe -// pos - position of pixel -// dir - pixel normal -// lod - which mip to bias towards (lower is higher res, sharper reflections) -// c - center of probe -// r2 - radius of probe squared -// i - index of probe -// vi - point at which reflection vector struck the influence volume, in clip space -vec3 tapRefMap(vec3 pos, vec3 dir, float lod, vec3 c, float r2, int i) -{ - //lod = max(lod, 1); - // parallax adjustment - - vec3 v; - if (refIndex[i].w < 0) - { - v = boxIntersect(pos, dir, i); - } - else - { - v = sphereIntersect(pos, dir, c, r2); - } - - v -= c; - v = env_mat * v; - { - float min_lod = textureQueryLod(reflectionProbes,v).y; // lower is higher res - return textureLod(reflectionProbes, vec4(v.xyz, refIndex[i].x), max(min_lod, lod)).rgb; - //return texture(reflectionProbes, vec4(v.xyz, refIndex[i].x)).rgb; - } -} - -vec3 sampleRefMap(vec3 pos, vec3 dir, float lod) -{ - float wsum = 0.0; - vec3 col = vec3(0,0,0); - float vd2 = dot(pos,pos); // view distance squared - - for (int idx = 0; idx < probeInfluences; ++idx) - { - int i = probeIndex[idx]; - float r = refSphere[i].w; // radius of sphere volume - float p = float(abs(refIndex[i].w)); // priority - float rr = r*r; // radius squred - 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; - - { - vec3 refcol = tapRefMap(pos, dir, lod, refSphere[i].xyz, rr, i); - - float w = 1.0/d2; - - float atten = 1.0-max(d2-r2, 0.0)/(rr-r2); - w *= atten; - w *= p; // boost weight based on priority - col += refcol*w; - - wsum += w; - } - } - - if (probeInfluences <= 1) - { //edge-of-scene probe or no probe influence, mix in with embiggened version of probes closest to camera - for (int idx = 0; idx < 8; ++idx) - { - if (refIndex[idx].w < 0) - { // don't fallback to box probes, they are *very* specific - continue; - } - int i = idx; - vec3 delta = pos.xyz-refSphere[i].xyz; - float d2 = dot(delta,delta); - - { - vec3 refcol = tapRefMap(pos, dir, lod, refSphere[i].xyz, d2, i); - - float w = 1.0/d2; - w *= w; - col += refcol*w; - wsum += w; - } - } - } - - if (wsum > 0.0) - { - col *= 1.0/wsum; - } - - return col; -} - -vec3 sampleAmbient(vec3 pos, vec3 dir, float lod) -{ - vec3 col = sampleRefMap(pos, dir, lod); - - //desaturate - vec3 hcol = col *0.5; - - col *= 2.0; - col = vec3( - col.r + hcol.g + hcol.b, - col.g + hcol.r + hcol.b, - col.b + hcol.r + hcol.g - ); - - col *= 0.333333; - - return col*reflectionAmbiance; - -} - -// brighten a color so that at least one component is 1 -vec3 brighten(vec3 c) -{ - float m = max(max(c.r, c.g), c.b); - - if (m == 0) - { - return vec3(1,1,1); - } - - return c * 1.0/m; -} - void main() { - float reflection_lods = 8; // TODO -- base this on resolution of reflection map instead of hard coding - vec2 tc = vary_fragcoord.xy; float depth = texture2DRect(depthMap, tc.xy).r; vec4 pos = getPositionWithDepth(tc, depth); @@ -504,13 +112,15 @@ void main() vec3 additive; vec3 atten; - getRefIndex(pos.xyz); - calcAtmosphericVars(pos.xyz, light_dir, ambocc, sunlit, amblit, additive, atten, true); //vec3 amb_vec = env_mat * norm.xyz; - vec3 ambenv = sampleAmbient(pos.xyz, norm.xyz, reflection_lods-1); + vec3 ambenv; + vec3 glossenv; + vec3 legacyenv; + sampleReflectionProbes(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); + amblit = max(ambenv, amblit); color.rgb = amblit*ambocc; @@ -527,7 +137,6 @@ void main() vec3 refnormpersp = reflect(pos.xyz, norm.xyz); - vec3 env_vec = env_mat * refnormpersp; if (spec.a > 0.0) // specular reflection { float sa = dot(normalize(refnormpersp), light_dir.xyz); @@ -539,27 +148,16 @@ void main() color.rgb += spec_contrib; // add reflection map - EXPERIMENTAL WORK IN PROGRESS - - float lod = (1.0-spec.a)*reflection_lods; - vec3 reflected_color = sampleRefMap(pos.xyz, normalize(refnormpersp), lod); - reflected_color *= 0.35; // fudge darker - float fresnel = 1.0+dot(normalize(pos.xyz), norm.xyz); - float minf = spec.a * 0.1; - fresnel = fresnel * (1.0-minf) + minf; - reflected_color *= spec.rgb*min(fresnel, 1.0); - color.rgb += reflected_color; + applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); } color.rgb = mix(color.rgb, diffuse.rgb, diffuse.a); if (envIntensity > 0.0) { // add environmentmap - vec3 reflected_color = sampleRefMap(pos.xyz, normalize(refnormpersp), 0.0)*0.5; //fudge darker - float fresnel = 1.0+dot(normalize(pos.xyz), norm.xyz); - fresnel *= fresnel; - fresnel = min(fresnel+envIntensity, 1.0); - reflected_color *= (envIntensity*fresnel)*brighten(spec.rgb); - color = mix(color.rgb, reflected_color, envIntensity); + //fudge darker + legacyenv *= 0.5*diffuse.a+0.5;; + applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); } if (norm.w < 0.5) @@ -577,6 +175,8 @@ void main() // convert to linear as fullscreen lights need to sum in linear colorspace // and will be gamma (re)corrected downstream... //color = vec3(ambocc); - //color = ambenv; + //color = ambenv; + //color.b = diffuse.a; frag_color.rgb = srgb_to_linear(color.rgb); + frag_color.a = bloom; } -- cgit v1.2.3 From 0940e8871894e08da80730d11c31cbd252a05b35 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 24 May 2022 10:34:47 -0500 Subject: SL-17472 Add checkbox to preferences for enabling "PBR" that uses "class3" deferred shaders. Move reflection probe shaders to class3 and restore class2 shaders to non-reflection probe versions. --- .../shaders/class2/deferred/softenLightF.glsl | 52 ++++++---------------- 1 file changed, 14 insertions(+), 38 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index d88400dddb..7700d16007 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -26,10 +26,7 @@ #extension GL_ARB_texture_rectangle : enable #extension GL_ARB_shader_texture_lod : enable -#define FLT_MAX 3.402823466e+38 - -#define REFMAP_COUNT 256 -#define REF_SAMPLE_COUNT 64 //maximum number of samples to consider +/*[EXTRA_CODE_HERE]*/ #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; @@ -42,6 +39,7 @@ uniform sampler2DRect specularRect; uniform sampler2DRect normalMap; uniform sampler2DRect lightMap; uniform sampler2DRect depthMap; +uniform samplerCube environmentMap; uniform sampler2D lightFunc; uniform float blur_size; @@ -68,12 +66,6 @@ vec3 scaleSoftClipFrag(vec3 l); vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); vec3 fullbrightScaleSoftClip(vec3 light); -// reflection probe interface -void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyEnv, - 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); - vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); @@ -111,53 +103,40 @@ void main() vec3 amblit; vec3 additive; vec3 atten; - calcAtmosphericVars(pos.xyz, light_dir, ambocc, sunlit, amblit, additive, atten, true); - //vec3 amb_vec = env_mat * norm.xyz; + color.rgb = amblit; - vec3 ambenv; - vec3 glossenv; - vec3 legacyenv; - sampleReflectionProbes(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); - - amblit = max(ambenv, amblit); - color.rgb = amblit*ambocc; - - //float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); - //ambient *= 0.5; - //ambient *= ambient; - //ambient = (1.0 - ambient); - //color.rgb *= ambient; + float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0 - ambient); + color.rgb *= ambient; vec3 sun_contrib = min(da, scol) * sunlit; color.rgb += sun_contrib; - color.rgb = min(color.rgb, vec3(1,1,1)); color.rgb *= diffuse.rgb; - vec3 refnormpersp = reflect(pos.xyz, norm.xyz); + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); if (spec.a > 0.0) // specular reflection { - float sa = dot(normalize(refnormpersp), light_dir.xyz); + float sa = dot(refnormpersp, light_dir.xyz); vec3 dumbshiny = sunlit * scol * (texture2D(lightFunc, vec2(sa, spec.a)).r); // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; bloom = dot(spec_contrib, spec_contrib) / 6; color.rgb += spec_contrib; - - // add reflection map - EXPERIMENTAL WORK IN PROGRESS - applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); } color.rgb = mix(color.rgb, diffuse.rgb, diffuse.a); if (envIntensity > 0.0) { // add environmentmap - //fudge darker - legacyenv *= 0.5*diffuse.a+0.5;; - applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); + vec3 env_vec = env_mat * refnormpersp; + vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; + color = mix(color.rgb, reflected_color, envIntensity); } if (norm.w < 0.5) @@ -174,9 +153,6 @@ void main() // convert to linear as fullscreen lights need to sum in linear colorspace // and will be gamma (re)corrected downstream... - //color = vec3(ambocc); - //color = ambenv; - //color.b = diffuse.a; frag_color.rgb = srgb_to_linear(color.rgb); - frag_color.a = bloom; + frag_color.a = bloom; } -- cgit v1.2.3 From 77b96114c30232c1d3f3b548bf982f89f11d09da Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 21 Jun 2022 22:00:12 -0700 Subject: SL-17274 Cleanup hard-coded gbuffer atmos flag for softenlight --- indra/newview/app_settings/shaders/class2/deferred/skyF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl index 6841a8194f..4379024680 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -195,5 +195,5 @@ void main() // Gamma correct for WL (soft clip effect). frag_data[0] = vec4(color.rgb, 1.0); frag_data[1] = vec4(0.0, 0.0, 0.0, 0.0); - frag_data[2] = vec4(0.0, 0.0, 0.0, 1.0); // 1.0 in norm.w masks off fog + frag_data[2] = vec4(0.0, 0.0, 0.0, GBUFFER_FLAG_SKIP_ATMOS); // 1.0 in norm.w masks off fog } -- cgit v1.2.3 From 27ca7760cc4126c8c45a5c22edafee5d2984a742 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 21 Jun 2022 22:23:38 -0700 Subject: SL-17274: Remove hard-coded magic number checking if G-Buffer flag is set --- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 7700d16007..dfb93c17dc 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -139,7 +139,7 @@ void main() color = mix(color.rgb, reflected_color, envIntensity); } - if (norm.w < 0.5) + if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_ATMOS)) { color = mix(atmosFragLighting(color, additive, atten), fullbrightAtmosTransportFrag(color, additive, atten), diffuse.a); color = mix(scaleSoftClipFrag(color), fullbrightScaleSoftClip(color), diffuse.a); -- cgit v1.2.3 From bb5b552e75058fac3af2c15fd464acfb16f7fcf2 Mon Sep 17 00:00:00 2001 From: Brad Kittenbrink Date: Fri, 24 Jun 2022 00:03:43 -0700 Subject: fix DRTVWR-559 mac build coding policy error for missing newline at EOF --- .../newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl index 8c1323ba1a..ab5badf538 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl @@ -473,4 +473,5 @@ void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 no fresnel = min(fresnel+envIntensity, 1.0); reflected_color *= (envIntensity*fresnel)*brighten(spec.rgb); color = mix(color.rgb, reflected_color, envIntensity); - } \ No newline at end of file + } + -- cgit v1.2.3 From 2ec7a9af8212211a15a65e5301e44807e2e4e53d Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 29 Jun 2022 08:43:33 -0700 Subject: SL-17274: Fix typo in reference to SL-14035 --- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index dfb93c17dc..677c9c244c 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -88,7 +88,7 @@ void main() da = pow(da, light_gamma); vec4 diffuse = texture2DRect(diffuseRect, tc); - diffuse.rgb = linear_to_srgb(diffuse.rgb); // SL-14025 + diffuse.rgb = linear_to_srgb(diffuse.rgb); // SL-14035 vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; -- cgit v1.2.3 From 88e1740d205bdfaa57d1d5dec4e6e9e755eae075 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Thu, 1 Sep 2022 16:18:14 -0700 Subject: SL-17967 - block layout binding acceptable to apple --- .../newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl index ab5badf538..3d96fe25be 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl @@ -32,7 +32,7 @@ uniform samplerCubeArray reflectionProbes; -layout (std140, binding = 1) uniform ReflectionProbes +layout (std140) uniform ReflectionProbes { // list of OBBs for user override probes // box is a set of 3 planes outward facing planes and the depth of the box along that plane -- cgit v1.2.3 From e5d463ca200bdfa93b8c65e588d490c2f23e3918 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 22 Sep 2022 17:27:18 -0500 Subject: SL-17705 Backwards compatibility pass. Support OpenGL pre-4.0 by disabling reflection probes and anti-aliasing. Get render parity with current release viewer when reflection probes are disabled. --- .../shaders/class2/deferred/reflectionProbeF.glsl | 451 +-------------------- 1 file changed, 21 insertions(+), 430 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl index 3d96fe25be..15d6b5a05d 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl @@ -23,455 +23,46 @@ * $/LicenseInfo$ */ -#extension GL_ARB_shader_texture_lod : enable +// Implementation for when reflection probes are disabled -#define FLT_MAX 3.402823466e+38 +uniform float minimumReflectionAmbiance; -#define REFMAP_COUNT 256 -#define REF_SAMPLE_COUNT 64 //maximum number of samples to consider +uniform samplerCube environmentMap; -uniform samplerCubeArray reflectionProbes; - -layout (std140) uniform ReflectionProbes -{ - // list of OBBs for user override probes - // box is a set of 3 planes outward facing planes and the depth of the box along that plane - // for each box refBox[i]... - /// box[0..2] - plane 0 .. 2 in [A,B,C,D] notation - // box[3][0..2] - plane thickness - mat4 refBox[REFMAP_COUNT]; - // list of bounding spheres for reflection probes sorted by distance to camera (closest first) - vec4 refSphere[REFMAP_COUNT]; - // index of cube map in reflectionProbes for a corresponding reflection probe - // e.g. cube map channel of refSphere[2] is stored in refIndex[2] - // refIndex.x - cubemap channel in reflectionProbes - // refIndex.y - index in refNeighbor of neighbor list (index is ivec4 index, not int index) - // refIndex.z - number of neighbors - // refIndex.w - priority, if negative, this probe has a box influence - ivec4 refIndex[REFMAP_COUNT]; - - // neighbor list data (refSphere indices, not cubemap array layer) - ivec4 refNeighbor[1024]; - - // number of reflection probes present in refSphere - int refmapCount; - - // intensity of ambient light from reflection probes - float reflectionAmbiance; -}; - -// Inputs uniform mat3 env_mat; -// list of probeIndexes shader will actually use after "getRefIndex" is called -// (stores refIndex/refSphere indices, NOT rerflectionProbes layer) -int probeIndex[REF_SAMPLE_COUNT]; - -// number of probes stored in probeIndex -int probeInfluences = 0; - -bool isAbove(vec3 pos, vec4 plane) -{ - return (dot(plane.xyz, pos) + plane.w) > 0; -} - -// return true if probe at index i influences position pos -bool shouldSampleProbe(int i, vec3 pos) -{ - if (refIndex[i].w < 0) - { - vec4 v = refBox[i] * vec4(pos, 1.0); - if (abs(v.x) > 1 || - abs(v.y) > 1 || - abs(v.z) > 1) - { - return false; - } - } - 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; - } - } - - return true; -} - -// call before sampleRef -// populate "probeIndex" with N probe indices that influence pos where N is REF_SAMPLE_COUNT -// overall algorithm -- -void preProbeSample(vec3 pos) -{ - // TODO: make some sort of structure that reduces the number of distance checks - - for (int i = 0; i < refmapCount; ++i) - { - // found an influencing probe - if (shouldSampleProbe(i, pos)) - { - probeIndex[probeInfluences] = i; - ++probeInfluences; - - int neighborIdx = refIndex[i].y; - if (neighborIdx != -1) - { - int neighborCount = min(refIndex[i].z, REF_SAMPLE_COUNT-1); - - int count = 0; - while (count < neighborCount) - { - // check up to REF_SAMPLE_COUNT-1 neighbors (neighborIdx is ivec4 index) - - int idx = refNeighbor[neighborIdx].x; - if (shouldSampleProbe(idx, pos)) - { - probeIndex[probeInfluences++] = idx; - if (probeInfluences == REF_SAMPLE_COUNT) - { - return; - } - } - count++; - if (count == neighborCount) - { - return; - } - - idx = refNeighbor[neighborIdx].y; - if (shouldSampleProbe(idx, pos)) - { - probeIndex[probeInfluences++] = idx; - if (probeInfluences == REF_SAMPLE_COUNT) - { - return; - } - } - count++; - if (count == neighborCount) - { - return; - } - - idx = refNeighbor[neighborIdx].z; - if (shouldSampleProbe(idx, pos)) - { - probeIndex[probeInfluences++] = idx; - if (probeInfluences == REF_SAMPLE_COUNT) - { - return; - } - } - count++; - if (count == neighborCount) - { - return; - } - - idx = refNeighbor[neighborIdx].w; - if (shouldSampleProbe(idx, pos)) - { - probeIndex[probeInfluences++] = idx; - if (probeInfluences == REF_SAMPLE_COUNT) - { - return; - } - } - count++; - if (count == neighborCount) - { - return; - } - - ++neighborIdx; - } - - return; - } - } - } -} - -// from https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-sphere-intersection - -// original reference implementation: -/* -bool intersect(const Ray &ray) const -{ - float t0, t1; // solutions for t if the ray intersects -#if 0 - // geometric solution - Vec3f L = center - orig; - float tca = L.dotProduct(dir); - // if (tca < 0) return false; - float d2 = L.dotProduct(L) - tca * tca; - if (d2 > radius2) return false; - float thc = sqrt(radius2 - d2); - t0 = tca - thc; - t1 = tca + thc; -#else - // analytic solution - Vec3f L = orig - center; - float a = dir.dotProduct(dir); - float b = 2 * dir.dotProduct(L); - float c = L.dotProduct(L) - radius2; - if (!solveQuadratic(a, b, c, t0, t1)) return false; -#endif - if (t0 > t1) std::swap(t0, t1); - - if (t0 < 0) { - t0 = t1; // if t0 is negative, let's use t1 instead - if (t0 < 0) return false; // both t0 and t1 are negative - } - - t = t0; - - return true; -} */ - -// adapted -- assume that origin is inside sphere, return distance from origin to edge of sphere -vec3 sphereIntersect(vec3 origin, vec3 dir, vec3 center, float radius2) -{ - float t0, t1; // solutions for t if the ray intersects - - vec3 L = center - origin; - float tca = dot(L,dir); - - float d2 = dot(L,L) - tca * tca; - - float thc = sqrt(radius2 - d2); - t0 = tca - thc; - t1 = tca + thc; - - vec3 v = origin + dir * t1; - return v; -} - -// from https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/ -/* -vec3 DirectionWS = normalize(PositionWS - CameraWS); -vec3 ReflDirectionWS = reflect(DirectionWS, NormalWS); - -// Intersection with OBB convertto unit box space -// Transform in local unit parallax cube space (scaled and rotated) -vec3 RayLS = MulMatrix( float(3x3)WorldToLocal, ReflDirectionWS); -vec3 PositionLS = MulMatrix( WorldToLocal, PositionWS); - -vec3 Unitary = vec3(1.0f, 1.0f, 1.0f); -vec3 FirstPlaneIntersect = (Unitary - PositionLS) / RayLS; -vec3 SecondPlaneIntersect = (-Unitary - PositionLS) / RayLS; -vec3 FurthestPlane = max(FirstPlaneIntersect, SecondPlaneIntersect); -float Distance = min(FurthestPlane.x, min(FurthestPlane.y, FurthestPlane.z)); - -// Use Distance in WS directly to recover intersection -vec3 IntersectPositionWS = PositionWS + ReflDirectionWS * Distance; -vec3 ReflDirectionWS = IntersectPositionWS - CubemapPositionWS; +vec3 srgb_to_linear(vec3 c); -return texCUBE(envMap, ReflDirectionWS); -*/ - -// get point of intersection with given probe's box influence volume -// 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) -{ - // Intersection with OBB convertto unit box space - // Transform in local unit parallax cube space (scaled and rotated) - mat4 clipToLocal = refBox[i]; - - vec3 RayLS = mat3(clipToLocal) * dir; - vec3 PositionLS = (clipToLocal * vec4(origin, 1.0)).xyz; - - vec3 Unitary = vec3(1.0f, 1.0f, 1.0f); - vec3 FirstPlaneIntersect = (Unitary - PositionLS) / RayLS; - vec3 SecondPlaneIntersect = (-Unitary - PositionLS) / RayLS; - vec3 FurthestPlane = max(FirstPlaneIntersect, SecondPlaneIntersect); - float Distance = min(FurthestPlane.x, min(FurthestPlane.y, FurthestPlane.z)); - - // Use Distance in CS directly to recover intersection - vec3 IntersectPositionCS = origin + dir * Distance; - - return IntersectPositionCS; -} - - - -// Tap a sphere based reflection probe -// pos - position of pixel -// dir - pixel normal -// lod - which mip to bias towards (lower is higher res, sharper reflections) -// c - center of probe -// r2 - radius of probe squared -// i - index of probe -// vi - point at which reflection vector struck the influence volume, in clip space -vec3 tapRefMap(vec3 pos, vec3 dir, float lod, vec3 c, float r2, int i) +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, + vec3 pos, vec3 norm, float glossiness) { - //lod = max(lod, 1); - // parallax adjustment - - vec3 v; - if (refIndex[i].w < 0) - { - v = boxIntersect(pos, dir, i); - } - else - { - v = sphereIntersect(pos, dir, c, r2); - } - - v -= c; - v = env_mat * v; - { - float min_lod = textureQueryLod(reflectionProbes,v).y; // lower is higher res - return textureLod(reflectionProbes, vec4(v.xyz, refIndex[i].x), max(min_lod, lod)).rgb; - //return texture(reflectionProbes, vec4(v.xyz, refIndex[i].x)).rgb; - } -} - -vec3 sampleProbes(vec3 pos, vec3 dir, float lod) -{ - float wsum = 0.0; - vec3 col = vec3(0,0,0); - float vd2 = dot(pos,pos); // view distance squared - - for (int idx = 0; idx < probeInfluences; ++idx) - { - int i = probeIndex[idx]; - float r = refSphere[i].w; // radius of sphere volume - float p = float(abs(refIndex[i].w)); // priority - float rr = r*r; // radius squred - 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; - - { - vec3 refcol = tapRefMap(pos, dir, lod, refSphere[i].xyz, rr, i); - - float w = 1.0/d2; - - float atten = 1.0-max(d2-r2, 0.0)/(rr-r2); - w *= atten; - w *= p; // boost weight based on priority - col += refcol*w; - - wsum += w; - } - } - - if (probeInfluences <= 1) - { //edge-of-scene probe or no probe influence, mix in with embiggened version of probes closest to camera - for (int idx = 0; idx < 8; ++idx) - { - if (refIndex[idx].w < 0) - { // don't fallback to box probes, they are *very* specific - continue; - } - int i = idx; - vec3 delta = pos.xyz-refSphere[i].xyz; - float d2 = dot(delta,delta); - - { - vec3 refcol = tapRefMap(pos, dir, lod, refSphere[i].xyz, d2, i); - - float w = 1.0/d2; - w *= w; - col += refcol*w; - wsum += w; - } - } - } - - if (wsum > 0.0) - { - col *= 1.0/wsum; - } + ambenv = vec3(0,0,0); - return col; + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + vec3 env_vec = env_mat * refnormpersp; + glossenv = srgb_to_linear(textureCube(environmentMap, env_vec).rgb); } -vec3 sampleProbeAmbient(vec3 pos, vec3 dir, float lod) +void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, + vec3 pos, vec3 norm, float glossiness, float envIntensity) { - vec3 col = sampleProbes(pos, dir, lod); - - //desaturate - vec3 hcol = col *0.5; - - col *= 2.0; - col = vec3( - col.r + hcol.g + hcol.b, - col.g + hcol.r + hcol.b, - col.b + hcol.r + hcol.g - ); + ambenv = vec3(0,0,0); - col *= 0.333333; + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + vec3 env_vec = env_mat * refnormpersp; - return col*reflectionAmbiance; + legacyenv = textureCube(environmentMap, env_vec).rgb; + glossenv = legacyenv; } -// brighten a color so that at least one component is 1 -vec3 brighten(vec3 c) -{ - float m = max(max(c.r, c.g), c.b); - - if (m == 0) - { - return vec3(1,1,1); - } - - return c * 1.0/m; -} - - -void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, - vec3 pos, vec3 norm, float glossiness, float envIntensity) +void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 norm) { - // TODO - don't hard code lods - float reflection_lods = 8; - preProbeSample(pos); - - vec3 refnormpersp = reflect(pos.xyz, norm.xyz); - - ambenv = sampleProbeAmbient(pos, norm, reflection_lods-1); - - if (glossiness > 0.0) - { - float lod = (1.0-glossiness)*reflection_lods; - glossenv = sampleProbes(pos, normalize(refnormpersp), lod); - } - - if (envIntensity > 0.0) - { - legacyenv = sampleProbes(pos, normalize(refnormpersp), 0.0); - } + } -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) { - glossenv *= 0.35; // fudge darker - float fresnel = 1.0+dot(normalize(pos.xyz), norm.xyz); - float minf = spec.a * 0.1; - fresnel = fresnel * (1.0-minf) + minf; - glossenv *= spec.rgb*min(fresnel, 1.0); - color.rgb += glossenv; + color = mix(color.rgb, legacyenv, envIntensity); } - void applyLegacyEnv(inout vec3 color, vec3 legacyenv, vec4 spec, vec3 pos, vec3 norm, float envIntensity) - { - vec3 reflected_color = legacyenv; //*0.5; //fudge darker - vec3 lookAt = normalize(pos); - float fresnel = 1.0+dot(lookAt, norm.xyz); - fresnel *= fresnel; - fresnel = min(fresnel+envIntensity, 1.0); - reflected_color *= (envIntensity*fresnel)*brighten(spec.rgb); - color = mix(color.rgb, reflected_color, envIntensity); - } - -- cgit v1.2.3 From 725d042640f5b0474b58e6a1af0a4063c7e5cfc2 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 26 Sep 2022 17:17:34 -0500 Subject: SL-18190 WIP - Windlight to linear space proof of concept, better parity between release viewer and materials viewer when reflections disabled. Avoid run-away probe ambiance. --- .../app_settings/shaders/class2/deferred/reflectionProbeF.glsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl index 15d6b5a05d..a7cac6c523 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl @@ -25,7 +25,7 @@ // Implementation for when reflection probes are disabled -uniform float minimumReflectionAmbiance; +uniform float reflection_probe_ambiance; uniform samplerCube environmentMap; @@ -36,7 +36,7 @@ vec3 srgb_to_linear(vec3 c); void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, vec3 pos, vec3 norm, float glossiness) { - ambenv = vec3(0,0,0); + ambenv = vec3(reflection_probe_ambiance * 0.25); vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); vec3 env_vec = env_mat * refnormpersp; @@ -46,7 +46,7 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, vec3 pos, vec3 norm, float glossiness, float envIntensity) { - ambenv = vec3(0,0,0); + ambenv = vec3(reflection_probe_ambiance * 0.25); vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); vec3 env_vec = env_mat * refnormpersp; -- cgit v1.2.3 From aaf7b17db047f0cb2630b479d5468062e6ca815e Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 27 Sep 2022 23:32:02 -0500 Subject: SL-18190 WIP -- Take 2 on linear space windlight (more methodical approach -- make desired interface but brute force color conversions). Placeholder PBR water and move to deprecate forward rendering shaders. --- .../shaders/class2/deferred/alphaF.glsl | 306 +++++++++++++++++++++ .../shaders/class2/deferred/pbralphaF.glsl | 234 ++++++++++++++++ .../shaders/class2/windlight/atmosphericsF.glsl | 20 ++ .../class2/windlight/atmosphericsFuncs.glsl | 148 ++++++++++ .../shaders/class2/windlight/gammaF.glsl | 16 ++ .../shaders/class2/windlight/skyV.glsl | 2 - .../shaders/class2/windlight/transportF.glsl | 13 + 7 files changed, 737 insertions(+), 2 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl create mode 100644 indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl create mode 100644 indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl new file mode 100644 index 0000000000..39aec699fe --- /dev/null +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl @@ -0,0 +1,306 @@ +/** + * @file alphaF.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$ + */ + +//class2/deferred/alphaF.glsl + +#extension GL_ARB_texture_rectangle : enable + +/*[EXTRA_CODE_HERE]*/ + +#define INDEXED 1 +#define NON_INDEXED 2 +#define NON_INDEXED_NO_COLOR 3 + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform mat3 env_mat; +uniform vec3 sun_dir; +uniform vec3 moon_dir; + +#ifdef USE_DIFFUSE_TEX +uniform sampler2D diffuseMap; +#endif + +VARYING vec3 vary_fragcoord; +VARYING vec3 vary_position; +VARYING vec2 vary_texcoord0; +VARYING vec3 vary_norm; + +#ifdef USE_VERTEX_COLOR +VARYING vec4 vertex_color; //vertex color should be treated as sRGB +#endif + +#ifdef HAS_ALPHA_MASK +uniform float minimum_alpha; +#endif + +uniform mat4 proj_mat; +uniform mat4 inv_proj; +uniform vec2 screen_res; +uniform int sun_up_factor; +uniform vec4 light_position[8]; +uniform vec3 light_direction[8]; +uniform vec4 light_attenuation[8]; +uniform vec3 light_diffuse[8]; + +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 color); +#endif + +vec3 srgb_to_linear(vec3 c); +vec3 linear_to_srgb(vec3 c); + +vec2 encode_normal (vec3 n); +vec3 scaleSoftClipFragLinear(vec3 l); +vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten); + +void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive, bool use_ao); + +#ifdef HAS_SHADOW +float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); +#endif + +float getAmbientClamp(); + +void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, + 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) +{ + // SL-14895 inverted attenuation work-around + // This routine is tweaked to match deferred lighting, but previously used an inverted la value. To reconstruct + // that previous value now that the inversion is corrected, we reverse the calculations in LLPipeline::setupHWLights() + // to recover the `adjusted_radius` value previously being sent as la. + float falloff_factor = (12.0 * fa) - 9.0; + float inverted_la = falloff_factor / la; + // Yes, it makes me want to cry as well. DJH + + vec3 col = vec3(0); + + //get light vector + vec3 lv = lp.xyz-v; + + //get distance + float dist = length(lv); + float da = 1.0; + + /*if (dist > inverted_la) + { + return col; + } + + clip to projector bounds + vec4 proj_tc = proj_mat * lp; + + if (proj_tc.z < 0 + || proj_tc.z > 1 + || proj_tc.x < 0 + || proj_tc.x > 1 + || proj_tc.y < 0 + || proj_tc.y > 1) + { + return col; + }*/ + + if (dist > 0.0 && inverted_la > 0.0) + { + dist /= inverted_la; + + //normalize light vector + lv = normalize(lv); + + //distance attenuation + float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); + dist_atten *= dist_atten; + dist_atten *= 2.0f; + + if (dist_atten <= 0.0) + { + return col; + } + + // spotlight coefficient. + float spot = max(dot(-ln, lv), is_pointlight); + da *= spot*spot; // GL_SPOT_EXPONENT=2 + + //angular attenuation + da *= dot(n, lv); + da = max(0.0, da); + + float lit = 0.0f; + + float amb_da = 0.0;//ambiance; + if (da > 0) + { + lit = max(da * dist_atten,0.0); + col = lit * light_col * diffuse; + amb_da += (da*0.5+0.5) * ambiance; + } + amb_da += (da*da*0.5 + 0.5) * ambiance; + amb_da *= dist_atten; + amb_da = min(amb_da, 1.0f - lit); + + // SL-10969 ... need to work out why this blows out in many setups... + //col.rgb += amb_da * light_col * diffuse; + + // no spec for alpha shader... + } + col = max(col, vec3(0)); + return col; +} + +void main() +{ + vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; + frag *= screen_res; + + vec4 pos = vec4(vary_position, 1.0); + vec3 norm = vary_norm; + + float shadow = 1.0f; + +#ifdef HAS_SHADOW + shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, frag); +#endif + +#ifdef USE_DIFFUSE_TEX + vec4 diffuse_tap = texture2D(diffuseMap,vary_texcoord0.xy); +#endif + +#ifdef USE_INDEXED_TEX + vec4 diffuse_tap = diffuseLookup(vary_texcoord0.xy); +#endif + + vec4 diffuse_srgb = diffuse_tap; + +#ifdef FOR_IMPOSTOR + vec4 color; + color.rgb = diffuse_srgb.rgb; + color.a = 1.0; + + float final_alpha = diffuse_srgb.a * vertex_color.a; + diffuse_srgb.rgb *= vertex_color.rgb; + + // Insure we don't pollute depth with invis pixels in impostor rendering + // + if (final_alpha < minimum_alpha) + { + discard; + } + + color.rgb = diffuse_srgb.rgb; + color.a = final_alpha; + +#else // FOR_IMPOSTOR + + vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); + + vec3 light_dir = (sun_up_factor == 1) ? sun_dir: moon_dir; + + float final_alpha = diffuse_linear.a; + +#ifdef USE_VERTEX_COLOR + final_alpha *= vertex_color.a; + + if (final_alpha < minimum_alpha) + { // TODO: figure out how to get invisible faces out of + // render batches without breaking glow + discard; + } + + diffuse_srgb.rgb *= vertex_color.rgb; + diffuse_linear.rgb = srgb_to_linear(diffuse_srgb.rgb); +#endif // USE_VERTEX_COLOR + + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; + + calcAtmosphericVarsLinear(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); + + vec3 ambenv; + vec3 glossenv; + vec3 legacyenv; + sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, 0.0, 0.0); + + + float da = dot(norm.xyz, light_dir.xyz); + da = clamp(da, -1.0, 1.0); + + float final_da = da; + final_da = clamp(final_da, 0.0f, 1.0f); + + vec4 color = vec4(0.0); + + color.a = final_alpha; + + float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0 - ambient); + + vec3 sun_contrib = min(final_da, shadow) * sunlit; + + color.rgb = max(amblit, ambenv); + color.rgb *= ambient; + + color.rgb += sun_contrib; + + color.rgb *= diffuse_linear.rgb; + + color.rgb = atmosFragLightingLinear(color.rgb, additive, atten); + color.rgb = scaleSoftClipFragLinear(color.rgb); + + vec4 light = vec4(0,0,0,0); + + #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diffuse_linear.rgb, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, light_attenuation[i].w); + + LIGHT_LOOP(1) + LIGHT_LOOP(2) + LIGHT_LOOP(3) + LIGHT_LOOP(4) + LIGHT_LOOP(5) + LIGHT_LOOP(6) + LIGHT_LOOP(7) + + // sum local light contrib in linear colorspace +#if !defined(LOCAL_LIGHT_KILL) + color.rgb += light.rgb; +#endif // !defined(LOCAL_LIGHT_KILL) + +#ifdef WATER_FOG + color = applyWaterFogView(pos.xyz, color); +#endif // WATER_FOG + +#endif // #else // FOR_IMPOSTOR + + frag_color = color; +} + diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl new file mode 100644 index 0000000000..f49a7bd169 --- /dev/null +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -0,0 +1,234 @@ +/** + * @file class1\deferred\pbralphaF.glsl + * + * $LicenseInfo:firstyear=2022&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2022, 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$ + */ + +/*[EXTRA_CODE_HERE]*/ + +uniform sampler2D diffuseMap; //always in sRGB space +uniform sampler2D bumpMap; +uniform sampler2D emissiveMap; +uniform sampler2D specularMap; // PBR: Packed: Occlusion, Metal, Roughness + +uniform float metallicFactor; +uniform float roughnessFactor; +uniform vec3 emissiveColor; + +#if defined(HAS_SUN_SHADOW) || defined(HAS_SSAO) +uniform sampler2DRect lightMap; +#endif + +uniform int sun_up_factor; +uniform vec3 sun_dir; +uniform vec3 moon_dir; + +out vec4 frag_color; + +#ifdef HAS_SHADOW + VARYING vec3 vary_fragcoord; + uniform vec2 screen_res; +#endif + +VARYING vec3 vary_position; +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; +VARYING vec2 vary_texcoord1; +VARYING vec2 vary_texcoord2; +VARYING vec3 vary_normal; +VARYING vec3 vary_tangent; +flat in float vary_sign; + + +#ifdef HAS_ALPHA_MASK +uniform float minimum_alpha; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlphaCutoff() +#endif + +// Lights +// See: LLRender::syncLightState() +uniform vec4 light_position[8]; +uniform vec3 light_direction[8]; // spot direction +uniform vec4 light_attenuation[8]; // linear, quadratic, is omni, unused, See: LLPipeline::setupHWLights() and syncLightState() +uniform vec3 light_diffuse[8]; +uniform vec2 light_deferred_attenuation[8]; // light size and falloff + +vec3 srgb_to_linear(vec3 c); +vec3 linear_to_srgb(vec3 c); + +// These are in deferredUtil.glsl but we can't set: mFeatures.isDeferred to include it +void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); +vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten); +vec3 scaleSoftClipFragLinear(vec3 l); + +void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist); +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); + +// PBR interface +vec3 pbrIbl(vec3 diffuseColor, + vec3 specularColor, + vec3 radiance, // radiance map sample + vec3 irradiance, // irradiance map sample + float ao, // ambient occlusion factor + float nv, // normal dot view vector + float perceptualRoughness); + +vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, + float perceptualRoughness, + float metallic, + vec3 n, // normal + vec3 v, // surface point to camera + vec3 l); //surface point to light + +vec3 calcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, + float perceptualRoughness, + float metallic, + vec3 n, // normal + vec3 p, // pixel position + vec3 v, // view vector (negative normalized pixel position) + vec3 lp, // light position + vec3 ld, // light direction (for spotlights) + vec3 lightColor, + float lightSize, float falloff, float is_pointlight, float ambiance) +{ + vec3 color = vec3(0,0,0); + + vec3 lv = lp.xyz - p; + + float lightDist = length(lv); + + float dist = lightDist / lightSize; + if (dist <= 1.0) + { + lv /= lightDist; + + float dist_atten = calcLegacyDistanceAttenuation(dist, falloff); + + vec3 intensity = dist_atten * lightColor * 3.0; + + color = intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, lv); + } + + return color; +} + +void main() +{ + vec3 color = vec3(0,0,0); + + vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + vec3 pos = vary_position; + + float scol = 1.0; + float ambocc = 1.0; + + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; + calcAtmosphericVarsLinear(pos.xyz, light_dir, ambocc, sunlit, amblit, additive, atten, true); + + +// IF .mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels; +// vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb; +// else + vec4 albedo = texture(diffuseMap, vary_texcoord0.xy).rgba; + albedo.rgb = srgb_to_linear(albedo.rgb); +#ifdef HAS_ALPHA_MASK + if (albedo.a < minimum_alpha) + { + discard; + } +#endif + + vec3 baseColor = vertex_color.rgb * albedo.rgb; + + vec3 vNt = texture(bumpMap, vary_texcoord1.xy).xyz*2.0-1.0; + float sign = vary_sign; + vec3 vN = vary_normal; + vec3 vT = vary_tangent.xyz; + + vec3 vB = sign * cross(vN, vT); + vec3 norm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN ); + + norm *= gl_FrontFacing ? 1.0 : -1.0; + +#ifdef HAS_SHADOW + vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; + frag *= screen_res; + scol = sampleDirectionalShadow(pos.xyz, norm.xyz, frag); +#endif + + vec3 orm = texture(specularMap, vary_texcoord2.xy).rgb; //orm is packed into "emissiveRect" to keep the data in linear color space + + float perceptualRoughness = orm.g * roughnessFactor; + float metallic = orm.b * metallicFactor; + float ao = orm.r; + + // emissiveColor is the emissive color factor from GLTF and is already in linear space + vec3 colorEmissive = emissiveColor; + // emissiveMap here is a vanilla RGB texture encoded as sRGB, manually convert to linear + colorEmissive *= srgb_to_linear(texture2D(emissiveMap, vary_texcoord0.xy).rgb); + + // PBR IBL + float gloss = 1.0 - perceptualRoughness; + vec3 irradiance = vec3(0); + vec3 radiance = vec3(0); + sampleReflectionProbes(irradiance, radiance, pos.xyz, norm.xyz, gloss); + irradiance = max(amblit*1.5,irradiance); + + vec3 f0 = vec3(0.04); + + vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0); + diffuseColor *= 1.0 - metallic; + + vec3 specularColor = mix(f0, baseColor.rgb, metallic); + + vec3 v = -normalize(pos.xyz); + float NdotV = clamp(abs(dot(norm.xyz, v)), 0.001, 1.0); + + color += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, perceptualRoughness); + color += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, v, light_dir) * sunlit*2.75 * scol; + color += colorEmissive; + + vec3 light = vec3(0); + + // Punctual lights +#define LIGHT_LOOP(i) light += calcPointLightOrSpotLight(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, pos.xyz, v, light_position[i].xyz, light_direction[i].xyz, light_diffuse[i].rgb, light_deferred_attenuation[i].x, light_deferred_attenuation[i].y, light_attenuation[i].z, light_attenuation[i].w); + + LIGHT_LOOP(1) + LIGHT_LOOP(2) + LIGHT_LOOP(3) + LIGHT_LOOP(4) + LIGHT_LOOP(5) + LIGHT_LOOP(6) + LIGHT_LOOP(7) + + color.rgb += light.rgb; + + color = atmosFragLightingLinear(color, additive, atten); + color = scaleSoftClipFragLinear(color); + + frag_color = vec4(color.rgb,albedo.a * vertex_color.a); +} diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index ee9c990b12..ecf1545d2d 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -29,6 +29,26 @@ vec3 scaleSoftClipFrag(vec3 light); uniform int no_atmo; +vec3 srgb_to_linear(vec3 col); +vec3 linear_to_srgb(vec3 col); + +vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten) +{ + if (no_atmo == 1) + { + return light; + } + + light = linear_to_srgb(light); + additive = linear_to_srgb(additive); + atten = linear_to_srgb(atten); + + light *= atten.r; + light += additive; + return srgb_to_linear(light); +} + + vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) { if (no_atmo == 1) diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl new file mode 100644 index 0000000000..e7e1938a11 --- /dev/null +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl @@ -0,0 +1,148 @@ +/** + * @file class2\windlight\atmosphericsFuncs.glsl + * + * $LicenseInfo:firstyear=2022&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2022, 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 vec4 lightnorm; +uniform vec4 sunlight_color; +uniform vec4 moonlight_color; +uniform int sun_up_factor; +uniform vec4 ambient_color; +uniform vec4 blue_horizon; +uniform vec4 blue_density; +uniform float haze_horizon; +uniform float haze_density; +uniform float cloud_shadow; +uniform float density_multiplier; +uniform float distance_multiplier; +uniform float max_y; +uniform vec4 glow; +uniform float scene_light_strength; +uniform mat3 ssao_effect_mat; +uniform int no_atmo; +uniform float sun_moon_glow_factor; + +vec3 srgb_to_linear(vec3 col); + +float getAmbientClamp() { return 1.0f; } + +// return colors in sRGB space +void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, + out vec3 atten, bool use_ao) +{ + vec3 rel_pos = inPositionEye; + + //(TERRAIN) limit altitude + if (abs(rel_pos.y) > max_y) rel_pos *= (max_y / rel_pos.y); + + vec3 rel_pos_norm = normalize(rel_pos); + float rel_pos_len = length(rel_pos); + vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; + + // sunlight attenuation effect (hue and brightness) due to atmosphere + // this is used later for sunlight modulation at various altitudes + vec4 light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + // I had thought blue_density and haze_density should have equal weighting, + // but attenuation due to haze_density tends to seem too strong + + vec4 combined_haze = blue_density + vec4(haze_density); + vec4 blue_weight = blue_density / combined_haze; + vec4 haze_weight = vec4(haze_density) / combined_haze; + + //(TERRAIN) compute sunlight from lightnorm y component. Factor is roughly cosecant(sun elevation) (for short rays like terrain) + float above_horizon_factor = 1.0 / max(1e-6, lightnorm.y); + sunlight *= exp(-light_atten * above_horizon_factor); // for sun [horizon..overhead] this maps to an exp curve [0..1] + + // main atmospheric scattering line integral + float density_dist = rel_pos_len * density_multiplier; + + // Transparency (-> combined_haze) + // ATI Bugfix -- can't store combined_haze*density_dist*distance_multiplier in a variable because the ati + // compiler gets confused. + combined_haze = exp(-combined_haze * density_dist * distance_multiplier); + + // final atmosphere attenuation factor + atten = combined_haze.rgb; + + // compute haze glow + float haze_glow = dot(rel_pos_norm, lightnorm.xyz); + + // dampen sun additive contrib when not facing it... + // SL-13539: This "if" clause causes an "additive" white artifact at roughly 77 degreees. + // if (length(light_dir) > 0.01) + haze_glow *= max(0.0f, dot(light_dir, rel_pos_norm)); + + haze_glow = 1. - haze_glow; + // haze_glow is 0 at the sun and increases away from sun + haze_glow = max(haze_glow, .001); // set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + haze_glow *= glow.x; + // higher glow.x gives dimmer glow (because next step is 1 / "angle") + haze_glow = pow(haze_glow, glow.z); + // glow.z should be negative, so we're doing a sort of (1 / "angle") function + + // add "minimum anti-solar illumination" + haze_glow += .25; + + haze_glow *= sun_moon_glow_factor; + + vec4 amb_color = ambient_color; + + // increase ambient when there are more clouds + vec4 tmpAmbient = amb_color + (vec4(1.) - amb_color) * cloud_shadow * 0.5; + + /* decrease value and saturation (that in HSV, not HSL) for occluded areas + * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html + * // The following line of code performs the equivalent of: + * float ambAlpha = tmpAmbient.a; + * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis + * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); + * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, + * ambAlpha); + */ + if (use_ao) + { + tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); + } + + // Similar/Shared Algorithms: + // indra\llinventory\llsettingssky.cpp -- LLSettingsSky::calculateLightSettings() + // indra\newview\app_settings\shaders\class1\windlight\atmosphericsFuncs.glsl -- calcAtmosphericVars() + // haze color + vec3 cs = sunlight.rgb * (1. - cloud_shadow); + additive = (blue_horizon.rgb * blue_weight.rgb) * (cs + tmpAmbient.rgb) + (haze_horizon * haze_weight.rgb) * (cs * haze_glow + tmpAmbient.rgb); + + // brightness of surface both sunlight and ambient + sunlit = sunlight.rgb; + amblit = tmpAmbient.rgb; + additive *= vec3(1.0 - combined_haze); +} + +// return colors in linear space +void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, + out vec3 atten, bool use_ao) +{ + calcAtmosphericVars(inPositionEye, light_dir, ambFactor, sunlit, amblit, additive, atten, use_ao); + sunlit = srgb_to_linear(sunlit)*2.25; + amblit = srgb_to_linear(amblit)*0.15; + additive = srgb_to_linear(additive); + atten = srgb_to_linear(atten); +} diff --git a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl index 68db7fcbb1..6dfb2e7cf6 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl @@ -28,6 +28,22 @@ uniform int no_atmo; vec3 getAtmosAttenuation(); vec3 getAdditiveColor(); +vec3 srgb_to_linear(vec3 col); +vec3 linear_to_srgb(vec3 col); + +vec3 scaleSoftClipFragLinear(vec3 light) +{ + if (no_atmo == 1) + { + return light; + } + light = linear_to_srgb(light); + //soft clip effect: + light = 1. - clamp(light, vec3(0.), vec3(1.)); + light = 1. - pow(light, vec3(gamma)); // s/b inverted already CPU-side + return srgb_to_linear(light); +} + vec3 scaleSoftClipFrag(vec3 light) { if (no_atmo == 1) diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl index a0a33b8642..3edc94f4ca 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl @@ -55,8 +55,6 @@ uniform float max_y; uniform vec4 glow; uniform float sun_moon_glow_factor; -uniform vec4 cloud_color; - void main() { // World / view / projection diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index b53a2e237f..4bf2275e6a 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -32,6 +32,9 @@ vec3 getAtmosAttenuation(); uniform int no_atmo; +vec3 srgb_to_linear(vec3 col); +vec3 linear_to_srgb(vec3 col); + vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { light *= atten.r; @@ -44,6 +47,16 @@ vec3 atmosTransport(vec3 light) return atmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); } +vec3 fullbrightAtmosTransportFragLinear(vec3 light, vec3 additive, vec3 atten) +{ + light = linear_to_srgb(light); + additive = linear_to_srgb(additive); + atten = linear_to_srgb(atten); + + float brightness = dot(light.rgb * 0.5, vec3(0.3333)) + 0.1; + return srgb_to_linear(mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive, brightness * brightness)); +} + vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { float brightness = dot(light.rgb * 0.5, vec3(0.3333)) + 0.1; -- cgit v1.2.3 From 67c7a13647d7b337efc97c7c48386b0b60918915 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 27 Sep 2022 23:46:03 -0500 Subject: SL-18190 Missed magic number. --- indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index f49a7bd169..93c51ba313 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -196,7 +196,7 @@ void main() vec3 irradiance = vec3(0); vec3 radiance = vec3(0); sampleReflectionProbes(irradiance, radiance, pos.xyz, norm.xyz, gloss); - irradiance = max(amblit*1.5,irradiance); + irradiance = max(amblit,irradiance); vec3 f0 = vec3(0.04); -- cgit v1.2.3 From a63fcfc9d584075bb263ccf10857852b3327be43 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 28 Sep 2022 00:15:34 -0500 Subject: SL-18190 Remove some (likely) superfluous color space conversions --- .../shaders/class2/windlight/atmosphericsF.glsl | 15 +++++---------- .../app_settings/shaders/class2/windlight/gammaF.glsl | 5 ++--- .../app_settings/shaders/class2/windlight/transportF.glsl | 7 ++----- 3 files changed, 9 insertions(+), 18 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index ecf1545d2d..e578f618da 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -32,32 +32,27 @@ uniform int no_atmo; vec3 srgb_to_linear(vec3 col); vec3 linear_to_srgb(vec3 col); -vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten) +vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) { if (no_atmo == 1) { return light; } - - light = linear_to_srgb(light); - additive = linear_to_srgb(additive); - atten = linear_to_srgb(atten); - light *= atten.r; light += additive; - return srgb_to_linear(light); + return light * 2.0; } - -vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) +vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten) { if (no_atmo == 1) { return light; } + light *= atten.r; light += additive; - return light * 2.0; + return light; } vec3 atmosLighting(vec3 light) diff --git a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl index 6dfb2e7cf6..a32a572461 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl @@ -32,16 +32,15 @@ vec3 srgb_to_linear(vec3 col); vec3 linear_to_srgb(vec3 col); vec3 scaleSoftClipFragLinear(vec3 light) -{ +{ // identical to non-linear version and that's probably close enough if (no_atmo == 1) { return light; } - light = linear_to_srgb(light); //soft clip effect: light = 1. - clamp(light, vec3(0.), vec3(1.)); light = 1. - pow(light, vec3(gamma)); // s/b inverted already CPU-side - return srgb_to_linear(light); + return light; } vec3 scaleSoftClipFrag(vec3 light) diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index 4bf2275e6a..ecf0430a88 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -49,12 +49,9 @@ vec3 atmosTransport(vec3 light) vec3 fullbrightAtmosTransportFragLinear(vec3 light, vec3 additive, vec3 atten) { - light = linear_to_srgb(light); - additive = linear_to_srgb(additive); - atten = linear_to_srgb(atten); - + // same as non-linear version, probably fine float brightness = dot(light.rgb * 0.5, vec3(0.3333)) + 0.1; - return srgb_to_linear(mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive, brightness * brightness)); + return mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive, brightness * brightness); } vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) -- cgit v1.2.3 From f887f65830c05d15517cbd8f15ca0e59210dfbee Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 28 Sep 2022 16:49:11 -0500 Subject: SL-18190 WIP - Linear space atmospherics take 2 --- .../shaders/class2/deferred/pbralphaF.glsl | 9 +- .../shaders/class2/windlight/atmosphericsF.glsl | 2 +- .../class2/windlight/atmosphericsFuncs.glsl | 96 +++++++++++++++++++++- 3 files changed, 99 insertions(+), 8 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index 93c51ba313..e6cb8f37c7 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -196,7 +196,7 @@ void main() vec3 irradiance = vec3(0); vec3 radiance = vec3(0); sampleReflectionProbes(irradiance, radiance, pos.xyz, norm.xyz, gloss); - irradiance = max(amblit,irradiance); + irradiance = max(amblit*2.0,irradiance); vec3 f0 = vec3(0.04); @@ -212,6 +212,9 @@ void main() color += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, v, light_dir) * sunlit*2.75 * scol; color += colorEmissive; + color = atmosFragLightingLinear(color, additive, atten); + color = scaleSoftClipFragLinear(color); + vec3 light = vec3(0); // Punctual lights @@ -227,8 +230,6 @@ void main() color.rgb += light.rgb; - color = atmosFragLightingLinear(color, additive, atten); - color = scaleSoftClipFragLinear(color); - + frag_color = vec4(color.rgb,albedo.a * vertex_color.a); } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index e578f618da..20b1e3513e 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -52,7 +52,7 @@ vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten) light *= atten.r; light += additive; - return light; + return light*2.0; } vec3 atmosLighting(vec3 light) diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl index e7e1938a11..516550be1c 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl @@ -22,15 +22,24 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ + +vec3 srgb_to_linear(vec3 col); + uniform vec4 lightnorm; uniform vec4 sunlight_color; +vec3 sunlight_linear = srgb_to_linear(sunlight_color.rgb); uniform vec4 moonlight_color; +vec3 moonlight_linear = srgb_to_linear(moonlight_color.rgb); uniform int sun_up_factor; uniform vec4 ambient_color; +vec3 ambient_linear = srgb_to_linear(ambient_color.rgb); uniform vec4 blue_horizon; +vec3 blue_horizon_linear = srgb_to_linear(blue_horizon.rgb); uniform vec4 blue_density; +vec3 blue_density_linear = srgb_to_linear(blue_density.rgb); uniform float haze_horizon; uniform float haze_density; +vec3 haze_density_linear = srgb_to_linear(vec3(haze_density)); uniform float cloud_shadow; uniform float density_multiplier; uniform float distance_multiplier; @@ -41,8 +50,6 @@ uniform mat3 ssao_effect_mat; uniform int no_atmo; uniform float sun_moon_glow_factor; -vec3 srgb_to_linear(vec3 col); - float getAmbientClamp() { return 1.0f; } // return colors in sRGB space @@ -136,13 +143,96 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou additive *= vec3(1.0 - combined_haze); } + + + // return colors in linear space void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao) { - calcAtmosphericVars(inPositionEye, light_dir, ambFactor, sunlit, amblit, additive, atten, use_ao); +#if 0 + calcAtmosphericVars(inPositionEye, light_dir, 1.0, sunlit, amblit, additive, atten, false); sunlit = srgb_to_linear(sunlit)*2.25; amblit = srgb_to_linear(amblit)*0.15; additive = srgb_to_linear(additive); atten = srgb_to_linear(atten); +#else + vec3 rel_pos = inPositionEye; + + //(TERRAIN) limit altitude + if (abs(rel_pos.y) > max_y) rel_pos *= (max_y / rel_pos.y); + + vec3 rel_pos_norm = normalize(rel_pos); + float rel_pos_len = length(rel_pos); + vec3 sunlight = (sun_up_factor == 1) ? sunlight_linear : moonlight_linear; + + // sunlight attenuation effect (hue and brightness) due to atmosphere + // this is used later for sunlight modulation at various altitudes + vec3 light_atten = (blue_density_linear + (haze_density_linear * 0.25)) * (density_multiplier * max_y); + // I had thought blue_density and haze_density should have equal weighting, + // but attenuation due to haze_density tends to seem too strong + + + vec3 combined_haze_linear = blue_density_linear + haze_density_linear; + vec3 combined_haze = blue_density.rgb + vec3(haze_density); + vec3 blue_weight = blue_density_linear / combined_haze_linear; + vec3 haze_weight = haze_density_linear / combined_haze_linear; + + //(TERRAIN) compute sunlight from lightnorm y component. Factor is roughly cosecant(sun elevation) (for short rays like terrain) + float above_horizon_factor = 1.0 / max(1e-6, lightnorm.y); + sunlight *= exp(-light_atten * above_horizon_factor); // for sun [horizon..overhead] this maps to an exp curve [0..1] + + // main atmospheric scattering line integral + float density_dist = rel_pos_len * density_multiplier; + + // Transparency (-> combined_haze) + // ATI Bugfix -- can't store combined_haze*density_dist*distance_multiplier in a variable because the ati + // compiler gets confused. + combined_haze = exp(-combined_haze * density_dist * distance_multiplier); + combined_haze_linear = exp(-combined_haze_linear * density_dist * distance_multiplier); + // final atmosphere attenuation factor + atten = combined_haze.rgb; + + // compute haze glow + float haze_glow = dot(rel_pos_norm, lightnorm.xyz); + + // dampen sun additive contrib when not facing it... + // SL-13539: This "if" clause causes an "additive" white artifact at roughly 77 degreees. + // if (length(light_dir) > 0.01) + haze_glow *= max(0.0f, dot(light_dir, rel_pos_norm)); + + haze_glow = 1. - haze_glow; + // haze_glow is 0 at the sun and increases away from sun + haze_glow = max(haze_glow, .001); // set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + haze_glow *= glow.x; + // higher glow.x gives dimmer glow (because next step is 1 / "angle") + haze_glow = pow(haze_glow, glow.z); + // glow.z should be negative, so we're doing a sort of (1 / "angle") function + + // add "minimum anti-solar illumination" + haze_glow += .25; + + haze_glow *= sun_moon_glow_factor; + + vec3 amb_color = ambient_linear; + + // increase ambient when there are more clouds + vec3 tmpAmbient = amb_color + (vec3(1.) - amb_color) * cloud_shadow * 0.5; + + // Similar/Shared Algorithms: + // indra\llinventory\llsettingssky.cpp -- LLSettingsSky::calculateLightSettings() + // indra\newview\app_settings\shaders\class1\windlight\atmosphericsFuncs.glsl -- calcAtmosphericVars() + // haze color + vec3 cs = sunlight.rgb * (1. - cloud_shadow); + additive = (blue_horizon_linear.rgb * blue_weight.rgb) * (cs + tmpAmbient.rgb) + (haze_horizon * haze_weight.rgb) * (cs * haze_glow + tmpAmbient.rgb); + + // brightness of surface both sunlight and ambient + sunlit = sunlight.rgb; + amblit = tmpAmbient.rgb; + additive *= vec3(1.0 - combined_haze_linear); + + sunlit *= 0.8; + amblit *= 0.05; + additive *= 0.25; +#endif } -- cgit v1.2.3 From 2f082bb4ee433cba857499559dbfb30886fd0fb4 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 28 Sep 2022 18:13:58 -0500 Subject: SL-18190 Parity with release viewer when reflections are disabled. --- .../app_settings/shaders/class2/deferred/reflectionProbeF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl index a7cac6c523..878724982f 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl @@ -51,7 +51,7 @@ void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); vec3 env_vec = env_mat * refnormpersp; - legacyenv = textureCube(environmentMap, env_vec).rgb; + legacyenv = srgb_to_linear(textureCube(environmentMap, env_vec).rgb); glossenv = legacyenv; } @@ -63,6 +63,6 @@ void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 no void applyLegacyEnv(inout vec3 color, vec3 legacyenv, vec4 spec, vec3 pos, vec3 norm, float envIntensity) { - color = mix(color.rgb, legacyenv, envIntensity); + color = mix(color.rgb, legacyenv*0.5, envIntensity); } -- cgit v1.2.3 From 2e499bcc40871b6a68700203cc83fe7d81c79c24 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 28 Sep 2022 19:14:00 -0500 Subject: SL-18190 Prune srgb_to_linear from atmosphericsFuncs.glsl --- .../class2/windlight/atmosphericsFuncs.glsl | 28 +++++++--------------- 1 file changed, 9 insertions(+), 19 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl index 516550be1c..3d6c15fe55 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl @@ -23,23 +23,21 @@ * $/LicenseInfo$ */ -vec3 srgb_to_linear(vec3 col); - uniform vec4 lightnorm; uniform vec4 sunlight_color; -vec3 sunlight_linear = srgb_to_linear(sunlight_color.rgb); +uniform vec3 sunlight_linear; uniform vec4 moonlight_color; -vec3 moonlight_linear = srgb_to_linear(moonlight_color.rgb); +uniform vec3 moonlight_linear; uniform int sun_up_factor; uniform vec4 ambient_color; -vec3 ambient_linear = srgb_to_linear(ambient_color.rgb); +uniform vec3 ambient_linear; uniform vec4 blue_horizon; -vec3 blue_horizon_linear = srgb_to_linear(blue_horizon.rgb); +uniform vec3 blue_horizon_linear; uniform vec4 blue_density; -vec3 blue_density_linear = srgb_to_linear(blue_density.rgb); +uniform vec3 blue_density_linear; uniform float haze_horizon; uniform float haze_density; -vec3 haze_density_linear = srgb_to_linear(vec3(haze_density)); +uniform float haze_density_linear; uniform float cloud_shadow; uniform float density_multiplier; uniform float distance_multiplier; @@ -150,13 +148,6 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao) { -#if 0 - calcAtmosphericVars(inPositionEye, light_dir, 1.0, sunlit, amblit, additive, atten, false); - sunlit = srgb_to_linear(sunlit)*2.25; - amblit = srgb_to_linear(amblit)*0.15; - additive = srgb_to_linear(additive); - atten = srgb_to_linear(atten); -#else vec3 rel_pos = inPositionEye; //(TERRAIN) limit altitude @@ -168,15 +159,15 @@ void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 light_dir, float ambFact // sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes - vec3 light_atten = (blue_density_linear + (haze_density_linear * 0.25)) * (density_multiplier * max_y); + vec3 light_atten = (blue_density_linear + vec3(haze_density_linear * 0.25)) * (density_multiplier * max_y); // I had thought blue_density and haze_density should have equal weighting, // but attenuation due to haze_density tends to seem too strong - vec3 combined_haze_linear = blue_density_linear + haze_density_linear; + vec3 combined_haze_linear = blue_density_linear + vec3(haze_density_linear); vec3 combined_haze = blue_density.rgb + vec3(haze_density); vec3 blue_weight = blue_density_linear / combined_haze_linear; - vec3 haze_weight = haze_density_linear / combined_haze_linear; + vec3 haze_weight = vec3(haze_density_linear) / combined_haze_linear; //(TERRAIN) compute sunlight from lightnorm y component. Factor is roughly cosecant(sun elevation) (for short rays like terrain) float above_horizon_factor = 1.0 / max(1e-6, lightnorm.y); @@ -234,5 +225,4 @@ void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 light_dir, float ambFact sunlit *= 0.8; amblit *= 0.05; additive *= 0.25; -#endif } -- cgit v1.2.3 From 411aa9f727efba971c8577cef4d6a31f096a6fea Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 29 Sep 2022 00:19:52 -0500 Subject: SL-18190 Fix for haze color being completely wrong (now it's just half wrong). --- .../class2/windlight/atmosphericsFuncs.glsl | 32 +++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl index 3d6c15fe55..739f00a8b0 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl @@ -142,7 +142,7 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou } - +vec3 srgb_to_linear(vec3 col); // return colors in linear space void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, @@ -155,19 +155,17 @@ void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 light_dir, float ambFact vec3 rel_pos_norm = normalize(rel_pos); float rel_pos_len = length(rel_pos); - vec3 sunlight = (sun_up_factor == 1) ? sunlight_linear : moonlight_linear; + vec4 sunlight = (sun_up_factor == 1) ? vec4(sunlight_linear, 0.0) : vec4(moonlight_linear, 0.0); // sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes - vec3 light_atten = (blue_density_linear + vec3(haze_density_linear * 0.25)) * (density_multiplier * max_y); + vec4 light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); // I had thought blue_density and haze_density should have equal weighting, // but attenuation due to haze_density tends to seem too strong - - vec3 combined_haze_linear = blue_density_linear + vec3(haze_density_linear); - vec3 combined_haze = blue_density.rgb + vec3(haze_density); - vec3 blue_weight = blue_density_linear / combined_haze_linear; - vec3 haze_weight = vec3(haze_density_linear) / combined_haze_linear; + vec4 combined_haze = blue_density + vec4(haze_density); + vec4 blue_weight = blue_density / combined_haze; + vec4 haze_weight = vec4(haze_density) / combined_haze; //(TERRAIN) compute sunlight from lightnorm y component. Factor is roughly cosecant(sun elevation) (for short rays like terrain) float above_horizon_factor = 1.0 / max(1e-6, lightnorm.y); @@ -180,7 +178,7 @@ void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 light_dir, float ambFact // ATI Bugfix -- can't store combined_haze*density_dist*distance_multiplier in a variable because the ati // compiler gets confused. combined_haze = exp(-combined_haze * density_dist * distance_multiplier); - combined_haze_linear = exp(-combined_haze_linear * density_dist * distance_multiplier); + // final atmosphere attenuation factor atten = combined_haze.rgb; @@ -205,24 +203,26 @@ void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 light_dir, float ambFact haze_glow *= sun_moon_glow_factor; - vec3 amb_color = ambient_linear; + //vec4 amb_color = vec4(ambient_linear, 0.0); + vec4 amb_color = ambient_color; // increase ambient when there are more clouds - vec3 tmpAmbient = amb_color + (vec3(1.) - amb_color) * cloud_shadow * 0.5; + vec4 tmpAmbient = amb_color + (vec4(1.) - amb_color) * cloud_shadow * 0.5; // Similar/Shared Algorithms: // indra\llinventory\llsettingssky.cpp -- LLSettingsSky::calculateLightSettings() // indra\newview\app_settings\shaders\class1\windlight\atmosphericsFuncs.glsl -- calcAtmosphericVars() // haze color vec3 cs = sunlight.rgb * (1. - cloud_shadow); - additive = (blue_horizon_linear.rgb * blue_weight.rgb) * (cs + tmpAmbient.rgb) + (haze_horizon * haze_weight.rgb) * (cs * haze_glow + tmpAmbient.rgb); + additive = (blue_horizon.rgb * blue_weight.rgb) * (cs + tmpAmbient.rgb) + (haze_horizon * haze_weight.rgb) * (cs * haze_glow + tmpAmbient.rgb); // brightness of surface both sunlight and ambient sunlit = sunlight.rgb; amblit = tmpAmbient.rgb; - additive *= vec3(1.0 - combined_haze_linear); + additive *= vec3(1.0 - combined_haze); + + //sunlit = srgb_to_linear(sunlit); + amblit = ambient_linear; + additive = srgb_to_linear(additive*1.5); - sunlit *= 0.8; - amblit *= 0.05; - additive *= 0.25; } -- cgit v1.2.3 From 10b2d1be01978261ee0c452fdfabe2ec68ad1642 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 29 Sep 2022 18:56:21 -0500 Subject: SL-18190 End of linear space odyssey -- just eat the conversions in atmosphericsFuncsF for sunlight and additive, but leave linear ambient in tact. --- .../shaders/class2/deferred/pbralphaF.glsl | 6 +++--- .../shaders/class2/deferred/reflectionProbeF.glsl | 2 +- .../shaders/class2/windlight/atmosphericsF.glsl | 11 ++--------- .../shaders/class2/windlight/atmosphericsFuncs.glsl | 19 ++++++++++++++----- 4 files changed, 20 insertions(+), 18 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index e6cb8f37c7..13544af0b1 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -196,7 +196,7 @@ void main() vec3 irradiance = vec3(0); vec3 radiance = vec3(0); sampleReflectionProbes(irradiance, radiance, pos.xyz, norm.xyz, gloss); - irradiance = max(amblit*2.0,irradiance); + irradiance = max(amblit*0.75,irradiance); vec3 f0 = vec3(0.04); @@ -209,8 +209,8 @@ void main() float NdotV = clamp(abs(dot(norm.xyz, v)), 0.001, 1.0); color += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, perceptualRoughness); - color += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, v, light_dir) * sunlit*2.75 * scol; - color += colorEmissive; + color += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, v, light_dir) * sunlit * scol; + color += colorEmissive*0.5; color = atmosFragLightingLinear(color, additive, atten); color = scaleSoftClipFragLinear(color); diff --git a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl index 878724982f..0236680ac0 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl @@ -63,6 +63,6 @@ void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 no void applyLegacyEnv(inout vec3 color, vec3 legacyenv, vec4 spec, vec3 pos, vec3 norm, float envIntensity) { - color = mix(color.rgb, legacyenv*0.5, envIntensity); + color = mix(color.rgb, legacyenv*1.5, envIntensity); } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 20b1e3513e..1463d507bc 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -33,7 +33,7 @@ vec3 srgb_to_linear(vec3 col); vec3 linear_to_srgb(vec3 col); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) -{ +{ if (no_atmo == 1) { return light; @@ -45,14 +45,7 @@ vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten) { - if (no_atmo == 1) - { - return light; - } - - light *= atten.r; - light += additive; - return light*2.0; + return atmosFragLighting(light, additive, atten); } vec3 atmosLighting(vec3 light) diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl index 739f00a8b0..0093e8a31e 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl @@ -50,6 +50,8 @@ uniform float sun_moon_glow_factor; float getAmbientClamp() { return 1.0f; } +vec3 srgb_to_linear(vec3 col); + // return colors in sRGB space void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao) @@ -148,6 +150,14 @@ vec3 srgb_to_linear(vec3 col); void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao) { +#if 1 + calcAtmosphericVars(inPositionEye, light_dir, 1.0, sunlit, amblit, additive, atten, false); + sunlit = srgb_to_linear(sunlit); + additive = srgb_to_linear(additive); + amblit = ambient_linear; +#else + + //EXPERIMENTAL -- attempt to factor out srgb_to_linear conversions above vec3 rel_pos = inPositionEye; //(TERRAIN) limit altitude @@ -217,12 +227,11 @@ void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 light_dir, float ambFact additive = (blue_horizon.rgb * blue_weight.rgb) * (cs + tmpAmbient.rgb) + (haze_horizon * haze_weight.rgb) * (cs * haze_glow + tmpAmbient.rgb); // brightness of surface both sunlight and ambient - sunlit = sunlight.rgb; + sunlit = min(sunlight.rgb, vec3(1)); amblit = tmpAmbient.rgb; additive *= vec3(1.0 - combined_haze); - //sunlit = srgb_to_linear(sunlit); - amblit = ambient_linear; - additive = srgb_to_linear(additive*1.5); - + //sunlit = sunlight_linear; + amblit = ambient_linear*0.8; +#endif } -- cgit v1.2.3 From 7d426815019ac5394e5821f1c6ba374e12606aaa Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 30 Sep 2022 10:57:01 -0500 Subject: SL-18239 Unify PBR and non-PBR treatment of ambient/SSAO/irradiance. Restore SSAO to release version. --- .../app_settings/shaders/class2/deferred/alphaF.glsl | 16 +++++----------- .../shaders/class2/deferred/pbralphaF.glsl | 19 ++++++++----------- .../shaders/class2/windlight/atmosphericsFuncs.glsl | 18 ++++++++++++++++-- 3 files changed, 29 insertions(+), 24 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl index 39aec699fe..b4406aabc0 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl @@ -80,7 +80,7 @@ vec2 encode_normal (vec3 n); vec3 scaleSoftClipFragLinear(vec3 l); vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten); -void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive, bool use_ao); +void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); #ifdef HAS_SHADOW float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); @@ -243,12 +243,12 @@ void main() vec3 additive; vec3 atten; - calcAtmosphericVarsLinear(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); + calcAtmosphericVarsLinear(pos.xyz, norm, light_dir, sunlit, amblit, additive, atten); - vec3 ambenv; + vec3 irradiance; vec3 glossenv; vec3 legacyenv; - sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, 0.0, 0.0); + sampleReflectionProbesLegacy(irradiance, glossenv, legacyenv, pos.xyz, norm.xyz, 0.0, 0.0); float da = dot(norm.xyz, light_dir.xyz); @@ -261,15 +261,9 @@ void main() color.a = final_alpha; - float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0 - ambient); - vec3 sun_contrib = min(final_da, shadow) * sunlit; - color.rgb = max(amblit, ambenv); - color.rgb *= ambient; + color.rgb = max(amblit, irradiance); color.rgb += sun_contrib; diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index 13544af0b1..9bbc4f87bf 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -74,8 +74,7 @@ uniform vec2 light_deferred_attenuation[8]; // light size and falloff vec3 srgb_to_linear(vec3 c); vec3 linear_to_srgb(vec3 c); -// These are in deferredUtil.glsl but we can't set: mFeatures.isDeferred to include it -void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); +void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten); vec3 scaleSoftClipFragLinear(vec3 l); @@ -140,15 +139,6 @@ void main() vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; vec3 pos = vary_position; - float scol = 1.0; - float ambocc = 1.0; - - vec3 sunlit; - vec3 amblit; - vec3 additive; - vec3 atten; - calcAtmosphericVarsLinear(pos.xyz, light_dir, ambocc, sunlit, amblit, additive, atten, true); - // IF .mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels; // vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb; @@ -174,6 +164,13 @@ void main() norm *= gl_FrontFacing ? 1.0 : -1.0; + float scol = 1.0; + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; + calcAtmosphericVarsLinear(pos.xyz, norm, light_dir, sunlit, amblit, additive, atten); + #ifdef HAS_SHADOW vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; frag *= screen_res; diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl index 0093e8a31e..8937488484 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl @@ -146,15 +146,29 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou vec3 srgb_to_linear(vec3 col); +// provide a touch of lighting in the opposite direction of the sun light + // so areas in shadow don't lose all detail +float ambientLighting(vec3 norm, vec3 light_dir) +{ + float ambient = min(abs(dot(norm.xyz, light_dir.xyz)), 1.0); + ambient *= 0.56; + ambient *= ambient; + ambient = (1.0 - ambient); + return ambient; +} + + // return colors in linear space -void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, - out vec3 atten, bool use_ao) +void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 additive, + out vec3 atten) { #if 1 calcAtmosphericVars(inPositionEye, light_dir, 1.0, sunlit, amblit, additive, atten, false); sunlit = srgb_to_linear(sunlit); additive = srgb_to_linear(additive); amblit = ambient_linear; + + amblit *= ambientLighting(norm, light_dir); #else //EXPERIMENTAL -- attempt to factor out srgb_to_linear conversions above -- cgit v1.2.3 From 1900df361558313f10e8b27ada03bcefd41241d9 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 4 Oct 2022 12:20:19 -0500 Subject: SL-18293, SL-18190 -- Fix for debug displays not showing up (wireframe still busted). WIP on reflection probe/PBR driven water shader. --- .../shaders/class2/deferred/waterF.glsl | 192 +++++++++++++++++ .../shaders/class2/environment/waterF.glsl | 237 +++++++++++++++++++++ 2 files changed, 429 insertions(+) create mode 100644 indra/newview/app_settings/shaders/class2/deferred/waterF.glsl create mode 100644 indra/newview/app_settings/shaders/class2/environment/waterF.glsl (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class2/deferred/waterF.glsl new file mode 100644 index 0000000000..96739d91d7 --- /dev/null +++ b/indra/newview/app_settings/shaders/class2/deferred/waterF.glsl @@ -0,0 +1,192 @@ +/** + * @file class1/deferred/waterF.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$ + */ + +#extension GL_ARB_texture_rectangle : enable + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_data[4]; +#else +#define frag_data gl_FragData +#endif + +vec3 scaleSoftClip(vec3 inColor); +vec3 atmosTransport(vec3 inColor); + +uniform sampler2D bumpMap; +uniform sampler2D bumpMap2; +uniform float blend_factor; +uniform sampler2D screenTex; +uniform sampler2D refTex; +uniform float sunAngle; +uniform float sunAngle2; +uniform vec3 lightDir; +uniform vec3 specular; +uniform float lightExp; +uniform float refScale; +uniform float kd; +uniform vec2 screenRes; +uniform vec3 normScale; +uniform float fresnelScale; +uniform float fresnelOffset; +uniform float blurMultiplier; +uniform vec2 screen_res; +uniform mat4 norm_mat; //region space to screen space +uniform int water_edge; + +//bigWave is (refCoord.w, view.w); +VARYING vec4 refCoord; +VARYING vec4 littleWave; +VARYING vec4 view; +VARYING vec4 vary_position; + +vec2 encode_normal(vec3 n); +vec3 scaleSoftClip(vec3 l); +vec3 srgb_to_linear(vec3 c); +vec3 linear_to_srgb(vec3 c); + +vec3 BlendNormal(vec3 bump1, vec3 bump2) +{ + vec3 n = mix(bump1, bump2, blend_factor); + return n; +} + +void main() +{ + vec4 color; + float dist = length(view.xyz); + + //normalize view vector + vec3 viewVec = normalize(view.xyz); + + //get wave normals + vec3 wave1_a = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; + vec3 wave2_a = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; + vec3 wave3_a = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; + + + vec3 wave1_b = texture2D(bumpMap2, vec2(refCoord.w, view.w)).xyz*2.0-1.0; + vec3 wave2_b = texture2D(bumpMap2, littleWave.xy).xyz*2.0-1.0; + vec3 wave3_b = texture2D(bumpMap2, littleWave.zw).xyz*2.0-1.0; + + vec3 wave1 = BlendNormal(wave1_a, wave1_b); + vec3 wave2 = BlendNormal(wave2_a, wave2_b); + vec3 wave3 = BlendNormal(wave3_a, wave3_b); + + //get base fresnel components + + vec3 df = vec3( + dot(viewVec, wave1), + dot(viewVec, (wave2 + wave3) * 0.5), + dot(viewVec, wave3) + ) * fresnelScale + fresnelOffset; + df *= df; + + vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; + + float dist2 = dist; + dist = max(dist, 5.0); + + float dmod = sqrt(dist); + + vec2 dmod_scale = vec2(dmod*dmod, dmod); + + //get reflected color + vec2 refdistort1 = wave1.xy*normScale.x; + vec2 refvec1 = distort+refdistort1/dmod_scale; + vec4 refcol1 = texture2D(refTex, refvec1); + + vec2 refdistort2 = wave2.xy*normScale.y; + vec2 refvec2 = distort+refdistort2/dmod_scale; + vec4 refcol2 = texture2D(refTex, refvec2); + + vec2 refdistort3 = wave3.xy*normScale.z; + vec2 refvec3 = distort+refdistort3/dmod_scale; + vec4 refcol3 = texture2D(refTex, refvec3); + + vec4 refcol = refcol1 + refcol2 + refcol3; + float df1 = df.x + df.y + df.z; + refcol *= df1 * 0.333; + + vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; + wavef.z *= max(-viewVec.z, 0.1); + wavef = normalize(wavef); + + float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset; + + vec2 refdistort4 = wavef.xy*0.125; + refdistort4.y -= abs(refdistort4.y); + vec2 refvec4 = distort+refdistort4/dmod; + float dweight = min(dist2*blurMultiplier, 1.0); + vec4 baseCol = texture2D(refTex, refvec4); + + refcol = mix(baseCol*df2, refcol, dweight); + + //get specular component + float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); + + //harden specular + spec = pow(spec, 128.0); + + //figure out distortion vector (ripply) + vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); + + vec4 fb = texture2D(screenTex, distort2); + + //mix with reflection + // Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug + color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999f); + + vec4 pos = vary_position; + + //color.rgb += spec * specular; + + //color.rgb = atmosTransport(color.rgb); + //color.rgb = scaleSoftClip(color.rgb); + + //color.rgb = refcol.rgb; + color.rgb = vec3(0.0); + color.a = spec * sunAngle2; + + vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); + + //frag_data[0] = color; + + // TODO: The non-obvious assignment below is copied from the pre-EEP WL shader code + // Unfortunately, fixing it causes a mismatch for EEP, and so it remains... for now + // SL-12975 (unfix pre-EEP broken alpha) + frag_data[0] = vec4(srgb_to_linear(color.rgb), 0.0); + + frag_data[1] = vec4(1.0, 0.1, 0.0, 0.0); // occlusion, roughness, metalness + frag_data[2] = vec4(encode_normal(screenspacewavef.xyz), 0.0, GBUFFER_FLAG_HAS_PBR);// normalxy, env intens, flags (atmo kill) + //frag_data[3] = vec4(srgb_to_linear(refcol.rgb),0); + frag_data[3] = vec4(0, 0, 0, 0); + + + //frag_data[0] = vec4(0.0,0,0,0); + //frag_data[1] = vec4(0, 1.0, 0.0, 0.0); + //frag_data[3] = vec4(0); +} diff --git a/indra/newview/app_settings/shaders/class2/environment/waterF.glsl b/indra/newview/app_settings/shaders/class2/environment/waterF.glsl new file mode 100644 index 0000000000..2e7efa9b2a --- /dev/null +++ b/indra/newview/app_settings/shaders/class2/environment/waterF.glsl @@ -0,0 +1,237 @@ +/** + * @file waterF.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$ + */ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +vec3 scaleSoftClipFragLinear(vec3 l); +vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten); +void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); + +// PBR interface +vec3 pbrIbl(vec3 diffuseColor, + vec3 specularColor, + vec3 radiance, // radiance map sample + vec3 irradiance, // irradiance map sample + float ao, // ambient occlusion factor + float nv, // normal dot view vector + float perceptualRoughness); + +vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, + float perceptualRoughness, + float metallic, + vec3 n, // normal + vec3 v, // surface point to camera + vec3 l); //surface point to light + +uniform sampler2D bumpMap; +uniform sampler2D bumpMap2; +uniform float blend_factor; +uniform sampler2D screenTex; +uniform sampler2D refTex; + +uniform float sunAngle; +uniform float sunAngle2; +uniform vec3 lightDir; +uniform vec3 specular; +uniform float lightExp; +uniform float refScale; +uniform float kd; +uniform vec2 screenRes; +uniform vec3 normScale; +uniform float fresnelScale; +uniform float fresnelOffset; +uniform float blurMultiplier; +uniform vec4 waterFogColor; + + +//bigWave is (refCoord.w, view.w); +VARYING vec4 refCoord; +VARYING vec4 littleWave; +VARYING vec4 view; +in vec3 vary_position; +in vec3 vary_normal; +in vec3 vary_tangent; +in vec3 vary_light_dir; + +vec3 BlendNormal(vec3 bump1, vec3 bump2) +{ + vec3 n = mix(bump1, bump2, blend_factor); + return n; +} + +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) +{ + return normalize(vNt.x * vT + vNt.y * vB + vNt.z * vN); +} + +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, + vec3 pos, vec3 norm, float glossiness); + +void main() +{ + vec4 color; + + vN = vary_normal; + vT = vary_tangent; + vB = cross(vN, vT); + + vec3 pos = vary_position.xyz; + + float dist = length(view.xy); + + //normalize view vector + vec3 viewVec = normalize(pos.xyz); + + //get wave normals + vec2 bigwave = vec2(refCoord.w, view.w); + vec3 wave1_a = texture2D(bumpMap, bigwave ).xyz*2.0-1.0; + vec3 wave2_a = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; + vec3 wave3_a = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; + + + vec3 wave1_b = texture2D(bumpMap2, bigwave ).xyz*2.0-1.0; + vec3 wave2_b = texture2D(bumpMap2, littleWave.xy).xyz*2.0-1.0; + vec3 wave3_b = texture2D(bumpMap2, littleWave.zw).xyz*2.0-1.0; + + vec3 wave1 = BlendNormal(wave1_a, wave1_b); + vec3 wave2 = BlendNormal(wave2_a, wave2_b); + vec3 wave3 = BlendNormal(wave3_a, wave3_b); + + wave1 = transform_normal(wave1); + wave2 = transform_normal(wave2); + wave3 = transform_normal(wave3); + + vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; + + wavef.z *= max(-viewVec.z, 0.1); + + wavef = normalize(wavef); + + //get base fresnel components + + /*vec3 df = vec3( + dot(viewVec, wave1), + dot(viewVec, (wave2 + wave3) * 0.5), + dot(viewVec, wave3) + ) * fresnelScale + fresnelOffset;*/ + + vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; + + float dist2 = dist; + dist = max(dist, 5.0); + + float dmod = sqrt(dist); + + vec2 dmod_scale = vec2(dmod*dmod, dmod); + + //float df1 = df.x + df.y + df.z; + + vec4 refcol = vec4(0, 0, 0, 0); + + //get specular component + float spec = clamp(dot(vary_light_dir, (reflect(viewVec,wavef))),0.0,1.0); + + //harden specular + spec = pow(spec, 128.0); + + //figure out distortion vector (ripply) + //vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); + + //vec4 fb = texture2D(screenTex, distort2); + + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; + + calcAtmosphericVarsLinear(pos.xyz, wavef, lightDir, sunlit, amblit, additive, atten); + + vec3 v = -viewVec; + float NdotV = clamp(abs(dot(wavef.xyz, v)), 0.001, 1.0); + + float metallic = fresnelOffset * 0.1; // fudge -- use fresnelOffset as metalness + float roughness = 0.08; + float gloss = 1.0 - roughness; + + vec3 baseColor = vec3(0); + vec3 f0 = vec3(0.04); + vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0); + diffuseColor *= gloss; + + vec3 specularColor = mix(f0, baseColor.rgb, metallic); + + + vec3 refnorm = normalize(wavef + vary_normal); + + vec3 irradiance = vec3(0); + vec3 radiance = vec3(0); + sampleReflectionProbes(irradiance, radiance, pos, refnorm, gloss); + + // fudge -- use refracted color as irradiance + irradiance = srgb_to_linear(waterFogColor.rgb); + + color.rgb = pbrIbl(diffuseColor, specularColor, radiance, irradiance, gloss, NdotV, 0.0); + + //vec4 fb = waterFogColor; + //fb.rgb = srgb_to_linear(fb.rgb); + + //refcol.rgb = vec3(0, 1, 0); + + //mix with reflection + //color.rgb = mix(fb.rgb, refcol.rgb, df1); + + //color.rgb += spec * specular; + + // fudge -- for punctual lighting, pretend water is metallic + diffuseColor = vec3(0); + specularColor = vec3(1); + roughness = 0.1; + color.rgb += pbrPunctual(diffuseColor, specularColor, roughness, metallic, wavef, v, vary_light_dir); + color.rgb = atmosFragLightingLinear(color.rgb, additive, atten); + color.rgb = scaleSoftClipFragLinear(color.rgb); + + color.a = 0.f; + + //color.a = spec * sunAngle2; + + frag_color = color; + +#if defined(WATER_EDGE) + gl_FragDepth = 0.9999847f; +#endif + +} + -- cgit v1.2.3 From 30bcc7d6d5fa4ceedfec28cc0973c253364c555e Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 5 Oct 2022 08:11:33 -0500 Subject: SL-18190 WIP - Add refraction to water without splitting scene between above and below water --- .../shaders/class2/environment/waterF.glsl | 82 +++++++++++++--------- 1 file changed, 47 insertions(+), 35 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/environment/waterF.glsl b/indra/newview/app_settings/shaders/class2/environment/waterF.glsl index 2e7efa9b2a..59e7e64fbb 100644 --- a/indra/newview/app_settings/shaders/class2/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class2/environment/waterF.glsl @@ -32,6 +32,7 @@ out vec4 frag_color; vec3 scaleSoftClipFragLinear(vec3 l); vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten); void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); +vec4 applyWaterFogViewLinear(vec3 pos, vec4 color); // PBR interface vec3 pbrIbl(vec3 diffuseColor, @@ -53,6 +54,8 @@ uniform sampler2D bumpMap; uniform sampler2D bumpMap2; uniform float blend_factor; uniform sampler2D screenTex; +uniform sampler2D screenDepth; + uniform sampler2D refTex; uniform float sunAngle; @@ -100,6 +103,8 @@ vec3 transform_normal(vec3 vNt) void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, vec3 pos, vec3 norm, float glossiness); +vec3 getPositionWithNDC(vec3 ndc); + void main() { vec4 color; @@ -110,7 +115,7 @@ void main() vec3 pos = vary_position.xyz; - float dist = length(view.xy); + float dist = length(pos.xyz); //normalize view vector vec3 viewVec = normalize(pos.xyz); @@ -121,7 +126,6 @@ void main() vec3 wave2_a = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; vec3 wave3_a = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; - vec3 wave1_b = texture2D(bumpMap2, bigwave ).xyz*2.0-1.0; vec3 wave2_b = texture2D(bumpMap2, littleWave.xy).xyz*2.0-1.0; vec3 wave3_b = texture2D(bumpMap2, littleWave.zw).xyz*2.0-1.0; @@ -142,11 +146,11 @@ void main() //get base fresnel components - /*vec3 df = vec3( + vec3 df = vec3( dot(viewVec, wave1), dot(viewVec, (wave2 + wave3) * 0.5), dot(viewVec, wave3) - ) * fresnelScale + fresnelOffset;*/ + ) * fresnelScale + fresnelOffset; vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; @@ -157,20 +161,33 @@ void main() vec2 dmod_scale = vec2(dmod*dmod, dmod); - //float df1 = df.x + df.y + df.z; + float df1 = df.x + df.y + df.z; - vec4 refcol = vec4(0, 0, 0, 0); + wavef = normalize(wavef + vary_normal); + //wavef = vary_normal; - //get specular component - float spec = clamp(dot(vary_light_dir, (reflect(viewVec,wavef))),0.0,1.0); - - //harden specular - spec = pow(spec, 128.0); + vec3 waver = reflect(viewVec, -wavef)*3; //figure out distortion vector (ripply) - //vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); - - //vec4 fb = texture2D(screenTex, distort2); + vec2 distort2 = distort + waver.xy * refScale / max(dmod * df1, 1.0); + distort2 = clamp(distort2, vec2(0), vec2(0.99)); + + vec4 fb = texture2D(screenTex, distort2); + float depth = texture2D(screenDepth, distort2).r; + vec3 refPos = getPositionWithNDC(vec3(distort2*2.0-vec2(1.0), depth*2.0-1.0)); + +#if 1 + if (refPos.z > pos.z-0.05) + { + //we sampled an above water sample, don't distort + distort2 = distort; + fb = texture2D(screenTex, distort2); + depth = texture2D(screenDepth, distort2).r; + refPos = getPositionWithNDC(vec3(distort2 * 2.0 - vec2(1.0), depth * 2.0 - 1.0)); + } +#endif + + fb = applyWaterFogViewLinear(refPos, fb); vec3 sunlit; vec3 amblit; @@ -186,48 +203,43 @@ void main() float roughness = 0.08; float gloss = 1.0 - roughness; - vec3 baseColor = vec3(0); + vec3 baseColor = vec3(0.25); vec3 f0 = vec3(0.04); vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0); diffuseColor *= gloss; vec3 specularColor = mix(f0, baseColor.rgb, metallic); + //vec3 refnorm = normalize(wavef + vary_normal); + vec3 refnorm = wavef; - vec3 refnorm = normalize(wavef + vary_normal); - + vec3 irradiance = vec3(0); vec3 radiance = vec3(0); sampleReflectionProbes(irradiance, radiance, pos, refnorm, gloss); - - // fudge -- use refracted color as irradiance - irradiance = srgb_to_linear(waterFogColor.rgb); + radiance *= 0.5; + irradiance = fb.rgb; color.rgb = pbrIbl(diffuseColor, specularColor, radiance, irradiance, gloss, NdotV, 0.0); - //vec4 fb = waterFogColor; - //fb.rgb = srgb_to_linear(fb.rgb); - - //refcol.rgb = vec3(0, 1, 0); - - //mix with reflection - //color.rgb = mix(fb.rgb, refcol.rgb, df1); - - //color.rgb += spec * specular; - + // fudge -- for punctual lighting, pretend water is metallic diffuseColor = vec3(0); specularColor = vec3(1); roughness = 0.1; - color.rgb += pbrPunctual(diffuseColor, specularColor, roughness, metallic, wavef, v, vary_light_dir); + float scol = 1.0; // TODO -- incorporate shadow map + + //color.rgb += pbrPunctual(diffuseColor, specularColor, roughness, metallic, wavef, v, vary_light_dir) * sunlit * 2.75 * scol; color.rgb = atmosFragLightingLinear(color.rgb, additive, atten); color.rgb = scaleSoftClipFragLinear(color.rgb); color.a = 0.f; - - //color.a = spec * sunAngle2; - - frag_color = color; + //color.rgb = fb.rgb; + //color.rgb = vec3(depth*depth*depth*depth); + //color.rgb = srgb_to_linear(normalize(refPos) * 0.5 + 0.5); + //color.rgb = srgb_to_linear(normalize(pos) * 0.5 + 0.5); + //color.rgb = srgb_to_linear(wavef * 0.5 + 0.5); + frag_color = color; #if defined(WATER_EDGE) gl_FragDepth = 0.9999847f; -- cgit v1.2.3 From 9448db5d4af7bba094e5bc51f85e5c2491d3f5a1 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 6 Oct 2022 18:40:01 -0500 Subject: SL-18190 Water shader WIP. Better parallax correction for sphere probes. Reduce probe memory footprint. Remove framebuffer copies and move to deprecate stencil buffer usage. --- .../app_settings/shaders/class2/environment/waterF.glsl | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/environment/waterF.glsl b/indra/newview/app_settings/shaders/class2/environment/waterF.glsl index 59e7e64fbb..b51583de26 100644 --- a/indra/newview/app_settings/shaders/class2/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class2/environment/waterF.glsl @@ -163,7 +163,7 @@ void main() float df1 = df.x + df.y + df.z; - wavef = normalize(wavef + vary_normal); + //wavef = normalize(wavef - vary_normal); //wavef = vary_normal; vec3 waver = reflect(viewVec, -wavef)*3; @@ -194,13 +194,13 @@ void main() vec3 additive; vec3 atten; - calcAtmosphericVarsLinear(pos.xyz, wavef, lightDir, sunlit, amblit, additive, atten); - + calcAtmosphericVarsLinear(pos.xyz, wavef, vary_light_dir, sunlit, amblit, additive, atten); + sunlit = vec3(1); // TODO -- figure out why sunlit is breaking at some view angles vec3 v = -viewVec; float NdotV = clamp(abs(dot(wavef.xyz, v)), 0.001, 1.0); float metallic = fresnelOffset * 0.1; // fudge -- use fresnelOffset as metalness - float roughness = 0.08; + float roughness = 0.1; float gloss = 1.0 - roughness; vec3 baseColor = vec3(0.25); @@ -210,8 +210,8 @@ void main() vec3 specularColor = mix(f0, baseColor.rgb, metallic); - //vec3 refnorm = normalize(wavef + vary_normal); - vec3 refnorm = wavef; + vec3 refnorm = normalize(wavef + vary_normal); + //vec3 refnorm = wavef; vec3 irradiance = vec3(0); @@ -221,7 +221,6 @@ void main() irradiance = fb.rgb; color.rgb = pbrIbl(diffuseColor, specularColor, radiance, irradiance, gloss, NdotV, 0.0); - // fudge -- for punctual lighting, pretend water is metallic diffuseColor = vec3(0); @@ -229,7 +228,7 @@ void main() roughness = 0.1; float scol = 1.0; // TODO -- incorporate shadow map - //color.rgb += pbrPunctual(diffuseColor, specularColor, roughness, metallic, wavef, v, vary_light_dir) * sunlit * 2.75 * scol; + color.rgb += pbrPunctual(diffuseColor, specularColor, roughness, metallic, wavef, v, vary_light_dir) * sunlit * 2.75 * scol; color.rgb = atmosFragLightingLinear(color.rgb, additive, atten); color.rgb = scaleSoftClipFragLinear(color.rgb); @@ -239,6 +238,8 @@ void main() //color.rgb = srgb_to_linear(normalize(refPos) * 0.5 + 0.5); //color.rgb = srgb_to_linear(normalize(pos) * 0.5 + 0.5); //color.rgb = srgb_to_linear(wavef * 0.5 + 0.5); + + //color.rgb = radiance; frag_color = color; #if defined(WATER_EDGE) -- cgit v1.2.3 From 25bff0c21dafcfca4d098f2d51a46a09c543a12c Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 7 Oct 2022 19:27:19 -0500 Subject: SL-18190 Move water shaders to class 3, add debug stub for underWaterF.glsl, make underWaterF and softenLightF apply water fog in linear space. --- .../shaders/class2/environment/waterF.glsl | 196 ++++++--------------- 1 file changed, 58 insertions(+), 138 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/environment/waterF.glsl b/indra/newview/app_settings/shaders/class2/environment/waterF.glsl index b51583de26..d485379a56 100644 --- a/indra/newview/app_settings/shaders/class2/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class2/environment/waterF.glsl @@ -22,40 +22,22 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - + +//class2/environment/waterF.glsl + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else #define frag_color gl_FragColor #endif -vec3 scaleSoftClipFragLinear(vec3 l); -vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten); -void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); -vec4 applyWaterFogViewLinear(vec3 pos, vec4 color); - -// PBR interface -vec3 pbrIbl(vec3 diffuseColor, - vec3 specularColor, - vec3 radiance, // radiance map sample - vec3 irradiance, // irradiance map sample - float ao, // ambient occlusion factor - float nv, // normal dot view vector - float perceptualRoughness); - -vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, - float perceptualRoughness, - float metallic, - vec3 n, // normal - vec3 v, // surface point to camera - vec3 l); //surface point to light +vec3 scaleSoftClip(vec3 inColor); +vec3 atmosTransport(vec3 inColor); uniform sampler2D bumpMap; uniform sampler2D bumpMap2; uniform float blend_factor; uniform sampler2D screenTex; -uniform sampler2D screenDepth; - uniform sampler2D refTex; uniform float sunAngle; @@ -70,17 +52,12 @@ uniform vec3 normScale; uniform float fresnelScale; uniform float fresnelOffset; uniform float blurMultiplier; -uniform vec4 waterFogColor; //bigWave is (refCoord.w, view.w); VARYING vec4 refCoord; VARYING vec4 littleWave; VARYING vec4 view; -in vec3 vary_position; -in vec3 vary_normal; -in vec3 vary_tangent; -in vec3 vary_light_dir; vec3 BlendNormal(vec3 bump1, vec3 bump2) { @@ -88,37 +65,15 @@ vec3 BlendNormal(vec3 bump1, vec3 bump2) return n; } -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) -{ - return normalize(vNt.x * vT + vNt.y * vB + vNt.z * vN); -} - -void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec3 pos, vec3 norm, float glossiness); - -vec3 getPositionWithNDC(vec3 ndc); void main() { vec4 color; - - vN = vary_normal; - vT = vary_tangent; - vB = cross(vN, vT); - - vec3 pos = vary_position.xyz; - - float dist = length(pos.xyz); + + float dist = length(view.xy); //normalize view vector - vec3 viewVec = normalize(pos.xyz); + vec3 viewVec = normalize(view.xyz); //get wave normals vec2 bigwave = vec2(refCoord.w, view.w); @@ -126,6 +81,7 @@ void main() vec3 wave2_a = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; vec3 wave3_a = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; + vec3 wave1_b = texture2D(bumpMap2, bigwave ).xyz*2.0-1.0; vec3 wave2_b = texture2D(bumpMap2, littleWave.xy).xyz*2.0-1.0; vec3 wave3_b = texture2D(bumpMap2, littleWave.zw).xyz*2.0-1.0; @@ -134,15 +90,6 @@ void main() vec3 wave2 = BlendNormal(wave2_a, wave2_b); vec3 wave3 = BlendNormal(wave3_a, wave3_b); - wave1 = transform_normal(wave1); - wave2 = transform_normal(wave2); - wave3 = transform_normal(wave3); - - vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; - - wavef.z *= max(-viewVec.z, 0.1); - - wavef = normalize(wavef); //get base fresnel components @@ -151,6 +98,7 @@ void main() dot(viewVec, (wave2 + wave3) * 0.5), dot(viewVec, wave3) ) * fresnelScale + fresnelOffset; + df *= df; vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; @@ -161,85 +109,57 @@ void main() vec2 dmod_scale = vec2(dmod*dmod, dmod); - float df1 = df.x + df.y + df.z; - - //wavef = normalize(wavef - vary_normal); - //wavef = vary_normal; + //get reflected color + vec2 refdistort1 = wave1.xy*normScale.x; + vec2 refvec1 = distort+refdistort1/dmod_scale; + vec4 refcol1 = texture2D(refTex, refvec1); + + vec2 refdistort2 = wave2.xy*normScale.y; + vec2 refvec2 = distort+refdistort2/dmod_scale; + vec4 refcol2 = texture2D(refTex, refvec2); + + vec2 refdistort3 = wave3.xy*normScale.z; + vec2 refvec3 = distort+refdistort3/dmod_scale; + vec4 refcol3 = texture2D(refTex, refvec3); - vec3 waver = reflect(viewVec, -wavef)*3; + vec4 refcol = refcol1 + refcol2 + refcol3; + float df1 = df.x + df.y + df.z; + refcol *= df1 * 0.333; + + vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; + + wavef.z *= max(-viewVec.z, 0.1); + wavef = normalize(wavef); + + float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset; + + vec2 refdistort4 = wavef.xy*0.125; + refdistort4.y -= abs(refdistort4.y); + vec2 refvec4 = distort+refdistort4/dmod; + float dweight = min(dist2*blurMultiplier, 1.0); + vec4 baseCol = texture2D(refTex, refvec4); + refcol = mix(baseCol*df2, refcol, dweight); + + //get specular component + float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); + + //harden specular + spec = pow(spec, 128.0); //figure out distortion vector (ripply) - vec2 distort2 = distort + waver.xy * refScale / max(dmod * df1, 1.0); - distort2 = clamp(distort2, vec2(0), vec2(0.99)); - - vec4 fb = texture2D(screenTex, distort2); - float depth = texture2D(screenDepth, distort2).r; - vec3 refPos = getPositionWithNDC(vec3(distort2*2.0-vec2(1.0), depth*2.0-1.0)); - -#if 1 - if (refPos.z > pos.z-0.05) - { - //we sampled an above water sample, don't distort - distort2 = distort; - fb = texture2D(screenTex, distort2); - depth = texture2D(screenDepth, distort2).r; - refPos = getPositionWithNDC(vec3(distort2 * 2.0 - vec2(1.0), depth * 2.0 - 1.0)); - } -#endif - - fb = applyWaterFogViewLinear(refPos, fb); - - vec3 sunlit; - vec3 amblit; - vec3 additive; - vec3 atten; - - calcAtmosphericVarsLinear(pos.xyz, wavef, vary_light_dir, sunlit, amblit, additive, atten); - sunlit = vec3(1); // TODO -- figure out why sunlit is breaking at some view angles - vec3 v = -viewVec; - float NdotV = clamp(abs(dot(wavef.xyz, v)), 0.001, 1.0); - - float metallic = fresnelOffset * 0.1; // fudge -- use fresnelOffset as metalness - float roughness = 0.1; - float gloss = 1.0 - roughness; - - vec3 baseColor = vec3(0.25); - vec3 f0 = vec3(0.04); - vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0); - diffuseColor *= gloss; - - vec3 specularColor = mix(f0, baseColor.rgb, metallic); - - vec3 refnorm = normalize(wavef + vary_normal); - //vec3 refnorm = wavef; - - - vec3 irradiance = vec3(0); - vec3 radiance = vec3(0); - sampleReflectionProbes(irradiance, radiance, pos, refnorm, gloss); - radiance *= 0.5; - irradiance = fb.rgb; - - color.rgb = pbrIbl(diffuseColor, specularColor, radiance, irradiance, gloss, NdotV, 0.0); - - // fudge -- for punctual lighting, pretend water is metallic - diffuseColor = vec3(0); - specularColor = vec3(1); - roughness = 0.1; - float scol = 1.0; // TODO -- incorporate shadow map - - color.rgb += pbrPunctual(diffuseColor, specularColor, roughness, metallic, wavef, v, vary_light_dir) * sunlit * 2.75 * scol; - color.rgb = atmosFragLightingLinear(color.rgb, additive, atten); - color.rgb = scaleSoftClipFragLinear(color.rgb); - - color.a = 0.f; - //color.rgb = fb.rgb; - //color.rgb = vec3(depth*depth*depth*depth); - //color.rgb = srgb_to_linear(normalize(refPos) * 0.5 + 0.5); - //color.rgb = srgb_to_linear(normalize(pos) * 0.5 + 0.5); - //color.rgb = srgb_to_linear(wavef * 0.5 + 0.5); - - //color.rgb = radiance; + vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); + + vec4 fb = texture2D(screenTex, distort2); + + //mix with reflection + // Note we actually want to use just df1, but multiplying by 0.999999 gets around and nvidia compiler bug + color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999); + color.rgb += spec * specular; + + color.rgb = atmosTransport(color.rgb); + color.rgb = scaleSoftClip(color.rgb); + color.a = spec * sunAngle2; + frag_color = color; #if defined(WATER_EDGE) -- cgit v1.2.3 From 0fed3884c21453eac23a4de714bc87cac9e5377e Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 10 Oct 2022 10:19:36 -0500 Subject: SL-18190 Use funky distance based error correction only on water surface (revisit for general use later). --- .../app_settings/shaders/class2/deferred/reflectionProbeF.glsl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl index 0236680ac0..eb26143438 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) + vec3 pos, vec3 norm, float glossiness, bool errorCorrect) { ambenv = vec3(reflection_probe_ambiance * 0.25); @@ -43,6 +43,13 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, glossenv = srgb_to_linear(textureCube(environmentMap, env_vec).rgb); } +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, + vec3 pos, vec3 norm, float glossiness) +{ + sampleReflectionProbes(ambenv, glossenv, + pos, norm, glossiness, false); +} + void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, vec3 pos, vec3 norm, float glossiness, float envIntensity) { -- cgit v1.2.3 From 07bca31e06e4219401f82ae04539418c65e22ea8 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 10 Oct 2022 18:53:43 -0500 Subject: SL-18190 Fix alpha not playing nice with water surface by split LLDrawPoolAlpha into two passes, one above water, one below water, and clip against water plane. Currently brute forces two complete alpha passes, still need to cull against water plane and add support for fullbright shaders. --- indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl | 4 ++++ indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl | 3 +++ 2 files changed, 7 insertions(+) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl index b4406aabc0..b3f15f81f1 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl @@ -69,6 +69,8 @@ uniform vec3 light_direction[8]; uniform vec4 light_attenuation[8]; uniform vec3 light_diffuse[8]; +void waterClip(vec3 pos); + #ifdef WATER_FOG vec4 applyWaterFogView(vec3 pos, vec4 color); #endif @@ -181,6 +183,7 @@ void main() frag *= screen_res; vec4 pos = vec4(vary_position, 1.0); + waterClip(pos.xyz); vec3 norm = vary_norm; float shadow = 1.0f; @@ -295,6 +298,7 @@ void main() #endif // #else // FOR_IMPOSTOR + //color.rgb = waterPlane.xyz * 0.5 + 0.5; frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index 9bbc4f87bf..922da0c441 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -84,6 +84,8 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, vec3 pos, vec3 norm, float glossiness); +void waterClip(vec3 pos); + // PBR interface vec3 pbrIbl(vec3 diffuseColor, vec3 specularColor, @@ -139,6 +141,7 @@ void main() vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; vec3 pos = vary_position; + waterClip(pos); // IF .mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels; // vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb; -- cgit v1.2.3 From b6e576c7c2a1cb395092cc66b1836157872b131f Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 11 Oct 2022 20:20:39 -0500 Subject: SL-18190 Cleanup -- convert some vec4's to vec3's (as they really are), remove some unused glsl files. --- .../app_settings/shaders/class2/deferred/skyF.glsl | 32 +++++++-------- .../class2/windlight/atmosphericsFuncs.glsl | 46 +++++++++++----------- .../shaders/class2/windlight/cloudsF.glsl | 14 +++---- .../shaders/class2/windlight/cloudsV.glsl | 38 +++++++++--------- .../shaders/class2/windlight/skyV.glsl | 36 ++++++++--------- 5 files changed, 83 insertions(+), 83 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl index 4379024680..668f70c3ab 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -32,13 +32,13 @@ uniform mat4 modelview_projection_matrix; // Inputs uniform vec3 camPosLocal; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 moonlight_color; +uniform vec3 lightnorm; +uniform vec3 sunlight_color; +uniform vec3 moonlight_color; uniform int sun_up_factor; -uniform vec4 ambient_color; -uniform vec4 blue_horizon; -uniform vec4 blue_density; +uniform vec3 ambient_color; +uniform vec3 blue_horizon; +uniform vec3 blue_density; uniform float haze_horizon; uniform float haze_density; @@ -47,10 +47,10 @@ uniform float density_multiplier; uniform float distance_multiplier; uniform float max_y; -uniform vec4 glow; +uniform vec3 glow; uniform float sun_moon_glow_factor; -uniform vec4 cloud_color; +uniform vec3 cloud_color; #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; @@ -123,16 +123,16 @@ void main() float rel_pos_len = length(rel_pos); // Initialize temp variables - vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; + vec3 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes - vec4 light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + vec3 light_atten = (blue_density + vec3(haze_density * 0.25)) * (density_multiplier * max_y); // Calculate relative weights - vec4 combined_haze = abs(blue_density) + vec4(abs(haze_density)); - vec4 blue_weight = blue_density / combined_haze; - vec4 haze_weight = haze_density / combined_haze; + vec3 combined_haze = abs(blue_density) + vec3(abs(haze_density)); + vec3 blue_weight = blue_density / combined_haze; + vec3 haze_weight = haze_density / combined_haze; // Compute sunlight from rel_pos & lightnorm (for long rays like sky) float off_axis = 1.0 / max(1e-6, max(0, rel_pos_norm.y) + lightnorm.y); @@ -162,7 +162,7 @@ void main() haze_glow = (sun_moon_glow_factor < 1.0) ? 0.0 : (sun_moon_glow_factor * (haze_glow + 0.25)); // Haze color above cloud - vec4 color = blue_horizon * blue_weight * (sunlight + ambient_color) + vec3 color = blue_horizon * blue_weight * (sunlight + ambient_color) + haze_horizon * haze_weight * (sunlight * haze_glow + ambient_color); // Final atmosphere additive @@ -170,13 +170,13 @@ void main() // Increase ambient when there are more clouds // TODO 9/20: DJH what does this do? max(0,(1-ambient)) will change the color - vec4 ambient = ambient_color + max(vec4(0), (1. - ambient_color)) * cloud_shadow * 0.5; + vec3 ambient = ambient_color + max(vec3(0), (1. - ambient_color)) * cloud_shadow * 0.5; // Dim sunlight by cloud shadow percentage sunlight *= max(0.0, (1. - cloud_shadow)); // Haze color below cloud - vec4 add_below_cloud = blue_horizon * blue_weight * (sunlight + ambient) + vec3 add_below_cloud = blue_horizon * blue_weight * (sunlight + ambient) + haze_horizon * haze_weight * (sunlight * haze_glow + ambient); // Attenuate cloud color by atmosphere diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl index 8937488484..c69eba93b6 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl @@ -23,17 +23,17 @@ * $/LicenseInfo$ */ -uniform vec4 lightnorm; -uniform vec4 sunlight_color; +uniform vec3 lightnorm; +uniform vec3 sunlight_color; uniform vec3 sunlight_linear; -uniform vec4 moonlight_color; +uniform vec3 moonlight_color; uniform vec3 moonlight_linear; uniform int sun_up_factor; -uniform vec4 ambient_color; +uniform vec3 ambient_color; uniform vec3 ambient_linear; -uniform vec4 blue_horizon; +uniform vec3 blue_horizon; uniform vec3 blue_horizon_linear; -uniform vec4 blue_density; +uniform vec3 blue_density; uniform vec3 blue_density_linear; uniform float haze_horizon; uniform float haze_density; @@ -42,7 +42,7 @@ uniform float cloud_shadow; uniform float density_multiplier; uniform float distance_multiplier; uniform float max_y; -uniform vec4 glow; +uniform vec3 glow; uniform float scene_light_strength; uniform mat3 ssao_effect_mat; uniform int no_atmo; @@ -63,17 +63,17 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou vec3 rel_pos_norm = normalize(rel_pos); float rel_pos_len = length(rel_pos); - vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; + vec3 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; // sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes - vec4 light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + vec3 light_atten = (blue_density + vec3(haze_density * 0.25)) * (density_multiplier * max_y); // I had thought blue_density and haze_density should have equal weighting, // but attenuation due to haze_density tends to seem too strong - vec4 combined_haze = blue_density + vec4(haze_density); - vec4 blue_weight = blue_density / combined_haze; - vec4 haze_weight = vec4(haze_density) / combined_haze; + vec3 combined_haze = blue_density + vec3(haze_density); + vec3 blue_weight = blue_density / combined_haze; + vec3 haze_weight = vec3(haze_density) / combined_haze; //(TERRAIN) compute sunlight from lightnorm y component. Factor is roughly cosecant(sun elevation) (for short rays like terrain) float above_horizon_factor = 1.0 / max(1e-6, lightnorm.y); @@ -111,10 +111,10 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou haze_glow *= sun_moon_glow_factor; - vec4 amb_color = ambient_color; + vec3 amb_color = ambient_color; // increase ambient when there are more clouds - vec4 tmpAmbient = amb_color + (vec4(1.) - amb_color) * cloud_shadow * 0.5; + vec3 tmpAmbient = amb_color + (vec3(1.) - amb_color) * cloud_shadow * 0.5; /* decrease value and saturation (that in HSV, not HSL) for occluded areas * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html @@ -127,7 +127,7 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou */ if (use_ao) { - tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); + tmpAmbient = mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor); } // Similar/Shared Algorithms: @@ -179,17 +179,17 @@ void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, ou vec3 rel_pos_norm = normalize(rel_pos); float rel_pos_len = length(rel_pos); - vec4 sunlight = (sun_up_factor == 1) ? vec4(sunlight_linear, 0.0) : vec4(moonlight_linear, 0.0); + vec3 sunlight = (sun_up_factor == 1) ? vec3(sunlight_linear, 0.0) : vec3(moonlight_linear, 0.0); // sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes - vec4 light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + vec3 light_atten = (blue_density + vec3(haze_density * 0.25)) * (density_multiplier * max_y); // I had thought blue_density and haze_density should have equal weighting, // but attenuation due to haze_density tends to seem too strong - vec4 combined_haze = blue_density + vec4(haze_density); - vec4 blue_weight = blue_density / combined_haze; - vec4 haze_weight = vec4(haze_density) / combined_haze; + vec3 combined_haze = blue_density + vec3(haze_density); + vec3 blue_weight = blue_density / combined_haze; + vec3 haze_weight = vec3(haze_density) / combined_haze; //(TERRAIN) compute sunlight from lightnorm y component. Factor is roughly cosecant(sun elevation) (for short rays like terrain) float above_horizon_factor = 1.0 / max(1e-6, lightnorm.y); @@ -227,11 +227,11 @@ void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, ou haze_glow *= sun_moon_glow_factor; - //vec4 amb_color = vec4(ambient_linear, 0.0); - vec4 amb_color = ambient_color; + //vec3 amb_color = vec4(ambient_linear, 0.0); + vec3 amb_color = ambient_color; // increase ambient when there are more clouds - vec4 tmpAmbient = amb_color + (vec4(1.) - amb_color) * cloud_shadow * 0.5; + vec3 tmpAmbient = amb_color + (vec3(1.) - amb_color) * cloud_shadow * 0.5; // Similar/Shared Algorithms: // indra\llinventory\llsettingssky.cpp -- LLSettingsSky::calculateLightSettings() diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl index fa928d993e..9c5a4903d0 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl @@ -35,15 +35,15 @@ out vec4 frag_color; // The fragment shader for the sky ///////////////////////////////////////////////////////////////////////// -VARYING vec4 vary_CloudColorSun; -VARYING vec4 vary_CloudColorAmbient; +VARYING vec3 vary_CloudColorSun; +VARYING vec3 vary_CloudColorAmbient; VARYING float vary_CloudDensity; uniform sampler2D cloud_noise_texture; uniform sampler2D cloud_noise_texture_next; uniform float blend_factor; -uniform vec4 cloud_pos_density1; -uniform vec4 cloud_pos_density2; +uniform vec3 cloud_pos_density1; +uniform vec3 cloud_pos_density2; uniform float cloud_scale; uniform float cloud_variance; @@ -70,8 +70,8 @@ void main() vec2 uv1 = vary_texcoord0.xy; vec2 uv2 = vary_texcoord1.xy; - vec4 cloudColorSun = vary_CloudColorSun; - vec4 cloudColorAmbient = vary_CloudColorAmbient; + vec3 cloudColorSun = vary_CloudColorSun; + vec3 cloudColorAmbient = vary_CloudColorAmbient; float cloudDensity = vary_CloudDensity; vec2 uv3 = vary_texcoord2.xy; vec2 uv4 = vary_texcoord3.xy; @@ -120,7 +120,7 @@ void main() alpha2 = 1. - alpha2 * alpha2; // Combine - vec4 color; + vec3 color; color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); color.rgb *= 2.; color.rgb = scaleSoftClip(color.rgb); diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl index 97ffa9feef..650009d393 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl @@ -33,8 +33,8 @@ ATTRIBUTE vec2 texcoord0; /////////////////////////////////////////////////////////////////////////////// // Output parameters -VARYING vec4 vary_CloudColorSun; -VARYING vec4 vary_CloudColorAmbient; +VARYING vec3 vary_CloudColorSun; +VARYING vec3 vary_CloudColorAmbient; VARYING float vary_CloudDensity; VARYING vec2 vary_texcoord0; @@ -46,13 +46,13 @@ VARYING float altitude_blend_factor; // Inputs uniform vec3 camPosLocal; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 moonlight_color; +uniform vec3 lightnorm; +uniform vec3 sunlight_color; +uniform vec3 moonlight_color; uniform int sun_up_factor; -uniform vec4 ambient_color; -uniform vec4 blue_horizon; -uniform vec4 blue_density; +uniform vec3 ambient_color; +uniform vec3 blue_horizon; +uniform vec3 blue_density; uniform float haze_horizon; uniform float haze_density; @@ -60,10 +60,10 @@ uniform float cloud_shadow; uniform float density_multiplier; uniform float max_y; -uniform vec4 glow; +uniform vec3 glow; uniform float sun_moon_glow_factor; -uniform vec4 cloud_color; +uniform vec3 cloud_color; uniform float cloud_scale; @@ -114,17 +114,17 @@ void main() float rel_pos_len = length(rel_pos); // Initialize temp variables - vec4 sunlight = sunlight_color; - vec4 light_atten; + vec3 sunlight = sunlight_color; + vec3 light_atten; // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + light_atten = (blue_density + vec3(haze_density * 0.25)) * (density_multiplier * max_y); // Calculate relative weights - vec4 combined_haze = abs(blue_density) + vec4(abs(haze_density)); - vec4 blue_weight = blue_density / combined_haze; - vec4 haze_weight = haze_density / combined_haze; + vec3 combined_haze = abs(blue_density) + vec3(abs(haze_density)); + vec3 blue_weight = blue_density / combined_haze; + vec3 haze_weight = haze_density / combined_haze; // Compute sunlight from rel_pos & lightnorm (for long rays like sky) float off_axis = 1.0 / max(1e-6, max(0., rel_pos_norm.y) + lightnorm.y); @@ -155,14 +155,14 @@ void main() haze_glow = (sun_moon_glow_factor < 1.0) ? 0.0 : (haze_glow + 0.25); // Increase ambient when there are more clouds - vec4 tmpAmbient = ambient_color; + vec3 tmpAmbient = ambient_color; tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; // Dim sunlight by cloud shadow percentage sunlight *= (1. - cloud_shadow); // Haze color below cloud - vec4 additiveColorBelowCloud = + vec3 additiveColorBelowCloud = (blue_horizon * blue_weight * (sunlight + tmpAmbient) + (haze_horizon * haze_weight) * (sunlight * haze_glow + tmpAmbient)); // CLOUDS @@ -178,7 +178,7 @@ void main() combined_haze = sqrt(combined_haze); // less atmos opacity (more transparency) below clouds vary_CloudColorSun *= combined_haze; vary_CloudColorAmbient *= combined_haze; - vec4 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - combined_haze); + vec3 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - combined_haze); // Make a nice cloud density based on the cloud_shadow value that was passed in. vary_CloudDensity = 2. * (cloud_shadow - 0.25); diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl index 3edc94f4ca..8f7726bb0b 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl @@ -32,18 +32,18 @@ ATTRIBUTE vec3 position; /////////////////////////////////////////////////////////////////////////////// // Output parameters -VARYING vec4 vary_HazeColor; +VARYING vec3 vary_HazeColor; // Inputs uniform vec3 camPosLocal; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 moonlight_color; +uniform vec3 lightnorm; +uniform vec3 sunlight_color; +uniform vec3 moonlight_color; uniform int sun_up_factor; -uniform vec4 ambient_color; -uniform vec4 blue_horizon; -uniform vec4 blue_density; +uniform vec3 ambient_color; +uniform vec3 blue_horizon; +uniform vec3 blue_density; uniform float haze_horizon; uniform float haze_density; @@ -52,7 +52,7 @@ uniform float density_multiplier; uniform float distance_multiplier; uniform float max_y; -uniform vec4 glow; +uniform vec3 glow; uniform float sun_moon_glow_factor; void main() @@ -81,17 +81,17 @@ void main() float rel_pos_len = length(rel_pos); // Initialize temp variables - vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; - vec4 light_atten; + vec3 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; + vec3 light_atten; // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + light_atten = (blue_density + vec3(haze_density * 0.25)) * (density_multiplier * max_y); // Calculate relative weights - vec4 combined_haze = abs(blue_density) + vec4(abs(haze_density)); - vec4 blue_weight = blue_density / combined_haze; - vec4 haze_weight = haze_density / combined_haze; + vec3 combined_haze = abs(blue_density) + vec3(abs(haze_density)); + vec3 blue_weight = blue_density / combined_haze; + vec3 haze_weight = haze_density / combined_haze; // Compute sunlight from rel_pos & lightnorm (for long rays like sky) float off_axis = 1.0 / max(1e-6, max(0., rel_pos_norm.y) + lightnorm.y); @@ -119,21 +119,21 @@ void main() // For sun, add to glow. For moon, remove glow entirely. SL-13768 haze_glow = (sun_moon_glow_factor < 1.0) ? 0.0 : (haze_glow + 0.25); - vec4 color = + vec3 color = (blue_horizon * blue_weight * (sunlight + ambient_color) + (haze_horizon * haze_weight) * (sunlight * haze_glow + ambient_color)); // Final atmosphere additive color *= (1. - combined_haze); // Increase ambient when there are more clouds - vec4 tmpAmbient = ambient_color; - tmpAmbient += max(vec4(0), (1. - ambient_color)) * cloud_shadow * 0.5; + vec3 tmpAmbient = ambient_color; + tmpAmbient += max(vec3(0), (1. - ambient_color)) * cloud_shadow * 0.5; // Dim sunlight by cloud shadow percentage sunlight *= max(0.0, (1. - cloud_shadow)); // Haze color below cloud - vec4 additiveColorBelowCloud = + vec3 additiveColorBelowCloud = (blue_horizon * blue_weight * (sunlight + tmpAmbient) + (haze_horizon * haze_weight) * (sunlight * haze_glow + tmpAmbient)); // Attenuate cloud color by atmosphere -- cgit v1.2.3 From 9670139241891e4f93ddb5e42b2c5356e338af5f Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 12 Oct 2022 14:59:37 -0500 Subject: SL-18190 Fix for mismatch between alpha and opaque water fog. --- indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl index b3f15f81f1..7f566e67fa 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl @@ -72,7 +72,7 @@ uniform vec3 light_diffuse[8]; void waterClip(vec3 pos); #ifdef WATER_FOG -vec4 applyWaterFogView(vec3 pos, vec4 color); +vec4 applyWaterFogViewLinear(vec3 pos, vec4 color); #endif vec3 srgb_to_linear(vec3 c); @@ -293,7 +293,7 @@ void main() #endif // !defined(LOCAL_LIGHT_KILL) #ifdef WATER_FOG - color = applyWaterFogView(pos.xyz, color); + color = applyWaterFogViewLinear(pos.xyz, color); #endif // WATER_FOG #endif // #else // FOR_IMPOSTOR -- cgit v1.2.3 From 8a82305068f68ae4075be7ff86b5b4af8a71e5c3 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Tue, 11 Oct 2022 15:29:08 -0700 Subject: SL-18340: Fix PBR alpha materials treating spotlight as point light --- indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index 922da0c441..d7da50e25e 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -126,7 +126,12 @@ vec3 calcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, float dist_atten = calcLegacyDistanceAttenuation(dist, falloff); - vec3 intensity = dist_atten * lightColor * 3.0; + // spotlight coefficient. + float spot = max(dot(-ld, lv), is_pointlight); + // spot*spot => GL_SPOT_EXPONENT=2 + float spot_atten = spot*spot; + + vec3 intensity = spot_atten * dist_atten * lightColor * 3.0; color = intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, lv); } -- cgit v1.2.3 From 16a7989f065ac0870ad147592e4604cdcb204405 Mon Sep 17 00:00:00 2001 From: Brad Kittenbrink Date: Thu, 13 Oct 2022 11:34:37 -0700 Subject: SL-18362 Fix mac shader loading --- indra/newview/app_settings/shaders/class2/windlight/skyF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl index 7146349453..7a229e0f5e 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl @@ -33,7 +33,7 @@ out vec4 frag_color; // The fragment shader for the sky ///////////////////////////////////////////////////////////////////////// -VARYING vec4 vary_HazeColor; +VARYING vec3 vary_HazeColor; /// Soft clips the light with a gamma correction vec3 scaleSoftClip(vec3 light); @@ -45,7 +45,7 @@ void main() // the fragment) if the sky wouldn't show up because the clouds // are fully opaque. - vec4 color; + vec3 color; color = vary_HazeColor; color.rgb *= 2.; /// Gamma correct for WL (soft clip effect). -- cgit v1.2.3 From bc6ad18826995103015cfba6018cf1de30070fee Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 13 Oct 2022 16:15:41 -0500 Subject: SL-18376 Fix for transparent legacy avatar bits disappearing. --- indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl index 7f566e67fa..d211064701 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl @@ -183,7 +183,10 @@ void main() frag *= screen_res; vec4 pos = vec4(vary_position, 1.0); +#ifndef IS_AVATAR_SKIN + // clip against water plane unless this is a legacy avatar skin waterClip(pos.xyz); +#endif vec3 norm = vary_norm; float shadow = 1.0f; @@ -298,7 +301,6 @@ void main() #endif // #else // FOR_IMPOSTOR - //color.rgb = waterPlane.xyz * 0.5 + 0.5; frag_color = color; } -- cgit v1.2.3 From 982e2bcbeaa3a56a884ecb168dc655dc6413465c Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Thu, 13 Oct 2022 16:59:34 -0700 Subject: SL-18340: Consolidate shared pbr shading into calcDiffuseSpecular, pbrBaseLight --- .../shaders/class2/deferred/pbralphaF.glsl | 49 +++++++++++----------- 1 file changed, 24 insertions(+), 25 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index d7da50e25e..f5c36be897 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -75,8 +75,6 @@ vec3 srgb_to_linear(vec3 c); vec3 linear_to_srgb(vec3 c); void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); -vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten); -vec3 scaleSoftClipFragLinear(vec3 l); void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist); float calcLegacyDistanceAttenuation(float distance, float falloff); @@ -86,14 +84,23 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, void waterClip(vec3 pos); -// PBR interface -vec3 pbrIbl(vec3 diffuseColor, - vec3 specularColor, - vec3 radiance, // radiance map sample - vec3 irradiance, // irradiance map sample - float ao, // ambient occlusion factor - float nv, // normal dot view vector - float perceptualRoughness); +void calcDiffuseSpecular(vec3 baseColor, float metallic, inout vec3 diffuseColor, inout vec3 specularColor); + +vec3 pbrBaseLight(vec3 diffuseColor, + vec3 specularColor, + float metallic, + vec3 pos, + vec3 norm, + float perceptualRoughness, + vec3 light_dir, + vec3 sunlit, + float scol, + vec3 radiance, + vec3 irradiance, + vec3 colorEmissive, + float ao, + vec3 additive, + vec3 atten); vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, float perceptualRoughness, @@ -201,24 +208,16 @@ void main() vec3 irradiance = vec3(0); vec3 radiance = vec3(0); sampleReflectionProbes(irradiance, radiance, pos.xyz, norm.xyz, gloss); - irradiance = max(amblit*0.75,irradiance); + // 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); - vec3 f0 = vec3(0.04); - - vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0); - diffuseColor *= 1.0 - metallic; - - vec3 specularColor = mix(f0, baseColor.rgb, metallic); + vec3 diffuseColor; + vec3 specularColor; + calcDiffuseSpecular(baseColor.rgb, metallic, diffuseColor, specularColor); vec3 v = -normalize(pos.xyz); - float NdotV = clamp(abs(dot(norm.xyz, v)), 0.001, 1.0); - - color += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, perceptualRoughness); - color += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, v, light_dir) * sunlit * scol; - color += colorEmissive*0.5; - - color = atmosFragLightingLinear(color, additive, atten); - color = scaleSoftClipFragLinear(color); + color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit, scol, radiance, irradiance, colorEmissive, ao, additive, atten); vec3 light = vec3(0); -- cgit v1.2.3 From 239dc764e66b3cfeb165a304e64f3f5ad756c3e5 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Thu, 13 Oct 2022 17:10:09 -0700 Subject: SL-18340: Consistently use HAS_SUN_SHADOW for shader permutation --- indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl | 4 ++-- indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl index b3f15f81f1..be605b6e60 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl @@ -84,7 +84,7 @@ vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten); void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); -#ifdef HAS_SHADOW +#ifdef HAS_SUN_SHADOW float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); #endif @@ -188,7 +188,7 @@ void main() float shadow = 1.0f; -#ifdef HAS_SHADOW +#ifdef HAS_SUN_SHADOW shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, frag); #endif diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index f5c36be897..b39f834e41 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -44,7 +44,7 @@ uniform vec3 moon_dir; out vec4 frag_color; -#ifdef HAS_SHADOW +#ifdef HAS_SUN_SHADOW VARYING vec3 vary_fragcoord; uniform vec2 screen_res; #endif @@ -186,7 +186,7 @@ void main() vec3 atten; calcAtmosphericVarsLinear(pos.xyz, norm, light_dir, sunlit, amblit, additive, atten); -#ifdef HAS_SHADOW +#ifdef HAS_SUN_SHADOW vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; frag *= screen_res; scol = sampleDirectionalShadow(pos.xyz, norm.xyz, frag); -- cgit v1.2.3 From 9e7b725c15ea0bfea5246eb81dd7a100b7ac5b6b Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Mon, 31 Oct 2022 09:42:27 -0700 Subject: SL-18485: Render GLTF materials with extension KHR_texture_transform with approprate texture transforms --- .../shaders/class2/deferred/pbralphaF.glsl | 41 +++++++++++----------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index b39f834e41..6500c4bb1f 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -45,17 +45,21 @@ uniform vec3 moon_dir; out vec4 frag_color; #ifdef HAS_SUN_SHADOW - VARYING vec3 vary_fragcoord; + in vec3 vary_fragcoord; uniform vec2 screen_res; #endif -VARYING vec3 vary_position; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; -VARYING vec2 vary_texcoord1; -VARYING vec2 vary_texcoord2; -VARYING vec3 vary_normal; -VARYING vec3 vary_tangent; +in vec3 vary_position; + +in vec2 basecolor_texcoord; +in vec2 normal_texcoord; +in vec2 metallic_roughness_texcoord; +in vec2 emissive_texcoord; + +in vec4 vertex_color; + +in vec3 vary_normal; +in vec3 vary_tangent; flat in float vary_sign; @@ -155,21 +159,18 @@ void main() waterClip(pos); -// IF .mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels; -// vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb; -// else - vec4 albedo = texture(diffuseMap, vary_texcoord0.xy).rgba; - albedo.rgb = srgb_to_linear(albedo.rgb); + vec4 basecolor = texture(diffuseMap, basecolor_texcoord.xy).rgba; + basecolor.rgb = srgb_to_linear(basecolor.rgb); #ifdef HAS_ALPHA_MASK - if (albedo.a < minimum_alpha) + if (basecolor.a < minimum_alpha) { discard; } #endif - vec3 baseColor = vertex_color.rgb * albedo.rgb; + vec3 col = vertex_color.rgb * basecolor.rgb; - vec3 vNt = texture(bumpMap, vary_texcoord1.xy).xyz*2.0-1.0; + vec3 vNt = texture(bumpMap, normal_texcoord.xy).xyz*2.0-1.0; float sign = vary_sign; vec3 vN = vary_normal; vec3 vT = vary_tangent.xyz; @@ -192,7 +193,7 @@ void main() scol = sampleDirectionalShadow(pos.xyz, norm.xyz, frag); #endif - vec3 orm = texture(specularMap, vary_texcoord2.xy).rgb; //orm is packed into "emissiveRect" to keep the data in linear color space + vec3 orm = texture(specularMap, metallic_roughness_texcoord.xy).rgb; //orm is packed into "emissiveRect" to keep the data in linear color space float perceptualRoughness = orm.g * roughnessFactor; float metallic = orm.b * metallicFactor; @@ -201,7 +202,7 @@ void main() // emissiveColor is the emissive color factor from GLTF and is already in linear space vec3 colorEmissive = emissiveColor; // emissiveMap here is a vanilla RGB texture encoded as sRGB, manually convert to linear - colorEmissive *= srgb_to_linear(texture2D(emissiveMap, vary_texcoord0.xy).rgb); + colorEmissive *= srgb_to_linear(texture2D(emissiveMap, emissive_texcoord.xy).rgb); // PBR IBL float gloss = 1.0 - perceptualRoughness; @@ -214,7 +215,7 @@ void main() vec3 diffuseColor; vec3 specularColor; - calcDiffuseSpecular(baseColor.rgb, metallic, diffuseColor, specularColor); + calcDiffuseSpecular(col.rgb, metallic, diffuseColor, specularColor); vec3 v = -normalize(pos.xyz); color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit, scol, radiance, irradiance, colorEmissive, ao, additive, atten); @@ -235,5 +236,5 @@ void main() color.rgb += light.rgb; - frag_color = vec4(color.rgb,albedo.a * vertex_color.a); + frag_color = vec4(color.rgb,basecolor.a * vertex_color.a); } -- cgit v1.2.3 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 --- .../shaders/class2/deferred/alphaF.glsl | 1 - .../shaders/class2/deferred/multiSpotLightF.glsl | 19 +++++++++--------- .../shaders/class2/deferred/pbralphaF.glsl | 3 +-- .../shaders/class2/deferred/softenLightF.glsl | 23 +++++++++++----------- .../shaders/class2/deferred/softenLightV.glsl | 6 ++---- .../shaders/class2/deferred/spotLightF.glsl | 19 +++++++++--------- .../shaders/class2/deferred/sunLightV.glsl | 6 ++---- 7 files changed, 35 insertions(+), 42 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl index e255c78b86..25b0a0b970 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl @@ -180,7 +180,6 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec void main() { vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; - frag *= screen_res; vec4 pos = vec4(vary_position, 1.0); #ifndef IS_AVATAR_SKIN diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 1b7a1cc6ec..24068c04b5 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -34,12 +34,12 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect depthMap; -uniform sampler2DRect normalMap; +uniform sampler2D diffuseRect; +uniform sampler2D specularRect; +uniform sampler2D depthMap; +uniform sampler2D normalMap; uniform samplerCube environmentMap; -uniform sampler2DRect lightMap; +uniform sampler2D lightMap; uniform sampler2D noiseMap; uniform sampler2D projectionMap; uniform sampler2D lightFunc; @@ -138,7 +138,6 @@ void main() vec4 frag = vary_fragcoord; frag.xyz /= frag.w; frag.xyz = frag.xyz*0.5+0.5; - frag.xy *= screen_res; vec3 pos = getPosition(frag.xy).xyz; vec3 lv = center.xyz-pos.xyz; @@ -154,13 +153,13 @@ void main() if (proj_shadow_idx >= 0) { - vec4 shd = texture2DRect(lightMap, frag.xy); + vec4 shd = texture2D(lightMap, frag.xy); shadow = (proj_shadow_idx==0)?shd.b:shd.a; shadow += shadow_fade; shadow = clamp(shadow, 0.0, 1.0); } - vec3 norm = texture2DRect(normalMap, frag.xy).xyz; + vec3 norm = texture2D(normalMap, frag.xy).xyz; float envIntensity = norm.z; @@ -190,9 +189,9 @@ void main() lv = normalize(lv); float da = dot(norm, lv); - vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; + vec3 diff_tex = texture2D(diffuseRect, frag.xy).rgb; - vec4 spec = texture2DRect(specularRect, frag.xy); + vec4 spec = texture2D(specularRect, frag.xy); vec3 dlit = vec3(0, 0, 0); diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index 6500c4bb1f..d81102991e 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -35,7 +35,7 @@ uniform float roughnessFactor; uniform vec3 emissiveColor; #if defined(HAS_SUN_SHADOW) || defined(HAS_SSAO) -uniform sampler2DRect lightMap; +uniform sampler2D lightMap; #endif uniform int sun_up_factor; @@ -189,7 +189,6 @@ void main() #ifdef HAS_SUN_SHADOW vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; - frag *= screen_res; scol = sampleDirectionalShadow(pos.xyz, norm.xyz, frag); #endif diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 677c9c244c..fab227f5a4 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -34,11 +34,11 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect normalMap; -uniform sampler2DRect lightMap; -uniform sampler2DRect depthMap; +uniform sampler2D diffuseRect; +uniform sampler2D specularRect; +uniform sampler2D normalMap; +uniform sampler2D lightMap; +uniform sampler2D depthMap; uniform samplerCube environmentMap; uniform sampler2D lightFunc; @@ -58,6 +58,7 @@ uniform vec2 screen_res; vec3 getNorm(vec2 pos_screen); vec4 getPositionWithDepth(vec2 pos_screen, float depth); +float getDepth(vec2 pos_screen); void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); float getAmbientClamp(); @@ -76,9 +77,9 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); void main() { vec2 tc = vary_fragcoord.xy; - float depth = texture2DRect(depthMap, tc.xy).r; + float depth = getDepth(tc.xy); vec4 pos = getPositionWithDepth(tc, depth); - vec4 norm = texture2DRect(normalMap, tc); + vec4 norm = texture2D(normalMap, tc); float envIntensity = norm.z; norm.xyz = getNorm(tc); @@ -87,11 +88,11 @@ void main() float light_gamma = 1.0 / 1.3; da = pow(da, light_gamma); - vec4 diffuse = texture2DRect(diffuseRect, tc); + vec4 diffuse = texture2D(diffuseRect, tc); diffuse.rgb = linear_to_srgb(diffuse.rgb); // SL-14035 - vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); + vec4 spec = texture2D(specularRect, vary_fragcoord.xy); - vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; + vec2 scol_ambocc = texture2D(lightMap, vary_fragcoord.xy).rg; scol_ambocc = pow(scol_ambocc, vec2(light_gamma)); float scol = max(scol_ambocc.r, diffuse.a); float ambocc = scol_ambocc.g; @@ -153,6 +154,6 @@ void main() // convert to linear as fullscreen lights need to sum in linear colorspace // and will be gamma (re)corrected downstream... - frag_color.rgb = srgb_to_linear(color.rgb); + frag_color.rgb = pos.xyz;// srgb_to_linear(color.rgb); frag_color.a = bloom; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl index bd11aa3f05..1e7ccb747a 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl @@ -23,8 +23,6 @@ * $/LicenseInfo$ */ -uniform mat4 modelview_projection_matrix; - ATTRIBUTE vec3 position; uniform vec2 screen_res; @@ -38,12 +36,12 @@ void setAdditiveColor(vec3 c); void main() { //transform vertex - vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); + vec4 pos = vec4(position.xyz, 1.0); gl_Position = pos; // appease OSX GLSL compiler/linker by touching all the varyings we said we would setAtmosAttenuation(vec3(1)); setAdditiveColor(vec3(0)); - vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; + vary_fragcoord = (pos.xy*0.5+0.5); } diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 774f537821..c41b7b210c 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -34,12 +34,12 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect depthMap; -uniform sampler2DRect normalMap; +uniform sampler2D diffuseRect; +uniform sampler2D specularRect; +uniform sampler2D depthMap; +uniform sampler2D normalMap; uniform samplerCube environmentMap; -uniform sampler2DRect lightMap; +uniform sampler2D lightMap; uniform sampler2D noiseMap; uniform sampler2D projectionMap; uniform sampler2D lightFunc; @@ -138,7 +138,6 @@ void main() vec4 frag = vary_fragcoord; frag.xyz /= frag.w; frag.xyz = frag.xyz*0.5+0.5; - frag.xy *= screen_res; vec3 pos = getPosition(frag.xy).xyz; vec3 lv = trans_center.xyz-pos.xyz; @@ -154,13 +153,13 @@ void main() if (proj_shadow_idx >= 0) { - vec4 shd = texture2DRect(lightMap, frag.xy); + vec4 shd = texture2D(lightMap, frag.xy); shadow = (proj_shadow_idx == 0) ? shd.b : shd.a; shadow += shadow_fade; shadow = clamp(shadow, 0.0, 1.0); } - vec3 norm = texture2DRect(normalMap, frag.xy).xyz; + vec3 norm = texture2D(normalMap, frag.xy).xyz; float envIntensity = norm.z; norm = getNorm(frag.xy); @@ -189,8 +188,8 @@ void main() lv = normalize(lv); float da = dot(norm, lv); - vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; - vec4 spec = texture2DRect(specularRect, frag.xy); + vec3 diff_tex = texture2D(diffuseRect, frag.xy).rgb; + vec4 spec = texture2D(specularRect, frag.xy); vec3 dlit = vec3(0, 0, 0); float noise = texture2D(noiseMap, frag.xy/128.0).b; diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightV.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightV.glsl index bc5eb5181d..3dfca0f655 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightV.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightV.glsl @@ -23,8 +23,6 @@ * $/LicenseInfo$ */ -uniform mat4 modelview_projection_matrix; - ATTRIBUTE vec3 position; VARYING vec2 vary_fragcoord; @@ -34,8 +32,8 @@ uniform vec2 screen_res; void main() { //transform vertex - vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); + vec4 pos = vec4(position.xyz, 1.0); gl_Position = pos; - vary_fragcoord = (pos.xy * 0.5 + 0.5)*screen_res; + vary_fragcoord = (pos.xy * 0.5 + 0.5); } -- cgit v1.2.3 From 34d3f94db6d2ab243f8ee63522e60cb1e22dedff Mon Sep 17 00:00:00 2001 From: Geenz Linden Date: Sun, 20 Nov 2022 11:09:05 +0100 Subject: Fix for SSAO not behaving properly. SL-18662 --- indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl | 2 +- indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 24068c04b5..ba419e7a65 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -195,7 +195,7 @@ void main() vec3 dlit = vec3(0, 0, 0); - float noise = texture2D(noiseMap, frag.xy/128.0).b; + float noise = texture2D(noiseMap, frag.xy).b; if (proj_tc.z > 0.0 && proj_tc.x < 1.0 && proj_tc.y < 1.0 && diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index c41b7b210c..e6a627fbf7 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -192,7 +192,7 @@ void main() vec4 spec = texture2D(specularRect, frag.xy); vec3 dlit = vec3(0, 0, 0); - float noise = texture2D(noiseMap, frag.xy/128.0).b; + float noise = texture2D(noiseMap, frag.xy).b; if (proj_tc.z > 0.0 && proj_tc.x < 1.0 && proj_tc.y < 1.0 && -- cgit v1.2.3 From e6b5481cad3f81f18ff04ff6af86bd7ad5b9c5da Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 14 Dec 2022 11:00:31 -0600 Subject: SL-18782 WIP -- stub for reflection probe display. --- .../shaders/class2/deferred/reflectionProbeF.glsl | 6 ++++ .../shaders/class2/interface/reflectionprobeF.glsl | 42 ++++++++++++++++++++++ .../shaders/class2/interface/reflectionprobeV.glsl | 38 ++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 indra/newview/app_settings/shaders/class2/interface/reflectionprobeF.glsl create mode 100644 indra/newview/app_settings/shaders/class2/interface/reflectionprobeV.glsl (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl index eb26143438..af43c7b4e3 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl @@ -50,6 +50,12 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, pos, norm, glossiness, false); } +vec4 sampleReflectionProbesDebug(vec3 pos) +{ + // show nothing in debug display + 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) { diff --git a/indra/newview/app_settings/shaders/class2/interface/reflectionprobeF.glsl b/indra/newview/app_settings/shaders/class2/interface/reflectionprobeF.glsl new file mode 100644 index 0000000000..986b233e0b --- /dev/null +++ b/indra/newview/app_settings/shaders/class2/interface/reflectionprobeF.glsl @@ -0,0 +1,42 @@ +/** + * @file reflectionprobeF.glsl + * + * $LicenseInfo:firstyear=2022&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2022, 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$ + */ + +out vec4 frag_color; + +in vec2 vary_fragcoord; + +vec4 getPositionWithDepth(vec2 pos_screen, float depth); +float getDepth(vec2 pos_screen); + +vec4 sampleReflectionProbesDebug(vec3 pos); + +void main() +{ + vec2 tc = vary_fragcoord.xy; + float depth = getDepth(tc.xy); + vec4 pos = getPositionWithDepth(tc, depth); + + frag_color = sampleReflectionProbesDebug(pos.xyz); +} diff --git a/indra/newview/app_settings/shaders/class2/interface/reflectionprobeV.glsl b/indra/newview/app_settings/shaders/class2/interface/reflectionprobeV.glsl new file mode 100644 index 0000000000..e45b1c288b --- /dev/null +++ b/indra/newview/app_settings/shaders/class2/interface/reflectionprobeV.glsl @@ -0,0 +1,38 @@ +/** + * @file reflectionprobeV.glsl + * + * $LicenseInfo:firstyear=2022&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, 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$ + */ + + +in vec3 position; + +out vec2 vary_fragcoord; + +void main() +{ + //transform vertex + vec4 pos = vec4(position.xyz, 1.0); + gl_Position = pos; + + vary_fragcoord = (pos.xy*0.5+0.5); +} -- cgit v1.2.3 From 40799b97c188bb3c0a4b2d00a35bcc41be461f08 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 19 Dec 2022 15:27:43 -0600 Subject: SL-18779 Fix for water fog staying bright when sun is dark. --- indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl index 25b0a0b970..076b976dc4 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl @@ -72,7 +72,7 @@ uniform vec3 light_diffuse[8]; void waterClip(vec3 pos); #ifdef WATER_FOG -vec4 applyWaterFogViewLinear(vec3 pos, vec4 color); +vec4 applyWaterFogViewLinear(vec3 pos, vec4 color, vec3 sunlit); #endif vec3 srgb_to_linear(vec3 c); @@ -226,7 +226,7 @@ void main() vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); - vec3 light_dir = (sun_up_factor == 1) ? sun_dir: moon_dir; + vec3 light_dir = (sun_up_factor == 1) ? sun_dir: moon_dir; // TODO -- factor out "sun_up_factor" and just send in the appropriate light vector float final_alpha = diffuse_linear.a; @@ -295,7 +295,7 @@ void main() #endif // !defined(LOCAL_LIGHT_KILL) #ifdef WATER_FOG - color = applyWaterFogViewLinear(pos.xyz, color); + color = applyWaterFogViewLinear(pos.xyz, color, sunlit); #endif // WATER_FOG #endif // #else // FOR_IMPOSTOR -- 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. --- indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl | 6 +++--- .../app_settings/shaders/class2/deferred/pbralphaF.glsl | 4 ++-- .../app_settings/shaders/class2/deferred/reflectionProbeF.glsl | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') 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); -- cgit v1.2.3 From 10b8dcc497599042655dcc4037c9ae98d494bd6f Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 30 Jan 2023 18:56:19 -0600 Subject: SL-19015 Bump probe resolution back to 256 by default (drop to 128 if vram < 2GB), remove irradiance map feedback loop (one bounce, but but more stable and allows for much brighter first bounce), make sky contribution to irradiance not tint the world blue. Make irradiance that appears in radiance maps match world irradiance. --- .../shaders/class2/interface/irradianceGenF.glsl | 231 +++++++++++++++++++++ .../class2/windlight/atmosphericsFuncs.glsl | 80 ------- 2 files changed, 231 insertions(+), 80 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class2/interface/irradianceGenF.glsl (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/interface/irradianceGenF.glsl b/indra/newview/app_settings/shaders/class2/interface/irradianceGenF.glsl new file mode 100644 index 0000000000..a4aec48c59 --- /dev/null +++ b/indra/newview/app_settings/shaders/class2/interface/irradianceGenF.glsl @@ -0,0 +1,231 @@ +/** + * @file irradianceGenF.glsl + * + * $LicenseInfo:firstyear=2022&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2022, 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$ + */ + + +/*[EXTRA_CODE_HERE]*/ + + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform samplerCubeArray reflectionProbes; +uniform int sourceIdx; + +uniform float max_probe_lod; + +VARYING vec3 vary_dir; + + +// Code below is derived from the Khronos GLTF Sample viewer: +// https://github.com/KhronosGroup/glTF-Sample-Viewer/blob/master/source/shaders/ibl_filtering.frag + + +#define MATH_PI 3.1415926535897932384626433832795 + +float u_roughness = 1.0; +int u_sampleCount = 64; +float u_lodBias = 2.0; +int u_width = 64; + +// Hammersley Points on the Hemisphere +// CC BY 3.0 (Holger Dammertz) +// http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html +// with adapted interface +float radicalInverse_VdC(uint bits) +{ + bits = (bits << 16u) | (bits >> 16u); + bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u); + bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u); + bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u); + bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u); + return float(bits) * 2.3283064365386963e-10; // / 0x100000000 +} + +// hammersley2d describes a sequence of points in the 2d unit square [0,1)^2 +// that can be used for quasi Monte Carlo integration +vec2 hammersley2d(int i, int N) { + return vec2(float(i)/float(N), radicalInverse_VdC(uint(i))); +} + +// Hemisphere Sample + +// TBN generates a tangent bitangent normal coordinate frame from the normal +// (the normal must be normalized) +mat3 generateTBN(vec3 normal) +{ + vec3 bitangent = vec3(0.0, 1.0, 0.0); + + float NdotUp = dot(normal, vec3(0.0, 1.0, 0.0)); + float epsilon = 0.0000001; + /*if (1.0 - abs(NdotUp) <= epsilon) + { + // Sampling +Y or -Y, so we need a more robust bitangent. + if (NdotUp > 0.0) + { + bitangent = vec3(0.0, 0.0, 1.0); + } + else + { + bitangent = vec3(0.0, 0.0, -1.0); + } + }*/ + + vec3 tangent = normalize(cross(bitangent, normal)); + bitangent = cross(normal, tangent); + + return mat3(tangent, bitangent, normal); +} + +struct MicrofacetDistributionSample +{ + float pdf; + float cosTheta; + float sinTheta; + float phi; +}; + +MicrofacetDistributionSample Lambertian(vec2 xi, float roughness) +{ + MicrofacetDistributionSample lambertian; + + // Cosine weighted hemisphere sampling + // http://www.pbr-book.org/3ed-2018/Monte_Carlo_Integration/2D_Sampling_with_Multidimensional_Transformations.html#Cosine-WeightedHemisphereSampling + lambertian.cosTheta = sqrt(1.0 - xi.y); + lambertian.sinTheta = sqrt(xi.y); // equivalent to `sqrt(1.0 - cosTheta*cosTheta)`; + lambertian.phi = 2.0 * MATH_PI * xi.x; + + lambertian.pdf = lambertian.cosTheta / MATH_PI; // evaluation for solid angle, therefore drop the sinTheta + + return lambertian; +} + + +// getImportanceSample returns an importance sample direction with pdf in the .w component +vec4 getImportanceSample(int sampleIndex, vec3 N, float roughness) +{ + // generate a quasi monte carlo point in the unit square [0.1)^2 + vec2 xi = hammersley2d(sampleIndex, u_sampleCount); + + MicrofacetDistributionSample importanceSample; + + // generate the points on the hemisphere with a fitting mapping for + // the distribution (e.g. lambertian uses a cosine importance) + importanceSample = Lambertian(xi, roughness); + + // transform the hemisphere sample to the normal coordinate frame + // i.e. rotate the hemisphere to the normal direction + vec3 localSpaceDirection = normalize(vec3( + importanceSample.sinTheta * cos(importanceSample.phi), + importanceSample.sinTheta * sin(importanceSample.phi), + importanceSample.cosTheta + )); + mat3 TBN = generateTBN(N); + vec3 direction = TBN * localSpaceDirection; + + return vec4(direction, importanceSample.pdf); +} + +// Mipmap Filtered Samples (GPU Gems 3, 20.4) +// https://developer.nvidia.com/gpugems/gpugems3/part-iii-rendering/chapter-20-gpu-based-importance-sampling +// https://cgg.mff.cuni.cz/~jaroslav/papers/2007-sketch-fis/Final_sap_0073.pdf +float computeLod(float pdf) +{ + // // Solid angle of current sample -- bigger for less likely samples + // float omegaS = 1.0 / (float(u_sampleCount) * pdf); + // // Solid angle of texel + // // note: the factor of 4.0 * MATH_PI + // float omegaP = 4.0 * MATH_PI / (6.0 * float(u_width) * float(u_width)); + // // Mip level is determined by the ratio of our sample's solid angle to a texel's solid angle + // // note that 0.5 * log2 is equivalent to log4 + // float lod = 0.5 * log2(omegaS / omegaP); + + // babylon introduces a factor of K (=4) to the solid angle ratio + // this helps to avoid undersampling the environment map + // this does not appear in the original formulation by Jaroslav Krivanek and Mark Colbert + // log4(4) == 1 + // lod += 1.0; + + // We achieved good results by using the original formulation from Krivanek & Colbert adapted to cubemaps + + // https://cgg.mff.cuni.cz/~jaroslav/papers/2007-sketch-fis/Final_sap_0073.pdf + float lod = 0.5 * log2( 6.0 * float(u_width) * float(u_width) / (float(u_sampleCount) * pdf)); + + + return lod; +} + +vec4 filterColor(vec3 N) +{ + //return textureLod(uCubeMap, N, 3.0).rgb; + vec4 color = vec4(0.f); + float weight = 0.0f; + + for(int i = 0; i < u_sampleCount; ++i) + { + vec4 importanceSample = getImportanceSample(i, N, 1.0); + + vec3 H = vec3(importanceSample.xyz); + float pdf = importanceSample.w; + + // mipmap filtered samples (GPU Gems 3, 20.4) + float lod = computeLod(pdf); + + // apply the bias to the lod + lod += u_lodBias; + + lod = clamp(lod, 0, max_probe_lod); + // sample lambertian at a lower resolution to avoid fireflies + vec4 lambertian = textureLod(reflectionProbes, vec4(H, sourceIdx), lod); + + color += lambertian; + } + + if(weight != 0.0f) + { + color /= weight; + } + else + { + color /= float(u_sampleCount); + } + + color = min(color*1.9, vec4(1)); + color = pow(color, vec4(0.5)); + return color; +} + +// entry point +void main() +{ + vec4 color = vec4(0); + + color = filterColor(vary_dir); + + frag_color = color; +} + diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl index c69eba93b6..ba02070e45 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl @@ -162,90 +162,10 @@ float ambientLighting(vec3 norm, vec3 light_dir) void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { -#if 1 calcAtmosphericVars(inPositionEye, light_dir, 1.0, sunlit, amblit, additive, atten, false); sunlit = srgb_to_linear(sunlit); additive = srgb_to_linear(additive); amblit = ambient_linear; amblit *= ambientLighting(norm, light_dir); -#else - - //EXPERIMENTAL -- attempt to factor out srgb_to_linear conversions above - vec3 rel_pos = inPositionEye; - - //(TERRAIN) limit altitude - if (abs(rel_pos.y) > max_y) rel_pos *= (max_y / rel_pos.y); - - vec3 rel_pos_norm = normalize(rel_pos); - float rel_pos_len = length(rel_pos); - vec3 sunlight = (sun_up_factor == 1) ? vec3(sunlight_linear, 0.0) : vec3(moonlight_linear, 0.0); - - // sunlight attenuation effect (hue and brightness) due to atmosphere - // this is used later for sunlight modulation at various altitudes - vec3 light_atten = (blue_density + vec3(haze_density * 0.25)) * (density_multiplier * max_y); - // I had thought blue_density and haze_density should have equal weighting, - // but attenuation due to haze_density tends to seem too strong - - vec3 combined_haze = blue_density + vec3(haze_density); - vec3 blue_weight = blue_density / combined_haze; - vec3 haze_weight = vec3(haze_density) / combined_haze; - - //(TERRAIN) compute sunlight from lightnorm y component. Factor is roughly cosecant(sun elevation) (for short rays like terrain) - float above_horizon_factor = 1.0 / max(1e-6, lightnorm.y); - sunlight *= exp(-light_atten * above_horizon_factor); // for sun [horizon..overhead] this maps to an exp curve [0..1] - - // main atmospheric scattering line integral - float density_dist = rel_pos_len * density_multiplier; - - // Transparency (-> combined_haze) - // ATI Bugfix -- can't store combined_haze*density_dist*distance_multiplier in a variable because the ati - // compiler gets confused. - combined_haze = exp(-combined_haze * density_dist * distance_multiplier); - - // final atmosphere attenuation factor - atten = combined_haze.rgb; - - // compute haze glow - float haze_glow = dot(rel_pos_norm, lightnorm.xyz); - - // dampen sun additive contrib when not facing it... - // SL-13539: This "if" clause causes an "additive" white artifact at roughly 77 degreees. - // if (length(light_dir) > 0.01) - haze_glow *= max(0.0f, dot(light_dir, rel_pos_norm)); - - haze_glow = 1. - haze_glow; - // haze_glow is 0 at the sun and increases away from sun - haze_glow = max(haze_glow, .001); // set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - haze_glow *= glow.x; - // higher glow.x gives dimmer glow (because next step is 1 / "angle") - haze_glow = pow(haze_glow, glow.z); - // glow.z should be negative, so we're doing a sort of (1 / "angle") function - - // add "minimum anti-solar illumination" - haze_glow += .25; - - haze_glow *= sun_moon_glow_factor; - - //vec3 amb_color = vec4(ambient_linear, 0.0); - vec3 amb_color = ambient_color; - - // increase ambient when there are more clouds - vec3 tmpAmbient = amb_color + (vec3(1.) - amb_color) * cloud_shadow * 0.5; - - // Similar/Shared Algorithms: - // indra\llinventory\llsettingssky.cpp -- LLSettingsSky::calculateLightSettings() - // indra\newview\app_settings\shaders\class1\windlight\atmosphericsFuncs.glsl -- calcAtmosphericVars() - // haze color - vec3 cs = sunlight.rgb * (1. - cloud_shadow); - additive = (blue_horizon.rgb * blue_weight.rgb) * (cs + tmpAmbient.rgb) + (haze_horizon * haze_weight.rgb) * (cs * haze_glow + tmpAmbient.rgb); - - // brightness of surface both sunlight and ambient - sunlit = min(sunlight.rgb, vec3(1)); - amblit = tmpAmbient.rgb; - additive *= vec3(1.0 - combined_haze); - - //sunlit = sunlight_linear; - amblit = ambient_linear*0.8; -#endif } -- cgit v1.2.3 From c9d56e212aa0117661f9c76545ca84b39412bae7 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 31 Jan 2023 15:01:05 -0600 Subject: SL-19015 Balance sun/sky ambiance with punctual light ambiance. Prevent irradiance maps from being brighter than the environment. --- .../shaders/class2/interface/irradianceGenF.glsl | 29 ++++++---------------- 1 file changed, 8 insertions(+), 21 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/interface/irradianceGenF.glsl b/indra/newview/app_settings/shaders/class2/interface/irradianceGenF.glsl index a4aec48c59..c7da23fb00 100644 --- a/indra/newview/app_settings/shaders/class2/interface/irradianceGenF.glsl +++ b/indra/newview/app_settings/shaders/class2/interface/irradianceGenF.glsl @@ -26,20 +26,15 @@ /*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif uniform samplerCubeArray reflectionProbes; uniform int sourceIdx; uniform float max_probe_lod; +uniform float ambiance_scale; -VARYING vec3 vary_dir; - +in vec3 vary_dir; // Code below is derived from the Khronos GLTF Sample viewer: // https://github.com/KhronosGroup/glTF-Sample-Viewer/blob/master/source/shaders/ibl_filtering.frag @@ -48,7 +43,7 @@ VARYING vec3 vary_dir; #define MATH_PI 3.1415926535897932384626433832795 float u_roughness = 1.0; -int u_sampleCount = 64; +int u_sampleCount = 32; float u_lodBias = 2.0; int u_width = 64; @@ -183,8 +178,7 @@ vec4 filterColor(vec3 N) { //return textureLod(uCubeMap, N, 3.0).rgb; vec4 color = vec4(0.f); - float weight = 0.0f; - + for(int i = 0; i < u_sampleCount; ++i) { vec4 importanceSample = getImportanceSample(i, N, 1.0); @@ -198,24 +192,17 @@ vec4 filterColor(vec3 N) // apply the bias to the lod lod += u_lodBias; - lod = clamp(lod, 0, max_probe_lod); + lod = clamp(lod, 0, 7); // sample lambertian at a lower resolution to avoid fireflies vec4 lambertian = textureLod(reflectionProbes, vec4(H, sourceIdx), lod); color += lambertian; } - if(weight != 0.0f) - { - color /= weight; - } - else - { - color /= float(u_sampleCount); - } + color /= float(u_sampleCount); + + color.rgb *= ambiance_scale; - color = min(color*1.9, vec4(1)); - color = pow(color, vec4(0.5)); return color; } -- cgit v1.2.3 From 830cb6b66551025285120fb628f0b5ebf3841756 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 3 Feb 2023 17:18:39 -0600 Subject: SL-19148 Decruft some forward shaders and drawpools. Fix HUDs being in wrong color space. --- indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl | 3 +++ .../app_settings/shaders/class2/windlight/atmosphericsF.glsl | 6 ------ .../app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl | 1 - .../shaders/class2/windlight/atmosphericsHelpersF.glsl | 2 -- .../shaders/class2/windlight/atmosphericsHelpersV.glsl | 2 -- indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl | 9 --------- .../app_settings/shaders/class2/windlight/transportF.glsl | 2 -- 7 files changed, 3 insertions(+), 22 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl index 7435f1c0e1..e2694e060e 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl @@ -300,6 +300,9 @@ void main() #endif // #else // FOR_IMPOSTOR +#ifdef IS_HUD + color.rgb = linear_to_srgb(color.rgb); +#endif frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 1463d507bc..6668a00841 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -27,17 +27,11 @@ vec3 getAdditiveColor(); vec3 getAtmosAttenuation(); vec3 scaleSoftClipFrag(vec3 light); -uniform int no_atmo; - vec3 srgb_to_linear(vec3 col); vec3 linear_to_srgb(vec3 col); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) { - if (no_atmo == 1) - { - return light; - } light *= atten.r; light += additive; return light * 2.0; diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl index ba02070e45..f9f625ecdb 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl @@ -45,7 +45,6 @@ uniform float max_y; uniform vec3 glow; uniform float scene_light_strength; uniform mat3 ssao_effect_mat; -uniform int no_atmo; uniform float sun_moon_glow_factor; float getAmbientClamp() { return 1.0f; } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl index 5788871744..800d08047a 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl @@ -26,11 +26,9 @@ // Output variables uniform float scene_light_strength; -uniform int no_atmo; vec3 atmosFragAmbient(vec3 light, vec3 amblit) { - if (no_atmo == 1) return light; return amblit + light / 2.0; } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl index 9c42b84eca..257a76c663 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl @@ -33,11 +33,9 @@ vec3 getAtmosAttenuation(); vec3 getPositionEye(); uniform float scene_light_strength; -uniform int no_atmo; vec3 atmosAmbient() { - if (no_atmo == 1) return vec3(0.16); return getAmblitColor(); } diff --git a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl index a32a572461..9a9b179e6a 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl @@ -23,7 +23,6 @@ * $/LicenseInfo$ */ uniform float gamma; -uniform int no_atmo; vec3 getAtmosAttenuation(); vec3 getAdditiveColor(); @@ -33,10 +32,6 @@ vec3 linear_to_srgb(vec3 col); vec3 scaleSoftClipFragLinear(vec3 light) { // identical to non-linear version and that's probably close enough - if (no_atmo == 1) - { - return light; - } //soft clip effect: light = 1. - clamp(light, vec3(0.), vec3(1.)); light = 1. - pow(light, vec3(gamma)); // s/b inverted already CPU-side @@ -45,10 +40,6 @@ vec3 scaleSoftClipFragLinear(vec3 light) vec3 scaleSoftClipFrag(vec3 light) { - if (no_atmo == 1) - { - return light; - } //soft clip effect: light = 1. - clamp(light, vec3(0.), vec3(1.)); light = 1. - pow(light, vec3(gamma)); // s/b inverted already CPU-side diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index ecf0430a88..c509d865ba 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -30,8 +30,6 @@ vec3 getAdditiveColor(); vec3 getAtmosAttenuation(); -uniform int no_atmo; - vec3 srgb_to_linear(vec3 col); vec3 linear_to_srgb(vec3 col); -- cgit v1.2.3 From 1c2410b8af62254e96d60b2ae2e411d4756215e4 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 3 Feb 2023 19:45:31 -0600 Subject: SL-19148 Decruft followthrough -- decruft shader tree and some remaining forward rendering code. --- .../shaders/class2/avatar/eyeballV.glsl | 62 ----- .../shaders/class2/deferred/indirect.glsl | 32 --- .../shaders/class2/deferred/multiSpotLightF.glsl | 298 --------------------- .../shaders/class2/deferred/softenLightF.glsl | 159 ----------- .../shaders/class2/deferred/spotLightF.glsl | 292 -------------------- .../shaders/class2/environment/waterF.glsl | 170 ------------ .../class2/lighting/sumLightsSpecularV.glsl | 64 ----- .../shaders/class2/lighting/sumLightsV.glsl | 60 ----- 8 files changed, 1137 deletions(-) delete mode 100644 indra/newview/app_settings/shaders/class2/avatar/eyeballV.glsl delete mode 100644 indra/newview/app_settings/shaders/class2/deferred/indirect.glsl delete mode 100644 indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl delete mode 100644 indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl delete mode 100644 indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl delete mode 100644 indra/newview/app_settings/shaders/class2/environment/waterF.glsl delete mode 100644 indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl delete mode 100644 indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/avatar/eyeballV.glsl b/indra/newview/app_settings/shaders/class2/avatar/eyeballV.glsl deleted file mode 100644 index 563c5f562b..0000000000 --- a/indra/newview/app_settings/shaders/class2/avatar/eyeballV.glsl +++ /dev/null @@ -1,62 +0,0 @@ -/** - * @file eyeballV.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 mat3 normal_matrix; -uniform mat4 texture_matrix0; -uniform mat4 modelview_matrix; -uniform mat4 modelview_projection_matrix; - -ATTRIBUTE vec3 position; -ATTRIBUTE vec4 diffuse_color; -ATTRIBUTE vec3 normal; -ATTRIBUTE vec2 texcoord0; - -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; - - -vec4 calcLightingSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor); -void calcAtmospherics(vec3 inPositionEye); - -void main() -{ - //transform vertex - vec3 pos = (modelview_matrix * vec4(position.xyz, 1.0)).xyz; - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); - vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; - - vec3 norm = normalize(normal_matrix * normal); - - calcAtmospherics(pos.xyz); - - // vec4 specular = specularColor; - vec4 specular = vec4(1.0); - vec4 color = calcLightingSpecular(pos, norm, diffuse_color, specular); - - vertex_color = color; - - -} - diff --git a/indra/newview/app_settings/shaders/class2/deferred/indirect.glsl b/indra/newview/app_settings/shaders/class2/deferred/indirect.glsl deleted file mode 100644 index 67b98e0fb1..0000000000 --- a/indra/newview/app_settings/shaders/class2/deferred/indirect.glsl +++ /dev/null @@ -1,32 +0,0 @@ -/** - * @file class2/deferred/indirect.glsl - * - * $LicenseInfo:firstyear=2018&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$ - */ - -float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen); - -vec3 getIndirect(vec3 ambient, vec3 norm, vec4 pos, vec2 pos_screen) -{ - return ambient * calcAmbientOcclusion(pos, norm, pos_screen); -} - diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl deleted file mode 100644 index ba419e7a65..0000000000 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ /dev/null @@ -1,298 +0,0 @@ -/** - * @file multiSpotLightF.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$ - */ - -#extension GL_ARB_texture_rectangle : enable -#extension GL_ARB_shader_texture_lod : enable - -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -uniform sampler2D diffuseRect; -uniform sampler2D specularRect; -uniform sampler2D depthMap; -uniform sampler2D normalMap; -uniform samplerCube environmentMap; -uniform sampler2D lightMap; -uniform sampler2D noiseMap; -uniform sampler2D projectionMap; -uniform sampler2D lightFunc; - -uniform mat4 proj_mat; //screen space to light space -uniform float proj_near; //near clip for projection -uniform vec3 proj_p; //plane projection is emitting from (in screen space) -uniform vec3 proj_n; -uniform float proj_focus; //distance from plane to begin blurring -uniform float proj_lod; //(number of mips in proj map) -uniform float proj_range; //range between near clip and far clip plane of projection -uniform float proj_ambient_lod; -uniform float proj_ambiance; -uniform float near_clip; -uniform float far_clip; - -uniform vec3 proj_origin; //origin of projection to be used for angular attenuation -uniform float sun_wash; -uniform int proj_shadow_idx; -uniform float shadow_fade; - -uniform vec3 center; -uniform float size; -uniform vec3 color; -uniform float falloff; - -VARYING vec4 vary_fragcoord; -uniform vec2 screen_res; - -uniform mat4 inv_proj; - -vec3 srgb_to_linear(vec3 cs); -vec3 getNorm(vec2 pos_screen); - -vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); - vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); - - float det = min(lod/(proj_lod*0.5), 1.0); - - float d = min(dist.x, dist.y); - - d *= min(1, d * (proj_lod - lod)); - - float edge = 0.25*det; - - ret *= clamp(d/edge, 0.0, 1.0); - - return ret; -} - -vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); - - vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); - - float det = min(lod/(proj_lod*0.5), 1.0); - - float d = min(dist.x, dist.y); - - float edge = 0.25*det; - - ret *= clamp(d/edge, 0.0, 1.0); - - return ret; -} - -vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); - - vec2 dist = tc-vec2(0.5); - - float d = dot(dist,dist); - - ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); - - return ret; -} - -vec4 getPosition(vec2 pos_screen); - -void main() -{ - - vec3 col = vec3(0,0,0); - -#if defined(LOCAL_LIGHT_KILL) - discard; -#else - vec4 frag = vary_fragcoord; - frag.xyz /= frag.w; - frag.xyz = frag.xyz*0.5+0.5; - - vec3 pos = getPosition(frag.xy).xyz; - vec3 lv = center.xyz-pos.xyz; - float dist = length(lv); - - if (dist >= size) - { - discard; - } - dist /= size; - - float shadow = 1.0; - - if (proj_shadow_idx >= 0) - { - vec4 shd = texture2D(lightMap, frag.xy); - shadow = (proj_shadow_idx==0)?shd.b:shd.a; - shadow += shadow_fade; - shadow = clamp(shadow, 0.0, 1.0); - } - - vec3 norm = texture2D(normalMap, frag.xy).xyz; - - float envIntensity = norm.z; - - norm = getNorm(frag.xy); - - norm = normalize(norm); - float l_dist = -dot(lv, proj_n); - - vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); - if (proj_tc.z < 0.0) - { - discard; - } - - proj_tc.xyz /= proj_tc.w; - - float fa = falloff+1.0; - float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); - dist_atten *= dist_atten; - dist_atten *= 2.0; - if (dist_atten <= 0.0) - { - discard; - } - - lv = proj_origin-pos.xyz; - lv = normalize(lv); - float da = dot(norm, lv); - - vec3 diff_tex = texture2D(diffuseRect, frag.xy).rgb; - - vec4 spec = texture2D(specularRect, frag.xy); - - vec3 dlit = vec3(0, 0, 0); - - float noise = texture2D(noiseMap, frag.xy).b; - if (proj_tc.z > 0.0 && - proj_tc.x < 1.0 && - proj_tc.y < 1.0 && - proj_tc.x > 0.0 && - proj_tc.y > 0.0) - { - float amb_da = proj_ambiance; - float lit = 0.0; - - if (da > 0.0) - { - lit = da * dist_atten * noise; - - float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); - float lod = diff * proj_lod; - - vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); - - dlit = color.rgb * plcol.rgb * plcol.a; - - col = dlit*lit*diff_tex*shadow; - - // unshadowed for consistency between forward and deferred? - amb_da += (da*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; - } - - //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); - vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); - - // use unshadowed for consistency between forward and deferred? - amb_da += (da*da*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; - amb_da *= dist_atten * noise; - amb_da = min(amb_da, 1.0-lit); - - col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; - } - - - if (spec.a > 0.0) - { - vec3 npos = -normalize(pos); - dlit *= min(da*6.0, 1.0) * dist_atten; - - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(lv+npos); - float nh = dot(norm, h); - float nv = dot(norm, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 speccol = dlit*scol*spec.rgb*shadow; - speccol = clamp(speccol, vec3(0), vec3(1)); - col += speccol; - } - } - - if (envIntensity > 0.0) - { - vec3 ref = reflect(normalize(pos), norm); - - //project from point pos in direction ref to plane proj_p, proj_n - vec3 pdelta = proj_p-pos; - float ds = dot(ref, proj_n); - - if (ds < 0.0) - { - vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; - - vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); - - if (stc.z > 0.0) - { - stc /= stc.w; - - if (stc.x < 1.0 && - stc.y < 1.0 && - stc.x > 0.0 && - stc.y > 0.0) - { - col += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; - } - } - } - } -#endif - - //not sure why, but this line prevents MATBUG-194 - col = max(col, vec3(0.0)); - - //output linear - frag_color.rgb = col; - frag_color.a = 0.0; -} diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl deleted file mode 100644 index fab227f5a4..0000000000 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ /dev/null @@ -1,159 +0,0 @@ -/** - * @file class2/deferred/softenLightF.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$ - */ - -#extension GL_ARB_texture_rectangle : enable -#extension GL_ARB_shader_texture_lod : enable - -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -uniform sampler2D diffuseRect; -uniform sampler2D specularRect; -uniform sampler2D normalMap; -uniform sampler2D lightMap; -uniform sampler2D depthMap; -uniform samplerCube environmentMap; -uniform sampler2D lightFunc; - -uniform float blur_size; -uniform float blur_fidelity; - -// Inputs -uniform mat3 env_mat; - -uniform vec3 sun_dir; -uniform vec3 moon_dir; -uniform int sun_up_factor; -VARYING vec2 vary_fragcoord; - -uniform mat4 inv_proj; -uniform vec2 screen_res; - -vec3 getNorm(vec2 pos_screen); -vec4 getPositionWithDepth(vec2 pos_screen, float depth); -float getDepth(vec2 pos_screen); - -void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); -float getAmbientClamp(); -vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); -vec3 scaleSoftClipFrag(vec3 l); -vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); -vec3 fullbrightScaleSoftClip(vec3 light); - -vec3 linear_to_srgb(vec3 c); -vec3 srgb_to_linear(vec3 c); - -#ifdef WATER_FOG -vec4 applyWaterFogView(vec3 pos, vec4 color); -#endif - -void main() -{ - vec2 tc = vary_fragcoord.xy; - float depth = getDepth(tc.xy); - vec4 pos = getPositionWithDepth(tc, depth); - vec4 norm = texture2D(normalMap, tc); - float envIntensity = norm.z; - norm.xyz = getNorm(tc); - - vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); - float light_gamma = 1.0 / 1.3; - da = pow(da, light_gamma); - - vec4 diffuse = texture2D(diffuseRect, tc); - diffuse.rgb = linear_to_srgb(diffuse.rgb); // SL-14035 - vec4 spec = texture2D(specularRect, vary_fragcoord.xy); - - vec2 scol_ambocc = texture2D(lightMap, vary_fragcoord.xy).rg; - scol_ambocc = pow(scol_ambocc, vec2(light_gamma)); - float scol = max(scol_ambocc.r, diffuse.a); - float ambocc = scol_ambocc.g; - - vec3 color = vec3(0); - float bloom = 0.0; - - vec3 sunlit; - vec3 amblit; - vec3 additive; - vec3 atten; - calcAtmosphericVars(pos.xyz, light_dir, ambocc, sunlit, amblit, additive, atten, true); - - color.rgb = amblit; - - float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0 - ambient); - color.rgb *= ambient; - - vec3 sun_contrib = min(da, scol) * sunlit; - color.rgb += sun_contrib; - color.rgb *= diffuse.rgb; - - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - - if (spec.a > 0.0) // specular reflection - { - float sa = dot(refnormpersp, light_dir.xyz); - vec3 dumbshiny = sunlit * scol * (texture2D(lightFunc, vec2(sa, spec.a)).r); - - // add the two types of shiny together - vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 6; - color.rgb += spec_contrib; - } - - color.rgb = mix(color.rgb, diffuse.rgb, diffuse.a); - - if (envIntensity > 0.0) - { // add environmentmap - vec3 env_vec = env_mat * refnormpersp; - vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; - color = mix(color.rgb, reflected_color, envIntensity); - } - - if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_ATMOS)) - { - color = mix(atmosFragLighting(color, additive, atten), fullbrightAtmosTransportFrag(color, additive, atten), diffuse.a); - color = mix(scaleSoftClipFrag(color), fullbrightScaleSoftClip(color), diffuse.a); - } - -#ifdef WATER_FOG - vec4 fogged = applyWaterFogView(pos.xyz, vec4(color, bloom)); - color = fogged.rgb; - bloom = fogged.a; -#endif - - // convert to linear as fullscreen lights need to sum in linear colorspace - // and will be gamma (re)corrected downstream... - frag_color.rgb = pos.xyz;// srgb_to_linear(color.rgb); - frag_color.a = bloom; -} diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl deleted file mode 100644 index e6a627fbf7..0000000000 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ /dev/null @@ -1,292 +0,0 @@ -/** - * @file spotLightF.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$ - */ - -#extension GL_ARB_texture_rectangle : enable -#extension GL_ARB_shader_texture_lod : enable - -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -uniform sampler2D diffuseRect; -uniform sampler2D specularRect; -uniform sampler2D depthMap; -uniform sampler2D normalMap; -uniform samplerCube environmentMap; -uniform sampler2D lightMap; -uniform sampler2D noiseMap; -uniform sampler2D projectionMap; -uniform sampler2D lightFunc; - -uniform mat4 proj_mat; //screen space to light space -uniform float proj_near; //near clip for projection -uniform vec3 proj_p; //plane projection is emitting from (in screen space) -uniform vec3 proj_n; -uniform float proj_focus; //distance from plane to begin blurring -uniform float proj_lod; //(number of mips in proj map) -uniform float proj_range; //range between near clip and far clip plane of projection -uniform float proj_ambient_lod; -uniform float proj_ambiance; -uniform float near_clip; -uniform float far_clip; - -uniform vec3 proj_origin; //origin of projection to be used for angular attenuation -uniform float sun_wash; -uniform int proj_shadow_idx; -uniform float shadow_fade; - -uniform float size; -uniform vec3 color; -uniform float falloff; - -VARYING vec3 trans_center; -VARYING vec4 vary_fragcoord; -uniform vec2 screen_res; - -uniform mat4 inv_proj; - -vec3 getNorm(vec2 pos_screen); -vec3 srgb_to_linear(vec3 c); - -vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); - - vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); - - float det = min(lod/(proj_lod*0.5), 1.0); - - float d = min(dist.x, dist.y); - - d *= min(1, d * (proj_lod - lod)); - - float edge = 0.25*det; - - ret *= clamp(d/edge, 0.0, 1.0); - - return ret; -} - -vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); - - vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); - - float det = min(lod/(proj_lod*0.5), 1.0); - - float d = min(dist.x, dist.y); - - float edge = 0.25*det; - - ret *= clamp(d/edge, 0.0, 1.0); - - return ret; -} - -vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); - - vec2 dist = tc-vec2(0.5); - - float d = dot(dist,dist); - - ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); - - return ret; -} - -vec4 getPosition(vec2 pos_screen); - -void main() -{ - vec3 col = vec3(0,0,0); - -#if defined(LOCAL_LIGHT_KILL) - discard; -#else - vec4 frag = vary_fragcoord; - frag.xyz /= frag.w; - frag.xyz = frag.xyz*0.5+0.5; - - vec3 pos = getPosition(frag.xy).xyz; - vec3 lv = trans_center.xyz-pos.xyz; - float dist = length(lv); - - if (dist >= size) - { - discard; - } - dist /= size; - - float shadow = 1.0; - - if (proj_shadow_idx >= 0) - { - vec4 shd = texture2D(lightMap, frag.xy); - shadow = (proj_shadow_idx == 0) ? shd.b : shd.a; - shadow += shadow_fade; - shadow = clamp(shadow, 0.0, 1.0); - } - - vec3 norm = texture2D(normalMap, frag.xy).xyz; - float envIntensity = norm.z; - norm = getNorm(frag.xy); - - norm = normalize(norm); - float l_dist = -dot(lv, proj_n); - - vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); - if (proj_tc.z < 0.0) - { - discard; - } - - proj_tc.xyz /= proj_tc.w; - - float fa = falloff+1.0; - float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); - dist_atten *= dist_atten; - dist_atten *= 2.0; - - if (dist_atten <= 0.0) - { - discard; - } - - lv = proj_origin-pos.xyz; - lv = normalize(lv); - float da = dot(norm, lv); - - vec3 diff_tex = texture2D(diffuseRect, frag.xy).rgb; - vec4 spec = texture2D(specularRect, frag.xy); - vec3 dlit = vec3(0, 0, 0); - - float noise = texture2D(noiseMap, frag.xy).b; - if (proj_tc.z > 0.0 && - proj_tc.x < 1.0 && - proj_tc.y < 1.0 && - proj_tc.x > 0.0 && - proj_tc.y > 0.0) - { - float amb_da = proj_ambiance; - float lit = 0.0; - - if (da > 0.0) - { - lit = da * dist_atten * noise; - - float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); - float lod = diff * proj_lod; - - vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); - - dlit = color.rgb * plcol.rgb * plcol.a; - - col = dlit*lit*diff_tex*shadow; - - amb_da += (da*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; - } - - //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); - vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); - - amb_da += (da*da*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; - amb_da *= dist_atten * noise; - amb_da = min(amb_da, 1.0-lit); - - col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; - } - - if (spec.a > 0.0) - { - dlit *= min(da*6.0, 1.0) * dist_atten; - vec3 npos = -normalize(pos); - - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(lv+npos); - float nh = dot(norm, h); - float nv = dot(norm, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 speccol = dlit*scol*spec.rgb*shadow; - speccol = clamp(speccol, vec3(0), vec3(1)); - col += speccol; - } - } - - if (envIntensity > 0.0) - { - vec3 ref = reflect(normalize(pos), norm); - - //project from point pos in direction ref to plane proj_p, proj_n - vec3 pdelta = proj_p-pos; - float ds = dot(ref, proj_n); - - if (ds < 0.0) - { - vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; - - vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); - - if (stc.z > 0.0) - { - stc /= stc.w; - - if (stc.x < 1.0 && - stc.y < 1.0 && - stc.x > 0.0 && - stc.y > 0.0) - { - col += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; - } - } - } - } -#endif - - //not sure why, but this line prevents MATBUG-194 - col = max(col, vec3(0.0)); - - //output linear colors as gamma correction happens down stream - frag_color.rgb = col; - frag_color.a = 0.0; -} diff --git a/indra/newview/app_settings/shaders/class2/environment/waterF.glsl b/indra/newview/app_settings/shaders/class2/environment/waterF.glsl deleted file mode 100644 index d485379a56..0000000000 --- a/indra/newview/app_settings/shaders/class2/environment/waterF.glsl +++ /dev/null @@ -1,170 +0,0 @@ -/** - * @file waterF.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$ - */ - -//class2/environment/waterF.glsl - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -vec3 scaleSoftClip(vec3 inColor); -vec3 atmosTransport(vec3 inColor); - -uniform sampler2D bumpMap; -uniform sampler2D bumpMap2; -uniform float blend_factor; -uniform sampler2D screenTex; -uniform sampler2D refTex; - -uniform float sunAngle; -uniform float sunAngle2; -uniform vec3 lightDir; -uniform vec3 specular; -uniform float lightExp; -uniform float refScale; -uniform float kd; -uniform vec2 screenRes; -uniform vec3 normScale; -uniform float fresnelScale; -uniform float fresnelOffset; -uniform float blurMultiplier; - - -//bigWave is (refCoord.w, view.w); -VARYING vec4 refCoord; -VARYING vec4 littleWave; -VARYING vec4 view; - -vec3 BlendNormal(vec3 bump1, vec3 bump2) -{ - vec3 n = mix(bump1, bump2, blend_factor); - return n; -} - - -void main() -{ - vec4 color; - - float dist = length(view.xy); - - //normalize view vector - vec3 viewVec = normalize(view.xyz); - - //get wave normals - vec2 bigwave = vec2(refCoord.w, view.w); - vec3 wave1_a = texture2D(bumpMap, bigwave ).xyz*2.0-1.0; - vec3 wave2_a = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; - vec3 wave3_a = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; - - - vec3 wave1_b = texture2D(bumpMap2, bigwave ).xyz*2.0-1.0; - vec3 wave2_b = texture2D(bumpMap2, littleWave.xy).xyz*2.0-1.0; - vec3 wave3_b = texture2D(bumpMap2, littleWave.zw).xyz*2.0-1.0; - - vec3 wave1 = BlendNormal(wave1_a, wave1_b); - vec3 wave2 = BlendNormal(wave2_a, wave2_b); - vec3 wave3 = BlendNormal(wave3_a, wave3_b); - - - //get base fresnel components - - vec3 df = vec3( - dot(viewVec, wave1), - dot(viewVec, (wave2 + wave3) * 0.5), - dot(viewVec, wave3) - ) * fresnelScale + fresnelOffset; - df *= df; - - vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; - - float dist2 = dist; - dist = max(dist, 5.0); - - float dmod = sqrt(dist); - - vec2 dmod_scale = vec2(dmod*dmod, dmod); - - //get reflected color - vec2 refdistort1 = wave1.xy*normScale.x; - vec2 refvec1 = distort+refdistort1/dmod_scale; - vec4 refcol1 = texture2D(refTex, refvec1); - - vec2 refdistort2 = wave2.xy*normScale.y; - vec2 refvec2 = distort+refdistort2/dmod_scale; - vec4 refcol2 = texture2D(refTex, refvec2); - - vec2 refdistort3 = wave3.xy*normScale.z; - vec2 refvec3 = distort+refdistort3/dmod_scale; - vec4 refcol3 = texture2D(refTex, refvec3); - - vec4 refcol = refcol1 + refcol2 + refcol3; - float df1 = df.x + df.y + df.z; - refcol *= df1 * 0.333; - - vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; - - wavef.z *= max(-viewVec.z, 0.1); - wavef = normalize(wavef); - - float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset; - - vec2 refdistort4 = wavef.xy*0.125; - refdistort4.y -= abs(refdistort4.y); - vec2 refvec4 = distort+refdistort4/dmod; - float dweight = min(dist2*blurMultiplier, 1.0); - vec4 baseCol = texture2D(refTex, refvec4); - refcol = mix(baseCol*df2, refcol, dweight); - - //get specular component - float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); - - //harden specular - spec = pow(spec, 128.0); - - //figure out distortion vector (ripply) - vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); - - vec4 fb = texture2D(screenTex, distort2); - - //mix with reflection - // Note we actually want to use just df1, but multiplying by 0.999999 gets around and nvidia compiler bug - color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999); - color.rgb += spec * specular; - - color.rgb = atmosTransport(color.rgb); - color.rgb = scaleSoftClip(color.rgb); - color.a = spec * sunAngle2; - - frag_color = color; - -#if defined(WATER_EDGE) - gl_FragDepth = 0.9999847f; -#endif - -} - diff --git a/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl b/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl deleted file mode 100644 index 89d9d1bde3..0000000000 --- a/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl +++ /dev/null @@ -1,64 +0,0 @@ -/** - * @file class2\lighting\sumLightsSpecularV.glsl - * - * $LicenseInfo:firstyear=2005&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2005, 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$ - */ - - - -float calcDirectionalLightSpecular(inout vec4 specular, vec3 view, vec3 n, vec3 l, vec3 lightCol, float da); -vec3 calcPointLightSpecular(inout vec4 specular, vec3 view, vec3 v, vec3 n, vec3 l, float r, float pw, vec3 lightCol); - -vec3 atmosAmbient(); -vec3 atmosAffectDirectionalLight(float lightIntensity); -vec3 atmosGetDiffuseSunlightColor(); -vec3 scaleDownLight(vec3 light); - -uniform vec4 light_position[8]; -uniform vec4 light_attenuation[8]; -uniform vec3 light_diffuse[8]; - -vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor) -{ - vec4 col = vec4(0.0, 0.0, 0.0, color.a); - - vec3 view = normalize(pos); - - /// collect all the specular values from each calcXXXLightSpecular() function - vec4 specularSum = vec4(0.0); - - // Collect normal lights (need to be divided by two, as we later multiply by 2) - col.rgb += light_diffuse[1].rgb * calcDirectionalLightSpecular(specularColor, view, norm, light_position[1].xyz,light_diffuse[1].rgb, 1.0); - col.rgb += calcPointLightSpecular(specularSum, view, pos, norm, light_position[2].xyz, light_attenuation[2].x, light_attenuation[2].y, light_diffuse[2].rgb); - col.rgb += calcPointLightSpecular(specularSum, view, pos, norm, light_position[3].xyz, light_attenuation[3].x, light_attenuation[3].y, light_diffuse[3].rgb); - col.rgb = scaleDownLight(col.rgb); - - // Add windlight lights - col.rgb += atmosAmbient(); - col.rgb += atmosAffectDirectionalLight(calcDirectionalLightSpecular(specularSum, view, norm, light_position[0].xyz, atmosGetDiffuseSunlightColor(), 1.0)); - - col.rgb = min(col.rgb*color.rgb, 1.0); - specularColor.rgb = min(specularColor.rgb*specularSum.rgb, 1.0); - col.rgb += specularColor.rgb; - - return col; -} diff --git a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl deleted file mode 100644 index 30ca88afd2..0000000000 --- a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @file class2\lighting\sumLightsV.glsl - * - * $LicenseInfo:firstyear=2005&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2005, 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$ - */ - -float calcDirectionalLight(vec3 n, vec3 l); -float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight); - -vec3 atmosAffectDirectionalLight(float lightIntensity); -vec3 scaleDownLight(vec3 light); - -uniform vec4 light_position[8]; -uniform vec3 light_direction[8]; -uniform vec3 light_attenuation[8]; -uniform vec3 light_diffuse[8]; - -vec4 sumLights(vec3 pos, vec3 norm, vec4 color) -{ - vec4 col = vec4(0.0, 0.0, 0.0, color.a); - - // Collect normal lights (need to be divided by two, as we later multiply by 2) - col.rgb += light_diffuse[1].rgb * calcDirectionalLight(norm, light_position[1].xyz); - col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].y, light_attenuation[2].z); - col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].y, light_attenuation[3].z); - col.rgb = scaleDownLight(col.rgb); - -#if defined(LOCAL_LIGHT_KILL) - col.rgb = vec3(0); -i#endif - - // Add windlight lights - col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); - -#if !defined(SUNLIGHT_KILL) - col.rgb = min(col.rgb*color.rgb, 1.0); -#endif - - return col; -} - -- cgit v1.2.3 From 4ea51c6ce4b29c0b3875e32f0daf86390cec8950 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 3 Feb 2023 19:53:43 -0600 Subject: SL-19148 Decruft followthrough -- kill more unused shader files --- .../shaders/class2/deferred/waterF.glsl | 192 -------------------- .../shaders/class2/windlight/cloudsF.glsl | 137 --------------- .../shaders/class2/windlight/cloudsV.glsl | 193 --------------------- .../shaders/class2/windlight/skyF.glsl | 55 ------ .../shaders/class2/windlight/skyV.glsl | 147 ---------------- 5 files changed, 724 deletions(-) delete mode 100644 indra/newview/app_settings/shaders/class2/deferred/waterF.glsl delete mode 100644 indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl delete mode 100644 indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl delete mode 100644 indra/newview/app_settings/shaders/class2/windlight/skyF.glsl delete mode 100644 indra/newview/app_settings/shaders/class2/windlight/skyV.glsl (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class2/deferred/waterF.glsl deleted file mode 100644 index 96739d91d7..0000000000 --- a/indra/newview/app_settings/shaders/class2/deferred/waterF.glsl +++ /dev/null @@ -1,192 +0,0 @@ -/** - * @file class1/deferred/waterF.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$ - */ - -#extension GL_ARB_texture_rectangle : enable - -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[4]; -#else -#define frag_data gl_FragData -#endif - -vec3 scaleSoftClip(vec3 inColor); -vec3 atmosTransport(vec3 inColor); - -uniform sampler2D bumpMap; -uniform sampler2D bumpMap2; -uniform float blend_factor; -uniform sampler2D screenTex; -uniform sampler2D refTex; -uniform float sunAngle; -uniform float sunAngle2; -uniform vec3 lightDir; -uniform vec3 specular; -uniform float lightExp; -uniform float refScale; -uniform float kd; -uniform vec2 screenRes; -uniform vec3 normScale; -uniform float fresnelScale; -uniform float fresnelOffset; -uniform float blurMultiplier; -uniform vec2 screen_res; -uniform mat4 norm_mat; //region space to screen space -uniform int water_edge; - -//bigWave is (refCoord.w, view.w); -VARYING vec4 refCoord; -VARYING vec4 littleWave; -VARYING vec4 view; -VARYING vec4 vary_position; - -vec2 encode_normal(vec3 n); -vec3 scaleSoftClip(vec3 l); -vec3 srgb_to_linear(vec3 c); -vec3 linear_to_srgb(vec3 c); - -vec3 BlendNormal(vec3 bump1, vec3 bump2) -{ - vec3 n = mix(bump1, bump2, blend_factor); - return n; -} - -void main() -{ - vec4 color; - float dist = length(view.xyz); - - //normalize view vector - vec3 viewVec = normalize(view.xyz); - - //get wave normals - vec3 wave1_a = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; - vec3 wave2_a = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; - vec3 wave3_a = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; - - - vec3 wave1_b = texture2D(bumpMap2, vec2(refCoord.w, view.w)).xyz*2.0-1.0; - vec3 wave2_b = texture2D(bumpMap2, littleWave.xy).xyz*2.0-1.0; - vec3 wave3_b = texture2D(bumpMap2, littleWave.zw).xyz*2.0-1.0; - - vec3 wave1 = BlendNormal(wave1_a, wave1_b); - vec3 wave2 = BlendNormal(wave2_a, wave2_b); - vec3 wave3 = BlendNormal(wave3_a, wave3_b); - - //get base fresnel components - - vec3 df = vec3( - dot(viewVec, wave1), - dot(viewVec, (wave2 + wave3) * 0.5), - dot(viewVec, wave3) - ) * fresnelScale + fresnelOffset; - df *= df; - - vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; - - float dist2 = dist; - dist = max(dist, 5.0); - - float dmod = sqrt(dist); - - vec2 dmod_scale = vec2(dmod*dmod, dmod); - - //get reflected color - vec2 refdistort1 = wave1.xy*normScale.x; - vec2 refvec1 = distort+refdistort1/dmod_scale; - vec4 refcol1 = texture2D(refTex, refvec1); - - vec2 refdistort2 = wave2.xy*normScale.y; - vec2 refvec2 = distort+refdistort2/dmod_scale; - vec4 refcol2 = texture2D(refTex, refvec2); - - vec2 refdistort3 = wave3.xy*normScale.z; - vec2 refvec3 = distort+refdistort3/dmod_scale; - vec4 refcol3 = texture2D(refTex, refvec3); - - vec4 refcol = refcol1 + refcol2 + refcol3; - float df1 = df.x + df.y + df.z; - refcol *= df1 * 0.333; - - vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; - wavef.z *= max(-viewVec.z, 0.1); - wavef = normalize(wavef); - - float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset; - - vec2 refdistort4 = wavef.xy*0.125; - refdistort4.y -= abs(refdistort4.y); - vec2 refvec4 = distort+refdistort4/dmod; - float dweight = min(dist2*blurMultiplier, 1.0); - vec4 baseCol = texture2D(refTex, refvec4); - - refcol = mix(baseCol*df2, refcol, dweight); - - //get specular component - float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); - - //harden specular - spec = pow(spec, 128.0); - - //figure out distortion vector (ripply) - vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); - - vec4 fb = texture2D(screenTex, distort2); - - //mix with reflection - // Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug - color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999f); - - vec4 pos = vary_position; - - //color.rgb += spec * specular; - - //color.rgb = atmosTransport(color.rgb); - //color.rgb = scaleSoftClip(color.rgb); - - //color.rgb = refcol.rgb; - color.rgb = vec3(0.0); - color.a = spec * sunAngle2; - - vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); - - //frag_data[0] = color; - - // TODO: The non-obvious assignment below is copied from the pre-EEP WL shader code - // Unfortunately, fixing it causes a mismatch for EEP, and so it remains... for now - // SL-12975 (unfix pre-EEP broken alpha) - frag_data[0] = vec4(srgb_to_linear(color.rgb), 0.0); - - frag_data[1] = vec4(1.0, 0.1, 0.0, 0.0); // occlusion, roughness, metalness - frag_data[2] = vec4(encode_normal(screenspacewavef.xyz), 0.0, GBUFFER_FLAG_HAS_PBR);// normalxy, env intens, flags (atmo kill) - //frag_data[3] = vec4(srgb_to_linear(refcol.rgb),0); - frag_data[3] = vec4(0, 0, 0, 0); - - - //frag_data[0] = vec4(0.0,0,0,0); - //frag_data[1] = vec4(0, 1.0, 0.0, 0.0); - //frag_data[3] = vec4(0); -} diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl deleted file mode 100644 index 6f4bdbde28..0000000000 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl +++ /dev/null @@ -1,137 +0,0 @@ -/** - * @file class2\wl\cloudsF.glsl - * - * $LicenseInfo:firstyear=2005&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2005, 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$ - */ - -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -///////////////////////////////////////////////////////////////////////// -// The fragment shader for the sky -///////////////////////////////////////////////////////////////////////// - -VARYING vec3 vary_CloudColorSun; -VARYING vec3 vary_CloudColorAmbient; -VARYING float vary_CloudDensity; - -uniform sampler2D cloud_noise_texture; -uniform sampler2D cloud_noise_texture_next; -uniform float blend_factor; -uniform vec3 cloud_pos_density1; -uniform vec3 cloud_pos_density2; -uniform float cloud_scale; -uniform float cloud_variance; - -VARYING vec2 vary_texcoord0; -VARYING vec2 vary_texcoord1; -VARYING vec2 vary_texcoord2; -VARYING vec2 vary_texcoord3; -VARYING float altitude_blend_factor; - -/// Soft clips the light with a gamma correction -vec3 scaleSoftClip(vec3 light); - -vec4 cloudNoise(vec2 uv) -{ - vec4 a = texture2D(cloud_noise_texture, uv); - vec4 b = texture2D(cloud_noise_texture_next, uv); - vec4 cloud_noise_sample = mix(a, b, blend_factor); - return cloud_noise_sample; -} - -void main() -{ - // Set variables - vec2 uv1 = vary_texcoord0.xy; - vec2 uv2 = vary_texcoord1.xy; - - vec3 cloudColorSun = vary_CloudColorSun; - vec3 cloudColorAmbient = vary_CloudColorAmbient; - float cloudDensity = vary_CloudDensity; - vec2 uv3 = vary_texcoord2.xy; - vec2 uv4 = vary_texcoord3.xy; - - if (cloud_scale < 0.001) - { - discard; - } - - vec2 disturbance = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); - vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); - - // Offset texture coords - uv1 += cloud_pos_density1.xy + (disturbance * 0.2); //large texture, visible density - uv2 += cloud_pos_density1.xy; //large texture, self shadow - uv3 += cloud_pos_density2.xy; //small texture, visible density - uv4 += cloud_pos_density2.xy; //small texture, self shadow - - float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y) * 4.0); - - cloudDensity *= 1.0 - (density_variance * density_variance); - - // Compute alpha1, the main cloud opacity - - float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; - alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); - - // And smooth - alpha1 = 1. - alpha1 * alpha1; - alpha1 = 1. - alpha1 * alpha1; - - alpha1 *= altitude_blend_factor; - - //if (alpha1 < 0.001f) - //{ - // discard; - //} - - // Compute alpha2, for self shadowing effect - // (1 - alpha2) will later be used as percentage of incoming sunlight - float alpha2 = (cloudNoise(uv2).x - 0.5); - alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); - - // And smooth - alpha2 = 1. - alpha2; - alpha2 = 1. - alpha2 * alpha2; - - // Combine - vec3 color; - color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); - color.rgb *= 2.; - color.rgb = scaleSoftClip(color.rgb); - - /// Gamma correct for WL (soft clip effect). - frag_color = vec4(color.rgb, alpha1); - - // SL-14113 Moon Haze -- When the camera is underwater fix clouds clipping into moon - // camera above water: class1\deferred\cloudsF.glsl - // camera below water: class2\windlight\coudsV.glsl - // See: starsV.glsl, cloudsV.glsl, moonF.glsl - gl_FragDepth = LL_SHADER_CONST_CLOUD_MOON_DEPTH; -} - diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl deleted file mode 100644 index 650009d393..0000000000 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl +++ /dev/null @@ -1,193 +0,0 @@ -/** - * @file class2\wl\cloudsV.glsl - * - * $LicenseInfo:firstyear=2005&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2005, 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 mat4 modelview_projection_matrix; - -ATTRIBUTE vec3 position; -ATTRIBUTE vec2 texcoord0; - -////////////////////////////////////////////////////////////////////////// -// The vertex shader for creating the atmospheric sky -/////////////////////////////////////////////////////////////////////////////// - -// Output parameters -VARYING vec3 vary_CloudColorSun; -VARYING vec3 vary_CloudColorAmbient; -VARYING float vary_CloudDensity; - -VARYING vec2 vary_texcoord0; -VARYING vec2 vary_texcoord1; -VARYING vec2 vary_texcoord2; -VARYING vec2 vary_texcoord3; -VARYING float altitude_blend_factor; - -// Inputs -uniform vec3 camPosLocal; - -uniform vec3 lightnorm; -uniform vec3 sunlight_color; -uniform vec3 moonlight_color; -uniform int sun_up_factor; -uniform vec3 ambient_color; -uniform vec3 blue_horizon; -uniform vec3 blue_density; -uniform float haze_horizon; -uniform float haze_density; - -uniform float cloud_shadow; -uniform float density_multiplier; -uniform float max_y; - -uniform vec3 glow; -uniform float sun_moon_glow_factor; - -uniform vec3 cloud_color; - -uniform float cloud_scale; - -// NOTE: Keep these in sync! -// indra\newview\app_settings\shaders\class1\deferred\skyV.glsl -// indra\newview\app_settings\shaders\class1\deferred\cloudsV.glsl -// indra\newview\app-settings\shaders\class2\windlight\cloudsV.glsl -// indra\newview\lllegacyatmospherics.cpp -// indra\newview\llsettingsvo.cpp -void main() -{ - // World / view / projection - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); - - // Texture coords - // SL-13084 EEP added support for custom cloud textures -- flip them horizontally to match the preview of Clouds > Cloud Scroll - vary_texcoord0 = vec2(-texcoord0.x, texcoord0.y); // See: LLSettingsVOSky::applySpecial - - vary_texcoord0.xy -= 0.5; - vary_texcoord0.xy /= cloud_scale; - vary_texcoord0.xy += 0.5; - - vary_texcoord1 = vary_texcoord0; - vary_texcoord1.x += lightnorm.x * 0.0125; - vary_texcoord1.y += lightnorm.z * 0.0125; - - vary_texcoord2 = vary_texcoord0 * 16.; - vary_texcoord3 = vary_texcoord1 * 16.; - - // Get relative position - vec3 rel_pos = position.xyz - camPosLocal.xyz + vec3(0, 50, 0); - - // fade clouds beyond a certain point so the bottom of the sky dome doesn't look silly at high altitude - altitude_blend_factor = clamp((rel_pos.y + 512.0) / max_y, 0.0, 1.0); - - // Adj position vector to clamp altitude - if (rel_pos.y > 0.) - { - rel_pos *= (max_y / rel_pos.y); - } - if (rel_pos.y < 0.) - { - rel_pos *= (-32000. / rel_pos.y); - } - - // Can normalize then - vec3 rel_pos_norm = normalize(rel_pos); - float rel_pos_len = length(rel_pos); - - // Initialize temp variables - vec3 sunlight = sunlight_color; - vec3 light_atten; - - // Sunlight attenuation effect (hue and brightness) due to atmosphere - // this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec3(haze_density * 0.25)) * (density_multiplier * max_y); - - // Calculate relative weights - vec3 combined_haze = abs(blue_density) + vec3(abs(haze_density)); - vec3 blue_weight = blue_density / combined_haze; - vec3 haze_weight = haze_density / combined_haze; - - // Compute sunlight from rel_pos & lightnorm (for long rays like sky) - float off_axis = 1.0 / max(1e-6, max(0., rel_pos_norm.y) + lightnorm.y); - sunlight *= exp(-light_atten * off_axis); - - // Distance - float density_dist = rel_pos_len * density_multiplier; - - // Transparency (-> combined_haze) - // ATI Bugfix -- can't store combined_haze*density_dist in a variable because the ati - // compiler gets confused. - combined_haze = exp(-combined_haze * density_dist); - - // Compute haze glow - float haze_glow = 1.0 - dot(rel_pos_norm, lightnorm.xyz); - // haze_glow is 0 at the sun and increases away from sun - haze_glow = max(haze_glow, .001); - // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - haze_glow *= glow.x; - // Higher glow.x gives dimmer glow (because next step is 1 / "angle") - haze_glow = pow(haze_glow, glow.z); - // glow.z should be negative, so we're doing a sort of (1 / "angle") function - - haze_glow *= sun_moon_glow_factor; - - // Add "minimum anti-solar illumination" - // For sun, add to glow. For moon, remove glow entirely. SL-13768 - haze_glow = (sun_moon_glow_factor < 1.0) ? 0.0 : (haze_glow + 0.25); - - // Increase ambient when there are more clouds - vec3 tmpAmbient = ambient_color; - tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; - - // Dim sunlight by cloud shadow percentage - sunlight *= (1. - cloud_shadow); - - // Haze color below cloud - vec3 additiveColorBelowCloud = - (blue_horizon * blue_weight * (sunlight + tmpAmbient) + (haze_horizon * haze_weight) * (sunlight * haze_glow + tmpAmbient)); - - // CLOUDS - sunlight = sunlight_color; // SL-14707 reset color -- Clouds are unusually dim in EEP - off_axis = 1.0 / max(1e-6, lightnorm.y * 2.); - sunlight *= exp(-light_atten * off_axis); - - // Cloud color out - vary_CloudColorSun = (sunlight * haze_glow) * cloud_color; - vary_CloudColorAmbient = tmpAmbient * cloud_color; - - // Attenuate cloud color by atmosphere - combined_haze = sqrt(combined_haze); // less atmos opacity (more transparency) below clouds - vary_CloudColorSun *= combined_haze; - vary_CloudColorAmbient *= combined_haze; - vec3 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - combined_haze); - - // Make a nice cloud density based on the cloud_shadow value that was passed in. - vary_CloudDensity = 2. * (cloud_shadow - 0.25); - - // Combine these to minimize register use - vary_CloudColorAmbient += oHazeColorBelowCloud; - - // needs this to compile on mac - //vary_AtmosAttenuation = vec3(0.0,0.0,0.0); - - // END CLOUDS -} diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl deleted file mode 100644 index 7a229e0f5e..0000000000 --- a/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl +++ /dev/null @@ -1,55 +0,0 @@ -/** - * @file class2/windlight/skyF.glsl - * - * $LicenseInfo:firstyear=2005&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2005, 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$ - */ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -///////////////////////////////////////////////////////////////////////// -// The fragment shader for the sky -///////////////////////////////////////////////////////////////////////// - -VARYING vec3 vary_HazeColor; - -/// Soft clips the light with a gamma correction -vec3 scaleSoftClip(vec3 light); - -void main() -{ - // Potential Fill-rate optimization. Add cloud calculation - // back in and output alpha of 0 (so that alpha culling kills - // the fragment) if the sky wouldn't show up because the clouds - // are fully opaque. - - vec3 color; - color = vary_HazeColor; - color.rgb *= 2.; - /// Gamma correct for WL (soft clip effect). - frag_color.rgb = scaleSoftClip(color.rgb); - frag_color.a = 1.0; -} - diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl deleted file mode 100644 index 8f7726bb0b..0000000000 --- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl +++ /dev/null @@ -1,147 +0,0 @@ -/** - * @file class2\wl\skyV.glsl - * - * $LicenseInfo:firstyear=2005&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2005, 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 mat4 modelview_projection_matrix; - -ATTRIBUTE vec3 position; - -// SKY //////////////////////////////////////////////////////////////////////// -// The vertex shader for creating the atmospheric sky -/////////////////////////////////////////////////////////////////////////////// - -// Output parameters -VARYING vec3 vary_HazeColor; - -// Inputs -uniform vec3 camPosLocal; - -uniform vec3 lightnorm; -uniform vec3 sunlight_color; -uniform vec3 moonlight_color; -uniform int sun_up_factor; -uniform vec3 ambient_color; -uniform vec3 blue_horizon; -uniform vec3 blue_density; -uniform float haze_horizon; -uniform float haze_density; - -uniform float cloud_shadow; -uniform float density_multiplier; -uniform float distance_multiplier; -uniform float max_y; - -uniform vec3 glow; -uniform float sun_moon_glow_factor; - -void main() -{ - // World / view / projection - vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); - - gl_Position = pos; - - // Get relative position - vec3 rel_pos = position.xyz - camPosLocal.xyz + vec3(0, 50, 0); - - // Adj position vector to clamp altitude - if (rel_pos.y > 0.) - { - rel_pos *= (max_y / rel_pos.y); - } - if (rel_pos.y < 0.) - { - rel_pos *= (-32000. / rel_pos.y); - } - - // Can normalize then - vec3 rel_pos_norm = normalize(rel_pos); - - float rel_pos_len = length(rel_pos); - - // Initialize temp variables - vec3 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; - vec3 light_atten; - - // Sunlight attenuation effect (hue and brightness) due to atmosphere - // this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec3(haze_density * 0.25)) * (density_multiplier * max_y); - - // Calculate relative weights - vec3 combined_haze = abs(blue_density) + vec3(abs(haze_density)); - vec3 blue_weight = blue_density / combined_haze; - vec3 haze_weight = haze_density / combined_haze; - - // Compute sunlight from rel_pos & lightnorm (for long rays like sky) - float off_axis = 1.0 / max(1e-6, max(0., rel_pos_norm.y) + lightnorm.y); - sunlight *= exp(-light_atten * off_axis); - - // Distance - float density_dist = rel_pos_len * density_multiplier; - - // Transparency (-> combined_haze) - // ATI Bugfix -- can't store combined_haze*density_dist in a variable because the ati - // compiler gets confused. - combined_haze = exp(-combined_haze * density_dist); - - // Compute haze glow - float haze_glow = 1.0 - dot(rel_pos_norm, lightnorm.xyz); - // haze_glow is 0 at the sun and increases away from sun - haze_glow = max(haze_glow, .001); - // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - haze_glow *= glow.x; - // Higher glow.x gives dimmer glow (because next step is 1 / "angle") - haze_glow = pow(haze_glow, glow.z); - // glow.z should be negative, so we're doing a sort of (1 / "angle") function - - // Add "minimum anti-solar illumination" - // For sun, add to glow. For moon, remove glow entirely. SL-13768 - haze_glow = (sun_moon_glow_factor < 1.0) ? 0.0 : (haze_glow + 0.25); - - vec3 color = - (blue_horizon * blue_weight * (sunlight + ambient_color) + (haze_horizon * haze_weight) * (sunlight * haze_glow + ambient_color)); - - // Final atmosphere additive - color *= (1. - combined_haze); - - // Increase ambient when there are more clouds - vec3 tmpAmbient = ambient_color; - tmpAmbient += max(vec3(0), (1. - ambient_color)) * cloud_shadow * 0.5; - - // Dim sunlight by cloud shadow percentage - sunlight *= max(0.0, (1. - cloud_shadow)); - - // Haze color below cloud - vec3 additiveColorBelowCloud = - (blue_horizon * blue_weight * (sunlight + tmpAmbient) + (haze_horizon * haze_weight) * (sunlight * haze_glow + tmpAmbient)); - - // Attenuate cloud color by atmosphere - combined_haze = sqrt(combined_haze); // less atmos opacity (more transparency) below clouds - - // At horizon, blend high altitude sky color towards the darker color below the clouds - color += (additiveColorBelowCloud - color) * (1. - sqrt(combined_haze)); - - // Haze color above cloud - vary_HazeColor = color; -} -- cgit v1.2.3 From c8fb3ad4de0575a0538b9532e819319f655613d1 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 6 Feb 2023 10:28:26 -0600 Subject: SL-19148 Decruft followthrough -- fix for crash when running from installer. Feed fresnel component into PBR alpha. Remove obsolete "shader_hierarchy.txt", remove redundant LL_PROFILE_ZONE_SCOPED, remove unused shader feature flag. --- .../app_settings/shaders/class2/deferred/pbralphaF.glsl | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index ccf20942e3..35e22ef3a2 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -113,6 +113,8 @@ vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, vec3 v, // surface point to camera vec3 l); //surface point to light +vec2 BRDF(float NoV, float roughness); + vec3 calcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, float perceptualRoughness, float metallic, @@ -217,8 +219,12 @@ void main() calcDiffuseSpecular(col.rgb, metallic, diffuseColor, specularColor); vec3 v = -normalize(pos.xyz); + color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit, scol, radiance, irradiance, colorEmissive, ao, additive, atten); + float nv = clamp(abs(dot(norm.xyz, v)), 0.001, 1.0); + vec2 brdf = BRDF(clamp(nv, 0, 1), 1.0-perceptualRoughness); + vec3 light = vec3(0); // Punctual lights @@ -235,5 +241,11 @@ void main() color.rgb += light.rgb; - frag_color = vec4(color.rgb,basecolor.a * vertex_color.a); + float a = basecolor.a*vertex_color.a; + vec3 spec = radiance; // *specularColor; + float lum = max(max(spec.r, spec.g), spec.b); + + float f = brdf.y; + a += f; + frag_color = vec4(color.rgb,a); } -- cgit v1.2.3 From a2647e953aeee26ef99e62e0146adcd37c8afca1 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 7 Feb 2023 18:25:22 -0600 Subject: SL-18229 Fix for PBR materials on HUDs misbehaving. Incidental decruft. --- .../shaders/class2/deferred/pbralphaF.glsl | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index 35e22ef3a2..35ccc65a8e 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -25,6 +25,8 @@ /*[EXTRA_CODE_HERE]*/ +#ifndef IS_HUD + uniform sampler2D diffuseMap; //always in sRGB space uniform sampler2D bumpMap; uniform sampler2D emissiveMap; @@ -249,3 +251,59 @@ void main() a += f; frag_color = vec4(color.rgb,a); } + +#else + +uniform sampler2D diffuseMap; //always in sRGB space +uniform sampler2D emissiveMap; + +uniform vec3 emissiveColor; + +out vec4 frag_color; + +in vec3 vary_position; + +in vec2 basecolor_texcoord; +in vec2 emissive_texcoord; + +in vec4 vertex_color; + +#ifdef HAS_ALPHA_MASK +uniform float minimum_alpha; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlphaCutoff() +#endif + +vec3 srgb_to_linear(vec3 c); +vec3 linear_to_srgb(vec3 c); + + +void main() +{ + vec3 color = vec3(0,0,0); + + vec3 pos = vary_position; + + vec4 basecolor = texture(diffuseMap, basecolor_texcoord.xy).rgba; + basecolor.rgb = srgb_to_linear(basecolor.rgb); +#ifdef HAS_ALPHA_MASK + if (basecolor.a < minimum_alpha) + { + discard; + } +#endif + + color = vertex_color.rgb * basecolor.rgb; + + // emissiveColor is the emissive color factor from GLTF and is already in linear space + vec3 colorEmissive = emissiveColor; + // emissiveMap here is a vanilla RGB texture encoded as sRGB, manually convert to linear + colorEmissive *= srgb_to_linear(texture2D(emissiveMap, emissive_texcoord.xy).rgb); + + + float a = basecolor.a*vertex_color.a; + a = 1.0; + color += colorEmissive; + color = linear_to_srgb(color); + frag_color = vec4(color.rgb,a); +} + +#endif -- cgit v1.2.3 From 0336c1a06de89937d5c0f971e06270afc868ddfa Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 21 Feb 2023 22:13:08 -0600 Subject: DRTVWR-559 Fix SSR on transparent PBR surfaces. --- indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index 35ccc65a8e..a95feb8e2f 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -46,8 +46,9 @@ uniform vec3 moon_dir; out vec4 frag_color; +in vec3 vary_fragcoord; + #ifdef HAS_SUN_SHADOW - in vec3 vary_fragcoord; uniform vec2 screen_res; #endif @@ -191,8 +192,9 @@ void main() vec3 atten; calcAtmosphericVarsLinear(pos.xyz, norm, light_dir, sunlit, amblit, additive, atten); -#ifdef HAS_SUN_SHADOW vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; + +#ifdef HAS_SUN_SHADOW scol = sampleDirectionalShadow(pos.xyz, norm.xyz, frag); #endif @@ -211,7 +213,7 @@ void main() float gloss = 1.0 - perceptualRoughness; vec3 irradiance = vec3(0); vec3 radiance = vec3(0); - sampleReflectionProbes(irradiance, radiance, vec2(0), pos.xyz, norm.xyz, gloss); + sampleReflectionProbes(irradiance, radiance, vary_position.xy*0.5+0.5, 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); -- cgit v1.2.3 From e5e94b5fa832c62dc0df239fdb4aefc23e559c0c Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 23 Feb 2023 11:47:24 -0600 Subject: DRTVWR-559 Fix for irradiance maps going black at 128x128 radiance map resolution. Improve radiance map anti-aliasing and default to 128x128 everywhere. --- .../newview/app_settings/shaders/class2/interface/irradianceGenF.glsl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/interface/irradianceGenF.glsl b/indra/newview/app_settings/shaders/class2/interface/irradianceGenF.glsl index c7da23fb00..baf68e11f4 100644 --- a/indra/newview/app_settings/shaders/class2/interface/irradianceGenF.glsl +++ b/indra/newview/app_settings/shaders/class2/interface/irradianceGenF.glsl @@ -176,7 +176,6 @@ float computeLod(float pdf) vec4 filterColor(vec3 N) { - //return textureLod(uCubeMap, N, 3.0).rgb; vec4 color = vec4(0.f); for(int i = 0; i < u_sampleCount; ++i) @@ -192,7 +191,7 @@ vec4 filterColor(vec3 N) // apply the bias to the lod lod += u_lodBias; - lod = clamp(lod, 0, 7); + lod = clamp(lod, 0, max_probe_lod); // sample lambertian at a lower resolution to avoid fireflies vec4 lambertian = textureLod(reflectionProbes, vec4(H, sourceIdx), lod); -- cgit v1.2.3 From 6494eed242b1cf64160e379c6d40df333deae23a Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Thu, 23 Feb 2023 10:58:39 -0800 Subject: SL-19228: Fix GLTF texture transform rotation and add UV debug (PBR only). See textureUtilV.glsl for UV coordinate comments --- .../app_settings/shaders/class2/deferred/pbralphaF.glsl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index 35ccc65a8e..47d6c5e195 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -57,6 +57,9 @@ in vec2 basecolor_texcoord; in vec2 normal_texcoord; in vec2 metallic_roughness_texcoord; in vec2 emissive_texcoord; +#if DEBUG_TEXCOORD +in vec2 original_texcoord; +#endif in vec4 vertex_color; @@ -173,6 +176,10 @@ void main() #endif vec3 col = vertex_color.rgb * basecolor.rgb; +#if DEBUG_TEXCOORD + vec3 texcoord_color = vec3(mod(original_texcoord, 1.0), 0); + col = texcoord_color; +#endif vec3 vNt = texture(bumpMap, normal_texcoord.xy).xyz*2.0-1.0; float sign = vary_sign; @@ -265,6 +272,9 @@ in vec3 vary_position; in vec2 basecolor_texcoord; in vec2 emissive_texcoord; +#if DEBUG_TEXCOORD +in vec2 original_texcoord; +#endif in vec4 vertex_color; @@ -292,6 +302,10 @@ void main() #endif color = vertex_color.rgb * basecolor.rgb; +#if DEBUG_TEXCOORD + vec3 texcoord_color = vec3(mod(original_texcoord, 1.0), 0); + color = texcoord_color; +#endif // emissiveColor is the emissive color factor from GLTF and is already in linear space vec3 colorEmissive = emissiveColor; -- cgit v1.2.3 From a7ecfc9b1907d6ecd5fe50aeb1c41e38540b2665 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 24 Feb 2023 09:27:19 -0800 Subject: SL-19228: Remove DEBUG_TEXCOORD --- .../app_settings/shaders/class2/deferred/pbralphaF.glsl | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index 47d6c5e195..35ccc65a8e 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -57,9 +57,6 @@ in vec2 basecolor_texcoord; in vec2 normal_texcoord; in vec2 metallic_roughness_texcoord; in vec2 emissive_texcoord; -#if DEBUG_TEXCOORD -in vec2 original_texcoord; -#endif in vec4 vertex_color; @@ -176,10 +173,6 @@ void main() #endif vec3 col = vertex_color.rgb * basecolor.rgb; -#if DEBUG_TEXCOORD - vec3 texcoord_color = vec3(mod(original_texcoord, 1.0), 0); - col = texcoord_color; -#endif vec3 vNt = texture(bumpMap, normal_texcoord.xy).xyz*2.0-1.0; float sign = vary_sign; @@ -272,9 +265,6 @@ in vec3 vary_position; in vec2 basecolor_texcoord; in vec2 emissive_texcoord; -#if DEBUG_TEXCOORD -in vec2 original_texcoord; -#endif in vec4 vertex_color; @@ -302,10 +292,6 @@ void main() #endif color = vertex_color.rgb * basecolor.rgb; -#if DEBUG_TEXCOORD - vec3 texcoord_color = vec3(mod(original_texcoord, 1.0), 0); - color = texcoord_color; -#endif // emissiveColor is the emissive color factor from GLTF and is already in linear space vec3 colorEmissive = emissiveColor; -- cgit v1.2.3 From 86427ec145c7b956ec9ff5d9aa7ddde630cf45e1 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 24 Feb 2023 14:54:25 -0600 Subject: SL-19212 Resurrect glare and apply to PBR materials as well (and fix color mismatch in legacy alpha vs opaque). --- .../shaders/class2/deferred/pbralphaF.glsl | 32 ++++++++++++---------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index a95feb8e2f..987b0ca1d5 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -107,16 +107,16 @@ vec3 pbrBaseLight(vec3 diffuseColor, vec3 colorEmissive, float ao, vec3 additive, - vec3 atten); + vec3 atten, + out vec3 specContrib); vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, float perceptualRoughness, float metallic, vec3 n, // normal vec3 v, // surface point to camera - vec3 l); //surface point to light - -vec2 BRDF(float NoV, float roughness); + vec3 l, //surface point to light + out vec3 specContrib); vec3 calcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, float perceptualRoughness, @@ -127,7 +127,7 @@ vec3 calcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, vec3 lp, // light position vec3 ld, // light direction (for spotlights) vec3 lightColor, - float lightSize, float falloff, float is_pointlight, float ambiance) + float lightSize, float falloff, float is_pointlight, inout float glare, float ambiance) { vec3 color = vec3(0,0,0); @@ -149,7 +149,10 @@ vec3 calcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, vec3 intensity = spot_atten * dist_atten * lightColor * 3.0; - color = intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, lv); + vec3 speccol; + color = intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, lv, speccol); + speccol *= intensity; + glare += max(max(speccol.r, speccol.g), speccol.b); } return color; @@ -158,6 +161,7 @@ vec3 calcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, void main() { vec3 color = vec3(0,0,0); + float glare = 0.0; vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; vec3 pos = vary_position; @@ -224,15 +228,14 @@ void main() vec3 v = -normalize(pos.xyz); - color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit, scol, radiance, irradiance, colorEmissive, ao, additive, atten); - - float nv = clamp(abs(dot(norm.xyz, v)), 0.001, 1.0); - vec2 brdf = BRDF(clamp(nv, 0, 1), 1.0-perceptualRoughness); + vec3 spec; + color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit, scol, radiance, irradiance, colorEmissive, ao, additive, atten, spec); + glare += max(max(spec.r, spec.g), spec.b); vec3 light = vec3(0); // Punctual lights -#define LIGHT_LOOP(i) light += calcPointLightOrSpotLight(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, pos.xyz, v, light_position[i].xyz, light_direction[i].xyz, light_diffuse[i].rgb, light_deferred_attenuation[i].x, light_deferred_attenuation[i].y, light_attenuation[i].z, light_attenuation[i].w); +#define LIGHT_LOOP(i) light += calcPointLightOrSpotLight(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, pos.xyz, v, light_position[i].xyz, light_direction[i].xyz, light_diffuse[i].rgb, light_deferred_attenuation[i].x, light_deferred_attenuation[i].y, light_attenuation[i].z, glare, light_attenuation[i].w); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -246,11 +249,10 @@ void main() float a = basecolor.a*vertex_color.a; - vec3 spec = radiance; // *specularColor; - float lum = max(max(spec.r, spec.g), spec.b); - float f = brdf.y; - a += f; + glare = min(glare, 1.0); + a = max(a, glare); + frag_color = vec4(color.rgb,a); } -- cgit v1.2.3 From 33085b9d830ac1db280d678760b3972798aa1129 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 24 Feb 2023 13:53:55 -0800 Subject: SL-19265: Fix precision issue with texture transforms by moving transform matrix calculation into the shader --- indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index 35ccc65a8e..7cd6bae181 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -53,7 +53,7 @@ out vec4 frag_color; in vec3 vary_position; -in vec2 basecolor_texcoord; +in vec2 base_color_texcoord; in vec2 normal_texcoord; in vec2 metallic_roughness_texcoord; in vec2 emissive_texcoord; @@ -163,7 +163,7 @@ void main() waterClip(pos); - vec4 basecolor = texture(diffuseMap, basecolor_texcoord.xy).rgba; + vec4 basecolor = texture(diffuseMap, base_color_texcoord.xy).rgba; basecolor.rgb = srgb_to_linear(basecolor.rgb); #ifdef HAS_ALPHA_MASK if (basecolor.a < minimum_alpha) @@ -263,7 +263,7 @@ out vec4 frag_color; in vec3 vary_position; -in vec2 basecolor_texcoord; +in vec2 base_color_texcoord; in vec2 emissive_texcoord; in vec4 vertex_color; @@ -282,7 +282,7 @@ void main() vec3 pos = vary_position; - vec4 basecolor = texture(diffuseMap, basecolor_texcoord.xy).rgba; + vec4 basecolor = texture(diffuseMap, base_color_texcoord.xy).rgba; basecolor.rgb = srgb_to_linear(basecolor.rgb); #ifdef HAS_ALPHA_MASK if (basecolor.a < minimum_alpha) -- cgit v1.2.3 From e5a2f85005bbf94f39ef048dbfe43276990f1154 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 27 Feb 2023 16:53:56 -0600 Subject: SL-19226 Reimplement water fresnel offset/scale, exposure balance for midday, adjust reflections off, and decruft depth buffer error correction shenanigans that are no longer used. --- .../app_settings/shaders/class2/deferred/reflectionProbeF.glsl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl index f1ee4b4681..5fa53c374b 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, - vec2 tc, vec3 pos, vec3 norm, float glossiness, bool errorCorrect) + vec2 tc, vec3 pos, vec3 norm, float glossiness) { ambenv = vec3(reflection_probe_ambiance * 0.25); @@ -43,11 +43,11 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, glossenv = srgb_to_linear(textureCube(environmentMap, env_vec).rgb); } -void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness) +void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv, + vec2 tc, vec3 pos, vec3 norm, float glossiness) { - sampleReflectionProbes(ambenv, glossenv, - tc, pos, norm, glossiness, false); + sampleReflectionProbes(ambenv, glossenv, tc, pos, norm, glossiness); + glossenv *= 8.0; } vec4 sampleReflectionProbesDebug(vec3 pos) -- cgit v1.2.3 From bc7856098f70371dd392c74689df267cce819aa7 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 2 Mar 2023 16:36:03 -0600 Subject: SL-19281 Unify handling of haze and gamma between fullbright and not and move haze back to sRGB color space to stay consistent with sky colors. Also fix broken "roughness" stuck at 0.2. --- .../shaders/class2/deferred/alphaF.glsl | 11 ++++++-- .../shaders/class2/deferred/pbralphaF.glsl | 11 +++++++- .../shaders/class2/deferred/reflectionProbeF.glsl | 1 - .../shaders/class2/windlight/atmosphericsF.glsl | 4 +-- .../class2/windlight/atmosphericsFuncs.glsl | 15 +++++------ .../shaders/class2/windlight/gammaF.glsl | 29 ++++++++-------------- .../shaders/class2/windlight/transportF.glsl | 18 ++++++++------ 7 files changed, 50 insertions(+), 39 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl index e2694e060e..ef35bf3fd7 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl @@ -250,6 +250,9 @@ void main() calcAtmosphericVarsLinear(pos.xyz, norm, light_dir, sunlit, amblit, additive, atten); + vec3 sunlit_linear = srgb_to_linear(sunlit); + vec3 amblit_linear = amblit; + vec3 irradiance; vec3 glossenv; vec3 legacyenv; @@ -266,7 +269,7 @@ void main() color.a = final_alpha; - vec3 sun_contrib = min(final_da, shadow) * sunlit; + vec3 sun_contrib = min(final_da, shadow) * sunlit_linear; color.rgb = max(amblit, irradiance); @@ -274,8 +277,10 @@ void main() color.rgb *= diffuse_linear.rgb; + color.rgb = linear_to_srgb(color.rgb); color.rgb = atmosFragLightingLinear(color.rgb, additive, atten); color.rgb = scaleSoftClipFragLinear(color.rgb); + color.rgb = srgb_to_linear(color.rgb); vec4 light = vec4(0,0,0,0); @@ -294,8 +299,9 @@ void main() color.rgb += light.rgb; #endif // !defined(LOCAL_LIGHT_KILL) + #ifdef WATER_FOG - color = applyWaterFogViewLinear(pos.xyz, color, sunlit); + color = applyWaterFogViewLinear(pos.xyz, color, sunlit_linear); #endif // WATER_FOG #endif // #else // FOR_IMPOSTOR @@ -303,6 +309,7 @@ void main() #ifdef IS_HUD color.rgb = linear_to_srgb(color.rgb); #endif + frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index 2a093827cb..fb76db99a0 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -82,6 +82,8 @@ vec3 srgb_to_linear(vec3 c); vec3 linear_to_srgb(vec3 c); void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); +vec3 atmosFragLightingLinear(vec3 color, vec3 additive, vec3 atten); +vec3 scaleSoftClipFragLinear(vec3 color); void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist); float calcLegacyDistanceAttenuation(float distance, float falloff); @@ -196,6 +198,8 @@ void main() vec3 atten; calcAtmosphericVarsLinear(pos.xyz, norm, light_dir, sunlit, amblit, additive, atten); + vec3 sunlit_linear = srgb_to_linear(sunlit); + vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; #ifdef HAS_SUN_SHADOW @@ -229,9 +233,14 @@ void main() vec3 v = -normalize(pos.xyz); vec3 spec; - color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit, scol, radiance, irradiance, colorEmissive, ao, additive, atten, spec); + color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit_linear, scol, radiance, irradiance, colorEmissive, ao, additive, atten, spec); glare += max(max(spec.r, spec.g), spec.b); + color.rgb = linear_to_srgb(color.rgb); + color.rgb = atmosFragLightingLinear(color.rgb, additive, atten); + color.rgb = scaleSoftClipFragLinear(color.rgb); + color.rgb = srgb_to_linear(color.rgb); + vec3 light = vec3(0); // Punctual lights diff --git a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl index 5fa53c374b..080f622155 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl @@ -47,7 +47,6 @@ void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv, vec2 tc, vec3 pos, vec3 norm, float glossiness) { sampleReflectionProbes(ambenv, glossenv, tc, pos, norm, glossiness); - glossenv *= 8.0; } vec4 sampleReflectionProbesDebug(vec3 pos) diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 6668a00841..1d02498209 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -33,8 +33,8 @@ vec3 linear_to_srgb(vec3 col); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) { light *= atten.r; - light += additive; - return light * 2.0; + light += additive * 2.0; + return light; } vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten) diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl index f9f625ecdb..768f422060 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl @@ -137,8 +137,8 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou additive = (blue_horizon.rgb * blue_weight.rgb) * (cs + tmpAmbient.rgb) + (haze_horizon * haze_weight.rgb) * (cs * haze_glow + tmpAmbient.rgb); // brightness of surface both sunlight and ambient - sunlit = sunlight.rgb; - amblit = tmpAmbient.rgb; + sunlit = sunlight.rgb * 0.7; + amblit = tmpAmbient.rgb * 0.25; additive *= vec3(1.0 - combined_haze); } @@ -150,21 +150,22 @@ vec3 srgb_to_linear(vec3 col); float ambientLighting(vec3 norm, vec3 light_dir) { float ambient = min(abs(dot(norm.xyz, light_dir.xyz)), 1.0); - ambient *= 0.56; + ambient *= 0.5; ambient *= ambient; ambient = (1.0 - ambient); return ambient; } -// return colors in linear space +// return lit amblit in linear space, leave sunlit and additive in sRGB space void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { calcAtmosphericVars(inPositionEye, light_dir, 1.0, sunlit, amblit, additive, atten, false); - sunlit = srgb_to_linear(sunlit); - additive = srgb_to_linear(additive); - amblit = ambient_linear; + + sunlit *= 2.0; + amblit *= 2.0; amblit *= ambientLighting(norm, light_dir); + amblit = srgb_to_linear(amblit); } diff --git a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl index 9a9b179e6a..027bfb866f 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl @@ -22,43 +22,34 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ -uniform float gamma; -vec3 getAtmosAttenuation(); -vec3 getAdditiveColor(); + // DEPRECATED -vec3 srgb_to_linear(vec3 col); -vec3 linear_to_srgb(vec3 col); +//soft clip effect has been moved to postDeferredGammaCorrect legacyGamma, this file is effectively dead +// but these functions need to be removed from all existing shaders before removing this file -vec3 scaleSoftClipFragLinear(vec3 light) -{ // identical to non-linear version and that's probably close enough - //soft clip effect: - light = 1. - clamp(light, vec3(0.), vec3(1.)); - light = 1. - pow(light, vec3(gamma)); // s/b inverted already CPU-side +vec3 scaleSoftClipFrag(vec3 light) +{ return light; } -vec3 scaleSoftClipFrag(vec3 light) -{ - //soft clip effect: - light = 1. - clamp(light, vec3(0.), vec3(1.)); - light = 1. - pow(light, vec3(gamma)); // s/b inverted already CPU-side +vec3 scaleSoftClipFragLinear(vec3 light) +{ // identical to non-linear version and that's probably close enough return light; } vec3 scaleSoftClip(vec3 light) { - return scaleSoftClipFrag(light); + return light; } vec3 fullbrightScaleSoftClipFrag(vec3 light, vec3 add, vec3 atten) { - //return mix(scaleSoftClipFrag(light.rgb), add, atten); - return scaleSoftClipFrag(light.rgb); + return light; } vec3 fullbrightScaleSoftClip(vec3 light) { - return fullbrightScaleSoftClipFrag(light, getAdditiveColor(), getAtmosAttenuation()); + return light; } diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index c509d865ba..6aa719d200 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -48,23 +48,27 @@ vec3 atmosTransport(vec3 light) vec3 fullbrightAtmosTransportFragLinear(vec3 light, vec3 additive, vec3 atten) { // same as non-linear version, probably fine - float brightness = dot(light.rgb * 0.5, vec3(0.3333)) + 0.1; - return mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive, brightness * brightness); + //float brightness = dot(light.rgb * 0.5, vec3(0.3333)) + 0.1; + //return mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive, brightness * brightness); + return atmosTransportFrag(light, additive, atten); } vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { - float brightness = dot(light.rgb * 0.5, vec3(0.3333)) + 0.1; - return mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive, brightness * brightness); + //float brightness = dot(light.rgb * 0.5, vec3(0.3333)) + 0.1; + //return mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive, brightness * brightness); + return atmosTransportFrag(light, additive, atten); } vec3 fullbrightAtmosTransport(vec3 light) { - return fullbrightAtmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); + //return fullbrightAtmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); + return atmosTransport(light); } vec3 fullbrightShinyAtmosTransport(vec3 light) { - float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosTransport(light.rgb), (light.rgb + getAdditiveColor().rgb) * (2.0 - brightness), brightness * brightness); + //float brightness = dot(light.rgb, vec3(0.33333)); + //return mix(atmosTransport(light.rgb), (light.rgb + getAdditiveColor().rgb) * (2.0 - brightness), brightness * brightness); + return atmosTransport(light); } -- cgit v1.2.3 From 7139444461aae953a263a60f1a093070cc870225 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 2 Mar 2023 18:36:57 -0600 Subject: SL-19281 Post review cleanup. --- .../app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl index 768f422060..34ac0c62dc 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl @@ -137,12 +137,15 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou additive = (blue_horizon.rgb * blue_weight.rgb) * (cs + tmpAmbient.rgb) + (haze_horizon * haze_weight.rgb) * (cs * haze_glow + tmpAmbient.rgb); // brightness of surface both sunlight and ambient + + // fudge sunlit and amblit to get consistent lighting compared to legacy + // midday before PBR was a thing sunlit = sunlight.rgb * 0.7; amblit = tmpAmbient.rgb * 0.25; + additive *= vec3(1.0 - combined_haze); } - vec3 srgb_to_linear(vec3 col); // provide a touch of lighting in the opposite direction of the sun light @@ -163,6 +166,8 @@ void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, ou { calcAtmosphericVars(inPositionEye, light_dir, 1.0, sunlit, amblit, additive, atten, false); + // multiply by 2 to get same colors as when the "scaleSoftClip" implementation was doubling color values + // (allows for mixing of light sources other than sunlight e.g. reflection probes) sunlit *= 2.0; amblit *= 2.0; -- cgit v1.2.3 From 29b3727b8cc833c664a79a242c9043e6070041e8 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 7 Mar 2023 14:06:01 -0600 Subject: SL-19355 Irradiance rebalance. --- .../app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl index 34ac0c62dc..55e1411be2 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl @@ -169,7 +169,9 @@ void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, ou // multiply by 2 to get same colors as when the "scaleSoftClip" implementation was doubling color values // (allows for mixing of light sources other than sunlight e.g. reflection probes) sunlit *= 2.0; - amblit *= 2.0; + + // squash ambient to approximate whatever weirdness legacy atmospherics were doing + amblit = ambient_color * 0.5; amblit *= ambientLighting(norm, light_dir); amblit = srgb_to_linear(amblit); -- cgit v1.2.3 From 960715efc1cda86f924acc50f2a322e9403abd14 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 27 Mar 2023 13:07:31 -0500 Subject: SL-19477 Remove angular attenuation from sphere probe weight to fix harsh indirect lighting. Minor incidental decruft. --- indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl | 2 -- 1 file changed, 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl index ef35bf3fd7..e7322c14fb 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl @@ -79,7 +79,6 @@ vec3 srgb_to_linear(vec3 c); vec3 linear_to_srgb(vec3 c); vec2 encode_normal (vec3 n); -vec3 scaleSoftClipFragLinear(vec3 l); vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten); void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); @@ -279,7 +278,6 @@ void main() color.rgb = linear_to_srgb(color.rgb); color.rgb = atmosFragLightingLinear(color.rgb, additive, atten); - color.rgb = scaleSoftClipFragLinear(color.rgb); color.rgb = srgb_to_linear(color.rgb); vec4 light = vec4(0,0,0,0); -- cgit v1.2.3 From 10f66c05190585e9de2e85831712323c297d81c4 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 28 Mar 2023 14:30:59 -0500 Subject: DRTVWR-559 Dynamically adjust exposure. --- .../app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl index 55e1411be2..f9a1f5e4d6 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl @@ -62,7 +62,9 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou vec3 rel_pos_norm = normalize(rel_pos); float rel_pos_len = length(rel_pos); - vec3 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; + float scale = sun_up_factor + 1.0; + vec3 sunlight = (sun_up_factor == 1) ? sunlight_color: moonlight_color; + sunlight *= scale; // sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes @@ -140,7 +142,7 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou // fudge sunlit and amblit to get consistent lighting compared to legacy // midday before PBR was a thing - sunlit = sunlight.rgb * 0.7; + sunlit = sunlight.rgb / scale; amblit = tmpAmbient.rgb * 0.25; additive *= vec3(1.0 - combined_haze); -- cgit v1.2.3 From 81c440a4a962a314d85cee854365e6593b72e87c Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 28 Mar 2023 15:51:29 -0500 Subject: DRTVWR-559 Dynamic exposure followup -- balance moon brightness and add glow to exposure sample. --- .../app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl index f9a1f5e4d6..7129718ff8 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl @@ -62,9 +62,8 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou vec3 rel_pos_norm = normalize(rel_pos); float rel_pos_len = length(rel_pos); - float scale = sun_up_factor + 1.0; - vec3 sunlight = (sun_up_factor == 1) ? sunlight_color: moonlight_color; - sunlight *= scale; + float scale = 2.0; + vec3 sunlight = (sun_up_factor == 1) ? sunlight_color * scale: moonlight_color/scale; // sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes -- cgit v1.2.3 From b130831106d058f0be5414a9a3bcaa99636c7bc0 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 29 Mar 2023 13:24:07 -0500 Subject: DRTVWR-559 Dynamic exposure followup -- stochastic sampling, weight based on luminance and distance to center of screen, rebalance night, don't rely on blending not clamping R16F. --- .../app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl index 7129718ff8..0d3dbf85e2 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl @@ -63,7 +63,7 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou vec3 rel_pos_norm = normalize(rel_pos); float rel_pos_len = length(rel_pos); float scale = 2.0; - vec3 sunlight = (sun_up_factor == 1) ? sunlight_color * scale: moonlight_color/scale; + vec3 sunlight = (sun_up_factor == 1) ? sunlight_color * scale: moonlight_color*0.75; // sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes -- cgit v1.2.3 From 46702c4e80e96cd8dbe7f37d5c14fbb1830e798d Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 30 Mar 2023 18:19:32 -0500 Subject: DRTVWR-559 Auto exposure tuning. --- .../app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl index 0d3dbf85e2..12a99edc34 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl @@ -62,8 +62,8 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou vec3 rel_pos_norm = normalize(rel_pos); float rel_pos_len = length(rel_pos); - float scale = 2.0; - vec3 sunlight = (sun_up_factor == 1) ? sunlight_color * scale: moonlight_color*0.75; + + vec3 sunlight = (sun_up_factor == 1) ? sunlight_color: moonlight_color; // sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes @@ -141,7 +141,7 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou // fudge sunlit and amblit to get consistent lighting compared to legacy // midday before PBR was a thing - sunlit = sunlight.rgb / scale; + sunlit = sunlight.rgb; amblit = tmpAmbient.rgb * 0.25; additive *= vec3(1.0 - combined_haze); -- cgit v1.2.3 From c0958922c3b3015fd7f17781a79032050b2ed387 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 30 Mar 2023 18:41:34 -0500 Subject: DRTVWR-559 Auto exposure tuning (fix horizon). --- .../app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl index 12a99edc34..c2527db218 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl @@ -63,7 +63,9 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou vec3 rel_pos_norm = normalize(rel_pos); float rel_pos_len = length(rel_pos); + float scale = sun_up_factor + 1; vec3 sunlight = (sun_up_factor == 1) ? sunlight_color: moonlight_color; + sunlight *= scale; // sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes @@ -141,7 +143,7 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou // fudge sunlit and amblit to get consistent lighting compared to legacy // midday before PBR was a thing - sunlit = sunlight.rgb; + sunlit = sunlight.rgb / scale; amblit = tmpAmbient.rgb * 0.25; additive *= vec3(1.0 - combined_haze); -- cgit v1.2.3 From 698966f8e7ddcc0b123a83d7c4e381778f8cd8ab Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Tue, 4 Apr 2023 12:29:12 -0500 Subject: =?UTF-8?q?SL-19538=20Remove=20hacky=20ambiance=20scale=20and=20ta?= =?UTF-8?q?ke=20the=20mittens=20off=20probe=20a=E2=80=A6=20(#151)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * SL-19538 Remove hacky ambiance scale and take the mittens off probe ambiance values. Fix for sky brightening being done in sRGB space. --- .../shaders/class2/deferred/alphaF.glsl | 2 -- .../shaders/class2/deferred/pbralphaF.glsl | 6 +----- .../shaders/class2/interface/irradianceGenF.glsl | 3 --- .../shaders/class2/windlight/atmosphericsF.glsl | 6 +++++- .../class2/windlight/atmosphericsFuncs.glsl | 4 +--- .../shaders/class2/windlight/transportF.glsl | 22 ++++------------------ 6 files changed, 11 insertions(+), 32 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl index e7322c14fb..70be9a9029 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl @@ -276,9 +276,7 @@ void main() color.rgb *= diffuse_linear.rgb; - color.rgb = linear_to_srgb(color.rgb); color.rgb = atmosFragLightingLinear(color.rgb, additive, atten); - color.rgb = srgb_to_linear(color.rgb); vec4 light = vec4(0,0,0,0); diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index fb76db99a0..b76443f0f0 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -83,7 +83,6 @@ vec3 linear_to_srgb(vec3 c); void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); vec3 atmosFragLightingLinear(vec3 color, vec3 additive, vec3 atten); -vec3 scaleSoftClipFragLinear(vec3 color); void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist); float calcLegacyDistanceAttenuation(float distance, float falloff); @@ -236,11 +235,8 @@ void main() color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit_linear, scol, radiance, irradiance, colorEmissive, ao, additive, atten, spec); glare += max(max(spec.r, spec.g), spec.b); - color.rgb = linear_to_srgb(color.rgb); color.rgb = atmosFragLightingLinear(color.rgb, additive, atten); - color.rgb = scaleSoftClipFragLinear(color.rgb); - color.rgb = srgb_to_linear(color.rgb); - + vec3 light = vec3(0); // Punctual lights diff --git a/indra/newview/app_settings/shaders/class2/interface/irradianceGenF.glsl b/indra/newview/app_settings/shaders/class2/interface/irradianceGenF.glsl index baf68e11f4..d21af946e0 100644 --- a/indra/newview/app_settings/shaders/class2/interface/irradianceGenF.glsl +++ b/indra/newview/app_settings/shaders/class2/interface/irradianceGenF.glsl @@ -32,7 +32,6 @@ uniform samplerCubeArray reflectionProbes; uniform int sourceIdx; uniform float max_probe_lod; -uniform float ambiance_scale; in vec3 vary_dir; @@ -200,8 +199,6 @@ vec4 filterColor(vec3 N) color /= float(u_sampleCount); - color.rgb *= ambiance_scale; - return color; } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 1d02498209..22e93496d2 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -30,10 +30,14 @@ vec3 scaleSoftClipFrag(vec3 light); vec3 srgb_to_linear(vec3 col); vec3 linear_to_srgb(vec3 col); +uniform int sun_up_factor; + vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) { light *= atten.r; - light += additive * 2.0; + additive = srgb_to_linear(additive*2.0); + additive *= sun_up_factor + 1.0; + light += additive; return light; } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl index c2527db218..12a99edc34 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl @@ -63,9 +63,7 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou vec3 rel_pos_norm = normalize(rel_pos); float rel_pos_len = length(rel_pos); - float scale = sun_up_factor + 1; vec3 sunlight = (sun_up_factor == 1) ? sunlight_color: moonlight_color; - sunlight *= scale; // sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes @@ -143,7 +141,7 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou // fudge sunlit and amblit to get consistent lighting compared to legacy // midday before PBR was a thing - sunlit = sunlight.rgb / scale; + sunlit = sunlight.rgb; amblit = tmpAmbient.rgb * 0.25; additive *= vec3(1.0 - combined_haze); diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index 6aa719d200..8221ba9516 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -30,14 +30,13 @@ vec3 getAdditiveColor(); vec3 getAtmosAttenuation(); -vec3 srgb_to_linear(vec3 col); -vec3 linear_to_srgb(vec3 col); +vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); + +// the below implementations are deprecated but remain here as adapters for shaders that haven't been refactored yet vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { - light *= atten.r; - light += additive * 2.0; - return light; + return atmosFragLighting(light, additive, atten); } vec3 atmosTransport(vec3 light) @@ -45,30 +44,17 @@ vec3 atmosTransport(vec3 light) return atmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); } -vec3 fullbrightAtmosTransportFragLinear(vec3 light, vec3 additive, vec3 atten) -{ - // same as non-linear version, probably fine - //float brightness = dot(light.rgb * 0.5, vec3(0.3333)) + 0.1; - //return mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive, brightness * brightness); - return atmosTransportFrag(light, additive, atten); -} - vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { - //float brightness = dot(light.rgb * 0.5, vec3(0.3333)) + 0.1; - //return mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive, brightness * brightness); return atmosTransportFrag(light, additive, atten); } vec3 fullbrightAtmosTransport(vec3 light) { - //return fullbrightAtmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); return atmosTransport(light); } vec3 fullbrightShinyAtmosTransport(vec3 light) { - //float brightness = dot(light.rgb, vec3(0.33333)); - //return mix(atmosTransport(light.rgb), (light.rgb + getAdditiveColor().rgb) * (2.0 - brightness), brightness * brightness); return atmosTransport(light); } -- cgit v1.2.3 From 1f79379bf215c5368337c64b4f72c7c9ef3e09c2 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Wed, 5 Apr 2023 11:55:51 -0500 Subject: SL-19538 Followup -- tune exposure parameters and clamp local light ambiance. Make render targets 16F and scrube NaNs (thanks Rye). Update midday. (#154) --- .../app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl | 4 ---- 1 file changed, 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl index 257a76c663..6ecbfaecb1 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl @@ -54,8 +54,4 @@ vec3 scaleDownLight(vec3 light) return (light / scene_light_strength ); } -vec3 scaleUpLight(vec3 light) -{ - return (light * scene_light_strength); -} -- cgit v1.2.3 From 5bf60f5d9e722f6210572fd92e79e9994abd2ec1 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Wed, 5 Apr 2023 16:48:34 -0500 Subject: =?UTF-8?q?SL-19538=20Followup=20--=20fix=20for=20dynamic=20exposu?= =?UTF-8?q?re=20having=20large=20gaps=20in=20it=E2=80=A6=20(#157)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * SL-19538 Followup -- fix for dynamic exposure having large gaps in its luminance sampling. * SL-19538 Followup -- review feedback changes. --- .../newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 22e93496d2..49ff49fdd8 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -36,7 +36,9 @@ vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) { light *= atten.r; additive = srgb_to_linear(additive*2.0); - additive *= sun_up_factor + 1.0; + // magic 3.0 here is to match the default RenderSkyHDRScale -- this parameter needs to be plumbed into sky settings or something + // so it's available to all shaders that call atmosFragLighting instead of just softenLightF.glsl + additive *= sun_up_factor*3.0 + 1.0; light += additive; return light; } -- cgit v1.2.3 From bb79718c8f0050569c80a1bfe4dd428321706d1a Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 6 Apr 2023 13:21:25 -0500 Subject: SL-19538 Followup -- scrub all possible sources of NaNs, make dynamic exposure controls not persist, limit exposure range, and do a debug gl pass. --- indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl | 2 +- indra/newview/app_settings/shaders/class2/interface/irradianceGenF.glsl | 2 +- .../newview/app_settings/shaders/class2/interface/reflectionprobeF.glsl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl index 70be9a9029..53552870ae 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl @@ -306,6 +306,6 @@ void main() color.rgb = linear_to_srgb(color.rgb); #endif - frag_color = color; + frag_color = max(color, vec4(0)); } diff --git a/indra/newview/app_settings/shaders/class2/interface/irradianceGenF.glsl b/indra/newview/app_settings/shaders/class2/interface/irradianceGenF.glsl index d21af946e0..0753e73dc8 100644 --- a/indra/newview/app_settings/shaders/class2/interface/irradianceGenF.glsl +++ b/indra/newview/app_settings/shaders/class2/interface/irradianceGenF.glsl @@ -209,6 +209,6 @@ void main() color = filterColor(vary_dir); - frag_color = color; + frag_color = max(color, vec4(0)); } diff --git a/indra/newview/app_settings/shaders/class2/interface/reflectionprobeF.glsl b/indra/newview/app_settings/shaders/class2/interface/reflectionprobeF.glsl index 986b233e0b..c858531998 100644 --- a/indra/newview/app_settings/shaders/class2/interface/reflectionprobeF.glsl +++ b/indra/newview/app_settings/shaders/class2/interface/reflectionprobeF.glsl @@ -38,5 +38,5 @@ void main() float depth = getDepth(tc.xy); vec4 pos = getPositionWithDepth(tc, depth); - frag_color = sampleReflectionProbesDebug(pos.xyz); + frag_color = max(sampleReflectionProbesDebug(pos.xyz), vec4(0)); } -- cgit v1.2.3 From b127e1bd12442953801eb6b53f052aa69d8ee580 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 6 Apr 2023 18:58:24 -0500 Subject: SL-19538 Nudge sun brightness and replace "gamma" with an exposure scaler approximation --- .../app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl index 12a99edc34..7f6827b160 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl @@ -141,7 +141,7 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou // fudge sunlit and amblit to get consistent lighting compared to legacy // midday before PBR was a thing - sunlit = sunlight.rgb; + sunlit = sunlight.rgb * (1.0+sun_up_factor*0.3); amblit = tmpAmbient.rgb * 0.25; additive *= vec3(1.0 - combined_haze); @@ -172,7 +172,7 @@ void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, ou sunlit *= 2.0; // squash ambient to approximate whatever weirdness legacy atmospherics were doing - amblit = ambient_color * 0.5; + amblit = ambient_color * 0.5 * (1.0+sun_up_factor*0.3); amblit *= ambientLighting(norm, light_dir); amblit = srgb_to_linear(amblit); -- cgit v1.2.3 From 72a0408401e4fa8f22ec8a70584bf90e5f0ccc73 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 6 Apr 2023 22:55:51 -0500 Subject: SL-19538 Back off on sun brightening a bit, remove errant brightening of clouds, and update midday to not be red shifted. --- .../app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl index 7f6827b160..14ce33f81f 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl @@ -141,7 +141,7 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou // fudge sunlit and amblit to get consistent lighting compared to legacy // midday before PBR was a thing - sunlit = sunlight.rgb * (1.0+sun_up_factor*0.3); + sunlit = sunlight.rgb * (1.0+sun_up_factor*0.2); amblit = tmpAmbient.rgb * 0.25; additive *= vec3(1.0 - combined_haze); -- cgit v1.2.3 From 2b2154f0217758b27b544d066024d922ba234d51 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Tue, 11 Apr 2023 15:09:58 -0500 Subject: SL-19564 Rebalance exposure and sky. Hack legacy diffuse map saturation and brightness to allow ACES Hill all the time. --- indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl | 2 ++ .../app_settings/shaders/class2/windlight/atmosphericsF.glsl | 4 ++-- .../app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl | 8 +++----- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl index 53552870ae..f4d6eff69e 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl @@ -77,6 +77,7 @@ vec4 applyWaterFogViewLinear(vec3 pos, vec4 color, vec3 sunlit); vec3 srgb_to_linear(vec3 c); vec3 linear_to_srgb(vec3 c); +vec3 legacy_adjust(vec3 c); vec2 encode_normal (vec3 n); vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten); @@ -239,6 +240,7 @@ void main() } diffuse_srgb.rgb *= vertex_color.rgb; + diffuse_srgb.rgb = legacy_adjust(diffuse_srgb.rgb); diffuse_linear.rgb = srgb_to_linear(diffuse_srgb.rgb); #endif // USE_VERTEX_COLOR diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 49ff49fdd8..e314555ef9 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -36,9 +36,9 @@ vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) { light *= atten.r; additive = srgb_to_linear(additive*2.0); - // magic 3.0 here is to match the default RenderSkyHDRScale -- this parameter needs to be plumbed into sky settings or something + // magic 1.25 here is to match the default RenderSkyHDRScale -- this parameter needs to be plumbed into sky settings or something // so it's available to all shaders that call atmosFragLighting instead of just softenLightF.glsl - additive *= sun_up_factor*3.0 + 1.0; + additive *= sun_up_factor*1.25 + 1.0; light += additive; return light; } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl index 14ce33f81f..22db9dce03 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl @@ -139,10 +139,8 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou // brightness of surface both sunlight and ambient - // fudge sunlit and amblit to get consistent lighting compared to legacy - // midday before PBR was a thing - sunlit = sunlight.rgb * (1.0+sun_up_factor*0.2); - amblit = tmpAmbient.rgb * 0.25; + sunlit = sunlight.rgb; + amblit = vec3(1,0,1); //should no longer be used, filled in by calcAtmosphericVarsLinear additive *= vec3(1.0 - combined_haze); } @@ -172,7 +170,7 @@ void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, ou sunlit *= 2.0; // squash ambient to approximate whatever weirdness legacy atmospherics were doing - amblit = ambient_color * 0.5 * (1.0+sun_up_factor*0.3); + amblit = ambient_color; // * (1.0+sun_up_factor*0.3); amblit *= ambientLighting(norm, light_dir); amblit = srgb_to_linear(amblit); -- cgit v1.2.3 From 137a21fd99a591ad4a0cb8d322e14bc3c45ce0a0 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Thu, 13 Apr 2023 11:51:48 -0700 Subject: SL-19592: Fix alpha blend PBR prims on HUD --- indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl | 1 - 1 file changed, 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index b76443f0f0..d3fa03b02a 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -309,7 +309,6 @@ void main() float a = basecolor.a*vertex_color.a; - a = 1.0; color += colorEmissive; color = linear_to_srgb(color); frag_color = vec4(color.rgb,a); -- cgit v1.2.3 From 03bd681564f0b0a630f6330ab9c61daa4856e5fe Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Fri, 14 Apr 2023 19:24:21 -0500 Subject: DRTVWR-559 Balance night scenes against release, nudge glow down a smidge, remove exposure correction from legacy fullbright balance PBR materials against legacy. --- indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl | 2 +- .../app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index d3fa03b02a..cd7c005162 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -148,7 +148,7 @@ vec3 calcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, // spot*spot => GL_SPOT_EXPONENT=2 float spot_atten = spot*spot; - vec3 intensity = spot_atten * dist_atten * lightColor * 3.0; + vec3 intensity = spot_atten * dist_atten * lightColor * 3.9; //magic number to balance with legacy materials vec3 speccol; color = intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, lv, speccol); diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl index 22db9dce03..4e0933f922 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl @@ -50,6 +50,7 @@ uniform float sun_moon_glow_factor; float getAmbientClamp() { return 1.0f; } vec3 srgb_to_linear(vec3 col); +vec3 legacy_adjust(vec3 col); // return colors in sRGB space void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, @@ -63,8 +64,8 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou vec3 rel_pos_norm = normalize(rel_pos); float rel_pos_len = length(rel_pos); - vec3 sunlight = (sun_up_factor == 1) ? sunlight_color: moonlight_color; - + vec3 sunlight = (sun_up_factor == 1) ? sunlight_color: moonlight_color * 0.7; // magic 0.7 to match legacy color + // sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes vec3 light_atten = (blue_density + vec3(haze_density * 0.25)) * (density_multiplier * max_y); -- cgit v1.2.3 From 49a88c6f5a890129b094669659931513bd804adc Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Thu, 20 Apr 2023 13:39:16 -0500 Subject: SL-19560 Revert hacky fix for other avatars having low res BoM textures. Fix for brightening of PBR materials at the shadow horizon. --- .../app_settings/shaders/class2/deferred/sunLightF.glsl | 11 +++++++---- .../app_settings/shaders/class2/deferred/sunLightSSAOF.glsl | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl index 8abdeae5ae..e1cbfcce1a 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl @@ -53,8 +53,11 @@ void main() vec4 pos = getPosition(pos_screen); vec3 norm = getNorm(pos_screen); - frag_color.r = sampleDirectionalShadow(pos.xyz, norm, pos_screen); - frag_color.g = 1.0f; - frag_color.b = sampleSpotShadow(pos.xyz, norm, 0, pos_screen); - frag_color.a = sampleSpotShadow(pos.xyz, norm, 1, pos_screen); + vec4 col; + col.r = sampleDirectionalShadow(pos.xyz, norm, pos_screen); + col.g = 1.0f; + col.b = sampleSpotShadow(pos.xyz, norm, 0, pos_screen); + col.a = sampleSpotShadow(pos.xyz, norm, 1, pos_screen); + + frag_color = clamp(col, vec4(0), vec4(1)); } diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl index 64d99bae2c..99a26a050d 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl @@ -50,8 +50,11 @@ void main() vec4 pos = getPosition(pos_screen); vec3 norm = getNorm(pos_screen); - frag_color.r = sampleDirectionalShadow(pos.xyz, norm, pos_screen); - frag_color.g = calcAmbientOcclusion(pos, norm, pos_screen); - frag_color.b = sampleSpotShadow(pos.xyz, norm, 0, pos_screen); - frag_color.a = sampleSpotShadow(pos.xyz, norm, 1, pos_screen); + vec4 col; + col.r = sampleDirectionalShadow(pos.xyz, norm, pos_screen); + col.g = calcAmbientOcclusion(pos, norm, pos_screen); + col.b = sampleSpotShadow(pos.xyz, norm, 0, pos_screen); + col.a = sampleSpotShadow(pos.xyz, norm, 1, pos_screen); + + frag_color = clamp(col, vec4(0), vec4(1)); } -- cgit v1.2.3 From cdc9852f052d804f8b25564ab7d90eb2b79cddd4 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Mon, 15 May 2023 11:01:24 -0500 Subject: SL-19709 Fix for fullbright shiny not factoring out exposure and flickering fullbright alpha. Incidental decruft. --- .../shaders/class2/windlight/transportF.glsl | 60 ---------------------- 1 file changed, 60 deletions(-) delete mode 100644 indra/newview/app_settings/shaders/class2/windlight/transportF.glsl (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl deleted file mode 100644 index 8221ba9516..0000000000 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @file class2\wl\transportF.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$ - */ - -////////////////////////////////////////////////////////// -// The fragment shader for the terrain atmospherics -////////////////////////////////////////////////////////// - -vec3 getAdditiveColor(); -vec3 getAtmosAttenuation(); - -vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); - -// the below implementations are deprecated but remain here as adapters for shaders that haven't been refactored yet - -vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) -{ - return atmosFragLighting(light, additive, atten); -} - -vec3 atmosTransport(vec3 light) -{ - return atmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); -} - -vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) -{ - return atmosTransportFrag(light, additive, atten); -} - -vec3 fullbrightAtmosTransport(vec3 light) -{ - return atmosTransport(light); -} - -vec3 fullbrightShinyAtmosTransport(vec3 light) -{ - return atmosTransport(light); -} -- cgit v1.2.3 From c827d32ebedeaa46ed75a91ae779f6547fc0d090 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Wed, 17 May 2023 18:09:36 -0500 Subject: SL-19655 Decruft legacy GLSL shaders and now unused build queues. --- .../app_settings/shaders/class2/deferred/alphaF.glsl | 18 ++++++------------ .../shaders/class2/deferred/pbralphaF.glsl | 4 ++-- .../shaders/class2/deferred/reflectionProbeF.glsl | 4 ++-- .../shaders/class2/deferred/softenLightV.glsl | 4 ++-- .../shaders/class2/deferred/sunLightF.glsl | 8 +------- .../shaders/class2/deferred/sunLightSSAOF.glsl | 8 +------- .../shaders/class2/deferred/sunLightV.glsl | 4 ++-- .../shaders/class2/windlight/atmosphericsV.glsl | 2 +- .../shaders/class2/windlight/atmosphericsVarsF.glsl | 4 ++-- .../shaders/class2/windlight/atmosphericsVarsV.glsl | 4 ++-- .../class2/windlight/atmosphericsVarsWaterF.glsl | 6 +++--- .../class2/windlight/atmosphericsVarsWaterV.glsl | 6 +++--- 12 files changed, 27 insertions(+), 45 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl index f4d6eff69e..ae8cd97b18 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl @@ -25,19 +25,13 @@ //class2/deferred/alphaF.glsl -#extension GL_ARB_texture_rectangle : enable - /*[EXTRA_CODE_HERE]*/ #define INDEXED 1 #define NON_INDEXED 2 #define NON_INDEXED_NO_COLOR 3 -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif uniform mat3 env_mat; uniform vec3 sun_dir; @@ -47,13 +41,13 @@ uniform vec3 moon_dir; uniform sampler2D diffuseMap; #endif -VARYING vec3 vary_fragcoord; -VARYING vec3 vary_position; -VARYING vec2 vary_texcoord0; -VARYING vec3 vary_norm; +in vec3 vary_fragcoord; +in vec3 vary_position; +in vec2 vary_texcoord0; +in vec3 vary_norm; #ifdef USE_VERTEX_COLOR -VARYING vec4 vertex_color; //vertex color should be treated as sRGB +in vec4 vertex_color; //vertex color should be treated as sRGB #endif #ifdef HAS_ALPHA_MASK @@ -195,7 +189,7 @@ void main() #endif #ifdef USE_DIFFUSE_TEX - vec4 diffuse_tap = texture2D(diffuseMap,vary_texcoord0.xy); + vec4 diffuse_tap = texture(diffuseMap,vary_texcoord0.xy); #endif #ifdef USE_INDEXED_TEX diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index cd7c005162..7b7b4a040c 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -214,7 +214,7 @@ void main() // emissiveColor is the emissive color factor from GLTF and is already in linear space vec3 colorEmissive = emissiveColor; // emissiveMap here is a vanilla RGB texture encoded as sRGB, manually convert to linear - colorEmissive *= srgb_to_linear(texture2D(emissiveMap, emissive_texcoord.xy).rgb); + colorEmissive *= srgb_to_linear(texture(emissiveMap, emissive_texcoord.xy).rgb); // PBR IBL float gloss = 1.0 - perceptualRoughness; @@ -305,7 +305,7 @@ void main() // emissiveColor is the emissive color factor from GLTF and is already in linear space vec3 colorEmissive = emissiveColor; // emissiveMap here is a vanilla RGB texture encoded as sRGB, manually convert to linear - colorEmissive *= srgb_to_linear(texture2D(emissiveMap, emissive_texcoord.xy).rgb); + colorEmissive *= srgb_to_linear(texture(emissiveMap, emissive_texcoord.xy).rgb); float a = basecolor.a*vertex_color.a; diff --git a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl index 080f622155..60134a7f72 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl @@ -40,7 +40,7 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); vec3 env_vec = env_mat * refnormpersp; - glossenv = srgb_to_linear(textureCube(environmentMap, env_vec).rgb); + glossenv = srgb_to_linear(texture(environmentMap, env_vec).rgb); } void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv, @@ -63,7 +63,7 @@ void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); vec3 env_vec = env_mat * refnormpersp; - legacyenv = srgb_to_linear(textureCube(environmentMap, env_vec).rgb); + legacyenv = srgb_to_linear(texture(environmentMap, env_vec).rgb); glossenv = legacyenv; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl index 1e7ccb747a..d1db6dd943 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl @@ -23,11 +23,11 @@ * $/LicenseInfo$ */ -ATTRIBUTE vec3 position; +in vec3 position; uniform vec2 screen_res; -VARYING vec2 vary_fragcoord; +out vec2 vary_fragcoord; // forwards void setAtmosAttenuation(vec3 c); diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl index e1cbfcce1a..1ea57516a4 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl @@ -23,20 +23,14 @@ * $/LicenseInfo$ */ -#extension GL_ARB_texture_rectangle : enable - /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif //class 2, shadows, no SSAO // Inputs -VARYING vec2 vary_fragcoord; +in vec2 vary_fragcoord; uniform vec3 sun_dir; uniform float shadow_bias; diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl index 99a26a050d..0126e09d4c 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl @@ -22,20 +22,14 @@ * $/LicenseInfo$ */ -#extension GL_ARB_texture_rectangle : enable - /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif //class 2 -- shadows and SSAO // Inputs -VARYING vec2 vary_fragcoord; +in vec2 vary_fragcoord; vec4 getPosition(vec2 pos_screen); vec3 getNorm(vec2 pos_screen); diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightV.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightV.glsl index 3dfca0f655..5ae7f2c571 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightV.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightV.glsl @@ -23,9 +23,9 @@ * $/LicenseInfo$ */ -ATTRIBUTE vec3 position; +in vec3 position; -VARYING vec2 vary_fragcoord; +out vec2 vary_fragcoord; uniform vec2 screen_res; diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl index 4c418e414f..3773f191e8 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl @@ -23,7 +23,7 @@ * $/LicenseInfo$ */ -// VARYING param funcs +// out param funcs uniform vec3 sun_dir; diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl index 07733bda18..34669a6796 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl @@ -24,8 +24,8 @@ */ -VARYING vec3 vary_AdditiveColor; -VARYING vec3 vary_AtmosAttenuation; +in vec3 vary_AdditiveColor; +in vec3 vary_AtmosAttenuation; vec3 getSunlitColor() { diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl index 31109aed31..1b854d80b3 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl @@ -24,8 +24,8 @@ */ -VARYING vec3 vary_AdditiveColor; -VARYING vec3 vary_AtmosAttenuation; +out vec3 vary_AdditiveColor; +out vec3 vary_AtmosAttenuation; vec3 additive_color; vec3 atmos_attenuation; diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterF.glsl index 22e16b7e0f..7a6741fe0e 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterF.glsl @@ -23,9 +23,9 @@ * $/LicenseInfo$ */ -VARYING vec3 vary_PositionEye; -VARYING vec3 vary_AdditiveColor; -VARYING vec3 vary_AtmosAttenuation; +in vec3 vary_PositionEye; +in vec3 vary_AdditiveColor; +in vec3 vary_AtmosAttenuation; vec3 getSunlitColor() { diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterV.glsl index 0f2a3ee527..23c3aed4d8 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterV.glsl @@ -23,9 +23,9 @@ * $/LicenseInfo$ */ -VARYING vec3 vary_PositionEye; -VARYING vec3 vary_AdditiveColor; -VARYING vec3 vary_AtmosAttenuation; +out vec3 vary_PositionEye; +out vec3 vary_AdditiveColor; +out vec3 vary_AtmosAttenuation; vec3 atmos_attenuation; vec3 sunlit_color; -- cgit v1.2.3 From c12712aa9609325ba3247a67354e91e9342106d6 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Thu, 25 May 2023 13:09:03 -0500 Subject: DRTVWR-559 Fix for off-color fullbright alpha blinn-phong materials. Scrub some NaNs. --- indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index 7b7b4a040c..e6aef7abdc 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -258,7 +258,7 @@ void main() glare = min(glare, 1.0); a = max(a, glare); - frag_color = vec4(color.rgb,a); + frag_color = max(vec4(color.rgb,a), vec4(0)); } #else @@ -311,7 +311,7 @@ void main() float a = basecolor.a*vertex_color.a; color += colorEmissive; color = linear_to_srgb(color); - frag_color = vec4(color.rgb,a); + frag_color = max(vec4(color.rgb,a), vec4(0)); } #endif -- cgit v1.2.3 From cbd17fce86cc30434d6d665338a7d771bddcad8b Mon Sep 17 00:00:00 2001 From: Rye Mutt Date: Thu, 25 May 2023 16:09:22 -0400 Subject: Fix underwater fog mismatch between opaque and alpha blend when local lights are nearby (#227) * Fix water fog mismatch between alpha blend and opaque when local light is nearby * Add PBR underwater alpha blend shader --- indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl | 9 ++++----- .../newview/app_settings/shaders/class2/deferred/pbralphaF.glsl | 9 +++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl index ae8cd97b18..cd57b47eae 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl @@ -274,6 +274,10 @@ void main() color.rgb = atmosFragLightingLinear(color.rgb, additive, atten); +#ifdef WATER_FOG + color = applyWaterFogViewLinear(pos.xyz, color, sunlit_linear); +#endif // WATER_FOG + vec4 light = vec4(0,0,0,0); #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diffuse_linear.rgb, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, light_attenuation[i].w); @@ -291,11 +295,6 @@ void main() color.rgb += light.rgb; #endif // !defined(LOCAL_LIGHT_KILL) - -#ifdef WATER_FOG - color = applyWaterFogViewLinear(pos.xyz, color, sunlit_linear); -#endif // WATER_FOG - #endif // #else // FOR_IMPOSTOR #ifdef IS_HUD diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index e6aef7abdc..9ac106149e 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -84,6 +84,10 @@ vec3 linear_to_srgb(vec3 c); void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); vec3 atmosFragLightingLinear(vec3 color, vec3 additive, vec3 atten); +#ifdef WATER_FOG +vec4 applyWaterFogViewLinear(vec3 pos, vec4 color, vec3 sunlit); +#endif + void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist); float calcLegacyDistanceAttenuation(float distance, float falloff); float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); @@ -237,6 +241,11 @@ void main() color.rgb = atmosFragLightingLinear(color.rgb, additive, atten); +#ifdef WATER_FOG + vec4 temp = applyWaterFogViewLinear(pos, vec4(color, 0.0), sunlit_linear); + color = temp.rgb; +#endif + vec3 light = vec3(0); // Punctual lights -- cgit v1.2.3 From 50ec54831de88926ca13c9a72d89006ceda6c355 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Thu, 1 Jun 2023 19:49:23 -0500 Subject: DRTVWR-559 Revert skies to be very close to release and disable tone mapping when probe ambiance is zero. Hack for desaturating legacy materials has been removed for performance and quality reasons. Adds a new setting for auto adjusting legacy skies. This is the PBR "opt out" button. If disabled, legacy skies will disable tonemapping, automatic probe ambiance, and HDR/exposure. If enabled, legacy skies will behave as if probe ambiance and HDR scale are 1.0, and ambient will be cut in half. HDR scale will act as a sky brightener, but will automatically adjust dynamic exposure so the sky will be properly exposed. If you want relatively even exposure all the time, set HDR Scale to 1.0. If you want a high range of exposures between indoor/dark areas and outdoor/bright areas, increase HDR Scale. Also tuned up SSAO (thanks Rye!). Reviewed with Brad. --- .../shaders/class2/windlight/atmosphericsF.glsl | 54 ------- .../class2/windlight/atmosphericsFuncs.glsl | 178 --------------------- .../class2/windlight/atmosphericsHelpersF.glsl | 44 ----- .../class2/windlight/atmosphericsHelpersV.glsl | 57 ------- .../shaders/class2/windlight/atmosphericsV.glsl | 56 ------- .../class2/windlight/atmosphericsVarsF.glsl | 48 ------ .../class2/windlight/atmosphericsVarsV.glsl | 84 ---------- .../class2/windlight/atmosphericsVarsWaterF.glsl | 50 ------ .../class2/windlight/atmosphericsVarsWaterV.glsl | 81 ---------- .../shaders/class2/windlight/gammaF.glsl | 55 ------- 10 files changed, 707 deletions(-) delete mode 100644 indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl delete mode 100644 indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl delete mode 100644 indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl delete mode 100644 indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl delete mode 100644 indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl delete mode 100644 indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl delete mode 100644 indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl delete mode 100644 indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterF.glsl delete mode 100644 indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterV.glsl delete mode 100644 indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl deleted file mode 100644 index e314555ef9..0000000000 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ /dev/null @@ -1,54 +0,0 @@ -/** - * @file class2\wl\atmosphericsF.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$ - */ - -vec3 getAdditiveColor(); -vec3 getAtmosAttenuation(); -vec3 scaleSoftClipFrag(vec3 light); - -vec3 srgb_to_linear(vec3 col); -vec3 linear_to_srgb(vec3 col); - -uniform int sun_up_factor; - -vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) -{ - light *= atten.r; - additive = srgb_to_linear(additive*2.0); - // magic 1.25 here is to match the default RenderSkyHDRScale -- this parameter needs to be plumbed into sky settings or something - // so it's available to all shaders that call atmosFragLighting instead of just softenLightF.glsl - additive *= sun_up_factor*1.25 + 1.0; - light += additive; - return light; -} - -vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten) -{ - return atmosFragLighting(light, additive, atten); -} - -vec3 atmosLighting(vec3 light) -{ - return atmosFragLighting(light, getAdditiveColor(), getAtmosAttenuation()); -} diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl deleted file mode 100644 index 4e0933f922..0000000000 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsFuncs.glsl +++ /dev/null @@ -1,178 +0,0 @@ -/** - * @file class2\windlight\atmosphericsFuncs.glsl - * - * $LicenseInfo:firstyear=2022&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2022, 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 vec3 lightnorm; -uniform vec3 sunlight_color; -uniform vec3 sunlight_linear; -uniform vec3 moonlight_color; -uniform vec3 moonlight_linear; -uniform int sun_up_factor; -uniform vec3 ambient_color; -uniform vec3 ambient_linear; -uniform vec3 blue_horizon; -uniform vec3 blue_horizon_linear; -uniform vec3 blue_density; -uniform vec3 blue_density_linear; -uniform float haze_horizon; -uniform float haze_density; -uniform float haze_density_linear; -uniform float cloud_shadow; -uniform float density_multiplier; -uniform float distance_multiplier; -uniform float max_y; -uniform vec3 glow; -uniform float scene_light_strength; -uniform mat3 ssao_effect_mat; -uniform float sun_moon_glow_factor; - -float getAmbientClamp() { return 1.0f; } - -vec3 srgb_to_linear(vec3 col); -vec3 legacy_adjust(vec3 col); - -// return colors in sRGB space -void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, - out vec3 atten, bool use_ao) -{ - vec3 rel_pos = inPositionEye; - - //(TERRAIN) limit altitude - if (abs(rel_pos.y) > max_y) rel_pos *= (max_y / rel_pos.y); - - vec3 rel_pos_norm = normalize(rel_pos); - float rel_pos_len = length(rel_pos); - - vec3 sunlight = (sun_up_factor == 1) ? sunlight_color: moonlight_color * 0.7; // magic 0.7 to match legacy color - - // sunlight attenuation effect (hue and brightness) due to atmosphere - // this is used later for sunlight modulation at various altitudes - vec3 light_atten = (blue_density + vec3(haze_density * 0.25)) * (density_multiplier * max_y); - // I had thought blue_density and haze_density should have equal weighting, - // but attenuation due to haze_density tends to seem too strong - - vec3 combined_haze = blue_density + vec3(haze_density); - vec3 blue_weight = blue_density / combined_haze; - vec3 haze_weight = vec3(haze_density) / combined_haze; - - //(TERRAIN) compute sunlight from lightnorm y component. Factor is roughly cosecant(sun elevation) (for short rays like terrain) - float above_horizon_factor = 1.0 / max(1e-6, lightnorm.y); - sunlight *= exp(-light_atten * above_horizon_factor); // for sun [horizon..overhead] this maps to an exp curve [0..1] - - // main atmospheric scattering line integral - float density_dist = rel_pos_len * density_multiplier; - - // Transparency (-> combined_haze) - // ATI Bugfix -- can't store combined_haze*density_dist*distance_multiplier in a variable because the ati - // compiler gets confused. - combined_haze = exp(-combined_haze * density_dist * distance_multiplier); - - // final atmosphere attenuation factor - atten = combined_haze.rgb; - - // compute haze glow - float haze_glow = dot(rel_pos_norm, lightnorm.xyz); - - // dampen sun additive contrib when not facing it... - // SL-13539: This "if" clause causes an "additive" white artifact at roughly 77 degreees. - // if (length(light_dir) > 0.01) - haze_glow *= max(0.0f, dot(light_dir, rel_pos_norm)); - - haze_glow = 1. - haze_glow; - // haze_glow is 0 at the sun and increases away from sun - haze_glow = max(haze_glow, .001); // set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - haze_glow *= glow.x; - // higher glow.x gives dimmer glow (because next step is 1 / "angle") - haze_glow = pow(haze_glow, glow.z); - // glow.z should be negative, so we're doing a sort of (1 / "angle") function - - // add "minimum anti-solar illumination" - haze_glow += .25; - - haze_glow *= sun_moon_glow_factor; - - vec3 amb_color = ambient_color; - - // increase ambient when there are more clouds - vec3 tmpAmbient = amb_color + (vec3(1.) - amb_color) * cloud_shadow * 0.5; - - /* decrease value and saturation (that in HSV, not HSL) for occluded areas - * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html - * // The following line of code performs the equivalent of: - * float ambAlpha = tmpAmbient.a; - * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis - * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); - * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, - * ambAlpha); - */ - if (use_ao) - { - tmpAmbient = mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor); - } - - // Similar/Shared Algorithms: - // indra\llinventory\llsettingssky.cpp -- LLSettingsSky::calculateLightSettings() - // indra\newview\app_settings\shaders\class1\windlight\atmosphericsFuncs.glsl -- calcAtmosphericVars() - // haze color - vec3 cs = sunlight.rgb * (1. - cloud_shadow); - additive = (blue_horizon.rgb * blue_weight.rgb) * (cs + tmpAmbient.rgb) + (haze_horizon * haze_weight.rgb) * (cs * haze_glow + tmpAmbient.rgb); - - // brightness of surface both sunlight and ambient - - sunlit = sunlight.rgb; - amblit = vec3(1,0,1); //should no longer be used, filled in by calcAtmosphericVarsLinear - - additive *= vec3(1.0 - combined_haze); -} - -vec3 srgb_to_linear(vec3 col); - -// provide a touch of lighting in the opposite direction of the sun light - // so areas in shadow don't lose all detail -float ambientLighting(vec3 norm, vec3 light_dir) -{ - float ambient = min(abs(dot(norm.xyz, light_dir.xyz)), 1.0); - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0 - ambient); - return ambient; -} - - -// return lit amblit in linear space, leave sunlit and additive in sRGB space -void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 additive, - out vec3 atten) -{ - calcAtmosphericVars(inPositionEye, light_dir, 1.0, sunlit, amblit, additive, atten, false); - - // multiply by 2 to get same colors as when the "scaleSoftClip" implementation was doubling color values - // (allows for mixing of light sources other than sunlight e.g. reflection probes) - sunlit *= 2.0; - - // squash ambient to approximate whatever weirdness legacy atmospherics were doing - amblit = ambient_color; // * (1.0+sun_up_factor*0.3); - - amblit *= ambientLighting(norm, light_dir); - amblit = srgb_to_linear(amblit); -} diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl deleted file mode 100644 index 800d08047a..0000000000 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl +++ /dev/null @@ -1,44 +0,0 @@ -/** - * @file class2\wl\atmosphericsHelpersV.glsl - * - * $LicenseInfo:firstyear=2005&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2005, 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$ - */ - -// Output variables - -uniform float scene_light_strength; - -vec3 atmosFragAmbient(vec3 light, vec3 amblit) -{ - return amblit + light / 2.0; -} - -vec3 atmosFragAffectDirectionalLight(float lightIntensity, vec3 sunlit) -{ - return sunlit * lightIntensity; -} - -vec3 scaleDownLightFrag(vec3 light) -{ - return (light / scene_light_strength ); -} - diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl deleted file mode 100644 index 6ecbfaecb1..0000000000 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl +++ /dev/null @@ -1,57 +0,0 @@ -/** - * @file class2\wl\atmosphericsHelpersV.glsl - * - * $LicenseInfo:firstyear=2005&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2005, 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$ - */ - - - -// Output variables -vec3 getSunlitColor(); -vec3 getAmblitColor(); -vec3 getAdditiveColor(); -vec3 getAtmosAttenuation(); -vec3 getPositionEye(); - -uniform float scene_light_strength; - -vec3 atmosAmbient() -{ - return getAmblitColor(); -} - -vec3 atmosAffectDirectionalLight(float lightIntensity) -{ - return getSunlitColor() * lightIntensity; -} - -vec3 atmosGetDiffuseSunlightColor() -{ - return getSunlitColor(); -} - -vec3 scaleDownLight(vec3 light) -{ - return (light / scene_light_strength ); -} - - diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl deleted file mode 100644 index 3773f191e8..0000000000 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl +++ /dev/null @@ -1,56 +0,0 @@ -/** - * @file class2\wl\atmosphericsV.glsl - * - * $LicenseInfo:firstyear=2005&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2005, 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$ - */ - -// out param funcs - - -uniform vec3 sun_dir; -uniform vec3 moon_dir; -uniform int sun_up_factor; - -void setSunlitColor(vec3 v); -void setAmblitColor(vec3 v); -void setAdditiveColor(vec3 v); -void setAtmosAttenuation(vec3 v); -void setPositionEye(vec3 v); - -vec3 getAdditiveColor(); - -void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); - -void calcAtmospherics(vec3 inPositionEye) { - vec3 P = inPositionEye; - setPositionEye(P); - vec3 tmpsunlit = vec3(1); - vec3 tmpamblit = vec3(1); - vec3 tmpaddlit = vec3(1); - vec3 tmpattenlit = vec3(1); - vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - calcAtmosphericVars(inPositionEye, light_dir, 1, tmpsunlit, tmpamblit, tmpaddlit, tmpattenlit, false); - setSunlitColor(tmpsunlit); - setAmblitColor(tmpamblit); - setAdditiveColor(tmpaddlit); - setAtmosAttenuation(tmpattenlit); -} diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl deleted file mode 100644 index 34669a6796..0000000000 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl +++ /dev/null @@ -1,48 +0,0 @@ -/** - * @file class2\wl\atmosphericVarsF.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$ - */ - - -in vec3 vary_AdditiveColor; -in vec3 vary_AtmosAttenuation; - -vec3 getSunlitColor() -{ - return vec3(0,0,0); -} - -vec3 getAmblitColor() -{ - return vec3(0,0,0); -} - -vec3 getAdditiveColor() -{ - return vary_AdditiveColor; -} - -vec3 getAtmosAttenuation() -{ - return vec3(vary_AtmosAttenuation); -} diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl deleted file mode 100644 index 1b854d80b3..0000000000 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl +++ /dev/null @@ -1,84 +0,0 @@ -/** - * @file class2\wl\atmosphericVars.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$ - */ - - -out vec3 vary_AdditiveColor; -out vec3 vary_AtmosAttenuation; - -vec3 additive_color; -vec3 atmos_attenuation; -vec3 sunlit_color; -vec3 amblit_color; -vec3 position_eye; - -vec3 getSunlitColor() -{ - return sunlit_color; -} -vec3 getAmblitColor() -{ - return amblit_color; -} - -vec3 getAdditiveColor() -{ - return additive_color; -} -vec3 getAtmosAttenuation() -{ - return atmos_attenuation; -} - -vec3 getPositionEye() -{ - return position_eye; -} - -void setPositionEye(vec3 v) -{ - position_eye = v; -} - -void setSunlitColor(vec3 v) -{ - sunlit_color = v; -} - -void setAmblitColor(vec3 v) -{ - amblit_color = v; -} - -void setAdditiveColor(vec3 v) -{ - additive_color = v; - vary_AdditiveColor = v; -} - -void setAtmosAttenuation(vec3 v) -{ - atmos_attenuation = v; - vary_AtmosAttenuation = v; -} diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterF.glsl deleted file mode 100644 index 7a6741fe0e..0000000000 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterF.glsl +++ /dev/null @@ -1,50 +0,0 @@ -/** - * @file class2\wl\atmosphericVarsWaterF.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$ - */ - -in vec3 vary_PositionEye; -in vec3 vary_AdditiveColor; -in vec3 vary_AtmosAttenuation; - -vec3 getSunlitColor() -{ - return vec3(0,0,0); -} -vec3 getAmblitColor() -{ - return vec3(0,0,0); -} -vec3 getAdditiveColor() -{ - return vary_AdditiveColor; -} -vec3 getAtmosAttenuation() -{ - return vary_AtmosAttenuation; -} -vec3 getPositionEye() -{ - return vary_PositionEye; -} - diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterV.glsl deleted file mode 100644 index 23c3aed4d8..0000000000 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterV.glsl +++ /dev/null @@ -1,81 +0,0 @@ -/** - * @file class2\wl\atmosphericVarsWaterV.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$ - */ - -out vec3 vary_PositionEye; -out vec3 vary_AdditiveColor; -out vec3 vary_AtmosAttenuation; - -vec3 atmos_attenuation; -vec3 sunlit_color; -vec3 amblit_color; - -vec3 getSunlitColor() -{ - return sunlit_color; -} -vec3 getAmblitColor() -{ - return amblit_color; -} - -vec3 getAdditiveColor() -{ - return vary_AdditiveColor; -} -vec3 getAtmosAttenuation() -{ - return atmos_attenuation; -} - -vec3 getPositionEye() -{ - return vary_PositionEye; -} - -void setPositionEye(vec3 v) -{ - vary_PositionEye = v; -} - -void setSunlitColor(vec3 v) -{ - sunlit_color = v; -} - -void setAmblitColor(vec3 v) -{ - amblit_color = v; -} - -void setAdditiveColor(vec3 v) -{ - vary_AdditiveColor = v; -} - -void setAtmosAttenuation(vec3 v) -{ - atmos_attenuation = v; - vary_AtmosAttenuation = v; -} diff --git a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl deleted file mode 100644 index 027bfb866f..0000000000 --- a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl +++ /dev/null @@ -1,55 +0,0 @@ -/** - * @file class2\wl\gammaF.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$ - */ - - // DEPRECATED - -//soft clip effect has been moved to postDeferredGammaCorrect legacyGamma, this file is effectively dead -// but these functions need to be removed from all existing shaders before removing this file - -vec3 scaleSoftClipFrag(vec3 light) -{ - return light; -} - -vec3 scaleSoftClipFragLinear(vec3 light) -{ // identical to non-linear version and that's probably close enough - return light; -} - -vec3 scaleSoftClip(vec3 light) -{ - return light; -} - -vec3 fullbrightScaleSoftClipFrag(vec3 light, vec3 add, vec3 atten) -{ - return light; -} - -vec3 fullbrightScaleSoftClip(vec3 light) -{ - return light; -} - -- cgit v1.2.3 From b0540f8189d28da66c143c5de961deaba7a86f17 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Thu, 1 Jun 2023 20:15:35 -0500 Subject: DRTVWR-559 Rebalance PBR against Blinn-Phong. --- indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index 9ac106149e..d678973515 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -152,7 +152,7 @@ vec3 calcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, // spot*spot => GL_SPOT_EXPONENT=2 float spot_atten = spot*spot; - vec3 intensity = spot_atten * dist_atten * lightColor * 3.9; //magic number to balance with legacy materials + vec3 intensity = spot_atten * dist_atten * lightColor * 3.0; //magic number to balance with legacy materials vec3 speccol; color = intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, lv, speccol); -- cgit v1.2.3 From 3581c81328f4a34f62ca867f3052115ef590a6b6 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Wed, 14 Jun 2023 05:35:34 -0700 Subject: More performance addressing. Ditch glossy SSR on semi-transparent surfaces. SL-19784 --- indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl | 4 ++-- indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl | 4 ++-- .../app_settings/shaders/class2/deferred/reflectionProbeF.glsl | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl index cd57b47eae..da5f997429 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl @@ -85,7 +85,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); float getAmbientClamp(); void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity); + vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity, bool transparent); vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, float ambiance) { @@ -251,7 +251,7 @@ void main() vec3 irradiance; vec3 glossenv; vec3 legacyenv; - sampleReflectionProbesLegacy(irradiance, glossenv, legacyenv, frag, pos.xyz, norm.xyz, 0.0, 0.0); + sampleReflectionProbesLegacy(irradiance, glossenv, legacyenv, frag, pos.xyz, norm.xyz, 0.0, 0.0, true); 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 d678973515..e8db856b1f 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -92,7 +92,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, - vec2 tc, vec3 pos, vec3 norm, float glossiness); + vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent); void waterClip(vec3 pos); @@ -224,7 +224,7 @@ void main() float gloss = 1.0 - perceptualRoughness; vec3 irradiance = vec3(0); vec3 radiance = vec3(0); - sampleReflectionProbes(irradiance, radiance, vary_position.xy*0.5+0.5, pos.xyz, norm.xyz, gloss); + sampleReflectionProbes(irradiance, radiance, vary_position.xy*0.5+0.5, pos.xyz, norm.xyz, gloss, true); // 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 60134a7f72..719319004d 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, - vec2 tc, vec3 pos, vec3 norm, float glossiness) + vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent) { ambenv = vec3(reflection_probe_ambiance * 0.25); @@ -46,7 +46,7 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv, vec2 tc, vec3 pos, vec3 norm, float glossiness) { - sampleReflectionProbes(ambenv, glossenv, tc, pos, norm, glossiness); + sampleReflectionProbes(ambenv, glossenv, tc, pos, norm, glossiness, true); } vec4 sampleReflectionProbesDebug(vec3 pos) @@ -56,7 +56,7 @@ vec4 sampleReflectionProbesDebug(vec3 pos) } void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity) + vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity, bool transparent) { ambenv = vec3(reflection_probe_ambiance * 0.25); -- cgit v1.2.3 From 22f83b3436129e3198fcdd24ccb30baf253955c7 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Thu, 15 Jun 2023 09:01:39 -0700 Subject: Add missing variable initialization, and make water support glossy SSR again. SL-19784 --- .../newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl index 719319004d..aa6f5a3b62 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl @@ -46,7 +46,7 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv, vec2 tc, vec3 pos, vec3 norm, float glossiness) { - sampleReflectionProbes(ambenv, glossenv, tc, pos, norm, glossiness, true); + sampleReflectionProbes(ambenv, glossenv, tc, pos, norm, glossiness, false); } vec4 sampleReflectionProbesDebug(vec3 pos) -- cgit v1.2.3 From 43cd4e84bc01abcf2820b9557abe761fbf5e8432 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Wed, 6 Sep 2023 10:31:03 -0500 Subject: SL-19842 WIP -- Change how probe ambiance mixes with sky ambient. --- indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl | 6 +++--- .../newview/app_settings/shaders/class2/deferred/pbralphaF.glsl | 9 +++------ .../app_settings/shaders/class2/deferred/reflectionProbeF.glsl | 8 ++++---- 3 files changed, 10 insertions(+), 13 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl index da5f997429..3a251af240 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl @@ -85,7 +85,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); float getAmbientClamp(); void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity, bool transparent); + vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity, bool transparent, vec3 amblit_linear); vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, float ambiance) { @@ -251,7 +251,7 @@ void main() vec3 irradiance; vec3 glossenv; vec3 legacyenv; - sampleReflectionProbesLegacy(irradiance, glossenv, legacyenv, frag, pos.xyz, norm.xyz, 0.0, 0.0, true); + sampleReflectionProbesLegacy(irradiance, glossenv, legacyenv, frag, pos.xyz, norm.xyz, 0.0, 0.0, true, amblit_linear); float da = dot(norm.xyz, light_dir.xyz); @@ -266,7 +266,7 @@ void main() vec3 sun_contrib = min(final_da, shadow) * sunlit_linear; - color.rgb = max(amblit, irradiance); + color.rgb = irradiance; color.rgb += sun_contrib; diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index e8db856b1f..be66b6feb2 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -92,7 +92,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, - vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent); + vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent, vec3 amblit_linear); void waterClip(vec3 pos); @@ -224,11 +224,8 @@ void main() float gloss = 1.0 - perceptualRoughness; vec3 irradiance = vec3(0); vec3 radiance = vec3(0); - sampleReflectionProbes(irradiance, radiance, vary_position.xy*0.5+0.5, pos.xyz, norm.xyz, gloss, true); - // 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); - + sampleReflectionProbes(irradiance, radiance, vary_position.xy*0.5+0.5, pos.xyz, norm.xyz, gloss, true, amblit); + vec3 diffuseColor; vec3 specularColor; calcDiffuseSpecular(col.rgb, metallic, diffuseColor, specularColor); diff --git a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl index aa6f5a3b62..52e71edcac 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, - vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent) + vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent, vec3 amblit_linear) { ambenv = vec3(reflection_probe_ambiance * 0.25); @@ -44,9 +44,9 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, } void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness) + vec2 tc, vec3 pos, vec3 norm, float glossiness, vec3 amblit_linear) { - sampleReflectionProbes(ambenv, glossenv, tc, pos, norm, glossiness, false); + sampleReflectionProbes(ambenv, glossenv, tc, pos, norm, glossiness, false, amblit_linear); } vec4 sampleReflectionProbesDebug(vec3 pos) @@ -56,7 +56,7 @@ vec4 sampleReflectionProbesDebug(vec3 pos) } void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity, bool transparent) + vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity, bool transparent, vec3 amblit_linear) { ambenv = vec3(reflection_probe_ambiance * 0.25); -- cgit v1.2.3 From 41433fdb08b50e4721b2285a045cc8f14e82433c Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Mon, 2 Oct 2023 15:16:53 -0500 Subject: SL-20394 Remove "glare" effect from PBR alpha shaders. --- .../shaders/class2/deferred/pbralphaF.glsl | 23 ++++++---------------- 1 file changed, 6 insertions(+), 17 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index be66b6feb2..35d752be02 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -112,16 +112,14 @@ vec3 pbrBaseLight(vec3 diffuseColor, vec3 colorEmissive, float ao, vec3 additive, - vec3 atten, - out vec3 specContrib); + vec3 atten); vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, float perceptualRoughness, float metallic, vec3 n, // normal vec3 v, // surface point to camera - vec3 l, //surface point to light - out vec3 specContrib); + vec3 l); //surface point to light vec3 calcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, float perceptualRoughness, @@ -132,7 +130,7 @@ vec3 calcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, vec3 lp, // light position vec3 ld, // light direction (for spotlights) vec3 lightColor, - float lightSize, float falloff, float is_pointlight, inout float glare, float ambiance) + float lightSize, float falloff, float is_pointlight, float ambiance) { vec3 color = vec3(0,0,0); @@ -154,10 +152,7 @@ vec3 calcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, vec3 intensity = spot_atten * dist_atten * lightColor * 3.0; //magic number to balance with legacy materials - vec3 speccol; - color = intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, lv, speccol); - speccol *= intensity; - glare += max(max(speccol.r, speccol.g), speccol.b); + color = intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, lv); } return color; @@ -166,7 +161,6 @@ vec3 calcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, void main() { vec3 color = vec3(0,0,0); - float glare = 0.0; vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; vec3 pos = vary_position; @@ -232,9 +226,7 @@ void main() vec3 v = -normalize(pos.xyz); - vec3 spec; - color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit_linear, scol, radiance, irradiance, colorEmissive, ao, additive, atten, spec); - glare += max(max(spec.r, spec.g), spec.b); + color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit_linear, scol, radiance, irradiance, colorEmissive, ao, additive, atten); color.rgb = atmosFragLightingLinear(color.rgb, additive, atten); @@ -246,7 +238,7 @@ void main() vec3 light = vec3(0); // Punctual lights -#define LIGHT_LOOP(i) light += calcPointLightOrSpotLight(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, pos.xyz, v, light_position[i].xyz, light_direction[i].xyz, light_diffuse[i].rgb, light_deferred_attenuation[i].x, light_deferred_attenuation[i].y, light_attenuation[i].z, glare, light_attenuation[i].w); +#define LIGHT_LOOP(i) light += calcPointLightOrSpotLight(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, pos.xyz, v, light_position[i].xyz, light_direction[i].xyz, light_diffuse[i].rgb, light_deferred_attenuation[i].x, light_deferred_attenuation[i].y, light_attenuation[i].z, light_attenuation[i].w); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -261,9 +253,6 @@ void main() float a = basecolor.a*vertex_color.a; - glare = min(glare, 1.0); - a = max(a, glare); - frag_color = max(vec4(color.rgb,a), vec4(0)); } -- cgit v1.2.3 From 478703e3c82df7b5751d80007264468bf44cb379 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Wed, 11 Oct 2023 14:20:47 -0500 Subject: SL-20440 Fix for projector ambiance destroying PBR shading. Also fix longstanding bug with hard line in projector ambiance lighting. Incidental decruft of legacy_adjust and LOCAL_LIGHT_KILL, etc. --- indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl | 4 ---- 1 file changed, 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class2') diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl index 3a251af240..b63f3b60f9 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl @@ -71,7 +71,6 @@ vec4 applyWaterFogViewLinear(vec3 pos, vec4 color, vec3 sunlit); vec3 srgb_to_linear(vec3 c); vec3 linear_to_srgb(vec3 c); -vec3 legacy_adjust(vec3 c); vec2 encode_normal (vec3 n); vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten); @@ -234,7 +233,6 @@ void main() } diffuse_srgb.rgb *= vertex_color.rgb; - diffuse_srgb.rgb = legacy_adjust(diffuse_srgb.rgb); diffuse_linear.rgb = srgb_to_linear(diffuse_srgb.rgb); #endif // USE_VERTEX_COLOR @@ -291,9 +289,7 @@ void main() LIGHT_LOOP(7) // sum local light contrib in linear colorspace -#if !defined(LOCAL_LIGHT_KILL) color.rgb += light.rgb; -#endif // !defined(LOCAL_LIGHT_KILL) #endif // #else // FOR_IMPOSTOR -- cgit v1.2.3