![Page 1: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/1.jpg)
CSE 5542 - Real Time Rendering
Week 10
![Page 2: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/2.jpg)
Spheres
![Page 3: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/3.jpg)
GLUT
void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks);
void glutWireSphere(GLdouble radius, GLint slices, GLint stacks);
![Page 4: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/4.jpg)
Direct Method
![Page 5: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/5.jpg)
GL_LINE_LOOP
![Page 6: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/6.jpg)
Problems - @ poles
![Page 7: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/7.jpg)
Use GL_TRIANGLE FAN
![Page 8: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/8.jpg)
Method II
![Page 9: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/9.jpg)
YAS (Yet Another Solution)http://www.andrewnoske.com/wiki/Generating_a_sphere_as_a_3D_mesh
![Page 10: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/10.jpg)
Platonic Solids
![Page 11: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/11.jpg)
ProcedureCreate Platonic Solid –
http://www.csee.umbc.edu/~squire/reference/polyhedra.shtml#icosahedron
Subdivide each face –http://donhavey.com/blog/tutorials/tutorial-3-the-icosahedron-
sphere/
![Page 12: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/12.jpg)
Think Sierpinski-like
![Page 13: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/13.jpg)
Method III
![Page 14: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/14.jpg)
![Page 15: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/15.jpg)
Impostor Spheres
http://www.arcsynthesis.org/gltut/Illumination/Tutorial%2013.html
![Page 16: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/16.jpg)
Impostors
![Page 17: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/17.jpg)
Clipping and Scan Conversion
![Page 18: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/18.jpg)
Cohen Sutherland in 3D• Use 6-bit outcodes • When needed, clip line segment against
planes
![Page 19: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/19.jpg)
Liang-Barsky Clipping• In (a): a4 > a3 > a2 > a1
– Intersect right, top, left, bottom: shorten
• In (b): a4 > a2 > a3 > a1
– Intersect right, left, top, bottom: reject
![Page 20: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/20.jpg)
Polygon Clipping• Not as simple as line segment clipping
– Clipping a line segment yields at most one line segment
– Clipping a polygon can yield multiple polygons
• Convex polygon is cool
20
![Page 21: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/21.jpg)
Fixes
![Page 22: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/22.jpg)
Tessellation and ConvexityReplace nonconvex (concave) polygons with triangular polygons (a tessellation)
22
![Page 23: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/23.jpg)
Clipping as a Black BoxLine segment clipping - takes in two vertices and produces either no vertices or vertices of a clipped segment
23
![Page 24: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/24.jpg)
Pipeline Clipping - Line SegmentsClipping side of window is independent of other sides
– Can use four independent clippers in a pipeline
24
![Page 25: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/25.jpg)
Pipeline Clipping of Polygons
• Three dimensions: add front and back clippers
• Small increase in latency
25
![Page 26: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/26.jpg)
Bounding BoxesUe an axis-aligned bounding box or extent
– Smallest rectangle aligned with axes that encloses the polygon
– Simple to compute: max and min of x and y
26
![Page 27: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/27.jpg)
Bounding boxesCan usually determine accept/reject
based only on bounding box
reject
accept
requires detailed clipping
27
![Page 28: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/28.jpg)
Clipping vs. Visibility• Clipping similar to hidden-surface
removal• Remove objects that are not visible to
the camera• Use visibility or occlusion testing early
in the process to eliminate as many polygons as possible before going through the entire pipeline
28
![Page 29: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/29.jpg)
Clipping
![Page 30: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/30.jpg)
Hidden Surface RemovalObject-space approach: use pairwise testing between polygons (objects)
Worst case complexity O(n2) for n polygons
partially obscuring can draw independently
30
![Page 31: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/31.jpg)
Better Still
![Page 32: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/32.jpg)
Better Still
![Page 33: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/33.jpg)
Painter’s AlgorithmRender polygons a back to front order so that polygons behind others are simply painted over
B behind A as seen by viewer Fill B then A
33
![Page 34: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/34.jpg)
Depth SortRequires ordering of polygons first
– O(n log n) calculation for ordering– Not all polygons front or behind all other polygons
Order polygons and deal with easy cases first, harder later
Polygons sorted by distance from COP
34
![Page 35: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/35.jpg)
Easy CasesA lies behind all other polygons
– Can render
Polygons overlap in z but not in either x or y
– Can render independently
35
![Page 36: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/36.jpg)
Hard Cases
Overlap in all directionsbut can one is fully on one side of the other
cyclic overlap
penetration
36
![Page 37: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/37.jpg)
Back-Face Removal (Culling)
face is visible iff 90 -90equivalently cos 0or v • n 0
- plane of face has form ax + by +cz +d =0- After normalization n = ( 0 0 1 0)T
+ Need only test the sign of c
- Will not work correctly if we have nonconvex objects
37
![Page 38: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/38.jpg)
Image Space Approach• Look at each ray (nm for an n x m frame
buffer)• Find closest of k polygons• Complexity O(nmk)• Ray tracing • z-buffer
38
![Page 39: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/39.jpg)
z-Buffer Algorithm• Use a buffer called z or depth buffer to store
depth of closest object at each pixel found so far• As we render each polygon, compare the depth
of each pixel to depth in z buffer• If less, place shade of pixel in color buffer and
update z buffer
39
![Page 40: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/40.jpg)
z-Bufferfor(each polygon P in the polygon list) do{ for(each pixel(x,y) that intersects P) do{ Calculate z-depth of P at (x,y) If (z-depth < z-buffer[x,y]) then{ z-buffer[x,y]=z-depth; COLOR(x,y)=Intensity of P at(x,y); } #If-programming-for alpha compositing: Else if (COLOR(x,y).opacity < 100%) then{ COLOR(x,y)=Superimpose COLOR(x,y) in front of Intensity of P at(x,y); } #Endif-programming-for } } display COLOR array.
![Page 41: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/41.jpg)
![Page 42: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/42.jpg)
Efficiency - ScanlineAs we move across a scan line, the depth changes satisfy ax+by+cz=0
Along scan line
y = 0z = - x
c
a
In screen space x = 1
42
![Page 43: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/43.jpg)
Scan-Line AlgorithmCombine shading and hsr through scan line algorithm
scan line i: no need for depth information, can only be in noor one polygon
scan line j: need depth information only when inmore than one polygon
43
![Page 44: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/44.jpg)
ImplementationNeed a data structure to store
– Flag for each polygon (inside/outside)– Incremental structure for scan lines
that stores which edges are encountered
– Parameters for planes
44
![Page 45: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/45.jpg)
Rasterization• Rasterization (scan conversion)
– Determine which pixels that are inside primitive specified by a set of vertices
– Produces a set of fragments– Fragments have a location (pixel location)
and other attributes such color and texture coordinates that are determined by interpolating values at vertices
• Pixel colors determined later using color, texture, and other vertex properties
![Page 46: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/46.jpg)
Diversion
![Page 47: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/47.jpg)
Rendering Spheres
![Page 48: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/48.jpg)
Spheres - Application
![Page 49: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/49.jpg)
Sphere-Definition
![Page 50: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/50.jpg)
Sphere-Lighting
![Page 51: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/51.jpg)
VBOs & VAOs
![Page 52: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/52.jpg)
Material Properties
![Page 53: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/53.jpg)
The Usual
![Page 54: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/54.jpg)
Finally
![Page 55: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/55.jpg)
But …
![Page 56: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/56.jpg)
Vertex Shader – Object Space
![Page 57: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/57.jpg)
Fragment Shader
![Page 58: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/58.jpg)
Yet Another Way
![Page 59: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/59.jpg)
Vertex Lighting Shaders I
59
// vertex shaderin vec4 vPosition;in vec3 vNormal;out vec4 color; //vertex shade
// light and material propertiesuniform vec4 AmbientProduct, DiffuseProduct, SpecularProduct;uniform mat4 ModelView;uniform mat4 Projection;uniform vec4 LightPosition;uniform float Shininess;
![Page 60: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/60.jpg)
Vertex Lighting Shaders II
60
void main(){ // Transform vertex position into eye coordinates vec3 pos = (ModelView * vPosition).xyz;
vec3 L = normalize( LightPosition.xyz - pos ); vec3 E = normalize( -pos ); vec3 H = normalize( L + E );
// Transform vertex normal into eye coordinates vec3 N = normalize( ModelView*vec4(vNormal, 0.0) ).xyz;
![Page 61: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/61.jpg)
Vertex Lighting Shaders II
61
void main(){ // Transform vertex position into eye coordinates vec3 pos = (ModelView * vPosition).xyz;
vec3 L = normalize( LightPosition.xyz - pos ); vec3 E = normalize( -pos ); vec3 H = normalize( L + E );
// Transform vertex normal into eye coordinates vec3 N = normalize( ModelView*vec4(vNormal, 0.0) ).xyz;
![Page 62: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/62.jpg)
Vertex Lighting Shaders III
62
// Compute terms in the illumination equation vec4 ambient = AmbientProduct;
float Kd = max( dot(L, N), 0.0 ); vec4 diffuse = Kd*DiffuseProduct; float Ks = pow( max(dot(N, H), 0.0), Shininess ); vec4 specular = Ks * SpecularProduct; if( dot(L, N) < 0.0 ) specular = vec4(0.0, 0.0, 0.0, 1.0); gl_Position = Projection * ModelView * vPosition;
color = ambient + diffuse + specular; color.a = 1.0;}
![Page 63: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/63.jpg)
Vertex Lighting Shaders IV
63
// fragment shader
in vec4 color;
void main() { gl_FragColor = color;}
![Page 64: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/64.jpg)
Scan-Line Rasterization
![Page 65: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/65.jpg)
ScanConversion -Line Segments• Start with line segment in window
coordinates with integer values for endpoints
• Assume implementation has a write_pixel function
y = mx + h
x
ym
![Page 66: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/66.jpg)
DDA Algorithm• Digital Differential Analyzer
– Line y=mx+ h satisfies differential equation
dy/dx = m = Dy/Dx = y2-y1/x2-x1
• Along scan line Dx = 1For(x=x1; x<=x2,ix++) { y+=m; display (x, round(y), line_color)}
![Page 67: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/67.jpg)
ProblemDDA = for each x plot pixel at closest y
– Problems for steep lines
![Page 68: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/68.jpg)
Bresenham’s Algorithm• DDA requires one floating point addition per
step
• Eliminate computations through Bresenham’s algorithm
• Consider only 1 m 0– Other cases by symmetry
• Assume pixel centers are at half integers
![Page 69: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/69.jpg)
Main PremiseIf we start at a pixel that has been written, there are only two candidates for the next pixel to be written into the frame buffer
![Page 70: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/70.jpg)
Candidate Pixels1 m 0
last pixel
candidates
Note that line could havepassed through anypart of this pixel
![Page 71: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/71.jpg)
Decision Variable
-
d = Dx(b-a)
d is an integerd > 0 use upper pixeld < 0 use lower pixel
![Page 72: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/72.jpg)
Incremental FormInspect dk at x = k
dk+1= dk –2Dy, if dk <0dk+1= dk –2(Dy- Dx), otherwise
For each x, we need do only an integer addition and test
Single instruction on graphics chips
![Page 73: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/73.jpg)
Polygon Scan Conversion• Scan Conversion = Fill• How to tell inside from outside
– Convex easy– Nonsimple difficult– Odd even test
• Count edge crossings
![Page 74: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/74.jpg)
Filling in the Frame BufferFill at end of pipeline
– Convex Polygons only– Nonconvex polygons assumed to
have been tessellated– Shades (colors) have been computed
for vertices (Gouraud shading)– Combine with z-buffer algorithm
• March across scan lines interpolating shades
• Incremental work small
![Page 75: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/75.jpg)
Using Interpolation
span
C1
C3
C2
C5
C4scan line
C1 C2 C3 specified by glColor or by vertex shadingC4 determined by interpolating between C1 and C2
C5 determined by interpolating between C2 and C3
interpolate between C4 and C5 along span
![Page 76: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/76.jpg)
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Scan Line Fill Can also fill by maintaining a data structure of all intersections of polygons with scan lines
– Sort by scan line– Fill each span
vertex order generated by vertex list desired order
![Page 77: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/77.jpg)
Data Structure
![Page 78: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/78.jpg)
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Aliasing• Ideal rasterized line should be 1 pixel
wide
• Choosing best y for each x (or visa versa) produces aliased raster lines
![Page 79: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/79.jpg)
Antialiasing by Area Averaging• Color multiple pixels for each x depending on
coverage by ideal line
original antialiased
magnified
![Page 80: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/80.jpg)
Polygon Aliasing• Aliasing problems can be serious for
polygons– Jaggedness of edges– Small polygons neglected– Need compositing so colorof one polygon does nottotally determine color ofpixel
All three polygons should contribute to color
![Page 81: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/81.jpg)
Hierarchical Modeling
![Page 82: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/82.jpg)
Cars, Robots, Solar System
![Page 83: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/83.jpg)
The Terminator
![Page 84: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/84.jpg)
Our Goal
![Page 85: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/85.jpg)
Heliocentric Coordinates
Heliocentric ecliptic coordinates. The origin is the center of the Sun. The fundamental plane is the plane of the ecliptic. The primary direction (the x axis) is the vernal equinox. A right-handed convention specifies a y axis 90° to the east in the fundamental plane; the z axis points toward the north ecliptic pole. The reference frame is relatively stationary, aligned with the vernal equinox.
![Page 86: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/86.jpg)
Inclinations
![Page 87: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/87.jpg)
Axial Tilt
![Page 88: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/88.jpg)
W. Pedia says
To understand axial tilt, we employ the right-hand rule. When the fingers of the right hand are curled around in the direction of the planet's rotation, the thumb points in the direction of the north pole.
![Page 89: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/89.jpg)
Axial Tilts of Planets
The axial tilt of three planets: Earth, Uranus, and Venus. Here, a vertical line (black) is drawn perpendicular to the plane of each planet's orbit. The angle between this line and the planet's north pole (red) is the tilt. The surrounding arrows (green) show the direction of the planet's rotation.
![Page 90: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/90.jpg)
Ecliptic Coordinate System
where \epsilon is the obliquity of the ecliptic.
![Page 91: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/91.jpg)
Roots
![Page 92: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/92.jpg)
Back 2 Earth
![Page 93: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/93.jpg)
93
Instance Transformation• Start with prototype object• Each appearance of object in model is instance
– Must scale, orient, position– Defines instance transformation
![Page 94: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/94.jpg)
94
Symbol-Instance Table
![Page 95: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/95.jpg)
95
Relationships• Car
– Chassis + 4 identical wheels– Two symbols
• Rate of forward motion function of rotational speed of wheels
![Page 96: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/96.jpg)
96
Move The Carcar(speed){ chassis() wheel(right_front); wheel(left_front); wheel(right_rear); wheel(left_rear);}
![Page 97: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/97.jpg)
97
Graphs – Composition of Car• Set of nodes and edges (links)• Edge connects a pair of nodes
– Directed or undirected• Cycle: directed path that is a loop
loop
![Page 98: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/98.jpg)
98
Tree – Composition of CarGraph in which each node (except the root) has exactly one parent node
– May have multiple children– Leaf or terminal node: no children
root node
leaf node
![Page 99: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/99.jpg)
99
Tree Model of Car
![Page 100: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/100.jpg)
100
DAG ModelAll the wheels are identical
Not much different than dealing with a tree
![Page 101: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/101.jpg)
101
Robot Arm
robot arm parts in their own coodinate systems
![Page 102: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/102.jpg)
102
Articulated Models– Parts connected at joints– Specify state of model by joint angles
![Page 103: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/103.jpg)
103
Relationships - Composition- Base- Lower Arm- Upper Arm
![Page 104: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/104.jpg)
Base- Single angle determines position- Is cylinder
![Page 105: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/105.jpg)
Lower ArmAttached to base
– Position depends on rotation of base– Also translate relative to base, rotate about
connecting joint– Is cube
![Page 106: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/106.jpg)
Upper ArmUpper arm attached to lower arm
– Its position depends on both base and lower arm
– Translate relative to lower arm and rotate about joint connecting to lower arm
![Page 107: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/107.jpg)
Upper ArmUpper arm attached to lower arm
– Its position depends on both base and lower arm
– Translate relative to lower arm and rotate about joint connecting to lower arm
![Page 108: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/108.jpg)
Do the same …
![Page 109: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/109.jpg)
109
Required Matrices
![Page 110: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/110.jpg)
BaseRotation of base: Rb
– Apply M = Rb to base
![Page 111: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/111.jpg)
Lower ArmTranslate lower arm relative to base: Tlu
Rotate lower arm around joint: Rlu
– Apply M = Rb Tlu Rlu to lower arm
![Page 112: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/112.jpg)
Upper ArmTranslate upper arm relative to upper arm: Tuu
Rotate upper arm around joint: Ruu
– Apply M = Rb Tlu Rlu Tuu Ruu to upper arm
![Page 113: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/113.jpg)
113
Simple Robotmat4 ctm;robot_arm(){ ctm = RotateY(theta); base(); ctm *= Translate(0.0, h1, 0.0); ctm *= RotateZ(phi); lower_arm(); ctm *= Translate(0.0, h2, 0.0); ctm *= RotateZ(psi); upper_arm();}
![Page 114: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/114.jpg)
114
Tree Model of RobotCode shows relationships between parts of model
– Can change shape/texture w/o altering relationships
![Page 115: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/115.jpg)
115
Possible Node Structure
Code for drawing part orpointer to drawing function
linked list of pointers to children
matrix relating node to parent
![Page 116: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/116.jpg)
Do the same …
![Page 117: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/117.jpg)
Generalizations
![Page 118: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/118.jpg)
118
Generalizations• Need to deal with multiple children
– How do we represent a more general tree?
– How do we traverse such a data structure?
• Animation– How to use dynamically?– Can we create and delete nodes
during execution?
![Page 119: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/119.jpg)
119
Breadth-First Tree
![Page 120: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/120.jpg)
Solar System ?
![Page 121: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/121.jpg)
121
Humanoid Figure
![Page 122: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/122.jpg)
122
Building the Model• Implementation using quadrics: ellipsoids and
cylinders• Access parts through functions
– torso()– left_upper_arm()
• Matrices describe position of node with respect to parent– Mlla positions leftlowerleg with respect to
leftupperarm
![Page 123: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/123.jpg)
123
Matrices Tree
![Page 124: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/124.jpg)
124
Display and Traversal• The position determined by 11 joint
angles (two for the head and one for each other part)
• Display of the tree requires a graph traversal– Visit each node once– Display function at each node pertaining to
part – Applying correct transformation matrix for
position and orientation
![Page 125: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/125.jpg)
125
Transformation Matrices10 relevant matrices
– M positions and orients entire figure through the torso which is the root node
– Mh positions head with respect to torso
– Mlua, Mrua, Mlul, Mrul position arms and legs with respect to torso
– Mlla, Mrla, Mlll, Mrll position lower parts of limbs with respect to corresponding upper limbs
![Page 126: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/126.jpg)
126
Stack-based Traversal• Set model-view matrix to M and draw
torso• Set model-view matrix to MMh and
draw head• For left-upper arm need MMlua and so on
• No need recomputing Mmlua – Use the matrix stack to store M and other
matrices in tree traversal
![Page 127: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/127.jpg)
127
Old Style GL Codefigure() { PushMatrix() torso(); Rotate (…); head(); PopMatrix(); PushMatrix(); Translate(…); Rotate(…); left_upper_arm(); PopMatrix(); PushMatrix();
save present model-view matrix
update model-view matrix for head
recover original model-view matrix
save it again
update model-view matrix for left upper arm
recover and save original model-view matrix again
rest of code
![Page 128: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/128.jpg)
128
Tree Data Structure• Represent tree and algorithm to
traverse tree• We will use a left-child right sibling
structure– Uses linked lists– Each node in data structure is two pointers– Left: next node– Right: linked list of children
![Page 129: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/129.jpg)
In GLSL
![Page 130: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/130.jpg)
In GLSL
![Page 131: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/131.jpg)
Still Use
![Page 132: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/132.jpg)
132
Left-Child Right-Sibling Tree
![Page 133: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/133.jpg)
133
Tree node StructureAt each node
- Pointer to sibling– Pointer to child– Pointer to a function that draws the object
represented by the node– Homogeneous coordinate matrix to multiply on
the right of the current model-view matrix• Represents changes going from parent to node• In OpenGL this matrix is a 1D array storing matrix
by columns
![Page 134: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/134.jpg)
134
Ctypedef struct treenode{ mat4 m; void (*f)(); struct treenode *sibling; struct treenode *child;} treenode;
![Page 135: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/135.jpg)
135
torso and head nodestreenode torso_node, head_node, lua_node, … ;torso_node.m = RotateY(theta[0]);torso_node.f = torso;torso_node.sibling = NULL;torso_node.child = &head_node;
head_node.m = translate(0.0, TORSO_HEIGHT+0.5*HEAD_HEIGHT, 0.0)*RotateX(theta[1])*RotateY(theta[2]);
head_node.f = head;head_node.sibling = &lua_node;head_node.child = NULL;
![Page 136: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/136.jpg)
136
Notes• Position determined by 11 joint angles in theta[11]• Animate by changing angles and redisplaying• Form required matrices using Rotate and Translate
![Page 137: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/137.jpg)
137
Preorder Traversalvoid traverse(treenode* root){ if(root==NULL) return; mvstack.push(model_view); model_view = model_view*root->m; root->f(); if(root->child!=NULL) traverse(root->child); model_view = mvstack.pop(); if(root->sibling!=NULL) traverse(root->sibling);}
![Page 138: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/138.jpg)
138
Notes• Save model-view matrix before
multiplying it by node matrix – Updated matrix applies to children but not to
siblings • Traversal applies to any left-child right-
sibling tree– Particular tree encoded in definition of
individual nodes• Order of traversal matters given state
changes in the functions
![Page 139: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/139.jpg)
139
Dynamic TreesUse pointers, the structure can be dynamic
typedef treenode *tree_ptr;tree_ptr torso_ptr;torso_ptr = malloc(sizeof(treenode));
Definition of nodes and traversal are essentially the same as before but we can add and delete nodes during execution
![Page 140: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/140.jpg)
140
The Real Thing
![Page 141: CSE 5542 - Real Time Rendering Week 10. Spheres GLUT void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble](https://reader035.vdocuments.net/reader035/viewer/2022062217/56649e2b5503460f94b191af/html5/thumbnails/141.jpg)
As Opposed