diff options
author | Graham Linden <graham@lindenlab.com> | 2019-05-02 13:49:35 -0700 |
---|---|---|
committer | Graham Linden <graham@lindenlab.com> | 2019-05-02 13:49:35 -0700 |
commit | c4032528aff8ef1938e897ec583bbf25a3e713e1 (patch) | |
tree | 4addd3b6619e6e911898d09ef446d0d40ef8a73e /indra/newview/app_settings/shaders/class1/deferred | |
parent | 1ff876a961dc00b7f162054ea1a9fed79240bffc (diff) |
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.
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/deferred')
9 files changed, 192 insertions, 147 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index ae579d7f85..ecb1d599de 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -121,7 +121,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec 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; + dist_atten *= 2.0; // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); @@ -140,9 +140,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec amb_da *= dist_atten; amb_da = min(amb_da, 1.0f - lit); -#ifndef NO_AMBIANCE col.rgb += amb_da * 0.5 * light_col * diffuse; -#endif // no spec for alpha shader... } @@ -164,22 +162,26 @@ void main() shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, frag); #endif +#ifdef USE_DIFFUSE_TEX + vec4 diffuse_linear = texture2D(diffuseMap,vary_texcoord0.xy); +#endif + #ifdef USE_INDEXED_TEX - vec4 diff = diffuseLookup(vary_texcoord0.xy); -#else - vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); + vec4 diffuse_linear = diffuseLookup(vary_texcoord0.xy); #endif + vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_linear.a); + #ifdef FOR_IMPOSTOR vec4 color; - color.rgb = diff.rgb; + color.rgb = diffuse_srgb.rgb; color.a = 1.0; #ifdef USE_VERTEX_COLOR - float final_alpha = diff.a * vertex_color.a; - diff.rgb *= vertex_color.rgb; + float final_alpha = diffuse_srgb.a * vertex_color.a; + diffuse_srgb.rgb *= vertex_color.rgb; #else - float final_alpha = diff.a; + float final_alpha = diffuse_srgb.a; #endif // Insure we don't pollute depth with invis pixels in impostor rendering @@ -191,16 +193,12 @@ void main() #else #ifdef USE_VERTEX_COLOR - float final_alpha = diff.a * vertex_color.a; - diff.rgb *= vertex_color.rgb; + float final_alpha = diffuse_linear.a * vertex_color.a; + diffuse_srgb.rgb *= vertex_color.rgb; #else - float final_alpha = diff.a; + float final_alpha = diffuse_linear.a; #endif - vec3 gamma_diff = diff.rgb; - - diff.rgb = srgb_to_linear(diff.rgb); - vec3 sunlit; vec3 amblit; vec3 additive; @@ -217,7 +215,7 @@ void main() float final_da = da; final_da = clamp(final_da, 0.0f, 1.0f); - vec4 color = vec4(0,0,0,0); + vec4 color = vec4(0.0); color.rgb = amblit; color.a = final_alpha; @@ -225,6 +223,7 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; + ambient = max(getAmbientClamp(), ambient); // keeps shadows dark ambient = 1.0 - ambient; vec3 sun_contrib = min(final_da, shadow) * sunlit; @@ -237,14 +236,12 @@ vec3 post_ambient = color.rgb; vec3 post_sunlight = color.rgb; - color.rgb *= diff.rgb; + color.rgb *= diffuse_linear.rgb; vec3 post_diffuse = color.rgb; - color.rgb = mix(diff.rgb, color.rgb, final_alpha); - - //color.rgb = srgb_to_linear(color.rgb); - + //color.rgb = mix(diffuse_srgb.rgb, color.rgb, final_alpha); + color.rgb = atmosFragLighting(color.rgb, additive, atten); color.rgb = scaleSoftClipFrag(color.rgb); @@ -252,7 +249,10 @@ vec3 post_atmo = color.rgb; vec4 light = vec4(0,0,0,0); - #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diff.rgb, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, light_attenuation[i].w * 0.5); + // to linear! + color.rgb = srgb_to_linear(color.rgb); + + #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diffuse_linear.rgb, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, light_attenuation[i].w * 0.5); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -262,15 +262,29 @@ vec3 post_atmo = color.rgb; LIGHT_LOOP(6) LIGHT_LOOP(7) + // sum local light contrib in linear colorspace + color.rgb += light.rgb; + + // back to sRGB as we're going directly to the final RT post-deferred gamma correction color.rgb = linear_to_srgb(color.rgb); - color.rgb += light.rgb; -#endif + +//color.rgb = amblit; +//color.rgb = vec3(ambient); +//color.rgb = sunlit; +//color.rgb = vec3(final_da); +//color.rgb = post_ambient; +//color.rgb = post_sunlight; +//color.rgb = sun_contrib; +//color.rgb = diffuse_srgb.rgb; +//color.rgb = post_diffuse; +//color.rgb = post_atmo; #ifdef WATER_FOG color = applyWaterFogView(pos.xyz, color); -#endif +#endif // WATER_FOG +#endif frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index 9535cd6870..c5eaacbd0b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -86,14 +86,14 @@ void main() vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); // Offset texture coords - uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density + uv1 += cloud_pos_density1.xy;// + (disturbance * 0.02); //large texture, visible density uv2 += cloud_pos_density1.xy; //large texture, self shadow uv3 += cloud_pos_density2.xy; //small texture, visible density uv4 += cloud_pos_density2.xy; //small texture, self shadow float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); - cloudDensity *= 1.0 - (density_variance * density_variance); + //cloudDensity *= 1.0 - (density_variance * density_variance); // Compute alpha1, the main cloud opacity @@ -104,8 +104,8 @@ void main() alpha1 = 1. - alpha1 * alpha1; alpha1 = 1. - alpha1 * alpha1; - alpha1 *= altitude_blend_factor; - alpha1 = clamp(alpha1, 0.0, 1.0); + //alpha1 *= altitude_blend_factor; + //alpha1 = clamp(alpha1, 0.0, 1.0); // Compute alpha2, for self shadowing effect // (1 - alpha2) will later be used as percentage of incoming sunlight @@ -122,6 +122,10 @@ void main() color.rgb= max(vec3(0), color.rgb); color.rgb = linear_to_srgb(color.rgb); +//alpha1 = 1.0; +//color.rgb = cloudColorAmbient.rgb; + + /// Gamma correct for WL (soft clip effect). frag_data[0] = vec4(scaleSoftClip(color.rgb), alpha1); frag_data[1] = vec4(0.0,0.0,0.0,0.0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl index 61fd43f1ee..10425bb91f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl @@ -78,7 +78,7 @@ void main() // Get relative position vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); - altitude_blend_factor = (P.y > -4096.0) ? 1.0 : 1.0 - clamp(abs(P.y) / max_y, 0.0, 1.0); + altitude_blend_factor = (P.y > -4096.0) ? 1.0 : 1.0 - clamp(abs(P.y) / max_y, 0.0, 1.0); // Set altitude if (P.y > 0.) @@ -86,7 +86,6 @@ void main() P *= (max_y / P.y); } else - if (P.y <= 0.0) { P *= (-32000. / P.y); } @@ -100,14 +99,14 @@ void main() vec4 temp2 = vec4(0.); vec4 blue_weight; vec4 haze_weight; - vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; + //vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; + vec4 sunlight = sunlight_color; vec4 light_atten; - float dens_mul = density_multiplier; // 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)) * (dens_mul * max_y); + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); // Calculate relative weights temp1 = blue_density + haze_density; @@ -120,13 +119,14 @@ void main() sunlight *= exp( - light_atten * temp2.y); // Distance - temp2.z = Plen * dens_mul; + temp2.z = Plen * density_multiplier; // Transparency (-> temp1) // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati // compiler gets confused. temp1 = exp(-temp1 * temp2.z); + // Compute haze glow temp2.x = dot(Pn, lightnorm.xyz); temp2.x = 1. - temp2.x; @@ -138,7 +138,7 @@ void main() temp2.x = pow(temp2.x, glow.z); // glow.z should be negative, so we're doing a sort of (1 / "angle") function - temp2.x *= sun_moon_glow_factor; + //temp2.x *= sun_moon_glow_factor; // Add "minimum anti-solar illumination" temp2.x += .25; @@ -179,7 +179,7 @@ void main() // Texture coords vary_texcoord0 = texcoord0; vary_texcoord0.xy -= 0.5; - vary_texcoord0.xy /= max(0.001, cloud_scale); + vary_texcoord0.xy /= cloud_scale; vary_texcoord0.xy += 0.5; vary_texcoord1 = vary_texcoord0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl index 828c325c9d..ccd1df84f9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl @@ -36,11 +36,12 @@ VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; vec2 encode_normal(vec3 n); +vec3 linear_to_srgb(vec3 c); void main() { vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb; - + vec3 spec; spec.rgb = vec3(vertex_color.a); 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. diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index 187b5a62dd..8256d5f106 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -44,12 +44,15 @@ uniform sampler2D altDiffuseMap; uniform float blend_factor; // interp factor between moon A/B VARYING vec2 vary_texcoord0; +vec3 srgb_to_linear(vec3 c); void main() { vec4 moonA = texture2D(diffuseMap, vary_texcoord0.xy); vec4 moonB = texture2D(altDiffuseMap, vary_texcoord0.xy); vec4 c = mix(moonA, moonB, blend_factor); + c.rgb = srgb_to_linear(c.rgb); + // mix factor which blends when sunlight is brighter // and shows true moon color at night vec3 luma_weights = vec3(0.3, 0.5, 0.3); diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 6489508c00..2569e49743 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -72,8 +72,6 @@ uniform vec2 screen_res; uniform mat4 inv_proj; vec3 getNorm(vec2 pos_screen); -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index bcd93d9a2d..84642b2f98 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -36,7 +36,6 @@ out vec4 frag_color; uniform sampler2DRect diffuseRect; uniform sampler2DRect specularRect; -uniform sampler2DRect positionMap; uniform sampler2DRect normalMap; uniform sampler2DRect lightMap; uniform sampler2DRect depthMap; @@ -47,13 +46,7 @@ uniform float blur_size; uniform float blur_fidelity; // Inputs -uniform vec4 morphFactor; -uniform vec3 camPosLocal; -//uniform vec4 camPosWorld; -uniform vec4 gamma; -uniform float global_gamma; uniform mat3 env_mat; -uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; uniform vec3 moon_dir; @@ -63,21 +56,20 @@ VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; uniform vec2 screen_res; -#ifdef WATER_FOG -vec4 applyWaterFogView(vec3 pos, vec4 color); -#endif - vec3 getNorm(vec2 pos_screen); -vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); +vec4 getPositionWithDepth(vec2 pos_screen, float depth); -float getAmbientClamp(); void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); - +float getAmbientClamp(); +vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); -vec3 srgb_to_linear(vec3 c); + vec3 linear_to_srgb(vec3 c); +vec3 srgb_to_linear(vec3 c); -vec4 getPositionWithDepth(vec2 pos_screen, float depth); +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 color); +#endif void main() { @@ -88,50 +80,49 @@ void main() float envIntensity = norm.z; norm.xyz = getNorm(tc); - float light_gamma = 1.0/1.3; vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - float da = dot(normalize(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, light_gamma); - vec4 gamma_diff = texture2DRect(diffuseRect, tc); - vec4 diffuse = gamma_diff; - diffuse.rgb = srgb_to_linear(gamma_diff.rgb); + vec4 diffuse_linear = texture2DRect(diffuseRect, tc); + vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_linear.a); vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); - vec3 col; + vec3 color = vec3(0); float bloom = 0.0; { + float ambocc = 1.0; // no AO... + vec3 sunlit; vec3 amblit; vec3 additive; vec3 atten; - - calcAtmosphericVars(pos.xyz, 1.0, sunlit, amblit, additive, atten); + + calcAtmosphericVars(pos.xyz, ambocc, sunlit, amblit, additive, atten); float ambient = da; ambient *= 0.5; ambient *= ambient; + ambient = max(getAmbientClamp(), ambient); ambient = 1.0 - ambient; vec3 sun_contrib = final_da * 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 *= gamma_diff.rgb; + color.rgb *= diffuse_linear.rgb; -vec3 post_diffuse = col.rgb; +vec3 post_diffuse = color.rgb; vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); @@ -152,40 +143,59 @@ vec3 post_diffuse = col.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; + float scontrib = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + vec3 speccol = sun_contrib*scontrib*spec.rgb; speccol = clamp(speccol, vec3(0), vec3(1)); - bloom = dot(speccol, speccol) / 6; - col += speccol; + bloom += dot (speccol, speccol) / 6; + color += speccol; } } - vec3 post_spec = col.rgb; + vec3 post_spec = color.rgb; - col.rgb += diffuse.a * diffuse.rgb; + color.rgb += diffuse_srgb.a * diffuse_srgb.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); + vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; + color = mix(color.rgb, reflected_color, envIntensity); } - + +vec3 post_env = color.rgb; + if (norm.w < 1) { - col = atmosFragLighting(col, additive, atten); - col = scaleSoftClipFrag(col); + color = atmosFragLighting(color, additive, atten); + color = scaleSoftClipFrag(color); } -vec3 post_atmo = col.rgb; +vec3 post_atmo = color.rgb; #ifdef WATER_FOG - vec4 fogged = applyWaterFogView(pos.xyz,vec4(col, bloom)); - col = fogged.rgb; + vec4 fogged = applyWaterFogView(pos.xyz,vec4(color, bloom)); + color = fogged.rgb; bloom = fogged.a; #endif + +//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; + +// convert to linear as fullscreen lights need to sum in linear colorspace +// and will be gamma (re)corrected downstream... + color.rgb = srgb_to_linear(color.rgb); } - frag_color.rgb = col.rgb; + frag_color.rgb = color.rgb; frag_color.a = bloom; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl index 571e9d9326..454af2a9bc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl @@ -33,6 +33,7 @@ out vec4 frag_data[3]; #define frag_data gl_FragData #endif +vec3 srgb_to_linear(vec3 c); vec3 fullbrightAtmosTransport(vec3 light); vec3 fullbrightScaleSoftClip(vec3 light); @@ -47,6 +48,8 @@ void main() vec4 sunDiscA = texture2D(diffuseMap, vary_texcoord0.xy); vec4 sunDiscB = texture2D(altDiffuseMap, vary_texcoord0.xy); vec4 c = mix(sunDiscA, sunDiscB, blend_factor); + + c.rgb = srgb_to_linear(c.rgb); c.rgb = clamp(c.rgb, vec3(0), vec3(1)); c.rgb = pow(c.rgb, vec3(0.7f)); |