by date
WTF is a clipmap?
WTF is a clipmap?
| Name: | Thomas Buscaglia | ![]() |
|---|---|---|
| Date Posted: | Jun 09, 2007 | |
| Rating: | 4.0 out of 5 | |
| Public: | YES | |
| Comments: | YES | |
| RSS Feed: | or Subscribe with . | |
| Profile Page: | View profile page for Thomas Buscaglia |
Blog post
Hey, guys. I was recently sentenced to port the Atlas clipmap to Torque X terrain. Now that it's done I thought I'd take a couple minutes to to talk a little about the concept and implementation.
What is a clip map?
Hello, Wikipedia....
What this means is that you can effectively have a freakishly huge virtual texture for a very small fraction of the memory cost. This has obvious implications for terrain, which is why I was forced to implement it.
How does it work?
You take a stack of textures the same size and fill them with texture data sampled from descending mip levels of the virtual texture. What you get is a series of textures of degrading quality. Each one represents a larger area of the virtual texture. This set of textures is the clip stack.
If your clipmap textures are 512x512 you can effectively represent a 16384x16384 virtual texture with only 6 clip stack levels. The first level would be a 512x512 piece of the virtual texture that's closest to your viewpoint, the second level would be a 512x512 representation of a 1024x1024 area of the virtual texture closest to your viewpoint, and so on and the 6th level would be a 512x512 representation of the entire 16384x16384 virtual texture.
Because the texture data in the clip stack is only relevant to the areas around you, you have to recenter the clipmap when you viewpoint changes. Below you can see a clipmap with a simple debug texture being drawn on a terrain. Each clip level's checkerboard size is the same size across the texture space to make the level transitions more obvious (4 squares on one level will appear the same size as 1 square on the next level when drawn on the terrain).

To make things more efficient, instead of updating the entire texture for a clip level, clipmaps take advantage of toroidal mapping - meaning they rely on the fact that textures coordinates can wrap. When a clip level is recentered, the clip map calculates which regions of the texture need to be filled with new data and only updates those regions. Below is the same debug texture, now toggling between three colors each time it performs an update on a section of the clip level texture. Each different color rectangle is a single region update to a clip level's texture (notice that the lowest detailed level is never updated).

As a result of using this method, instead of the seams of the source texture region that's in a given clip level being along the edges of the texture they move through the texture space and the shader compensates for that offset in the texture coordinates at render time. Below are snapshots of all 6 512x512 clip levels of the clip stack described above from highest to lowest detail.






And below, a hideuos F terrain exported from TGE and imported into Torque X with the above blender clipmap applied.

That's all for now. Hope someone found this interesting.
If you'd like more information on the topic, there's a pretty detailed paper
here.
What is a clip map?
Hello, Wikipedia....
Quote:
Clipmapping is a method of clipping a mipmap to a subset of data pertinent to the geometry being displayed. This is useful for loading as little data as possible when memory is limited, such as on a graphics processing unit.
What this means is that you can effectively have a freakishly huge virtual texture for a very small fraction of the memory cost. This has obvious implications for terrain, which is why I was forced to implement it.
How does it work?
You take a stack of textures the same size and fill them with texture data sampled from descending mip levels of the virtual texture. What you get is a series of textures of degrading quality. Each one represents a larger area of the virtual texture. This set of textures is the clip stack.
If your clipmap textures are 512x512 you can effectively represent a 16384x16384 virtual texture with only 6 clip stack levels. The first level would be a 512x512 piece of the virtual texture that's closest to your viewpoint, the second level would be a 512x512 representation of a 1024x1024 area of the virtual texture closest to your viewpoint, and so on and the 6th level would be a 512x512 representation of the entire 16384x16384 virtual texture.
Because the texture data in the clip stack is only relevant to the areas around you, you have to recenter the clipmap when you viewpoint changes. Below you can see a clipmap with a simple debug texture being drawn on a terrain. Each clip level's checkerboard size is the same size across the texture space to make the level transitions more obvious (4 squares on one level will appear the same size as 1 square on the next level when drawn on the terrain).

To make things more efficient, instead of updating the entire texture for a clip level, clipmaps take advantage of toroidal mapping - meaning they rely on the fact that textures coordinates can wrap. When a clip level is recentered, the clip map calculates which regions of the texture need to be filled with new data and only updates those regions. Below is the same debug texture, now toggling between three colors each time it performs an update on a section of the clip level texture. Each different color rectangle is a single region update to a clip level's texture (notice that the lowest detailed level is never updated).

As a result of using this method, instead of the seams of the source texture region that's in a given clip level being along the edges of the texture they move through the texture space and the shader compensates for that offset in the texture coordinates at render time. Below are snapshots of all 6 512x512 clip levels of the clip stack described above from highest to lowest detail.






And below, a hideuos F terrain exported from TGE and imported into Torque X with the above blender clipmap applied.

That's all for now. Hope someone found this interesting.
If you'd like more information on the topic, there's a pretty detailed paper
here.
Recent Blog Posts
| List: | 11/29/07 - Torque X 3D Beta is here! 06/14/07 - Introducing TXB! 06/09/07 - WTF is a clipmap? 04/10/07 - Something to look forward to... 02/07/07 - About this deadline... 08/13/06 - GG: Thanks for everything 06/21/06 - Interning at GG |
|---|
Submit your own resources!| Dan MacDonald (Jun 09, 2007 at 18:26 GMT) |
| Tom Eastman (Eastbeast314) (Jun 10, 2007 at 03:26 GMT) |
Terrain is groovy stuff. Perhaps tonight's bedtime reading will be the Atlas source :)
| Ben Garney (Jun 10, 2007 at 04:50 GMT) |
| Ben Garney (Jun 10, 2007 at 04:51 GMT) |
| Anton Bursch (Jun 10, 2007 at 18:00 GMT) |
| Tom Spilman (Jun 10, 2007 at 18:10 GMT) |
| Jonathon Stevens (Jun 11, 2007 at 00:39 GMT) |
| Thomas Buscaglia (Jun 11, 2007 at 02:01 GMT) |
| Tom Spilman (Jun 11, 2007 at 02:50 GMT) |
My beef with the clipmap in TGEA is that the "virtual map" size is limited by the clipmap size. This keeps us from having tightly repeating terrain textures in the blender.
Your probably thinking... "Why the hell would you want your textures to repeat more? Doesn't that look like ass?". It actually looks great if you repeat your detail texture at a very low frequency over the terrain... sort of what Brian did over here.
The results are really freaking good...


This "macro detail" texture works better in a blender terrain as it is not blend layer specific unlike the common complaint about using detail textures.
| Thomas Buscaglia (Jun 11, 2007 at 04:03 GMT) |
This is because the clip map effect uses a vertex shader to calculate when to fade between clip levels. If you try to blend between clip levels between verts on a mesh you get visible wrapping of one of the clip levels because the fade doesn't account for surface area between verts. That's the only limitation and it can easily be solved by adding more vertex density to your terrain or decreasing the distance between verts, rather than increasing the clip stack depth (essentially, shrink the terrain - which sounds limiting, but I think we're going to have support for multiple terrains per level to allow people to create vast landscapes).
There might be another solution involving clip level alignment against edges, but I haven't experimented with that at all.
| Tom Spilman (Jun 11, 2007 at 04:27 GMT) |
Well the other option here is to allow per-blend layer detail maps. If the clipmap is that much of a performance gain then using a unique detail texture per layer shouldn't be that much of a burn and would resolve my issue just as nicely. You can also fade the detail map out based on the clipmap level, so that it is only really used on the closer more detailed areas.
| Thomas Buscaglia (Jun 11, 2007 at 08:42 GMT) |
I'm thinking we'll probably go the range-based route with TX. If I'm feeling fancy I might add support for multiple detail textures (one per base texture) if it's not too slow in XNA. I guess you could just specify the size in texels you want the detail map to be, then whenever it updates the smallest layer that would fit the detail map, you would update that aswell. Hmm...
| Tom Spilman (Jun 11, 2007 at 08:56 GMT) |
| James Brad Barnette (Jun 14, 2007 at 18:40 GMT) |
| Matt Vitelli (Jun 24, 2007 at 01:03 GMT) |
| J.C. Smith (Jun 24, 2007 at 09:12 GMT) |
| James Brad Barnette (Jun 24, 2007 at 17:21 GMT) |
however having a 4 sepperate sets of these for blended atlas terrains I would think would require atlas blended being a sepperate class. then again I'm not a programmer.
| Matt Vitelli (Jun 24, 2007 at 18:05 GMT) |
You must be a member and be logged in to either append comments or rate this resource.



4.0 out of 5


