summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings/shaders/class1/deferred/sunLightF.glsl
diff options
context:
space:
mode:
authorDavid Parks <davep@lindenlab.com>2009-09-22 11:11:45 +0000
committerDavid Parks <davep@lindenlab.com>2009-09-22 11:11:45 +0000
commit536e38ad51b89808f26d8e3cd107fe093862d22a (patch)
tree230159ae9e319f5c419f1a643177b2bbb17d52c5 /indra/newview/app_settings/shaders/class1/deferred/sunLightF.glsl
parent760adead96e62cab8f9cdacc6469773a87dfbc1a (diff)
Merging render-pipeline-6-qa-2 into viewer-2
Self reviewed.
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/deferred/sunLightF.glsl')
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/sunLightF.glsl111
1 files changed, 86 insertions, 25 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightF.glsl
index d43fe6ca95..22bdd2c7f3 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/sunLightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightF.glsl
@@ -7,17 +7,21 @@
#extension GL_ARB_texture_rectangle : enable
-uniform sampler2DRect positionMap;
-uniform sampler2DRect normalMap;
uniform sampler2DRect depthMap;
-uniform sampler2DShadow shadowMap0;
-uniform sampler2DShadow shadowMap1;
-uniform sampler2DShadow shadowMap2;
-uniform sampler2DShadow shadowMap3;
+uniform sampler2DRect normalMap;
+uniform sampler2DRectShadow shadowMap0;
+uniform sampler2DRectShadow shadowMap1;
+uniform sampler2DRectShadow shadowMap2;
+uniform sampler2DRectShadow shadowMap3;
+uniform sampler2DRectShadow shadowMap4;
+uniform sampler2DRectShadow shadowMap5;
uniform sampler2D noiseMap;
+uniform sampler2D lightFunc;
+
+
// Inputs
-uniform mat4 shadow_matrix[4];
+uniform mat4 shadow_matrix[6];
uniform vec4 shadow_clip;
uniform float ssao_radius;
uniform float ssao_max_radius;
@@ -27,6 +31,25 @@ uniform float ssao_factor_inv;
varying vec2 vary_fragcoord;
varying vec4 vary_light;
+uniform mat4 inv_proj;
+uniform vec2 screen_res;
+
+uniform float shadow_bias;
+uniform float shadow_offset;
+
+vec4 getPosition(vec2 pos_screen)
+{
+ float depth = texture2DRect(depthMap, pos_screen.xy).a;
+ vec2 sc = pos_screen.xy*2.0;
+ sc /= screen_res;
+ sc -= vec2(1.0,1.0);
+ vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0);
+ vec4 pos = inv_proj * ndc;
+ pos /= pos.w;
+ pos.w = 1.0;
+ return pos;
+}
+
//calculate decreases in ambient lighting when crowded out (SSAO)
float calcAmbientOcclusion(vec4 pos, vec3 norm)
{
@@ -54,7 +77,7 @@ float calcAmbientOcclusion(vec4 pos, vec3 norm)
for (int i = 0; i < 8; i++)
{
vec2 samppos_screen = pos_screen + scale * reflect(kern[i], noise_reflect);
- vec3 samppos_world = texture2DRect(positionMap, samppos_screen).xyz;
+ vec3 samppos_world = getPosition(samppos_screen).xyz;
vec3 diff = pos_world - samppos_world;
float dist2 = dot(diff, diff);
@@ -74,14 +97,18 @@ float calcAmbientOcclusion(vec4 pos, vec3 norm)
angle_hidden = min(ssao_factor*angle_hidden/float(points), 1.0);
- return 1.0 - (float(points != 0) * angle_hidden);
+ return (1.0 - (float(points != 0) * angle_hidden));
}
void main()
{
vec2 pos_screen = vary_fragcoord.xy;
- vec4 pos = vec4(texture2DRect(positionMap, pos_screen).xyz, 1.0);
- vec3 norm = texture2DRect(normalMap, pos_screen).xyz;
+
+ //try doing an unproject here
+
+ vec4 pos = getPosition(pos_screen);
+
+ vec3 norm = texture2DRect(normalMap, pos_screen).xyz*2.0-1.0;
/*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL
{
@@ -90,35 +117,45 @@ void main()
}*/
float shadow = 1.0;
- float dp_directional_light = max(0.0, dot(norm, vary_light.xyz));
+ float dp_directional_light = max(0.0, dot(norm, vary_light.xyz));
+ vec4 spos = vec4(pos.xyz + norm.xyz * (-pos.z/64.0*shadow_offset+shadow_bias), 1.0);
+
+ //vec3 debug = vec3(0,0,0);
+
if (dp_directional_light == 0.0)
{
// if we know this point is facing away from the sun then we know it's in shadow without having to do a squirrelly shadow-map lookup
shadow = 0.0;
}
- else if (pos.z > -shadow_clip.w)
+ else if (spos.z > -shadow_clip.w)
{
- if (pos.z < -shadow_clip.z)
+ vec4 lpos;
+
+ if (spos.z < -shadow_clip.z)
{
- vec4 lpos = shadow_matrix[3]*pos;
- shadow = shadow2DProj(shadowMap3, lpos).x;
+ lpos = shadow_matrix[3]*spos;
+ lpos.xy *= screen_res;
+ shadow = shadow2DRectProj(shadowMap3, lpos).x;
shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0);
}
- else if (pos.z < -shadow_clip.y)
+ else if (spos.z < -shadow_clip.y)
{
- vec4 lpos = shadow_matrix[2]*pos;
- shadow = shadow2DProj(shadowMap2, lpos).x;
+ lpos = shadow_matrix[2]*spos;
+ lpos.xy *= screen_res;
+ shadow = shadow2DRectProj(shadowMap2, lpos).x;
}
- else if (pos.z < -shadow_clip.x)
+ else if (spos.z < -shadow_clip.x)
{
- vec4 lpos = shadow_matrix[1]*pos;
- shadow = shadow2DProj(shadowMap1, lpos).x;
+ lpos = shadow_matrix[1]*spos;
+ lpos.xy *= screen_res;
+ shadow = shadow2DRectProj(shadowMap1, lpos).x;
}
else
{
- vec4 lpos = shadow_matrix[0]*pos;
- shadow = shadow2DProj(shadowMap0, lpos).x;
+ lpos = shadow_matrix[0]*spos;
+ lpos.xy *= screen_res;
+ shadow = shadow2DRectProj(shadowMap0, lpos).x;
}
// take the most-shadowed value out of these two:
@@ -126,6 +163,17 @@ void main()
// * an unblurred dot product between the sun and this norm
// the goal is to err on the side of most-shadow to fill-in shadow holes and reduce artifacting
shadow = min(shadow, dp_directional_light);
+
+ /*debug.r = lpos.y / (lpos.w*screen_res.y);
+
+ lpos.xy /= lpos.w*32.0;
+ if (fract(lpos.x) < 0.1 || fract(lpos.y) < 0.1)
+ {
+ debug.gb = vec2(0.5, 0.5);
+ }
+
+ debug += (1.0-shadow)*0.5;*/
+
}
else
{
@@ -135,5 +183,18 @@ void main()
gl_FragColor[0] = shadow;
gl_FragColor[1] = calcAmbientOcclusion(pos, norm);
- //gl_FragColor[2] is unused as of August 2008, may be used for debugging
+
+ //spotlight shadow 1
+ vec4 lpos = shadow_matrix[4]*spos;
+ lpos.xy *= screen_res;
+ gl_FragColor[2] = shadow2DRectProj(shadowMap4, lpos).x;
+
+ //spotlight shadow 2
+ lpos = shadow_matrix[5]*spos;
+ lpos.xy *= screen_res;
+ gl_FragColor[3] = shadow2DRectProj(shadowMap5, lpos).x;
+
+ //gl_FragColor.rgb = pos.xyz;
+ //gl_FragColor.b = shadow;
+ //gl_FragColor.rgb = debug;
}