diff options
| author | Runitai Linden <davep@lindenlab.com> | 2020-03-05 16:28:06 -0600 | 
|---|---|---|
| committer | Runitai Linden <davep@lindenlab.com> | 2020-03-05 16:28:06 -0600 | 
| commit | 7c7d71269f5b47397d14bbe44e341e4ac1d96889 (patch) | |
| tree | ea9ff1c27a6e067d225929b2f28d637db32d20bf /indra/newview/app_settings/shaders/class1/deferred | |
| parent | 90ad38db065877be16371e7814a39618135a30ab (diff) | |
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.
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/deferred')
5 files changed, 34 insertions, 24 deletions
| diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 814d5036db..e38eeab370 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -251,7 +251,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; @@ -261,6 +261,11 @@ vec3 post_atmo = color.rgb;      vec4 light = vec4(0,0,0,0); +    color.rgb = scaleSoftClipFrag(color.rgb); +     +    //convert to linear before applying local lights +    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);      LIGHT_LOOP(1) @@ -275,9 +280,6 @@ vec3 post_atmo = color.rgb;  #if !defined(LOCAL_LIGHT_KILL)      color.rgb += light.rgb;  #endif - -    color.rgb = scaleSoftClipFrag(color.rgb); -      // back to sRGB as we're going directly to the final RT post-deferred gamma correction      color.rgb = linear_to_srgb(color.rgb); 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  diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index a690cc45a8..9bba45bc4e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -163,15 +163,19 @@ void main()  	proj_tc.xyz /= proj_tc.w;  	float fa = falloff+1.0; -	float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 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.0; +	  	if (dist_atten <= 0.0)  	{  		discard;  	} +	float noise = texture2D(noiseMap, frag.xy/128.0).b; +	dist_atten *= noise; +  	lv = proj_origin-pos.xyz;  	lv = normalize(lv);  	float da = dot(norm, lv); @@ -179,12 +183,13 @@ void main()  	vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb;      // SL-12005 Projector light pops as we get closer, more objectionable than being in wrong color space. -    //          We can't switch to linear here unless we do it everywhere -    //diff_tex.rgb = srgb_to_linear(diff_tex.rgb); +    //          We can't switch to linear here unless we do it everywhere* +	// *gbuffer is sRGB, convert to linear whenever sampling from it +    diff_tex.rgb = srgb_to_linear(diff_tex.rgb);  	vec3 dlit = vec3(0, 0, 0); -	float noise = texture2D(noiseMap, frag.xy/128.0).b; +	  	if (proj_tc.z > 0.0 &&  		proj_tc.x < 1.0 &&  		proj_tc.y < 1.0 && @@ -203,7 +208,7 @@ void main()  			dlit = color.rgb * plcol.rgb * plcol.a; -			lit = da * dist_atten * noise; +			lit = da * dist_atten;  			col = dlit*lit*diff_tex;  			amb_da += (da*0.5)*proj_ambiance; @@ -245,7 +250,7 @@ void main()  			col += dlit*scol*spec.rgb;  			//col += spec.rgb;  		} -	}	 +	}  	if (envIntensity > 0.0)  	{ @@ -277,6 +282,7 @@ void main()  	}  #endif +	//output linear, sum of lights will be gamma corrected later	  	frag_color.rgb = col;	  	frag_color.a = 0.0;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index 966c73ef24..cd37a34e0d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -43,6 +43,7 @@ vec3 linear_to_srgb(vec3 cl);  void main()   { +    //this is the one of the rare spots where diffuseRect contains linear color values (not sRGB)      vec4 diff = texture2DRect(diffuseRect, vary_fragcoord);      //diff.rgb = pow(diff.rgb, vec3(display_gamma));      diff.rgb = linear_to_srgb(diff.rgb); diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index da2eb47e3b..19e737326d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -119,7 +119,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; @@ -199,9 +199,6 @@ vec3 post_atmo = color.rgb;  //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);      }  // linear debuggables @@ -209,7 +206,9 @@ vec3 post_atmo = color.rgb;  //color.rgb = vec3(ambient);  //color.rgb = vec3(scol);  //color.rgb = diffuse_linear.rgb; -     -    frag_color.rgb = color.rgb; + +    // convert to linear as fullscreen lights need to sum in linear colorspace +    // and will be gamma (re)corrected downstream... +    frag_color.rgb = srgb_to_linear(color.rgb);      frag_color.a = 0.0; //bloom;  } | 
