This video documents the procedural mathematical modeling of a brick-and-mortar tower inside Shaderoy using Signed Distance Fields (SDFs). The presenter demonstrates the step-by-step construction of the scene's geometry, domain operations, and procedural texturing from first principles without relying on polygons or traditional 3D modeling packages.
The technical process begins with the derivation of a 3D box SDF to represent an individual brick, followed by polar and vertical domain repetitions to populate the tower. Polar repetition is achieved by computing cylindrical coordinates, dividing the space into angular sectors, and applying a 2D rotation matrix to fold space back into a single base sector. Vertical repetition is capped using limited domain repetition to expose the tower's interior. To eliminate synthetic uniformity, the presenter introduces pseudo-random variations to brick orientation, height, and radial protrusion using high-frequency aliasing hashes derived from sector and layer IDs. A hollow tube SDF is constructed to represent the mortar, which is then blended with the brick geometry using a custom quadratic smooth minimum ($smin$) function. This blending operation also yields an interpolant factor used to cleanly transition between brick and mortar shaders. Finally, the presenter implements a custom 3D trilinear lattice noise and Fractional Brownian Motion (FBM) algorithm, smoothed with a cubic Hermite interpolant, to procedurally displace the surfaces and generate organic, rock-like material textures.
-
0:00 Mathematical Rendering Setup: The renderer utilizes Signed Distance Fields (SDFs), where a function evaluates any 3D point $P$ to return the shortest distance to a surface. A basic sphere is defined by subtracting the radius from the length of coordinate vector $P$.
-
2:08 Box SDF Derivation: A 3D box SDF is constructed by taking the absolute value of coordinate vector $P$, subtracting the half-dimensions $B$, clamping the positive outer components, and accounting for the negative inner distances.
-
4:02 Radial Domain Repetition: To arrange the bricks in a ring, the angular component of point $P$ is calculated via arc-tangent. The circle is divided into discrete angular sectors (e.g., 12 or 16), and a 2D rotation matrix maps all coordinates back to a primary base sector.
-
6:44 Vertical Repetition & Limited Domain: Bricks are tiled vertically by dividing the Y-coordinate by the layer spacing and flooring the result to establish a layer ID. Domain repetition is restricted using conditional bounds to prevent geometry from rendering above a specific layer, revealing the tower's interior.
-
9:09 Procedural Randomization & Ring Offsets: To break up vertical alignment, each brick layer is rotated by a pseudo-random angle derived from its layer ID. This is achieved by passing the layer ID through a modified sine wave function.
-
11:01 Tube SDF Construction: A hollow cylinder representing the mortar is modeled by projecting 3D space into a 2D plane revolving around the central axis, then evaluating a 2D box SDF with defined wall thickness and height parameters.
-
13:59 Undistorted Coordinate Space Mapping: To prevent the mortar tube from warping under the influence of the brick domain's polar and vertical repetitions, the tube's SDF is evaluated using the original, undistorted input coordinates ($OP$).
-
16:02 Parametric Randomization via High-Frequency Aliasing: High-frequency deterministic hashes are generated by multiplying sector and layer IDs by large coefficients inside a sine function. The resulting aliased noise modulates individual brick dimensions and radial offsets.
-
19:51 Spatial Identity & Color Assignment: A conditional switch determines whether a rendering step is closest to the brick or mortar geometry, returning an object ID channel to drive procedural color assignment in the shader.
-
23:17 Smooth Minimum Blending: A quadratic smooth minimum function ($smin$) blends the intersection of the bricks and mortar. This replaces sharp intersections with an organic, physically plausible transition zone governed by a metric tolerance parameter.
-
27:32 Interpolating Material IDs: The smooth minimum function is modified to return both the blended distance and a normalized interpolation factor. This factor serves as a transition map to blend shaders and colors seamlessly at the brick-mortar boundary.
-
29:52 Procedural Color Variation: A 3D color hash samples a sine wave at phase-shifted intervals ($0$, $2\pi/3$, $4\pi/3$) to shift the hue and brightness of individual bricks, mitigating the flat appearance of synthetic computer graphics.
-
34:01 Procedural 3D Lattice Noise: A custom 3D noise function is built by dividing space into integer lattice cells, hashing the eight surrounding corner vertices, and interpolating the values trilinearly based on fractional cell coordinates.
-
38:59 Normal Discontinuities and Cubic Interpolant Smoothing: To eliminate lighting artifacts caused by derivative discontinuities in linear interpolation, the noise interpolant is passed through a cubic Hermite curve ($3t^2 - 2t^3$), ensuring continuous surface normals.
-
40:42 Fractional Brownian Motion (FBM) for Surface Displacement: Multiple octaves of the cubic lattice noise are layered together with accumulating frequency and decaying amplitude. This FBM output displaces the SDF boundaries to produce realistic, weathered rock textures on the brick surfaces.