SHOW:
|
|
- or go back to the newest paste.
1 | - | // passthrough.vert |
1 | + | // gaussianTexCoordsX.vert |
2 | #version 120 | |
3 | ||
4 | - | attribute vec3 position; |
4 | + | attribute vec4 position; |
5 | - | varying vec3 vertex; |
5 | + | attribute vec2 texCoord; |
6 | ||
7 | varying vec2 vertex; | |
8 | - | vertex = position; |
8 | + | varying vec2 blurCoords[7]; |
9 | - | gl_Position = gl_ModelViewProjectionMatrix * vec4(position, 1); |
9 | + | |
10 | void main() { | |
11 | gl_Position = position; | |
12 | ||
13 | vertex = texCoord; | |
14 | blurCoords[0] = texCoord + vec2(-3, 0); | |
15 | - | varying vec3 vertex; |
15 | + | blurCoords[1] = texCoord + vec2(-2, 0); |
16 | blurCoords[2] = texCoord + vec2(-1, 0); | |
17 | blurCoords[3] = texCoord + vec2( 0, 0); | |
18 | blurCoords[4] = texCoord + vec2( 1, 0); | |
19 | blurCoords[5] = texCoord + vec2( 2, 0); | |
20 | blurCoords[6] = texCoord + vec2( 3, 0); | |
21 | } | |
22 | - | uniform sampler3D tex; |
22 | + | |
23 | - | uniform vec3 direction; |
23 | + | |
24 | - | uniform vec4 color; |
24 | + | |
25 | ||
26 | - | // Simple gaussian blur in the specified direction (set direction.x, direction.y, direction.z) |
26 | + | varying vec2 vertex; |
27 | - | // standard deviation is 1, sample rate is 1 per pixel in a 3 pixel radius |
27 | + | varying vec2 blurCoords[7]; |
28 | ||
29 | const float gaussD3 = 0.0044318; | |
30 | const float gaussD2 = 0.0539910; | |
31 | - | sum += texture3D(tex, vec3(vertex.x - 3*direction.x, vertex.y - 3*direction.y, vertex.z - 3*direction.z)) * gaussD3; |
31 | + | |
32 | - | sum += texture3D(tex, vec3(vertex.x - 2*direction.x, vertex.y - 2*direction.y, vertex.z - 2*direction.z)) * gaussD2; |
32 | + | |
33 | - | sum += texture3D(tex, vec3(vertex.x - 1*direction.x, vertex.y - 1*direction.y, vertex.z - 1*direction.z)) * gaussD1; |
33 | + | |
34 | - | sum += texture3D(tex, vec3(vertex.x, vertex.y, vertex.z)) * gaussD0; |
34 | + | uniform sampler2D tex; |
35 | - | sum += texture3D(tex, vec3(vertex.x + 1*direction.x, vertex.y + 1*direction.y, vertex.z + 1*direction.z)) * gaussD1; |
35 | + | |
36 | - | sum += texture3D(tex, vec3(vertex.x + 2*direction.x, vertex.y + 2*direction.y, vertex.z + 2*direction.z)) * gaussD2; |
36 | + | // Simple gaussian blur over the specified coordinates (blurCoords[blurCoords.length/2] is middle point) |
37 | - | sum += texture3D(tex, vec3(vertex.x + 3*direction.x, vertex.y + 3*direction.y, vertex.z + 3*direction.z)) * gaussD3; |
37 | + | // standard deviation is 1 |
38 | void main() { | |
39 | - | gl_FragColor = color * sum; |
39 | + | |
40 | ||
41 | sum += texture2D(tex, blurCoords[0]) * gaussD3; | |
42 | sum += texture2D(tex, blurCoords[1]) * gaussD2; | |
43 | sum += texture2D(tex, blurCoords[2]) * gaussD1; | |
44 | sum += texture2D(tex, blurCoords[3]) * gaussD0; | |
45 | sum += texture2D(tex, blurCoords[4]) * gaussD1; | |
46 | sum += texture2D(tex, blurCoords[5]) * gaussD2; | |
47 | sum += texture2D(tex, blurCoords[6]) * gaussD3; | |
48 | ||
49 | gl_FragColor = sum; | |
50 | } |