Algorithm Search⌘K

Data structureadvanced

Texture clipmap

Also called clipmap.

A mipmap whose finer levels are clipped to a fixed-size window around the viewer, so that very large textures fit in a bounded memory.

Time
Θ(C^2 (1 + log(N/C))) buildO(1) lookupO(C (d + log(N/C))) recenter
Space
Θ(C^2 (1 + log(N/C))) total
Where
C = the clip size in texels; N = the side of the finest level in texels; d = the number of finest-level texels by which the center moves, along one axis
Properties
not concurrentexternalnot persistent
Origin
Christopher C. Tanner, Christopher J. Migdal, Michael T. Jones, 1998

A texture clipmap is a mipmap in which every level larger than a clip size CC keeps only a C×CC \times C window of texels around a clip center, the point of the texture that the viewer looks at; the levels of size CC or less are kept whole. A full mipmap of a 16384216384^2 texture takes about 358 million texels, and a clipmap with C=512C = 512 takes 1.66 million. Virtual texturing keeps the pages that the view needs, wherever they are, with a page table; the clipmap keeps fixed windows around one point, so it needs no table, and a lookup only has to find the finest level whose window holds the point. Geometry clipmaps use the same nested windows for the heights of a terrain.

In plain words

A huge photo of the ground is too big for the graphics card, and a viewer near the ground sees fine detail only close by. Far away, the coarse versions of the photo are enough.

So keep each coarse version of the photo whole while it is small. For each large version, keep only a square of fixed size around the place under the viewer. The squares of the finer versions cover smaller areas, and the coarsest versions cover everything.

To color a point, use the finest version whose square holds that point. When the viewer moves, each square moves with them. Only the strip of new texels on one side is loaded, and it goes into the place of the strip that drops off the other side.

The abstract type

A texture clipmap of a texture with the mipmap levels 00 (finest, N×NN \times N) to log⁡2N\log_2 N (one texel) has these operations.

  • build(c): make the clipmap for the clip center cc.
  • recenter(c): change the clip center to cc, so that every clipped level holds its new window.
  • lookup(u, v, lambda): the filtered sample at the point (u,v)(u, v) for the level of detail λ\lambda that the hardware computes, but from a coarser level if the window of level λ\lambda does not hold the point.

Inside the windows, lookup gives the same value as the full mipmap. Outside, it gives a value of a coarser level, which is a blur, not a wrong texel.

Representation

Level ll has N/2lN / 2^l texels along each side. The levels with N/2l>CN / 2^l > C form the clip stack: each is an array SlS_l of C×CC \times C texels. The clip center at level ll is cl=⌊c/2l⌋c_l = \lfloor c / 2^l \rfloor per coordinate, and the window of level ll is the square of texels tt with cl−C/2≤t<cl+C/2c_l - C/2 \le t < c_l + C/2 in each coordinate. The texel tt is stored at the slot (tx mod C,ty mod C)(t_x \bmod C, t_y \bmod C), a toroidal address as in a circular buffer, so a texel that stays in the window keeps its slot when the center moves. The levels with N/2l≤CN / 2^l \le C form the clip pyramid and are stored whole, as in a mipmap.

In level 0 units the window of level ll is a square of side C⋅2lC \cdot 2^l, so each level of the stack covers four times the area of the level before it, and the pyramid covers the whole texture. The full texture stays on disk or in main memory, and the stack is filled from it.

Operations

  1. RECENTER(c) ▷ the new clip center, in level 0 texels
  2. 1for each level l of the clip stack do
  3. 2c_l ← floor(c / 2^l) ▷ per coordinate
  4. 3for each texel t with c_l - C/2 ≤ t < c_l + C/2 that is not in the old window do
  5. 4S_l[t_x mod C, t_y mod C] ← texel t of level l, read from the full texture
  6. 5the window of level l ← the new window
  7. LOOKUP(u, v, λ) ▷ λ from the texel footprint, as for a mipmap
  8. 6l_min ← the smallest l such that the levels l, l + 1, ... all hold the bilinear taps of (u, v)
  9. 7l ← max(λ, l_min)
  10. 8return the trilinear sample between the levels floor(l) and floor(l) + 1

BUILD is RECENTER with every texel new, plus the fill of the pyramid. The pyramid levels hold every point. The code finds lmin⁡l_{\min} in line L6 by a walk from the coarsest level down, in O(log⁡(N/C))O(\log(N/C)) steps. A renderer can compute it in O(1)O(1): a window of level ll reaches about C⋅2l−1C \cdot 2^{l-1} level 0 texels from the center, so lmin⁡l_{\min} follows from the largest coordinate distance between (u,v)(u, v) and cc with a logarithm, and a margin of a few texels covers the filter; that margin is a tuning.

Example

Take a 16384×1638416384 \times 16384 texture and C=512C = 512. The levels have the sides 16384, 8192, ..., 1. The five levels of side 16384 to 1024 form the stack, with 5⋅5122=1,310,7205 \cdot 512^2 = 1{,}310{,}720 texels. The pyramid holds the levels of side 512 to 1, with (410−1)/3=349,525(4^{10} - 1)/3 = 349{,}525 texels. So the clipmap has 1,660,245 texels, against 357,913,941 for the full mipmap: 215.6 times fewer. At 4 bytes per texel, that is 6.64 MB in place of 1.43 GB.

A lookup. The clip center is c=(8000,8000)c = (8000, 8000) and the point is at the level 0 texel (8400,8100)(8400, 8100), with λ=0\lambda = 0.

level center clc_l the point at this level window holds the point
0 (8000,8000)(8000, 8000) (8400,8100)(8400, 8100) no, 8400≥8000+2568400 \ge 8000 + 256
1 (4000,4000)(4000, 4000) (4200,4050)(4200, 4050) yes
2 (2000,2000)(2000, 2000) (2100,2025)(2100, 2025) yes

So line L6 gives lmin⁡=1l_{\min} = 1, and the lookup returns a sample of level 1 where the full mipmap would give level 0. The point is 400 texels from the center, and the full level 0 detail reaches only 256.

A move. Moving the center by 64 texels of level 0 in xx moves the windows of the levels 0 to 4 by 64, 32, 16, 8 and 4 texels. Line L4 then loads 512⋅(64+32+16+8+4)=63,488512 \cdot (64 + 32 + 16 + 8 + 4) = 63{,}488 texels, against 1,310,720 for a reload of the whole stack.

Correctness

The proof file gives the arguments. The tests compare the stack after 60 random moves with a fresh fill and with the full mipmap, and compare 800 lookups with trilinear samples of the full mipmap.

  • One slot per texel. The texels of a window have, in each coordinate, CC consecutive values, which have CC distinct residues mod CC. So the toroidal slots of line L4 are one to one on a window (a proved property).
  • The update. A texel in both the old and the new window keeps its slot and its value, and line L4 writes each new texel. So after line L5 each stack level holds exactly its new window, as a fresh fill would (a proved property).
  • The lookup. The lookup reads only texels inside the windows, and it returns the trilinear sample of the full mipmap at max⁡(λ,lmin⁡)\max(\lambda, l_{\min}). So if lmin⁡≤λl_{\min} \le \lambda, it equals the sample of the full mipmap. Otherwise l>λl > \lambda, and the sample comes from a coarser level of the same mipmap, so it is a blurred value of the right image (a proved property of the structure; how visible the blur is depends on the scene).
  • Nesting. In level 0 units the window of level ll is [2l(cl−C/2),2l(cl+C/2))[2^l (c_l - C/2), 2^l (c_l + C/2)) in each coordinate, and 2lcl2^l c_l lies in (c−2l,c](c - 2^l, c]. Comparing the two ends with those of level l+1l + 1 shows that for C≥4C \ge 4 each window lies inside the next coarser one. So the levels that hold a point are lmin⁡l_{\min} and all coarser ones, and line L6 is well defined (a proved property).
Proof: The toroidal clip stack equals a fresh fill after every move, the windows nest for clip sizes of at least four, and a lookup equals a full mipmap sample at the level it usesfull

We use the notation of the page and the code. Level ll has the side N/2lN / 2^l, and the levels 0,…,k−10, \ldots, k - 1 with N/2l>CN / 2^l > C form the clip stack; CC is even. For a clip center cc (integer level 0 texels), cl=⌊c/2l⌋c_l = \lfloor c / 2^l \rfloor per coordinate, and the window Wl(c)W_l(c) is the set of texels tt with cl−C/2≤t<cl+C/2c_l - C/2 \le t < c_l + C/2 in each coordinate. The slot of the texel tt of a stack level is σ(t)=(tx mod C,ty mod C)\sigma(t) = (t_x \bmod C, t_y \bmod C). The texel values of the full mipmap are ml(t)m_l(t).

The slots

Lemma 1. For each ll and cc, σ\sigma is one to one on Wl(c)W_l(c).

Proof. In each coordinate the texels of the window take CC consecutive integer values, and CC consecutive integers have CC distinct residues mod CC. So two texels of the window with the same slot have the same xx and the same yy. □\square

The update

Proposition 2. After RECENTER(c)(c) (lines L1 to L5), for each stack level ll the window is Wl(c)W_l(c) and the slot σ(t)\sigma(t) holds ml(t)m_l(t) for every texel tt of Wl(c)W_l(c) inside the texture. The call writes exactly the texels of Wl(c)W_l(c) that are not in the old window. So the stack equals the stack of a fresh build at cc.

Proof. By induction on the calls. For the first call (from the constructor) there is no old window, so lines L3 and L4 write every texel of Wl(c)W_l(c), each to its own slot by Lemma 1. For a later call, let W′W' be the old window, with σ(t)\sigma(t) holding ml(t)m_l(t) for t∈W′t \in W' by induction. A texel t∈Wl(c)∩W′t \in W_l(c) \cap W' is skipped, and its slot still holds ml(t)m_l(t): a write in this call goes to the slot of a texel t′∈Wl(c)∖W′t' \in W_l(c) \setminus W', and σ(t′)≠σ(t)\sigma(t') \ne \sigma(t) by Lemma 1 on Wl(c)W_l(c). Each texel of Wl(c)∖W′W_l(c) \setminus W' is written by line L4 with its value. Line L5 sets the window. The writes are exactly the texels of Wl(c)∖W′W_l(c) \setminus W', and the contents of the slots depend only on Wl(c)W_l(c), as for a fresh build. □\square

If the center moves by d≥0d \ge 0 level 0 texels along one axis, clc_l moves by at most ⌈d/2l⌉≤d/2l+1\lceil d / 2^l \rceil \le d / 2^l + 1, and the new texels form a strip of at most that many columns of CC texels. So a move writes at most C(d/2l+1)C (d / 2^l + 1) texels at level ll, and O(C(d+k))O(C (d + k)) over the stack. When dd is a multiple of 2k−12^{k-1}, the rounding does not change the shifts, and the count is exactly C∑l<kd/2lC \sum_{l < k} d / 2^l; the test checks C(8+4+2)C (8 + 4 + 2) for d=8d = 8 and k=3k = 3.

The windows nest

Lemma 3. If C≥4C \ge 4, then for every l≥0l \ge 0 and cc, the window of level ll lies inside the window of level l+1l + 1 when both are written in level 0 units.

Proof. Let Xl=2lclX_l = 2^l c_l, so that c−2l<Xl≤cc - 2^l < X_l \le c in each coordinate. In level 0 units the window of level ll is the interval [Xl−2l−1C,Xl+2l−1C)[X_l - 2^{l-1} C, X_l + 2^{l-1} C) in each coordinate. On the low side,

Xl+1−2lC≤c−2lC≤c−2l−2l−1C<Xl−2l−1C,X_{l+1} - 2^l C \le c - 2^l C \le c - 2^l - 2^{l-1} C < X_l - 2^{l-1} C,

where the middle step is 2l−1C≥2l2^{l-1} C \ge 2^l, that is C≥2C \ge 2. On the high side,

Xl+2l−1C≤c+2l−1C≤c−2l+1+2lC<Xl+1+2lC,X_l + 2^{l-1} C \le c + 2^{l-1} C \le c - 2^{l+1} + 2^l C < X_{l+1} + 2^l C,

where the middle step is 2l−1C≥2l+12^{l-1} C \ge 2^{l+1}, that is C≥4C \ge 4. □\square

The pyramid levels l≥kl \ge k hold the whole texture. So by Lemma 3 the set of levels whose window holds a given texel position is all levels from some level on. The bilinear taps of a coarser level reach a little farther from the point than those of a finer level, so line L6 defines lmin⁡l_{\min} as the smallest ll such that every level from ll on holds the taps; it exists because the coarsest level is in the pyramid or, if N≤CN \le C, there is no stack.

The lookup

Proposition 4. For every point (u,v)(u, v) in the texture and every λ≥0\lambda \ge 0, LOOKUP(u,v,λ)(u, v, \lambda) reads only texels of the windows, and it returns the trilinear sample of the full mipmap at the level of detail max⁡(λ,lmin⁡)\max(\lambda, l_{\min}).

Proof. Line L7 sets l=max⁡(λ,lmin⁡)l = \max(\lambda, l_{\min}). The trilinear sample of line L8 reads the bilinear taps of the levels ⌊l⌋\lfloor l \rfloor and, if the fraction is not zero, ⌊l⌋+1\lfloor l \rfloor + 1. Both are at least lmin⁡l_{\min}, so by the definition of line L6 their taps are in the windows. The taps are clamped to the texture, so they are texels inside it. By Proposition 2 each slot that is read holds ml(t)m_l(t), and the pyramid levels are the mipmap levels. So each read value equals the value that the full mipmap gives, and the weights depend only on (u,v)(u, v) and ll. □\square

So when lmin⁡≤λl_{\min} \le \lambda, the lookup equals the sample of the full mipmap at λ\lambda. When lmin⁡>λl_{\min} > \lambda, it equals the sample at the coarser level lmin⁡l_{\min}, a blurred value of the same image. The tests check Proposition 2 after 60 random moves, Lemma 3 for C∈{4,8,16,32}C \in \{4, 8, 16, 32\} and random centers, and Proposition 4 on 800 random lookups.

Complexity

operation time note
build Θ(C2(1+log⁡(N/C)))\Theta(C^2 (1 + \log(N / C))) each stack level and the pyramid once
recenter O(C(d+log⁡(N/C)))O(C (d + \log(N / C))) a move by dd level 0 texels along one axis writes at most C(d/2l+1)C (d / 2^l + 1) texels at level ll; the +1+1 is the rounding of clc_l
lookup O(1)O(1) the level from the distance to the center, then a mipmap sample; the walk of the code takes O(log⁡(N/C))O(\log(N / C))

The space is Θ(C2(1+log⁡(N/C)))\Theta(C^2 (1 + \log(N / C))): C2C^2 texels for each of the log⁡2(N/C)\log_2(N / C) stack levels, and less than 43C2\frac43 C^2 for the pyramid. The full mipmap needs Θ(N2)\Theta(N^2). The cost of a recenter is dominated in practice by the reads from disk or main memory, which is why the structure is external.

Variants

  • Virtual texturing. Virtual texturing splits all levels into pages and keeps the pages that the frame uses, with a page table per lookup. It serves views where the needed texels are not around one point, such as many objects with their own textures.
  • Geometry clipmaps. Geometry clipmaps use the same stack for the heights of a terrain, with the window centered on the viewer.
  • Several centers. A scene with two areas of interest, such as two viewers, needs two stacks or larger windows; the clipmap serves one center well.
  • Updates over several frames. A large move can load the new strips over several frames, and the lookup uses a coarser level until a strip is complete, which a margin in line L6 makes safe.

When to use it

Use a texture clipmap for one very large texture seen from a viewer that moves over it, such as satellite images on a terrain in a flight simulator or a map viewer, when the full mipmap does not fit in texture memory. If the texels in view are spread over many textures, or the view jumps far from frame to frame, virtual texturing fits better. If the texture fits in memory, a plain mipmap is simpler.

Pitfalls

  • An address relative to the window. If line L4 stores the texel at t−(cl−C/2)t - (c_l - C/2) in place of t mod Ct \bmod C, the slot of every texel changes when the center moves, and each move must copy the whole stack.
  • No margin for the filter. If line L6 tests only the point and not its footprint, a bilinear or trilinear sample near the border of a window reads texels outside it, which hold values of the opposite side of the window.
  • The wrong level. If line L7 uses min⁡\min in place of max⁡\max, the lookup can read a finer level than the hardware asked for, and the texture aliases; or, with a window that does not hold the point, it reads a wrong texel.
  • One center for all levels without rounding. If line L2 uses c/2lc / 2^l without the floor, the windows of the levels do not start on texel borders, and the test of line L6 and the slots of line L4 disagree by one texel.
  • A visible edge between levels. Where lmin⁡l_{\min} jumps from one level to the next across the image, the sharpness changes along a line. Blending between ⌊l⌋\lfloor l \rfloor and ⌊l⌋+1\lfloor l \rfloor + 1 in line L8 with a fractional lmin⁡l_{\min} near the border hides it.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

texture_clipmap.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/texture-clipmap/. The authors are listed in prov/NPGSAB.jsonl.

"""A texture clipmap: a mipmap whose levels larger than C keep a C x C window.

Texel coordinates are integers, level 0 is the finest level of side N, and
level l has side N / 2^l. The clip center c is a level 0 texel. A level of
the clip stack stores its window in a C x C array with toroidal addressing;
the levels of side C or less (the clip pyramid) are kept whole. Sample
points (u, v) are in level 0 texel units, with texel centers at i + 1/2.
Values are exact fractions.
"""

from fractions import Fraction
from math import floor


def build_mipmap(tex):
    """All levels of a square power-of-two texture, by 2 x 2 box averages."""
    levels = [[[Fraction(x) for x in row] for row in tex]]
    while len(levels[-1]) > 1:
        a = levels[-1]
        m = len(a) // 2
        levels.append(
            [[Fraction(a[2 * i][2 * j] + a[2 * i + 1][2 * j] + a[2 * i][2 * j + 1] + a[2 * i + 1][2 * j + 1], 4) for j in range(m)] for i in range(m)]
        )
    return levels


def window(c, l, C):
    """The half-open window (x0, y0, x1, y1) of level l for the clip center c."""
    cx, cy = c[0] // 2 ** l, c[1] // 2 ** l
    return (cx - C // 2, cy - C // 2, cx + C // 2, cy + C // 2)


def in_window(w, t):
    return w[0] <= t[0] < w[2] and w[1] <= t[1] < w[3]


def texel_counts(N, C):
    """The texels of the clipmap and of the full mipmap of an N x N texture."""
    sides = []
    s = N
    while s >= 1:
        sides.append(s)
        s //= 2
    return sum(min(s, C) ** 2 for s in sides), sum(s * s for s in sides)


def taps(size, u, v, l):
    """The bilinear taps of level l at (u, v), with clamp addressing, and the weights."""
    x = Fraction(u) / 2 ** l - Fraction(1, 2)
    y = Fraction(v) / 2 ** l - Fraction(1, 2)
    i0, j0 = floor(x), floor(y)
    fx, fy = x - i0, y - j0

    def cl(k):
        return min(max(k, 0), size - 1)

    return (cl(i0), cl(i0 + 1)), (cl(j0), cl(j0 + 1)), fx, fy


def bilinear(get, size, u, v, l):
    (i0, i1), (j0, j1), fx, fy = taps(size, u, v, l)
    return (
        (1 - fx) * (1 - fy) * get(l, i0, j0)
        + fx * (1 - fy) * get(l, i1, j0)
        + (1 - fx) * fy * get(l, i0, j1)
        + fx * fy * get(l, i1, j1)
    )


def trilinear(get, sizes, u, v, lam):
    """The trilinear sample at the level of detail lam >= 0."""
    a = min(floor(lam), len(sizes) - 1)
    f = Fraction(lam) - a if a < len(sizes) - 1 else Fraction(0)
    s = bilinear(get, sizes[a], u, v, a)
    if f == 0:
        return s
    return (1 - f) * s + f * bilinear(get, sizes[a + 1], u, v, a + 1)


def mip_sample(mip, u, v, lam):
    """The reference: a trilinear sample of the full mipmap."""
    return trilinear(lambda l, i, j: mip[l][i][j], [len(a) for a in mip], u, v, lam)


class Clipmap:
    def __init__(self, mip, C, c):
        self.mip = mip  # the full texture, on disk or in main memory
        self.C = C
        self.sizes = [len(a) for a in mip]
        self.k = sum(1 for s in self.sizes if s > C)  # the levels of the clip stack
        self.S = [[[None] * C for _ in range(C)] for _ in range(self.k)]
        self.win = [None] * self.k
        self.recenter(c)

    def recenter(self, c):
        """Move the clip center to c. Returns the number of texels written."""
        C = self.C
        count = 0
        for l in range(self.k):  # @line L1
            new = window(c, l, C)  # @line L2
            old = self.win[l]
            for tx in range(new[0], new[2]):
                for ty in range(new[1], new[3]):  # @line L3
                    if old is not None and in_window(old, (tx, ty)):
                        continue
                    inside = 0 <= tx < self.sizes[l] and 0 <= ty < self.sizes[l]
                    self.S[l][tx % C][ty % C] = self.mip[l][tx][ty] if inside else None  # @line L4
                    count += 1
            self.win[l] = new  # @line L5
        return count

    def get(self, l, i, j):
        if l >= self.k:
            return self.mip[l][i][j]
        if not in_window(self.win[l], (i, j)):
            raise KeyError((l, i, j))
        return self.S[l][i % self.C][j % self.C]

    def holds(self, u, v, l):
        """Does level l hold the bilinear footprint of (u, v)?"""
        if l >= self.k:
            return True
        (i0, i1), (j0, j1), _, _ = taps(self.sizes[l], u, v, l)
        return all(in_window(self.win[l], (i, j)) for i in (i0, i1) for j in (j0, j1))

    def finest_level(self, u, v):
        """The smallest l such that the levels l, l + 1, ... all hold the footprint."""
        l = len(self.sizes) - 1
        while l > 0 and self.holds(u, v, l - 1):  # @line L6
            l -= 1
        return l

    def lookup(self, u, v, lam):
        l = max(Fraction(lam), self.finest_level(u, v))  # @line L7
        return trilinear(self.get, self.sizes, u, v, l)  # @line L8
test_texture_clipmap.py 84 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/texture-clipmap/. The authors are listed in prov/NPGSAB.jsonl.

import random
from fractions import Fraction

from texture_clipmap import Clipmap, build_mipmap, in_window, mip_sample, texel_counts, window

N, C = 64, 8


def make_mip(rng):
    return build_mipmap([[rng.randrange(256) for _ in range(N)] for _ in range(N)])


def centers(rng, k):
    return [(rng.randrange(-8, N + 8), rng.randrange(-8, N + 8)) for _ in range(k)]


def test_stack_after_moves_equals_a_fresh_fill():
    rng = random.Random(1)
    mip = make_mip(rng)
    cm = Clipmap(mip, C, (N // 2, N // 2))
    for c in centers(rng, 60):
        olds = [set((x, y) for x in range(w[0], w[2]) for y in range(w[1], w[3])) for w in cm.win]
        written = cm.recenter(c)
        fresh = Clipmap(mip, C, c)
        expected = 0
        for l in range(cm.k):
            w = window(c, l, C)
            assert cm.win[l] == w == fresh.win[l]
            pts = [(x, y) for x in range(w[0], w[2]) for y in range(w[1], w[3])]
            expected += len(set(pts) - olds[l])
            for x, y in pts:
                slot = cm.S[l][x % C][y % C]
                assert slot == fresh.S[l][x % C][y % C]
                if 0 <= x < len(mip[l]) and 0 <= y < len(mip[l]):
                    assert slot == mip[l][x][y]
        assert written == expected


def test_a_move_writes_only_the_new_strips():
    mip = make_mip(random.Random(2))
    cm = Clipmap(mip, C, (32, 32))
    assert cm.k == 3
    # The windows of the levels 0, 1 and 2 move by 8, 4 and 2 texels.
    assert cm.recenter((40, 32)) == C * (8 + 4 + 2)
    assert cm.recenter((40, 32)) == 0


def test_lookup_equals_the_full_mipmap_at_the_level_it_uses():
    rng = random.Random(3)
    mip = make_mip(rng)
    full = 0
    for c in centers(rng, 20):
        cm = Clipmap(mip, C, c)
        for _ in range(40):
            u = Fraction(rng.randrange(0, 16 * N), 16)
            v = Fraction(rng.randrange(0, 16 * N), 16)
            lam = Fraction(rng.randrange(0, 4 * len(mip)), 4)
            lmin = cm.finest_level(u, v)
            assert cm.lookup(u, v, lam) == mip_sample(mip, u, v, max(lam, lmin))
            if lmin <= int(lam):
                full += 1
                assert cm.lookup(u, v, lam) == mip_sample(mip, u, v, lam)
    assert full > 0


def test_windows_nest_for_clip_sizes_of_at_least_four():
    rng = random.Random(4)
    for size in (4, 8, 16, 32):
        for c in centers(rng, 200):
            for l in range(6):
                a, b = window(c, l, size), window(c, l + 1, size)
                lo = (a[0] * 2 ** l, a[1] * 2 ** l, a[2] * 2 ** l, a[3] * 2 ** l)
                hi = (b[0] * 2 ** (l + 1), b[1] * 2 ** (l + 1), b[2] * 2 ** (l + 1), b[3] * 2 ** (l + 1))
                assert hi[0] <= lo[0] and hi[1] <= lo[1] and lo[2] <= hi[2] and lo[3] <= hi[3]


def test_the_numbers_of_the_page():
    assert texel_counts(16384, 512) == (1660245, 357913941)
    c, p = (8000, 8000), (8400, 8100)
    held = [in_window(window(c, l, 512), (p[0] // 2 ** l, p[1] // 2 ** l)) for l in range(3)]
    assert held == [False, True, True]

History

Tanner, Migdal and Jones presented the clipmap at SIGGRAPH 98 as a "virtual mipmap": a mipmap of a texture much larger than texture memory, in which only a window around a point of interest is kept for each fine level, and the windows are updated toroidally as the point moves. Losasso and Hoppe took the same nested windows from textures to terrain geometry in 2004, as geometry clipmaps. Later systems for large textures moved to page-based virtual texturing, which does not need a single center of interest.

References

  1. Christopher C. Tanner, Christopher J. Migdal and Michael T. Jones, The clipmap, a virtual mipmap, SIGGRAPH 98, 151 to 158, the clip stack and the clip pyramid, the clip center, the toroidal update of the clipped levels, and the choice of a coarser level outside the clip region (general locator)
  2. Frank Losasso and Hugues Hoppe, Geometry clipmaps, terrain rendering using nested regular grids, ACM Transactions on Graphics 23(3), SIGGRAPH 2004, 769 to 776, the comparison with the texture clipmap and the reuse of its nested windows for geometry (general locator)
  3. Tomas Akenine-Möller, Eric Haines, Naty Hoffman, Angelo Pesce, Michał Iwanicki and Sébastien Hillaire, Real-Time Rendering, fourth edition, CRC Press, 2018, the part on texture streaming and very large textures in the chapter on texturing (general locator)

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.build
  • a full proof of time.lookup
  • a full proof of time.recenter
  • a full proof of space.total
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/NPGSAB/text.yaml