Esempio n. 1
0
    private static void DrawFlatLine(__VSOutputType__ v1, __VSOutputType__ v2)
    {
        if (v1.Position.Y > Canvas.Height || v1.Position.Y < 0)
        {
            return;
        }
        if (v1.Position.X > v2.Position.X)
        {
            Swap(ref v1, ref v2);
        }
        if (v1.Position.X > Canvas.Width || v2.Position.X < 0)
        {
            return;
        }
        float x0 = v1.Position.X;
        float x1 = v2.Position.X > Canvas.Width ? Canvas.Width : v2.Position.X;
        float dx = v2.Position.X - x0 + 0.01f;

        for (int i = (int)x0; i <= x1; i++)
        {
            float            t = (i - x0) / dx;
            __VSOutputType__ v = Lerp(v1, v2, t);
            v = MulOnePerZ(v);
            __FSOutputType__ o = Shader.__FragmentShaderName__(v);
            Canvas.SetPixel(i, (int)(v1.Position.Y + 0.5), o.Color, v1.Position.Z);
        }
    }
Esempio n. 2
0
    private static void DrawFlatLine(__VSOutputType__ v1, __VSOutputType__ v2, __ShaderName__ shader)
    {
        if (v1.Position.X > v2.Position.X)
        {
            Swap(ref v1, ref v2);
        }
        float x0 = v1.Position.X;
        float x1 = v2.Position.X;
        //if (x0 > x1) Swap(ref x0, ref x1);
        float dx = x1 - x0 + 0.01f;

        //Console.WriteLine($"dx: {dx}");
        for (int i = (int)x0; i <= x1; i++)
        {
            __FSOutputType__ o = shader.__FragmentShaderName__(Lerp(v1, v2, (i - x0) / dx));
            Canvas.SetPixel(i, (int)(v1.Position.Y /*+ 0.5f*/), o.Color);
        }
    }