diff options
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/deferred')
18 files changed, 719 insertions, 75 deletions
| diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index d9f021b114..98d034c2b5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -26,7 +26,7 @@ uniform vec2 screen_res;  vec4 getPosition(vec2 pos_screen)  { -	float depth = texture2DRect(depthMap, pos_screen.xy).a; +	float depth = texture2DRect(depthMap, pos_screen.xy).r;  	vec2 sc = pos_screen.xy*2.0;  	sc /= screen_res;  	sc -= vec2(1.0,1.0); @@ -39,7 +39,7 @@ vec4 getPosition(vec2 pos_screen)  void main()   { -        vec2 tc = vary_fragcoord.xy; +    vec2 tc = vary_fragcoord.xy;  	vec3 norm = texture2DRect(normalMap, tc).xyz;  	norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm  	vec3 pos = getPosition(tc).xyz; diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightMSF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightMSF.glsl index 113197c871..4366376d99 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightMSF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightMSF.glsl @@ -28,12 +28,12 @@ uniform vec2 screen_res;  vec4 texture2DMS(sampler2DMS tex, ivec2 tc)  {  	vec4 ret = vec4(0,0,0,0); -	for (int i = 0; i < 4; i++) +	for (int i = 0; i < samples; i++)  	{  		ret += texelFetch(tex, tc, i);  	} -	return ret * 0.25; +	return ret/samples;  }  vec4 getPosition(ivec2 pos_screen) diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index 609fc4f14f..e10fb105e8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -36,7 +36,7 @@ uniform mat4 inv_proj;  vec4 getPosition(vec2 pos_screen)  { -	float depth = texture2DRect(depthMap, pos_screen.xy).a; +	float depth = texture2DRect(depthMap, pos_screen.xy).r;  	vec2 sc = pos_screen.xy*2.0;  	sc /= screen_res;  	sc -= vec2(1.0,1.0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightMSF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightMSF.glsl new file mode 100644 index 0000000000..16e97109f9 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightMSF.glsl @@ -0,0 +1,137 @@ +/**  + * @file multiPointLightF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * $/LicenseInfo$ + */ + +#version 120 + +#extension GL_ARB_texture_rectangle : enable +#extension GL_ARB_texture_multisample : enable + +uniform sampler2DMS depthMap; +uniform sampler2DMS diffuseRect; +uniform sampler2DMS specularRect; +uniform sampler2DMS normalMap; +uniform sampler2D noiseMap; +uniform sampler2D lightFunc; + + +uniform vec3 env_mat[3]; +uniform float sun_wash; + +uniform int light_count; + +#define MAX_LIGHT_COUNT		16 +uniform vec4 light[MAX_LIGHT_COUNT]; +uniform vec4 light_col[MAX_LIGHT_COUNT]; + +varying vec4 vary_fragcoord; +uniform vec2 screen_res; + +uniform float far_z; + +uniform mat4 inv_proj; + +vec4 getPosition(ivec2 pos_screen, int sample) +{ +	float depth = texelFetch(depthMap, pos_screen, sample).r; +	vec2 sc = vec2(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; +} + +void main()  +{ +	vec2 frag = (vary_fragcoord.xy*0.5+0.5)*screen_res; +	ivec2 itc = ivec2(frag); + +	int wght = 0; +	vec3 fcol = vec3(0,0,0); + +	for (int s = 0; s < samples; ++s) +	{ +		vec3 pos = getPosition(itc, s).xyz; +		if (pos.z >= far_z) +		{ +			vec3 norm = texelFetch(normalMap, itc, s).xyz; +			norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm +			norm = normalize(norm); +			vec4 spec = texelFetch(specularRect, itc, s); +			vec3 diff = texelFetch(diffuseRect, itc, s).rgb; +			float noise = texture2D(noiseMap, frag.xy/128.0).b; +			vec3 out_col = vec3(0,0,0); +			vec3 npos = normalize(-pos); + +			// As of OSX 10.6.7 ATI Apple's crash when using a variable size loop +			for (int i = 0; i < MAX_LIGHT_COUNT; ++i) +			{ +				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) +				{ +					light_contrib = false; +				} +		 +				float da = dot(norm, lv); +				if (da < 0.0) +				{ +					light_contrib = false; +				} +		 +				if (light_contrib) +				{ +					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); +					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) +					{ +						//vec3 ref = dot(pos+lv, norm); +				 +						float sa = dot(normalize(lv+npos),norm); +				 +						if (sa > 0.0) +						{ +							sa = texture2D(lightFunc,vec2(sa, spec.a)).a * min(dist_atten*4.0, 1.0); +							sa *= noise; +							col += da*sa*light_col[i].rgb*spec.rgb; +						} +					} +			 +					out_col += col; +				} +			} +	 +			fcol += out_col; +			++wght; +		} +	} + +	if (wght <= 0) +	{ +		discard; +	} + +	gl_FragColor.rgb = fcol/wght; +	gl_FragColor.a = 0.0; + +	 +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightMSF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightMSF.glsl new file mode 100644 index 0000000000..bdaa8e59c4 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightMSF.glsl @@ -0,0 +1,233 @@ +/**  + * @file multiSpotLightF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * $/LicenseInfo$ + */ + +#version 120 + +//class 1 -- no shadows + +#extension GL_ARB_texture_rectangle : enable +#extension GL_ARB_texture_multisample : enable + +uniform sampler2DMS diffuseRect; +uniform sampler2DMS specularRect; +uniform sampler2DMS depthMap; +uniform sampler2DMS normalMap; +uniform sampler2D noiseMap; +uniform sampler2D lightFunc; +uniform sampler2D projectionMap; + +uniform mat4 proj_mat; //screen space to light space +uniform float proj_near; //near clip for projection +uniform vec3 proj_p; //plane projection is emitting from (in screen space) +uniform vec3 proj_n; +uniform float proj_focus; //distance from plane to begin blurring +uniform float proj_lod;  //(number of mips in proj map) +uniform float proj_range; //range between near clip and far clip plane of projection +uniform float proj_ambient_lod; +uniform float proj_ambiance; +uniform float near_clip; +uniform float far_clip; + +uniform vec3 proj_origin; //origin of projection to be used for angular attenuation +uniform float sun_wash; +uniform int proj_shadow_idx; +uniform float shadow_fade; + +varying vec4 vary_light; + +varying vec4 vary_fragcoord; +uniform vec2 screen_res; + +uniform mat4 inv_proj; + +vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) +{ +	vec4 ret = texture2DLod(projectionMap, tc, lod); +	 +	vec2 dist = tc-vec2(0.5); +	 +	float det = max(1.0-lod/(proj_lod*0.5), 0.0); +	 +	float d = dot(dist,dist); +		 +	ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0)+det, 1.0); +	 +	return ret; +} + +vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) +{ +	vec4 ret = texture2DLod(projectionMap, tc, lod); +	 +	vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); +	 +	float det = min(lod/(proj_lod*0.5), 1.0); +	 +	float d = min(dist.x, dist.y); +	 +	float edge = 0.25*det; +		 +	ret *= clamp(d/edge, 0.0, 1.0); +	 +	return ret; +} + +vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) +{ +	vec4 ret = texture2DLod(projectionMap, tc, lod); +	 +	vec2 dist = tc-vec2(0.5); +	 +	float d = dot(dist,dist); +		 +	ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); +	 +	return ret; +} + + +vec4 getPosition(ivec2 pos_screen, int sample) +{ +	float depth = texelFetch(depthMap, pos_screen, sample).r; +	vec2 sc = vec2(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; +} + +void main()  +{ +	int wght = 0; + +	vec3 fcol = vec3(0,0,0); + +	vec2 frag = (vary_fragcoord.xy*0.5+0.5)*screen_res; +	 +	ivec2 itc = ivec2(frag.xy); + +	for (int i = 0; i < samples; ++i) +	{ +		vec3 pos = getPosition(itc, i).xyz; +		vec3 lv = vary_light.xyz-pos.xyz; +		float dist2 = dot(lv,lv); +		dist2 /= vary_light.w; +		if (dist2 <= 1.0) +		{ +			vec3 norm = texelFetch(normalMap, itc, i).xyz*2.0-1.0; +	 +			norm = normalize(norm); +			float l_dist = -dot(lv, proj_n); +	 +			vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); +			if (proj_tc.z >= 0.0) +			{ +				proj_tc.xyz /= proj_tc.w; +	 +				float fa = gl_Color.a+1.0; +				float dist_atten = min(1.0-(dist2-1.0*(1.0-fa))/fa, 1.0); +				if (dist_atten > 0.0) +				{ +					lv = proj_origin-pos.xyz; +					lv = normalize(lv); +					float da = dot(norm, lv); +		 +					vec3 col = vec3(0,0,0); +		 +					vec3 diff_tex = texelFetch(diffuseRect, itc, i).rgb; +		 +					float noise = texture2D(noiseMap, frag.xy/128.0).b; +					if (proj_tc.z > 0.0 && +						proj_tc.x < 1.0 && +						proj_tc.y < 1.0 && +						proj_tc.x > 0.0 && +						proj_tc.y > 0.0) +					{ +						float lit = 0.0; +						float amb_da = proj_ambiance; +		 +						if (da > 0.0) +						{ +							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 = gl_Color.rgb * plcol.rgb * plcol.a; +			 +							lit = da * dist_atten * noise; +			 +							col = lcol*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); +							 +						amb_da += (da*da*0.5+0.5)*proj_ambiance; +				 +						amb_da *= dist_atten * noise; +			 +						amb_da = min(amb_da, 1.0-lit); +			 +						col += amb_da*gl_Color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; +					} +	 +	 +					vec4 spec = texelFetch(specularRect, itc, i); +					if (spec.a > 0.0) +					{ +						vec3 ref = reflect(normalize(pos), norm); +		 +						//project from point pos in direction ref to plane proj_p, proj_n +						vec3 pdelta = proj_p-pos; +						float ds = dot(ref, proj_n); +		 +						if (ds < 0.0) +						{ +							vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; +			 +							vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); + +							if (stc.z > 0.0) +							{ +								stc.xy /= stc.w; + +								float fatten = clamp(spec.a*spec.a+spec.a*0.5, 0.25, 1.0); +				 +								stc.xy = (stc.xy - vec2(0.5)) * fatten + vec2(0.5); +								 +								if (stc.x < 1.0 && +									stc.y < 1.0 && +									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*gl_Color.rgb*scol.a*spec.rgb; +								} +							} +						} +					} +	 +					fcol += col; +					++wght; +				} +			} +		} +	} + +	if (wght <= 0) +	{ +		discard; +	} + +	gl_FragColor.rgb = fcol/wght;	 +	gl_FragColor.a = 0.0; +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 22ed9dcd40..0d771109fb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -30,7 +30,7 @@ uniform vec4 viewport;  vec4 getPosition(vec2 pos_screen)  { -	float depth = texture2DRect(depthMap, pos_screen.xy).a; +	float depth = texture2DRect(depthMap, pos_screen.xy).r;  	vec2 sc = (pos_screen.xy-viewport.xy)*2.0;  	sc /= viewport.zw;  	sc -= vec2(1.0,1.0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl index 22ed9dcd40..23b5e76735 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl @@ -8,14 +8,15 @@   #version 120  #extension GL_ARB_texture_rectangle : enable +#extension GL_ARB_texture_multisample : enable -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect normalMap; -uniform samplerCube environmentMap; +uniform sampler2DMS depthMap; +uniform sampler2DMS diffuseRect; +uniform sampler2DMS specularRect; +uniform sampler2DMS normalMap;  uniform sampler2D noiseMap;  uniform sampler2D lightFunc; -uniform sampler2DRect depthMap; +  uniform vec3 env_mat[3];  uniform float sun_wash; @@ -28,10 +29,10 @@ uniform vec2 screen_res;  uniform mat4 inv_proj;  uniform vec4 viewport; -vec4 getPosition(vec2 pos_screen) +vec4 getPosition(ivec2 pos_screen, int sample)  { -	float depth = texture2DRect(depthMap, pos_screen.xy).a; -	vec2 sc = (pos_screen.xy-viewport.xy)*2.0; +	float depth = texelFetch(depthMap, pos_screen, sample).r; +	vec2 sc = (vec2(pos_screen.xy)-viewport.xy)*2.0;  	sc /= viewport.zw;  	sc -= vec2(1.0,1.0);  	vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); @@ -48,53 +49,60 @@ void main()  	frag.xyz = frag.xyz*0.5+0.5;  	frag.xy *= screen_res; -	vec3 pos = getPosition(frag.xy).xyz; -	vec3 lv = vary_light.xyz-pos; -	float dist2 = dot(lv,lv); -	dist2 /= vary_light.w; -	if (dist2 > 1.0) -	{ -		discard; -	} -	 -	vec3 norm = texture2DRect(normalMap, frag.xy).xyz; -	norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm -	float da = dot(norm, lv); -	if (da < 0.0) +	ivec2 itc = ivec2(frag.xy); + +	int wght = 0; +	vec3 fcol = vec3(0,0,0); + +	for (int s = 0; s < samples; ++s)  	{ -		discard; -	} -	 -	norm = normalize(norm); -	lv = normalize(lv); -	da = dot(norm, lv); +		vec3 pos = getPosition(itc, s).xyz; +		vec3 lv = vary_light.xyz-pos; +		float dist2 = dot(lv,lv); +		dist2 /= vary_light.w; +		if (dist2 <= 1.0) +		{ +			vec3 norm = texelFetch(normalMap, itc, s).xyz; +			norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm +			float da = dot(norm, lv); +			if (da >= 0.0) +			{ +				norm = normalize(norm); +				lv = normalize(lv); +				da = dot(norm, lv); -	float noise = texture2D(noiseMap, frag.xy/128.0).b; +				float noise = texture2D(noiseMap, frag.xy/128.0).b; -	vec3 col = texture2DRect(diffuseRect, frag.xy).rgb; -	float fa = gl_Color.a+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; +				vec3 col = texelFetch(diffuseRect, itc, s).rgb; +				float fa = gl_Color.a+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; -	col = gl_Color.rgb*lit*col; +				col = gl_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) -		{ -			sa = texture2D(lightFunc, vec2(sa, spec.a)).a * min(dist_atten*4.0, 1.0); -			sa *= noise; -			col += da*sa*gl_Color.rgb*spec.rgb; +				vec4 spec = texelFetch(specularRect, itc, s); +				if (spec.a > 0.0) +				{ +					float sa = dot(normalize(lv-normalize(pos)),norm); +					if (sa > 0.0) +					{ +						sa = texture2D(lightFunc, vec2(sa, spec.a)).a * min(dist_atten*4.0, 1.0); +						sa *= noise; +						col += da*sa*gl_Color.rgb*spec.rgb; +					} +				} + +				fcol += col; +				++wght; +			}  		}  	} -	if (dot(col, col) <= 0.0) +	if (wght <= 0)  	{  		discard;  	} -	gl_FragColor.rgb = col;	 +	gl_FragColor.rgb = fcol/wght;	  	gl_FragColor.a = 0.0;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl index 8e74feb615..2377947e7f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl @@ -10,14 +10,9 @@  varying vec4 vary_light;  varying vec4 vary_fragcoord; -uniform vec2 screen_res; -uniform float near_clip; -  void main()  {  	//transform vertex -	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;  -  	vec4 pos = gl_ModelViewProjectionMatrix * gl_Vertex;  	vary_fragcoord = pos; @@ -25,6 +20,8 @@ void main()  	tex.w = 1.0;  	vary_light = gl_MultiTexCoord0; +	 +	gl_Position = pos;  	gl_FrontColor = gl_Color;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl index 77f1b2224c..d389add03b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl @@ -29,7 +29,7 @@ varying vec2 vary_fragcoord;  float getDepth(vec2 pos_screen)  { -	float z = texture2DRect(depthMap, pos_screen.xy).a; +	float z = texture2DRect(depthMap, pos_screen.xy).r;  	z = z*2.0-1.0;  	vec4 ndc = vec4(0.0, 0.0, z, 1.0);  	vec4 p = inv_proj*ndc; diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredMSF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredMSF.glsl index a34f882c39..711c6dc96d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredMSF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredMSF.glsl @@ -31,12 +31,12 @@ varying vec2 vary_fragcoord;  vec4 texture2DMS(sampler2DMS tex, ivec2 tc)  {  	vec4 ret = vec4(0,0,0,0); -	for (int i = 0; i < 4; ++i) +	for (int i = 0; i < samples; ++i)  	{  		ret += texelFetch(tex, tc, i);  	} -	return ret * 0.25; +	return ret/samples;  }  float getDepth(ivec2 pos_screen) diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFMSF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFMSF.glsl index 7b14974f8b..359b26b7d4 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFMSF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFMSF.glsl @@ -18,13 +18,14 @@ varying vec2 vary_fragcoord;  vec4 texture2DMS(sampler2DMS tex, ivec2 tc)  { -	vec4 ret = texelFetch(tex,tc,0); -	ret += texelFetch(tex,tc,1); -	ret += texelFetch(tex,tc,2); -	ret += texelFetch(tex,tc,3); -	ret *= 0.25; +	vec4 ret = vec4(0,0,0,0); -	return ret; +	for (int i = 0; i < samples; ++i) +	{ +		 ret += texelFetch(tex,tc,i); +	} + +	return ret/samples;  }  void main()  diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 29340c7e9f..c1147feff6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -259,7 +259,7 @@ vec3 scaleSoftClip(vec3 light)  void main()   {  	vec2 tc = vary_fragcoord.xy; -	float depth = texture2DRect(depthMap, tc.xy).a; +	float depth = texture2DRect(depthMap, tc.xy).r;  	vec3 pos = getPosition_d(tc, depth).xyz;  	vec3 norm = texture2DRect(normalMap, tc).xyz;  	norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightMSF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightMSF.glsl index 4c38d91499..fcba4f57e6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightMSF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightMSF.glsl @@ -251,18 +251,18 @@ vec3 scaleSoftClip(vec3 light)  vec4 texture2DMS(sampler2DMS tex, ivec2 tc)  { -	vec4 ret = texelFetch(tex,tc,0); -	ret += texelFetch(tex,tc,1); -	ret += texelFetch(tex,tc,2); -	ret += texelFetch(tex,tc,3); -	ret *= 0.25; +	vec4 ret = vec4(0,0,0,0); -	return ret; +	for (int i = 0; i < samples; ++i) +	{ +		 ret += texelFetch(tex,tc,i); +	} + +	return ret/samples;  }  void main()   { -	int samples = 4;  	vec2 tc = vary_fragcoord.xy;  	ivec2 itc = ivec2(tc); diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightMSF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightMSF.glsl new file mode 100644 index 0000000000..3a9d9266bb --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightMSF.glsl @@ -0,0 +1,234 @@ +/**  + * @file multiSpotLightF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * $/LicenseInfo$ + */ + +#version 120 + +//class 1 -- no shadows + +#extension GL_ARB_texture_rectangle : enable +#extension GL_ARB_texture_multisample : enable + +uniform sampler2DMS diffuseRect; +uniform sampler2DMS specularRect; +uniform sampler2DMS depthMap; +uniform sampler2DMS normalMap; +uniform sampler2D noiseMap; +uniform sampler2D lightFunc; +uniform sampler2D projectionMap; + +uniform mat4 proj_mat; //screen space to light space +uniform float proj_near; //near clip for projection +uniform vec3 proj_p; //plane projection is emitting from (in screen space) +uniform vec3 proj_n; +uniform float proj_focus; //distance from plane to begin blurring +uniform float proj_lod;  //(number of mips in proj map) +uniform float proj_range; //range between near clip and far clip plane of projection +uniform float proj_ambient_lod; +uniform float proj_ambiance; +uniform float near_clip; +uniform float far_clip; + +uniform vec3 proj_origin; //origin of projection to be used for angular attenuation +uniform float sun_wash; +uniform int proj_shadow_idx; +uniform float shadow_fade; + +varying vec4 vary_light; + +varying vec4 vary_fragcoord; +uniform vec2 screen_res; + +uniform mat4 inv_proj; + +vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) +{ +	vec4 ret = texture2DLod(projectionMap, tc, lod); +	 +	vec2 dist = tc-vec2(0.5); +	 +	float det = max(1.0-lod/(proj_lod*0.5), 0.0); +	 +	float d = dot(dist,dist); +		 +	ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0)+det, 1.0); +	 +	return ret; +} + +vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) +{ +	vec4 ret = texture2DLod(projectionMap, tc, lod); +	 +	vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); +	 +	float det = min(lod/(proj_lod*0.5), 1.0); +	 +	float d = min(dist.x, dist.y); +	 +	float edge = 0.25*det; +		 +	ret *= clamp(d/edge, 0.0, 1.0); +	 +	return ret; +} + +vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) +{ +	vec4 ret = texture2DLod(projectionMap, tc, lod); +	 +	vec2 dist = tc-vec2(0.5); +	 +	float d = dot(dist,dist); +		 +	ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); +	 +	return ret; +} + + +vec4 getPosition(ivec2 pos_screen, int sample) +{ +	float depth = texelFetch(depthMap, pos_screen, sample).r; +	vec2 sc = vec2(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; +} + +void main()  +{ +	vec4 frag = vary_fragcoord; +	frag.xyz /= frag.w; +	frag.xyz = frag.xyz*0.5+0.5; +	frag.xy *= screen_res; +	ivec2 itc = ivec2(frag.xy); + +	vec3 fcol = vec3(0,0,0); +	int wght = 0; +	 +	for (int i = 0; i < samples; ++i) +	{ +		vec3 pos = getPosition(itc, i).xyz; +		vec3 lv = vary_light.xyz-pos.xyz; +		float dist2 = dot(lv,lv); +		dist2 /= vary_light.w; +		if (dist2 <= 1.0) +		{ +			vec3 norm = texelFetch(normalMap, itc, i).xyz*2.0-1.0; +	 +			norm = normalize(norm); +			float l_dist = -dot(lv, proj_n); +	 +			vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); +			if (proj_tc.z >= 0.0) +			{ +				proj_tc.xyz /= proj_tc.w; +	 +				float fa = gl_Color.a+1.0; +				float dist_atten = min(1.0-(dist2-1.0*(1.0-fa))/fa, 1.0); +				if (dist_atten > 0.0) +				{ +					lv = proj_origin-pos.xyz; +					lv = normalize(lv); +					float da = dot(norm, lv); +		 +					vec3 col = vec3(0,0,0); +		 +					vec3 diff_tex = texelFetch(diffuseRect, itc, i).rgb; +		 +					float noise = texture2D(noiseMap, frag.xy/128.0).b; +					if (proj_tc.z > 0.0 && +						proj_tc.x < 1.0 && +						proj_tc.y < 1.0 && +						proj_tc.x > 0.0 && +						proj_tc.y > 0.0) +					{ +						float lit = 0.0; +						float amb_da = proj_ambiance; +		 +						if (da > 0.0) +						{ +							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 = gl_Color.rgb * plcol.rgb * plcol.a; +			 +							lit = da * dist_atten * noise; +			 +							col = lcol*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); +							 +						amb_da += (da*da*0.5+0.5)*proj_ambiance; +				 +						amb_da *= dist_atten * noise; +			 +						amb_da = min(amb_da, 1.0-lit); +			 +						col += amb_da*gl_Color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; +					} +	 +	 +					vec4 spec = texelFetch(specularRect, itc, i); +					if (spec.a > 0.0) +					{ +						vec3 ref = reflect(normalize(pos), norm); +		 +						//project from point pos in direction ref to plane proj_p, proj_n +						vec3 pdelta = proj_p-pos; +						float ds = dot(ref, proj_n); +		 +						if (ds < 0.0) +						{ +							vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; +			 +							vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); + +							if (stc.z > 0.0) +							{ +								stc.xy /= stc.w; + +								float fatten = clamp(spec.a*spec.a+spec.a*0.5, 0.25, 1.0); +				 +								stc.xy = (stc.xy - vec2(0.5)) * fatten + vec2(0.5); +								 +								if (stc.x < 1.0 && +									stc.y < 1.0 && +									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*gl_Color.rgb*scol.a*spec.rgb; +								} +							} +						} +					} +	 +					fcol += col; +					++wght; +				} +			} +		} +	} + +	if (wght <= 0) +	{ +		discard; +	} + +	gl_FragColor.rgb = fcol/wght;	 +	gl_FragColor.a = 0.0; +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl new file mode 100644 index 0000000000..b1c25b7fd3 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl @@ -0,0 +1,19 @@ +/**  + * @file starsF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * $/LicenseInfo$ + */ +  +#version 120 + +uniform sampler2D diffuseMap; + +void main()  +{ +	vec4 col = gl_Color * texture2D(diffuseMap, gl_TexCoord[0].xy); +	 +	gl_FragData[0] = col; +	gl_FragData[1] = vec4(0,0,0,0); +	gl_FragData[2] = vec4(0,0,1,0);	 +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl new file mode 100644 index 0000000000..1f0376ce6b --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl @@ -0,0 +1,17 @@ +/**  + * @file starsV.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * $/LicenseInfo$ + */ +  +#version 120 + + +void main() +{ +	//transform vertex +	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;  +	gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; +	gl_FrontColor = gl_Color; +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl index cd91351ad4..d1e8359742 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl @@ -35,7 +35,7 @@ uniform float shadow_offset;  vec4 getPosition(vec2 pos_screen)  { -	float depth = texture2DRect(depthMap, pos_screen.xy).a; +	float depth = texture2DRect(depthMap, pos_screen.xy).r;  	vec2 sc = pos_screen.xy*2.0;  	sc /= screen_res;  	sc -= vec2(1.0,1.0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOMSF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOMSF.glsl index 49b45dedd6..ce0ebc54f8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOMSF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOMSF.glsl @@ -101,8 +101,6 @@ float calcAmbientOcclusion(vec4 pos, vec3 norm, int sample)  void main()   { -	int samples = 4; -  	vec2 pos_screen = vary_fragcoord.xy;  	ivec2 itc = ivec2(pos_screen); | 
