forked from pyalot/WebGL-City-SSAO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiply.shader
38 lines (33 loc) · 955 Bytes
/
multiply.shader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
:copyright: 2011 by Florian Boesch <[email protected]>.
:license: GNU AGPL3, see LICENSE for more details.
*/
vertex:
attribute vec3 position;
attribute vec2 texcoord;
varying vec2 v_texcoord;
void main(void) {
gl_Position = vec4(position, 1.0);
v_texcoord = texcoord;
}
fragment: depthutil
varying vec2 v_texcoord;
uniform sampler2D source, occlusionmap;
float far = 1.0;
float near = 0.0;
vec3 decode_normal(vec2 enc)
{
vec2 fenc = enc*4.0-2.0;
float f = dot(fenc,fenc);
float g = sqrt(1.0-f/4.0);
return vec3(fenc*g, 1.0-f/2.0);
}
float decode_depth(vec2 src){
float depth = src.x/255.0+src.y;
return depth*far+near;
}
void main(void){
vec3 color = texture2D(source, v_texcoord).rgb;
vec4 occlusion = texture2D(occlusionmap, v_texcoord);
gl_FragColor = vec4(color*occlusion.a, 1.0);
}