11 ComputeCullData
Chuck Walbourn редактировал(а) эту страницу 2022-01-20 17:34:24 -08:00
DirectXMesh

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. These are generally the direct result of a successful call to ComputeMeshlets.

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 is a 4-vector containing the normal cone of the meshlet geometry, which envelops all triangle normals within the meshlet. This is represented by a 3D axis in xyz, and angular spread stored in w. The value of w is actually -cos(angle + 90 deg), which facilitates backface testing. These values are encoded as uint8 - cone axes are converted from (-1.0, 1.0) to [0, 255], spread from (0.0, 1.0) to [0, 255].
  • ApexOffset is a scalar value representing a conservative offset for the apex of the normal cone from the bounding sphere center in the direction of the negative normal axis, apex = 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();

auto pos = std::make_unique<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);

std::vector<CullData> cull;
cull.resize(meshlets.size());

if ( FAILED( ComputeCullData(g_fmCubeVerts, 24,
    meshlets.data(), meshlets.size(),
    uniqueVertexIndices, vertIndices,
    primitiveIndices.data(), primitiveIndices.size(), cull.data()) )
    // Error