diff options
Diffstat (limited to 'linden/indra/newview/app_settings/shaders/class3/deferred/postgiF.glsl')
-rw-r--r-- | linden/indra/newview/app_settings/shaders/class3/deferred/postgiF.glsl | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/linden/indra/newview/app_settings/shaders/class3/deferred/postgiF.glsl b/linden/indra/newview/app_settings/shaders/class3/deferred/postgiF.glsl new file mode 100644 index 0000000..12a5f39 --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class3/deferred/postgiF.glsl | |||
@@ -0,0 +1,87 @@ | |||
1 | /** | ||
2 | * @file postgiF.glsl | ||
3 | * | ||
4 | * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc. | ||
5 | * $License$ | ||
6 | */ | ||
7 | |||
8 | uniform sampler2DRect depthMap; | ||
9 | uniform sampler2DRect normalMap; | ||
10 | uniform sampler2DRect giLightMap; | ||
11 | uniform sampler2D noiseMap; | ||
12 | |||
13 | uniform vec2 kern[32]; | ||
14 | uniform float dist_factor; | ||
15 | uniform float blur_size; | ||
16 | uniform vec2 delta; | ||
17 | uniform int kern_length; | ||
18 | uniform float kern_scale; | ||
19 | uniform vec3 blur_quad; | ||
20 | |||
21 | varying vec2 vary_fragcoord; | ||
22 | |||
23 | uniform mat4 inv_proj; | ||
24 | uniform vec2 screen_res; | ||
25 | |||
26 | vec4 getPosition(vec2 pos_screen) | ||
27 | { | ||
28 | float depth = texture2DRect(depthMap, pos_screen.xy).a; | ||
29 | vec2 sc = pos_screen.xy*2.0; | ||
30 | sc /= screen_res; | ||
31 | sc -= vec2(1.0,1.0); | ||
32 | vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); | ||
33 | vec4 pos = inv_proj * ndc; | ||
34 | pos /= pos.w; | ||
35 | pos.w = 1.0; | ||
36 | return pos; | ||
37 | } | ||
38 | |||
39 | float getDepth(vec2 pos_screen) | ||
40 | { | ||
41 | float z = texture2DRect(depthMap, pos_screen.xy).a; | ||
42 | z = z*2.0-1.0; | ||
43 | vec4 ndc = vec4(0.0, 0.0, z, 1.0); | ||
44 | vec4 p = inv_proj*ndc; | ||
45 | return p.z/p.w; | ||
46 | } | ||
47 | |||
48 | void main() | ||
49 | { | ||
50 | vec3 norm = texture2DRect(normalMap, vary_fragcoord.xy).xyz*2.0-1.0; | ||
51 | float depth = getDepth(vary_fragcoord.xy); | ||
52 | |||
53 | vec3 ccol = texture2DRect(giLightMap, vary_fragcoord.xy).rgb; | ||
54 | vec2 dlt = kern_scale * delta/(vec2(1.0,1.0)+norm.xy*norm.xy); | ||
55 | dlt /= clamp(-depth*blur_quad.x, 1.0, 3.0); | ||
56 | float defined_weight = kern[0].x; | ||
57 | vec3 col = ccol*kern[0].x; | ||
58 | |||
59 | for (int i = 0; i < kern_length; i++) | ||
60 | { | ||
61 | vec2 tc = vary_fragcoord.xy + kern[i].y*dlt; | ||
62 | vec3 sampNorm = texture2DRect(normalMap, tc.xy).xyz*2.0-1.0; | ||
63 | |||
64 | float d = dot(norm.xyz, sampNorm); | ||
65 | |||
66 | if (d > 0.5) | ||
67 | { | ||
68 | float sampdepth = getDepth(tc.xy); | ||
69 | sampdepth -= depth; | ||
70 | if (sampdepth*sampdepth < blur_quad.z) | ||
71 | { | ||
72 | col += texture2DRect(giLightMap, tc).rgb*kern[i].x; | ||
73 | defined_weight += kern[i].x; | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | |||
78 | col /= defined_weight; | ||
79 | |||
80 | //col = ccol; | ||
81 | |||
82 | col = col*blur_quad.y; | ||
83 | |||
84 | gl_FragData[0].xyz = col; | ||
85 | |||
86 | //gl_FragColor = ccol; | ||
87 | } | ||