• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
cephalo

Bezier Triangles

5 posts in this topic

Original post-------------------------------

I was reading up about Bezier triangles in the hopes of running some experiments, but my understanding of math terminology is not keeping up. According to this article:

[url="http://www.gamasutra.com/view/feature/131389/b%C3%A9zier_triangles_and_npatches.php?print=1"]http://www.gamasutra.com/view/feature/131389/b%C3%A9zier_triangles_and_npatches.php?print=1[/url]

 

You can interpolate positions on a triangular surface with some number of control points with this formula

 

You can also determine the tangent frame at that point with the two partial derivatives:

 

The problem I am having is that I just can't figure out how to write this out in long form. The sigma operator always defeats any chance I have of math comprehension. I have seen 3rd order triangles written out in the case of PN-triangles etc. but I can't make out the pattern of iteration enough to expand it to higher orders. I don't even understand how and why the big 'B' is different than the bold 'p'. My experiment is going to be using a 6th order Bezier triangle (7 control points on each side) So if I have all the 28 control points set and I want to know the position at the barycentric coords p(u,v) how to I calculate that with code? I need the same help with the two partial derivatives as well.

-------------------------------------------------

 

Ok, here are the results that I calculated. Hopefully there aren't too many mistakes. First I will calculate w so that the patterns can be more easily seen for calculating the position at (u,v):

w = 1 - u - v;

p(u,v) =
	p600 * u^6 +
	p060 * v^6 +
	p006 * w^6 +
	p501 * 6 * u^5 * w +
	p510 * 6 * u^5 * v +
	p150 * 6 * u * v^5 +
	p051 * 6 * v^5 * w +
	p105 * 6 * u * w^5 +
	p015 * 6 * v * w^5 +
	p402 * 15 * u^4 * w^2 +
	p411 * 30 * u^4 * v * w +
	p420 * 15 * u^4 * w^2 +
	p240 * 15 * u^2 * v^4 +
	p141 * 30 * u * v^4 * w +
	p042 * 15 * v^4 * w^2 +
	p024 * 15 * v^2 * w^4 +
	p114 * 30 * u * v * w^4 +
	p204 * 15 * u^2 * w^4 +
	p303 * 20 * u^3 * w^3 +
	p312 * 60 * u^3 * v * w^2 +
	p321 * 60 * u^3 * v^2 * w +
	p330 * 20 * u^3 * v^3 +
	p231 * 60 * u^2 * v^3 * w +
	p132 * 60 * u * v^3 * w^2 +
	p033 * 20 * v^3 * w^3 +
	p213 * 60 * u^2 * v * w^3 +
	p123 * 60 * u * v^2 * w^3 + 
	p222 * 90 * u^2 * v^2 * w^2;

 

Now for the partial derivatives. This is a little more complicated to understand, because you calculate these with a subset of control points that is basically a bezier triangle at an order that is one smaller, such that you are leaving off the opposite edge of the original triangle. Mapping this smaller triangle onto the original control points looks a bit strange, hopefully I did it correctly:


partial derivative for u
dp(u,v)/du =
	p600 * u^5 +
	p501 * 5 * u^4 * w +
	p510 * 5 * u^4 * v +
	p402 * 10 * u^3 * w^2 + 
	p411 * 20 * u^3 * v * w +
	p420 * 10 * u^3 * v^2 +
	p303 * 10 * u^2 * w^3 + 
	p312 * 30 * u^2 * v * w^2 +
	p321 * 30 * u^2 * v^2 * w +
	p330 * 10 * u^2 * v^3 +
	p204 * 5 * u * w^4 +
	p213 * 20 * u * v * w^3 +
	p222 * 30 * u * v^2 * w^2 +
	p231 * 20 * u * v^3 * w +
	p240 * 5 * u * v^4 +
	p105 * w^5 +
	p114 * 5 * v * w^4 +
	p123 * 10 * v^2 * w^3 +
	p132 * 10 * v^3 * w^2 +
	p141 * 5 * v^4 * w +
	p150 * v^5;

partial derivative for v
dp(u,v)/dv =
	p060 * v^5 +
	p150 * 5 * u * v^4 +
	p051 * 5 * v^4 * w +
	p240 * 10 * u^2 * v^3 +
	p141 * 20 * u * v^3 * w +
	p042 * 10 * v^3 * w^2 +
	p330 * 10 * u^3 * v^2 +
	p231 * 30 * u^2 * v^2 * w +
	p132 * 30 * u * v^2 * w^2 +
	p033 * 10 * v^2 * w^3 +
	p420 * 5 * u^4 * v +
	p321 * 20 * u^3 * v * w +
	p222 * 30 * u^2 * v * w^2 +
	p123 * 20 * u * v * w^3 +
	p024 * 5 * v * w^4 +
	p510 * u^5 +
	p411 * 5 * u^4 * w +
	p312 * 10 * u^3 * w^2 +
	p213 * 10 * u^2 * w^3 +
	p114 * 5 * u * w^4 +
	p015 * w^5; 

 

I would guess if you were going to use these tangents for a tangent frame in a shader, you might have to fiddle with them a bit since they are calculated from barycentric coordinates and are probably not perpendicular on the plane. Perhaps you could calculate the normal, then create a new bitangent from the normal and tangent, and then rotate it to your texture edge somehow.

 

0

Share this post


Link to post
Share on other sites


First of all, the bold vs. not bold: Anything bold is a point, anything not bold is a number. So when you see p(u, v), it means the Point at the barycentric coordinates u, v.

 

Secondly, the sigma notation used in the article means "sum together all of the values where this equation is true." So, for example, the equation i+j+k=n could be true when 1+0+6=7 or when 0+3+4=7, and so on. 

 

Let's look at the first equation you have posted:

 

When determining how to create the loops, I found the picture of the triangle very helpful. Lets assume that each digit in the point corresponds to the variables i, j, and k in order. Thus, the lower left point of the triangle p003 means i=0, j=0, and k=3. 

 

The first thing that I notice is that i increases from 0 to 3 from bottom to top of the image. This is a basic for loop that we can easily handle.

 

Next, I notice that for any i, the j value starts at 0 on the left and increases until i+j=n on the right. This is another loop we can handle.

 

Finally, the original equation gives us k via algebra: i+j+k=n can be rearranged to k = n - (i+j). That is the final value we need to know.

 

This gives us our final form:

Point p;
for (int i = 0; i <= n; ++i) {
    for (int j = 0; i+j <= n; ++j) {
        int k = n - (i + j);
        p += B(i, j, k, u, v, n) * p(i, j, k); //Probably not quite what you want here, but this is an example of what this might look like.
    }
}

 

Now, the B() function refers to the function on the Gamasutra page and the p function here means "give me the point with i, j, k index." For example, p(0, 6, 1) means p061. 

 

Does this help? The partial derivatives would then be created in a very similar way.

1

Share this post


Link to post
Share on other sites

Thanks for the help! That gives me a bit more confidence in figuring it out. I need to better understand the big 'B' I think. The examples I've seen with the 3 order PN-Triangles seem a lot simpler than that crazy 'B' formula. There must be a way to simplify it. For example, check this out.

 

eq1s-a.gif

I guess that B number also has a i,j,k index, I guess that is what is creating the decreasing exponent on these terms... somehow. How do you know which exponent goes with which point?

Edited by cephalo
0

Share this post


Link to post
Share on other sites

Thanks for the help! That gives me a bit more confidence in figuring it out. I need to better understand the big 'B' I think. The examples I've seen with the 3 order PN-Triangles seem a lot simpler than that crazy 'B' formula. There must be a way to simplify it. For example, check this out.

 

eq1s-a.gif

I guess that B number also has a i,j,k index, I guess that is what is creating the decreasing exponent on these terms... somehow. How do you know which exponent goes with which point?

 

The first thing to understand is that B (a bernstein polynomial) determines how much each point contributes to the final p(u, v) point. The value it returns is between 0 and 1, with 0 meaning that the point won't affect the final output and 1 meaning that it completely determines the output.

 

The "simplified" equation you give is just that... a simplified version of B when n = 3. You can do the math yourself if you want to take the time. Just take the equation for B, make n always 3, and compute the result for every valid i, j, k combination. Then with a bit of algebraic manipulation you could get the same equation. But the way this equation is written is only true for n=3. Breaking down the case of seven control points into a single equation is going to be too unwieldy. Instead, I would suggest trying to understand how to use:

beq3.gif

which works for any n, before trying to simplify it.

 

Let's look at how this will be used:

 

Let's say that we have a triangle patch with n = 5 and are trying to determine how much point p301 will contribute to the output point at (u,v). We would use the "big B" to determine this. B of 3,1,1 at u,v. The equation would be:

 

( 5! / (3! * 1! * 1!) )   * (ui) * (vj) * (1 - u - v)k =

(5*4 *3*2*1) / (3 * 2 * 1 * 1 * 1)  * u3 * v * (1 - u -v) =

20*(u3) * v * (1 - u - v)

 

This means that when u = 0.1 and v = 0.5), the point p301 would contribute to the point:

20*(0.001) *0.1 * 1 * (1 - 0.1 - 0.5) =

20*(0.0001)*(0.4) =

0.0008

 

Then back in the for-loop I had talked about before, p(3, 0, 1) would be multiplied by 0.0008 and added to the output point.

 

Note that B can be created as a function in code somewhat easily once you have a factorial function (something that can also be created easily) and a power function (should be available in your favorite programming language's standard library). All that it needs to do is take in multiple parameters (n, u, v, i, j, and k) and output a double value.

 

...well, that was a long explanation. I probably got something in there wrong :)

Let me know if something needs to be clarified.

1

Share this post


Link to post
Share on other sites

Wow, thanks. I completely understand now. Once you know your n and that its not going to change, all that stuff can be pre-calculated. As soon as I have time I'm going to post my results here for future reference.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0