-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpseudocode.txt
55 lines (40 loc) · 1.42 KB
/
pseudocode.txt
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
50
51
52
53
54
55
Pseudocode for Sobel Operator (GLSL FragShader)
BEGIN
uniform -> uTexture // Main texture
uniform -> uResolution // Renderbuffer size
uniform -> uThreshold // Black/white threshold value
kernalY -> matrix(3x3) {
-1, 0, 1,
-2, 0, 2,
-1, 0, 1
}
kernalX -> matrix(3x3) {
-1, -2, -1,
0, 0, 0,
1, 2, 1
}
# Main function (per fragment)
MAIN
# Gradient intensity on the x,y direction
gX -> 0.0
gY -> 0.0
# x,y axis kernal pass
FOR each value between -1 to 1 as i THEN
FOR each value between -1 to 1 as j THEN
# Calculate uvs of surrounding fragments
x -> (get_uvs().x / uResolution.x) + float(i) / uResolution.x
y -> (get_uvs().y / uResolution.y) + float(j) / uResolution.y
# Add intensity of the gradient on the x,y axies
gX += texture(uTexture, vec2(x,y)).r * float(kernalX[i+1][j+1])
gY += texture(uTexture, vec2(x,y)).r * float(kernalY[i+1][j+1])
ENDFOR
ENDFOR
# Euclidean Distance
mag = sqrt(pow(gX, 2) + pow(gY, 2))
if (g > uThreshold){
finalColour = vec4(g, g, g, 1.0);
} else {
finalColour = vec4(0.0, 0.0, 0.0, 1.0);
}
ENDMAIN
END