• 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
mrhyperpenguin

B-Spline Surface Normal

4 posts in this topic

I'm trying to compute the analytic normals for a B-Spline surface. I know the normal is the cross product of the partial derivatives of the surface but I'm not sure if I'm taking the partial derivatives correctly.

 

atzr9Ca.png

 

Since a B-Spline surface is just the sum of the basis functions in each direction multiplied by the control points (2), I should just be able to take the derivative of each term and add them up (3), correct?

 

I'm getting the derivative of the basis function from [0].

 

What about the control points? Are they constant with respect to u and v? How do I take their derivative?

 

Thanks,

Victor

 

[0] - http://members.gamedev.net/skyork/pdfs/Bspline_Construction_Summary2005.pdf

0

Share this post


Link to post
Share on other sites

Mathematically you are correct, but the terminology is wrong.

There is a difference between Bézier curves and B-splines (both 2D).

And their higher dimensional counterparts Bézier surfaces and NURBS (both 3D).

A B-spline is made of multiple weighted bezier curves, broadly speaking.

 

But the equations you have there seem like they belong to a Bézier surface not a B-Spline surface (or NURBS).

Their derivatives can be calculated with different approaches. I think using De Casteljau's algorithm is a easy one.

For example, exactly calculating the derivative in the direction of u:

float s = 1.0-u, t = 1.0-v;
Vector3 points[4];

for(unsigned int i = 0; i < 4; i ++) {
    unsigned int i4 = i+4, i8 = i+8;
    Vector3   a = controlPoints[i ]*t+controlPoints[i4]*v,
              b = controlPoints[i4]*t+controlPoints[i8]*v,
              c = controlPoints[i8]*t+controlPoints[i+12]*v,
              d = a*v+b*t,
              e = b*v+c*t;
    points[i] = d*v+e*t;
}

points[0] = points[0]*s+points[1]*u;
points[1] = points[1]*s+points[2]*u;
points[2] = points[2]*s+points[3]*u;
points[0] = points[0]*s+points[1]*u;
points[1] = points[1]*s+points[2]*u;

return (points[1]-points[0])*3;

for the other derivative you would have to swap u and v and flip the order of the control points.

 

I'm preoccupied in this topic for a while now because I'm trying to write a Bézier surface raytracing algorithm.

What are you planing to use them for?

0

Share this post


Link to post
Share on other sites

I'm trying to compute the analytic normals for a B-Spline surface. I know the normal is the cross product of the partial derivatives of the surface but I'm not sure if I'm taking the partial derivatives correctly.

 

atzr9Ca.png

 

Since a B-Spline surface is just the sum of the basis functions in each direction multiplied by the control points (2), I should just be able to take the derivative of each term and add them up (3), correct?

 

I'm getting the derivative of the basis function from [0].

 

What about the control points? Are they constant with respect to u and v? How do I take their derivative?

 

Thanks,

Victor

 

[0] - http://members.gamedev.net/skyork/pdfs/Bspline_Construction_Summary2005.pdf

 

The control points aren't functions of u or v, so  you don't have to take derivatives of them. They're really just constants. You should be fine computing the derivative like you want. The tricky part is taking the derivatives of the B-spline basis functions. The functions themselves are built recursively, so the derivatives of a B-spline basis function of degree n can be formulated in terms of B-spline basis functions of degree n-1. This website should clarify:

 

http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/B-spline/bspline-derv.html

 

If you're interested in getting code snippets for B-splines, "The NURBS Book" by Piegl and Tiller is a great resource. I would also like to know what you're using B-splines for. I work with CAD surfaces a lot and it's good to see someone else interested in them too.

 

 

Mathematically you are correct, but the terminology is wrong.

There is a difference between Bézier curves and B-splines (both 2D).

And their higher dimensional counterparts Bézier surfaces and NURBS (both 3D).

A B-spline is made of multiple weighted bezier curves, broadly speaking.

 

But the equations you have there seem like they belong to a Bézier surface not a B-Spline surface (or NURBS).

Their derivatives can be calculated with different approaches. I think using De Casteljau's algorithm is a easy one.

The equations that OP posted are the equations for a B-spline surface as well as a Bezier surface. The only difference is which basis functions appear as the \(N_{i,p}(u)\) terms. If it's the Bernstein basis functions, the surface is Bezier; if it's B-spline basis functions, then it's a B-spline surface. Strictly speaking, the B-spline basis is a generalization of the Bernstein basis.

 

Bezier and B-spline curves can be 3D spatial curves, and thus could also be described as 4D rational curves as well. B-splines can be decomposed into Bezier curves via generalizations of the de Casteljau method, like the Cox-de Boor or Boehm algorithm, or also known as knot refinement.

 

You're right that the equations posted don't describe a rational surface. Those equations would look like this:

\[ S(u,v) = \frac{\sum_{i=0}^n \sum_{j=0}^m w_{ij} P_{ij} N_{i,p}(u) N_{j,q}(v)}{\sum_{i=0}^n \sum_{j=0}^m w_{ij} N_{i,p}(u) N_{j,q}(v)} \]

Edited by cadjunkie
0

Share this post


Link to post
Share on other sites

Thanks guys. With your help I have been able to compute what appears to be the correct normals (when compared to the central differences method.)

 

Mathematically you are correct, but the terminology is wrong.

 

I don't have too much background in these topics so it's completely possible I'm using the terminology wrong. But yes, I am dealing with B-spline surfaces. I'm just assuming that all the weights are one (for now).

 

The control points aren't functions of u or v, so  you don't have to take derivatives of them. They're really just constants. You should be fine computing the derivative like you want. The tricky part is taking the derivatives of the B-spline basis functions. The functions themselves are built recursively, so the derivatives of a B-spline basis function of degree n can be formulated in terms of B-spline basis functions of degree n-1. This website should clarify:

 

http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/B-spline/bspline-derv.html

 

Thanks for the clarification. It was actually the website you posted that initially confused me. Their definition for \(Q_i\) involves a difference in control points but I see now that that is from a simplification and not from the derivative.

 

I actually found the computation of the basis functions and their derivatives to be pretty simple. I just took a dynamic programming approach and computed the values from their definition directly. As long as you compute them from the "bottom up" and store the values as you go, the code is relatively simple and straight forward. Though, I haven't looked at the algorithms you guys posted, so maybe there are gains to be made somewhere.

 

I don't have a particular use case for B-spline surfaces in mind at the moment. I'm more experimenting with GPU tessellation and decided to use B-splines. Now I'm going to come up with an intelligent level of detail scheme and see how many I can render at once.

 

I would be interested in hearing what you guys are doing with them though.

 

Thanks again,

Victor

 

 

0

Share this post


Link to post
Share on other sites

That's good that you were able to figure it out. Doing the recursive algorithm to evaluate the B-spline basis functions isn't a bad way to go about it, but there are gains to take advantage of. For example, you can take advantage of the local support property to only calculate the nonzero B-spline basis functions and save yourself a bit of computation. Also, there are ways to do away with recursion when computing the B-spline basis functions.

 

I'm actually trying to write a complete trimmed B-spline visualization program so I'm actually very interested in your approach and your results. Post them if you get a chance.

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