CSCI 420: Computer Graphics
Hao Li
http://cs420.hao-li.com
Fall 2017
3.2 Hierarchical Modeling
1
3.2 Hierarchical Modeling Hao Li http://cs420.hao-li.com 1 - - PowerPoint PPT Presentation
Fall 2017 CSCI 420: Computer Graphics 3.2 Hierarchical Modeling Hao Li http://cs420.hao-li.com 1 Importance of shadows Source: UNC 2 Importance of shadows Source: UNC 3 Importance of shadows Source: UNC 4 Importance of shadows Without
CSCI 420: Computer Graphics
http://cs420.hao-li.com
Fall 2017
1
Source: UNC
2
Source: UNC
3
Source: UNC
4
Without shadows With shadows
Source: UNC
5
6
Reported to spend 50% of time rendering shadows!
point light source directional light source area light source
7
Source: UNC
Point Light Area Light umbra umbra penumbra
Hard shadow Soft shadow
8
[Foley, Ch. 16.4.4] [RTR 6.12]
9
10
transformation from simpler ones!
11
(xp, yp, zp) (x, y, z) y x xp
x
y yp = -yl shadow of point a point on object light source shadow plane (y = -yl)
12
13
M x y z 1 = w − xyl
y
−yl − zyl
y
1
M x y z 1 = x y z − y
yl
14
yl
GLfloat m[16] = {1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -1.0 / yl, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0};
15
glMatrixMode(GL_MODELVIEW); drawPolygon(); /* draw normally */ glPushMatrix(); /* save current matrix */ glTranslatef(xl, yl, zl); /* translate back */ glMultMatrixf(m); /* project */ glTranslatef(-xl, -yl, -zl); /* move light to origin */ drawPolygon(); /* draw polygon again for shadow */ glPopMatrix(); /* restore original transformation */ ...
16
17
when drawing shadow on surface
buffer
either the surface or the shadow (glPolygonOffset in OpenGL) z-buffer fighting no z-buffer fighting
18
draw surface (to get the color of surface)
draw shadow (on top of surface)
draw surface again (to get complete depth
buffer)
depth buffer color buffer shadow on surface
19
20
structured
model parameters
Physical realism
hierarchical
21
instances of an object
22
“standard” configuration
23
glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(...); glRotatef(...); glScalef(...); gluCylinder(...);
24
across different frames in time
GLuint torus = glGenLists(1); glNewList(torus, GL_COMPILE); Torus(8, 25); glEndList();
25
expressions themselves
current transformations and attributes
OpenGL extension instead
26
Base rotation θ, arm angle φ, joint angle ψ
27
void drawRobot(GLfloat theta, GLfloat phi, GLfloat psi) { glRotatef(theta, 0.0, 1.0, 0.0); drawBase(); glTranslatef(0.0, h1, 0.0); glRotatef(phi, 0.0, 0.0, 1.0); drawLowerArm(); glTranslatef(0.0, h2, 0.0); glRotatef(psi, 0.0, 0.0, 1.0); drawUpperArm(); }
28
glPushMatrix(); glRotatef(theta, ...); drawBase(); glPopMatrix(); glPushMatrix(); glRotatef(theta, ...); glTranslatef(...); glRotatef(phi, ...); drawLowerArm(); glPopMatrix(); ...etc...
29
drawBase(); drawLowerArm(); drawUpperArm();
30
GLfloat theta = 0.0; ...; /* update in idle callback */ GLfloat phi = 0.0; ...; /* update in idle callback */ GLuint arm = glGenLists(1); /* in init function */ glNewList(arm, GL_COMPILE); glRotatef(theta, 0.0, 1.0, 0.0); drawBase(); ... drawUpperArm(); glEndList(); /* in display callback */ glCallList(arm);
What is wrong?
31
32
void drawFigure() { glPushMatrix(); /* save */ drawTorso(); glTranslatef(...); /* move head */ glRotatef(...); /* rotate head */ drawHead(); glPopMatrix(); /* restore */ glPushMatrix(); glTranslatef(...); glRotatef(...); drawLeftUpperArm(); glTranslatef(...) glRotatef(...) drawLeftLowerArm(); glPopMatrix(); ... }
33
typedef struct treenode { GLfloat m[16]; void (*f) ( ); struct treenode *sibling; struct treenode *child; } treenode;
34
treenode torso, head, ...; /* in init function */ glLoadIdentity(); glRotatef(...); glGetFloatv(GL_MODELVIEW_MATRIX, torso.m);
torso.f = drawTorso; torso.sibling = NULL; torso.child = &head;
35
void traverse (treenode *root) { if (root == NULL) return; glPushMatrix(); glMultMatrixf(root->m); root->f(); if (root->child != NULL) traverse(root->child); glPopMatrix(); if (root->sibling != NULL) traverse(root->sibling); }
36
37
polygonal meshes, curves and surfaces
38
39