-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlive.pxr
284 lines (237 loc) · 6.7 KB
/
live.pxr
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
@ /live root:video {
#%autostart true
#%praxis.version 4.0.0-rc1
.renderer OpenGL
.width 1280
.height 800
.fps 24
@ ./screen video:output {
#%graph.x 671
#%graph.y 186
.title Live
.full-screen true
.always-on-top true
.undecorated true
.show-cursor true
}
@ ./ch1 video:gl:receive {
#%graph.x 177
#%graph.y 24
.server-id preview1
}
@ ./ch2 video:gl:receive {
#%graph.x 177
#%graph.y 147
.server-id preview2
}
@ ./start-trigger-1 core:start-trigger {
#%graph.x -43
#%graph.y 97
}
@ ./mixer1 video:gl:p2d {
#%graph.x 350
#%graph.y 71
.code "
@P(1) double level;
@P(2) double aux1;
@P(3) double aux2;
@P(11)
String color1;
@P(12)
String color2;
@P(13)
String color3;
@P(14)
String color4;
@P(15)
String color5;
void updateUniforms() \{
shader.set(\"background\", ch2);
shader.set(\"level\", level);
shader.set(\"aux1\", aux1);
shader.set(\"aux2\", aux2);
setColor(\"color1\", color1);
setColor(\"color2\", color2);
setColor(\"color3\", color3);
setColor(\"color4\", color4);
setColor(\"color5\", color5);
\}
void setColor(String key, String hex) \{
if(hex.isEmpty()) \{
hex = \"00FF00\";
\}
hex = hex.replace(\"#\", \"\");
int red = Integer.valueOf(hex.substring(0, 2), 16);
int green = Integer.valueOf(hex.substring(2, 4), 16);
int blue = Integer.valueOf(hex.substring(4, 6), 16);
int alpha = 255;
if(hex.length() == 8) \{
alpha = Integer.valueOf(hex.substring(6, 8), 16);
\}
shader.set(key, red / 255.0, green / 255.0, blue / 255.0, alpha / 255.0);
\}
// BOILERPLATE BELOW
@In(0)
PImage in;
@In(1)
PImage ch2;
@P(0)
//@Type.String(mime = GLSL_FRAGMENT_MIME, template = DEFAULT_FRAGMENT_SHADER)
@Type.String()
@OnChange(\"updateShader\")
//@Config.Port(false)
String fragment;
PShader shader;
@Override
public void setup() \{
updateShader();
\}
@Override
public void draw() \{
if (shader == null) \{
System.out.println(\"Shader created preview2\");
shader = createShader(DEFAULT_VERTEX_SHADER,
fragment.isEmpty() ? DEFAULT_FRAGMENT_SHADER : fragment);
\}
shader(shader);
updateUniforms();
image(in, 0, 0);
resetShader();
\}
void updateShader() \{
shader = null;
\}
"
.fragment "// Blend texture with background with given level
uniform sampler2D texture;
uniform sampler2D background;
uniform vec2 texOffset;
varying vec4 vertColor;
varying vec4 vertTexCoord;
uniform float level;
void main() \{
vec4 texture_colour = texture2D(texture, vertTexCoord.st);
vec4 background_colour = texture2D(background, vertTexCoord.st);
gl_FragColor = mix(texture_colour, background_colour, level);
\}
"
}
@ ./an1-fade core:timing:animator {
#%graph.x 224
#%graph.y 525
.time 1.58
}
@ ./shader-bank1 core:custom {
#%graph.x 113
#%graph.y 268
.code "import static org.praxislive.video.pgl.code.userapi.Constants.*;
import java.net.URI;
import java.io.File;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.net.URISyntaxException;
@T(0)
void trigger() \{
fileSelected();
\}
@P(0) @Type(value = PResource.class, properties = \{PResource.KEY_ALLOW_EMPTY, \"true\"\})
@OnChange(\"fileSelected\")
Property file;
@P(1)
@Type.String()
@ReadOnly()
String fragment;
@Out(0)
Output out;
@Override
public void init() \{
fragment = DEFAULT_FRAGMENT_SHADER;
\}
void fileSelected() \{
String path = file.get().toString();
try \{
fragment = loadStringFromFile(path);
out.send(fragment);
\} catch(FileNotFoundException e) \{
System.out.println(\"File not found: \" + e.getLocalizedMessage());
\} catch(IOException e) \{
System.out.println(\"Can't read a file: \" + e.getLocalizedMessage());
\} catch(URISyntaxException e) \{
System.out.println(\"Can't parse uri: \" + e.getLocalizedMessage());
\};
\}
String loadStringFromFile(String path)
throws FileNotFoundException, IOException, URISyntaxException \{
URI uri = new URI(path);
File file = new File(uri.getPath());
BufferedReader reader = new BufferedReader(new FileReader(file));
StringBuilder data = new StringBuilder();
char\[\] buf = new char\[1024\];
int read = 0;
while ((read = reader.read(buf)) != -1) \{
data.append(buf, 0, read);
\}
reader.close();
return data.toString();
\}
"
.file [file "resources/shaders/mixer/blend.frag"]
}
@ ./composite-1 video:composite {
#%graph.x 506
#%graph.y 97
.force-alpha true
}
@ ./shader-switch1 core:custom {
#%graph.x 69
#%graph.y 411
.code "
@P(0)
@OnChange(\"channelUpdated\")
int channel;
@P(1)
@OnChange(\"listUpdated\")
String files;
@P(2)
@ReadOnly
String active;
String fileList\[\];
@Out(0)
Output out;
@Override
public void init() \{
fileList = files.split(\"\\\\r?\\\\n\");
\}
void channelUpdated() \{
System.out.println(\"Item selected: \" + channel);
System.out.println(\"Total items \" + fileList.length);
if(fileList.length == 0 && channel < 0) \{
return;
\}
if((channel + 1) > fileList.length) \{
return;
\}
active = fileList\[channel\];
out.send(active);
\}
void listUpdated() \{
fileList = files.split(\"\\\\r?\\\\n\");
\}
"
.files "file:/Users/y13/Documents/Apps/Praxis/TraceGL/resources/shaders/mixer/blend.frag
file:/Users/y13/Documents/Apps/Praxis/TraceGL/resources/shaders/mixer/vsplit.frag
file:/Users/y13/Documents/Apps/Praxis/TraceGL/resources/shaders/mixer/hsplit.frag
file:/Users/y13/Documents/Apps/Praxis/TraceGL/resources/shaders/mixer/circle.frag"
}
~ ./start-trigger-1!out ./ch1!start
~ ./ch2!out ./mixer1!ch-2
~ ./ch1!out ./mixer1!in
~ ./start-trigger-1!out ./ch2!start
~ ./an1-fade!out ./mixer1!level
~ ./shader-bank1!out ./mixer1!fragment
~ ./mixer1!out ./composite-1!src
~ ./composite-1!out ./screen!in
~ ./shader-switch1!out ./shader-bank1!file
}