Skip to content

Commit 9fc74c9

Browse files
committed
add: shader-study-201910.frag
update: Refactor some codes, Exapmles.md, .gitignore(for local dev)
1 parent e8ae8f8 commit 9fc74c9

File tree

4 files changed

+70
-3
lines changed

4 files changed

+70
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ application.windows32
66
application.windows64
77
application.macosx
88
.vscode
9+
.data-workplace
910
img

SoundVisualShaderBase.pde

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ void draw() {
5454
recorder.finish();
5555
recorder = null;
5656
}
57+
if (0 < frameDropCount) {
58+
println("Frame drop count: ", frameDropCount, " / ", frameCount, "(", (frameDropCount * 100.0 / frameCount) ,"%)");
59+
}
5760
exit();
5861
return;
5962
}
@@ -66,9 +69,9 @@ void draw() {
6669
provider.update();
6770
final float progress = provider.getProgressPercentage();
6871

69-
if (0 <= startFrameCount && 0.0 < progress) {
70-
println("Leading frame count: " + (frameCount - startFrameCount));
71-
startFrameCount = -1;
72+
if (startFrameCount == 0 && 0.0 < progress) {
73+
println("Leading frame count: ", frameCount);
74+
startFrameCount = frameCount;
7275
}
7376

7477
if (onlyInitialization == false) {

data/shader-study-201910.frag

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* shader: ray marching study 201910
3+
* references:
4+
* - [GLSL SandBoxで手軽にレイマーチングで遊ぼう](https://hackerslab.aktsk.jp/2018/12/01/131928)
5+
* - [魔法使いになりたい人のためのシェーダーライブコーディング入門](https://qiita.com/kaneta1992/items/21149c78159bd27e0860)
6+
* - [Phantom Mode](https://www.shadertoy.com/view/MtScWW)
7+
* - [Live Coding Using Phantom Mode](https://www.shadertoy.com/view/wl2GWG)
8+
* - [distance functions](https://iquilezles.org/www/articles/distfunctions/distfunctions.htm)
9+
*/
10+
11+
uniform ivec2 resolution;
12+
uniform float time;
13+
uniform float progress;
14+
uniform vec3 soundLevel;
15+
16+
uniform float kick;
17+
18+
const float PI = acos(-1);
19+
const float TWO_PI = PI * 2;
20+
21+
vec3 hsb2rgb(float h, float s, float v) {
22+
// [[汎用関数]HSV2RGB 関数](https://qiita.com/keim_at_si/items/c2d1afd6443f3040e900)
23+
return ((clamp(abs(fract(h + vec3(0, 2, 1) / 3.) * 6. - 3.) - 1., 0., 1.) - 1.) * s + 1.) * v;
24+
}
25+
26+
float sdTriPrism( vec3 p, vec2 h ) {
27+
vec3 q = abs(p);
28+
return max(q.z-h.y,max(q.x*0.866025+p.y*0.5,-p.y)-h.x*0.5);
29+
}
30+
31+
vec3 repeat(vec3 p, float interval) {
32+
return mod(p, interval) - 2.0;
33+
}
34+
35+
float dist(vec3 p) {
36+
vec3 pos = repeat(p - 2.0, 4.0);
37+
return sdTriPrism(pos, vec2(0.5, 2.0 * progress));
38+
}
39+
40+
void main() {
41+
vec2 uv = (gl_FragCoord.xy * 2.0 - resolution.xy) / min(resolution.x, resolution.y);
42+
43+
vec3 cameraUp = normalize(vec3(sin(progress * 5 * TWO_PI), cos(progress * 5 * TWO_PI), 0.0));
44+
vec3 cameraDir = vec3(0.0, 0.0, 1.0 * progress);
45+
vec3 cameraSite = normalize(cross(cameraUp, cameraDir));
46+
vec3 rayDir = normalize((uv.x * cameraSite + uv.y * cameraUp) + cameraDir);
47+
48+
float t = 0.01;
49+
float ac = 0.0;
50+
for (int i = 0; i < 48; ++i) {
51+
float d = dist(rayDir * t);
52+
d = max(abs(d), 0.02);
53+
ac += exp(-d * 3.0);
54+
t += d * 0.5;
55+
}
56+
57+
gl_FragColor = vec4(hsb2rgb(soundLevel.z * ac * 0.2, ac * 0.01 * kick, ac * 0.02), 1.0);
58+
}

doc/Examples.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Examples
22
======
33

4+
[shader-study-201910.frag](../data/shader-study-201910.frag)
5+
------
6+
7+
[![With impatient heart by Sad Juno](https://i.ytimg.com/vi/ILZz3aaolQ0/sddefault.jpg "With impatient heart by Sad Juno")](https://www.youtube.com/ILZz3aaolQ0)
8+
49
[shader-study-201909.frag](../data/shader-study-201909.frag)
510
------
611

0 commit comments

Comments
 (0)