EnhancedMesh Sample

The EnhancedMesh sample demonstrates mesh tessellation in Direct3D. Mesh tessellation subdivides mesh triangles. This produces a mesh with finer geometry details which can produce better lighting results even with per-vertex lighting. Mesh tessellation is often used to implement a LOD technique where meshes closer to the viewer are rendered with more details, and meshes further away are rendered with less detail.

Path

Source: (SDK root)\Samples\C++\Direct3D\EnhancedMesh
Executable: (SDK root)\Samples\C++\Direct3D\Bin\x86 or x64\EnhancedMesh.exe

How the Sample Works

The sample can run in one of two modes: hardware tessellation or software tessellation. The user can set the tessellation level to different values and see how the mesh changes in reaction to the level adjustment.

When running in hardware tessellation mode, the sample tessellates the mesh by calling IDirect3DDevice9::SetNPatchMode which sets the number of tessellation segments into which the device will tessellate each mesh segment. For instance, specifying 3.0 will cause each original segment in the input mesh to be tessellated into three segments. This tessellation happens in real-time, after the mesh draw calls in the render loop.

When running in software tessellation mode, the sample does not rely on the hardware to do on-the-fly tessellation. Therefore, the sample must process the mesh and obtain the desired detail level before rendering it. The code achieves this by calling D3DXTessellateNPatches which takes an input mesh and a segment count, and then outputs another mesh that represents the tessellated version of the input mesh. The sample can then render this tessellated mesh using any standard mechanism.