Академический Документы
Профессиональный Документы
Культура Документы
5/2/07
Dongsoo Han
University of Pennsylvania
PROJECT ABSTRACT
NURBS(Non Uniform Rational B-Splines) are nearly ubiquitous for computer-aided design (CAD),
manufacturing (CAM), and 3D modelers and part of numerous industry wide 3D data exchange standards
such as IGES and STEP. With a rapidly growing hardware system, NURBS is getting more attentions in
real-time systems or 3D games. In this new trend, the biggest obstacle is that tessellating NURBS into
triangles is still slower than loading pre-triangulated data.
However NURBS can give lots of freedom to 3D application developers such as unlimited control over
LOD (Level of Detail) or high rendering quality to the curved surface.
In this project, geometry shader is used to tessellate and render curves and surfaces. The benefits of
using geometry shader are to reduce the rendering data transferring from CPU to GPU as well as
tessellate and render curves and surfaces as a parallel process.
1. INTROUDUCTION
1.1. Technology
A geometry shader can generate new primitives from existing primitives like pixels, lines and triangles. It
is executed after vertex shader and its input is the whole primitive or primitive with adjacency information.
Then it can emit zero or more primitives, which are rasterized and their fragments passed to fragment
shader.
With the input of control vertices and other information such as number of input control vertices, geometry
shader can generate line or triangle primitives to render Bezier, B-Spline or NURBS curves and surfaces.
1.2.2 Software
1. Operating System: Window XP
2. Programming Tool: Visual Studio 2005 Professional
1
3. Programming Language: C/C++, Cg 2.0 (beta)
4. Major Programming Library: MFC (User Interface), Win32 API, OpenGL/GLU
5. 3rd Party Programming Library: N/A
2. PROJECT DEVELOPMENT
Equation 1
Equation 2
Degree three Bezier curve is most common and can be represented as below. It is usually called
Cubic Bezier curve.
Equation 3
2
⎡ −1 3 −3 1 ⎤ ⎡t 3 ⎤
⎡ p0 x p3 x ⎤ ⎢ ⎢ ⎥
0 ⎥⎥ ⎢t 2 ⎥
p1x p2 x
⎢ 3 −6 3
B(t ) = ⎢ p0 y p1 y p2 y p3 y ⎥⎥ ⎢
⎢ −3 3 0 0⎥ ⎢ t ⎥
⎣⎢ p0 z p1z p2 z p3 z ⎦⎥ ⎢ ⎥⎢ ⎥
⎣1 0 0 0⎦ ⎣ 1 ⎦
Equation 4
In this project matrix form was used since we can take advantage of matrix vector multiplication
inside GPU. Below is the screenshot that shows Bezier curve generated by geometry shader.
Figure 1
n
X (t ) = ∑P B
k =0
k k ,d (t )
Equation 5
3
⎧1 tk ≤ t ≤ tk +1
Bk ,1 ( t ) = ⎨
⎩0 otherwise
⎛ t − tk ⎞ ⎛ tk +d − t ⎞
Bk ,d ( t ) = ⎜ ⎟ Bk ,d −1 ( t ) + ⎜ ⎟ Bk +1,d −1 ( t )
⎝ tk + d −1 − tk ⎠ ⎝ tk + d − tk +1 ⎠
Equation 6
Particularly, degree three uniform B-Spline curve can be represented as matrix form as below.
⎡ −1 3 −3 1⎤ ⎡t 3 ⎤
⎢ ⎥⎢ ⎥
1 3 −6 0 4 ⎥ ⎢t 2 ⎥
x (t ) = ⎡P0 P1 P2 P3 ⎤⎦ ⎢
6⎣ ⎢ −3 3 3 1⎥ ⎢ t ⎥
⎢ ⎥⎢ ⎥
⎣1 0 0 0 ⎦ ⎢⎣ 1 ⎥⎦
Equation 7
In this project, matrix form was used to tessellate and render unform B-Spline curves and
surfaces in geometry shader.
Figure 2
4
2.1.3 What is NURBS curve
NURBS stands for Non Uniform Rational B-Splines. NURBS curve can be evaluated using Cox-
de Boor algorithm (Equation 6). With weights associated to each control point, conic sections can
be created.
Equation 8
CPU GPU
Figure 3
5
Figure 3 explains that control vertices (points) are transferred to GPU (geometry shader) along with other
uniform information such as number of cv or LOD(Level of Detail) value. The output of geometry shader is
either lines or triangles corresponding to curves and surfaces.
The nice thing of geometry shader is that it can control LOD automatically based on the distance between
camera (eye) position to the object (curve or surface). Figure 5 is B-Spline surface geometry shader
program. In Figure 6, 7 and 8, red surface is tessellated by CPU and triangle list is transferred to GPU.
On the other hand yellow surface is done by GPU. Figure 6, 7 and 8 shows different LODs which are
automatically done by geometry shader.
Figure 4
There are two projects in visual studio 2005. To compare implementation in CPU vs. GPU, Brep project
contains curve and surface CPU implementations. Cg folder in GLModeler project contains geometry
shader codes. GLModeler project also contains user interface and interaction implementations.
LINE_ADJ
TRIANGLE_OUT
void bspline_surface_txtr_gp(
AttribArray<float4> pos : POSITION,
AttribArray<float4> color : COLOR0,
uniform float4x4 modelViewProj : state.matrix.mvp,
uniform float4x4 inverseMVP :
state.matrix.mvp.inverse,
uniform int segments = 10,
6
float4 newPt = mul(inverseMVP, pos[0]);
int v = round(newPt.x);
float4 cv[4];
float4 cv1[4];
float step = 1;
if ( segments < 2 )
segments = 2;
else if ( segments > 13 )
segments = 13;
7
float4 b = mul(bSplineBasis, tvec);
float4 p = cv[0]*b.x + cv[1]*b.y + cv[2]*b.z + cv[3]*b.w;
float4 p1 = cv1[0]*b.x + cv1[1]*b.y + cv1[2]*b.z + cv1[3]*b.w;
Figure 5
To render a full surface, each geometry shader renders only one strip. If there are mutiple strips to
tessellate and render, geometry shaders work as a parallel process and it can achieve a big performance
increase.
Figure 6
8
Figure 7
Figure 8
9
3. Conclusion
Using geometry shader to tessellate and render Bezier/B-Spline/Nurbs curves and surfaces has three
benifits:
1. The volume of transferring data to GPU is much less than using triangles. Also it is independent to the
LOD (Level of Detail). Therefore without suffering from limited bandwidth, high quality curves and
surfaces can be displayed.
4. REFERENCES
SAMUEL R. BUSS
University of California, San Diego
3-D Computer Graphics A Mathematical Introduction with OpenGL
Hans-Friedrich Pabst, Jan P. Springer, Andr´e Schollmeyer, Robert Lenhardt, Christian Lessig, Bernd
Fr¨ohlich
http://www.sci.utah.edu/~wald/RT06/papers/hanspabst.pdf
10
Thomas W. Sederberg
An Introduction to B-Spline Curves
Brian A. Barsky
Berkeley Computer Graphics Laboratory
A STUDY OF PARAMETRIC UNIFORM B-SPLINE CURVE AND SURFACE REPRESENTATIONS
Christopher K. Ingram
University of Waterloo
A Geometric B-Spline Over the Triangular Domain
Ronen Barzel
University of California, San Diego
Introduction to Computer Graphics Lecture Notes
http://graphics.ucsd.edu/courses/cse167_w06/
Jared Hoberock
Geometry Shader Hello World
https://agora.cs.uiuc.edu/display/graphics/Geometry+Shader+Hello+World
Denis Zorin
Computer Graphics Lecture Notes
http://mrl.nyu.edu/~dzorin/geom04/
NVidia
GeForce 8800 OpenGL Extensions
5. CREDITES
11