Skip to content

Commit

Permalink
Update shader_design.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Xtarsia committed Jan 8, 2025
1 parent 33cd92a commit 1afa969
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions doc/docs/shader_design.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,17 @@ All splat maps are sampled, and of the 16-32 values, the 4 strongest are blended

*Side note:* Storing blend values in 3-bits is possible, where each of the 8 numbers represents an index in a array of 0-1 values: `{ 0.0f, .125f, .25f, .334f, .5f, .667f, .8f, 1.0f }`. In the future, this may be baked at runtime. However, editing using a 3-bit array of fixed values was exceedingly difficult and unsuccessful.

*Side note 2:* The bilinear blend can be skipped for distant terrain, allowing only 1/4 of the samples normally required.

The position of the pixel within its grid square is used to bilinear interpolate the values of the 4 surrounding samples. We disable the default GPU interpolation on texture lookups and interpolate ourselves here.
The position of the pixel within its grid square is used to bilinear interpolate the values of the 4 surrounding samples. We disable the default GPU interpolation on texture lookups and interpolate ourselves here. At distances where the The bilinear blend would occur across only 1 pixel in sceen space, the blend is skipped, allowing only 1/4 of the samples normally required.

**Comparing the two methods:**

* **Texture lookups** - Considering only lookups for which ground texture to use and loading the texture data:
* Splat maps use 12-16 lookups per pixel depending on 16 or 32 textures:
* 4 for the 4 splat maps for 16 textures. 8 for 32 textures. This gets the texture for the closest vertex point
* 8 for the strongest 4 albedo_height textures and the 4 normal_rough textures
* Terrain3D uses 12-20 lookups per pixel depending on if an area has an overlay texture:
* 4 for the surrounding 4 grid points on the control map
* 8-16 for the 2-4 albedo_height & normal_rough for the base and overlay textures, for each of the 4 grid points
* Terrain3D uses 5-20 lookups per pixel depending on terrain distance:
* 1-4 for the surrounding 4 grid points on the control map
* 4-16 for the 2-4 albedo_height & normal_rough for the base and overlay textures, for each of the 4 grid points

* **VRAM consumed** - Splat maps store 16 texture strength values in 16 bytes per pixel (16 * 8 bits = 128 bits). We could store that in 16 bits. Splat maps with 32 textures would require 32 bytes per pixel. We store that in 18 bits (5 base, 5 overlay, 8 blend value). On a 4096 x 4096 terrain with 16M pixels, splat maps consume 256MB for 16 textures, 512MB for 32. We can specify 32 textures in only 36MB for a 93% reduction in VRAM. This calculation considers only the portion of the maps that define where to place the textures on the terrain. Tools use up a lot more VRAM for other things.

Expand Down

0 comments on commit 1afa969

Please sign in to comment.