Created
October 7, 2021 08:18
-
-
Save yonatan/f1793265416354f1229a41352d4bb115 to your computer and use it in GitHub Desktop.
A commented version of https://twitter.com/zozuar/status/1443012484189888515 by https://twitter.com/User2E32
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
// 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 | |
for(;s<200;s*=1.0/0.6){ | |
// the position also serves as a source for the seed: higher octaves just use a more-quickly changing noise function | |
p.xz *= rotate2D(s); | |
// generate two random numbers: fog density, and terrain height | |
e+=abs(dot(sin(p*s)/s,p-p+.4));// fog density, because it contains y | |
f+=abs(dot(sin(p.xz*s*.6)/s, vec2(1.0)));// terrain height | |
} | |
o += (f > k*k ? e : -exp(-f*f))*o*k;// when the terrain is hit, add terrain color, otherwise add fog color | |
g += min(f,max(.03,e))*.3 // go deeper, but at max go to the terrain | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment