diff options
| author | Aura Linden <aura@lindenlab.com> | 2013-07-11 17:49:13 -0700 | 
|---|---|---|
| committer | Aura Linden <aura@lindenlab.com> | 2013-07-11 17:49:13 -0700 | 
| commit | ce9962b33872db65b70c9b10901ec9062cb59169 (patch) | |
| tree | 94be5367128e241ef1c6f802e8551a9b4ed786ff /indra/newview/app_settings/shaders/class1/deferred | |
| parent | 8642f57dd95864ec6b002f6519701f30866c6502 (diff) | |
| parent | 6060e5e46acbeb20a301070a0fd0efea029d33d0 (diff) | |
Merged in viewer-release
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/deferred')
82 files changed, 2037 insertions, 197 deletions
| diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index dd87ddb330..0899caa2af 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -25,17 +25,33 @@  #extension GL_ARB_texture_rectangle : enable +#define INDEXED 1 +#define NON_INDEXED 2 +#define NON_INDEXED_NO_COLOR 3 +  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_color;  #else  #define frag_color gl_FragColor  #endif -uniform sampler2DRect depthMap; +#if HAS_SHADOW +uniform sampler2DShadow shadowMap0; +uniform sampler2DShadow shadowMap1; +uniform sampler2DShadow shadowMap2; +uniform sampler2DShadow shadowMap3; -vec4 diffuseLookup(vec2 texcoord); +uniform vec2 shadow_res; -uniform vec2 screen_res; +uniform mat4 shadow_matrix[6]; +uniform vec4 shadow_clip; +uniform float shadow_bias; + +#endif + +#ifdef USE_DIFFUSE_TEX +uniform sampler2D diffuseMap; +#endif  vec3 atmosLighting(vec3 light);  vec3 scaleSoftClip(vec3 light); @@ -45,11 +61,80 @@ VARYING vec3 vary_directional;  VARYING vec3 vary_fragcoord;  VARYING vec3 vary_position;  VARYING vec3 vary_pointlight_col; +VARYING vec2 vary_texcoord0; +VARYING vec3 vary_norm; +#ifdef USE_VERTEX_COLOR  VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; +#endif + +uniform vec4 light_position[8]; +uniform vec3 light_direction[8]; +uniform vec3 light_attenuation[8];  +uniform vec3 light_diffuse[8]; + +uniform vec2 screen_res; + +vec3 calcDirectionalLight(vec3 n, vec3 l) +{ +	float a = max(dot(n,l),0.0); +	a = pow(a, 1.0/1.3); +	return vec3(a,a,a); +} + +vec3 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 = length(lv); +	 +	float da = 0.0; + +	if (d > 0.0 && la > 0.0 && fa > 0.0) +	{ +		//normalize light vector +		lv = normalize(lv); +	 +		//distance attenuation +		float dist = d/la; +		da = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); +		da *= da; +		da *= 1.4; +	 + +		// 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 vec3(da,da,da);	 +} + +#if HAS_SHADOW +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; +} +#endif -uniform mat4 inv_proj;  void main()   { @@ -58,16 +143,123 @@ void main()  	vec4 pos = vec4(vary_position, 1.0); -	vec4 diff= diffuseLookup(vary_texcoord0.xy); -	vec4 col = vec4(vary_ambient + vary_directional.rgb, vertex_color.a); -	vec4 color = diff * col; +#if HAS_SHADOW +	float shadow = 0.0; +	vec4 spos = pos; +		 +	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; +	} +#endif + +#ifdef USE_INDEXED_TEX +	vec4 diff = diffuseLookup(vary_texcoord0.xy); +#else +	vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); +#endif +	vec4 gamma_diff = diff; + +	diff.rgb = pow(diff.rgb, vec3(2.2f, 2.2f, 2.2f)); + +#ifdef USE_VERTEX_COLOR +	float vertex_color_alpha = vertex_color.a;	 +#else +	float vertex_color_alpha = 1.0; +#endif +	 +	vec3 normal = vary_norm;  +	 +	vec3 l = light_position[0].xyz; +	vec3 dlight = calcDirectionalLight(normal, l); +	dlight = dlight * vary_directional.rgb * vary_pointlight_col; + +#if HAS_SHADOW +	vec4 col = vec4(vary_ambient + dlight * shadow, vertex_color_alpha); +#else +	vec4 col = vec4(vary_ambient + dlight, vertex_color_alpha); +#endif + +	vec4 color = gamma_diff * col;  	color.rgb = atmosLighting(color.rgb);  	color.rgb = scaleSoftClip(color.rgb); -	color.rgb += diff.rgb * vary_pointlight_col.rgb; +	color.rgb = pow(color.rgb, vec3(2.2)); +	col = vec4(0,0,0,0); + +	 +   #define LIGHT_LOOP(i) col.rgb += light_diffuse[i].rgb * calcPointLightOrSpotLight(pos.xyz, normal, 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) + +	color.rgb += diff.rgb * pow(vary_pointlight_col, vec3(2.2)) * col.rgb; + +	color.rgb = pow(color.rgb, vec3(1.0/2.2));  	frag_color = color;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl index beb3290187..2ce44d599f 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl @@ -47,9 +47,51 @@ VARYING vec3 vary_position;  VARYING vec3 vary_pointlight_col;  VARYING vec2 vary_texcoord0;  VARYING vec4 vertex_color; +VARYING vec3 vary_norm;  uniform mat4 inv_proj; +uniform vec4 light_position[8]; +uniform vec3 light_direction[8]; +uniform vec3 light_attenuation[8];  +uniform vec3 light_diffuse[8]; + +vec3 calcDirectionalLight(vec3 n, vec3 l) +{ +        float a = pow(max(dot(n,l),0.0), 0.7); +        return vec3(a,a,a); +} + +vec3 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(pow(dot(n, lv), 0.7), 0.0);		 +	} + +	return vec3(da,da,da);	 +} +  vec4 getPosition(vec2 pos_screen)  {  	float depth = texture2DRect(depthMap, pos_screen.xy).a; @@ -72,14 +114,33 @@ void main()  	vec4 diff= texture2D(diffuseMap,vary_texcoord0.xy); -	vec4 col = vec4(vary_ambient + vary_directional.rgb, vertex_color.a); +	vec3 n = vary_norm; +	vec3 l = light_position[0].xyz; +	vec3 dlight = calcDirectionalLight(n, l); +	dlight = dlight * vary_directional.rgb * vary_pointlight_col; + +	vec4 col = vec4(vary_ambient + dlight, vertex_color.a);  	vec4 color = diff * col;  	color.rgb = atmosLighting(color.rgb);  	color.rgb = scaleSoftClip(color.rgb); +	vec3 light_col = vec3(0,0,0); + +  #define LIGHT_LOOP(i) \ +	light_col += light_diffuse[i].rgb * calcPointLightOrSpotLight(pos.xyz, vary_norm, light_position[i], light_direction[i], 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) + +	color.rgb += diff.rgb * vary_pointlight_col * light_col; -	color.rgb += diff.rgb * vary_pointlight_col.rgb; +	color.rgb = pow(color.rgb, vec3(1.0/2.2));  	frag_color = color;  	//frag_color = vec4(1,0,1,1); diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedNoColorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedNoColorF.glsl index 1113a9845b..1113a9845b 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedNoColorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedNoColorF.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaSkinnedV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaSkinnedV.glsl index 5a0e8ff684..5f93986f1d 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaSkinnedV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaSkinnedV.glsl @@ -46,6 +46,7 @@ VARYING vec3 vary_pointlight_col;  VARYING vec4 vertex_color;  VARYING vec2 vary_texcoord0; +VARYING vec3 vary_norm;  uniform float near_clip; @@ -104,7 +105,7 @@ void main()  	norm = position.xyz + normal.xyz;  	norm = normalize(( trans*vec4(norm, 1.0) ).xyz-pos.xyz); -	 +	vary_norm = norm;  	vec4 frag_pos = projection_matrix * pos;  	gl_Position = frag_pos; @@ -112,27 +113,18 @@ void main()  	calcAtmospherics(pos.xyz); +	//vec4 color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.));  	vec4 col = vec4(0.0, 0.0, 0.0, diffuse_color.a); - -	// 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].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); - -	vary_pointlight_col = col.rgb*diffuse_color.rgb; - +	vary_pointlight_col = diffuse_color.rgb;  	col.rgb = vec3(0,0,0);  	// Add windlight lights  	col.rgb = atmosAmbient(vec3(0.));  	vary_ambient = col.rgb*diffuse_color.rgb; -	vary_directional = diffuse_color.rgb*atmosAffectDirectionalLight(max(calcDirectionalLight(norm, light_position[0].xyz), (1.0-diffuse_color.a)*(1.0-diffuse_color.a))); +	vary_directional.rgb = atmosAffectDirectionalLight(1); -	col.rgb = min(col.rgb*diffuse_color.rgb, 1.0); +	col.rgb = col.rgb*diffuse_color.rgb;  	vertex_color = col; diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index cf38a2f4f7..9d3ba564cd 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -23,22 +23,41 @@   * $/LicenseInfo$   */ +#define INDEXED 1 +#define NON_INDEXED 2 +#define NON_INDEXED_NO_COLOR 3 +  uniform mat3 normal_matrix;  uniform mat4 texture_matrix0; +uniform mat4 projection_matrix;  uniform mat4 modelview_matrix;  uniform mat4 modelview_projection_matrix;  ATTRIBUTE vec3 position; + +#ifdef USE_INDEXED_TEX  void passTextureIndex(); +#endif +  ATTRIBUTE vec3 normal; + +#ifdef USE_VERTEX_COLOR  ATTRIBUTE vec4 diffuse_color; +#endif +  ATTRIBUTE vec2 texcoord0; +#ifdef HAS_SKIN +mat4 getObjectSkinnedTransform(); +#else +#ifdef IS_AVATAR_SKIN +mat4 getSkinnedTransform(); +#endif +#endif +  vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol);  void calcAtmospherics(vec3 inPositionEye); -float calcDirectionalLight(vec3 n, vec3 l); -  vec3 atmosAmbient(vec3 light);  vec3 atmosAffectDirectionalLight(float lightIntensity);  vec3 scaleDownLight(vec3 light); @@ -50,26 +69,24 @@ VARYING vec3 vary_fragcoord;  VARYING vec3 vary_position;  VARYING vec3 vary_pointlight_col; +#ifdef USE_VERTEX_COLOR  VARYING vec4 vertex_color; +#endif +  VARYING vec2 vary_texcoord0; +VARYING vec3 vary_norm;  uniform float near_clip; -uniform float shadow_offset; -uniform float shadow_bias;  uniform vec4 light_position[8];  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; -} +uniform vec3 sun_dir; -float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) +vec3 calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight)  {  	//get light vector  	vec3 lv = lp.xyz-v; @@ -96,53 +113,110 @@ float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, floa  		da *= max(dot(n, lv), 0.0);		  	} -	return da;	 +	return vec3(da,da,da);	  }  void main()  { +	vec4 pos; +	vec3 norm; +	  	//transform vertex +#ifdef HAS_SKIN +	mat4 trans = getObjectSkinnedTransform(); +	trans = modelview_matrix * trans; +	 +	pos = trans * vec4(position.xyz, 1.0); +	 +	norm = position.xyz + normal.xyz; +	norm = normalize((trans * vec4(norm, 1.0)).xyz - pos.xyz); +	vec4 frag_pos = projection_matrix * pos; +	gl_Position = frag_pos; +#else + +#ifdef IS_AVATAR_SKIN +	mat4 trans = getSkinnedTransform(); +	vec4 pos_in = vec4(position.xyz, 1.0); +	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); +	 +	vec4 frag_pos = projection_matrix * pos; +	gl_Position = frag_pos; +#else +	norm = normalize(normal_matrix * normal);  	vec4 vert = vec4(position.xyz, 1.0); -	passTextureIndex(); -	vec4 pos = (modelview_matrix * vert); +	pos = (modelview_matrix * vert);  	gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); +#endif +#endif + +#ifdef USE_INDEXED_TEX +	passTextureIndex();  	vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; +#else +	vary_texcoord0 = texcoord0; +#endif -	vec3 norm = normalize(normal_matrix * normal); -	 -	float dp_directional_light = max(0.0, dot(norm, light_position[0].xyz)); -	vary_position = pos.xyz + light_position[0].xyz * (1.0-dp_directional_light)*shadow_offset; -		 +	vary_norm = norm; +	vary_position = pos.xyz; +  	calcAtmospherics(pos.xyz); +#ifndef USE_VERTEX_COLOR +	vec4 diffuse_color = vec4(1,1,1,1); +#endif  	//vec4 color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.));  	vec4 col = vec4(0.0, 0.0, 0.0, diffuse_color.a); +	 +	vec3 diff = diffuse_color.rgb; + +	 + +	vary_pointlight_col = diff; -	// 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].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); -	vary_pointlight_col = col.rgb*diffuse_color.rgb;  	col.rgb = vec3(0,0,0);  	// Add windlight lights -	col.rgb = atmosAmbient(vec3(0.)); +	col.rgb = atmosAmbient(col.rgb); -	vary_ambient = col.rgb*diffuse_color.rgb; -	vary_directional.rgb = diffuse_color.rgb*atmosAffectDirectionalLight(max(calcDirectionalLight(norm, light_position[0].xyz), (1.0-diffuse_color.a)*(1.0-diffuse_color.a))); +	float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); +	ambient *= 0.5; +	ambient *= ambient; +	ambient = (1.0-ambient); + +	col.rgb *= ambient; + +	vary_ambient = col.rgb*diff.rgb; + +	vary_directional.rgb = atmosAffectDirectionalLight(1.0f); -	col.rgb = col.rgb*diffuse_color.rgb; +	col.rgb = col.rgb*diff.rgb; +#ifdef USE_VERTEX_COLOR  	vertex_color = col; - -	 +#endif +#ifdef HAS_SKIN +	vary_fragcoord.xyz = frag_pos.xyz + vec3(0,0,near_clip); +#else + +#ifdef IS_AVATAR_SKIN +	vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip); +#else  	pos = modelview_projection_matrix * vert;  	vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip); +#endif +#endif +  } + diff --git a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowF.glsl index 22c9a4d14e..22c9a4d14e 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowF.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowV.glsl index 81961d7746..3f90600ace 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowV.glsl @@ -39,7 +39,12 @@ void main()  	mat = modelview_matrix * mat;  	vec3 pos = (mat*vec4(position.xyz, 1.0)).xyz; +  	vec4 p = projection_matrix * vec4(pos, 1.0); +#if !DEPTH_CLAMP  	p.z = max(p.z, -p.w+0.01);  	gl_Position = p; +#else +	gl_Position = p; +#endif  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl index 5f395801e5..c8ddefac26 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl @@ -47,6 +47,7 @@ VARYING vec3 vary_directional;  VARYING vec3 vary_fragcoord;  VARYING vec3 vary_pointlight_col;  VARYING vec2 vary_texcoord0; +VARYING vec3 vary_norm;  uniform float near_clip; @@ -112,6 +113,7 @@ void main()  	norm.y = dot(trans[1].xyz, normal);  	norm.z = dot(trans[2].xyz, normal);  	norm = normalize(norm); +	vary_norm = norm;  	vec4 frag_pos = projection_matrix * pos;  	gl_Position = frag_pos; diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaV.glsl index d6149fcc32..d6149fcc32 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaV.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarEyesV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarEyesV.glsl index 01ffb862f7..01ffb862f7 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarEyesV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarEyesV.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl index bfd9b9b3eb..bcccbf77d2 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl @@ -34,6 +34,12 @@ 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; +} +  void main()   {  	vec4 diff = texture2D(diffuseMap, vary_texcoord0.xy); @@ -46,6 +52,6 @@ void main()  	frag_data[0] = vec4(diff.rgb, 0.0);  	frag_data[1] = vec4(0,0,0,0);  	vec3 nvn = normalize(vary_normal); -	frag_data[2] = vec4(nvn.xyz * 0.5 + 0.5, 0.0); +	frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 0.0);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl index 3686f2f647..b809b73973 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl @@ -31,12 +31,16 @@ out vec4 frag_color;  uniform sampler2D diffuseMap; +#if !DEPTH_CLAMP  VARYING vec4 post_pos; +#endif  void main()   {  	frag_color = vec4(1,1,1,1); +#if !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 23feb09d72..bde1ad4e9f 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl @@ -31,7 +31,9 @@ ATTRIBUTE vec3 position;  ATTRIBUTE vec3 normal;  ATTRIBUTE vec2 texcoord0; +#if !DEPTH_CLAMP  VARYING vec4 post_pos; +#endif  void main()  { @@ -51,9 +53,13 @@ void main()  	norm = normalize(norm);  	pos = projection_matrix * pos; +#if !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/class1/deferred/avatarV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarV.glsl index 1bd8fee7c9..1bd8fee7c9 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarV.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index f400eb7a5b..968a5f6b3d 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -46,11 +46,6 @@ VARYING vec2 vary_fragcoord;  uniform mat4 inv_proj;  uniform vec2 screen_res; -vec3 getKern(int i) -{ -	return kern[i]; -} -  vec4 getPosition(vec2 pos_screen)  {  	float depth = texture2DRect(depthMap, pos_screen.xy).r; @@ -64,18 +59,53 @@ vec4 getPosition(vec2 pos_screen)  	return pos;  } +#ifdef SINGLE_FP_ONLY +vec2 encode_normal(vec3 n) +{ +	vec2 sn; +	sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); +	return sn; +} + +vec3 decode_normal (vec2 enc) +{ +	vec3 n; +	n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); +	n.z = sqrt(1.0f - dot(n.xy,n.xy)); +	return n; +} +#else +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; +} +#endif +  void main()   {      vec2 tc = vary_fragcoord.xy;  	vec3 norm = texture2DRect(normalMap, tc).xyz; -	norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm +	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 = getKern(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' +	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 @@ -85,28 +115,33 @@ void main()  	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) * getKern(1).z * dlt * 0.5 ); +	tc += ( (tc_mod - 0.5) * kern[1].z * dlt * 0.5 );  	for (int i = 1; i < 4; i++)  	{ -		vec2 samptc = tc + getKern(i).z*dlt; -	        vec3 samppos = getPosition(samptc).xyz;  +		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)*getKern(i).xyxx; -			defined_weight += getKern(i).xy; +			col += texture2DRect(lightMap, samptc)*kern[i].xyxx; +			defined_weight += kern[i].xy;  		}  	} +  	for (int i = 1; i < 4; i++)  	{ -		vec2 samptc = tc - getKern(i).z*dlt; -	        vec3 samppos = getPosition(samptc).xyz;  +		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)*getKern(i).xyxx; -			defined_weight += getKern(i).xy; +			col += texture2DRect(lightMap, samptc)*kern[i].xyxx; +			defined_weight += kern[i].xy;  		}  	} diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightV.glsl index 212f7e56ad..212f7e56ad 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightV.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl index 23c4ea2fff..595c11fae2 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl @@ -39,6 +39,12 @@ 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; +} +  void main()   {  	vec3 col = vertex_color.rgb * texture2D(diffuseMap, vary_texcoord0.xy).rgb; @@ -52,5 +58,5 @@ void main()  	frag_data[1] = vertex_color.aaaa; // spec  	//frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested  	vec3 nvn = normalize(tnorm); -	frag_data[2] = vec4(nvn.xyz * 0.5 + 0.5, 0.0); +	frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, 0.0);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpSkinnedV.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpSkinnedV.glsl index 8ba75010a2..10144f3e16 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/bumpSkinnedV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/bumpSkinnedV.glsl @@ -30,7 +30,7 @@ ATTRIBUTE vec3 position;  ATTRIBUTE vec4 diffuse_color;  ATTRIBUTE vec3 normal;  ATTRIBUTE vec2 texcoord0; -ATTRIBUTE vec3 binormal; +ATTRIBUTE vec4 tangent;  VARYING vec3 vary_mat0;  VARYING vec3 vary_mat1; @@ -52,8 +52,8 @@ void main()  	vec3 n = normalize((mat * vec4(normal.xyz+position.xyz, 1.0)).xyz-pos.xyz); -	vec3 b = normalize((mat * vec4(binormal.xyz+position.xyz, 1.0)).xyz-pos.xyz); -	vec3 t = cross(b, n); +	vec3 t = normalize((mat * vec4(tangent.xyz+position.xyz, 1.0)).xyz-pos.xyz); +	vec3 b = cross(n, t) * tangent.w;  	vary_mat0 = vec3(t.x, b.x, n.x);  	vary_mat1 = vec3(t.y, b.y, n.y); diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl index c8d38bb8f7..9f9749394e 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl @@ -31,7 +31,7 @@ ATTRIBUTE vec3 position;  ATTRIBUTE vec4 diffuse_color;  ATTRIBUTE vec3 normal;  ATTRIBUTE vec2 texcoord0; -ATTRIBUTE vec3 binormal; +ATTRIBUTE vec4 tangent;  VARYING vec3 vary_mat0;  VARYING vec3 vary_mat1; @@ -46,8 +46,8 @@ void main()  	vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy;  	vec3 n = normalize(normal_matrix * normal); -	vec3 b = normalize(normal_matrix * binormal); -	vec3 t = cross(b, n); +	vec3 t = normalize(normal_matrix * tangent.xyz); +	vec3 b = cross(n, t) * tangent.w;  	vary_mat0 = vec3(t.x, b.x, n.x);  	vary_mat1 = vec3(t.y, b.y, n.y); diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index 1d8ca04ccd..1d8ca04ccd 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl index 17f425475c..17f425475c 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl index ccbc3c557c..ccbc3c557c 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl index c1fa9e4aac..7930b5d18b 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl @@ -37,6 +37,12 @@ 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; +} +  void main()   {  	vec4 col = texture2D(diffuseMap, vary_texcoord0.xy) * vertex_color; @@ -49,6 +55,6 @@ void main()  	frag_data[0] = vec4(col.rgb, 0.0);  	frag_data[1] = vec4(0,0,0,0); // spec  	vec3 nvn = normalize(vary_normal); -	frag_data[2] = vec4(nvn.xyz * 0.5 + 0.5, 0.0); +	frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 0.0);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl index 4c68123fac..59d109b886 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl @@ -36,6 +36,12 @@ 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; +} +  void main()   {  	vec4 col = diffuseLookup(vary_texcoord0.xy) * vertex_color; @@ -48,5 +54,5 @@ void main()  	frag_data[0] = vec4(col.rgb, 0.0);  	frag_data[1] = vec4(0,0,0,0);  	vec3 nvn = normalize(vary_normal); -	frag_data[2] = vec4(nvn.xyz * 0.5 + 0.5, 0.0); +	frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 0.0);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl index ad65c7d330..37d70a2412 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl @@ -37,6 +37,12 @@ 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; +} +  void main()   {  	vec4 col = texture2D(diffuseMap, vary_texcoord0.xy); @@ -49,6 +55,6 @@ void main()  	frag_data[0] = vec4(col.rgb, 0.0);  	frag_data[1] = vec4(0,0,0,0); // spec  	vec3 nvn = normalize(vary_normal); -	frag_data[2] = vec4(nvn.xyz * 0.5 + 0.5, 0.0); +	frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 0.0);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl index 86390bdd83..6befb1bd8b 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl @@ -35,6 +35,12 @@ 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; +} +  void main()   {  	vec3 col = vertex_color.rgb * texture2D(diffuseMap, vary_texcoord0.xy).rgb; @@ -42,6 +48,6 @@ void main()  	frag_data[1] = vertex_color.aaaa; // spec  	//frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested  	vec3 nvn = normalize(vary_normal); -	frag_data[2] = vec4(nvn.xyz * 0.5 + 0.5, 0.0); +	frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, 0.0);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl index 788b966af8..adc361d7a2 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl @@ -33,13 +33,22 @@ 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; +} + +  void main()   {  	vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb; +	 +	vec3 spec; +	spec.rgb = vec3(vertex_color.a);  	frag_data[0] = vec4(col, 0.0); -	frag_data[1] = vertex_color.aaaa; // spec -	//frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested +	frag_data[1] = vec4(spec, vertex_color.a); // spec  	vec3 nvn = normalize(vary_normal); -	frag_data[2] = vec4(nvn.xyz * 0.5 + 0.5, 0.0); +	frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, 0.0);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseNoColorV.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseNoColorV.glsl index 9461e3e32e..9461e3e32e 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseNoColorV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseNoColorV.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseSkinnedV.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseSkinnedV.glsl index a74290bfcd..a74290bfcd 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseSkinnedV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseSkinnedV.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl index 76d29b1df7..3c026796c8 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl @@ -47,6 +47,6 @@ void main()  	passTextureIndex();  	vary_normal = normalize(normal_matrix * normal); - +	  	vertex_color = diffuse_color;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/dofCombineF.glsl b/indra/newview/app_settings/shaders/class1/deferred/dofCombineF.glsl index a425e5062e..a425e5062e 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/dofCombineF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/dofCombineF.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl b/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl index 6aa4d7b4ed..ed02c4a481 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl @@ -42,7 +42,7 @@ 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..115b04797f 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/emissiveV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/emissiveV.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 36433a5827..dc1dead656 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -31,6 +31,10 @@ out vec4 frag_color;  #define frag_color gl_FragColor  #endif +#if !HAS_DIFFUSE_LOOKUP +uniform sampler2D diffuseMap; +#endif +  VARYING vec4 vertex_color;  VARYING vec2 vary_texcoord0; @@ -40,14 +44,20 @@ vec3 fullbrightScaleSoftClip(vec3 light);  void main()   { -	float shadow = 1.0; - +#if HAS_DIFFUSE_LOOKUP  	vec4 color = diffuseLookup(vary_texcoord0.xy)*vertex_color; +#else +	vec4 color = texture2D(diffuseMap, vary_texcoord0.xy)*vertex_color; +#endif + +	color.rgb = pow(color.rgb,vec3(2.2f,2.2f,2.2f));  	color.rgb = fullbrightAtmosTransport(color.rgb);  	color.rgb = fullbrightScaleSoftClip(color.rgb); +	color.rgb = pow(color.rgb, vec3(1.0/2.2)); +  	frag_color = color;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl new file mode 100644 index 0000000000..b0db9876d3 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl @@ -0,0 +1,72 @@ +/**  + * @file fullbrightShinyF.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 + +#ifndef diffuseLookup +uniform sampler2D diffuseMap; +#endif + +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; +VARYING vec3 vary_texcoord1; + +uniform samplerCube environmentMap; + +vec3 fullbrightShinyAtmosTransport(vec3 light); +vec3 fullbrightScaleSoftClip(vec3 light); + +void main() +{ +#if HAS_DIFFUSE_LOOKUP +	vec4 color = diffuseLookup(vary_texcoord0.xy); +#else +	vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); +#endif + +	 +	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 = pow(color.rgb,vec3(2.2f,2.2f,2.2f)); +	 +	color.rgb = fullbrightShinyAtmosTransport(color.rgb); +	color.rgb = fullbrightScaleSoftClip(color.rgb); + +	color.a = 1.0; + +	color.rgb = pow(color.rgb, vec3(1.0/2.2)); + +	frag_color = color; +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl new file mode 100644 index 0000000000..34bd8d445a --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl @@ -0,0 +1,67 @@ +/** + * @file fullbrightShinyV.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 texture_matrix1; +uniform mat4 modelview_matrix; +uniform mat4 modelview_projection_matrix; + + +void calcAtmospherics(vec3 inPositionEye); + +uniform vec4 origin; + + + +ATTRIBUTE vec3 position; +void passTextureIndex(); +ATTRIBUTE vec3 normal; +ATTRIBUTE vec4 diffuse_color; +ATTRIBUTE vec2 texcoord0; + +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; +VARYING vec3 vary_texcoord1; + + +void main() +{ +	//transform vertex +	vec4 vert = vec4(position.xyz,1.0); +	passTextureIndex(); +	vec4 pos = (modelview_matrix * vert); +	gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); +	 +	vec3 norm = normalize(normal_matrix * normal); +	vec3 ref = reflect(pos.xyz, -norm); + +	vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; +	vary_texcoord1 = (texture_matrix1*vec4(ref,1.0)).xyz; + +	calcAtmospherics(pos.xyz); + +	vertex_color = diffuse_color; +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl index 2e6982d101..3f09a15375 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl @@ -57,8 +57,6 @@ void main()  	vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy;  	calcAtmospherics(pos.xyz); -	 -	vertex_color = diffuse_color; -	 +	vertex_color = diffuse_color;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/fxaaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fxaaF.glsl index 2cef8f2a5d..2cef8f2a5d 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fxaaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fxaaF.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/giF.glsl b/indra/newview/app_settings/shaders/class1/deferred/giF.glsl index da1b234240..da1b234240 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/giF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/giF.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl index bc0719cb82..bc0719cb82 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/impostorV.glsl b/indra/newview/app_settings/shaders/class1/deferred/impostorV.glsl index 42266e9378..42266e9378 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/impostorV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/impostorV.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl index dcf474824d..dcf474824d 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/luminanceV.glsl b/indra/newview/app_settings/shaders/class1/deferred/luminanceV.glsl index f2dc60aa5d..f2dc60aa5d 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/luminanceV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/luminanceV.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl new file mode 100644 index 0000000000..618ea747f5 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -0,0 +1,696 @@ +/**  + * @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 +#define DIFFUSE_ALPHA_MODE_EMISSIVE 3 + +uniform float emissive_brightness; + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#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; +} + +#endif + +uniform samplerCube environmentMap; +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; +VARYING vec2 vary_fragcoord; + +VARYING vec3 vary_position; + +vec3 vary_PositionEye; + +vec3 vary_SunlitColor; +vec3 vary_AmblitColor; +vec3 vary_AdditiveColor; +vec3 vary_AtmosAttenuation; + +uniform mat4 inv_proj; +uniform vec2 screen_res; + +uniform vec4 light_position[8]; +uniform vec3 light_direction[8]; +uniform vec3 light_attenuation[8];  +uniform vec3 light_diffuse[8]; + +vec3 calcDirectionalLight(vec3 n, vec3 l) +{ +	float a = max(dot(n,l),0.0); +	return vec3(a,a,a); +} + + +vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spec, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, inout float glare) +{ +	//get light vector +	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 *= 1.4; + +		// 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; +} + +vec3 getPositionEye() +{ +	return vary_PositionEye; +} +vec3 getSunlitColor() +{ +	return vary_SunlitColor; +} +vec3 getAmblitColor() +{ +	return vary_AmblitColor; +} +vec3 getAdditiveColor() +{ +	return vary_AdditiveColor; +} +vec3 getAtmosAttenuation() +{ +	return vary_AtmosAttenuation; +} + +void setPositionEye(vec3 v) +{ +	vary_PositionEye = v; +} + +void setSunlitColor(vec3 v) +{ +	vary_SunlitColor = v; +} + +void setAmblitColor(vec3 v) +{ +	vary_AmblitColor = v; +} + +void setAdditiveColor(vec3 v) +{ +	vary_AdditiveColor = v; +} + +void setAtmosAttenuation(vec3 v) +{ +	vary_AtmosAttenuation = v; +} + +void calcAtmospherics(vec3 inPositionEye, float ambFactor) { + +	vec3 P = inPositionEye; +	setPositionEye(P); +	 +	vec3 tmpLightnorm = lightnorm.xyz; + +	vec3 Pn = normalize(P); +	float Plen = length(P); + +	vec4 temp1 = vec4(0); +	vec3 temp2 = vec3(0); +	vec4 blue_weight; +	vec4 haze_weight; +	vec4 sunlight = sunlight_color; +	vec4 light_atten; + +	//sunlight attenuation effect (hue and brightness) due to atmosphere +	//this is used later for sunlight modulation at various altitudes +	light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); +		//I had thought blue_density and haze_density should have equal weighting, +		//but attenuation due to haze_density tends to seem too strong + +	temp1 = blue_density + vec4(haze_density); +	blue_weight = blue_density / temp1; +	haze_weight = vec4(haze_density) / temp1; + +	//(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) +	temp2.y = max(0.0, tmpLightnorm.y); +	temp2.y = 1. / temp2.y; +	sunlight *= exp( - light_atten * temp2.y); + +	// main atmospheric scattering line integral +	temp2.z = Plen * density_multiplier; + +	// Transparency (-> temp1) +	// ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati +	// compiler gets confused. +	temp1 = exp(-temp1 * temp2.z * distance_multiplier); + +	//final atmosphere attenuation factor +	setAtmosAttenuation(temp1.rgb); +	 +	//compute haze glow +	//(can use temp2.x as temp because we haven't used it yet) +	temp2.x = dot(Pn, tmpLightnorm.xyz); +	temp2.x = 1. - temp2.x; +		//temp2.x is 0 at the sun and increases away from sun +	temp2.x = max(temp2.x, .03);	//was glow.y +		//set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) +	temp2.x *= glow.x; +		//higher glow.x gives dimmer glow (because next step is 1 / "angle") +	temp2.x = pow(temp2.x, glow.z); +		//glow.z should be negative, so we're doing a sort of (1 / "angle") function + +	//add "minimum anti-solar illumination" +	temp2.x += .25; +	 +	//increase ambient when there are more clouds +	vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; +	 +	/*  decrease value and saturation (that in HSV, not HSL) for occluded areas +	 * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html +	 * // The following line of code performs the equivalent of: +	 * float ambAlpha = tmpAmbient.a; +	 * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis +	 * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); +	 * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); +	 */ +	tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); + +	//haze color +	setAdditiveColor( +		vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) +	  + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x +		  + tmpAmbient))); + +	//brightness of surface both sunlight and ambient +	setSunlitColor(vec3(sunlight * .5)); +	setAmblitColor(vec3(tmpAmbient * .25)); +	setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); +} + +vec3 atmosLighting(vec3 light) +{ +	light *= getAtmosAttenuation().r; +	light += getAdditiveColor(); +	return (2.0 * light); +} + +vec3 atmosTransport(vec3 light) { +	light *= getAtmosAttenuation().r; +	light += getAdditiveColor() * 2.0; +	return light; +} +vec3 atmosGetDiffuseSunlightColor() +{ +	return getSunlitColor(); +} + +vec3 scaleDownLight(vec3 light) +{ +	return (light / vec3(scene_light_strength, scene_light_strength, scene_light_strength)); +} + +vec3 scaleUpLight(vec3 light) +{ +	return (light * vec3(scene_light_strength, scene_light_strength, scene_light_strength)); +} + +vec3 atmosAmbient(vec3 light) +{ +	return getAmblitColor() + (light * vec3(0.5f, 0.5f, 0.5f)); +} + +vec3 atmosAffectDirectionalLight(float lightIntensity) +{ +	return getSunlitColor() * vec3(lightIntensity, lightIntensity, lightIntensity); +} + +vec3 scaleSoftClip(vec3 light) +{ +	//soft clip effect: +    vec3 zeroes = vec3(0.0f, 0.0f, 0.0f); +    vec3 ones   = vec3(1.0f, 1.0f, 1.0f); + +	light = ones - clamp(light, zeroes, ones); +	light = ones - pow(light, gamma.xxx); + +	return light; +} + +vec3 fullbrightAtmosTransport(vec3 light) { +	float brightness = dot(light.rgb, vec3(0.33333)); + +	return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); +} + +vec3 fullbrightScaleSoftClip(vec3 light) +{ +	//soft clip effect: +	return light; +} + +#else +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_data[3]; +#else +#define frag_data gl_FragData +#endif +#endif + +uniform sampler2D diffuseMap; + +#if HAS_NORMAL_MAP +uniform sampler2D bumpMap; +#endif + +#if HAS_SPECULAR_MAP +uniform sampler2D specularMap; + +VARYING vec2 vary_texcoord2; +#endif + +uniform float env_intensity; +uniform vec4 specular_color;  // specular color RGB and specular exponent (glossiness) in alpha + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) +uniform float minimum_alpha; +#endif + +#if HAS_NORMAL_MAP +VARYING vec3 vary_mat0; +VARYING vec3 vary_mat1; +VARYING vec3 vary_mat2; +VARYING vec2 vary_texcoord1; +#else +VARYING vec3 vary_normal; +#endif + +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; + +#ifdef SINGLE_FP_ONLY +vec2 encode_normal(vec3 n) +{ +	vec2 sn; +	sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); +	return sn; +} + +vec3 decode_normal (vec2 enc) +{ +	vec3 n; +	n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); +	n.z = sqrt(1.0f - dot(n.xy,n.xy)); +	return n; +} +#else +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; +} +#endif + +void main()  +{ +	vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); +	diffcol.rgb *= vertex_color.rgb; + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) +	if (diffcol.a < minimum_alpha) +	{ +		discard; +	} +#endif + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) +	vec3 old_diffcol = diffcol.rgb; +	diffcol.rgb = pow(diffcol.rgb, vec3(2.2)); +#endif + +#if HAS_SPECULAR_MAP +	vec4 spec = texture2D(specularMap, vary_texcoord2.xy); +	spec.rgb *= specular_color.rgb; +#else +	vec4 spec = vec4(specular_color.rgb, 1.0); +#endif + +#if HAS_NORMAL_MAP +	vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); + +	norm.xyz = norm.xyz * 2 - 1; + +	vec3 tnorm = vec3(dot(norm.xyz,vary_mat0), +			  dot(norm.xyz,vary_mat1), +			  dot(norm.xyz,vary_mat2)); +#else +	vec4 norm = vec4(0,0,0,1.0); +	vec3 tnorm = vary_normal; +#endif + +    norm.xyz = tnorm; +    norm.xyz = normalize(norm.xyz); + +	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_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; +#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; +#endif + +	spec = final_specular; +	vec4 diffuse = final_color; +	float envIntensity = final_normal.z; + +    vec3 col = vec3(0.0f,0.0f,0.0f); + +	float bloom = 0.0; +	calcAtmospherics(pos.xyz, 1.0); +	 +	vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + +	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); + +	col.rgb = atmosAmbient(col); +	 +	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.rgb = col.rgb + atmosAffectDirectionalLight(pow(final_da, 1.0/1.3)); +	col.rgb *= old_diffcol.rgb; +	 + +	float glare = 0.0; + +	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; + +		glare = max(spec_contrib.r, spec_contrib.g); +		glare = max(glare, spec_contrib.b); + +		col += spec_contrib; +	} + +	col = mix(col.rgb, old_diffcol.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);   + +		float cur_glare = max(refcol.r, refcol.g); +		cur_glare = max(cur_glare, refcol.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); + +	//convert to linear space before adding local lights +	col = pow(col, vec3(2.2)); + +			 +	vec3 npos = normalize(-pos.xyz); + + #define LIGHT_LOOP(i) col.rgb = col.rgb + calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare); + +		LIGHT_LOOP(1) +		LIGHT_LOOP(2) +		LIGHT_LOOP(3) +		LIGHT_LOOP(4) +		LIGHT_LOOP(5) +		LIGHT_LOOP(6) +		LIGHT_LOOP(7) + + +	//convert to gamma space for display on screen +	col.rgb = pow(col.rgb, vec3(1.0/2.2)); + +	frag_color.rgb = col.rgb; +	glare = min(glare, 1.0); +	frag_color.a = max(diffcol.a,glare)*vertex_color.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. +#endif +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl new file mode 100644 index 0000000000..b25032866b --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl @@ -0,0 +1,144 @@ +/**  + * @file bumpV.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 +#define DIFFUSE_ALPHA_MODE_EMISSIVE 3 + +#if HAS_SKIN +uniform mat4 modelview_matrix; +uniform mat4 projection_matrix; +mat4 getObjectSkinnedTransform(); +#else +uniform mat3 normal_matrix; +uniform mat4 modelview_projection_matrix; +#endif + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + +#if !HAS_SKIN +uniform mat4 modelview_matrix; +#endif + +VARYING vec3 vary_position; + +#endif + +uniform mat4 texture_matrix0; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec4 diffuse_color; +ATTRIBUTE vec3 normal; +ATTRIBUTE vec2 texcoord0; + + +#if HAS_NORMAL_MAP +ATTRIBUTE vec4 tangent; +ATTRIBUTE vec2 texcoord1; + +VARYING vec3 vary_mat0; +VARYING vec3 vary_mat1; +VARYING vec3 vary_mat2; + +VARYING vec2 vary_texcoord1; +#else +VARYING vec3 vary_normal; +#endif + +#if HAS_SPECULAR_MAP +ATTRIBUTE vec2 texcoord2; +VARYING vec2 vary_texcoord2; +#endif +  +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; + +void main() +{ +#if HAS_SKIN +	mat4 mat = getObjectSkinnedTransform(); + +	mat = modelview_matrix * mat; + +	vec3 pos = (mat*vec4(position.xyz,1.0)).xyz; + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) +	vary_position = pos; +#endif + +	gl_Position = projection_matrix*vec4(pos,1.0); + +#else +	//transform vertex +	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);  + +#endif +	 +	vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; +	 +#if HAS_NORMAL_MAP +	vary_texcoord1 = (texture_matrix0 * vec4(texcoord1,0,1)).xy; +#endif + +#if HAS_SPECULAR_MAP +	vary_texcoord2 = (texture_matrix0 * vec4(texcoord2,0,1)).xy; +#endif + +#if HAS_SKIN +	vec3 n = normalize((mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz); +#if HAS_NORMAL_MAP +	vec3 t = normalize((mat*vec4(tangent.xyz+position.xyz,1.0)).xyz-pos.xyz); +	vec3 b = cross(n, t)*tangent.w; +	 +	vary_mat0 = vec3(t.x, b.x, n.x); +	vary_mat1 = vec3(t.y, b.y, n.y); +	vary_mat2 = vec3(t.z, b.z, n.z); +#else //HAS_NORMAL_MAP +vary_normal  = n; +#endif //HAS_NORMAL_MAP +#else //HAS_SKIN +	vec3 n = normalize(normal_matrix * normal); +#if HAS_NORMAL_MAP +	vec3 t = normalize(normal_matrix * tangent.xyz); +	vec3 b = cross(n,t)*tangent.w; +	//vec3 t = cross(b,n) * binormal.w; +	 +	vary_mat0 = vec3(t.x, b.x, n.x); +	vary_mat1 = vec3(t.y, b.y, n.y); +	vary_mat2 = vec3(t.z, b.z, n.z); +#else //HAS_NORMAL_MAP +	vary_normal = n; +#endif //HAS_NORMAL_MAP +#endif //HAS_SKIN +	 +	vertex_color = diffuse_color; + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) +#if !HAS_SKIN +	vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz; +#endif +#endif +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index 7e79317543..868526d457 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -56,6 +56,40 @@ uniform float far_z;  uniform mat4 inv_proj; +#ifdef SINGLE_FP_ONLY +vec2 encode_normal(vec3 n) +{ +	vec2 sn; +	sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); +	return sn; +} + +vec3 decode_normal (vec2 enc) +{ +	vec3 n; +	n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); +	n.z = sqrt(1.0f - dot(n.xy,n.xy)); +	return n; +} +#else +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; +} +#endif +  vec4 getPosition(vec2 pos_screen)  {  	float depth = texture2DRect(depthMap, pos_screen.xy).r; @@ -79,7 +113,7 @@ void main()  	}  	vec3 norm = texture2DRect(normalMap, frag.xy).xyz; -	norm = (norm.xyz-0.5)*2.0; // unpack norm +	norm = decode_normal(norm.xy); // unpack norm  	norm = normalize(norm);  	vec4 spec = texture2DRect(specularRect, frag.xy);  	vec3 diff = texture2DRect(diffuseRect, frag.xy).rgb; @@ -93,9 +127,9 @@ void main()  		bool light_contrib = (i < light_count);  		vec3 lv = light[i].xyz-pos; -		float dist2 = dot(lv,lv); -		dist2 /= light[i].w; -		if (dist2 > 1.0) +		float dist = length(lv); +		dist /= light[i].w; +		if (dist > 1.0)  		{  			light_contrib = false;  		} @@ -110,27 +144,39 @@ void main()  		{  			lv = normalize(lv);  			da = dot(norm, lv); -					 +			  			float fa = light_col[i].a+1.0; -			float dist_atten = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0); +			float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); +			dist_atten *= dist_atten; +			dist_atten *= 2.0; +			  			dist_atten *= noise;  			float lit = da * dist_atten; -			 +						  			vec3 col = light_col[i].rgb*lit*diff; +			  			//vec3 col = vec3(dist2, light_col[i].a, lit);  			if (spec.a > 0.0)  			{ +				lit = min(da*6.0, 1.0) * dist_atten;  				//vec3 ref = dot(pos+lv, norm); -				 -				float sa = dot(normalize(lv+npos),norm); -				 -				if (sa > 0.0) +				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)  				{ -					sa = 6 * texture2D(lightFunc, vec2(sa, spec.a)).r * min(dist_atten*4.0, 1.0); -					sa *= noise; -					col += da*sa*light_col[i].rgb*spec.rgb; +					float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); +					col += lit*scol*light_col[i].rgb*spec.rgb; +					//col += spec.rgb;  				}  			} diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightV.glsl index eefefa640d..eefefa640d 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightV.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index bff87cb6aa..97bf49a605 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -40,6 +40,7 @@ uniform sampler2DRect normalMap;  uniform samplerCube environmentMap;  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 @@ -66,9 +67,49 @@ uniform vec2 screen_res;  uniform mat4 inv_proj; +#ifdef SINGLE_FP_ONLY +vec2 encode_normal(vec3 n) +{ +	vec2 sn; +	sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); +	return sn; +} + +vec3 decode_normal (vec2 enc) +{ +	vec3 n; +	n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); +	n.z = sqrt(1.0f - dot(n.xy,n.xy)); +	return n; +} +#else +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; +} +#endif + +vec4 correctWithGamma(vec4 col) +{ +	return vec4(pow(col.rgb, vec3(2.2)), col.a); +} +  vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod)  {  	vec4 ret = texture2DLod(projectionMap, tc, lod); +	ret = correctWithGamma(ret);  	vec2 dist = tc-vec2(0.5); @@ -84,6 +125,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);  	vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -101,6 +143,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);  	vec2 dist = tc-vec2(0.5); @@ -134,15 +177,17 @@ void main()  	vec3 pos = getPosition(frag.xy).xyz;  	vec3 lv = center.xyz-pos.xyz; -	float dist2 = dot(lv,lv); -	dist2 /= size; -	if (dist2 > 1.0) +	float dist = length(lv); +	dist /= size; +	if (dist > 1.0)  	{  		discard;  	}  	vec3 norm = texture2DRect(normalMap, frag.xy).xyz; -	norm = vec3((norm.xy-0.5)*2.0, norm.z); +	float envIntensity = norm.z; + +	norm = decode_normal(norm.xy);  	norm = normalize(norm);  	float l_dist = -dot(lv, proj_n); @@ -156,7 +201,10 @@ void main()  	proj_tc.xyz /= proj_tc.w;  	float fa = falloff+1.0; -	float dist_atten = min(1.0-(dist2-1.0*(1.0-fa))/fa, 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; @@ -169,7 +217,8 @@ void main()  	vec3 col = vec3(0,0,0);  	vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).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 && @@ -187,14 +236,13 @@ void main()  			vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); -			vec3 lcol = color.rgb * plcol.rgb * plcol.a; +			dlit = color.rgb * plcol.rgb * plcol.a;  			lit = da * dist_atten * noise; -			col = lcol*lit*diff_tex; +			col = dlit*lit*diff_tex;  			amb_da += (da*0.5)*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); @@ -203,14 +251,39 @@ void main()  		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*amb_plcol.rgb*amb_plcol.a;  	}  	vec4 spec = texture2DRect(specularRect, frag.xy); +	  	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; +			//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 @@ -227,8 +300,9 @@ void main()  			{  				stc.xy /= stc.w; -				float fatten = clamp(spec.a*spec.a+spec.a*0.5, 0.25, 1.0); +				float fatten = clamp(envIntensity*envIntensity+envIntensity*0.5, 0.25, 1.0); +				//stc.xy = (stc.xy - vec2(0.5)) * fatten + vec2(0.5);  				stc.xy = (stc.xy - vec2(0.5)) * fatten + vec2(0.5);  				if (stc.x < 1.0 && @@ -236,8 +310,7 @@ void main()  					stc.x > 0.0 &&  					stc.y > 0.0)  				{ -					vec4 scol = texture2DLodSpecular(projectionMap, stc.xy, proj_lod-spec.a*proj_lod); -					col += dist_atten*scol.rgb*color.rgb*scol.a*spec.rgb; +					col += color.rgb*texture2DLodSpecular(projectionMap, stc.xy, proj_lod-envIntensity*proj_lod).rgb*spec.rgb;										  				}  			}  		} diff --git a/indra/newview/app_settings/shaders/class1/deferred/normgenF.glsl b/indra/newview/app_settings/shaders/class1/deferred/normgenF.glsl index 62cfa5c316..62cfa5c316 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/normgenF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/normgenF.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/normgenV.glsl b/indra/newview/app_settings/shaders/class1/deferred/normgenV.glsl index 9bceae05b7..9bceae05b7 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/normgenV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/normgenV.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 75757b26c8..caf20ce707 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -54,6 +54,40 @@ uniform vec2 screen_res;  uniform mat4 inv_proj;  uniform vec4 viewport; +#ifdef SINGLE_FP_ONLY +vec2 encode_normal(vec3 n) +{ +	vec2 sn; +	sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); +	return sn; +} + +vec3 decode_normal (vec2 enc) +{ +	vec3 n; +	n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); +	n.z = sqrt(1.0f - dot(n.xy,n.xy)); +	return n; +} +#else +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; +} +#endif +  vec4 getPosition(vec2 pos_screen)  {  	float depth = texture2DRect(depthMap, pos_screen.xy).r; @@ -76,15 +110,15 @@ void main()  	vec3 pos = getPosition(frag.xy).xyz;  	vec3 lv = trans_center.xyz-pos; -	float dist2 = dot(lv,lv); -	dist2 /= size; -	if (dist2 > 1.0) +	float dist = length(lv); +	dist /= size; +	if (dist > 1.0)  	{  		discard;  	}  	vec3 norm = texture2DRect(normalMap, frag.xy).xyz; -	norm = (norm.xyz-0.5)*2.0; // unpack norm +	norm = decode_normal(norm.xy); // unpack norm  	float da = dot(norm, lv);  	if (da < 0.0)  	{ @@ -99,20 +133,33 @@ void main()  	vec3 col = texture2DRect(diffuseRect, frag.xy).rgb;  	float fa = falloff+1.0; -	float dist_atten = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0); -	float lit = da * dist_atten * noise; +	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)  	{ -		float sa = dot(normalize(lv-normalize(pos)),norm); -		if (sa > 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)  		{ -			sa = 6 * texture2D(lightFunc, vec2(sa, spec.a)).r * min(dist_atten*4.0, 1.0); -			sa *= noise; -			col += da*sa*color.rgb*spec.rgb; +			float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); +			col += lit*scol*color.rgb*spec.rgb;  		}  	} diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl index 9491421236..a5625fbc16 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl @@ -37,7 +37,7 @@ VARYING vec3 trans_center;  void main()  {  	//transform vertex -	vec3 p = position*sqrt(size)+center; +	vec3 p = position*size+center;  	vec4 pos = modelview_projection_matrix * vec4(p.xyz, 1.0);  	vary_fragcoord = pos;  	trans_center = (modelview_matrix*vec4(center.xyz, 1.0)).xyz; diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl index bf362e21a4..bf362e21a4 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl new file mode 100644 index 0000000000..6f2cfae6d2 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -0,0 +1,46 @@ +/**  + * @file postDeferredGammaCorrect.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 + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2DRect diffuseRect; + +uniform vec2 screen_res; +VARYING vec2 vary_fragcoord; + +uniform float texture_gamma; + +void main()  +{ +	vec4 diff = texture2DRect(diffuseRect, vary_fragcoord); +	frag_color = pow(diff, vec4(texture_gamma, texture_gamma, texture_gamma, 1.0f)); +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl index eb5beeef39..eb5beeef39 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoTCV.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoTCV.glsl index bd0cb50464..bd0cb50464 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoTCV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoTCV.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredV.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredV.glsl index 8edf5b2723..8edf5b2723 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredV.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl index 96f9628424..96f9628424 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl index bced4a5577..91a96977f0 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl @@ -31,8 +31,12 @@ out vec4 frag_color;  uniform sampler2D diffuseMap; +#if !DEPTH_CLAMP  VARYING float pos_zd2; +#endif +  VARYING float pos_w; +  VARYING float target_pos_x;  VARYING vec4 vertex_color;  VARYING vec2 vary_texcoord0; @@ -56,5 +60,7 @@ void main()  	frag_color = vec4(1,1,1,1); +#if !DEPTH_CLAMP  	gl_FragDepth = max(pos_zd2/pos_w+0.5, 0.0); +#endif  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl index c1f2d90712..11411a605c 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl @@ -31,8 +31,12 @@ ATTRIBUTE vec3 position;  ATTRIBUTE vec4 diffuse_color;  ATTRIBUTE vec2 texcoord0; +#if !DEPTH_CLAMP  VARYING float pos_zd2; +#endif +  VARYING float pos_w; +  VARYING float target_pos_x;  VARYING vec4 vertex_color;  VARYING vec2 vary_texcoord0; @@ -45,10 +49,16 @@ void main()  	vec4 pre_pos = vec4(position.xyz, 1.0);  	vec4 pos = modelview_projection_matrix * pre_pos;  	target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; +  	pos_w = pos.w; + +#if !DEPTH_CLAMP  	pos_zd2 = pos.z * 0.5;  	gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); +#else +	gl_Position = pos; +#endif  	passTextureIndex(); diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowCubeV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowCubeV.glsl index 6195e2f1ec..ef153dfc5b 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowCubeV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowCubeV.glsl @@ -27,7 +27,9 @@ uniform mat4 modelview_projection_matrix;  ATTRIBUTE vec3 position; +#if !DEPTH_CLAMP  VARYING vec4 post_pos; +#endif  uniform vec3 box_center;  uniform vec3 box_size; @@ -37,8 +39,12 @@ void main()  	//transform vertex  	vec3 p = position*box_size+box_center;  	vec4 pos = modelview_projection_matrix*vec4(p.xyz, 1.0); -	 + +#if !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/class1/deferred/shadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl index 7e55fdc12a..3d1b182875 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl @@ -29,11 +29,16 @@ out vec4 frag_color;  #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  	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/shadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl index 8b46e81f90..cc77a4cea0 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl @@ -27,14 +27,20 @@ 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; -	 +  	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 faa54a316e..22f4729e2e 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -61,6 +61,6 @@ void main()  	/// 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,0,1,0); +	frag_data[2] = vec4(0.5,0.5,0.0,1.0); //1.0 in norm.w masks off fog  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl index 7c02d31d43..7c02d31d43 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 89448e2167..08583ad0f2 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -60,6 +60,7 @@ 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; @@ -77,6 +78,34 @@ vec3 vary_AtmosAttenuation;  uniform mat4 inv_proj;  uniform vec2 screen_res; +#ifdef SINGLE_FP_ONLY +vec2 encode_normal(vec3 n) +{ +	vec2 sn; +	sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); +	return sn; +} + +vec3 decode_normal (vec2 enc) +{ +	vec3 n; +	n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); +	n.z = sqrt(1.0f - dot(n.xy,n.xy)); +	return n; +} +#else +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; +} +#endif +  vec4 getPosition_d(vec2 pos_screen, float depth)  {  	vec2 sc = pos_screen.xy*2.0; @@ -116,7 +145,6 @@ vec3 getAtmosAttenuation()  	return vary_AtmosAttenuation;  } -  void setPositionEye(vec3 v)  {  	vary_PositionEye = v; @@ -237,6 +265,15 @@ vec3 atmosTransport(vec3 light) {  	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(); @@ -271,57 +308,88 @@ vec3 scaleSoftClip(vec3 light)  	return light;  } + +vec3 fullbrightScaleSoftClip(vec3 light) +{ +	//soft clip effect: +	return light; +} +  void main()   {  	vec2 tc = vary_fragcoord.xy;  	float depth = texture2DRect(depthMap, tc.xy).r;  	vec3 pos = getPosition_d(tc, depth).xyz; -	vec3 norm = texture2DRect(normalMap, tc).xyz; -	norm = (norm.xyz-0.5)*2.0; // unpack norm +	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); -	 +	da = pow(da, 1.0/1.3); +  	vec4 diffuse = texture2DRect(diffuseRect, tc); + +	//convert to gamma space +	diffuse.rgb = pow(diffuse.rgb, vec3(1.0/2.2)); +  	vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); -	  	vec3 col;  	float bloom = 0.0; -	if (diffuse.a < 0.9)  	{  		calcAtmospherics(pos.xyz, 1.0);  		col = atmosAmbient(vec3(0)); -		col += atmosAffectDirectionalLight(max(min(da, 1.0), diffuse.a)); +		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, 1.0), 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  			// -			vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); +			  			float sa = dot(refnormpersp, sun_dir.xyz); -			vec3 dumbshiny = vary_SunlitColor*(6 * texture2D(lightFunc, vec2(sa, spec.a)).r); +			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) / 4; +			bloom = dot(spec_contrib, spec_contrib) / 6;  			col += spec_contrib; - -			//add environmentmap +		} +		 +		 +		col = mix(col.rgb, diffuse.rgb, diffuse.a); +				 +		if (envIntensity > 0.0) +		{ //add environmentmap  			vec3 env_vec = env_mat * refnormpersp; -			col = mix(col.rgb, textureCube(environmentMap, env_vec).rgb,  -				max(spec.a-diffuse.a*2.0, 0.0));  +			 +			 +			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);  		} -	 -		col = atmosLighting(col); -		col = scaleSoftClip(col); -		col = mix(col.rgb, diffuse.rgb, diffuse.a); -	} -	else -	{ -		col = diffuse.rgb; +		col = pow(col, vec3(2.2)); + +		//col = vec3(1,0,1); +		//col.g = envIntensity;  	}  	frag_color.rgb = col; diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl index c6031fc45a..b59fcbe017 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl @@ -35,6 +35,6 @@ 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/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index cca63872de..1975b18652 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -22,18 +22,15 @@   * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA   * $/LicenseInfo$   */ - +#extension GL_ARB_texture_rectangle : enable +  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_color;  #else  #define frag_color gl_FragColor  #endif -//class 1 -- no shadows - -#extension GL_ARB_texture_rectangle : enable -  uniform sampler2DRect diffuseRect;  uniform sampler2DRect specularRect;  uniform sampler2DRect depthMap; @@ -41,6 +38,7 @@ uniform sampler2DRect normalMap;  uniform samplerCube environmentMap;  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 @@ -57,20 +55,59 @@ uniform float far_clip;  uniform vec3 proj_origin; //origin of projection to be used for angular attenuation  uniform float sun_wash; +uniform float size;  uniform vec3 color;  uniform float falloff; -uniform float size; -VARYING vec4 vary_fragcoord;  VARYING vec3 trans_center; - +VARYING vec4 vary_fragcoord;  uniform vec2 screen_res;  uniform mat4 inv_proj; +#ifdef SINGLE_FP_ONLY +vec2 encode_normal(vec3 n) +{ +	vec2 sn; +	sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); +	return sn; +} + +vec3 decode_normal (vec2 enc) +{ +	vec3 n; +	n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); +	n.z = sqrt(1.0f - dot(n.xy,n.xy)); +	return n; +} +#else +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; +} +#endif + +vec4 correctWithGamma(vec4 col) +{ +	return vec4(pow(col.rgb, vec3(2.2)), col.a); +} +  vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod)  {  	vec4 ret = texture2DLod(projectionMap, tc, lod); +	ret = correctWithGamma(ret);  	vec2 dist = tc-vec2(0.5); @@ -86,6 +123,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);  	vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -103,6 +141,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);  	vec2 dist = tc-vec2(0.5); @@ -136,15 +175,17 @@ void main()  	vec3 pos = getPosition(frag.xy).xyz;  	vec3 lv = trans_center.xyz-pos.xyz; -	float dist2 = dot(lv,lv); -	dist2 /= size; -	if (dist2 > 1.0) +	float dist = length(lv); +	dist /= size; +	if (dist > 1.0)  	{  		discard;  	} +	  	vec3 norm = texture2DRect(normalMap, frag.xy).xyz; -	norm = vec3((norm.xy-0.5)*2.0, norm.z); +	float envIntensity = norm.z; +	norm = decode_normal(norm.xy);  	norm = normalize(norm);  	float l_dist = -dot(lv, proj_n); @@ -158,7 +199,10 @@ void main()  	proj_tc.xyz /= proj_tc.w;  	float fa = falloff+1.0; -	float dist_atten = min(1.0-(dist2-1.0*(1.0-fa))/fa, 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; @@ -172,31 +216,35 @@ void main()  	vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; +	vec4 spec = texture2DRect(specularRect, frag.xy); + +	 +  	float noise = texture2D(noiseMap, frag.xy/128.0).b; +	vec3 dlit = vec3(0, 0, 0); +	  	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 lit = 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); -		 -			vec3 lcol = color.rgb * plcol.rgb * plcol.a; +			dlit = color.rgb * plcol.rgb * plcol.a; -			lit = da * dist_atten * noise; -			 -			col = lcol*lit*diff_tex; -			amb_da += (da*0.5)*proj_ambiance; +			col = dlit*lit*diff_tex; +			//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); @@ -205,14 +253,38 @@ void main()  		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*diff_tex.rgb;  	} -	 -	vec4 spec = texture2DRect(specularRect, frag.xy); +  	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; +			//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 @@ -229,8 +301,9 @@ void main()  			{  				stc.xy /= stc.w; -				float fatten = clamp(spec.a*spec.a+spec.a*0.5, 0.25, 1.0); +				float fatten = clamp(envIntensity*envIntensity+envIntensity*0.5, 0.25, 1.0); +				//stc.xy = (stc.xy - vec2(0.5)) * fatten + vec2(0.5);  				stc.xy = (stc.xy - vec2(0.5)) * fatten + vec2(0.5);  				if (stc.x < 1.0 && @@ -238,8 +311,7 @@ void main()  					stc.x > 0.0 &&  					stc.y > 0.0)  				{ -					vec4 scol = texture2DLodSpecular(projectionMap, stc.xy, proj_lod-spec.a*proj_lod); -					col += dist_atten*scol.rgb*color.rgb*scol.a*spec.rgb; +					col += color.rgb*texture2DLodSpecular(projectionMap, stc.xy, proj_lod-envIntensity*proj_lod).rgb*spec.rgb;										  				}  			}  		} diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl index 821058804c..821058804c 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl index 8bc5b06379..8bc5b06379 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightF.glsl index 5ca817aff6..5ca817aff6 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightF.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightNoFragCoordV.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightNoFragCoordV.glsl index 47e9d15fbc..47e9d15fbc 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightNoFragCoordV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightNoFragCoordV.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl index bac74cbbef..6653f57ee1 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl @@ -49,6 +49,40 @@ VARYING vec2 vary_fragcoord;  uniform mat4 inv_proj;  uniform vec2 screen_res; +#ifdef SINGLE_FP_ONLY +vec2 encode_normal(vec3 n) +{ +	vec2 sn; +	sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); +	return sn; +} + +vec3 decode_normal (vec2 enc) +{ +	vec3 n; +	n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); +	n.z = sqrt(1.0f - dot(n.xy,n.xy)); +	return n; +} +#else +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; +} +#endif +  vec4 getPosition(vec2 pos_screen)  {  	float depth = texture2DRect(depthMap, pos_screen.xy).r; @@ -123,7 +157,7 @@ void main()  	vec4 pos = getPosition(pos_screen);  	vec3 norm = texture2DRect(normalMap, pos_screen).xyz; -	norm = (norm.xyz-0.5)*2.0; // unpack norm +	norm = decode_normal(norm.xy);  	frag_color[0] = 1.0;  	frag_color[1] = calcAmbientOcclusion(pos, norm); diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightV.glsl index 473d6df8fa..473d6df8fa 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightV.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl index daf1cc7ea2..52a429465f 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl @@ -39,6 +39,12 @@ 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; +} +  void main()  {  	/// Note: This should duplicate the blending functionality currently used for the terrain rendering. @@ -56,6 +62,6 @@ void main()  	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(nvn.xyz * 0.5 + 0.5, 0.0); +	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..5effee4e4e 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl index da253846ef..808750496f 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl @@ -37,6 +37,12 @@ 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; +} +  void main()   {  	vec4 col = texture2D(diffuseMap, vary_texcoord0.xy); @@ -48,5 +54,5 @@ void main()  	frag_data[0] = vec4(vertex_color.rgb*col.rgb, 0.0);  	frag_data[1] = vec4(0,0,0,0);  	vec3 nvn = normalize(vary_normal); -	frag_data[2] = vec4(nvn.xyz * 0.5 + 0.5, 0.0); +	frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 0.0);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeShadowF.glsl index d4d2f5f571..d4d2f5f571 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/treeShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeShadowF.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeShadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeShadowV.glsl index e472a75304..e472a75304 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/treeShadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeShadowV.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeV.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeV.glsl index 3b6571a24a..3b6571a24a 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/treeV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeV.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 3427d6db57..daa2fb390a 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -67,6 +67,12 @@ VARYING vec4 littleWave;  VARYING vec4 view;  VARYING vec4 vary_position; +vec2 encode_normal(vec3 n) +{ +	float f = sqrt(8 * n.z + 8); +	return n.xy / f + 0.5; +} +  void main()   {  	vec4 color; @@ -151,8 +157,8 @@ void main()  	//spec *= shadow;  	//color.rgb += spec * specular; -	//color.rgb = atmosTransport(color.rgb); -	//color.rgb = scaleSoftClip(color.rgb); +	color.rgb = atmosTransport(color.rgb); +	color.rgb = scaleSoftClip(color.rgb);  	//color.a = spec * sunAngle2;  	//wavef.z *= 0.1f; @@ -161,5 +167,5 @@ void main()  	frag_data[0] = vec4(color.rgb, 0.5); // diffuse  	frag_data[1] = vec4(0.5,0.5,0.5, 0.95); // speccolor*spec, spec -	frag_data[2] = vec4(screenspacewavef.xyz*0.5+0.5, screenspacewavef.z*0.5); // normalxyz, displace +	frag_data[2] = vec4(encode_normal(screenspacewavef), 0.0, 0.0); // normalxyz, displace  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl index 9734acf005..ece34dcc4e 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl @@ -85,7 +85,7 @@ void main()  	pos.w = 1.0;  	pos = modelview_matrix*pos; -	calcAtmospherics(pos.xyz); +	calcAtmospherics(view.xyz);  	//pass wave parameters to pixel shader  	vec2 bigWave =  (v.xy) * vec2(0.04,0.04)  + d1 * time * 0.055; | 
