人脸处理功能中最接近纹理的实现问题

问题描述

我一直在从事一些项目,并尝试实现与我的FaceProssesing功能最接近的功能纹理。 我已经用所有的灯光(phong,Gourard,flat)和脸部颜色进行了照明。 代码

void FaceProcessing(Vertex* v1,Vertex* v2,Vertex* v3,GLfloat FaceColor[3])
{
    V4HomogeneousDivide(v1->pointScreen);
    V4HomogeneousDivide(v2->pointScreen);
    V4HomogeneousDivide(v3->pointScreen);
    if (GlobalGuiParamsForYou.displayType == FACE_VERTEXES)
    {
        DrawLineBresenham(round(v1->pointScreen[0]),round(v1->pointScreen[1]),round(v2->pointScreen[0]),round(v2->pointScreen[1]),1,1);
        DrawLineBresenham(round(v2->pointScreen[0]),round(v3->pointScreen[0]),round(v3->pointScreen[1]),1);
        DrawLineBresenham(round(v3->pointScreen[0]),round(v1->pointScreen[0]),1);
    }
    else {
        GLfloat a1,a2,a3;
        GLfloat b1,b2,b3;
        GLfloat c1,c2,c3;
        GLfloat x1,y1,x2,y2,x3,y3;
        GLfloat pixelDepth,flat_shading_color,gourard_shading_color,phong_shading_color;
        GLfloat phong_position[3],phong_normal[3];
        GLfloat y_min,y_max,x_min,x_max;
        GLfloat alpha = 0,beta = 0,gamma = 0;
        x1 = round(v1->pointScreen[0]);
        y1 = round(v1->pointScreen[1]);
        x2 = round(v2->pointScreen[0]);
        y2 = round(v2->pointScreen[1]);
        x3 = round(v3->pointScreen[0]);
        y3 = round(v3->pointScreen[1]);
        y_min = getMinV3(v1->pointScreen[1],v2->pointScreen[1],v3->pointScreen[1]);
        y_max = getMaxV3(v1->pointScreen[1],v3->pointScreen[1]);
        x_min = getMinV3(v1->pointScreen[0],v2->pointScreen[0],v3->pointScreen[0]);
        x_max = getMaxV3(v1->pointScreen[0],v3->pointScreen[0]);
        a1 = y1 - y2;
        b1 = x2 - x1;
        c1 = (y2 * x1) - (y1 * x2);
        a2 = y2 - y3;
        b2 = x3 - x2;
        c2 = (y3 * x2) - (y2 * x3);
        a3 = y3 - y1;
        b3 = x1 - x3;
        c3 = (y1 * x3) - (y3 * x1);
        for (GLint x = x_min; x <= x_max && x >= 0; x++)
        {
            for (GLint y = y_min; y <= y_max && y >= 0; y++)
            {
                alpha = (a1 * x + b1 * y + c1) / (a1 * x3 + b1 * y3 + c1);
                beta = (a2 * x + b2 * y + c2) / (a2 * x1 + b2 * y1 + c2);
                gamma = (a3 * x + b3 * y + c3) / (a3 * x2 + b3 * y2 + c3);

                if ((alpha >= 0 && alpha <= 1) && (beta >= 0 && beta <= 1) && (gamma >= 0 && gamma <= 1))
                {
                    pixelDepth = (alpha * v3->pointScreen[2]) + (beta * v1->pointScreen[2]) + (gamma * v2->pointScreen[2]);
                    if (pixelDepth <= _Zbuffer[x][y])
                    {
                        _Zbuffer[x][y] = pixelDepth;
                        if (GlobalGuiParamsForYou.displayType == FACE_COLOR)
                        {
                            setPixel(x,y,FaceColor[0],FaceColor[1],FaceColor[2]);
                        }
                        else if (GlobalGuiParamsForYou.displayType == LIGHTING_FLAT)
                        {
                            flat_shading_color = (v1->PixelValue + v2->PixelValue + v3->PixelValue) / 3.0;
                            setPixel(x,flat_shading_color);
                        }
                        else if (GlobalGuiParamsForYou.displayType == LIGHTING_GOURARD)
                        {
                            gourard_shading_color = (alpha * v3->PixelValue) + (beta * v1->PixelValue) + (gamma * v2->PixelValue);
                            setPixel(x,gourard_shading_color);
                        }
                        else if (GlobalGuiParamsForYou.displayType == LIGHTING_phong)
                        {
                            for (int i = 0; i < 3; i++)
                            {
                                phong_position[i] = (alpha * v3->point3DeyeCoordinates[i]) + (beta * v1->point3DeyeCoordinates[i]) + (gamma * v2->point3DeyeCoordinates[i]);
                                phong_normal[i] = (alpha * v3->normalEyeCoordinates[i]) + (beta * v1->normalEyeCoordinates[i]) + (gamma * v2->normalEyeCoordinates[i]);
                            }
                            phong_shading_color = LightingEquation(phong_position,phong_normal,GlobalGuiParamsForYou.LightPosition,GlobalGuiParamsForYou.Lighting_Diffuse,GlobalGuiParamsForYou.Lighting_specular,GlobalGuiParamsForYou.Lighting_Ambient,GlobalGuiParamsForYou.Lighting_sHininess);
                            setPixel(x,phong_shading_color,phong_shading_color);
                        }
                        else if (GlobalGuiParamsForYou.displayType == TEXTURE_NEAREST)
                        { 

                        }

如您所见,我已经实现了其中的大多数,但是我找不到有关如何找到最接近其当前要采样的纹理坐标的单个像素的像素颜色的任何信息。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)