Precise texture mapping for polygon voxelization

I recently implemented a voxel cone tracking algorithm, the first step is voxelize polygons ...

I use sparse octree to convert the polygon, everything was fine except for the texture display

mipmap = 6 (64x64x64) enter image description here

// We find its smallest AABB
AABB aabb = FindAABB(in);
// better aabb with same width, height and depth
AABB betterAABB = FixAABB(aabb);
// Create Octree and marked the grids that are touched by triangles in the mesh
// dfunc is a callable object which return true when triangle and grid are overlapped
// cb is a callable object, it is called when octree reaches its leaf..
Octree<uint8> tree(betterAABB, mipmap);
for(auto &f: in.faces)
    tree.findTouchedLeaves(f, dfunc, cb);

Callback Function ...

struct Callback
{
    void operator()(OctreeNode<uint8> *node, const Face &obj)
    {
        // Check if the node is already marked.
        if(!node->data.value)
        {
            const glm::vec3 &center=node->aabb.getCenter();
            out.push_back(center);
            // Problem here!! how to calculate precise uv for texture mapping
            color.push_back(text->getPixel((obj.o.texCoord+obj.a.texCoord+obj.b.texCoord)/3.0f));
        }
        node->data.value=1;
    }

    std::vector<glm::vec3> out;
    std::vector<glm::vec4> color;
    const ImageTexture *text;
} cb;

as you can see ... I am directly averaging the three UVs o, a, b. (terribly right?) This is more inaccurate when the triangle is larger than the grid. enter image description here Should I use a rasterization based algorithm?

My question is: how to color the grid exactly?

+4
source share

All Articles