From b2d8d63890e3ba0a5fe303f8e2de7358e4f9fc23 Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Fri, 9 Mar 2018 20:59:18 +0000 Subject: Fix warnings from shaders and include EXTRA_CODE_HERE sentinel in places using DEFINE_GL_FRAGCOLOR for consistency. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 07d28ed4cd..76750c400a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #define DIFFUSE_ALPHA_MODE_IGNORE 0 #define DIFFUSE_ALPHA_MODE_BLEND 1 #define DIFFUSE_ALPHA_MODE_MASK 2 -- cgit v1.2.3 From b6b23926340d8a2ac142b02923f04624b7c6b08e Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Fri, 9 Mar 2018 21:40:46 +0000 Subject: De-duplicate water fog code and modify programs to include the shared object as necessary. --- .../shaders/class1/deferred/materialF.glsl | 52 +++------------------- 1 file changed, 5 insertions(+), 47 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 76750c400a..6fa625765a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -33,6 +33,10 @@ uniform float emissive_brightness; uniform float display_gamma; +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 color); +#endif + vec3 srgb_to_linear(vec3 cs) { vec3 low_range = cs / vec3(12.92); @@ -154,52 +158,6 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; -#ifdef WATER_FOG -uniform vec4 waterPlane; -uniform vec4 waterFogColor; -uniform float waterFogDensity; -uniform float waterFogKS; - -vec4 applyWaterFogDeferred(vec3 pos, vec4 color) -{ - //normalize view vector - vec3 view = normalize(pos); - 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; - float ks = waterFogKS; - vec4 kc = waterFogColor; - - 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.a = kc.a + color.a; - - return color; -} -#endif - vec3 calcDirectionalLight(vec3 n, vec3 l) { float a = max(dot(n,l),0.0); @@ -773,7 +731,7 @@ void main() col.rgb = linear_to_srgb(col.rgb); #ifdef WATER_FOG - vec4 temp = applyWaterFogDeferred(pos, vec4(col.rgb, al)); + vec4 temp = applyWaterFogView(pos, vec4(col.rgb, al)); col.rgb = temp.rgb; al = temp.a; #endif -- cgit v1.2.3 From cf460b13bee894684d0ca1bcb5bbc9eb38df719c Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Mon, 12 Mar 2018 16:24:16 +0100 Subject: De-duplicate sRGB conversion funcs from many shaders and unify on using the version that works on OSX. Add more logging to shader loading about fallbacks and loading succcess. Add frag shaders for sharing sRGB and normal encode/decode via GL shader linkage. --- .../shaders/class1/deferred/materialF.glsl | 38 ++-------------------- 1 file changed, 2 insertions(+), 36 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 6fa625765a..e1b582c08c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -37,42 +37,8 @@ uniform float display_gamma; vec4 applyWaterFogView(vec3 pos, vec4 color); #endif -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lte); -#endif - -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif - -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) -- cgit v1.2.3 From 98b2fed85fd459012ed2b859ea40a3f56d27c0e8 Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Mon, 12 Mar 2018 17:52:04 +0100 Subject: De-duplicate shader code for encoding and decoding normals to/from gbuffer format. --- .../shaders/class1/deferred/materialF.glsl | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index e1b582c08c..d14805eccf 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -441,22 +441,8 @@ VARYING vec3 vary_normal; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +vec2 encode_normal(vec3 n); +vec3 decode_normal (vec2 enc); void main() { -- cgit v1.2.3 From 4f6682ca29cefb83ac2307657d8605f96051da19 Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Mon, 12 Mar 2018 22:26:22 +0100 Subject: De-duplicate deferred shader code for atmospherics and transport. --- .../shaders/class1/deferred/materialF.glsl | 235 ++------------------- 1 file changed, 17 insertions(+), 218 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index d14805eccf..a90e433622 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -40,6 +40,12 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); +vec3 atmosFragAmbient(vec3 l, vec3 ambient); +vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); +vec3 scaleFragSoftClip(vec3 l); +vec3 atmosFragAffectDirectionalLight(float intensity, vec3 sunlit); +void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); + #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) #ifdef DEFINE_GL_FRAGCOLOR @@ -88,19 +94,6 @@ uniform vec4 morphFactor; uniform vec3 camPosLocal; //uniform vec4 camPosWorld; uniform vec4 gamma; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 blue_density; -uniform float haze_horizon; -uniform float haze_density; -uniform float cloud_shadow; -uniform float density_multiplier; -uniform float distance_multiplier; -uniform float max_y; -uniform vec4 glow; -uniform float scene_light_strength; uniform mat3 env_mat; uniform mat3 ssao_effect_mat; @@ -109,13 +102,6 @@ VARYING vec2 vary_fragcoord; VARYING vec3 vary_position; -vec3 vary_PositionEye; - -vec3 vary_SunlitColor; -vec3 vary_AmblitColor; -vec3 vary_AdditiveColor; -vec3 vary_AtmosAttenuation; - uniform mat4 inv_proj; uniform vec2 screen_res; @@ -209,198 +195,6 @@ vec4 getPosition_d(vec2 pos_screen, float depth) return pos; } -#ifndef WATER_FOG -vec3 getPositionEye() -{ - return vary_PositionEye; -} -#endif - -vec3 getSunlitColor() -{ - return vary_SunlitColor; -} -vec3 getAmblitColor() -{ - return vary_AmblitColor; -} -vec3 getAdditiveColor() -{ - return vary_AdditiveColor; -} -vec3 getAtmosAttenuation() -{ - return vary_AtmosAttenuation; -} - -void setPositionEye(vec3 v) -{ - vary_PositionEye = v; -} - -void setSunlitColor(vec3 v) -{ - vary_SunlitColor = v; -} - -void setAmblitColor(vec3 v) -{ - vary_AmblitColor = v; -} - -void setAdditiveColor(vec3 v) -{ - vary_AdditiveColor = v; -} - -void setAtmosAttenuation(vec3 v) -{ - vary_AtmosAttenuation = v; -} - -void calcAtmospherics(vec3 inPositionEye, float ambFactor) { - - vec3 P = inPositionEye; - setPositionEye(P); - - vec3 tmpLightnorm = lightnorm.xyz; - - vec3 Pn = normalize(P); - float Plen = length(P); - - vec4 temp1 = vec4(0); - vec3 temp2 = vec3(0); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - //sunlight attenuation effect (hue and brightness) due to atmosphere - //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); - //I had thought blue_density and haze_density should have equal weighting, - //but attenuation due to haze_density tends to seem too strong - - temp1 = blue_density + vec4(haze_density); - blue_weight = blue_density / temp1; - haze_weight = vec4(haze_density) / temp1; - - //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) - temp2.y = max(0.0, tmpLightnorm.y); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier); - - //final atmosphere attenuation factor - setAtmosAttenuation(temp1.rgb); - - //compute haze glow - //(can use temp2.x as temp because we haven't used it yet) - temp2.x = dot(Pn, tmpLightnorm.xyz); - temp2.x = 1. - temp2.x; - //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .03); //was glow.y - //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - //glow.z should be negative, so we're doing a sort of (1 / "angle") function - - //add "minimum anti-solar illumination" - temp2.x += .25; - - //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; - - /* decrease value and saturation (that in HSV, not HSL) for occluded areas - * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html - * // The following line of code performs the equivalent of: - * float ambAlpha = tmpAmbient.a; - * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis - * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); - * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); - */ - tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); - - //haze color - setAdditiveColor( - vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - + tmpAmbient))); - - //brightness of surface both sunlight and ambient - setSunlitColor(vec3(sunlight * .5)); - setAmblitColor(vec3(tmpAmbient * .25)); - setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); -} - -vec3 atmosLighting(vec3 light) -{ - light *= getAtmosAttenuation().r; - light += getAdditiveColor(); - return (2.0 * light); -} - -vec3 atmosTransport(vec3 light) { - light *= getAtmosAttenuation().r; - light += getAdditiveColor() * 2.0; - return light; -} -vec3 atmosGetDiffuseSunlightColor() -{ - return getSunlitColor(); -} - -vec3 scaleDownLight(vec3 light) -{ - return (light / vec3(scene_light_strength, scene_light_strength, scene_light_strength)); -} - -vec3 scaleUpLight(vec3 light) -{ - return (light * vec3(scene_light_strength, scene_light_strength, scene_light_strength)); -} - -vec3 atmosAmbient(vec3 light) -{ - return getAmblitColor() + (light * vec3(0.5f, 0.5f, 0.5f)); -} - -vec3 atmosAffectDirectionalLight(float lightIntensity) -{ - return getSunlitColor() * vec3(lightIntensity, lightIntensity, lightIntensity); -} - -vec3 scaleSoftClip(vec3 light) -{ - //soft clip effect: - vec3 zeroes = vec3(0.0f, 0.0f, 0.0f); - vec3 ones = vec3(1.0f, 1.0f, 1.0f); - - light = ones - clamp(light, zeroes, ones); - light = ones - pow(light, gamma.xxx); - - return light; -} - -vec3 fullbrightAtmosTransport(vec3 light) { - float brightness = dot(light.rgb, vec3(0.33333)); - - return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); -} - -vec3 fullbrightScaleSoftClip(vec3 light) -{ - //soft clip effect: - return light; -} #else #ifdef DEFINE_GL_FRAGCOLOR @@ -585,7 +379,12 @@ void main() vec3 col = vec3(0.0f,0.0f,0.0f); float bloom = 0.0; - calcAtmospherics(pos.xyz, 1.0); + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; + + calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); @@ -598,7 +397,7 @@ void main() final_da = min(final_da, 1.0f); final_da = pow(final_da, 1.0/1.3); - col.rgb = atmosAmbient(col); + col.rgb = atmosFragAmbient(col, amblit); float ambient = min(abs(da), 1.0); ambient *= 0.5; @@ -607,7 +406,7 @@ void main() col.rgb *= ambient; - col.rgb = col.rgb + atmosAffectDirectionalLight(final_da); + col.rgb = col.rgb + atmosFragAffectDirectionalLight(final_da, sunlit); col.rgb *= gamma_diff.rgb; @@ -620,7 +419,7 @@ void main() // float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = vary_SunlitColor*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); + vec3 dumbshiny = sunlit*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; @@ -654,8 +453,8 @@ void main() //col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); //col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); - col = atmosLighting(col); - col = scaleSoftClip(col); + col = atmosFragLighting(col, additive, atten); + col = scaleFragSoftClip(col); //convert to linear space before adding local lights col = srgb_to_linear(col); -- cgit v1.2.3 From 67ab0084f87c40bf31d7fadded55cc9ea6299ca2 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 12 Jun 2018 18:42:07 +0100 Subject: Fix env panel forward action. Make env panel update environment when jumping frame to frame. Add separate funcs for sun/moon vectors in various coord systems. Make haze glow only pay attention to sun (i.e. fix sun glow when moon is near horizon in daytime). --- .../app_settings/shaders/class1/deferred/materialF.glsl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index a90e433622..4dc15dbc89 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -98,6 +98,7 @@ uniform mat3 env_mat; uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; +uniform vec3 moon_dir; VARYING vec2 vary_fragcoord; VARYING vec3 vary_position; @@ -388,7 +389,9 @@ void main() vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - float da =dot(norm.xyz, sun_dir.xyz); + float da_sun =dot(norm.xyz, sun_dir.xyz); + float da_moon =dot(norm.xyz, moon_dir.xyz); + float da = max(da_sun, da_moon); float final_da = da; final_da = min(final_da, shadow); @@ -418,7 +421,10 @@ void main() // the old infinite-sky shiny reflection // - float sa = dot(refnormpersp, sun_dir.xyz); + float sa_sun = dot(refnormpersp, sun_dir.xyz); + float sa_moon = dot(refnormpersp, moon_dir.xyz); + float sa = max(sa_sun, sa_moon); + vec3 dumbshiny = sunlit*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); // add the two types of shiny together -- cgit v1.2.3 From facc678391417c5fa8ca659adc1d449bba2fd349 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 9 Aug 2018 22:46:47 +0100 Subject: MAINT-8951 Remove moon_dir related shader code causing sunlight shadow artifacting. --- .../newview/app_settings/shaders/class1/deferred/materialF.glsl | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 4dc15dbc89..6e06453a5b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -98,7 +98,6 @@ uniform mat3 env_mat; uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; -uniform vec3 moon_dir; VARYING vec2 vary_fragcoord; VARYING vec3 vary_position; @@ -389,9 +388,7 @@ void main() vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - float da_sun =dot(norm.xyz, sun_dir.xyz); - float da_moon =dot(norm.xyz, moon_dir.xyz); - float da = max(da_sun, da_moon); + float da =dot(norm.xyz, sun_dir.xyz); float final_da = da; final_da = min(final_da, shadow); @@ -421,9 +418,7 @@ void main() // the old infinite-sky shiny reflection // - float sa_sun = dot(refnormpersp, sun_dir.xyz); - float sa_moon = dot(refnormpersp, moon_dir.xyz); - float sa = max(sa_sun, sa_moon); + float sa = dot(refnormpersp, sun_dir.xyz); vec3 dumbshiny = sunlit*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); -- cgit v1.2.3 From fb335cc243581925bb772a1f10112ec493db8552 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 1 Nov 2018 18:26:24 +0100 Subject: SL-10000 fix storing of ambient value when converting legacy settings --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 6e06453a5b..9f52e72313 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -42,7 +42,7 @@ vec3 linear_to_srgb(vec3 cl); vec3 atmosFragAmbient(vec3 l, vec3 ambient); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); -vec3 scaleFragSoftClip(vec3 l); +vec3 scaleSoftClipFrag(vec3 l); vec3 atmosFragAffectDirectionalLight(float intensity, vec3 sunlit); void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); @@ -455,7 +455,7 @@ void main() //col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); col = atmosFragLighting(col, additive, atten); - col = scaleFragSoftClip(col); + col = scaleSoftClipFrag(col); //convert to linear space before adding local lights col = srgb_to_linear(col); -- cgit v1.2.3 From a67cf385d763325119f4d2a37beb96c9c6a80282 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 1 Nov 2018 19:04:11 +0100 Subject: Back out unintended shader changes from SL-10000 fix. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 9f52e72313..6e06453a5b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -42,7 +42,7 @@ vec3 linear_to_srgb(vec3 cl); vec3 atmosFragAmbient(vec3 l, vec3 ambient); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); -vec3 scaleSoftClipFrag(vec3 l); +vec3 scaleFragSoftClip(vec3 l); vec3 atmosFragAffectDirectionalLight(float intensity, vec3 sunlit); void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); @@ -455,7 +455,7 @@ void main() //col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); col = atmosFragLighting(col, additive, atten); - col = scaleSoftClipFrag(col); + col = scaleFragSoftClip(col); //convert to linear space before adding local lights col = srgb_to_linear(col); -- cgit v1.2.3 From 4f267a5723e7da2de36b9f2295e4942a4c8bf6c5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 1 Nov 2018 20:28:47 +0100 Subject: SL-9994 Make shaders use consistent naming and parameter order for transport and atmospheric helpers. Share transport and gamma correction code where possible. Add lots of asserts and other validation for when things don't go as planned. Engage dumpShaderSource to get more source output with shader compilation fail. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 6e06453a5b..c001ff9ac8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -42,8 +42,8 @@ vec3 linear_to_srgb(vec3 cl); vec3 atmosFragAmbient(vec3 l, vec3 ambient); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); -vec3 scaleFragSoftClip(vec3 l); -vec3 atmosFragAffectDirectionalLight(float intensity, vec3 sunlit); +vec3 scaleSoftClipFrag(vec3 l); + void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) @@ -406,7 +406,7 @@ void main() col.rgb *= ambient; - col.rgb = col.rgb + atmosFragAffectDirectionalLight(final_da, sunlit); + col.rgb = col.rgb + (final_da * sunlit); col.rgb *= gamma_diff.rgb; @@ -455,7 +455,7 @@ void main() //col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); col = atmosFragLighting(col, additive, atten); - col = scaleFragSoftClip(col); + col = scaleSoftClipFrag(col); //convert to linear space before adding local lights col = srgb_to_linear(col); -- cgit v1.2.3 From 8c1aefc17c710b55ed7a72bd9de14cbed58ccd31 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 6 Nov 2018 16:38:06 +0000 Subject: Remove scaleDownLight funcs and eliminate unused copy-pasted funcs in lighting shaders. Also fix terrain response to atmospherics shaders (was failing to apply ambient on low end even when atmospherics was on). --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 7 ------- 1 file changed, 7 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index c001ff9ac8..c1c17532b8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -110,13 +110,6 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; -vec3 calcDirectionalLight(vec3 n, vec3 l) -{ - float a = max(dot(n,l),0.0); - return vec3(a,a,a); -} - - 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) { //get light vector -- cgit v1.2.3 From 2929998982f37221a58b9fa8037748a2e905f4b1 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 6 Nov 2018 19:33:04 +0000 Subject: Move to using a shared deferredUtil object for getting pos/norm from gbuffer. Eliminate 20+ callsites with copy-paste of getPosition and/or getNorm code. Make pipeline use getShadowTarget/releaseShadowTarget consistently. --- .../shaders/class1/deferred/materialF.glsl | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index c1c17532b8..1e566b77bf 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -40,7 +40,6 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); -vec3 atmosFragAmbient(vec3 l, vec3 ambient); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); @@ -176,19 +175,6 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe } -vec4 getPosition_d(vec2 pos_screen, float depth) -{ - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} - - #else #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; @@ -233,6 +219,8 @@ vec3 decode_normal (vec2 enc); void main() { + vec2 pos_screen = vary_texcoord0.xy; + vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); diffcol.rgb *= vertex_color.rgb; @@ -390,7 +378,7 @@ void main() final_da = min(final_da, 1.0f); final_da = pow(final_da, 1.0/1.3); - col.rgb = atmosFragAmbient(col, amblit); + col.rgb = (col * 0.5) + amblit; float ambient = min(abs(da), 1.0); ambient *= 0.5; @@ -444,9 +432,6 @@ void main() glare += cur_glare; } - //col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); - //col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); - col = atmosFragLighting(col, additive, atten); col = scaleSoftClipFrag(col); -- cgit v1.2.3 From db270df7cc00c1e2519749831e7e98c2c10e3ee6 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 9 Nov 2018 18:31:29 +0000 Subject: Back out changes causing broken shadows and other render shenanigans. --- .../shaders/class1/deferred/materialF.glsl | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 1e566b77bf..c1c17532b8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -40,6 +40,7 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); +vec3 atmosFragAmbient(vec3 l, vec3 ambient); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); @@ -175,6 +176,19 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe } +vec4 getPosition_d(vec2 pos_screen, float depth) +{ + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} + + #else #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; @@ -219,8 +233,6 @@ vec3 decode_normal (vec2 enc); void main() { - vec2 pos_screen = vary_texcoord0.xy; - vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); diffcol.rgb *= vertex_color.rgb; @@ -378,7 +390,7 @@ void main() final_da = min(final_da, 1.0f); final_da = pow(final_da, 1.0/1.3); - col.rgb = (col * 0.5) + amblit; + col.rgb = atmosFragAmbient(col, amblit); float ambient = min(abs(da), 1.0); ambient *= 0.5; @@ -432,6 +444,9 @@ void main() glare += cur_glare; } + //col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); + //col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); + col = atmosFragLighting(col, additive, atten); col = scaleSoftClipFrag(col); -- cgit v1.2.3 From b6fa72d3c4d02527f6d118eadc9ba1ac48a297f5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 3 Dec 2018 15:33:15 -0800 Subject: SL-10055 Modify handling of directional light to prefer sun when it is up but use moon dir/color when it is alone in the sky. Modify handling of shader in shaders to get some shadowing of ambient and nighttime shadowing. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index c1c17532b8..7d5ae7c2e7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -98,6 +98,7 @@ uniform mat3 env_mat; uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; +uniform vec3 moon_dir; VARYING vec2 vary_fragcoord; VARYING vec3 vary_position; @@ -381,9 +382,10 @@ void main() vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - float da =dot(norm.xyz, sun_dir.xyz); + float sun_da = dot(norm.xyz, sun_dir.xyz); + float moon_da = dot(norm.xyz, moon_dir.xyz); - float final_da = da; + float final_da = max(sun_da,moon_da); final_da = min(final_da, shadow); //final_da = max(final_da, diffuse.a); final_da = max(final_da, 0.0f); @@ -392,7 +394,7 @@ void main() col.rgb = atmosFragAmbient(col, amblit); - float ambient = min(abs(da), 1.0); + float ambient = min(abs(final_da), 1.0); ambient *= 0.5; ambient *= ambient; ambient = (1.0-ambient); -- cgit v1.2.3 From 26c1430a04de585c1823569b60dc99abc798231b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 5 Dec 2018 13:08:06 -0800 Subject: Shader cleanup and consolidation of use of sRGB conversion funcs. --- .../shaders/class1/deferred/materialF.glsl | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 7d5ae7c2e7..211bedee59 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -37,10 +37,6 @@ uniform float display_gamma; vec4 applyWaterFogView(vec3 pos, vec4 color); #endif -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); - -vec3 atmosFragAmbient(vec3 l, vec3 ambient); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); @@ -234,6 +230,8 @@ vec3 decode_normal (vec2 enc); void main() { + vec2 pos_screen = vary_texcoord0.xy; + vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); diffcol.rgb *= vertex_color.rgb; @@ -246,7 +244,6 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) vec3 gamma_diff = diffcol.rgb; - diffcol.rgb = srgb_to_linear(diffcol.rgb); #endif #if HAS_SPECULAR_MAP @@ -390,9 +387,9 @@ void main() //final_da = max(final_da, diffuse.a); final_da = max(final_da, 0.0f); final_da = min(final_da, 1.0f); - final_da = pow(final_da, 1.0/1.3); + final_da = pow(final_da, display_gamma); - col.rgb = atmosFragAmbient(col, amblit); + col.rgb = (col * 0.5) + amblit; float ambient = min(abs(final_da), 1.0); ambient *= 0.5; @@ -446,14 +443,7 @@ void main() glare += cur_glare; } - //col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); - //col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); - col = atmosFragLighting(col, additive, atten); - col = scaleSoftClipFrag(col); - - //convert to linear space before adding local lights - col = srgb_to_linear(col); vec3 npos = normalize(-pos.xyz); @@ -474,8 +464,7 @@ void main() glare = min(glare, 1.0); float al = max(diffcol.a,glare)*vertex_color.a; - //convert to gamma space for display on screen - col.rgb = linear_to_srgb(col.rgb); + col = scaleSoftClipFrag(col); #ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(col.rgb, al)); -- cgit v1.2.3 From 7e9033821a96a9d6e80b58fafb4c7da63807b9d4 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 6 Dec 2018 10:59:11 -0800 Subject: De-duplicate deferred gbuffer access for getPosition/getNorm. De-duplicate ambient occlusion shader code and move to new aoUtil.glsl Split shared shadow tap funcs into shadowUtil.glsl --- .../shaders/class1/deferred/materialF.glsl | 487 +++++++++++---------- 1 file changed, 244 insertions(+), 243 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 211bedee59..a0da8563a2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -25,9 +25,9 @@ /*[EXTRA_CODE_HERE]*/ -#define DIFFUSE_ALPHA_MODE_IGNORE 0 -#define DIFFUSE_ALPHA_MODE_BLEND 1 -#define DIFFUSE_ALPHA_MODE_MASK 2 +#define DIFFUSE_ALPHA_MODE_IGNORE 0 +#define DIFFUSE_ALPHA_MODE_BLEND 1 +#define DIFFUSE_ALPHA_MODE_MASK 2 #define DIFFUSE_ALPHA_MODE_EMISSIVE 3 uniform float emissive_brightness; @@ -62,7 +62,7 @@ uniform vec4 shadow_clip; uniform vec2 shadow_res; uniform float shadow_bias; -float pcfShadow(sampler2DShadow shadowMap, vec4 stc) +float pcfShadowLegacy(sampler2DShadow shadowMap, vec4 stc) { stc.xyz /= stc.w; stc.z += shadow_bias; @@ -80,10 +80,11 @@ float pcfShadow(sampler2DShadow shadowMap, vec4 stc) return shadow*0.2; } +float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen); #endif uniform samplerCube environmentMap; -uniform sampler2D lightFunc; +uniform sampler2D lightFunc; // Inputs uniform vec4 morphFactor; @@ -109,80 +110,80 @@ uniform vec3 light_diffuse[8]; 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) { - //get light vector - vec3 lv = lp.xyz-v; - - //get distance - float d = length(lv); - - float da = 1.0; - - vec3 col = vec3(0,0,0); - - if (d > 0.0 && la > 0.0 && fa > 0.0) - { - //normalize light vector - lv = normalize(lv); - - //distance attenuation - float dist = d/la; - float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); - dist_atten *= dist_atten; - dist_atten *= 2.0; - - // spotlight coefficient. - float spot = max(dot(-ln, lv), is_pointlight); - da *= spot*spot; // GL_SPOT_EXPONENT=2 - - //angular attenuation - da *= max(dot(n, lv), 0.0); - - float lit = max(da * dist_atten, 0.0); - - col = light_col*lit*diffuse; - - if (spec.a > 0.0) - { - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(lv+npos); - float nh = dot(n, h); - float nv = dot(n, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 speccol = lit*scol*light_col.rgb*spec.rgb; - 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); - //col += spec.rgb; - } - } - } - - return max(col, vec3(0.0,0.0,0.0)); + //get light vector + vec3 lv = lp.xyz-v; + + //get distance + float d = length(lv); + + float da = 1.0; + + vec3 col = vec3(0,0,0); + + if (d > 0.0 && la > 0.0 && fa > 0.0) + { + //normalize light vector + lv = normalize(lv); + + //distance attenuation + float dist = d/la; + float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); + dist_atten *= dist_atten; + dist_atten *= 2.0; + + // spotlight coefficient. + float spot = max(dot(-ln, lv), is_pointlight); + da *= spot*spot; // GL_SPOT_EXPONENT=2 + + //angular attenuation + da *= max(dot(n, lv), 0.0); + + float lit = max(da * dist_atten, 0.0); + + col = light_col*lit*diffuse; + + if (spec.a > 0.0) + { + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(lv+npos); + float nh = dot(n, h); + float nv = dot(n, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + vec3 speccol = lit*scol*light_col.rgb*spec.rgb; + 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); + //col += spec.rgb; + } + } + } + + return max(col, vec3(0.0,0.0,0.0)); } vec4 getPosition_d(vec2 pos_screen, float depth) { - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; } @@ -232,253 +233,253 @@ void main() { vec2 pos_screen = vary_texcoord0.xy; - vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); - diffcol.rgb *= vertex_color.rgb; + vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); + diffcol.rgb *= vertex_color.rgb; #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) - if (diffcol.a < minimum_alpha) - { - discard; - } + if (diffcol.a < minimum_alpha) + { + discard; + } #endif #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - vec3 gamma_diff = diffcol.rgb; + vec3 gamma_diff = diffcol.rgb; #endif #if HAS_SPECULAR_MAP - vec4 spec = texture2D(specularMap, vary_texcoord2.xy); - spec.rgb *= specular_color.rgb; + vec4 spec = texture2D(specularMap, vary_texcoord2.xy); + spec.rgb *= specular_color.rgb; #else - vec4 spec = vec4(specular_color.rgb, 1.0); + vec4 spec = vec4(specular_color.rgb, 1.0); #endif #if HAS_NORMAL_MAP - vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); + vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); - norm.xyz = norm.xyz * 2 - 1; + norm.xyz = norm.xyz * 2 - 1; - vec3 tnorm = vec3(dot(norm.xyz,vary_mat0), - dot(norm.xyz,vary_mat1), - dot(norm.xyz,vary_mat2)); + vec3 tnorm = vec3(dot(norm.xyz,vary_mat0), + dot(norm.xyz,vary_mat1), + dot(norm.xyz,vary_mat2)); #else - vec4 norm = vec4(0,0,0,1.0); - vec3 tnorm = vary_normal; + vec4 norm = vec4(0,0,0,1.0); + vec3 tnorm = vary_normal; #endif norm.xyz = tnorm; norm.xyz = normalize(norm.xyz); - vec2 abnormal = encode_normal(norm.xyz); - norm.xyz = decode_normal(abnormal.xy); + vec2 abnormal = encode_normal(norm.xyz); + norm.xyz = decode_normal(abnormal.xy); - vec4 final_color = diffcol; - + vec4 final_color = diffcol; + #if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) - final_color.a = emissive_brightness; + final_color.a = emissive_brightness; #else - final_color.a = max(final_color.a, emissive_brightness); + final_color.a = max(final_color.a, emissive_brightness); #endif - vec4 final_specular = spec; + vec4 final_specular = spec; #if HAS_SPECULAR_MAP - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, 0.0); - final_specular.a = specular_color.a * norm.a; + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, 0.0); + final_specular.a = specular_color.a * norm.a; #else - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); - final_specular.a = specular_color.a; + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); + final_specular.a = specular_color.a; #endif - + #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - //forward rendering, output just lit RGBA - vec3 pos = vary_position; + //forward rendering, output just lit RGBA + vec3 pos = vary_position; #if HAS_SUN_SHADOW - float shadow = 0.0; - - vec4 spos = vec4(pos,1.0); - - if (spos.z > -shadow_clip.w) - { - vec4 lpos; - - vec4 near_split = shadow_clip*-0.75; - vec4 far_split = shadow_clip*-1.25; - vec4 transition_domain = near_split-far_split; - float weight = 0.0; - - if (spos.z < near_split.z) - { - lpos = shadow_matrix[3]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap3, lpos)*w; - weight += w; - shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); - } - - if (spos.z < near_split.y && spos.z > far_split.z) - { - lpos = shadow_matrix[2]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; - w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap2, lpos)*w; - weight += w; - } - - if (spos.z < near_split.x && spos.z > far_split.y) - { - lpos = shadow_matrix[1]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; - w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; - shadow += pcfShadow(shadowMap1, lpos)*w; - weight += w; - } - - if (spos.z > far_split.x) - { - lpos = shadow_matrix[0]*spos; - - float w = 1.0; - w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; - - shadow += pcfShadow(shadowMap0, lpos)*w; - weight += w; - } - - - shadow /= weight; - } - else - { - shadow = 1.0; - } + float shadow = 0.0; + + vec4 spos = vec4(pos,1.0); + + if (spos.z > -shadow_clip.w) + { + vec4 lpos; + + vec4 near_split = shadow_clip*-0.75; + vec4 far_split = shadow_clip*-1.25; + vec4 transition_domain = near_split-far_split; + float weight = 0.0; + + if (spos.z < near_split.z) + { + lpos = shadow_matrix[3]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; + shadow += pcfShadowLegacy(shadowMap3, lpos)*w; + weight += w; + shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); + } + + if (spos.z < near_split.y && spos.z > far_split.z) + { + lpos = shadow_matrix[2]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; + w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; + shadow += pcfShadowLegacy(shadowMap2, lpos)*w; + weight += w; + } + + if (spos.z < near_split.x && spos.z > far_split.y) + { + lpos = shadow_matrix[1]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; + w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; + shadow += pcfShadowLegacy(shadowMap1, lpos)*w; + weight += w; + } + + if (spos.z > far_split.x) + { + lpos = shadow_matrix[0]*spos; + + float w = 1.0; + w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; + + shadow += pcfShadowLegacy(shadowMap0, lpos)*w; + weight += w; + } + + + shadow /= weight; + } + else + { + shadow = 1.0; + } #else - float shadow = 1.0; + float shadow = 1.0; #endif - spec = final_specular; - vec4 diffuse = final_color; - float envIntensity = final_normal.z; + spec = final_specular; + vec4 diffuse = final_color; + float envIntensity = final_normal.z; vec3 col = vec3(0.0f,0.0f,0.0f); - float bloom = 0.0; + float bloom = 0.0; vec3 sunlit; vec3 amblit; vec3 additive; vec3 atten; - calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); - - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); + + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - float sun_da = dot(norm.xyz, sun_dir.xyz); - float moon_da = dot(norm.xyz, moon_dir.xyz); + float sun_da = dot(norm.xyz, sun_dir.xyz); + float moon_da = dot(norm.xyz, moon_dir.xyz); float final_da = max(sun_da,moon_da); final_da = min(final_da, shadow); //final_da = max(final_da, diffuse.a); final_da = max(final_da, 0.0f); - final_da = min(final_da, 1.0f); - final_da = pow(final_da, display_gamma); + final_da = min(final_da, 1.0f); + final_da = pow(final_da, display_gamma); - col.rgb = (col * 0.5) + amblit; - - float ambient = min(abs(final_da), 1.0); - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0-ambient); + col.rgb = (col * 0.5) + amblit; + + float ambient = min(abs(final_da), 1.0); + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0-ambient); - col.rgb *= ambient; + col.rgb *= ambient; - col.rgb = col.rgb + (final_da * sunlit); + col.rgb = col.rgb + (final_da * sunlit); - col.rgb *= gamma_diff.rgb; - + col.rgb *= gamma_diff.rgb; + - float glare = 0.0; + float glare = 0.0; - if (spec.a > 0.0) // specular reflection - { - // the old infinite-sky shiny reflection - // - + if (spec.a > 0.0) // specular reflection + { + // the old infinite-sky shiny reflection + // + float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = sunlit*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); - - // add the two types of shiny together - vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 6; + vec3 dumbshiny = sunlit*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); + + // add the two types of shiny together + vec3 spec_contrib = dumbshiny * spec.rgb; + bloom = dot(spec_contrib, spec_contrib) / 6; - glare = max(spec_contrib.r, spec_contrib.g); - glare = max(glare, spec_contrib.b); + glare = max(spec_contrib.r, spec_contrib.g); + glare = max(glare, spec_contrib.b); - col += spec_contrib; - } + col += spec_contrib; + } - col = mix(col.rgb, diffcol.rgb, diffuse.a); + col = mix(col.rgb, diffcol.rgb, diffuse.a); - if (envIntensity > 0.0) - { - //add environmentmap - vec3 env_vec = env_mat * refnormpersp; - - vec3 refcol = textureCube(environmentMap, env_vec).rgb; + if (envIntensity > 0.0) + { + //add environmentmap + vec3 env_vec = env_mat * refnormpersp; + + vec3 refcol = textureCube(environmentMap, env_vec).rgb; - col = mix(col.rgb, refcol, - envIntensity); + col = mix(col.rgb, refcol, + envIntensity); - float cur_glare = max(refcol.r, refcol.g); - cur_glare = max(cur_glare, refcol.b); - cur_glare *= envIntensity*4.0; - glare += cur_glare; - } + float cur_glare = max(refcol.r, refcol.g); + cur_glare = max(cur_glare, refcol.b); + cur_glare *= envIntensity*4.0; + glare += cur_glare; + } - col = atmosFragLighting(col, additive, atten); + col = atmosFragLighting(col, additive, atten); - vec3 npos = normalize(-pos.xyz); - - vec3 light = vec3(0,0,0); + 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, glare); - LIGHT_LOOP(1) - LIGHT_LOOP(2) - LIGHT_LOOP(3) - LIGHT_LOOP(4) - LIGHT_LOOP(5) - LIGHT_LOOP(6) - LIGHT_LOOP(7) + LIGHT_LOOP(1) + LIGHT_LOOP(2) + LIGHT_LOOP(3) + LIGHT_LOOP(4) + LIGHT_LOOP(5) + LIGHT_LOOP(6) + LIGHT_LOOP(7) - col.rgb += light.rgb; + col.rgb += light.rgb; - glare = min(glare, 1.0); - float al = max(diffcol.a,glare)*vertex_color.a; + glare = min(glare, 1.0); + float al = max(diffcol.a,glare)*vertex_color.a; - col = scaleSoftClipFrag(col); + col = scaleSoftClipFrag(col); #ifdef WATER_FOG - vec4 temp = applyWaterFogView(pos, vec4(col.rgb, al)); - col.rgb = temp.rgb; - al = temp.a; + vec4 temp = applyWaterFogView(pos, vec4(col.rgb, al)); + col.rgb = temp.rgb; + al = temp.a; #endif - frag_color.rgb = col.rgb; - frag_color.a = al; + frag_color.rgb = col.rgb; + frag_color.a = al; #else - frag_data[0] = final_color; - frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. - frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. + frag_data[0] = final_color; + frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. + frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. #endif } -- cgit v1.2.3 From c007e1197c521a1b48736cbba29e7c7dadf39c20 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 4 Jan 2019 13:26:47 -0800 Subject: Convert to using shared shadow sampling function (reduce duplicated code blocks in several shaders). --- .../shaders/class1/deferred/materialF.glsl | 115 +-------------------- 1 file changed, 2 insertions(+), 113 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index a0da8563a2..0f7c514e94 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -50,38 +50,7 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -#if HAS_SUN_SHADOW - -uniform sampler2DShadow shadowMap0; -uniform sampler2DShadow shadowMap1; -uniform sampler2DShadow shadowMap2; -uniform sampler2DShadow shadowMap3; - -uniform mat4 shadow_matrix[6]; -uniform vec4 shadow_clip; -uniform vec2 shadow_res; -uniform float shadow_bias; - -float pcfShadowLegacy(sampler2DShadow shadowMap, vec4 stc) -{ - stc.xyz /= stc.w; - stc.z += shadow_bias; - - stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y*12345))/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 shadow = cs; - - shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - - return shadow*0.2; -} - -float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen); -#endif +float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); uniform samplerCube environmentMap; uniform sampler2D lightFunc; @@ -174,19 +143,6 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe } -vec4 getPosition_d(vec2 pos_screen, float depth) -{ - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} - - #else #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; @@ -295,74 +251,7 @@ void main() //forward rendering, output just lit RGBA vec3 pos = vary_position; -#if HAS_SUN_SHADOW - float shadow = 0.0; - - vec4 spos = vec4(pos,1.0); - - if (spos.z > -shadow_clip.w) - { - vec4 lpos; - - vec4 near_split = shadow_clip*-0.75; - vec4 far_split = shadow_clip*-1.25; - vec4 transition_domain = near_split-far_split; - float weight = 0.0; - - if (spos.z < near_split.z) - { - lpos = shadow_matrix[3]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - shadow += pcfShadowLegacy(shadowMap3, lpos)*w; - weight += w; - shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); - } - - if (spos.z < near_split.y && spos.z > far_split.z) - { - lpos = shadow_matrix[2]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; - w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - shadow += pcfShadowLegacy(shadowMap2, lpos)*w; - weight += w; - } - - if (spos.z < near_split.x && spos.z > far_split.y) - { - lpos = shadow_matrix[1]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; - w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; - shadow += pcfShadowLegacy(shadowMap1, lpos)*w; - weight += w; - } - - if (spos.z > far_split.x) - { - lpos = shadow_matrix[0]*spos; - - float w = 1.0; - w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; - - shadow += pcfShadowLegacy(shadowMap0, lpos)*w; - weight += w; - } - - - shadow /= weight; - } - else - { - shadow = 1.0; - } -#else - float shadow = 1.0; -#endif + float shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen); spec = final_specular; vec4 diffuse = final_color; -- cgit v1.2.3 From acbc7f4cddd6ad999c2bc7690c10b85a414a8102 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 30 Jan 2019 08:37:07 -0800 Subject: SL-10415, SL-10434 Further tweaking of directional shadow sampling to balance between peter-panning and shadow acne. Move stars to just this side of the sky some to reduce parallax. Remove decodeNormF and uses of decode_normal in favor of unified use of getNorm (try to help the Intel HD x000 compiler learn to link correctly). --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 -- 1 file changed, 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 0f7c514e94..09bb6c5bb8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -183,7 +183,6 @@ VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; vec2 encode_normal(vec3 n); -vec3 decode_normal (vec2 enc); void main() { @@ -227,7 +226,6 @@ void main() norm.xyz = normalize(norm.xyz); vec2 abnormal = encode_normal(norm.xyz); - norm.xyz = decode_normal(abnormal.xy); vec4 final_color = diffcol; -- cgit v1.2.3 From aafa561215b7b69a72d00ed709d6411f6438474d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 11 Feb 2019 09:36:01 -0800 Subject: SL-10500 Replace clamp on height in atmospherics calcs on fragment shader path. Fix colorspace conversions in material shaders in forward rendering mode. Fix deferred shaders not setting the sun_up_factor uniform and getting moonlight instead of sunlight. --- .../newview/app_settings/shaders/class1/deferred/materialF.glsl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 09bb6c5bb8..c8f4d7c570 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -42,6 +42,9 @@ vec3 scaleSoftClipFrag(vec3 l); void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cs); + #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) #ifdef DEFINE_GL_FRAGCOLOR @@ -199,7 +202,7 @@ void main() #endif #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - vec3 gamma_diff = diffcol.rgb; + vec3 gamma_diff = linear_to_srgb(diffcol.rgb); #endif #if HAS_SPECULAR_MAP @@ -332,6 +335,7 @@ void main() } col = atmosFragLighting(col, additive, atten); + col = scaleSoftClipFrag(col); vec3 npos = normalize(-pos.xyz); @@ -352,7 +356,8 @@ void main() glare = min(glare, 1.0); float al = max(diffcol.a,glare)*vertex_color.a; - col = scaleSoftClipFrag(col); + //convert to gamma space for display on screen + col.rgb = linear_to_srgb(col.rgb); #ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(col.rgb, al)); -- cgit v1.2.3 From 4aad62006259c20bcdda1495138f7313b8f35e8d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 22 Feb 2019 14:50:03 -0800 Subject: SL-10415, SL-10612, SL-10569 Fix shadow sampling min with caster dp and offset tweaks. Fix moon direction not being transformed as the sun dir is. Fix colorspace issue causing some objects to render grayish instead of blackish. --- .../shaders/class1/deferred/materialF.glsl | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index c8f4d7c570..251e60c59e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -202,7 +202,8 @@ void main() #endif #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - vec3 gamma_diff = linear_to_srgb(diffcol.rgb); + vec3 gamma_diff = diffcol.rgb; + diffcol.rgb = srgb_to_linear(diffcol.rgb); #endif #if HAS_SPECULAR_MAP @@ -280,20 +281,17 @@ void main() final_da = min(final_da, 1.0f); final_da = pow(final_da, display_gamma); - col.rgb = (col * 0.5) + amblit; + col.rgb = amblit; float ambient = min(abs(final_da), 1.0); ambient *= 0.5; ambient *= ambient; ambient = (1.0-ambient); - col.rgb *= ambient; - - col.rgb = col.rgb + (final_da * sunlit); - + col.rgb *= min(ambient, max(shadow,0.3)); + col.rgb += (final_da * sunlit); col.rgb *= gamma_diff.rgb; - float glare = 0.0; if (spec.a > 0.0) // specular reflection @@ -315,6 +313,7 @@ void main() col += spec_contrib; } +vec3 post_spec = col.rgb; col = mix(col.rgb, diffcol.rgb, diffuse.a); @@ -337,6 +336,8 @@ void main() col = atmosFragLighting(col, additive, atten); col = scaleSoftClipFrag(col); +vec3 post_atmo= col.rgb; + vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0,0,0); @@ -353,18 +354,24 @@ void main() col.rgb += light.rgb; +vec3 post_lighting = col.rgb; + glare = min(glare, 1.0); float al = max(diffcol.a,glare)*vertex_color.a; //convert to gamma space for display on screen col.rgb = linear_to_srgb(col.rgb); +vec3 post_srgb = col.rgb; + #ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(col.rgb, al)); col.rgb = temp.rgb; al = temp.a; #endif +//col.rgb = post_lighting; + frag_color.rgb = col.rgb; frag_color.a = al; -- cgit v1.2.3 From bc86ad9523460ae883ea840d7b11c9de542a14aa Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 22 Feb 2019 17:03:11 -0800 Subject: SL-5186 Add ambiance handling to the light loop in the forward incarnation of materialF and tweak alphaF to match lighing of material alpha-blend objects and non-ALM rendering. --- .../shaders/class1/deferred/materialF.glsl | 37 +++++++++++----------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 251e60c59e..6dcfaddd44 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -32,6 +32,7 @@ uniform float emissive_brightness; uniform float display_gamma; +uniform int sun_up_factor; #ifdef WATER_FOG vec4 applyWaterFogView(vec3 pos, vec4 color); @@ -77,10 +78,10 @@ uniform vec2 screen_res; uniform vec4 light_position[8]; uniform vec3 light_direction[8]; -uniform vec3 light_attenuation[8]; +uniform vec4 light_attenuation[8]; uniform vec3 light_diffuse[8]; -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) +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) { //get light vector vec3 lv = lp.xyz-v; @@ -114,6 +115,12 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe col = light_col*lit*diffuse; + float amb_da = (da*da*0.5 + 0.25) * ambiance; + amb_da *= dist_atten; + amb_da = min(amb_da, 1.0f - lit); + + col.rgb += amb_da * light_col * diffuse; + if (spec.a > 0.0) { //vec3 ref = dot(pos+lv, norm); @@ -203,7 +210,6 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) vec3 gamma_diff = diffcol.rgb; - diffcol.rgb = srgb_to_linear(diffcol.rgb); #endif #if HAS_SPECULAR_MAP @@ -271,15 +277,14 @@ void main() vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - float sun_da = dot(norm.xyz, sun_dir.xyz); - float moon_da = dot(norm.xyz, moon_dir.xyz); + vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + float da = dot(norm.xyz, light_dir.xyz); - float final_da = max(sun_da,moon_da); + float final_da = da; final_da = min(final_da, shadow); //final_da = max(final_da, diffuse.a); final_da = max(final_da, 0.0f); final_da = min(final_da, 1.0f); - final_da = pow(final_da, display_gamma); col.rgb = amblit; @@ -289,8 +294,9 @@ void main() ambient = (1.0-ambient); col.rgb *= min(ambient, max(shadow,0.3)); + col.rgb += (final_da * sunlit); - col.rgb *= gamma_diff.rgb; + col.rgb *= diffuse.rgb; float glare = 0.0; @@ -315,7 +321,7 @@ void main() vec3 post_spec = col.rgb; - col = mix(col.rgb, diffcol.rgb, diffuse.a); + col = mix(col.rgb, diffuse.rgb, diffuse.a); if (envIntensity > 0.0) { @@ -333,8 +339,8 @@ vec3 post_spec = col.rgb; glare += cur_glare; } - col = atmosFragLighting(col, additive, atten); - col = scaleSoftClipFrag(col); + //col = atmosFragLighting(col, additive, atten); + //col = scaleSoftClipFrag(col); vec3 post_atmo= col.rgb; @@ -342,7 +348,7 @@ vec3 post_atmo= col.rgb; 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, glare); + #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, glare, light_attenuation[i].w); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -359,19 +365,12 @@ vec3 post_lighting = col.rgb; glare = min(glare, 1.0); float al = max(diffcol.a,glare)*vertex_color.a; - //convert to gamma space for display on screen - col.rgb = linear_to_srgb(col.rgb); - -vec3 post_srgb = col.rgb; - #ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(col.rgb, al)); col.rgb = temp.rgb; al = temp.a; #endif -//col.rgb = post_lighting; - frag_color.rgb = col.rgb; frag_color.a = al; -- cgit v1.2.3 From f9896dc100ccd6dd2d92610cb4f71f61284f76a6 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 26 Feb 2019 10:09:32 -0800 Subject: SL-5186, SL-10612 Fix lighting and gamma correction differences between deferred and forward rendering including materials objects. Verify 10612 and 10500 remain fixed. Make sure all necessary deferred shaders get the atmospheric uniform updates for doing frag-based atmospherics. --- .../shaders/class1/deferred/materialF.glsl | 59 ++++++++++++---------- 1 file changed, 32 insertions(+), 27 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 6dcfaddd44..586926dc01 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -81,7 +81,7 @@ uniform vec3 light_direction[8]; uniform vec4 light_attenuation[8]; uniform vec3 light_diffuse[8]; -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) +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, float shadow) { //get light vector vec3 lv = lp.xyz-v; @@ -102,21 +102,24 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe float dist = d/la; float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); dist_atten *= dist_atten; - dist_atten *= 2.0; - + // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); da *= spot*spot; // GL_SPOT_EXPONENT=2 //angular attenuation - da *= max(dot(n, lv), 0.0); + da = dot(n, lv); + da *= clamp(da, 0.0, 1.0); + da *= pow(da, 1.0 / 1.3); - float lit = max(da * dist_atten, 0.0); + float lit = max(min(da,shadow) * dist_atten, 0.0); col = light_col*lit*diffuse; - float amb_da = (da*da*0.5 + 0.25) * ambiance; + float amb_da = ambiance; amb_da *= dist_atten; + amb_da += (da*0.5) * ambiance; + amb_da += (da*da*0.5 + 0.25) * ambiance; amb_da = min(amb_da, 1.0f - lit); col.rgb += amb_da * light_col * diffuse; @@ -144,7 +147,6 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe cur_glare = max(cur_glare, speccol.b); glare = max(glare, speccol.r); glare += max(cur_glare, 0.0); - //col += spec.rgb; } } } @@ -263,41 +265,42 @@ void main() spec = final_specular; vec4 diffuse = final_color; + + diffuse.rgb = srgb_to_linear(diffuse.rgb); + float envIntensity = final_normal.z; vec3 col = vec3(0.0f,0.0f,0.0f); float bloom = 0.0; - vec3 sunlit; - vec3 amblit; - vec3 additive; - vec3 atten; + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); - + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - float da = dot(norm.xyz, light_dir.xyz); - float final_da = da; - final_da = min(final_da, shadow); - //final_da = max(final_da, diffuse.a); - final_da = max(final_da, 0.0f); - final_da = min(final_da, 1.0f); + float da = dot(norm.xyz, light_dir.xyz); + da = clamp(da, 0.0, 1.0); + da = pow(da, 1.0 / 1.3); col.rgb = amblit; - float ambient = min(abs(final_da), 1.0); + float ambient = abs(da); ambient *= 0.5; ambient *= ambient; - ambient = (1.0-ambient); - - col.rgb *= min(ambient, max(shadow,0.3)); + ambient = 1.0 - ambient * smoothstep(0.0, 0.3, shadow); - col.rgb += (final_da * sunlit); + vec3 sun_contrib = min(da, shadow) * sunlit; + + col.rgb *= ambient; + col.rgb += sun_contrib; col.rgb *= diffuse.rgb; - + float glare = 0.0; if (spec.a > 0.0) // specular reflection @@ -339,8 +342,8 @@ vec3 post_spec = col.rgb; glare += cur_glare; } - //col = atmosFragLighting(col, additive, atten); - //col = scaleSoftClipFrag(col); + col = atmosFragLighting(col, additive, atten); + col = scaleSoftClipFrag(col); vec3 post_atmo= col.rgb; @@ -348,7 +351,7 @@ vec3 post_atmo= col.rgb; 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, glare, light_attenuation[i].w); + #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, glare, light_attenuation[i].w, shadow); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -371,6 +374,8 @@ vec3 post_lighting = col.rgb; al = temp.a; #endif + col.rgb = linear_to_srgb(col.rgb); + frag_color.rgb = col.rgb; frag_color.a = al; -- cgit v1.2.3 From 6f820163ce3a42eb90edba6f3907952e7d83517c Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 26 Feb 2019 14:51:02 -0800 Subject: SL-10566 part the first Tie using deferred rendering in water reflection/distortion map generation to debug var again (claw back some performance lost to doing post-deferred in water map generation). Edit softenLightF for class1/class2 to make them comparable again. --- .../app_settings/shaders/class1/deferred/materialF.glsl | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 586926dc01..a18eb7b075 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -41,7 +41,14 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); +#if defined(VERT_ATMOSPHERICS) +vec3 getSunlitColor(); +vec3 getAmblitColor(); +vec3 getAdditiveColor(); +vec3 getAtmosAttenuation(); +#else void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); +#endif vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cs); @@ -278,8 +285,15 @@ void main() vec3 additive; vec3 atten; +#if VERT_ATMOSPHERICS + sunlit = getSunlitColor(); + amblit = getAmblitColor(); + additive = getAdditiveColor(); + atten = getAtmosAttenuation(); +#else calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); - +#endif + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; -- cgit v1.2.3 From 2b9943d6f2a02423f555d46e8100a68483f26244 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 26 Feb 2019 15:07:33 -0800 Subject: Fix up ifdefs to make OSX shader compiler happy. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index a18eb7b075..e2ebd928ef 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -285,7 +285,7 @@ void main() vec3 additive; vec3 atten; -#if VERT_ATMOSPHERICS +#if defined(VERT_ATMOSPHERICS) sunlit = getSunlitColor(); amblit = getAmblitColor(); additive = getAdditiveColor(); -- cgit v1.2.3 From 4c3050a3953153aa8753fc10706ad2ef464f3e3d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Sun, 3 Mar 2019 10:42:19 -0800 Subject: SL-10664, SL-10666 Fix up culling issues from perf work and fix Depth of Field rendering to get depth values properly. Baseline for performance work. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index e2ebd928ef..4db2b9ae54 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -119,7 +119,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe da *= clamp(da, 0.0, 1.0); da *= pow(da, 1.0 / 1.3); - float lit = max(min(da,shadow) * dist_atten, 0.0); + float lit = max(da * dist_atten, 0.0); col = light_col*lit*diffuse; -- cgit v1.2.3 From 423fa1ac297e39c9395f45490278b8751188b6db Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 7 Mar 2019 10:56:26 -0800 Subject: SL-10618, SL-10698 Fix reflection/distortion map culling planes again. Fix broken handling of shadow disables in ALM forward shaders. --- .../shaders/class1/deferred/materialF.glsl | 34 +++++++++------------- 1 file changed, 13 insertions(+), 21 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 4db2b9ae54..dd691fb36b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -41,14 +41,7 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); -#if defined(VERT_ATMOSPHERICS) -vec3 getSunlitColor(); -vec3 getAmblitColor(); -vec3 getAdditiveColor(); -vec3 getAtmosAttenuation(); -#else void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); -#endif vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cs); @@ -61,7 +54,9 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif +#ifdef HAS_SUN_SHADOW float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); +#endif uniform samplerCube environmentMap; uniform sampler2D lightFunc; @@ -172,11 +167,11 @@ out vec4 frag_data[3]; uniform sampler2D diffuseMap; -#if HAS_NORMAL_MAP +#ifdef HAS_NORMAL_MAP uniform sampler2D bumpMap; #endif -#if HAS_SPECULAR_MAP +#ifdef HAS_SPECULAR_MAP uniform sampler2D specularMap; VARYING vec2 vary_texcoord2; @@ -189,7 +184,7 @@ uniform vec4 specular_color; // specular color RGB and specular exponent (gloss uniform float minimum_alpha; #endif -#if HAS_NORMAL_MAP +#ifdef HAS_NORMAL_MAP VARYING vec3 vary_mat0; VARYING vec3 vary_mat1; VARYING vec3 vary_mat2; @@ -221,14 +216,14 @@ void main() vec3 gamma_diff = diffcol.rgb; #endif -#if HAS_SPECULAR_MAP +#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 -#if HAS_NORMAL_MAP +#ifdef HAS_NORMAL_MAP vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); norm.xyz = norm.xyz * 2 - 1; @@ -255,7 +250,7 @@ void main() #endif vec4 final_specular = spec; -#if HAS_SPECULAR_MAP +#ifdef HAS_SPECULAR_MAP vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, 0.0); final_specular.a = specular_color.a * norm.a; #else @@ -268,8 +263,12 @@ void main() //forward rendering, output just lit RGBA vec3 pos = vary_position; - float shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen); + float shadow = 1.0f; +#ifdef HAS_SUN_SHADOW + shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen); +#endif + spec = final_specular; vec4 diffuse = final_color; @@ -285,14 +284,7 @@ void main() vec3 additive; vec3 atten; -#if defined(VERT_ATMOSPHERICS) - sunlit = getSunlitColor(); - amblit = getAmblitColor(); - additive = getAdditiveColor(); - atten = getAtmosAttenuation(); -#else calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); -#endif vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); -- cgit v1.2.3 From 53f3755a4629206754a5695de233d88062a54d3d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 7 Mar 2019 15:09:34 -0800 Subject: Fix tabs. --- .../newview/app_settings/shaders/class1/deferred/materialF.glsl | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index dd691fb36b..5f4f1677d7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -301,7 +301,8 @@ void main() ambient *= ambient; ambient = 1.0 - ambient * smoothstep(0.0, 0.3, shadow); - vec3 sun_contrib = min(da, shadow) * sunlit; + float final_da = min(da, shadow); + vec3 sun_contrib = final_da * sunlit; col.rgb *= ambient; col.rgb += sun_contrib; @@ -314,7 +315,7 @@ void main() // the old infinite-sky shiny reflection // - float sa = dot(refnormpersp, sun_dir.xyz); + float sa = dot(refnormpersp, light_dir.xyz); vec3 dumbshiny = sunlit*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); @@ -351,8 +352,6 @@ vec3 post_spec = col.rgb; col = atmosFragLighting(col, additive, atten); col = scaleSoftClipFrag(col); -vec3 post_atmo= col.rgb; - vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0,0,0); @@ -369,8 +368,6 @@ vec3 post_atmo= col.rgb; col.rgb += light.rgb; -vec3 post_lighting = col.rgb; - glare = min(glare, 1.0); float al = max(diffcol.a,glare)*vertex_color.a; -- cgit v1.2.3 From c10754ea6d47f88f3499f86543a7d6c7d439fda6 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 13 Mar 2019 13:56:04 -0700 Subject: SL-10741 Remove shadow influence on ambient term causing inverted lighting in extreme setups. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 5f4f1677d7..76c1fc7cf4 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -294,16 +294,15 @@ void main() da = clamp(da, 0.0, 1.0); da = pow(da, 1.0 / 1.3); - col.rgb = amblit; - float ambient = abs(da); ambient *= 0.5; ambient *= ambient; - ambient = 1.0 - ambient * smoothstep(0.0, 0.3, shadow); + ambient = 1.0 - ambient; float final_da = min(da, shadow); vec3 sun_contrib = final_da * sunlit; + col.rgb = amblit; col.rgb *= ambient; col.rgb += sun_contrib; col.rgb *= diffuse.rgb; -- cgit v1.2.3 From a10ec81e82d79bd79d5b058fda1b370073bfb480 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 15 Mar 2019 08:13:04 -0700 Subject: SL-10743, SL-10744 Don't step on SUNLIGHT_COLOR uniform w/ syncLightState competing set. Put drawpool alpha render loop lighting setup changes as they were (this will give back some performance and possibly require reopening 10566). --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 1 - 1 file changed, 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 76c1fc7cf4..ae2dd24b19 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -112,7 +112,6 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe //angular attenuation da = dot(n, lv); da *= clamp(da, 0.0, 1.0); - da *= pow(da, 1.0 / 1.3); float lit = max(da * dist_atten, 0.0); -- cgit v1.2.3 From d99e2e119f08370b2003bad23617b7fdd435d19e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 25 Mar 2019 14:52:23 -0700 Subject: Add clamp to keep speccolor non-negative. Make spot shadowing more consistent. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index ae2dd24b19..9112b6afd3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -135,13 +135,14 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe float sa = nh; float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - float gtdenom = 2 * nh; + float gtdenom = abs(2 * nh); float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - if (nh > 0.0) + if (gtdenom > 0.0) { float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); vec3 speccol = lit*scol*light_col.rgb*spec.rgb; + speccol = max(speccol, vec3(0)); col += speccol; float cur_glare = max(speccol.r, speccol.g); -- cgit v1.2.3 From fb7c887a5e09024731038eef0a57e5f1e8e08b2e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 26 Mar 2019 10:28:25 -0700 Subject: More consistent lighting across ALM/non-ALM/deferred/forward rendering. --- .../shaders/class1/deferred/materialF.glsl | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 9112b6afd3..c43b5b22bf 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -104,23 +104,28 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe float dist = d/la; float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); dist_atten *= dist_atten; - + dist_atten *= 2.0f; + // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); da *= spot*spot; // GL_SPOT_EXPONENT=2 //angular attenuation da = dot(n, lv); + //da = min(da, shadow); da *= clamp(da, 0.0, 1.0); - + float lit = max(da * dist_atten, 0.0); + // shadowmap is wrong for alpha-blended objs + // since we created shadowmaps for 2 but render N + //col = light_col*lit*diffuse*shadow; col = light_col*lit*diffuse; - + float amb_da = ambiance; + amb_da += (da*0.5) * (1.0 - shadow) * ambiance; + amb_da += (da*da*0.5 + 0.5) * (1.0 - shadow) * ambiance; amb_da *= dist_atten; - amb_da += (da*0.5) * ambiance; - amb_da += (da*da*0.5 + 0.25) * ambiance; amb_da = min(amb_da, 1.0f - lit); col.rgb += amb_da * light_col * diffuse; @@ -135,10 +140,10 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe float sa = nh; float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - float gtdenom = abs(2 * nh); + float gtdenom = 2 * nh; float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - if (gtdenom > 0.0) + if (nh > 0.0) { float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); vec3 speccol = lit*scol*light_col.rgb*spec.rgb; -- cgit v1.2.3 From c699ee9a7f102aa541dcc102e8fa1de2d6c55bde Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 4 Apr 2019 17:19:59 -0700 Subject: SL-10854 Clamp ambient contrib to get darker shadows. New PCF sampling func. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index c43b5b22bf..d389d975fa 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -302,7 +302,7 @@ void main() float ambient = abs(da); ambient *= 0.5; ambient *= ambient; - ambient = 1.0 - ambient; + ambient = 1.0 - max(0.9, ambient); float final_da = min(da, shadow); vec3 sun_contrib = final_da * sunlit; -- cgit v1.2.3 From 09bb0336f15027e907fbd28130b4ffda28a830cd Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 5 Apr 2019 09:19:46 -0700 Subject: SL-10854 part 2 Clamp ambient to keep shadows dark. Apply min with shadow value after we've pow'd by light gamma consistently between forward and deferred. --- .../app_settings/shaders/class1/deferred/materialF.glsl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index d389d975fa..4e24e61018 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -296,16 +296,18 @@ void main() vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; float da = dot(norm.xyz, light_dir.xyz); - da = clamp(da, 0.0, 1.0); - da = pow(da, 1.0 / 1.3); + + float final_da = da; + final_da = clamp(final_da, 0.0, 1.0); + final_da = pow(final_da, 1.0 / 1.3); float ambient = abs(da); ambient *= 0.5; ambient *= ambient; - ambient = 1.0 - max(0.9, ambient); + ambient = max(0.9, ambient); + ambient = 1.0 - ambient; - float final_da = min(da, shadow); - vec3 sun_contrib = final_da * sunlit; + vec3 sun_contrib = min(final_da, shadow) * sunlit; col.rgb = amblit; col.rgb *= ambient; -- cgit v1.2.3 From fff2aecf7f96de9e53620887210487a48dd45580 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 5 Apr 2019 14:35:55 -0700 Subject: SL-10821 Fix directionality of da and preserve bumps on completely shadowed areas. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 4e24e61018..8691e729ee 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -296,18 +296,19 @@ void main() vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; float da = dot(norm.xyz, light_dir.xyz); + da = clamp(da, -1.0, 1.0); float final_da = da; final_da = clamp(final_da, 0.0, 1.0); final_da = pow(final_da, 1.0 / 1.3); - float ambient = abs(da); + float ambient = da; ambient *= 0.5; ambient *= ambient; ambient = max(0.9, ambient); ambient = 1.0 - ambient; - vec3 sun_contrib = min(final_da, shadow) * sunlit; + vec3 sun_contrib = mix(final_da, min(final_da, shadow), 0.1) * sunlit; col.rgb = amblit; col.rgb *= ambient; -- cgit v1.2.3 From fe589170d3faa5ca681baca7b9a664e2d851cd6e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 5 Apr 2019 15:54:21 -0700 Subject: SL-10896 Fix deferred water soften prog lightnorm getting stomped with rotated lightnorm, because it's a water shader and needs water atmo uniform values, but it's a deferred lighting shader that needs not-so-rotated lightnorms. Make sunlight_color not get auto-updated so we can get the correct value from mSunDiffuse. Remove mix to preserve bumps as it was washing out shadows. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 8691e729ee..4a47311eb7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -308,7 +308,7 @@ void main() ambient = max(0.9, ambient); ambient = 1.0 - ambient; - vec3 sun_contrib = mix(final_da, min(final_da, shadow), 0.1) * sunlit; + vec3 sun_contrib = min(final_da, shadow) * sunlit; col.rgb = amblit; col.rgb *= ambient; -- cgit v1.2.3 From 282f91aaf38cd108ee96475e351623ae203c57a6 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 8 Apr 2019 10:34:59 -0700 Subject: Make ambient clamping consistent between class1/2 deferred lighting and forward rendering. Add decls for intermediate lighting values for debug. --- .../app_settings/shaders/class1/deferred/materialF.glsl | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 4a47311eb7..4bb01824bf 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -305,16 +305,24 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - ambient = max(0.9, ambient); + ambient = max(0.66, ambient); ambient = 1.0 - ambient; vec3 sun_contrib = min(final_da, shadow) * sunlit; col.rgb = amblit; col.rgb *= ambient; + +vec3 post_ambient = col.rgb; + col.rgb += sun_contrib; + +vec3 post_sunlight = col.rgb; + col.rgb *= diffuse.rgb; +vec3 post_diffuse = col.rgb; + float glare = 0.0; if (spec.a > 0.0) // specular reflection @@ -363,6 +371,8 @@ vec3 post_spec = col.rgb; vec3 light = vec3(0,0,0); + vec3 prelight_linearish_maybe = col.rgb; + #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, glare, light_attenuation[i].w, shadow); LIGHT_LOOP(1) @@ -375,6 +385,8 @@ vec3 post_spec = col.rgb; col.rgb += light.rgb; +vec3 postlight_linear = col.rgb; + glare = min(glare, 1.0); float al = max(diffcol.a,glare)*vertex_color.a; @@ -384,6 +396,8 @@ vec3 post_spec = col.rgb; al = temp.a; #endif +//col.rgb = prelight_linearish_maybe; + col.rgb = linear_to_srgb(col.rgb); frag_color.rgb = col.rgb; -- cgit v1.2.3 From 996d441ddc64996711b5a4eb3135607686992b86 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 8 Apr 2019 16:53:57 -0700 Subject: SL-5186 Make projector ambiance unshadowed in both forward and deferred for consistency. --- .../app_settings/shaders/class1/deferred/materialF.glsl | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 4bb01824bf..8c5a0ef297 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -112,23 +112,20 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe //angular attenuation da = dot(n, lv); - //da = min(da, shadow); - da *= clamp(da, 0.0, 1.0); + da = clamp(da, 0.0, 1.0); float lit = max(da * dist_atten, 0.0); // shadowmap is wrong for alpha-blended objs // since we created shadowmaps for 2 but render N - //col = light_col*lit*diffuse*shadow; - col = light_col*lit*diffuse; + col = light_col*lit*diffuse*shadow; float amb_da = ambiance; - amb_da += (da*0.5) * (1.0 - shadow) * ambiance; + amb_da += (da*0.5+0.5) * (1.0 - shadow) * ambiance; amb_da += (da*da*0.5 + 0.5) * (1.0 - shadow) * ambiance; - amb_da *= dist_atten; amb_da = min(amb_da, 1.0f - lit); - col.rgb += amb_da * light_col * diffuse; + col.rgb += amb_da * 0.5 * light_col * diffuse; if (spec.a > 0.0) { @@ -373,7 +370,7 @@ vec3 post_spec = col.rgb; vec3 prelight_linearish_maybe = col.rgb; - #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, glare, light_attenuation[i].w, shadow); + #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, glare, light_attenuation[i].w, 1.0); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -383,6 +380,8 @@ vec3 post_spec = col.rgb; LIGHT_LOOP(6) LIGHT_LOOP(7) +vec3 light_linear = light.rgb; + col.rgb += light.rgb; vec3 postlight_linear = col.rgb; @@ -396,7 +395,7 @@ vec3 postlight_linear = col.rgb; al = temp.a; #endif -//col.rgb = prelight_linearish_maybe; +//col.rgb = light_linear; col.rgb = linear_to_srgb(col.rgb); -- cgit v1.2.3 From f9c0b021ea1a695c0d5d4042981045fe265e7918 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 9 Apr 2019 13:02:58 -0700 Subject: SL-5186 Fix falloff on projectors in forward rendering (different falloff calcs than deferred). --- .../app_settings/shaders/class1/deferred/materialF.glsl | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 8c5a0ef297..6d7162b5a2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -95,14 +95,15 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe vec3 col = vec3(0,0,0); - if (d > 0.0 && la > 0.0 && fa > 0.0) + if (d > 0.0) { //normalize light vector lv = normalize(lv); //distance attenuation - float dist = d/la; - float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); + float dist = (la > 0) ? d/la : 1.0f; + fa += 1.0f; + float dist_atten = ( fa > 0) ? clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0) : 1.0f; dist_atten *= dist_atten; dist_atten *= 2.0f; @@ -121,8 +122,11 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe col = light_col*lit*diffuse*shadow; float amb_da = ambiance; - amb_da += (da*0.5+0.5) * (1.0 - shadow) * ambiance; - amb_da += (da*da*0.5 + 0.5) * (1.0 - shadow) * ambiance; + if (da > 0) + { + amb_da += (da*0.5 + 0.5) * ambiance; + } + amb_da += (da*da*0.5+0.5) * ambiance; amb_da = min(amb_da, 1.0f - lit); col.rgb += amb_da * 0.5 * light_col * diffuse; @@ -370,7 +374,7 @@ vec3 post_spec = col.rgb; vec3 prelight_linearish_maybe = col.rgb; - #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, glare, light_attenuation[i].w, 1.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, glare, light_attenuation[i].w * 0.5, 1.0); LIGHT_LOOP(1) LIGHT_LOOP(2) -- cgit v1.2.3 From d7d8a15092c91f6fa55547515b243b61a78868ff Mon Sep 17 00:00:00 2001 From: Geenz Date: Wed, 10 Apr 2019 02:49:25 -0700 Subject: Fullbright + elimination of all references to calcFragAtmospherics. --HG-- branch : OPEN-340 --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 6d7162b5a2..9b07c11361 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -41,7 +41,7 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); -void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); +void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cs); @@ -290,7 +290,7 @@ void main() vec3 additive; vec3 atten; - calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); + calcAtmosphericVars(pos.xyz, 1.0, sunlit, amblit, additive, atten); vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); -- cgit v1.2.3 From 27184c74b4b8085e362c6e21d5d1071889476fe9 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 10 Apr 2019 13:43:58 -0700 Subject: SL-10901 Fix up shadow sampling and tweak shadow biasing. Clean up shader decls of unused funcs. Clean up whitespace diffs from release. --- .../app_settings/shaders/class1/deferred/materialF.glsl | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 9b07c11361..d14e67fc73 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -83,7 +83,7 @@ uniform vec3 light_direction[8]; uniform vec4 light_attenuation[8]; uniform vec3 light_diffuse[8]; -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, float shadow) +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) { //get light vector vec3 lv = lp.xyz-v; @@ -109,17 +109,16 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); - da *= spot*spot; // GL_SPOT_EXPONENT=2 //angular attenuation da = dot(n, lv); da = clamp(da, 0.0, 1.0); + da *= spot*spot; // GL_SPOT_EXPONENT=2 + float lit = max(da * dist_atten, 0.0); - // shadowmap is wrong for alpha-blended objs - // since we created shadowmaps for 2 but render N - col = light_col*lit*diffuse*shadow; + col = light_col*lit*diffuse; float amb_da = ambiance; if (da > 0) @@ -148,7 +147,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe { float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); vec3 speccol = lit*scol*light_col.rgb*spec.rgb; - speccol = max(speccol, vec3(0)); + speccol = clamp(speccol, vec3(0), vec3(1)); col += speccol; float cur_glare = max(speccol.r, speccol.g); @@ -372,9 +371,9 @@ vec3 post_spec = col.rgb; vec3 light = vec3(0,0,0); - vec3 prelight_linearish_maybe = col.rgb; + vec3 prelight_linearish_maybe = srgb_to_linear(col.rgb); - #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, glare, light_attenuation[i].w * 0.5, 1.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, glare, light_attenuation[i].w * 0.5); LIGHT_LOOP(1) LIGHT_LOOP(2) -- cgit v1.2.3 From a7e7d4a8185cd63c2f6f87fea992667912999426 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 16 Apr 2019 08:41:12 -0700 Subject: Make blended material objects use the same BRDF for spec as everything else. --- .../shaders/class1/deferred/materialF.glsl | 36 +++++++++++++--------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index d14e67fc73..0819f1b292 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -327,21 +327,27 @@ vec3 post_diffuse = col.rgb; if (spec.a > 0.0) // specular reflection { - // the old infinite-sky shiny reflection - // - - float sa = dot(refnormpersp, light_dir.xyz); - - vec3 dumbshiny = sunlit*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); - - // add the two types of shiny together - vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 6; - - glare = max(spec_contrib.r, spec_contrib.g); - glare = max(glare, spec_contrib.b); - - col += spec_contrib; + 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 speccol = sun_contrib*scol*spec.rgb; + speccol = clamp(speccol, vec3(0), vec3(1)); + bloom = dot(speccol, speccol) / 6; + col += speccol; + } } vec3 post_spec = col.rgb; -- cgit v1.2.3 From a685e024a62751289ccfa41c962b039d1de748bd Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 23 Apr 2019 13:12:16 -0700 Subject: SL-10901 Bias shadow sampling and allow control of how dark shadows are (clamped ambient). --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 0819f1b292..f1dbf4af46 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -83,6 +83,8 @@ uniform vec3 light_direction[8]; uniform vec4 light_attenuation[8]; uniform vec3 light_diffuse[8]; +float getAmbientClamp(); + 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) { //get light vector @@ -305,7 +307,7 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - ambient = max(0.66, ambient); + ambient = max(getAmbientClamp(), ambient); ambient = 1.0 - ambient; vec3 sun_contrib = min(final_da, shadow) * sunlit; -- cgit v1.2.3 From 4ed05fc84fce0fbee76c583e91feed5aff2dbbfc Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 25 Apr 2019 10:59:00 -0700 Subject: Fix dark ALM and strangeness at Mid lighting (class 3 but with a darkness about it). Make a distinct class3/lighting/lightV which boosts to WL levels (* 2.0) and make lighting without WL atmo enabled use class 2 or below. Make forward shaders (alpha and materialF with alpha-blend mode on) more consistent with deferred lighting. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index f1dbf4af46..5926236fd7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -302,7 +302,6 @@ void main() float final_da = da; final_da = clamp(final_da, 0.0, 1.0); - final_da = pow(final_da, 1.0 / 1.3); float ambient = da; ambient *= 0.5; @@ -372,6 +371,8 @@ vec3 post_spec = col.rgb; glare += cur_glare; } +vec3 post_env = col.rgb; + col = atmosFragLighting(col, additive, atten); col = scaleSoftClipFrag(col); @@ -379,7 +380,7 @@ vec3 post_spec = col.rgb; vec3 light = vec3(0,0,0); - vec3 prelight_linearish_maybe = srgb_to_linear(col.rgb); +vec3 post_atmo = col.rgb; #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, glare, light_attenuation[i].w * 0.5); @@ -393,7 +394,7 @@ vec3 post_spec = col.rgb; vec3 light_linear = light.rgb; - col.rgb += light.rgb; + col.rgb += light_linear; vec3 postlight_linear = col.rgb; -- cgit v1.2.3 From 948deb56d9aa11d61bba76a1e79040e8db0baf49 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 26 Apr 2019 07:59:20 -0700 Subject: Add projector light within da gtz test. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 5926236fd7..b3d9b1e9c5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -120,11 +120,10 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe float lit = max(da * dist_atten, 0.0); - col = light_col*lit*diffuse; - float amb_da = ambiance; if (da > 0) { + col = light_col*lit*diffuse; amb_da += (da*0.5 + 0.5) * ambiance; } amb_da += (da*da*0.5+0.5) * ambiance; -- cgit v1.2.3 From f133be068a4aa23c02c47348f5c7d4a28e1d5c37 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 26 Apr 2019 16:02:21 -0700 Subject: Lighting WIP Consistency across class2/3/ALM lighting. --- .../shaders/class1/deferred/materialF.glsl | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index b3d9b1e9c5..f21b7644bb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -75,6 +75,7 @@ VARYING vec2 vary_fragcoord; VARYING vec3 vary_position; +uniform mat4 proj_mat; uniform mat4 inv_proj; uniform vec2 screen_res; @@ -97,6 +98,17 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe vec3 col = vec3(0,0,0); + vec4 proj_tc = proj_mat * lp; + + if (proj_tc.z < 0 + || proj_tc.x < 0 + || proj_tc.z > 1 + || proj_tc.y < 0 + || proj_tc.y > 1) + { + return col; + } + if (d > 0.0) { //normalize light vector @@ -381,6 +393,8 @@ vec3 post_env = col.rgb; vec3 post_atmo = col.rgb; + //col.rgb = srgb_to_linear(col.rgb); + #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, glare, light_attenuation[i].w * 0.5); LIGHT_LOOP(1) @@ -393,7 +407,7 @@ vec3 post_atmo = col.rgb; vec3 light_linear = light.rgb; - col.rgb += light_linear; + col.rgb += light_linear; vec3 postlight_linear = col.rgb; @@ -406,7 +420,7 @@ vec3 postlight_linear = col.rgb; al = temp.a; #endif -//col.rgb = light_linear; +//col.rgb = post_atmo; col.rgb = linear_to_srgb(col.rgb); -- cgit v1.2.3 From 0f83696585b8810c24d535432716215caf0c21e9 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 29 Apr 2019 11:11:05 -0700 Subject: SL-10956, SL-10969 Don't ignore far z in culling. Fix Mid lighting being very dark. Partial fix for broken projectors with forward rendering. --- .../shaders/class1/deferred/materialF.glsl | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index f21b7644bb..cbb7a04631 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -101,8 +101,9 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe vec4 proj_tc = proj_mat * lp; if (proj_tc.z < 0 - || proj_tc.x < 0 || proj_tc.z > 1 + || proj_tc.x < 0 + || proj_tc.x > 1 || proj_tc.y < 0 || proj_tc.y > 1) { @@ -119,7 +120,11 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe fa += 1.0f; float dist_atten = ( fa > 0) ? clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0) : 1.0f; dist_atten *= dist_atten; - dist_atten *= 2.0f; + + if (dist_atten <= 0) + { + return col; + } // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); @@ -141,7 +146,9 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe amb_da += (da*da*0.5+0.5) * ambiance; amb_da = min(amb_da, 1.0f - lit); +#ifndef NO_AMBIANCE col.rgb += amb_da * 0.5 * light_col * diffuse; +#endif if (spec.a > 0.0) { @@ -172,7 +179,6 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe } return max(col, vec3(0.0,0.0,0.0)); - } #else @@ -405,10 +411,6 @@ vec3 post_atmo = col.rgb; LIGHT_LOOP(6) LIGHT_LOOP(7) -vec3 light_linear = light.rgb; - - col.rgb += light_linear; - vec3 postlight_linear = col.rgb; glare = min(glare, 1.0); @@ -424,6 +426,8 @@ vec3 postlight_linear = col.rgb; col.rgb = linear_to_srgb(col.rgb); + col.rgb += light.rgb; + frag_color.rgb = col.rgb; frag_color.a = al; -- cgit v1.2.3 From bfce96d684d5d056061ce16a36daba9a2bd0aa9d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 30 Apr 2019 10:04:20 -0700 Subject: SL-10856 Remove ambient clamp to keep shadows dark. Partial fix for class 3 ambient term being wrong. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 1 - 1 file changed, 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index cbb7a04631..f7af3647a1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -323,7 +323,6 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - ambient = max(getAmbientClamp(), ambient); ambient = 1.0 - ambient; vec3 sun_contrib = min(final_da, shadow) * sunlit; -- cgit v1.2.3 From c4032528aff8ef1938e897ec583bbf25a3e713e1 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 2 May 2019 13:49:35 -0700 Subject: Roll back sRGB decode changes from contrib for now. Fix direct light matching across alpha/blended-material/deferred. Get diffuse lighting to match from Low to Ultra. --- .../shaders/class1/deferred/materialF.glsl | 128 +++++++++++---------- 1 file changed, 70 insertions(+), 58 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index f7af3647a1..f640dba59b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -120,6 +120,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe fa += 1.0f; float dist_atten = ( fa > 0) ? clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0) : 1.0f; dist_atten *= dist_atten; + dist_atten *= 2.0; if (dist_atten <= 0) { @@ -226,19 +227,17 @@ void main() { vec2 pos_screen = vary_texcoord0.xy; - vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); - diffcol.rgb *= vertex_color.rgb; + vec4 diffuse_linear = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_linear.a); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) - if (diffcol.a < minimum_alpha) + if (diffuse_linear.a < minimum_alpha) { discard; } #endif -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - vec3 gamma_diff = diffcol.rgb; -#endif + diffuse_linear.rgb *= vertex_color.rgb; #ifdef HAS_SPECULAR_MAP vec4 spec = texture2D(specularMap, vary_texcoord2.xy); @@ -247,17 +246,19 @@ void main() vec4 spec = vec4(specular_color.rgb, 1.0); #endif -#ifdef HAS_NORMAL_MAP - vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); + vec4 norm = vec4(0,0,0,1.0); + vec3 tnorm; +#ifdef HAS_NORMAL_MAP + norm = texture2D(bumpMap, vary_texcoord1.xy); norm.xyz = norm.xyz * 2 - 1; - vec3 tnorm = vec3(dot(norm.xyz,vary_mat0), - dot(norm.xyz,vary_mat1), - dot(norm.xyz,vary_mat2)); + // tangent space norm + tnorm = vec3(dot(norm.xyz,vary_mat0), + dot(norm.xyz,vary_mat1), + dot(norm.xyz,vary_mat2)); #else - vec4 norm = vec4(0,0,0,1.0); - vec3 tnorm = vary_normal; + tnorm = vary_normal; #endif norm.xyz = tnorm; @@ -265,7 +266,7 @@ void main() vec2 abnormal = encode_normal(norm.xyz); - vec4 final_color = diffcol; + vec4 final_color = diffuse_linear; #if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) final_color.a = emissive_brightness; @@ -274,14 +275,15 @@ void main() #endif vec4 final_specular = spec; + final_specular.a = specular_color.a; #ifdef HAS_SPECULAR_MAP - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, 0.0); - final_specular.a = specular_color.a * norm.a; -#else + final_specular.a *= norm.a; +#endif + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); - final_specular.a = specular_color.a; +#ifdef HAS_SPECULAR_MAP + final_normal.z *= spec.a; #endif - #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) //forward rendering, output just lit RGBA @@ -294,13 +296,10 @@ void main() #endif spec = final_specular; - vec4 diffuse = final_color; - - diffuse.rgb = srgb_to_linear(diffuse.rgb); float envIntensity = final_normal.z; - vec3 col = vec3(0.0f,0.0f,0.0f); + vec3 color = vec3(0.0); float bloom = 0.0; vec3 sunlit; @@ -314,7 +313,7 @@ void main() vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - float da = dot(norm.xyz, light_dir.xyz); + float da = dot(normalize(norm.xyz), normalize(light_dir.xyz)); da = clamp(da, -1.0, 1.0); float final_da = da; @@ -323,22 +322,23 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; + ambient = max(getAmbientClamp(), ambient); ambient = 1.0 - ambient; vec3 sun_contrib = min(final_da, shadow) * sunlit; - col.rgb = amblit; - col.rgb *= ambient; + color.rgb = amblit; + color.rgb *= ambient; -vec3 post_ambient = col.rgb; +vec3 post_ambient = color.rgb; - col.rgb += sun_contrib; + color.rgb += sun_contrib; -vec3 post_sunlight = col.rgb; +vec3 post_sunlight = color.rgb; - col.rgb *= diffuse.rgb; + color.rgb *= diffuse_linear.rgb; -vec3 post_diffuse = col.rgb; +vec3 post_diffuse = color.rgb; float glare = 0.0; @@ -363,44 +363,44 @@ vec3 post_diffuse = col.rgb; vec3 speccol = sun_contrib*scol*spec.rgb; speccol = clamp(speccol, vec3(0), vec3(1)); bloom = dot(speccol, speccol) / 6; - col += speccol; + color += speccol; } } -vec3 post_spec = col.rgb; +vec3 post_spec = color.rgb; - col = mix(col.rgb, diffuse.rgb, diffuse.a); + //color = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); if (envIntensity > 0.0) { //add environmentmap vec3 env_vec = env_mat * refnormpersp; - vec3 refcol = textureCube(environmentMap, env_vec).rgb; + vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; - col = mix(col.rgb, refcol, - envIntensity); + color = mix(color.rgb, reflected_color, envIntensity); - float cur_glare = max(refcol.r, refcol.g); - cur_glare = max(cur_glare, refcol.b); + float cur_glare = max(reflected_color.r, reflected_color.g); + cur_glare = max(cur_glare, reflected_color.b); cur_glare *= envIntensity*4.0; glare += cur_glare; } -vec3 post_env = col.rgb; +vec3 post_env = color.rgb; + + color = atmosFragLighting(color, additive, atten); + color = scaleSoftClipFrag(color); + +vec3 post_atmo = color.rgb; - col = atmosFragLighting(col, additive, atten); - col = scaleSoftClipFrag(col); + //convert to linear space before adding local lights + color = srgb_to_linear(color); vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0,0,0); -vec3 post_atmo = col.rgb; - - //col.rgb = srgb_to_linear(col.rgb); - - #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, glare, light_attenuation[i].w * 0.5); + #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.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, glare, light_attenuation[i].w * 0.5); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -410,27 +410,39 @@ vec3 post_atmo = col.rgb; LIGHT_LOOP(6) LIGHT_LOOP(7) -vec3 postlight_linear = col.rgb; glare = min(glare, 1.0); - float al = max(diffcol.a,glare)*vertex_color.a; + float al = max(diffuse_linear.a,glare)*vertex_color.a; + + color.rgb += light.rgb; + + // (only) post-deferred needs inline gamma correction + color.rgb = linear_to_srgb(color.rgb); + +//color.rgb = amblit; +//color.rgb = vec3(ambient); +//color.rgb = sunlit; +//color.rgb = post_ambient; +//color.rgb = vec3(final_da); +//color.rgb = sun_contrib; +//color.rgb = post_sunlight; +//color.rgb = diffuse_srgb.rgb; +//color.rgb = post_diffuse; +//color.rgb = post_spec; +//color.rgb = post_env; +//color.rgb = post_atmo; #ifdef WATER_FOG - vec4 temp = applyWaterFogView(pos, vec4(col.rgb, al)); - col.rgb = temp.rgb; + vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); + color.rgb = temp.rgb; al = temp.a; #endif -//col.rgb = post_atmo; - - col.rgb = linear_to_srgb(col.rgb); - - col.rgb += light.rgb; - - frag_color.rgb = col.rgb; + frag_color.rgb = color.rgb; frag_color.a = al; #else + // deferred path frag_data[0] = final_color; frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. -- cgit v1.2.3 From 906b0be675e5467665f65180924e6117700b4cbb Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 3 May 2019 08:47:13 -0700 Subject: SL-11087, SL-11086, SL-11092 Fix sun/moon glow factor bustage. Make darkness an option. Fix moon fade shader logic getting confused when sun was below horizon. --- .../app_settings/shaders/class1/deferred/materialF.glsl | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index f640dba59b..54bed38fb7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -120,7 +120,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe fa += 1.0f; float dist_atten = ( fa > 0) ? clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0) : 1.0f; dist_atten *= dist_atten; - dist_atten *= 2.0; + dist_atten *= 2.2f; if (dist_atten <= 0) { @@ -143,13 +143,10 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe { col = light_col*lit*diffuse; amb_da += (da*0.5 + 0.5) * ambiance; + amb_da += (da*da*0.5+0.5) * ambiance; + amb_da = min(amb_da, 1.0f - lit); } - amb_da += (da*da*0.5+0.5) * ambiance; - amb_da = min(amb_da, 1.0f - lit); - -#ifndef NO_AMBIANCE - col.rgb += amb_da * 0.5 * light_col * diffuse; -#endif + col.rgb += amb_da * 0.25 * light_col * diffuse; if (spec.a > 0.0) { @@ -362,7 +359,7 @@ vec3 post_diffuse = color.rgb; float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); vec3 speccol = sun_contrib*scol*spec.rgb; speccol = clamp(speccol, vec3(0), vec3(1)); - bloom = dot(speccol, speccol) / 6; + bloom = dot(speccol, speccol) / 6.0f; color += speccol; } } @@ -400,7 +397,7 @@ vec3 post_atmo = color.rgb; vec3 light = vec3(0,0,0); - #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.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, glare, light_attenuation[i].w * 0.5); + #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.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, glare, light_attenuation[i].w); LIGHT_LOOP(1) LIGHT_LOOP(2) -- cgit v1.2.3 From 8d32aade01b0b87bd626a81f68b210538e90095b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 3 May 2019 11:45:17 -0700 Subject: SL-11090 Tamp down bloom so we don't have to redo ten thousand gloss maps. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 54bed38fb7..541d6bd4fb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -357,9 +357,9 @@ vec3 post_diffuse = color.rgb; if (nh > 0.0) { float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 speccol = sun_contrib*scol*spec.rgb; + vec3 speccol = sun_contrib*scol*spec.rgb*0.25; speccol = clamp(speccol, vec3(0), vec3(1)); - bloom = dot(speccol, speccol) / 6.0f; + bloom = dot(speccol, speccol); color += speccol; } } -- cgit v1.2.3 From 89c24095c6c1b778b93a4eb7ad398627f4d5479f Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 3 May 2019 12:02:59 -0700 Subject: SL-11085 Remove ambient term clamping to get less dark shadows where we want less dark shadows in ALM. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 541d6bd4fb..64cdacd4a2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -319,7 +319,7 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - ambient = max(getAmbientClamp(), ambient); + //ambient = max(getAmbientClamp(), ambient); ambient = 1.0 - ambient; vec3 sun_contrib = min(final_da, shadow) * sunlit; -- cgit v1.2.3 From 21c1941a4f4780c0675ae338cbbc5899aa7c0613 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 6 May 2019 10:16:31 -0700 Subject: Fix missin atten and atten only applied when da > 0 in material and alpha shaders resp. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 64cdacd4a2..ba1f121bfd 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -144,8 +144,9 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe col = light_col*lit*diffuse; amb_da += (da*0.5 + 0.5) * ambiance; amb_da += (da*da*0.5+0.5) * ambiance; - amb_da = min(amb_da, 1.0f - lit); } + amb_da *= dist_atten; + amb_da = min(amb_da, 1.0f - lit); col.rgb += amb_da * 0.25 * light_col * diffuse; if (spec.a > 0.0) -- cgit v1.2.3 From c61f73321dbef9f0f5741830bfbaa8facd6ec060 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 6 May 2019 16:29:06 -0700 Subject: SL-11102, SL-11103 Fix diffuse boost in deferred lighting to match non-deferred. Make class2 soften not clamp shadow color to incoming alpha (make shadows appear on terrain underwater). --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 -- 1 file changed, 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index ba1f121bfd..7533762a96 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -367,8 +367,6 @@ vec3 post_diffuse = color.rgb; vec3 post_spec = color.rgb; - //color = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); - if (envIntensity > 0.0) { //add environmentmap -- cgit v1.2.3 From b143aa96fcd6d16558464c98bcfd9984f7d29750 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 13 May 2019 15:33:48 -0700 Subject: SL-10856 Modify calc of sunlight to avoid clipping in gamma correct on values outside 0-1 range. Modify shaders to put back ambient clamp tuned to be close to ambient contrib in low/mid lighting. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 7533762a96..274d1818f0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -320,8 +320,7 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - //ambient = max(getAmbientClamp(), ambient); - ambient = 1.0 - ambient; + ambient = min(getAmbientClamp(), 1.0 - ambient); vec3 sun_contrib = min(final_da, shadow) * sunlit; -- cgit v1.2.3 From b9cd2ca7907e1543b77597fb7d9280944a9fa4bd Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 14 May 2019 08:24:23 -0700 Subject: SL-11085 Reduce spec bloom further. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 274d1818f0..dabdf69681 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -357,7 +357,7 @@ vec3 post_diffuse = color.rgb; if (nh > 0.0) { float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 speccol = sun_contrib*scol*spec.rgb*0.25; + vec3 speccol = sun_contrib*scol*spec.rgb / 16.0f; speccol = clamp(speccol, vec3(0), vec3(1)); bloom = dot(speccol, speccol); color += speccol; -- cgit v1.2.3 From cce6254aec2de6606b4940d961cef6cceb549d61 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 16 May 2019 09:23:07 -0700 Subject: SL-11085 Modify new spec response to better match old gloss response curve. Tuned at 255, 192, 160, 128, 64, and 32 glossiness. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index dabdf69681..0880a73b26 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -357,10 +357,10 @@ vec3 post_diffuse = color.rgb; if (nh > 0.0) { float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 speccol = sun_contrib*scol*spec.rgb / 16.0f; - speccol = clamp(speccol, vec3(0), vec3(1)); - bloom = dot(speccol, speccol); - color += speccol; + vec3 sp = sun_contrib*scol / 16.0f; + sp = clamp(sp, vec3(0), vec3(1)); + bloom = dot(sp, sp) / 6.0; + color += sp * spec.rgb; } } -- cgit v1.2.3 From e9dbee00262a437e4b3f971b37ea636e92032133 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 21 May 2019 16:00:45 -0700 Subject: SL-11238 Fix ambient light inputs to the renderer. Fix 3rd sky shader w/ mistaken density mod conversion. Make ambient clamp apply to all modes. Tune ALM ambient clamp to match non-ALM. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 0880a73b26..b9c16bfa11 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -320,7 +320,9 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - ambient = min(getAmbientClamp(), 1.0 - ambient); + + float ambient_clamp = getAmbientClamp() + 0.2; + ambient = (1.0 - ambient) * ambient_clamp; vec3 sun_contrib = min(final_da, shadow) * sunlit; -- cgit v1.2.3 From db091d23db70952b4ad8b610ef02942a8f13f223 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 22 May 2019 11:00:30 -0700 Subject: SL-10969 Fix linear attenuation on forward projector lighting. Revert setup of falloff to prev code. Revert deferred water spec and tweak refl/refr blend. --- .../shaders/class1/deferred/materialF.glsl | 23 +++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index b9c16bfa11..373727f572 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -110,17 +110,18 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe return col; } - if (d > 0.0) - { + if (d > 0.0 && la > 0.0 && fa > 0.0) + { //normalize light vector lv = normalize(lv); - + +la /= 20.0f; + //distance attenuation - float dist = (la > 0) ? d/la : 1.0f; - fa += 1.0f; - float dist_atten = ( fa > 0) ? clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0) : 1.0f; + float dist = d/la; + + float dist_atten = (fa > 0) ? clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0) : 1.0f; dist_atten *= dist_atten; - dist_atten *= 2.2f; if (dist_atten <= 0) { @@ -139,15 +140,15 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe float lit = max(da * dist_atten, 0.0); float amb_da = ambiance; - if (da > 0) - { + if (lit > 0) + { col = light_col*lit*diffuse; amb_da += (da*0.5 + 0.5) * ambiance; amb_da += (da*da*0.5+0.5) * ambiance; } amb_da *= dist_atten; amb_da = min(amb_da, 1.0f - lit); - col.rgb += amb_da * 0.25 * light_col * diffuse; + col.rgb += amb_da * 0.5 * light_col * diffuse; if (spec.a > 0.0) { @@ -321,7 +322,7 @@ void main() ambient *= 0.5; ambient *= ambient; - float ambient_clamp = getAmbientClamp() + 0.2; + float ambient_clamp = getAmbientClamp() + 0.1; ambient = (1.0 - ambient) * ambient_clamp; vec3 sun_contrib = min(final_da, shadow) * sunlit; -- cgit v1.2.3 From d0a0eede63fdbd4ba597b86cbfbeb5b394ed2395 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 23 May 2019 09:58:33 -0700 Subject: Add render debug controls for forcing disable of ambient, sun, and local light contributions (engages AMBIENT_KILL, SUNLIGHT_KILL, and LOCAL_LIGHT_KILL defines in shaders to accomplish those tasks as required by each render mode). --- .../shaders/class1/deferred/materialF.glsl | 136 ++++++++++----------- 1 file changed, 67 insertions(+), 69 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 373727f572..1c0516923e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -88,17 +88,19 @@ float getAmbientClamp(); 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) { - //get light vector - vec3 lv = lp.xyz-v; - - //get distance - float d = length(lv); - - float da = 1.0; + vec3 col = vec3(0); + +la /= 20.0f; - vec3 col = vec3(0,0,0); + //get light vector + vec3 lv = lp.xyz-v; + + //get distance + float d = length(lv); + + float da = 1.0; - vec4 proj_tc = proj_mat * lp; + /*vec4 proj_tc = proj_mat * lp; if (proj_tc.z < 0 || proj_tc.z > 1 @@ -108,77 +110,68 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe || proj_tc.y > 1) { return col; - } + }*/ - if (d > 0.0 && la > 0.0 && fa > 0.0) + if (d > 0.0 && la > 0.0 && fa > 0.0) { - //normalize light vector - lv = normalize(lv); - -la /= 20.0f; - - //distance attenuation - float dist = d/la; - - float dist_atten = (fa > 0) ? clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0) : 1.0f; - dist_atten *= dist_atten; - - if (dist_atten <= 0) - { - return col; - } - - // spotlight coefficient. - float spot = max(dot(-ln, lv), is_pointlight); - - //angular attenuation - da = dot(n, lv); - da = clamp(da, 0.0, 1.0); - - da *= spot*spot; // GL_SPOT_EXPONENT=2 - - float lit = max(da * dist_atten, 0.0); + //normalize light vector + lv = normalize(lv); + + //distance attenuation + float dist = d/la; + float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); + dist_atten *= dist_atten; + dist_atten *= 2.0f; + + // spotlight coefficient. + float spot = max(dot(-ln, lv), is_pointlight); + da *= spot*spot; // GL_SPOT_EXPONENT=2 + + //angular attenuation + da *= max(dot(n, lv), 0.0); + + float lit = max(da * dist_atten, 0.0); float amb_da = ambiance; if (lit > 0) { col = light_col*lit*diffuse; amb_da += (da*0.5 + 0.5) * ambiance; - amb_da += (da*da*0.5+0.5) * ambiance; } + amb_da += (da*da*0.5+0.5) * ambiance; amb_da *= dist_atten; amb_da = min(amb_da, 1.0f - lit); - col.rgb += amb_da * 0.5 * light_col * diffuse; - - if (spec.a > 0.0) - { - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(lv+npos); - float nh = dot(n, h); - float nv = dot(n, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 speccol = lit*scol*light_col.rgb*spec.rgb; + col.rgb += amb_da * light_col * diffuse; + + if (spec.a > 0.0) + { + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(lv+npos); + float nh = dot(n, h); + float nv = dot(n, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + vec3 speccol = lit*scol*light_col.rgb*spec.rgb; speccol = clamp(speccol, vec3(0), vec3(1)); - col += speccol; + 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); - } - } - } + 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); + } + } + } - return max(col, vec3(0.0,0.0,0.0)); + return max(col, vec3(0.0,0.0,0.0)); } #else @@ -321,18 +314,22 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - + float ambient_clamp = getAmbientClamp() + 0.1; ambient = (1.0 - ambient) * ambient_clamp; vec3 sun_contrib = min(final_da, shadow) * sunlit; +#if !defined(AMBIENT_KILL) color.rgb = amblit; color.rgb *= ambient; +#endif vec3 post_ambient = color.rgb; +#if !defined(SUNLIGHT_KILL) color.rgb += sun_contrib; +#endif vec3 post_sunlight = color.rgb; @@ -398,7 +395,7 @@ vec3 post_atmo = color.rgb; vec3 light = vec3(0,0,0); - #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.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, glare, light_attenuation[i].w); + #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.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, glare, light_attenuation[i].w ); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -408,11 +405,12 @@ vec3 post_atmo = color.rgb; LIGHT_LOOP(6) LIGHT_LOOP(7) - glare = min(glare, 1.0); float al = max(diffuse_linear.a,glare)*vertex_color.a; +#if !defined(LOCAL_LIGHT_KILL) color.rgb += light.rgb; +#endif // (only) post-deferred needs inline gamma correction color.rgb = linear_to_srgb(color.rgb); -- cgit v1.2.3 From 3c37658c02a2cf4b257203a9bc68246c5ac4042a Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 23 May 2019 11:16:23 -0700 Subject: Re-enable projector ambiance for forward alpha objects. Undo attenuation hacks and balance with deferred path projector lighting. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 1c0516923e..b599b6d2fc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -90,8 +90,6 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe { vec3 col = vec3(0); -la /= 20.0f; - //get light vector vec3 lv = lp.xyz-v; @@ -121,7 +119,7 @@ la /= 20.0f; float dist = d/la; float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); dist_atten *= dist_atten; - dist_atten *= 2.0f; + //dist_atten *= 2.0f; // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); -- cgit v1.2.3 From 3d9bd0fb8291ad3de4aaa20100149bd45680538b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 28 May 2019 14:36:00 -0700 Subject: SL-10969, SL-11073 Modify forward projector lighting to use falloff like the deferred lights. Make tex cache not evaluate evictions for size during validation passes. --- .../shaders/class1/deferred/materialF.glsl | 66 ++++++++++++++-------- 1 file changed, 43 insertions(+), 23 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index b599b6d2fc..c3ca9a6904 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -88,17 +88,19 @@ float getAmbientClamp(); 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) { - vec3 col = vec3(0); + vec3 col = vec3(0); //get light vector vec3 lv = lp.xyz-v; - + //get distance - float d = length(lv); - + float dist = length(lv); float da = 1.0; - /*vec4 proj_tc = proj_mat * lp; + dist /= la; + + /* clip to projector bounds + vec4 proj_tc = proj_mat * lp; if (proj_tc.z < 0 || proj_tc.z > 1 @@ -110,35 +112,42 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe return col; }*/ - if (d > 0.0 && la > 0.0 && fa > 0.0) + fa += 1.0; + if (dist > 0.0 && la > 0.0 && fa > 0.0) { //normalize light vector lv = normalize(lv); //distance attenuation - float dist = d/la; float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); dist_atten *= dist_atten; - //dist_atten *= 2.0f; + dist_atten *= 2.0f; + + if (dist_atten <= 0.0) + { + return col; + } // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); da *= spot*spot; // GL_SPOT_EXPONENT=2 //angular attenuation - da *= max(dot(n, lv), 0.0); - - float lit = max(da * dist_atten, 0.0); + da *= dot(n, lv); + + float lit = 0.0f; float amb_da = ambiance; - if (lit > 0) - { - col = light_col*lit*diffuse; - amb_da += (da*0.5 + 0.5) * ambiance; + if (da > 0) + { + lit = max(da * dist_atten,0.0); + col = lit * light_col * diffuse; + amb_da += (da*0.5+0.5) * ambiance; } - amb_da += (da*da*0.5+0.5) * ambiance; + amb_da += (da*da*0.5 + 0.5) * ambiance; amb_da *= dist_atten; amb_da = min(amb_da, 1.0f - lit); + col.rgb += amb_da * light_col * diffuse; if (spec.a > 0.0) @@ -217,8 +226,15 @@ void main() { vec2 pos_screen = vary_texcoord0.xy; - vec4 diffuse_linear = texture2D(diffuseMap, vary_texcoord0.xy); - vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_linear.a); + vec4 diffuse_tap = texture2D(diffuseMap, vary_texcoord0.xy); + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + vec4 diffuse_srgb = diffuse_tap; + vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_tap.a); +#else + vec4 diffuse_linear = diffuse_tap; + vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_tap.a); +#endif #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) if (diffuse_linear.a < minimum_alpha) @@ -331,7 +347,7 @@ vec3 post_ambient = color.rgb; vec3 post_sunlight = color.rgb; - color.rgb *= diffuse_linear.rgb; + color.rgb *= diffuse_srgb.rgb; vec3 post_diffuse = color.rgb; @@ -358,7 +374,9 @@ vec3 post_diffuse = color.rgb; vec3 sp = sun_contrib*scol / 16.0f; sp = clamp(sp, vec3(0), vec3(1)); bloom = dot(sp, sp) / 6.0; +#if !defined(SUNLIGHT_KILL) color += sp * spec.rgb; +#endif } } @@ -371,8 +389,9 @@ vec3 post_spec = color.rgb; vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; +#if !defined(SUNLIGHT_KILL) color = mix(color.rgb, reflected_color, envIntensity); - +#endif float cur_glare = max(reflected_color.r, reflected_color.g); cur_glare = max(cur_glare, reflected_color.b); cur_glare *= envIntensity*4.0; @@ -382,13 +401,12 @@ vec3 post_spec = color.rgb; vec3 post_env = color.rgb; color = atmosFragLighting(color, additive, atten); - color = scaleSoftClipFrag(color); - -vec3 post_atmo = color.rgb; //convert to linear space before adding local lights color = srgb_to_linear(color); +vec3 post_atmo = color.rgb; + vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0,0,0); @@ -410,6 +428,8 @@ vec3 post_atmo = color.rgb; color.rgb += light.rgb; #endif + color = scaleSoftClipFrag(color); + // (only) post-deferred needs inline gamma correction color.rgb = linear_to_srgb(color.rgb); -- cgit v1.2.3 From 2f2cf6d855e1e5977ef0ed3583238636e890220a Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 29 May 2019 15:57:24 -0700 Subject: SL-10969 Modify ambient handling and forward projector lighting again to stamp out alpha fires. --- .../newview/app_settings/shaders/class1/deferred/materialF.glsl | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index c3ca9a6904..4701157909 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -112,8 +112,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe return col; }*/ - fa += 1.0; - if (dist > 0.0 && la > 0.0 && fa > 0.0) + if (dist > 0.0 && la > 0.0) { //normalize light vector lv = normalize(lv); @@ -121,7 +120,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe //distance attenuation float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); dist_atten *= dist_atten; - dist_atten *= 2.0f; + //dist_atten *= 2.0f; if (dist_atten <= 0.0) { @@ -328,9 +327,7 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - - float ambient_clamp = getAmbientClamp() + 0.1; - ambient = (1.0 - ambient) * ambient_clamp; + ambient = (1.0 - ambient); vec3 sun_contrib = min(final_da, shadow) * sunlit; -- cgit v1.2.3 From 58f7b981bdb415311f23dfffc39e7a841b3017a0 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 31 May 2019 13:47:44 -0700 Subject: SL-11337 Fix handling of ambient (was getting reset to 1,1,1,1 unintentionally). Modify shaders to balance ambient across render modes again. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 4701157909..8e0b903d04 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -332,7 +332,7 @@ void main() vec3 sun_contrib = min(final_da, shadow) * sunlit; #if !defined(AMBIENT_KILL) - color.rgb = amblit; + color.rgb = amblit * 0.5; color.rgb *= ambient; #endif -- cgit v1.2.3 From ee9ad6520ec0cad689a9dfa7ca55717a43f2e897 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 31 May 2019 15:25:54 -0700 Subject: SL-11343 Make materials apply vertex color to both linear and srgb versions of diffuse color. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 8e0b903d04..1e7ca08aa1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -243,6 +243,7 @@ void main() #endif diffuse_linear.rgb *= vertex_color.rgb; + diffuse_srgb.rgb *= linear_to_srgb(vertex_color.rgb); #ifdef HAS_SPECULAR_MAP vec4 spec = texture2D(specularMap, vary_texcoord2.xy); -- cgit v1.2.3 From b79d0d2fdd047636598cbc9b088c3d4a10a84460 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 10 Jun 2019 09:15:35 -0700 Subject: SL-10969, SL-11051 Make fullbright alpha mask with mask cutoff == 0 not generate shadows. Adjust handling of ambient across forward and deferred again. --- .../app_settings/shaders/class1/deferred/materialF.glsl | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 1e7ca08aa1..1f0fa97297 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -41,7 +41,7 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); -void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); +void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cs); @@ -67,7 +67,6 @@ uniform vec3 camPosLocal; //uniform vec4 camPosWorld; uniform vec4 gamma; uniform mat3 env_mat; -uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; uniform vec3 moon_dir; @@ -226,14 +225,8 @@ void main() vec2 pos_screen = vary_texcoord0.xy; vec4 diffuse_tap = texture2D(diffuseMap, vary_texcoord0.xy); - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - vec4 diffuse_srgb = diffuse_tap; - vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_tap.a); -#else vec4 diffuse_linear = diffuse_tap; vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_tap.a); -#endif #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) if (diffuse_linear.a < minimum_alpha) @@ -313,7 +306,7 @@ void main() vec3 additive; vec3 atten; - calcAtmosphericVars(pos.xyz, 1.0, sunlit, amblit, additive, atten); + calcAtmosphericVars(pos.xyz, 1.0, sunlit, amblit, additive, atten, false); vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); @@ -333,7 +326,7 @@ void main() vec3 sun_contrib = min(final_da, shadow) * sunlit; #if !defined(AMBIENT_KILL) - color.rgb = amblit * 0.5; + color.rgb = amblit * 2.0; color.rgb *= ambient; #endif @@ -345,7 +338,7 @@ vec3 post_ambient = color.rgb; vec3 post_sunlight = color.rgb; - color.rgb *= diffuse_srgb.rgb; + color.rgb *= diffuse_linear.rgb; vec3 post_diffuse = color.rgb; -- cgit v1.2.3 From 653133b9c035e7c34563b199e991189ca3046092 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 11 Jun 2019 13:03:06 -0700 Subject: SL-11370, SL-11372, SL-11337 Fix culling on Low+ water reflection pass. Make Mid+ / High use class1 deferred sky again (no rainbows, but faster!). Fix setting of cloud color for deferred sky/cloud shaders. Put water reflections back in wrong colorspace for consistency with release. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 1f0fa97297..571d0dd17a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -326,7 +326,7 @@ void main() vec3 sun_contrib = min(final_da, shadow) * sunlit; #if !defined(AMBIENT_KILL) - color.rgb = amblit * 2.0; + color.rgb = amblit; color.rgb *= ambient; #endif -- cgit v1.2.3 From 4abb342e9564a7740475c3abe60cd62ae5bbc34d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 18 Jun 2019 13:14:27 -0700 Subject: SL-10969 Remove ambiance handling from alpha and blended materials objects for now. Still too many setups where they get blown out due to attenuation mismatches with deferred. --- .../app_settings/shaders/class1/deferred/materialF.glsl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 571d0dd17a..8ebb2f44d3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -117,6 +117,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe lv = normalize(lv); //distance attenuation + fa += 1.0f; float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); dist_atten *= dist_atten; //dist_atten *= 2.0f; @@ -136,7 +137,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe float lit = 0.0f; float amb_da = ambiance; - if (da > 0) + if (da >= 0) { lit = max(da * dist_atten,0.0); col = lit * light_col * diffuse; @@ -146,7 +147,8 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe amb_da *= dist_atten; amb_da = min(amb_da, 1.0f - lit); - col.rgb += amb_da * light_col * diffuse; + // SL-10969 need to see why these are blown out + //col.rgb += amb_da * light_col * diffuse; if (spec.a > 0.0) { @@ -225,8 +227,14 @@ void main() vec2 pos_screen = vary_texcoord0.xy; vec4 diffuse_tap = texture2D(diffuseMap, vary_texcoord0.xy); + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + vec4 diffuse_srgb = diffuse_tap; + vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); +#else vec4 diffuse_linear = diffuse_tap; - vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_tap.a); + vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_linear.a); +#endif #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) if (diffuse_linear.a < minimum_alpha) @@ -338,7 +346,7 @@ vec3 post_ambient = color.rgb; vec3 post_sunlight = color.rgb; - color.rgb *= diffuse_linear.rgb; + color.rgb *= diffuse_srgb.rgb; vec3 post_diffuse = color.rgb; -- cgit v1.2.3 From 5bd055fe585233b3c43e02f2082f5a95f79b825b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 18 Jun 2019 14:33:28 -0700 Subject: SL-10829 the 2nd Made pointLightF use correct colorspace as multiPoint already was. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 8ebb2f44d3..6e5ec7d34c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -117,10 +117,9 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe lv = normalize(lv); //distance attenuation - fa += 1.0f; float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); dist_atten *= dist_atten; - //dist_atten *= 2.0f; + dist_atten *= 2.0f; if (dist_atten <= 0.0) { -- cgit v1.2.3 From 81c90124829c6830a3511bd6064e4ff07c94e35a Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 18 Jun 2019 14:44:10 -0700 Subject: SL-11406 Fix alpha output of fullbright deferred materials objects. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 6e5ec7d34c..a82af996a1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -280,6 +280,10 @@ void main() final_color.a = max(final_color.a, emissive_brightness); #endif +#if !defined(HAS_NORMAL_MAP) + final_color.a = 0.0f; +#endif + vec4 final_specular = spec; final_specular.a = specular_color.a; #ifdef HAS_SPECULAR_MAP -- cgit v1.2.3 From 48f169423ba0c1da8ffe13fc8bc4cec76336d8fc Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 3 Jul 2019 10:04:05 -0700 Subject: SL-11545, SL-11543, SL-10625 Fix emissives without normal maps clobbering the alpha output in materialF. Modify glow size calc to get close to pre-EEP sun glow behavior (may require sky vert settings >= mid). Make bake ignore alpha readback for Intel until we can determine why their drivers now go boom. --- .../app_settings/shaders/class1/deferred/materialF.glsl | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index a82af996a1..a8cac3e5a9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -273,15 +273,11 @@ void main() vec2 abnormal = encode_normal(norm.xyz); vec4 final_color = diffuse_linear; - -#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) - final_color.a = emissive_brightness; -#else - final_color.a = max(final_color.a, emissive_brightness); -#endif -#if !defined(HAS_NORMAL_MAP) - final_color.a = 0.0f; +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_EMISSIVE) + // nop, use content of alpha emissive mask as is... +#else + final_color.a = emissive_brightness; #endif vec4 final_specular = spec; @@ -459,6 +455,8 @@ vec3 post_atmo = color.rgb; #else // deferred path + +final_color = diffuse_linear; frag_data[0] = final_color; frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. -- cgit v1.2.3 From 9f2148cc1f2469a1f45f8f3f736251a0300d1d6a Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 5 Jul 2019 11:21:45 -0700 Subject: SL-11552 Fix materialF including debug force to linear color and re-add logic to stomp emissiveness when normals are not present unless explicitly requested via diffuse alpha mode. --- .../app_settings/shaders/class1/deferred/materialF.glsl | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index a8cac3e5a9..72b1535332 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -25,7 +25,7 @@ /*[EXTRA_CODE_HERE]*/ -#define DIFFUSE_ALPHA_MODE_IGNORE 0 +#define DIFFUSE_ALPHA_MODE_NONE 0 #define DIFFUSE_ALPHA_MODE_BLEND 1 #define DIFFUSE_ALPHA_MODE_MASK 2 #define DIFFUSE_ALPHA_MODE_EMISSIVE 3 @@ -274,10 +274,11 @@ void main() vec4 final_color = diffuse_linear; -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_EMISSIVE) - // nop, use content of alpha emissive mask as is... -#else - final_color.a = emissive_brightness; +#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) + final_color.a = max(final_color.a, emissive_brightness); + #if !defined(HAS_NORMAL_MAP) + final_color.a = 0.0f; + #endif #endif vec4 final_specular = spec; @@ -455,8 +456,6 @@ vec3 post_atmo = color.rgb; #else // deferred path - -final_color = diffuse_linear; frag_data[0] = final_color; frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. -- cgit v1.2.3 From 5e84b7af3513851e52606a9c4610041ad1aec177 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 8 Jul 2019 13:23:43 -0700 Subject: Fix materials content being emissive when it should not. --- .../app_settings/shaders/class1/deferred/materialF.glsl | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 72b1535332..4cbef89fef 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -272,14 +272,12 @@ void main() vec2 abnormal = encode_normal(norm.xyz); - vec4 final_color = diffuse_linear; + vec4 final_color = vec4(diffuse_linear.rgb, 0.0); -#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) - final_color.a = max(final_color.a, emissive_brightness); - #if !defined(HAS_NORMAL_MAP) - final_color.a = 0.0f; - #endif +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_EMISSIVE) + final_color.a = diffuse_linear.a; #endif + final_color.a = max(final_color.a, emissive_brightness); vec4 final_specular = spec; final_specular.a = specular_color.a; -- cgit v1.2.3 From 664722168d7016d8bf80a65626bbff542913dc24 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 10 Jul 2019 14:50:59 -0700 Subject: SL-1491 Make sun additive contribition depend on facing the sun (without breaking fog). Put back scaling factor keeping sun contrib from blowing out with new FS param range for glow. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 4cbef89fef..38792601f6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -41,7 +41,7 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); -void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); +void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cs); @@ -304,6 +304,8 @@ void main() float envIntensity = final_normal.z; + vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + vec3 color = vec3(0.0); float bloom = 0.0; @@ -312,11 +314,10 @@ void main() vec3 additive; vec3 atten; - calcAtmosphericVars(pos.xyz, 1.0, sunlit, amblit, additive, atten, false); + calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; float da = dot(normalize(norm.xyz), normalize(light_dir.xyz)); da = clamp(da, -1.0, 1.0); -- cgit v1.2.3 From b507d63566e8896af702dd10f5643dc29068a8a9 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 23 Jul 2019 11:36:22 -0700 Subject: SL-11621 Remove all references to unused shader var global_gamma. Remove many unused decls for gamma from shaders. Make post-deferred gamma correction use display_gamma. Make setting display_gamma use the correct RenderDeferredDisplayGamma setting. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 3 --- 1 file changed, 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 38792601f6..a13c8de43e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -31,7 +31,6 @@ #define DIFFUSE_ALPHA_MODE_EMISSIVE 3 uniform float emissive_brightness; -uniform float display_gamma; uniform int sun_up_factor; #ifdef WATER_FOG @@ -64,8 +63,6 @@ uniform sampler2D lightFunc; // Inputs uniform vec4 morphFactor; uniform vec3 camPosLocal; -//uniform vec4 camPosWorld; -uniform vec4 gamma; uniform mat3 env_mat; uniform vec3 sun_dir; -- cgit v1.2.3 From 440a40c8f9fd35577470aee193a4b7dd128d80bb Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 22 Aug 2019 10:41:55 -0700 Subject: SL-11406 Restore code to stomp emissive in the absence of a normal map (to avoid fullbright implying full emissive). --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index a13c8de43e..023172c844 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -276,6 +276,10 @@ void main() #endif final_color.a = max(final_color.a, emissive_brightness); +#if !defined(HAS_NORMAL_MAP) + final_color.a = 0.0f; +#endif + vec4 final_specular = spec; final_specular.a = specular_color.a; #ifdef HAS_SPECULAR_MAP -- cgit v1.2.3 From 16933b0ab9a8556467fba18790050f2d025d06a5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 3 Sep 2019 15:57:49 -0700 Subject: SL-11543, SL-11443 Fix faullbright/emissive problems. --- .../app_settings/shaders/class1/deferred/materialF.glsl | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 023172c844..fafecd57cc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -274,20 +274,16 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_EMISSIVE) final_color.a = diffuse_linear.a; #endif - final_color.a = max(final_color.a, emissive_brightness); -#if !defined(HAS_NORMAL_MAP) - final_color.a = 0.0f; -#endif + final_color.a = max(final_color.a, emissive_brightness); + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); vec4 final_specular = spec; + final_specular.a = specular_color.a; -#ifdef HAS_SPECULAR_MAP - final_specular.a *= norm.a; -#endif - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); -#ifdef HAS_SPECULAR_MAP +#if HAS_SPECULAR_MAP + final_specular.a *= norm.a; final_normal.z *= spec.a; #endif -- cgit v1.2.3 From 3dfdb2f6e8be4fb2a08102847520585dc1d8fd7d Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Tue, 29 Oct 2019 17:46:33 -0600 Subject: SL-10449 FIX [EEP] Fixed a (Mac-only) shader regression in changeset 41246 --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index fafecd57cc..9505f2eb74 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -277,13 +277,13 @@ void main() final_color.a = max(final_color.a, emissive_brightness); - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); + vec4 final_normal = vec4(abnormal, env_intensity, 0.0); vec4 final_specular = spec; final_specular.a = specular_color.a; -#if HAS_SPECULAR_MAP - final_specular.a *= norm.a; +#ifdef HAS_SPECULAR_MAP + final_specular.a *= norm.a; final_normal.z *= spec.a; #endif -- cgit v1.2.3 From e1ea2c2b1eda89cf08fc31d3d1970446daea1883 Mon Sep 17 00:00:00 2001 From: "Michael Pohoreski (Ptolemy Linden)" Date: Thu, 21 Nov 2019 05:25:18 +0000 Subject: SL-11406 Fix fullbright to better match non-EEP. Minor optimization cleanup. --- .../shaders/class1/deferred/materialF.glsl | 27 ++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 9505f2eb74..e640c2d7ae 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -264,8 +264,7 @@ void main() tnorm = vary_normal; #endif - norm.xyz = tnorm; - norm.xyz = normalize(norm.xyz); + norm.xyz = normalize(tnorm.xyz); vec2 abnormal = encode_normal(norm.xyz); @@ -277,7 +276,20 @@ void main() final_color.a = max(final_color.a, emissive_brightness); - vec4 final_normal = vec4(abnormal, env_intensity, 0.0); + // SL-11406 Fullbright: Object > Texture > Shininess > Environment Intensity = 1 + // NOTE: There are two shaders that are used depending on the EI byte value: + // EI = 0 fullbright + // EI > 0 .. 255 material + // When it is passed to us it is normalized. + // We can either modify the output environment intensity + // OR + // adjust the final color via: + // final_color *= 0.666666; + // We remap the environment intensity to closely simulate what non-EEP is doing. + // At midnight the brightness is exact. + // At midday the brightness is very close. + float ei = env_intensity*0.5 + 0.5; + vec4 final_normal = vec4(abnormal, ei, 0.0); vec4 final_specular = spec; final_specular.a = specular_color.a; @@ -316,11 +328,11 @@ void main() vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - float da = dot(normalize(norm.xyz), normalize(light_dir.xyz)); - da = clamp(da, -1.0, 1.0); + float da = dot(norm.xyz, normalize(light_dir.xyz)); + // Dot product is guaranteed to be in -1 <= da <= +1 range for normalized vectors + // da = clamp(da, -1.0, 1.0); - float final_da = da; - final_da = clamp(final_da, 0.0, 1.0); + float final_da = clamp(da, 0.0, 1.0); float ambient = da; ambient *= 0.5; @@ -458,3 +470,4 @@ vec3 post_atmo = color.rgb; #endif } + -- cgit v1.2.3 From a164daad74fc0c8729aac5601df23c0f5cb3c02c Mon Sep 17 00:00:00 2001 From: "Michael Pohoreski (Ptolemy Linden)" Date: Sat, 23 Nov 2019 00:02:30 +0000 Subject: Cleanup comments --- .../newview/app_settings/shaders/class1/deferred/materialF.glsl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index e640c2d7ae..c23314a4b9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -276,7 +276,11 @@ void main() final_color.a = max(final_color.a, emissive_brightness); - // SL-11406 Fullbright: Object > Texture > Shininess > Environment Intensity = 1 + // Texture + // [x] Full Bright Object + // Shininess (specular) + // [X] Texture + // Environment Intensity = 1 // NOTE: There are two shaders that are used depending on the EI byte value: // EI = 0 fullbright // EI > 0 .. 255 material @@ -329,9 +333,6 @@ void main() float da = dot(norm.xyz, normalize(light_dir.xyz)); - // Dot product is guaranteed to be in -1 <= da <= +1 range for normalized vectors - // da = clamp(da, -1.0, 1.0); - float final_da = clamp(da, 0.0, 1.0); float ambient = da; -- cgit v1.2.3 From 05e54ac96be519e5f60f2681ac3226dab7dcb8b2 Mon Sep 17 00:00:00 2001 From: "Michael Pohoreski (Ptolemy Linden)" Date: Tue, 10 Dec 2019 14:41:03 -0800 Subject: SL-11406: Skip avatars being effected. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index c23314a4b9..52c69b46ea 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -292,8 +292,12 @@ void main() // We remap the environment intensity to closely simulate what non-EEP is doing. // At midnight the brightness is exact. // At midday the brightness is very close. +#ifdef HAS_SKIN + vec4 final_normal = vec4(abnormal, env_intensity, 0.0); +#else float ei = env_intensity*0.5 + 0.5; vec4 final_normal = vec4(abnormal, ei, 0.0); +#endif vec4 final_specular = spec; final_specular.a = specular_color.a; -- cgit v1.2.3 From 124c5cf4a781e50f81e7266a1af5f83b36777651 Mon Sep 17 00:00:00 2001 From: "Michael Pohoreski (Ptolemy Linden)" Date: Tue, 17 Dec 2019 23:34:54 +0000 Subject: SL-12472 to address SL-11406 --- .../app_settings/shaders/class1/deferred/materialF.glsl | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 52c69b46ea..2b5fa3979b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -277,7 +277,7 @@ void main() final_color.a = max(final_color.a, emissive_brightness); // Texture - // [x] Full Bright Object + // [x] Full Bright (emissive_brightness > 0.0) // Shininess (specular) // [X] Texture // Environment Intensity = 1 @@ -292,11 +292,14 @@ void main() // We remap the environment intensity to closely simulate what non-EEP is doing. // At midnight the brightness is exact. // At midday the brightness is very close. -#ifdef HAS_SKIN vec4 final_normal = vec4(abnormal, env_intensity, 0.0); -#else - float ei = env_intensity*0.5 + 0.5; - vec4 final_normal = vec4(abnormal, ei, 0.0); + +#ifdef HAS_SPECULAR_MAP + if( emissive_brightness > 0.0) + { + float ei = env_intensity*0.5 + 0.5; + final_normal = vec4(abnormal, ei, 0.0); + } #endif vec4 final_specular = spec; -- cgit v1.2.3 From 874368d4f30b59640e843d7e30c612dd0d0baa75 Mon Sep 17 00:00:00 2001 From: "Michael Pohoreski (Ptolemy Linden)" Date: Wed, 18 Dec 2019 01:48:44 +0000 Subject: Future-proof Full Bright --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 2b5fa3979b..1be1595a47 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -277,7 +277,7 @@ void main() final_color.a = max(final_color.a, emissive_brightness); // Texture - // [x] Full Bright (emissive_brightness > 0.0) + // [x] Full Bright (emissive_brightness >= 1.0) // Shininess (specular) // [X] Texture // Environment Intensity = 1 @@ -295,7 +295,7 @@ void main() vec4 final_normal = vec4(abnormal, env_intensity, 0.0); #ifdef HAS_SPECULAR_MAP - if( emissive_brightness > 0.0) + if( emissive_brightness >= 1.0) { float ei = env_intensity*0.5 + 0.5; final_normal = vec4(abnormal, ei, 0.0); -- cgit v1.2.3 From c453a0df6fe9f2d6611e7368d3f1d17ba4d5f09e Mon Sep 17 00:00:00 2001 From: "Michael Pohoreski (Ptolemy Linden)" Date: Mon, 23 Dec 2019 23:15:03 +0000 Subject: SL-12006 pre-checkin --- .../shaders/class1/deferred/materialF.glsl | 428 +++++++++++---------- 1 file changed, 217 insertions(+), 211 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 1be1595a47..10a9e3a5b4 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -47,142 +47,142 @@ vec3 linear_to_srgb(vec3 cs); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif + #ifdef DEFINE_GL_FRAGCOLOR + out vec4 frag_color; + #else + #define frag_color gl_FragColor + #endif -#ifdef HAS_SUN_SHADOW -float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); -#endif + #ifdef HAS_SUN_SHADOW + float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); + #endif -uniform samplerCube environmentMap; -uniform sampler2D lightFunc; + uniform samplerCube environmentMap; + uniform sampler2D lightFunc; -// Inputs -uniform vec4 morphFactor; -uniform vec3 camPosLocal; -uniform mat3 env_mat; + // Inputs + uniform vec4 morphFactor; + uniform vec3 camPosLocal; + uniform mat3 env_mat; -uniform vec3 sun_dir; -uniform vec3 moon_dir; -VARYING vec2 vary_fragcoord; + uniform vec3 sun_dir; + uniform vec3 moon_dir; + VARYING vec2 vary_fragcoord; -VARYING vec3 vary_position; + VARYING vec3 vary_position; -uniform mat4 proj_mat; -uniform mat4 inv_proj; -uniform vec2 screen_res; + uniform mat4 proj_mat; + uniform mat4 inv_proj; + uniform vec2 screen_res; -uniform vec4 light_position[8]; -uniform vec3 light_direction[8]; -uniform vec4 light_attenuation[8]; -uniform vec3 light_diffuse[8]; + uniform vec4 light_position[8]; + uniform vec3 light_direction[8]; + uniform vec4 light_attenuation[8]; + uniform vec3 light_diffuse[8]; -float getAmbientClamp(); + float getAmbientClamp(); -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) -{ - vec3 col = vec3(0); + 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) + { + vec3 col = vec3(0); - //get light vector - vec3 lv = lp.xyz-v; + //get light vector + vec3 lv = lp.xyz-v; - //get distance - float dist = length(lv); - float da = 1.0; + //get distance + float dist = length(lv); + float da = 1.0; - dist /= la; + dist /= la; - /* clip to projector bounds - vec4 proj_tc = proj_mat * lp; + /* clip to projector bounds + vec4 proj_tc = proj_mat * lp; - if (proj_tc.z < 0 - || proj_tc.z > 1 - || proj_tc.x < 0 - || proj_tc.x > 1 - || proj_tc.y < 0 - || proj_tc.y > 1) - { - return col; - }*/ + if (proj_tc.z < 0 + || proj_tc.z > 1 + || proj_tc.x < 0 + || proj_tc.x > 1 + || proj_tc.y < 0 + || proj_tc.y > 1) + { + return col; + }*/ - if (dist > 0.0 && la > 0.0) - { - //normalize light vector - lv = normalize(lv); - - //distance attenuation - float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); - dist_atten *= dist_atten; - dist_atten *= 2.0f; - - if (dist_atten <= 0.0) - { - return col; - } - - // spotlight coefficient. - float spot = max(dot(-ln, lv), is_pointlight); - da *= spot*spot; // GL_SPOT_EXPONENT=2 - - //angular attenuation - da *= dot(n, lv); - - float lit = 0.0f; - - float amb_da = ambiance; - if (da >= 0) - { - lit = max(da * dist_atten,0.0); - col = lit * light_col * diffuse; - amb_da += (da*0.5+0.5) * ambiance; - } - amb_da += (da*da*0.5 + 0.5) * ambiance; - amb_da *= dist_atten; - amb_da = min(amb_da, 1.0f - lit); - - // SL-10969 need to see why these are blown out - //col.rgb += amb_da * light_col * diffuse; - - if (spec.a > 0.0) + if (dist > 0.0 && la > 0.0) { - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(lv+npos); - float nh = dot(n, h); - float nv = dot(n, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + //normalize light vector + lv = normalize(lv); + + //distance attenuation + float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); + dist_atten *= dist_atten; + dist_atten *= 2.0f; + + if (dist_atten <= 0.0) + { + return col; + } - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) + // spotlight coefficient. + float spot = max(dot(-ln, lv), is_pointlight); + da *= spot*spot; // GL_SPOT_EXPONENT=2 + + //angular attenuation + da *= dot(n, lv); + + float lit = 0.0f; + + float amb_da = ambiance; + if (da >= 0) { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - 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); + lit = max(da * dist_atten,0.0); + col = lit * light_col * diffuse; + amb_da += (da*0.5+0.5) * ambiance; + } + amb_da += (da*da*0.5 + 0.5) * ambiance; + amb_da *= dist_atten; + amb_da = min(amb_da, 1.0f - lit); + + // SL-10969 need to see why these are blown out + //col.rgb += amb_da * light_col * diffuse; + + if (spec.a > 0.0) + { + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(lv+npos); + float nh = dot(n, h); + float nv = dot(n, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + vec3 speccol = 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); + } } } - } - return max(col, vec3(0.0,0.0,0.0)); -} + return max(col, vec3(0.0,0.0,0.0)); + } -#else -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif + #else + #ifdef DEFINE_GL_FRAGCOLOR + out vec4 frag_data[3]; + #else + #define frag_data gl_FragData + #endif #endif uniform sampler2D diffuseMap; @@ -218,7 +218,7 @@ VARYING vec2 vary_texcoord0; vec2 encode_normal(vec3 n); -void main() +void main() { vec2 pos_screen = vary_texcoord0.xy; @@ -294,6 +294,9 @@ void main() // At midday the brightness is very close. vec4 final_normal = vec4(abnormal, env_intensity, 0.0); + vec3 color = vec3(0.0); + float al = 0.0; + #ifdef HAS_SPECULAR_MAP if( emissive_brightness >= 1.0) { @@ -301,8 +304,9 @@ void main() final_normal = vec4(abnormal, ei, 0.0); } #endif + vec4 final_specular = spec; - + final_specular.a = specular_color.a; #ifdef HAS_SPECULAR_MAP @@ -310,143 +314,143 @@ void main() final_normal.z *= spec.a; #endif + #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - //forward rendering, output just lit RGBA - vec3 pos = vary_position; + { + //forward rendering, output just lit RGBA + vec3 pos = vary_position; - float shadow = 1.0f; + float shadow = 1.0f; #ifdef HAS_SUN_SHADOW - shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen); + shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen); #endif - - spec = final_specular; - float envIntensity = final_normal.z; + spec = final_specular; - vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + float envIntensity = final_normal.z; - vec3 color = vec3(0.0); + vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - float bloom = 0.0; - vec3 sunlit; - vec3 amblit; - vec3 additive; - vec3 atten; + float bloom = 0.0; + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; - calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); + calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - float da = dot(norm.xyz, normalize(light_dir.xyz)); - float final_da = clamp(da, 0.0, 1.0); + float da = dot(norm.xyz, normalize(light_dir.xyz)); + float final_da = clamp(da, 0.0, 1.0); - float ambient = da; - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0 - ambient); + float ambient = da; + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0 - ambient); + + vec3 sun_contrib = min(final_da, shadow) * sunlit; - vec3 sun_contrib = min(final_da, shadow) * sunlit; - #if !defined(AMBIENT_KILL) - color.rgb = amblit; - color.rgb *= ambient; + color.rgb = amblit; + color.rgb *= ambient; #endif vec3 post_ambient = color.rgb; #if !defined(SUNLIGHT_KILL) - color.rgb += sun_contrib; + color.rgb += sun_contrib; #endif vec3 post_sunlight = color.rgb; - color.rgb *= diffuse_srgb.rgb; - + color.rgb *= diffuse_srgb.rgb; + vec3 post_diffuse = color.rgb; - float glare = 0.0; + float glare = 0.0; - if (spec.a > 0.0) // specular reflection - { - 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 / 16.0f; - sp = clamp(sp, vec3(0), vec3(1)); - bloom = dot(sp, sp) / 6.0; -#if !defined(SUNLIGHT_KILL) - color += sp * spec.rgb; -#endif - } - } + if (spec.a > 0.0) // specular reflection + { + vec3 npos = -normalize(pos.xyz); -vec3 post_spec = color.rgb; + //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; - if (envIntensity > 0.0) - { - //add environmentmap - vec3 env_vec = env_mat * refnormpersp; - - vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); -#if !defined(SUNLIGHT_KILL) - color = mix(color.rgb, reflected_color, envIntensity); -#endif - float cur_glare = max(reflected_color.r, reflected_color.g); - cur_glare = max(cur_glare, reflected_color.b); - cur_glare *= envIntensity*4.0; - glare += cur_glare; - } + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + vec3 sp = sun_contrib*scol / 16.0f; + sp = clamp(sp, vec3(0), vec3(1)); + bloom = dot(sp, sp) / 6.0; + #if !defined(SUNLIGHT_KILL) + color += sp * spec.rgb; + #endif + } + } + + vec3 post_spec = color.rgb; + + if (envIntensity > 0.0) + { + //add environmentmap + vec3 env_vec = env_mat * refnormpersp; + + vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; + + #if !defined(SUNLIGHT_KILL) + color = mix(color.rgb, reflected_color, envIntensity); + #endif + float cur_glare = max(reflected_color.r, reflected_color.g); + cur_glare = max(cur_glare, reflected_color.b); + cur_glare *= envIntensity*4.0; + glare += cur_glare; + } vec3 post_env = color.rgb; - color = atmosFragLighting(color, additive, atten); + color = atmosFragLighting(color, additive, atten); - //convert to linear space before adding local lights - color = srgb_to_linear(color); + //convert to linear space before adding local lights + color = srgb_to_linear(color); vec3 post_atmo = color.rgb; - vec3 npos = normalize(-pos.xyz); - - vec3 light = vec3(0,0,0); + vec3 npos = normalize(-pos.xyz); - #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.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, glare, light_attenuation[i].w ); + vec3 light = vec3(0,0,0); - LIGHT_LOOP(1) - LIGHT_LOOP(2) - LIGHT_LOOP(3) - LIGHT_LOOP(4) - LIGHT_LOOP(5) - LIGHT_LOOP(6) - LIGHT_LOOP(7) +#define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.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, glare, light_attenuation[i].w ); - glare = min(glare, 1.0); - float al = max(diffuse_linear.a,glare)*vertex_color.a; + LIGHT_LOOP(1) + LIGHT_LOOP(2) + LIGHT_LOOP(3) + LIGHT_LOOP(4) + LIGHT_LOOP(5) + LIGHT_LOOP(6) + LIGHT_LOOP(7) + + glare = min(glare, 1.0); + al = max(diffuse_linear.a,glare)*vertex_color.a; #if !defined(LOCAL_LIGHT_KILL) - color.rgb += light.rgb; + color.rgb += light.rgb; #endif - color = scaleSoftClipFrag(color); + color = scaleSoftClipFrag(color); - // (only) post-deferred needs inline gamma correction - color.rgb = linear_to_srgb(color.rgb); + // (only) post-deferred needs inline gamma correction + color.rgb = linear_to_srgb(color.rgb); //color.rgb = amblit; //color.rgb = vec3(ambient); @@ -462,15 +466,17 @@ vec3 post_atmo = color.rgb; //color.rgb = post_atmo; #ifdef WATER_FOG - vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); - color.rgb = temp.rgb; - al = temp.a; + vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); + color.rgb = temp.rgb; + al = temp.a; #endif + } frag_color.rgb = color.rgb; frag_color.a = al; -#else +#else // if DIFFUSE_ALPHA_MODE_BLEND ... + // deferred path frag_data[0] = final_color; frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. -- cgit v1.2.3 From a6f7de660f942419bc0ec4632b87b77157cd058b Mon Sep 17 00:00:00 2001 From: "Michael Pohoreski (Ptolemy Linden)" Date: Mon, 23 Dec 2019 23:48:33 +0000 Subject: Fix SL-12006: Fullbright with specular map, Alpha Mode Emissive, and wrong Diffuse for Alpha Mode Blend --- .../app_settings/shaders/class1/deferred/materialF.glsl | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 10a9e3a5b4..c072d44e63 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -272,6 +272,7 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_EMISSIVE) final_color.a = diffuse_linear.a; + final_color.rgb *= 0.5; #endif final_color.a = max(final_color.a, emissive_brightness); @@ -297,13 +298,16 @@ void main() vec3 color = vec3(0.0); float al = 0.0; -#ifdef HAS_SPECULAR_MAP - if( emissive_brightness >= 1.0) + if (emissive_brightness >= 1.0) { +#ifdef HAS_SPECULAR_MAP float ei = env_intensity*0.5 + 0.5; final_normal = vec4(abnormal, ei, 0.0); - } + #endif + color.rgb = final_color.rgb; + al = vertex_color.a; + } vec4 final_specular = spec; @@ -316,6 +320,7 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + if (emissive_brightness < 1.0) { //forward rendering, output just lit RGBA vec3 pos = vary_position; @@ -366,7 +371,8 @@ vec3 post_ambient = color.rgb; vec3 post_sunlight = color.rgb; - color.rgb *= diffuse_srgb.rgb; + //color.rgb *= diffuse_srgb.rgb; + color.rgb *= diffuse_linear.rgb; // SL-12006 vec3 post_diffuse = color.rgb; @@ -470,7 +476,7 @@ vec3 post_atmo = color.rgb; color.rgb = temp.rgb; al = temp.a; #endif - } + } // !fullbright frag_color.rgb = color.rgb; frag_color.a = al; -- cgit v1.2.3 From 2eb8b9af5a14ffa4a27b2c7d4f5985c2d5d00d6c Mon Sep 17 00:00:00 2001 From: "Michael Pohoreski (Ptolemy Linden)" Date: Tue, 24 Dec 2019 00:01:25 +0000 Subject: De-tabify --- .../shaders/class1/deferred/materialF.glsl | 472 ++++++++++----------- 1 file changed, 236 insertions(+), 236 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index c072d44e63..72e61095f2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -47,142 +47,142 @@ vec3 linear_to_srgb(vec3 cs); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - #ifdef DEFINE_GL_FRAGCOLOR - out vec4 frag_color; - #else - #define frag_color gl_FragColor - #endif - - #ifdef HAS_SUN_SHADOW - float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); - #endif - - uniform samplerCube environmentMap; - uniform sampler2D lightFunc; - - // Inputs - uniform vec4 morphFactor; - uniform vec3 camPosLocal; - uniform mat3 env_mat; - - uniform vec3 sun_dir; - uniform vec3 moon_dir; - VARYING vec2 vary_fragcoord; - - VARYING vec3 vary_position; - - uniform mat4 proj_mat; - uniform mat4 inv_proj; - uniform vec2 screen_res; - - uniform vec4 light_position[8]; - uniform vec3 light_direction[8]; - uniform vec4 light_attenuation[8]; - uniform vec3 light_diffuse[8]; - - float getAmbientClamp(); - - 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) - { - vec3 col = vec3(0); - - //get light vector - vec3 lv = lp.xyz-v; - - //get distance - float dist = length(lv); - float da = 1.0; - - dist /= la; - - /* clip to projector bounds - vec4 proj_tc = proj_mat * lp; - - if (proj_tc.z < 0 - || proj_tc.z > 1 - || proj_tc.x < 0 - || proj_tc.x > 1 - || proj_tc.y < 0 - || proj_tc.y > 1) - { - return col; - }*/ - - if (dist > 0.0 && la > 0.0) - { - //normalize light vector - lv = normalize(lv); - - //distance attenuation - float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); - dist_atten *= dist_atten; - dist_atten *= 2.0f; - - if (dist_atten <= 0.0) - { - return col; - } - - // spotlight coefficient. - float spot = max(dot(-ln, lv), is_pointlight); - da *= spot*spot; // GL_SPOT_EXPONENT=2 - - //angular attenuation - da *= dot(n, lv); - - float lit = 0.0f; - - float amb_da = ambiance; - if (da >= 0) - { - lit = max(da * dist_atten,0.0); - col = lit * light_col * diffuse; - amb_da += (da*0.5+0.5) * ambiance; - } - amb_da += (da*da*0.5 + 0.5) * ambiance; - amb_da *= dist_atten; - amb_da = min(amb_da, 1.0f - lit); - - // SL-10969 need to see why these are blown out - //col.rgb += amb_da * light_col * diffuse; - - if (spec.a > 0.0) - { - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(lv+npos); - float nh = dot(n, h); - float nv = dot(n, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 speccol = 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); - } - } - } - - return max(col, vec3(0.0,0.0,0.0)); - } - - #else - #ifdef DEFINE_GL_FRAGCOLOR - out vec4 frag_data[3]; - #else - #define frag_data gl_FragData - #endif + #ifdef DEFINE_GL_FRAGCOLOR + out vec4 frag_color; + #else + #define frag_color gl_FragColor + #endif + + #ifdef HAS_SUN_SHADOW + float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); + #endif + + uniform samplerCube environmentMap; + uniform sampler2D lightFunc; + + // Inputs + uniform vec4 morphFactor; + uniform vec3 camPosLocal; + uniform mat3 env_mat; + + uniform vec3 sun_dir; + uniform vec3 moon_dir; + VARYING vec2 vary_fragcoord; + + VARYING vec3 vary_position; + + uniform mat4 proj_mat; + uniform mat4 inv_proj; + uniform vec2 screen_res; + + uniform vec4 light_position[8]; + uniform vec3 light_direction[8]; + uniform vec4 light_attenuation[8]; + uniform vec3 light_diffuse[8]; + + float getAmbientClamp(); + + 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) + { + vec3 col = vec3(0); + + //get light vector + vec3 lv = lp.xyz-v; + + //get distance + float dist = length(lv); + float da = 1.0; + + dist /= la; + + /* clip to projector bounds + vec4 proj_tc = proj_mat * lp; + + if (proj_tc.z < 0 + || proj_tc.z > 1 + || proj_tc.x < 0 + || proj_tc.x > 1 + || proj_tc.y < 0 + || proj_tc.y > 1) + { + return col; + }*/ + + if (dist > 0.0 && la > 0.0) + { + //normalize light vector + lv = normalize(lv); + + //distance attenuation + float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); + dist_atten *= dist_atten; + dist_atten *= 2.0f; + + if (dist_atten <= 0.0) + { + return col; + } + + // spotlight coefficient. + float spot = max(dot(-ln, lv), is_pointlight); + da *= spot*spot; // GL_SPOT_EXPONENT=2 + + //angular attenuation + da *= dot(n, lv); + + float lit = 0.0f; + + float amb_da = ambiance; + if (da >= 0) + { + lit = max(da * dist_atten,0.0); + col = lit * light_col * diffuse; + amb_da += (da*0.5+0.5) * ambiance; + } + amb_da += (da*da*0.5 + 0.5) * ambiance; + amb_da *= dist_atten; + amb_da = min(amb_da, 1.0f - lit); + + // SL-10969 need to see why these are blown out + //col.rgb += amb_da * light_col * diffuse; + + if (spec.a > 0.0) + { + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(lv+npos); + float nh = dot(n, h); + float nv = dot(n, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + vec3 speccol = 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); + } + } + } + + return max(col, vec3(0.0,0.0,0.0)); + } + + #else + #ifdef DEFINE_GL_FRAGCOLOR + out vec4 frag_data[3]; + #else + #define frag_data gl_FragData + #endif #endif uniform sampler2D diffuseMap; @@ -295,8 +295,8 @@ void main() // At midday the brightness is very close. vec4 final_normal = vec4(abnormal, env_intensity, 0.0); - vec3 color = vec3(0.0); - float al = 0.0; + vec3 color = vec3(0.0); + float al = 0.0; if (emissive_brightness >= 1.0) { @@ -305,8 +305,8 @@ void main() final_normal = vec4(abnormal, ei, 0.0); #endif - color.rgb = final_color.rgb; - al = vertex_color.a; + color.rgb = final_color.rgb; + al = vertex_color.a; } vec4 final_specular = spec; @@ -320,143 +320,143 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - if (emissive_brightness < 1.0) - { - //forward rendering, output just lit RGBA - vec3 pos = vary_position; + if (emissive_brightness < 1.0) + { + //forward rendering, output just lit RGBA + vec3 pos = vary_position; - float shadow = 1.0f; + float shadow = 1.0f; #ifdef HAS_SUN_SHADOW - shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen); + shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen); #endif - spec = final_specular; + spec = final_specular; - float envIntensity = final_normal.z; + float envIntensity = final_normal.z; - vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - float bloom = 0.0; - vec3 sunlit; - vec3 amblit; - vec3 additive; - vec3 atten; + float bloom = 0.0; + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; - calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); + calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - float da = dot(norm.xyz, normalize(light_dir.xyz)); - float final_da = clamp(da, 0.0, 1.0); + float da = dot(norm.xyz, normalize(light_dir.xyz)); + float final_da = clamp(da, 0.0, 1.0); - float ambient = da; - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0 - ambient); + float ambient = da; + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0 - ambient); - vec3 sun_contrib = min(final_da, shadow) * sunlit; + vec3 sun_contrib = min(final_da, shadow) * sunlit; #if !defined(AMBIENT_KILL) - color.rgb = amblit; - color.rgb *= ambient; + color.rgb = amblit; + color.rgb *= ambient; #endif vec3 post_ambient = color.rgb; #if !defined(SUNLIGHT_KILL) - color.rgb += sun_contrib; + color.rgb += sun_contrib; #endif vec3 post_sunlight = color.rgb; - //color.rgb *= diffuse_srgb.rgb; - color.rgb *= diffuse_linear.rgb; // SL-12006 + //color.rgb *= diffuse_srgb.rgb; + color.rgb *= diffuse_linear.rgb; // SL-12006 vec3 post_diffuse = color.rgb; - float glare = 0.0; - - if (spec.a > 0.0) // specular reflection - { - 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 / 16.0f; - sp = clamp(sp, vec3(0), vec3(1)); - bloom = dot(sp, sp) / 6.0; - #if !defined(SUNLIGHT_KILL) - color += sp * spec.rgb; - #endif - } - } - - vec3 post_spec = color.rgb; - - if (envIntensity > 0.0) - { - //add environmentmap - vec3 env_vec = env_mat * refnormpersp; - - vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; - - #if !defined(SUNLIGHT_KILL) - color = mix(color.rgb, reflected_color, envIntensity); - #endif - float cur_glare = max(reflected_color.r, reflected_color.g); - cur_glare = max(cur_glare, reflected_color.b); - cur_glare *= envIntensity*4.0; - glare += cur_glare; - } + float glare = 0.0; + + if (spec.a > 0.0) // specular reflection + { + 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 / 16.0f; + sp = clamp(sp, vec3(0), vec3(1)); + bloom = dot(sp, sp) / 6.0; + #if !defined(SUNLIGHT_KILL) + color += sp * spec.rgb; + #endif + } + } + + vec3 post_spec = color.rgb; + + if (envIntensity > 0.0) + { + //add environmentmap + vec3 env_vec = env_mat * refnormpersp; + + vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; + + #if !defined(SUNLIGHT_KILL) + color = mix(color.rgb, reflected_color, envIntensity); + #endif + float cur_glare = max(reflected_color.r, reflected_color.g); + cur_glare = max(cur_glare, reflected_color.b); + cur_glare *= envIntensity*4.0; + glare += cur_glare; + } vec3 post_env = color.rgb; - color = atmosFragLighting(color, additive, atten); + color = atmosFragLighting(color, additive, atten); - //convert to linear space before adding local lights - color = srgb_to_linear(color); + //convert to linear space before adding local lights + color = srgb_to_linear(color); vec3 post_atmo = color.rgb; - vec3 npos = normalize(-pos.xyz); + vec3 npos = normalize(-pos.xyz); - vec3 light = vec3(0,0,0); + vec3 light = vec3(0,0,0); #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.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, glare, light_attenuation[i].w ); - LIGHT_LOOP(1) - LIGHT_LOOP(2) - LIGHT_LOOP(3) - LIGHT_LOOP(4) - LIGHT_LOOP(5) - LIGHT_LOOP(6) - LIGHT_LOOP(7) + LIGHT_LOOP(1) + LIGHT_LOOP(2) + LIGHT_LOOP(3) + LIGHT_LOOP(4) + LIGHT_LOOP(5) + LIGHT_LOOP(6) + LIGHT_LOOP(7) - glare = min(glare, 1.0); - al = max(diffuse_linear.a,glare)*vertex_color.a; + glare = min(glare, 1.0); + al = max(diffuse_linear.a,glare)*vertex_color.a; #if !defined(LOCAL_LIGHT_KILL) - color.rgb += light.rgb; + color.rgb += light.rgb; #endif - color = scaleSoftClipFrag(color); + color = scaleSoftClipFrag(color); - // (only) post-deferred needs inline gamma correction - color.rgb = linear_to_srgb(color.rgb); + // (only) post-deferred needs inline gamma correction + color.rgb = linear_to_srgb(color.rgb); //color.rgb = amblit; //color.rgb = vec3(ambient); @@ -472,11 +472,11 @@ vec3 post_atmo = color.rgb; //color.rgb = post_atmo; #ifdef WATER_FOG - vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); - color.rgb = temp.rgb; - al = temp.a; + vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); + color.rgb = temp.rgb; + al = temp.a; #endif - } // !fullbright + } // !fullbright frag_color.rgb = color.rgb; frag_color.a = al; -- cgit v1.2.3 From 090803733455a09c9763d16106ad055c2532e61d Mon Sep 17 00:00:00 2001 From: "Michael Pohoreski (Ptolemy Linden)" Date: Tue, 24 Dec 2019 01:37:40 +0000 Subject: Cleanup indentation and commented out debug color stage vectors --- .../shaders/class1/deferred/materialF.glsl | 253 +++++++++++---------- 1 file changed, 127 insertions(+), 126 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 72e61095f2..f4e041eb5c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -47,142 +47,142 @@ vec3 linear_to_srgb(vec3 cs); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - #ifdef DEFINE_GL_FRAGCOLOR - out vec4 frag_color; - #else - #define frag_color gl_FragColor - #endif +#ifdef DEFINE_GL_FRAGCOLOR + out vec4 frag_color; +#else + #define frag_color gl_FragColor +#endif - #ifdef HAS_SUN_SHADOW +#ifdef HAS_SUN_SHADOW float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); - #endif +#endif - uniform samplerCube environmentMap; - uniform sampler2D lightFunc; +uniform samplerCube environmentMap; +uniform sampler2D lightFunc; - // Inputs - uniform vec4 morphFactor; - uniform vec3 camPosLocal; - uniform mat3 env_mat; +// Inputs +uniform vec4 morphFactor; +uniform vec3 camPosLocal; +uniform mat3 env_mat; - uniform vec3 sun_dir; - uniform vec3 moon_dir; - VARYING vec2 vary_fragcoord; +uniform vec3 sun_dir; +uniform vec3 moon_dir; +VARYING vec2 vary_fragcoord; - VARYING vec3 vary_position; +VARYING vec3 vary_position; - uniform mat4 proj_mat; - uniform mat4 inv_proj; - uniform vec2 screen_res; +uniform mat4 proj_mat; +uniform mat4 inv_proj; +uniform vec2 screen_res; - uniform vec4 light_position[8]; - uniform vec3 light_direction[8]; - uniform vec4 light_attenuation[8]; - uniform vec3 light_diffuse[8]; +uniform vec4 light_position[8]; +uniform vec3 light_direction[8]; +uniform vec4 light_attenuation[8]; +uniform vec3 light_diffuse[8]; - float getAmbientClamp(); +float getAmbientClamp(); - 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) - { - vec3 col = vec3(0); +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) +{ + vec3 col = vec3(0); - //get light vector - vec3 lv = lp.xyz-v; + //get light vector + vec3 lv = lp.xyz-v; - //get distance - float dist = length(lv); - float da = 1.0; + //get distance + float dist = length(lv); + float da = 1.0; - dist /= la; + dist /= la; - /* clip to projector bounds - vec4 proj_tc = proj_mat * lp; + /* clip to projector bounds + vec4 proj_tc = proj_mat * lp; - if (proj_tc.z < 0 - || proj_tc.z > 1 - || proj_tc.x < 0 - || proj_tc.x > 1 - || proj_tc.y < 0 - || proj_tc.y > 1) - { - return col; - }*/ + if (proj_tc.z < 0 + || proj_tc.z > 1 + || proj_tc.x < 0 + || proj_tc.x > 1 + || proj_tc.y < 0 + || proj_tc.y > 1) + { + return col; + }*/ - if (dist > 0.0 && la > 0.0) + if (dist > 0.0 && la > 0.0) + { + //normalize light vector + lv = normalize(lv); + + //distance attenuation + float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); + dist_atten *= dist_atten; + dist_atten *= 2.0f; + + if (dist_atten <= 0.0) { - //normalize light vector - lv = normalize(lv); - - //distance attenuation - float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); - dist_atten *= dist_atten; - dist_atten *= 2.0f; - - if (dist_atten <= 0.0) - { - return col; - } + return col; + } - // spotlight coefficient. - float spot = max(dot(-ln, lv), is_pointlight); - da *= spot*spot; // GL_SPOT_EXPONENT=2 + // spotlight coefficient. + float spot = max(dot(-ln, lv), is_pointlight); + da *= spot*spot; // GL_SPOT_EXPONENT=2 - //angular attenuation - da *= dot(n, lv); + //angular attenuation + da *= dot(n, lv); - float lit = 0.0f; + float lit = 0.0f; - float amb_da = ambiance; - if (da >= 0) - { - lit = max(da * dist_atten,0.0); - col = lit * light_col * diffuse; - amb_da += (da*0.5+0.5) * ambiance; - } - amb_da += (da*da*0.5 + 0.5) * ambiance; - amb_da *= dist_atten; - amb_da = min(amb_da, 1.0f - lit); + float amb_da = ambiance; + if (da >= 0) + { + lit = max(da * dist_atten,0.0); + col = lit * light_col * diffuse; + amb_da += (da*0.5+0.5) * ambiance; + } + amb_da += (da*da*0.5 + 0.5) * ambiance; + amb_da *= dist_atten; + amb_da = min(amb_da, 1.0f - lit); + + // SL-10969 need to see why these are blown out + //col.rgb += amb_da * light_col * diffuse; - // SL-10969 need to see why these are blown out - //col.rgb += amb_da * light_col * diffuse; + if (spec.a > 0.0) + { + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(lv+npos); + float nh = dot(n, h); + float nv = dot(n, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - if (spec.a > 0.0) + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) { - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(lv+npos); - float nh = dot(n, h); - float nv = dot(n, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 speccol = 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); - } + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + 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); } } - - return max(col, vec3(0.0,0.0,0.0)); } - #else - #ifdef DEFINE_GL_FRAGCOLOR - out vec4 frag_data[3]; - #else - #define frag_data gl_FragData - #endif + return max(col, vec3(0.0,0.0,0.0)); +} + +#else +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_data[3]; +#else +#define frag_data gl_FragData +#endif #endif uniform sampler2D diffuseMap; @@ -358,23 +358,25 @@ void main() vec3 sun_contrib = min(final_da, shadow) * sunlit; +// vec3 debug_sun_contrib = sun_contrib; + #if !defined(AMBIENT_KILL) color.rgb = amblit; color.rgb *= ambient; #endif -vec3 post_ambient = color.rgb; +//vec3 debug_post_ambient = color.rgb; #if !defined(SUNLIGHT_KILL) color.rgb += sun_contrib; #endif -vec3 post_sunlight = color.rgb; +//vec3 debug_post_sunlight = color.rgb; //color.rgb *= diffuse_srgb.rgb; color.rgb *= diffuse_linear.rgb; // SL-12006 -vec3 post_diffuse = color.rgb; +//vec3 debug_post_diffuse = color.rgb; float glare = 0.0; @@ -399,13 +401,13 @@ vec3 post_diffuse = color.rgb; vec3 sp = sun_contrib*scol / 16.0f; sp = clamp(sp, vec3(0), vec3(1)); bloom = dot(sp, sp) / 6.0; - #if !defined(SUNLIGHT_KILL) +#if !defined(SUNLIGHT_KILL) color += sp * spec.rgb; - #endif +#endif } } - vec3 post_spec = color.rgb; +//vec3 debug_post_spec = color.rgb; if (envIntensity > 0.0) { @@ -414,23 +416,23 @@ vec3 post_diffuse = color.rgb; vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; - #if !defined(SUNLIGHT_KILL) +#if !defined(SUNLIGHT_KILL) color = mix(color.rgb, reflected_color, envIntensity); - #endif +#endif float cur_glare = max(reflected_color.r, reflected_color.g); cur_glare = max(cur_glare, reflected_color.b); cur_glare *= envIntensity*4.0; glare += cur_glare; } -vec3 post_env = color.rgb; +//vec3 debug_post_env = color.rgb; color = atmosFragLighting(color, additive, atten); //convert to linear space before adding local lights color = srgb_to_linear(color); -vec3 post_atmo = color.rgb; +//vec3 debug_post_atmo = color.rgb; vec3 npos = normalize(-pos.xyz); @@ -461,15 +463,15 @@ vec3 post_atmo = color.rgb; //color.rgb = amblit; //color.rgb = vec3(ambient); //color.rgb = sunlit; -//color.rgb = post_ambient; +//color.rgb = debug_post_ambient; //color.rgb = vec3(final_da); -//color.rgb = sun_contrib; -//color.rgb = post_sunlight; +//color.rgb = debug_sun_contrib; +//color.rgb = debug_post_sunlight; //color.rgb = diffuse_srgb.rgb; -//color.rgb = post_diffuse; -//color.rgb = post_spec; -//color.rgb = post_env; -//color.rgb = post_atmo; +//color.rgb = debug_post_diffuse; +//color.rgb = debug_post_spec; +//color.rgb = debug_post_env; +//color.rgb = debug_post_atmo; #ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); @@ -490,4 +492,3 @@ vec3 post_atmo = color.rgb; #endif } - -- cgit v1.2.3 From a471ddd0be09a7bd6815c09a98fc7acd87feac58 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 10 Jan 2020 17:26:54 -0800 Subject: SL-12171: Fix for SL-12006 that made non-emissive portions of textures too dim. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index f4e041eb5c..8ed5713e22 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -272,7 +272,7 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_EMISSIVE) final_color.a = diffuse_linear.a; - final_color.rgb *= 0.5; + final_color.rgb = mix( diffuse_linear.rgb, final_color.rgb*0.5, diffuse_tap.a ); // SL-12171: Fix emissive texture portion being twice as bright. #endif final_color.a = max(final_color.a, emissive_brightness); -- cgit v1.2.3 From 8545b81a32e1f8a7621ca7e136a5899545a5788b Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 24 Jan 2020 16:30:48 -0800 Subject: SL-11406: Fix specularity being blown out due to previous fix --- .../newview/app_settings/shaders/class1/deferred/materialF.glsl | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 8ed5713e22..8a6b2b7066 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -290,9 +290,7 @@ void main() // OR // adjust the final color via: // final_color *= 0.666666; - // We remap the environment intensity to closely simulate what non-EEP is doing. - // At midnight the brightness is exact. - // At midday the brightness is very close. + // We don't remap the environment intensity but adjust the final color to closely simulate what non-EEP is doing. vec4 final_normal = vec4(abnormal, env_intensity, 0.0); vec3 color = vec3(0.0); @@ -301,9 +299,8 @@ void main() if (emissive_brightness >= 1.0) { #ifdef HAS_SPECULAR_MAP - float ei = env_intensity*0.5 + 0.5; - final_normal = vec4(abnormal, ei, 0.0); - + // Note: We actually need to adjust all 4 channels not just .rgb + final_color *= 0.666666; #endif color.rgb = final_color.rgb; al = vertex_color.a; -- cgit v1.2.3 From 54bd5ed5fa6257508f9882455b49599dd84b76e8 Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Tue, 4 Feb 2020 17:45:04 -0700 Subject: SL-12592, fix transparency for full-brights --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 8a6b2b7066..80a2e16fb0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -317,7 +317,7 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - if (emissive_brightness < 1.0) + if (emissive_brightness <= 1.0) { //forward rendering, output just lit RGBA vec3 pos = vary_position; -- cgit v1.2.3 From 8e0d5f463edc24101ecdcb420c05f6d5b0e6b6c0 Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Thu, 6 Feb 2020 18:43:21 -0700 Subject: SL-12682, remove negative light & clean up materialF.glsl --- .../shaders/class1/deferred/materialF.glsl | 46 +++++++++++----------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 80a2e16fb0..d28fc128b6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -249,24 +249,25 @@ void main() vec4 spec = vec4(specular_color.rgb, 1.0); #endif - vec4 norm = vec4(0,0,0,1.0); - vec3 tnorm; + vec3 norm = vec3(0); + float bmap_specular = 1.0; #ifdef HAS_NORMAL_MAP - norm = texture2D(bumpMap, vary_texcoord1.xy); - norm.xyz = norm.xyz * 2 - 1; - - // tangent space norm - tnorm = vec3(dot(norm.xyz,vary_mat0), - dot(norm.xyz,vary_mat1), - dot(norm.xyz,vary_mat2)); + vec4 bump_sample = texture2D(bumpMap, vary_texcoord1.xy); + norm = (bump_sample.xyz * 2) - vec3(1); + bmap_specular = bump_sample.w; + + // convert sampled normal to tangent space normal + norm = vec3(dot(norm, vary_mat0), + dot(norm, vary_mat1), + dot(norm, vary_mat2)); #else - tnorm = vary_normal; + norm = vary_normal; #endif - norm.xyz = normalize(tnorm.xyz); + norm = normalize(norm); - vec2 abnormal = encode_normal(norm.xyz); + vec2 abnormal = encode_normal(norm); vec4 final_color = vec4(diffuse_linear.rgb, 0.0); @@ -311,7 +312,7 @@ void main() final_specular.a = specular_color.a; #ifdef HAS_SPECULAR_MAP - final_specular.a *= norm.a; + final_specular.a *= bmap_specular; final_normal.z *= spec.a; #endif @@ -325,7 +326,7 @@ void main() float shadow = 1.0f; #ifdef HAS_SUN_SHADOW - shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen); + shadow = sampleDirectionalShadow(pos.xyz, norm, pos_screen); #endif spec = final_specular; @@ -342,18 +343,17 @@ void main() calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - + vec3 refnormpersp = normalize(reflect(pos.xyz, norm)); - float da = dot(norm.xyz, normalize(light_dir.xyz)); - float final_da = clamp(da, 0.0, 1.0); + float da = dot(norm, normalize(light_dir)); + da = clamp(da, 0.0, 1.0); // No negative light contributions float ambient = da; ambient *= 0.5; ambient *= ambient; ambient = (1.0 - ambient); - vec3 sun_contrib = min(final_da, shadow) * sunlit; + vec3 sun_contrib = min(da, shadow) * sunlit; // vec3 debug_sun_contrib = sun_contrib; @@ -383,8 +383,8 @@ void main() //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 nh = dot(norm, h); + float nv = dot(norm, npos); float vh = dot(npos, h); float sa = nh; float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; @@ -435,7 +435,7 @@ void main() vec3 light = vec3(0,0,0); -#define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.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, glare, light_attenuation[i].w ); +#define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.rgb, final_specular, pos.xyz, norm, 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) @@ -461,7 +461,7 @@ void main() //color.rgb = vec3(ambient); //color.rgb = sunlit; //color.rgb = debug_post_ambient; -//color.rgb = vec3(final_da); +//color.rgb = vec3(da); //color.rgb = debug_sun_contrib; //color.rgb = debug_post_sunlight; //color.rgb = diffuse_srgb.rgb; -- cgit v1.2.3 From 2ea507526921b68cb5f9929be1a7693203fe608e Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Tue, 25 Feb 2020 08:05:24 -0700 Subject: SL-12638, fix overly dark appearance of normal-mapped objects Adds the 'additive' component of calcAtmosphericVars into the sunlit color to reduce darkening of sun lighting component, and adds a further magic number gainto boost final result to rough parity with windlight. Removes all light calculations on fullbright objects, just passing through the unlit diffuse color. --- .../shaders/class1/deferred/materialF.glsl | 73 ++++++---------------- 1 file changed, 19 insertions(+), 54 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index d28fc128b6..2df683a5fd 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -95,19 +95,6 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe dist /= la; - /* clip to projector bounds - vec4 proj_tc = proj_mat * lp; - - if (proj_tc.z < 0 - || proj_tc.z > 1 - || proj_tc.x < 0 - || proj_tc.x > 1 - || proj_tc.y < 0 - || proj_tc.y > 1) - { - return col; - }*/ - if (dist > 0.0 && la > 0.0) { //normalize light vector @@ -252,7 +239,11 @@ void main() vec3 norm = vec3(0); float bmap_specular = 1.0; + // Non-physical gain, sole purpose to make EEP viewer better match windlight when normal-mapped. + float eep_bump_gain = 1.0; + #ifdef HAS_NORMAL_MAP + eep_bump_gain = 1.75; vec4 bump_sample = texture2D(bumpMap, vary_texcoord1.xy); norm = (bump_sample.xyz * 2) - vec3(1); bmap_specular = bump_sample.w; @@ -295,7 +286,7 @@ void main() vec4 final_normal = vec4(abnormal, env_intensity, 0.0); vec3 color = vec3(0.0); - float al = 0.0; + float al = 1.0; if (emissive_brightness >= 1.0) { @@ -318,7 +309,12 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - if (emissive_brightness <= 1.0) + if (emissive_brightness >= 1.0) + { + // fullbright = diffuse texture pass-through, no lighting + frag_color = diffuse_srgb; + } + else { //forward rendering, output just lit RGBA vec3 pos = vary_position; @@ -348,40 +344,28 @@ void main() float da = dot(norm, normalize(light_dir)); da = clamp(da, 0.0, 1.0); // No negative light contributions - float ambient = da; - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0 - ambient); - - vec3 sun_contrib = min(da, shadow) * sunlit; + // ambient weight varies from 0.75 at max direct light to 1.0 with sun at grazing angle + float ambient = 1.0 - (0.25 * da * da); -// vec3 debug_sun_contrib = sun_contrib; + vec3 sun_contrib = additive + (min(da, shadow) * sunlit); #if !defined(AMBIENT_KILL) color.rgb = amblit; color.rgb *= ambient; #endif -//vec3 debug_post_ambient = color.rgb; - #if !defined(SUNLIGHT_KILL) - color.rgb += sun_contrib; + color.rgb += eep_bump_gain * sun_contrib; #endif -//vec3 debug_post_sunlight = color.rgb; - - //color.rgb *= diffuse_srgb.rgb; color.rgb *= diffuse_linear.rgb; // SL-12006 -//vec3 debug_post_diffuse = color.rgb; - float glare = 0.0; if (spec.a > 0.0) // specular reflection { vec3 npos = -normalize(pos.xyz); - //vec3 ref = dot(pos+lv, norm); vec3 h = normalize(light_dir.xyz+npos); float nh = dot(norm, h); float nv = dot(norm, npos); @@ -404,8 +388,6 @@ void main() } } -//vec3 debug_post_spec = color.rgb; - if (envIntensity > 0.0) { //add environmentmap @@ -422,15 +404,11 @@ void main() glare += cur_glare; } -//vec3 debug_post_env = color.rgb; - color = atmosFragLighting(color, additive, atten); //convert to linear space before adding local lights color = srgb_to_linear(color); -//vec3 debug_post_atmo = color.rgb; - vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0,0,0); @@ -453,32 +431,19 @@ void main() #endif color = scaleSoftClipFrag(color); - + // (only) post-deferred needs inline gamma correction color.rgb = linear_to_srgb(color.rgb); -//color.rgb = amblit; -//color.rgb = vec3(ambient); -//color.rgb = sunlit; -//color.rgb = debug_post_ambient; -//color.rgb = vec3(da); -//color.rgb = debug_sun_contrib; -//color.rgb = debug_post_sunlight; -//color.rgb = diffuse_srgb.rgb; -//color.rgb = debug_post_diffuse; -//color.rgb = debug_post_spec; -//color.rgb = debug_post_env; -//color.rgb = debug_post_atmo; - #ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); color.rgb = temp.rgb; al = temp.a; #endif - } // !fullbright - frag_color.rgb = color.rgb; - frag_color.a = al; + frag_color.rgb = color.rgb; + frag_color.a = al; + } #else // if DIFFUSE_ALPHA_MODE_BLEND ... -- cgit v1.2.3 From 823d8bce6034eaa748b65dfec3618d1283f1ec9d Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Thu, 27 Feb 2020 11:48:04 -0700 Subject: SL-12638, further tweaking of normal-map lighting, add some de-saturation --- .../app_settings/shaders/class1/deferred/materialF.glsl | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 2df683a5fd..eebb0a5fe5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -164,6 +164,14 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe return max(col, vec3(0.0,0.0,0.0)); } +// Q&D approximate RGB-space de-saturation, strength from 0 (no effect) to 1.0 (complete grey-scale) +vec3 desat(vec3 color, float strength) +{ + float primary_value = max(color.r, max(color.g, color.b)); + vec3 delta = strength * (vec3(primary_value)-color); + return color + delta; +} + #else #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; @@ -355,11 +363,15 @@ void main() #endif #if !defined(SUNLIGHT_KILL) - color.rgb += eep_bump_gain * sun_contrib; + color.rgb += sun_contrib; #endif color.rgb *= diffuse_linear.rgb; // SL-12006 + // ad-hoc brighten and de-saturate (normal-mapped only), to match windlight - SL-12638 + color.rgb = desat(color.rgb, 0.33 * (eep_bump_gain - 1.0)); + color.rgb *= eep_bump_gain; + float glare = 0.0; if (spec.a > 0.0) // specular reflection -- cgit v1.2.3 From 8c2b7e0e83566e9a27a65856d5ae7fbe3558422f Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Tue, 3 Mar 2020 16:39:17 -0700 Subject: Revert 2 merges (PR#13, PR#16) related to SL-12638 This reverts commits 9d9b890 and 5f846e4. --- .../shaders/class1/deferred/materialF.glsl | 81 ++++++++++++++-------- 1 file changed, 52 insertions(+), 29 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index eebb0a5fe5..d28fc128b6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -95,6 +95,19 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe dist /= la; + /* clip to projector bounds + vec4 proj_tc = proj_mat * lp; + + if (proj_tc.z < 0 + || proj_tc.z > 1 + || proj_tc.x < 0 + || proj_tc.x > 1 + || proj_tc.y < 0 + || proj_tc.y > 1) + { + return col; + }*/ + if (dist > 0.0 && la > 0.0) { //normalize light vector @@ -164,14 +177,6 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe return max(col, vec3(0.0,0.0,0.0)); } -// Q&D approximate RGB-space de-saturation, strength from 0 (no effect) to 1.0 (complete grey-scale) -vec3 desat(vec3 color, float strength) -{ - float primary_value = max(color.r, max(color.g, color.b)); - vec3 delta = strength * (vec3(primary_value)-color); - return color + delta; -} - #else #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; @@ -247,11 +252,7 @@ void main() vec3 norm = vec3(0); float bmap_specular = 1.0; - // Non-physical gain, sole purpose to make EEP viewer better match windlight when normal-mapped. - float eep_bump_gain = 1.0; - #ifdef HAS_NORMAL_MAP - eep_bump_gain = 1.75; vec4 bump_sample = texture2D(bumpMap, vary_texcoord1.xy); norm = (bump_sample.xyz * 2) - vec3(1); bmap_specular = bump_sample.w; @@ -294,7 +295,7 @@ void main() vec4 final_normal = vec4(abnormal, env_intensity, 0.0); vec3 color = vec3(0.0); - float al = 1.0; + float al = 0.0; if (emissive_brightness >= 1.0) { @@ -317,12 +318,7 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - if (emissive_brightness >= 1.0) - { - // fullbright = diffuse texture pass-through, no lighting - frag_color = diffuse_srgb; - } - else + if (emissive_brightness <= 1.0) { //forward rendering, output just lit RGBA vec3 pos = vary_position; @@ -352,25 +348,32 @@ void main() float da = dot(norm, normalize(light_dir)); da = clamp(da, 0.0, 1.0); // No negative light contributions - // ambient weight varies from 0.75 at max direct light to 1.0 with sun at grazing angle - float ambient = 1.0 - (0.25 * da * da); + float ambient = da; + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0 - ambient); + + vec3 sun_contrib = min(da, shadow) * sunlit; - vec3 sun_contrib = additive + (min(da, shadow) * sunlit); +// vec3 debug_sun_contrib = sun_contrib; #if !defined(AMBIENT_KILL) color.rgb = amblit; color.rgb *= ambient; #endif +//vec3 debug_post_ambient = color.rgb; + #if !defined(SUNLIGHT_KILL) color.rgb += sun_contrib; #endif +//vec3 debug_post_sunlight = color.rgb; + + //color.rgb *= diffuse_srgb.rgb; color.rgb *= diffuse_linear.rgb; // SL-12006 - // ad-hoc brighten and de-saturate (normal-mapped only), to match windlight - SL-12638 - color.rgb = desat(color.rgb, 0.33 * (eep_bump_gain - 1.0)); - color.rgb *= eep_bump_gain; +//vec3 debug_post_diffuse = color.rgb; float glare = 0.0; @@ -378,6 +381,7 @@ void main() { vec3 npos = -normalize(pos.xyz); + //vec3 ref = dot(pos+lv, norm); vec3 h = normalize(light_dir.xyz+npos); float nh = dot(norm, h); float nv = dot(norm, npos); @@ -400,6 +404,8 @@ void main() } } +//vec3 debug_post_spec = color.rgb; + if (envIntensity > 0.0) { //add environmentmap @@ -416,11 +422,15 @@ void main() glare += cur_glare; } +//vec3 debug_post_env = color.rgb; + color = atmosFragLighting(color, additive, atten); //convert to linear space before adding local lights color = srgb_to_linear(color); +//vec3 debug_post_atmo = color.rgb; + vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0,0,0); @@ -443,19 +453,32 @@ void main() #endif color = scaleSoftClipFrag(color); - + // (only) post-deferred needs inline gamma correction color.rgb = linear_to_srgb(color.rgb); +//color.rgb = amblit; +//color.rgb = vec3(ambient); +//color.rgb = sunlit; +//color.rgb = debug_post_ambient; +//color.rgb = vec3(da); +//color.rgb = debug_sun_contrib; +//color.rgb = debug_post_sunlight; +//color.rgb = diffuse_srgb.rgb; +//color.rgb = debug_post_diffuse; +//color.rgb = debug_post_spec; +//color.rgb = debug_post_env; +//color.rgb = debug_post_atmo; + #ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); color.rgb = temp.rgb; al = temp.a; #endif + } // !fullbright - frag_color.rgb = color.rgb; - frag_color.a = al; - } + frag_color.rgb = color.rgb; + frag_color.a = al; #else // if DIFFUSE_ALPHA_MODE_BLEND ... -- cgit v1.2.3 From 1ba0df9abe26a18f2c870210be9b8fe6a1c72699 Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Tue, 3 Mar 2020 17:13:46 -0700 Subject: Roll back SL-12006 commits to materialF.glsl (Dec23) --- .../shaders/class1/deferred/materialF.glsl | 69 ++++------------------ 1 file changed, 11 insertions(+), 58 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index d28fc128b6..0829968dd1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -95,19 +95,6 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe dist /= la; - /* clip to projector bounds - vec4 proj_tc = proj_mat * lp; - - if (proj_tc.z < 0 - || proj_tc.z > 1 - || proj_tc.x < 0 - || proj_tc.x > 1 - || proj_tc.y < 0 - || proj_tc.y > 1) - { - return col; - }*/ - if (dist > 0.0 && la > 0.0) { //normalize light vector @@ -273,7 +260,6 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_EMISSIVE) final_color.a = diffuse_linear.a; - final_color.rgb = mix( diffuse_linear.rgb, final_color.rgb*0.5, diffuse_tap.a ); // SL-12171: Fix emissive texture portion being twice as bright. #endif final_color.a = max(final_color.a, emissive_brightness); @@ -295,17 +281,15 @@ void main() vec4 final_normal = vec4(abnormal, env_intensity, 0.0); vec3 color = vec3(0.0); - float al = 0.0; + float al = 0; +#ifdef HAS_SPECULAR_MAP if (emissive_brightness >= 1.0) { -#ifdef HAS_SPECULAR_MAP - // Note: We actually need to adjust all 4 channels not just .rgb - final_color *= 0.666666; -#endif - color.rgb = final_color.rgb; - al = vertex_color.a; + float ei = env_intensity*0.5 + 0.5; + final_normal = vec4(abnormal, ei, 0.0); } +#endif vec4 final_specular = spec; @@ -318,7 +302,6 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - if (emissive_brightness <= 1.0) { //forward rendering, output just lit RGBA vec3 pos = vary_position; @@ -348,33 +331,22 @@ void main() float da = dot(norm, normalize(light_dir)); da = clamp(da, 0.0, 1.0); // No negative light contributions - float ambient = da; - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0 - ambient); + // ambient weight varies from 0.75 at max direct light to 1.0 with sun at grazing angle + float ambient = 1.0 - (0.25 * da * da); vec3 sun_contrib = min(da, shadow) * sunlit; -// vec3 debug_sun_contrib = sun_contrib; - #if !defined(AMBIENT_KILL) color.rgb = amblit; color.rgb *= ambient; #endif -//vec3 debug_post_ambient = color.rgb; - #if !defined(SUNLIGHT_KILL) color.rgb += sun_contrib; #endif -//vec3 debug_post_sunlight = color.rgb; - - //color.rgb *= diffuse_srgb.rgb; - color.rgb *= diffuse_linear.rgb; // SL-12006 - -//vec3 debug_post_diffuse = color.rgb; - + color.rgb *= diffuse_srgb.rgb; + float glare = 0.0; if (spec.a > 0.0) // specular reflection @@ -404,8 +376,6 @@ void main() } } -//vec3 debug_post_spec = color.rgb; - if (envIntensity > 0.0) { //add environmentmap @@ -422,15 +392,11 @@ void main() glare += cur_glare; } -//vec3 debug_post_env = color.rgb; - color = atmosFragLighting(color, additive, atten); //convert to linear space before adding local lights color = srgb_to_linear(color); -//vec3 debug_post_atmo = color.rgb; - vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0,0,0); @@ -457,30 +423,17 @@ void main() // (only) post-deferred needs inline gamma correction color.rgb = linear_to_srgb(color.rgb); -//color.rgb = amblit; -//color.rgb = vec3(ambient); -//color.rgb = sunlit; -//color.rgb = debug_post_ambient; -//color.rgb = vec3(da); -//color.rgb = debug_sun_contrib; -//color.rgb = debug_post_sunlight; -//color.rgb = diffuse_srgb.rgb; -//color.rgb = debug_post_diffuse; -//color.rgb = debug_post_spec; -//color.rgb = debug_post_env; -//color.rgb = debug_post_atmo; - #ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); color.rgb = temp.rgb; al = temp.a; #endif - } // !fullbright + } frag_color.rgb = color.rgb; frag_color.a = al; -#else // if DIFFUSE_ALPHA_MODE_BLEND ... +#else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer // deferred path frag_data[0] = final_color; -- cgit v1.2.3 From cc5044bce06598aab9f405bba745f0e8209fc5ce Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Wed, 4 Mar 2020 15:56:02 -0600 Subject: WIP - fix various inconsistencies in sRGB vs linear color space. Fix inconsistencies between softenLightF.glsl, materialF.glsl, and alphaF.glsl --- .../shaders/class1/deferred/materialF.glsl | 70 +++++++++++----------- 1 file changed, 34 insertions(+), 36 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index eebb0a5fe5..c6ba489d52 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -25,6 +25,10 @@ /*[EXTRA_CODE_HERE]*/ +//class1/deferred/materialF.glsl + +// This shader is used for both writing opaque/masked content to the gbuffer and writing blended content to the framebuffer during the alpha pass. + #define DIFFUSE_ALPHA_MODE_NONE 0 #define DIFFUSE_ALPHA_MODE_BLEND 1 #define DIFFUSE_ALPHA_MODE_MASK 2 @@ -180,7 +184,7 @@ out vec4 frag_data[3]; #endif #endif -uniform sampler2D diffuseMap; +uniform sampler2D diffuseMap; //always in sRGB space #ifdef HAS_NORMAL_MAP uniform sampler2D bumpMap; @@ -218,14 +222,16 @@ void main() vec2 pos_screen = vary_texcoord0.xy; vec4 diffuse_tap = texture2D(diffuseMap, vary_texcoord0.xy); + diffuse_tap.rgb *= vertex_color.rgb; + //diffuse_tap = vec4(1,1,1,1); -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) +//#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) vec4 diffuse_srgb = diffuse_tap; vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); -#else +/*#else vec4 diffuse_linear = diffuse_tap; vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_linear.a); -#endif +#endif*/ #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) if (diffuse_linear.a < minimum_alpha) @@ -234,9 +240,6 @@ void main() } #endif - diffuse_linear.rgb *= vertex_color.rgb; - diffuse_srgb.rgb *= linear_to_srgb(vertex_color.rgb); - #ifdef HAS_SPECULAR_MAP vec4 spec = texture2D(specularMap, vary_texcoord2.xy); spec.rgb *= specular_color.rgb; @@ -298,10 +301,10 @@ void main() if (emissive_brightness >= 1.0) { -#ifdef HAS_SPECULAR_MAP +/*#ifdef HAS_SPECULAR_MAP // Note: We actually need to adjust all 4 channels not just .rgb final_color *= 0.666666; -#endif +#endif*/ color.rgb = final_color.rgb; al = vertex_color.a; } @@ -320,11 +323,12 @@ void main() if (emissive_brightness >= 1.0) { // fullbright = diffuse texture pass-through, no lighting - frag_color = diffuse_srgb; + color = diffuse_linear.rgb; + al = diffuse_linear.a; } else { - //forward rendering, output just lit RGBA + //forward rendering, output just lit sRGBA vec3 pos = vary_position; float shadow = 1.0f; @@ -349,13 +353,14 @@ void main() vec3 refnormpersp = normalize(reflect(pos.xyz, norm)); - float da = dot(norm, normalize(light_dir)); - da = clamp(da, 0.0, 1.0); // No negative light contributions + float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0); - // ambient weight varies from 0.75 at max direct light to 1.0 with sun at grazing angle - float ambient = 1.0 - (0.25 * da * da); + float ambient = da; + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0 - ambient); - vec3 sun_contrib = additive + (min(da, shadow) * sunlit); + vec3 sun_contrib = da * sunlit; #if !defined(AMBIENT_KILL) color.rgb = amblit; @@ -367,11 +372,7 @@ void main() #endif color.rgb *= diffuse_linear.rgb; // SL-12006 - - // ad-hoc brighten and de-saturate (normal-mapped only), to match windlight - SL-12638 - color.rgb = desat(color.rgb, 0.33 * (eep_bump_gain - 1.0)); - color.rgb *= eep_bump_gain; - + float glare = 0.0; if (spec.a > 0.0) // specular reflection @@ -391,9 +392,9 @@ void main() if (nh > 0.0) { float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 sp = sun_contrib*scol / 16.0f; + vec3 sp = sun_contrib*scol / 6.0f; sp = clamp(sp, vec3(0), vec3(1)); - bloom = dot(sp, sp) / 6.0; + bloom = dot(sp, sp) / 4.0; #if !defined(SUNLIGHT_KILL) color += sp * spec.rgb; #endif @@ -418,9 +419,6 @@ void main() color = atmosFragLighting(color, additive, atten); - //convert to linear space before adding local lights - color = srgb_to_linear(color); - vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0,0,0); @@ -444,23 +442,23 @@ void main() color = scaleSoftClipFrag(color); - // (only) post-deferred needs inline gamma correction - color.rgb = linear_to_srgb(color.rgb); - -#ifdef WATER_FOG +/*#ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); color.rgb = temp.rgb; al = temp.a; -#endif - - frag_color.rgb = color.rgb; - frag_color.a = al; +#endif*/ } -#else // if DIFFUSE_ALPHA_MODE_BLEND ... + // (only) post-deferred needs inline gamma correction + color.rgb = linear_to_srgb(color.rgb); + + frag_color = vec4(color, al); + +#else // if DIFFUSE_ALPHA_MODE_BLEND ... + // deferred path - frag_data[0] = final_color; + frag_data[0] = vec4(linear_to_srgb(final_color.rgb), final_color.a); //gbuffer is sRGB frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. #endif -- cgit v1.2.3 From 265cefd2621a7d29e322ac903835bceb365f4f0a Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Wed, 4 Mar 2020 16:38:37 -0600 Subject: Merge fix --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 57e30c0ef3..ffd9dfed8c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -349,7 +349,7 @@ void main() color.rgb += sun_contrib; #endif - color.rgb *= diffuse_srgb.rgb; + color.rgb *= diffuse_linear.rgb; float glare = 0.0; -- cgit v1.2.3 From ca5cc79dfbc55a2160212f213a1a622691b7f02e Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Wed, 4 Mar 2020 16:43:18 -0600 Subject: Fix line endings? --- .../shaders/class1/deferred/materialF.glsl | 888 ++++++++++----------- 1 file changed, 444 insertions(+), 444 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index ffd9dfed8c..586ce4a9b7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -1,444 +1,444 @@ -/** - * @file materialF.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -/*[EXTRA_CODE_HERE]*/ - -//class1/deferred/materialF.glsl - -// This shader is used for both writing opaque/masked content to the gbuffer and writing blended content to the framebuffer during the alpha pass. - -#define DIFFUSE_ALPHA_MODE_NONE 0 -#define DIFFUSE_ALPHA_MODE_BLEND 1 -#define DIFFUSE_ALPHA_MODE_MASK 2 -#define DIFFUSE_ALPHA_MODE_EMISSIVE 3 - -uniform float emissive_brightness; -uniform int sun_up_factor; - -#ifdef WATER_FOG -vec4 applyWaterFogView(vec3 pos, vec4 color); -#endif - -vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); -vec3 scaleSoftClipFrag(vec3 l); - -void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); - -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cs); - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - -#ifdef DEFINE_GL_FRAGCOLOR - out vec4 frag_color; -#else - #define frag_color gl_FragColor -#endif - -#ifdef HAS_SUN_SHADOW - float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); -#endif - -uniform samplerCube environmentMap; -uniform sampler2D lightFunc; - -// Inputs -uniform vec4 morphFactor; -uniform vec3 camPosLocal; -uniform mat3 env_mat; - -uniform vec3 sun_dir; -uniform vec3 moon_dir; -VARYING vec2 vary_fragcoord; - -VARYING vec3 vary_position; - -uniform mat4 proj_mat; -uniform mat4 inv_proj; -uniform vec2 screen_res; - -uniform vec4 light_position[8]; -uniform vec3 light_direction[8]; -uniform vec4 light_attenuation[8]; -uniform vec3 light_diffuse[8]; - -float getAmbientClamp(); - -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) -{ - vec3 col = vec3(0); - - //get light vector - vec3 lv = lp.xyz-v; - - //get distance - float dist = length(lv); - float da = 1.0; - - dist /= la; - - if (dist > 0.0 && la > 0.0) - { - //normalize light vector - lv = normalize(lv); - - //distance attenuation - float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); - dist_atten *= dist_atten; - dist_atten *= 2.0f; - - if (dist_atten <= 0.0) - { - return col; - } - - // spotlight coefficient. - float spot = max(dot(-ln, lv), is_pointlight); - da *= spot*spot; // GL_SPOT_EXPONENT=2 - - //angular attenuation - da *= dot(n, lv); - - float lit = 0.0f; - - float amb_da = ambiance; - if (da >= 0) - { - lit = max(da * dist_atten,0.0); - col = lit * light_col * diffuse; - amb_da += (da*0.5+0.5) * ambiance; - } - amb_da += (da*da*0.5 + 0.5) * ambiance; - amb_da *= dist_atten; - amb_da = min(amb_da, 1.0f - lit); - - // SL-10969 need to see why these are blown out - //col.rgb += amb_da * light_col * diffuse; - - if (spec.a > 0.0) - { - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(lv+npos); - float nh = dot(n, h); - float nv = dot(n, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 speccol = 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); - } - } - } - - return max(col, vec3(0.0,0.0,0.0)); -} - -#else -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif -#endif - -uniform sampler2D diffuseMap; //always in sRGB space - -#ifdef HAS_NORMAL_MAP -uniform sampler2D bumpMap; -#endif - -#ifdef HAS_SPECULAR_MAP -uniform sampler2D specularMap; - -VARYING vec2 vary_texcoord2; -#endif - -uniform float env_intensity; -uniform vec4 specular_color; // specular color RGB and specular exponent (glossiness) in alpha - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) -uniform float minimum_alpha; -#endif - -#ifdef HAS_NORMAL_MAP -VARYING vec3 vary_mat0; -VARYING vec3 vary_mat1; -VARYING vec3 vary_mat2; -VARYING vec2 vary_texcoord1; -#else -VARYING vec3 vary_normal; -#endif - -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; - -vec2 encode_normal(vec3 n); - -void main() -{ - vec2 pos_screen = vary_texcoord0.xy; - - vec4 diffuse_tap = texture2D(diffuseMap, vary_texcoord0.xy); - diffuse_tap.rgb *= vertex_color.rgb; - //diffuse_tap = vec4(1,1,1,1); - -//#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - vec4 diffuse_srgb = diffuse_tap; - vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); -/*#else - vec4 diffuse_linear = diffuse_tap; - vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_linear.a); -#endif*/ - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) - if (diffuse_linear.a < minimum_alpha) - { - 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); -#endif - - vec3 norm = vec3(0); - float bmap_specular = 1.0; - -#ifdef HAS_NORMAL_MAP - vec4 bump_sample = texture2D(bumpMap, vary_texcoord1.xy); - norm = (bump_sample.xyz * 2) - vec3(1); - bmap_specular = bump_sample.w; - - // convert sampled normal to tangent space normal - norm = vec3(dot(norm, vary_mat0), - dot(norm, vary_mat1), - dot(norm, vary_mat2)); -#else - norm = vary_normal; -#endif - - norm = normalize(norm); - - vec2 abnormal = encode_normal(norm); - - vec4 final_color = vec4(diffuse_linear.rgb, 0.0); - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_EMISSIVE) - final_color.a = diffuse_linear.a; -#endif - - final_color.a = max(final_color.a, emissive_brightness); - - // Texture - // [x] Full Bright (emissive_brightness >= 1.0) - // Shininess (specular) - // [X] Texture - // Environment Intensity = 1 - // NOTE: There are two shaders that are used depending on the EI byte value: - // EI = 0 fullbright - // EI > 0 .. 255 material - // When it is passed to us it is normalized. - // We can either modify the output environment intensity - // OR - // adjust the final color via: - // final_color *= 0.666666; - // We don't remap the environment intensity but adjust the final color to closely simulate what non-EEP is doing. - vec4 final_normal = vec4(abnormal, env_intensity, 0.0); - - vec3 color = vec3(0.0); - float al = 0; - -#ifdef HAS_SPECULAR_MAP - if (emissive_brightness >= 1.0) - { - float ei = env_intensity*0.5 + 0.5; - final_normal = vec4(abnormal, ei, 0.0); - } -#endif - - vec4 final_specular = spec; - - final_specular.a = specular_color.a; - -#ifdef HAS_SPECULAR_MAP - final_specular.a *= bmap_specular; - final_normal.z *= spec.a; -#endif - - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - { - //forward rendering, output just lit sRGBA - vec3 pos = vary_position; - - float shadow = 1.0f; - -#ifdef HAS_SUN_SHADOW - shadow = sampleDirectionalShadow(pos.xyz, norm, pos_screen); -#endif - - spec = final_specular; - - float envIntensity = final_normal.z; - - vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - - float bloom = 0.0; - vec3 sunlit; - vec3 amblit; - vec3 additive; - vec3 atten; - - calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); - - vec3 refnormpersp = normalize(reflect(pos.xyz, norm)); - - float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0); - - float ambient = da; - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0 - ambient); - - vec3 sun_contrib = min(da, shadow) * sunlit; - -#if !defined(AMBIENT_KILL) - color.rgb = amblit; - color.rgb *= ambient; -#endif - -#if !defined(SUNLIGHT_KILL) - color.rgb += sun_contrib; -#endif - - color.rgb *= diffuse_linear.rgb; - - float glare = 0.0; - - if (spec.a > 0.0) // specular reflection - { - vec3 npos = -normalize(pos.xyz); - - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(light_dir.xyz+npos); - float nh = dot(norm, h); - float nv = dot(norm, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 sp = sun_contrib*scol / 6.0f; - sp = clamp(sp, vec3(0), vec3(1)); - bloom = dot(sp, sp) / 4.0; -#if !defined(SUNLIGHT_KILL) - color += sp * spec.rgb; -#endif - } - } - - if (envIntensity > 0.0) - { - //add environmentmap - vec3 env_vec = env_mat * refnormpersp; - - vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; - -#if !defined(SUNLIGHT_KILL) - color = mix(color.rgb, reflected_color, envIntensity); -#endif - float cur_glare = max(reflected_color.r, reflected_color.g); - cur_glare = max(cur_glare, reflected_color.b); - cur_glare *= envIntensity*4.0; - glare += cur_glare; - } - - color = atmosFragLighting(color, additive, atten); - - vec3 npos = normalize(-pos.xyz); - - vec3 light = vec3(0,0,0); - -#define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.rgb, final_specular, pos.xyz, norm, 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) - LIGHT_LOOP(3) - LIGHT_LOOP(4) - LIGHT_LOOP(5) - LIGHT_LOOP(6) - LIGHT_LOOP(7) - - glare = min(glare, 1.0); - al = max(diffuse_linear.a,glare)*vertex_color.a; - -#if !defined(LOCAL_LIGHT_KILL) - color.rgb += light.rgb; -#endif - - color = scaleSoftClipFrag(color); - -/*#ifdef WATER_FOG - vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); - color.rgb = temp.rgb; - al = temp.a; -#endif*/ - } - - - color.rgb = linear_to_srgb(color.rgb); - - frag_color = vec4(color, al); - -#else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer - - // deferred path - frag_data[0] = vec4(linear_to_srgb(final_color.rgb), final_color.a); //gbuffer is sRGB - frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. - frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. -#endif -} - +/** + * @file materialF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +/*[EXTRA_CODE_HERE]*/ + +//class1/deferred/materialF.glsl + +// This shader is used for both writing opaque/masked content to the gbuffer and writing blended content to the framebuffer during the alpha pass. + +#define DIFFUSE_ALPHA_MODE_NONE 0 +#define DIFFUSE_ALPHA_MODE_BLEND 1 +#define DIFFUSE_ALPHA_MODE_MASK 2 +#define DIFFUSE_ALPHA_MODE_EMISSIVE 3 + +uniform float emissive_brightness; +uniform int sun_up_factor; + +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 color); +#endif + +vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); +vec3 scaleSoftClipFrag(vec3 l); + +void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); + +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cs); + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + +#ifdef DEFINE_GL_FRAGCOLOR + out vec4 frag_color; +#else + #define frag_color gl_FragColor +#endif + +#ifdef HAS_SUN_SHADOW + float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); +#endif + +uniform samplerCube environmentMap; +uniform sampler2D lightFunc; + +// Inputs +uniform vec4 morphFactor; +uniform vec3 camPosLocal; +uniform mat3 env_mat; + +uniform vec3 sun_dir; +uniform vec3 moon_dir; +VARYING vec2 vary_fragcoord; + +VARYING vec3 vary_position; + +uniform mat4 proj_mat; +uniform mat4 inv_proj; +uniform vec2 screen_res; + +uniform vec4 light_position[8]; +uniform vec3 light_direction[8]; +uniform vec4 light_attenuation[8]; +uniform vec3 light_diffuse[8]; + +float getAmbientClamp(); + +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) +{ + vec3 col = vec3(0); + + //get light vector + vec3 lv = lp.xyz-v; + + //get distance + float dist = length(lv); + float da = 1.0; + + dist /= la; + + if (dist > 0.0 && la > 0.0) + { + //normalize light vector + lv = normalize(lv); + + //distance attenuation + float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); + dist_atten *= dist_atten; + dist_atten *= 2.0f; + + if (dist_atten <= 0.0) + { + return col; + } + + // spotlight coefficient. + float spot = max(dot(-ln, lv), is_pointlight); + da *= spot*spot; // GL_SPOT_EXPONENT=2 + + //angular attenuation + da *= dot(n, lv); + + float lit = 0.0f; + + float amb_da = ambiance; + if (da >= 0) + { + lit = max(da * dist_atten,0.0); + col = lit * light_col * diffuse; + amb_da += (da*0.5+0.5) * ambiance; + } + amb_da += (da*da*0.5 + 0.5) * ambiance; + amb_da *= dist_atten; + amb_da = min(amb_da, 1.0f - lit); + + // SL-10969 need to see why these are blown out + //col.rgb += amb_da * light_col * diffuse; + + if (spec.a > 0.0) + { + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(lv+npos); + float nh = dot(n, h); + float nv = dot(n, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + vec3 speccol = 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); + } + } + } + + return max(col, vec3(0.0,0.0,0.0)); +} + +#else +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_data[3]; +#else +#define frag_data gl_FragData +#endif +#endif + +uniform sampler2D diffuseMap; //always in sRGB space + +#ifdef HAS_NORMAL_MAP +uniform sampler2D bumpMap; +#endif + +#ifdef HAS_SPECULAR_MAP +uniform sampler2D specularMap; + +VARYING vec2 vary_texcoord2; +#endif + +uniform float env_intensity; +uniform vec4 specular_color; // specular color RGB and specular exponent (glossiness) in alpha + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) +uniform float minimum_alpha; +#endif + +#ifdef HAS_NORMAL_MAP +VARYING vec3 vary_mat0; +VARYING vec3 vary_mat1; +VARYING vec3 vary_mat2; +VARYING vec2 vary_texcoord1; +#else +VARYING vec3 vary_normal; +#endif + +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; + +vec2 encode_normal(vec3 n); + +void main() +{ + vec2 pos_screen = vary_texcoord0.xy; + + vec4 diffuse_tap = texture2D(diffuseMap, vary_texcoord0.xy); + diffuse_tap.rgb *= vertex_color.rgb; + //diffuse_tap = vec4(1,1,1,1); + +//#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + vec4 diffuse_srgb = diffuse_tap; + vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); +/*#else + vec4 diffuse_linear = diffuse_tap; + vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_linear.a); +#endif*/ + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) + if (diffuse_linear.a < minimum_alpha) + { + 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); +#endif + + vec3 norm = vec3(0); + float bmap_specular = 1.0; + +#ifdef HAS_NORMAL_MAP + vec4 bump_sample = texture2D(bumpMap, vary_texcoord1.xy); + norm = (bump_sample.xyz * 2) - vec3(1); + bmap_specular = bump_sample.w; + + // convert sampled normal to tangent space normal + norm = vec3(dot(norm, vary_mat0), + dot(norm, vary_mat1), + dot(norm, vary_mat2)); +#else + norm = vary_normal; +#endif + + norm = normalize(norm); + + vec2 abnormal = encode_normal(norm); + + vec4 final_color = vec4(diffuse_linear.rgb, 0.0); + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_EMISSIVE) + final_color.a = diffuse_linear.a; +#endif + + final_color.a = max(final_color.a, emissive_brightness); + + // Texture + // [x] Full Bright (emissive_brightness >= 1.0) + // Shininess (specular) + // [X] Texture + // Environment Intensity = 1 + // NOTE: There are two shaders that are used depending on the EI byte value: + // EI = 0 fullbright + // EI > 0 .. 255 material + // When it is passed to us it is normalized. + // We can either modify the output environment intensity + // OR + // adjust the final color via: + // final_color *= 0.666666; + // We don't remap the environment intensity but adjust the final color to closely simulate what non-EEP is doing. + vec4 final_normal = vec4(abnormal, env_intensity, 0.0); + + vec3 color = vec3(0.0); + float al = 0; + +#ifdef HAS_SPECULAR_MAP + if (emissive_brightness >= 1.0) + { + float ei = env_intensity*0.5 + 0.5; + final_normal = vec4(abnormal, ei, 0.0); + } +#endif + + vec4 final_specular = spec; + + final_specular.a = specular_color.a; + +#ifdef HAS_SPECULAR_MAP + final_specular.a *= bmap_specular; + final_normal.z *= spec.a; +#endif + + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + { + //forward rendering, output just lit sRGBA + vec3 pos = vary_position; + + float shadow = 1.0f; + +#ifdef HAS_SUN_SHADOW + shadow = sampleDirectionalShadow(pos.xyz, norm, pos_screen); +#endif + + spec = final_specular; + + float envIntensity = final_normal.z; + + vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + + float bloom = 0.0; + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; + + calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); + + vec3 refnormpersp = normalize(reflect(pos.xyz, norm)); + + float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0); + + float ambient = da; + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0 - ambient); + + vec3 sun_contrib = min(da, shadow) * sunlit; + +#if !defined(AMBIENT_KILL) + color.rgb = amblit; + color.rgb *= ambient; +#endif + +#if !defined(SUNLIGHT_KILL) + color.rgb += sun_contrib; +#endif + + color.rgb *= diffuse_linear.rgb; + + float glare = 0.0; + + if (spec.a > 0.0) // specular reflection + { + vec3 npos = -normalize(pos.xyz); + + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(light_dir.xyz+npos); + float nh = dot(norm, h); + float nv = dot(norm, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + vec3 sp = sun_contrib*scol / 6.0f; + sp = clamp(sp, vec3(0), vec3(1)); + bloom = dot(sp, sp) / 4.0; +#if !defined(SUNLIGHT_KILL) + color += sp * spec.rgb; +#endif + } + } + + if (envIntensity > 0.0) + { + //add environmentmap + vec3 env_vec = env_mat * refnormpersp; + + vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; + +#if !defined(SUNLIGHT_KILL) + color = mix(color.rgb, reflected_color, envIntensity); +#endif + float cur_glare = max(reflected_color.r, reflected_color.g); + cur_glare = max(cur_glare, reflected_color.b); + cur_glare *= envIntensity*4.0; + glare += cur_glare; + } + + color = atmosFragLighting(color, additive, atten); + + vec3 npos = normalize(-pos.xyz); + + vec3 light = vec3(0,0,0); + +#define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.rgb, final_specular, pos.xyz, norm, 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) + LIGHT_LOOP(3) + LIGHT_LOOP(4) + LIGHT_LOOP(5) + LIGHT_LOOP(6) + LIGHT_LOOP(7) + + glare = min(glare, 1.0); + al = max(diffuse_linear.a,glare)*vertex_color.a; + +#if !defined(LOCAL_LIGHT_KILL) + color.rgb += light.rgb; +#endif + + color = scaleSoftClipFrag(color); + +/*#ifdef WATER_FOG + vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); + color.rgb = temp.rgb; + al = temp.a; +#endif*/ + } + + + color.rgb = linear_to_srgb(color.rgb); + + frag_color = vec4(color, al); + +#else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer + + // deferred path + frag_data[0] = vec4(linear_to_srgb(final_color.rgb), final_color.a); //gbuffer is sRGB + frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. + frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. +#endif +} + -- cgit v1.2.3 From d33655828c104d1afe484b63093ad5aab1571a3c Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Thu, 5 Mar 2020 11:58:58 -0600 Subject: Reenable water fog in materialF.glsl (oops) --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 586ce4a9b7..18293f4c11 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -421,16 +421,16 @@ void main() color = scaleSoftClipFrag(color); -/*#ifdef WATER_FOG +#ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); color.rgb = temp.rgb; al = temp.a; -#endif*/ +#endif } - - color.rgb = linear_to_srgb(color.rgb); + color.rgb = linear_to_srgb(color.rgb); + frag_color = vec4(color, al); #else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer -- cgit v1.2.3 From 7c7d71269f5b47397d14bbe44e341e4ac1d96889 Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Thu, 5 Mar 2020 16:28:06 -0600 Subject: WIP - Windlight sun lighting should happen in sRGB space, not linear space. This keeps ambient from getting overblown and better matches environment lighting with ALM on/off. --- .../shaders/class1/deferred/materialF.glsl | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 18293f4c11..e4ebf0edee 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -117,7 +117,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); da *= spot*spot; // GL_SPOT_EXPONENT=2 - + //angular attenuation da *= dot(n, lv); @@ -215,8 +215,7 @@ void main() vec4 diffuse_tap = texture2D(diffuseMap, vary_texcoord0.xy); diffuse_tap.rgb *= vertex_color.rgb; - //diffuse_tap = vec4(1,1,1,1); - + //#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) vec4 diffuse_srgb = diffuse_tap; vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); @@ -349,7 +348,7 @@ void main() color.rgb += sun_contrib; #endif - color.rgb *= diffuse_linear.rgb; + color.rgb *= diffuse_srgb.rgb; float glare = 0.0; @@ -397,11 +396,15 @@ void main() } color = atmosFragLighting(color, additive, atten); + color = scaleSoftClipFrag(color); vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0,0,0); + //convert to linear before adding local lights + color.rgb = srgb_to_linear(color.rgb); + #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.rgb, final_specular, pos.xyz, norm, 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) @@ -419,8 +422,9 @@ void main() color.rgb += light.rgb; #endif - color = scaleSoftClipFrag(color); - +//convert to srgb as this color is being written post gamma correction + color.rgb = linear_to_srgb(color.rgb); + #ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); color.rgb = temp.rgb; @@ -429,8 +433,6 @@ void main() } - color.rgb = linear_to_srgb(color.rgb); - frag_color = vec4(color, al); #else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer -- cgit v1.2.3 From 0390dc2fec2afdc053f373813d419178a70b299c Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Fri, 6 Mar 2020 14:33:58 -0600 Subject: Fix for mismatch on angular attenuation between sunlight on opaque and transparent objects from last commit. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index e4ebf0edee..d07de529ca 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -331,8 +331,9 @@ void main() vec3 refnormpersp = normalize(reflect(pos.xyz, norm)); float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0); + da = pow(da, 1.0/1.3); - float ambient = da; + float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); ambient *= 0.5; ambient *= ambient; ambient = (1.0 - ambient); -- cgit v1.2.3 From f9eada575bfa46a1da5aeaf27c73537a9b86aa76 Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Tue, 10 Mar 2020 00:21:52 -0600 Subject: SL-12592, avoid light modulation of fullbright and preserve diffuse alpha component --- .../shaders/class1/deferred/materialF.glsl | 191 +++++++++++---------- 1 file changed, 96 insertions(+), 95 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index d07de529ca..21a462e2db 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -1,28 +1,28 @@ -/** - * @file materialF.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - +/** +* @file materialF.glsl +* +* $LicenseInfo:firstyear=2007&license=viewerlgpl$ +* Second Life Viewer Source Code +* Copyright (C) 2007, Linden Research, Inc. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; +* version 2.1 of the License only. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* +* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA +* $/LicenseInfo$ +*/ + /*[EXTRA_CODE_HERE]*/ //class1/deferred/materialF.glsl @@ -34,7 +34,7 @@ #define DIFFUSE_ALPHA_MODE_MASK 2 #define DIFFUSE_ALPHA_MODE_EMISSIVE 3 -uniform float emissive_brightness; +uniform float emissive_brightness; // fullbright flag, 1.0 == fullbright, 0.0 otherwise uniform int sun_up_factor; #ifdef WATER_FOG @@ -52,13 +52,13 @@ vec3 linear_to_srgb(vec3 cs); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) #ifdef DEFINE_GL_FRAGCOLOR - out vec4 frag_color; +out vec4 frag_color; #else - #define frag_color gl_FragColor +#define frag_color gl_FragColor #endif #ifdef HAS_SUN_SHADOW - float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); +float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); #endif uniform samplerCube environmentMap; @@ -81,7 +81,7 @@ uniform vec2 screen_res; uniform vec4 light_position[8]; uniform vec3 light_direction[8]; -uniform vec4 light_attenuation[8]; +uniform vec4 light_attenuation[8]; uniform vec3 light_diffuse[8]; float getAmbientClamp(); @@ -91,7 +91,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe vec3 col = vec3(0); //get light vector - vec3 lv = lp.xyz-v; + vec3 lv = lp.xyz - v; //get distance float dist = length(lv); @@ -103,21 +103,21 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe { //normalize light vector lv = normalize(lv); - + //distance attenuation - float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); + float dist_atten = clamp(1.0 - (dist - 1.0*(1.0 - fa)) / fa, 0.0, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0f; if (dist_atten <= 0.0) { - return col; + return col; } // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); da *= spot*spot; // GL_SPOT_EXPONENT=2 - + //angular attenuation da *= dot(n, lv); @@ -126,9 +126,9 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe float amb_da = ambiance; if (da >= 0) { - lit = max(da * dist_atten,0.0); + lit = max(da * dist_atten, 0.0); col = lit * light_col * diffuse; - amb_da += (da*0.5+0.5) * ambiance; + amb_da += (da*0.5 + 0.5) * ambiance; } amb_da += (da*da*0.5 + 0.5) * ambiance; amb_da *= dist_atten; @@ -140,19 +140,19 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe if (spec.a > 0.0) { //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(lv+npos); + vec3 h = normalize(lv + npos); float nh = dot(n, h); float nv = dot(n, npos); float vh = dot(npos, h); float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + 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); + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt / (nh*da); vec3 speccol = lit*scol*light_col.rgb*spec.rgb; speccol = clamp(speccol, vec3(0), vec3(1)); col += speccol; @@ -165,7 +165,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe } } - return max(col, vec3(0.0,0.0,0.0)); + return max(col, vec3(0.0, 0.0, 0.0)); } #else @@ -213,16 +213,9 @@ void main() { vec2 pos_screen = vary_texcoord0.xy; - vec4 diffuse_tap = texture2D(diffuseMap, vary_texcoord0.xy); - diffuse_tap.rgb *= vertex_color.rgb; - -//#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - vec4 diffuse_srgb = diffuse_tap; + vec4 diffuse_srgb = texture2D(diffuseMap, vary_texcoord0.xy); + diffuse_srgb.rgb *= vertex_color.rgb; vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); -/*#else - vec4 diffuse_linear = diffuse_tap; - vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_linear.a); -#endif*/ #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) if (diffuse_linear.a < minimum_alpha) @@ -248,15 +241,15 @@ void main() // convert sampled normal to tangent space normal norm = vec3(dot(norm, vary_mat0), - dot(norm, vary_mat1), - dot(norm, vary_mat2)); + dot(norm, vary_mat1), + dot(norm, vary_mat2)); #else norm = vary_normal; #endif norm = normalize(norm); - vec2 abnormal = encode_normal(norm); + vec2 abnormal = encode_normal(norm); vec4 final_color = vec4(diffuse_linear.rgb, 0.0); @@ -286,7 +279,7 @@ void main() float al = 0; #ifdef HAS_SPECULAR_MAP - if (emissive_brightness >= 1.0) + if (emissive_brightness >= 1.0) // ie, if fullbright { float ei = env_intensity*0.5 + 0.5; final_normal = vec4(abnormal, ei, 0.0); @@ -304,34 +297,43 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - { - //forward rendering, output just lit sRGBA - vec3 pos = vary_position; - float shadow = 1.0f; + //forward rendering, output just lit sRGBA + vec3 pos = vary_position; + + float shadow = 1.0f; #ifdef HAS_SUN_SHADOW - shadow = sampleDirectionalShadow(pos.xyz, norm, pos_screen); + shadow = sampleDirectionalShadow(pos.xyz, norm, pos_screen); #endif - spec = final_specular; + spec = final_specular; - float envIntensity = final_normal.z; + float envIntensity = final_normal.z; - vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - float bloom = 0.0; - vec3 sunlit; - vec3 amblit; - vec3 additive; - vec3 atten; + float bloom = 0.0; + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; - calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); + calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); + if (emissive_brightness >= 1.0) // fullbright, skip lighting calculations + { + // just do atmos attenuation (ad hoc 60% factor to match release viewer) + color = atmosFragLighting(diffuse_srgb.rgb, additive, atten*0.6); + color = scaleSoftClipFrag(color); + al = diffuse_srgb.a; + } + else // not fullbright, calculate lighting + { vec3 refnormpersp = normalize(reflect(pos.xyz, norm)); float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0); - da = pow(da, 1.0/1.3); + da = pow(da, 1.0 / 1.3); float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); ambient *= 0.5; @@ -341,16 +343,15 @@ void main() vec3 sun_contrib = min(da, shadow) * sunlit; #if !defined(AMBIENT_KILL) - color.rgb = amblit; - color.rgb *= ambient; + color = amblit; + color *= ambient; #endif #if !defined(SUNLIGHT_KILL) - color.rgb += sun_contrib; + color += sun_contrib; #endif + color *= diffuse_srgb.rgb; - color.rgb *= diffuse_srgb.rgb; - float glare = 0.0; if (spec.a > 0.0) // specular reflection @@ -358,19 +359,19 @@ void main() vec3 npos = -normalize(pos.xyz); //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(light_dir.xyz+npos); + vec3 h = normalize(light_dir.xyz + npos); float nh = dot(norm, h); float nv = dot(norm, npos); float vh = dot(npos, h); float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + float 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); + 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; @@ -384,11 +385,11 @@ void main() { //add environmentmap vec3 env_vec = env_mat * refnormpersp; - + vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; #if !defined(SUNLIGHT_KILL) - color = mix(color.rgb, reflected_color, envIntensity); + color = mix(color, reflected_color, envIntensity); #endif float cur_glare = max(reflected_color.r, reflected_color.g); cur_glare = max(cur_glare, reflected_color.b); @@ -401,14 +402,14 @@ void main() vec3 npos = normalize(-pos.xyz); - vec3 light = vec3(0,0,0); + vec3 light = vec3(0, 0, 0); //convert to linear before adding local lights - color.rgb = srgb_to_linear(color.rgb); + color = srgb_to_linear(color); #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.rgb, final_specular, pos.xyz, norm, 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(1) LIGHT_LOOP(2) LIGHT_LOOP(3) LIGHT_LOOP(4) @@ -416,25 +417,25 @@ void main() LIGHT_LOOP(6) LIGHT_LOOP(7) - glare = min(glare, 1.0); - al = max(diffuse_linear.a,glare)*vertex_color.a; + glare = min(glare, 1.0); + al = max(diffuse_linear.a, glare)*vertex_color.a; #if !defined(LOCAL_LIGHT_KILL) - color.rgb += light.rgb; + color += light; #endif -//convert to srgb as this color is being written post gamma correction - color.rgb = linear_to_srgb(color.rgb); - + //convert to srgb as this color is being written post gamma correction + color = linear_to_srgb(color); + } + #ifdef WATER_FOG - vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); - color.rgb = temp.rgb; - al = temp.a; + vec4 temp = applyWaterFogView(pos, vec4(color, al)); + color = temp.rgb; + al = temp.a; #endif - } - - frag_color = vec4(color, al); + // Don't allow alpha to exceed input value - SL-12592 + frag_color = vec4(color, min(al, diffuse_srgb.a)); #else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer -- cgit v1.2.3 From b1e2615cd80f27dac6712995edcc890df021041a Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 10 Mar 2020 12:35:12 -0700 Subject: SL-12171 Fix emissive mask being too bright post sRGB/Linear cleanup --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 21a462e2db..5999063ae5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -254,7 +254,7 @@ void main() vec4 final_color = vec4(diffuse_linear.rgb, 0.0); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_EMISSIVE) - final_color.a = diffuse_linear.a; + final_color.a = diffuse_linear.a * 0.5; // SL-12171 #endif final_color.a = max(final_color.a, emissive_brightness); -- cgit v1.2.3 From c7f2712d9576c0122726104f74690c1ee5f94ae2 Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Thu, 12 Mar 2020 16:52:48 -0600 Subject: SL-12784 restore vertex color alpha contribution --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 5999063ae5..553c2f3045 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -214,7 +214,7 @@ void main() vec2 pos_screen = vary_texcoord0.xy; vec4 diffuse_srgb = texture2D(diffuseMap, vary_texcoord0.xy); - diffuse_srgb.rgb *= vertex_color.rgb; + diffuse_srgb *= vertex_color; vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) -- cgit v1.2.3 From 0a0cfcf2ef92375f099ed91f009db1ebf2d410c0 Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Fri, 13 Mar 2020 12:58:47 -0500 Subject: SL-12233 Fix for disagreement between fullbright implementations with ALM on and off. --- .../app_settings/shaders/class1/deferred/materialF.glsl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 5999063ae5..a69653fe4e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -44,6 +44,9 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); +vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); +vec3 fullbrightScaleSoftClip(vec3 light); + void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); vec3 srgb_to_linear(vec3 cs); @@ -320,21 +323,26 @@ void main() vec3 atten; calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); - + if (emissive_brightness >= 1.0) // fullbright, skip lighting calculations { - // just do atmos attenuation (ad hoc 60% factor to match release viewer) - color = atmosFragLighting(diffuse_srgb.rgb, additive, atten*0.6); - color = scaleSoftClipFrag(color); + color = fullbrightAtmosTransportFrag(diffuse_srgb.rgb, additive, atten); + color = fullbrightScaleSoftClip(color); + al = diffuse_srgb.a; } else // not fullbright, calculate lighting { vec3 refnormpersp = normalize(reflect(pos.xyz, norm)); + //we're in sRGB space, so gamma correct this dot product so + // 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); + //darken ambient for normals perpendicular to light vector so surfaces in shadow + // and facing away from light still have some definition to them. + // do NOT gamma correct this dot product so ambient lighting stays soft float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); ambient *= 0.5; ambient *= ambient; -- cgit v1.2.3 From 09b13b3981f121f20674b874f47f96bef2ac73ce Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Fri, 13 Mar 2020 14:59:11 -0600 Subject: SL-12784 disambiguate vertex_color.a of 0 --- .../app_settings/shaders/class1/deferred/materialF.glsl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index ca11f58888..a8a5cc22db 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -217,7 +217,16 @@ void main() vec2 pos_screen = vary_texcoord0.xy; vec4 diffuse_srgb = texture2D(diffuseMap, vary_texcoord0.xy); - diffuse_srgb *= vertex_color; + diffuse_srgb.rgb *= vertex_color.rgb; + + // For some reason the Transparency slider sets vertex_color.a to 0.0 both for + // fully opaque and for fully transparent objects. This code assumes the 0 alpha + // is always from the opaque end of the scale. TODO: Remove the conditional once + // the root cause of the slider ambiguity is fixed. + if (vertex_color.a > 0.0) + { + diffuse_srgb.a *= vertex_color.a; + } vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) -- cgit v1.2.3 From 6dbc72df774a99cd80c4a690e7d03017d39005e9 Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Tue, 17 Mar 2020 13:46:52 -0600 Subject: SL-10449 remove soft gamma adjustment that breaks Mac GLSL compiler --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index a8a5cc22db..f1b13c8825 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -336,7 +336,10 @@ void main() if (emissive_brightness >= 1.0) // fullbright, skip lighting calculations { color = fullbrightAtmosTransportFrag(diffuse_srgb.rgb, additive, atten); - color = fullbrightScaleSoftClip(color); + // This call breaks the Mac GLSL compiler/linker for unknown reasons (17Mar2020) + // The call is either a no-op or a pure (pow) gamma adjustment, depending on GPU level + // TODO: determine if we want to re-apply the gamma adjustment, and if so understand & fix Mac breakage + //color = fullbrightScaleSoftClip(color); al = diffuse_srgb.a; } -- cgit v1.2.3 From ff683a7127d299694a8fece5772f3656d9214edc Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Wed, 18 Mar 2020 16:30:20 -0600 Subject: SL-12865, add bias to alpha mask values to avoid 8-bit acne --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index f1b13c8825..4198053c99 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -230,7 +230,10 @@ void main() vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) - if (diffuse_linear.a < minimum_alpha) + + // 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 (diffuse_linear.a < minimum_alpha-bias) { discard; } -- cgit v1.2.3 From 3e472948db34e8efc905b5b50249f4587ba1507f Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Fri, 20 Mar 2020 16:50:37 -0500 Subject: WIP - Make EEP match production. --- .../shaders/class1/deferred/materialF.glsl | 293 +++++++++------------ 1 file changed, 130 insertions(+), 163 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index a8a5cc22db..85d664ea1f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -216,98 +216,63 @@ void main() { vec2 pos_screen = vary_texcoord0.xy; - vec4 diffuse_srgb = texture2D(diffuseMap, vary_texcoord0.xy); - diffuse_srgb.rgb *= vertex_color.rgb; - - // For some reason the Transparency slider sets vertex_color.a to 0.0 both for - // fully opaque and for fully transparent objects. This code assumes the 0 alpha - // is always from the opaque end of the scale. TODO: Remove the conditional once - // the root cause of the slider ambiguity is fixed. - if (vertex_color.a > 0.0) - { - diffuse_srgb.a *= vertex_color.a; - } - vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); + vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); + diffcol.rgb *= vertex_color.rgb; #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) - if (diffuse_linear.a < minimum_alpha) + if (diffcol.a < minimum_alpha) { discard; } #endif -#ifdef HAS_SPECULAR_MAP +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + vec3 gamma_diff = diffcol.rgb; + diffcol.rgb = srgb_to_linear(diffcol.rgb); +#endif + +#if HAS_SPECULAR_MAP != 0 vec4 spec = texture2D(specularMap, vary_texcoord2.xy); spec.rgb *= specular_color.rgb; #else vec4 spec = vec4(specular_color.rgb, 1.0); #endif - vec3 norm = vec3(0); - float bmap_specular = 1.0; +#if HAS_NORMAL_MAP + vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); -#ifdef HAS_NORMAL_MAP - vec4 bump_sample = texture2D(bumpMap, vary_texcoord1.xy); - norm = (bump_sample.xyz * 2) - vec3(1); - bmap_specular = bump_sample.w; - - // convert sampled normal to tangent space normal - norm = vec3(dot(norm, vary_mat0), - dot(norm, vary_mat1), - dot(norm, vary_mat2)); + norm.xyz = norm.xyz * 2 - 1; + + vec3 tnorm = vec3(dot(norm.xyz,vary_mat0), + dot(norm.xyz,vary_mat1), + dot(norm.xyz,vary_mat2)); #else - norm = vary_normal; + vec4 norm = vec4(0,0,0,1.0); + vec3 tnorm = vary_normal; #endif - norm = normalize(norm); - - vec2 abnormal = encode_normal(norm); + norm.xyz = normalize(tnorm.xyz); - vec4 final_color = vec4(diffuse_linear.rgb, 0.0); - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_EMISSIVE) - final_color.a = diffuse_linear.a * 0.5; // SL-12171 -#endif + vec2 abnormal = encode_normal(norm.xyz); - final_color.a = max(final_color.a, emissive_brightness); - - // Texture - // [x] Full Bright (emissive_brightness >= 1.0) - // Shininess (specular) - // [X] Texture - // Environment Intensity = 1 - // NOTE: There are two shaders that are used depending on the EI byte value: - // EI = 0 fullbright - // EI > 0 .. 255 material - // When it is passed to us it is normalized. - // We can either modify the output environment intensity - // OR - // adjust the final color via: - // final_color *= 0.666666; - // We don't remap the environment intensity but adjust the final color to closely simulate what non-EEP is doing. - vec4 final_normal = vec4(abnormal, env_intensity, 0.0); - - vec3 color = vec3(0.0); - float al = 0; + vec4 final_color = diffcol; -#ifdef HAS_SPECULAR_MAP - if (emissive_brightness >= 1.0) // ie, if fullbright - { - float ei = env_intensity*0.5 + 0.5; - final_normal = vec4(abnormal, ei, 0.0); - } +#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) + final_color.a = emissive_brightness; +#else + final_color.a = max(final_color.a, emissive_brightness); #endif vec4 final_specular = spec; - - final_specular.a = specular_color.a; - -#ifdef HAS_SPECULAR_MAP - final_specular.a *= bmap_specular; - final_normal.z *= spec.a; + +#if HAS_SPECULAR_MAP != 0 + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, 0.0); + final_specular.a = specular_color.a * norm.a; +#else + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); + final_specular.a = specular_color.a; #endif - #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) //forward rendering, output just lit sRGBA @@ -316,13 +281,15 @@ void main() float shadow = 1.0f; #ifdef HAS_SUN_SHADOW - shadow = sampleDirectionalShadow(pos.xyz, norm, pos_screen); + shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen); #endif spec = final_specular; - + vec4 diffuse = final_color; float envIntensity = final_normal.z; + vec3 color = vec3(0,0,0); + vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; float bloom = 0.0; @@ -333,117 +300,118 @@ void main() calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); - if (emissive_brightness >= 1.0) // fullbright, skip lighting calculations - { - color = fullbrightAtmosTransportFrag(diffuse_srgb.rgb, additive, atten); - color = fullbrightScaleSoftClip(color); - al = diffuse_srgb.a; - } - else // not fullbright, calculate lighting - { - vec3 refnormpersp = normalize(reflect(pos.xyz, norm)); - - //we're in sRGB space, so gamma correct this dot product so - // 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); - - //darken ambient for normals perpendicular to light vector so surfaces in shadow - // and facing away from light still have some definition to them. - // do NOT gamma correct this dot product so ambient lighting stays soft - float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0 - ambient); - - vec3 sun_contrib = min(da, shadow) * sunlit; - -#if !defined(AMBIENT_KILL) - color = amblit; - color *= ambient; -#endif + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); -#if !defined(SUNLIGHT_KILL) - color += sun_contrib; -#endif - color *= diffuse_srgb.rgb; + //we're in sRGB space, so gamma correct this dot product so + // 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); - float glare = 0.0; + color = amblit; - if (spec.a > 0.0) // specular reflection - { - vec3 npos = -normalize(pos.xyz); + //darken ambient for normals perpendicular to light vector so surfaces in shadow + // and facing away from light still have some definition to them. + // do NOT gamma correct this dot product so ambient lighting stays soft + float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0 - ambient); - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(light_dir.xyz + npos); - float nh = dot(norm, h); - float nv = dot(norm, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4 + 0.5; + vec3 sun_contrib = min(da, shadow) * sunlit; + + color *= ambient; - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + color += sun_contrib; - 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; -#if !defined(SUNLIGHT_KILL) - color += sp * spec.rgb; -#endif - } - } + color *= gamma_diff.rgb; - if (envIntensity > 0.0) - { - //add environmentmap - vec3 env_vec = env_mat * refnormpersp; + float glare = 0.0; - vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; + if (spec.a > 0.0) // specular reflection + { +#if 1 //EEP -#if !defined(SUNLIGHT_KILL) - color = mix(color, reflected_color, envIntensity); -#endif - float cur_glare = max(reflected_color.r, reflected_color.g); - cur_glare = max(cur_glare, reflected_color.b); - cur_glare *= envIntensity*4.0; - glare += cur_glare; + 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; } +#else // PRODUCTION + float sa = dot(refnormpersp, sun_dir.xyz); + vec3 dumbshiny = sunlit*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); + + // add the two types of shiny together + vec3 spec_contrib = dumbshiny * spec.rgb; + bloom = dot(spec_contrib, spec_contrib) / 6; + + glare = max(spec_contrib.r, spec_contrib.g); + glare = max(glare, spec_contrib.b); + + color += spec_contrib; +#endif + } - color = atmosFragLighting(color, additive, atten); - color = scaleSoftClipFrag(color); + color = mix(color.rgb, diffcol.rgb, diffuse.a); + + if (envIntensity > 0.0) + { + //add environmentmap + vec3 env_vec = env_mat * refnormpersp; - vec3 npos = normalize(-pos.xyz); + vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; - vec3 light = vec3(0, 0, 0); + color = mix(color, reflected_color, envIntensity); - //convert to linear before adding local lights - color = srgb_to_linear(color); + float cur_glare = max(reflected_color.r, reflected_color.g); + cur_glare = max(cur_glare, reflected_color.b); + cur_glare *= envIntensity*4.0; + glare += cur_glare; + } -#define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.rgb, final_specular, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare, light_attenuation[i].w ); + color = atmosFragLighting(color, additive, atten); + color = scaleSoftClipFrag(color); - LIGHT_LOOP(1) - LIGHT_LOOP(2) - LIGHT_LOOP(3) - LIGHT_LOOP(4) - LIGHT_LOOP(5) - LIGHT_LOOP(6) - LIGHT_LOOP(7) + //convert to linear before adding local lights + color = srgb_to_linear(color); - glare = min(glare, 1.0); - al = max(diffuse_linear.a, glare)*vertex_color.a; + vec3 npos = normalize(-pos.xyz); -#if !defined(LOCAL_LIGHT_KILL) - color += light; -#endif + 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, glare, light_attenuation[i].w ); - //convert to srgb as this color is being written post gamma correction - color = linear_to_srgb(color); - } + LIGHT_LOOP(1) + LIGHT_LOOP(2) + LIGHT_LOOP(3) + LIGHT_LOOP(4) + LIGHT_LOOP(5) + LIGHT_LOOP(6) + LIGHT_LOOP(7) + + color += light; + + glare = min(glare, 1.0); + float al = max(diffcol.a, glare)*vertex_color.a; + + //convert to srgb as this color is being written post gamma correction + color = linear_to_srgb(color); #ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(color, al)); @@ -451,13 +419,12 @@ void main() al = temp.a; #endif - // Don't allow alpha to exceed input value - SL-12592 - frag_color = vec4(color, min(al, diffuse_srgb.a)); + frag_color = vec4(color, al); #else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer // deferred path - frag_data[0] = vec4(linear_to_srgb(final_color.rgb), final_color.a); //gbuffer is sRGB + frag_data[0] = final_color; //gbuffer is sRGB frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. #endif -- cgit v1.2.3 From 20e5ad48ec1a9c6fa4902fa34b6b53f0a7fc5858 Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Tue, 24 Mar 2020 13:44:40 -0500 Subject: Merge cleanup --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 4644fe3f2b..2999abacef 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -223,7 +223,7 @@ void main() // 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 (diffuse_linear.a < minimum_alpha-bias) + if (diffcol.a < minimum_alpha-bias) { discard; } -- cgit v1.2.3 From 1016b9de1804e445252bda297ae93aed6c2971f0 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 7 Apr 2020 14:02:48 -0700 Subject: SL-10449 Fix ALM on OSX --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 2999abacef..0afd1a9672 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -234,14 +234,14 @@ void main() diffcol.rgb = srgb_to_linear(diffcol.rgb); #endif -#if HAS_SPECULAR_MAP != 0 +#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 -#if HAS_NORMAL_MAP +#ifdef HAS_NORMAL_MAP vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); norm.xyz = norm.xyz * 2 - 1; @@ -268,7 +268,7 @@ void main() vec4 final_specular = spec; -#if HAS_SPECULAR_MAP != 0 +#ifdef HAS_SPECULAR_MAP vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, 0.0); final_specular.a = specular_color.a * norm.a; #else -- cgit v1.2.3