Пример #1
0
    private static void DrawTriangle(Vertex v1, Vertex v2, Vertex v3)
    {
        __ShaderName__ shader = new __ShaderName__();
        //调用顶点着色shader
        __CreateVSInputStruct1__
        __VSOutputType__ p1 = shader.__VertexShaderName__(vi1);
        __CreateVSInputStruct2__
        __VSOutputType__ p2 = shader.__VertexShaderName__(vi2);
        __CreateVSInputStruct3__
        __VSOutputType__ p3 = shader.__VertexShaderName__(vi3);

        p1 = ToScreen(p1);
        p2 = ToScreen(p2);
        p3 = ToScreen(p3);
        //Console.WriteLine($"{p1.Position} {p2.Position} {p3.Position}");
        //Console.WriteLine((p1.Position.Y - p2.Position.Y));
        //排序,并调用填充函数
        Sort(ref p1, ref p2, ref p3);
        if (p2.Position.Y == p3.Position.Y)
        {
            FillFlatTriangle(p1, p2, p3, shader, false);
        }
        else if (p1.Position.Y == p2.Position.Y)
        {
            FillFlatTriangle(p3, p1, p2, shader, true);
        }
        else
        {
            float            t  = (p2.Position.Y - p1.Position.Y) / (p3.Position.Y - p1.Position.Y);
            __VSOutputType__ p4 = Lerp(p1, p3, t);
            FillFlatTriangle(p1, p2, p4, shader, false);
            FillFlatTriangle(p3, p2, p4, shader, true);
        }
    }
Пример #2
0
    private static void DrawTriangle(Vertex v1, Vertex v2, Vertex v3)
    {
        //调用顶点着色shader
        __CreateVSInputStruct1__
        __VSOutputType__ p1 = Shader.__VertexShaderName__(vi1);
        __CreateVSInputStruct2__
        __VSOutputType__ p2 = Shader.__VertexShaderName__(vi2);
        __CreateVSInputStruct3__
        __VSOutputType__ p3 = Shader.__VertexShaderName__(vi3);

        //转换到屏幕坐标
        p1 = ToScreen(p1);
        p2 = ToScreen(p2);
        p3 = ToScreen(p3);

        //消除畸变
        p1 = MulOnePerZ(p1);
        p2 = MulOnePerZ(p2);
        p3 = MulOnePerZ(p3);

        //排序,并调用填充函数
        Sort(ref p1, ref p2, ref p3);
        if (p2.Position.Y == p3.Position.Y)
        {
            FillFlatTriangle(p1, p2, p3, false);
        }
        else if (p1.Position.Y == p2.Position.Y)
        {
            FillFlatTriangle(p3, p1, p2, true);
        }
        else
        {
            float            t  = (p2.Position.Y - p1.Position.Y) / (p3.Position.Y - p1.Position.Y);
            __VSOutputType__ p4 = Lerp(p1, p3, t);
            FillFlatTriangle(p1, p2, p4, false);
            FillFlatTriangle(p3, p2, p4, true);
        }
    }