English 中文(简体)
Bézier curves, Loop和Blinn风格
原标题:Bézier curves, Loop and Blinn style

几天前,我开始寻找高效的带子曲线,我走过了由查尔斯·洛普和希姆·布林恩制定的一种似乎非常有趣的方法。 在对其算法进行了大量试验之后,我似乎无法让它能够使立方位曲线。 罚款,没有问题。

我迄今发现的唯一资源如下:

GPU Gems 3 Chapter 25

Curvy Blues

Resolution Independent Curve Rendering using Programmablegraphics soil

为了迅速进行测试,Im在XNA中这样做。 基本上,Im 顺差与我对万国邮联的vert相坐标,适用一种观点,改变和使用所有条款中提到的公式,使最终结果达到最终结果。 问题(我认为)如何在我计算正文坐标时出现。 检查该法典:

public void Update()
{
    float a1 = Vector3.Dot(p1, Vector3.Cross(p4, p3));
    float a2 = Vector3.Dot(p2, Vector3.Cross(p1, p4));
    float a3 = Vector3.Dot(p3, Vector3.Cross(p2, p2));

    float d1 = a1 - 2 * a2 + 3 * a3;
    float d2 = -a2 + 3 * a3;
    float d3 = 3 * a3;

    float discr = d1 * d1 * (3 * d2 * d2 - 4 * d1 * d3);

    if (discr > 0)
    {
        Type = CurveTypes.Serpentine;

        float ls = 3 * d2 - (float)Math.Sqrt(9 * d2 * d2 - 12 * d1 * d3);
        float lt = 6 * d1;
        float ms = 3 * d2 + (float)Math.Sqrt(9 * d2 * d2 - 12 * d1 * d3);
        float mt = 6 * d1;

        TexCoord1 = new Vector3(ls * ms, (float)Math.Pow(ls, 3), (float)Math.Pow(ms, 3));
        TexCoord2 = new Vector3((3 * ls * ms - ls * mt - lt * ms) / 3, ls * ls * (ls - lt), ms * ms * (ms - mt));
        TexCoord3 = new Vector3((lt * (mt - 2 * ms) + ls * (3 * ms - 2 * mt)) / 3, (float)Math.Pow(lt - ls, 2) * ls, (float)Math.Pow(mt - ms, 2) * ms);
        TexCoord4 = new Vector3((lt - ls) * (mt - ms), -(float)Math.Pow(lt - ls, 3), -(float)Math.Pow(mt - ms, 3));
    }
    else if (discr == 0)
    {
        Type = CurveTypes.Cusp;
    }
    else if (discr < 0)
    {
        Type = CurveTypes.Loop;
    }
}

它只使用肉类,只是一些测试法。 页: 1 这是对万国邮联Gems的文章的复制。

这里存在几个问题,首先是在计算一个3时,我们使用两个参数的2页,这当然总是产生一种(0,0)病媒,并且把这一和第3页的直观产品带给我们。 那么,他们为什么在该条中提及这一点?

This will of course make discr incorrect, and we won t even be able to determine what type of curve it is.

在绕过该法典一段时间之后,我决定尽力在Loop和Blinn文件中说明为什么这样做。 从那以后,我就取得了这样的成就:

public void Update()
{
    Matrix m1 = new Matrix(
        p4.X, p4.Y, 1, 0,
        p3.X, p3.Y, 1, 0,
        p2.X, p2.Y, 1, 0,
        0, 0, 0, 1);
    Matrix m2 = new Matrix(
        p4.X, p4.Y, 1, 0,
        p3.X, p3.Y, 1, 0,
        p1.X, p1.Y, 1, 0,
        0, 0, 0, 1);
    Matrix m3 = new Matrix(
        p4.X, p4.Y, 1, 0,
        p2.X, p2.Y, 1, 0,
        p1.X, p1.Y, 1, 0,
        0, 0, 0, 1);
    Matrix m4 = new Matrix(
        p3.X, p3.Y, 1, 0,
        p2.X, p2.Y, 1, 0,
        p1.X, p1.Y, 1, 0,
        0, 0, 0, 1);

    float det1 = m1.Determinant();
    float det2 = -m2.Determinant();
    float det3 = m3.Determinant();
    float det4 = -m4.Determinant();

    float tet1 = det1 * det3 - det2 * det2;
    float tet2 = det2 * det3 - det1 * det4;
    float tet3 = det2 * det4 - det3 * det3;

    float discr = 4 * tet1 * tet3 - tet2 * tet2;

    if (discr > 0)
    {
        Type = CurveTypes.Serpentine;

        float ls = 2 * det2;
        float lt = det3 + (float)((1 / Math.Sqrt(3)) * Math.Sqrt(3 * det3 * det3 - 4 * det2 * det4));
        float ms = 2 * det2;
        float mt = det3 - (float)((1 / Math.Sqrt(3)) * Math.Sqrt(3 * det3 * det3 - 4 * det2 * det4));

        TexCoord1 = new Vector3(lt * mt, (float)Math.Pow(lt, 3), (float)Math.Pow(mt, 3));
        TexCoord2 = new Vector3(-ms * lt - ls * mt, -3 * ls * lt * lt, -3 * ms * mt * mt);
        TexCoord3 = new Vector3(ls * ms, 3 * ls * ls * lt, 3 * ms * ms * mt);
        TexCoord4 = new Vector3(0, -ls * ls * ls, -ms * ms * ms);
    }
    else if (discr == 0)
    {
        Type = CurveTypes.Cusp;
    }
    else if (discr < 0)
    {
        Type = CurveTypes.Loop;
    }
}

Guess what, that didn t work either. How ever, discr seem to be at least a little more correct now. At least it has the right sign, and it is zero when the control points are arranged to form a cusp. I still get the same visual result though, except the curve disappears randomly for a while (the pixel shader formula is always greater than zero) and returns after I move the control point back to more of a square shape. Here is the pixel shader code by the way:

 PixelToFrame PixelShader(VertexToPixel PSIn)
 {
     PixelToFrame Output = (PixelToFrame)0;

     if(pow(PSIn.TexCoords.x, 3) - PSIn.TexCoords.y * PSIn.TexCoords.z > 0)
     {
     Output.Color = float4(0,0,0,0.1);
     }
     else
     {
     Output.Color = float4(0,1,0,1);
     }

    return Output;
}

这就是我认为现在能够正确掌握的所有有用信息。 是否有任何想法? 由于我已经离开了他们。

最佳回答

我正在研究该文件和你的法典,你把多彩的复制品重新 missing到M3矩阵中。

Your p1, p2, p3 and p4 coordinates should be placed in a matrix and multiplied by the M3 matrix, before using it to calculate the determinants. eg.

Matrix M3 = Matrix(
    1, 0, 0, 0,
    -3, 3, 0, 0,
    3, -6, 3, 0,
    -1, 3, -3, 1);
Matrix B = Matrix(
    p1.X, p1.Y, 0, 1,
    p2.X, p2.Y, 0, 1,
    p3.X, p3.Y, 0, 1,
    p4.X, p4.Y, 0, 1);
Matrix C = M3*B;

然后,你将C类矩阵的每一行作为你代码中1至4级矩阵的坐标。 如果输电的第一和第二数值为x,y坐标,最后是轮值。

Finally the matrix of texture coordinates needs to be mutiplied by the inverse of M3 eg.

Matrix invM3 = Matrix(
    1, 0, 0, 0,
    1, 0.3333333, 0, 0,
    1, 0.6666667, 0.333333, 0,
    1, 1, 1, 1);
Matrix F = Matrix(
    TexCoord1,
    TexCoord2,
    TexCoord3,
    TexCoord4);
Matrix result = invM3*F;

由此产生的矩阵的每行均符合梯子所需的文字坐标。

我尚未执行,因此不能保证它将解决你的问题。 我在阅读该文件之后就注意到,这完全是你在执行过程中所没有的。

我希望这一帮助,如果我错听我的话,我会很快尝试这样做。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签