Aaron from R2R Games shared part of the process behind StoneWorks, his procedural building system for generating walls, towers, destruction, and erosion effects in real time inside Unity.
Developer
Aaron from
R2R Games gave us a closer look at
StoneWorks, his new procedural building system for generating walls, towers, and stone structures in Unity.
The original inspiration for the project came from early
Tiny Glade demo videos. According to Aaron, seeing walls change shape in real time made him want to build
his own procedural system from scratch.
The system originally started with straight walls and trying to figure out how to generate each stone layer. Stones are placed from bottom to top, and to avoid repetition, each row shifts a bit to the side.
Each stone begins as a simple cube, then some of its corners get cut to give it a more natural shape. A small collection of stone variations is then generated in memory, which each new stone picks from while building the wall.
According to Aaron, this allows entire walls and towers to be built from a relatively small amount of mesh data.
# Simplified pseudo-code shared by the developer
function BuildWall(path, height, stoneSize):
y = 0
rowIndex = 0
while y < height:
rowHeight = stoneSize.y * random(MIN_Y_VARIATION, MAX_Y_VARIATION)
layCourseAlongPath(path, y, rowHeight, rowIndex)
y += rowHeight
rowIndex++
end
// Top stone course for decoration
addCapstoneRow()
// chip corners for weathered look
chipRandomCorners()
// split stones into spatial groupings
combineIntoChunks()
end
After the walls, the system expanded into circular structures, spline paths, and towers. That later led to archways and windows through a modifier system that removes stones from certain sections and rebuilds the surrounding areas.
Aaron explained that archways use angled stones, while windows use flatter ones for the sill sections. Once stone removal was working, Aaron moved to implement erosion.
Erosion is done by removing stones starting from the upper sections of the structure. The system also simulates destroyed sections by using spherical areas with some noise around the edges.
One of the more difficult parts during development was the destruction of larger structures with thousands of stones. Aaron explained that the original version rebuilt too much geometry whenever part of a tower was destroyed.
To improve this, the system was later split into chunks, or small groups of around 32 to 64 stones each. For example, in a cannonball test Aaron made, only the nearby chunks were rebuilt.
Since structures like castles, towers, and bridges can become very large, Aaron also built a custom LOD system. The meshes are simplified using baked textures so the damaged shapes and missing stones still remain visible from a distance.
According to Aaron, this reduced triangle counts by roughly 98% for the first LOD level. The system also uses a dithered crossfade between LODs instead of Unity’s default transitions. Alongside this project, Aaron is also prototyping a cozy game where players work for nobles and slowly build their own estate over time.
If you want to follow the development of StoneWorks and other R2R Games projects, the links will be right below.
Interested in learning more?
If you’re interested in
technical art and
editor scripting in Unity, the
Unity Tool Development Bundle covers topics like procedural shapes, Shader Graph, HLSL, ray marching, custom inspectors, editor windows, and more. 📘