image - ipp.ptave.dee.isep.ipp.pt/~jml/intmu/acetatos/3dgraphics.pdf12-04-2018 4 aplicação 3d...
Post on 30-Sep-2020
1 Views
Preview:
TRANSCRIPT
12-04-2018
1
3D
Image
12-04-2018
2
Vector graphics
Raster / Vector
12-04-2018
3
Aplicação Vector
Transformações
12-04-2018
4
Aplicação 3D
Display Object
DB Graphics Pipeline
.obj .dxf .iv .dwg .wrl .flt
.3ds .blend
Simulator
Eye, Lookat
Graphics Pipeline
Screen
Model Transformation
Culling
Ilumination
Projection
Oclusion
Shading
Viewport Transformation
Screen Transformation
Objects
3D, Object Space 3D, World Space
2D, Fragments
pixels
12-04-2018
5
Transformações 3D
Escalamento
Translação
z
y
x
vzz
vyy
vxx
'
'
'
zsz
ysy
xsx
z
y
x
'
'
'
1000
100
010
001
z
y
x
v
v
v
vT
1000
000
000
000
,,
z
y
x
szsysx
s
s
s
S
zyxPjObzyxPObj ii ,,,,
PP vT
PP szsysx ,,S
Rotação 3D
Rotação
Rotação
Rotação
1000
0cos0sen
0010
0sen0cos
,
yR
zz
yxy
yxx
'
cossen'
sencos'
cossen'
sencos'
'
zyz
zyy
xx
cossen'
'
sencos'
zxz
yy
zxx
1000
0cossen0
0sencos0
0001
,
xR
1000
0100
00cossen
00sencos
,
zR
PP zR ,
PP xR ,
PP yR ,
12-04-2018
6
Modelação
Sala
CadeiraTampoPerna 4Perna 3Perna 2Perna 1
Perna
Cadeira 2 Cadeira 3SofáMesa ArmárioCadeira 1
Sala{ Mesa; Sofá; Cadeira 1; Cadeira 2; Cadeira 3; Armário}
Mesa{ Perna 1; Perna 2; Perna 3; Perna 4; Tampo;}
Perna{ Box(10,100,10);}
Perna 1{ Transformação(p1); Perna;}
Perna 2{ Transformação(p2); Perna;}
Perna 3{ Transformação(p3); Perna;}
Perna 4{ Transformação(p4); Perna;}
Cadeira 1{ Transformação(c1); Cadeira;}
Cadeira 2{ Transformação(c2); Cadeira;}
Cadeira 3{ Transformação(c3); Cadeira;}
Cadeira{ … …}
Orientação HPR
12-04-2018
7
View Frustum Culling
Hirarchical Culling
-> Todos os sub-objetos são rejeitados
-> Todos os sub-objetos são mantidos
-> Todos os sub-objetos são analisados
• Objetos são organizados hierarquicamente. • Volume envolvente definido para cada nó.
12-04-2018
8
Projection
Projecção
PMP
z
zyy
z
zxx
per
'
0
0
0100
000
000
000
d
d
d
M per
12-04-2018
9
Projecção perspectiva P
z0
P’
O
x
z
P
yp
yp’
zpz0
P’
z
y
P
xp
xp’
zpz0
P’
z
x
0100
000
000
000
'
0
0
d
d
d
M
PMP
z
zyy
z
zxx
per
per
Visibilidade
12-04-2018
10
Z-Buffer
AD
Z
Z
WR RD
Reg
VRAM
Controlo
Comparador
R
R
G
G
B
B
Z_Buffer[max_x, max_y]; Put_Pixel_Z(x, y, z) { if( z<Z_Buffer[x,y] ) { Put_Pixel(x,y); Z_Buffer[x,y] = z; } } Clear_Window_Z() { Clear_Window(); for x:=1 to max_x for y:=1 to max_y Z_Buffer[x,y] = max_z; }
Z-Buffer
dmin dmax
z=Zmax
dd
z=0
O
minmax
minmax
dd
ddZz
Bits por pixel no Z-Buffer ( ):Zbits 12 Zbits
maxZ
NCNLZbitsZbuffer Tamanho do Z-Buffer:
Zbits
minmax
max
minmax
res
dd
Z
ddZ
21
Resolução em :z
12-04-2018
11
Iluminação ambiente
I0
Ia
ka
aa kII 0
Ka = Coefieciente de reflexão ambiente
Reflexão Difusa
NL
IL
Id
)(cos NL dLdLd kIkII
Coeficiente de reflexão difusa
kd
12-04-2018
12
Iluminação difusa + ambiente
ka
kd
Reflexão especular
N
IL
Ir
Is
n
sL
n
sLs KIKII )()(cos)( VR
n
sLs kII )( VR
Simplificando:
Coeficiente de reflexão especular
Brilho (Shininess)
NIL
Ir NIL
Ir
n pequeno: n grande:
n
ks
12-04-2018
13
Iluminação Global
IL
IL’|L|
n
sdLasda kkIkIIIII )()(0 VRNL
n
sdL
a kkk
IkII )()(0 VRNL
L
Para considerar a atenuação da luz em função da distância:
Para considerar os efeitos devidos à existência de fontes de luz:NL
NL
i
i
s
i
da IIII0
Normais de Polígonos
• Normal - Vetor perpendicular à superfície a representar.
• O cálculo de iluminação requer a definição de normais.
• As normais podem ser:
– obtidas implicitamente, a partir das das coordenadas dos vértices. -> Regra da mão direita.
– especificadas explicitamente.
12-04-2018
14
Constant Shading ou flat shading
Uma única intensidade luminosa é utilizada para colorir todo o polígono.
Um único cálculo de iluminação por polígono.
Interpolated Shading
R
F P
T
G
S
São determinados os valores da intensidade luminosa em cada um dos vértices de um triângulo. O triângulo é colorido pela interpolação linear dos valores obtidos para os seus vértices.
),,()1(),,(),,( FFFGGGPPP BGRdBGRdBGRFG
FPd
),,()1(),,(),,( SSSTTTGGG BGRdBGRdBGRST
SGd
Independentemente de se utilizar constant shading, interpolated shading ou shading por píxel, quando os polígonos são coloridos de forma independente, os objectos aparecem facetados. Diferentes orientações dos polígonos provocam iluminações distintas. Solução: Agrupar os polígonos em malhas que partilham vértices e normais!
12-04-2018
15
Iluminação por Vértice
Fonte de Luz
Desejado Obtido
Gouraud Shading
As superfícies curvas são aproximadas por uma malha de polígonos. Este método requer a especificação de uma normal para cada vértice da malha poligonal. As intensidades luminosas nos vértices são determinadas utilizando as normais especificadas para cada vértice. Os polígonos são coloridos por interpolação linear.
12-04-2018
16
Normais por vértice
Normais por vértice
12-04-2018
17
Phong Shading
É realizada uma interpolação da normal em vez da interpolação da intensidade luminosa.
IS&T Tutorial: Graphics Prog - OpenGL and OSG
Texture map
+
12-04-2018
18
Texturas
Coordenadas de Textura
Imagem de Textura tem coordenada (u,v ) [0, 1]
12-04-2018
19
Texture Mapping
v0
v1
v2
t2 t0
t1
(1,1)
(0,0) x
y
Texture Space Triangle (in any space)
Vértice em OpenGL
void Draw() { glColor3f(Color.x, Color.y, Color.z); glNormal3f(Normal.x, Normal.y, Normal.z); glTexCoord2f(TexCoord.x, TexCoord.y); glVertex3f(Position.x, Position.y, Position.z);
// This has to be last
}
12-04-2018
20
Wavefront obj format
# example obj file v -1.63 -3.04 -8.81 v -4.62 -2.47 -4.55 v -7.34 -5.84 -9.22 vn 0.03 0.40 0.01 vt 0.22 0.97 vt 0.98 0.97 vt 0.98 0.14 f 1/3/1 3/2/1 2/1/1 (index to v/t/n)
Tiling / Clamping
x
y
Tiling
(0,0)
(1,1)
A imagem de textura existe entre as coordenadas (0,0) e (1,1). É possível especificar coordenadas fora desta zona.
(0,0)
(1,1)
Clamping
12-04-2018
21
Bump mapping
Simulação de rugosidade
Photorealism
Co
rnel
l PC
G
Real Synthetic
12-04-2018
22
Photorealism?
Shadows motivation
Shadows help to:
• improve the realism in rendered images
• illustrate spatial relations between objects
12-04-2018
23
Shadows
with shadows without shadows
Shadow support
• shadow algorithms are not standard functionality of the rasterization-based rendering pipeline
• rendering pipeline
– generates 2D images from 3D scenes (camera, light, objects)
– evaluates lighting models using local information
– spatial relations among objects are not considered
12-04-2018
24
Shadow maps
• see shadow casting as a visibility problem
• scene points are
– visible from the light source (illuminated)
– invisible from the light source (in shadow)
• resolving visibility is standard functionality in the rendering pipeline (z-buffer algorithm)
Visualizing the Shadow
• The scene from the light’s point-of-view
12-04-2018
25
Shadow map Algorithm
• Shadow map generation – render scene from the light source
– store all distances to visible (illuminated) scene points in a shadow map
• Scene Rendering – render scene from the camera
– compare the distance of rendered scene points to the light with stored values in the shadow map
– if both distances are equal, the rendered scene point is illuminated
Shadow map generation
Scene is rendered from the light source
12-04-2018
26
Shadow map
• The depth buffer from the light’s point-of-view
Visualizing the Shadow
• Projecting light’s planar distance onto eye’s view
12-04-2018
27
Shadow map: Scene Rendering
Shadow map: Summary
• use two depth buffers – the “usual” depth buffer for the view point
– a second depth buffer for the light position (shadow map)
• render the scene from the light position into the shadow map
• render the scene from the view position into the depth buffer
• transform depth values to shadow values
• compare transformed depth values and shadow map values to decide whether a fragment is shadowed or not
12-04-2018
28
Shadow map offset
• discretized representation of depth values can cause an erroneous classification of scene points
• offset of shadow map values reduces artifacts
No offset Correct offset
Blocky Shadow Edge
Light position out
here pointing
towards the viewer.
Blocky shadow
edge artifacts.
Shadow
edge is well
defined in
the distance.
12-04-2018
29
Hardware Shadow Map Filtering
GL_NEAREST: blocky GL_LINEAR: antialiased edges
Low shadow map resolution
used to heightens filtering artifacts
Backward Ray-Tracing
Os raios são enviados do olho para a fonte de luz !
12-04-2018
30
Ray-Tracing
R1
N1
N2S11
S12S21
S22
Obj1
L1
L2
Obj2Obj3
R2
T2
R3
Ray-Tracing
• Qualidades do Ray-Tracing
– Reflexões especulares exatas.
– Sombras detalhadas.
• Deficiências do Ray-Tracing
– Deficientes inter-reflexões difusas.
12-04-2018
31
Radiosity
Basic Ideas:
• Divide surfaces into discrete patches
– Object space algorithm
• Model light transfer between patches as system of linear equations
• Solve matrix equation for radiosity of each patch
– Do it for R,G,B
• Render patches as colored polygons
Simplifying assumptions
• All surfaces are perfectly diffuse
– Does not matter which way light enters or leaves a surface
• Radiosity is constant over a patch
12-04-2018
32
Radiosity Equation
• Bi is radiosity of patch i – energy per unit area leaving a surface patch per unit time – rate energy emitted + rate energy reflected
• Ei is the rate of energy emitted. (non-zero for emitters) • Ri is reflectivity of the patch
– Wavelength dependent
• Fij is the form factor – how much light patch j contributes to patch i – Depends on geometric relationship – distance and relative
orientation
Radiosity solution
• Finding form factors – Hemicube method
– Ray casting
– …
• Solving set of linear equations to get radiosity for each patch
12-04-2018
33
Progressive radiosity
What is a GPU?
• It is a processor optimized for 2D/3D graphics, video, visual computing, and display.
• It is highly parallel, highly multithreaded multiprocessor optimized for visual computing.
• It provide real-time visual interaction with computed objects via graphics images, and video.
• It serves as both a programmable graphics processor and a scalable parallel computing platform.
• Heterogeneous Systems: combine a GPU with a CPU
12-04-2018
34
GPU Evolution
1980’s: No GPU. PC used VGA controller
1990’s: Add more function into VGA controller
1997: 3D acceleration functions: Hardware for triangle setup and rasterization
Texture mapping
Shading
2000: A single chip graphics processor (beginning of GPU term)
2005: Massively parallel programmable processors
2007: CUDA (Compute Unified Device Architecture)
Why Program the GPU ?
http://ixbtlabs.com/articles3/video/cuda-1-p1.html
12-04-2018
35
Modern GPU Architecture Size
• NV40 (Geforce 6)
– 225 million xtors
– 450mhz
• Pentium 4 EE chip
– 175 million xtors
– 3.2 Ghz
From ‘Stream Programming Environments’ – Hanrahan, 2004:
Results:
Matrix Dimension GPU CPU GPU/CPU
64x64 0.417465 ms 18.0876 ms
128x128 0.41691 ms 18.3007 ms
256x256 2.146367 ms 145.6302 ms
512x512 8.093004 ms 1494.7275 ms
768x768 25.97624 ms 4866.3246 ms
1024x1024 52.42811 ms 66097.1688 ms
2048x2048 407.648 ms Didn’t finish
4096x4096 3.1 seconds Didn’t finish
12-04-2018
36
The (Old) Graphics Pipeline
Vertex Shader
Light
Transform
Project
Triangle Setup
Combine vertices into triangle, convert to fragments
Frame- buffer
GPU CPU
Fragment Blender
Z-cull
Alpha Blend
Fragment Shader
Texture Maps
Texture map fragments
3dfx Voodoo (’96), Nvidia RIVA TNT (‘98)
More Programable Graphics Pipeline
Vertex Shader
Triangle Setup
Fragment Blender
Light
Transform
Project
Combine vertices into triangle, convert to fragments
Texture map fragments
Z-cull
Alpha Blend
Frame- buffer
GPU
Fragment Shader
Texture Maps
Geforce, ATI 3D Rage II (’97)
12-04-2018
37
Texture map fragments
Light
Programable Graphics Pipeline
Vertex Shader
Triangle Setup
Fragment Blender
Light
Transform
Project
Combine vertices into triangle, convert to fragments
Z-cull
Alpha Blend
Frame- buffer
GPU
Fragment Shader
Texture Maps
Geforce2-4, Xbox, Radeon 7000-8000, DX8
The Modern Graphics Pipeline
Vertex Shader
Triangle Setup
Fragment Shader
Fragment Blender
Transform
Project
Combine vertices into triangle, convert to fragments
Texture map fragments
Light
GPU
Texture Maps
Z-cull
Alpha Blend
Frame- Buffer(s)
Radeon 9000,X---, GeforceFX-6, DX9
12-04-2018
38
Basic Unified GPU Architecture
Logical pipeline mapped to physical processors.
Vertex Shader
Geometry
Shader
Pixel Shader
Input
Assembler
Rasterizer Output Merger
Unified Processor Array
Basic unified GPU architecture
Copyright © 2009 Elsevier, Inc
GPU with 112 streaming processor (SP) cores organized in 14 streaming multiprocessors (SMs); Each SM has eight SP cores, two special function units (SFUs), instruction and constant caches, a multithreaded instruction unit, and a shared memory.
Nvidia GeForce 8800
top related