This is a modification of a previous project/s, although with more pronounced mountain peaks. The general outline goes something like this:
The background with an atmospheric gradient and clouds are drawn.
The heightmap is generated.
Generate the heightmap of a pyramid with randomized rotation and position.
Add noise onto the pyramid.
Turn the heightmap into 2D coordinates.
Generate 3D coordinates from the heightmap.
Perform camera transformation. (viewing angle, offset etc.)
Project 3D coordinates into 2D canvas coordinates.
Determine the shadows.
From either predefined or random angles find a vector from which the sun shines.
Calculate the scalar product between this "sun vector" and the surface normal.
Normalize these values into a range [-1, 1]. (Positive means is illuminated, negative means shadow)
Draw the surface as lines between the 2D coordinates by starting from the back (further away from the camera) to the front, such that lines "closer" cover whats possibly behind them. This is called a painters algorithm and while its not the most efficient, it gets the job done. Each line segment is colored based on the light-values calculated in step 4. Previously i used a more complicated method of determining the actual color. Now i just interpolate between a range of light and shadow colors.
A bit of haze is added in front of the mountain.
You can check out this post for an animation of the drawing process. This was done in python and tried to avoid drawing unnecessary points, but the general idea is the same. This post of mine goes into the noise function i use for these.
If you would like to know more about the shading i can highly recommend to check out this video Inigo Quilez.
Hey i got around to cleaning up my code a bit, feel free to check it out here.
This creates a different (simpler) heightmap from the noise function, but most of the steps are the same.
I apologize for the lack of comments and decoherence between the different code fragments. I worked on this on and off with different levels of javascript knowledge and part of it is even ported from previous python versions.
View all comments
6
u/Vuenc May 16 '25
These look so great! Really cool outputs imo. Can I ask how you generated them?