-
Notifications
You must be signed in to change notification settings - Fork 152
ComputeCullData
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);
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.
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
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
All content and source code for this package are subject to the terms of the MIT License.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
- Universal Windows Platform apps
- Windows desktop apps
- Windows 11
- Windows 10
- Windows 8.1
- Xbox One
- Xbox Series X|S
- Windows Subsystem for Linux
- x86
- x64
- ARM64
- 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
DirectX Tool Kit for DirectX 11