Modeling Modelin Transformati tions Lighti ting/shading model - - PowerPoint PPT Presentation
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)
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
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
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
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
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
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
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
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
“Graphics Processing Unit” Specialized processor for graphics rendering Spécificities:
Highly parallel (SIMD) Fast local memory Large throughput
10
Highly efficient parallel processor:
- GPGPU : “General-Purpose computation on GPU”
11
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
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
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
API
API (Application Programming Interface) for graphics hardware
Mostly 2 different graphics APIs:
Direct3D (Microsoft) Op OpenGL enGL (Khronos Group)
15
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
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
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
( 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
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
What you can do:
Add/remove vertices Change the primitives Get the actual geometry, before rasterization
Geometr try shad shader er
21
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
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
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
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
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
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
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
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
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
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
Advanced rendering
Global illumination Image-based rendering …
Signal processing Algorithmic geometry Genetic algorithms Anything you can massively parallelize
32
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
- 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