我最近实施了体素锥跟踪算法,第一步是对多边形进行体素化...
我使用稀疏八叉树来转换多边形,除纹理映射外,一切都很好
mipmap = 6(64x64x64)
// 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);
回调功能......
struct Callback
{
void operator()(OctreeNode<uint8> *node, const Face &obj)
{
// Check if the node is already marked.
if(!node->data.value)
{
const glm::vec3 ¢er=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;
你可以看到...我直接平均了o,a,b的三个紫外线(可怕吧?)
当三角形大于网格时,它更不精确。
我是否需要使用基于栅格化的算法?
我的问题是:如何精确地为网格着色?