diff options
Diffstat (limited to 'indra/newview/app_settings')
69 files changed, 1792 insertions, 1906 deletions
| diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index f0782e0bf7..c058d33e52 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -6617,6 +6617,17 @@        <key>Value</key>        <integer>0</integer>      </map> +    <key>MouseMoon</key> +    <map> +      <key>Comment</key> +      <string /> +      <key>Persist</key> +      <integer>0</integer> +      <key>Type</key> +      <string>Boolean</string> +      <key>Value</key> +      <integer>0</integer> +    </map>     <key>MuteAmbient</key>      <map>        <key>Comment</key> @@ -8653,7 +8664,7 @@      <key>Type</key>      <string>Boolean</string>      <key>Value</key> -    <integer>0</integer> +    <integer>1</integer>    </map>    <key>RenderLocalLights</key>    <map> @@ -10145,6 +10156,17 @@        <key>Value</key>        <integer>0</integer>      </map> +  <key>RenderUseAdvancedAtmospherics</key> +  <map> +    <key>Comment</key> +    <string>Use fancy precomputed atmospherics and stuff.</string> +    <key>Persist</key> +    <integer>1</integer> +    <key>Type</key> +    <string>Boolean</string> +    <key>Value</key> +    <integer>0</integer> +  </map>    <key>RenderUseTriStrips</key>    <map>      <key>Comment</key> diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index b9c8f34cb0..8dda96984e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -39,23 +39,11 @@ out vec4 frag_color;  uniform float display_gamma;  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;  uniform vec3 sun_dir; +uniform vec3 moon_dir;  #if HAS_SHADOW  uniform sampler2DShadow shadowMap0; @@ -84,12 +72,6 @@ VARYING vec3 vary_norm;  VARYING vec4 vertex_color;  #endif -vec3 vary_PositionEye; -vec3 vary_SunlitColor; -vec3 vary_AmblitColor; -vec3 vary_AdditiveColor; -vec3 vary_AtmosAttenuation; -  uniform mat4 inv_proj;  uniform vec2 screen_res; @@ -98,59 +80,20 @@ uniform vec3 light_direction[8];  uniform vec3 light_attenuation[8];   uniform vec3 light_diffuse[8]; -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); +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 color);  #endif -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); +vec2 encode_normal (vec3 n); +vec3 decode_normal (vec2 enc); -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; -} +vec3 scaleFragSoftClip(vec3 l); +vec3 atmosFragAmbient(vec3 light, vec3 sunlit); +vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); +vec3 atmosFragAffectDirectionalLight(float light, vec3 sunlit); +void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive);  vec3 calcDirectionalLight(vec3 n, vec3 l)  { @@ -219,237 +162,6 @@ float pcfShadow(sampler2DShadow shadowMap, vec4 stc)  }  #endif -#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 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; -}  void main()   { @@ -566,12 +278,20 @@ void main()  	vec3 norm = vary_norm;  -	calcAtmospherics(pos.xyz, 1.0); +        vec3 sunlit; +        vec3 amblit; +        vec3 additive; +        vec3 atten; + +	calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten);  	vec2 abnormal	= encode_normal(norm.xyz); -		 norm.xyz   = decode_normal(abnormal.xy); +	 norm.xyz   = decode_normal(abnormal.xy); + +	float da_sun = dot(norm.xyz, sun_dir.xyz); +	float da_moon = dot(norm.xyz, moon_dir.xyz); -	float da = dot(norm.xyz, sun_dir.xyz); +    float da = max(da_sun, da_moon);      float final_da = da;            final_da = min(final_da, shadow); @@ -581,7 +301,7 @@ void main()  	vec4 color = vec4(0,0,0,0); -	color.rgb = atmosAmbient(color.rgb); +	color.rgb = atmosFragAmbient(color.rgb, amblit);  	color.a   = final_alpha;  	float ambient = abs(da); @@ -590,13 +310,13 @@ void main()  	ambient = (1.0-ambient);  	color.rgb *= ambient; -	color.rgb += atmosAffectDirectionalLight(final_da); +	color.rgb += atmosFragAffectDirectionalLight(final_da, sunlit);  	color.rgb *= gamma_diff.rgb;  	//color.rgb = mix(diff.rgb, color.rgb, final_alpha); -	color.rgb = atmosLighting(color.rgb); -	color.rgb = scaleSoftClip(color.rgb); +	color.rgb = atmosFragLighting(color.rgb, additive, atten); +	color.rgb = scaleFragSoftClip(color.rgb);  	vec4 light = vec4(0,0,0,0); @@ -621,9 +341,8 @@ void main()  	color.rgb = linear_to_srgb(color.rgb);  #ifdef WATER_FOG -	color = applyWaterFogDeferred(pos.xyz, color); +	color = applyWaterFogView(pos.xyz, color);  #endif -  #endif  	frag_color = color; diff --git a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowF.glsl index 22c9a4d14e..8e9a5fcd41 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowF.glsl @@ -22,6 +22,8 @@   * $/LicenseInfo$   */ +/*[EXTRA_CODE_HERE]*/ +  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_color;  #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl index 662c762bca..60d83cc623 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl @@ -23,6 +23,8 @@   * $/LicenseInfo$   */ +/*[EXTRA_CODE_HERE]*/ +  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_data[3];  #else @@ -36,11 +38,7 @@ uniform float minimum_alpha;  VARYING vec3 vary_normal;  VARYING vec2 vary_texcoord0; -vec2 encode_normal(vec3 n) -{ -	float f = sqrt(8 * n.z + 8); -	return n.xy / f + 0.5; -} +vec2 encode_normal(vec3 n);  void main()   { diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl index b809b73973..8e46425ea8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl @@ -22,7 +22,9 @@   * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA   * $/LicenseInfo$   */ -  + +/*[EXTRA_CODE_HERE]*/  +  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_color;  #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index cbd8d2ebfc..b56abb66d1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -61,22 +61,7 @@ vec4 getPosition(vec2 pos_screen)  	return pos;  } -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; -} +vec3 decode_normal (vec2 enc);  void main()   { diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl index 58fb01d200..b5677a07ee 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl @@ -22,6 +22,8 @@   * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA   * $/LicenseInfo$   */ + +/*[EXTRA_CODE_HERE]*/  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_data[3]; @@ -40,11 +42,7 @@ VARYING vec3 vary_mat2;  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; -} +vec2 encode_normal(vec3 n);  void main()   { diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index 1d8ca04ccd..1a4cdff23d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -22,7 +22,7 @@   * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA   * $/LicenseInfo$   */ -  +/*[EXTRA_CODE_HERE]*/   #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_data[3]; @@ -39,6 +39,8 @@ VARYING vec4 vary_CloudColorAmbient;  VARYING float vary_CloudDensity;  uniform sampler2D cloud_noise_texture; +uniform sampler2D cloud_noise_texture_next; +uniform float blend_factor;  uniform vec4 cloud_pos_density1;  uniform vec4 cloud_pos_density2;  uniform vec4 gamma; @@ -57,6 +59,14 @@ vec3 scaleSoftClip(vec3 light) {  	return light;  } +vec4 cloudNoise(vec2 uv) +{ +   vec4 a = texture2D(cloud_noise_texture, uv); +   vec4 b = texture2D(cloud_noise_texture_next, uv); +   vec4 cloud_noise_sample = mix(a, b, blend_factor); +   return cloud_noise_sample; +} +  void main()  {  	// Set variables @@ -77,7 +87,7 @@ void main()  	// Compute alpha1, the main cloud opacity -	float alpha1 = (texture2D(cloud_noise_texture, uv1).x - 0.5) + (texture2D(cloud_noise_texture, uv3).x - 0.5) * cloud_pos_density2.z; +	float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z;  	alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10. * cloud_pos_density1.z, 1.);  	// And smooth @@ -87,7 +97,7 @@ void main()  	// Compute alpha2, for self shadowing effect  	// (1 - alpha2) will later be used as percentage of incoming sunlight -	float alpha2 = (texture2D(cloud_noise_texture, uv2).x - 0.5); +	float alpha2 = (cloudNoise(uv2).x - 0.5);  	alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.);  	// And smooth diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl index 7930b5d18b..b328ee9483 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl @@ -23,6 +23,8 @@   * $/LicenseInfo$   */ +/*[EXTRA_CODE_HERE]*/ +  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_data[3];  #else @@ -37,11 +39,7 @@ 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; -} +vec2 encode_normal(vec3 n);  void main()   { diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl index 8525e13333..fc5c86b4d6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl @@ -23,6 +23,8 @@   * $/LicenseInfo$   */ +/*[EXTRA_CODE_HERE]*/ +  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_data[3];  #else @@ -36,11 +38,7 @@ uniform float minimum_alpha;  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; -} +vec2 encode_normal(vec3 n);  void main()   { diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl index 37d70a2412..1bb8eb8bd0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl @@ -23,6 +23,7 @@   * $/LicenseInfo$   */ +/*[EXTRA_CODE_HERE]*/  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_data[3]; @@ -37,11 +38,7 @@ uniform sampler2D diffuseMap;  VARYING vec3 vary_normal;  VARYING vec2 vary_texcoord0; -vec2 encode_normal(vec3 n) -{ -	float f = sqrt(8 * n.z + 8); -	return n.xy / f + 0.5; -} +vec2 encode_normal(vec3 n);  void main()   { diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl index 6befb1bd8b..8319e61242 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl @@ -22,6 +22,8 @@   * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA   * $/LicenseInfo$   */ + +/*[EXTRA_CODE_HERE]*/  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_data[3]; @@ -35,11 +37,7 @@ 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; -} +vec2 encode_normal(vec3 n);  void main()   { diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl index adc361d7a2..828c325c9d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl @@ -23,6 +23,8 @@   * $/LicenseInfo$   */ +/*[EXTRA_CODE_HERE]*/ +  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_data[3];  #else @@ -33,12 +35,7 @@ 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; -} - +vec2 encode_normal(vec3 n);  void main()   { diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 756e625d07..134e9c3b4c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -41,43 +41,12 @@ VARYING vec3 vary_position;  VARYING vec4 vertex_color;  VARYING vec2 vary_texcoord0; - -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); +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 color);  #endif -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl);  vec3 fullbrightAtmosTransportDeferred(vec3 light)  { @@ -94,52 +63,6 @@ vec3 fullbrightScaleSoftClipDeferred(vec3 light)  uniform float minimum_alpha;  #endif -#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 -  void main()   {  #if HAS_DIFFUSE_LOOKUP @@ -166,7 +89,7 @@ void main()  #ifdef WATER_FOG  	vec3 pos = vary_position; -	vec4 fogged = applyWaterFogDeferred(pos, vec4(color.rgb, final_alpha)); +	vec4 fogged = applyWaterFogView(pos, vec4(color.rgb, final_alpha));  	color.rgb = fogged.rgb;  	color.a   = fogged.a;  #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl index b0db9876d3..30e560450b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl @@ -23,7 +23,7 @@   * $/LicenseInfo$   */ - +/*[EXTRA_CODE_HERE]*/  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_color; diff --git a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl index f8fdde43f9..6ba16b169c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl @@ -23,6 +23,8 @@   * $/LicenseInfo$   */ +/*[EXTRA_CODE_HERE]*/ +  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_data[3];  #else @@ -38,41 +40,7 @@ uniform sampler2D specularMap;  VARYING vec2 vary_texcoord0; -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) -{ -	float f = sqrt(8 * n.z + 8); -	return n.xy / f + 0.5; -} - -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 linear_to_srgb(vec3 cl);  void main()   { diff --git a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl index dcf474824d..be1003a7e0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl @@ -22,8 +22,8 @@   * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA   * $/LicenseInfo$   */ -  -uniform sampler2DRect diffuseMap; + +/*[EXTRA_CODE_HERE]*/  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_color; @@ -31,6 +31,7 @@ out vec4 frag_color;  #define frag_color gl_FragColor  #endif +uniform sampler2DRect diffuseMap;  VARYING vec2 vary_fragcoord;  void main()  diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 07d28ed4cd..4dc15dbc89 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 @@ -31,42 +33,18 @@  uniform float emissive_brightness;  uniform float display_gamma; -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); +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 color);  #endif -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); -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 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) @@ -116,34 +94,15 @@ 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;  uniform vec3 sun_dir; +uniform vec3 moon_dir;  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; @@ -152,52 +111,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); @@ -283,198 +196,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 @@ -515,22 +236,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()   { @@ -673,11 +380,18 @@ 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)); -	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); @@ -686,7 +400,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; @@ -695,7 +409,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; @@ -707,8 +421,11 @@ void main()  		// the old infinite-sky shiny reflection  		// -		float sa = dot(refnormpersp, sun_dir.xyz); -		vec3 dumbshiny = vary_SunlitColor*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); +		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  		vec3 spec_contrib = dumbshiny * spec.rgb; @@ -742,8 +459,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); @@ -771,7 +488,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 diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index 9974f8f31b..d1ac19270d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -57,22 +57,7 @@ uniform float far_z;  uniform mat4 inv_proj; -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; -} +vec3 decode_normal (vec2 enc);  vec4 getPosition(vec2 pos_screen)  { diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 3a3e871ade..1d75322b4c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -30,14 +30,14 @@  #extension GL_ARB_texture_rectangle : enable  #extension GL_ARB_shader_texture_lod : enable +/*[EXTRA_CODE_HERE]*/ +  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_color;  #else  #define frag_color gl_FragColor  #endif -/*[EXTRA_CODE_HERE]*/ -  uniform sampler2DRect diffuseRect;  uniform sampler2DRect specularRect;  uniform sampler2DRect depthMap; @@ -72,59 +72,9 @@ uniform vec2 screen_res;  uniform mat4 inv_proj; -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; -} -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 decode_normal (vec2 enc); +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/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index aba4a01754..13b803e03e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -56,22 +56,7 @@ uniform vec2 screen_res;  uniform mat4 inv_proj;  uniform vec4 viewport; -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; -} +vec3 decode_normal (vec2 enc);  vec4 getPosition(vec2 pos_screen)  { diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index 6669947d1b..cbc19bbba3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -40,25 +40,7 @@ VARYING vec2 vary_fragcoord;  uniform float display_gamma; -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 linear_to_srgb(vec3 cl);  void main()   { diff --git a/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl index 018ced4cad..e33254304b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl @@ -23,6 +23,8 @@   * $/LicenseInfo$   */ +/*[EXTRA_CODE_HERE]*/ +   #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_color;  #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendF.glsl new file mode 100644 index 0000000000..12bc690553 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendF.glsl @@ -0,0 +1,55 @@ +/**  + * @file shadowAlphaMaskF.glsl + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, 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]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2D diffuseMap; + +#if !DEPTH_CLAMP +VARYING float pos_zd2; +#endif + +VARYING float pos_w; + +VARYING float target_pos_x; +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; + +void main()  +{ +	float alpha = diffuseLookup(vary_texcoord0.xy).a * vertex_color.a; + +	frag_color = vec4(alpha, alpha, alpha, 1); +	 +#if !DEPTH_CLAMP +	gl_FragDepth = max(pos_zd2/pos_w+0.5, 0.0); +#endif +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendV.glsl new file mode 100644 index 0000000000..11411a605c --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendV.glsl @@ -0,0 +1,67 @@ +/**  + * @file shadowAlphaMaskV.glsl + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, 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$ + */ + +uniform mat4 texture_matrix0; +uniform mat4 modelview_projection_matrix; +uniform float shadow_target_width; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec4 diffuse_color; +ATTRIBUTE vec2 texcoord0; + +#if !DEPTH_CLAMP +VARYING float pos_zd2; +#endif + +VARYING float pos_w; + +VARYING float target_pos_x; +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; + +void passTextureIndex(); + +void main() +{ +	//transform vertex +	vec4 pre_pos = vec4(position.xyz, 1.0); +	vec4 pos = modelview_projection_matrix * pre_pos; +	target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; + +	pos_w = pos.w; + +#if !DEPTH_CLAMP +	pos_zd2 = pos.z * 0.5; +	 +	gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); +#else +	gl_Position = pos; +#endif +	 +	passTextureIndex(); + +	vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; +	vertex_color = diffuse_color; +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl index 91a96977f0..ae1b19a35c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl @@ -23,6 +23,8 @@   * $/LicenseInfo$   */ +/*[EXTRA_CODE_HERE]*/ +  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_color;  #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl index 3d1b182875..242aef821d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl @@ -23,6 +23,8 @@   * $/LicenseInfo$   */ +/*[EXTRA_CODE_HERE]*/ +  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_color;  #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index 22f4729e2e..8e4696cfaa 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -1,5 +1,5 @@  /**  - * @file WLSkyF.glsl + * @file class1/deferred/skyF.glsl   *   * $LicenseInfo:firstyear=2005&license=viewerlgpl$   * Second Life Viewer Source Code @@ -23,6 +23,8 @@   * $/LicenseInfo$   */ +/*[EXTRA_CODE_HERE]*/ +  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_data[3];  #else @@ -35,7 +37,6 @@ out vec4 frag_data[3];  VARYING vec4 vary_HazeColor; -uniform sampler2D cloud_noise_texture;  uniform vec4 gamma;  /// Soft clips the light with a gamma correction diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 03bdb754b5..a4543c325e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -51,83 +51,33 @@ 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 global_gamma; -uniform float scene_light_strength;  uniform mat3 env_mat;  uniform mat3 ssao_effect_mat;  uniform vec3 sun_dir; +uniform vec3 moon_dir;  VARYING vec2 vary_fragcoord; -vec3 vary_PositionEye; - -vec3 vary_SunlitColor; -vec3 vary_AmblitColor; -vec3 vary_AdditiveColor; -vec3 vary_AtmosAttenuation; -  uniform mat4 inv_proj;  uniform vec2 screen_res; -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); +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 color);  #endif -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); +vec3 decode_normal (vec2 enc); -vec3 linear_to_srgb(vec3 cl) -{ -	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)); +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 fullbrightFragAtmosTransport(vec3 l, vec3 additive, vec3 atten); +vec3 fullbrightScaleSoftClipFrag(vec3 l, vec3 atten); -#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 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; -} +void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten);  vec4 getPosition_d(vec2 pos_screen, float depth)  { @@ -147,243 +97,6 @@ vec4 getPosition(vec2 pos_screen)  	return getPosition_d(pos_screen, depth);  } -vec3 getPositionEye() -{ -	return vary_PositionEye; -} -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; -} - - -#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 - -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 fullbrightAtmosTransport(vec3 light) { -	float brightness = dot(light.rgb, vec3(0.33333)); - -	return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); -} - - - -vec3 atmosGetDiffuseSunlightColor() -{ -	return getSunlitColor(); -} - -vec3 scaleDownLight(vec3 light) -{ -	return (light / scene_light_strength ); -} - -vec3 scaleUpLight(vec3 light) -{ -	return (light * scene_light_strength); -} - -vec3 atmosAmbient(vec3 light) -{ -	return getAmblitColor() + light / 2.0; -} - -vec3 atmosAffectDirectionalLight(float lightIntensity) -{ -	return getSunlitColor() * lightIntensity; -} - -vec3 scaleSoftClip(vec3 light) -{ -	//soft clip effect: -	light = 1. - clamp(light, vec3(0.), vec3(1.)); -	light = 1. - pow(light, gamma.xxx); - -	return light; -} - - -vec3 fullbrightScaleSoftClip(vec3 light) -{ -	//soft clip effect: -	return light; -}  void main()   { @@ -394,10 +107,14 @@ void main()  	float envIntensity = norm.z;  	norm.xyz = decode_normal(norm.xy); // unpack norm -	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 = max(0.0,da); -          final_da = min(final_da, 1.0f); +              final_da = min(final_da, 1.0f); + +// why an ad hoc gamma boost here? srgb_to_linear instead?  	      final_da = pow(final_da, 1.0/1.3);  	vec4 diffuse = texture2DRect(diffuseRect, tc); @@ -409,9 +126,13 @@ void main()  	vec3 col;  	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); -		col = atmosAmbient(vec3(0)); +		col = atmosFragAmbient(vec3(0), amblit);  		float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0);  		ambient *= 0.5;  		ambient *= ambient; @@ -419,7 +140,7 @@ void main()  		col.rgb *= ambient; -		col += atmosAffectDirectionalLight(final_da);	 +		col += atmosFragAffectDirectionalLight(final_da, sunlit);  		col *= diffuse.rgb; @@ -430,8 +151,11 @@ void main()  			// the old infinite-sky shiny reflection  			// -			float sa = dot(refnormpersp, sun_dir.xyz); -			vec3 dumbshiny = vary_SunlitColor*(texture2D(lightFunc, vec2(sa, spec.a)).r); +			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*(texture2D(lightFunc, vec2(sa, spec.a)).r);  			// add the two types of shiny together  			vec3 spec_contrib = dumbshiny * spec.rgb; @@ -455,12 +179,12 @@ void main()  		if (norm.w < 0.5)  		{ -			col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); -			col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); +			col = mix(atmosFragLighting(col, additive, atten), fullbrightFragAtmosTransport(col, atten, additive), diffuse.a); +			col = mix(scaleFragSoftClip(col), fullbrightScaleSoftClipFrag(col, atten), diffuse.a);  		}  		#ifdef WATER_FOG -			vec4 fogged = applyWaterFogDeferred(pos,vec4(col, bloom)); +			vec4 fogged = applyWaterFogView(pos,vec4(col, bloom));  			col = fogged.rgb;  			bloom = fogged.a;  		#endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index f1aec315cc..2b6428963d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -70,59 +70,9 @@ uniform vec2 screen_res;  uniform mat4 inv_proj; -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; -} - -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 decode_normal (vec2 enc); +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl);  vec4 correctWithGamma(vec4 col)  { diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl index 821058804c..029a98e16a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl @@ -23,6 +23,8 @@   * $/LicenseInfo$   */ +/*[EXTRA_CODE_HERE]*/ +  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_data[3];  #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl index 930255729b..403df87853 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl @@ -51,22 +51,7 @@ VARYING vec2 vary_fragcoord;  uniform mat4 inv_proj;  uniform vec2 screen_res; -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; -} +vec3 decode_normal (vec2 enc);  vec4 getPosition(vec2 pos_screen)  { diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl index 52a429465f..0cd90b0d97 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl @@ -23,6 +23,8 @@   * $/LicenseInfo$   */ +/*[EXTRA_CODE_HERE]*/ +  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_data[3];  #else @@ -39,11 +41,7 @@ VARYING vec3 vary_normal;  VARYING vec4 vary_texcoord0;  VARYING vec4 vary_texcoord1; -vec2 encode_normal(vec3 n) -{ -	float f = sqrt(8 * n.z + 8); -	return n.xy / f + 0.5; -} +vec2 encode_normal(vec3 n);  void main()  { diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl index 808750496f..89e354558a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl @@ -23,6 +23,8 @@   * $/LicenseInfo$   */ +/*[EXTRA_CODE_HERE]*/ +  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_data[3];  #else @@ -37,11 +39,7 @@ VARYING vec2 vary_texcoord0;  uniform float minimum_alpha; -vec2 encode_normal(vec3 n) -{ -	float f = sqrt(8 * n.z + 8); -	return n.xy / f + 0.5; -} +vec2 encode_normal(vec3 n);  void main()   { diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeShadowF.glsl index d4d2f5f571..e34d75ba1d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/treeShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeShadowF.glsl @@ -23,6 +23,8 @@   * $/LicenseInfo$   */ +/*[EXTRA_CODE_HERE]*/ +  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_color;  #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl index 78f841c733..3a8565ee38 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl @@ -23,6 +23,8 @@   * $/LicenseInfo$   */ +/*[EXTRA_CODE_HERE]*/ +  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_data[3];  #else @@ -56,48 +58,10 @@ VARYING vec4 refCoord;  VARYING vec4 littleWave;  VARYING vec4 view; -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); -} - -vec2 encode_normal(vec3 n) -{ -	float f = sqrt(8 * n.z + 8); -	return n.xy / f + 0.5; -} +vec2 encode_normal(vec3 n);  vec4 applyWaterFog(vec4 color, vec3 viewVec)  { diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 37dcd3ad34..98c5030a04 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -37,6 +37,8 @@ vec3 scaleSoftClip(vec3 inColor);  vec3 atmosTransport(vec3 inColor);  uniform sampler2D bumpMap;    +uniform sampler2D bumpMap2; +uniform float blend_factor;  uniform sampler2D screenTex;  uniform sampler2D refTex;  uniform sampler2DRectShadow shadowMap0; @@ -69,47 +71,16 @@ VARYING vec4 littleWave;  VARYING vec4 view;  VARYING vec4 vary_position; -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 srgb_to_linear(vec3 cs); +vec2 encode_normal(vec3 n); -vec3 linear_to_srgb(vec3 cl) +vec3 BlendNormal(vec3 bump1, vec3 bump2)  { -	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 - -} - -vec2 encode_normal(vec3 n) -{ -	float f = sqrt(8 * n.z + 8); -	return n.xy / f + 0.5; +    //vec3 normal   = bump1.xyz * vec3( 2.0,  2.0, 2.0) - vec3(1.0, 1.0,  0.0); +    //vec3 normal2  = bump2.xyz * vec3(-2.0, -2.0, 2.0) + vec3(1.0, 1.0, -1.0); +    //vec3 n        = normalize(normal * dot(normal, normal2) - (normal2 * normal.z)); +    vec3 n = normalize(mix(bump1, bump2, blend_factor)); +    return n;  }  void main()  @@ -121,9 +92,19 @@ void main()  	vec3 viewVec = normalize(view.xyz);  	//get wave normals -	vec3 wave1 = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; -	vec3 wave2 = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; -	vec3 wave3 = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; +	vec3 wave1_a = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; +	vec3 wave2_a = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; +	vec3 wave3_a = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; + + +	vec3 wave1_b = texture2D(bumpMap2, vec2(refCoord.w, view.w)).xyz*2.0-1.0; +	vec3 wave2_b = texture2D(bumpMap2, littleWave.xy).xyz*2.0-1.0; +	vec3 wave3_b = texture2D(bumpMap2, littleWave.zw).xyz*2.0-1.0; + +    vec3 wave1 = BlendNormal(wave1_a, wave1_b); +    vec3 wave2 = BlendNormal(wave2_a, wave2_b); +    vec3 wave3 = BlendNormal(wave3_a, wave3_b); +  	//get base fresnel components	  	vec3 df = vec3( diff --git a/indra/newview/app_settings/shaders/class1/environment/decodeNormF.glsl b/indra/newview/app_settings/shaders/class1/environment/decodeNormF.glsl new file mode 100644 index 0000000000..becc6d89c1 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/environment/decodeNormF.glsl @@ -0,0 +1,36 @@ +/** + * @file decodeNormF.glsl + * + * $LicenseInfo:firstyear=2018&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2018, 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$ + */ + +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; +} + diff --git a/indra/newview/app_settings/shaders/class1/environment/encodeNormF.glsl b/indra/newview/app_settings/shaders/class1/environment/encodeNormF.glsl new file mode 100644 index 0000000000..50e781fa78 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/environment/encodeNormF.glsl @@ -0,0 +1,31 @@ +/** + * @file encodeNormF.glsl + * + * $LicenseInfo:firstyear=2018&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2018, 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$ + */ + +vec2 encode_normal(vec3 n) +{ +	float f = sqrt(8 * n.z + 8); +	return n.xy / f + 0.5; +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/srgb_mac.glsl b/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl index 6cc1e6e798..835662732a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/srgb_mac.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl @@ -1,5 +1,5 @@  /**  - * @file srgb.glsl + * @file srgbF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -27,14 +27,18 @@ 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) @@ -42,13 +46,17 @@ 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; +    return result; +#else +	return mix(high_range, low_range, lt); +#endif +  } diff --git a/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl index 0d8dab0a41..e918bdcb9d 100644 --- a/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl @@ -56,41 +56,7 @@ VARYING vec4 refCoord;  VARYING vec4 littleWave;  VARYING vec4 view; -vec4 applyWaterFog(vec4 color, vec3 viewVec) -{ -	//normalize view vector -	vec3 view = normalize(viewVec); -	float es = -view.z; - -	//find intersection point with water plane and eye vector -	 -	//get eye depth -	float e0 = max(-waterPlane.w, 0.0); -	 -	//get object depth -	float depth = length(viewVec); -		 -	//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); -	//return vec4(1.0, 0.0, 1.0, 1.0); -	return color * D + kc * L; -	//depth /= 10.0; -	//return vec4(depth,depth,depth,0.0); -} +vec4 applyWaterFogView(vec3 pos, vec4 color);  void main()   { @@ -108,5 +74,5 @@ void main()  	vec4 fb = texture2D(screenTex, distort); -	frag_color = applyWaterFog(fb,view.xyz); +	frag_color = applyWaterFogView(view.xyz, fb);  } diff --git a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl index 79bffab745..37f109c637 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl @@ -33,6 +33,8 @@ vec3 scaleSoftClip(vec3 inColor);  vec3 atmosTransport(vec3 inColor);  uniform sampler2D bumpMap;    +uniform sampler2D bumpMap2; +uniform float     blend_factor;  uniform sampler2D screenTex;  uniform sampler2D refTex; @@ -55,6 +57,15 @@ VARYING vec4 refCoord;  VARYING vec4 littleWave;  VARYING vec4 view; +vec3 BlendNormal(vec3 bump1, vec3 bump2) +{ +    //vec3 normal   = bump1.xyz * vec3( 2.0,  2.0, 2.0) - vec3(1.0, 1.0,  0.0); +    //vec3 normal2  = bump2.xyz * vec3(-2.0, -2.0, 2.0) + vec3(1.0, 1.0, -1.0); +    //vec3 n        = normalize(normal * dot(normal, normal2) - (normal2 * normal.z)); +    vec3 n = normalize(mix(bump1, bump2, blend_factor)); +    return n; +} +  void main()   {  	vec4 color; @@ -65,9 +76,18 @@ void main()  	vec3 viewVec = normalize(view.xyz);  	//get wave normals -	vec3 wave1 = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; -	vec3 wave2 = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; -	vec3 wave3 = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; +	vec3 wave1_a = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; +	vec3 wave2_a = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; +	vec3 wave3_a = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; + +	vec3 wave1_b = texture2D(bumpMap2, vec2(refCoord.w, view.w)).xyz*2.0-1.0; +	vec3 wave2_b = texture2D(bumpMap2, littleWave.xy).xyz*2.0-1.0; +	vec3 wave3_b = texture2D(bumpMap2, littleWave.zw).xyz*2.0-1.0; + +	vec3 wave1 = BlendNormal(wave1_a, wave1_b); +	vec3 wave2 = BlendNormal(wave2_a, wave2_b); +	vec3 wave3 = BlendNormal(wave3_a, wave3_b); +  	//get base fresnel components	  	vec3 df = vec3( diff --git a/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl index 4bdfce9260..68ce2843d0 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl @@ -25,7 +25,6 @@ -uniform vec4 lightnorm;  uniform vec4 waterPlane;  uniform vec4 waterFogColor;  uniform float waterFogDensity; @@ -33,10 +32,10 @@ uniform float waterFogKS;  vec3 getPositionEye(); -vec4 applyWaterFog(vec4 color) +vec4 applyWaterFogView(vec3 pos, vec4 color)  { +	vec3 view = normalize(pos);  	//normalize view vector -	vec3 view = normalize(getPositionEye());  	float es = -(dot(view, waterPlane.xyz));  	//find intersection point with water plane and eye vector @@ -47,7 +46,7 @@ vec4 applyWaterFog(vec4 color)  	vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0);  	//get object depth -	float depth = length(getPositionEye() - int_v); +	float depth = length(pos - int_v);  	//get "thickness" of water  	float l = max(depth, 0.1); @@ -72,3 +71,9 @@ vec4 applyWaterFog(vec4 color)  	return color;  } +vec4 applyWaterFog(vec4 color) +{ +	//normalize view vector +        return applyWaterFogView(getPositionEye(), color); +} + diff --git a/indra/newview/app_settings/shaders/class1/interface/glowcombineF.glsl b/indra/newview/app_settings/shaders/class1/interface/glowcombineF.glsl index 5c088b3a3c..b5bbbb5c73 100644 --- a/indra/newview/app_settings/shaders/class1/interface/glowcombineF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/glowcombineF.glsl @@ -25,14 +25,14 @@  #extension GL_ARB_texture_rectangle : enable +/*[EXTRA_CODE_HERE]*/ +  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_color;  #else  #define frag_color gl_FragColor  #endif -/*[EXTRA_CODE_HERE]*/ -  uniform sampler2D glowMap;  uniform sampler2DRect screenMap; diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl index aacc503e13..584bd568c5 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl @@ -31,3 +31,8 @@ vec3 atmosLighting(vec3 light)  	return light;  } + +void calcFragAtmospherics(vec3 inPositionEye, float ambFactor) { +	/* stub function for fallback compatibility on class1 hardware */ +} + diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl new file mode 100644 index 0000000000..3f70a8935b --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl @@ -0,0 +1,55 @@ +/**  + * @file atmosphericsHelpersF.glsl  + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ +  +uniform vec4 sunlight_color; +uniform vec4 light_ambient; + +vec3 atmosAmbient(vec3 light) +{ +	return light + light_ambient.rgb; +} + +vec3 atmosAffectDirectionalLight(float lightIntensity) +{ +	return sunlight_color.rgb * lightIntensity; +} + +vec3 atmosGetDiffuseSunlightColor() +{ +	return sunlight_color.rgb; +} + +vec3 scaleDownLight(vec3 light) +{ +	/* stub function for fallback compatibility on class1 hardware */ +	return light; +} + +vec3 scaleUpLight(vec3 light) +{ +	/* stub function for fallback compatibility on class1 hardware */ +	return light; +} + diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl index 6ff860362c..89b6a52909 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl @@ -23,7 +23,7 @@   * $/LicenseInfo$   */ -uniform vec4 sunlight_color_copy; +uniform vec4 sunlight_color;  uniform vec4 light_ambient;  vec3 atmosAmbient(vec3 light) @@ -33,12 +33,12 @@ vec3 atmosAmbient(vec3 light)  vec3 atmosAffectDirectionalLight(float lightIntensity)  { -	return sunlight_color_copy.rgb * lightIntensity; +	return sunlight_color.rgb * lightIntensity;  }  vec3 atmosGetDiffuseSunlightColor()  { -	return sunlight_color_copy.rgb; +	return sunlight_color.rgb;  }  vec3 scaleDownLight(vec3 light) diff --git a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl new file mode 100644 index 0000000000..4d0d8882b9 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl @@ -0,0 +1,63 @@ +/**  + * @file moonF.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ +  +#extension GL_ARB_texture_rectangle : enable + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +vec3 fullbrightAtmosTransport(vec3 light); +vec3 fullbrightScaleSoftClip(vec3 light); + +uniform vec4 color; +uniform vec4 sunlight_color; +uniform vec3 lumWeights; +uniform float minLuminance; +uniform sampler2D diffuseMap; +uniform sampler2D altDiffuseMap; +uniform float blend_factor; // interp factor between moon A/B +VARYING vec2 vary_texcoord0; + +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 = fullbrightAtmosTransport(c.rgb); +    c.rgb = fullbrightScaleSoftClip(c.rgb); +    c.rgb = pow(c.rgb, vec3(0.45f)); +    // mix factor which blends when sunlight is brighter +    // and shows true moon color at night +    float mix = dot(normalize(sunlight_color.rgb), lumWeights); +    mix = smoothstep(-0.5f, 2.0f, mix); +	frag_color = vec4(c.rgb, mix * c.a); +} + diff --git a/indra/newview/app_settings/shaders/class1/windlight/moonV.glsl b/indra/newview/app_settings/shaders/class1/windlight/moonV.glsl new file mode 100644 index 0000000000..7c4dfbd999 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/windlight/moonV.glsl @@ -0,0 +1,48 @@ +/**  + * @file moonV.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$ + */ + +uniform mat4 texture_matrix0; +uniform mat4 modelview_matrix; +uniform mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec2 texcoord0; + +//void calcAtmospherics(vec3 inPositionEye); + +VARYING vec2 vary_texcoord0; + +void main() +{ +	//transform vertex +	vec4 vert = vec4(position.xyz, 1.0); +	vec4 pos = (modelview_matrix * vert); + +	gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); +	 +	vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; +	 +	//calcAtmospherics(pos.xyz); +} diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index b9bb522842..864ba4859d 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -71,59 +71,9 @@ uniform vec2 screen_res;  uniform mat4 inv_proj; -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 - -} - -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; -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); +vec3 decode_normal (vec2 enc);  vec4 correctWithGamma(vec4 col)  { diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index f7832521fa..5046ede00d 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -49,7 +49,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; @@ -68,71 +67,23 @@ uniform vec4 shadow_clip;  uniform mat3 ssao_effect_mat;  uniform vec3 sun_dir; +uniform vec3 moon_dir;  VARYING vec2 vary_fragcoord; -vec3 vary_PositionEye; - -vec3 vary_SunlitColor; -vec3 vary_AmblitColor; -vec3 vary_AdditiveColor; -vec3 vary_AtmosAttenuation; -  uniform mat4 inv_proj;  uniform vec2 screen_res; -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 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); +vec3 decode_normal (vec2 enc); -} - -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 - -} - -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; -} +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); +vec3 fullbrightFragAtmosTransport(vec3 l, vec3 additive, vec3 atten); +vec3 fullbrightScaleSoftClipFrag(vec3 l, vec3 atten);  vec4 getPosition_d(vec2 pos_screen, float depth)  { @@ -152,247 +103,11 @@ vec4 getPosition(vec2 pos_screen)  	return getPosition_d(pos_screen, depth);  } -vec3 getPositionEye() -{ -	return vary_PositionEye; -} -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(pow(vec3(sunlight * .5), vec3(global_gamma)) * global_gamma); -	setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(global_gamma)) * global_gamma); -	setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(global_gamma)) * global_gamma);*/ - -	setSunlitColor(vec3(sunlight * .5)); -	setAmblitColor(vec3(tmpAmbient * .25)); -	setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); -}  #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; -} +vec4 applyWaterFogView(vec3 pos, vec4 color);  #endif -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 fullbrightAtmosTransport(vec3 light) { -	float brightness = dot(light.rgb, vec3(0.33333)); - -	return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); -} - - - -vec3 atmosGetDiffuseSunlightColor() -{ -	return getSunlitColor(); -} - -vec3 scaleDownLight(vec3 light) -{ -	return (light / scene_light_strength ); -} - -vec3 scaleUpLight(vec3 light) -{ -	return (light * scene_light_strength); -} - -vec3 atmosAmbient(vec3 light) -{ -	return getAmblitColor() + light / 2.0; -} - -vec3 atmosAffectDirectionalLight(float lightIntensity) -{ -	return getSunlitColor() * lightIntensity; -} - -vec3 scaleSoftClip(vec3 light) -{ -	//soft clip effect: -	light = 1. - clamp(light, vec3(0.), vec3(1.)); -	light = 1. - pow(light, gamma.xxx); - -	return light; -} - - -vec3 fullbrightScaleSoftClip(vec3 light) -{ -	//soft clip effect: -	return light; -} -  void main()   {  	vec2 tc = vary_fragcoord.xy; @@ -402,7 +117,9 @@ void main()  	float envIntensity = norm.z;  	norm.xyz = decode_normal(norm.xy); // unpack norm -	float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); +	float da_sun = max(dot(norm.xyz, sun_dir.xyz), 0.0); +	float da_moon = max(dot(norm.xyz, moon_dir.xyz), 0.0); +	float da = max(da_sun, da_moon);  	float light_gamma = 1.0/1.3;  	da = pow(da, light_gamma); @@ -426,10 +143,15 @@ void main()  		float ambocc = scol_ambocc.g; + +                vec3 sunlit; +                vec3 amblit; +                vec3 additive; +                vec3 atten; -		calcAtmospherics(pos.xyz, ambocc); +		calcFragAtmospherics(pos.xyz, ambocc, sunlit, amblit, additive, atten); -		col = atmosAmbient(vec3(0)); +		col = atmosFragAmbient(vec3(0), amblit);  		float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0);  		ambient *= 0.5;  		ambient *= ambient; @@ -437,7 +159,7 @@ void main()  		col.rgb *= ambient; -		col += atmosAffectDirectionalLight(max(min(da, scol), 0.0)); +		col += atmosFragAffectDirectionalLight(max(min(da, scol), 0.0), sunlit);  		col *= diffuse.rgb; @@ -448,8 +170,10 @@ void main()  			// the old infinite-sky shiny reflection  			// -			float sa = dot(refnormpersp, sun_dir.xyz); -			vec3 dumbshiny = vary_SunlitColor*scol_ambocc.r*(texture2D(lightFunc, vec2(sa, spec.a)).r); +			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*scol_ambocc.r*(texture2D(lightFunc, vec2(sa, spec.a)).r);  			// add the two types of shiny together  			vec3 spec_contrib = dumbshiny * spec.rgb; @@ -473,12 +197,12 @@ void main()  		if (norm.w < 0.5)  		{ -			col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); -			col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); +			col = mix(atmosFragLighting(col, additive, atten), fullbrightFragAtmosTransport(col, atten, additive), diffuse.a); +			col = mix(scaleFragSoftClip(col), fullbrightScaleSoftClipFrag(col, atten), diffuse.a);  		}  		#ifdef WATER_FOG -			vec4 fogged = applyWaterFogDeferred(pos,vec4(col, bloom)); +			vec4 fogged = applyWaterFogView(pos,vec4(col, bloom));  			col = fogged.rgb;  			bloom = fogged.a;  		#endif diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 81af1fdc8a..a7da140b31 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -71,59 +71,9 @@ uniform vec2 screen_res;  uniform mat4 inv_proj; -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; -} - -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 decode_normal (vec2 enc); +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl);  vec4 correctWithGamma(vec4 col)  { @@ -238,8 +188,8 @@ 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 fa = falloff + 1.0; +	float dist_atten = min(1.0 - (dist - 1.0 * (1.0 - fa)) / fa, 1.0);  	dist_atten *= dist_atten;  	dist_atten *= 2.0; diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl index 265da8df99..11ccdf638c 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl @@ -59,6 +59,7 @@ uniform mat4 inv_proj;  uniform vec2 screen_res;  uniform vec2 proj_shadow_res;  uniform vec3 sun_dir; +uniform vec3 moon_dir;  uniform vec2 shadow_res;  uniform float shadow_bias; @@ -67,22 +68,7 @@ uniform float shadow_offset;  uniform float spot_shadow_bias;  uniform float spot_shadow_offset; -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; -} +vec3 decode_normal (vec2 enc);  vec4 getPosition(vec2 pos_screen)  { @@ -154,10 +140,14 @@ void main()  	}*/  	float shadow = 0.0; -	float dp_directional_light = max(0.0, dot(norm, sun_dir.xyz)); +    float da_sun = dot(norm, sun_dir.xyz); +    float da_moon = dot(norm, moon_dir.xyz); +    float da = max(da_sun, da_moon); + +	float dp_directional_light = max(0.0, da);  	vec3 shadow_pos = pos.xyz; -	vec3 offset = sun_dir.xyz * (1.0-dp_directional_light); +	vec3 offset = ((da_sun > da_moon) ? sun_dir.xyz  : moon_dir.xyz) * (1.0-dp_directional_light);  	vec4 spos = vec4(shadow_pos+offset*shadow_offset, 1.0); diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl index 5c6fe30daa..4fccb1d33c 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl @@ -59,6 +59,7 @@ uniform mat4 inv_proj;  uniform vec2 screen_res;  uniform vec2 proj_shadow_res;  uniform vec3 sun_dir; +uniform vec3 moon_dir;  uniform vec2 shadow_res; @@ -68,22 +69,7 @@ uniform float shadow_offset;  uniform float spot_shadow_bias;  uniform float spot_shadow_offset; -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; -} +vec3 decode_normal (vec2 enc);  vec4 getPosition(vec2 pos_screen)  { @@ -215,10 +201,13 @@ void main()  	}*/  	float shadow = 0.0; -	float dp_directional_light = max(0.0, dot(norm, sun_dir.xyz)); +    float da_sun = dot(norm, sun_dir.xyz); +    float da_moon = dot(norm, moon_dir.xyz); +    float da = max(da_sun, da_moon); +	float dp_directional_light = max(0.0, da);  	vec3 shadow_pos = pos.xyz; -	vec3 offset = sun_dir.xyz * (1.0-dp_directional_light); +	vec3 offset = ((da_sun > da_moon) ? sun_dir.xyz : moon_dir.xyz) * (1.0-dp_directional_light);  	vec4 spos = vec4(shadow_pos+offset*shadow_offset, 1.0); diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index fea3cbf69b..fee1a7f311 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -22,23 +22,127 @@   * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA   * $/LicenseInfo$   */ -  - - -////////////////////////////////////////////////////////// -// The fragment shader for the terrain atmospherics -//////////////////////////////////////////////////////////  vec3 getAdditiveColor();  vec3 getAtmosAttenuation();  uniform sampler2D cloudMap; +uniform vec4 gamma;  uniform vec4 cloud_pos_density1; +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 ssao_effect_mat; -vec3 atmosLighting(vec3 light) +vec3 scaleFragSoftClip(vec3 light) +{ +	//soft clip effect: +	light = 1. - clamp(light, vec3(0.), vec3(1.)); +	light = 1. - pow(light, gamma.xxx); +	return light; +} + +vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten)  { -	light *= getAtmosAttenuation().r; -	light += getAdditiveColor(); +	light *= atten.r; +	light += additive;  	return (2.0 * light);  } +vec3 atmosLighting(vec3 light) +{ +    return atmosFragLighting(light, getAdditiveColor(), getAtmosAttenuation()); +} + +void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { + +	vec3 P = inPositionEye; +	 +	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 +	atten = 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 +        additive = +		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 +	sunlit = vec3(sunlight * .5); +	amblit = vec3(tmpAmbient * .25); +	additive *= vec3(1.0 - temp1); +} + diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl new file mode 100644 index 0000000000..3582759e62 --- /dev/null +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl @@ -0,0 +1,49 @@ +/** + * @file atmosphericsHelpersV.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ + +// Output variables + +uniform float scene_light_strength; + +vec3 atmosFragAmbient(vec3 light, vec3 amblit) +{ +	return amblit + light / 2.0; +} + +vec3 atmosFragAffectDirectionalLight(float lightIntensity, vec3 sunlit) +{ +	return sunlit * lightIntensity; +} + +vec3 scaleDownLightFrag(vec3 light) +{ +	return (light / scene_light_strength ); +} + +vec3 scaleUpLightFrag(vec3 light) +{ +	return (light * scene_light_strength); +} + diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl index 96c70651b1..e0c7e18a6f 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl @@ -42,6 +42,8 @@ VARYING vec2 vary_texcoord2;  VARYING vec2 vary_texcoord3;  uniform sampler2D cloud_noise_texture; +uniform sampler2D cloud_noise_texture_next; +uniform float blend_factor;  uniform vec4 cloud_pos_density1;  uniform vec4 cloud_pos_density2;  uniform vec4 gamma; @@ -55,6 +57,14 @@ vec3 scaleSoftClip(vec3 light) {  	return light;  } +vec4 cloudNoise(vec2 uv) +{ +    vec4 a = texture2D(cloud_noise_texture, uv); +    vec4 b = texture2D(cloud_noise_texture_next, uv); +    vec4 samp = mix(a, b, blend_factor); +	return samp; +} +  void main()  {  	// Set variables @@ -75,7 +85,7 @@ void main()  	// Compute alpha1, the main cloud opacity -	float alpha1 = (texture2D(cloud_noise_texture, uv1).x - 0.5) + (texture2D(cloud_noise_texture, uv3).x - 0.5) * cloud_pos_density2.z; +	float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z;  	alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10. * cloud_pos_density1.z, 1.);  	// And smooth @@ -85,7 +95,7 @@ void main()  	// Compute alpha2, for self shadowing effect  	// (1 - alpha2) will later be used as percentage of incoming sunlight -	float alpha2 = (texture2D(cloud_noise_texture, uv2).x - 0.5); +	float alpha2 = (cloudNoise(uv2).x - 0.5);  	alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.);  	// And smooth diff --git a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl index 478373d729..2db633cd01 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl @@ -38,7 +38,12 @@ vec3 scaleSoftClip(vec3 light) {  	return light;  } +vec3 fullbrightScaleSoftClipFrag(vec3 light, vec3 atten) +{ +	return mix(scaleSoftClip(light.rgb), light.rgb, atten); +} +  vec3 fullbrightScaleSoftClip(vec3 light) { -	return mix(scaleSoftClip(light.rgb), light.rgb, getAtmosAttenuation()); +	return fullbrightScaleSoftClipFrag(light.rgb, getAtmosAttenuation());  } diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl index e2a2367626..25fd0584f8 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl @@ -1,5 +1,5 @@  /**  - * @file WLSkyF.glsl + * @file class2/windlight/skyF.glsl   *   * $LicenseInfo:firstyear=2005&license=viewerlgpl$   * Second Life Viewer Source Code @@ -35,7 +35,6 @@ out vec4 frag_color;  VARYING vec4 vary_HazeColor; -uniform sampler2D cloud_noise_texture;  uniform vec4 gamma;  /// Soft clips the light with a gamma correction diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index 8a8e4cb0f6..82e1d7fe35 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -33,21 +33,30 @@ vec3 getAtmosAttenuation();  uniform sampler2D cloudMap;  uniform vec4 cloud_pos_density1; -vec3 atmosTransport(vec3 light) { -	light *= getAtmosAttenuation().r; -	light += getAdditiveColor() * 2.0; +vec3 atmosFragTransport(vec3 light, vec3 atten, vec3 additive) { +	light *= atten.r; +	light += additive * 2.0;  	return light;  } -vec3 fullbrightAtmosTransport(vec3 light) { +vec3 fullbrightFragAtmosTransport(vec3 light, vec3 atten, vec3 additive) {  	float brightness = dot(light.rgb, vec3(0.33333)); - -	return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); +	return mix(atmosFragTransport(light.rgb, atten, additive), light.rgb + additive.rgb, brightness * brightness);  } -vec3 fullbrightShinyAtmosTransport(vec3 light) { +vec3 fullbrightFragShinyAtmosTransport(vec3 light, vec3 atten, vec3 additive) {  	float brightness = dot(light.rgb, vec3(0.33333)); +	return mix(atmosFragTransport(light.rgb, atten, additive), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); +} -	return mix(atmosTransport(light.rgb), (light.rgb + getAdditiveColor().rgb) * (2.0 - brightness), brightness * brightness); +vec3 atmosTransport(vec3 light) { +     return atmosFragTransport(light, getAtmosAttenuation(), getAdditiveColor());  } +vec3 fullbrightAtmosTransport(vec3 light) { +     return fullbrightFragAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); +} + +vec3 fullbrightShinyAtmosTransport(vec3 light) { +    return fullbrightFragShinyAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl new file mode 100644 index 0000000000..44b41cc0b8 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl @@ -0,0 +1,115 @@ +/**  + * @file WLCloudsF.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ +  +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +///////////////////////////////////////////////////////////////////////// +// The fragment shader for the sky +///////////////////////////////////////////////////////////////////////// + +VARYING vec4 vary_CloudColorSun; +VARYING vec4 vary_CloudColorAmbient; +VARYING float vary_CloudDensity; +VARYING vec2 vary_texcoord0; +VARYING vec2 vary_texcoord1; +VARYING vec2 vary_texcoord2; +VARYING vec2 vary_texcoord3; + +uniform sampler2D cloud_noise_texture; +uniform sampler2D cloud_noise_texture_next; +uniform float blend_factor; +uniform vec4 cloud_pos_density1; +uniform vec4 cloud_pos_density2; +uniform vec4 gamma; + +vec4 cloudNoise(vec2 uv) +{ +	vec4 a = texture2D(cloud_noise_texture, uv); +	vec4 b = texture2D(cloud_noise_texture_next, uv); +    vec4 samp = mix(a, b, blend_factor); +	return samp; +} + + +/// Soft clips the light with a gamma correction +vec3 scaleSoftClip(vec3 light) { +	//soft clip effect: +	light = 1. - clamp(light, vec3(0.), vec3(1.)); +	light = 1. - pow(light, gamma.xxx); + +	return light; +} + +void main() +{ +	// Set variables +	vec2 uv1 = vary_texcoord0.xy; +	vec2 uv2 = vary_texcoord1.xy; + +	vec4 cloudColorSun = vary_CloudColorSun; +	vec4 cloudColorAmbient = vary_CloudColorAmbient; +	float cloudDensity = vary_CloudDensity; +	vec2 uv3 = vary_texcoord2.xy; +	vec2 uv4 = vary_texcoord3.xy; + +	// Offset texture coords +	uv1 += cloud_pos_density1.xy;	//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 + + +	// Compute alpha1, the main cloud opacity +	float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; +	alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10. * cloud_pos_density1.z, 1.); + +	// And smooth +	alpha1 = 1. - alpha1 * alpha1; +	alpha1 = 1. - alpha1 * alpha1;	 + + +	// Compute alpha2, for self shadowing effect +	// (1 - alpha2) will later be used as percentage of incoming sunlight +	float alpha2 = (cloudNoise(uv2).x - 0.5); +	alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); + +	// And smooth +	alpha2 = 1. - alpha2; +	alpha2 = 1. - alpha2 * alpha2;	 + +	// Combine +	vec4 color; +	color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); +	color *= 2.; + +	/// Gamma correct for WL (soft clip effect). +	frag_color.rgb = scaleSoftClip(color.rgb); +	frag_color.a = alpha1; +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl new file mode 100644 index 0000000000..c1dd45cd67 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl @@ -0,0 +1,190 @@ +/**  + * @file WLCloudsV.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ + +uniform mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec2 texcoord0; + +////////////////////////////////////////////////////////////////////////// +// The vertex shader for creating the atmospheric sky +/////////////////////////////////////////////////////////////////////////////// + +// Output parameters +VARYING vec4 vary_CloudColorSun; +VARYING vec4 vary_CloudColorAmbient; +VARYING float vary_CloudDensity; +VARYING vec2 vary_texcoord0; +VARYING vec2 vary_texcoord1; +VARYING vec2 vary_texcoord2; +VARYING vec2 vary_texcoord3; + +// Inputs +uniform vec3 camPosLocal; + +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 max_y; + +uniform vec4 glow; + +uniform vec4 cloud_color; + +uniform float cloud_scale; + +void main() +{ + +	// World / view / projection +	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + +	vary_texcoord0 = texcoord0; + +	// Get relative position +	vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); + +	// Set altitude +	if (P.y > 0.) +	{ +		P *= (max_y / P.y); +	} +	else +	{ +		P *= (-32000. / P.y); +	} + +	// Can normalize then +	vec3 Pn = normalize(P); +	float  Plen = length(P); + +	// Initialize temp variables +	vec4 temp1 = vec4(0.); +	vec4 temp2 = vec4(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); + +	// Calculate relative weights +	temp1 = blue_density + haze_density; +	blue_weight = blue_density / temp1; +	haze_weight = haze_density / temp1; + +	// Compute sunlight from P & lightnorm (for long rays like sky) +	temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); +	temp2.y = 1. / temp2.y; +	sunlight *= exp( - light_atten * temp2.y); + +	// Distance +	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; +		// temp2.x is 0 at the sun and increases away from sun +	temp2.x = max(temp2.x, .001);	 +		// 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; +	tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5;  + +	// Dim sunlight by cloud shadow percentage +	sunlight *= (1. - cloud_shadow); + +	// Haze color below cloud +	vec4 additiveColorBelowCloud = (	  blue_horizon * blue_weight * (sunlight + tmpAmbient) +				+ (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) +			 );	 + +	// CLOUDS + +	sunlight = sunlight_color; +	temp2.y = max(0., lightnorm.y * 2.); +	temp2.y = 1. / temp2.y; +	sunlight *= exp( - light_atten * temp2.y); + +	// Cloud color out +	vary_CloudColorSun = (sunlight * temp2.x) * cloud_color; +	vary_CloudColorAmbient = tmpAmbient * cloud_color; +	 +	// Attenuate cloud color by atmosphere +	temp1 = sqrt(temp1);	//less atmos opacity (more transparency) below clouds +	vary_CloudColorSun *= temp1; +	vary_CloudColorAmbient *= temp1; +	vec4 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - temp1); + +	// Make a nice cloud density based on the cloud_shadow value that was passed in. +	vary_CloudDensity = 2. * (cloud_shadow - 0.25); + + +	// Texture coords +	vary_texcoord0 = texcoord0; +	vary_texcoord0.xy -= 0.5; +	vary_texcoord0.xy /= cloud_scale; +	vary_texcoord0.xy += 0.5; + +	vary_texcoord1 = vary_texcoord0; +	vary_texcoord1.x += lightnorm.x * 0.0125; +	vary_texcoord1.y += lightnorm.z * 0.0125; + +	vary_texcoord2 = vary_texcoord0 * 16.; +	vary_texcoord3 = vary_texcoord1 * 16.; + +	// Combine these to minimize register use +	vary_CloudColorAmbient += oHazeColorBelowCloud; + +	// needs this to compile on mac +	//vary_AtmosAttenuation = vec3(0.0,0.0,0.0); + +	// END CLOUDS +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl new file mode 100644 index 0000000000..0fb990611e --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl @@ -0,0 +1,86 @@ +/**  + * @file advancedAtmoF.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ +  +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +in vec3 view_pos; +in vec3 view_dir; + +uniform vec3 cameraPosLocal; +uniform vec3 sun_dir; +uniform vec3 moon_dir; +uniform float sun_size; + +uniform sampler2D transmittance_texture; +uniform sampler3D scattering_texture; +uniform sampler3D single_mie_scattering_texture; +uniform sampler2D irradiance_texture; + +vec3 GetSolarLuminance(); +vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 dir, out vec3 transmittance); +vec3 GetSkyLuminanceToPoint(vec3 camPos, vec3 pos, float shadow_length, vec3 dir, out vec3 transmittance); +vec3 GetSunAndSkyIlluminance(vec3 pos, vec3 norm, vec3 dir, out vec3 sky_irradiance); + +void main() +{ +    vec3 view_direction = normalize(view_dir); + +    vec3 sun_direction = sun_dir; + +    vec3 camPos = cameraPosLocal + vec3(0, 0, 6360.0f); +    vec3 transmittance; +    vec3 sky_illum; + +    vec3 radiance_sun = GetSkyLuminance(camPos, view_direction, 0.0f, sun_direction, transmittance); +    vec3 radiance2_sun = GetSunAndSkyIlluminance(camPos, view_direction, sun_direction, sky_illum); + +    radiance *= transmittance; + +    vec3 solar_luminance = transmittance * GetSolarLuminance(); + +    // If the view ray intersects the Sun, add the Sun radiance. +    if (dot(view_direction, sun_direction) >= sun_size) +    { +        radiance = radiance + solar_luminance; +    } + +    vec3 color = radiance; +     +    color = vec3(1.0) - exp(-color * 0.0001); + +    //float d = dot(view_direction, sun_direction); +    //frag_color.rgb = vec3(d, d >= sun_size ? 1.0f : 0.0f, 0.0f); + +    frag_color.rgb = color; +    //frag_color.rgb = vec3(dot(view_direction, sun_direction) > 0.95f ? 1.0 : 0.0, 0,0); +    frag_color.rgb = normalize(view_pos); + +    frag_color.a = 1.0; +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl new file mode 100644 index 0000000000..cf3eb658fc --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl @@ -0,0 +1,51 @@ +/**  + * @file advancedAtmoV.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ +  +uniform vec3 cameraPosLocal; +uniform mat4 modelview_projection_matrix; +uniform mat4 modelview_matrix; +uniform mat4 inv_proj; +uniform mat4 inv_modelview; + +ATTRIBUTE vec3 position; + +// Inputs +uniform vec3 camPosLocal; + +out vec3 view_pos; +out vec3 view_dir; + +void main() +{ +    // pass through untransformed fullscreen pos (clipspace) +	gl_Position = vec4(position.xyz, 1.0); + +    view_pos = (inv_proj * vec4(position, 1.0f)).xyz; + +	// this will be normalized in the frag shader... +	//view_dir = (inv_modelview * view_pos).xyz; +    view_dir = view_pos - camPosLocal; +} + diff --git a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl new file mode 100644 index 0000000000..bdb54a1d63 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl @@ -0,0 +1,74 @@ +/**  + * @file advancedAtmoF.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ +  +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +in vec3 view_dir; + +uniform vec3 cameraPosLocal; +uniform vec3 sun_dir; +uniform vec3 moon_dir; +uniform float sun_size; + +uniform sampler2D transmittance_texture; +uniform sampler3D scattering_texture; +uniform sampler3D mie_scattering_texture; +uniform sampler2D irradiance_texture; + +vec3 GetSolarLuminance(); +vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 sun_dir, out vec3 transmittance); +vec3 GetSkyLuminanceToPoint(vec3 camPos, vec3 pos, float shadow_length, vec3 sun_dir, out vec3 transmittance); +vec3 GetSunAndSkyIlluminance(vec3 pos, vec3 norm, vec3 sun_dir, out vec3 sky_irradiance); + +void main() +{ +    vec3 view_direction = normalize(view_dir); + +    vec3 camPos = cameraPosLocal; +    vec3 transmittance; +    vec3 sky_illum; +    vec3 radiance = GetSkyLuminance(camPos, view_direction, 0.0f, sun_dir, transmittance); +    vec3 radiance2 = GetSunAndSkyIlluminance(camPos, view_direction, sun_dir, sky_illum); + +    //radiance *= transmittance; + +    // If the view ray intersects the Sun, add the Sun radiance. +    if (dot(view_direction, sun_dir) >= sun_size) +    { +        radiance = radiance + transmittance * GetSolarLuminance(); +    } + +    //vec3 color = vec3(1.0) - exp(-radiance); +    //color = pow(color, vec3(1.0 / 2.2)); + +    frag_color.rgb = radiance; +  +    frag_color.a = 1.0; +} + diff --git a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoV.glsl b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoV.glsl new file mode 100644 index 0000000000..52a7595379 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoV.glsl @@ -0,0 +1,43 @@ +/**  + * @file advancedAtmoV.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ +  +uniform mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; + +// Inputs +uniform vec3 camPosLocal; + +out vec3 view_dir; + +void main() +{ +	// World / view / projection +	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + +	// this will be normalized in the frag shader... +	view_dir = position.xyz - camPosLocal.xyz;  +} + diff --git a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl new file mode 100644 index 0000000000..fee1a7f311 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl @@ -0,0 +1,148 @@ +/**  + * @file atmosphericsF.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$ + */ + +vec3 getAdditiveColor(); +vec3 getAtmosAttenuation(); + +uniform sampler2D cloudMap; +uniform vec4 gamma; +uniform vec4 cloud_pos_density1; +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 ssao_effect_mat; + +vec3 scaleFragSoftClip(vec3 light) +{ +	//soft clip effect: +	light = 1. - clamp(light, vec3(0.), vec3(1.)); +	light = 1. - pow(light, gamma.xxx); +	return light; +} + +vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) +{ +	light *= atten.r; +	light += additive; +	return (2.0 * light); +} + +vec3 atmosLighting(vec3 light) +{ +    return atmosFragLighting(light, getAdditiveColor(), getAtmosAttenuation()); +} + +void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { + +	vec3 P = inPositionEye; +	 +	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 +	atten = 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 +        additive = +		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 +	sunlit = vec3(sunlight * .5); +	amblit = vec3(tmpAmbient * .25); +	additive *= vec3(1.0 - temp1); +} + diff --git a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl new file mode 100644 index 0000000000..3270c243a4 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl @@ -0,0 +1,133 @@ +/** + * @file atmosphericsV.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ + +// VARYING param funcs +void setSunlitColor(vec3 v); +void setAmblitColor(vec3 v); +void setAdditiveColor(vec3 v); +void setAtmosAttenuation(vec3 v); +void setPositionEye(vec3 v); + +vec3 getAdditiveColor(); + +// Inputs +uniform vec4 morphFactor; +uniform vec3 camPosLocal; + +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; + +void calcAtmospherics(vec3 inPositionEye) { + +	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)); +} diff --git a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl new file mode 100644 index 0000000000..82e1d7fe35 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl @@ -0,0 +1,62 @@ +/**  + * @file transportF.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$ + */ +  +////////////////////////////////////////////////////////// +// The fragment shader for the terrain atmospherics +////////////////////////////////////////////////////////// + +vec3 getAdditiveColor(); +vec3 getAtmosAttenuation(); + +uniform sampler2D cloudMap; +uniform vec4 cloud_pos_density1; + +vec3 atmosFragTransport(vec3 light, vec3 atten, vec3 additive) { +	light *= atten.r; +	light += additive * 2.0; +	return light; +} + +vec3 fullbrightFragAtmosTransport(vec3 light, vec3 atten, vec3 additive) { +	float brightness = dot(light.rgb, vec3(0.33333)); +	return mix(atmosFragTransport(light.rgb, atten, additive), light.rgb + additive.rgb, brightness * brightness); +} + +vec3 fullbrightFragShinyAtmosTransport(vec3 light, vec3 atten, vec3 additive) { +	float brightness = dot(light.rgb, vec3(0.33333)); +	return mix(atmosFragTransport(light.rgb, atten, additive), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); +} + +vec3 atmosTransport(vec3 light) { +     return atmosFragTransport(light, getAtmosAttenuation(), getAdditiveColor()); +} + +vec3 fullbrightAtmosTransport(vec3 light) { +     return fullbrightFragAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); +} + +vec3 fullbrightShinyAtmosTransport(vec3 light) { +    return fullbrightFragShinyAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); +} | 
