diff options
Diffstat (limited to 'indra/newview/app_settings/shaders')
33 files changed, 862 insertions, 483 deletions
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 e71d080fc5..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) { @@ -383,7 +382,8 @@ vec3 pbrIbl(vec3 diffuseColor, vec3 irradiance, // irradiance map sample float ao, // ambient occlusion factor float nv, // normal dot view vector - float perceptualRough) + float perceptualRough, + out vec3 specContrib) { // retrieve a scale and bias to F0. See [1], Figure 3 vec2 brdf = BRDF(clamp(nv, 0, 1), 1.0-perceptualRough); @@ -393,9 +393,24 @@ vec3 pbrIbl(vec3 diffuseColor, vec3 diffuse = diffuseLight * diffuseColor; vec3 specular = specularLight * (specularColor * brdf.x + brdf.y); - return (diffuse + specular*0.5) * ao; //reduce by half to place in appropriate color space for atmospherics + specContrib = specular * ao; + + return (diffuse + specular) * ao; +} + +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 perceptualRough) +{ + vec3 specContrib; + return pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, nv, perceptualRough, specContrib); } + // Encapsulate the various inputs used by the various functions in the shading equation // We store values in this struct to simplify the integration of alternative implementations // of the shading terms, outlined in the Readme.MD Appendix. @@ -460,7 +475,8 @@ vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, float metallic, vec3 n, // normal vec3 v, // surface point to camera - vec3 l) //surface point to light + vec3 l, //surface point to light + out vec3 specContrib) //specular contribution (exposed to alpha shaders to calculate "glare") { // make sure specular highlights from punctual lights don't fall off of polished surfaces perceptualRoughness = max(perceptualRoughness, 8.0/255.0); @@ -506,17 +522,30 @@ vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, float G = geometricOcclusion(pbrInputs); float D = microfacetDistribution(pbrInputs); - const vec3 u_LightColor = vec3(1.0); - // Calculation of analytical lighting contribution vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInputs); - vec3 specContrib = F * G * D / (4.0 * NdotL * NdotV); + specContrib = F * G * D / (4.0 * NdotL * NdotV); // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law) - vec3 color = NdotL * u_LightColor * (diffuseContrib + specContrib); + vec3 color = NdotL * (diffuseContrib + specContrib); + + specContrib *= NdotL; + specContrib = max(specContrib, vec3(0)); return color; } +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 specContrib; + + return pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n, v, l, specContrib); +} + void calcDiffuseSpecular(vec3 baseColor, float metallic, inout vec3 diffuseColor, inout vec3 specularColor) { vec3 f0 = vec3(0.04); @@ -525,23 +554,30 @@ void calcDiffuseSpecular(vec3 baseColor, float metallic, inout vec3 diffuseColor specularColor = mix(f0, baseColor, metallic); } -vec3 pbrBaseLight(vec3 diffuseColor, vec3 specularColor, float metallic, vec3 v, vec3 norm, float perceptualRoughness, vec3 light_dir, vec3 sunlit, float scol, vec3 radiance, vec3 irradiance, vec3 colorEmissive, float ao, vec3 additive, vec3 atten) +vec3 pbrBaseLight(vec3 diffuseColor, vec3 specularColor, float metallic, vec3 v, vec3 norm, float perceptualRoughness, vec3 light_dir, vec3 sunlit, float scol, vec3 radiance, vec3 irradiance, vec3 colorEmissive, float ao, vec3 additive, vec3 atten, out vec3 specContrib) { vec3 color = vec3(0); float NdotV = clamp(abs(dot(norm, v)), 0.001, 1.0); - color += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, 0.2); + vec3 ibl_spec; + color += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, perceptualRoughness, ibl_spec); - color += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm, v, normalize(light_dir)) * sunlit * 2.75 * scol; - color += colorEmissive*0.5; + 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 = atmosFragLightingLinear(color, additive, atten); - color = scaleSoftClipFragLinear(color); + color += colorEmissive; return color; } +vec3 pbrBaseLight(vec3 diffuseColor, vec3 specularColor, float metallic, vec3 v, vec3 norm, float perceptualRoughness, vec3 light_dir, vec3 sunlit, float scol, vec3 radiance, vec3 irradiance, vec3 colorEmissive, float ao, vec3 additive, vec3 atten) +{ + vec3 specContrib; + return pbrBaseLight(diffuseColor, specularColor, metallic, v, norm, perceptualRoughness, light_dir, sunlit, scol, radiance, irradiance, colorEmissive, ao, additive, atten, specContrib); +} + uniform vec4 waterPlane; uniform float waterSign; 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 afe504743d..3a15fd1111 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -88,8 +88,10 @@ void main() #endif #ifndef IS_HUD + color.rgb = fullbrightAtmosTransport(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/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl new file mode 100644 index 0000000000..4b98e6708f --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -0,0 +1,49 @@ +/** +* @file materialF.glsl +* +* $LicenseInfo:firstyear=2023&license=viewerlgpl$ +* Second Life Viewer Source Code +* Copyright (C) 2023, 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]*/ + +// debug stub + +#define DIFFUSE_ALPHA_MODE_BLEND 1 + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) +out vec4 frag_color; +#else +out vec4 frag_data[3]; +#endif + +void main() +{ +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + frag_color = vec4(0.5, 0, 1, 0.5); +#else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer + // deferred path // See: C++: addDeferredAttachment(), shader: softenLightF.glsl + frag_data[0] = vec4(0.5, 0, 1, 0); // gbuffer is sRGB for legacy materials + frag_data[1] = vec4(0); // XYZ = Specular color. W = Specular exponent. + frag_data[2] = vec4(0); // XY = Normal. Z = Env. intensity. W = 1 skip atmos (mask off fog) +#endif +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl index 7b9aa0a4dc..032245a01c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl @@ -27,10 +27,10 @@ uniform mat4 texture_matrix0; uniform mat4 modelview_matrix; uniform mat4 modelview_projection_matrix; -ATTRIBUTE vec3 position; -ATTRIBUTE vec2 texcoord0; +in vec3 position; +in vec2 texcoord0; -VARYING vec2 vary_texcoord0; +out vec2 vary_texcoord0; void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbralphaF.glsl new file mode 100644 index 0000000000..2ccd3fd962 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/pbralphaF.glsl @@ -0,0 +1,33 @@ +/** + * @file pbralphaF.glsl + * + * $LicenseInfo:firstyear=2023&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2023, 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$ + */ + + // debug stub + +out vec4 frag_color; + +void main() +{ + frag_color = vec4(1.0, 0, 0.5, 0.5); +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl index da27be6e7f..e9515a9187 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl @@ -44,15 +44,14 @@ uniform mat4 modelview_matrix; out vec3 vary_position; -uniform mat3 texture_basecolor_matrix; -uniform mat3 texture_normal_matrix; -uniform mat3 texture_metallic_roughness_matrix; -uniform mat3 texture_emissive_matrix; +uniform vec4[2] texture_base_color_transform; +uniform vec4[2] texture_normal_transform; +uniform vec4[2] texture_metallic_roughness_transform; +uniform vec4[2] texture_emissive_transform; -#ifdef HAS_SUN_SHADOW out vec3 vary_fragcoord; + uniform float near_clip; -#endif in vec3 position; in vec4 diffuse_color; @@ -60,7 +59,7 @@ in vec3 normal; in vec4 tangent; in vec2 texcoord0; -out vec2 basecolor_texcoord; +out vec2 base_color_texcoord; out vec2 normal_texcoord; out vec2 metallic_roughness_texcoord; out vec2 emissive_texcoord; @@ -71,6 +70,8 @@ out vec3 vary_tangent; flat out float vary_sign; out vec3 vary_normal; +vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); + void main() { @@ -86,14 +87,12 @@ void main() #endif gl_Position = vert; -#ifdef HAS_SUN_SHADOW vary_fragcoord.xyz = vert.xyz + vec3(0,0,near_clip); -#endif - basecolor_texcoord = (texture_matrix0 * vec4(texture_basecolor_matrix * vec3(texcoord0,1), 1)).xy; - normal_texcoord = (texture_matrix0 * vec4(texture_normal_matrix * vec3(texcoord0,1), 1)).xy; - metallic_roughness_texcoord = (texture_matrix0 * vec4(texture_metallic_roughness_matrix * vec3(texcoord0,1), 1)).xy; - emissive_texcoord = (texture_matrix0 * vec4(texture_emissive_matrix * vec3(texcoord0,1), 1)).xy; + base_color_texcoord = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0); + normal_texcoord = texture_transform(texcoord0, texture_normal_transform, texture_matrix0); + metallic_roughness_texcoord = texture_transform(texcoord0, texture_metallic_roughness_transform, texture_matrix0); + emissive_texcoord = texture_transform(texcoord0, texture_emissive_transform, texture_matrix0); #ifdef HAS_SKIN vec3 n = (mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz; @@ -126,18 +125,21 @@ uniform mat4 modelview_matrix; out vec3 vary_position; -uniform mat3 texture_basecolor_matrix; -uniform mat3 texture_emissive_matrix; +uniform vec4[2] texture_base_color_transform; +uniform vec4[2] texture_emissive_transform; in vec3 position; in vec4 diffuse_color; in vec2 texcoord0; -out vec2 basecolor_texcoord; +out vec2 base_color_texcoord; out vec2 emissive_texcoord; out vec4 vertex_color; +vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); + + void main() { //transform vertex @@ -145,8 +147,8 @@ void main() gl_Position = vert; vary_position = vert.xyz; - basecolor_texcoord = (texture_matrix0 * vec4(texture_basecolor_matrix * vec3(texcoord0,1), 1)).xy; - emissive_texcoord = (texture_matrix0 * vec4(texture_emissive_matrix * vec3(texcoord0,1), 1)).xy; + base_color_texcoord = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0); + emissive_texcoord = texture_transform(texcoord0, texture_emissive_transform, texture_matrix0); vertex_color = diffuse_color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrglowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrglowF.glsl index 8dc9e02f7a..1c36aa6b50 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrglowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrglowF.glsl @@ -37,7 +37,7 @@ out vec4 frag_color; in vec3 vary_position; in vec4 vertex_emissive; -in vec2 basecolor_texcoord; +in vec2 base_color_texcoord; in vec2 emissive_texcoord; uniform float minimum_alpha; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlphaCutoff() @@ -47,7 +47,7 @@ vec3 srgb_to_linear(vec3 c); void main() { - vec4 basecolor = texture2D(diffuseMap, basecolor_texcoord.xy).rgba; + vec4 basecolor = texture2D(diffuseMap, base_color_texcoord.xy).rgba; if (basecolor.a < minimum_alpha) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrglowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrglowV.glsl index 75b24336c5..82a50a115c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrglowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrglowV.glsl @@ -34,19 +34,21 @@ uniform mat4 modelview_projection_matrix; uniform mat4 texture_matrix0; -uniform mat3 texture_basecolor_matrix; -uniform mat3 texture_emissive_matrix; +uniform vec4[2] texture_base_color_transform; +uniform vec4[2] texture_emissive_transform; in vec3 position; in vec4 emissive; in vec2 texcoord0; -out vec2 basecolor_texcoord; +out vec2 base_color_texcoord; out vec2 emissive_texcoord; out vec4 vertex_emissive; +vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); + void main() { #ifdef HAS_SKIN @@ -62,8 +64,8 @@ void main() gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); #endif - basecolor_texcoord = (texture_matrix0 * vec4(texture_basecolor_matrix * vec3(texcoord0,1), 1)).xy; - emissive_texcoord = (texture_matrix0 * vec4(texture_emissive_matrix * vec3(texcoord0,1), 1)).xy; + base_color_texcoord = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0); + emissive_texcoord = texture_transform(texcoord0, texture_emissive_transform, texture_matrix0); vertex_emissive = emissive; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl index c4c5a7872b..6659e67a7a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl @@ -47,7 +47,7 @@ in vec3 vary_normal; in vec3 vary_tangent; flat in float vary_sign; -in vec2 basecolor_texcoord; +in vec2 base_color_texcoord; in vec2 normal_texcoord; in vec2 metallic_roughness_texcoord; in vec2 emissive_texcoord; @@ -62,7 +62,7 @@ uniform mat3 normal_matrix; void main() { - vec4 basecolor = texture2D(diffuseMap, basecolor_texcoord.xy).rgba; + vec4 basecolor = texture2D(diffuseMap, base_color_texcoord.xy).rgba; if (basecolor.a < minimum_alpha) { discard; @@ -121,7 +121,7 @@ out vec4 frag_color; in vec3 vary_position; in vec4 vertex_color; -in vec2 basecolor_texcoord; +in vec2 base_color_texcoord; in vec2 emissive_texcoord; uniform float minimum_alpha; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlphaCutoff() @@ -131,7 +131,7 @@ vec3 srgb_to_linear(vec3 c); void main() { - vec4 basecolor = texture2D(diffuseMap, basecolor_texcoord.xy).rgba; + vec4 basecolor = texture2D(diffuseMap, base_color_texcoord.xy).rgba; if (basecolor.a < minimum_alpha) { discard; diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl index 8320640e42..e2c23ac8f0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl @@ -38,10 +38,10 @@ uniform mat4 modelview_projection_matrix; #endif uniform mat4 texture_matrix0; -uniform mat3 texture_basecolor_matrix; -uniform mat3 texture_normal_matrix; -uniform mat3 texture_metallic_roughness_matrix; -uniform mat3 texture_emissive_matrix; +uniform vec4[2] texture_base_color_transform; +uniform vec4[2] texture_normal_transform; +uniform vec4[2] texture_metallic_roughness_transform; +uniform vec4[2] texture_emissive_transform; in vec3 position; in vec4 diffuse_color; @@ -49,7 +49,7 @@ in vec3 normal; in vec4 tangent; in vec2 texcoord0; -out vec2 basecolor_texcoord; +out vec2 base_color_texcoord; out vec2 normal_texcoord; out vec2 metallic_roughness_texcoord; out vec2 emissive_texcoord; @@ -60,6 +60,8 @@ out vec3 vary_tangent; flat out float vary_sign; out vec3 vary_normal; +vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); + void main() { #ifdef HAS_SKIN @@ -75,11 +77,11 @@ void main() //transform vertex gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); #endif - - basecolor_texcoord = (texture_matrix0 * vec4(texture_basecolor_matrix * vec3(texcoord0,1), 1)).xy; - normal_texcoord = (texture_matrix0 * vec4(texture_normal_matrix * vec3(texcoord0,1), 1)).xy; - metallic_roughness_texcoord = (texture_matrix0 * vec4(texture_metallic_roughness_matrix * vec3(texcoord0,1), 1)).xy; - emissive_texcoord = (texture_matrix0 * vec4(texture_emissive_matrix * vec3(texcoord0,1), 1)).xy; + + base_color_texcoord = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0); + normal_texcoord = texture_transform(texcoord0, texture_normal_transform, texture_matrix0); + metallic_roughness_texcoord = texture_transform(texcoord0, texture_metallic_roughness_transform, texture_matrix0); + emissive_texcoord = texture_transform(texcoord0, texture_emissive_transform, texture_matrix0); #ifdef HAS_SKIN vec3 n = (mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz; @@ -104,27 +106,29 @@ uniform mat4 modelview_projection_matrix; uniform mat4 texture_matrix0; -uniform mat3 texture_basecolor_matrix; -uniform mat3 texture_normal_matrix; -uniform mat3 texture_metallic_roughness_matrix; -uniform mat3 texture_emissive_matrix; +uniform vec4[2] texture_base_color_transform; +uniform vec4[2] texture_normal_transform; +uniform vec4[2] texture_metallic_roughness_transform; +uniform vec4[2] texture_emissive_transform; in vec3 position; in vec4 diffuse_color; in vec2 texcoord0; -out vec2 basecolor_texcoord; +out vec2 base_color_texcoord; out vec2 emissive_texcoord; out vec4 vertex_color; +vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); + void main() { //transform vertex gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); - basecolor_texcoord = (texture_matrix0 * vec4(texture_basecolor_matrix * vec3(texcoord0,1), 1)).xy; - emissive_texcoord = (texture_matrix0 * vec4(texture_emissive_matrix * vec3(texcoord0,1), 1)).xy; + base_color_texcoord = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0); + emissive_texcoord = texture_transform(texcoord0, texture_emissive_transform, texture_matrix0); vertex_color = diffuse_color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index 987b2d1fe8..383fcaa9a7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -41,6 +41,95 @@ uniform float display_gamma; vec3 linear_to_srgb(vec3 cl); +//=============================================================== +// tone mapping taken from Khronos sample implementation +//=============================================================== + +// sRGB => XYZ => D65_2_D60 => AP1 => RRT_SAT +const mat3 ACESInputMat = mat3 +( + 0.59719, 0.07600, 0.02840, + 0.35458, 0.90834, 0.13383, + 0.04823, 0.01566, 0.83777 +); + + +// ODT_SAT => XYZ => D60_2_D65 => sRGB +const mat3 ACESOutputMat = mat3 +( + 1.60475, -0.10208, -0.00327, + -0.53108, 1.10813, -0.07276, + -0.07367, -0.00605, 1.07602 +); + +// ACES tone map (faster approximation) +// see: https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/ +vec3 toneMapACES_Narkowicz(vec3 color) +{ + const float A = 2.51; + const float B = 0.03; + const float C = 2.43; + const float D = 0.59; + const float E = 0.14; + return clamp((color * (A * color + B)) / (color * (C * color + D) + E), 0.0, 1.0); +} + + +// ACES filmic tone map approximation +// see https://github.com/TheRealMJP/BakingLab/blob/master/BakingLab/ACES.hlsl +vec3 RRTAndODTFit(vec3 color) +{ + vec3 a = color * (color + 0.0245786) - 0.000090537; + vec3 b = color * (0.983729 * color + 0.4329510) + 0.238081; + return a / b; +} + + +// tone mapping +vec3 toneMapACES_Hill(vec3 color) +{ + color = ACESInputMat * color; + + // Apply RRT and ODT + color = RRTAndODTFit(color); + + color = ACESOutputMat * color; + + // Clamp to [0, 1] + color = clamp(color, 0.0, 1.0); + + return color; +} + +uniform float exposure; +uniform float gamma; + +vec3 toneMap(vec3 color) +{ + color *= exposure; + +#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 /= 0.6; + color = toneMapACES_Hill(color); +#endif + + return linear_to_srgb(color); +} + +//=============================================================== + //================================= // borrowed noise from: // <https://www.shadertoy.com/view/4dS3Wd> @@ -79,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 = linear_to_srgb(diff.rgb); - vec2 tc = vary_fragcoord.xy*screen_res; - + diff.rgb = toneMap(diff.rgb); + 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; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index cd49202f89..ee3a5f1f31 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -59,12 +59,12 @@ float pcfShadow(sampler2DShadow shadowMap, vec3 norm, vec4 stc, float bias_mul, stc.xyz /= stc.w; stc.z += offset * 2.0; stc.x = floor(stc.x*shadow_res.x + fract(pos_screen.y*shadow_res.y))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here - float cs = shadow2D(shadowMap, stc.xyz).x; + float cs = texture(shadowMap, stc.xyz); float shadow = cs * 4.0; - shadow += shadow2D(shadowMap, stc.xyz+vec3( 1.5/shadow_res.x, 0.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3( 0.5/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.5/shadow_res.x, -0.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-0.5/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; + shadow += texture(shadowMap, stc.xyz+vec3( 1.5/shadow_res.x, 0.5/shadow_res.y, 0.0)); + shadow += texture(shadowMap, stc.xyz+vec3( 0.5/shadow_res.x, -1.5/shadow_res.y, 0.0)); + shadow += texture(shadowMap, stc.xyz+vec3(-1.5/shadow_res.x, -0.5/shadow_res.y, 0.0)); + shadow += texture(shadowMap, stc.xyz+vec3(-0.5/shadow_res.x, 1.5/shadow_res.y, 0.0)); return clamp(shadow * 0.125, 0.0, 1.0); #else return 1.0; @@ -78,16 +78,16 @@ float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 stc.z += spot_shadow_bias * bias_scale; stc.x = floor(proj_shadow_res.x * stc.x + fract(pos_screen.y*0.666666666)) / proj_shadow_res.x; // snap - float cs = shadow2D(shadowMap, stc.xyz).x; + float cs = texture(shadowMap, stc.xyz); float shadow = cs; vec2 off = 1.0/proj_shadow_res; off.y *= 1.5; - shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x*2.0, off.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x, -off.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x, off.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x*2.0, -off.y, 0.0)).x; + shadow += texture(shadowMap, stc.xyz+vec3(off.x*2.0, off.y, 0.0)); + shadow += texture(shadowMap, stc.xyz+vec3(off.x, -off.y, 0.0)); + shadow += texture(shadowMap, stc.xyz+vec3(-off.x, off.y, 0.0)); + shadow += texture(shadowMap, stc.xyz+vec3(-off.x*2.0, -off.y, 0.0)); return shadow*0.2; #else return 1.0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl new file mode 100644 index 0000000000..71f7ec52c4 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl @@ -0,0 +1,78 @@ +/** + * @file class1/deferred/textureUtilV.glsl + * + * $LicenseInfo:firstyear=2023&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2023, 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$ + */ + +// This shader code is taken from the sample code on the KHR_texture_transform +// spec page page, plus or minus some sign error corrections (I think because the GLSL +// matrix constructor is backwards?): +// https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform +// Previously (6494eed242b1), we passed in a single, precalculated matrix +// uniform per transform into the shaders. However, that was found to produce +// small-but-noticeable discrepancies with the GLTF sample model +// "TextureTransformTest", likely due to numerical precision differences. In +// the interest of parity with other renderers, calculate the transform +// directly in the shader. -Cosmic,2023-02-24 +vec2 khr_texture_transform(vec2 texcoord, vec2 scale, float rotation, vec2 offset) +{ + mat3 scale_mat = mat3(scale.x,0,0, 0,scale.y,0, 0,0,1); + mat3 offset_mat = mat3(1,0,0, 0,1,0, offset.x, offset.y, 1); + mat3 rotation_mat = mat3( + cos(rotation),-sin(rotation), 0, + sin(rotation), cos(rotation), 0, + 0, 0, 1 + ); + + mat3 transform = offset_mat * rotation_mat * scale_mat; + + return (transform * vec3(texcoord, 1)).xy; +} + +// vertex_texcoord - The UV texture coordinates sampled from the vertex at +// runtime. Per SL convention, this is in a right-handed UV coordinate +// system. Collada models also have right-handed UVs. +// khr_gltf_transform - The texture transform matrix as defined in the +// KHR_texture_transform GLTF extension spec. It assumes a left-handed UV +// coordinate system. GLTF models also have left-handed UVs. +// sl_animation_transform - The texture transform matrix for texture +// animations, available through LSL script functions such as +// LlSetTextureAnim. It assumes a right-handed UV coordinate system. +// texcoord - The final texcoord to use for image sampling +vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform) +{ + vec2 texcoord = vertex_texcoord; + + // Apply texture animation first to avoid shearing and other artifacts + texcoord = (sl_animation_transform * vec4(texcoord, 0, 1)).xy; + // Convert to left-handed coordinate system. The offset of 1 is necessary + // for rotations to be applied correctly. + texcoord.y = 1.0 - texcoord.y; + texcoord = khr_texture_transform(texcoord, khr_gltf_transform[0].xy, khr_gltf_transform[0].z, khr_gltf_transform[1].xy); + // Convert back to right-handed coordinate system + texcoord.y = 1.0 - texcoord.y; + + // To make things more confusing, all SL image assets are upside-down + // We may need an additional sign flip here when we implement a Vulkan backend + + return texcoord; +} diff --git a/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl index 16651dcdbc..745999fc2f 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl @@ -33,6 +33,7 @@ uniform float waterFogKS; vec3 getPositionEye(); vec3 srgb_to_linear(vec3 col); +vec3 linear_to_srgb(vec3 col); vec4 applyWaterFogView(vec3 pos, vec4 color) { @@ -68,48 +69,16 @@ vec4 applyWaterFogView(vec3 pos, vec4 color) float D = pow(0.98, l*kd); color.rgb = color.rgb * D + kc.rgb * L; + color.a = kc.a + color.a; return color; } vec4 applyWaterFogViewLinearNoClip(vec3 pos, vec4 color, vec3 sunlit) { - vec3 view = normalize(pos); - //normalize view vector - float es = -(dot(view, waterPlane.xyz)); - - - //find intersection point with water plane and eye vector - - //get eye depth - float e0 = max(-waterPlane.w, 0.0); - - vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w / es : vec3(0.0, 0.0, 0.0); - - //get object depth - float depth = length(pos - int_v); - - //get "thickness" of water - float l = max(depth, 0.1); - - float kd = waterFogDensity*1.3; - float ks = waterFogKS; - vec4 kc = waterFogColor; - kc.rgb = srgb_to_linear(kc.rgb); // TODO -- pass in waterFogColor linear - kc.rgb *= sunlit; - - float F = 0.98; - - float t1 = -kd * pow(F, ks * e0); - float t2 = kd + ks * es; - float t3 = pow(F, t2 * l) - 1.0; - - float L = min(t1 / t2 * t3, 1.0); - - float D = pow(0.98, l * kd); - - color.rgb = color.rgb * D + kc.rgb * L; - + color.rgb = linear_to_srgb(color.rgb); + color = applyWaterFogView(pos, color); + color.rgb = srgb_to_linear(color.rgb); return color; } diff --git a/indra/newview/app_settings/shaders/class1/interface/gaussianF.glsl b/indra/newview/app_settings/shaders/class1/interface/gaussianF.glsl new file mode 100644 index 0000000000..188fac5460 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/interface/gaussianF.glsl @@ -0,0 +1,53 @@ +/** + * @file gaussianF.glsl + * + * $LicenseInfo:firstyear=2023&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2023, 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; + +uniform sampler2D diffuseRect; + +uniform float resScale; + +// texture direction, will be <1, 0> or <0, 1> +uniform vec2 direction; + +in vec2 vary_texcoord0; + +// get linear depth value given a depth buffer sample d and znear and zfar values +float linearDepth(float d, float znear, float zfar); + +void main() +{ + vec3 col = vec3(0,0,0); + + float w[9] = float[9]( 0.0002, 0.0060, 0.0606, 0.2417, 0.3829, 0.2417, 0.0606, 0.0060, 0.0002 ); + + for (int i = 0; i < 9; ++i) + { + vec2 tc = vary_texcoord0 + (i-4)*direction*resScale; + col += texture(diffuseRect, tc).rgb * w[i]; + } + + frag_color = vec4(col, 0.0); +} diff --git a/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl b/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl index e60ddcd569..b6f080739e 100644 --- a/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl @@ -127,14 +127,11 @@ vec4 prefilterEnvMap(vec3 R) vec3 V = R; vec4 color = vec4(0.0); float totalWeight = 0.0; - float envMapDim = u_width; - int numSamples = 4; - - float numMips = max_probe_lod; + float envMapDim = float(textureSize(reflectionProbes, 0).s); + float roughness = mipLevel/max_probe_lod; + int numSamples = max(int(32*roughness), 1); - float roughness = mipLevel/numMips; - - numSamples = max(int(numSamples*roughness), 1); + float numMips = max_probe_lod+1; for(uint i = 0u; i < numSamples; i++) { vec2 Xi = hammersley2d(i, numSamples); @@ -154,11 +151,9 @@ vec4 prefilterEnvMap(vec3 R) // Solid angle of 1 pixel across all cube faces float omegaP = 4.0 * PI / (6.0 * envMapDim * envMapDim); // Biased (+1.0) mip level for better result - float mip = roughness == 0.0 ? 0.0 : clamp(0.5 * log2(omegaS / omegaP) + 1.0, 0.0f, numMips); - //float mip = clamp(0.5 * log2(omegaS / omegaP) + 1.0, 0.0f, 7.f); - color += textureLod(reflectionProbes, vec4(L,sourceIdx), mip) * dotNL; + float mipLevel = roughness == 0.0 ? 0.0 : max(0.5 * log2(omegaS / omegaP) + 1.0, 0.0f); + color += textureLod(reflectionProbes, vec4(L, sourceIdx), mipLevel) * dotNL; totalWeight += dotNL; - } } return (color / totalWeight); diff --git a/indra/newview/app_settings/shaders/class1/interface/reflectionmipF.glsl b/indra/newview/app_settings/shaders/class1/interface/reflectionmipF.glsl index a9c28b2974..45267e4403 100644 --- a/indra/newview/app_settings/shaders/class1/interface/reflectionmipF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/reflectionmipF.glsl @@ -23,78 +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 -// NOTE screenMap should always be texture channel 0 and -// depthmap should always be channel 1 uniform sampler2D diffuseRect; -uniform sampler2D depthMap; - -uniform float resScale; -uniform float znear; -uniform float zfar; - -VARYING vec2 vary_texcoord0; -// get linear depth value given a depth buffer sample d and znear and zfar values -float linearDepth(float d, float znear, float zfar); +in vec2 vary_texcoord0; void main() { -#if 0 - float w[9]; - - float c = 1.0/16.0; //corner weight - float e = 1.0/8.0; //edge weight - float m = 1.0/4.0; //middle weight - - //float wsum = c*4+e*4+m; - - w[0] = c; w[1] = e; w[2] = c; - w[3] = e; w[4] = m; w[5] = e; - w[6] = c; w[7] = e; w[8] = c; - - vec2 tc[9]; - - float ed = 1; - float cd = 1; - - - tc[0] = vec2(-cd, cd); tc[1] = vec2(0, ed); tc[2] = vec2(cd, cd); - tc[3] = vec2(-ed, 0); tc[4] = vec2(0, 0); tc[5] = vec2(ed, 0); - tc[6] = vec2(-cd, -cd); tc[7] = vec2(0, -ed); tc[8] = vec2(cd, -1); - - vec3 color = vec3(0,0,0); - - for (int i = 0; i < 9; ++i) - { - color += texture2D(screenMap, vary_texcoord0.xy+tc[i]).rgb * w[i]; - //color += texture2D(screenMap, vary_texcoord0.xy+tc[i]*2.0).rgb * w[i]*0.5; - } - - //color /= wsum; - - frag_color = vec4(color, 1.0); -#else - float depth = texture(depthMap, vary_texcoord0.xy).r; - float dist = linearDepth(depth, znear, zfar); - - // convert linear depth to distance - vec3 v; - v.xy = vary_texcoord0.xy / 512.0 * 2.0 - 1.0; - v.z = 1.0; - v = normalize(v); - dist /= v.z; - - vec3 col = texture2D(diffuseRect, vary_texcoord0.xy).rgb; - frag_color = vec4(col, dist/256.0); -#endif + vec3 col = texture(diffuseRect, vary_texcoord0.xy).rgb; + frag_color = vec4(col, 0.0); } diff --git a/indra/newview/app_settings/shaders/class1/interface/splattexturerectV.glsl b/indra/newview/app_settings/shaders/class1/interface/splattexturerectV.glsl index 641d670c26..7af7f20f85 100644 --- a/indra/newview/app_settings/shaders/class1/interface/splattexturerectV.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/splattexturerectV.glsl @@ -25,17 +25,13 @@ uniform mat4 modelview_projection_matrix; -ATTRIBUTE vec3 position; -ATTRIBUTE vec2 texcoord0; -ATTRIBUTE vec4 diffuse_color; +in vec3 position; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; +out vec2 vary_texcoord0; void main() { gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); - vary_texcoord0 = texcoord0; - vertex_color = diffuse_color; + vary_texcoord0 = position.xy*0.5+0.5; } 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 35ccc65a8e..fb76db99a0 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -46,14 +46,15 @@ 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 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; @@ -81,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); @@ -106,16 +109,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, @@ -126,7 +129,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); @@ -148,7 +151,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; @@ -157,13 +163,14 @@ 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; 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) @@ -191,8 +198,11 @@ void main() vec3 atten; calcAtmosphericVarsLinear(pos.xyz, norm, light_dir, sunlit, amblit, additive, atten); -#ifdef HAS_SUN_SHADOW + vec3 sunlit_linear = srgb_to_linear(sunlit); + 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 +221,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); @@ -222,15 +232,19 @@ 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); + 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); - float nv = clamp(abs(dot(norm.xyz, v)), 0.001, 1.0); - vec2 brdf = BRDF(clamp(nv, 0, 1), 1.0-perceptualRoughness); + 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 -#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) @@ -244,11 +258,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); } @@ -263,7 +276,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 +295,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) diff --git a/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class2/deferred/reflectionProbeF.glsl index f1ee4b4681..080f622155 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,10 @@ 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); } vec4 sampleReflectionProbesDebug(vec3 pos) 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); 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..55e1411be2 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 - sunlit = sunlight.rgb; - amblit = tmpAmbient.rgb; + + // 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 @@ -150,21 +153,26 @@ 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; + + // 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 * 0.5; 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); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index 8d2a65d4a9..add1cb2a37 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -92,7 +92,7 @@ uniform vec3 light_diffuse[8]; float getAmbientClamp(); void waterClip(vec3 pos); -vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spec, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, float ambiance) +vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spec, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, inout float glare, 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 @@ -170,6 +170,11 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe vec3 speccol = lit*scol*light_col.rgb*spec.rgb; speccol = clamp(speccol, vec3(0), vec3(1)); col += speccol; + + float cur_glare = max(speccol.r, speccol.g); + cur_glare = max(cur_glare, speccol.b); + glare = max(glare, speccol.r); + glare += max(cur_glare, 0.0); } } } @@ -218,83 +223,105 @@ VARYING vec2 vary_texcoord0; vec2 encode_normal(vec3 n); -void main() +// get the transformed normal and apply glossiness component from normal map +vec3 getNormal(inout float glossiness) { -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - waterClip(vary_position.xyz); -#endif +#ifdef HAS_NORMAL_MAP + vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); + glossiness *= norm.a; - vec2 pos_screen = vary_texcoord0.xy; + norm.xyz = norm.xyz * 2 - 1; - vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); - diffcol.rgb *= vertex_color.rgb; + return normalize(vec3(dot(norm.xyz,vary_mat0), + dot(norm.xyz,vary_mat1), + dot(norm.xyz,vary_mat2))); +#else + return normalize(vary_normal); +#endif +} -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) +vec4 getSpecular() +{ +#ifdef HAS_SPECULAR_MAP + vec4 spec = texture2D(specularMap, vary_texcoord2.xy); + spec.rgb *= specular_color.rgb; +#else + vec4 spec = vec4(specular_color.rgb, 1.0); +#endif + return spec; +} +void alphaMask(float alpha) +{ +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) // Comparing floats cast from 8-bit values, produces acne right at the 8-bit transition points float bias = 0.001953125; // 1/512, or half an 8-bit quantization - if (diffcol.a < minimum_alpha-bias) + if (alpha < minimum_alpha-bias) { discard; } #endif +} -#ifdef HAS_SPECULAR_MAP - vec4 spec = texture2D(specularMap, vary_texcoord2.xy); - spec.rgb *= specular_color.rgb; -#else - vec4 spec = vec4(specular_color.rgb, 1.0); +void waterClip() +{ +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + waterClip(vary_position.xyz); #endif +} -#ifdef HAS_NORMAL_MAP - vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); - - norm.xyz = norm.xyz * 2 - 1; +float getEmissive(vec4 diffcol) +{ +#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) + return emissive_brightness; +#else + return max(diffcol.a, emissive_brightness); +#endif +} - vec3 tnorm = vec3(dot(norm.xyz,vary_mat0), - dot(norm.xyz,vary_mat1), - dot(norm.xyz,vary_mat2)); +float getShadow(vec3 pos, vec3 norm) +{ +#ifdef HAS_SUN_SHADOW + #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + return sampleDirectionalShadow(pos, norm, vary_texcoord0.xy); + #else + return 1; + #endif #else - vec4 norm = vec4(0,0,0,1.0); - vec3 tnorm = vary_normal; + return 1; #endif +} - norm.xyz = normalize(tnorm.xyz); +void main() +{ + waterClip(); - vec2 abnormal = encode_normal(norm.xyz); + // diffcol == diffuse map combined with vertex color + vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); + diffcol.rgb *= vertex_color.rgb; - vec4 final_color = diffcol; + alphaMask(diffcol.a); -#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) - final_color.a = emissive_brightness; -#else - final_color.a = max(final_color.a, emissive_brightness); -#endif + // spec == specular map combined with specular color + vec4 spec = getSpecular(); + float env = env_intensity * spec.a; + float glossiness = specular_color.a; + vec3 norm = getNormal(glossiness); - vec4 final_specular = spec; - -#ifdef HAS_SPECULAR_MAP - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, GBUFFER_FLAG_HAS_ATMOS); - final_specular.a = specular_color.a * norm.a; -#else - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, GBUFFER_FLAG_HAS_ATMOS); - final_specular.a = specular_color.a; -#endif + vec2 abnormal = encode_normal(norm.xyz); + + float emissive = getEmissive(diffcol); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) //forward rendering, output lit linear color diffcol.rgb = srgb_to_linear(diffcol.rgb); - final_specular.rgb = srgb_to_linear(final_specular.rgb); + spec.rgb = srgb_to_linear(spec.rgb); vec3 pos = vary_position; - float shadow = 1.0f; + float shadow = getShadow(pos, norm); -#ifdef HAS_SUN_SHADOW - shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen); -#endif - - vec4 diffuse = final_color; + vec4 diffuse = diffcol; vec3 color = vec3(0,0,0); @@ -307,54 +334,63 @@ void main() vec3 atten; calcAtmosphericVarsLinear(pos.xyz, norm.xyz, light_dir, sunlit, amblit, additive, atten); + vec3 sunlit_linear = srgb_to_linear(sunlit); + vec3 amblit_linear = amblit; + vec3 ambenv; vec3 glossenv; vec3 legacyenv; - sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos_screen, pos.xyz, norm.xyz, final_specular.a, env_intensity); + sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xy*0.5+0.5, pos.xyz, norm.xyz, glossiness, env); // use sky settings ambient or irradiance map sample, whichever is brighter - color = max(amblit, ambenv); + color = max(amblit_linear, ambenv); float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); - vec3 sun_contrib = min(da, shadow) * sunlit; + vec3 sun_contrib = min(da, shadow) * sunlit_linear; color.rgb += sun_contrib; color *= diffcol.rgb; vec3 refnormpersp = reflect(pos.xyz, norm.xyz); - if (final_specular.a > 0.0) // specular reflection + float glare = 0.0; + + if (glossiness > 0.0) // specular reflection { float sa = dot(normalize(refnormpersp), light_dir.xyz); - vec3 dumbshiny = sunlit * shadow * (texture2D(lightFunc, vec2(sa, final_specular.a)).r); + vec3 dumbshiny = sunlit_linear * shadow * (texture2D(lightFunc, vec2(sa, glossiness)).r); // add the two types of shiny together - vec3 spec_contrib = dumbshiny * final_specular.rgb; + vec3 spec_contrib = dumbshiny * spec.rgb; bloom = dot(spec_contrib, spec_contrib) / 6; + glare = max(spec_contrib.r, spec_contrib.g); + glare = max(glare, spec_contrib.b); + color += spec_contrib; - applyGlossEnv(color, glossenv, final_specular, pos.xyz, norm.xyz); + applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); } - color = mix(color.rgb, diffcol.rgb, diffuse.a); + color = mix(color.rgb, diffcol.rgb, emissive); - if (env_intensity > 0.0) + if (env > 0.0) { // add environmentmap - applyLegacyEnv(color, legacyenv, final_specular, pos.xyz, norm.xyz, env_intensity); + 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; + glare += cur_glare; } - color.rgb = mix(atmosFragLightingLinear(color.rgb, additive, atten), fullbrightAtmosTransportFragLinear(color, additive, atten), diffuse.a); + color.rgb = linear_to_srgb(color.rgb); + color.rgb = atmosFragLightingLinear(color.rgb, additive, atten); color.rgb = scaleSoftClipFragLinear(color.rgb); - -#ifdef WATER_FOG - vec4 temp = applyWaterFogView(pos, vec4(color, 0.0)); - color = temp.rgb; -#endif + color.rgb = srgb_to_linear(color.rgb); vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0, 0, 0); -#define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, light_attenuation[i].w ); +#define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, spec, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare, light_attenuation[i].w ); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -364,17 +400,25 @@ void main() LIGHT_LOOP(6) LIGHT_LOOP(7) + light *= 1.0-emissive; color += light; - float al = diffcol.a*vertex_color.a; + glare *= 1.0-emissive; + glare = min(glare, 1.0); + float al = max(diffcol.a, glare) * vertex_color.a; + +#ifdef WATER_FOG + vec4 temp = applyWaterFogView(pos, vec4(color, 0.0)); + color = temp.rgb; +#endif frag_color = vec4(color, al); -#else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer +#else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer // deferred path // See: C++: addDeferredAttachment(), shader: softenLightF.glsl - frag_data[0] = final_color; // gbuffer is sRGB for legacy materials - frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. - frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. W = 1 skip atmos (mask off fog) + frag_data[0] = vec4(diffcol.rgb, emissive); // gbuffer is sRGB for legacy materials + frag_data[1] = vec4(spec.rgb, glossiness); // XYZ = Specular color. W = Specular exponent. + frag_data[2] = vec4(encode_normal(norm), env, GBUFFER_FLAG_HAS_ATMOS);; // XY = Normal. Z = Env. intensity. W = 1 skip atmos (mask off fog) #endif } diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index d9cbae45a6..8229ecbbb7 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -37,7 +37,6 @@ uniform sampler2D diffuseRect; uniform sampler2D specularRect; uniform sampler2D normalMap; uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl -uniform sampler2D noiseMap; uniform sampler2D lightFunc; uniform sampler2D depthMap; @@ -126,8 +125,7 @@ void main() diffuse = srgb_to_linear(diffuse); spec.rgb = srgb_to_linear(spec.rgb); - float noise = texture2D(noiseMap, tc).b; - float lit = nl * dist_atten * noise; + float lit = nl * dist_atten; final_color = color.rgb*lit*diffuse; diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 8b1d41776f..a6a2543915 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -80,7 +80,7 @@ bool isAbove(vec3 pos, vec4 plane) return (dot(plane.xyz, pos) + plane.w) > 0; } -int max_priority = 0; +bool sample_automatic = true; // return true if probe at index i influences position pos bool shouldSampleProbe(int i, vec3 pos) @@ -95,24 +95,24 @@ bool shouldSampleProbe(int i, vec3 pos) return false; } - max_priority = max(max_priority, -refIndex[i].w); + sample_automatic = false; } else { - if (refSphere[i].w > 0.0) // zero is special indicator to always sample this probe + if (refIndex[i].w == 0 && !sample_automatic) { - 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 false; } - max_priority = max(max_priority, refIndex[i].w); + 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; @@ -120,7 +120,6 @@ bool shouldSampleProbe(int i, vec3 pos) // 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 @@ -210,7 +209,7 @@ void preProbeSample(vec3 pos) } } - if (max_priority <= 1) + if (sample_automatic) { // probe at index 0 is a special probe for smoothing out automatic probes probeIndex[probeInfluences++] = 0; } @@ -342,7 +341,7 @@ return texCUBE(envMap, ReflDirectionWS); // d - distance to nearest wall in clip space vec3 boxIntersect(vec3 origin, vec3 dir, int i, out float d) { - // Intersection with OBB convertto unit box space + // Intersection with OBB convert to unit box space // Transform in local unit parallax cube space (scaled and rotated) mat4 clipToLocal = refBox[i]; @@ -431,18 +430,24 @@ void boxIntersectDebug(vec3 origin, vec3 pos, int i, inout vec4 col) // origin - center of sphere probe // r - radius of probe influence volume // min_da - minimum angular attenuation coefficient -float sphereWeight(vec3 pos, vec3 dir, vec3 origin, float r, float min_da) +// i - index of probe in refSphere +// dw - distance weight +float sphereWeight(vec3 pos, vec3 dir, vec3 origin, float r, float min_da, int i, out float dw) { float r1 = r * 0.5; // 50% of radius (outer sphere to start interpolating down) vec3 delta = pos.xyz - origin; float d2 = max(length(delta), 0.001); + float r2 = r1; //r1 * r1; //float atten = 1.0 - max(d2 - r2, 0.0) / max((rr - r2), 0.001); float atten = 1.0 - max(d2 - r2, 0.0) / max((r - r2), 0.001); + float w = 1.0 / d2; + + dw = w * atten * max(r, 1.0)*4; atten *= max(dot(normalize(-delta), dir), min_da); - float w = 1.0 / d2; + w *= atten; return w; @@ -451,48 +456,43 @@ float sphereWeight(vec3 pos, vec3 dir, vec3 origin, float r, float min_da) // Tap a reflection probe // pos - position of pixel // dir - pixel normal -// vi - return value of intersection point with influence volume -// wi - return value of approximate world space position of sampled pixel -// lod - which mip to bias towards (lower is higher res, sharper reflections) +// w - weight of sample (distance and angular attenuation) +// dw - weight of sample (distance only) +// lod - which mip to sample (lower is higher res, sharper reflections) // c - center of probe // r2 - radius of probe squared // i - index of probe -vec3 tapRefMap(vec3 pos, vec3 dir, out float w, out vec3 vi, out vec3 wi, float lod, vec3 c, int i) +vec3 tapRefMap(vec3 pos, vec3 dir, out float w, out float dw, float lod, vec3 c, int i) { - //lod = max(lod, 1); // parallax adjustment - vec3 v; if (refIndex[i].w < 0) - { + { // box probe float d = 0; v = boxIntersect(pos, dir, i, d); w = max(d, 0.001); } else - { - float r = refSphere[i].w; // radius of sphere volume - float rr = r * r; // radius squared + { // sphere probe + float r = refSphere[i].w; + + float rr = r * r; v = sphereIntersect(pos, dir, c, - refIndex[i].w <= 1 ? 4096.0*4096.0 : // <== effectively disable parallax correction for automatically placed probes to keep from bombing the world with obvious spheres + refIndex[i].w < 1 ? 4096.0*4096.0 : // <== effectively disable parallax correction for automatically placed probes to keep from bombing the world with obvious spheres rr); - w = sphereWeight(pos, dir, refSphere[i].xyz, r, 0.25); + w = sphereWeight(pos, dir, refSphere[i].xyz, r, 0.25, i, dw); } - vi = v; - v -= c; vec3 d = normalize(v); v = env_mat * v; - vec4 ret = textureLod(reflectionProbes, vec4(v.xyz, refIndex[i].x), lod); - - wi = d * ret.a * 256.0+c; + vec4 ret = textureLod(reflectionProbes, vec4(v.xyz, refIndex[i].x), lod) * refParams[i].y; return ret.rgb; } @@ -500,10 +500,10 @@ vec3 tapRefMap(vec3 pos, vec3 dir, out float w, out vec3 vi, out vec3 wi, float // Tap an irradiance map // pos - position of pixel // dir - pixel normal -// c - center of probe -// r2 - radius of probe squared +// w - weight of sample (distance and angular attenuation) +// dw - weight of sample (distance only) // i - index of probe -vec3 tapIrradianceMap(vec3 pos, vec3 dir, out float w, vec3 c, int i) +vec3 tapIrradianceMap(vec3 pos, vec3 dir, out float w, out float dw, vec3 c, int i) { // parallax adjustment vec3 v; @@ -516,14 +516,15 @@ vec3 tapIrradianceMap(vec3 pos, vec3 dir, out float w, vec3 c, int i) else { float r = refSphere[i].w; // radius of sphere volume - float p = float(abs(refIndex[i].w)); // priority - float rr = r * r; // radius squred + + // pad sphere for manual probe extending into automatic probe space + float rr = r * r; v = sphereIntersect(pos, dir, c, - refIndex[i].w <= 1 ? 4096.0*4096.0 : // <== effectively disable parallax correction for automatically placed probes to keep from bombing the world with obvious spheres + refIndex[i].w < 1 ? 4096.0*4096.0 : // <== effectively disable parallax correction for automatically placed probes to keep from bombing the world with obvious spheres rr); - w = sphereWeight(pos, dir, refSphere[i].xyz, r, 0.001); + w = sphereWeight(pos, dir, refSphere[i].xyz, r, 0.001, i, dw); } v -= c; @@ -533,106 +534,129 @@ vec3 tapIrradianceMap(vec3 pos, vec3 dir, out float w, vec3 c, int i) } } -vec3 sampleProbes(vec3 pos, vec3 dir, float lod, bool errorCorrect) +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 + float wsum[2]; + wsum[0] = 0; + wsum[1] = 0; + + float dwsum[2]; + dwsum[0] = 0; + dwsum[1] = 0; + + vec3 col[2]; + col[0] = vec3(0); + col[1] = vec3(0); for (int idx = 0; idx < probeInfluences; ++idx) { int i = probeIndex[idx]; - if (abs(refIndex[i].w) < max_priority) + int p = clamp(abs(refIndex[i].w), 0, 1); + + if (p == 0 && !sample_automatic) { continue; } - float w; - vec3 vi, wi; + float w = 0; + float dw = 0; vec3 refcol; { - if (errorCorrect && refIndex[i].w >= 0) - { // error correction is on and this probe is a sphere - //take a sample to get depth value, then error correct - refcol = tapRefMap(pos, dir, w, vi, wi, abs(lod + 2), refSphere[i].xyz, i); - - //adjust lookup by distance result - float d = length(vi - wi); - vi += dir * d; - - vi -= refSphere[i].xyz; + refcol = tapRefMap(pos, dir, w, dw, lod, refSphere[i].xyz, i); - vi = env_mat * vi; - - refcol = textureLod(reflectionProbes, vec4(vi, refIndex[i].x), lod).rgb; - - // weight by vector correctness - vec3 pi = normalize(wi - pos); - w *= max(dot(pi, dir), 0.1); - //w = pow(w, 32.0); - } - else - { - refcol = tapRefMap(pos, dir, w, vi, wi, lod, refSphere[i].xyz, i); - } - - col += refcol.rgb*w; - - wsum += w; + col[p] += refcol.rgb*w; + wsum[p] += w; + dwsum[p] += dw; } } - if (wsum > 0.0) + // mix automatic and manual probes + if (sample_automatic && wsum[0] > 0.0) + { // some automatic probes were sampled + col[0] *= 1.0/wsum[0]; + if (wsum[1] > 0.0) + { //some manual probes were sampled, mix between the two + col[1] *= 1.0/wsum[1]; + col[1] = mix(col[0], col[1], min(dwsum[1], 1.0)); + col[0] = vec3(0); + } + } + else if (wsum[1] > 0.0) { - col *= 1.0/wsum; + // manual probes were sampled but no automatic probes were + col[1] *= 1.0/wsum[1]; + col[0] = vec3(0); } - return col; + return col[1]+col[0]; } vec3 sampleProbeAmbient(vec3 pos, vec3 dir) { // modified copy/paste of sampleProbes follows, will likely diverge from sampleProbes further // as irradiance map mixing is tuned independently of radiance map mixing - float wsum = 0.0; - vec3 col = vec3(0,0,0); - float vd2 = dot(pos,pos); // view distance squared + float wsum[2]; + wsum[0] = 0; + wsum[1] = 0; + + float dwsum[2]; + dwsum[0] = 0; + dwsum[1] = 0; - float minweight = 1.0; + vec3 col[2]; + col[0] = vec3(0); + col[1] = vec3(0); for (int idx = 0; idx < probeInfluences; ++idx) { int i = probeIndex[idx]; - if (abs(refIndex[i].w) < max_priority) + int p = clamp(abs(refIndex[i].w), 0, 1); + + if (p == 0 && !sample_automatic) { continue; } { - float w; - vec3 refcol = tapIrradianceMap(pos, dir, w, refSphere[i].xyz, i); + float w = 0; + float dw = 0; + + vec3 refcol = tapIrradianceMap(pos, dir, w, dw, refSphere[i].xyz, i); - col += refcol*w; - - wsum += w; + col[p] += refcol*w; + wsum[p] += w; + dwsum[p] += dw; } } - if (wsum > 0.0) + // mix automatic and manual probes + if (sample_automatic && wsum[0] > 0.0) + { // some automatic probes were sampled + col[0] *= 1.0/wsum[0]; + if (wsum[1] > 0.0) + { //some manual probes were sampled, mix between the two + col[1] *= 1.0/wsum[1]; + col[1] = mix(col[0], col[1], min(dwsum[1], 1.0)); + col[0] = vec3(0); + } + } + else if (wsum[1] > 0.0) { - col *= 1.0/wsum; + // manual probes were sampled but no automatic probes were + col[1] *= 1.0/wsum[1]; + col[0] = vec3(0); } - - return col; + + return col[1]+col[0]; } 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) { // TODO - don't hard code lods - float reflection_lods = max_probe_lod; + float reflection_lods = max_probe_lod-1; preProbeSample(pos); vec3 refnormpersp = reflect(pos.xyz, norm.xyz); @@ -640,13 +664,12 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, ambenv = sampleProbeAmbient(pos, norm); float lod = (1.0-glossiness)*reflection_lods; - glossenv = sampleProbes(pos, normalize(refnormpersp), lod, errorCorrect); + glossenv = sampleProbes(pos, normalize(refnormpersp), lod); #if defined(SSR) if (cube_snapshot != 1 && glossiness >= 0.9) { vec4 ssr = vec4(0); - //float w = tapScreenSpaceReflection(errorCorrect ? 1 : 4, tc, pos, norm, ssr, sceneMap); float w = tapScreenSpaceReflection(1, tc, pos, norm, ssr, sceneMap); glossenv = mix(glossenv, ssr.rgb, w); @@ -654,11 +677,20 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, #endif } +void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv, + vec2 tc, vec3 pos, vec3 norm, float glossiness) +{ + sampleReflectionProbes(ambenv, glossenv, tc, pos, norm, glossiness); + + // fudge factor to get PBR water at a similar luminance ot legacy water + glossenv *= 0.25; +} + void debugTapRefMap(vec3 pos, vec3 dir, float depth, int i, inout vec4 col) { vec3 origin = vec3(0,0,0); - bool manual_probe = abs(refIndex[i].w) > 2; + bool manual_probe = abs(refIndex[i].w) > 0; if (manual_probe) { @@ -694,18 +726,9 @@ vec4 sampleReflectionProbesDebug(vec3 pos) return col; } -void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness) -{ - sampleReflectionProbes(ambenv, glossenv, - tc, pos, norm, glossiness, false); -} - - void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity) { - // TODO - don't hard code lods float reflection_lods = max_probe_lod; preProbeSample(pos); @@ -716,12 +739,12 @@ void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout if (glossiness > 0.0) { float lod = (1.0-glossiness)*reflection_lods; - glossenv = sampleProbes(pos, normalize(refnormpersp), lod, false); + glossenv = sampleProbes(pos, normalize(refnormpersp), lod); } if (envIntensity > 0.0) { - legacyenv = sampleProbes(pos, normalize(refnormpersp), 0.0, false); + legacyenv = sampleProbes(pos, normalize(refnormpersp), 0.0); } #if defined(SSR) diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 8d48e6f596..dfd1d47b3e 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -85,6 +85,8 @@ float getDepth(vec2 pos_screen); vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); +uniform vec4 waterPlane; + #ifdef WATER_FOG vec4 applyWaterFogViewLinear(vec3 pos, vec4 color); #endif @@ -153,6 +155,24 @@ void main() calcAtmosphericVarsLinear(pos.xyz, norm.xyz, light_dir, sunlit, amblit, additive, atten); + vec3 sunlit_linear = srgb_to_linear(sunlit); + vec3 amblit_linear = amblit; + + bool do_atmospherics = false; + +#ifndef WATER_FOG + // when above water, mask off atmospherics below water + if (dot(pos.xyz, waterPlane.xyz) + waterPlane.w > 0.0) + { + do_atmospherics = true; + } +#else + do_atmospherics = true; +#endif + + vec3 irradiance = vec3(0); + vec3 radiance = vec3(0); + if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { vec3 orm = texture2D(specularRect, tc).rgb; @@ -161,23 +181,32 @@ void main() float ao = orm.r * ambocc; vec3 colorEmissive = texture2D(emissiveRect, tc).rgb; - // PBR IBL float gloss = 1.0 - perceptualRoughness; - vec3 irradiance = vec3(0); - vec3 radiance = vec3(0); + sampleReflectionProbes(irradiance, radiance, tc, pos.xyz, norm.xyz, gloss); // Take maximium of legacy ambient vs irradiance sample as irradiance // NOTE: ao is applied in pbrIbl (see pbrBaseLight), do not apply here - irradiance = max(amblit,irradiance); + irradiance = max(amblit_linear,irradiance); vec3 diffuseColor; vec3 specularColor; calcDiffuseSpecular(baseColor.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); + color = vec3(1,0,1); + color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit_linear, scol, radiance, irradiance, colorEmissive, ao, additive, atten); + + + if (do_atmospherics) + { + color = linear_to_srgb(color); + color = atmosFragLightingLinear(color, additive, atten); + color = srgb_to_linear(color); + } + + } else if (!GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_ATMOS)) { @@ -199,12 +228,12 @@ void main() sampleReflectionProbesLegacy(irradiance, glossenv, legacyenv, tc, pos.xyz, norm.xyz, spec.a, envIntensity); // use sky settings ambient or irradiance map sample, whichever is brighter - irradiance = max(amblit, irradiance); + irradiance = max(amblit_linear, irradiance); // apply lambertian IBL only (see pbrIbl) color.rgb = irradiance * ambocc; - vec3 sun_contrib = min(da, scol) * sunlit; + vec3 sun_contrib = min(da, scol) * sunlit_linear; color.rgb += sun_contrib; color.rgb *= baseColor.rgb; @@ -230,9 +259,16 @@ void main() applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); } - color = mix(atmosFragLightingLinear(color, additive, atten), fullbrightAtmosTransportFragLinear(color, additive, atten), baseColor.a); - color = scaleSoftClipFragLinear(color); - } + + if (do_atmospherics) + { + color = linear_to_srgb(color); + color = atmosFragLightingLinear(color, additive, atten); + color = srgb_to_linear(color); + } + } + + #ifdef WATER_FOG vec4 fogged = applyWaterFogViewLinear(pos.xyz, vec4(color, bloom)); diff --git a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl index 3d721cd048..7524567f6b 100644 --- a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl @@ -114,6 +114,7 @@ vec3 BlendNormal(vec3 bump1, vec3 bump2) } vec3 srgb_to_linear(vec3 col); +vec3 linear_to_srgb(vec3 col); vec3 vN, vT, vB; @@ -122,11 +123,8 @@ vec3 transform_normal(vec3 vNt) return normalize(vNt.x * vT + vNt.y * vB + vNt.z * vN); } -void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness); - -void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness, bool errorCorrect); +void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv, + vec2 tc, vec3 pos, vec3 norm, float glossiness); vec3 getPositionWithNDC(vec3 ndc); @@ -203,6 +201,8 @@ void main() calcAtmosphericVarsLinear(pos.xyz, wavef, vary_light_dir, sunlit, amblit, additive, atten); + vec3 sunlit_linear = srgb_to_linear(sunlit); + #ifdef TRANSPARENT_WATER vec4 fb = texture2D(screenTex, distort2); float depth = texture2D(screenDepth, distort2).r; @@ -219,21 +219,24 @@ void main() fb = applyWaterFogViewLinear(refPos, fb, sunlit); #else - vec4 fb = applyWaterFogViewLinear(viewVec*2048.0, vec4(0.5), sunlit); + vec4 fb = applyWaterFogViewLinear(viewVec*2048.0, vec4(1.0), sunlit_linear); #endif + // fudge sample on other side of water to be a tad darker + fb.rgb *= 0.75; + float metallic = 0.0; - float perceptualRoughness = 0.1; + float perceptualRoughness = 0.05; float gloss = 1.0 - perceptualRoughness; vec3 irradiance = vec3(0); vec3 radiance = vec3(0); - sampleReflectionProbes(irradiance, radiance, distort2, pos.xyz, wave_ibl.xyz, gloss); + sampleReflectionProbesWater(irradiance, radiance, distort2, pos.xyz, wave_ibl.xyz, gloss); irradiance = vec3(0); - vec3 diffuseColor; - vec3 specularColor; + vec3 diffuseColor = vec3(0); + vec3 specularColor = vec3(0); calcDiffuseSpecular(vec3(1), metallic, diffuseColor, specularColor); vec3 v = -normalize(pos.xyz); @@ -250,10 +253,7 @@ void main() vec3 punctual = pbrPunctual(vec3(0), specularColor, 0.1, metallic, normalize(wavef+up*max(dist, 32.0)/32.0*(1.0-vdu)), v, normalize(light_dir)); - vec3 color = punctual * sunlit * 2.75 * scol; - - color = atmosFragLightingLinear(color, additive, atten); - color = scaleSoftClipFragLinear(color); + vec3 color = punctual * sunlit_linear * 2.75 * scol; vec3 ibl = pbrIbl(vec3(0), vec3(1), radiance, vec3(0), ao, NdotV, 0.0); @@ -265,10 +265,24 @@ void main() f *= 0.9; f *= f; + // incoming scale is [0, 1] with 0.5 being default + // shift to 0.5 to 1.5 + f *= (fresnelScale - 0.5)+1.0; + + // incoming offset is [0, 1] with 0.5 being default + // shift from -1 to 1 + f += (fresnelOffset - 0.5) * 2.0; + f = clamp(f, 0, 1); - //fb.rgb *= 1.; - + color = mix(color, fb.rgb, f); + + color.rgb = linear_to_srgb(color.rgb); + color = atmosFragLightingLinear(color, additive, atten); + color = scaleSoftClipFragLinear(color); + color.rgb = srgb_to_linear(color.rgb); + + float spec = min(max(max(punctual.r, punctual.g), punctual.b), 0.05); frag_color = vec4(color, spec); //*sunAngle2); |