-
Notifications
You must be signed in to change notification settings - Fork 0
/
b.frag
51 lines (40 loc) · 1.26 KB
/
b.frag
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
#version 330 core
/*
Image buffer
Takes previous image and kernel as input,
returns a new image
*/
uniform vec2 iMouse;
uniform int iMouseLeftDown;
uniform int iMouseRightDown;
uniform vec2 iResolution;
uniform sampler2D kernelTexture;
uniform sampler2D iChannel1;
out vec2 fragColor;
uniform int brush = 5; // size of wall painting
void main()
{
vec2 uv = gl_FragCoord.xy / iResolution.xy;
ivec2 ifragCoord = ivec2(gl_FragCoord);
ivec2 intMouse = ivec2(iMouse.xy);
vec4 kernel = texture(kernelTexture, uv);
vec2 draw = texture(iChannel1, uv).rg; // texture only return float or vec4
if (ifragCoord.x == intMouse.x && ifragCoord.y == iResolution.y - intMouse.y
&& iMouseLeftDown == 1) {
draw = vec2(1.,0.); // white
}
// wall painting, with 'zone effect'
if (ifragCoord.x <= intMouse.x + brush && ifragCoord.x >= intMouse.x - brush
&& ifragCoord.y <= iResolution.y - intMouse.y + brush && ifragCoord.y >= iResolution.y - intMouse.y - brush
&& iMouseRightDown == 1) {
draw = vec2(0.,1.);
}
float sum = 0.;
sum += kernel.r;
sum += kernel.g;
sum += kernel.b;
sum += kernel.a;
sum /= 4.; // try 2.4
fragColor = draw;
fragColor.r -= sum; // adds to red channel
}