top of page
Search

The Demo of Basic Virtual Texture

Writer: Andy DoAndy Do

Virtual texture has been used more and more in recent years. Simply to say, it’s a technology that uses textures in a highly efficient way that can give your game extremely high visual quality for textures, but only consume little video memory at the same time. It’s easy to find many papers talking about the detail of this technology on the network. This article is only about the things that I did in my basic virtual texture demo.

The demo is based on DX11 and was written in VS 2017.

  • The demo implements virtual texture in the style of Mega Texture, it doesn’t procedurally generate virtual texture pages at runtime.

  • The conversion of mesh UV from individual texture space to virtual texture space is done when meshes are being loaded, by simply adding texture offsets in the virtual texture to original UVs.

  • Two pixels are added to virtual texture pages on each side as borders, this enables built-in hardware bilinear filtering can be applied. The page size is reduced by the border so that the sum of both to be power-of-two, the downscale is preprocessed by a compute shader.

  • In the simple demo, virtual page requests are sent out from pixel shader through a downscaled UAV in the lighting pass. The UAV is only about 1/64 of screen size but a dither factor is applied so that every screen pixel can have a chance to send out page requests in a sequence of frames. One screen pixel can send out at most one page request in one frame because a Z-pre pass is rendered before the lighting pass.

  • Virtual page data are stored in a custom file with streaming friendly format. At present, the demo loads page data in the same thread of rendering. Each frame, at most 32 requested pages are loaded into memory and stored into a texture array, then one draw call updates all the pages to the page cache. In real projects, streaming page data definitely should be done in additional threads, and it’s not difficult to be implemented.

  • In the below video, the page cache is set to a small size (2048 x 2048) so that the page replacement that occurs when the cache gets full could be clearly seen.

  • The demo is based on DX11 and was written in VS 2017.



 
 
 

Comments


©2020 by Andy Do. Proudly created with Wix.com

bottom of page