Skip to content

Commit

Permalink
add: shader-study-201910.frag
Browse files Browse the repository at this point in the history
update: Refactor some codes, Exapmles.md, .gitignore(for local dev)
  • Loading branch information
DBC-Works committed Oct 20, 2019
1 parent e8ae8f8 commit 9fc74c9
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ application.windows32
application.windows64
application.macosx
.vscode
.data-workplace
img
9 changes: 6 additions & 3 deletions SoundVisualShaderBase.pde
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ void draw() {
recorder.finish();
recorder = null;
}
if (0 < frameDropCount) {
println("Frame drop count: ", frameDropCount, " / ", frameCount, "(", (frameDropCount * 100.0 / frameCount) ,"%)");
}
exit();
return;
}
Expand All @@ -66,9 +69,9 @@ void draw() {
provider.update();
final float progress = provider.getProgressPercentage();

if (0 <= startFrameCount && 0.0 < progress) {
println("Leading frame count: " + (frameCount - startFrameCount));
startFrameCount = -1;
if (startFrameCount == 0 && 0.0 < progress) {
println("Leading frame count: ", frameCount);
startFrameCount = frameCount;
}

if (onlyInitialization == false) {
Expand Down
58 changes: 58 additions & 0 deletions data/shader-study-201910.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* shader: ray marching study 201910
* references:
* - [GLSL SandBoxで手軽にレイマーチングで遊ぼう](https://hackerslab.aktsk.jp/2018/12/01/131928)
* - [魔法使いになりたい人のためのシェーダーライブコーディング入門](https://qiita.com/kaneta1992/items/21149c78159bd27e0860)
* - [Phantom Mode](https://www.shadertoy.com/view/MtScWW)
* - [Live Coding Using Phantom Mode](https://www.shadertoy.com/view/wl2GWG)
* - [distance functions](https://iquilezles.org/www/articles/distfunctions/distfunctions.htm)
*/

uniform ivec2 resolution;
uniform float time;
uniform float progress;
uniform vec3 soundLevel;

uniform float kick;

const float PI = acos(-1);
const float TWO_PI = PI * 2;

vec3 hsb2rgb(float h, float s, float v) {
// [[汎用関数]HSV2RGB 関数](https://qiita.com/keim_at_si/items/c2d1afd6443f3040e900)
return ((clamp(abs(fract(h + vec3(0, 2, 1) / 3.) * 6. - 3.) - 1., 0., 1.) - 1.) * s + 1.) * v;
}

float sdTriPrism( vec3 p, vec2 h ) {
vec3 q = abs(p);
return max(q.z-h.y,max(q.x*0.866025+p.y*0.5,-p.y)-h.x*0.5);
}

vec3 repeat(vec3 p, float interval) {
return mod(p, interval) - 2.0;
}

float dist(vec3 p) {
vec3 pos = repeat(p - 2.0, 4.0);
return sdTriPrism(pos, vec2(0.5, 2.0 * progress));
}

void main() {
vec2 uv = (gl_FragCoord.xy * 2.0 - resolution.xy) / min(resolution.x, resolution.y);

vec3 cameraUp = normalize(vec3(sin(progress * 5 * TWO_PI), cos(progress * 5 * TWO_PI), 0.0));
vec3 cameraDir = vec3(0.0, 0.0, 1.0 * progress);
vec3 cameraSite = normalize(cross(cameraUp, cameraDir));
vec3 rayDir = normalize((uv.x * cameraSite + uv.y * cameraUp) + cameraDir);

float t = 0.01;
float ac = 0.0;
for (int i = 0; i < 48; ++i) {
float d = dist(rayDir * t);
d = max(abs(d), 0.02);
ac += exp(-d * 3.0);
t += d * 0.5;
}

gl_FragColor = vec4(hsb2rgb(soundLevel.z * ac * 0.2, ac * 0.01 * kick, ac * 0.02), 1.0);
}
5 changes: 5 additions & 0 deletions doc/Examples.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Examples
======

[shader-study-201910.frag](../data/shader-study-201910.frag)
------

[![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)

[shader-study-201909.frag](../data/shader-study-201909.frag)
------

Expand Down

0 comments on commit 9fc74c9

Please sign in to comment.