Skip to content

Instantly share code, notes, and snippets.

@sebastien
Created February 2, 2019 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastien/166810fa95251ec3c5108ddfbc66b504 to your computer and use it in GitHub Desktop.
Save sebastien/166810fa95251ec3c5108ddfbc66b504 to your computer and use it in GitHub Desktop.
let
EPSILON = 0.001;
between (v,a,b) = 1 - smoothstep(a-EPSILON,a+EPSILON,v) + smoothstep(b-EPSILON,b+EPSILON,v);
prel (v,a,b) = (v - a)/(b - a);
scale (v,a,b) = lerp(b[0],b[1],prel(v,a[0],a[1]));
hash x = frac(sin(x)*100000.0);
wave (x,y,z,t) = let
row = floor(x/2);
k = hash(row);
phase = lerp(0,20,k);
amplitude = lerp(2,6,k);
frequency = lerp(10,20,k)
in scale(
cos(scale(phase + y,[0,frequency],[0,2*pi]))+1,
[-1,1], [0, amplitude]
)
in
intersection (
box {zmin:0, zmax:5, xmin:-10, xmax:10, ymin:-10, ymax:10},
make_shape {
dist (x,y,z,t) : let
h = wave (x,y,z,t);
in max(0,z - h) + between(mod(x,2),0,1.5),
is_2d : false,
is_3d : true
}
)
// EOF - vim: ts=2 sw=2 et syn=javascript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment