Skip to content

Instantly share code, notes, and snippets.

// r = probably screen resolution, o = output color, g = ray depth into the scene
// FC.xy = which pixel we are on
float i,e,f,s,g,k=.01;
for(o++;i++<100;){// go upto 100 steps with the ray
s=2.;
vec3 p = vec3((FC.xy-r/s)/r.y*g, g-s); // defining ray direction
p.yz *= rotate2D(-.8); // rotate the camera/ray downwards
p.z += t;// fly forward over time
e=f=p.y
// compute the terrain height and fog density at this xz coordinate
// Commented version of https://twitter.com/zozuar/status/1441384708441456651
// Google-translated (with some editing) from @gam0022's version
float i, // Ray marching loop counter
e, // Volume density (the smaller the value, the higher the density)
s, // FBM scale (and loop counter)
g, // Ray's distance (also used for tunnel twirl and camera prespective)
k = .01; // Handy constant
// Ray marching loop
// This is Twigl's "geekest mode" so the code runs inside a "main" function.
// FC.xy is fragcoord
// r.xy is resolution
// t is time (in seconds I think)
// o.rgba is output color
// This is the original code, before any readability improvements:
/*
#define X(S,D)I=ivec3(S);D=fract(float(I.x^I.y^I.z)*PI
@yonatan
yonatan / twigl-capjs-shim.glsl
Last active February 13, 2022 07:32
Twigl geekest mode (es 300) shim for CapJS video captures
/*
*
* Twigl geekest mode 300 es shim for CapJS (no mouse, sound or backbuffer support!)
*
* To render long videos for twitter:
*
* - Paste this into http://capjs.3d2k.com/
* - Scroll to the bottom and paste your twigl code
* - Set resolution, time, format (webm), etc.
* - Capture
@yonatan
yonatan / swf-surgery
Last active March 16, 2017 21:25
Patch wonderfl swfs to change asset urls to relative paths
#!/bin/bash -e
if [[ $# -ne 2 ]]; then
echo "Usage: swf-surgery <input-file> <output-file>"
exit 1
fi
TMP="/tmp/$(basename $0).$$"
SWF="$TMP.swf"
BAK="$TMP.\$wf"
var null::no name()::void
maxStack:2 localCount:5 initScopeDepth:10 maxScopeDepth:10
pushundefined ; 1 item on stack
coerce_a
setlocal1 ; 0 items on stack
pushundefined ; 1 item on stack
coerce_a
setlocal2 ; 0 items on stack
pushundefined ; 1 item on stack
coerce_a