for(float e,i,a,w,x,g,h;i++<90.;o+=.01-.02/exp(max(s,e)*3e3)/h){vec3 p=vec3((FC.xy-.5*r)/r.y*g+2.,g);p.zy*=rotate2D(.5);e=p.y;h=e+p.x*.3;p.z+=t;for(a=.6;a>.001;a*=.7)p.xz*=rotate2D(5.),x=(p.x+p.z)/a+t+t,e-=w=exp(sin(x)-3.)*a,h+=abs(dot(sin(p.xz/a*.3)*a,r/r));g+=e=min(e,h*.5-1.);}
In case anyone was wondering, I asked ChatGPT to figure out why it looks so cool. === Certainly, let's dissect specific parts of the code and correlate them with natural phenomena: 1. **Coordinate Transformation and Perspective**: - `vec3 p=vec3((FC.xy-.5*r)/r.y*g+2.,g);` - This part is setting up the initial position `p` in a 3D space. The transformation `(FC.xy-.5*r)/r.y*g+2.` adjusts the fragment coordinates (`FC.xy`) based on the aspect ratio (`r`), zoom level (`g`), and centers the view. This doesn't directly create natural features but establishes the "camera" perspective from which the natural landscape (mountains and ocean) will be viewed. 2. **Rotation for Variation**: - `p.zy*=rotate2D(.5);` - Applying a 2D rotation to the `z` and `y` components of `p` introduces variation in the terrain's elevation and orientation, contributing to a more natural, less uniform appearance. This mimics how in nature, landforms are not perfectly aligned or uniform but have varied orientations and angles. 3. **Iterative Detailing with Fractal-like Patterns**: - `for(a=.6;a>.001;a*=.7)p.xz*=rotate2D(5.), x=(p.x+p.z)/a+t+t, e-=w=exp(sin(x)-3.)*a` - The loop reduces `a` progressively, adding details at smaller scales, which is a fractal-like approach. Each iteration applies a rotation (`rotate2D(5.)`) to `x` and `z` components, introducing more variation and complexity akin to natural ruggedness in terrain. The expression `exp(sin(x)-3.)*a` modifies the elevation `e`, creating wave-like or undulating patterns similar to mountainous regions or ocean waves. 4. **Noise-like Variation and Complexity**: - `h+=abs(dot(sin(p.xz/a*.3)*a, r/r));` - This line introduces additional complexity to the height `h` by using a sine function on scaled and rotated coordinates, which can create patterns reminiscent of natural noise (similar to Perlin noise but more simplistic). The `dot` product with `r/r` (a normalized vector) and the use of `abs` function ensure that the modifications contribute positively to the height, adding peaks and troughs that resemble natural landforms. 5. **Dynamic Elevation Adjustment**: - `g+=e=min(e,h*.5-1.);` - This part dynamically adjusts the elevation `e` by comparing it with a modified version of `h` (`h*.5-1.`) and choosing the minimum. This adjustment can create sharp transitions and cliffs, akin to how erosion and tectonic movements create sharp features in mountains. 6. **Final Accumulation for Rendering**: - `o+=.01-.02/exp(max(s,e)*3e3)/h;` - This line likely contributes to the final color or intensity of the pixel (`o`), which could be related to the height or depth of the terrain at that point. The use of `exp` and division by `h` suggests that higher regions might be rendered differently from lower ones, simulating how lighting and atmosphere affect the appearance of natural landscapes from a distance. Each piece of this code snippet contributes to creating a visual that mimics natural terrains, through iterative detailing, noise-like variations, dynamic elevation adjustments, and perspective transformations, all of which are essential techniques in procedural terrain generation. ===
@zozuar Here is the same code, with improved readability
@zozuar I typed something similar once, when I fell asleep on my keyboard
@zozuar Can you explain how this “works,” ie how the various parts of this work together to create the output?
@zozuar huh! ...would already be incredible without the water ;-)
@zozuar That’s one of the best ones I’ve seen so far, hauntingly amazing
@zozuar 🤯 when you see stuff like this, one tends to think that all of reality is just a manifestation of a mathematical formula
is this anything close to the supplied function: for(float elevation, iteration, scale, waveHeight, positionModifier, globalOffset, horizontalDisplacement; iteration++ < 90.; offsetIncrement += .01 - .02 / exp(max(scale, elevation) * 3000.) / horizontalDisplacement) { vec3 point = vec3((frameCoordinates.xy - .5 * resolution) / resolution.y * globalOffset + 2., globalOffset); point.zy *= rotate2D(.5); elevation = point.y; horizontalDisplacement = elevation + point.x * .3; point.z += time; // Assuming 't' is a time variable for(scale = .6; scale > .001; scale *= .7) { point.xz *= rotate2D(5.); positionModifier = (point.x + point.z) / scale + time + time; elevation -= waveHeight = exp(sin(positionModifier) - 3.) * scale; horizontalDisplacement += abs(dot(sin(point.xz / scale * .3) * scale, resolution / resolution)); } globalOffset += elevation = min(elevation, horizontalDisplacement * .5 - 1.); }
@zozuar Where do you input the above to get the output below?
@zozuar ShaderToy has a ton of other fun real time renders: shadertoy.com/view/ldXXDj
@zozuar Haha, so fun to just play with some constants in that code. I got more snow on the rocks with one tiny change. Thanks for sharing!
@zozuar To fit all of those minified shader code into precisely 280 characters, and get a what seems to be depth based noise landscape and water... It's wild
@zozuar We can use GLSL directly in an X post!? Damn... that's cool.
@zozuar Hey. Mind Slartibartfast's patent here. You could at least have quoted him.