CSCI 420: Computer Graphics
Hao Li
http://cs420.hao-li.com
Fall 2014
3.2 Hierarchical Modeling
1
3.2 Hierarchical Modeling Hao Li http://cs420.hao-li.com 1 - - PowerPoint PPT Presentation
Fall 2014 CSCI 420: Computer Graphics 3.2 Hierarchical Modeling Hao Li http://cs420.hao-li.com 1 Roadmap Last lecture: Viewing and projection Today: - Shadows via projections - Hierarchical models Next: Polygonal Meshes, Curves
CSCI 420: Computer Graphics
http://cs420.hao-li.com
Fall 2014
1
2
Source: UNC
3
Source: UNC
4
Source: UNC
5
Without shadows With shadows
Source: UNC
6
Reported to spend 50% of time rendering shadows!
Source: Wikipedia
7
point light source directional light source area light source
8
Source: UNC
Point Light Area Light umbra umbra penumbra
Hard shadow Soft shadow
9
[Foley, Ch. 16.4.4] [RTR 6.12]
10
11
transformation from simpler ones!
12
(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)
13
14
M x y z 1 = w − xyl
y
−yl − zyl
y
1
M x y z 1 = x y z − y
yl
15
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};
16
glMatrixMode(GL_MODELVIEW); drawPolygon(); /* draw normally */
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 */ ...
17
18
when drawing shadow on surface
buffer
either the surface or the shadow (glPolygonOffset in OpenGL) z-buffer fighting no z-buffer fighting
19
draw surface
draw shadow
draw surface again
depth buffer color buffer shadow on surface
20
21
structured
model parameters
Physical realism
hierarchical
22
instances of an object
23
“standard” configuration
24
glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(...); glRotatef(...); glScalef(...); gluCylinder(...);
25
across different frames in time
GLuint torus = glGenLists(1); glNewList(torus, GL_COMPILE); Torus(8, 25); glEndList();
26
expressions themselves
current transformations and attributes
OpenGL extension instead
Base rotation θ, arm angle φ, joint angle ψ
28
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(); }
29
glPushMatrix(); glRotatef(theta, ...); drawBase(); glPopMatrix(); glPushMatrix(); glRotatef(theta, ...); glTranslatef(...); glRotatef(phi, ...); drawLowerArm(); glPopMatrix(); ...etc...
30
drawBase(); drawLowerArm(); drawUpperArm();
31
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?
32
33
void drawFigure() { glPushMatrix(); /* save */ drawTorso(); glTranslatef(...); /* move head */ glRotatef(...); /* rotate head */ drawHead(); glPopMatrix(); /* restore */ glPushMatrix(); glTranslatef(...); glRotatef(...); drawLeftUpperArm(); glTranslatef(...) glRotatef(...) drawLeftLowerArm(); glPopMatrix(); ... }
34
typedef struct treenode { GLfloat m[16]; void (*f) ( ); struct treenode *sibling; struct treenode *child; } treenode;
35
treenode torso, head, ...; /* in init function */ glLoadIdentity(); glRotatef(...); glGetFloatv(GL_MODELVIEW_MATRIX, torso.m);
torso.f = drawTorso; torso.sibling = NULL; torso.child = &head;
36
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); }
37
38
polygonal meshes, curves and surfaces
39
40