Skip to content

Commit e8ae8f8

Browse files
committed
add: shader-study-201909.frag
update: add image output directory setting processing close #1
1 parent 5f7cde4 commit e8ae8f8

File tree

6 files changed

+112
-31
lines changed

6 files changed

+112
-31
lines changed

FrameRecorder.pde

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ interface FrameRecorder {
99

1010
final class SyncFrameRecorder implements FrameRecorder {
1111
private final String frameFormat;
12-
SyncFrameRecorder(String ext) {
13-
frameFormat = "img/########." + ext;
12+
SyncFrameRecorder(String path, String ext) {
13+
frameFormat = path + "/########." + ext;
1414
}
1515

1616
void recordFrame() {
@@ -24,8 +24,10 @@ final class SyncFrameRecorder implements FrameRecorder {
2424
final class AsyncFrameRecorder implements FrameRecorder {
2525
private final ExecutorService executor = Executors.newCachedThreadPool();
2626
private final List<Future> futures = new ArrayList<Future>();
27+
private final String recordPath;
2728

28-
AsyncFrameRecorder() {
29+
AsyncFrameRecorder(String path) {
30+
recordPath = path;
2931
}
3032

3133
void recordFrame() {
@@ -41,7 +43,7 @@ final class AsyncFrameRecorder implements FrameRecorder {
4143
public void run() {
4244
final PImage frameImage = createImage(width, height, HSB);
4345
frameImage.pixels = savePixels;
44-
frameImage.save(String.format("img/%08d.jpg", saveFrameCount));
46+
frameImage.save(String.format("%s/%08d.jpg", recordPath, saveFrameCount));
4547
}
4648
};
4749

@@ -114,18 +116,18 @@ enum FrameRecorderType {
114116
AsyncRecorder
115117
}
116118

117-
FrameRecorder createFrameRecorderInstanceOf(FrameRecorderType type) {
119+
FrameRecorder createFrameRecorderInstanceOf(FrameRecorderType type, String path) {
118120
switch (type) {
119121
/*
120122
case VideoExportRecorder:
121123
return new VideoExportRecorder(this);
122124
*/
123125
case SyncTgaRecorder:
124-
return new SyncFrameRecorder("tga");
126+
return new SyncFrameRecorder(path, "tga");
125127
case SyncPngRecorder:
126-
return new SyncFrameRecorder("png");
128+
return new SyncFrameRecorder(path, "png");
127129
case AsyncRecorder:
128-
return new AsyncFrameRecorder();
130+
return new AsyncFrameRecorder(path);
129131
default:
130132
throw new RuntimeException();
131133
}

Implementation.pde

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,36 @@ final class ShaderInfo {
5858
}
5959

6060
FrameRecorder createFrameRecorder(JSONObject setting) {
61+
final JSONObject record = setting.getJSONObject("record");
62+
if (record == null) {
63+
return null;
64+
}
65+
6166
FrameRecorderType recorderType = null;
62-
String recordImageType = setting.getString("recordImageType");
63-
if (recordImageType != null) {
64-
recordImageType = recordImageType.toLowerCase();
65-
if (recordImageType.equals("jpeg") || recordImageType.equals("jpg")) {
67+
68+
String imageType = record.getString("imageType");
69+
if (imageType != null) {
70+
imageType = imageType.toLowerCase();
71+
if (imageType.equals("jpeg") || imageType.equals("jpg")) {
6672
recorderType = FrameRecorderType.AsyncRecorder;
6773
}
68-
else if (recordImageType.equals("tga")) {
74+
else if (imageType.equals("tga")) {
6975
recorderType = FrameRecorderType.SyncTgaRecorder;
7076
}
71-
else if (recordImageType.equals("png")) {
77+
else if (imageType.equals("png")) {
7278
recorderType = FrameRecorderType.SyncPngRecorder;
7379
}
7480
}
81+
if (recorderType == null) {
82+
return null;
83+
}
84+
85+
String recordPath = record.getString("path");
86+
if (recordPath == null || recordPath.length() == 0) {
87+
recordPath = "img";
88+
}
7589

76-
return recorderType != null ? createFrameRecorderInstanceOf(recorderType) : null;
90+
return createFrameRecorderInstanceOf(recorderType, recordPath);
7791
}
7892

7993
List<SoundInfo> loadSounds(JSONArray soundDefinitions) {

data/setting-schema.json

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,29 @@
3535
"description": "Output definition.",
3636
"type": "object",
3737
"properties": {
38-
"recordImageType": {
39-
"description": "Image type of recording frame.",
40-
"type": [
41-
"string",
42-
"null"
43-
],
44-
"enum": [
45-
"jpeg",
46-
"jpg",
47-
"png",
48-
"tga",
49-
""
50-
]
38+
"record": {
39+
"description": "Record information.",
40+
"type": "object",
41+
"properties": {
42+
"imageType": {
43+
"description": "Image type of recording frame.",
44+
"type": [
45+
"string",
46+
"null"
47+
],
48+
"enum": [
49+
"jpeg",
50+
"jpg",
51+
"png",
52+
"tga",
53+
""
54+
]
55+
},
56+
"path": {
57+
"description": "Path to save recording images.",
58+
"type": "string"
59+
}
60+
}
5161
},
5262
"connection": {
5363
"description": "External connection name(for spout).",

data/setting.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{
22
"framePerSecond": 18,
33
"out": {
4-
"recordImageType": "",
4+
"record": {
5+
"imageType": "",
6+
"path": "img"
7+
},
58
"connection": {
69
"name": ""
710
}

data/shader-study-201909.frag

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* shader: cellular noise study
3+
* based on: [Cellular Noise](https://thebookofshaders.com/12/?lan=jp) by @patriciogv
4+
*/
5+
6+
uniform vec2 resolution;
7+
uniform float time;
8+
uniform float progress;
9+
10+
uint xorshift(uint seed) {
11+
uint y = seed;
12+
y = y ^ (y << 13);
13+
y = y ^ (y >> 17);
14+
return y ^ (y << 15);
15+
}
16+
17+
vec2 focusPoint(vec2 p) {
18+
return vec2(sin(xorshift(uint(dot(p, resolution)))));
19+
}
20+
21+
void main() {
22+
vec2 st = gl_FragCoord.xy / resolution.xy;
23+
st.x *= resolution.x / resolution.y;
24+
25+
st *= 3.0 * progress;
26+
vec2 intSt = floor(st);
27+
vec2 fractSt = fract(st);
28+
29+
float dist = 1.0;
30+
for (int y = -1; y <= 1; ++y) {
31+
for (int x = -1; x <= 1; ++x) {
32+
vec2 neighbor = vec2(float(x), float(y));
33+
/*
34+
vec2 fp = focusPoint(intSt + neighbor);
35+
vec2 point = vec2(0.5);
36+
point.x += 0.5 * cos(time + acos(-1) * fp.x);
37+
point.y += 0.5 * sin(time + acos(-1) * fp.y);
38+
*/
39+
vec2 point = 0.5 + 0.5 * cos(time + acos(-1) * focusPoint(intSt + neighbor));
40+
vec2 diff = neighbor + point - fractSt;
41+
dist = min(dist, length(diff));
42+
}
43+
}
44+
gl_FragColor = vec4(vec3(dist * dist), 1.0);
45+
}

doc/Examples.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
Examples
22
======
33

4+
[shader-study-201909.frag](../data/shader-study-201909.frag)
5+
------
6+
7+
[![星屑降る地より(feat. GUMI, VOCALOID Megpoid V4) by Sad Juno](https://i.ytimg.com/vi/JOH3b3gxxdA/sddefault.jpg "星屑降る地より(feat. GUMI, VOCALOID Megpoid V4) by Sad Juno")](https://www.youtube.com/JOH3b3gxxdA)
8+
9+
(with other source)
10+
411
[shader-study-20190804.frag](../data/shader-study-20190804.frag)
512
------
613

7-
<iframe width="560" height="315" src="https://www.youtube.com/qMwQ23na1Ek" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
14+
[![Small bird in the rain(Processing + GLSL sound visualization study)](https://i.ytimg.com/vi/qMwQ23na1Ek/sddefault.jpg "Small bird in the rain(Processing + GLSL sound visualization study)")](https://www.youtube.com/qMwQ23na1Ek)
815

916
[shader-ray-marching-study-01.frag](../data/shader-ray-marching-study-01.frag)
1017
------
1118

12-
<iframe width="560" height="315" src="https://www.youtube.com/8bA4d6-tRKE" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
19+
[![Running on the fence(Processing + GLSL sound visualization study)](https://i.ytimg.com/vi/8bA4d6-tRKE/sddefault.jpg "Running on the fence(Processing + GLSL sound visualization study)")](https://www.youtube.com/8bA4d6-tRKE)

0 commit comments

Comments
 (0)