Modeling Modelin Transformati tions Lighti ting/shading model - - PowerPoint PPT Presentation

modeling modelin transformati tions
SMART_READER_LITE
LIVE PREVIEW

Modeling Modelin Transformati tions Lighti ting/shading model - - PowerPoint PPT Presentation

Geometr try: objects, surfaces, light sources Modeling Modelin Transformati tions Lighti ting/shading model Camera Camera: viewpoint, direction, field-of-view Illuminati tion (frustum) (Shadin (S ading) ) Window (viewport)


slide-1
SLIDE 1
slide-2
SLIDE 2

Modelin Modeling 
 Transformati tions Illuminati tion (S (Shadin ading) ) Viewing Transformati tion (Perspecti tive / Orth thographic) Clip Clipping ing Projecti tion 
 (to to Screen Space) Sc Scan n Co Conve nversi sion
 (Raste terizati tion) Visibility ty / Di Display

Geometr try: objects, surfaces, light sources… Lighti ting/shading model Camera Camera: viewpoint, direction, field-of-view (frustum) Window (viewport) t): pixel grid where the picture is displayed Colors, inte tensiti ties ta tailored for 
 dis display play (ex : 24 bits, RVB)

2

slide-3
SLIDE 3

Modelin Modeling 
 Transformati tions Illuminati tion (S (Shadin ading) ) Viewing Transformati tion (Perspecti tive / Orth thographic) Clip Clipping ing Projecti tion 
 (to to Screen Space) Sc Scan n Co Conve nversi sion
 (Raste terizati tion) Visibility ty / Di Display

Object space World space

From each object’s local

local coordinate te syste tem (object space) to a global coordinate te syste tem (world space)

3 z y x

slide-4
SLIDE 4

Modelin Modeling 
 Transformati tions Illuminati tion (S (Shadin ading) ) Viewing Transformati tion (Perspecti tive / Orth thographic) Clip Clipping ing Projecti tion 
 (to to Screen Space) Sc Scan n Co Conve nversi sion
 (Raste terizati tion) Visibility ty / Di Display

Each primitive is shaded

depending on its material and the light sources.

Local illumination only (no

shadows), independent computation for each primitive

4

slide-5
SLIDE 5

Modelin Modeling 
 Transformati tions Illuminati tion (S (Shadin ading) ) Viewing Transformati tion (Perspecti tive / Orth thographic) Clip Clipping ing Projecti tion 
 (to to Screen Space) Sc Scan n Co Conve nversi sion
 (Raste terizati tion) Visibility ty / Di Display

From world coordinate system to

view point (eye space).

Eye space

5

World space

z y x near far v u eye p

slide-6
SLIDE 6

Modelin Modeling 
 Transformati tions Illuminati tion (S (Shadin ading) ) Viewing Transformati tion (Perspecti tive / Orth thographic) Clip Clipping ing Projecti tion 
 (to to Screen Space) Sc Scan n Co Conve nversi sion
 (Raste terizati tion) Visibility ty / Di Display

Normalized coordinate

tes:

Eye space NDC

Anything outside the

viewing frustu tum is clipped:

6 near far eye z y x

slide-7
SLIDE 7

Modelin Modeling 
 Transformati tions Illuminati tion (S (Shadin ading) ) Viewing Transformati tion (Perspecti tive / Orth thographic) Clip Clipping ing Projecti tion 
 (to to Screen Space) Sc Scan n Co Conve nversi sion
 (Raste terizati tion) Visibility ty / Di Display

NDC Screen Space

3D primitives are projected onto a

2D picture (screen space)

7 z y x z y x

slide-8
SLIDE 8

Modelin Modeling 
 Transformati tions Illuminati tion (S (Shadin ading) ) Viewing Transformati tion (Perspecti tive / Orth thographic) Clip Clipping ing Projecti tion 
 (to to Screen Space) Sc Scan n Co Conve nversi sion
 (Raste terizati tion) Visibility ty / Di Display

Convert the 2D primitive in pixels Interpolate values known at the

vertices (color, depth...)

8

slide-9
SLIDE 9

Modelin Modeling 
 Transformati tions Illuminati tion (S (Shadin ading) ) Viewing Transformati tion (Perspecti tive / Orth thographic) Clip Clipping ing Projecti tion 
 (to to Screen Space) Sc Scan n Co Conve nversi sion
 (Raste terizati tion) Visibility ty / Di Display

Hidden surface removal Filling the frame buffer with

the right color format

9

slide-10
SLIDE 10

“Graphics Processing Unit” Specialized processor for graphics rendering Spécificities:

Highly parallel (SIMD) Fast local memory Large throughput

10

slide-11
SLIDE 11

Highly efficient parallel processor:

  • GPGPU : “General-Purpose computation on GPU”

11

slide-12
SLIDE 12

Modelin Modeling 
 Transformati tions Illuminati tion (S (Shadin ading) ) Viewing Transformati tion (Perspecti tive / Orth thographic) Clip Clipping ing Projecti tion 
 (to to Screen Space) Sc Scan n Co Conve nversi sion
 (Raste terizati tion) Visibility ty / Di Display

Softw tware con config igurable rable

Before graphics hardware

(1970s)

12

slide-13
SLIDE 13

Modelin Modeling 
 Transformati tions Illuminati tion (S (Shadin ading) ) Viewing Transformati tion (Perspecti tive / Orth thographic) Clip Clipping ing Projecti tion 
 (to to Screen Space) Sc Scan n Co Conve nversi sion
 (Raste terizati tion) Visibility ty / Di Display

Hard Hardware ware (G (GPU) U)

1st generation graphics hardware

(1980s)

Softw tware con config igurable rable

13

slide-14
SLIDE 14

Modelin Modeling 
 Transformati tions Illuminati tion (S (Shadin ading) ) Viewing Transformati tion (Perspecti tive / Orth thographic) Clip Clipping ing Projecti tion 
 (to to Screen Space) Sc Scan n Co Conve nversi sion
 (Raste terizati tion) Visibility ty / Di Display

Hard Hardware ware con config igurable rable

2nd generation graphics hardware

(1990s)

14

slide-15
SLIDE 15

API

API (Application Programming Interface) for graphics hardware

Mostly 2 different graphics APIs:

Direct3D (Microsoft) Op OpenGL enGL (Khronos Group)

15

slide-16
SLIDE 16

Modelin Modeling 
 Transformati tions Illuminati tion (S (Shadin ading) ) Viewing Transformati tion (Perspecti tive / Orth thographic) Clip Clipping ing Projecti tion 
 (to to Screen Space) Sc Scan n Co Conve nversi sion
 (Raste terizati tion) Visibility ty / Di Display

Hard Hardware ware prog program rammable able (sh (shaders) aders)

3rd generation graphics hardware

(2000s)

16

slide-17
SLIDE 17

Sha

Shaders: :

Short programs, that the GPU runs at specific steps in the pipeline Different languages (C-like), depending on the API: NVIDIA ➭ Cg (2002) Direct3D ➭ HLSL (2003) OpenGL ➭ GLSL (2004)

For GPGPU :

CUDA (NVIDIA) ATI Stream OpenCL (Khronos Group)

17

slide-18
SLIDE 18

Primiti tive Assemb Assembly ly

3 types of shaders

1.

  • 1. Verte

tex shader 2.

  • 2. Geometr

try shader 3.

  • 3. Pix

Pixel el shader

Local effect

  • 1. one vertex
  • 2. one primitive (& neighbors)
  • 3. one pixel

Per-fragment t

  • perati

tions Fragment
 shad shader er Raste terizer Fram Framebu ebuffer ffer Verte tex Da Data ta Textu tures Verte tex
 shad shader er

fixed programmable memory

18

Geometr try shad shader er

slide-19
SLIDE 19

( x’, y’, z’, w’ ) ( nx’, ny’, nz’ ) ( s’, t’, r’, q’ ) ( r’, g’, b’, a’ ) ( x, y ) ( r, g, b, a ) ( depth ) ( x, y ) ( r’, g’, b’, a’ ) ( depth’ ) ( x, y, z, w ) ( nx, ny, nz ) ( s, t, r, q ) ( r, g, b, a )

Verte tex
 shad shader er Geometr try s shader ader

19

Fragment
 shad shader er

slide-20
SLIDE 20

What you can do:

Geometric transformations, changing position Lighting, shading, computing a color per vertex Computing texture coordinates

( x, y, z, w ) ( nx, ny, nz ) ( s, t, r, q ) ( r, g, b, a ) ( x’, y’, z’, w’ ) ( nx’, ny’, nz’ ) ( s’, t’, r’, q’ ) ( r’, g’, b’, a’ )

Verte tex
 shad shader er

20

slide-21
SLIDE 21

What you can do:

Add/remove vertices Change the primitives Get the actual geometry, before rasterization

Geometr try shad shader er

21

slide-22
SLIDE 22

What you can do:

Lighting, shading, computing a color... per pixel Use the textures as input for computations Change pixel depth

Fragment
 shad shader er

22

slide-23
SLIDE 23

uniform mat4 modelViewProjectionMatrix; in vec4 vertex;

  • ut vec3 color;

vec4 UneFonction( vec4 Entree ) { return Entree.zxyw; } void main() { vec4 pos = modelViewProjectionMatrix * vertex; gl_Position = pos + UneFonction( vertex ); color = vec3(1.0,0.0,0.0); } Input Swizzle OpenGL Output Function Main program Local variable

23

Matrix-vector multiplication Output

slide-24
SLIDE 24

Code slowly, step by step, and te

test t ofte ten!

Debugging is really difficult

Opti

timizati tion

Best place for each computation:

Vertex shader : 1x per vertex Fragment shader : 1x per fragment: much more frequent!

Use textures to tabulate complicated functions Use the functions in the language, rather than coding them yourself (sin, sqrt,…)

24

slide-25
SLIDE 25

Model generati tion & tr transformati tion
 (te tessellati tion / tr transformati tions) Illuminati tion (S (Shadin ading) ) Viewing Transformati tion (Perspecti tive / Orth thographic) Clip Clipping ing Projecti tion 
 (to to Screen Space) Sc Scan n Co Conve nversi sion
 (Raste terizati tion) Visibility ty / Di Display

Hard Hardware ware prog program rammable able (sh (shaders) aders)

4th generation graphics hardware

(2010s)

25

slide-26
SLIDE 26

Another step, between vertex and geometry

shaders

26

Primiti tive Assemb Assembly ly Per-fragment t

  • perati

tions Fragment
 shad shader er Raste terizer Fram Framebu ebuffer ffer Verte tex
 shad shader er

fixed programmable

Geometr try shad shader er

Bef Before

  • re
slide-27
SLIDE 27

Between vertex and geometry shaders

27

Primiti tive Assemb Assembly ly Per-fragment t

  • perati

tions Fragment
 shad shader er Raste terizer Fram Framebu ebuffer ffer

fixed programmable

Geometr try shad shader er

Afte ter

Tesselati tion Contr trol Tesselati tion Ev Evaluati tion Verte tex
 shad shader er Tesselati tion Primiti tive Generato tor

slide-28
SLIDE 28

Before “primitive assembly” Input: a patch

Control points, coordinates inside the patch Patch type (triangles, quads, iso-lines)

Output:

a vertex Called several times, once for each vertex generated Local effect, no global view of the patch

What for?

Subdivision surfaces, splines...

28

slide-29
SLIDE 29

Called before the Tessellation Eval Shader Facultative Controls tessellation level for each patch Once for each control point

(gl_InvocationID)

Can modify the control points Tessellation Primitive Generator

Generates the coordinates where we call TessEval Fixed functionality

29

slide-30
SLIDE 30

Apparently, useless:

Anything it does, you can do with geometry shader

In practice:

GPU needs predictability Parallel processor / resource allocation Useful for subdivision surfaces, splines

30

slide-31
SLIDE 31

General-Purpose Computation Using

Graphics Hardware

GPU = a SIMD processor 


(Single Instruction Multiple Data)

One texture = array of input data One picture= array of output data

31

Outp tput t Da Data ta SIMD D Pr Processo essors s Mem Memory

  • ry
slide-32
SLIDE 32

Advanced rendering

Global illumination Image-based rendering …

Signal processing Algorithmic geometry Genetic algorithms Anything you can massively parallelize

32

slide-33
SLIDE 33

Get back the data (from GPU to CPU) = slower

PCI Express

Limited operators, functions, types A parallel algorithm is not necessarily faster

than the sequential version

Synchronization between multiple cores

33

slide-34
SLIDE 34
  • OpenGL red book: http://www.opengl-redbook.com/
  • GLSL specification: https://www.opengl.org/registry/doc/GLSLangSpec.4.40.pdf
  • Cg: http://developer.nvidia.com/page/cg_main.html
  • Cuda: http://www.nvidia.com/cuda
  • OpenCL: http://www.kronos.org/opencl/
  • Debugging OpenGL/GLSL:

glslDevil : http://www.vis.uni-stuttgart.de/glsldevil/

  • Many examples (to use as a starting point):

http://developer.nvidia.com/object/sdk_home.html

  • GPGPU reference, with code, forums, tutorials: http://www.gpgpu.org/

34