05 The Geometry Pass
Each shader pass (frame) will examine the geometry it has stored, and based on the current viewers location and view direction, will calculate whether the geometry needs be be refined (split) or coarsened (merged).
The basic unit of this process is the ATM Patch. This is a equilateral triangle P0, P1, P2 reading from the bottom left, bottom right, apex. This winding order is consistent no matter the actual orientation of the triangle in space.
Note that the ATM Patch is never directly rendered - it is a data structrure which will later have geometry added to it
The ATM Patch always decomposes into smaller patches in the order Bottom Left Triangle, Bottom Right Triangle, Apex Triangle, Inverted Centre Triangle. Again this ordering must be consisent with respect to P0, P1, P2.

During Split and Merge we obey the rule that a ATM Patch cannot split if any of its neighbours are more coarse that it; and it cannot merge if any of its neighbours are more detailed than it. This '1-Step Rule' allows us to generate completely seamless, crack free tesellations.
The ATM Patch structure is critical to operating the ATM concept. The patch represents an area of land on the Geoid surface (i.e. without any height applied). A Patch has a number of data structures which define its relationship with its children, and its neighbours.

This is represented by the following code
struct Patch
{
// When merging, this contains a indication of whether this was accepted as a merge, or was rejected for some reason
uint MergeVoteOutcome ;
// The ID of the patch. This is also the offset into the ATM Patches buffer.
uint ID;
// When merging, this contains a count of how many children have voted to merge ?
uint MergeVoteCount;
// The Datum coordinate of the patch
float3 PatchDatum;
// Once split, this contains the ATM Patch IDs of the three Children
uint Child0Index;
uint Child1Index;
uint Child2Index;
uint Child3Index;
// Records the Level of Detail for the patch. Children have a LOD value of one more than their parent
uint LODLevel;
// All Position are in Datum Relative coordiante systems. Add PatchDatum if you need to establish a global coordinate
float3 P0Position;
// Contains the ATM Patch ID of the Parent patch
uint ParentIndex;
// All Position are in Datum Relative coordiante systems. Add PatchDatum if you need to establish a global coordinate
float3 P1Position;
// All Position are in Datum Relative coordiante systems. Add PatchDatum if you need to establish a global coordinate
float3 P2Position;
// When splitting, this contains the status of the split operation
// 0 - No operation pending
// 1 - Split operation pending
// 2 - Merge into parent operation pending
uint SplitStatus;
// My single egde might border one (same LOD or less LOD) or two (Greater LOD) neighbours.
// Therefore I need two external reference slots, to cater for where my neighbour is a greater LOD.
// These are Index_A and Index_B for each edge. The value Unallocated is assigned to B unless we actually
// have a dual neighbour.
// Edge 0 (P0→P1)
// Slot 0 -> P0->P0P1
uint Edge0Slot0NeighbourPatchID;
// Slot 1 -> P0P1->P1
uint Edge0Slot1NeighbourPatchID;
uint Edge0NeighbourLOD;
uint Edge0NeighbourEdgeID; // which edge slot on the E0 neighbour references us
// Edge 1 (P1→P2)
uint Edge1Slot0NeighbourPatchID;
uint Edge1Slot1NeighbourPatchID;
uint Edge1NeighbourLOD;
uint Edge1NeighbourEdgeID; // which edge slot on the E1 neighbour references us
// Edge 2 (P2→P0)
uint Edge2Slot0NeighbourPatchID;
uint Edge2Slot1NeighbourPatchID;
uint Edge2NeighbourLOD;
uint Edge2NeighbourEdgeID; // which edge slot on the E2 neighbour references us
uint PositionInParent; // Where LOD > 0 this indicates which of the four positions in the parent this child was generated as.
}
Each Patch Side may be adjacent to one (where the neighbour is same size, or larger) or two (where the neighbours are smaller) patches. The information on these is stored in Slot0 and Slot1 structures. In order to interpret a Patches neighbour the following rule is used;
- The Slot0 is always present - a patch always is adjacent to another patch
- If Edge N Neighbour LOD is larger than the Patch LOD, this edge is adjacent to two neighbours. Slot0 and Slot1 will be filled
- If Edge N Neighbour LOD is smaller than the Patch LOD, this edge is adjacent to one larger neighbour. Slot0 will be filled.
- The Edge N Neighbour ID contains the neighbours edge ID. This is used when looking up the neighbours own ATM Patch data and tells us how the neigbour is oriented with respect to this ATM Patch.
When considering the orientation of one patch to its neighbour there are only three valid orientations per edge;
- Edge0 meets neighbours Edge0
- Edge0 meets neighbours Edge1
- Edge0 meets neighbours Edge2
The three possible relationships between Side 0 and neighbouring Patches of the same size are shown below.



… and so on.
Since the patches are always generated in the same winding order, and always decompose into four children in the same way, the information in the struct is sufficient to be able to calculate all possible combinations of orientation, and enable walking of the neighbouring patches where required.
Data Structures
Stable
Const_MaxPatches = 50,000
Patch Buffer (Const_MaxPatches) - contains a list of all the ATM Patches.
This is composed of the three cardinal points plus the IDs of the neighbours. Note that each Side can have a minimum of one neighbour and a maximum of two neighbours (where the neighbour is split). The ATM Patch also records the LOD level (Level of Detail) and the LOD Level of each of its neighbours. This is later used when determining whether the tile can follow the 1-Step Rule.
Available Patch IDs Buffer (Const_MaxPatches) - contains a list of all the unused Patch IDs, prefilled in reverse order.
Leaf Patch IDs Buffer - a list of all the patches which are leaves, i.e. are not themselves split into further patches.
Per Frame
Split Candidate Patch IDs Buffer - a list of all the Patches which are identified as needing splitting
Merge Candidate Patch IDs Buffer - a list of all the Patches which are identified as needing merging
Split Patch IDs Buffer - a list of all the Patches which successfully split this frame
Merged Patch IDs Buffer - a list of all the Patches which successfulyl merged this frame
Leaf Patch IDs Buffer - a list of the existing Leaf patches, added to during Split.
The Split/Merge Pass
Multiple shaders are used sequentially to carry out specific tasks. Each shader operates on a single ATM Patch per thread, with the patches themselves passed into the shaders via per-Frame buffers which they update.
This is a highly efficient mechanism using the GPU multi-threading environment to the fullest, and scales from the initial IcoSphere level-of-detail down to the most detailed ATM patch, which is typically 100m to 200m in size.
Stage 1 - Initial Icosphere
Prepare a set of ATM Patches on the CPU and upload them, and a set of Available Patch IDs and Leaf Patch IDs. This patch set can be as few as 20 or so ATM Patches devolved from an IcoSphere calculation. This is a once-only operation. The following steps are executed every frame.
Stage 2 - Per Frame Preparation
Clear the list of per-Frame Leaf Patch IDs
Stage 3 - Parse For Split
In a compute shader
- Parse the Leaf Patch IDs buffer and compute whether or not they should be split further.
- You can use any algorithm you like to determine whether to split (distance from camera, screen space size, or combination of the two).
- If it needs splitting, mark the ATM Patch SplitStatus flag accordingly.
- Add the Patch ID to the Split Candidates buffer
Key tests:
- If the ATM Patch has a more coarse neighbour (Edge N NeighbourLOD < ATM Patch LOD Level) then it cannnot split. Add it to the Leaf Patch IDs buffer.
- If the ATM Patch has reached max LOD level, it cannot split. Add it to the Leaf Patch IDs buffer.

Stage 4 - Split
In a compute shader,
- Parse the ATM Split Candidates buffer and Consume four new ATM Patch Indexes from the Available Patch IDs buffer.
- Create new Child ATM Patches. These children inherit their parent patches Neighbour information.
- Add the child ATM Patch IDs to the Leaf Patch IDs buffer.
- Add the ATM Patch ID to the Split Patch IDs buffer.
Do not clear the ATM Patch SplitStatus - there is further processing to do.
Stage 5 - Resolve Split Neighbours
In a compute shader,
- Parse the Split Patch IDs buffer. This lists all Parents split this pass.
- If the neighbour it points to is not itself split, then the setting is correct and can stay
- If the neighbour has itself split we need to work out our new siblings (the children of the neighbouring parent) and record the new status.
This shader is a series complex IF() branches examining the various possible states of the new relationship from the new Child perspective.
- All newly generated Children inherited its parents neighbour data.
- Our 1-Step rule tells us that the neighbour might have also split this pass, so it may now have children, or it may have stayed as originally.
- The neighbours original state may have been as a smaller sibling or the same size sibling. It cannot have been a larger sibling, otherwise we would break the 1-Step rule.
The shader updates the Child Edge pointers to the correct Neighbour data, and updates any Neighbours to point to the new Child ensuring continued bi-directional references are correct. This is essentially a bookeeping step.
Stage 6 - Clear Split Status
In a compute shader,
- Parse the Split Patch IDs buffer and update the SplitStatus of newly split ATM Patches back to the unprocessed state.
- Copy the Pre-Frame Leaf Patch IDs buffer over the top of the Stable-Leaf Patch IDs buffer for the renderer to use.
Stage 7 - Parse For Merge
In a compute shader,
- Parse the Leaf Patch IDs and compute whether or not they should be merged to their parent.
- The same basic algorithm should be used as Split but with hyterisys meaning that merging is slightly less likely than splitting. This prevents ATM Patches flip-flopping between splitting and merging continuously.
- If it needs merging back to its parent, mark the SplitStatus of the ATM Patch accordingly.
- Using thread-safe interlocks, increment the parent Patch MergeVoteCount. A parent must have all four children voting to merge to be successful.
- Add the parents Patch ID to the Merge Candidate IDs buffer.
Key tests:
- If the ATM Patch has a more fine neighbours (Edge N NeighbourLOD > ATM Patch LOD Level) then it cannnot merge. Add it to the Leaf Patch IDs buffer.
- If the ATM Patch has reached min LOD level, it cannot merge. Add it to the Leaf Patch IDs buffer.
Stage 8 - Merge
In a compute shader,
- Parse the ATM Merge Candidates buffer and check the MergeVoteCount. The ATM Merge Candidates are the Parent patches that the children will be merged up into, not the children that will be merged.
- If less than four, this cannot be merged. Add all four Child IDs to the Leaf Patch buffer. Clear the MergeVoteCount.
- If merging is poissible, add this Patch ID to the Leaf Patch Buffer and the Merge Patch IDs buffer. Mark each child SplitStatus to MergePending.
Although we have prepared to merge, the merge cannot complete at this stage because we need the parent-child relationship to remain intact until we have resolved the neighbour bookeeping.
Stage 9 - Resolve Merge Neighbours
In a compute shader, parse the ATM Merge Patch IDs buffer and execute similar code to the Reolve Split Neighbours, but in this case examining the Child Patches relationships with their neighbours, and updating the Parent patch accordingly.
Stage 10 - Clear Merge Status
In a compute shader, parse the ATM Merge Patch IDs
- Add the Child Patch IDs back into the Available Patch IDs buffer for re-use
- Set the Child N Index fields to unallocated in the Parent Patch
- Clear the retained values in the Child N Patch record in the ATM Patch buffer to prevent leakage when these records are reused.
- Clear the SplitStatus of the parent, the MergeVoteCount etc.
- Copy the Pre-Frame Leaf Patch IDs buffer over the top of the Stable-Leaf Patch IDs buffer for the renderer to use.
The Result
At the conclusion of this sequence the list of Leaf Patch IDs now describes a set of ATM Patches which are the leaves of a tree. These leaves are candidates for rendering. Those ATM Patches that exist outside this list are all Parents which are maintained but are not rendered.
The Leaf Patches are guaranteed to differ by only one LOD level from each other, and their Neighbour information embeded in each ATM Patch is sufficient for crack-free rendering later in the frame pass.