diff options
Diffstat (limited to 'indra/newview/app_settings/shaders')
212 files changed, 8400 insertions, 4684 deletions
| diff --git a/indra/newview/app_settings/shaders/class1/avatar/avatarV.glsl b/indra/newview/app_settings/shaders/class1/avatar/avatarV.glsl index 19203ab670..0543a26642 100644 --- a/indra/newview/app_settings/shaders/class1/avatar/avatarV.glsl +++ b/indra/newview/app_settings/shaders/class1/avatar/avatarV.glsl @@ -34,7 +34,7 @@ VARYING vec2 vary_texcoord0;  uniform vec4 color; -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color);  mat4 getSkinnedTransform();  void calcAtmospherics(vec3 inPositionEye); @@ -62,7 +62,7 @@ void main()  	calcAtmospherics(pos.xyz); -	vec4 col = calcLighting(pos.xyz, norm, color, vec4(0,0,0,0)); +	vec4 col = calcLighting(pos.xyz, norm, color);  	vertex_color = col;   } diff --git a/indra/newview/app_settings/shaders/class1/avatar/eyeballV.glsl b/indra/newview/app_settings/shaders/class1/avatar/eyeballV.glsl index 82db15c3ae..fac1599c6b 100644 --- a/indra/newview/app_settings/shaders/class1/avatar/eyeballV.glsl +++ b/indra/newview/app_settings/shaders/class1/avatar/eyeballV.glsl @@ -36,7 +36,7 @@ ATTRIBUTE vec2 texcoord0;  VARYING vec4 vertex_color;  VARYING vec2 vary_texcoord0; -vec4 calcLightingSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol); +vec4 calcLightingSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor);  void calcAtmospherics(vec3 inPositionEye);  void main() @@ -52,7 +52,7 @@ void main()  	calcAtmospherics(pos.xyz);  	vec4 specular = vec4(1.0); -	vec4 color = calcLightingSpecular(pos, norm, diffuse_color, specular, vec4(0.0));	 +	vec4 color = calcLightingSpecular(pos, norm, diffuse_color, specular);	  	vertex_color = color;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index b9c8f34cb0..dc484317e9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -22,7 +22,9 @@   * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA   * $/LicenseInfo$   */ -  + +//class1/deferred/alphaF.glsl +  #extension GL_ARB_texture_rectangle : enable  /*[EXTRA_CODE_HERE]*/ @@ -37,39 +39,9 @@ out vec4 frag_color;  #define frag_color gl_FragColor  #endif -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; - -#if HAS_SHADOW -uniform sampler2DShadow shadowMap0; -uniform sampler2DShadow shadowMap1; -uniform sampler2DShadow shadowMap2; -uniform sampler2DShadow shadowMap3; - -uniform vec2 shadow_res; - -uniform mat4 shadow_matrix[6]; -uniform vec4 shadow_clip; -uniform float shadow_bias; - -#endif +uniform vec3 moon_dir;  #ifdef USE_DIFFUSE_TEX  uniform sampler2D diffuseMap; @@ -81,551 +53,254 @@ VARYING vec2 vary_texcoord0;  VARYING vec3 vary_norm;  #ifdef USE_VERTEX_COLOR -VARYING vec4 vertex_color; +VARYING vec4 vertex_color; //vertex color should be treated as sRGB  #endif -vec3 vary_PositionEye; -vec3 vary_SunlitColor; -vec3 vary_AmblitColor; -vec3 vary_AdditiveColor; -vec3 vary_AtmosAttenuation; - +uniform mat4 proj_mat;  uniform mat4 inv_proj;  uniform vec2 screen_res; - +uniform int sun_up_factor;  uniform vec4 light_position[8];  uniform vec3 light_direction[8]; -uniform vec3 light_attenuation[8];  +uniform vec4 light_attenuation[8];   uniform vec3 light_diffuse[8]; -vec3 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 c); +vec3 linear_to_srgb(vec3 c); -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); +vec3 scaleSoftClipFrag(vec3 l); +vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); -} +void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive, bool use_ao); -vec2 encode_normal(vec3 n) -{ -	float f = sqrt(8 * n.z + 8); -	return n.xy / f + 0.5; -} +#ifdef HAS_SHADOW +float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); +#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; -} +float getAmbientClamp(); -vec3 calcDirectionalLight(vec3 n, vec3 l) +vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, float ambiance)  { -	float a = max(dot(n,l),0.0); -	a = pow(a, 1.0/1.3); -	return vec3(a,a,a); -} +    vec3 col = vec3(0); -vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) -{  	//get light vector  	vec3 lv = lp.xyz-v; -	 +  	//get distance -	float d = length(lv); -	 +	float dist = length(lv);  	float da = 1.0; -	vec3 col = vec3(0); - -	if (d > 0.0 && la > 0.0 && fa > 0.0) +    /*if (dist > la) +    { +        return col; +    } + +    clip to projector bounds +     vec4 proj_tc = proj_mat * lp; + +    if (proj_tc.z < 0 +     || proj_tc.z > 1 +     || proj_tc.x < 0 +     || proj_tc.x > 1  +     || proj_tc.y < 0 +     || proj_tc.y > 1) +    { +        return col; +    }*/ + +	if (dist > 0.0 && la > 0.0)  	{ +        dist /= la; +  		//normalize light vector  		lv = normalize(lv);  		//distance attenuation -		float dist = d/la;  		float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0);  		dist_atten *= dist_atten; -		dist_atten *= 2.0; +        dist_atten *= 2.0f; + +        if (dist_atten <= 0.0) +        { +           return col; +        }  		// spotlight coefficient.  		float spot = max(dot(-ln, lv), is_pointlight);  		da *= spot*spot; // GL_SPOT_EXPONENT=2  		//angular attenuation -		da *= max(dot(n, lv), 0.0);		 - -		float lit = max(da * dist_atten,0.0); - -		col = light_col * lit * diffuse; - -		// no spec for alpha shader... -	} - -	return max(col, vec3(0.0,0.0,0.0)); +		da *= dot(n, lv); +        da = max(0.0, da); + +		float lit = 0.0f; + +        float amb_da = 0.0;//ambiance; +        if (da > 0) +        { +		    lit = max(da * dist_atten,0.0); +            col = lit * light_col * diffuse; +            amb_da += (da*0.5+0.5) * ambiance; +        } +        amb_da += (da*da*0.5 + 0.5) * ambiance; +        amb_da *= dist_atten; +        amb_da = min(amb_da, 1.0f - lit); + +        // SL-10969 ... need to work out why this blows out in many setups... +        //col.rgb += amb_da * light_col * diffuse; + +        // no spec for alpha shader... +    } +    col = max(col, vec3(0)); +    return col;  } -#if HAS_SHADOW -float pcfShadow(sampler2DShadow shadowMap, vec4 stc) +void main()   { -	stc.xyz /= stc.w; -	stc.z += shadow_bias; -		 -	stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y*12345))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here -	 -	float cs = shadow2D(shadowMap, stc.xyz).x; -	float shadow = cs; -	 -    shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; -    shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; -    shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; -    shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; -                        -    return shadow*0.2; -} -#endif +    vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; +    frag *= screen_res; +     +    vec4 pos = vec4(vary_position, 1.0); +    vec3 norm = vary_norm; -#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)); +    float shadow = 1.0f; -	//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; -} +#ifdef HAS_SHADOW +    shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, frag);  #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)); -} +#ifdef USE_DIFFUSE_TEX +    vec4 diffuse_tap = texture2D(diffuseMap,vary_texcoord0.xy); +#endif -vec3 atmosLighting(vec3 light) -{ -	light *= getAtmosAttenuation().r; -	light += getAdditiveColor(); -	return (2.0 * light); -} +#ifdef USE_INDEXED_TEX +    vec4 diffuse_tap = diffuseLookup(vary_texcoord0.xy); +#endif -vec3 atmosTransport(vec3 light) { -	light *= getAtmosAttenuation().r; -	light += getAdditiveColor() * 2.0; -	return light; -} -vec3 atmosGetDiffuseSunlightColor() -{ -	return getSunlitColor(); -} +    vec4 diffuse_srgb = diffuse_tap; +    vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); -vec3 scaleDownLight(vec3 light) -{ -	return (light / vec3(scene_light_strength, scene_light_strength, scene_light_strength)); -} +#ifdef FOR_IMPOSTOR +    vec4 color; +    color.rgb = diffuse_srgb.rgb; +    color.a = 1.0; + +    float final_alpha = diffuse_srgb.a * vertex_color.a; +    diffuse_srgb.rgb *= vertex_color.rgb; +    diffuse_linear.rgb = srgb_to_linear(diffuse_srgb.rgb);  +     +    // Insure we don't pollute depth with invis pixels in impostor rendering +    // +    if (final_alpha < 0.01) +    { +        discard; +    } +#else +     +    vec3 light_dir = (sun_up_factor == 1) ? sun_dir: moon_dir; -vec3 scaleUpLight(vec3 light) -{ -	return (light * vec3(scene_light_strength, scene_light_strength, scene_light_strength)); -} +    float final_alpha = diffuse_linear.a; -vec3 atmosAmbient(vec3 light) -{ -	return getAmblitColor() + (light * vec3(0.5f, 0.5f, 0.5f)); -} +#ifdef USE_VERTEX_COLOR +    final_alpha *= vertex_color.a; +    diffuse_srgb.rgb *= vertex_color.rgb; +    diffuse_linear.rgb = srgb_to_linear(diffuse_srgb.rgb); +#endif -vec3 atmosAffectDirectionalLight(float lightIntensity) -{ -	return getSunlitColor() * vec3(lightIntensity, lightIntensity, lightIntensity); -} +    vec3 sunlit; +    vec3 amblit; +    vec3 additive; +    vec3 atten; -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); +    calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); -	light = ones - clamp(light, zeroes, ones); -	light = ones - pow(light, gamma.xxx); +    vec2 abnormal = encode_normal(norm.xyz); -	return light; -} +    float da = dot(norm.xyz, light_dir.xyz); +          da = clamp(da, -1.0, 1.0); +          da = pow(da, 1.0/1.3); +  +    float final_da = da; +          final_da = clamp(final_da, 0.0f, 1.0f); -vec3 fullbrightAtmosTransport(vec3 light) { -	float brightness = dot(light.rgb, vec3(0.33333)); +    vec4 color = vec4(0.0); -	return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); -} +    color.a   = final_alpha; -vec3 fullbrightScaleSoftClip(vec3 light) -{ -	//soft clip effect: -	return light; -} +    float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); +    ambient *= 0.5; +    ambient *= ambient; +    ambient = (1.0 - ambient); -void main()  -{ -	vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; -	frag *= screen_res; -	 -	vec4 pos = vec4(vary_position, 1.0); -	 -	float shadow = 1.0; - -#if HAS_SHADOW -	vec4 spos = pos; -		 -	if (spos.z > -shadow_clip.w) -	{	 -		shadow = 0.0; - -		vec4 lpos; -		 -		vec4 near_split = shadow_clip*-0.75; -		vec4 far_split = shadow_clip*-1.25; -		vec4 transition_domain = near_split-far_split; -		float weight = 0.0; - -		if (spos.z < near_split.z) -		{ -			lpos = shadow_matrix[3]*spos; -			 -			float w = 1.0; -			w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; -			shadow += pcfShadow(shadowMap3, lpos)*w; -			weight += w; -			shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); -		} - -		if (spos.z < near_split.y && spos.z > far_split.z) -		{ -			lpos = shadow_matrix[2]*spos; -			 -			float w = 1.0; -			w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; -			w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; -			shadow += pcfShadow(shadowMap2, lpos)*w; -			weight += w; -		} - -		if (spos.z < near_split.x && spos.z > far_split.y) -		{ -			lpos = shadow_matrix[1]*spos; -			 -			float w = 1.0; -			w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; -			w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; -			shadow += pcfShadow(shadowMap1, lpos)*w; -			weight += w; -		} - -		if (spos.z > far_split.x) -		{ -			lpos = shadow_matrix[0]*spos; -							 -			float w = 1.0; -			w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; -				 -			shadow += pcfShadow(shadowMap0, lpos)*w; -			weight += w; -		} -		 - -		shadow /= weight; -	} -	else -	{ -		shadow = 1.0; -	} -#endif +    vec3 sun_contrib = min(final_da, shadow) * sunlit; -#ifdef USE_INDEXED_TEX -	vec4 diff = diffuseLookup(vary_texcoord0.xy); -#else -	vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); +#if !defined(AMBIENT_KILL) +    color.rgb = amblit; +    color.rgb *= ambient;  #endif -#ifdef FOR_IMPOSTOR -	vec4 color; -	color.rgb = diff.rgb; -	color.a = 1.0; +vec3 post_ambient = color.rgb; -#ifdef USE_VERTEX_COLOR -	float final_alpha = diff.a * vertex_color.a; -	diff.rgb *= vertex_color.rgb; -#else -	float final_alpha = diff.a; -#endif -	 -	// Insure we don't pollute depth with invis pixels in impostor rendering -	// -	if (final_alpha < 0.01) -	{ -		discard; -	} -#else -	 -#ifdef USE_VERTEX_COLOR -	float final_alpha = diff.a * vertex_color.a; -	diff.rgb *= vertex_color.rgb; -#else -	float final_alpha = diff.a; +#if !defined(SUNLIGHT_KILL) +    color.rgb += sun_contrib;  #endif +vec3 post_sunlight = color.rgb; -	vec4 gamma_diff = diff;	 -	diff.rgb = srgb_to_linear(diff.rgb); +    color.rgb *= diffuse_srgb.rgb; -	vec3 norm = vary_norm;  +vec3 post_diffuse = color.rgb; -	calcAtmospherics(pos.xyz, 1.0); +    color.rgb = atmosFragLighting(color.rgb, additive, atten); -	vec2 abnormal	= encode_normal(norm.xyz); -		 norm.xyz   = decode_normal(abnormal.xy); +vec3 post_atmo = color.rgb; -	float da = dot(norm.xyz, sun_dir.xyz); +    vec4 light = vec4(0,0,0,0); +     +    color.rgb = scaleSoftClipFrag(color.rgb); -    float final_da = da; -          final_da = min(final_da, shadow); -          final_da = max(final_da, 0.0f); -		  final_da = min(final_da, 1.0f); -		  final_da = pow(final_da, 1.0/1.3); +    //convert to linear before applying local lights +    color.rgb = srgb_to_linear(color.rgb); -	vec4 color = vec4(0,0,0,0); +   #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diffuse_linear.rgb, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, light_attenuation[i].w); -	color.rgb = atmosAmbient(color.rgb); -	color.a   = final_alpha; - -	float ambient = abs(da); -	ambient *= 0.5; -	ambient *= ambient; -	ambient = (1.0-ambient); - -	color.rgb *= ambient; -	color.rgb += atmosAffectDirectionalLight(final_da); -	color.rgb *= gamma_diff.rgb; - -	//color.rgb = mix(diff.rgb, color.rgb, final_alpha); -	 -	color.rgb = atmosLighting(color.rgb); -	color.rgb = scaleSoftClip(color.rgb); +    LIGHT_LOOP(1) +    LIGHT_LOOP(2) +    LIGHT_LOOP(3) +    LIGHT_LOOP(4) +    LIGHT_LOOP(5) +    LIGHT_LOOP(6) +    LIGHT_LOOP(7) -	vec4 light = vec4(0,0,0,0); - -	color.rgb = srgb_to_linear(color.rgb); -	 -   #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diff.rgb, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); - -	LIGHT_LOOP(1) -	LIGHT_LOOP(2) -	LIGHT_LOOP(3) -	LIGHT_LOOP(4) -	LIGHT_LOOP(5) -	LIGHT_LOOP(6) -	LIGHT_LOOP(7) - -	// keep it linear -	// -	color.rgb += light.rgb; - -	// straight to display gamma, we're post-deferred -	// -	color.rgb = linear_to_srgb(color.rgb); +    // sum local light contrib in linear colorspace +#if !defined(LOCAL_LIGHT_KILL) +    color.rgb += light.rgb; +#endif +    // back to sRGB as we're going directly to the final RT post-deferred gamma correction +    color.rgb = linear_to_srgb(color.rgb); + +//color.rgb = amblit; +//color.rgb = vec3(ambient); +//color.rgb = sunlit; +//color.rgb = vec3(final_da); +//color.rgb = post_ambient; +//color.rgb = post_sunlight; +//color.rgb = sun_contrib; +//color.rgb = diffuse_srgb.rgb; +//color.rgb = post_diffuse; +//color.rgb = post_atmo;  #ifdef WATER_FOG -	color = applyWaterFogDeferred(pos.xyz, color); -#endif +    color = applyWaterFogView(pos.xyz, color); +#endif // WATER_FOG  #endif - -	frag_color = color; +     +    frag_color = color;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl new file mode 100644 index 0000000000..23adbded5e --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl @@ -0,0 +1,123 @@ +/**  + * @file class1/deferred/aoUtil.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 sampler2D       noiseMap; +uniform sampler2DRect   normalMap; +uniform sampler2DRect   depthMap; + +uniform float ssao_radius; +uniform float ssao_max_radius; +uniform float ssao_factor; +uniform float ssao_factor_inv; + +uniform mat4 inv_proj; +uniform vec2 screen_res; + +vec2 getScreenCoordinateAo(vec2 screenpos) +{ +    vec2 sc = screenpos.xy * 2.0; +    if (screen_res.x > 0 && screen_res.y > 0) +    { +       sc /= screen_res; +    } +    return sc - vec2(1.0, 1.0); +} + +float getDepthAo(vec2 pos_screen) +{ +    float depth = texture2DRect(depthMap, pos_screen).r; +    return depth; +} + +vec4 getPositionAo(vec2 pos_screen) +{ +    float depth = getDepthAo(pos_screen); +    vec2 sc = getScreenCoordinateAo(pos_screen); +    vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); +    vec4 pos = inv_proj * ndc; +    pos /= pos.w; +    pos.w = 1.0; +    return pos; +} + +vec2 getKern(int i) +{ +    vec2 kern[8]; +    // exponentially (^2) distant occlusion samples spread around origin +    kern[0] = vec2(-1.0, 0.0) * 0.125*0.125; +    kern[1] = vec2(1.0, 0.0) * 0.250*0.250; +    kern[2] = vec2(0.0, 1.0) * 0.375*0.375; +    kern[3] = vec2(0.0, -1.0) * 0.500*0.500; +    kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625; +    kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750; +    kern[6] = vec2(-0.7071, 0.7071) * 0.875*0.875; +    kern[7] = vec2(0.7071, -0.7071) * 1.000*1.000; +        +    return kern[i]; +} + +//calculate decreases in ambient lighting when crowded out (SSAO) +float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen) +{ +    float ret = 1.0; +    vec3 pos_world = pos.xyz; +    vec2 noise_reflect = texture2D(noiseMap, pos_screen.xy/128.0).xy; +         +    float angle_hidden = 0.0; +    float points = 0; +         +    float scale = min(ssao_radius / -pos_world.z, ssao_max_radius); +     +    // it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations (unrolling?) +    for (int i = 0; i < 8; i++) +    { +        vec2 samppos_screen = pos_screen + scale * reflect(getKern(i), noise_reflect); +        vec3 samppos_world = getPositionAo(samppos_screen).xyz;  +         +        vec3 diff = pos_world - samppos_world; +        float dist2 = dot(diff, diff); +             +        // assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area +        // --> solid angle shrinking by the square of distance +        //radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2 +        //(k should vary inversely with # of samples, but this is taken care of later) +         +        float funky_val = (dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) ? 1.0 : 0.0; +        angle_hidden = angle_hidden + funky_val * min(1.0/dist2, ssao_factor_inv); +             +        // 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion"  +        float diffz_val = (diff.z > -1.0) ? 1.0 : 0.0; +        points = points + diffz_val; +    } +         +    angle_hidden = min(ssao_factor*angle_hidden/points, 1.0); +     +    float points_val = (points > 0.0) ? 1.0 : 0.0; +    ret = (1.0 - (points_val * angle_hidden)); + +    ret = max(ret, 0.0); +    return min(ret, 1.0); +} + 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/attachmentShadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowV.glsl index 3f90600ace..0fa0edfd67 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowV.glsl @@ -41,7 +41,7 @@ void main()  	vec4 p = projection_matrix * vec4(pos, 1.0); -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP)  	p.z = max(p.z, -p.w+0.01);  	gl_Position = p;  #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl index c8ddefac26..bbdc8fdd1c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl @@ -29,17 +29,13 @@ ATTRIBUTE vec3 position;  ATTRIBUTE vec3 normal;  ATTRIBUTE vec2 texcoord0; -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol);  mat4 getSkinnedTransform();  void calcAtmospherics(vec3 inPositionEye);  float calcDirectionalLight(vec3 n, vec3 l); -float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float is_pointlight); -vec3 atmosAmbient(vec3 light); +vec3 atmosAmbient();  vec3 atmosAffectDirectionalLight(float lightIntensity); -vec3 scaleDownLight(vec3 light); -vec3 scaleUpLight(vec3 light);  VARYING vec3 vary_position;  VARYING vec3 vary_ambient; @@ -59,41 +55,7 @@ uniform vec3 light_direction[8];  uniform vec3 light_attenuation[8];   uniform vec3 light_diffuse[8]; -float calcDirectionalLight(vec3 n, vec3 l) -{ -        float a = max(dot(n,l),0.0); -        return a; -} - -float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) -{ -	//get light vector -	vec3 lv = lp.xyz-v; -	 -	//get distance -	float d = dot(lv,lv); -	 -	float da = 0.0; - -	if (d > 0.0 && la > 0.0 && fa > 0.0) -	{ -		//normalize light vector -		lv = normalize(lv); -	 -		//distance attenuation -		float dist2 = d/la; -		da = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0); - -		// spotlight coefficient. -		float spot = max(dot(-ln, lv), is_pointlight); -		da *= spot*spot; // GL_SPOT_EXPONENT=2 - -		//angular attenuation -		da *= max(dot(n, lv), 0.0);		 -	} - -	return da;	 -} +float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight);  void main()  { @@ -137,7 +99,7 @@ void main()  	col.rgb = vec3(0,0,0);  	// Add windlight lights -	col.rgb = atmosAmbient(vec3(0.)); +	col.rgb = atmosAmbient();  	vary_ambient = col.rgb*color.rgb;  	vary_directional = color.rgb*atmosAffectDirectionalLight(max(calcDirectionalLight(norm, light_position[0].xyz), 0.0)); 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..50020a50d8 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 @@ -31,7 +33,7 @@ out vec4 frag_color;  uniform sampler2D diffuseMap; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP)  VARYING vec4 post_pos;  #endif @@ -39,7 +41,7 @@ void main()  {  	frag_color = vec4(1,1,1,1); -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP)  	gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0);  #endif  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl index bde1ad4e9f..91b25613e0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl @@ -31,7 +31,7 @@ ATTRIBUTE vec3 position;  ATTRIBUTE vec3 normal;  ATTRIBUTE vec2 texcoord0; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP)  VARYING vec4 post_pos;  #endif @@ -53,7 +53,7 @@ void main()  	norm = normalize(norm);  	pos = projection_matrix * pos; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP)  	post_pos = pos;  	gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index cbd8d2ebfc..596d0274af 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -33,7 +33,6 @@ out vec4 frag_color;  #define frag_color gl_FragColor  #endif -uniform sampler2DRect depthMap;  uniform sampler2DRect normalMap;  uniform sampler2DRect lightMap; @@ -45,100 +44,68 @@ uniform float kern_scale;  VARYING vec2 vary_fragcoord; -uniform mat4 inv_proj; -uniform vec2 screen_res; - -vec4 getPosition(vec2 pos_screen) -{ -	float depth = texture2DRect(depthMap, pos_screen.xy).r; -	vec2 sc = pos_screen.xy*2.0; -	sc /= screen_res; -	sc -= vec2(1.0,1.0); -	vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); -	vec4 pos = inv_proj * ndc; -	pos /= pos.w; -	pos.w = 1.0; -	return pos; -} - -vec2 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; -} +vec4 getPosition(vec2 pos_screen); +vec3 getNorm(vec2 pos_screen);  void main()   {      vec2 tc = vary_fragcoord.xy; -	vec3 norm = texture2DRect(normalMap, tc).xyz; -	norm = decode_normal(norm.xy); // unpack norm - -	vec3 pos = getPosition(tc).xyz; -	vec4 ccol = texture2DRect(lightMap, tc).rgba; -	 -	vec2 dlt = kern_scale * delta / (1.0+norm.xy*norm.xy); -	dlt /= max(-pos.z*dist_factor, 1.0); -	 -	vec2 defined_weight = kern[0].xy; // special case the first (centre) sample's weight in the blur; we have to sample it anyway so we get it for 'free' -	vec4 col = defined_weight.xyxx * ccol; - -	// relax tolerance according to distance to avoid speckling artifacts, as angles and distances are a lot more abrupt within a small screen area at larger distances -	float pointplanedist_tolerance_pow2 = pos.z*pos.z*0.00005; - -	// perturb sampling origin slightly in screen-space to hide edge-ghosting artifacts where smoothing radius is quite large -	float tc_mod = 0.5*(tc.x + tc.y); // mod(tc.x+tc.y,2) -	tc_mod -= floor(tc_mod); -	tc_mod *= 2.0; -	tc += ( (tc_mod - 0.5) * kern[1].z * dlt * 0.5 ); - -	for (int i = 1; i < 4; i++) -	{ -		vec2 samptc = tc + kern[i].z*dlt; -	    vec3 samppos = getPosition(samptc).xyz;  - -		float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane -		 -		if (d*d <= pointplanedist_tolerance_pow2) -		{ -			col += texture2DRect(lightMap, samptc)*kern[i].xyxx; -			defined_weight += kern[i].xy; -		} -	} - -	for (int i = 1; i < 4; i++) -	{ -		vec2 samptc = tc - kern[i].z*dlt; -	    vec3 samppos = getPosition(samptc).xyz;  - -		float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane -		 -		if (d*d <= pointplanedist_tolerance_pow2) -		{ -			col += texture2DRect(lightMap, samptc)*kern[i].xyxx; -			defined_weight += kern[i].xy; -		} -	} - -	col /= defined_weight.xyxx; -	col.y *= col.y; -	 -	frag_color = col; +    vec3 norm = getNorm(tc); +    vec3 pos = getPosition(tc).xyz; +    vec4 ccol = texture2DRect(lightMap, tc).rgba; +     +    vec2 dlt = kern_scale * delta / (1.0+norm.xy*norm.xy); +    dlt /= max(-pos.z*dist_factor, 1.0); +     +    vec2 defined_weight = kern[0].xy; // special case the first (centre) sample's weight in the blur; we have to sample it anyway so we get it for 'free' +    vec4 col = defined_weight.xyxx * ccol; + +    // relax tolerance according to distance to avoid speckling artifacts, as angles and distances are a lot more abrupt within a small screen area at larger distances +    float pointplanedist_tolerance_pow2 = pos.z*pos.z*0.00005; + +    // perturb sampling origin slightly in screen-space to hide edge-ghosting artifacts where smoothing radius is quite large +    float tc_mod = 0.5*(tc.x + tc.y); // mod(tc.x+tc.y,2) +    tc_mod -= floor(tc_mod); +    tc_mod *= 2.0; +    tc += ( (tc_mod - 0.5) * kern[1].z * dlt * 0.5 ); + +    for (int i = 1; i < 4; i++) +    { +        vec2 samptc = tc + kern[i].z*dlt; +        vec3 samppos = getPosition(samptc).xyz;  + +        float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane +         +        if (d*d <= pointplanedist_tolerance_pow2) +        { +            col += texture2DRect(lightMap, samptc)*kern[i].xyxx; +            defined_weight += kern[i].xy; +        } +    } + +    for (int i = 1; i < 4; i++) +    { +        vec2 samptc = tc - kern[i].z*dlt; +        vec3 samppos = getPosition(samptc).xyz;  + +        float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane +         +        if (d*d <= pointplanedist_tolerance_pow2) +        { +            col += texture2DRect(lightMap, samptc)*kern[i].xyxx; +            defined_weight += kern[i].xy; +        } +    } + +    col /= defined_weight.xyxx; +    col.y *= col.y; +     +    frag_color = col;  #ifdef IS_AMD_CARD -	// If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. -	vec3 dummy1 = kern[0]; -	vec3 dummy2 = kern[3]; +    // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. +    vec3 dummy1 = kern[0]; +    vec3 dummy2 = kern[3];  #endif  } 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/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl new file mode 100644 index 0000000000..0157d166e0 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl @@ -0,0 +1,127 @@ +/**  + * @file class3/deferred/cloudsF.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 + +uniform sampler2D diffuseMap; + +VARYING vec4 pos; +VARYING float target_pos_x; +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 sunlight_color; +uniform vec4 cloud_color; +uniform float cloud_shadow; +uniform float cloud_scale; +uniform float cloud_variance; +uniform vec3 camPosLocal; +uniform vec3 sun_dir; +uniform float sun_size; +uniform float far_z; + +#if !defined(DEPTH_CLAMP) +VARYING vec4 post_pos; +#endif + +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 normalize(cloud_noise_sample); +} + +void main() +{ +    // Set variables +    vec2 uv1 = vary_texcoord0.xy; +    vec2 uv2 = vary_texcoord1.xy; +    vec2 uv3 = vary_texcoord2.xy; +    float cloudDensity = 2.0 * (cloud_shadow - 0.25); + +    if (cloud_scale >= 0.0001) +    { +        vec2 uv4 = vary_texcoord3.xy; +     +        vec2 disturbance  = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); +        vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); +     +        // Offset texture coords +        uv1 += cloud_pos_density1.xy + (disturbance * 0.2);    //large texture, visible density +        uv2 += cloud_pos_density1.xy;   //large texture, self shadow +        uv3 += cloud_pos_density2.xy;   //small texture, visible density +        uv4 += cloud_pos_density2.xy;   //small texture, self shadow +     +        float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y) * 4.0); +     +        cloudDensity *= 1.0 - (density_variance * density_variance); +     +        // 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;   +     +        if (alpha1 < 0.001f) +        { +            discard; +        } +     +        // 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;   +     +        frag_color = vec4(alpha1, alpha1, alpha1, 1); +    } +    else +    { +        frag_color = vec4(1); +    } + +#if !defined(DEPTH_CLAMP) +    gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0); +#endif + +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudShadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudShadowV.glsl new file mode 100644 index 0000000000..effb070f93 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudShadowV.glsl @@ -0,0 +1,63 @@ +/**  + * @file cloudShadowV.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 !defined(DEPTH_CLAMP) +VARYING float pos_zd2; +#endif + +VARYING vec4 pos; +VARYING float target_pos_x; +VARYING vec2 vary_texcoord0; +VARYING vec4 vertex_color; + +void passTextureIndex(); + +void main() +{ +	//transform vertex +	vec4 pre_pos = vec4(position.xyz, 1.0); +	pos = modelview_projection_matrix * pre_pos; +	target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; + +#if !defined(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/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index 1d8ca04ccd..ae1ac5de7f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -1,5 +1,5 @@  /**  - * @file WLCloudsF.glsl + * @file class1\deferred\cloudsF.glsl   *   * $LicenseInfo:firstyear=2005&license=viewerlgpl$   * Second Life Viewer Source Code @@ -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,69 +39,93 @@ 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; +uniform float cloud_scale; +uniform float cloud_variance;  VARYING vec2 vary_texcoord0;  VARYING vec2 vary_texcoord1;  VARYING vec2 vary_texcoord2;  VARYING vec2 vary_texcoord3; +VARYING float altitude_blend_factor;  /// 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); +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 -	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 = (texture2D(cloud_noise_texture, uv1).x - 0.5) + (texture2D(cloud_noise_texture, 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 = (texture2D(cloud_noise_texture, 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_data[0] = vec4(scaleSoftClip(color.rgb), alpha1); -	frag_data[1] = vec4(0.0,0.0,0.0,0.0); -	frag_data[2] = vec4(0,0,1,0); +    // 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; + +    if (cloud_scale < 0.001) +    { +        discard; +    } + +    vec2 disturbance  = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); +    vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + +    // Offset texture coords +    uv1 += cloud_pos_density1.xy + (disturbance * 0.2);    //large texture, visible density +    uv2 += cloud_pos_density1.xy;   //large texture, self shadow +    uv3 += cloud_pos_density2.xy;   //small texture, visible density +    uv4 += cloud_pos_density2.xy;   //small texture, self shadow + +    float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y) * 4.0); + +    cloudDensity *= 1.0 - (density_variance * density_variance); + +    // 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;   + +    alpha1 *= altitude_blend_factor; +    alpha1 = clamp(alpha1, 0.0, 1.0); + +    // Compute alpha2, for self shadowing effect +    // (1 - alpha2) will later be used as percentage of incoming sunlight +    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.rgb= max(vec3(0), color.rgb); +    color.rgb *= 2.0; +    color.rgb = scaleSoftClip(color.rgb); + +    /// Gamma correct for WL (soft clip effect). +    frag_data[0] = vec4(color.rgb, alpha1); +    frag_data[1] = vec4(0.0,0.0,0.0,0.0); +    frag_data[2] = vec4(0,0,0,1); + +    gl_FragDepth = 0.99995f;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl index 17f425475c..8e90c1481f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl @@ -41,13 +41,16 @@ VARYING vec2 vary_texcoord0;  VARYING vec2 vary_texcoord1;  VARYING vec2 vary_texcoord2;  VARYING vec2 vary_texcoord3; +VARYING float altitude_blend_factor;  // Inputs  uniform vec3 camPosLocal;  uniform vec4 lightnorm;  uniform vec4 sunlight_color; -uniform vec4 ambient; +uniform vec4 moonlight_color; +uniform int sun_up_factor; +uniform vec4 ambient_color;  uniform vec4 blue_horizon;  uniform vec4 blue_density;  uniform float haze_horizon; @@ -58,6 +61,7 @@ uniform float density_multiplier;  uniform float max_y;  uniform vec4 glow; +uniform float sun_moon_glow_factor;  uniform vec4 cloud_color; @@ -74,6 +78,8 @@ void main()  	// Get relative position  	vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); +    altitude_blend_factor = clamp((P.y + 512.0) / max_y, 0.0, 1.0); +  	// Set altitude  	if (P.y > 0.)  	{ @@ -93,16 +99,18 @@ void main()  	vec4 temp2 = vec4(0.);  	vec4 blue_weight;  	vec4 haze_weight; +	//vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color;  	vec4 sunlight = sunlight_color;  	vec4 light_atten; +    float dens_mul = density_multiplier;  	// Sunlight attenuation effect (hue and brightness) due to atmosphere  	// this is used later for sunlight modulation at various altitudes -	light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); +	light_atten = (blue_density + vec4(haze_density * 0.25)) * (dens_mul * max_y);  	// Calculate relative weights -	temp1 = blue_density + haze_density; +	temp1 = abs(blue_density) + vec4(abs(haze_density));  	blue_weight = blue_density / temp1;  	haze_weight = haze_density / temp1; @@ -112,7 +120,7 @@ void main()  	sunlight *= exp( - light_atten * temp2.y);  	// Distance -	temp2.z = Plen * density_multiplier; +	temp2.z = Plen * dens_mul;  	// Transparency (-> temp1)  	// ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati @@ -131,11 +139,13 @@ void main()  	temp2.x = pow(temp2.x, glow.z);  		// glow.z should be negative, so we're doing a sort of (1 / "angle") function +    temp2.x *= sun_moon_glow_factor; +  	// Add "minimum anti-solar illumination"  	temp2.x += .25;  	// Increase ambient when there are more clouds -	vec4 tmpAmbient = ambient; +	vec4 tmpAmbient = ambient_color;  	tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5;   	// Dim sunlight by cloud shadow percentage @@ -147,8 +157,6 @@ void main()  			 );	  	// CLOUDS - -	sunlight = sunlight_color;  	temp2.y = max(0., lightnorm.y * 2.);  	temp2.y = 1. / temp2.y;  	sunlight *= exp( - light_atten * temp2.y); diff --git a/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl index fef1c5a584..079d8458c9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl @@ -50,15 +50,6 @@ uniform vec2 screen_res;  VARYING vec2 vary_fragcoord; -float getDepth(vec2 pos_screen) -{ -	float z = texture2DRect(depthMap, pos_screen.xy).r; -	z = z*2.0-1.0; -	vec4 ndc = vec4(0.0, 0.0, z, 1.0); -	vec4 p = inv_proj*ndc; -	return p.z/p.w; -} -  float calc_cof(float depth)  {  	float sc = (depth-focal_distance)/-depth*blur_constant; @@ -77,8 +68,12 @@ float calc_cof(float depth)  void main()   {  	vec2 tc = vary_fragcoord.xy; -	 -	float depth = getDepth(tc); + +    float z = texture2DRect(depthMap, tc).r; +	z = z*2.0-1.0; +	vec4 ndc = vec4(0.0, 0.0, z, 1.0); +	vec4 p = inv_proj*ndc; +	float depth = p.z/p.w;  	vec4 diff = texture2DRect(diffuseRect, vary_fragcoord.xy); diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl new file mode 100644 index 0000000000..e27bbce094 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -0,0 +1,79 @@ +/**  + * @file class1/deferred/deferredUtil.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 sampler2DRect   normalMap; +uniform sampler2DRect   depthMap; + +uniform mat4 inv_proj; +uniform vec2 screen_res; + +vec2 getScreenCoordinate(vec2 screenpos) +{ +    vec2 sc = screenpos.xy * 2.0; +    if (screen_res.x > 0 && screen_res.y > 0) +    { +       sc /= screen_res; +    } +    return sc - vec2(1.0, 1.0); +} + +vec3 getNorm(vec2 screenpos) +{ +   vec2 enc = texture2DRect(normalMap, screenpos.xy).xy; +   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; +} + +float getDepth(vec2 pos_screen) +{ +    float depth = texture2DRect(depthMap, pos_screen).r; +    return depth; +} + +vec4 getPosition(vec2 pos_screen) +{ +    float depth = getDepth(pos_screen); +    vec2 sc = getScreenCoordinate(pos_screen); +    vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); +    vec4 pos = inv_proj * ndc; +    pos /= pos.w; +    pos.w = 1.0; +    return pos; +} + +vec4 getPositionWithDepth(vec2 pos_screen, float depth) +{ +    vec2 sc = getScreenCoordinate(pos_screen); +    vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); +    vec4 pos = inv_proj * ndc; +    pos /= pos.w; +    pos.w = 1.0; +    return pos; +} 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..ccd1df84f9 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,17 +35,13 @@ 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); +vec3 linear_to_srgb(vec3 c);  void main()   {  	vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb; -	 +  	vec3 spec;  	spec.rgb = vec3(vertex_color.a); diff --git a/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl b/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl index 0ffca8515c..f0522850de 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl @@ -44,7 +44,6 @@ void main()  	float shadow = 1.0;  	vec4 color = diffuseLookup(vary_texcoord0.xy)*vertex_color; -	color.rgb = pow(color.rgb, vec3(2.2));  	color.rgb = fullbrightAtmosTransport(color.rgb);  	color.rgb = fullbrightScaleSoftClip(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/deferred/emissiveV.glsl b/indra/newview/app_settings/shaders/class1/deferred/emissiveV.glsl index 115b04797f..5e4f08b017 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/emissiveV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/emissiveV.glsl @@ -34,11 +34,8 @@ ATTRIBUTE vec2 texcoord0;  void calcAtmospherics(vec3 inPositionEye); -vec3 atmosAmbient(vec3 light); +vec3 atmosAmbient();  vec3 atmosAffectDirectionalLight(float lightIntensity); -vec3 scaleDownLight(vec3 light); -vec3 scaleUpLight(vec3 light); -  VARYING vec4 vertex_color;  VARYING vec2 vary_texcoord0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 756e625d07..46ec20c8b0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -1,5 +1,5 @@  /**  - * @file fullbrightF.glsl + * @file deferred/fullbrightF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -33,7 +33,7 @@ out vec4 frag_color;  #define frag_color gl_FragColor  #endif -#if !HAS_DIFFUSE_LOOKUP +#if !defined(HAS_DIFFUSE_LOOKUP)  uniform sampler2D diffuseMap;  #endif @@ -41,108 +41,22 @@ 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 fullbrightAtmosTransportDeferred(vec3 light) -{ -	return light; -} - -vec3 fullbrightScaleSoftClipDeferred(vec3 light) -{ -	//soft clip effect: -	return light; -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); +vec3 fullbrightAtmosTransport(vec3 light); +vec3 fullbrightScaleSoftClip(vec3 light);  #ifdef HAS_ALPHA_MASK  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 +#ifdef HAS_DIFFUSE_LOOKUP  	vec4 color = diffuseLookup(vary_texcoord0.xy);  #else  	vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); @@ -158,19 +72,16 @@ void main()  #endif  	color.rgb *= vertex_color.rgb; -	color.rgb = srgb_to_linear(color.rgb); -	color.rgb = fullbrightAtmosTransportDeferred(color.rgb); -	color.rgb = fullbrightScaleSoftClipDeferred(color.rgb); -	 -	color.rgb = linear_to_srgb(color.rgb);  #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 -	color.a   = final_alpha; +    color.rgb = fullbrightAtmosTransport(color.rgb); +	color.rgb = fullbrightScaleSoftClip(color.rgb); +    color.a   = final_alpha;  #endif  	frag_color.rgb = color.rgb; diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl index b0db9876d3..523e7f9e04 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; @@ -31,7 +31,7 @@ out vec4 frag_color;  #define frag_color gl_FragColor  #endif -#ifndef diffuseLookup +#ifndef HAS_DIFFUSE_LOOKUP  uniform sampler2D diffuseMap;  #endif @@ -46,7 +46,7 @@ vec3 fullbrightScaleSoftClip(vec3 light);  void main()  { -#if HAS_DIFFUSE_LOOKUP +#ifdef HAS_DIFFUSE_LOOKUP  	vec4 color = diffuseLookup(vary_texcoord0.xy);  #else  	vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); @@ -56,7 +56,7 @@ void main()  	color.rgb *= vertex_color.rgb;  	vec3 envColor = textureCube(environmentMap, vary_texcoord1.xyz).rgb;	 -	color.rgb = mix(color.rgb, envColor.rgb, vertex_color.a); +	color.rgb = mix(color.rgb, envColor.rgb, vertex_color.a*0.75); // MAGIC NUMBER SL-12574; ALM: Off, Quality > Low  	color.rgb = pow(color.rgb,vec3(2.2f,2.2f,2.2f)); diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl index 8e899e3e0f..bdf3546aa5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl @@ -35,10 +35,8 @@ ATTRIBUTE vec2 texcoord0;  void calcAtmospherics(vec3 inPositionEye); -vec3 atmosAmbient(vec3 light); +vec3 atmosAmbient();  vec3 atmosAffectDirectionalLight(float lightIntensity); -vec3 scaleDownLight(vec3 light); -vec3 scaleUpLight(vec3 light);  #ifdef WATER_FOG  VARYING vec3 vary_position; diff --git a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl index f8fdde43f9..d29e8a9423 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,42 +40,6 @@ 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 - -} -  void main()   {  	vec4 col = texture2D(diffuseMap, vary_texcoord0.xy); @@ -86,8 +52,6 @@ void main()  	vec4 norm = texture2D(normalMap,   vary_texcoord0.xy);  	vec4 spec = texture2D(specularMap, vary_texcoord0.xy); -	col.rgb = linear_to_srgb(col.rgb); -  	frag_data[0] = vec4(col.rgb, 0.0);  	frag_data[1] = spec;  	frag_data[2] = vec4(norm.xy,0,0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/indirect.glsl b/indra/newview/app_settings/shaders/class1/deferred/indirect.glsl new file mode 100644 index 0000000000..49bfa660f8 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/indirect.glsl @@ -0,0 +1,30 @@ +/**  + * @file class1/deferred/indirect.glsl + * + * $LicenseInfo:firstyear=2018&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 getIndirect(vec3 ambient, vec3 norm, vec3 pos, vec2 pos_screen) +{ +    return ambient; +} + 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..f1b13c8825 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -1,72 +1,56 @@ -/**  - * @file materialF.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - *  - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - *  - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU - * Lesser General Public License for more details. - *  - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA - *  - * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA - * $/LicenseInfo$ - */ -  -#define DIFFUSE_ALPHA_MODE_IGNORE	0 -#define DIFFUSE_ALPHA_MODE_BLEND	1 -#define DIFFUSE_ALPHA_MODE_MASK		2 +/** +* @file materialF.glsl +* +* $LicenseInfo:firstyear=2007&license=viewerlgpl$ +* Second Life Viewer Source Code +* Copyright (C) 2007, Linden Research, Inc. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; +* version 2.1 of the License only. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA +* +* Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA +* $/LicenseInfo$ +*/ + +/*[EXTRA_CODE_HERE]*/ + +//class1/deferred/materialF.glsl + +// This shader is used for both writing opaque/masked content to the gbuffer and writing blended content to the framebuffer during the alpha pass. + +#define DIFFUSE_ALPHA_MODE_NONE     0 +#define DIFFUSE_ALPHA_MODE_BLEND    1 +#define DIFFUSE_ALPHA_MODE_MASK     2  #define DIFFUSE_ALPHA_MODE_EMISSIVE 3 -uniform float emissive_brightness; -uniform float display_gamma; +uniform float emissive_brightness;  // fullbright flag, 1.0 == fullbright, 0.0 otherwise +uniform int sun_up_factor; -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 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); +vec3 scaleSoftClipFrag(vec3 l); -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 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); +vec3 fullbrightScaleSoftClip(vec3 light); -} +void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); + +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cs);  #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) @@ -76,404 +60,115 @@ out vec4 frag_color;  #define frag_color gl_FragColor  #endif -#if HAS_SUN_SHADOW - -uniform sampler2DShadow shadowMap0; -uniform sampler2DShadow shadowMap1; -uniform sampler2DShadow shadowMap2; -uniform sampler2DShadow shadowMap3; - -uniform mat4 shadow_matrix[6]; -uniform vec4 shadow_clip; -uniform vec2 shadow_res; -uniform float shadow_bias; - -float pcfShadow(sampler2DShadow shadowMap, vec4 stc) -{ -	stc.xyz /= stc.w; -	stc.z += shadow_bias; -		 -	stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y*12345))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here -	 -	float cs = shadow2D(shadowMap, stc.xyz).x; -	float shadow = cs; -	 -    shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; -    shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; -    shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; -    shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; -                        -    return shadow*0.2; -} - +#ifdef HAS_SUN_SHADOW +float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen);  #endif  uniform samplerCube environmentMap; -uniform sampler2D	  lightFunc; +uniform sampler2D     lightFunc;  // Inputs  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 proj_mat;  uniform mat4 inv_proj;  uniform vec2 screen_res;  uniform vec4 light_position[8];  uniform vec3 light_direction[8]; -uniform vec3 light_attenuation[8];  +uniform vec4 light_attenuation[8];  uniform vec3 light_diffuse[8]; -#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); -	return vec3(a,a,a); -} - - -vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spec, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, inout float glare) -{ -	//get light vector -	vec3 lv = lp.xyz-v; -	 -	//get distance -	float d = length(lv); -	 -	float da = 1.0; - -	vec3 col = vec3(0,0,0); - -	if (d > 0.0 && la > 0.0 && fa > 0.0) -	{ -		//normalize light vector -		lv = normalize(lv); -	 -		//distance attenuation -		float dist = d/la; -		float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); -		dist_atten *= dist_atten; -		dist_atten *= 2.0; - -		// spotlight coefficient. -		float spot = max(dot(-ln, lv), is_pointlight); -		da *= spot*spot; // GL_SPOT_EXPONENT=2 - -		//angular attenuation -		da *= max(dot(n, lv), 0.0);		 -		 -		float lit = max(da * dist_atten, 0.0); - -		col = light_col*lit*diffuse; - -		if (spec.a > 0.0) -		{ -			//vec3 ref = dot(pos+lv, norm); -			vec3 h = normalize(lv+npos); -			float nh = dot(n, h); -			float nv = dot(n, npos); -			float vh = dot(npos, h); -			float sa = nh; -			float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - -			float gtdenom = 2 * nh; -			float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); -								 -			if (nh > 0.0) -			{ -				float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); -				vec3 speccol = lit*scol*light_col.rgb*spec.rgb; -				col += speccol; - -				float cur_glare = max(speccol.r, speccol.g); -				cur_glare = max(cur_glare, speccol.b); -				glare = max(glare, speccol.r); -				glare += max(cur_glare, 0.0); -				//col += spec.rgb; -			} -		} -	} - -	return max(col, vec3(0.0,0.0,0.0));	 - -} - -vec4 getPosition_d(vec2 pos_screen, float depth) -{ -	vec2 sc = pos_screen.xy*2.0; -	sc /= screen_res; -	sc -= vec2(1.0,1.0); -	vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); -	vec4 pos = inv_proj * ndc; -	pos /= pos.w; -	pos.w = 1.0; -	return pos; -} - -#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)); -} +float getAmbientClamp(); -vec3 atmosAffectDirectionalLight(float lightIntensity) +vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spec, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, inout float glare, float ambiance)  { -	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; +    vec3 col = vec3(0); + +    //get light vector +    vec3 lv = lp.xyz - v; + +    //get distance +    float dist = length(lv); +    float da = 1.0; + +    dist /= la; + +    if (dist > 0.0 && la > 0.0) +    { +        //normalize light vector +        lv = normalize(lv); + +        //distance attenuation +        float dist_atten = clamp(1.0 - (dist - 1.0*(1.0 - fa)) / fa, 0.0, 1.0); +        dist_atten *= dist_atten; +        dist_atten *= 2.0f; + +        if (dist_atten <= 0.0) +        { +            return col; +        } + +        // spotlight coefficient. +        float spot = max(dot(-ln, lv), is_pointlight); +        da *= spot*spot; // GL_SPOT_EXPONENT=2 + +        //angular attenuation +        da *= dot(n, lv); + +        float lit = 0.0f; + +        float amb_da = ambiance; +        if (da >= 0) +        { +            lit = max(da * dist_atten, 0.0); +            col = lit * light_col * diffuse; +            amb_da += (da*0.5 + 0.5) * ambiance; +        } +        amb_da += (da*da*0.5 + 0.5) * ambiance; +        amb_da *= dist_atten; +        amb_da = min(amb_da, 1.0f - lit); + +        // SL-10969 need to see why these are blown out +        //col.rgb += amb_da * light_col * diffuse; + +        if (spec.a > 0.0) +        { +            //vec3 ref = dot(pos+lv, norm); +            vec3 h = normalize(lv + npos); +            float nh = dot(n, h); +            float nv = dot(n, npos); +            float vh = dot(npos, h); +            float sa = nh; +            float fres = pow(1 - dot(h, npos), 5)*0.4 + 0.5; + +            float gtdenom = 2 * nh; +            float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + +            if (nh > 0.0) +            { +                float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt / (nh*da); +                vec3 speccol = lit*scol*light_col.rgb*spec.rgb; +                speccol = clamp(speccol, vec3(0), vec3(1)); +                col += speccol; + +                float cur_glare = max(speccol.r, speccol.g); +                cur_glare = max(cur_glare, speccol.b); +                glare = max(glare, speccol.r); +                glare += max(cur_glare, 0.0); +            } +        } +    } + +    return max(col, vec3(0.0, 0.0, 0.0));  }  #else @@ -484,13 +179,13 @@ out vec4 frag_data[3];  #endif  #endif -uniform sampler2D diffuseMap; +uniform sampler2D diffuseMap;  //always in sRGB space -#if HAS_NORMAL_MAP +#ifdef HAS_NORMAL_MAP  uniform sampler2D bumpMap;  #endif -#if HAS_SPECULAR_MAP +#ifdef HAS_SPECULAR_MAP  uniform sampler2D specularMap;  VARYING vec2 vary_texcoord2; @@ -503,7 +198,7 @@ uniform vec4 specular_color;  // specular color RGB and specular exponent (gloss  uniform float minimum_alpha;  #endif -#if HAS_NORMAL_MAP +#ifdef HAS_NORMAL_MAP  VARYING vec3 vary_mat0;  VARYING vec3 vary_mat1;  VARYING vec3 vary_mat2; @@ -515,274 +210,259 @@ 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); -void main()  +void main()  { -	vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); -	diffcol.rgb *= vertex_color.rgb; +    vec2 pos_screen = vary_texcoord0.xy; + +    vec4 diffuse_srgb = texture2D(diffuseMap, vary_texcoord0.xy); +    diffuse_srgb.rgb *= vertex_color.rgb; +     +    // For some reason the Transparency slider sets vertex_color.a to 0.0 both for +    // fully opaque and for fully transparent objects. This code assumes the 0 alpha +    // is always from the opaque end of the scale. TODO: Remove the conditional once +    // the root cause of the slider ambiguity is fixed. +    if (vertex_color.a > 0.0) +    { +        diffuse_srgb.a *= vertex_color.a; +    } +    vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a);  #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) -	if (diffcol.a < minimum_alpha) -	{ -		discard; -	} +    if (diffuse_linear.a < minimum_alpha) +    { +        discard; +    }  #endif -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) -	vec3 gamma_diff = diffcol.rgb; -	diffcol.rgb = srgb_to_linear(diffcol.rgb); -#endif - -#if HAS_SPECULAR_MAP -	vec4 spec = texture2D(specularMap, vary_texcoord2.xy); -	spec.rgb *= specular_color.rgb; +#ifdef HAS_SPECULAR_MAP +    vec4 spec = texture2D(specularMap, vary_texcoord2.xy); +    spec.rgb *= specular_color.rgb;  #else -	vec4 spec = vec4(specular_color.rgb, 1.0); +    vec4 spec = vec4(specular_color.rgb, 1.0);  #endif -#if HAS_NORMAL_MAP -	vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); +    vec3 norm = vec3(0); +    float bmap_specular = 1.0; -	norm.xyz = norm.xyz * 2 - 1; +#ifdef HAS_NORMAL_MAP +    vec4 bump_sample = texture2D(bumpMap, vary_texcoord1.xy); +    norm = (bump_sample.xyz * 2) - vec3(1); +    bmap_specular = bump_sample.w; -	vec3 tnorm = vec3(dot(norm.xyz,vary_mat0), -			  dot(norm.xyz,vary_mat1), -			  dot(norm.xyz,vary_mat2)); +    // convert sampled normal to tangent space normal +    norm = vec3(dot(norm, vary_mat0), +        dot(norm, vary_mat1), +        dot(norm, vary_mat2));  #else -	vec4 norm = vec4(0,0,0,1.0); -	vec3 tnorm = vary_normal; +    norm = vary_normal;  #endif -    norm.xyz = tnorm; -    norm.xyz = normalize(norm.xyz); +    norm = normalize(norm); -	vec2 abnormal	= encode_normal(norm.xyz); -		 norm.xyz   = decode_normal(abnormal.xy); +    vec2 abnormal = encode_normal(norm); -	vec4 final_color = diffcol; -	 -#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) -	final_color.a = emissive_brightness; -#else -	final_color.a = max(final_color.a, emissive_brightness); -#endif +    vec4 final_color = vec4(diffuse_linear.rgb, 0.0); -	vec4 final_specular = spec; -#if HAS_SPECULAR_MAP -	vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, 0.0); -	final_specular.a = specular_color.a * norm.a; -#else -	vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); -	final_specular.a = specular_color.a; +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_EMISSIVE) +    final_color.a = diffuse_linear.a * 0.5; // SL-12171  #endif -	 -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) -		//forward rendering, output just lit RGBA -	vec3 pos = vary_position; - -#if HAS_SUN_SHADOW -	float shadow = 0.0; -	 -	vec4 spos = vec4(pos,1.0); -		 -	if (spos.z > -shadow_clip.w) -	{	 -		vec4 lpos; -		 -		vec4 near_split = shadow_clip*-0.75; -		vec4 far_split = shadow_clip*-1.25; -		vec4 transition_domain = near_split-far_split; -		float weight = 0.0; - -		if (spos.z < near_split.z) -		{ -			lpos = shadow_matrix[3]*spos; -			 -			float w = 1.0; -			w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; -			shadow += pcfShadow(shadowMap3, lpos)*w; -			weight += w; -			shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); -		} - -		if (spos.z < near_split.y && spos.z > far_split.z) -		{ -			lpos = shadow_matrix[2]*spos; -			 -			float w = 1.0; -			w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; -			w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; -			shadow += pcfShadow(shadowMap2, lpos)*w; -			weight += w; -		} - -		if (spos.z < near_split.x && spos.z > far_split.y) -		{ -			lpos = shadow_matrix[1]*spos; -			 -			float w = 1.0; -			w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; -			w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; -			shadow += pcfShadow(shadowMap1, lpos)*w; -			weight += w; -		} - -		if (spos.z > far_split.x) -		{ -			lpos = shadow_matrix[0]*spos; -							 -			float w = 1.0; -			w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; -				 -			shadow += pcfShadow(shadowMap0, lpos)*w; -			weight += w; -		} -		 - -		shadow /= weight; -	} -	else -	{ -		shadow = 1.0; -	} -#else -	float shadow = 1.0; +    final_color.a = max(final_color.a, emissive_brightness); + +    // Texture +    //     [x] Full Bright (emissive_brightness >= 1.0) +    //     Shininess (specular) +    //       [X] Texture +    //       Environment Intensity = 1 +    // NOTE: There are two shaders that are used depending on the EI byte value: +    //     EI = 0        fullbright +    //     EI > 0 .. 255 material +    // When it is passed to us it is normalized. +    // We can either modify the output environment intensity +    //   OR +    // adjust the final color via: +    //     final_color *= 0.666666; +    // We don't remap the environment intensity but adjust the final color to closely simulate what non-EEP is doing. +    vec4 final_normal = vec4(abnormal, env_intensity, 0.0); + +    vec3 color = vec3(0.0); +    float al = 0; + +#ifdef HAS_SPECULAR_MAP +    if (emissive_brightness >= 1.0) // ie, if fullbright +    { +        float ei = env_intensity*0.5 + 0.5; +        final_normal = vec4(abnormal, ei, 0.0); +    }  #endif -	spec = final_specular; -	vec4 diffuse = final_color; -	float envIntensity = final_normal.z; - -    vec3 col = vec3(0.0f,0.0f,0.0f); +    vec4 final_specular = spec; -	float bloom = 0.0; -	calcAtmospherics(pos.xyz, 1.0); -	 -	vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); +    final_specular.a = specular_color.a; -	float da =dot(norm.xyz, sun_dir.xyz); - -    float final_da = da; -          final_da = min(final_da, shadow); -          //final_da = max(final_da, diffuse.a); -          final_da = max(final_da, 0.0f); -		  final_da = min(final_da, 1.0f); -		  final_da = pow(final_da, 1.0/1.3); - -	col.rgb = atmosAmbient(col); -	 -	float ambient = min(abs(da), 1.0); -	ambient *= 0.5; -	ambient *= ambient; -	ambient = (1.0-ambient); - -	col.rgb *= ambient; - -	col.rgb = col.rgb + atmosAffectDirectionalLight(final_da); +#ifdef HAS_SPECULAR_MAP +    final_specular.a *= bmap_specular; +    final_normal.z *= spec.a; +#endif -	col.rgb *= gamma_diff.rgb; -	 -	float glare = 0.0; +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) -	if (spec.a > 0.0) // specular reflection -	{ -		// 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); -							 -		// add the two types of shiny together -		vec3 spec_contrib = dumbshiny * spec.rgb; -		bloom = dot(spec_contrib, spec_contrib) / 6; +    //forward rendering, output just lit sRGBA +    vec3 pos = vary_position; -		glare = max(spec_contrib.r, spec_contrib.g); -		glare = max(glare, spec_contrib.b); +    float shadow = 1.0f; -		col += spec_contrib; -	} +#ifdef HAS_SUN_SHADOW +    shadow = sampleDirectionalShadow(pos.xyz, norm, pos_screen); +#endif +    spec = final_specular; + +    float envIntensity = final_normal.z; + +    vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + +    float bloom = 0.0; +    vec3 sunlit; +    vec3 amblit; +    vec3 additive; +    vec3 atten; + +    calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); +     +    if (emissive_brightness >= 1.0)	// fullbright, skip lighting calculations +    { +        color = fullbrightAtmosTransportFrag(diffuse_srgb.rgb, additive, atten); +        // This call breaks the Mac GLSL compiler/linker for unknown reasons (17Mar2020) +        // The call is either a no-op or a pure (pow) gamma adjustment, depending on GPU level +        // TODO: determine if we want to re-apply the gamma adjustment, and if so understand & fix Mac breakage +        //color = fullbrightScaleSoftClip(color); + +        al = diffuse_srgb.a; +    } +    else // not fullbright, calculate lighting +    { +        vec3 refnormpersp = normalize(reflect(pos.xyz, norm)); + +        //we're in sRGB space, so gamma correct this dot product so  +        // lighting from the sun stays sharp +        float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0); +        da = pow(da, 1.0 / 1.3); + +        //darken ambient for normals perpendicular to light vector so surfaces in shadow  +        // and facing away from light still have some definition to them. +        // do NOT gamma correct this dot product so ambient lighting stays soft +        float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); +        ambient *= 0.5; +        ambient *= ambient; +        ambient = (1.0 - ambient); + +        vec3 sun_contrib = min(da, shadow) * sunlit; + +#if !defined(AMBIENT_KILL) +        color = amblit; +        color *= ambient; +#endif -	col = mix(col.rgb, diffcol.rgb, diffuse.a); +#if !defined(SUNLIGHT_KILL) +        color += sun_contrib; +#endif +        color *= diffuse_srgb.rgb; + +        float glare = 0.0; + +        if (spec.a > 0.0) // specular reflection +        { +            vec3 npos = -normalize(pos.xyz); + +            //vec3 ref = dot(pos+lv, norm); +            vec3 h = normalize(light_dir.xyz + npos); +            float nh = dot(norm, h); +            float nv = dot(norm, npos); +            float vh = dot(npos, h); +            float sa = nh; +            float fres = pow(1 - dot(h, npos), 5)*0.4 + 0.5; + +            float gtdenom = 2 * nh; +            float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + +            if (nh > 0.0) +            { +                float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt / (nh*da); +                vec3 sp = sun_contrib*scol / 6.0f; +                sp = clamp(sp, vec3(0), vec3(1)); +                bloom = dot(sp, sp) / 4.0; +#if !defined(SUNLIGHT_KILL) +                color += sp * spec.rgb; +#endif +            } +        } -	if (envIntensity > 0.0) -	{ -		//add environmentmap -		vec3 env_vec = env_mat * refnormpersp; -		 -		vec3 refcol = textureCube(environmentMap, env_vec).rgb; +        if (envIntensity > 0.0) +        { +            //add environmentmap +            vec3 env_vec = env_mat * refnormpersp; -		col = mix(col.rgb, refcol,  -			envIntensity);   +            vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; -		float cur_glare = max(refcol.r, refcol.g); -		cur_glare = max(cur_glare, refcol.b); -		cur_glare *= envIntensity*4.0; -		glare += cur_glare; -	} +#if !defined(SUNLIGHT_KILL) +            color = mix(color, reflected_color, envIntensity); +#endif +            float cur_glare = max(reflected_color.r, reflected_color.g); +            cur_glare = max(cur_glare, reflected_color.b); +            cur_glare *= envIntensity*4.0; +            glare += cur_glare; +        } -	//col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); -	//col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col),  diffuse.a); +        color = atmosFragLighting(color, additive, atten); +        color = scaleSoftClipFrag(color); -	col = atmosLighting(col); -	col = scaleSoftClip(col); +        vec3 npos = normalize(-pos.xyz); -	//convert to linear space before adding local lights -	col = srgb_to_linear(col); +        vec3 light = vec3(0, 0, 0); -	vec3 npos = normalize(-pos.xyz); -			 -	vec3 light = vec3(0,0,0); +        //convert to linear before adding local lights +        color = srgb_to_linear(color); - #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare); +#define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.rgb, final_specular, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare, light_attenuation[i].w ); -		LIGHT_LOOP(1) -		LIGHT_LOOP(2) -		LIGHT_LOOP(3) -		LIGHT_LOOP(4) -		LIGHT_LOOP(5) -		LIGHT_LOOP(6) -		LIGHT_LOOP(7) +        LIGHT_LOOP(1) +            LIGHT_LOOP(2) +            LIGHT_LOOP(3) +            LIGHT_LOOP(4) +            LIGHT_LOOP(5) +            LIGHT_LOOP(6) +            LIGHT_LOOP(7) -	col.rgb += light.rgb; +            glare = min(glare, 1.0); +        al = max(diffuse_linear.a, glare)*vertex_color.a; -	glare = min(glare, 1.0); -	float al = max(diffcol.a,glare)*vertex_color.a; +#if !defined(LOCAL_LIGHT_KILL) +        color += light; +#endif -	//convert to gamma space for display on screen -	col.rgb = linear_to_srgb(col.rgb); +        //convert to srgb as this color is being written post gamma correction +        color = linear_to_srgb(color); +    }  #ifdef WATER_FOG -	vec4 temp = applyWaterFogDeferred(pos, vec4(col.rgb, al)); -	col.rgb = temp.rgb; -	al = temp.a; +    vec4 temp = applyWaterFogView(pos, vec4(color, al)); +    color = temp.rgb; +    al = temp.a;  #endif -	frag_color.rgb = col.rgb; -	frag_color.a   = al; +    // Don't allow alpha to exceed input value - SL-12592 +    frag_color = vec4(color, min(al, diffuse_srgb.a)); -#else -	frag_data[0] = final_color; -	frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. -	frag_data[2] = final_normal; // XY = Normal.  Z = Env. intensity. +#else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer  + +    // deferred path +    frag_data[0] = vec4(linear_to_srgb(final_color.rgb), final_color.a); //gbuffer is sRGB +    frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. +    frag_data[2] = final_normal; // XY = Normal.  Z = Env. intensity.  #endif  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl index 393d1e69da..7e29ada205 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl @@ -28,7 +28,7 @@  #define DIFFUSE_ALPHA_MODE_MASK 2  #define DIFFUSE_ALPHA_MODE_EMISSIVE 3 -#if HAS_SKIN +#ifdef HAS_SKIN  uniform mat4 modelview_matrix;  uniform mat4 projection_matrix;  mat4 getObjectSkinnedTransform(); @@ -39,7 +39,7 @@ uniform mat4 modelview_projection_matrix;  #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) -#if !HAS_SKIN +#if !defined(HAS_SKIN)  uniform mat4 modelview_matrix;  #endif @@ -55,7 +55,7 @@ ATTRIBUTE vec3 normal;  ATTRIBUTE vec2 texcoord0; -#if HAS_NORMAL_MAP +#ifdef HAS_NORMAL_MAP  ATTRIBUTE vec4 tangent;  ATTRIBUTE vec2 texcoord1; @@ -68,7 +68,7 @@ VARYING vec2 vary_texcoord1;  VARYING vec3 vary_normal;  #endif -#if HAS_SPECULAR_MAP +#ifdef HAS_SPECULAR_MAP  ATTRIBUTE vec2 texcoord2;  VARYING vec2 vary_texcoord2;  #endif @@ -78,7 +78,7 @@ VARYING vec2 vary_texcoord0;  void main()  { -#if HAS_SKIN +#ifdef HAS_SKIN  	mat4 mat = getObjectSkinnedTransform();  	mat = modelview_matrix * mat; @@ -99,17 +99,17 @@ void main()  	vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; -#if HAS_NORMAL_MAP +#ifdef HAS_NORMAL_MAP  	vary_texcoord1 = (texture_matrix0 * vec4(texcoord1,0,1)).xy;  #endif -#if HAS_SPECULAR_MAP +#ifdef HAS_SPECULAR_MAP  	vary_texcoord2 = (texture_matrix0 * vec4(texcoord2,0,1)).xy;  #endif -#if HAS_SKIN +#ifdef HAS_SKIN  	vec3 n = normalize((mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz); -#if HAS_NORMAL_MAP +#ifdef HAS_NORMAL_MAP  	vec3 t = normalize((mat*vec4(tangent.xyz+position.xyz,1.0)).xyz-pos.xyz);  	vec3 b = cross(n, t)*tangent.w; @@ -121,7 +121,7 @@ vary_normal  = n;  #endif //HAS_NORMAL_MAP  #else //HAS_SKIN  	vec3 n = normalize(normal_matrix * normal); -#if HAS_NORMAL_MAP +#ifdef HAS_NORMAL_MAP  	vec3 t = normalize(normal_matrix * tangent.xyz);  	vec3 b = cross(n,t)*tangent.w;  	//vec3 t = cross(b,n) * binormal.w; @@ -137,7 +137,7 @@ vary_normal  = n;  	vertex_color = diffuse_color;  #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) -#if !HAS_SKIN +#if !defined(HAS_SKIN)  	vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz;  #endif  #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl new file mode 100644 index 0000000000..80f232948a --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -0,0 +1,74 @@ +/**  + * @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_data[3]; +#else +#define frag_data gl_FragData +#endif + +uniform vec4 color; +uniform vec4 sunlight_color; +uniform vec4 moonlight_color; +uniform vec3 lumWeights; +uniform float moon_brightness; +uniform float minLuminance; +uniform sampler2D diffuseMap; +uniform sampler2D altDiffuseMap; +uniform float blend_factor; // interp factor between moon A/B +VARYING vec2 vary_texcoord0; + +vec3 srgb_to_linear(vec3 c); +void main()  +{ +    vec4 moonA = texture2D(diffuseMap, vary_texcoord0.xy); +    vec4 moonB = texture2D(altDiffuseMap, vary_texcoord0.xy); +    vec4 c     = mix(moonA, moonB, blend_factor); + +    c.rgb = srgb_to_linear(c.rgb); + +    // mix factor which blends when sunlight is brighter +    // and shows true moon color at night +    vec3 luma_weights = vec3(0.3, 0.5, 0.3); + +    vec4 light_color = max(sunlight_color, moonlight_color); +    float mix = 1.0 - dot(normalize(light_color.rgb), luma_weights); + +    vec3 exp = vec3(1.0 - mix * moon_brightness) * 2.0  - 1.0; +    c.rgb = pow(c.rgb, exp); + +    //c.rgb *= moonlight_color.rgb; + +    frag_data[0] = vec4(c.rgb, c.a); +    frag_data[1] = vec4(0.0); +    frag_data[2] = vec4(0.0f); + +    gl_FragDepth = 0.999985f; +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl new file mode 100644 index 0000000000..e1bac4f248 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl @@ -0,0 +1,49 @@ +/**  + * @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; + +VARYING vec2 vary_texcoord0; + +void calcAtmospherics(vec3 eye_pos); + +void main() +{ +    //transform vertex +    vec3 offset = vec3(0, 0, 50); +    vec4 vert = vec4(position.xyz - offset, 1.0); +    vec4 pos = (modelview_matrix * vert); + +    gl_Position = modelview_projection_matrix*vert; + +    calcAtmospherics(pos.xyz); +     +    vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index 9974f8f31b..0d1cc81786 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -36,7 +36,6 @@ out vec4 frag_color;  uniform sampler2DRect depthMap;  uniform sampler2DRect diffuseRect;  uniform sampler2DRect specularRect; -uniform sampler2DRect normalMap;  uniform samplerCube environmentMap;  uniform sampler2D noiseMap;  uniform sampler2D lightFunc; @@ -57,38 +56,17 @@ 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; -} - -vec4 getPosition(vec2 pos_screen) -{ -	float depth = texture2DRect(depthMap, pos_screen.xy).r; -	vec2 sc = pos_screen.xy*2.0; -	sc /= screen_res; -	sc -= vec2(1.0,1.0); -	vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); -	vec4 pos = inv_proj * ndc; -	pos /= pos.w; -	pos.w = 1.0; -	return pos; -} +vec4 getPosition(vec2 pos_screen); +vec3 getNorm(vec2 pos_screen); +vec3 srgb_to_linear(vec3 c);  void main()   { +	vec3 out_col = vec3(0,0,0); + +#if defined(LOCAL_LIGHT_KILL) +    discard; +#else  	vec2 frag = (vary_fragcoord.xy*0.5+0.5)*screen_res;  	vec3 pos = getPosition(frag.xy).xyz;  	if (pos.z < far_z) @@ -96,14 +74,13 @@ void main()  		discard;  	} -	vec3 norm = texture2DRect(normalMap, frag.xy).xyz; -	norm = decode_normal(norm.xy); // unpack norm -	norm = normalize(norm); +	vec3 norm = getNorm(frag.xy); +  	vec4 spec = texture2DRect(specularRect, frag.xy);  	vec3 diff = texture2DRect(diffuseRect, frag.xy).rgb; +    diff.rgb = srgb_to_linear(diff.rgb);  	float noise = texture2D(noiseMap, frag.xy/128.0).b; -	vec3 out_col = vec3(0,0,0);  	vec3 npos = normalize(-pos);  	// As of OSX 10.6.7 ATI Apple's crash when using a variable size loop @@ -123,6 +100,9 @@ void main()  			float fa = light_col[i].a+1.0;  			float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0);  			dist_atten *= dist_atten; +             +            // Tweak falloff slightly to match pre-EEP attenuation +			// NOTE: this magic number also shows up in a great many other places, search for dist_atten *= to audit  			dist_atten *= 2.0;  			dist_atten *= noise; @@ -159,7 +139,7 @@ void main()  		}  	}  	} -	 +#endif  	frag_color.rgb = out_col;  	frag_color.a = 0.0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 3a3e871ade..9bba45bc4e 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; @@ -71,60 +71,8 @@ VARYING vec4 vary_fragcoord;  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 getNorm(vec2 pos_screen); +vec3 srgb_to_linear(vec3 c);  vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod)  { @@ -178,22 +126,15 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod)  	return ret;  } - -vec4 getPosition(vec2 pos_screen) -{ -	float depth = texture2DRect(depthMap, pos_screen.xy).r; -	vec2 sc = pos_screen.xy*2.0; -	sc /= screen_res; -	sc -= vec2(1.0,1.0); -	vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); -	vec4 pos = inv_proj * ndc; -	pos /= pos.w; -	pos.w = 1.0; -	return pos; -} +vec4 getPosition(vec2 pos_screen);  void main()   { +	vec3 col = vec3(0,0,0); + +#if defined(LOCAL_LIGHT_KILL) +    discard; +#else  	vec4 frag = vary_fragcoord;  	frag.xyz /= frag.w;  	frag.xyz = frag.xyz*0.5+0.5; @@ -208,12 +149,9 @@ void main()  		discard;  	} -	vec3 norm = texture2DRect(normalMap, frag.xy).xyz; -	float envIntensity = norm.z; +	float envIntensity = texture2DRect(normalMap, frag.xy).z; +	vec3 norm = getNorm(frag.xy); -	norm = decode_normal(norm.xy); -	 -	norm = normalize(norm);  	float l_dist = -dot(lv, proj_n);  	vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); @@ -225,25 +163,33 @@ void main()  	proj_tc.xyz /= proj_tc.w;  	float fa = falloff+1.0; -	float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); +	float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0);  	dist_atten *= dist_atten;  	dist_atten *= 2.0; +	  	if (dist_atten <= 0.0)  	{  		discard;  	} +	float noise = texture2D(noiseMap, frag.xy/128.0).b; +	dist_atten *= noise; +  	lv = proj_origin-pos.xyz;  	lv = normalize(lv);  	float da = dot(norm, lv); -	vec3 col = vec3(0,0,0);  	vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; +    // SL-12005 Projector light pops as we get closer, more objectionable than being in wrong color space. +    //          We can't switch to linear here unless we do it everywhere* +	// *gbuffer is sRGB, convert to linear whenever sampling from it +    diff_tex.rgb = srgb_to_linear(diff_tex.rgb); +  	vec3 dlit = vec3(0, 0, 0); -	float noise = texture2D(noiseMap, frag.xy/128.0).b; +	  	if (proj_tc.z > 0.0 &&  		proj_tc.x < 1.0 &&  		proj_tc.y < 1.0 && @@ -262,7 +208,7 @@ void main()  			dlit = color.rgb * plcol.rgb * plcol.a; -			lit = da * dist_atten * noise; +			lit = da * dist_atten;  			col = dlit*lit*diff_tex;  			amb_da += (da*0.5)*proj_ambiance; @@ -304,7 +250,7 @@ void main()  			col += dlit*scol*spec.rgb;  			//col += spec.rgb;  		} -	}	 +	}  	if (envIntensity > 0.0)  	{ @@ -334,7 +280,9 @@ void main()  			}  		}  	} -	 +#endif + +	//output linear, sum of lights will be gamma corrected later	  	frag_color.rgb = col;	  	frag_color.a = 0.0;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index aba4a01754..d805c9ea48 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -56,103 +56,78 @@ 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; -} - -vec4 getPosition(vec2 pos_screen) -{ -	float depth = texture2DRect(depthMap, pos_screen.xy).r; -	vec2 sc = (pos_screen.xy-viewport.xy)*2.0; -	sc /= viewport.zw; -	sc -= vec2(1.0,1.0); -	vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); -	vec4 pos = inv_proj * ndc; -	pos /= pos.w; -	pos.w = 1.0; -	return pos; -} +vec3 getNorm(vec2 pos_screen); +vec4 getPosition(vec2 pos_screen); +vec3 srgb_to_linear(vec3 c);  void main()   { -	vec4 frag = vary_fragcoord; -	frag.xyz /= frag.w; -	frag.xyz = frag.xyz*0.5+0.5; -	frag.xy *= screen_res; -	 -	vec3 pos = getPosition(frag.xy).xyz; -	vec3 lv = trans_center.xyz-pos; -	float dist = length(lv); -	dist /= size; -	if (dist > 1.0) -	{ -		discard; -	} -	 -	vec3 norm = texture2DRect(normalMap, frag.xy).xyz; -	norm = decode_normal(norm.xy); // unpack norm -	float da = dot(norm, lv); -	if (da < 0.0) -	{ -		discard; -	} -	 -	norm = normalize(norm); -	lv = normalize(lv); -	da = dot(norm, lv); -	 -	float noise = texture2D(noiseMap, frag.xy/128.0).b; -	 -	vec3 col = texture2DRect(diffuseRect, frag.xy).rgb; -	float fa = falloff+1.0; -	float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); -	dist_atten *= dist_atten; -	dist_atten *= 2.0; -	 -	float lit = da * dist_atten * noise; - -	col = color.rgb*lit*col; - -	vec4 spec = texture2DRect(specularRect, frag.xy); -	if (spec.a > 0.0) -	{ -		lit = min(da*6.0, 1.0) * dist_atten; - -		vec3 npos = -normalize(pos); -		vec3 h = normalize(lv+npos); -		float nh = dot(norm, h); -		float nv = dot(norm, npos); -		float vh = dot(npos, h); -		float sa = nh; -		float fres = pow(1 - dot(h, npos), 5) * 0.4+0.5; -		float gtdenom = 2 * nh; -		float gt = max(0,(min(gtdenom * nv / vh, gtdenom * da / vh))); - -		if (nh > 0.0) -		{ -			float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); -			col += lit*scol*color.rgb*spec.rgb; -		} -	} -	 -	if (dot(col, col) <= 0.0) -	{ -		discard; -	} -		 -	frag_color.rgb = col;	 -	frag_color.a = 0.0; +    vec4 frag = vary_fragcoord; +    frag.xyz /= frag.w; +    frag.xyz = frag.xyz*0.5+0.5; +    frag.xy *= screen_res; +     +    vec3 pos = getPosition(frag.xy).xyz; +    vec3 lv = trans_center.xyz-pos; +    float dist = length(lv); +    dist /= size; +    if (dist > 1.0) +    { +        discard; +    } +     +    vec3 norm = getNorm(frag.xy); + +    float da = dot(norm, lv); +    if (da < 0.0) +    { +        discard; +    } +     +    lv = normalize(lv); +    da = dot(norm, lv); +     +    float noise = texture2D(noiseMap, frag.xy/128.0).b; +     +    vec3 col = texture2DRect(diffuseRect, frag.xy).rgb; +    col.rgb = srgb_to_linear(col.rgb); + +    float fa = falloff+1.0; +    float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); +    dist_atten *= dist_atten; +    dist_atten *= 2.0; +     +    float lit = da * dist_atten * noise; + +    col = color.rgb*lit*col; + +    vec4 spec = texture2DRect(specularRect, frag.xy); +    if (spec.a > 0.0) +    { +        lit = min(da*6.0, 1.0) * dist_atten; + +        vec3 npos = -normalize(pos); +        vec3 h = normalize(lv+npos); +        float nh = dot(norm, h); +        float nv = dot(norm, npos); +        float vh = dot(npos, h); +        float sa = nh; +        float fres = pow(1 - dot(h, npos), 5) * 0.4+0.5; +        float gtdenom = 2 * nh; +        float gt = max(0,(min(gtdenom * nv / vh, gtdenom * da / vh))); + +        if (nh > 0.0) +        { +            float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); +            col += lit*scol*color.rgb*spec.rgb; +        } +    } +     +    if (dot(col, col) <= 0.0) +    { +        discard; +    } +//col.rgb = vec3(0);         +    frag_color.rgb = col;    +    frag_color.a = 0.0;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl index a5625fbc16..3da8531442 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl @@ -1,5 +1,5 @@  /**  - * @file pointLightF.glsl + * @file pointLightV.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index 6669947d1b..cd37a34e0d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -37,33 +37,16 @@ uniform sampler2DRect diffuseRect;  uniform vec2 screen_res;  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()   { -	vec4 diff = texture2DRect(diffuseRect, vary_fragcoord); -	diff.rgb = linear_to_srgb(diff.rgb); -	frag_color = diff; +    //this is the one of the rare spots where diffuseRect contains linear color values (not sRGB) +    vec4 diff = texture2DRect(diffuseRect, vary_fragcoord); +    //diff.rgb = pow(diff.rgb, vec3(display_gamma)); +    diff.rgb = linear_to_srgb(diff.rgb); +    frag_color = diff;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl index 018ced4cad..cf994d3547 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 @@ -47,18 +49,7 @@ VARYING vec2 vary_fragcoord;  uniform mat4 inv_proj;  uniform vec2 screen_res; -vec4 getPosition(vec2 pos_screen) -{ -	float depth = texture2DRect(depthMap, pos_screen.xy).a; -	vec2 sc = pos_screen.xy*2.0; -	sc /= screen_res; -	sc -= vec2(1.0,1.0); -	vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); -	vec4 pos = inv_proj * ndc; -	pos /= pos.w; -	pos.w = 1.0; -	return pos; -} +vec4 getPosition(vec2 pos_screen);  void main()   { 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..44f2a73e1f --- /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 !defined(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 !defined(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..f45c343066 --- /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 !defined(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 !defined(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..9b8df0a5a4 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 @@ -31,19 +33,25 @@ out vec4 frag_color;  uniform sampler2D diffuseMap; -#if !DEPTH_CLAMP -VARYING float pos_zd2; -#endif - -VARYING float pos_w; - +VARYING vec4 post_pos;  VARYING float target_pos_x;  VARYING vec4 vertex_color;  VARYING vec2 vary_texcoord0; +uniform float minimum_alpha;  void main()   { -	float alpha = diffuseLookup(vary_texcoord0.xy).a * vertex_color.a; +	float alpha = diffuseLookup(vary_texcoord0.xy).a; + +    // mask cutoff 0 -> no shadow SL-11051 +    if (minimum_alpha == 0) +    { +        discard; +    } + +#if !defined(IS_FULLBRIGHT) +    alpha *= vertex_color.a; +#endif  	if (alpha < 0.05) // treat as totally transparent  	{ @@ -52,7 +60,7 @@ void main()  	if (alpha < 0.88) // treat as semi-transparent  	{ -	  if (fract(0.5*floor(target_pos_x / pos_w )) < 0.25) +	  if (fract(0.5*floor(target_pos_x / post_pos.w )) < 0.25)  	  {  	    discard;  	  } @@ -60,7 +68,7 @@ void main()  	frag_color = vec4(1,1,1,1); -#if !DEPTH_CLAMP -	gl_FragDepth = max(pos_zd2/pos_w+0.5, 0.0); +#if !defined(DEPTH_CLAMP) +	gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0);  #endif  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl index 11411a605c..b6a0f0b165 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl @@ -31,12 +31,7 @@ ATTRIBUTE vec3 position;  ATTRIBUTE vec4 diffuse_color;  ATTRIBUTE vec2 texcoord0; -#if !DEPTH_CLAMP -VARYING float pos_zd2; -#endif - -VARYING float pos_w; - +VARYING vec4 post_pos;  VARYING float target_pos_x;  VARYING vec4 vertex_color;  VARYING vec2 vary_texcoord0; @@ -50,11 +45,9 @@ void main()  	vec4 pos = modelview_projection_matrix * pre_pos;  	target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; -	pos_w = pos.w; +	post_pos = pos; -#if !DEPTH_CLAMP -	pos_zd2 = pos.z * 0.5; -	 +#if !defined(DEPTH_CLAMP)  	gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w);  #else  	gl_Position = pos; diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowCubeV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowCubeV.glsl index ef153dfc5b..0e74d2eb8a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowCubeV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowCubeV.glsl @@ -27,7 +27,7 @@ uniform mat4 modelview_projection_matrix;  ATTRIBUTE vec3 position; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP)  VARYING vec4 post_pos;  #endif @@ -40,7 +40,7 @@ void main()  	vec3 p = position*box_size+box_center;  	vec4 pos = modelview_projection_matrix*vec4(p.xyz, 1.0); -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP)  	post_pos = pos;  	gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl index 3d1b182875..1ea96918bb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl @@ -23,21 +23,21 @@   * $/LicenseInfo$   */ +/*[EXTRA_CODE_HERE]*/ +  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_color;  #else  #define frag_color gl_FragColor  #endif -#if !DEPTH_CLAMP  VARYING vec4 post_pos; -#endif  void main()   {  	frag_color = vec4(1,1,1,1); -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP)  	gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0);  #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl new file mode 100644 index 0000000000..4134220306 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -0,0 +1,221 @@ +/**  + * @file class1/deferred/shadowUtil.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 sampler2DRect   normalMap; +uniform sampler2DRect   depthMap; +uniform sampler2DShadow shadowMap0; +uniform sampler2DShadow shadowMap1; +uniform sampler2DShadow shadowMap2; +uniform sampler2DShadow shadowMap3; +uniform sampler2DShadow shadowMap4; +uniform sampler2DShadow shadowMap5; + +uniform vec3 sun_dir; +uniform vec3 moon_dir; +uniform vec2 shadow_res; +uniform vec2 proj_shadow_res; +uniform mat4 shadow_matrix[6]; +uniform vec4 shadow_clip; +uniform float shadow_bias; +uniform float shadow_offset; +uniform float spot_shadow_bias; +uniform float spot_shadow_offset; +uniform mat4 inv_proj; +uniform vec2 screen_res; +uniform int sun_up_factor; + +float pcfShadow(sampler2DShadow shadowMap, vec3 norm, vec4 stc, float bias_mul, vec2 pos_screen, vec3 light_dir) +{ +    float offset = shadow_bias * bias_mul; +    stc.xyz /= stc.w; +    stc.z += offset * 2.0; +    stc.x = floor(stc.x*shadow_res.x + fract(pos_screen.y*shadow_res.y))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here +    float cs = shadow2D(shadowMap, stc.xyz).x; +    float shadow = cs * 4.0; +    shadow += shadow2D(shadowMap, stc.xyz+vec3( 1.5/shadow_res.x,  0.5/shadow_res.y, 0.0)).x; +    shadow += shadow2D(shadowMap, stc.xyz+vec3( 0.5/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; +    shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.5/shadow_res.x, -0.5/shadow_res.y, 0.0)).x; +    shadow += shadow2D(shadowMap, stc.xyz+vec3(-0.5/shadow_res.x,  1.5/shadow_res.y, 0.0)).x; +    return clamp(shadow * 0.125, 0.0, 1.0); +} + +float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) +{ +    stc.xyz /= stc.w; +    stc.z += spot_shadow_bias * bias_scale; +    stc.x = floor(proj_shadow_res.x * stc.x + fract(pos_screen.y*0.666666666)) / proj_shadow_res.x; // snap + +    float cs = shadow2D(shadowMap, stc.xyz).x; +    float shadow = cs; + +    vec2 off = 1.0/proj_shadow_res; +    off.y *= 1.5; +     +    shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x*2.0, off.y, 0.0)).x; +    shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x, -off.y, 0.0)).x; +    shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x, off.y, 0.0)).x; +    shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x*2.0, -off.y, 0.0)).x; +    return shadow*0.2; +} + +float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) +{ +    float shadow = 0.0f; +    vec3 light_dir = normalize((sun_up_factor == 1) ? sun_dir : moon_dir); + +    float dp_directional_light = max(0.0, dot(norm.xyz, light_dir)); +          dp_directional_light = clamp(dp_directional_light, 0.0, 1.0); + +    vec3 shadow_pos = pos.xyz; + +    vec3 offset = light_dir.xyz * (1.0 - dp_directional_light); + +    shadow_pos += offset * shadow_offset * 2.0; + +    vec4 spos = vec4(shadow_pos.xyz, 1.0); + +    if (spos.z > -shadow_clip.w) +    {    +        vec4 lpos; +        vec4 near_split = shadow_clip*-0.75; +        vec4 far_split = shadow_clip*-1.25; +        vec4 transition_domain = near_split-far_split; +        float weight = 0.0; + +        if (spos.z < near_split.z) +        { +            lpos = shadow_matrix[3]*spos; +             +            float w = 1.0; +            w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; +            //w = clamp(w, 0.0, 1.0); +            float contrib = pcfShadow(shadowMap3, norm, lpos, 1.0, pos_screen, light_dir)*w; +            //if (contrib > 0) +            { +                shadow += contrib; +                weight += w; +            } +            shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); +        } + +        if (spos.z < near_split.y && spos.z > far_split.z) +        { +            lpos = shadow_matrix[2]*spos; +             +            float w = 1.0; +            w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; +            w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; +            //w = clamp(w, 0.0, 1.0); +            float contrib = pcfShadow(shadowMap2, norm, lpos, 1.0, pos_screen, light_dir)*w; +            //if (contrib > 0) +            { +                shadow += contrib; +                weight += w; +            } +        } + +        if (spos.z < near_split.x && spos.z > far_split.y) +        { +            lpos = shadow_matrix[1]*spos; +             +            float w = 1.0; +            w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; +            w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; +            //w = clamp(w, 0.0, 1.0); +            float contrib = pcfShadow(shadowMap1, norm, lpos, 1.0, pos_screen, light_dir)*w; +            //if (contrib > 0) +            { +                shadow += contrib; +                weight += w; +            } +        } + +        if (spos.z > far_split.x) +        { +            lpos = shadow_matrix[0]*spos; +                             +            float w = 1.0; +            w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; +            //w = clamp(w, 0.0, 1.0); +            float contrib = pcfShadow(shadowMap0, norm, lpos, 1.0, pos_screen, light_dir)*w; +            //if (contrib > 0) +            { +                shadow += contrib; +                weight += w; +            } +        } + +        shadow /= weight; +    } +    else +    { +        return 1.0f; // lit beyond the far split... +    } +    //shadow = min(dp_directional_light,shadow); +    return shadow; +} + +float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen) +{ +    float shadow = 0.0f; +    pos += norm * spot_shadow_offset; + +    vec4 spos = vec4(pos,1.0); +    if (spos.z > -shadow_clip.w) +    {    +        vec4 lpos; +         +        vec4 near_split = shadow_clip*-0.75; +        vec4 far_split = shadow_clip*-1.25; +        vec4 transition_domain = near_split-far_split; +        float weight = 0.0; + +        { +            float w = 1.0; +            w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; + +            if (index == 0) +            {         +                lpos = shadow_matrix[4]*spos; +                shadow += pcfSpotShadow(shadowMap4, lpos, 0.8, spos.xy)*w; +            } +            else +            { +                lpos = shadow_matrix[5]*spos; +                shadow += pcfSpotShadow(shadowMap5, lpos, 0.8, spos.xy)*w; +            } +            weight += w; +            shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); +        } + +        shadow /= weight; +    } +    else +    { +        shadow = 1.0f; +    } +    return shadow; +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl index cc77a4cea0..72bd0f0f34 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl @@ -27,20 +27,19 @@ uniform mat4 modelview_projection_matrix;  ATTRIBUTE vec3 position; -#if !DEPTH_CLAMP  VARYING vec4 post_pos; -#endif  void main()  {  	//transform vertex  	vec4 pos = modelview_projection_matrix*vec4(position.xyz, 1.0); -#if !DEPTH_CLAMP  	post_pos = pos; +#if !defined(DEPTH_CLAMP)  	gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w);  #else  	gl_Position = pos;  #endif +  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index 22f4729e2e..331249dc33 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,32 +37,28 @@ 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 -vec3 scaleSoftClip(vec3 light) { -	//soft clip effect: -	light = 1. - clamp(light, vec3(0.), vec3(1.)); -	light = 1. - pow(light, gamma.xxx); - -	return light; -} +vec3 scaleSoftClip(vec3 light); +vec3 srgb_to_linear(vec3 c);  void main()  { -	// Potential Fill-rate optimization.  Add cloud calculation  -	// back in and output alpha of 0 (so that alpha culling kills  -	// the fragment) if the sky wouldn't show up because the clouds  -	// are fully opaque. +    // Potential Fill-rate optimization.  Add cloud calculation  +    // back in and output alpha of 0 (so that alpha culling kills  +    // the fragment) if the sky wouldn't show up because the clouds  +    // are fully opaque. + +    vec4 color; +    color = vary_HazeColor; + +    color.rgb *= 2.; +    color.rgb = scaleSoftClip(color.rgb); -	vec4 color; -	color = vary_HazeColor; -	color *= 2.; +    /// Gamma correct for WL (soft clip effect). +    frag_data[0] = vec4(color.rgb, 0.0); +    frag_data[1] = vec4(0.0,0.0,0.0,0.0); +    frag_data[2] = vec4(0.0,0.0,0.0,1.0); //1.0 in norm.w masks off fog -	/// Gamma correct for WL (soft clip effect). -	frag_data[0] = vec4(scaleSoftClip(color.rgb), 1.0); -	frag_data[1] = vec4(0.0,0.0,0.0,0.0); -	frag_data[2] = vec4(0.5,0.5,0.0,1.0); //1.0 in norm.w masks off fog +    gl_FragDepth = 0.99999f;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl index 7c02d31d43..2cd660ab79 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl @@ -39,7 +39,9 @@ uniform vec3 camPosLocal;  uniform vec4 lightnorm;  uniform vec4 sunlight_color; -uniform vec4 ambient; +uniform vec4 moonlight_color; +uniform int sun_up_factor; +uniform vec4 ambient_color;  uniform vec4 blue_horizon;  uniform vec4 blue_density;  uniform float haze_horizon; @@ -47,9 +49,11 @@ 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 sun_moon_glow_factor;  uniform vec4 cloud_color; @@ -57,11 +61,12 @@ void main()  {  	// World / view / projection -	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); +    vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); + +	gl_Position = pos;  	// Get relative position  	vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); -	//vec3 P = position.xyz + vec3(0,50,0);  	// Set altitude  	if (P.y > 0.) @@ -75,39 +80,40 @@ void main()  	// Can normalize then  	vec3 Pn = normalize(P); -	float  Plen = length(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 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color;  	vec4 light_atten; +    float dens_mul = density_multiplier;  	// Sunlight attenuation effect (hue and brightness) due to atmosphere  	// this is used later for sunlight modulation at various altitudes -	light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); +	light_atten = (blue_density + vec4(haze_density * 0.25)) * (dens_mul * max_y);  	// Calculate relative weights -	temp1 = blue_density + haze_density; +	temp1 = abs(blue_density) + vec4(abs(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); +    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; +	temp2.z = Plen * dens_mul;  	// Transparency (-> temp1) -	// ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati -	// compiler gets confused. -	temp1 = exp(-temp1 * temp2.z); - +    // 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); @@ -123,35 +129,33 @@ void main()  	// Add "minimum anti-solar illumination"  	temp2.x += .25; +    vec4 color = (    blue_horizon * blue_weight * (sunlight + ambient_color) +                + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient_color) +             ); -	// Haze color above cloud -	vary_HazeColor = (	  blue_horizon * blue_weight * (sunlight + ambient) -				+ (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient) -			 );	 +    // Final atmosphere additive +    color *= (1. - temp1);  	// Increase ambient when there are more clouds -	vec4 tmpAmbient = ambient; -	tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5;  +	vec4 tmpAmbient = ambient_color; +	tmpAmbient += max(vec4(0), (1. - ambient_color)) * cloud_shadow * 0.5;   	// Dim sunlight by cloud shadow percentage -	sunlight *= (1. - cloud_shadow); +	sunlight *= max(0.0, (1. - cloud_shadow));  	// Haze color below cloud  	vec4 additiveColorBelowCloud = (	  blue_horizon * blue_weight * (sunlight + tmpAmbient)  				+ (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient)  			 );	 -	// Final atmosphere additive -	vary_HazeColor *= (1. - temp1); -	  	// Attenuate cloud color by atmosphere  	temp1 = sqrt(temp1);	//less atmos opacity (more transparency) below clouds  	// At horizon, blend high altitude sky color towards the darker color below the clouds -	vary_HazeColor += (additiveColorBelowCloud - vary_HazeColor) * (1. - sqrt(temp1)); -	 -	// won't compile on mac without this being set -	//vary_AtmosAttenuation = vec3(0.0,0.0,0.0); +	color += (additiveColorBelowCloud - color) * (1. - sqrt(temp1)); + +    // Haze color above cloud +	vary_HazeColor = color;	  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 03bdb754b5..20ac78947b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -1,5 +1,5 @@  /**  - * @file softenLightF.glsl + * @file class1/deferred/softenLightF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -36,442 +36,179 @@ out vec4 frag_color;  uniform sampler2DRect diffuseRect;  uniform sampler2DRect specularRect; -uniform sampler2DRect positionMap;  uniform sampler2DRect normalMap;  uniform sampler2DRect lightMap;  uniform sampler2DRect depthMap;  uniform samplerCube environmentMap; -uniform sampler2D	  lightFunc; +uniform sampler2D     lightFunc;  uniform float blur_size;  uniform float blur_fidelity;  // Inputs -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; +uniform int sun_up_factor;  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 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)); - -#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; -} - -vec4 getPosition_d(vec2 pos_screen, float depth) -{ -	vec2 sc = pos_screen.xy*2.0; -	sc /= screen_res; -	sc -= vec2(1.0,1.0); -	vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); -	vec4 pos = inv_proj * ndc; -	pos /= pos.w; -	pos.w = 1.0; -	return pos; -} - -vec4 getPosition(vec2 pos_screen) -{ //get position in screen space (world units) given window coordinate and depth map -	float depth = texture2DRect(depthMap, pos_screen.xy).a; -	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; -} +vec3 getNorm(vec2 pos_screen); +vec4 getPositionWithDepth(vec2 pos_screen, float depth); -void setAtmosAttenuation(vec3 v) -{ -	vary_AtmosAttenuation = v; -} +void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); +float getAmbientClamp(); +vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); +vec3 scaleSoftClipFrag(vec3 l); +vec3 linear_to_srgb(vec3 c); +vec3 srgb_to_linear(vec3 c);  #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 -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) +void main()   { -	//soft clip effect: -	light = 1. - clamp(light, vec3(0.), vec3(1.)); -	light = 1. - pow(light, gamma.xxx); - -	return light; -} +    vec2 tc = vary_fragcoord.xy; +    float depth = texture2DRect(depthMap, tc.xy).r; +    vec4 pos = getPositionWithDepth(tc, depth); +    vec4 norm = texture2DRect(normalMap, tc); +    float envIntensity = norm.z; +    norm.xyz = getNorm(tc); +     +    vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; +    float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0); +    da = pow(da, 1.0/1.3); + +    vec4 diffuse_srgb = texture2DRect(diffuseRect, tc); +    vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); + +    vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); +    vec3 color = vec3(0); +    float bloom = 0.0; +    { +        float ambocc = 1.0; // no AO... + +        vec3 sunlit; +        vec3 amblit; +        vec3 additive; +        vec3 atten; +     +        calcAtmosphericVars(pos.xyz, light_dir, ambocc, sunlit, amblit, additive, atten, false); + +        float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); +        ambient *= 0.5; +        ambient *= ambient; +        ambient = (1.0 - ambient); + +        vec3 sun_contrib = da * sunlit; + +#if !defined(AMBIENT_KILL) +        color.rgb = amblit; +        color.rgb *= ambient; +#endif +vec3 post_ambient = color.rgb; -vec3 fullbrightScaleSoftClip(vec3 light) -{ -	//soft clip effect: -	return light; -} +#if !defined(SUNLIGHT_KILL) +        color.rgb += sun_contrib; +#endif -void main()  -{ -	vec2 tc = vary_fragcoord.xy; -	float depth = texture2DRect(depthMap, tc.xy).r; -	vec3 pos = getPosition_d(tc, depth).xyz; -	vec4 norm = texture2DRect(normalMap, tc); -	float envIntensity = norm.z; -	norm.xyz = decode_normal(norm.xy); // unpack norm -		 -	float da = dot(norm.xyz, sun_dir.xyz); - -	float final_da = max(0.0,da); -          final_da = min(final_da, 1.0f); -	      final_da = pow(final_da, 1.0/1.3); - -	vec4 diffuse = texture2DRect(diffuseRect, tc); - -	//convert to gamma space -	diffuse.rgb = linear_to_srgb(diffuse.rgb); - -	vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); -	vec3 col; -	float bloom = 0.0; -	{ -		calcAtmospherics(pos.xyz, 1.0); -	 -		col = atmosAmbient(vec3(0)); -		float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); -		ambient *= 0.5; -		ambient *= ambient; -		ambient = (1.0-ambient); - -		col.rgb *= ambient; - -		col += atmosAffectDirectionalLight(final_da);	 -	 -		col *= diffuse.rgb; -	 -		vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - -		if (spec.a > 0.0) // specular reflection -		{ -			// the old infinite-sky shiny reflection -			// -			 -			float sa = dot(refnormpersp, sun_dir.xyz); -			vec3 dumbshiny = vary_SunlitColor*(texture2D(lightFunc, vec2(sa, spec.a)).r); -			 -			// add the two types of shiny together -			vec3 spec_contrib = dumbshiny * spec.rgb; -			bloom = dot(spec_contrib, spec_contrib) / 6; -			col += spec_contrib; -		} -		 -		 -		col = mix(col.rgb, diffuse.rgb, diffuse.a); -				 -		if (envIntensity > 0.0) -		{ //add environmentmap -			vec3 env_vec = env_mat * refnormpersp; -			 -			 -			vec3 refcol = textureCube(environmentMap, env_vec).rgb; - -			col = mix(col.rgb, refcol,  -				envIntensity);   -		} -				 -		if (norm.w < 0.5) -		{ -			col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); -			col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); -		} - -		#ifdef WATER_FOG -			vec4 fogged = applyWaterFogDeferred(pos,vec4(col, bloom)); -			col = fogged.rgb; -			bloom = fogged.a; -		#endif - -		col = srgb_to_linear(col); - -		//col = vec3(1,0,1); -		//col.g = envIntensity; -	} - -	frag_color.rgb = col.rgb; -	frag_color.a = bloom; +vec3 post_sunlight = color.rgb; + +        color.rgb *= diffuse_srgb.rgb; + +vec3 post_diffuse = color.rgb; + +        vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + +        if (spec.a > 0.0) // specular reflection +        { +            vec3 npos = -normalize(pos.xyz); + +            //vec3 ref = dot(pos+lv, norm); +            vec3 h = normalize(light_dir.xyz+npos); +            float nh = dot(norm.xyz, h); +            float nv = dot(norm.xyz, npos); +            float vh = dot(npos, h); +            float sa = nh; +            float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + +            float gtdenom = 2 * nh; +            float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); +                                     +            if (nh > 0.0) +            { +                float scontrib = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); +                vec3 sp = sun_contrib*scontrib / 6.0; +                sp = clamp(sp, vec3(0), vec3(1)); +                bloom += dot(sp, sp) / 4.0; +#if !defined(SUNLIGHT_KILL) +                color += sp * spec.rgb; +#endif +            } +        } +        + vec3 post_spec = color.rgb; + +        if (envIntensity > 0.0) +        { //add environmentmap +            vec3 env_vec = env_mat * refnormpersp; +            vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; +#if !defined(SUNLIGHT_KILL) +            color = mix(color.rgb, reflected_color, envIntensity*0.75); // MAGIC NUMBER SL-12574; ALM: On, Quality <= Mid+ +#endif +        } +        else +        { +            color.rgb = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); +        } + +vec3 post_env = color.rgb; + +        if (norm.w < 1) +        { +#if !defined(SUNLIGHT_KILL) +            color = atmosFragLighting(color, additive, atten); +            color = scaleSoftClipFrag(color); +#endif +        } + +vec3 post_atmo = color.rgb; + +        #ifdef WATER_FOG +            vec4 fogged = applyWaterFogView(pos.xyz,vec4(color, bloom)); +            color = fogged.rgb; +            bloom = fogged.a; +        #endif + +// srgb colorspace debuggables +//color.rgb = amblit; +//color.rgb = sunlit; +//color.rgb = post_ambient; +//color.rgb = sun_contrib; +//color.rgb = post_sunlight; +//color.rgb = diffuse_srgb.rgb; +//color.rgb = post_diffuse; +//color.rgb = post_spec; +//color.rgb = post_env; +//color.rgb = post_atmo; + +    } + +// linear debuggables +//color.rgb = vec3(final_da); +//color.rgb = vec3(ambient); +//color.rgb = vec3(scol); +//color.rgb = diffuse_linear.rgb; + +    // convert to linear as fullscreen lights need to sum in linear colorspace +    // and will be gamma (re)corrected downstream... +     +    frag_color.rgb = srgb_to_linear(color.rgb); +    frag_color.a = bloom;  } - diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl index b59fcbe017..8891315e15 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl @@ -1,5 +1,5 @@  /**  - * @file softenLightF.glsl + * @file softenLightV.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -29,12 +29,17 @@ ATTRIBUTE vec3 position;  uniform vec2 screen_res; +void setAtmosAttenuation(vec3 c); +void setAdditiveColor(vec3 c); +  VARYING vec2 vary_fragcoord;  void main()  { -	//transform vertex -	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); -	gl_Position = pos;  -	 -	vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; +    //transform vertex +    vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); +    gl_Position = pos;  +    // appease OSX GLSL compiler/linker by touching all the varyings we said we would +    setAtmosAttenuation(vec3(1)); +    setAdditiveColor(vec3(0)); +    vary_fragcoord = (pos.xy*0.5+0.5)*screen_res;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index f1aec315cc..694b19cdfb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -70,64 +70,8 @@ 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 - -} - -vec4 correctWithGamma(vec4 col) -{ -	return vec4(srgb_to_linear(col.rgb), col.a); -} +vec3 getNorm(vec2 pos_screen); +vec3 srgb_to_linear(vec3 c);  vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod)  { @@ -152,7 +96,7 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod)  vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod)  {  	vec4 ret = texture2DLod(projectionMap, tc, lod); -	ret = correctWithGamma(ret); +	ret.rgb = srgb_to_linear(ret.rgb);  	vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -170,7 +114,7 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod)  vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod)  {  	vec4 ret = texture2DLod(projectionMap, tc, lod); -	ret = correctWithGamma(ret); +	ret.rgb = srgb_to_linear(ret.rgb);  	vec2 dist = tc-vec2(0.5); @@ -181,22 +125,15 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod)  	return ret;  } - -vec4 getPosition(vec2 pos_screen) -{ -	float depth = texture2DRect(depthMap, pos_screen.xy).r; -	vec2 sc = pos_screen.xy*2.0; -	sc /= screen_res; -	sc -= vec2(1.0,1.0); -	vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); -	vec4 pos = inv_proj * ndc; -	pos /= pos.w; -	pos.w = 1.0; -	return pos; -} +vec4 getPosition(vec2 pos_screen);  void main()   { +	vec3 col = vec3(0,0,0); + +#if defined(LOCAL_LIGHT_KILL) +    discard; +#else  	vec4 frag = vary_fragcoord;  	frag.xyz /= frag.w;  	frag.xyz = frag.xyz*0.5+0.5; @@ -210,12 +147,10 @@ void main()  	{  		discard;  	} -	  	vec3 norm = texture2DRect(normalMap, frag.xy).xyz;  	float envIntensity = norm.z; -	norm = decode_normal(norm.xy); -	 +	norm = getNorm(frag.xy);  	norm = normalize(norm);  	float l_dist = -dot(lv, proj_n); @@ -241,13 +176,11 @@ void main()  	lv = normalize(lv);  	float da = dot(norm, lv); -	vec3 col = vec3(0,0,0); -		  	vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; -		 -	vec4 spec = texture2DRect(specularRect, frag.xy); +	//light shaders output linear and are gamma corrected later in postDeferredGammaCorrectF.glsl +    diff_tex.rgb = srgb_to_linear(diff_tex.rgb); -	 +	vec4 spec = texture2DRect(specularRect, frag.xy);  	float noise = texture2D(noiseMap, frag.xy/128.0).b;  	vec3 dlit = vec3(0, 0, 0); @@ -284,7 +217,6 @@ void main()  		amb_da = min(amb_da, 1.0-lit);  		col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a*diff_tex.rgb;  	} -	  	if (spec.a > 0.0)  	{ @@ -311,7 +243,6 @@ void main()  		}  	}	 -  	if (envIntensity > 0.0)  	{  		vec3 ref = reflect(normalize(pos), norm); @@ -340,7 +271,9 @@ void main()  			}  		}  	} -	 +#endif + +	//col.r = 1.0;  	frag_color.rgb = col;	  	frag_color.a = 0.0;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl index 821058804c..bac79a9fdc 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 @@ -31,14 +33,35 @@ out vec4 frag_data[3];  VARYING vec4 vertex_color;  VARYING vec2 vary_texcoord0; +VARYING vec2 screenpos;  uniform sampler2D diffuseMap; +uniform sampler2D altDiffuseMap; +uniform float blend_factor; +uniform float custom_alpha; +uniform float time; + +float twinkle(){ +    float d = fract(screenpos.x + screenpos.y); +    return abs(d); +}  void main()   { -	vec4 col = vertex_color * texture2D(diffuseMap, vary_texcoord0.xy); -	 -	frag_data[0] = col; -	frag_data[1] = vec4(0,0,0,0); -	frag_data[2] = vec4(0,0,1,0);	 +    vec4 col_a = texture2D(diffuseMap, vary_texcoord0.xy); +    vec4 col_b = texture2D(diffuseMap, vary_texcoord0.xy); +    vec4 col = mix(col_b, col_a, blend_factor); +    col.rgb *= vertex_color.rgb; +  +    float factor = smoothstep(0.0f, 0.9f, custom_alpha); + +    col.a = (col.a * factor) * 32.0f; +    col.a *= twinkle(); + +    frag_data[0] = col; +    frag_data[1] = vec4(0.0f); +    frag_data[2] = vec4(0.0, 1.0, 0.0, 1.0); + +    gl_FragDepth = 0.99995f;  } + diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl index 8bc5b06379..bb2a2ee72b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl @@ -25,6 +25,7 @@  uniform mat4 texture_matrix0;  uniform mat4 modelview_projection_matrix; +uniform float time;  ATTRIBUTE vec3 position;  ATTRIBUTE vec4 diffuse_color; @@ -32,11 +33,20 @@ ATTRIBUTE vec2 texcoord0;  VARYING vec4 vertex_color;  VARYING vec2 vary_texcoord0; +VARYING vec2 screenpos;  void main()  {  	//transform vertex -	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);  +    vec4 pos = modelview_projection_matrix * vec4(position, 1.0); + +// bias z to fix SL-9806 and get stars to depth test against clouds +    pos.z += 0.001f; + +	gl_Position = pos; + +    float t = mod(time, 1.25f); +    screenpos = position.xy * vec2(t, t);  	vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy;  	vertex_color = diffuse_color;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl new file mode 100644 index 0000000000..454af2a9bc --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl @@ -0,0 +1,68 @@ +/**  + * @file sunDiscF.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_data[3]; +#else +#define frag_data gl_FragData +#endif + +vec3 srgb_to_linear(vec3 c); +vec3 fullbrightAtmosTransport(vec3 light); +vec3 fullbrightScaleSoftClip(vec3 light); + +uniform sampler2D diffuseMap; +uniform sampler2D altDiffuseMap; +uniform float blend_factor; // interp factor between sunDisc A/B +VARYING vec2 vary_texcoord0; +VARYING float sun_fade; + +void main()  +{ +    vec4 sunDiscA = texture2D(diffuseMap, vary_texcoord0.xy); +    vec4 sunDiscB = texture2D(altDiffuseMap, vary_texcoord0.xy); +    vec4 c     = mix(sunDiscA, sunDiscB, blend_factor); + +    c.rgb = srgb_to_linear(c.rgb); +    c.rgb = clamp(c.rgb, vec3(0), vec3(1)); +    c.rgb = pow(c.rgb, vec3(0.7f)); + +    //c.rgb = fullbrightAtmosTransport(c.rgb); +    c.rgb = fullbrightScaleSoftClip(c.rgb); + +    // SL-9806 stars poke through +    //c.a *= sun_fade; + +    frag_data[0] = c; +    frag_data[1] = vec4(0.0f); +    frag_data[2] = vec4(0.0, 1.0, 0.0, 1.0); + +    gl_FragDepth = 0.999988f; +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl new file mode 100644 index 0000000000..0d117c6bc7 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl @@ -0,0 +1,52 @@ +/**  + * @file sunDiscV.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; + +VARYING vec2 vary_texcoord0; +VARYING float sun_fade; + +void calcAtmospherics(vec3 eye_pos); + +void main() +{ +    //transform vertex +    vec3 offset = vec3(0, 0, 50); +    vec4 vert = vec4(position.xyz - offset, 1.0); +    vec4 pos  = modelview_projection_matrix*vert; + +    sun_fade = smoothstep(0.3, 1.0, (position.z + 50) / 512.0f); + +    gl_Position = pos; +     +    calcAtmospherics(pos.xyz); + +    vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl index 930255729b..15f141cbe5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl @@ -35,103 +35,16 @@ out vec4 frag_color;  //class 1 -- no shadow, SSAO only -uniform sampler2DRect depthMap;  uniform sampler2DRect normalMap; -uniform sampler2D noiseMap; -  // Inputs -uniform float ssao_radius; -uniform float ssao_max_radius; -uniform float ssao_factor; -uniform float ssao_factor_inv; -  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; -} - -vec4 getPosition(vec2 pos_screen) -{ -	float depth = texture2DRect(depthMap, pos_screen.xy).r; -	vec2 sc = pos_screen.xy*2.0; -	sc /= screen_res; -	sc -= vec2(1.0,1.0); -	vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); -	vec4 pos = inv_proj * ndc; -	pos /= pos.w; -	pos.w = 1.0; -	return pos; -} +vec3 getNorm(vec2 pos_screen); +vec4 getPosition(vec2 pos_screen);  //calculate decreases in ambient lighting when crowded out (SSAO) -float calcAmbientOcclusion(vec4 pos, vec3 norm) -{ -	float ret = 1.0; -	 -	vec2 kern[8]; -	// exponentially (^2) distant occlusion samples spread around origin -	kern[0] = vec2(-1.0, 0.0) * 0.125*0.125; -	kern[1] = vec2(1.0, 0.0) * 0.250*0.250; -	kern[2] = vec2(0.0, 1.0) * 0.375*0.375; -	kern[3] = vec2(0.0, -1.0) * 0.500*0.500; -	kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625; -	kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750; -	kern[6] = vec2(-0.7071, 0.7071) * 0.875*0.875; -	kern[7] = vec2(0.7071, -0.7071) * 1.000*1.000; - -	vec2 pos_screen = vary_fragcoord.xy; -	vec3 pos_world = pos.xyz; -	vec2 noise_reflect = texture2D(noiseMap, vary_fragcoord.xy/128.0).xy; -		 -	float angle_hidden = 0.0; -	int points = 0; -		 -	float scale = min(ssao_radius / -pos_world.z, ssao_max_radius); -		 -	// it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations unrolling?) -	for (int i = 0; i < 8; i++) -	{ -		vec2 samppos_screen = pos_screen + scale * reflect(kern[i], noise_reflect); -		vec3 samppos_world = getPosition(samppos_screen).xyz;  -			 -		vec3 diff = pos_world - samppos_world; -		float dist2 = dot(diff, diff); -			 -		// assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area -		// --> solid angle shrinking by the square of distance -		//radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2 -		//(k should vary inversely with # of samples, but this is taken care of later) -			 -		angle_hidden = angle_hidden + float(dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) * min(1.0/dist2, ssao_factor_inv); -			 -		// 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion"  -		points = points + int(diff.z > -1.0); -	} -		 -	angle_hidden = min(ssao_factor*angle_hidden/float(points), 1.0); -		 -	ret = (1.0 - (float(points != 0) * angle_hidden)); -	 -	return min(ret, 1.0); -} +float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen);  void main()   { @@ -139,13 +52,11 @@ void main()  	//try doing an unproject here -	vec4 pos = getPosition(pos_screen); -	 -	vec3 norm = texture2DRect(normalMap, pos_screen).xyz; -	norm = decode_normal(norm.xy); -		 +	vec4 pos  = getPosition(pos_screen); +	vec3 norm = getNorm(pos_screen); +  	frag_color[0] = 1.0; -	frag_color[1] = calcAmbientOcclusion(pos, norm); +	frag_color[1] = calcAmbientOcclusion(pos, norm, pos_screen);  	frag_color[2] = 1.0;   	frag_color[3] = 1.0;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl index 52a429465f..6b6eed9db8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl @@ -1,5 +1,5 @@  /**  - * @file terrainF.glsl + * @file class1\deferred\terrainF.glsl   *   * $LicenseInfo:firstyear=2007&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,33 +37,32 @@ uniform sampler2D detail_2;  uniform sampler2D detail_3;  uniform sampler2D alpha_ramp; +VARYING vec3 pos;  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()  { -	/// Note: This should duplicate the blending functionality currently used for the terrain rendering. -	 -	vec4 color0 = texture2D(detail_0, vary_texcoord0.xy); -	vec4 color1 = texture2D(detail_1, vary_texcoord0.xy); -	vec4 color2 = texture2D(detail_2, vary_texcoord0.xy); -	vec4 color3 = texture2D(detail_3, vary_texcoord0.xy); +    /// Note: This should duplicate the blending functionality currently used for the terrain rendering. +     +    vec4 color0 = texture2D(detail_0, vary_texcoord0.xy); +    vec4 color1 = texture2D(detail_1, vary_texcoord0.xy); +    vec4 color2 = texture2D(detail_2, vary_texcoord0.xy); +    vec4 color3 = texture2D(detail_3, vary_texcoord0.xy); -	float alpha1 = texture2D(alpha_ramp, vary_texcoord0.zw).a; -	float alpha2 = texture2D(alpha_ramp,vary_texcoord1.xy).a; -	float alphaFinal = texture2D(alpha_ramp, vary_texcoord1.zw).a; -	vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal ); -	 -	frag_data[0] = vec4(outColor.rgb, 0.0); -	frag_data[1] = vec4(0,0,0,0); -	vec3 nvn = normalize(vary_normal); -	frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 0.0); +    float alpha1 = texture2D(alpha_ramp, vary_texcoord0.zw).a; +    float alpha2 = texture2D(alpha_ramp,vary_texcoord1.xy).a; +    float alphaFinal = texture2D(alpha_ramp, vary_texcoord1.zw).a; +    vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal ); +    +    outColor.a = 0.0; // yes, downstream atmospherics  +     +    frag_data[0] = outColor; +    frag_data[1] = vec4(0.0,0.0,0.0,-1.0); +    vec3 nvn = normalize(vary_normal); +    frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 0.0);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl index 5effee4e4e..f42cb6ff6d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl @@ -1,5 +1,5 @@  /**  - * @file terrainV.glsl + * @file class1\environment\terrainV.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -33,8 +33,8 @@ ATTRIBUTE vec4 diffuse_color;  ATTRIBUTE vec2 texcoord0;  ATTRIBUTE vec2 texcoord1; +VARYING vec3 pos;  VARYING vec3 vary_normal; -  VARYING vec4 vary_texcoord0;  VARYING vec4 vary_texcoord1; @@ -43,31 +43,35 @@ uniform vec4 object_plane_t;  vec4 texgen_object(vec4  vpos, vec4 tc, mat4 mat, vec4 tp0, vec4 tp1)  { -	vec4 tcoord; -	 -	tcoord.x = dot(vpos, tp0); -	tcoord.y = dot(vpos, tp1); -	tcoord.z = tc.z; -	tcoord.w = tc.w; -	 -	tcoord = mat * tcoord;  -	 -	return tcoord;  +    vec4 tcoord; +     +    tcoord.x = dot(vpos, tp0); +    tcoord.y = dot(vpos, tp1); +    tcoord.z = tc.z; +    tcoord.w = tc.w; +     +    tcoord = mat * tcoord;  +     +    return tcoord;   }  void main()  { -	//transform vertex -	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); -			 -	vary_normal = normalize(normal_matrix * normal); -	 -	// Transform and pass tex coords - 	vary_texcoord0.xy = texgen_object(vec4(position, 1.0), vec4(texcoord0,0,1), texture_matrix0, object_plane_s, object_plane_t).xy; -	 -	vec4 t = vec4(texcoord1,0,1); -	 -	vary_texcoord0.zw = t.xy; -	vary_texcoord1.xy = t.xy-vec2(2.0, 0.0); -	vary_texcoord1.zw = t.xy-vec2(1.0, 0.0); +    //transform vertex +    vec4 pre_pos = vec4(position.xyz, 1.0); +    vec4 t_pos = modelview_projection_matrix * pre_pos; + +    gl_Position = t_pos; +    pos = t_pos.xyz; + +    vary_normal = normalize(normal_matrix * normal); +     +    // Transform and pass tex coords +    vary_texcoord0.xy = texgen_object(vec4(position, 1.0), vec4(texcoord0,0,1), texture_matrix0, object_plane_s, object_plane_t).xy; +     +    vec4 t = vec4(texcoord1,0,1); +     +    vary_texcoord0.zw = t.xy; +    vary_texcoord1.xy = t.xy-vec2(2.0, 0.0); +    vary_texcoord1.zw = t.xy-vec2(1.0, 0.0);  } 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..9a5debb3c1 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,84 +58,7 @@ 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 - -} - -vec2 encode_normal(vec3 n) -{ -	float f = sqrt(8 * n.z + 8); -	return n.xy / f + 0.5; -} - -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); -} +vec2 encode_normal(vec3 n);  void main()   { @@ -151,7 +76,7 @@ void main()  	vec4 fb = texture2D(screenTex, distort); -	frag_data[0] = vec4(linear_to_srgb(fb.rgb), 1.0); // diffuse +	frag_data[0] = vec4(fb.rgb, 1.0); // diffuse  	frag_data[1] = vec4(0.5,0.5,0.5, 0.95); // speccolor*spec, spec -	frag_data[2] = vec4(encode_normal(wavef), 0.0, 0.0); // normalxyz, displace +	frag_data[2] = vec4(encode_normal(wavef), 0.0, 0.0); // normalxyz, env intens, atmo kill  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 37dcd3ad34..b86867c460 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -1,5 +1,5 @@  /**  - * @file waterF.glsl + * @file class1/deferred/waterF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -37,17 +37,10 @@ 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; -uniform sampler2DRectShadow shadowMap1; -uniform sampler2DRectShadow shadowMap2; -uniform sampler2DRectShadow shadowMap3; -uniform sampler2D noiseMap; - -uniform mat4 shadow_matrix[6]; -uniform vec4 shadow_clip; -  uniform float sunAngle;  uniform float sunAngle2;  uniform vec3 lightDir; @@ -62,6 +55,7 @@ uniform float fresnelOffset;  uniform float blurMultiplier;  uniform vec2 screen_res;  uniform mat4 norm_mat; //region space to screen space +uniform int water_edge;  //bigWave is (refCoord.w, view.w);  VARYING vec4 refCoord; @@ -69,136 +63,115 @@ 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 +vec2 encode_normal(vec3 n); +vec3 scaleSoftClip(vec3 l); +vec3 srgb_to_linear(vec3 c); +vec3 linear_to_srgb(vec3 c); -} - -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 n = mix(bump1, bump2, blend_factor); +    return n;  }  void main()   { -	vec4 color; -	float dist = length(view.xy); -	 -	//normalize view vector -	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; -	//get base fresnel components	 -	 -	vec3 df = vec3( -					dot(viewVec, wave1), -					dot(viewVec, (wave2 + wave3) * 0.5), -					dot(viewVec, wave3) -				 ) * fresnelScale + fresnelOffset; -	df *= df; -		     -	vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; -	 -	float dist2 = dist; -	dist = max(dist, 5.0); -	 -	float dmod = sqrt(dist); -	 -	vec2 dmod_scale = vec2(dmod*dmod, dmod); -	 -	//get reflected color -	vec2 refdistort1 = wave1.xy*normScale.x; -	vec2 refvec1 = distort+refdistort1/dmod_scale; -	vec4 refcol1 = texture2D(refTex, refvec1); -	 -	vec2 refdistort2 = wave2.xy*normScale.y; -	vec2 refvec2 = distort+refdistort2/dmod_scale; -	vec4 refcol2 = texture2D(refTex, refvec2); -	 -	vec2 refdistort3 = wave3.xy*normScale.z; -	vec2 refvec3 = distort+refdistort3/dmod_scale; -	vec4 refcol3 = texture2D(refTex, refvec3); - -	vec4 refcol = refcol1 + refcol2 + refcol3; -	float df1 = df.x + df.y + df.z; +    vec4 color; +    float dist = length(view.xyz); +     +    //normalize view vector +    vec3 viewVec = normalize(view.xyz); +     +    //get wave normals +    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( +                    dot(viewVec, wave1), +                    dot(viewVec, (wave2 + wave3) * 0.5), +                    dot(viewVec, wave3) +                 ) * fresnelScale + fresnelOffset; +    df *= df; +             +    vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; +     +    float dist2 = dist; +    dist = max(dist, 5.0); +     +    float dmod = sqrt(dist); +     +    vec2 dmod_scale = vec2(dmod*dmod, dmod); +     +    //get reflected color +    vec2 refdistort1 = wave1.xy*normScale.x; +    vec2 refvec1 = distort+refdistort1/dmod_scale; +    vec4 refcol1 = texture2D(refTex, refvec1); +     +    vec2 refdistort2 = wave2.xy*normScale.y; +    vec2 refvec2 = distort+refdistort2/dmod_scale; +    vec4 refcol2 = texture2D(refTex, refvec2); +     +    vec2 refdistort3 = wave3.xy*normScale.z; +    vec2 refvec3 = distort+refdistort3/dmod_scale; +    vec4 refcol3 = texture2D(refTex, refvec3); + +    vec4 refcol = refcol1 + refcol2 + refcol3; +    float df1 = df.x + df.y + df.z;  	refcol *= df1 * 0.333; -	 -	vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; -	wavef.z *= max(-viewVec.z, 0.1); -	wavef = normalize(wavef); -	 -	float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset; -	 -	vec2 refdistort4 = wavef.xy*0.125; -	refdistort4.y -= abs(refdistort4.y); -	vec2 refvec4 = distort+refdistort4/dmod; -	float dweight = min(dist2*blurMultiplier, 1.0); -	vec4 baseCol = texture2D(refTex, refvec4); - -	refcol = mix(baseCol*df2, refcol, dweight); - -	//get specular component +     +    vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; +    wavef.z *= max(-viewVec.z, 0.1); +    wavef = normalize(wavef); +     +    float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset; +     +    vec2 refdistort4 = wavef.xy*0.125; +    refdistort4.y -= abs(refdistort4.y); +    vec2 refvec4 = distort+refdistort4/dmod; +    float dweight = min(dist2*blurMultiplier, 1.0); +    vec4 baseCol = texture2D(refTex, refvec4); + +    refcol = mix(baseCol*df2, refcol, dweight); + +    //get specular component  	float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0);  	//harden specular  	spec = pow(spec, 128.0);  	//figure out distortion vector (ripply)    -	vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); +	vec2 distort2 = distort+wavef.xy*refScale*0.16/max(dmod*df1, 1.0);  	vec4 fb = texture2D(screenTex, distort2);  	//mix with reflection  	// Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug -	color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999); +	color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999f);  	vec4 pos = vary_position;  	color.rgb += spec * specular; -	 -	color.rgb = atmosTransport(color.rgb); + +	//color.rgb = atmosTransport(color.rgb);  	color.rgb = scaleSoftClip(color.rgb); +      	color.a   = spec * sunAngle2; - +      	vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); -	 +  	frag_data[0] = vec4(color.rgb, color); // diffuse  	frag_data[1] = vec4(0);		// speccolor, spec -	frag_data[2] = vec4(encode_normal(screenspacewavef.xyz*0.5+0.5), 0.05, 0);// normalxy, 0, 0 +	frag_data[2] = vec4(encode_normal(screenspacewavef.xyz*0.5+0.5), 0.0, 0);// normalxy, 0, 0  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl index 9734acf005..8863869e44 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl @@ -31,8 +31,8 @@ ATTRIBUTE vec3 position;  void calcAtmospherics(vec3 inPositionEye); -uniform vec2 d1; -uniform vec2 d2; +uniform vec2 waveDir1; +uniform vec2 waveDir2;  uniform float time;  uniform vec3 eyeVec;  uniform float waterHeight; @@ -88,10 +88,10 @@ void main()  	calcAtmospherics(pos.xyz);  	//pass wave parameters to pixel shader -	vec2 bigWave =  (v.xy) * vec2(0.04,0.04)  + d1 * time * 0.055; +	vec2 bigWave =  (v.xy) * vec2(0.04,0.04)  + waveDir1 * time * 0.055;  	//get two normal map (detail map) texture coordinates -	littleWave.xy = (v.xy) * vec2(0.45, 0.9)   + d2 * time * 0.13; -	littleWave.zw = (v.xy) * vec2(0.1, 0.2) + d1 * time * 0.1; +	littleWave.xy = (v.xy) * vec2(0.45, 0.9)   + waveDir2 * time * 0.13; +	littleWave.zw = (v.xy) * vec2(0.1, 0.2) + waveDir1 * time * 0.1;  	view.w = bigWave.y;  	refCoord.w = bigWave.x; 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..4a8b892c3a 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,39 @@ 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 + +} + +vec3 ColorFromRadiance(vec3 radiance) +{ +    return vec3(1.0) - exp(-radiance * 0.0001);  } +vec3 rgb2hsv(vec3 c) +{ +    vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); +    vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); +    vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); + +    float d = q.x - min(q.w, q.y); +    float e = 1.0e-10; +    return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); +} + +vec3 hsv2rgb(vec3 c) +{ +    vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); +    vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); +    return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); +} diff --git a/indra/newview/app_settings/shaders/class1/environment/terrainF.glsl b/indra/newview/app_settings/shaders/class1/environment/terrainF.glsl index 668a710c04..6b68ed4169 100644 --- a/indra/newview/app_settings/shaders/class1/environment/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/terrainF.glsl @@ -1,5 +1,5 @@  /** - * @file terrainF.glsl + * @file class1\environment\terrainF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/environment/terrainV.glsl b/indra/newview/app_settings/shaders/class1/environment/terrainV.glsl index d09c5f9247..ef27848d37 100644 --- a/indra/newview/app_settings/shaders/class1/environment/terrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/terrainV.glsl @@ -1,5 +1,5 @@  /** - * @file terrainV.glsl + * @file class1\environment\terrainV.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -35,6 +35,7 @@ ATTRIBUTE vec3 position;  ATTRIBUTE vec3 normal;  ATTRIBUTE vec2 texcoord0;  ATTRIBUTE vec2 texcoord1; +ATTRIBUTE vec4 diffuse_color;  VARYING vec4 vertex_color;  VARYING vec4 vary_texcoord0; @@ -42,7 +43,7 @@ VARYING vec4 vary_texcoord1;  void calcAtmospherics(vec3 inPositionEye); -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color);  vec4 texgen_object(vec4  vpos, vec4 tc, mat4 mat, vec4 tp0, vec4 tp1)  { @@ -71,7 +72,7 @@ void main()  	/// Potentially better without it for water.  	pos /= pos.w; -	vec4 color = calcLighting(pos.xyz, norm, vec4(1,1,1,1), vec4(0)); +	vec4 color = calcLighting(pos.xyz, norm, /*diffuse_color*/vec4(1));  	vertex_color = color; diff --git a/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl b/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl index a956562396..bbfec3b532 100644 --- a/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl @@ -1,5 +1,5 @@  /** - * @file terrainWaterF.glsl + * @file class1\environment\terrainWaterF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -39,8 +39,6 @@ uniform sampler2D detail_2;  uniform sampler2D detail_3;  uniform sampler2D alpha_ramp; -vec3 atmosLighting(vec3 light); -  vec4 applyWaterFog(vec4 color);  void main() @@ -57,11 +55,10 @@ void main()  	float alpha2 = texture2D(alpha_ramp,vary_texcoord1.xy).a;  	float alphaFinal = texture2D(alpha_ramp, vary_texcoord1.zw).a;  	vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal ); -	 -	/// Add WL Components -	outColor.rgb = atmosLighting(outColor.rgb * vertex_color.rgb); -	 + +    outColor.rgb *= vertex_color.rgb;	  	outColor = applyWaterFog(outColor); +  	frag_color = outColor;  } diff --git a/indra/newview/app_settings/shaders/class1/environment/terrainWaterV.glsl b/indra/newview/app_settings/shaders/class1/environment/terrainWaterV.glsl new file mode 100644 index 0000000000..a075cfeef2 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/environment/terrainWaterV.glsl @@ -0,0 +1,84 @@ +/** + * @file class1\environment\terrainV.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 mat3 normal_matrix; +uniform mat4 texture_matrix0; +uniform mat4 modelview_matrix; +uniform mat4 modelview_projection_matrix; + +uniform vec4 object_plane_t; +uniform vec4 object_plane_s; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec3 normal; +ATTRIBUTE vec2 texcoord0; +ATTRIBUTE vec2 texcoord1; +ATTRIBUTE vec4 diffuse_color; + +VARYING vec4 vertex_color; +VARYING vec4 vary_texcoord0; +VARYING vec4 vary_texcoord1; + +void calcAtmospherics(vec3 inPositionEye); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color); + +vec4 texgen_object(vec4  vpos, vec4 tc, mat4 mat, vec4 tp0, vec4 tp1) +{ +	vec4 tcoord; +	 +	tcoord.x = dot(vpos, tp0); +	tcoord.y = dot(vpos, tp1); +	tcoord.z = tc.z; +	tcoord.w = tc.w; +	 +	tcoord = mat * tcoord;  +	 +	return tcoord;  +} + +void main() +{ +	//transform vertex +	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + +	vec4 pos = modelview_matrix * vec4(position.xyz, 1.0); +	vec3 norm = normalize(normal_matrix * normal); + +	calcAtmospherics(pos.xyz); + +	vec4 color = calcLighting(pos.xyz, norm, vec4(1.0)); + +	vertex_color.rgb = color.rgb; + +	// Transform and pass tex coords + 	vary_texcoord0.xy = texgen_object(vec4(position.xyz, 1.0), vec4(texcoord0,0,1), texture_matrix0, object_plane_s, object_plane_t).xy; +	 +	vec4 t = vec4(texcoord1,0,1); +	 +	vary_texcoord0.zw = t.xy; +	vary_texcoord1.xy = t.xy-vec2(2.0, 0.0); +	vary_texcoord1.zw = t.xy-vec2(1.0, 0.0); +} + diff --git a/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl index 0d8dab0a41..8c8bd6d0d5 100644 --- a/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl @@ -1,5 +1,5 @@  /** - * @file underWaterF.glsl + * @file class1\environment\underWaterF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -47,7 +47,6 @@ uniform float kd;  uniform vec4 waterPlane;  uniform vec3 eyeVec;  uniform vec4 waterFogColor; -uniform float waterFogDensity;  uniform float waterFogKS;  uniform vec2 screenRes; @@ -56,41 +55,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 +73,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..b3ae64bd82 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl @@ -1,5 +1,5 @@  /**  - * @file waterF.glsl + * @file class1/environment/waterF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -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; @@ -48,94 +50,118 @@ uniform vec3 normScale;  uniform float fresnelScale;  uniform float fresnelOffset;  uniform float blurMultiplier; - +uniform int water_edge;  //bigWave is (refCoord.w, view.w);  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; -	 -	float dist = length(view.xy); -	 -	//normalize view vector -	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; -	//get base fresnel components	 -	 -	vec3 df = vec3( -					dot(viewVec, wave1), -					dot(viewVec, (wave2 + wave3) * 0.5), -					dot(viewVec, wave3) -				 ) * fresnelScale + fresnelOffset; -	df *= df; -		     -	vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; -	 -	float dist2 = dist; -	dist = max(dist, 5.0); -	 -	float dmod = sqrt(dist); -	 -	vec2 dmod_scale = vec2(dmod*dmod, dmod); -	 -	//get reflected color -	vec2 refdistort1 = wave1.xy*normScale.x; -	vec2 refvec1 = distort+refdistort1/dmod_scale; -	vec4 refcol1 = texture2D(refTex, refvec1); -	 -	vec2 refdistort2 = wave2.xy*normScale.y; -	vec2 refvec2 = distort+refdistort2/dmod_scale; -	vec4 refcol2 = texture2D(refTex, refvec2); -	 -	vec2 refdistort3 = wave3.xy*normScale.z; -	vec2 refvec3 = distort+refdistort3/dmod_scale; -	vec4 refcol3 = texture2D(refTex, refvec3); - -	vec4 refcol = refcol1 + refcol2 + refcol3; -	float df1 = df.x + df.y + df.z; -	refcol *= df1 * 0.333; -	 -	vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; -	 -	wavef.z *= max(-viewVec.z, 0.1); -	wavef = normalize(wavef); -	 -	float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset; -	 -	vec2 refdistort4 = wavef.xy*0.125; -	refdistort4.y -= abs(refdistort4.y); -	vec2 refvec4 = distort+refdistort4/dmod; -	float dweight = min(dist2*blurMultiplier, 1.0); -	vec4 baseCol = texture2D(refTex, refvec4); -	refcol = mix(baseCol*df2, refcol, dweight); - -	//get specular component -	float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); -		 -	//harden specular -	spec = pow(spec, 128.0); - -	//figure out distortion vector (ripply)    -	vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); -		 -	vec4 fb = texture2D(screenTex, distort2); -	 -	//mix with reflection -	// Note we actually want to use just df1, but multiplying by 0.999999 gets around and nvidia compiler bug -	color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999); -	color.rgb += spec * specular; -	 -	color.rgb = atmosTransport(color.rgb); +    vec4 color; +     +    float dist = length(view.xy); +     +    //normalize view vector +    vec3 viewVec = normalize(view.xyz); +     +    //get wave normals +    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( +                    dot(viewVec, wave1), +                    dot(viewVec, (wave2 + wave3) * 0.5), +                    dot(viewVec, wave3) +                 ) * fresnelScale + fresnelOffset; +    df *= df; +             +    vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; +     +    float dist2 = dist; +    dist = max(dist, 5.0); +     +    float dmod = sqrt(dist); +     +    vec2 dmod_scale = vec2(dmod*dmod, dmod); +     +    //get reflected color +    vec2 refdistort1 = wave1.xy*normScale.x; +    vec2 refvec1 = distort+refdistort1/dmod_scale; +    vec4 refcol1 = texture2D(refTex, refvec1); +     +    vec2 refdistort2 = wave2.xy*normScale.y; +    vec2 refvec2 = distort+refdistort2/dmod_scale; +    vec4 refcol2 = texture2D(refTex, refvec2); +     +    vec2 refdistort3 = wave3.xy*normScale.z; +    vec2 refvec3 = distort+refdistort3/dmod_scale; +    vec4 refcol3 = texture2D(refTex, refvec3); + +    vec4 refcol = refcol1 + refcol2 + refcol3; +    float df1 = df.x + df.y + df.z; +    df1 *= 0.666666f; +    refcol *= df1; +     +    vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; +     +    wavef.z *= max(-viewVec.z, 0.1); +    wavef = normalize(wavef); +     +    float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset; +     +    vec2 refdistort4 = wavef.xy*0.125; +    refdistort4.y -= abs(refdistort4.y); +    vec2 refvec4 = distort+refdistort4/dmod; +    float dweight = min(dist2*blurMultiplier, 1.0); +    vec4 baseCol = texture2D(refTex, refvec4); +    refcol = mix(baseCol*df2, refcol, dweight); + +    //get specular component +    float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); +         +    //harden specular +    spec = pow(spec, 128.0); + +    //figure out distortion vector (ripply)    +    vec2 distort2 = distort+wavef.xy*refScale*0.16/max(dmod*df1, 1.0); +         +    vec4 fb = texture2D(screenTex, distort2); +     +    //mix with reflection +    // Note we actually want to use just df1, but multiplying by 0.999999 gets around and nvidia compiler bug +    color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.9999999); +    color.rgb += spec * specular; + +    color.a = spec * sunAngle2; + +    //color.rgb = atmosTransport(color.rgb);  	color.rgb = scaleSoftClip(color.rgb); -	color.a = spec * sunAngle2; -	frag_color = color; +#if defined(WATER_EDGE) +    gl_FragDepth = 0.9999847f; +#endif + +    frag_color = color;  } diff --git a/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl index 4bdfce9260..df640cba05 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl @@ -1,5 +1,5 @@  /** - * @file waterFogF.glsl + * @file class1\environment\waterFogF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -25,7 +25,6 @@ -uniform vec4 lightnorm;  uniform vec4 waterPlane;  uniform vec4 waterFogColor;  uniform float waterFogDensity; @@ -33,42 +32,48 @@ uniform float waterFogKS;  vec3 getPositionEye(); -vec4 applyWaterFog(vec4 color) +vec4 applyWaterFogView(vec3 pos, vec4 color)  { -	//normalize view vector -	vec3 view = normalize(getPositionEye()); -	float es = -(dot(view, waterPlane.xyz)); +    vec3 view = normalize(pos); +    //normalize view vector +    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; -	//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(getPositionEye() - int_v); -		 -	//get "thickness" of water -	float l = max(depth, 0.1); +    return color; +} -	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 applyWaterFog(vec4 color) +{ +    //normalize view vector +    return applyWaterFogView(getPositionEye(), color);  } diff --git a/indra/newview/app_settings/shaders/class1/environment/waterV.glsl b/indra/newview/app_settings/shaders/class1/environment/waterV.glsl index 352cea7aaa..cc41e3f740 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterV.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterV.glsl @@ -1,5 +1,5 @@  /**  - * @file waterV.glsl + * @file class1\environment\waterV.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -31,8 +31,8 @@ ATTRIBUTE vec3 position;  void calcAtmospherics(vec3 inPositionEye); -uniform vec2 d1; -uniform vec2 d2; +uniform vec2 waveDir1; +uniform vec2 waveDir2;  uniform float time;  uniform vec3 eyeVec;  uniform float waterHeight; @@ -86,10 +86,10 @@ void main()  	//pass wave parameters to pixel shader -	vec2 bigWave =  (v.xy) * vec2(0.04,0.04)  + d1 * time * 0.055; +	vec2 bigWave =  (v.xy) * vec2(0.04,0.04)  + waveDir1 * time * 0.055;  	//get two normal map (detail map) texture coordinates -	littleWave.xy = (v.xy) * vec2(0.45, 0.9)   + d2 * time * 0.13; -	littleWave.zw = (v.xy) * vec2(0.1, 0.2) + d1 * time * 0.1; +	littleWave.xy = (v.xy) * vec2(0.45, 0.9)   + waveDir2 * time * 0.13; +	littleWave.zw = (v.xy) * vec2(0.1, 0.2) + waveDir1 * time * 0.1;  	view.w = bigWave.y;  	refCoord.w = bigWave.x; diff --git a/indra/newview/app_settings/shaders/class1/interface/customalphaF.glsl b/indra/newview/app_settings/shaders/class1/interface/customalphaF.glsl index a96d04cc39..f6b31a5956 100644 --- a/indra/newview/app_settings/shaders/class1/interface/customalphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/customalphaF.glsl @@ -38,7 +38,9 @@ VARYING vec2 vary_texcoord0;  void main()   { -	vec4 color = vertex_color*texture2D(diffuseMap, vary_texcoord0.xy); -	color.a *= custom_alpha; +	vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); +    color.rgb = pow(color.rgb, vec3(0.45)); +    color.rgb *= vertex_color.rgb; +	color.a *= max(custom_alpha, vertex_color.a);  	frag_color = 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/lighting/lightAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskF.glsl index cad5b9ff04..f665394b46 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskF.glsl @@ -1,5 +1,5 @@  /**  - * @file lightAlphaMaskF.glsl + * @file class1\lighting\lightAlphaMaskF.glsl   *   * $LicenseInfo:firstyear=2011&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskNonIndexedF.glsl index 8918182853..b768d609f4 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskNonIndexedF.glsl @@ -1,5 +1,5 @@  /**  - * @file lightAlphaMaskNonIndexedF.glsl + * @file class1\lighting\lightAlphaMaskNonIndexedF.glsl   *   * $LicenseInfo:firstyear=2011&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightF.glsl index d6ebfcb825..9fd189358b 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightF.glsl @@ -1,5 +1,5 @@  /**  - * @file lightF.glsl + * @file class1\lighting\lightF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl index 5740987ab1..46390e4a0e 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl @@ -1,5 +1,5 @@  /**  - * @file lightFullbrightAlphaMaskF.glsl + * @file class1\lighting\lightFullbrightAlphaMaskF.glsl   *   * $LicenseInfo:firstyear=2011&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightF.glsl index c8771a3f1e..b967709c57 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightF.glsl @@ -1,5 +1,5 @@  /**  - * @file lightFullbrightF.glsl + * @file class1\lighting\lightFullbrightF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedAlphaMaskF.glsl index f72f20b03d..e8e71beb44 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedAlphaMaskF.glsl @@ -1,5 +1,5 @@  /**  - * @file lightFullbrightNonIndexedAlphaMaskF.glsl + * @file class1\lighting\lightFullbrightNonIndexedAlphaMaskF.glsl   *   * $LicenseInfo:firstyear=2011&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedF.glsl index 2738ff8947..11a0919086 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedF.glsl @@ -1,5 +1,5 @@  /**  - * @file lightFullbrightF.glsl + * @file class1\lighting\lightFullbrightF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyF.glsl index c8282e9a51..567811cd75 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyF.glsl @@ -1,5 +1,5 @@  /**  - * @file lightFullbrightShinyF.glsl + * @file class1\lighting\lightFullbrightShinyF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -44,7 +44,7 @@ void fullbright_shiny_lighting()  	color.rgb *= vertex_color.rgb;  	vec3 envColor = textureCube(environmentMap, vary_texcoord1.xyz).rgb;	 -	color.rgb = mix(color.rgb, envColor.rgb, vertex_color.a); +	color.rgb = mix(color.rgb, envColor.rgb, vertex_color.a*0.75); // MAGIC NUMBER SL-12574; ALM: Off, Quality > Low  	color.rgb = fullbrightShinyAtmosTransport(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyNonIndexedF.glsl index e7dbd4bbd2..3118453342 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyNonIndexedF.glsl @@ -1,5 +1,5 @@  /**  - * @file lightFullbrightShinyF.glsl + * @file class1\lighting\lightFullbrightShinyF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyWaterF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyWaterF.glsl index 5886fc65be..f78e5e0e8a 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyWaterF.glsl @@ -1,5 +1,5 @@  /**  - * @file lightFullbrightShinyWaterF.glsl + * @file class1\lighting\lightFullbrightShinyWaterF.glsl   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code   * Copyright (C) 2007, Linden Research, Inc. diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyWaterNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyWaterNonIndexedF.glsl index cddc7d8df8..90668bd2b6 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyWaterNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyWaterNonIndexedF.glsl @@ -1,5 +1,5 @@  /**  - * @file lightFullbrightShinyWaterF.glsl + * @file class1\lighting\lightFullbrightShinyWaterF.glsl   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code   * Copyright (C) 2007, Linden Research, Inc. diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterAlphaMaskF.glsl index 6dd3bb937f..d04cd79f4b 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterAlphaMaskF.glsl @@ -1,5 +1,5 @@  /**  - * @file lightFullbrightWaterAlphaMaskF.glsl + * @file class1\lighting\lightFullbrightWaterAlphaMaskF.glsl   *   * $LicenseInfo:firstyear=2011&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterF.glsl index d3dacf9bc4..27880b720c 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterF.glsl @@ -1,5 +1,5 @@  /**  - * @file lightFullbrightWaterF.glsl + * @file class1\lighting\lightFullbrightWaterF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterNonIndexedAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterNonIndexedAlphaMaskF.glsl index 63f92a8844..3b9c04b22b 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterNonIndexedAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterNonIndexedAlphaMaskF.glsl @@ -1,5 +1,5 @@  /**  - * @file lightFullbrightWaterNonIndexedAlphaMaskF.glsl + * @file class1\lighting\lightFullbrightWaterNonIndexedAlphaMaskF.glsl   *   * $LicenseInfo:firstyear=2011&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterNonIndexedF.glsl index 0e68091e7c..e9fd8ac820 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterNonIndexedF.glsl @@ -1,5 +1,5 @@  /**  - * @file lightFullbrightWaterF.glsl + * @file class1\lighting\lightFullbrightWaterF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFuncSpecularV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFuncSpecularV.glsl index 85cddc647d..13a6dde4aa 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFuncSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFuncSpecularV.glsl @@ -1,5 +1,5 @@  /**  - * @file lightFuncSpecularV.glsl + * @file class1/lighting\lightFuncSpecularV.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -23,14 +23,6 @@   * $/LicenseInfo$   */ - - -float calcDirectionalLight(vec3 n, vec3 l) -{ -	float a = max(dot(n,l),0.0); -	return a; -} -  float calcDirectionalSpecular(vec3 view, vec3 n, vec3 l)  {  	return pow(max(dot(reflect(view, n),l), 0.0),8.0); diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl index a9288b3df6..45701002b8 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl @@ -1,5 +1,5 @@  /**  - * @file lightFuncV.glsl + * @file class1\lighting\lightFuncV.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -32,8 +32,7 @@ float calcDirectionalLight(vec3 n, vec3 l)  	return a;  } - -float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float is_pointlight) +float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight)  {  	//get light vector  	vec3 lv = lp.xyz-v; @@ -54,6 +53,6 @@ float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, floa  	//angular attenuation  	da *= calcDirectionalLight(n, lv); -	return da;	 +	return da;  } diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightNonIndexedF.glsl index 0aca768021..f9c7ad2ab3 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightNonIndexedF.glsl @@ -1,5 +1,5 @@  /**  - * @file lightF.glsl + * @file class1\lighting\lightF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightShinyF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightShinyF.glsl index 9208c148ef..f621a00785 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightShinyF.glsl @@ -1,5 +1,5 @@  /**  - * @file lightShinyF.glsl + * @file class1\lighting\lightShinyF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -45,7 +45,7 @@ void shiny_lighting()  	color.rgb *= vertex_color.rgb;  	vec3 envColor = textureCube(environmentMap, vary_texcoord1.xyz).rgb;	 -	color.rgb = mix(color.rgb, envColor.rgb, vertex_color.a); +	color.rgb = mix(color.rgb, envColor.rgb, vertex_color.a*0.75); // MAGIC NUMBER SL-12574; ALM: Off, Quality > Low  	color.rgb = atmosLighting(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightShinyNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightShinyNonIndexedF.glsl index 92628faa68..2b6f414005 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightShinyNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightShinyNonIndexedF.glsl @@ -1,5 +1,5 @@  /**  - * @file lightShinyF.glsl + * @file class1\lighting\lightShinyF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightShinyWaterF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightShinyWaterF.glsl index 61841674e2..0f3371eba9 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightShinyWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightShinyWaterF.glsl @@ -1,5 +1,5 @@  /**  - * @file lightShinyWaterF.glsl + * @file class1\lighting\lightShinyWaterF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightShinyWaterNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightShinyWaterNonIndexedF.glsl index 0b6e835fd0..c607fa64cb 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightShinyWaterNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightShinyWaterNonIndexedF.glsl @@ -1,5 +1,5 @@  /**  - * @file lightShinyWaterF.glsl + * @file class1\lighting\lightShinyWaterNonIndexedF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightSpecularV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightSpecularV.glsl index 24bf9b3cee..06aed40e26 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightSpecularV.glsl @@ -1,5 +1,5 @@  /**  - * @file lightSpecularV.glsl + * @file class1\lighting\lightSpecularV.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -27,10 +27,10 @@  // All lights, no specular highlights -vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol); +vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor); -vec4 calcLightingSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol) +vec4 calcLightingSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor)  { -	return sumLightsSpecular(pos, norm, color, specularColor, baseCol); +	return sumLightsSpecular(pos, norm, color, specularColor);  } diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl index 8045809b82..5e39d1629d 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl @@ -1,5 +1,5 @@  /**  - * @file lightV.glsl + * @file class1\lighting\lightV.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -26,11 +26,18 @@  // All lights, no specular highlights +vec3 atmosAmbient(); +vec4 sumLights(vec3 pos, vec3 norm, vec4 color); +float getAmbientClamp(); -vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight); - -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color)  { -	return sumLights(pos, norm, color, baseLight); +	vec4 c = sumLights(pos, norm, color); + +#if !defined(AMBIENT_KILL) +    c.rgb += atmosAmbient() * color.rgb * 0.5 * getAmbientClamp(); +#endif + +    return c;  } diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightWaterAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightWaterAlphaMaskF.glsl index 3426fea52f..0916797259 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightWaterAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightWaterAlphaMaskF.glsl @@ -1,5 +1,5 @@  /**  - * @file lightWaterAlphaMaskF.glsl + * @file class1\lighting\lightWaterAlphaMaskF.glsl   *   * $LicenseInfo:firstyear=2011&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightWaterAlphaMaskNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightWaterAlphaMaskNonIndexedF.glsl index d9faa9b314..f2a84f1d42 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightWaterAlphaMaskNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightWaterAlphaMaskNonIndexedF.glsl @@ -1,5 +1,5 @@  /**  - * @file lightWaterAlphaMaskNonIndexedF.glsl + * @file class1\lighting\lightWaterAlphaMaskNonIndexedF.glsl   *   * $LicenseInfo:firstyear=2011&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightWaterF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightWaterF.glsl index 00609e93cd..57ed993a66 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightWaterF.glsl @@ -1,5 +1,5 @@  /**  - * @file lightWaterF.glsl + * @file class1\lighting\lightWaterF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightWaterNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightWaterNonIndexedF.glsl index 13ecb7a636..af5da1411b 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightWaterNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightWaterNonIndexedF.glsl @@ -1,5 +1,5 @@  /**  - * @file lightWaterF.glsl + * @file class1\lighting\lightWaterNonIndexedF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl b/indra/newview/app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl index 7059ff31ae..7c3697c333 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl @@ -1,5 +1,5 @@  /** - * @file sumLightsSpecularV.glsl + * @file class1\lighting\sumLightsSpecularV.glsl   *   * $LicenseInfo:firstyear=2005&license=viewerlgpl$   * Second Life Viewer Source Code @@ -26,7 +26,7 @@  float calcDirectionalLightSpecular(inout vec4 specular, vec3 view, vec3 n, vec3 l, vec3 lightCol, float da); -vec3 atmosAmbient(vec3 light); +vec3 atmosAmbient();  vec3 atmosAffectDirectionalLight(float lightIntensity);  vec3 atmosGetDiffuseSunlightColor();  vec3 scaleDownLight(vec3 light); @@ -34,7 +34,7 @@ vec3 scaleDownLight(vec3 light);  uniform vec4 light_position[8];  uniform vec3 light_diffuse[8]; -vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol) +vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor)  {  	vec4 col = vec4(0,0,0, color.a); @@ -45,8 +45,8 @@ vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor  	col.rgb += light_diffuse[1].rgb * calcDirectionalLightSpecular(specularColor, view, norm, light_position[1].xyz,light_diffuse[1].rgb, 1.0);  	col.rgb = scaleDownLight(col.rgb); -	col.rgb += atmosAmbient(baseCol.rgb); -	col.rgb += atmosAffectDirectionalLight(calcDirectionalLightSpecular(specularSum, view, norm, light_position[0].xyz,atmosGetDiffuseSunlightColor()*baseCol.a, 1.0)); +	col.rgb += atmosAmbient(); +	col.rgb += atmosAffectDirectionalLight(calcDirectionalLightSpecular(specularSum, view, norm, light_position[0].xyz, atmosGetDiffuseSunlightColor(), 1.0));  	col.rgb = min(col.rgb * color.rgb, 1.0);  	specularColor.rgb = min(specularColor.rgb * specularSum.rgb, 1.0); diff --git a/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl index 41288c21c1..0c3ea4231e 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl @@ -1,5 +1,5 @@  /** - * @file sumLightsV.glsl + * @file class1\lighting\sumLightsV.glsl   *   * $LicenseInfo:firstyear=2005&license=viewerlgpl$   * Second Life Viewer Source Code @@ -28,22 +28,27 @@ uniform vec3 light_diffuse[8];  float calcDirectionalLight(vec3 n, vec3 l); -vec3 atmosAmbient(vec3 light); +vec3 atmosAmbient();  vec3 atmosAffectDirectionalLight(float lightIntensity);  vec3 scaleDownLight(vec3 light); -vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) +vec4 sumLights(vec3 pos, vec3 norm, vec4 color)  { -	vec4 col; +	vec4 col = vec4(0);  	col.a = color.a;  	col.rgb = light_diffuse[1].rgb * calcDirectionalLight(norm, light_position[1].xyz);  	col.rgb = scaleDownLight(col.rgb); -	col.rgb += atmosAmbient(baseLight.rgb); + +#if defined(LOCAL_LIGHT_KILL) +    col.rgb = vec3(0); +#endif + +#if !defined(SUNLIGHT_KILL)  	col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); -	 +#endif +  	col.rgb = min(col.rgb*color.rgb, 1.0); -	  	return col;	  } diff --git a/indra/newview/app_settings/shaders/class1/objects/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/objects/fullbrightF.glsl index a54c0caf81..31a262f1db 100644 --- a/indra/newview/app_settings/shaders/class1/objects/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/fullbrightF.glsl @@ -1,5 +1,5 @@  /**  - * @file fullbrightF.glsl + * @file objects/fullbrightF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/objects/previewV.glsl b/indra/newview/app_settings/shaders/class1/objects/previewV.glsl index 7f3f84398b..88959266c8 100644 --- a/indra/newview/app_settings/shaders/class1/objects/previewV.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/previewV.glsl @@ -52,7 +52,7 @@ float calcDirectionalLight(vec3 n, vec3 l)  } -float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float is_pointlight) +float calcLocalLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float is_pointlight)  {  	//get light vector  	vec3 lv = lp.xyz-v; @@ -91,8 +91,8 @@ void main()  	// Collect normal lights (need to be divided by two, as we later multiply by 2)  	col.rgb += light_diffuse[1].rgb * calcDirectionalLight(norm, light_position[1].xyz); -	col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].z); -	col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].z); +	col.rgb += light_diffuse[2].rgb*calcLocalLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].z); +	col.rgb += light_diffuse[3].rgb*calcLocalLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].z);  	vertex_color = col*color;  } diff --git a/indra/newview/app_settings/shaders/class1/objects/shinySimpleSkinnedV.glsl b/indra/newview/app_settings/shaders/class1/objects/shinySimpleSkinnedV.glsl index 591d6fc5c9..727bae19c0 100644 --- a/indra/newview/app_settings/shaders/class1/objects/shinySimpleSkinnedV.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/shinySimpleSkinnedV.glsl @@ -36,7 +36,7 @@ VARYING vec4 vertex_color;  VARYING vec2 vary_texcoord0;  VARYING vec3 vary_texcoord1; -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color);  void calcAtmospherics(vec3 inPositionEye);  mat4 getObjectSkinnedTransform(); @@ -59,7 +59,7 @@ void main()  	calcAtmospherics(pos.xyz); -	vec4 color = calcLighting(pos.xyz, norm.xyz, diffuse_color, vec4(0.)); +	vec4 color = calcLighting(pos.xyz, norm.xyz, diffuse_color);  	vertex_color = color;  	gl_Position = projection_matrix*vec4(pos, 1.0); diff --git a/indra/newview/app_settings/shaders/class1/objects/shinyV.glsl b/indra/newview/app_settings/shaders/class1/objects/shinyV.glsl index fdb3453cc5..4ba8194d03 100644 --- a/indra/newview/app_settings/shaders/class1/objects/shinyV.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/shinyV.glsl @@ -39,7 +39,7 @@ VARYING vec4 vertex_color;  VARYING vec2 vary_texcoord0;  VARYING vec3 vary_texcoord1; -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color);  void calcAtmospherics(vec3 inPositionEye); @@ -61,5 +61,5 @@ void main()  	calcAtmospherics(pos.xyz); -	vertex_color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.0));	 +	vertex_color = calcLighting(pos.xyz, norm, diffuse_color);	  } diff --git a/indra/newview/app_settings/shaders/class1/objects/simpleNoColorV.glsl b/indra/newview/app_settings/shaders/class1/objects/simpleNoColorV.glsl index 0be52a52af..22821a2f76 100644 --- a/indra/newview/app_settings/shaders/class1/objects/simpleNoColorV.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/simpleNoColorV.glsl @@ -38,7 +38,7 @@ VARYING vec4 vertex_color;  VARYING vec2 vary_texcoord0; -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color);  void calcAtmospherics(vec3 inPositionEye);  void main() @@ -52,7 +52,7 @@ void main()  	calcAtmospherics(pos.xyz); -	vec4 col = calcLighting(pos.xyz, norm, color, vec4(0.)); +	vec4 col = calcLighting(pos.xyz, norm, color);  	vertex_color = col; diff --git a/indra/newview/app_settings/shaders/class1/objects/simpleNonIndexedV.glsl b/indra/newview/app_settings/shaders/class1/objects/simpleNonIndexedV.glsl index cb80697d15..e605676819 100644 --- a/indra/newview/app_settings/shaders/class1/objects/simpleNonIndexedV.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/simpleNonIndexedV.glsl @@ -37,7 +37,7 @@ VARYING vec4 vertex_color;  VARYING vec2 vary_texcoord0; -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color);  void calcAtmospherics(vec3 inPositionEye);  void main() @@ -54,7 +54,7 @@ void main()  	calcAtmospherics(pos.xyz); -	vec4 color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.)); +	vec4 color = calcLighting(pos.xyz, norm, diffuse_color);  	vertex_color = color; diff --git a/indra/newview/app_settings/shaders/class1/objects/simpleSkinnedV.glsl b/indra/newview/app_settings/shaders/class1/objects/simpleSkinnedV.glsl index 1c6e53b187..df31b5a79f 100644 --- a/indra/newview/app_settings/shaders/class1/objects/simpleSkinnedV.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/simpleSkinnedV.glsl @@ -35,7 +35,7 @@ VARYING vec4 vertex_color;  VARYING vec2 vary_texcoord0; -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color);  void calcAtmospherics(vec3 inPositionEye);  mat4 getObjectSkinnedTransform(); @@ -56,7 +56,7 @@ void main()  	calcAtmospherics(pos.xyz); -	vec4 color = calcLighting(pos.xyz, norm.xyz, diffuse_color, vec4(0.)); +	vec4 color = calcLighting(pos.xyz, norm.xyz, diffuse_color);  	vertex_color = color;  	gl_Position = projection_matrix*vec4(pos, 1.0); diff --git a/indra/newview/app_settings/shaders/class1/objects/simpleTexGenV.glsl b/indra/newview/app_settings/shaders/class1/objects/simpleTexGenV.glsl index d4dee78793..945f80f31e 100644 --- a/indra/newview/app_settings/shaders/class1/objects/simpleTexGenV.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/simpleTexGenV.glsl @@ -37,7 +37,7 @@ uniform vec4 color;  uniform vec4 object_plane_t;  uniform vec4 object_plane_s; -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color);  void calcAtmospherics(vec3 inPositionEye);  VARYING vec4 vertex_color; @@ -70,7 +70,7 @@ void main()  	calcAtmospherics(pos.xyz); -	vec4 color = calcLighting(pos.xyz, norm, color, vec4(0.)); +	vec4 color = calcLighting(pos.xyz, norm, color);  	vertex_color = color; diff --git a/indra/newview/app_settings/shaders/class1/objects/simpleV.glsl b/indra/newview/app_settings/shaders/class1/objects/simpleV.glsl index 37a20383e2..a59bd9c0a6 100644 --- a/indra/newview/app_settings/shaders/class1/objects/simpleV.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/simpleV.glsl @@ -34,7 +34,7 @@ ATTRIBUTE vec2 texcoord0;  ATTRIBUTE vec3 normal;  ATTRIBUTE vec4 diffuse_color; -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color);  void calcAtmospherics(vec3 inPositionEye); @@ -57,7 +57,7 @@ void main()  	calcAtmospherics(pos.xyz); -	vec4 color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.)); +	vec4 color = calcLighting(pos.xyz, norm, diffuse_color);  	vertex_color = color; diff --git a/indra/newview/app_settings/shaders/class1/objects/treeV.glsl b/indra/newview/app_settings/shaders/class1/objects/treeV.glsl index fa01a27ec0..0227e6e3b8 100644 --- a/indra/newview/app_settings/shaders/class1/objects/treeV.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/treeV.glsl @@ -31,8 +31,9 @@ uniform mat4 modelview_projection_matrix;  ATTRIBUTE vec3 position;  ATTRIBUTE vec2 texcoord0;  ATTRIBUTE vec3 normal; +ATTRIBUTE vec4 diffuse_color; -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color);  void calcAtmospherics(vec3 inPositionEye);  VARYING vec4 vertex_color; @@ -53,8 +54,6 @@ void main()  	calcAtmospherics(pos.xyz); -	vec4 color = calcLighting(pos.xyz, norm, vec4(1,1,1,1), vec4(0.)); +	vec4 color = calcLighting(pos.xyz, norm, diffuse_color);  	vertex_color = color; - -	  } diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl index aacc503e13..4e0618e276 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl @@ -1,5 +1,5 @@  /**  - * @file atmosphericsF.glsl + * @file class1\windlight\atmosphericsF.glsl   *   * $LicenseInfo:firstyear=2005&license=viewerlgpl$   * Second Life Viewer Source Code @@ -23,11 +23,26 @@   * $/LicenseInfo$   */ +vec3 atmosFragAmbient(vec3 light, vec3 sunlit) +{ +    /* stub function for fallback compatibility on class1 hardware */ +    return light; +} +vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) +{ +    /* stub function for fallback compatibility on class1 hardware */ +    return light; +} + +vec3 atmosFragAffectDirectionalLight(float light, vec3 sunlit) +{ +   return light * sunlit; +}  vec3 atmosLighting(vec3 light)  { -	/* stub function for fallback compatibility on class1 hardware */ -	return light; +    /* stub function for fallback compatibility on class1 hardware */ +    return light;  } diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl new file mode 100644 index 0000000000..dcb02bd1c1 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -0,0 +1,154 @@ +/**  + * @file class1\windlight\atmosphericsFuncs.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2019, 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 lightnorm; +uniform vec4 sunlight_color; +uniform vec4 moonlight_color; +uniform int sun_up_factor; +uniform vec4 ambient_color; +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; +uniform int no_atmo; +uniform float sun_moon_glow_factor; + +float getAmbientClamp() +{ +    return 1.0f; +} + + +void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao) { + +    vec3 P = inPositionEye; +    +    //(TERRAIN) limit altitude +    if (P.y > max_y) P *= (max_y / P.y); +    if (P.y < -max_y) P *= (-max_y / P.y);  + +    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 = (sun_up_factor == 1) ? sunlight_color : moonlight_color; +    vec4 light_atten; + +    float dens_mul = density_multiplier; +    float dist_mul = distance_multiplier; + +    //sunlight attenuation effect (hue and brightness) due to atmosphere +    //this is used later for sunlight modulation at various altitudes +    light_atten = (blue_density + vec4(haze_density * 0.25)) * (dens_mul * max_y); +        //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); +    if (abs(temp2.y) > 0.000001f) +    { +        temp2.y = 1. / abs(temp2.y); +    } +    temp2.y = max(0.0000001f, temp2.y); +    sunlight *= exp(-light_atten * temp2.y); + +    // main atmospheric scattering line integral +    temp2.z = Plen * dens_mul; + +    // Transparency (-> temp1) +    // ATI Bugfix -- can't store temp1*temp2.z*dist_mul in a variable because the ati +    // compiler gets confused. +    temp1 = exp(-temp1 * temp2.z * dist_mul); + +    //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); + +    // dampen sun additive contrib when not facing it... +    if (length(light_dir) > 0.01) +    { +        temp2.x *= max(0.0f, dot(light_dir, Pn)); +    } +    temp2.x = 1. - temp2.x; +        //temp2.x is 0 at the sun and increases away from sun +    temp2.x = max(temp2.x, .001);    //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; + +    temp2.x *= sun_moon_glow_factor; +  +    vec4 amb_color = ambient_color;  +     +    //increase ambient when there are more clouds +    vec4 tmpAmbient = amb_color + (vec4(1.) - amb_color) * 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); +     */ +    if (use_ao) +    { +        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 = sunlight.rgb * 0.5; +    amblit = tmpAmbient.rgb * .25; +    additive *= vec3(1.0 - temp1); +} 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..206a51db27 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl @@ -0,0 +1,51 @@ +/**  + * @file class1\windlight\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; +uniform int no_atmo; + +vec3 atmosAmbient() +{ +    if (no_atmo == 1) return vec3(0.16); +    return 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; +} + diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl index 6ff860362c..c266f9732f 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl @@ -1,5 +1,5 @@  /**  - * @file atmosphericsHelpersV.glsl  + * @file class1\windlight\atmosphericsHelpersV.glsl    *   * $LicenseInfo:firstyear=2005&license=viewerlgpl$   * Second Life Viewer Source Code @@ -23,33 +23,35 @@   * $/LicenseInfo$   */ -uniform vec4 sunlight_color_copy; +uniform vec4 sunlight_color;  uniform vec4 light_ambient; +uniform int no_atmo; -vec3 atmosAmbient(vec3 light) +vec3 atmosAmbient()  { -	return light + light_ambient.rgb; +    if (no_atmo == 1) return vec3(0.66); +    return light_ambient.rgb;  }  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)  { -	/* stub function for fallback compatibility on class1 hardware */ -	return 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; +    /* stub function for fallback compatibility on class1 hardware */ +    return light;  } diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsV.glsl index 76d7d5059d..20457ad125 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsV.glsl @@ -1,5 +1,5 @@  /**  - * @file atmosphericsV.glsl  + * @file class1\windlight\atmosphericsV.glsl    *   * $LicenseInfo:firstyear=2005&license=viewerlgpl$   * Second Life Viewer Source Code @@ -29,7 +29,7 @@ void setPositionEye(vec3 v);  void calcAtmospherics(vec3 inPositionEye)  { -	/* stub function for fallback compatibility on class1 hardware */ -	setPositionEye(inPositionEye); +    /* stub function for fallback compatibility on class1 hardware */ +    setPositionEye(inPositionEye);  } diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsF.glsl index 8bdae328bd..a0699affbf 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsF.glsl @@ -1,5 +1,5 @@  /**  - * @file atmosphericVarsF.glsl + * @file class1\windlight\atmosphericVarsF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsV.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsV.glsl index 8ec9ae617c..bd1d150fc8 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsV.glsl @@ -1,5 +1,5 @@  /**  - * @file atmosphericVarsV.glsl + * @file class1\windlight\atmosphericVarsV.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsWaterF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsWaterF.glsl index 636d4af006..5dc086ab1e 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsWaterF.glsl @@ -1,5 +1,5 @@  /**  - * @file atmosphericVarsWaterF.glsl + * @file class1\windlight\atmosphericVarsWaterF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsWaterV.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsWaterV.glsl index 8afcc20f6d..e59eca265a 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsWaterV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsWaterV.glsl @@ -1,5 +1,5 @@  /**  - * @file atmosphericVarsWaterV.glsl + * @file class1\windlight\atmosphericVarsWaterV.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl new file mode 100644 index 0000000000..82fad4db5a --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl @@ -0,0 +1,127 @@ +/**  + * @file class1/windlight/cloudShadowF.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 + +uniform sampler2D diffuseMap; + +VARYING vec4 pos; +VARYING float target_pos_x; +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 sunlight_color; +uniform vec4 cloud_color; +uniform float cloud_shadow; +uniform float cloud_scale; +uniform float cloud_variance; +uniform vec3 camPosLocal; +uniform vec3 sun_dir; +uniform float sun_size; +uniform float far_z; + +#if !defined(DEPTH_CLAMP) +VARYING vec4 post_pos; +#endif + +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 normalize(cloud_noise_sample); +} + +void main() +{ +    if (cloud_scale >= 0.0001) +    { +        // Set variables +        vec2 uv1 = vary_texcoord0.xy; +        vec2 uv2 = vary_texcoord1.xy; +        vec2 uv3 = vary_texcoord2.xy; +        float cloudDensity = 2.0 * (cloud_shadow - 0.25); +     +        vec2 uv4 = vary_texcoord3.xy; +     +        vec2 disturbance  = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); +        vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); +     +        // Offset texture coords +        uv1 += cloud_pos_density1.xy + (disturbance * 0.2);    //large texture, visible density +        uv2 += cloud_pos_density1.xy;   //large texture, self shadow +        uv3 += cloud_pos_density2.xy;   //small texture, visible density +        uv4 += cloud_pos_density2.xy;   //small texture, self shadow +     +        float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y) * 4.0); +     +        cloudDensity *= 1.0 - (density_variance * density_variance); +     +        // 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;   +     +        if (alpha1 < 0.001f) +        { +            discard; +        } +     +        // 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;   +     +        frag_color = vec4(alpha1, alpha1, alpha1, 1); +    } +    else +    { +        frag_color = vec4(1); +    } + +#if !defined(DEPTH_CLAMP) +    gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0); +#endif + +} diff --git a/indra/newview/app_settings/shaders/class1/windlight/cloudShadowV.glsl b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowV.glsl new file mode 100644 index 0000000000..09b6004481 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowV.glsl @@ -0,0 +1,61 @@ +/**  + * @file class1\windlight\cloudShadowV.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 !defined(DEPTH_CLAMP) +VARYING float pos_zd2; +#endif + +VARYING vec4 pos; +VARYING float target_pos_x; +VARYING vec2 vary_texcoord0; + +void passTextureIndex(); + +void main() +{ +	//transform vertex +	vec4 pre_pos = vec4(position.xyz, 1.0); +	pos = modelview_projection_matrix * pre_pos; +	target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; + +#if !defined(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; +} diff --git a/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl index 62f4e51449..fc51e81177 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl @@ -1,5 +1,5 @@  /**  - * @file gammaF.glsl + * @file class1\windlight\gammaF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -23,17 +23,30 @@   * $/LicenseInfo$   */ +uniform int no_atmo; - -uniform vec4 gamma; +vec3 scaleSoftClipFrag(vec3 light) +{ +	// For compatibility with lower cards. Do nothing. +	return light; +}  /// Soft clips the light with a gamma correction -vec3 scaleSoftClip(vec3 light) { -	// For compatibility with lower cards. Do nothing. +vec3 scaleSoftClip(vec3 light) +{ +	// For compatibility with lower cards. Do nothing +	return light; +} + +vec3 fullbrightScaleSoftClipFrag(vec3 light, vec3 additive, vec3 atten) +{ +	// For compatibility with lower cards. Do nothing  	return light;  } -vec3 fullbrightScaleSoftClip(vec3 light) { -	return scaleSoftClip(light); +vec3 fullbrightScaleSoftClip(vec3 light) +{ +	// For compatibility with lower cards. Do nothing +    return 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..24f3992e32 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl @@ -0,0 +1,64 @@ +/**  + * @file class1\wl\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 + +uniform vec4 color; +uniform vec4 sunlight_color; +uniform vec4 moonlight_color; +uniform vec3 lumWeights; +uniform float moon_brightness; +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); + +    // mix factor which blends when sunlight is brighter +    // and shows true moon color at night +    vec3 luma_weights = vec3(0.3, 0.5, 0.3); +    float mix = 1.0f - dot(normalize(sunlight_color.rgb), luma_weights); + +    vec3 exp = vec3(1.0 - mix * moon_brightness) * 2.0 - 1.0; +    c.rgb = pow(c.rgb, exp); +    //c.rgb *= moonlight_color.rgb; + +    frag_color = vec4(c.rgb, 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..8cd4b2ef47 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/windlight/moonV.glsl @@ -0,0 +1,49 @@ +/**  + * @file class1\wl\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 +    vec3 offset = vec3(0, 0, 50); +    vec4 vert = vec4(position.xyz - offset, 1.0); +    vec4 pos = (modelview_matrix * vert); + +    gl_Position = modelview_projection_matrix*vert; +     +    vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; +     +    calcAtmospherics(pos.xyz); +} diff --git a/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl new file mode 100644 index 0000000000..b9ae7a0226 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl @@ -0,0 +1,59 @@ +/**  + * @file class1\wl\sunDiscF.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 sampler2D diffuseMap; +uniform sampler2D altDiffuseMap; +uniform float blend_factor; // interp factor between sun A/B +VARYING vec2 vary_texcoord0; +VARYING float sun_fade; + +void main()  +{ +    vec4 sunA = texture2D(diffuseMap, vary_texcoord0.xy); +    vec4 sunB = texture2D(altDiffuseMap, vary_texcoord0.xy); +    vec4 c     = mix(sunA, sunB, blend_factor); + +// SL-9806 stars poke through +//    c.a *= sun_fade; + +    c.rgb = pow(c.rgb, vec3(0.7f)); +    c.rgb = fullbrightAtmosTransport(c.rgb); +    c.rgb = fullbrightScaleSoftClip(c.rgb); +    frag_color = c; +} + diff --git a/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl b/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl new file mode 100644 index 0000000000..6c0e795f6b --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl @@ -0,0 +1,51 @@ +/**  + * @file class1\wl\sunDiscV.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; + +VARYING vec2 vary_texcoord0; +VARYING float sun_fade; + +void calcAtmospherics(vec3 eye_pos); + +void main() +{ +    //transform vertex +    vec3 offset = vec3(0, 0, 50); +    vec4 vert = vec4(position.xyz - offset, 1.0); +    vec4 pos = modelview_projection_matrix*vert; + +    sun_fade = smoothstep(0.3, 1.0, (position.z + 50) / 512.0f); +    gl_Position = pos; +     +    calcAtmospherics(pos.xyz); + +    vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; +} diff --git a/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl index 7c95ecdb14..a937d9fa99 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl @@ -1,5 +1,5 @@  /**  - * @file transportF.glsl + * @file class1/windlight/transportF.glsl   *   * $LicenseInfo:firstyear=2005&license=viewerlgpl$   * Second Life Viewer Source Code @@ -22,25 +22,35 @@   * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA   * $/LicenseInfo$   */ -  +uniform int no_atmo; -vec3 atmosTransport(vec3 light) +vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten)  { -	/* stub function for fallback compatibility on class1 hardware */ +    /* stub function for fallback compatibility on class1 hardware */  	return light;  } -vec3 fullbrightAtmosTransport(vec3 light) +vec3 atmosTransport(vec3 light)  {  	/* stub function for fallback compatibility on class1 hardware */ -	return light; +    return light; +} + +vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) +{ +    /* stub function for fallback compatibility on class1 hardware */ +    return light;  } +vec3 fullbrightAtmosTransport(vec3 light) +{ +    /* stub function for fallback compatibility on class1 hardware */ +    return light; +}  vec3 fullbrightShinyAtmosTransport(vec3 light)  { -	/* stub function for fallback compatibility on class1 hardware */ -	return light; +    /* stub function for fallback compatibility on class1 hardware */ +    return light;  } - diff --git a/indra/newview/app_settings/shaders/class2/avatar/eyeballV.glsl b/indra/newview/app_settings/shaders/class2/avatar/eyeballV.glsl index 5af9f5c902..563c5f562b 100644 --- a/indra/newview/app_settings/shaders/class2/avatar/eyeballV.glsl +++ b/indra/newview/app_settings/shaders/class2/avatar/eyeballV.glsl @@ -37,7 +37,7 @@ VARYING vec4 vertex_color;  VARYING vec2 vary_texcoord0; -vec4 calcLightingSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol); +vec4 calcLightingSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor);  void calcAtmospherics(vec3 inPositionEye);  void main() @@ -53,7 +53,7 @@ void main()  	// vec4 specular = specularColor;  	vec4 specular = vec4(1.0); -	vec4 color = calcLightingSpecular(pos, norm, diffuse_color, specular, vec4(0.0)); +	vec4 color = calcLightingSpecular(pos, norm, diffuse_color, specular);  	vertex_color = color; diff --git a/indra/newview/app_settings/shaders/class2/deferred/indirect.glsl b/indra/newview/app_settings/shaders/class2/deferred/indirect.glsl new file mode 100644 index 0000000000..67b98e0fb1 --- /dev/null +++ b/indra/newview/app_settings/shaders/class2/deferred/indirect.glsl @@ -0,0 +1,32 @@ +/**  + * @file class2/deferred/indirect.glsl + * + * $LicenseInfo:firstyear=2018&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$ + */ + +float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen); + +vec3 getIndirect(vec3 ambient, vec3 norm, vec4 pos, vec2 pos_screen) +{ +    return ambient * calcAmbientOcclusion(pos, norm, pos_screen); +} + diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index b9bb522842..5d7a28c359 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -71,294 +71,233 @@ 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; -} - -vec4 correctWithGamma(vec4 col) -{ -	return vec4(srgb_to_linear(col.rgb), col.a); -} +vec3 srgb_to_linear(vec3 cs); +vec3 getNorm(vec2 pos_screen);  vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod)  { -	vec4 ret = texture2DLod(projectionMap, tc, lod); -	ret.rgb = srgb_to_linear(ret.rgb); -	 -	vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); -	 -	float det = min(lod/(proj_lod*0.5), 1.0); -	 -	float d = min(dist.x, dist.y); +    vec4 ret = texture2DLod(projectionMap, tc, lod); +    ret.rgb = srgb_to_linear(ret.rgb); +    vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); +     +    float det = min(lod/(proj_lod*0.5), 1.0); +     +    float d = min(dist.x, dist.y);      d *= min(1, d * (proj_lod - lod)); -	 -	float edge = 0.25*det; -	ret *= clamp(d/edge, 0.0, 1.0); -	 -	return ret; +    float edge = 0.25*det; +     +    ret *= clamp(d/edge, 0.0, 1.0); +     +    return ret;  }  vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod)  { -	vec4 ret = texture2DLod(projectionMap, tc, lod); -	ret = correctWithGamma(ret); - -	vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); -	 -	float det = min(lod/(proj_lod*0.5), 1.0); -	 -	float d = min(dist.x, dist.y); -	 -	float edge = 0.25*det; -		 -	ret *= clamp(d/edge, 0.0, 1.0); -	 -	return ret; +    vec4 ret = texture2DLod(projectionMap, tc, lod); +    ret.rgb = srgb_to_linear(ret.rgb); + +    vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); +     +    float det = min(lod/(proj_lod*0.5), 1.0); +     +    float d = min(dist.x, dist.y); +     +    float edge = 0.25*det; +         +    ret *= clamp(d/edge, 0.0, 1.0); +     +    return ret;  }  vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod)  { -	vec4 ret = texture2DLod(projectionMap, tc, lod); -	ret = correctWithGamma(ret); - -	vec2 dist = tc-vec2(0.5); -	 -	float d = dot(dist,dist); -		 -	ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); -	 -	return ret; -} +    vec4 ret = texture2DLod(projectionMap, tc, lod); +    ret.rgb = srgb_to_linear(ret.rgb); - -vec4 getPosition(vec2 pos_screen) -{ -	float depth = texture2DRect(depthMap, pos_screen.xy).r; -	vec2 sc = pos_screen.xy*2.0; -	sc /= screen_res; -	sc -= vec2(1.0,1.0); -	vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); -	vec4 pos = inv_proj * ndc; -	pos /= pos.w; -	pos.w = 1.0; -	return pos; +    vec2 dist = tc-vec2(0.5); +     +    float d = dot(dist,dist); +         +    ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); +     +    return ret;  } +vec4 getPosition(vec2 pos_screen); +  void main()   { -	vec4 frag = vary_fragcoord; -	frag.xyz /= frag.w; -	frag.xyz = frag.xyz*0.5+0.5; -	frag.xy *= screen_res; -	 -	vec3 pos = getPosition(frag.xy).xyz; -	vec3 lv = center.xyz-pos.xyz; -	float dist = length(lv); -	dist /= size; -	if (dist > 1.0) -	{ -		discard; -	} -	 -	float shadow = 1.0; -	 -	if (proj_shadow_idx >= 0) -	{ -		vec4 shd = texture2DRect(lightMap, frag.xy); -		float sh[2]; -		sh[0] = shd.b; -		sh[1] = shd.a; -		shadow = min(sh[proj_shadow_idx]+shadow_fade, 1.0); -	} -	 -	vec3 norm = texture2DRect(normalMap, frag.xy).xyz; -	 -	float envIntensity = norm.z; - -	norm = decode_normal(norm.xy); -	 -	norm = normalize(norm); -	float l_dist = -dot(lv, proj_n); -	 -	vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); -	if (proj_tc.z < 0.0) -	{ -		discard; -	} -	 -	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); -	dist_atten *= dist_atten; -	dist_atten *= 2.0; -	if (dist_atten <= 0.0) -	{ -		discard; -	} -	 -	lv = proj_origin-pos.xyz; -	lv = normalize(lv); -	float da = dot(norm, lv); - -	vec3 col = vec3(0,0,0); -		 -	vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; -	 -	vec4 spec = texture2DRect(specularRect, frag.xy); - -	vec3 dlit = vec3(0, 0, 0); - -	float noise = texture2D(noiseMap, frag.xy/128.0).b; -	if (proj_tc.z > 0.0 && -		proj_tc.x < 1.0 && -		proj_tc.y < 1.0 && -		proj_tc.x > 0.0 && -		proj_tc.y > 0.0) -	{ -		float amb_da = proj_ambiance; -		float lit = 0.0; - -		if (da > 0.0) -		{ -			lit = da * dist_atten * noise; - -			float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); -			float lod = diff * proj_lod; -			 -			vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); -		 -			dlit = color.rgb * plcol.rgb * plcol.a; -			 -			col = dlit*lit*diff_tex*shadow; -			amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; -		} -		 -		//float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); -		vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); -							 -		amb_da += (da*da*0.5+0.5)*proj_ambiance; -				 -		amb_da *= dist_atten * noise; -			 -		amb_da = min(amb_da, 1.0-lit); -			 -		col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; -	} -	 - -	if (spec.a > 0.0) -	{ -		vec3 npos = -normalize(pos); -		dlit *= min(da*6.0, 1.0) * dist_atten; - -		//vec3 ref = dot(pos+lv, norm); -		vec3 h = normalize(lv+npos); -		float nh = dot(norm, h); -		float nv = dot(norm, npos); -		float vh = dot(npos, h); -		float sa = nh; -		float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - -		float gtdenom = 2 * nh; -		float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); -								 -		if (nh > 0.0) -		{ -			float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); -			col += dlit*scol*spec.rgb*shadow; -			//col += spec.rgb; -		} -	}	 -	 -	 -	 -	 - -	if (envIntensity > 0.0) -	{ -		vec3 ref = reflect(normalize(pos), norm); -		 -		//project from point pos in direction ref to plane proj_p, proj_n -		vec3 pdelta = proj_p-pos; -		float ds = dot(ref, proj_n); -		 -		if (ds < 0.0) -		{ -			vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; -			 -			vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); - -			if (stc.z > 0.0) -			{ + +    vec3 col = vec3(0,0,0); + +#if defined(LOCAL_LIGHT_KILL) +    discard; +#else +    vec4 frag = vary_fragcoord; +    frag.xyz /= frag.w; +    frag.xyz = frag.xyz*0.5+0.5; +    frag.xy *= screen_res; +     +    vec3 pos = getPosition(frag.xy).xyz; +    vec3 lv = center.xyz-pos.xyz; +    float dist = length(lv); + +    if (dist >= size) +    { +        discard; +    } +    dist /= size; + +    float shadow = 1.0; +     +    if (proj_shadow_idx >= 0) +    { +        vec4 shd = texture2DRect(lightMap, frag.xy); +        shadow = (proj_shadow_idx==0)?shd.b:shd.a; +        shadow += shadow_fade; +        shadow = clamp(shadow, 0.0, 1.0);         +    } +     +    vec3 norm = texture2DRect(normalMap, frag.xy).xyz; +     +    float envIntensity = norm.z; + +    norm = getNorm(frag.xy); +     +    norm = normalize(norm); +    float l_dist = -dot(lv, proj_n); +     +    vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); +    if (proj_tc.z < 0.0) +    { +        discard; +    } +     +    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); +    dist_atten *= dist_atten; +    dist_atten *= 2.0; +    if (dist_atten <= 0.0) +    { +        discard; +    } +     +    lv = proj_origin-pos.xyz; +    lv = normalize(lv); +    float da = dot(norm, lv); +         +    vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; +    // SL-12005 Projector light pops as we get closer, more objectionable than being in wrong color space. +    //          We can't switch to linear here unless we do it everywhere* +    // *gbuffer IS sRGB, convert to linear since this shader outputs linear +    diff_tex.rgb = srgb_to_linear(diff_tex.rgb); +  +    vec4 spec = texture2DRect(specularRect, frag.xy); + +    vec3 dlit = vec3(0, 0, 0); + +    float noise = texture2D(noiseMap, frag.xy/128.0).b; +    if (proj_tc.z > 0.0 && +        proj_tc.x < 1.0 && +        proj_tc.y < 1.0 && +        proj_tc.x > 0.0 && +        proj_tc.y > 0.0) +    { +        float amb_da = proj_ambiance; +        float lit = 0.0; + +        if (da > 0.0) +        { +            lit = da * dist_atten * noise; + +            float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); +            float lod = diff * proj_lod; +             +            vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); +         +            dlit = color.rgb * plcol.rgb * plcol.a; +             +            col = dlit*lit*diff_tex*shadow; + +            // unshadowed for consistency between forward and deferred? +            amb_da += (da*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; +        } +         +        //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); +        vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); + +        // use unshadowed for consistency between forward and deferred? +        amb_da += (da*da*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; +        amb_da *= dist_atten * noise; +        amb_da = min(amb_da, 1.0-lit); + +        col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; +    } +     + +    if (spec.a > 0.0) +    { +        vec3 npos = -normalize(pos); +        dlit *= min(da*6.0, 1.0) * dist_atten; + +        //vec3 ref = dot(pos+lv, norm); +        vec3 h = normalize(lv+npos); +        float nh = dot(norm, h); +        float nv = dot(norm, npos); +        float vh = dot(npos, h); +        float sa = nh; +        float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + +        float gtdenom = 2 * nh; +        float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); +                                 +        if (nh > 0.0) +        { +            float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); +            vec3 speccol = dlit*scol*spec.rgb*shadow; +            speccol = clamp(speccol, vec3(0), vec3(1)); +            col += speccol; +        } +    }    + +    if (envIntensity > 0.0) +    { +        vec3 ref = reflect(normalize(pos), norm); +         +        //project from point pos in direction ref to plane proj_p, proj_n +        vec3 pdelta = proj_p-pos; +        float ds = dot(ref, proj_n); +         +        if (ds < 0.0) +        { +            vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; +             +            vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); + +            if (stc.z > 0.0) +            {                  stc /= stc.w; -								 -				if (stc.x < 1.0 && -					stc.y < 1.0 && -					stc.x > 0.0 && -					stc.y > 0.0) -				{ -					col += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; -				} -			} -		} -	} - -	//not sure why, but this line prevents MATBUG-194 -	col = max(col, vec3(0.0)); - -	frag_color.rgb = col;	 -	frag_color.a = 0.0; +                                 +                if (stc.x < 1.0 && +                    stc.y < 1.0 && +                    stc.x > 0.0 && +                    stc.y > 0.0) +                { +                    col += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; +                } +            } +        } +    } +#endif + +    //not sure why, but this line prevents MATBUG-194 +    col = max(col, vec3(0.0)); + +    //output linear +    frag_color.rgb = col; +    frag_color.a = 0.0;  } diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl new file mode 100644 index 0000000000..1dce85a83b --- /dev/null +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -0,0 +1,204 @@ +/**  + * @file class2/deferred/skyF.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; + +// SKY //////////////////////////////////////////////////////////////////////// +// The vertex shader for creating the atmospheric sky +/////////////////////////////////////////////////////////////////////////////// + +// Inputs +uniform vec3 camPosLocal; + +uniform vec4 lightnorm; +uniform vec4 sunlight_color; +uniform vec4 moonlight_color; +uniform int sun_up_factor; +uniform vec4 ambient_color; +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 sun_moon_glow_factor; + +uniform vec4 cloud_color; + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_data[3]; +#else +#define frag_data gl_FragData +#endif + +VARYING vec3 pos; + +///////////////////////////////////////////////////////////////////////// +// The fragment shader for the sky +///////////////////////////////////////////////////////////////////////// + +uniform sampler2D rainbow_map; +uniform sampler2D halo_map; + +uniform float moisture_level; +uniform float droplet_radius; +uniform float ice_level; + +vec3 rainbow(float d) +{ +   d = clamp(d, -1.0, 0.0); +   float rad = (droplet_radius - 5.0f) / 1024.0f; +   return pow(texture2D(rainbow_map, vec2(rad, d)).rgb, vec3(1.8)) * moisture_level; +} + +vec3 halo22(float d) +{ +   d = clamp(d, 0.1, 1.0); +   float v = sqrt(clamp(1 - (d * d), 0, 1)); +   return texture2D(halo_map, vec2(0, v)).rgb * ice_level; +} + +/// Soft clips the light with a gamma correction +vec3 scaleSoftClip(vec3 light); + +void main() +{ + +    // World / view / projection +    // Get relative position +    vec3 P = pos.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 = (sun_up_factor == 1) ? sunlight_color : moonlight_color; +    vec4 light_atten; + +    float dens_mul = density_multiplier; + +    // Sunlight attenuation effect (hue and brightness) due to atmosphere +    // this is used later for sunlight modulation at various altitudes +    light_atten = (blue_density + vec4(haze_density * 0.25)) * (dens_mul * max_y); + +    // Calculate relative weights +    temp1 = abs(blue_density) + vec4(abs(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 * dens_mul; + +    // 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; + +    temp2.x *= sun_moon_glow_factor; + +    // Haze color above cloud +    vec4 color = (    blue_horizon * blue_weight * (sunlight + ambient_color) +                + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient_color) +             );  + +    // Final atmosphere additive +    color *= (1. - temp1); + +    // Increase ambient when there are more clouds +    vec4 tmpAmbient = ambient_color; +    tmpAmbient += max(vec4(0), (1. - ambient_color)) * cloud_shadow * 0.5;  + +    // Dim sunlight by cloud shadow percentage +    sunlight *= max(0.0, (1. - cloud_shadow)); + +    // Haze color below cloud +    vec4 additiveColorBelowCloud = (blue_horizon * blue_weight * (sunlight + tmpAmbient) +                + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) +             );  + +     +     +    // Attenuate cloud color by atmosphere +    temp1 = sqrt(temp1);    //less atmos opacity (more transparency) below clouds + +    // At horizon, blend high altitude sky color towards the darker color below the clouds +    color += (additiveColorBelowCloud - color) * (1. - sqrt(temp1)); +     +    float optic_d = dot(Pn, lightnorm.xyz); + +    vec3 halo_22 = halo22(optic_d); + +    color.rgb += rainbow(optic_d); + +    color.rgb += halo_22; + +    color.rgb *= 2.; +    color.rgb = scaleSoftClip(color.rgb); + +    /// Gamma correct for WL (soft clip effect). +    frag_data[0] = vec4(color.rgb, 1.0); +    frag_data[1] = vec4(0.0,0.0,0.0,0.0); +    frag_data[2] = vec4(0.0,0.0,0.0,1.0); //1.0 in norm.w masks off fog +} + diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyV.glsl new file mode 100644 index 0000000000..bcf775577a --- /dev/null +++ b/indra/newview/app_settings/shaders/class2/deferred/skyV.glsl @@ -0,0 +1,42 @@ +/**  + * @file WLSkyV.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; + +// SKY //////////////////////////////////////////////////////////////////////// +// The vertex shader for creating the atmospheric sky +/////////////////////////////////////////////////////////////////////////////// + +VARYING vec3 pos; + +void main() +{ + +	// World / view / projection +    pos = position.xyz; +	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); +} diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index f7832521fa..9c7a4df767 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -1,5 +1,5 @@  /**  - * @file softenLightF.glsl + * @file class2/deferred/softenLightF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -24,6 +24,7 @@   */  #extension GL_ARB_texture_rectangle : enable +#extension GL_ARB_shader_texture_lod : enable  /*[EXTRA_CODE_HERE]*/ @@ -39,456 +40,182 @@ uniform sampler2DRect normalMap;  uniform sampler2DRect lightMap;  uniform sampler2DRect depthMap;  uniform samplerCube environmentMap; -uniform sampler2D	  lightFunc; +uniform sampler2D     lightFunc;  uniform float blur_size;  uniform float blur_fidelity;  // Inputs -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 vec4 shadow_clip; -uniform mat3 ssao_effect_mat;  uniform vec3 sun_dir; +uniform vec3 moon_dir; +uniform int sun_up_factor;  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 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; -} - -vec4 getPosition_d(vec2 pos_screen, float depth) -{ -	vec2 sc = pos_screen.xy*2.0; -	sc /= screen_res; -	sc -= vec2(1.0,1.0); -	vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); -	vec4 pos = inv_proj * ndc; -	pos /= pos.w; -	pos.w = 1.0; -	return pos; -} - -vec4 getPosition(vec2 pos_screen) -{ //get position in screen space (world units) given window coordinate and depth map -	float depth = texture2DRect(depthMap, pos_screen.xy).r; -	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; -} +vec3 getNorm(vec2 pos_screen); +vec4 getPositionWithDepth(vec2 pos_screen, float depth); -void setAtmosAttenuation(vec3 v) -{ -	vary_AtmosAttenuation = v; -} +void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); +float getAmbientClamp(); +vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); +vec3 scaleSoftClipFrag(vec3 l); -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)); -} +vec3 linear_to_srgb(vec3 c); +vec3 srgb_to_linear(vec3 c);  #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) +void main()   { -	//soft clip effect: -	light = 1. - clamp(light, vec3(0.), vec3(1.)); -	light = 1. - pow(light, gamma.xxx); - -	return light; -} +    vec2 tc = vary_fragcoord.xy; +    float depth = texture2DRect(depthMap, tc.xy).r; +    vec4 pos = getPositionWithDepth(tc, depth); +    vec4 norm = texture2DRect(normalMap, tc); +    float envIntensity = norm.z; +    norm.xyz = getNorm(tc); // unpack norm + +    vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir;         + +    float scol = 1.0; +    vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; + +    float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0); +    da = pow(da, 1.0/1.3); +    vec4 diffuse_srgb   = texture2DRect(diffuseRect, tc); +    vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); + +    // clamping to alpha value kills underwater shadows... +    //scol = max(scol_ambocc.r, diffuse_linear.a); +    scol = scol_ambocc.r; + +    vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); +    vec3 color = vec3(0); +    float bloom = 0.0; +    { +        float ambocc = scol_ambocc.g; + +        vec3 sunlit; +        vec3 amblit; +        vec3 additive; +        vec3 atten; +     +        calcAtmosphericVars(pos.xyz, light_dir, ambocc, sunlit, amblit, additive, atten, true); +         +        float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); +        ambient *= 0.5; +        ambient *= ambient; +        ambient = (1.0 - ambient); + +        vec3 sun_contrib = min(scol, da) * sunlit; + +#if !defined(AMBIENT_KILL) +        color.rgb = amblit; +        color.rgb *= ambient; +#endif +vec3 post_ambient = color.rgb; -vec3 fullbrightScaleSoftClip(vec3 light) -{ -	//soft clip effect: -	return light; -} +#if !defined(SUNLIGHT_KILL) +        color.rgb += sun_contrib; +#endif -void main()  -{ -	vec2 tc = vary_fragcoord.xy; -	float depth = texture2DRect(depthMap, tc.xy).r; -	vec3 pos = getPosition_d(tc, depth).xyz; -	vec4 norm = texture2DRect(normalMap, tc); -	float envIntensity = norm.z; -	norm.xyz = decode_normal(norm.xy); // unpack norm -		 -	float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); - -	float light_gamma = 1.0/1.3; -	da = pow(da, light_gamma); - - -	vec4 diffuse = texture2DRect(diffuseRect, tc); - -	//convert to gamma space -	diffuse.rgb = linear_to_srgb(diffuse.rgb); -	 -	vec3 col; -	float bloom = 0.0; -	{ -		vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); -		 -		vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; -		scol_ambocc = pow(scol_ambocc, vec2(light_gamma)); - -		float scol = max(scol_ambocc.r, diffuse.a);  - -		 - -		float ambocc = scol_ambocc.g; -	 -		calcAtmospherics(pos.xyz, ambocc); -	 -		col = atmosAmbient(vec3(0)); -		float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); -		ambient *= 0.5; -		ambient *= ambient; -		ambient = (1.0-ambient); - -		col.rgb *= ambient; - -		col += atmosAffectDirectionalLight(max(min(da, scol), 0.0)); -	 -		col *= diffuse.rgb; -	 -		vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - -		if (spec.a > 0.0) // specular reflection -		{ -			// 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); -			 -			// add the two types of shiny together -			vec3 spec_contrib = dumbshiny * spec.rgb; -			bloom = dot(spec_contrib, spec_contrib) / 6; -			col += spec_contrib; -		} -	 -		 -		col = mix(col, diffuse.rgb, diffuse.a); - -		if (envIntensity > 0.0) -		{ //add environmentmap -			vec3 env_vec = env_mat * refnormpersp; -			 -			vec3 refcol = textureCube(environmentMap, env_vec).rgb; - -			col = mix(col.rgb, refcol,  -				envIntensity);   - -		} -						 -		if (norm.w < 0.5) -		{ -			col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); -			col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); -		} - -		#ifdef WATER_FOG -			vec4 fogged = applyWaterFogDeferred(pos,vec4(col, bloom)); -			col = fogged.rgb; -			bloom = fogged.a; -		#endif - -		col = srgb_to_linear(col); - -		//col = vec3(1,0,1); -		//col.g = envIntensity; -	} -	 -	frag_color.rgb = col; -	frag_color.a = bloom; +vec3 post_sunlight = color.rgb; + +        color.rgb *= diffuse_srgb.rgb; + +vec3 post_diffuse = color.rgb; + +        vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + +        if (spec.a > 0.0) // specular reflection +        { +            vec3 npos = -normalize(pos.xyz); + +            //vec3 ref = dot(pos+lv, norm); +            vec3 h = normalize(light_dir.xyz+npos); +            float nh = dot(norm.xyz, h); +            float nv = dot(norm.xyz, npos); +            float vh = dot(npos, h); +            float sa = nh; +            float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + +            float gtdenom = 2 * nh; +            float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); +                                     +            if (nh > 0.0) +            { +                float scontrib = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); +                vec3 sp = sun_contrib*scontrib / 6.0; +                sp = clamp(sp, vec3(0), vec3(1)); +                bloom += dot(sp, sp) / 4.0; +#if !defined(SUNLIGHT_KILL) +                color += sp * spec.rgb; +#endif +            } +        } +        + vec3 post_spec = color.rgb; + +        if (envIntensity > 0.0) +        { //add environmentmap +            vec3 env_vec = env_mat * refnormpersp; +            vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; +#if !defined(SUNLIGHT_KILL) +            color = mix(color.rgb, reflected_color, envIntensity*0.75); // MAGIC NUMBER SL-12574; ALM: On, Quality >= High +#endif +        } +        else +        { +            color.rgb = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); +        } + +vec3 post_env = color.rgb; + +        if (norm.w < 1) +        { +#if !defined(SUNLIGHT_KILL) +            vec3 p = normalize(pos.xyz); +            color = atmosFragLighting(color, additive, atten); +            color = scaleSoftClipFrag(color); +#endif +        } + +vec3 post_atmo = color.rgb; + +        #ifdef WATER_FOG +            vec4 fogged = applyWaterFogView(pos.xyz,vec4(color, bloom)); +            color = fogged.rgb; +            bloom = fogged.a; +        #endif + +// srgb colorspace debuggables +//color.rgb = amblit; +//color.rgb = sunlit; +//color.rgb = post_ambient; +//color.rgb = sun_contrib; +//color.rgb = post_sunlight; +//color.rgb = diffuse_srgb.rgb; +//color.rgb = post_diffuse; +//color.rgb = post_spec; +//color.rgb = post_env; +//color.rgb = post_atmo; + +    } + +// linear debuggables +//color.rgb = vec3(final_da); +//color.rgb = vec3(ambient); +//color.rgb = vec3(scol); +//color.rgb = diffuse_linear.rgb; + +        //output linear RGB as lights are summed up in linear space and then gamma corrected prior to the  +        //post deferred passes +    frag_color.rgb = srgb_to_linear(color.rgb); +    frag_color.a = bloom;  } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl index c840d72784..8b8b338f68 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl @@ -36,7 +36,5 @@ void main()  	//transform vertex  	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);  	gl_Position = pos;  -	 -	  	vary_fragcoord = (pos.xy*0.5+0.5)*screen_res;  } diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 81af1fdc8a..5ab0b5c5b4 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -71,70 +71,14 @@ 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 - -} - -vec4 correctWithGamma(vec4 col) -{ -	return vec4(srgb_to_linear(col.rgb), col.a); -} +vec3 getNorm(vec2 pos_screen); +vec3 srgb_to_linear(vec3 c);  vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod)  {  	vec4 ret = texture2DLod(projectionMap, tc, lod);  	ret.rgb = srgb_to_linear(ret.rgb); -	 +  	vec2 dist = vec2(0.5) - abs(tc-vec2(0.5));  	float det = min(lod/(proj_lod*0.5), 1.0); @@ -153,7 +97,7 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod)  vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod)  {  	vec4 ret = texture2DLod(projectionMap, tc, lod); -	ret = correctWithGamma(ret); +	ret.rgb = srgb_to_linear(ret.rgb);  	vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -171,7 +115,7 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod)  vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod)  {  	vec4 ret = texture2DLod(projectionMap, tc, lod); -	ret = correctWithGamma(ret); +	ret.rgb = srgb_to_linear(ret.rgb);  	vec2 dist = tc-vec2(0.5); @@ -182,22 +126,15 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod)  	return ret;  } - -vec4 getPosition(vec2 pos_screen) -{ -	float depth = texture2DRect(depthMap, pos_screen.xy).r; -	vec2 sc = pos_screen.xy*2.0; -	sc /= screen_res; -	sc -= vec2(1.0,1.0); -	vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); -	vec4 pos = inv_proj * ndc; -	pos /= pos.w; -	pos.w = 1.0; -	return pos; -} +vec4 getPosition(vec2 pos_screen);  void main()   { +	vec3 col = vec3(0,0,0); + +#if defined(LOCAL_LIGHT_KILL) +    discard; +#else  	vec4 frag = vary_fragcoord;  	frag.xyz /= frag.w;  	frag.xyz = frag.xyz*0.5+0.5; @@ -206,26 +143,26 @@ void main()  	vec3 pos = getPosition(frag.xy).xyz;  	vec3 lv = trans_center.xyz-pos.xyz;  	float dist = length(lv); + +    if (dist >= size) +    { +        discard; +    }  	dist /= size; -	if (dist > 1.0) -	{ -		discard; -	} -	 +  	float shadow = 1.0;  	if (proj_shadow_idx >= 0)  	{  		vec4 shd = texture2DRect(lightMap, frag.xy); -		float sh[2]; -		sh[0] = shd.b; -		sh[1] = shd.a; -		shadow = min(sh[proj_shadow_idx]+shadow_fade, 1.0); +        shadow = (proj_shadow_idx == 0) ? shd.b : shd.a; +        shadow += shadow_fade; +		shadow = clamp(shadow, 0.0, 1.0);          	}  	vec3 norm = texture2DRect(normalMap, frag.xy).xyz;  	float envIntensity = norm.z; -	norm = decode_normal(norm.xy); +	norm = getNorm(frag.xy);  	norm = normalize(norm);  	float l_dist = -dot(lv, proj_n); @@ -252,12 +189,8 @@ void main()  	lv = normalize(lv);  	float da = dot(norm, lv); -	vec3 col = vec3(0,0,0); -		 -	vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; -		 +	vec3 diff_tex = srgb_to_linear(texture2DRect(diffuseRect, frag.xy).rgb);  	vec4 spec = texture2DRect(specularRect, frag.xy); -  	vec3 dlit = vec3(0, 0, 0);  	float noise = texture2D(noiseMap, frag.xy/128.0).b; @@ -280,23 +213,21 @@ void main()  			vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod);  			dlit = color.rgb * plcol.rgb * plcol.a; -			 +		  			col = dlit*lit*diff_tex*shadow; -			amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; + +			amb_da += (da*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance;  		}  		//float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0);  		vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); -		amb_da += (da*da*0.5+0.5)*proj_ambiance; -				 +		amb_da += (da*da*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance;  		amb_da *= dist_atten * noise; -			  		amb_da = min(amb_da, 1.0-lit); -			 -		col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; -	} +	    col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; +	}  	if (spec.a > 0.0)  	{ @@ -317,14 +248,11 @@ void main()  		if (nh > 0.0)  		{  			float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); -			col += dlit*scol*spec.rgb*shadow; -			//col += spec.rgb; +			vec3 speccol = dlit*scol*spec.rgb*shadow; +            speccol = clamp(speccol, vec3(0), vec3(1)); +			col += speccol;  		}  	}	 -	 -	 -	 -	  	if (envIntensity > 0.0)  	{ @@ -354,10 +282,12 @@ void main()  			}  		}  	} +#endif  	//not sure why, but this line prevents MATBUG-194  	col = max(col, vec3(0.0)); +	//output linear colors as gamma correction happens down stream  	frag_color.rgb = col;	  	frag_color.a = 0.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..8abdeae5ae 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl @@ -35,228 +35,26 @@ out vec4 frag_color;  //class 2, shadows, no SSAO -uniform sampler2DRect depthMap; -uniform sampler2DRect normalMap; -uniform sampler2DShadow shadowMap0; -uniform sampler2DShadow shadowMap1; -uniform sampler2DShadow shadowMap2; -uniform sampler2DShadow shadowMap3; -uniform sampler2DShadow shadowMap4; -uniform sampler2DShadow shadowMap5; - -  // Inputs -uniform mat4 shadow_matrix[6]; -uniform vec4 shadow_clip; -uniform float ssao_radius; -uniform float ssao_max_radius; -uniform float ssao_factor; -uniform float ssao_factor_inv; -  VARYING vec2 vary_fragcoord; -uniform mat4 inv_proj; -uniform vec2 screen_res; -uniform vec2 proj_shadow_res;  uniform vec3 sun_dir; - -uniform vec2 shadow_res;  uniform float shadow_bias; -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; -} - -vec4 getPosition(vec2 pos_screen) -{ -	float depth = texture2DRect(depthMap, pos_screen.xy).r; -	vec2 sc = pos_screen.xy*2.0; -	sc /= screen_res; -	sc -= vec2(1.0,1.0); -	vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); -	vec4 pos = inv_proj * ndc; -	pos /= pos.w; -	pos.w = 1.0; -	return pos; -} - -float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) -{ -	stc.xyz /= stc.w; -	stc.z += shadow_bias; - -	stc.x = floor(stc.x*shadow_res.x + fract(pos_screen.y*0.666666666))/shadow_res.x; // add some jitter to X sample pos according to Y to disguise the snapping going on here -	float cs = shadow2D(shadowMap, stc.xyz).x; -	float shadow = cs; +vec3 getNorm(vec2 pos_screen); +vec4 getPosition(vec2 pos_screen); -	shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; -	shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; -	shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; -	shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - -			 -    return shadow*0.2; -} - -float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) -{ -	stc.xyz /= stc.w; -	stc.z += spot_shadow_bias*scl; -	stc.x = floor(proj_shadow_res.x * stc.x + fract(pos_screen.y*0.666666666)) / proj_shadow_res.x; // snap - -	float cs = shadow2D(shadowMap, stc.xyz).x; -	float shadow = cs; - -	vec2 off = 1.0/proj_shadow_res; -	off.y *= 1.5; -	 -	shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x*2.0, off.y, 0.0)).x; -	shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x, -off.y, 0.0)).x; -	shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x, off.y, 0.0)).x; -	shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x*2.0, -off.y, 0.0)).x; - -        return shadow*0.2; -} +float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); +float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen);  void main()   { -	vec2 pos_screen = vary_fragcoord.xy; -	 -	//try doing an unproject here -	 -	vec4 pos = getPosition(pos_screen); -	 -	vec3 norm = texture2DRect(normalMap, pos_screen).xyz; -	norm = decode_normal(norm.xy); // unpack norm -		 -	/*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL -	{ -		frag_color = vec4(0.0); // doesn't matter -		return; -	}*/ -	 -	float shadow = 0.0; -	float dp_directional_light = max(0.0, dot(norm, sun_dir.xyz)); -	 -	vec3 shadow_pos = pos.xyz; -	vec3 offset = sun_dir.xyz * (1.0-dp_directional_light); -	 -	vec4 spos = vec4(shadow_pos+offset*shadow_offset, 1.0); -	 -	if (spos.z > -shadow_clip.w) -	{	 -		if (dp_directional_light == 0.0) -		{ -			// if we know this point is facing away from the sun then we know it's in shadow without having to do a squirrelly shadow-map lookup -			shadow = 0.0; -		} -		else -		{ -			vec4 lpos; -			 -			vec4 near_split = shadow_clip*-0.75; -			vec4 far_split = shadow_clip*-1.25; -			vec4 transition_domain = near_split-far_split; -			float weight = 0.0; - -			if (spos.z < near_split.z) -			{ -				lpos = shadow_matrix[3]*spos; -				 -				float w = 1.0; -				w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; -				shadow += pcfShadow(shadowMap3, lpos, 0.25, pos_screen)*w; -				weight += w; -				shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); -			} - -			if (spos.z < near_split.y && spos.z > far_split.z) -			{ -				lpos = shadow_matrix[2]*spos; -				 -				float w = 1.0; -				w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; -				w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; -				shadow += pcfShadow(shadowMap2, lpos, 0.5, pos_screen)*w; -				weight += w; -			} - -			if (spos.z < near_split.x && spos.z > far_split.y) -			{ -				lpos = shadow_matrix[1]*spos; - -				float w = 1.0; -				w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; -				w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; -				shadow += pcfShadow(shadowMap1, lpos, 0.75, pos_screen)*w; -				weight += w; -			} - -			if (spos.z > far_split.x) -			{ -				lpos = shadow_matrix[0]*spos; -				 -				float w = 1.0; -				w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; -				 -				shadow += pcfShadow(shadowMap0, lpos, 1.0, pos_screen)*w; -				weight += w; -			} -		 - -			shadow /= weight; - -			// take the most-shadowed value out of these two: -			//  * the blurred sun shadow in the light (shadow) map -			//  * an unblurred dot product between the sun and this norm -			// the goal is to err on the side of most-shadow to fill-in shadow holes and reduce artifacting -			shadow = min(shadow, dp_directional_light); -			 -			//lpos.xy /= lpos.w*32.0; -			//if (fract(lpos.x) < 0.1 || fract(lpos.y) < 0.1) -			//{ -			//	shadow = 0.0; -			//} -			 -		} -	} -	else -	{ -		// more distant than the shadow map covers -		shadow = 1.0; -	} -	 -	frag_color[0] = shadow; -	frag_color[1] = 1.0; -	 -	spos = vec4(shadow_pos+norm*spot_shadow_offset, 1.0); -	 -	//spotlight shadow 1 -	vec4 lpos = shadow_matrix[4]*spos; -	frag_color[2] = pcfSpotShadow(shadowMap4, lpos, 0.8, pos_screen);  -	 -	//spotlight shadow 2 -	lpos = shadow_matrix[5]*spos; -	frag_color[3] = pcfSpotShadow(shadowMap5, lpos, 0.8, pos_screen);  - -	//frag_color.rgb = pos.xyz; -	//frag_color.b = shadow; +    vec2 pos_screen = vary_fragcoord.xy; +    vec4 pos        = getPosition(pos_screen); +    vec3 norm       = getNorm(pos_screen); + +    frag_color.r = sampleDirectionalShadow(pos.xyz, norm, pos_screen); +    frag_color.g = 1.0f; +    frag_color.b = sampleSpotShadow(pos.xyz, norm, 0, pos_screen);  +    frag_color.a = sampleSpotShadow(pos.xyz, norm, 1, pos_screen);  } diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl index 5c6fe30daa..64d99bae2c 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl @@ -1,5 +1,5 @@  /**  - * @file sunLightSSAOF.glsl + * @file class2/deferred/sunLightSSAOF.glsl   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code   * Copyright (C) 2007, Linden Research, Inc. @@ -34,290 +34,24 @@ out vec4 frag_color;  //class 2 -- shadows and SSAO -uniform sampler2DRect depthMap; -uniform sampler2DRect normalMap; -uniform sampler2DShadow shadowMap0; -uniform sampler2DShadow shadowMap1; -uniform sampler2DShadow shadowMap2; -uniform sampler2DShadow shadowMap3; -uniform sampler2DShadow shadowMap4; -uniform sampler2DShadow shadowMap5; -uniform sampler2D noiseMap; - -  // Inputs -uniform mat4 shadow_matrix[6]; -uniform vec4 shadow_clip; -uniform float ssao_radius; -uniform float ssao_max_radius; -uniform float ssao_factor; -uniform float ssao_factor_inv; -  VARYING vec2 vary_fragcoord; -uniform mat4 inv_proj; -uniform vec2 screen_res; -uniform vec2 proj_shadow_res; -uniform vec3 sun_dir; - -uniform vec2 shadow_res; - -uniform float shadow_bias; -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; -} - -vec4 getPosition(vec2 pos_screen) -{ -	float depth = texture2DRect(depthMap, pos_screen.xy).r; -	vec2 sc = pos_screen.xy*2.0; -	sc /= screen_res; -	sc -= vec2(1.0,1.0); -	vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); -	vec4 pos = inv_proj * ndc; -	pos /= pos.w; -	pos.w = 1.0; -	return pos; -} - -vec2 getKern(int i) -{ -	vec2 kern[8]; -	// exponentially (^2) distant occlusion samples spread around origin -	kern[0] = vec2(-1.0, 0.0) * 0.125*0.125; -	kern[1] = vec2(1.0, 0.0) * 0.250*0.250; -	kern[2] = vec2(0.0, 1.0) * 0.375*0.375; -	kern[3] = vec2(0.0, -1.0) * 0.500*0.500; -	kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625; -	kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750; -	kern[6] = vec2(-0.7071, 0.7071) * 0.875*0.875; -	kern[7] = vec2(0.7071, -0.7071) * 1.000*1.000; -        -	return kern[i]; -} - -//calculate decreases in ambient lighting when crowded out (SSAO) -float calcAmbientOcclusion(vec4 pos, vec3 norm) -{ -	float ret = 1.0; - -	vec2 pos_screen = vary_fragcoord.xy; -	vec3 pos_world = pos.xyz; -	vec2 noise_reflect = texture2D(noiseMap, vary_fragcoord.xy/128.0).xy; -		 -	float angle_hidden = 0.0; -	float points = 0; -		 -	float scale = min(ssao_radius / -pos_world.z, ssao_max_radius); -	 -	// it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations (unrolling?) -	for (int i = 0; i < 8; i++) -	{ -		vec2 samppos_screen = pos_screen + scale * reflect(getKern(i), noise_reflect); -		vec3 samppos_world = getPosition(samppos_screen).xyz;  -		 -		vec3 diff = pos_world - samppos_world; -		float dist2 = dot(diff, diff); -			 -		// assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area -		// --> solid angle shrinking by the square of distance -		//radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2 -		//(k should vary inversely with # of samples, but this is taken care of later) -		 -		float funky_val = (dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) ? 1.0 : 0.0; -		angle_hidden = angle_hidden + funky_val * min(1.0/dist2, ssao_factor_inv); -			 -		// 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion"  -		float diffz_val = (diff.z > -1.0) ? 1.0 : 0.0; -		points = points + diffz_val; -	} -		 -	angle_hidden = min(ssao_factor*angle_hidden/points, 1.0); -	 -	float points_val = (points > 0.0) ? 1.0 : 0.0; -	ret = (1.0 - (points_val * angle_hidden)); - -	ret = max(ret, 0.0); -	return min(ret, 1.0); -} - -float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) -{ -	stc.xyz /= stc.w; -	stc.z += shadow_bias; - -	stc.x = floor(stc.x*shadow_res.x + fract(pos_screen.y*0.666666666))/shadow_res.x; -	float cs = shadow2D(shadowMap, stc.xyz).x; -	 -	float shadow = cs; -	 -	shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; -    shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; -    shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; -    shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; -	          -        return shadow*0.2; -} - -float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) -{ -	stc.xyz /= stc.w; -	stc.z += spot_shadow_bias*scl; -	stc.x = floor(proj_shadow_res.x * stc.x + fract(pos_screen.y*0.666666666)) / proj_shadow_res.x; // snap -		 -	float cs = shadow2D(shadowMap, stc.xyz).x; -	float shadow = cs; +vec4 getPosition(vec2 pos_screen); +vec3 getNorm(vec2 pos_screen); -	vec2 off = 1.0/proj_shadow_res; -	off.y *= 1.5; -	 -	shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x*2.0, off.y, 0.0)).x; -	shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x, -off.y, 0.0)).x; -	shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x, off.y, 0.0)).x; -	shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x*2.0, -off.y, 0.0)).x; - -        return shadow*0.2; -} +float sampleDirectionalShadow(vec3 shadow_pos, vec3 norm, vec2 pos_screen); +float sampleSpotShadow(vec3 shadow_pos, vec3 norm, int index, vec2 pos_screen); +float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen);  void main()   { -	vec2 pos_screen = vary_fragcoord.xy; -	 -	//try doing an unproject here -	 -	vec4 pos = getPosition(pos_screen); -	 -	vec3 norm = texture2DRect(normalMap, pos_screen).xyz; -	norm = decode_normal(norm.xy); // unpack norm -		 -	/*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL -	{ -		frag_color = vec4(0.0); // doesn't matter -		return; -	}*/ -	 -	float shadow = 0.0; -	float dp_directional_light = max(0.0, dot(norm, sun_dir.xyz)); -	 -	vec3 shadow_pos = pos.xyz; -	vec3 offset = sun_dir.xyz * (1.0-dp_directional_light); -	 -	vec4 spos = vec4(shadow_pos+offset*shadow_offset, 1.0); -	 -	if (spos.z > -shadow_clip.w) -	{	 -		if (dp_directional_light == 0.0) -		{ -			// if we know this point is facing away from the sun then we know it's in shadow without having to do a squirrelly shadow-map lookup -			shadow = 0.0; -		} -		else -		{ -			vec4 lpos; - -			vec4 near_split = shadow_clip*-0.75; -			vec4 far_split = shadow_clip*-1.25; -			vec4 transition_domain = near_split-far_split; -			float weight = 0.0; - -			if (spos.z < near_split.z) -			{ -				lpos = shadow_matrix[3]*spos; -				 -				float w = 1.0; -				w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; -				shadow += pcfShadow(shadowMap3, lpos, 0.25, pos_screen)*w; -				weight += w; -				shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); -			} - -			if (spos.z < near_split.y && spos.z > far_split.z) -			{ -				lpos = shadow_matrix[2]*spos; -				 -				float w = 1.0; -				w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; -				w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; -				shadow += pcfShadow(shadowMap2, lpos, 0.5, pos_screen)*w; -				weight += w; -			} - -			if (spos.z < near_split.x && spos.z > far_split.y) -			{ -				lpos = shadow_matrix[1]*spos; -				 -				float w = 1.0; -				w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; -				w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; -				shadow += pcfShadow(shadowMap1, lpos, 0.75, pos_screen)*w; -				weight += w; -			} - -			if (spos.z > far_split.x) -			{ -				lpos = shadow_matrix[0]*spos; -								 -				float w = 1.0; -				w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; -				 -				shadow += pcfShadow(shadowMap0, lpos, 1.0, pos_screen)*w; -				weight += w; -			} -		 - -			shadow /= weight; - -			// take the most-shadowed value out of these two: -			//  * the blurred sun shadow in the light (shadow) map -			//  * an unblurred dot product between the sun and this norm -			// the goal is to err on the side of most-shadow to fill-in shadow holes and reduce artifacting -			shadow = min(shadow, dp_directional_light); -			 -			//lpos.xy /= lpos.w*32.0; -			//if (fract(lpos.x) < 0.1 || fract(lpos.y) < 0.1) -			//{ -			//	shadow = 0.0; -			//} -			 -		} -	} -	else -	{ -		// more distant than the shadow map covers -		shadow = 1.0; -	} -	 -	frag_color[0] = shadow; -	frag_color[1] = calcAmbientOcclusion(pos, norm); -	 -	spos = vec4(shadow_pos+norm*spot_shadow_offset, 1.0); -	 -	//spotlight shadow 1 -	vec4 lpos = shadow_matrix[4]*spos; -	frag_color[2] = pcfSpotShadow(shadowMap4, lpos, 0.8, pos_screen); -	 -	//spotlight shadow 2 -	lpos = shadow_matrix[5]*spos; -	frag_color[3] = pcfSpotShadow(shadowMap5, lpos, 0.8, pos_screen); +    vec2 pos_screen = vary_fragcoord.xy; +    vec4 pos  = getPosition(pos_screen); +    vec3 norm = getNorm(pos_screen); -	//frag_color.rgb = pos.xyz; -	//frag_color.b = shadow; +    frag_color.r = sampleDirectionalShadow(pos.xyz, norm, pos_screen); +    frag_color.g = calcAmbientOcclusion(pos, norm, pos_screen); +    frag_color.b = sampleSpotShadow(pos.xyz, norm, 0, pos_screen); +    frag_color.a = sampleSpotShadow(pos.xyz, norm, 1, pos_screen);  } diff --git a/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl b/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl index 3acf9fe883..89d9d1bde3 100644 --- a/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl @@ -1,5 +1,5 @@  /** - * @file sumLightsV.glsl + * @file class2\lighting\sumLightsSpecularV.glsl   *   * $LicenseInfo:firstyear=2005&license=viewerlgpl$   * Second Life Viewer Source Code @@ -28,16 +28,16 @@  float calcDirectionalLightSpecular(inout vec4 specular, vec3 view, vec3 n, vec3 l, vec3 lightCol, float da);  vec3 calcPointLightSpecular(inout vec4 specular, vec3 view, vec3 v, vec3 n, vec3 l, float r, float pw, vec3 lightCol); -vec3 atmosAmbient(vec3 light); +vec3 atmosAmbient();  vec3 atmosAffectDirectionalLight(float lightIntensity);  vec3 atmosGetDiffuseSunlightColor();  vec3 scaleDownLight(vec3 light);  uniform vec4 light_position[8]; -uniform vec3 light_attenuation[8];  +uniform vec4 light_attenuation[8];   uniform vec3 light_diffuse[8]; -vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol) +vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor)  {  	vec4 col = vec4(0.0, 0.0, 0.0, color.a); @@ -53,8 +53,8 @@ vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor  	col.rgb = scaleDownLight(col.rgb);  	// Add windlight lights -	col.rgb += atmosAmbient(baseCol.rgb); -	col.rgb += atmosAffectDirectionalLight(calcDirectionalLightSpecular(specularSum, view, norm, light_position[0].xyz,atmosGetDiffuseSunlightColor()*baseCol.a, 1.0)); +	col.rgb += atmosAmbient(); +	col.rgb += atmosAffectDirectionalLight(calcDirectionalLightSpecular(specularSum, view, norm, light_position[0].xyz, atmosGetDiffuseSunlightColor(), 1.0));  	col.rgb = min(col.rgb*color.rgb, 1.0);  	specularColor.rgb = min(specularColor.rgb*specularSum.rgb, 1.0); diff --git a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl index c9987ef3b9..30ca88afd2 100644 --- a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl @@ -1,5 +1,5 @@  /** - * @file sumLightsV.glsl + * @file class2\lighting\sumLightsV.glsl   *   * $LicenseInfo:firstyear=2005&license=viewerlgpl$   * Second Life Viewer Source Code @@ -24,9 +24,8 @@   */  float calcDirectionalLight(vec3 n, vec3 l); -float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float is_pointlight); +float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight); -vec3 atmosAmbient(vec3 light);  vec3 atmosAffectDirectionalLight(float lightIntensity);  vec3 scaleDownLight(vec3 light); @@ -35,24 +34,27 @@ uniform vec3 light_direction[8];  uniform vec3 light_attenuation[8];   uniform vec3 light_diffuse[8]; -vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) +vec4 sumLights(vec3 pos, vec3 norm, vec4 color)  {  	vec4 col = vec4(0.0, 0.0, 0.0, color.a);  	// Collect normal lights (need to be divided by two, as we later multiply by 2)  	col.rgb += light_diffuse[1].rgb * calcDirectionalLight(norm, light_position[1].xyz); - -	col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].z); -	col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].z); - +	col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].y, light_attenuation[2].z); +	col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].y, light_attenuation[3].z);  	col.rgb = scaleDownLight(col.rgb); +#if defined(LOCAL_LIGHT_KILL) +    col.rgb = vec3(0); +i#endif +  	// Add windlight lights -	col.rgb += atmosAmbient(baseLight.rgb);  	col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); -				 + +#if !defined(SUNLIGHT_KILL)  	col.rgb = min(col.rgb*color.rgb, 1.0); -	 +#endif +  	return col;	  } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index fea3cbf69b..ee9c990b12 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -1,5 +1,5 @@  /**  - * @file atmosphericsF.glsl + * @file class2\wl\atmosphericsF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -22,23 +22,25 @@   * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA   * $/LicenseInfo$   */ -  - - -////////////////////////////////////////////////////////// -// The fragment shader for the terrain atmospherics -//////////////////////////////////////////////////////////  vec3 getAdditiveColor();  vec3 getAtmosAttenuation(); +vec3 scaleSoftClipFrag(vec3 light); -uniform sampler2D cloudMap; -uniform vec4 cloud_pos_density1; +uniform int no_atmo; -vec3 atmosLighting(vec3 light) +vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten)  { -	light *= getAtmosAttenuation().r; -	light += getAdditiveColor(); -	return (2.0 * light); +    if (no_atmo == 1) +    { +        return light; +    } +    light *= atten.r; +    light += additive; +    return light * 2.0;  } +vec3 atmosLighting(vec3 light) +{ +    return atmosFragLighting(light, getAdditiveColor(), getAtmosAttenuation()); +} 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..5788871744 --- /dev/null +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl @@ -0,0 +1,46 @@ +/** + * @file class2\wl\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; +uniform int no_atmo; + +vec3 atmosFragAmbient(vec3 light, vec3 amblit) +{ +    if (no_atmo == 1) return light; +    return amblit + light / 2.0; +} + +vec3 atmosFragAffectDirectionalLight(float lightIntensity, vec3 sunlit) +{ +    return sunlit * lightIntensity; +} + +vec3 scaleDownLightFrag(vec3 light) +{ +    return (light / scene_light_strength ); +} + diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl index 62a034ce05..9c42b84eca 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl @@ -1,5 +1,5 @@  /** - * @file atmosphericsHelpersV.glsl + * @file class2\wl\atmosphericsHelpersV.glsl   *   * $LicenseInfo:firstyear=2005&license=viewerlgpl$   * Second Life Viewer Source Code @@ -33,29 +33,31 @@ vec3 getAtmosAttenuation();  vec3 getPositionEye();  uniform float scene_light_strength; +uniform int no_atmo; -vec3 atmosAmbient(vec3 light) +vec3 atmosAmbient()  { -	return getAmblitColor() + light / 2.0; +    if (no_atmo == 1) return vec3(0.16); +    return getAmblitColor();  }  vec3 atmosAffectDirectionalLight(float lightIntensity)  { -	return getSunlitColor() * lightIntensity; +    return getSunlitColor() * lightIntensity;  }  vec3 atmosGetDiffuseSunlightColor()  { -	return getSunlitColor(); +    return getSunlitColor();  }  vec3 scaleDownLight(vec3 light)  { -	return (light / scene_light_strength ); +    return (light / scene_light_strength );  }  vec3 scaleUpLight(vec3 light)  { -	return (light * scene_light_strength); +    return (light * scene_light_strength);  } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl index d174805cc0..a4bd0d566b 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl @@ -1,5 +1,5 @@  /** - * @file atmosphericsV.glsl + * @file class2\wl\atmosphericsV.glsl   *   * $LicenseInfo:firstyear=2005&license=viewerlgpl$   * Second Life Viewer Source Code @@ -22,8 +22,6 @@   * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA   * $/LicenseInfo$   */ -  -  // VARYING param funcs  void setSunlitColor(vec3 v); @@ -34,124 +32,20 @@ void setPositionEye(vec3 v);  vec3 getAdditiveColor(); -//VARYING vec4 vary_CloudUVs; -//VARYING float vary_CloudDensity; - -// Inputs -uniform vec4 morphFactor; -uniform vec3 camPosLocal; -//uniform vec4 camPosWorld; - -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 calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao);  void calcAtmospherics(vec3 inPositionEye) { -	vec3 P = inPositionEye; -	setPositionEye(P); -	 -	//(TERRAIN) limit altitude -	if (P.y > max_y) P *= (max_y / P.y); -	if (P.y < -max_y) P *= (-max_y / P.y); - -	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); -	//vary_AtmosAttenuation = distance_multiplier / 10000.; -	//vary_AtmosAttenuation = density_multiplier * 100.; -	//vary_AtmosAttenuation = vec4(Plen / 100000., 0., 0., 1.); - -	//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; - -	//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)); - -	// vary_SunlitColor = vec3(0); -	// vary_AmblitColor = vec3(0); -	// vary_AdditiveColor = vec4(Pn, 1.0); - -	/* -	const float cloudShadowScale = 100.; -	// Get cloud uvs for shadowing -	vec3 cloudPos = inPositionEye + camPosWorld - cloudShadowScale / 2.; -	vary_CloudUVs.xy = cloudPos.xz / cloudShadowScale; - -	// We can take uv1 and multiply it by (TerrainSpan / CloudSpan) -//	cloudUVs *= (((worldMaxZ - worldMinZ) * 20) /40000.); -	vary_CloudUVs *= (10000./40000.); - -	// Offset by sun vector * (CloudAltitude / CloudSpan) -	vary_CloudUVs.x += tmpLightnorm.x / tmpLightnorm.y * (3000./40000.); -	vary_CloudUVs.y += tmpLightnorm.z / tmpLightnorm.y * (3000./40000.); -	*/ +    vec3 P = inPositionEye; +    setPositionEye(P); +    vec3 tmpsunlit = vec3(1); +    vec3 tmpamblit = vec3(1); +    vec3 tmpaddlit = vec3(1); +    vec3 tmpattenlit = vec3(1); +    calcAtmosphericVars(inPositionEye, vec3(0), 1, tmpsunlit, tmpamblit, tmpaddlit, tmpattenlit, false); +    setSunlitColor(tmpsunlit); +    setAmblitColor(tmpamblit); +    setAdditiveColor(tmpaddlit); +    setAtmosAttenuation(tmpattenlit);  } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl index 765b0927c3..ea37610502 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl @@ -1,5 +1,5 @@  /**  - * @file atmosphericVars.glsl + * @file class2\wl\atmosphericVars.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -32,14 +32,17 @@ vec3 getSunlitColor()  {  	return vec3(0,0,0);  } +  vec3 getAmblitColor()  {  	return vec3(0,0,0);  } +  vec3 getAdditiveColor()  {  	return vary_AdditiveColor;  } +  vec3 getAtmosAttenuation()  {  	return vec3(vary_AtmosAttenuation); diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl index 99dbee15ee..31109aed31 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl @@ -1,5 +1,5 @@  /**  - * @file atmosphericVars.glsl + * @file class2\wl\atmosphericVars.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterF.glsl index 163ef26444..22e16b7e0f 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterF.glsl @@ -1,5 +1,5 @@  /**  - * @file atmosphericVarsWaterF.glsl + * @file class2\wl\atmosphericVarsWaterF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterV.glsl index 553f6752e6..0f2a3ee527 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterV.glsl @@ -1,5 +1,5 @@  /**  - * @file atmosphericVarsWaterV.glsl + * @file class2\wl\atmosphericVarsWaterV.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl index 96c70651b1..75bf8730df 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl @@ -1,5 +1,5 @@  /**  - * @file WLCloudsF.glsl + * @file class2\wl\cloudsF.glsl   *   * $LicenseInfo:firstyear=2005&license=viewerlgpl$   * Second Life Viewer Source Code @@ -22,11 +22,13 @@   * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA   * $/LicenseInfo$   */ -  + +/*[EXTRA_CODE_HERE]*/  +  #ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; +out vec4 frag_data[3];  #else -#define frag_color gl_FragColor +#define frag_data gl_FragData  #endif  ///////////////////////////////////////////////////////////////////////// @@ -36,69 +38,96 @@ out vec4 frag_color;  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; +uniform float cloud_scale; +uniform float cloud_variance; + +VARYING vec2 vary_texcoord0; +VARYING vec2 vary_texcoord1; +VARYING vec2 vary_texcoord2; +VARYING vec2 vary_texcoord3; +VARYING float altitude_blend_factor;  /// 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); +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 -	vec2 uv1 = vary_texcoord0.xy; -	vec2 uv2 = vary_texcoord1.xy; +    // 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; + +    if (cloud_scale < 0.001) +    { +        discard; +    } + +    vec2 disturbance  = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); +    vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + +    // Offset texture coords +    uv1 += cloud_pos_density1.xy + (disturbance * 0.2);    //large texture, visible density +    uv2 += cloud_pos_density1.xy;   //large texture, self shadow +    uv3 += cloud_pos_density2.xy;   //small texture, visible density +    uv4 += cloud_pos_density2.xy;   //small texture, self shadow + +    float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y) * 4.0); -	vec4 cloudColorSun = vary_CloudColorSun; -	vec4 cloudColorAmbient = vary_CloudColorAmbient; -	float cloudDensity = vary_CloudDensity; -	vec2 uv3 = vary_texcoord2.xy; -	vec2 uv4 = vary_texcoord3.xy; +    cloudDensity *= 1.0 - (density_variance * density_variance); -	// 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.); -	// 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; -	alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10. * cloud_pos_density1.z, 1.); +    // And smooth +    alpha1 = 1. - alpha1 * alpha1; +    alpha1 = 1. - alpha1 * alpha1;   -	// And smooth -	alpha1 = 1. - alpha1 * alpha1; -	alpha1 = 1. - alpha1 * alpha1;	 +    alpha1 *= altitude_blend_factor; +    //if (alpha1 < 0.001f) +    //{ +    //    discard; +    //} -	// 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); -	alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); +    // 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;	 +    // And smooth +    alpha2 = 1. - alpha2; +    alpha2 = 1. - alpha2 * alpha2;   -	// Combine -	vec4 color; -	color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); -	color *= 2.; +    // Combine +    vec4 color; +    color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); +    color.rgb *= 2.; +    color.rgb = scaleSoftClip(color.rgb); -	/// Gamma correct for WL (soft clip effect). -	frag_color.rgb = scaleSoftClip(color.rgb); -	frag_color.a = alpha1; +    /// Gamma correct for WL (soft clip effect). +    frag_data[0] = vec4(color.rgb, alpha1); +    frag_data[1] = vec4(0.0,0.0,0.0,0.0); +    frag_data[2] = vec4(0,0,0,1);  } diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl index c1dd45cd67..2c1475d547 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl @@ -1,5 +1,5 @@  /**  - * @file WLCloudsV.glsl + * @file class2\wl\cloudsV.glsl   *   * $LicenseInfo:firstyear=2005&license=viewerlgpl$   * Second Life Viewer Source Code @@ -40,13 +40,16 @@ VARYING vec2 vary_texcoord0;  VARYING vec2 vary_texcoord1;  VARYING vec2 vary_texcoord2;  VARYING vec2 vary_texcoord3; +VARYING float altitude_blend_factor;  // Inputs  uniform vec3 camPosLocal;  uniform vec4 lightnorm;  uniform vec4 sunlight_color; -uniform vec4 ambient; +uniform vec4 moonlight_color; +uniform int sun_up_factor; +uniform vec4 ambient_color;  uniform vec4 blue_horizon;  uniform vec4 blue_density;  uniform float haze_horizon; @@ -57,6 +60,7 @@ uniform float density_multiplier;  uniform float max_y;  uniform vec4 glow; +uniform float sun_moon_glow_factor;  uniform vec4 cloud_color; @@ -73,6 +77,9 @@ void main()  	// Get relative position  	vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); +    // fade clouds beyond a certain point so the bottom of the sky dome doesn't look silly at high altitude +    altitude_blend_factor = clamp((P.y + 512.0) / max_y, 0.0, 1.0); +  	// Set altitude  	if (P.y > 0.)  	{ @@ -92,16 +99,18 @@ void main()  	vec4 temp2 = vec4(0.);  	vec4 blue_weight;  	vec4 haze_weight; +	//vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color;  	vec4 sunlight = sunlight_color;  	vec4 light_atten; +    float dens_mul = density_multiplier;  	// Sunlight attenuation effect (hue and brightness) due to atmosphere  	// this is used later for sunlight modulation at various altitudes -	light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); +	light_atten = (blue_density + vec4(haze_density * 0.25)) * (dens_mul * max_y);  	// Calculate relative weights -	temp1 = blue_density + haze_density; +	temp1 = abs(blue_density) + vec4(abs(haze_density));  	blue_weight = blue_density / temp1;  	haze_weight = haze_density / temp1; @@ -111,7 +120,7 @@ void main()  	sunlight *= exp( - light_atten * temp2.y);  	// Distance -	temp2.z = Plen * density_multiplier; +	temp2.z = Plen * dens_mul;  	// Transparency (-> temp1)  	// ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati @@ -130,11 +139,13 @@ void main()  	temp2.x = pow(temp2.x, glow.z);  		// glow.z should be negative, so we're doing a sort of (1 / "angle") function +    temp2.x *= sun_moon_glow_factor; +  	// Add "minimum anti-solar illumination"  	temp2.x += .25;  	// Increase ambient when there are more clouds -	vec4 tmpAmbient = ambient; +	vec4 tmpAmbient = ambient_color;  	tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5;   	// Dim sunlight by cloud shadow percentage @@ -146,8 +157,6 @@ void main()  			 );	  	// CLOUDS - -	sunlight = sunlight_color;  	temp2.y = max(0., lightnorm.y * 2.);  	temp2.y = 1. / temp2.y;  	sunlight *= exp( - light_atten * temp2.y); diff --git a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl index 478373d729..68db7fcbb1 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl @@ -1,5 +1,5 @@  /**  - * @file gammaF.glsl + * @file class2\wl\gammaF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -22,23 +22,37 @@   * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA   * $/LicenseInfo$   */ -  - - -uniform vec4 gamma; +uniform float gamma; +uniform int no_atmo;  vec3 getAtmosAttenuation(); +vec3 getAdditiveColor(); -/// 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); +vec3 scaleSoftClipFrag(vec3 light) +{ +    if (no_atmo == 1) +    { +        return light; +    } +    //soft clip effect: +    light = 1. - clamp(light, vec3(0.), vec3(1.)); +    light = 1. - pow(light, vec3(gamma)); // s/b inverted already CPU-side +    return light; +} + +vec3 scaleSoftClip(vec3 light) +{ +    return scaleSoftClipFrag(light); +} -	return light; +vec3 fullbrightScaleSoftClipFrag(vec3 light, vec3 add, vec3 atten) +{ +    //return mix(scaleSoftClipFrag(light.rgb), add, atten); +    return scaleSoftClipFrag(light.rgb);  } -vec3 fullbrightScaleSoftClip(vec3 light) { -	return mix(scaleSoftClip(light.rgb), light.rgb, getAtmosAttenuation()); +vec3 fullbrightScaleSoftClip(vec3 light) +{ +    return fullbrightScaleSoftClipFrag(light, getAdditiveColor(), 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..7146349453 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,17 +35,8 @@ out vec4 frag_color;  VARYING vec4 vary_HazeColor; -uniform sampler2D cloud_noise_texture; -uniform vec4 gamma; -  /// 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; -} +vec3 scaleSoftClip(vec3 light);  void main()  { @@ -56,8 +47,7 @@ void main()  	vec4 color;  	color = vary_HazeColor; -	color *= 2.; - +	color.rgb *= 2.;  	/// Gamma correct for WL (soft clip effect).  	frag_color.rgb = scaleSoftClip(color.rgb);  	frag_color.a = 1.0; diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl index 3788ddaf2d..0d141342ce 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl @@ -1,5 +1,5 @@  /**  - * @file WLSkyV.glsl + * @file class2\wl\skyV.glsl   *   * $LicenseInfo:firstyear=2005&license=viewerlgpl$   * Second Life Viewer Source Code @@ -39,7 +39,9 @@ uniform vec3 camPosLocal;  uniform vec4 lightnorm;  uniform vec4 sunlight_color; -uniform vec4 ambient; +uniform vec4 moonlight_color; +uniform int sun_up_factor; +uniform vec4 ambient_color;  uniform vec4 blue_horizon;  uniform vec4 blue_density;  uniform float haze_horizon; @@ -47,9 +49,11 @@ 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 sun_moon_glow_factor;  uniform vec4 cloud_color; @@ -57,11 +61,12 @@ void main()  {  	// World / view / projection -	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); +    vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); +	gl_Position = pos; +	  	// Get relative position  	vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); -	//vec3 P = position.xyz + vec3(0,50,0);  	// Set altitude  	if (P.y > 0.) @@ -75,38 +80,40 @@ void main()  	// Can normalize then  	vec3 Pn = normalize(P); -	float  Plen = length(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 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color;  	vec4 light_atten; +    float dens_mul = density_multiplier; +  	// Sunlight attenuation effect (hue and brightness) due to atmosphere  	// this is used later for sunlight modulation at various altitudes -	light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); +	light_atten = (blue_density + vec4(haze_density * 0.25)) * (dens_mul * max_y);  	// Calculate relative weights -	temp1 = blue_density + haze_density; +	temp1 = abs(blue_density) + vec4(abs(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); +    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; +	temp2.z = Plen * dens_mul;  	// Transparency (-> temp1) -	// ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati -	// compiler gets confused. -	temp1 = exp(-temp1 * temp2.z); - +    // 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); @@ -122,35 +129,33 @@ void main()  	// Add "minimum anti-solar illumination"  	temp2.x += .25; +    vec4 color = (    blue_horizon * blue_weight * (sunlight + ambient_color) +                + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient_color) +             ); -	// Haze color above cloud -	vary_HazeColor = (	  blue_horizon * blue_weight * (sunlight + ambient) -				+ (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient) -			 );	 +    // Final atmosphere additive +    color *= (1. - temp1);  	// Increase ambient when there are more clouds -	vec4 tmpAmbient = ambient; -	tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5;  +	vec4 tmpAmbient = ambient_color; +	tmpAmbient += max(vec4(0), (1. - ambient_color)) * cloud_shadow * 0.5;   	// Dim sunlight by cloud shadow percentage -	sunlight *= (1. - cloud_shadow); +	sunlight *= max(0.0, (1. - cloud_shadow));  	// Haze color below cloud  	vec4 additiveColorBelowCloud = (	  blue_horizon * blue_weight * (sunlight + tmpAmbient)  				+ (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient)  			 );	 -	// Final atmosphere additive -	vary_HazeColor *= (1. - temp1); -	  	// Attenuate cloud color by atmosphere  	temp1 = sqrt(temp1);	//less atmos opacity (more transparency) below clouds  	// At horizon, blend high altitude sky color towards the darker color below the clouds -	vary_HazeColor += (additiveColorBelowCloud - vary_HazeColor) * (1. - sqrt(temp1)); -	 -	// won't compile on mac without this being set -	//vary_AtmosAttenuation = vec3(0.0,0.0,0.0); +	color += (additiveColorBelowCloud - color) * (1. - sqrt(temp1)); + +    // Haze color above cloud +	vary_HazeColor = color;	  } diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index 8a8e4cb0f6..f69d36f715 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -1,5 +1,5 @@  /**  - * @file transportF.glsl + * @file class2\wl\transportF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -30,24 +30,38 @@  vec3 getAdditiveColor();  vec3 getAtmosAttenuation(); -uniform sampler2D cloudMap; -uniform vec4 cloud_pos_density1; +uniform int no_atmo; -vec3 atmosTransport(vec3 light) { -	light *= getAtmosAttenuation().r; -	light += getAdditiveColor() * 2.0; -	return light; +vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) +{ +    if (no_atmo == 1) +    { +        return light * 2.0; +    } +    // fullbright responds minimally to atmos scatter effects  +    light *= min(15.0 * atten.r, 1.0); +    light += (0.1 * additive); +    return light * 2.0;  } -vec3 fullbrightAtmosTransport(vec3 light) { -	float brightness = dot(light.rgb, vec3(0.33333)); - -	return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); +vec3 atmosTransport(vec3 light) +{ +     return atmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation());  } -vec3 fullbrightShinyAtmosTransport(vec3 light) { -	float brightness = dot(light.rgb, vec3(0.33333)); +vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) +{ +    float brightness = dot(light.rgb * 0.5, vec3(0.3333)) + 0.1; +    return atmosTransportFrag(light * 0.5, additive * brightness, atten); +} -	return mix(atmosTransport(light.rgb), (light.rgb + getAdditiveColor().rgb) * (2.0 - brightness), brightness * brightness); +vec3 fullbrightAtmosTransport(vec3 light) +{ +    return fullbrightAtmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation());  } +vec3 fullbrightShinyAtmosTransport(vec3 light) +{ +    float brightness = dot(light.rgb * 0.5, vec3(0.33333)) + 0.1; +    return atmosTransportFrag(light * 0.5, getAdditiveColor() * (brightness * brightness), getAtmosAttenuation()); +} diff --git a/indra/newview/app_settings/shaders/class3/avatar/avatarV.glsl b/indra/newview/app_settings/shaders/class3/avatar/avatarV.glsl index 721054b5ad..df9704ec25 100644 --- a/indra/newview/app_settings/shaders/class3/avatar/avatarV.glsl +++ b/indra/newview/app_settings/shaders/class3/avatar/avatarV.glsl @@ -33,7 +33,7 @@ ATTRIBUTE vec4 clothing;  VARYING vec4 vertex_color;  VARYING vec2 vary_texcoord0; -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color);  mat4 getSkinnedTransform();  void calcAtmospherics(vec3 inPositionEye); @@ -127,7 +127,7 @@ void main()  	calcAtmospherics(pos.xyz); -	vec4 col = calcLighting(pos.xyz, norm, color, vec4(0.0));			 +	vec4 col = calcLighting(pos.xyz, norm, color);			  	vertex_color = col;   	gl_Position = projection_matrix * pos; diff --git a/indra/newview/app_settings/shaders/class3/deferred/attachmentShadowF.glsl b/indra/newview/app_settings/shaders/class3/deferred/attachmentShadowF.glsl new file mode 100644 index 0000000000..d973326f93 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/attachmentShadowF.glsl @@ -0,0 +1,44 @@ +/**  + * @file avatarShadowF.glsl + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + *  + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + *  + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * Lesser General Public License for more details. + *  + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA + *  + * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA + * $/LicenseInfo$ + */ + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2D diffuseMap; + +VARYING vec4 pos; +VARYING vec2 vary_texcoord0; + +vec4 computeMoments(float depth, float a); + +void main()  +{ +    frag_color = computeMoments(length(pos), 1.0); +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/attachmentShadowV.glsl b/indra/newview/app_settings/shaders/class3/deferred/attachmentShadowV.glsl new file mode 100644 index 0000000000..1a655e6467 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/attachmentShadowV.glsl @@ -0,0 +1,49 @@ +/**  + * @file attachmentShadowV.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 projection_matrix; +uniform mat4 modelview_matrix; +uniform mat4 texture_matrix0; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec2 texcoord0; + +mat4 getObjectSkinnedTransform(); + +VARYING vec4 pos; + +void main() +{ +	//transform vertex +	mat4 mat = getObjectSkinnedTransform(); +	 +	mat = modelview_matrix * mat; +	pos = (mat*vec4(position.xyz, 1.0)); +	pos = projection_matrix * vec4(pos.xyz, 1.0); + +#if !defined(DEPTH_CLAMP) +	pos.z = max(pos.z, -pos.w+0.01); +#endif +	gl_Position = pos; +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl b/indra/newview/app_settings/shaders/class3/deferred/avatarShadowF.glsl index 587f3d5a94..48eefc7a73 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/avatarShadowF.glsl @@ -1,5 +1,5 @@  /**  - * @file srgb.glsl + * @file avatarShadowF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -23,24 +23,30 @@   * $/LicenseInfo$   */ -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)); +/*[EXTRA_CODE_HERE]*/  -	bvec3 lte = lessThanEqual(cs,vec3(0.04045)); -	return mix(high_range, low_range, lte); +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif -} +uniform sampler2D diffuseMap; -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; +#if !defined(DEPTH_CLAMP) +VARYING vec4 post_pos; +#endif -	bvec3 lt = lessThan(cl,vec3(0.0031308)); -	return mix(high_range, low_range, lt); +VARYING vec4 pos; + +vec4 computeMoments(float depth, float a); + +void main()  +{ +    frag_color = computeMoments(length(pos), 1.0); +#if !defined(DEPTH_CLAMP) +	gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0); +#endif  } diff --git a/indra/newview/app_settings/shaders/class3/deferred/avatarShadowV.glsl b/indra/newview/app_settings/shaders/class3/deferred/avatarShadowV.glsl new file mode 100644 index 0000000000..164b355f20 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/avatarShadowV.glsl @@ -0,0 +1,68 @@ +/**  + * @file avatarShadowV.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 projection_matrix; + +mat4 getSkinnedTransform(); + +ATTRIBUTE vec3 position; +ATTRIBUTE vec3 normal; +ATTRIBUTE vec2 texcoord0; + +#if !defined(DEPTH_CLAMP) +VARYING vec4 post_pos; +#endif + +VARYING vec4 pos; + +void main() +{ +	vec3 norm; +	 +	vec4 pos_in = vec4(position.xyz, 1.0); +	mat4 trans = getSkinnedTransform(); + +	pos.x = dot(trans[0], pos_in); +	pos.y = dot(trans[1], pos_in); +	pos.z = dot(trans[2], pos_in); +	pos.w = 1.0; +	 +	norm.x = dot(trans[0].xyz, normal); +	norm.y = dot(trans[1].xyz, normal); +	norm.z = dot(trans[2].xyz, normal); +	norm = normalize(norm); +	 +	pos = projection_matrix * pos; + +#if !defined(DEPTH_CLAMP) +	post_pos = pos; +	gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); +#else +	gl_Position = pos; +#endif + +} + + diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl new file mode 100644 index 0000000000..32210f60dc --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl @@ -0,0 +1,119 @@ +/**  + * @file class3/deferred/cloudsF.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 + +uniform sampler2D diffuseMap; + +VARYING vec4 pos; +VARYING float target_pos_x; +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 cloud_color; +uniform float cloud_shadow; +uniform float cloud_scale; +uniform float cloud_variance; +uniform vec3 camPosLocal; +uniform vec3 sun_dir; +uniform float sun_size; +uniform float far_z; + +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 normalize(cloud_noise_sample); +} + +vec4 computeMoments(float depth, float alpha); + +void main() +{ +    if (cloud_scale >= 0.001) +    { +        // Set variables +        vec2 uv1 = vary_texcoord0.xy; +        vec2 uv2 = vary_texcoord1.xy; +        vec2 uv3 = vary_texcoord2.xy; +        float cloudDensity = 2.0 * (cloud_shadow - 0.25); +     +        vec2 uv4 = vary_texcoord3.xy; +     +        vec2 disturbance  = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); +        vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); +     +        // Offset texture coords +        uv1 += cloud_pos_density1.xy + (disturbance * 0.2);    //large texture, visible density +        uv2 += cloud_pos_density1.xy;   //large texture, self shadow +        uv3 += cloud_pos_density2.xy;   //small texture, visible density +        uv4 += cloud_pos_density2.xy;   //small texture, self shadow +     +        float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y) * 4.0); +     +        cloudDensity *= 1.0 - (density_variance * density_variance); +     +        // 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;   +     +        if (alpha1 < 0.001f) +        { +            discard; +        } +     +        // 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;   +     +        frag_color = computeMoments(length(pos), alpha1); +    } +    else +    { +        frag_color = vec4(0); +    } +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudShadowV.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudShadowV.glsl new file mode 100644 index 0000000000..effb070f93 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudShadowV.glsl @@ -0,0 +1,63 @@ +/**  + * @file cloudShadowV.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 !defined(DEPTH_CLAMP) +VARYING float pos_zd2; +#endif + +VARYING vec4 pos; +VARYING float target_pos_x; +VARYING vec2 vary_texcoord0; +VARYING vec4 vertex_color; + +void passTextureIndex(); + +void main() +{ +	//transform vertex +	vec4 pre_pos = vec4(position.xyz, 1.0); +	pos = modelview_projection_matrix * pre_pos; +	target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; + +#if !defined(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/class3/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl new file mode 100644 index 0000000000..e40d7e7c75 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl @@ -0,0 +1,166 @@ +/**  + * @file class3/deferred/cloudsF.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_data[3]; +#else +#define frag_data gl_FragData +#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; +VARYING vec3 vary_pos; + +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 cloud_color; +uniform float cloud_shadow; +uniform float cloud_scale; +uniform float cloud_variance; +uniform vec3 camPosLocal; +uniform vec3 sun_dir; +uniform float sun_size; +uniform float far_z; + +uniform sampler2D transmittance_texture; +uniform sampler3D scattering_texture; +uniform sampler3D single_mie_scattering_texture; +uniform sampler2D irradiance_texture; +uniform sampler2D sh_input_r; +uniform sampler2D sh_input_g; +uniform sampler2D sh_input_b; + +vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 dir, out vec3 transmittance); + +/// Soft clips the light with a gamma correction +vec3 scaleSoftClip(vec3 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 +    vec2 uv1 = vary_texcoord0.xy; +    vec2 uv2 = vary_texcoord1.xy; +    vec2 uv3 = vary_texcoord2.xy; +    float cloudDensity = 2.0 * (cloud_shadow - 0.25); + +    if (cloud_scale < 0.001) +    { +        discard; +    } + +    vec2 uv4 = vary_texcoord3.xy; + +    vec2 disturbance = vec2(cloudNoise(uv1 / 16.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + +    // Offset texture coords +    uv1 += cloud_pos_density1.xy + (disturbance * 0.2); //large texture, visible density +    uv2 += cloud_pos_density1.xy;   //large texture, self shadow +    uv3 += cloud_pos_density2.xy; //small texture, visible density +    uv4 += cloud_pos_density2.xy;   //small texture, self shadow + +    float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0) * 4.0); + +    cloudDensity *= 1.0 - (density_variance * density_variance); + +    // 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;   + +    if (alpha1 < 0.001f) +    { +        discard; +    } + +    // 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;   + +    vec3 view_ray = vary_pos.xyz + camPosLocal; + +    vec3 view_direction = normalize(view_ray); +    vec3 sun_direction  = normalize(sun_dir); +    vec3 earth_center   = vec3(0, 0, -6360.0f); +    vec3 camPos = (camPosLocal / 1000.0f) - earth_center; + +    vec3 transmittance; +    vec3 radiance_sun  = GetSkyLuminance(camPos, view_direction, 1.0 - alpha1, sun_direction, transmittance); + +    vec3 sun_color = vec3(1.0) - exp(-radiance_sun * 0.0001); + +    // Combine +    vec4 color; + +    vec4 l1tap = vec4(1.0/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265)); + +    vec4 l1r = texture2D(sh_input_r, vec2(0,0)); +    vec4 l1g = texture2D(sh_input_g, vec2(0,0)); +    vec4 l1b = texture2D(sh_input_b, vec2(0,0)); + +    vec3 sun_indir = vec3(-view_direction.xy, view_direction.z); +    vec3 amb = vec3(dot(l1r, l1tap * vec4(1, sun_indir)), +                    dot(l1g, l1tap * vec4(1, sun_indir)), +                    dot(l1b, l1tap * vec4(1, sun_indir))); + + +    amb = max(vec3(0), amb); + +    color.rgb = sun_color * cloud_color.rgb * (1. - alpha2); +    color.rgb = pow(color.rgb, vec3(1.0 / 2.2)); +    color.rgb += amb; + +    frag_data[0] = vec4(color.rgb, alpha1); +    frag_data[1] = vec4(0); +    frag_data[2] = vec4(0,1,0,1); +} + 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..71e422ddf0 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl @@ -0,0 +1,70 @@ +/**  + * @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; +uniform mat4 modelview_matrix; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec2 texcoord0; + +////////////////////////////////////////////////////////////////////////// +// The vertex shader for creating the atmospheric sky +/////////////////////////////////////////////////////////////////////////////// + +// Output parameters +VARYING vec2 vary_texcoord0; +VARYING vec2 vary_texcoord1; +VARYING vec2 vary_texcoord2; +VARYING vec2 vary_texcoord3; +VARYING vec3 vary_pos; + +// Inputs +uniform float cloud_scale; +uniform vec4  lightnorm; +uniform vec3  camPosLocal; + +void main() +{ +    vary_pos = position; + +    // World / view / projection +    gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + +    // Texture coords +    vary_texcoord0 = texcoord0; +    vary_texcoord0.xy -= 0.5; +    vary_texcoord0.xy /= max(0.001, 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.; + +    // END CLOUDS +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/deferredUtil.glsl new file mode 100644 index 0000000000..e27bbce094 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/deferredUtil.glsl @@ -0,0 +1,79 @@ +/**  + * @file class1/deferred/deferredUtil.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 sampler2DRect   normalMap; +uniform sampler2DRect   depthMap; + +uniform mat4 inv_proj; +uniform vec2 screen_res; + +vec2 getScreenCoordinate(vec2 screenpos) +{ +    vec2 sc = screenpos.xy * 2.0; +    if (screen_res.x > 0 && screen_res.y > 0) +    { +       sc /= screen_res; +    } +    return sc - vec2(1.0, 1.0); +} + +vec3 getNorm(vec2 screenpos) +{ +   vec2 enc = texture2DRect(normalMap, screenpos.xy).xy; +   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; +} + +float getDepth(vec2 pos_screen) +{ +    float depth = texture2DRect(depthMap, pos_screen).r; +    return depth; +} + +vec4 getPosition(vec2 pos_screen) +{ +    float depth = getDepth(pos_screen); +    vec2 sc = getScreenCoordinate(pos_screen); +    vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); +    vec4 pos = inv_proj * ndc; +    pos /= pos.w; +    pos.w = 1.0; +    return pos; +} + +vec4 getPositionWithDepth(vec2 pos_screen, float depth) +{ +    vec2 sc = getScreenCoordinate(pos_screen); +    vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); +    vec4 pos = inv_proj * ndc; +    pos /= pos.w; +    pos.w = 1.0; +    return pos; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/depthToShadowVolumeG.glsl b/indra/newview/app_settings/shaders/class3/deferred/depthToShadowVolumeG.glsl new file mode 100644 index 0000000000..cdaff4b09f --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/depthToShadowVolumeG.glsl @@ -0,0 +1,202 @@ +/**  + * @file depthToShadowVolumeG.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$ + */ +#extension GL_ARB_geometry_shader4  : enable +#extension GL_ARB_texture_rectangle : enable + +/*[EXTRA_CODE_HERE]*/ + +layout (triangles) in; +layout (triangle_strip, max_vertices = 128) out; + +uniform sampler2DRect depthMap; +uniform mat4 shadowMatrix[6];  +uniform vec4 lightpos; + +VARYING vec2 vary_texcoord0; + +out vec3 to_vec; + +void cross_products(out vec4 ns[3], int a, int b, int c) +{ +   ns[0] = cross(gl_PositionIn[b].xyz - gl_PositionIn[a].xyz, gl_PositionIn[c].xyz - gl_PositionIn[a].xyz); +   ns[1] = cross(gl_PositionIn[c].xyz - gl_PositionIn[b].xyz, gl_PositionIn[a].xyz - gl_PositionIn[b].xyz); +   ns[2] = cross(gl_PositionIn[a].xyz - gl_PositionIn[c].xyz, gl_PositionIn[b].xyz - gl_PositionIn[c].xyz); +} + +vec3 getLightDirection(vec4 lightpos, vec3 pos) +{ + +    vec3 lightdir = lightpos.xyz - lightpos.w * pos; +    return lightdir; +} + +void emitTri(vec4 v[3]) +{ +    gl_Position = proj_matrix * v[0]; +    EmitVertex(); + +    gl_Position = proj_matrix * v[1]; +    EmitVertex(); + +    gl_Position = proj_matrix * v[2]; +    EmitVertex(); + +    EndPrimitive(); +} + +void emitQuad(vec4 v[4] +{ +    // Emit a quad as a triangle strip. +    gl_Position = proj_matrix*v[0]; +    EmitVertex(); + +    gl_Position = proj_matrix*v[1]; +    EmitVertex(); + +    gl_Position = proj_matrix*v[2]; +    EmitVertex(); + +    gl_Position = proj_matrix*v[3]; +    EmitVertex();  + +    EndPrimitive(); +} + +void emitPrimitives(int layer) +{ +    int i = layer; +    gl_Layer = i; + +    vec4 depth1 = vec4(texture2DRect(depthMap, tc0).rg, texture2DRect(depthMap, tc1).rg)); +    vec3 depth2 = vec4(texture2DRect(depthMap, tc2).rg, texture2DRect(depthMap, tc3).rg)); +    vec3 depth3 = vec4(texture2DRect(depthMap, tc4).rg, texture2DRect(depthMap, tc5).rg)); +    vec3 depth4 = vec4(texture2DRect(depthMap, tc6).rg, texture2DRect(depthMap, tc7).rg)); + +    depth1 = min(depth1, depth2); +    depth1 = min(depth1, depth3); +    depth1 = min(depth1, depth4); + +    vec2 depth = min(depth1.xy, depth1.zw); + +    int side = sqrt(gl_VerticesIn); + +    for (int j = 0; j < side; j++) +    { +        for (int k = 0; k < side; ++k) +        { +            vec3 pos = gl_PositionIn[(j * side) + k].xyz; +            vec4 v = shadowMatrix[i] * vec4(pos, 1.0); +            gl_Position = v; +            to_vec = pos - light_position.xyz * depth; +            EmitVertex(); +        } + +        EndPrimitive(); +    } + +    vec3 norms[3]; // Normals +    vec3 lightdir3]; // Directions toward light + +    vec4 v[4]; // Temporary vertices + +    vec4 or_pos[3] = +    {  // Triangle oriented toward light source +        gl_PositionIn[0], +        gl_PositionIn[2], +        gl_PositionIn[4] +    }; + +    // Compute normal at each vertex. +    cross_products(n, 0, 2, 4); + +    // Compute direction from vertices to light. +    lightdir[0] = getLightDirection(lightpos, gl_PositionIn[0].xyz); +    lightdir[1] = getLightDirection(lightpos, gl_PositionIn[2].xyz); +    lightdir[2] = getLightDirection(lightpos, gl_PositionIn[4].xyz); + +    // Check if the main triangle faces the light. +    bool faces_light = true; +    if (!(dot(ns[0],d[0]) > 0 +         |dot(ns[1],d[1]) > 0 +         |dot(ns[2],d[2]) > 0)) +    { +        // Flip vertex winding order in or_pos. +        or_pos[1] = gl_PositionIn[4]; +        or_pos[2] = gl_PositionIn[2]; +        faces_light = false; +    } + +    // Near cap: simply render triangle. +    emitTri(or_pos); + +    // Far cap: extrude positions to infinity. +    v[0] =vec4(lightpos.w * or_pos[0].xyz - lightpos.xyz,0); +    v[1] =vec4(lightpos.w * or_pos[2].xyz - lightpos.xyz,0); +    v[2] =vec4(lightpos.w * or_pos[1].xyz - lightpos.xyz,0); + +    emitTri(v); + +    // Loop over all edges and extrude if needed. +    for ( int i=0; i<3; i++ )  +    { +       // Compute indices of neighbor triangle. +       int v0 = i*2; +       int nb = (i*2+1); +       int v1 = (i*2+2) % 6; +       cross_products(n, v0, nb, v1); + +       // Compute direction to light, again as above. +       d[0] =lightpos.xyz-lightpos.w*gl_PositionIn[v0].xyz; +       d[1] =lightpos.xyz-lightpos.w*gl_PositionIn[nb].xyz; +       d[2] =lightpos.xyz-lightpos.w*gl_PositionIn[v1].xyz; + +       bool is_parallel = gl_PositionIn[nb].w < 1e-5; + +       // Extrude the edge if it does not have a +       // neighbor, or if it's a possible silhouette. +       if (is_parallel || +          ( faces_light != (dot(ns[0],d[0])>0 || +                            dot(ns[1],d[1])>0 || +                            dot(ns[2],d[2])>0) )) +       { +           // Make sure sides are oriented correctly. +           int i0 = faces_light ? v0 : v1; +           int i1 = faces_light ? v1 : v0; + +           v[0] = gl_PositionIn[i0]; +           v[1] = vec4(lightpos.w*gl_PositionIn[i0].xyz - lightpos.xyz, 0); +           v[2] = gl_PositionIn[i1]; +           v[3] = vec4(lightpos.w*gl_PositionIn[i1].xyz - lightpos.xyz, 0); + +           emitQuad(v); +       } +    } +} + +void main() +{ +    // Output +    emitPrimitives(0); +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/gatherSkyShF.glsl b/indra/newview/app_settings/shaders/class3/deferred/gatherSkyShF.glsl new file mode 100644 index 0000000000..34d26cddea --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/gatherSkyShF.glsl @@ -0,0 +1,70 @@ +/**  + * @file class3/deferred/gatherSkyShF.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_data[3]; +#else +#define frag_data gl_FragData +#endif + +VARYING vec2 vary_frag; + +uniform vec2 screen_res; +uniform sampler2D sh_input_r; +uniform sampler2D sh_input_g; +uniform sampler2D sh_input_b; + +void main() +{ +    vec2 offset	  = vec2(2.0) / screen_res; + +    vec4 r = vec4(0); +    vec4 g = vec4(0); +    vec4 b = vec4(0); + +    vec2 tc = vary_frag * 2.0; + +	r += texture2D(sh_input_r, tc + vec2(0,        0)); +	r += texture2D(sh_input_r, tc + vec2(offset.x, 0)); +	r += texture2D(sh_input_r, tc + vec2(0,        offset.y)); +	r += texture2D(sh_input_r, tc + vec2(offset.x, offset.y)); +    r /= 4.0f; + +	g += texture2D(sh_input_g, tc + vec2(0,        0)); +	g += texture2D(sh_input_g, tc + vec2(offset.x, 0)); +	g += texture2D(sh_input_g, tc + vec2(0,        offset.y)); +	g += texture2D(sh_input_g, tc + vec2(offset.x, offset.y)); +    g /= 4.0f; + +	b += texture2D(sh_input_b, tc + vec2(0,        0)); +	b += texture2D(sh_input_b, tc + vec2(offset.x, 0)); +	b += texture2D(sh_input_b, tc + vec2(0,        offset.y)); +	b += texture2D(sh_input_b, tc + vec2(offset.x, offset.y)); +    b /= 4.0f; + +    frag_data[0] = r; +    frag_data[1] = g; +    frag_data[2] = b; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/gatherSkyShV.glsl b/indra/newview/app_settings/shaders/class3/deferred/gatherSkyShV.glsl new file mode 100644 index 0000000000..337c8a50fe --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/gatherSkyShV.glsl @@ -0,0 +1,40 @@ +/**  + * @file gatherSkyShV.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$ + */ +  +ATTRIBUTE vec3 position; +ATTRIBUTE vec2 texcoord0; + +VARYING vec2 vary_frag; +uniform vec2 screen_res; + +void main() +{ +    // pass through untransformed fullscreen pos +    float oo_divisor = screen_res.x / 64.0; +    vec3 pos = (position.xyz * oo_divisor) + vec3(oo_divisor - 1, oo_divisor - 1, 0); +	gl_Position = vec4(pos.xyz, 1.0); +    vary_frag = texcoord0 * oo_divisor; +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/genSkyShF.glsl b/indra/newview/app_settings/shaders/class3/deferred/genSkyShF.glsl new file mode 100644 index 0000000000..d5d91c88f0 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/genSkyShF.glsl @@ -0,0 +1,111 @@ +/**  + * @file class3/deferred/genSkyShF.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_data[3]; +#else +#define frag_data gl_FragData +#endif + +VARYING vec2 vary_frag; + +uniform vec3 sun_dir; + +uniform sampler2D transmittance_texture; +uniform sampler3D scattering_texture; +uniform sampler3D single_mie_scattering_texture; +uniform sampler2D irradiance_texture; + +vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 dir, out vec3 transmittance); + +vec3 calcDirection(vec2 tc) +{ +     float phi = tc.y * 2.0 * 3.14159265; +     float cosTheta = sqrt(1.0 - tc.x); +     float sinTheta = sqrt(1.0 - cosTheta * cosTheta); +     return vec3(cos(phi) * sinTheta, sin(phi) * sinTheta, cosTheta); +} + +// reverse mapping above to convert a hemisphere direction into phi/theta values +void getPhiAndThetaFromDirection(vec3 dir, out float phi, out float theta) +{ +     float sin_theta; +     float cos_theta; +     cos_theta = dir.z; +     theta     = acos(cos_theta); +     sin_theta = sin(theta); +     phi       = abs(sin_theta) > 0.0001 ? acos(dir.x / sin_theta) : 1.0; +} + +// reverse mapping above to convert a hemisphere direction into an SH texture sample pos +vec2 calcShUvFromDirection(vec3 dir) +{ +    vec2 uv; +    float phi; +    float theta; +    getPhiAndThetaFromDirection(dir, phi, theta); +    uv.y = phi   / 2.0 * 3.14159265; +    uv.x = theta / 2.0 * 3.14159265; +    return uv; +} + +void projectToL1(vec3 n, vec3 c, vec4 basis, out vec4 coeffs[3]) +{ +    coeffs[0] = vec4(basis.x, n * basis.yzw * c.r); +    coeffs[1] = vec4(basis.x, n * basis.yzw * c.g); +    coeffs[2] = vec4(basis.x, n * basis.yzw * c.b); +} + +void main() +{ +    float Y00 = sqrt(1.0 / 3.14159265) * 0.5; +    float Y1x = sqrt(3.0 / 3.14159265) * 0.5; +    float Y1y = Y1x; +    float Y1z = Y1x; + +    vec4 L1 = vec4(Y00, Y1x, Y1y, Y1z); + +    vec3 view_direction = calcDirection(vary_frag); +    vec3 sun_direction  = normalize(sun_dir); +    vec3 cam_pos        = vec3(0, 0, 6360); + +    vec3 transmittance; +    vec3 radiance = GetSkyLuminance(cam_pos, view_direction, 0.0f, sun_direction, transmittance); + +    vec3 color = vec3(1.0) - exp(-radiance * 0.0001); + +    color = pow(color, vec3(1.0/2.2)); + +    vec4 coeffs[3]; +    coeffs[0] = vec4(0); +    coeffs[1] = vec4(0); +    coeffs[2] = vec4(0); + +    projectToL1(view_direction, color.rgb, L1, coeffs); + +    frag_data[0] = coeffs[0]; +    frag_data[1] = coeffs[1]; +    frag_data[2] = coeffs[2]; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/genSkyShV.glsl b/indra/newview/app_settings/shaders/class3/deferred/genSkyShV.glsl new file mode 100644 index 0000000000..b466883dc7 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/genSkyShV.glsl @@ -0,0 +1,37 @@ +/**  + * @file genSkyShV.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$ + */ +  +ATTRIBUTE vec3 position; +ATTRIBUTE vec2 texcoord0; + +VARYING vec2 vary_frag; + +void main() +{ +    // pass through untransformed fullscreen pos +	gl_Position = vec4(position.xyz, 1.0); +    vary_frag = texcoord0; +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/indirect.glsl b/indra/newview/app_settings/shaders/class3/deferred/indirect.glsl new file mode 100644 index 0000000000..33c5667cae --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/indirect.glsl @@ -0,0 +1,44 @@ +/**  + * @file class3/deferred/indirect.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]*/ + +uniform sampler2D sh_input_r; +uniform sampler2D sh_input_g; +uniform sampler2D sh_input_b; + +vec3 GetIndirect(vec3 norm) +{ +    vec4 l1tap = vec4(1.0/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265)); +    vec4 l1r = texture2D(sh_input_r, vec2(0,0)); +    vec4 l1g = texture2D(sh_input_g, vec2(0,0)); +    vec4 l1b = texture2D(sh_input_b, vec2(0,0)); +    vec3 indirect = vec3(dot(l1r, l1tap * vec4(1, norm.xyz)), +                         dot(l1g, l1tap * vec4(1, norm.xyz)), +                         dot(l1b, l1tap * vec4(1, norm.xyz))); +    indirect = clamp(indirect, vec3(0), vec3(1.0)); +    return indirect; +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/lightUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/lightUtil.glsl new file mode 100644 index 0000000000..8bb3f07fc6 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/lightUtil.glsl @@ -0,0 +1,117 @@ +/**  + * @file lightInfo.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$ + */ + +struct DirectionalLightInfo +{ +    vec4 pos; +    float depth; +    vec4 normal; +    vec3 normalizedLightDirection; +    vec3 normalizedToLight; +    float lightIntensity; +    vec3 lightDiffuseColor; +    float specExponent; +    float shadow; +}; + +struct SpotLightInfo +{ +    vec4 pos; +    float depth; +    vec4 normal; +    vec3 normalizedLightDirection; +    vec3 normalizedToLight; +    float lightIntensity; +    float attenuation; +    float distanceToLight; +    vec3 lightDiffuseColor; +    float innerHalfAngleCos; +    float outerHalfAngleCos; +    float spotExponent; +    float specExponent; +    float shadow; +}; + +struct PointLightInfo +{ +    vec4 pos; +    float depth; +    vec4 normal; +    vec3 normalizedToLight; +    float lightIntensity; +    float attenuation; +    float distanceToLight; +    vec3 lightDiffuseColor; +    float lightRadius; +    float specExponent; +    vec3 worldspaceLightDirection; +    float shadow; +}; + +float attenuate(float attenuationSelection, float distanceToLight) +{ +// LLRENDER_REVIEW +// sh/could eventually consume attenuation func defined in texture +    return (attenuationSelection == 0.0f) ? 1.0f : // none +           (attenuationSelection <  1.0f) ? (1.0f / distanceToLight) : // linear atten  +           (attenuationSelection <  2.0f) ? (1.0f / (distanceToLight*distanceToLight)) // quadratic atten +										  : (1.0f / (distanceToLight*distanceToLight*distanceToLight));	// cubic atten     +} + + +vec3 lightDirectional(struct DirectionalLightInfo dli) +{ +    float lightIntensity = dli.lightIntensity; +	lightIntensity *= dot(dli.normal.xyz, dli.normalizedLightDirection); +    //lightIntensity *= directionalShadowSample(vec4(dli.pos.xyz, 1.0f), dli.depth, dli.directionalShadowMap, dli.directionalShadowMatrix); +	return lightIntensity * dli.lightDiffuseColor; +} + + +vec3 lightSpot(struct SpotLightInfo sli)     +{ +	float penumbraRange = (sli.outerHalfAngleCos - sli.innerHalfAngleCos); +    float coneAngleCos = max(dot(sli.normalizedLightDirection, sli.normalizedToLight), 0.0); +	float coneAttenFactor = (coneAngleCos <= sli.outerHalfAngleCos) ? 1.0f : pow(smoothstep(1,0, sli.outerHalfAngleCos / penumbraRange), sli.spotExponent); +    float distanceAttenuation = attenuate(sli.attenuation, sli.distanceToLight); +    float lightIntensity = sli.lightIntensity; +    lightIntensity *= distanceAttenuation; +	lightIntensity *= max(dot(sli.normal.xyz, sli.normalizedLightDirection), 0.0); +	lightIntensity *= coneAttenFactor; +    lightIntensity *= sli.shadow; +	return lightIntensity * sli.lightDiffuseColor; +} + +vec3 lightPoint(struct PointLightInfo pli) +{ +    float padRadius = pli.lightRadius * 0.1; // distance for which to perform smoothed dropoff past light radius +	float distanceAttenuation =	attenuate(pli.attenuation, pli.distanceToLight); +    float lightIntensity = pli.lightIntensity; +    lightIntensity*= distanceAttenuation;     +	lightIntensity *= clamp((padRadius - pli.distanceToLight + pli.lightRadius) / padRadius, 0.0, 1.0); +    lightIntensity *= pli.shadow; +    lightIntensity *= max(dot(pli.normal.xyz, pli.normalizedToLight), 0.0); +	return lightIntensity * pli.lightDiffuseColor; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl new file mode 100644 index 0000000000..9d62b9d180 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -0,0 +1,291 @@ +/**  + * @file multiSpotLightF.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$ + */ +  +#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 + +uniform sampler2DRect diffuseRect; +uniform sampler2DRect specularRect; +uniform sampler2DRect depthMap; +uniform sampler2DRect normalMap; +uniform samplerCube environmentMap; +uniform sampler2DRect lightMap; +uniform sampler2D noiseMap; +uniform sampler2D projectionMap; +uniform sampler2D lightFunc; + +uniform mat4 proj_mat; //screen space to light space +uniform float proj_near; //near clip for projection +uniform vec3 proj_p; //plane projection is emitting from (in screen space) +uniform vec3 proj_n; +uniform float proj_focus; //distance from plane to begin blurring +uniform float proj_lod;  //(number of mips in proj map) +uniform float proj_range; //range between near clip and far clip plane of projection +uniform float proj_ambient_lod; +uniform float proj_ambiance; +uniform float near_clip; +uniform float far_clip; + +uniform vec3 proj_origin; //origin of projection to be used for angular attenuation +uniform float sun_wash; +uniform int proj_shadow_idx; +uniform float shadow_fade; + +uniform vec3 center; +uniform float size; +uniform vec3 color; +uniform float falloff; + +VARYING vec4 vary_fragcoord; +uniform vec2 screen_res; + +uniform mat4 inv_proj; + +vec3 getNorm(vec2 pos_screen); + +vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) +{ +    vec4 ret = texture2DLod(projectionMap, tc, lod); +     +    vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); +     +    float det = min(lod/(proj_lod*0.5), 1.0); +     +    float d = min(dist.x, dist.y); +     +    d *= min(1, d * (proj_lod - lod)); +     +    float edge = 0.25*det; +     +    ret *= clamp(d/edge, 0.0, 1.0); +     +    return ret; +} + +vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) +{ +    vec4 ret = texture2DLod(projectionMap, tc, lod); + +    vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); +     +    float det = min(lod/(proj_lod*0.5), 1.0); +     +    float d = min(dist.x, dist.y); +     +    float edge = 0.25*det; +         +    ret *= clamp(d/edge, 0.0, 1.0); +     +    return ret; +} + +vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) +{ +    vec4 ret = texture2DLod(projectionMap, tc, lod); + +    vec2 dist = tc-vec2(0.5); +     +    float d = dot(dist,dist); +         +    ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); +     +    return ret; +} + + +vec4 getPosition(vec2 pos_screen); + +void main()  +{ +    vec4 frag = vary_fragcoord; +    frag.xyz /= frag.w; +    frag.xyz = frag.xyz*0.5+0.5; +    frag.xy *= screen_res; +     +    vec3 pos = getPosition(frag.xy).xyz; +    vec3 lv = center.xyz-pos.xyz; +    float dist = length(lv); +    dist /= size; +    if (dist > 1.0) +    { +        discard; +    } +     +    float shadow = 1.0; +     +    if (proj_shadow_idx >= 0) +    { +        vec4 shd = texture2DRect(lightMap, frag.xy); +        shadow = (proj_shadow_idx == 0) ? shd.b : shd.a; +        shadow += shadow_fade; +        shadow = clamp(shadow, 0.0, 1.0);         +    } +     +    vec3 norm = texture2DRect(normalMap, frag.xy).xyz; +     +    float envIntensity = norm.z; + +    norm = getNorm(frag.xy); +     +    norm = normalize(norm); +    float l_dist = -dot(lv, proj_n); +     +    vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); +    if (proj_tc.z < 0.0) +    { +        discard; +    } +     +    proj_tc.xyz /= proj_tc.w; +     +    float fa = (falloff*0.5)+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; +    if (dist_atten <= 0.0) +    { +        discard; +    } +     +    lv = proj_origin-pos.xyz; +    lv = normalize(lv); +    float da = dot(norm, lv); + +    vec3 col = vec3(0,0,0); +         +    vec3 diff_tex = srgb_to_linear(texture2DRect(diffuseRect, frag.xy).rgb); +     +    vec4 spec = texture2DRect(specularRect, frag.xy); + +    vec3 dlit = vec3(0, 0, 0); + +    float noise = texture2D(noiseMap, frag.xy/128.0).b; +    if (proj_tc.z > 0.0 && +        proj_tc.x < 1.0 && +        proj_tc.y < 1.0 && +        proj_tc.x > 0.0 && +        proj_tc.y > 0.0) +    { +        float amb_da = proj_ambiance; +        float lit = 0.0; + +        if (da > 0.0) +        { +            lit = da * dist_atten * noise; + +            float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); +            float lod = diff * proj_lod; +             +            vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); +         +            dlit = color.rgb * plcol.rgb * plcol.a; +             +            col = dlit*lit*diff_tex*shadow; +            amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; +        } +         +        //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); +        vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); +                             +        amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance; +                 +        amb_da *= dist_atten * noise; +             +        amb_da = min(amb_da, 1.0-lit); +             +        col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; +    } +     + +    if (spec.a > 0.0) +    { +        vec3 npos = -normalize(pos); +        dlit *= min(da*6.0, 1.0) * dist_atten; + +        //vec3 ref = dot(pos+lv, norm); +        vec3 h = normalize(lv+npos); +        float nh = dot(norm, h); +        float nv = dot(norm, npos); +        float vh = dot(npos, h); +        float sa = nh; +        float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + +        float gtdenom = 2 * nh; +        float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); +                                 +        if (nh > 0.0) +        { +            float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); +            col += dlit*scol*spec.rgb*shadow; +            //col += spec.rgb; +        } +    }    + +    if (envIntensity > 0.0) +    { +        vec3 ref = reflect(normalize(pos), norm); +         +        //project from point pos in direction ref to plane proj_p, proj_n +        vec3 pdelta = proj_p-pos; +        float ds = dot(ref, proj_n); +         +        if (ds < 0.0) +        { +            vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; +             +            vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); + +            if (stc.z > 0.0) +            { +                stc /= stc.w; +                                 +                if (stc.x < 1.0 && +                    stc.y < 1.0 && +                    stc.x > 0.0 && +                    stc.y > 0.0) +                { +                    col += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; +                } +            } +        } +    } + +    //not sure why, but this line prevents MATBUG-194 +    col = max(col, vec3(0.0)); + +    col = scaleDownLight(col); + +    //output linear space color as gamma correction happens down stream +    frag_color.rgb = col;    +    frag_color.a = 0.0; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointShadowBlurF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointShadowBlurF.glsl new file mode 100644 index 0000000000..ca9ce3a2e1 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/pointShadowBlurF.glsl @@ -0,0 +1,37 @@ +/**  + * @file pointShadowBlur.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 samplerCube cube_map;  + +in vec3 to_vec; + +out vec4 fragColor; + +void main()  +{ +	vec4 vcol = texture(cube_map, to_vec); +	fragColor = vec4(vcol.rgb, 1.0); +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/shVisF.glsl b/indra/newview/app_settings/shaders/class3/deferred/shVisF.glsl new file mode 100644 index 0000000000..c8991f7a18 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/shVisF.glsl @@ -0,0 +1,73 @@ +/**  + * @file class3/deferred/shVisF.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$ + */ + +#ifdef DEFINE_GL_FRAGCOLOR +    out vec4 frag_color; +#else +    #define frag_color gl_FragColor +#endif + +///////////////////////////////////////////////////////////////////////// +// Fragment shader for L1 SH debug rendering +///////////////////////////////////////////////////////////////////////// + +uniform sampler2D sh_input_r; +uniform sampler2D sh_input_g; +uniform sampler2D sh_input_b; + +uniform mat3 inv_modelviewprojection; + +VARYING vec4 vary_pos; + +void main(void)  +{ +    vec2 coord = vary_pos.xy + vec2(0.5,0.5); + +    coord.x *= (1.6/0.9); + +    if (dot(coord, coord) > 0.25) +    { +        discard; +    } + +    vec4 n = vec4(coord*2.0, 0.0, 1); +    //n.y = -n.y; +    n.z = sqrt(max(1.0-n.x*n.x-n.y*n.y, 0.0)); +    //n.xyz = inv_modelviewprojection * n.xyz; + +    vec4 l1tap = vec4(1.0/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265)); +    vec4 l1r = texture2D(sh_input_r, vec2(0,0)); +    vec4 l1g = texture2D(sh_input_g, vec2(0,0)); +    vec4 l1b = texture2D(sh_input_b, vec2(0,0)); +    vec3 indirect = vec3( +                      dot(l1r, l1tap * n), +                      dot(l1g, l1tap * n), +                      dot(l1b, l1tap * n)); + +    //indirect = pow(indirect, vec3(0.45)); +    indirect *= 3.0; + +	frag_color = vec4(indirect, 1.0); +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/shVisV.glsl b/indra/newview/app_settings/shaders/class3/deferred/shVisV.glsl new file mode 100644 index 0000000000..8f32dfde79 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/shVisV.glsl @@ -0,0 +1,33 @@ +/**  + * @file class3/deferred/shVisV.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$ + */ +ATTRIBUTE vec3 position; +VARYING vec4 vary_pos; + +void main() +{ +    // Output +    vary_pos = vec4(position, 1); +    gl_Position = vary_pos; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendF.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendF.glsl new file mode 100644 index 0000000000..345c07a354 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendF.glsl @@ -0,0 +1,58 @@ +/**  + * @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 !defined(DEPTH_CLAMP) +VARYING float pos_zd2; +#endif + +VARYING float pos_w; + +VARYING float target_pos_x; +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; +VARYING vec3 pos; + +vec4 computeMoments(float depth, float a); + +void main()  +{ +	float alpha = diffuseLookup(vary_texcoord0.xy).a * vertex_color.a; + +    frag_color = computeMoments(length(pos), float a); + +#if !defined(DEPTH_CLAMP) +	gl_FragDepth = max(pos_zd2/pos_w+0.5, 0.0); +#endif +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendV.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendV.glsl new file mode 100644 index 0000000000..af1461c297 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendV.glsl @@ -0,0 +1,66 @@ +/**  + * @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 !defined(DEPTH_CLAMP) +VARYING float pos_zd2; +#endif + +VARYING float target_pos_x; +VARYING vec4 pos; +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 !defined(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/class3/deferred/shadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskF.glsl new file mode 100644 index 0000000000..50f1ffd626 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskF.glsl @@ -0,0 +1,74 @@ +/**  + * @file class3/deferred/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 !defined(DEPTH_CLAMP) +VARYING float pos_zd2; +#endif + +VARYING float pos_w; + +VARYING float target_pos_x; +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; + +vec4 getPosition(vec2 screen_coord); +vec4 computeMoments(float depth, float a); + +void main()  +{ +    vec4 pos = getPosition(vary_texcoord0.xy); + +    float alpha = diffuseLookup(vary_texcoord0.xy).a * vertex_color.a; + +    if (alpha < 0.05) // treat as totally transparent +    { +        discard; +    } + +    if (alpha < 0.88) // treat as semi-transparent +    { +        if (fract(0.5*floor(target_pos_x / pos_w )) < 0.25) +        { +            discard; +        } +    } + +    frag_color = computeMoments(length(pos.xyz), alpha); +     +#if !defined(DEPTH_CLAMP) +    gl_FragDepth = max(pos_zd2/pos_w+0.5, 0.0); +#endif + +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskV.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskV.glsl new file mode 100644 index 0000000000..6a646f5e9e --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskV.glsl @@ -0,0 +1,67 @@ +/**  + * @file class3/deferred/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 !defined(DEPTH_CLAMP) +VARYING float pos_zd2; +#endif + +VARYING vec4 pos; +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); + +	pos = modelview_projection_matrix * pre_pos; + +	target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; + +#if !defined(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/class3/deferred/shadowCubeV.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowCubeV.glsl new file mode 100644 index 0000000000..db8c75fb8a --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/shadowCubeV.glsl @@ -0,0 +1,50 @@ +/**  + * @file class3/deferred/shadowCubeV.glsl + * + * $LicenseInfo:firstyear=2011&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 modelview_projection_matrix; + +ATTRIBUTE vec3 position; + +#if !defined(DEPTH_CLAMP) +VARYING vec4 post_pos; +#endif + +uniform vec3 box_center; +uniform vec3 box_size; + +void main() +{ +	//transform vertex +	vec3 p = position*box_size+box_center; +	vec4 pos = modelview_projection_matrix*vec4(p.xyz, 1.0); + +#if !defined(DEPTH_CLAMP) +	post_pos = pos; + +	gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); +#else +	gl_Position = pos; +#endif +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowF.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowF.glsl new file mode 100644 index 0000000000..3350267130 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/shadowF.glsl @@ -0,0 +1,49 @@ +/**  + * @file class3/deferred/shadowF.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 !defined(DEPTH_CLAMP) +VARYING float pos_zd2; +#endif + +VARYING vec4 pos; +VARYING float target_pos_x; + +vec4 computeMoments(float depth, float a); + +void main()  +{ +    frag_color = computeMoments(length(pos), 1.0); +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowUtil.glsl new file mode 100644 index 0000000000..2f69a353e8 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/shadowUtil.glsl @@ -0,0 +1,157 @@ +/**  + * @file class3/deferred/shadowUtil.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 sampler2D       shadowMap0; +uniform sampler2D       shadowMap1; +uniform sampler2D       shadowMap2; +uniform sampler2D       shadowMap3; +uniform sampler2D       shadowMap4; +uniform sampler2D       shadowMap5; + +uniform vec3 sun_dir; +uniform vec3 moon_dir; +uniform vec2 shadow_res; +uniform vec2 proj_shadow_res; +uniform mat4 shadow_matrix[6]; +uniform vec4 shadow_clip; +uniform float shadow_bias; + +uniform float spot_shadow_bias; +uniform float spot_shadow_offset; + +float getDepth(vec2 screenpos); +vec3 getNorm(vec2 screenpos); +vec4 getPosition(vec2 pos_screen); + +float ReduceLightBleeding(float p_max, float Amount) +{ +    return smoothstep(Amount, 1, p_max); +} + +float ChebyshevUpperBound(vec2 m, float t, float min_v, float Amount) +{ +    float p = (t <= m.x) ? 1.0 : 0.0; + +    float v = m.y - (m.x*m.x); +    v = max(v, min_v); + +    float d = t - m.x; + +    float p_max = v / (v + d*d); + +    p_max = ReduceLightBleeding(p_max, Amount); + +    return max(p, p_max); +} + +vec4 computeMoments(float depth, float a) +{ +    float m1 = depth; +    float dx = dFdx(depth); +    float dy = dFdy(depth); +    float m2 = m1*m1 + 0.25 * a * (dx*dx + dy*dy); +    return vec4(m1, m2, a, max(dx, dy)); +} + +float vsmDirectionalSample(vec4 stc, float depth, sampler2D shadowMap, mat4 shadowMatrix) +{ +    vec4 lpos = shadowMatrix * stc; +    vec4 moments = texture2D(shadowMap, lpos.xy); +    return ChebyshevUpperBound(moments.rg, depth - shadow_bias * 256.0f, 0.125, 0.9); +} + +float vsmSpotSample(vec4 stc, float depth, sampler2D shadowMap, mat4 shadowMatrix) +{ +    vec4 lpos = shadowMatrix * stc; +    vec4 moments = texture2D(shadowMap, lpos.xy); +    lpos.xyz /= lpos.w; +    lpos.xy *= 0.5; +    lpos.xy += 0.5; +    return ChebyshevUpperBound(moments.rg, depth - spot_shadow_bias * 16.0f, 0.125, 0.9); +} + +#if VSM_POINT_SHADOWS +float vsmPointSample(float lightDistance, vec3 lightDirection, samplerCube shadow_cube_map) +{ +    vec4 moments = textureCube(shadow_cube_map, light_direction); +    return ChebyshevUpperBound(moments.rg, light_distance, 0.01, 0.25); +} +#endif + +float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) +{ +	if (pos.z < -shadow_clip.w) +    { +        discard; +    } + +    float depth = getDepth(pos_screen); + +    vec4 spos       = vec4(pos,1.0); +    vec4 near_split = shadow_clip*-0.75; +    vec4 far_split  = shadow_clip*-1.25; + +    float shadow = 0.0f; +    float weight = 1.0; + +    if (spos.z < near_split.z) +    { +        shadow += vsmDirectionalSample(spos, depth, shadowMap3, shadow_matrix[3]); +        weight += 1.0f; +    } +    if (spos.z < near_split.y) +    { +        shadow += vsmDirectionalSample(spos, depth, shadowMap2, shadow_matrix[2]); +        weight += 1.0f; +    } +    if (spos.z < near_split.x) +    { +        shadow += vsmDirectionalSample(spos, depth, shadowMap1, shadow_matrix[1]); +        weight += 1.0f; +    } +    if (spos.z > far_split.x) +    { +        shadow += vsmDirectionalSample(spos, depth, shadowMap0, shadow_matrix[0]); +        weight += 1.0f; +    } + +    shadow /= weight; + +    return shadow; +} + +float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen) +{ +	if (pos.z < -shadow_clip.w) +    { +        discard; +    } + +    float depth = getDepth(pos_screen); + +    pos += norm * spot_shadow_offset; +    return vsmSpotSample(vec4(pos, 1.0), depth, (index == 0) ? shadowMap4 : shadowMap5, shadow_matrix[4 + index]); +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowV.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowV.glsl new file mode 100644 index 0000000000..6577fe0ecf --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/shadowV.glsl @@ -0,0 +1,62 @@ +/**  + * @file class3/deferred/shadowV.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 modelview_projection_matrix; +uniform float shadow_target_width; +uniform mat4 texture_matrix0; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec2 texcoord0; + +#if !defined(DEPTH_CLAMP) +VARYING float pos_zd2; +#endif + +VARYING vec4 pos; +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); + +	pos = modelview_projection_matrix * pre_pos; + +	target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; + +#if !defined(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 +	 +	vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; +} 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..6de01cb667 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl @@ -0,0 +1,111 @@ +/**  + * @file class3/deferred/skyF.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_data[3]; +#else +#define frag_data gl_FragData +#endif + +VARYING vec2 vary_frag; + +uniform vec3 camPosLocal; +uniform vec3 sun_dir; +uniform float sun_size; +uniform float far_z; +uniform mat4 inv_proj; +uniform mat4 inv_modelview; + +uniform sampler2D transmittance_texture; +uniform sampler3D scattering_texture; +uniform sampler3D single_mie_scattering_texture; +uniform sampler2D irradiance_texture; +uniform sampler2D rainbow_map; +uniform sampler2D halo_map; + +uniform float moisture_level; +uniform float droplet_radius; +uniform float ice_level; + +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 ColorFromRadiance(vec3 radiance); +vec3 rainbow(float d) +{ +   float rad = (droplet_radius - 5.0f) / 1024.0f; +   return pow(texture2D(rainbow_map, vec2(rad, d)).rgb, vec3(1.8)) * moisture_level; +} + +vec3 halo22(float d) +{ +   float v = sqrt(max(0, 1 - (d*d))); +   return texture2D(halo_map, vec2(0, v)).rgb * ice_level; +} + +void main() +{ +    vec3 pos      = vec3((vary_frag * 2.0) - vec2(1.0, 1.0f), 1.0); +    vec4 view_pos = (inv_proj * vec4(pos, 1.0f)); + +    view_pos /= view_pos.w; + +    vec3 view_ray = (inv_modelview * vec4(view_pos.xyz, 0.0f)).xyz + camPosLocal; + +    vec3 view_direction = normalize(view_ray); +    vec3 sun_direction  = normalize(sun_dir); +    vec3 earth_center   = vec3(0, 0, -6360.0f); +    vec3 camPos = (camPosLocal / 1000.0f) - earth_center; + +    vec3 transmittance; +    vec3 radiance_sun  = GetSkyLuminance(camPos, view_direction, 0.0f, sun_direction, transmittance); +    vec3 solar_luminance = GetSolarLuminance(); + +    // If the view ray intersects the Sun, add the Sun radiance. +    float s = dot(view_direction, sun_direction); + +    // cheesy solar disc... +    if (s >= (sun_size * 0.999)) +    { +        radiance_sun += pow(smoothstep(0.0, 1.3, (s - (sun_size * 0.9))), 2.0) * solar_luminance * transmittance; +    } +    s = smoothstep(0.9, 1.0, s) * 16.0f; + +    vec3 color = ColorFromRadiance(radiance_sun); + +    float optic_d = dot(view_direction, sun_direction); +    vec3 halo_22 = halo22(optic_d); + +    color.rgb += rainbow(optic_d) * optic_d; +    color.rgb += halo_22; + +    color = pow(color, vec3(1.0/2.2)); + +    frag_data[0] = vec4(color, 1.0 + s); +    frag_data[1] = vec4(0.0); +    frag_data[2] = vec4(0.0, 1.0, 0.0, 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..2eb222ada4 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl @@ -0,0 +1,37 @@ +/**  + * @file class3/deferred/skyV.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$ + */ +  +ATTRIBUTE vec3 position; +ATTRIBUTE vec2 texcoord0; + +VARYING vec2 vary_frag; + +void main() +{ +    // pass through untransformed fullscreen pos at back of frustum for proper sky depth testing +	gl_Position = vec4(position.xy, 1.0f, 1.0); +    vary_frag = texcoord0; +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl new file mode 100644 index 0000000000..7ed9e7b4fc --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -0,0 +1,177 @@ +/**  + * @file class3/deferred/softenLightF.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$ + */ +  +#extension GL_ARB_texture_rectangle : enable + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2DRect diffuseRect; +uniform sampler2DRect specularRect; +uniform sampler2DRect normalMap; +uniform sampler2DRect lightMap; +uniform sampler2DRect depthMap; +uniform sampler2D     lightFunc; + +uniform samplerCube environmentMap; +uniform float blur_size; +uniform float blur_fidelity; + +// Inputs +uniform vec4 morphFactor; +uniform vec3 camPosLocal; +uniform float cloud_shadow; +uniform float max_y; +uniform vec4 glow; +uniform mat3 env_mat; +uniform vec4 shadow_clip; + +uniform vec3 sun_dir; +VARYING vec2 vary_fragcoord; + +uniform mat4 inv_proj; +uniform mat4 inv_modelview; + +uniform vec2 screen_res; + +uniform sampler2D transmittance_texture; +uniform sampler3D scattering_texture; +uniform sampler3D single_mie_scattering_texture; +uniform sampler2D irradiance_texture; + +uniform sampler2D sh_input_r; +uniform sampler2D sh_input_g; +uniform sampler2D sh_input_b; + +vec3 GetSunAndSkyIrradiance(vec3 camPos, vec3 norm, vec3 dir, out vec3 sky_irradiance); +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 ColorFromRadiance(vec3 radiance); +vec4 getPositionWithDepth(vec2 pos_screen, float depth); +vec4 getPosition(vec2 pos_screen); +vec3 getNorm(vec2 pos_screen); + +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 color); +#endif + +void main()  +{ +    vec2 tc = vary_fragcoord.xy; +    float depth = texture2DRect(depthMap, tc.xy).r; +    vec3 pos = getPositionWithDepth(tc, depth).xyz; +    vec4 norm = texture2DRect(normalMap, tc); +    float envIntensity = norm.z; +    norm.xyz = getNorm(tc); + +    float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); + +    vec4 diffuse = texture2DRect(diffuseRect, tc); // sRGB +    diffuse.rgb = srgb_to_linear(diffuse.rgb); + +    vec3 col; +    float bloom = 0.0; +    { +        vec3 camPos = (camPosLocal / 1000.0f) + vec3(0, 0, 6360.0f); + +        vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); +         +        vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; + +        float scol = max(scol_ambocc.r, diffuse.a);  + +        float ambocc = scol_ambocc.g; + +        vec4 l1tap = vec4(1.0/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265)); +        vec4 l1r = texture2D(sh_input_r, vec2(0,0)); +        vec4 l1g = texture2D(sh_input_g, vec2(0,0)); +        vec4 l1b = texture2D(sh_input_b, vec2(0,0)); + +        vec3 indirect = vec3(dot(l1r, l1tap * vec4(1, norm.xyz)), +                             dot(l1g, l1tap * vec4(1, norm.xyz)), +                             dot(l1b, l1tap * vec4(1, norm.xyz))); + +        indirect = clamp(indirect, vec3(0), vec3(1.0)); + +        vec3 transmittance; +        vec3 sky_irradiance; +        vec3 sun_irradiance = GetSunAndSkyIrradiance(camPos, norm.xyz, sun_dir, sky_irradiance); +        vec3 inscatter = GetSkyLuminanceToPoint(camPos, (pos / 1000.f) + vec3(0, 0, 6360.0f), scol, sun_dir, transmittance); + +        vec3 radiance   = scol * (sun_irradiance + sky_irradiance) + inscatter; +        vec3 atmo_color = ColorFromRadiance(radiance); + +        col = atmo_color + indirect; +        col *= transmittance; +        col *= diffuse.rgb; + +        vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + +        if (spec.a > 0.0) // specular reflection +        { +            // the old infinite-sky shiny reflection +            // +            float sa = dot(refnormpersp, sun_dir.xyz); +            vec3 dumbshiny = scol * texture2D(lightFunc, vec2(sa, spec.a)).r * atmo_color; +             +            // add the two types of shiny together +            vec3 spec_contrib = dumbshiny * spec.rgb * 0.25; +            bloom = dot(spec_contrib, spec_contrib); +            col += spec_contrib; +        } + +        col = mix(col, diffuse.rgb, diffuse.a); + +        if (envIntensity > 0.0) +        { //add environmentmap +            vec3 env_vec = env_mat * refnormpersp; +            vec3 sun_direction  = (inv_modelview * vec4(sun_dir, 1.0)).xyz; +            vec3 radiance_sun  = GetSkyLuminance(camPos, env_vec, 0.0f, sun_direction, transmittance); +            vec3 refcol = ColorFromRadiance(radiance_sun); +            col = mix(col.rgb, refcol, envIntensity); +        } +                         +        /*if (norm.w < 0.5) +        { +            col = scaleSoftClipFrag(col); +        }*/ + +        #ifdef WATER_FOG +            vec4 fogged = applyWaterFogView(pos,vec4(col, bloom)); +            col = fogged.rgb; +            bloom = fogged.a; +        #endif +    } + +    //output linear since gamma correction happens down stream +    frag_color.rgb = col; +    frag_color.a = bloom; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl new file mode 100644 index 0000000000..9d872b8df8 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl @@ -0,0 +1,38 @@ +/**  + * @file class3/deferred/softenLightV.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$ + */ +ATTRIBUTE vec3 position; + +VARYING vec2 vary_fragcoord; + +uniform mat4 modelview_projection_matrix; +uniform vec2 screen_res; + +void main() +{ +	//transform vertex +	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); +	gl_Position = pos;  +	vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl new file mode 100644 index 0000000000..56b0f4e5ce --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -0,0 +1,287 @@ +/**  + * @file spotLightF.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$ + */ +  +#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 + +uniform sampler2DRect diffuseRect; +uniform sampler2DRect specularRect; +uniform sampler2DRect depthMap; +uniform sampler2DRect normalMap; +uniform samplerCube environmentMap; +uniform sampler2DRect lightMap; +uniform sampler2D noiseMap; +uniform sampler2D projectionMap; +uniform sampler2D lightFunc; + +uniform mat4 proj_mat; //screen space to light space +uniform float proj_near; //near clip for projection +uniform vec3 proj_p; //plane projection is emitting from (in screen space) +uniform vec3 proj_n; +uniform float proj_focus; //distance from plane to begin blurring +uniform float proj_lod;  //(number of mips in proj map) +uniform float proj_range; //range between near clip and far clip plane of projection +uniform float proj_ambient_lod; +uniform float proj_ambiance; +uniform float near_clip; +uniform float far_clip; + +uniform vec3 proj_origin; //origin of projection to be used for angular attenuation +uniform float sun_wash; +uniform int proj_shadow_idx; +uniform float shadow_fade; + +uniform float size; +uniform vec3 color; +uniform float falloff; + +VARYING vec3 trans_center; +VARYING vec4 vary_fragcoord; +uniform vec2 screen_res; + +uniform mat4 inv_proj; + +vec3 getNorm(vec2 pos_screen); + +vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) +{ +    vec4 ret = texture2DLod(projectionMap, tc, lod); +     +    vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); +     +    float det = min(lod/(proj_lod*0.5), 1.0); +     +    float d = min(dist.x, dist.y); +     +    d *= min(1, d * (proj_lod - lod)); +     +    float edge = 0.25*det; +     +    ret *= clamp(d/edge, 0.0, 1.0); +     +    return ret; +} + +vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) +{ +    vec4 ret = texture2DLod(projectionMap, tc, lod); +     +    vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); +     +    float det = min(lod/(proj_lod*0.5), 1.0); +     +    float d = min(dist.x, dist.y); +     +    float edge = 0.25*det; +         +    ret *= clamp(d/edge, 0.0, 1.0); +     +    return ret; +} + +vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) +{ +    vec4 ret = texture2DLod(projectionMap, tc, lod); +     +    vec2 dist = tc-vec2(0.5); +     +    float d = dot(dist,dist); +         +    ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); +     +    return ret; +} + + +vec4 getPosition(vec2 pos_screen); + +void main()  +{ +    vec4 frag = vary_fragcoord; +    frag.xyz /= frag.w; +    frag.xyz = frag.xyz*0.5+0.5; +    frag.xy *= screen_res; +     +    vec3 pos = getPosition(frag.xy).xyz; +    vec3 lv = trans_center.xyz-pos.xyz; +    float dist = length(lv); +    dist /= size; +    if (dist > 1.0) +    { +        discard; +    } +     +    float shadow = 1.0; +     +    if (proj_shadow_idx >= 0) +    { +        vec4 shd = texture2DRect(lightMap, frag.xy); +        shadow = (proj_shadow_idx == 0) ? shd.b : shd.a; +        shadow += shadow_fade; +        shadow = clamp(shadow, 0.0, 1.0); +    } +     +    vec3 norm = texture2DRect(normalMap, frag.xy).xyz; +    float envIntensity = norm.z; +    norm = getNorm(frag.xy); +     +    norm = normalize(norm); +    float l_dist = -dot(lv, proj_n); +     +    vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); +    if (proj_tc.z < 0.0) +    { +        discard; +    } +     +    proj_tc.xyz /= proj_tc.w; +     +    float fa = (falloff*0.5) + 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; + +    if (dist_atten <= 0.0) +    { +        discard; +    } +     +    lv = proj_origin-pos.xyz; +    lv = normalize(lv); +    float da = dot(norm, lv); +         +    vec3 col = vec3(0,0,0); +         +    vec3 diff_tex = srgb_to_linear(texture2DRect(diffuseRect, frag.xy).rgb); +         +    vec4 spec = texture2DRect(specularRect, frag.xy); + +    vec3 dlit = vec3(0, 0, 0); + +    float noise = texture2D(noiseMap, frag.xy/128.0).b; +    if (proj_tc.z > 0.0 && +        proj_tc.x < 1.0 && +        proj_tc.y < 1.0 && +        proj_tc.x > 0.0 && +        proj_tc.y > 0.0) +    { +        float amb_da = proj_ambiance; +        float lit = 0.0; +         +        if (da > 0.0) +        { +            lit = da * dist_atten * noise; + +            float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); +            float lod = diff * proj_lod; +             +            vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); +         +            dlit = color.rgb * plcol.rgb * plcol.a; +             +            col = dlit*lit*diff_tex*shadow; +            amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; +        } +         +        //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); +        vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); +                             +        amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance; +                 +        amb_da *= dist_atten * noise; +             +        amb_da = min(amb_da, 1.0-lit); +             +        col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; +    } +     + +    if (spec.a > 0.0) +    { +        dlit *= min(da*6.0, 1.0) * dist_atten; +        vec3 npos = -normalize(pos); + +        //vec3 ref = dot(pos+lv, norm); +        vec3 h = normalize(lv+npos); +        float nh = dot(norm, h); +        float nv = dot(norm, npos); +        float vh = dot(npos, h); +        float sa = nh; +        float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + +        float gtdenom = 2 * nh; +        float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); +                                 +        if (nh > 0.0) +        { +            float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); +            col += dlit*scol*spec.rgb*shadow; +        } +    }    +     + +    if (envIntensity > 0.0) +    { +        vec3 ref = reflect(normalize(pos), norm); +         +        //project from point pos in direction ref to plane proj_p, proj_n +        vec3 pdelta = proj_p-pos; +        float ds = dot(ref, proj_n); +         +        if (ds < 0.0) +        { +            vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; +             +            vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); + +            if (stc.z > 0.0) +            { +                stc /= stc.w; +                                 +                if (stc.x < 1.0 && +                    stc.y < 1.0 && +                    stc.x > 0.0 && +                    stc.y > 0.0) +                { +                    col += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; +                } +            } +        } +    } +     +    //not sure why, but this line prevents MATBUG-194 +    col = max(col, vec3(0.0)); + +    frag_color.rgb = col;    +    frag_color.a = 0.0; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl new file mode 100644 index 0000000000..112b498c90 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl @@ -0,0 +1,57 @@ +/**  + * @file class3\deferred\sunLightF.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$ + */ + +#extension GL_ARB_texture_rectangle : enable + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +//class 2, shadows, no SSAO + +// Inputs +VARYING vec2 vary_fragcoord; + +vec4 getPosition(vec2 pos_screen); +vec3 getNorm(vec2 pos_screen); + +float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen);  +float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen);  + +void main()  +{ +	vec2 pos_screen = vary_fragcoord.xy; +	vec4 pos = getPosition(pos_screen); +	vec3 norm = getNorm(pos_screen); + +	frag_color.r = sampleDirectionalShadow(pos.xyz, norm, pos_screen); +	frag_color.g = 1.0f; +    frag_color.b = sampleSpotShadow(pos.xyz, norm, 0, pos_screen); +    frag_color.a = sampleSpotShadow(pos.xyz, norm, 1, pos_screen); +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl new file mode 100644 index 0000000000..342a2ff3ed --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl @@ -0,0 +1,61 @@ +/**  + * @file class3\deferred\sunLightSSAOF.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$ + */ +  +#extension GL_ARB_texture_rectangle : enable + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +//class 2 -- shadows and SSAO + +// Inputs +VARYING vec2 vary_fragcoord; + +uniform vec3 sun_dir; + +vec4 getPosition(vec2 pos_screen); +vec3 getNorm(vec2 pos_screen); + +float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); +float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen); + +//calculate decreases in ambient lighting when crowded out (SSAO) +float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen); + +void main()  +{ +	vec2 pos_screen = vary_fragcoord.xy; +	vec4 pos        = getPosition(pos_screen); +	vec3 norm       = getNorm(pos_screen); + +	frag_color.r = sampleDirectionalShadow(pos.xyz, norm, pos_screen); +    frag_color.b = calcAmbientOcclusion(pos, norm, pos_screen); +    frag_color.b = sampleSpotShadow(pos.xyz, norm, 0, pos_screen); +    frag_color.a = sampleSpotShadow(pos.xyz, norm, 1, pos_screen); +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/sunLightV.glsl b/indra/newview/app_settings/shaders/class3/deferred/sunLightV.glsl new file mode 100644 index 0000000000..bc5eb5181d --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/sunLightV.glsl @@ -0,0 +1,41 @@ +/**  + * @file sunLightV.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 modelview_projection_matrix; + +ATTRIBUTE vec3 position; + +VARYING vec2 vary_fragcoord; + +uniform vec2 screen_res; + +void main() +{ +	//transform vertex +	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); +	gl_Position = pos;  +	 +	vary_fragcoord = (pos.xy * 0.5 + 0.5)*screen_res;	 +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/treeShadowF.glsl b/indra/newview/app_settings/shaders/class3/deferred/treeShadowF.glsl new file mode 100644 index 0000000000..41673d1669 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/treeShadowF.glsl @@ -0,0 +1,59 @@ +/**  + * @file treeShadowF.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$ + */ + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform float minimum_alpha; + +uniform sampler2D diffuseMap; + +VARYING vec4 pos; +VARYING vec2 vary_texcoord0; + +vec4 computeMoments(float d, float a); + +void main()  +{ +	float alpha = texture2D(diffuseMap, vary_texcoord0.xy).a; + +	if (alpha < minimum_alpha) +	{ +		discard; +	} + +    frag_color = computeMoments(length(pos), 1.0); + +#if !defined(DEPTH_CLAMP) +	gl_FragDepth = max(pos.z/pos.w*0.5+0.5, 0.0); +#endif + +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/treeShadowV.glsl b/indra/newview/app_settings/shaders/class3/deferred/treeShadowV.glsl new file mode 100644 index 0000000000..15e769ac10 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/treeShadowV.glsl @@ -0,0 +1,43 @@ +/**  + * @file treeShadowV.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_projection_matrix; +  +ATTRIBUTE vec3 position; +ATTRIBUTE vec2 texcoord0; + +VARYING vec4 pos; +VARYING vec2 vary_texcoord0; + +void main() +{ +	//transform vertex +	pos = modelview_projection_matrix*vec4(position.xyz, 1.0); + +	gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); +	 +	vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/underWaterF.glsl b/indra/newview/app_settings/shaders/class3/deferred/underWaterF.glsl new file mode 100644 index 0000000000..540226e672 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/underWaterF.glsl @@ -0,0 +1,115 @@ +/** + * @file underWaterF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + *  + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + *  + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * Lesser General Public License for more details. + *  + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA + *  + * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA + * $/LicenseInfo$ + */ +  +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_data[3]; +#else +#define frag_data gl_FragData +#endif + +uniform sampler2D diffuseMap; +uniform sampler2D bumpMap;    +uniform sampler2D screenTex; +uniform sampler2D refTex; +uniform sampler2D screenDepth; + +uniform vec4 fogCol; +uniform vec3 lightDir; +uniform vec3 specular; +uniform float lightExp; +uniform vec2 fbScale; +uniform float refScale; +uniform float znear; +uniform float zfar; +uniform float kd; +uniform vec4 waterPlane; +uniform vec3 eyeVec; +uniform vec4 waterFogColor; +uniform float waterFogDensity; +uniform float waterFogKS; +uniform vec2 screenRes; + +//bigWave is (refCoord.w, view.w); +VARYING vec4 refCoord; +VARYING vec4 littleWave; +VARYING vec4 view; + +vec2 encode_normal(vec3 n); + +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 color * D + kc * L; +} + +void main()  +{ +	vec4 color; +	     +	//get detail 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 wavef = normalize(wave1+wave2+wave3); +	 +	//figure out distortion vector (ripply)    +	vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; +	distort = distort+wavef.xy*refScale; +		 +	vec4 fb = texture2D(screenTex, distort); + +	frag_data[0] = vec4(fb.rgb, 1.0); // diffuse +	frag_data[1] = vec4(0.5,0.5,0.5, 0.95); // speccolor*spec, spec +	frag_data[2] = vec4(encode_normal(wavef), 0.0, 0.0); // normalxyz, displace +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class3/deferred/waterF.glsl new file mode 100644 index 0000000000..c65cf48c67 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/waterF.glsl @@ -0,0 +1,174 @@ +/**  + * @file waterF.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$ + */ +  +#extension GL_ARB_texture_rectangle : enable + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_data[3]; +#else +#define frag_data gl_FragData +#endif + +uniform sampler2D bumpMap;    +uniform sampler2D bumpMap2; +uniform float blend_factor; +uniform sampler2D screenTex; +uniform sampler2D refTex; + +uniform float sunAngle; +uniform float sunAngle2; +uniform vec3 lightDir; +uniform vec3 specular; +uniform float lightExp; +uniform float refScale; +uniform float kd; +uniform vec2 screenRes; +uniform vec3 normScale; +uniform float fresnelScale; +uniform float fresnelOffset; +uniform float blurMultiplier; +uniform vec2 screen_res; +uniform mat4 norm_mat; //region space to screen space + +//bigWave is (refCoord.w, view.w); +VARYING vec4 refCoord; +VARYING vec4 littleWave; +VARYING vec4 view; +VARYING vec4 vary_position; + +vec3 scaleSoftClip(vec3 c); +vec2 encode_normal(vec3 n); + +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; +	float dist = length(view.xy); +	 +	//normalize view vector +	vec3 viewVec = normalize(view.xyz); +	 +	//get wave normals +	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( +					dot(viewVec, wave1), +					dot(viewVec, (wave2 + wave3) * 0.5), +					dot(viewVec, wave3) +				 ) * fresnelScale + fresnelOffset; +	df *= df; +		     +	vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; +	 +	float dist2 = dist; +	dist = max(dist, 5.0); +	 +	float dmod = sqrt(dist); +	 +	vec2 dmod_scale = vec2(dmod*dmod, dmod); +	 +	//get reflected color +	vec2 refdistort1 = wave1.xy*normScale.x; +	vec2 refvec1 = distort+refdistort1/dmod_scale; +	vec4 refcol1 = texture2D(refTex, refvec1); +	 +	vec2 refdistort2 = wave2.xy*normScale.y; +	vec2 refvec2 = distort+refdistort2/dmod_scale; +	vec4 refcol2 = texture2D(refTex, refvec2); +	 +	vec2 refdistort3 = wave3.xy*normScale.z; +	vec2 refvec3 = distort+refdistort3/dmod_scale; +	vec4 refcol3 = texture2D(refTex, refvec3); + +	vec4 refcol = refcol1 + refcol2 + refcol3; +	float df1 = df.x + df.y + df.z; +	refcol *= df1 * 0.333; +	 +	vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; +	wavef.z *= max(-viewVec.z, 0.1); +	wavef = normalize(wavef); +	 +	float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset; +	 +	vec2 refdistort4 = wavef.xy*0.125; +	refdistort4.y -= abs(refdistort4.y); +	vec2 refvec4 = distort+refdistort4/dmod; +	float dweight = min(dist2*blurMultiplier, 1.0); +	vec4 baseCol = texture2D(refTex, refvec4); + +	refcol = mix(baseCol*df2, refcol, dweight); + +	//get specular component +	float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); +		 +	//harden specular +	spec = pow(spec, 128.0); + +	//figure out distortion vector (ripply)    +	vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); +		 +	vec4 fb = texture2D(screenTex, distort2); +	 +	//mix with reflection +	// Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug +	color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999); + +    color.rgb *= 2.0f; +    color.rgb = scaleSoftClip(color.rgb); +	 +	vec4 pos = vary_position; +	 +	color.rgb += spec * specular; +	color.a    = spec * sunAngle2; +     +	vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); +	 +	frag_data[0] = vec4(color.rgb, color); // diffuse +	frag_data[1] = vec4(spec * specular, spec);		// speccolor, spec +	frag_data[2] = vec4(encode_normal(wavef.xyz), 0.05, 0);// normalxy, 0, 0 +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/waterV.glsl b/indra/newview/app_settings/shaders/class3/deferred/waterV.glsl new file mode 100644 index 0000000000..02000d90ca --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/waterV.glsl @@ -0,0 +1,95 @@ +/**  + * @file waterV.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 modelview_matrix; +uniform mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; + + +uniform vec2 d1; +uniform vec2 d2; +uniform float time; +uniform vec3 eyeVec; +uniform float waterHeight; + +VARYING vec4 refCoord; +VARYING vec4 littleWave; +VARYING vec4 view; + +VARYING vec4 vary_position; + +float wave(vec2 v, float t, float f, vec2 d, float s)  +{ +   return (dot(d, v)*f + t*s)*f; +} + +void main() +{ +	//transform vertex +	vec4 pos = vec4(position.xyz, 1.0); +	mat4 modelViewProj = modelview_projection_matrix; +	 +	vec4 oPosition; +		     +	//get view vector +	vec3 oEyeVec; +	oEyeVec.xyz = pos.xyz-eyeVec; +		 +	float d = length(oEyeVec.xy); +	float ld = min(d, 2560.0); +	 +	pos.xy = eyeVec.xy + oEyeVec.xy/d*ld; +	view.xyz = oEyeVec; +		 +	d = clamp(ld/1536.0-0.5, 0.0, 1.0);	 +	d *= d; +		 +	oPosition = vec4(position, 1.0); +	oPosition.z = mix(oPosition.z, max(eyeVec.z*0.75, 0.0), d); +	vary_position = modelview_matrix * oPosition; +	oPosition = modelViewProj * oPosition; +	 +	refCoord.xyz = oPosition.xyz + vec3(0,0,0.2); +	 +	//get wave position parameter (create sweeping horizontal waves) +	vec3 v = pos.xyz; +	v.x += (cos(v.x*0.08/*+time*0.01*/)+sin(v.y*0.02))*6.0; +	     +	//push position for further horizon effect. +	pos.xyz = oEyeVec.xyz*(waterHeight/oEyeVec.z); +	pos.w = 1.0; +	pos = modelview_matrix*pos; +	 +	//pass wave parameters to pixel shader +	vec2 bigWave =  (v.xy) * vec2(0.04,0.04)  + d1 * time * 0.055; +	//get two normal map (detail map) texture coordinates +	littleWave.xy = (v.xy) * vec2(0.45, 0.9)   + d2 * time * 0.13; +	littleWave.zw = (v.xy) * vec2(0.1, 0.2) + d1 * time * 0.1; +	view.w = bigWave.y; +	refCoord.w = bigWave.x; +	 +	gl_Position = oPosition; +} diff --git a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl new file mode 100644 index 0000000000..30ad493331 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl @@ -0,0 +1,43 @@ +/**  + * @file class3\lighting\lightV.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$ + */ +  + + +// All lights, no specular highlights +vec3 atmosAmbient(); +vec4 sumLights(vec3 pos, vec3 norm, vec4 color); +float getAmbientClamp(); + +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color) +{ +	vec4 c = sumLights(pos, norm, color); + +#if !defined(AMBIENT_KILL) +    c.rgb += atmosAmbient() * color.rgb * getAmbientClamp(); +#endif +  +    return c; +} + diff --git a/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl b/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl index e043ac873e..c1aee69c30 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl @@ -1,5 +1,5 @@  /** - * @file sumLightsV.glsl + * @file class3\lighting\sumLightsSpecularV.glsl   *   * $LicenseInfo:firstyear=2005&license=viewerlgpl$   * Second Life Viewer Source Code @@ -26,16 +26,16 @@  float calcDirectionalLightSpecular(inout vec4 specular, vec3 view, vec3 n, vec3 l, vec3 lightCol, float da);  vec3 calcPointLightSpecular(inout vec4 specular, vec3 view, vec3 v, vec3 n, vec3 l, float r, float pw, vec3 lightCol); -vec3 atmosAmbient(vec3 light); +vec3 atmosAmbient();  vec3 atmosAffectDirectionalLight(float lightIntensity);  vec3 atmosGetDiffuseSunlightColor();  vec3 scaleDownLight(vec3 light);  uniform vec4 light_position[8]; -uniform vec3 light_attenuation[8];  +uniform vec4 light_attenuation[8];   uniform vec3 light_diffuse[8]; -vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol) +vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor)  {  	vec4 col = vec4(0.0, 0.0, 0.0, color.a); @@ -55,8 +55,8 @@ vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor  	col.rgb = scaleDownLight(col.rgb);  	// Add windlight lights -	col.rgb += atmosAmbient(baseCol.rgb); -	col.rgb += atmosAffectDirectionalLight(calcDirectionalLightSpecular(specularSum, view, norm, light_position[0].xyz,atmosGetDiffuseSunlightColor()*baseCol.a, 1.0)); +	col.rgb += atmosAmbient(); +	col.rgb += atmosAffectDirectionalLight(calcDirectionalLightSpecular(specularSum, view, norm, light_position[0].xyz,atmosGetDiffuseSunlightColor(), 1.0));  	col.rgb = min(col.rgb*color.rgb, 1.0);  	specularColor.rgb = min(specularColor.rgb*specularSum.rgb, 1.0); diff --git a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl index dadff40933..4b663dd5b2 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl @@ -1,5 +1,5 @@  /** - * @file sumLightsV.glsl + * @file class3\lighting\sumLightsV.glsl   *   * $LicenseInfo:firstyear=2005&license=viewerlgpl$   * Second Life Viewer Source Code @@ -25,37 +25,40 @@  float calcDirectionalLight(vec3 n, vec3 l); -float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float is_pointlight); +float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight); -vec3 atmosAmbient(vec3 light);  vec3 atmosAffectDirectionalLight(float lightIntensity);  vec3 scaleDownLight(vec3 light); -vec3 scaleUpLight(vec3 light);  uniform vec4 light_position[8];  uniform vec3 light_direction[8]; -uniform vec3 light_attenuation[8];  +uniform vec4 light_attenuation[8];   uniform vec3 light_diffuse[8]; -vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) +vec4 sumLights(vec3 pos, vec3 norm, vec4 color)  {  	vec4 col = vec4(0.0, 0.0, 0.0, color.a);  	// Collect normal lights (need to be divided by two, as we later multiply by 2)  	// Collect normal lights -	col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].z); -	col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].z); -	col.rgb += light_diffuse[4].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[4], light_direction[4], light_attenuation[4].x, light_attenuation[4].z); -	col.rgb += light_diffuse[5].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[5], light_direction[5], light_attenuation[5].x, light_attenuation[5].z); -	col.rgb += light_diffuse[6].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[6], light_direction[6], light_attenuation[6].x, light_attenuation[6].z); -	col.rgb += light_diffuse[7].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[7], light_direction[7], light_attenuation[7].x, light_attenuation[7].z); +	col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].y, light_attenuation[2].z); +	col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].y, light_attenuation[3].z); +	col.rgb += light_diffuse[4].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[4], light_direction[4], light_attenuation[4].x, light_attenuation[4].y, light_attenuation[4].z); +	col.rgb += light_diffuse[5].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[5], light_direction[5], light_attenuation[5].x, light_attenuation[5].y, light_attenuation[5].z); +	col.rgb += light_diffuse[6].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[6], light_direction[6], light_attenuation[6].x, light_attenuation[6].y, light_attenuation[6].z); +	col.rgb += light_diffuse[7].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[7], light_direction[7], light_attenuation[7].x, light_attenuation[7].y, light_attenuation[7].z);  	col.rgb += light_diffuse[1].rgb*calcDirectionalLight(norm, light_position[1].xyz); -	col.rgb = scaleDownLight(col.rgb); +    col.rgb = scaleDownLight(col.rgb); + +#if defined(LOCAL_LIGHT_KILL) +    col.rgb = vec3(0); +#endif  	// Add windlight lights +#if !defined(SUNLIGHT_KILL)  	col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); -	col.rgb += atmosAmbient(baseLight.rgb); +#endif  	col.rgb = min(col.rgb*color.rgb, 1.0); 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..c6ea3ec9d4 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl @@ -0,0 +1,73 @@ +/**  + * @file class3\wl\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 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..65bb00b1f6 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoV.glsl @@ -0,0 +1,43 @@ +/**  + * @file class3\wl\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..2b70ba76dc --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl @@ -0,0 +1,46 @@ +/**  + * @file class3\wl\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(); +vec3 scaleSoftClipFrag(vec3 light); + +uniform int no_atmo; + +vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) +{ +    if (no_atmo == 1) +    { +        return light; +    } +    light *= atten.r; +    light += additive; +    return light * 2.0; +} + +vec3 atmosLighting(vec3 light) +{ +    return atmosFragLighting(light, getAdditiveColor(), getAtmosAttenuation()); +} 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..b76192d73f --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl @@ -0,0 +1,51 @@ +/** + * @file class3\wl\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(); + +void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); + +void calcAtmospherics(vec3 inPositionEye) { + +    vec3 P = inPositionEye; +    setPositionEye(P); +    vec3 tmpsunlit = vec3(1); +    vec3 tmpamblit = vec3(1); +    vec3 tmpaddlit = vec3(1); +    vec3 tmpattenlit = vec3(1); +    calcAtmosphericVars(inPositionEye, vec3(0), 1, tmpsunlit, tmpamblit, tmpaddlit, tmpattenlit, true); +    setSunlitColor(tmpsunlit); +    setAmblitColor(tmpamblit); +    setAdditiveColor(tmpaddlit); +    setAtmosAttenuation(tmpattenlit); +} + 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..aa7dbc39ce --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl @@ -0,0 +1,67 @@ +/**  + * @file class3\wl\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 int no_atmo; + +vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) +{ +    if (no_atmo == 1) +    { +        return light; +    } +    // fullbright responds minimally to atmos scatter effects  +    light *= min(15.0 * atten.r, 1.0); +    light += (0.1 * additive); +    return light * 2.0; +} + +vec3 atmosTransport(vec3 light) +{ +     return atmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); +} + +vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) +{ +    float brightness = dot(light.rgb, vec3(0.33333)); +    return atmosTransportFrag(light * 0.5, additive * (brightness * 0.5 + 0.5), atten); +} + +vec3 fullbrightAtmosTransport(vec3 light) +{ +    return atmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); +} + +vec3 fullbrightShinyAtmosTransport(vec3 light) +{ +    float brightness = dot(light.rgb, vec3(0.33333)); +    return atmosTransportFrag(light * 0.5, getAdditiveColor() * (brightness * brightness), getAtmosAttenuation()); +} diff --git a/indra/newview/app_settings/shaders/shader_hierarchy.txt b/indra/newview/app_settings/shaders/shader_hierarchy.txt index d8bbf69b38..8ef04d8e1f 100644 --- a/indra/newview/app_settings/shaders/shader_hierarchy.txt +++ b/indra/newview/app_settings/shaders/shader_hierarchy.txt @@ -1,3 +1,9 @@ +Class 3 is highest quality / lowest  performance +Class 2 is medium  quality / medium  performance +Class 1 is lowest  quality / highest performance + +Shaders WILL fall back to "lower" classes for functionality. +  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  avatar/avatarV.glsl - gAvatarProgram, gAvatarWaterProgram  	main() - avatar/avatarV.glsl @@ -7,7 +13,6 @@ avatar/avatarV.glsl - gAvatarProgram, gAvatarWaterProgram  			sumLights() - lighting/sumLightsV.glsl  				calcDirectionalLight() - lighting/lightFuncV.glsl  				calcPointLight() - lighting/lightFuncV.glsl -				scaleDownLight() - windlight/atmosphericsHelpersV.glsl  				atmosAmbient() - windlight/atmosphericsHelpersV.glsl  				atmosAffectDirectionalLight() - windlight/atmosphericsHelpersV.glsl  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -28,7 +33,6 @@ avatar/eyeballV.glsl - gAvatarEyeballProgram  				atmosAmbient() - windlight/atmosphericsHelpersV.glsl  				atmosAffectDirectionalLight() - windlight/atmosphericsHelpersV.glsl  				atmosGetDiffuseSunlightColor() - windlight/atmosphericsHelpersV.glsl -				scaleDownLight() - windlight/atmosphericsHelpersV.glsl  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  avatar/eyeballF.glsl - gAvatarEyeballProgram  	main() - avatar/eyeballF.glsl @@ -53,7 +57,6 @@ environment/terrainV.glsl - gTerrainProgram, gTerrainWaterProgram  			sumLights() - lighting/sumLightsV.glsl  				calcDirectionalLight() - lighting/lightFuncV.glsl  				calcPointLight() - lighting/lightFuncV.glsl -				scaleDownLight() - windlight/atmosphericsHelpersV.glsl  				atmosAmbient() - windlight/atmosphericsHelpersV.glsl  				atmosAffectDirectionalLight() - windlight/atmosphericsHelpersV.glsl  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -120,7 +123,6 @@ objects/shinyV.glsl - gObjectShinyProgram, gObjectShinyWaterProgram  				sumLights() - lighting/sumLightsV.glsl  					calcDirectionalLight() - lighting/lightFuncV.glsl  					calcPointLight() - lighting/lightFuncV.glsl -					scaleDownLight() - windlight/atmosphericsHelpersV.glsl  					atmosAmbient() - windlight/atmosphericsHelpersV.glsl  					atmosAffectDirectionalLight() - windlight/atmosphericsHelpersV.glsl  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -143,7 +145,6 @@ objects/simpleV.glsl - gObjectSimpleProgram, gObjectSimpleWaterProgram  			sumLights() - lighting/sumLightsV.glsl  				calcDirectionalLight() - lighting/lightFuncV.glsl  				calcPointLight() - lighting/lightFuncV.glsl -				scaleDownLight() - windlight/atmosphericsHelpersV.glsl  				atmosAmbient() - windlight/atmosphericsHelpersV.glsl  				atmosAffectDirectionalLight() - windlight/atmosphericsHelpersV.glsl  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
