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/class1/deferred/deferredUtil.glsl | 9 ++-- .../shaders/class1/deferred/fullbrightF.glsl | 3 ++ .../class1/deferred/postDeferredGammaCorrect.glsl | 49 ++++++++-------------- 3 files changed, 23 insertions(+), 38 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl index 6ab966ae01..0b4a59c866 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -396,7 +396,7 @@ vec3 pbrIbl(vec3 diffuseColor, specContrib = specular * ao; - return (diffuse + specular*0.5) * ao; //reduce by half to place in appropriate color space for atmospherics + return (diffuse + specular) * ao; } vec3 pbrIbl(vec3 diffuseColor, @@ -562,16 +562,13 @@ vec3 pbrBaseLight(vec3 diffuseColor, vec3 specularColor, float metallic, vec3 v, float NdotV = clamp(abs(dot(norm, v)), 0.001, 1.0); vec3 ibl_spec; - color += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, 0.2, ibl_spec); + color += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, perceptualRoughness, ibl_spec); color += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm, v, normalize(light_dir), specContrib) * sunlit * 2.75 * scol; specContrib *= sunlit * 2.75 * scol; specContrib += ibl_spec; - color += colorEmissive*0.5; - - color = atmosFragLightingLinear(color, additive, atten); - color = scaleSoftClipFragLinear(color); + color += colorEmissive; //divide by two to correct for magical multiply by two in atmosFragLighting return color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index afe504743d..c406c669f2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -88,8 +88,11 @@ void main() #endif #ifndef IS_HUD + color.rgb = fullbrightAtmosTransport(color.rgb); + color.rgb = fullbrightScaleSoftClip(color.rgb); color.rgb = srgb_to_linear(color.rgb); #endif + frag_color.rgb = color.rgb; frag_color.a = color.a; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index cc77712347..383fcaa9a7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -44,9 +44,6 @@ vec3 linear_to_srgb(vec3 cl); //=============================================================== // tone mapping taken from Khronos sample implementation //=============================================================== -const float GAMMA = 2.2; -const float INV_GAMMA = 1.0 / GAMMA; - // sRGB => XYZ => D65_2_D60 => AP1 => RRT_SAT const mat3 ACESInputMat = mat3 @@ -65,29 +62,6 @@ const mat3 ACESOutputMat = mat3 -0.07367, -0.00605, 1.07602 ); - -// linear to sRGB approximation -// see http://chilliant.blogspot.com/2012/08/srgb-approximations-for-hlsl.html -vec3 linearTosRGB(vec3 color) -{ - return pow(color, vec3(INV_GAMMA)); -} - - -// sRGB to linear approximation -// see http://chilliant.blogspot.com/2012/08/srgb-approximations-for-hlsl.html -vec3 sRGBToLinear(vec3 srgbIn) -{ - return vec3(pow(srgbIn.xyz, vec3(GAMMA))); -} - - -vec4 sRGBToLinear(vec4 srgbIn) -{ - return vec4(sRGBToLinear(srgbIn.xyz), srgbIn.w); -} - - // ACES tone map (faster approximation) // see: https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/ vec3 toneMapACES_Narkowicz(vec3 color) @@ -128,13 +102,13 @@ vec3 toneMapACES_Hill(vec3 color) } uniform float exposure; +uniform float gamma; vec3 toneMap(vec3 color) { color *= exposure; #ifdef TONEMAP_ACES_NARKOWICZ - color *= 0.8; color = toneMapACES_Narkowicz(color); #endif @@ -146,11 +120,12 @@ vec3 toneMap(vec3 color) // 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 *= 0.85/0.6; + color *= 1.0/0.6; + //color /= 0.6; color = toneMapACES_Hill(color); #endif - return linearTosRGB(color); + return linear_to_srgb(color); } //=============================================================== @@ -193,16 +168,26 @@ float noise(vec2 x) { //============================= + +vec3 legacyGamma(vec3 color) +{ + color = 1. - clamp(color, vec3(0.), vec3(1.)); + color = 1. - pow(color, vec3(gamma)); // s/b inverted already CPU-side + + return color; +} + void main() { //this is the one of the rare spots where diffuseRect contains linear color values (not sRGB) vec4 diff = texture2D(diffuseRect, vary_fragcoord); diff.rgb = toneMap(diff.rgb); - vec2 tc = vary_fragcoord.xy*screen_res; - + diff.rgb = legacyGamma(diff.rgb); + + vec2 tc = vary_fragcoord.xy*screen_res*4.0; vec3 seed = (diff.rgb+vec3(1.0))*vec3(tc.xy, tc.x+tc.y); vec3 nz = vec3(noise(seed.rg), noise(seed.gb), noise(seed.rb)); - diff.rgb += nz*0.008; + diff.rgb += nz*0.003; //diff.rgb = nz; frag_color = diff; } -- 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. --- indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl | 4 ---- .../newview/app_settings/shaders/class1/deferred/deferredUtil.glsl | 3 +-- indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl | 7 ------- .../newview/app_settings/shaders/class1/deferred/fullbrightF.glsl | 1 - 4 files changed, 1 insertion(+), 14 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index cf9ce646d1..fe796a054d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -52,9 +52,6 @@ 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); @@ -119,7 +116,6 @@ void main() color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); color.rgb= max(vec3(0), color.rgb); color.rgb *= 2.0; - color.rgb = scaleSoftClip(color.rgb); /// Gamma correct for WL (soft clip effect). frag_data[0] = vec4(color.rgb, alpha1); diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl index 0b4a59c866..4bf16b50bf 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -74,7 +74,6 @@ const float ONE_OVER_PI = 0.3183098861; vec3 srgb_to_linear(vec3 cs); vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten); -vec3 scaleSoftClipFragLinear(vec3 light); float calcLegacyDistanceAttenuation(float distance, float falloff) { @@ -568,7 +567,7 @@ vec3 pbrBaseLight(vec3 diffuseColor, vec3 specularColor, float metallic, vec3 v, specContrib *= sunlit * 2.75 * scol; specContrib += ibl_spec; - color += colorEmissive; //divide by two to correct for magical multiply by two in atmosFragLighting + color += colorEmissive; return color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl b/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl index f0522850de..fb97cd95b4 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl @@ -27,14 +27,9 @@ /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif vec3 fullbrightAtmosTransport(vec3 light); -vec3 fullbrightScaleSoftClip(vec3 light); VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; @@ -46,8 +41,6 @@ void main() vec4 color = diffuseLookup(vary_texcoord0.xy)*vertex_color; color.rgb = fullbrightAtmosTransport(color.rgb); - color.rgb = fullbrightScaleSoftClip(color.rgb); - frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index c406c669f2..3a15fd1111 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -89,7 +89,6 @@ void main() #ifndef IS_HUD color.rgb = fullbrightAtmosTransport(color.rgb); - color.rgb = fullbrightScaleSoftClip(color.rgb); color.rgb = srgb_to_linear(color.rgb); #endif -- cgit v1.2.3 From 97b5f07edd077e9b451e874275e9ce49c134f841 Mon Sep 17 00:00:00 2001 From: Rye Mutt Date: Fri, 10 Mar 2023 09:28:35 -0500 Subject: This corrects tangents on blinn-phong surfaces to use proper mikkt calculation (#118) --- .../shaders/class1/deferred/materialV.glsl | 27 ++++++++++------------ 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl index a1cab87092..d41e0b202b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl @@ -59,9 +59,9 @@ ATTRIBUTE vec2 texcoord0; ATTRIBUTE vec4 tangent; ATTRIBUTE vec2 texcoord1; -VARYING vec3 vary_mat0; -VARYING vec3 vary_mat1; -VARYING vec3 vary_mat2; +out vec3 vary_tangent; +flat out float vary_sign; +out vec3 vary_normal; VARYING vec2 vary_texcoord1; #else @@ -111,24 +111,21 @@ void main() vec3 n = normalize((mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz); #ifdef HAS_NORMAL_MAP vec3 t = normalize((mat*vec4(tangent.xyz+position.xyz,1.0)).xyz-pos.xyz); - vec3 b = cross(n, t)*tangent.w; - - vary_mat0 = vec3(t.x, b.x, n.x); - vary_mat1 = vec3(t.y, b.y, n.y); - vary_mat2 = vec3(t.z, b.z, n.z); + + vary_tangent = t; + vary_sign = tangent.w; + vary_normal = n; #else //HAS_NORMAL_MAP -vary_normal = n; + vary_normal = n; #endif //HAS_NORMAL_MAP #else //HAS_SKIN vec3 n = normalize(normal_matrix * normal); #ifdef HAS_NORMAL_MAP vec3 t = normalize(normal_matrix * tangent.xyz); - vec3 b = cross(n,t)*tangent.w; - //vec3 t = cross(b,n) * binormal.w; - - vary_mat0 = vec3(t.x, b.x, n.x); - vary_mat1 = vec3(t.y, b.y, n.y); - vary_mat2 = vec3(t.z, b.z, n.z); + + vary_tangent = t; + vary_sign = tangent.w; + vary_normal = n; #else //HAS_NORMAL_MAP vary_normal = n; #endif //HAS_NORMAL_MAP -- cgit v1.2.3