Last active
April 22, 2020 23:51
-
-
Save s4y/a79d25a513a2cbfed1d858271e288a6a to your computer and use it in GitHub Desktop.
Viz default state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:fn sin 1 | |
:fn cos 1 | |
:fn vec2.1 1 | |
:fn vec2 2 | |
:fn vec3 3 | |
:fn vec3.1 1 | |
:fn vec3.2 2 | |
:fn vec4.1 1 | |
:fn vec4.2 2 | |
:fn vec4.3 3 | |
:fn vec4 4 | |
:fn atan 2 | |
:fn pow 2 | |
:fn sqrt 1 | |
:fn distance 2 | |
:fn clamp 3 | |
:fn mod 2 | |
:fn abs 1 | |
:fn min 2 | |
:fn max 2 | |
:fn mix 3 | |
:fn step 2 | |
:fn mat4 16 | |
:fn length 1 | |
:fn texture2D 2 | |
:fn rgb2hsv 1 | |
:fn hsv2rgb 1 | |
:fn normalize 1 | |
1 0 0 0 | |
0 1 0 0 | |
0 0 1 0 | |
0 0 0 1 | |
mat4 =kIdentity | |
:def rotX | |
{ =angle | |
1 0 0 0 | |
0 angle cos angle sin -1 * 0 | |
0 angle sin angle cos 0 | |
0 0 0 1 | |
} mat4 | |
:def rotY | |
{ =angle | |
angle cos 0 angle sin 0 | |
0 1 0 0 | |
angle sin -1 * 0 angle cos 0 | |
0 0 0 1 | |
} mat4 | |
:def rotZ | |
{ =angle | |
angle cos angle sin -1 * 0 0 | |
angle sin angle cos 0 0 | |
0 0 1 0 | |
0 0 0 1 | |
} mat4 | |
:def transform swap 1 vec4.2 swap * dup .xyz swap .w / | |
:def unbal 2. / .5 + | |
:def bal 2. * 1 - | |
:def cmod { =by by 2 / + by mod by 2 / - } | |
:def uv p .xy unbal | |
:def angle p .x p .y atan | |
:def cdist 0 vec2.1 p .xy distance | |
:def polar cdist 2 PI angle / / vec2 | |
:def fitp p aspect 1 1 vec3 * =p | |
:def dup { =x x x } | |
:def swap { =x =y x y } | |
:def inv 1 swap - | |
:def tex texture2D | |
:def blend { =b =a a b a .a inv * + } | |
:def addHsv { =delta =c c .rgb rgb2hsv delta + hsv2rgb c .a vec4.2 } | |
:def x p .x | |
:def y p .y | |
:def z p .z | |
:def smin { =k =b =a | |
0.5 0.5 b a - * k / + 0 1 clamp =h | |
b a h mix k h 1 h - * * - | |
} | |
:def sdSphere { =size =p | |
p length size - | |
} | |
:def sdBox { =b =p | |
p abs b - =q | |
q 0 max length | |
q .x q .y q .z max max 0 min | |
- | |
} | |
:def estimateNormal { | |
=p | |
1 512 / =epsilon | |
p .x epsilon + p .y p .z vec3 sd | |
p .x epsilon - p .y p .z vec3 sd - | |
p .x p .y epsilon + p .z vec3 sd | |
p .x p .y epsilon - p .z vec3 sd - | |
p .x p .y p .z epsilon + vec3 sd | |
p .x p .y p .z epsilon - vec3 sd - | |
vec3 normalize | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0 0 1 1 vec4 | |
p .x | |
10 * | |
t + | |
p .y unbal sf + | |
sin unbal * | |
draw | |
bail | |
0.4 =kMeta | |
:def sd { | |
0 0 1 vec3 + =p | |
p -1.1 0 0 vec3 + 0.5 sdSphere | |
p 0.5 sdSphere | |
p 1.1 0 0 vec3 + 0.5 sdSphere | |
kMeta smin | |
kMeta smin | |
# p t rotX t rotY * transform 0.4 vec3.1 sdBox | |
} | |
fitp | |
# 0 0 -2 vec3 =camOrigin | |
# p camOrigin + .xy camOrigin .z 1 + vec3.2 =rayOrigin | |
# rayOrigin camOrigin - =direction | |
0 0 -1 vec3 =direction | |
:freeze vec3 p | |
:def marchOnce | |
direction * p + | |
sd | |
0 | |
:loop 80 | |
dup marchOnce + | |
=dist | |
dist direction * p + estimateNormal 1 vec4.2 | |
draw | |
bail | |
rayOrigin 1 vec4.2 draw | |
bail | |
# Comment the below line to take microphone input. | |
:def sf =_ t .1 * sin unbal | |
{ | |
fitp | |
:def sq dup .x swap .y max | |
:def sparks { =in | |
p .xy abs sq .2 - | |
angle in + 4 * sin unbal 50 20 + * 1 + * | |
abs 0.2 sf 0.9 * 0.1 + step | |
} | |
t t sin .1 sf * + sparks | |
t t 1.3 * sin 0.05 * + t sin .2 sf * + sparks | |
t t 1.6 * sin 0.05 * + t sin .2 sf * + sparks | |
1 | |
vec4 | |
} | |
fb'f p 0.99 * .xy unbal tex 0.9 * + | |
drawto'f | |
fb'f p .xy unbal tex draw | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p .y p .y st + 0.2 sf + 0.1 t * + 1 mod 1 1 vec3 rgb2hsv 1 vec4.2 | |
{ fitp cdist 2 / p .y abs max 0.2 sf 0.1 - 0 1 clamp 10 pow + 1 mod sf * } | |
fb'f p 1.01 * .xy unbal tex 0.9 * + | |
drawto'f | |
fb'f uv tex | |
inv | |
p .x abs p .y abs max 10 pow inv * | |
draw | |
0.4 =kMeta | |
:def sd { | |
0 0 2 vec3 + | |
1 1 1 vec3 / | |
t rotX t sin 0.5 * rotY * transform =p p | |
p .x unbal 2 / sf =sval | |
0.4 sval 0.4 * 0.2 + 0.4 vec3 sdBox | |
# 0.5 0.5 0.5 * 0.2 + 0.8 vec3 sdBox | |
# p t rotX t rotY * transform 0.4 vec3.1 sdBox | |
sval 0 0 vec4 | |
} | |
fitp | |
# 0 0 -2 vec3 =camOrigin | |
# p camOrigin + .xy camOrigin .z 1 + vec3.2 =rayOrigin | |
# rayOrigin camOrigin - =direction | |
0 0 -1 vec3 =direction | |
p | |
:def marchOnce { =components | |
components .x direction * p + | |
sd | |
} | |
0 vec4.1 | |
:loop 80 vec4 | |
dup marchOnce + | |
=ret | |
ret .x 1.01 - 1 / =dist | |
ret .x direction * p + sd .x =surfDist | |
ret .y 50 / 0.5 1 vec3 hsv2rgb 1 vec4.2 | |
surfDist abs 0.05 step inv * | |
dist inv * | |
draw |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment