diff options
author | Jonathan "Geenz" Goodman <geenz@geenzo.com> | 2023-04-12 15:18:27 -0700 |
---|---|---|
committer | Jonathan "Geenz" Goodman <geenz@geenzo.com> | 2023-04-12 15:18:27 -0700 |
commit | 6d5c16971654764de28833fd886f522212d3746d (patch) | |
tree | 977b913112505d09966133857c9a92fd07629431 /indra/newview/app_settings/shaders | |
parent | 58df456675f37146d9a6cdaaf75c0f2b93f234c6 (diff) | |
parent | d6b99cff8ab7550b5e0316c831087050f19c91c6 (diff) |
Merge branch 'DRTVWR-559' into DRTVWR-559-post-refactor
Diffstat (limited to 'indra/newview/app_settings/shaders')
15 files changed, 126 insertions, 31 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl b/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl index 7ed8e4c8ce..81f1e9aed0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl @@ -48,8 +48,11 @@ void main() vec2 tc = vec2(0.5,0.5); float L = textureLod(emissiveRect, tc, 8).r; - - float s = clamp(dynamic_exposure_params.x/L, dynamic_exposure_params.y, dynamic_exposure_params.z); + float max_L = dynamic_exposure_params.x; + L = clamp(L, 0.0, max_L); + L /= max_L; + L = pow(L, 2.0); + float s = mix(dynamic_exposure_params.z, dynamic_exposure_params.y, L); float prev = texture(exposureMap, vec2(0.5,0.5)).r; diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index b5eae3a1d5..11532135dd 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -42,6 +42,7 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); #endif vec3 srgb_to_linear(vec3 cs); +vec3 legacy_adjust(vec3 c); vec3 linear_to_srgb(vec3 cl); vec3 fullbrightAtmosTransport(vec3 light); @@ -87,6 +88,7 @@ void main() #endif #ifndef IS_HUD + color.rgb = legacy_adjust(color.rgb); color.rgb = srgb_to_linear(color.rgb); color.rgb = fullbrightAtmosTransport(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl index e63e666778..ee425f97fc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl @@ -44,9 +44,9 @@ float lum(vec3 col) void main() { vec2 tc = vary_fragcoord*0.6+0.2; + tc.y -= 0.1; // HACK - nudge exposure sample down a little bit to favor ground over sky vec3 c = texture(diffuseRect, tc).rgb + texture(emissiveRect, tc).rgb; float L = lum(c); - frag_color = vec4(L); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index ae6bdbba95..de766d6bc7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -105,29 +105,21 @@ vec3 toneMapACES_Hill(vec3 color) uniform float exposure; uniform float gamma; +vec3 legacy_adjust_post(vec3 c); + vec3 toneMap(vec3 color, float gs) { float exp_scale = texture(exposureMap, vec2(0.5,0.5)).r; color *= exposure * exp_scale * gs; -#ifdef TONEMAP_ACES_NARKOWICZ - color = toneMapACES_Narkowicz(color); -#endif - -#ifdef TONEMAP_ACES_HILL color = toneMapACES_Hill(color); -#endif -#ifdef TONEMAP_ACES_HILL_EXPOSURE_BOOST - // boost exposure as discussed in https://github.com/mrdoob/three.js/pull/19621 - // this factor is based on the exposure correction of Krzysztof Narkowicz in his - // implemetation of ACES tone mapping - color *= 1.0/0.6; - color = toneMapACES_Hill(color); -#endif + color = linear_to_srgb(color); - return linear_to_srgb(color); + color = legacy_adjust_post(color); + + return color; } //=============================================================== @@ -181,7 +173,7 @@ vec3 legacyGamma(vec3 color) float legacyGammaApprox() { - //TODO -- figure out how to plumb this in as a uniform + //TODO -- figure out how to plumb this in as a uniform float c = 0.5; float gc = 1.0-pow(c, gamma); diff --git a/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl b/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl index 4a8b892c3a..3cca84ca14 100644 --- a/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl @@ -72,7 +72,7 @@ vec3 rgb2hsv(vec3 c) vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); float d = q.x - min(q.w, q.y); - float e = 1.0e-10; + float e = 1.0e-3; return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); } @@ -82,3 +82,25 @@ vec3 hsv2rgb(vec3 c) vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); } + +vec3 legacy_adjust_no_brighten(vec3 c) +{ + vec3 desat = rgb2hsv(c.rgb); + desat.g *= 0.75; + desat.rgb = hsv2rgb(desat); + return desat; +} + +vec3 legacy_adjust(vec3 c) +{ + vec3 desat = rgb2hsv(c.rgb); + desat.g *= 1.0-(1.0-desat.b)*0.5; + desat.b += (1.0-desat.b)*0.1f; + desat.rgb = hsv2rgb(desat); + return desat; +} + +vec3 legacy_adjust_post(vec3 c) +{ + return c; +} 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); diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index 1aef971d3a..e5341386bd 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -44,9 +44,11 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 atmosFragLightingLinear(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFragLinear(vec3 l); void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); +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); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cs); +vec3 legacy_adjust(vec3 c); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) @@ -316,6 +318,7 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) //forward rendering, output lit linear color + diffcol.rgb = legacy_adjust(diffcol.rgb); diffcol.rgb = srgb_to_linear(diffcol.rgb); spec.rgb = srgb_to_linear(spec.rgb); spec.a = glossiness; // pack glossiness into spec alpha for lighting functions @@ -357,6 +360,7 @@ void main() float glare = 0.0; +#if 0 //wrong implementation if (glossiness > 0.0) // specular reflection { float sa = dot(normalize(refnormpersp), light_dir.xyz); @@ -373,6 +377,32 @@ void main() applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); } +#else //right implementation ported from pointLightF.glsl + if (glossiness > 0.0) + { + vec3 lv = light_dir.xyz; + vec3 h, l, v = -normalize(pos.xyz); + float nh, nl, nv, vh, lightDist; + vec3 n = norm.xyz; + calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); + + if (nl > 0.0 && nh > 0.0) + { + float lit = min(nl*6.0, 1.0); + + float sa = nh; + float fres = pow(1 - vh, 5) * 0.4+0.5; + float gtdenom = 2 * nh; + float gt = max(0,(min(gtdenom * nv / vh, gtdenom * nl / vh))); + + float scol = shadow*fres*texture2D(lightFunc, vec2(nh, glossiness)).r*gt/(nh*nl); + color.rgb += lit*scol*sunlit_linear.rgb*spec.rgb; + } + + // add radiance map + applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); + } +#endif color = mix(color.rgb, diffcol.rgb, emissive); @@ -381,7 +411,8 @@ void main() applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, env); float cur_glare = max(max(legacyenv.r, legacyenv.g), legacyenv.b); - cur_glare *= env*4.0; + cur_glare = clamp(cur_glare, 0, 1); + cur_glare *= env; glare += cur_glare; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 23ba95949a..5a2924afe5 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -58,6 +58,7 @@ vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensi vec2 getScreenXY(vec4 clip); vec2 getScreenCoord(vec4 clip); vec3 srgb_to_linear(vec3 c); +vec3 legacy_adjust(vec3 c); // Util vec3 hue_to_rgb(float hue); @@ -131,6 +132,7 @@ void main() } else { + diffuse.rgb = legacy_adjust(diffuse.rgb); diffuse = srgb_to_linear(diffuse); spec.rgb = srgb_to_linear(spec.rgb); diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 30b7895157..33e5b2346c 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -83,6 +83,7 @@ vec3 getProjectedLightSpecularColor(vec3 pos, vec3 n); vec2 getScreenXY(vec4 clip); vec2 getScreenCoord(vec4 clip); vec3 srgb_to_linear(vec3 cs); +vec3 legacy_adjust(vec3 c); vec4 texture2DLodSpecular(vec2 tc, float lod); vec4 getPosition(vec2 pos_screen); @@ -182,7 +183,7 @@ void main() } else { - + diffuse = legacy_adjust(diffuse); diffuse = srgb_to_linear(diffuse); spec.rgb = srgb_to_linear(spec.rgb); diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index 30b96ce8dc..471e5e7fd3 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -63,6 +63,7 @@ vec4 getPosition(vec2 pos_screen); vec2 getScreenXY(vec4 clip); vec2 getScreenCoord(vec4 clip); vec3 srgb_to_linear(vec3 c); +vec3 legacy_adjust(vec3 c); float getDepth(vec2 tc); vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, @@ -121,7 +122,7 @@ void main() { discard; } - + diffuse = legacy_adjust(diffuse); diffuse = srgb_to_linear(diffuse); spec.rgb = srgb_to_linear(spec.rgb); diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index e1b18935e8..55a43f76d0 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -752,6 +752,8 @@ void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout legacyenv = mix(legacyenv, ssr.rgb, w); } #endif + + glossenv = clamp(glossenv, vec3(0), vec3(10)); } void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 norm) diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index e1206cc844..ab83708c7b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -83,15 +83,19 @@ float getDepth(vec2 pos_screen); vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); +vec3 legacy_adjust(vec3 c); uniform vec4 waterPlane; +uniform int cube_snapshot; + #ifdef WATER_FOG vec4 applyWaterFogViewLinear(vec3 pos, vec4 color); #endif uniform float sky_hdr_scale; +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); void calcDiffuseSpecular(vec3 baseColor, float metallic, inout vec3 diffuseColor, inout vec3 specularColor); vec3 pbrBaseLight(vec3 diffuseColor, @@ -207,12 +211,18 @@ void main() else if (!GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_ATMOS)) { //should only be true of WL sky, just port over base color value - color = srgb_to_linear(texture2D(emissiveRect, tc).rgb); - color *= sun_up_factor * sky_hdr_scale + 1.0; + color = texture2D(emissiveRect, tc).rgb; + color = srgb_to_linear(color); + if (sun_up_factor > 0) + { + color *= sky_hdr_scale + 1.0; + } } else { // legacy shaders are still writng sRGB to gbuffer + baseColor.rgb = legacy_adjust(baseColor.rgb); + baseColor.rgb = srgb_to_linear(baseColor.rgb); spec.rgb = srgb_to_linear(spec.rgb); @@ -236,6 +246,7 @@ void main() vec3 refnormpersp = reflect(pos.xyz, norm.xyz); +#if 0 // wrong implementation if (spec.a > 0.0) // specular reflection { float sa = dot(normalize(refnormpersp), light_dir.xyz); @@ -248,6 +259,32 @@ void main() // add radiance map applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); } +#else //right implementation (ported from pointLightF.glsl) + if (spec.a > 0.0) + { + vec3 lv = light_dir.xyz; + vec3 h, l, v = -normalize(pos.xyz); + float nh, nl, nv, vh, lightDist; + vec3 n = norm.xyz; + calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); + + if (nl > 0.0 && nh > 0.0) + { + float lit = min(nl*6.0, 1.0); + + float sa = nh; + float fres = pow(1 - vh, 5) * 0.4+0.5; + float gtdenom = 2 * nh; + float gt = max(0,(min(gtdenom * nv / vh, gtdenom * nl / vh))); + + scol *= fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*nl); + color.rgb += lit*scol*sunlit_linear.rgb*spec.rgb; + } + + // add radiance map + applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); + } +#endif color.rgb = mix(color.rgb, baseColor.rgb, baseColor.a); diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 33ea2129cf..3d06bb27a5 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -91,6 +91,7 @@ vec3 getProjectedLightSpecularColor(vec3 pos, vec3 n); vec2 getScreenXY(vec4 clip_point); vec2 getScreenCoord(vec4 clip_point); vec3 srgb_to_linear(vec3 c); +vec3 legacy_adjust(vec3 c); vec4 texture2DLodSpecular(vec2 tc, float lod); vec4 getPosition(vec2 pos_screen); @@ -189,6 +190,7 @@ void main() } else { + diffuse = legacy_adjust(diffuse); diffuse = srgb_to_linear(diffuse); spec.rgb = srgb_to_linear(spec.rgb); |