|
| 1 | +Implement Manifold Dual Contouring (MDC) in OpenCL with the following requirements: |
| 2 | + |
| 3 | +1. **Input**: |
| 4 | + - A 3D grid of cells representing an implicit surface (Signed Distance Field). |
| 5 | + - Hermite data: intersection points and normals for edges crossing the surface. |
| 6 | + |
| 7 | +2. **Steps**: |
| 8 | + - **Kernel 1 (QEF Solve)**: |
| 9 | + - For each cell, gather Hermite samples. |
| 10 | + - Compute Quadratic Error Function (QEF) to find optimal vertex position. |
| 11 | + - Detect ambiguous topology (e.g., more than 4 samples or complex sign changes). |
| 12 | + - Output: |
| 13 | + - `baseVertices[cellId]` (float4) |
| 14 | + - `splitFlags[cellId]` (int: number of extra vertices needed) |
| 15 | + |
| 16 | + - **Prefix Sum (Blelloch Scan)**: |
| 17 | + - Implement an exclusive prefix sum on `splitFlags` to compute `vertexOffsets`. |
| 18 | + - This determines where each thread writes its duplicate vertices in the global buffer. |
| 19 | + |
| 20 | + - **Kernel 2 (Vertex Emission)**: |
| 21 | + - Write primary vertex to `outVertices[cellId]`. |
| 22 | + - If `splitFlags[cellId] > 0`, emit duplicates at positions: |
| 23 | + `outVertices[vertexOffsets[cellId] + i]` for `i` in [0, splitFlags[cellId]-1]. |
| 24 | + - Apply small offsets to duplicates to maintain manifoldness. |
| 25 | + |
| 26 | + - **Kernel 3 (Face Emission)**: |
| 27 | + - Build faces referencing correct vertex IDs (including duplicates). |
| 28 | + - Ensure manifold connectivity (each edge belongs to exactly two faces). |
| 29 | + |
| 30 | +3. **Blelloch Scan Details**: |
| 31 | + - Implement upsweep and downsweep phases for prefix sum in OpenCL. |
| 32 | + - Use local memory for block-level scan and global memory for inter-block aggregation. |
| 33 | + |
| 34 | +4. **Output**: |
| 35 | + - A watertight, manifold mesh with vertices and faces stored in global buffers. |
| 36 | + |
| 37 | +5. **Performance Considerations**: |
| 38 | + - Use work-groups for scan operations. |
| 39 | + - Avoid race conditions with atomic operations or prefix sums. |
| 40 | + - Optimize QEF solver using small matrix inversion or SVD. |
| 41 | + |
| 42 | +Provide: |
| 43 | +- Full OpenCL kernels for QEF pass, Blelloch scan, vertex emission, and face emission. |
| 44 | +- Host-side code to orchestrate kernel launches and buffer allocations. |
| 45 | +- Comments explaining each step. |
0 commit comments