问题描述
我知道我可以使用重心函数来内插三元组顶点的深度,但我不知道如何访问该内插值,因为该函数返回一个向量。
我还没有完全优化代码,因为我想在优化之前完全理解这个过程——用 C++ 编写它,呵呵)。
编辑:我认为插值深度只是 depth = v.x*tri.verts[0].z + v.y*tri.verts[1].z + v.z*tri.verts[2].z
。但是现在当我运行程序时,并不是所有应该被遮挡的像素都被遮挡了。它看起来像一个低样本透明度效果。
//for each pixel in tri's bounding Box
for (int x = minx; x <= maxx; x++)
{
for (int y = miny; y <= maxy; y++)
{
// the pixel coordinate in linear space
int coord = (int)(x+y*screenWidth);
// Barycentric function with output weight
Ops.computeBarycentricCoordinates(tri.verts[0],tri.verts[1],tri.verts[2],new Vec3D(x,y,1),weight);
weight.normalize(); // Do i even need this?
// if the triangle contains the pixel
if(weight.x>=0 && weight.y>0 && weight.z>=0)
{
float depth = weight.x * tri.verts[0].z + weight.y * tri.verts[1].z + weight.z * tri.verts[2].z;
if(depth<zbuffer[coord])
{
zbuffer[coord] = depth;
int rgb = (int)((depth/2)*255);
screenPixels[coord] = new Color(rgb,rgb,rgb).getRGB();
}
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)