diff options
Diffstat (limited to 'linden/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl')
-rw-r--r-- | linden/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/linden/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl b/linden/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl new file mode 100644 index 0000000..0055a73 --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl | |||
@@ -0,0 +1,112 @@ | |||
1 | /** | ||
2 | * @file alphaF.glsl | ||
3 | * | ||
4 | * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc. | ||
5 | * $License$ | ||
6 | */ | ||
7 | |||
8 | #extension GL_ARB_texture_rectangle : enable | ||
9 | |||
10 | uniform sampler2D diffuseMap; | ||
11 | uniform sampler2DRectShadow shadowMap0; | ||
12 | uniform sampler2DRectShadow shadowMap1; | ||
13 | uniform sampler2DRectShadow shadowMap2; | ||
14 | uniform sampler2DRectShadow shadowMap3; | ||
15 | uniform sampler2D noiseMap; | ||
16 | uniform sampler2DRect depthMap; | ||
17 | |||
18 | uniform mat4 shadow_matrix[6]; | ||
19 | uniform vec4 shadow_clip; | ||
20 | uniform vec2 screen_res; | ||
21 | |||
22 | vec3 atmosLighting(vec3 light); | ||
23 | vec3 scaleSoftClip(vec3 light); | ||
24 | |||
25 | varying vec3 vary_ambient; | ||
26 | varying vec3 vary_directional; | ||
27 | varying vec3 vary_fragcoord; | ||
28 | varying vec3 vary_position; | ||
29 | varying vec3 vary_light; | ||
30 | |||
31 | uniform float alpha_soften; | ||
32 | |||
33 | uniform mat4 inv_proj; | ||
34 | |||
35 | vec4 getPosition(vec2 pos_screen) | ||
36 | { | ||
37 | float depth = texture2DRect(depthMap, pos_screen.xy).a; | ||
38 | vec2 sc = pos_screen.xy*2.0; | ||
39 | sc /= screen_res; | ||
40 | sc -= vec2(1.0,1.0); | ||
41 | vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); | ||
42 | vec4 pos = inv_proj * ndc; | ||
43 | pos /= pos.w; | ||
44 | pos.w = 1.0; | ||
45 | return pos; | ||
46 | } | ||
47 | |||
48 | void main() | ||
49 | { | ||
50 | vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; | ||
51 | frag *= screen_res; | ||
52 | |||
53 | vec3 samp_pos = getPosition(frag).xyz; | ||
54 | |||
55 | float shadow = 1.0; | ||
56 | vec4 pos = vec4(vary_position, 1.0); | ||
57 | |||
58 | vec4 spos = pos; | ||
59 | |||
60 | if (spos.z > -shadow_clip.w) | ||
61 | { | ||
62 | vec4 lpos; | ||
63 | |||
64 | if (spos.z < -shadow_clip.z) | ||
65 | { | ||
66 | lpos = shadow_matrix[3]*spos; | ||
67 | lpos.xy *= screen_res; | ||
68 | shadow = shadow2DRectProj(shadowMap3, lpos).x; | ||
69 | shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); | ||
70 | } | ||
71 | else if (spos.z < -shadow_clip.y) | ||
72 | { | ||
73 | lpos = shadow_matrix[2]*spos; | ||
74 | lpos.xy *= screen_res; | ||
75 | shadow = shadow2DRectProj(shadowMap2, lpos).x; | ||
76 | } | ||
77 | else if (spos.z < -shadow_clip.x) | ||
78 | { | ||
79 | lpos = shadow_matrix[1]*spos; | ||
80 | lpos.xy *= screen_res; | ||
81 | shadow = shadow2DRectProj(shadowMap1, lpos).x; | ||
82 | } | ||
83 | else | ||
84 | { | ||
85 | lpos = shadow_matrix[0]*spos; | ||
86 | lpos.xy *= screen_res; | ||
87 | shadow = shadow2DRectProj(shadowMap0, lpos).x; | ||
88 | } | ||
89 | } | ||
90 | |||
91 | vec4 col = vec4(vary_ambient + vary_directional.rgb*shadow, gl_Color.a); | ||
92 | vec4 color = texture2D(diffuseMap, gl_TexCoord[0].xy) * col; | ||
93 | |||
94 | color.rgb = atmosLighting(color.rgb); | ||
95 | |||
96 | color.rgb = scaleSoftClip(color.rgb); | ||
97 | |||
98 | if (samp_pos.z != 0.0) | ||
99 | { | ||
100 | float dist_factor = alpha_soften; | ||
101 | float a = gl_Color.a; | ||
102 | a *= a; | ||
103 | dist_factor *= 1.0/(1.0-a); | ||
104 | color.a *= min((pos.z-samp_pos.z)*dist_factor, 1.0); | ||
105 | } | ||
106 | |||
107 | //gl_FragColor = gl_Color; | ||
108 | gl_FragColor = color; | ||
109 | //gl_FragColor = vec4(1,0,1,1)*shadow; | ||
110 | |||
111 | } | ||
112 | |||