我在大学完成了一项制作光栅器的任务,我通过制作自己的数学库和所有必要部件来实现这一目标,但结果并不完美
我已经测试过将颜色混合一点并且网格是整体的,没有空白区域,但我认为这是纹理的东西,可以有人暗示或告诉我如何获得一个清晰完整的纹理覆盖?
void Rasterizer::scanline(const Scanline &scan)
{
int diffX = scan.xEnd - scan.xBegin;
if (diffX == 0)
{
return;
}
for (int x = scan.xBegin; x <= scan.xEnd; x++)
{
float u, v, w;
barycentric(vector2D(x, scan.Y), vector2D(vertexOne.vecOrigin[0],
vertexOne.vecOrigin[1]), vector2D(vertexTwo.vecOrigin[0],
vertexTwo.vecOrigin[1]), vector2D(vertexThree.vecOrigin[0],
vertexThree.vecOrigin[1]), u, v, w);
float corrW = (u * wOne + v * wTwo + w * wThree);
float zPixel = ((vertexOne.vecOrigin[2] * u) + (vertexTwo.vecOrigin[2] * v) + (vertexThree.vecOrigin[2] * w));
int index = (scan.Y * width + x);
if (index < 0 || index >= (width * height))
{
continue;
}
if (zDepth[index] > zPixel)
{
continue;
}
zDepth[index] = zPixel;
vector2D texture = ((uvOne * u) * wOne + (uvTwo * v) * wTwo + (uvThree * w) * wThree) / corrW;
vector3D normal = ((normOne * u) * wOne + (normTwo * v) * wTwo + (normThree * w) * wThree) / corrW;
vector3D diff = ((diffColorOne * u) * wOne + (diffColorTwo * v) * wTwo + (diffColorThree * w) * wThree) / corrW;
PixelColor col = fragments({ texture.vecOrigin[0], 1 - texture.vecOrigin[1] }, normal, image, this->w, this->h, n);
col.r = std::min((col.r * diff.vecOrigin[0]), 255.0f);
col.g = std::min((col.g * diff.vecOrigin[1]), 255.0f);
col.b = std::min((col.b * diff.vecOrigin[2]), 255.0f);
if ((scan.Y * width + x) < 0)
{
continue;
}
else if ((scan.Y * width + x) >= width * height)
{
continue;
}
if (x > 0 && x < width)
{
this->pixels[index] = col;
}
}
}