Graphics Programmer

Virtual Texture Demo

This is an implementation of virtual texturing (also known as MegaTexture in idTech5). It is written in C# and uses Direct3D 10 with the help of SlimDX. I'm releasing it under the MIT license.

Due to the nature of texturing and mipmapping on graphics hardware, only a subset of texture information is needed per frame. This is roughly proportional to the number of pixels on screen. We can take advantage of this if we know which parts of the texture are needed each frame. Virtual texturing is a system that determines what is needed, loads it and renders it in a pixel shader. Because the texture memory required is proportional to the number of pixels on screen, we can scale the texture sizes much larger than traditional texturing. It even allows for textures larger than can fit in memory, while only using a small, fixed amount of memory at runtime.

This demo demonstrates the system with a simple scene texture mapped with a 32kx32k texture. During runtime the scene is rendered and the texture coordinates and derivatives are used to determine which texture pages are required. This information is downloaded to the CPU, which then schedules the required pages to be loaded in the background. Loaded pages are then uploaded into a texture atlas. The residency of a texture page is tracked in a quad-tree like structure called the page table. The page table is used in the pixel shader to map from the model’s texture coordinates to the texture atlas.



Requirements


Downloads


Usage

Download the binaries and one of the data files. Be sure to download and install the required libraries (see Requirements). Extract the data into the "Data" folder from the archive. A lower resolution version of the data is available, if you don't want to download the full resolution one. The data is compressed with 7zip. When starting the demo a window will pop up and give you various options. Mouse over the options to see what they do. The sample data included needs to be processed before running. It may take a few minutes.