CSE 5542 - Real Time Rendering Week 11, 12, 13
Full text
(2) Lab 4 Stuff.
(3) Spheres.
(4) Direct Method.
(5) GL_LINE_LOOP.
(6) Problems - @ poles.
(7) Use GL_TRIANGLE FAN .
(8) Method II.
(9) YAS (Yet Another Solution). http://www.andrewnoske.com/wiki/Generating_a_sphere_as_a_3D_mesh.
(10) Platonic Solids.
(11) Procedure. Create 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/. .
(12) Think Sierpinski-like.
(13) Method III.
(14)
(15) Impostor Spheres. http://www.arcsynthesis.org/gltut/Illumination/Tutorial%2013.html.
(16) Impostors.
(17) Rendering Spheres.
(18) Spheres - Application.
(19) Sphere-Definition.
(20) Sphere-Lighting.
(21) VBOs & VAOs.
(22) Material Properties.
(23) The Usual.
(24) Finally.
(25) But ….
(26) Vertex Shader – Object Space.
(27) Fragment Shader.
(28) Yet Another Way .
(29) Vertex Lighting Shaders I. // vertex shader. in vec4 vPosition;. in vec3 vNormal;. out vec4 color; //vertex shade. // light and material properties. uniform vec4 AmbientProduct, DiffuseProduct, SpecularProduct;. uniform mat4 ModelView;. uniform mat4 Projection;. uniform vec4 LightPosition;. uniform float Shininess;. 29.
(30) Vertex Lighting Shaders II. 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;. 30.
(31) Vertex Lighting Shaders II. 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;. 31.
(32) Vertex Lighting Shaders III. // 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;. }. 32.
(33) Vertex Lighting Shaders IV. // fragment shader. in vec4 color;. void main() . { . gl_FragColor = color;. } . 33.
(34) Hierarchical Modeling .
(35) Cars, Robots, Solar System.
(36) Our Goal J.
(37) 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..
(38) Inclinations.
(39) Axial Tilt.
(40) 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..
(41) 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..
(42) Ecliptic Coordinate System. where \epsilon is the obliquity of the ecliptic..
(43) Roots.
(44) Back 2 Earth J.
(45) Texture Mapping. Courtesy: Ed Angel. 45.
(46) Limits of Geometric Modeling.
(47) Millions of Polygons/Second. The image cannot be displayed. Your computer may not have enough memory to open the image, or the image may have been corrupted. Restart your computer, and then open the file again. If the red x still appears, you may have to delete the image and then insert it again..
(48) Cannot Do.
(49) Use Textures.
(50) Orange.
(51) Orange Spheres.
(52) Texture Mapping.
(53) Looking Better.
(54) Still Not Enough.
(55) Local Variation.
(56) Texture Mapping.
(57) Globe.
(58) Not Mercator.
(59) Yet Another Fruit.
(60) Three Types of Mapping. 60.
(61) Generating Textures.
(62) Pictures.
(63) Algorithms.
(64) Checkerboard Texture. GLubyte image[64][64][3];. // Create a 64 x 64 checkerboard pattern. for ( int i = 0; i < 64; i++ ) {. for ( int j = 0; j < 64; j++ ) {. GLubyte c = (((i & 0x8) == 0) ^ ((j & 0x8) == 0)) * 255;. image[i][j][0] = c;. image[i][j][1] = c;. image[i][j][2] = c;. 64.
(65) Brick Wall.
(66) Noise.
(67) Marble.
(68) Texture Mapping. geometric model 68. texture mapped.
(69) Environment Mapping. 69.
(70) Bump Mapping. 70.
(71) Three Types Texture mapping. smooth shading. 71. environment. mapping. bump mapping.
(72) Texture Mapping - Pipeline . Mapping techniques are implemented at the end of the rendering pipeline. – Very efficient because few polygons make it past the clipper . Vertices. G eometry processing. Pixels. Pixel processing. 72. Rasteriz ation. Fra gment processing. Frame buffer.
(73) Mapping Mechanics. 3 or 4 coordinate systems involved. 2D image. 3D surface. 73.
(74) Texture Mapping. parametric coordinates. texture coordinates. world coordinates. 74. window coordinates.
(75) Coordinate Systems. • Parametric coordinates. – Model curves and surfaces. • Texture coordinates. – Identify points in image to be mapped. • Object or World Coordinates. – Conceptually, where the mapping takes place. • Screen Coordinates. – Where the final image is really produced. 75.
(76) Mapping Functions. Mapping from texture coords to point on surface. • Appear to need three functions. x = x(s,t). y = y(s,t). z = z(s,t). (x,y,z). t. • Other direction needed. 76. s.
(77) Backward Mapping. Mechanics. – Given a pixel want point on object it corresponds. – Given point on object want point in the texture it corresponds. Need a map of the form . s = s(x,y,z). t = t(x,y,z). Such functions are difficult to find in general . . 77.
(78) Two-part mapping. • First map texture to a simple intermediate surface. • Map to cylinder. 78.
(79) Cylindrical Mapping. parametric cylinder. x = r cos 2π u. y = r sin 2πu. z = v/h. maps rectangle in u,v space to cylinder. of radius r and height h in world coordinates. s = u. t = v. maps from texture space. 79.
(80) Spherical Map. We can use a parametric sphere. x = r cos 2πu. y = r sin 2πu cos 2πv. z = r sin 2πu sin 2πv. in a similar manner to the cylinder. but have to decide where to put. the distortion. Spheres are used in environmental maps. 80.
(81) Box Mapping. • Easy to use with simple orthographic projection. • Also used in environment maps. 81.
(82) Second Mapping. Map from intermediate object to actual object. – Normals from intermediate to actual. – Normals from actual to intermediate. – Vectors from center of intermediate . actual. intermediate. 82.
(83) Aliasing Point sampling of texture leads to aliasing errors miss blue stripes. point samples in texture space 83. point samples in u,v (or x,y,z) space.
(84) Anti-Aliasing in Textures. point. sampling. mipmapped. point. sampling. 84. linear. filtering. mipmapped. linear. filtering.
(85) Area Averaging A better but slower option is to use area averaging. preimage Note that preimage of pixel is curved 85. pixel.
(86) OpenGL Texture. 86.
(87) Basic Stragegy. Three steps . 1. Specify texture. • read or generate image. • assign to texture. • enable texturing. 2. Assign texture coordinates to vertices. • Proper mapping function is left to application. 3. Specify texture parameters. • wrapping, filtering. 87.
(88) Texture Mapping. y. z. x. geometry. t. 88. image. s. display.
(89) Texture Example. 89.
(90) Texture Mapping in OpenGL. vertices. image. 90. geometry pipeline. pixel pipeline. fragment processo r.
(91) Specifying a Texture Image. • Define a texture image from an array of texels (texture elements) in CPU memory. Glubyte my_texels[512][512];. • Define as any other pixel map. – Scanned image. – Generate by application code. • Enable texture mapping. – glEnable(GL_TEXTURE_2D). – OpenGL supports 1-4 dimensional texture maps. 91.
(92) Defining a Texture Image. glTexImage2D( target, level, components, w, h, border, format, type, texels. target: type of texture, e.g. GL_TEXTURE_2D. level: used for mipmapping. components: elements per texel. w, h: width and height of texels in pixels. border: used for smoothing . format and type: describe texels. texels: pointer to texel array. glTexImage2D(GL_TEXTURE_2D, 0, 3, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, my_texels);. 92. );.
(93) Mapping a Texture. • Based on parametric texture coordinates. • glTexCoord*() specified at each vertex. Texture Space. t. 0, 1. Object Space. 1, 1. (s, t) = (0.2, 0.8). A. a. c. (0.4, 0.2). b. 0, 0. 93. B. 1, 0. s. C. (0.8, 0.4).
(94) GLSL - Typical Code. offset = 0;. GLuint vPosition = glGetAttribLocation( program, "vPosition" );. glEnableVertexAttribArray( vPosition );. glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0,BUFFER_OFFSET(offset) );. offset += sizeof(points);. GLuint vTexCoord = glGetAttribLocation( program, "vTexCoord" );. glEnableVertexAttribArray( vTexCoord );. glVertexAttribPointer( vTexCoord, 2,GL_FLOAT,. GL_FALSE, 0, BUFFER_OFFSET(offset) );. 94.
(95) Adding Texture Coordinates. void quad( int a, int b, int c, int d ). {. quad_colors[Index] = colors[a];. points[Index] = vertices[a];. tex_coords[Index] = vec2( 0.0, 0.0 );. index++;. quad_colors[Index] = colors[a];. points[Index] = vertices[b];. tex_coords[Index] = vec2( 0.0, 1.0 );. Index++;. // other vertices. }. 95.
(96) Role of Interpolation.
(97) Interpolation. OpenGL uses interpolation to find proper texels from specified texture coordinates. Can be distorted. good selection. of tex coordinates. 97. poor selection. of tex coordinates. texture stretched. over trapezoid . showing effects of . bilinear interpolation.
(98) Interpolation.
(99) Control of Texture Mapping.
(100) Texture Parameters. OpenGL has a variety of parameters that determine how texture is applied. – Wrapping parameters determine what happens if s and t are outside the (0,1) range. – Filter modes allow us to use area averaging instead of point samples. – Mipmapping allows us to use textures at multiple resolutions. – Environment parameters determine how texture mapping interacts with shading. 100.
(101) Wrapping Mode. Clamping: if s,t > 1 use 1, if s,t <0 use 0. Wrapping: use s,t modulo 1. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ). glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ). t. s. texture. GL_REPEAT. wrapping. GL_CLAMP. wrapping.
(102) Magnification/Minification More than one texel can cover a pixel (minification) or. more than one pixel can cover a texel (magnification). Can use point sampling (nearest texel) or linear filtering. ( 2 x 2 filter) to obtain texture values. Texture. Polygon. Magnification. 102. Texture. Polygon. Minification.
(103) Filter Modes. Modes determined by. – glTexParameteri( target, type, mode ) . glTexParameteri(GL_TEXTURE_2D, GL_TEXURE_MAG_FILTER,. GL_NEAREST);. glTexParameteri(GL_TEXTURE_2D, GL_TEXURE_MIN_FILTER,. GL_LINEAR);. Note that linear filtering requires a border of an . extra texel for filtering at edges (border = 1). 103.
(104) Mipmapped Textures. • Mipmapping allows for prefiltered texture maps of decreasing resolutions. • Lessens interpolation errors for smaller textured objects. • Declare mipmap level during texture definition. glTexImage2D( GL_TEXTURE_*D, level, … ). 104.
(105) MipMaps.
(106) Mip-Mapping.
(107) Mip-Mapping.
(108) Example. point. sampling. mipmapped. point. sampling. 108. linear. filtering. mipmapped. linear. filtering.
(109) Texture Functions. • Controls how texture is applied. • glTexEnv{fi}[v]( GL_TEXTURE_ENV, prop, param ). • GL_TEXTURE_ENV_MODE modes. – GL_MODULATE: modulates with computed shade – GL_BLEND: blends with an environmental color – GL_REPLACE: use only texture color. . . – GL(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);. • Set blend color with GL_TEXTURE_ENV_COLOR. 109.
(110) Using Texture Objects. 1. 2. 3. 4. 5. 6. 7. 8. . specify textures in texture objects. set texture filter . set texture function . set texture wrap mode. set optional perspective correction hint. bind texture object . enable texturing. supply texture coordinates for vertex. – . coordinates can also be generated. 110.
(111) Other Texture Features. • Environment Maps. – Start with image of environment through a wide angle lens . • Can be either a real scanned image or an image created in OpenGL. – Use this texture to generate a spherical map. – Alternative is to use a cube map. • Multitexturing. – Apply a sequence of textures through cascaded texture units. 111.
(112) GLSL.
(113) Samplers. https://www.opengl.org/wiki/Sampler_(GLSL).
(114) Applying Textures. • Textures are applied during fragment shading by a sampler. • Samplers return a texture color from a texture object. in vec4 color; //color from rasterizer. in vec2 texCoord; //texure coordinate from rasterizer. uniform sampler2D texture; //texture object from application. void main() { . gl_FragColor = color * texture2D( texture, texCoord );. } . 114.
(115) Vertex Shader. • Usually vertex shader will output texture coordinates to be rasterized. • Must do all other standard tasks too. – Compute vertex position. – Compute vertex color if needed. in vec4 vPosition; //vertex position in object coordinates. in vec4 vColor; //vertex color from application. in vec2 vTexCoord; //texture coordinate from application . out vec4 color; //output color to be interpolated. out vec2 texCoord; //output tex coordinate to be interpolated. 115.
(116) Adding Texture Coordinates. void quad( int a, int b, int c, int d ). {. quad_colors[Index] = colors[a];. points[Index] = vertices[a];. tex_coords[Index] = vec2( 0.0, 0.0 );. index++;. quad_colors[Index] = colors[a];. points[Index] = vertices[b];. tex_coords[Index] = vec2( 0.0, 1.0 );. Index++;. // other vertices. }. 116.
(117) Texture Object. GLuint textures[1];. glGenTextures( 1, textures );. glBindTexture( GL_TEXTURE_2D, textures[0] );. glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, TextureSize, . TextureSize, 0, GL_RGB, GL_UNSIGNED_BYTE, image );. glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, . GL_REPEAT );. glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, . GL_REPEAT );. glTexParameterf( GL_TEXTURE_2D, . GL_TEXTURE_MAG_FILTER, GL_NEAREST );. glTexParameterf( GL_TEXTURE_2D, . GL_TEXTURE_MIN_FILTER, GL_NEAREST );. glActiveTexture( GL_TEXTURE0 ); . 117.
(118) Linking with Shaders. GLuint vTexCoord = glGetAttribLocation( program, "vTexCoord" );. glEnableVertexAttribArray( vTexCoord );. glVertexAttribPointer( vTexCoord, 2, GL_FLOAT, GL_FALSE, 0,. BUFFER_OFFSET(offset) );. // Set the value of the fragment shader texture sampler variable. // ("texture") to the the appropriate texture unit. In this case,. // zero, for GL_TEXTURE0 which was previously set by calling. // glActiveTexture().. glUniform1i( glGetUniformLocation(program, "texture"), 0 );. 118.
(119) Vertex Shader Applications. • Moving vertices. – Morphing . – Wave motion. – Fractals. • Lighting. – More realistic models. – Cartoon shaders. 119.
(120) Wave Motion Vertex Shader. uniform float time;. uniform float xs, zs, // frequencies . uniform float h; // height scale. uniform mat4 ModelView, Projection;. in vec4 vPosition;. void main() {. vec4 t =vPosition;. t.y = vPosition.y . + h*sin(time + xs*vPosition.x). + h*sin(time + zs*vPosition.z);. gl_Position = Projection*ModelView*t;. }. 120.
(121) Particle System. uniform vec3 init_vel;. uniform float g, m, t;. uniform mat4 Projection, ModelView;. in vPosition;. void main(){. vec3 object_pos;. object_pos.x = vPosition.x + vel.x*t;. object_pos.y = vPosition.y + vel.y*t . + g/(2.0*m)*t*t;. object_pos.z = vPosition.z + vel.z*t;. gl_Position = Projection*. ModelView*vec4(object_pos,1);. }. 121.
(122) Example. http://www.lighthouse3d.com/tutorials/glsl-coretutorial/glsl-core-tutorial-texturing-with-images/.
(123) Example. http://www.lighthouse3d.com/tutorials/glsl-tutorial/ simple-texture/.
(124) Fragment Shader Texture mapping. smooth shading. 124. environment. mapping. bump mapping.
(125) Cube Maps. • We can form a cube map texture by defining six 2D texture maps that correspond to the sides of a box. • Supported by OpenGL. • Also supported in GLSL through cubemap sampler. vec4 texColor = textureCube(mycube, texcoord);. • Texture coordinates must be 3D. 125.
(126) Environment Map. Use reflection vector to locate texture in cube map. 126.
(127) Environment Maps with Shaders. • Computed in world coordinates . – keep track of modeling matrix & pass as a uniform variable. • Use reflection map or refraction map . • Simulate water. 127.
(128) Reflection Map Vertex Shader. uniform mat4 Projection, ModelView, NormalMatrix;. in vec4 vPosition;. in vec4 normal;. out vec3 R;. void main(void). {. gl_Position = Projection*ModelView*vPosition;. vec3 N = normalize(NormalMatrix*normal);. vec4 eyePos = ModelView*gvPosition;. R = reflect(-eyePos.xyz, N);. }. 128.
(129) Reflection Map Fragment Shader. in vec3 R;. uniform samplerCube texMap;. void main(void). {. gl_FragColor = textureCube(texMap, R);. }. 129.
(130) Bump Mapping. • Perturb normal for each fragment. • Store perturbation as textures. 130.
(131) Normalization Maps • Cube maps can be viewed as lookup tables 1-4 dimensional variables • Vector from origin is pointer into table • Example: store normalized value of vector in the map – Same for all points on that vector – Use “normalization map” instead of normalization function – Lookup replaces sqrt, mults and adds 131.
(132) Fragment Program Examples • Mapping methods – Texture mapping – Environmental (reflection) mapping • Variant of texture mapping. – Bump mapping • Solves flatness problem of texture mapping. 132.
(133) Back 2 Orange.
(134) The Orange. • Texture map a photo of an orange onto a surface. – Captures dimples. – Will not be correct if we move viewer or light. – We have shades of dimples rather than their correct orientation. • Ideally perturb normal across surface of object and compute a new color at each interior point. 134.
(135) Bump Mapping (Blinn) Consider a smooth surface n. p. 135.
(136) Rougher Version n’ p’ p. 136.
(137) Equations. p(u,v) = [x(u,v), y(u,v), z(u,v)]T pu=[ ∂x/ ∂u, ∂y/ ∂u, ∂z/ ∂u]T pv=[ ∂x/ ∂v, ∂y/ ∂v, ∂z/ ∂v]T n = (pu × pv ) / | pu × pv |. 137.
(138) Tangent Plane pv n pu. 138.
(139) Displacement Function. p’ = p + d(u,v) n. d(u,v) is the bump or displacement function. |d(u,v)| << 1. 139.
(140) Perturbed Normal. n’ = p’u × p’v. p’u = pu + (∂d/∂u)n + d(u,v)nu. p’v = pv + (∂d/∂v)n + d(u,v)nv. If d is small, we can neglect last term. 140.
(141) Approximating the Normal. n’ = p’u × p’v. ≈ n + (∂d/∂u)n × pv + (∂d/∂v)n × pu . The vectors n × pv and n × pu lie . in the tangent plane . Hence the normal is displaced in the tangent plane. Must precompute the arrays ∂d/ ∂u and ∂d/ ∂v . Finally,we perturb the normal during shading. 141.
(142) Hierarchical Modeling .
(143) Cars, Robots, Solar System.
(144) The Terminator.
(145) Instance Transformation. • Start with prototype object. • Each appearance of object in model is instance. – Must scale, orient, position. – Defines instance transformation. 145.
(146) Symbol-Instance Table. 146.
(147) Relationships. • Car. – Chassis + 4 identical wheels. – Two symbols. • Rate of forward motion function of rotational speed of wheels. 147.
(148) Move The Car. car(speed). {. chassis(). wheel(right_front);. wheel(left_front);. wheel(right_rear);. wheel(left_rear);. }. 148.
(149) 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. 149.
(150) Tree – Composition of Car. Graph 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. 150.
(151) Tree Model of Car. 151.
(152) DAG Model All the wheels are identical. Not much different than dealing with a tree. 152.
(153) Robot Arm. robot arm. 153. parts in their own . coodinate systems.
(154) Articulated Models. – Parts connected at joints. – Specify state of model by joint angles. 154.
(155) Relationships - Composition. - Base. - Lower Arm. - Upper Arm. 155.
(156) Base. - Single angle determines position - Is cylinder.
(157) Lower Arm. Attached to base. – Position depends on rotation of base. – Also translate relative to base, rotate about connecting joint. – Is cube.
(158) Upper Arm. Upper 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.
(159) Upper Arm. Upper 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.
(160) Do the same ….
(161) Required Matrices. 161.
(162) Base. Rotation of base: Rb. – Apply M = Rb to base.
(163) Lower Arm. Translate lower arm relative to base: Tlu. Rotate lower arm around joint: Rlu. – Apply M = Rb Tlu Rlu to lower arm.
(164) Upper Arm. Translate upper arm relative to upper arm: Tuu. Rotate upper arm around joint: Ruu. – Apply M = Rb Tlu Rlu Tuu Ruu to upper arm.
(165) Simple Robot. mat4 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();. }. 165.
(166) Tree Model of Robot. Code shows relationships between parts of model. – Can change shape/texture w/o altering relationships. 166.
(167) Possible Node Structure. Code for drawing part or. pointer to drawing function . linked list of pointers to children. matrix relating node to parent. 167.
(168) Do the same ….
(169) Generalizations.
(170) 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?. 170.
(171) Breadth-First Tree. 171.
(172) Solar System ?.
(173) Humanoid Figure. 173.
(174) 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. 174.
(175) Matrices Tree . 175.
(176) 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. 176.
(177) Transformation Matrices. 10 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. 177.
(178) 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. 178.
(179) Old Style GL Code. figure() {. PushMatrix(). torso();. Rotate (…);. head();. PopMatrix();. PushMatrix();. Translate(…);. Rotate(…);. left_upper_arm();. PopMatrix();. PushMatrix();. 179. 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.
(180) 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. 180.
(181) In GLSL.
(182) In GLSL.
(183) Still Use.
(184) Left-Child Right-Sibling Tree. 184.
(185) Tree node Structure. At 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 . 185.
(186) C. typedef struct treenode. {. mat4 m;. void (*f)();. struct treenode *sibling;. struct treenode *child;. } treenode;. 186.
(187) torso and head nodes treenode 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;. 187.
(188) Notes. • Position determined by 11 joint angles in theta[11]. • Animate by changing angles and redisplaying. • Form required matrices using Rotate and Translate . 188.
(189) Preorder Traversal. void 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);. }. 189.
(190) 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. 190.
(191) Dynamic Trees. Use 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. 191.
(192) The Real Thing. 192.
(193) As Opposed.
(194) Image Processing • Suppose that we start with a function d(u,v) • We can sample it to form an array D=[dij] • Then ∂d/ ∂u ≈ dij – di-1,j and ∂d/ ∂v ≈ dij – di,j-1 • Embossing: multipass approach using floating point buffer 194.
(195) Example Single Polygon and a Rotating Light Source. 195.
(196) How to do this? • The problem is that we want to apply the perturbation at all points on the surface • Cannot solve by vertex lighting (unless polygons are very small) • Really want to apply to every fragment • Can’t do that in fixed function pipeline • But can do with a fragment program!! 196.
(197) Compositing & Blending. 197.
(198) A. - Blending for translucent surfaces. - Compositing images. - Antialiasing. 198.
(199) A.
(200) A.
(201)
Related documents
• Given a point light source and a polygon, the vertices of the shadow polygon are the projections of the original polygon’s vertices from a point source onto a surface...
• Given a point light source and a polygon, the vertices of the shadow polygon are the projections of the original polygon’s vertices from a point source onto a surface...
• Ideally perturb normal across surface of object and compute a new color at each interior point... Rougher Version n’
Communication bridge between CPU & GPU Input: Commands from CPU; geometry information from memory Output: Stream of vertices in object space with associated information -
• Most state variables, attributes and related pre 3.1 OpenGL functions have
• Shader based OpenGL is based less on a state machine model than a data flow model.. • Most state variables, attributes and related pre 3.1 OpenGL functions have
Varying Length & Density • Vary overall length of hair by expanding shells • Vary density with noise texture as described • Both settings can be controlled per-pixel using
glPolygonOffset • Depth buffer contains “window space” depth values – Post-perspective divide means non-linear distribution – glPolygonOffset is guaranteed to be a window