Skip to content

ComputeCullData

Chuck Walbourn edited this page Jun 1, 2020 · 11 revisions

Computes culling data for input meshlets, typically generated by ComputeMeshlets.

HRESULT ComputeCullData(
    const XMFLOAT3* positions, size_t nVerts,
    const Meshlet* meshlets, size_t nMeshlets,
    const uint16_t* uniqueVertexIndices, size_t nVertIndices,
    const MeshletTriangle* primitiveIndices, size_t nPrimIndices,
    CullData* cullData,
    MESHLET_FLAGS flags = MESHLET_DEFAULT);
HRESULT ComputeCullData(
    const XMFLOAT3* positions, size_t nVerts,
    const Meshlet* meshlets, size_t nMeshlets,
    const uint32_t* uniqueVertexIndices, size_t nVertIndices,
    const MeshletTriangle* primitiveIndices, size_t nPrimIndices,
    CullData* cullData,
    MESHLET_FLAGS flags = MESHLET_DEFAULT);

Parameters

The meshlets to compute culling data for are provided in meshlets, uniqueVertexIndices, and primitiveIndices. The array sizes are nMeshlets, nVertIndices, and nPrimIndices.

The result is written into the _cullData__ array which must be of length nMeshlets.

The flags can be MESHLET_DEFAULT or MESHLET_WIND_CW. By default, it assumes the vertices are counter-clockwise for back facing.

Remarks

The CullData structure is defined with the following members:

  • BoundingSphere which is a bounding sphere for the meshlet geometry in the local space
  • NormalCone contains a 4-vector of 0..255 quantized data encoding the normal cone in xyz and w is the -cos(a + 90).
  • ApexOffset contains a float value for the center - axis * offset

Example

auto mesh = std::make_unique<WaveFrontReader<uint16_t>>();

if ( FAILED( mesh->Load( L"test.obj" ) ) )
   // Error

size_t nFaces = mesh->indices.size() / 3;
size_t nVerts = mesh->vertices.size();

std::unique_ptr<XMFLOAT3[]> pos( new XMFLOAT3[ nVerts ] );
for( size_t j = 0; j < nVerts; ++j )
   pos[ j ] = mesh->vertices[ j ].position;

std::vector<Meshlet> meshlets;
std::vector<uint8_t> uniqueVertexIB;
std::vector<MeshletTriangle> primitiveIndices;
if ( FAILED( ComputeMeshlets( mesh->indices.data(), nFaces,
    pos.get(), nVerts,
    nullptr,
    meshlets, uniqueVertexIB, primitiveIndices) )
    // Error

auto uniqueVertexIndices = reinterpret_cast<const uint16_t*>(uniqueVertexIB.data());
size_t vertIndices = uniqueVertexIB.size() / sizeof(uint16_t);

CullData cull = {};
if ( FAILED( ComputeCullData(g_fmCubeVerts, 24,
    meshlets.data(), meshlets.size(),
    uniqueVertexIndices, vertIndices,
    primitiveIndices.data(), primitiveIndices.size(), &cull) )
    // Error

For Use

  • Universal Windows Platform apps
  • Windows desktop apps
  • Windows 11
  • Windows 10
  • Windows 8.1
  • Xbox One
  • Xbox Series X|S
  • Windows Subsystem for Linux

Architecture

  • x86
  • x64
  • ARM64

For Development

  • Visual Studio 2022
  • Visual Studio 2019 (16.11)
  • clang/LLVM v12 - v18
  • GCC 10.5, 11.4, 12.3
  • MinGW 12.2, 13.2
  • CMake 3.20

Related Projects

DirectX Tool Kit for DirectX 11

DirectX Tool Kit for DirectX 12

DirectXTex

DirectXMath

Tools

Test Suite

Content Exporter

DxCapsViewer

See also

DirectX Landing Page

Clone this wiki locally