Parametric surface visualization in Directx 11 and C++

Preview:

DESCRIPTION

This presentation shows how to visualize parametric surfaces in DirectX 11. It has been programmed in C++, and performs standard per-pixel lighting.

Citation preview

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Parametric surface visualization in DirectX 11 (C++)

Alejandro Cosin Ayerbe

August 2012

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Introduction

Description

Based on my final project in bachelor’s degree in Mathematics (aslideshare presentation can be seen here), which was programmed inMatlab.

A translation was made from Matlab to C++.

The goal is to represent interpolating and approximating parametricsurfaces (like NURBS surfaces) in DirectX 11 with an arc ball camera.

The data describing the surface being represented (degree of the surface,knot vectors and control points) is loaded through a text file. Then, agrid of surface points is generated based on the information loaded.

The surface is generated with this grid, making triangles in anappropriate way.

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Introduction

Description

Based on my final project in bachelor’s degree in Mathematics (aslideshare presentation can be seen here), which was programmed inMatlab.

A translation was made from Matlab to C++.

The goal is to represent interpolating and approximating parametricsurfaces (like NURBS surfaces) in DirectX 11 with an arc ball camera.

The data describing the surface being represented (degree of the surface,knot vectors and control points) is loaded through a text file. Then, agrid of surface points is generated based on the information loaded.

The surface is generated with this grid, making triangles in anappropriate way.

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Introduction

Description

Based on my final project in bachelor’s degree in Mathematics (aslideshare presentation can be seen here), which was programmed inMatlab.

A translation was made from Matlab to C++.

The goal is to represent interpolating and approximating parametricsurfaces (like NURBS surfaces) in DirectX 11 with an arc ball camera.

The data describing the surface being represented (degree of the surface,knot vectors and control points) is loaded through a text file. Then, agrid of surface points is generated based on the information loaded.

The surface is generated with this grid, making triangles in anappropriate way.

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Introduction

Description

Based on my final project in bachelor’s degree in Mathematics (aslideshare presentation can be seen here), which was programmed inMatlab.

A translation was made from Matlab to C++.

The goal is to represent interpolating and approximating parametricsurfaces (like NURBS surfaces) in DirectX 11 with an arc ball camera.

The data describing the surface being represented (degree of the surface,knot vectors and control points) is loaded through a text file. Then, agrid of surface points is generated based on the information loaded.

The surface is generated with this grid, making triangles in anappropriate way.

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Introduction

Description

Based on my final project in bachelor’s degree in Mathematics (aslideshare presentation can be seen here), which was programmed inMatlab.

A translation was made from Matlab to C++.

The goal is to represent interpolating and approximating parametricsurfaces (like NURBS surfaces) in DirectX 11 with an arc ball camera.

The data describing the surface being represented (degree of the surface,knot vectors and control points) is loaded through a text file. Then, agrid of surface points is generated based on the information loaded.

The surface is generated with this grid, making triangles in anappropriate way.

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Introduction

Parametric surfaces like NURBS are defined by a set of data, consisting in thedegree (p, q) of the surface, two knot vectors U and V , and a grid of controlpoints Pi,j .

For example, given the set of points

Q = {(2, 0, 2), (1, 0, 2), (0, 0, 3), (2, 1, 2), (1, 1, 2), (0, 1, 3), (2, 2, 1), (1, 2, 1),(0, 2, 2), (2, 3, 1), (1, 3, 1), (0, 3, 2)}

a surface of degree (2, 2) interpolating this points is given by the followingdata: knot vectors

U = {0.0, 0.0, 0.0, 0.5, 1.0, 1.0, 1.0} and V = {0.0, 0.0, 0.0, 1.0, 1.0, 1.0},

and control points

P = {P0,0,P0,1,P0,2,P1,0,P1,1,P1,2,P2,0,P2,1,P2,2,P3,0,P3,1,P3,2} ={(2, 0, 2), (0.6464, 0, 1.6464), (0, 0, 3), (2, 1, 2.3536), (0.6464, 1, 2),(0, 1, 3.3536), (2, 2, 0.6464), (0.6464, 2, 0.2929), (0, 2, 1.6464),(2, 3, 1), (0.6464, 3, 0.6464), (0, 3, 2)}

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Introduction

Parametric surfaces like NURBS are defined by a set of data, consisting in thedegree (p, q) of the surface, two knot vectors U and V , and a grid of controlpoints Pi,j .

For example, given the set of points

Q = {(2, 0, 2), (1, 0, 2), (0, 0, 3), (2, 1, 2), (1, 1, 2), (0, 1, 3), (2, 2, 1), (1, 2, 1),(0, 2, 2), (2, 3, 1), (1, 3, 1), (0, 3, 2)}

a surface of degree (2, 2) interpolating this points is given by the followingdata: knot vectors

U = {0.0, 0.0, 0.0, 0.5, 1.0, 1.0, 1.0} and V = {0.0, 0.0, 0.0, 1.0, 1.0, 1.0},

and control points

P = {P0,0,P0,1,P0,2,P1,0,P1,1,P1,2,P2,0,P2,1,P2,2,P3,0,P3,1,P3,2} ={(2, 0, 2), (0.6464, 0, 1.6464), (0, 0, 3), (2, 1, 2.3536), (0.6464, 1, 2),(0, 1, 3.3536), (2, 2, 0.6464), (0.6464, 2, 0.2929), (0, 2, 1.6464),(2, 3, 1), (0.6464, 3, 0.6464), (0, 3, 2)}

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Introduction

Parametric surfaces like NURBS are defined by a set of data, consisting in thedegree (p, q) of the surface, two knot vectors U and V , and a grid of controlpoints Pi,j .

For example, given the set of points

Q = {(2, 0, 2), (1, 0, 2), (0, 0, 3), (2, 1, 2), (1, 1, 2), (0, 1, 3), (2, 2, 1), (1, 2, 1),(0, 2, 2), (2, 3, 1), (1, 3, 1), (0, 3, 2)}

a surface of degree (2, 2) interpolating this points is given by the followingdata: knot vectors

U = {0.0, 0.0, 0.0, 0.5, 1.0, 1.0, 1.0} and V = {0.0, 0.0, 0.0, 1.0, 1.0, 1.0},

and control points

P = {P0,0,P0,1,P0,2,P1,0,P1,1,P1,2,P2,0,P2,1,P2,2,P3,0,P3,1,P3,2} ={(2, 0, 2), (0.6464, 0, 1.6464), (0, 0, 3), (2, 1, 2.3536), (0.6464, 1, 2),(0, 1, 3.3536), (2, 2, 0.6464), (0.6464, 2, 0.2929), (0, 2, 1.6464),(2, 3, 1), (0.6464, 3, 0.6464), (0, 3, 2)}

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Introduction

Parametric surfaces like NURBS are defined by a set of data, consisting in thedegree (p, q) of the surface, two knot vectors U and V , and a grid of controlpoints Pi,j .

For example, given the set of points

Q = {(2, 0, 2), (1, 0, 2), (0, 0, 3), (2, 1, 2), (1, 1, 2), (0, 1, 3), (2, 2, 1), (1, 2, 1),(0, 2, 2), (2, 3, 1), (1, 3, 1), (0, 3, 2)}

a surface of degree (2, 2) interpolating this points is given by the followingdata: knot vectors

U = {0.0, 0.0, 0.0, 0.5, 1.0, 1.0, 1.0} and V = {0.0, 0.0, 0.0, 1.0, 1.0, 1.0},

and control points

P = {P0,0,P0,1,P0,2,P1,0,P1,1,P1,2,P2,0,P2,1,P2,2,P3,0,P3,1,P3,2} =

{(2, 0, 2), (0.6464, 0, 1.6464), (0, 0, 3), (2, 1, 2.3536), (0.6464, 1, 2),(0, 1, 3.3536), (2, 2, 0.6464), (0.6464, 2, 0.2929), (0, 2, 1.6464),(2, 3, 1), (0.6464, 3, 0.6464), (0, 3, 2)}

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Introduction

Parametric surfaces like NURBS are defined by a set of data, consisting in thedegree (p, q) of the surface, two knot vectors U and V , and a grid of controlpoints Pi,j .

For example, given the set of points

Q = {(2, 0, 2), (1, 0, 2), (0, 0, 3), (2, 1, 2), (1, 1, 2), (0, 1, 3), (2, 2, 1), (1, 2, 1),(0, 2, 2), (2, 3, 1), (1, 3, 1), (0, 3, 2)}

a surface of degree (2, 2) interpolating this points is given by the followingdata: knot vectors

U = {0.0, 0.0, 0.0, 0.5, 1.0, 1.0, 1.0} and V = {0.0, 0.0, 0.0, 1.0, 1.0, 1.0},

and control points

P = {P0,0,P0,1,P0,2,P1,0,P1,1,P1,2,P2,0,P2,1,P2,2,P3,0,P3,1,P3,2} ={(2, 0, 2), (0.6464, 0, 1.6464), (0, 0, 3), (2, 1, 2.3536), (0.6464, 1, 2),(0, 1, 3.3536), (2, 2, 0.6464), (0.6464, 2, 0.2929), (0, 2, 1.6464),(2, 3, 1), (0.6464, 3, 0.6464), (0, 3, 2)}

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Introduction

An example in Matlab of the previous grid of points (in green), and aninterpolant surface generated (control points in blue, interpolated points inred) can be seen below:

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Basis demo

In the chapter eight of [4], an arc-ball camera for Xbox 360 is made, and canbe modified to be controlled with pc keyboard and mouse.

Reading from a text file the degree, knot vectors and control points of aparametric surface, a grid of surface points can be generated dynamically.

This requires programming some functions that allow to evaluate the value ofa surface S at desired parameter values u and v , i.e., to obtain the value ofS(u, v), which will be a three dimensional point.

The parameter values u and v go from 0.0 to 1.0, so if a step is considered foreach parameter, for example uStep = 0.1 and vStep = 0.1, a grid of11 ∗ 11 = 121 surface points will be generated, by evaluatingS(0.0, 0.0),S(0.0, 0.1), S(0.0, 0.2), ..., S(0.0, 1.0),S(0.1, 0.0), ..., S(1.0, 1.0).

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Basis demo

In the chapter eight of [4], an arc-ball camera for Xbox 360 is made, and canbe modified to be controlled with pc keyboard and mouse.

Reading from a text file the degree, knot vectors and control points of aparametric surface, a grid of surface points can be generated dynamically.

This requires programming some functions that allow to evaluate the value ofa surface S at desired parameter values u and v , i.e., to obtain the value ofS(u, v), which will be a three dimensional point.

The parameter values u and v go from 0.0 to 1.0, so if a step is considered foreach parameter, for example uStep = 0.1 and vStep = 0.1, a grid of11 ∗ 11 = 121 surface points will be generated, by evaluatingS(0.0, 0.0),S(0.0, 0.1), S(0.0, 0.2), ..., S(0.0, 1.0),S(0.1, 0.0), ..., S(1.0, 1.0).

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Basis demo

In the chapter eight of [4], an arc-ball camera for Xbox 360 is made, and canbe modified to be controlled with pc keyboard and mouse.

Reading from a text file the degree, knot vectors and control points of aparametric surface, a grid of surface points can be generated dynamically.

This requires programming some functions that allow to evaluate the value ofa surface S at desired parameter values u and v , i.e., to obtain the value ofS(u, v), which will be a three dimensional point.

The parameter values u and v go from 0.0 to 1.0, so if a step is considered foreach parameter, for example uStep = 0.1 and vStep = 0.1, a grid of11 ∗ 11 = 121 surface points will be generated, by evaluatingS(0.0, 0.0),S(0.0, 0.1), S(0.0, 0.2), ..., S(0.0, 1.0),S(0.1, 0.0), ..., S(1.0, 1.0).

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Basis demo

In the chapter eight of [4], an arc-ball camera for Xbox 360 is made, and canbe modified to be controlled with pc keyboard and mouse.

Reading from a text file the degree, knot vectors and control points of aparametric surface, a grid of surface points can be generated dynamically.

This requires programming some functions that allow to evaluate the value ofa surface S at desired parameter values u and v , i.e., to obtain the value ofS(u, v), which will be a three dimensional point.

The parameter values u and v go from 0.0 to 1.0, so if a step is considered foreach parameter, for example uStep = 0.1 and vStep = 0.1, a grid of11 ∗ 11 = 121 surface points will be generated, by evaluatingS(0.0, 0.0),S(0.0, 0.1), S(0.0, 0.2), ..., S(0.0, 1.0),S(0.1, 0.0), ..., S(1.0, 1.0).

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Surface Points

The next image shows a grid of surface points generated for the same surfaceas seen in the previous slide. Each point is represented with a quad, generatedthrough the Geometry Shader:

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Surface Points

This set of points can be used to form triangles and render these trianglesthrough an index buffer, in order to obtain a representation of the surface:

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Adding per-pixel lighting

It is possible to add lighting effects to the surface such as standard per-pixellighting. Normal vectors will be needed, so they must be estimated in someway.

Given the points A, B and C that form each triangle in the surface, anacceptable estimation of the normal vector at the point A can be obtained

performing the cross product of the vectors−→AB and

−→AC .

Due that the surface is one-sided, to render with per-pixel lighting in bothsides of the surface, a ”copy” of the surface slightly moved down in the y axis(the demo uses a left handed coordinate system) is also rendered, with thenormal vectors at each point negated.

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Adding per-pixel lighting

It is possible to add lighting effects to the surface such as standard per-pixellighting. Normal vectors will be needed, so they must be estimated in someway.

Given the points A, B and C that form each triangle in the surface, anacceptable estimation of the normal vector at the point A can be obtained

performing the cross product of the vectors−→AB and

−→AC .

Due that the surface is one-sided, to render with per-pixel lighting in bothsides of the surface, a ”copy” of the surface slightly moved down in the y axis(the demo uses a left handed coordinate system) is also rendered, with thenormal vectors at each point negated.

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Adding per-pixel lighting

It is possible to add lighting effects to the surface such as standard per-pixellighting. Normal vectors will be needed, so they must be estimated in someway.

Given the points A, B and C that form each triangle in the surface, anacceptable estimation of the normal vector at the point A can be obtained

performing the cross product of the vectors−→AB and

−→AC .

Due that the surface is one-sided, to render with per-pixel lighting in bothsides of the surface, a ”copy” of the surface slightly moved down in the y axis(the demo uses a left handed coordinate system) is also rendered, with thenormal vectors at each point negated.

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Adding per-pixel lighting

The image below shows a surface rendering in the left, and the same surfacerendered whith per-pixel lighting:

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Dynamically generated points

The amount of points used to render a surface can be controlled with the uand v parameters step. The smaller the step, the more points obtained. Forexample, if the step is 0.1 for both parameters, then there will be11 ∗ 11 = 121 surface points.

If the step is 0.01, then there will be 101 ∗ 101 = 10201 surface points, withsubsequent increase in the detail of the rendering (and decrease in theperformance).

Next there are some examples of grids of points interpolated in Matlab. Thegenerated surfaces are loaded in the application programmed in DirectX 11and rendered with different steps for the parameters.

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Dynamically generated points

The amount of points used to render a surface can be controlled with the uand v parameters step. The smaller the step, the more points obtained. Forexample, if the step is 0.1 for both parameters, then there will be11 ∗ 11 = 121 surface points.

If the step is 0.01, then there will be 101 ∗ 101 = 10201 surface points, withsubsequent increase in the detail of the rendering (and decrease in theperformance).

Next there are some examples of grids of points interpolated in Matlab. Thegenerated surfaces are loaded in the application programmed in DirectX 11and rendered with different steps for the parameters.

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Dynamically generated points

The amount of points used to render a surface can be controlled with the uand v parameters step. The smaller the step, the more points obtained. Forexample, if the step is 0.1 for both parameters, then there will be11 ∗ 11 = 121 surface points.

If the step is 0.01, then there will be 101 ∗ 101 = 10201 surface points, withsubsequent increase in the detail of the rendering (and decrease in theperformance).

Next there are some examples of grids of points interpolated in Matlab. Thegenerated surfaces are loaded in the application programmed in DirectX 11and rendered with different steps for the parameters.

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Examples

Point grid and interpolated surface in Matlab (surface points in red, controlpoints in blue)

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Examples

u and v step are 0.1

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Examples

u and v step are 0.01

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Examples

Point grid and interpolated surface in Matlab (surface points in red, controlpoints in blue)

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Examples

u and v step are 0.1

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Examples

u and v step are 0.01

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Examples

Point grid and interpolated surface in Matlab (surface points in red, controlpoints in blue)

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Examples

u and v step are 0.1

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Examples

u and v step are 0.01

Parametricsurface vi-sualizationin DirectX11 (C++)

Introduction

Basis demo

Surfacevisualizationprocess

Dynamicallygeneratedpoints

Examples

Bibliography

Bibliography

G. Farin, J. Hoschek, and M. S. Kim.

Handbook of Computer Aided Geometric Design.

Elsevier, first edition, 2002.

Microsoft.

Direct3d 11 sdk documentation, October 2009.

L. Piegl and W. Tiller.

The NURBS Book.

Springer, second edition, 1997.

A. Sherrod and W. Jones.

Beginning DirectX 11 Game Programming.

Course Technology, Cengage Learning, first edition, 2012.

Recommended