forked from rodrigomas/DCTLs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gaussian2.dctl
49 lines (27 loc) · 2.16 KB
/
Gaussian2.dctl
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
39
40
41
42
43
44
45
46
47
48
49
// Gaussian Blur
// Resolution: 3x3
// Sigma^2 = 1
__DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, __TEXTURE__ p_TexR, __TEXTURE__ p_TexG, __TEXTURE__ p_TexB)
{
const float e = 2.718281828459f;
const float sqrtTwoPI = 2.506628274631f;
const float sigma = 1.0f;
const float a = (1.0f / (sqrtTwoPI * sigma));
const float b = _powf(e, -1.0f*( 1.0f / (2.0f * sigma * sigma))) * (1.0f / (sqrtTwoPI * sigma));
const float c = _powf(e, -1.0f*( 2.0f / (2.0f * sigma * sigma))) * (1.0f / (sqrtTwoPI * sigma));
const float N = a + (b * 4.0f) + (c * 4.0f);
const float A = a / N;
const float B = b / N;
const float C = c / N;
const float Gaus[9] = {C, B, C,
B, A, B,
C, B, C};
float3 result;
result.x = (Gaus[0] * _tex2D(p_TexR, p_X - 1, p_Y + 1)) + (Gaus[1] * _tex2D(p_TexR, p_X, p_Y + 1)) + (Gaus[2] * _tex2D(p_TexR, p_X + 1, p_Y + 1)) + (Gaus[3] * _tex2D(p_TexR, p_X - 1, p_Y)) + (Gaus[4] * _tex2D(p_TexR, p_X, p_Y))
+ (Gaus[5] * _tex2D(p_TexR, p_X + 1, p_Y)) + (Gaus[6] * _tex2D(p_TexR, p_X - 1, p_Y - 1)) + (Gaus[7] * _tex2D(p_TexR, p_X, p_Y - 1)) + (Gaus[8] * _tex2D(p_TexR, p_X - 1, p_Y - 1));
result.y = (Gaus[0] * _tex2D(p_TexG, p_X - 1, p_Y + 1)) + (Gaus[1] * _tex2D(p_TexG, p_X, p_Y + 1)) + (Gaus[2] * _tex2D(p_TexG, p_X + 1, p_Y + 1)) + (Gaus[3] * _tex2D(p_TexG, p_X - 1, p_Y)) + (Gaus[4] * _tex2D(p_TexG, p_X, p_Y))
+ (Gaus[5] * _tex2D(p_TexG, p_X + 1, p_Y)) + (Gaus[6] * _tex2D(p_TexG, p_X - 1, p_Y - 1)) + (Gaus[7] * _tex2D(p_TexG, p_X, p_Y - 1)) + (Gaus[8] * _tex2D(p_TexG, p_X - 1, p_Y - 1));
result.z = (Gaus[0] * _tex2D(p_TexB, p_X - 1, p_Y + 1)) + (Gaus[1] * _tex2D(p_TexB, p_X, p_Y + 1)) + (Gaus[2] * _tex2D(p_TexB, p_X + 1, p_Y + 1)) + (Gaus[3] * _tex2D(p_TexB, p_X - 1, p_Y)) + (Gaus[4] * _tex2D(p_TexB, p_X, p_Y))
+ (Gaus[5] * _tex2D(p_TexB, p_X + 1, p_Y)) + (Gaus[6] * _tex2D(p_TexB, p_X - 1, p_Y - 1)) + (Gaus[7] * _tex2D(p_TexB, p_X, p_Y - 1)) + (Gaus[8] * _tex2D(p_TexB, p_X - 1, p_Y - 1));
return result;
}