diff options
| author | Dave Parks <davep@lindenlab.com> | 2022-05-19 22:24:41 -0500 | 
|---|---|---|
| committer | Dave Parks <davep@lindenlab.com> | 2022-05-19 22:24:41 -0500 | 
| commit | 3564b24e2a90e0772c37185cc5dcedca29d62ab8 (patch) | |
| tree | 9c0e7fa9d747d7bca7b25352bf8e28c875163e77 /indra/newview/app_settings/shaders/class1 | |
| parent | 02fb1bd6103cad5538fc170e015f4329f3545542 (diff) | |
SL-17286 Reflection probe alpha/fullbright support.
Diffstat (limited to 'indra/newview/app_settings/shaders/class1')
4 files changed, 121 insertions, 53 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl index 9fcee04c32..a04f611440 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl @@ -35,10 +35,11 @@ out vec4 frag_color;  uniform sampler2D diffuseMap;  #endif +  VARYING vec4 vertex_color;  VARYING vec2 vary_texcoord0;  VARYING vec3 vary_texcoord1; -VARYING vec4 vary_position; +VARYING vec3 vary_position;  uniform samplerCube environmentMap; @@ -54,6 +55,14 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou  vec3 linear_to_srgb(vec3 c);  vec3 srgb_to_linear(vec3 c); +#ifdef HAS_REFLECTION_PROBES +// reflection probe interface +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyEnv,  +        vec3 pos, vec3 norm, float glossiness, float envIntensity); +void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 norm); +void applyLegacyEnv(inout vec3 color, vec3 legacyenv, vec4 spec, vec3 pos, vec3 norm, float envIntensity); +#endif +  // See:  //   class1\deferred\fullbrightShinyF.glsl  //   class1\lighting\lightFullbrightShinyF.glsl @@ -70,21 +79,29 @@ void main()  	// SL-9632 HUDs are affected by Atmosphere  	if (no_atmo == 0)  	{ -	vec3 sunlit; -	vec3 amblit; -	vec3 additive; -	vec3 atten; -		vec3 pos = vary_position.xyz/vary_position.w; - -	calcAtmosphericVars(pos.xyz, vec3(0), 1.0, sunlit, amblit, additive, atten, false); -	 -	vec3 envColor = textureCube(environmentMap, vary_texcoord1.xyz).rgb;	 -	float env_intensity = vertex_color.a; - -	//color.rgb = srgb_to_linear(color.rgb); -		color.rgb = mix(color.rgb, envColor.rgb, env_intensity); -	color.rgb = fullbrightAtmosTransportFrag(color.rgb, additive, atten); -	color.rgb = fullbrightScaleSoftClip(color.rgb); +        vec3 sunlit; +        vec3 amblit; +        vec3 additive; +        vec3 atten; +        vec3 pos = vary_position; +        calcAtmosphericVars(pos.xyz, vec3(0), 1.0, sunlit, amblit, additive, atten, false); + +        float env_intensity = vertex_color.a; +#ifndef HAS_REFLECTION_PROBES +        vec3 envColor = textureCube(environmentMap, vary_texcoord1.xyz).rgb;	 +        color.rgb = mix(color.rgb, envColor.rgb, env_intensity); +#else +        vec3 ambenv; +        vec3 glossenv; +        vec3 legacyenv; +        vec3 norm = normalize(vary_texcoord1.xyz); +        vec4 spec = vec4(0,0,0,0); +        sampleReflectionProbes(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, env_intensity); +        legacyenv *= 1.5; // fudge brighter +        applyLegacyEnv(color.rgb, legacyenv, spec, pos, norm, env_intensity); +#endif +        color.rgb = fullbrightAtmosTransportFrag(color.rgb, additive, atten); +        color.rgb = fullbrightScaleSoftClip(color.rgb);  	}  /* @@ -98,7 +115,6 @@ void main()  */  	color.a = 1.0; -  	//color.rgb = linear_to_srgb(color.rgb);  	frag_color = color; diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl index 2c139430e7..a897198062 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl @@ -44,7 +44,7 @@ ATTRIBUTE vec2 texcoord0;  VARYING vec4 vertex_color;  VARYING vec2 vary_texcoord0;  VARYING vec3 vary_texcoord1; -VARYING vec4 vary_position; +VARYING vec3 vary_position;  #ifdef HAS_SKIN  mat4 getObjectSkinnedTransform(); @@ -61,17 +61,23 @@ void main()      mat4 mat = getObjectSkinnedTransform();      mat = modelview_matrix * mat;      vec4 pos = mat * vert; -    vary_position = gl_Position = projection_matrix * pos; +    gl_Position = projection_matrix * pos;  	vec3 norm = normalize((mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz);  #else  	vec4 pos = (modelview_matrix * vert); -	vary_position = gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); +	gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0);  	vec3 norm = normalize(normal_matrix * normal);  #endif -	vec3 ref = reflect(pos.xyz, -norm); -	vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; +    vary_position = pos.xyz; +    vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; + +#ifndef HAS_REFLECTION_PROBES	 +    vec3 ref = reflect(pos.xyz, -norm);  	vary_texcoord1 = transpose(normal_matrix) * ref.xyz; +#else +    vary_texcoord1 = norm; +#endif  	calcAtmospherics(pos.xyz); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 02d83925ea..c5b1937cfb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -64,6 +64,13 @@ out vec4 frag_color;  float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen);  #endif +#ifdef HAS_REFLECTION_PROBES +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv,  +        vec3 pos, vec3 norm, float glossiness, float envIntensity); +void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 norm); +void applyLegacyEnv(inout vec3 color, vec3 legacyenv, vec4 spec, vec3 pos, vec3 norm, float envIntensity); +#endif +  uniform samplerCube environmentMap;  uniform sampler2D     lightFunc; @@ -322,6 +329,16 @@ void main()      // lighting from the sun stays sharp      float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0);      da = pow(da, 1.0 / 1.3); +    vec3 sun_contrib = min(da, shadow) * sunlit; + +#ifdef HAS_REFLECTION_PROBES +    vec3 ambenv; +    vec3 glossenv; +    vec3 legacyenv; +    sampleReflectionProbes(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); +    amblit = max(ambenv, amblit); +    color.rgb = amblit; +#else      color = amblit; @@ -333,9 +350,8 @@ void main()      ambient *= ambient;      ambient = (1.0 - ambient); -    vec3 sun_contrib = min(da, shadow) * sunlit; -          color *= ambient; +#endif      color += sun_contrib; @@ -345,35 +361,6 @@ void main()      if (spec.a > 0.0)  // specular reflection      { -        /*  // Reverting this specular calculation to previous 'dumbshiny' version - DJH 6/17/2020 -            // Preserving the refactored version as a comment for potential reconsideration, -            // overriding the general rule to avoid pollutiong the source with commented code. -            // -            //  If you're reading this in 2021+, feel free to obliterate. - -        vec3 npos = -normalize(pos.xyz); - -        //vec3 ref = dot(pos+lv, norm); -        vec3 h = normalize(light_dir.xyz + npos); -        float nh = dot(norm.xyz, h); -        float nv = dot(norm.xyz, npos); -        float vh = dot(npos, h); -        float sa = nh; -        float fres = pow(1 - dot(h, npos), 5)*0.4 + 0.5; - -        float gtdenom = 2 * nh; -        float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - -        if (nh > 0.0) -        { -            float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt / (nh*da); -            vec3 sp = sun_contrib*scol / 6.0f; -            sp = clamp(sp, vec3(0), vec3(1)); -            bloom = dot(sp, sp) / 4.0; -            color += sp * spec.rgb; -        } -        */ -          float sa        = dot(refnormpersp, sun_dir.xyz);          vec3  dumbshiny = sunlit * shadow * (texture2D(lightFunc, vec2(sa, spec.a)).r); @@ -385,10 +372,24 @@ void main()          glare = max(glare, spec_contrib.b);          color += spec_contrib; + +#ifdef HAS_REFLECTION_PROBES +        applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); +#endif      } +      color = mix(color.rgb, diffcol.rgb, diffuse.a); +#ifdef HAS_REFLECTION_PROBES +    if (envIntensity > 0.0) +    {  // add environmentmap +        //fudge darker +        legacyenv *= 0.5*diffuse.a+0.5; +         +        applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); +    } +#else      if (envIntensity > 0.0)      {          //add environmentmap @@ -403,6 +404,7 @@ void main()          cur_glare *= envIntensity*4.0;          glare += cur_glare;      } +#endif      color = atmosFragLighting(color, additive, atten);      color = scaleSoftClipFrag(color); diff --git a/indra/newview/app_settings/shaders/class1/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class1/deferred/reflectionProbeF.glsl new file mode 100644 index 0000000000..8f3e38b08b --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/reflectionProbeF.glsl @@ -0,0 +1,44 @@ +/** + * @file class1/deferred/reflectionProbeF.glsl + * + * $LicenseInfo:firstyear=2022&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2022, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA + * $/LicenseInfo$ + */ + +// fallback stub -- will be used if actual reflection probe shader failed to load (output pink so it's obvious) +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv,  +        vec3 pos, vec3 norm, float glossiness, float envIntensity) +{ +    ambenv = vec3(1,0,1); +    glossenv = vec3(1,0,1); +    legacyenv = vec3(1,0,1); +} + +void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 norm) +{ +    color = vec3(1,0,1); +} + +void applyLegacyEnv(inout vec3 color, vec3 legacyenv, vec4 spec, vec3 pos, vec3 norm, float envIntensity) +{ +    color = vec3(1,0,1); +} +  | 
