-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshaders.lua
executable file
·122 lines (91 loc) · 3.01 KB
/
shaders.lua
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
function createInkShader()
inksmooth=love.graphics.newShader[[
extern number cvsw;
extern number cvsh;
vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ){
vec4 pixel = Texel(texture, texture_coords );//This is the current pixel color
number pixel_w = 1.0 / cvsw;
number pixel_h = 1.0 / cvsh;
vec4 ink= vec4(0.0,0.0,0.0,1.0); //hard coded
vec4 white= vec4(1.0,1.0,1.0,1.0);
vec2 offset=vec2(2.0*pixel_w,0);
vec2 voffset=vec2(0,2.0*pixel_h);
vec4 left= Texel(texture, texture_coords+offset );
vec4 right= Texel(texture, texture_coords-offset );
vec4 down= Texel(texture, texture_coords+voffset );
vec4 up= Texel(texture, texture_coords-voffset );
vec4 aa= color *(0.8*pixel + 0.1*ink);
//for debug
//vec4 aa=vec4(0.0,0.0,1.0,1.0);
if (left==ink) {
if (pixel!=ink){
return aa;
}else{
return ink;
}
}else if(right==ink) {
if (pixel!=ink){
return aa;
}else{
return ink;
}
}else if(up==ink) {
if (pixel!=ink){
return aa;
}else{
return ink;
}
}else if(down==ink) {
if (pixel!=ink){
return aa;
}else{
return ink;
}
}else{
return pixel * color;
}
}
]]
inksmooth:send("cvsw",conf.cvsw)
inksmooth:send("cvsh",conf.cvsh)
end
--WIP need to pass screen cvs
--QUESTIONABLE since we need to pass picture texture ( so make a copy ) as input,
--to render on a canvas ( the picture itself but transient )
-- we don't gain anything for the coloring scenario
function createPaintUnderShaderOBSOLETE(rs,gs,bs)
paintUnderShader=love.graphics.newShader[[
extern cvs;
extern number r;
extern number g;
extern number b;
vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ){
vec4 pixel = Texel(texture, texture_coords );//This is the current pixel color
vec4 ink= vec4(r,g,b,1.0); //hard coded
vec4 white= vec4(1.0,1.0,1.0,1.0);
vec4 aa= color *(0.8*pixel + 0.1*ink);
//for debug
//vec4 aa=vec4(0.0,0.0,1.0,1.0);
return ink;
}
]]
paintUnderShader:send("r",rs)
paintUnderShader:send("g",gs)
paintUnderShader:send("b",bs)
end
--this is a square eraser ( shader cant return no value , compilation error )
function createEraserShader()
--returns alpha 0 so contribuges nothings .....
-- TO DO workaround : blit eraser on separate tex, as solid color
-- blit result of erase to new canvas with 2 cvs and eraser pane as input
eraserShader=love.graphics.newShader[[
vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ){
vec4 pixel = Texel(texture, texture_coords );//This is the current pixel color
// vec4 ink= vec4(0.0,0.0,0.0,0.5); //hard coded transp
vec4 ink= vec4(0.0,0.0,0.0,0.0); //hard coded transp
return ink ;
//illegal to return something
// return;
}
]]
end