r g r b fcg sect 16 6 procedural techniques 2 1 h
play

[ ( R G ) ( R B ) ] + FCG Sect 16.6 Procedural - PowerPoint PPT Presentation

University of British Columbia Reading for Last Time and Today Corrected Correction: HSI/HSV and RGB News CPSC 314 Computer Graphics HSV/HSI conversion from RGB H3 Q2: OK to use either HSV or HSI Jan-Apr 2007 FCG Chap 11 Texture


  1. University of British Columbia Reading for Last Time and Today Corrected Correction: HSI/HSV and RGB News CPSC 314 Computer Graphics • HSV/HSI conversion from RGB • H3 Q2: OK to use either HSV or HSI Jan-Apr 2007 • FCG Chap 11 Texture Mapping • hue same in both • except 11.8 • value is max, intensity is average Tamara Munzner • RB Chap Texture Mapping 1   [ ( R G ) ( R B ) ] − + − • FCG Sect 16.6 Procedural Techniques   2 1 H cos − Textures II =   • FCG Sect 16.7 Groups of Objects ( R G ) 2 ( R B )( G B ) − + − −     Week 9, Fri Mar 16 R G B S = 1 − min( R , G , B ) + + I • HSI: = http://www.ugrad.cs.ubc.ca/~cs314/Vjan2007 I 3 S = 1 − min( R , G , B ) V = max( R , G , B ) • HSV: V 2 3 4 News Review: Back-face Culling Review: Invisible Primitives Review: Texture Coordinates • Project 3 grading slot signup • why might a polygon be invisible? • texture image: 2D array of color values (texels) • polygon outside the field of view / frustum • assigning texture coordinates (s,t) at vertex with • Mon 11-12 object coordinates (x,y,z,w) • solved by clipping • Tue 10-12:30, 4-6 VCS VCS • polygon is backfacing • use interpolated (s,t) for texel lookup at each pixel y y • Wed 11-12, 2:30-4 • solved by backface culling • use value to modify a polygon’s color z z eye eye • polygon is occluded by object(s) nearer the viewpoint • or other surface property • solved by hidden surface removal • specified by programmer or artist glTexCoord2f(s,t) NDCS NDCS glVertexf(x,y,z,w) y y N 0 eye eye z z works to cull if works to cull if > Z 5 6 7 8 Review: Fractional Texture Coordinates Review: Texture Review: Tiled Texture Map • action when s or t is outside [0…1] interval texture (1,0) (1,1) image • tiling glTexCoord2d(1, 1); • clamping glVertex3d (x, y, z); (.25,.5) (0,1) (1,1) (0,.5) • functions (0,0) (0,1) Texturing II • replace/decal • modulate • blend (4,4) (4,0) • texture matrix stack glTexCoord2d(4, 4); (0,0) (.25,0) (0,0) (1,0) glMatrixMode( GL_TEXTURE ); glVertex3d (x, y, z); (0,0) (0,4) 9 10 11 12 Texture Pipeline Texture Objects and Binding Basic OpenGL Texturing Low-Level Details • create a texture object and fill it with texture data: • large range of functions for controlling layout of texture data • texture object • glGenTextures(num, &indices) to get identifiers for the objects • state how the data in your image is arranged (x, y, z) • an OpenGL data type that keeps textures resident in memory • glBindTexture(GL_TEXTURE_2D, identifier) to bind • e.g.: glPixelStorei(GL_UNPACK_ALIGNMENT, 1) tells and provides identifiers to easily access them Object position • following texture commands refer to the bound texture OpenGL not to skip bytes at the end of a row • provides efficiency gains over having to repeatedly load and (-2.3, 7.1, 17.7) • glTexParameteri(GL_TEXTURE_2D, …, …) to specify • you must state how you want the texture to be put in memory: reload a texture parameters for use when applying the texture how many bits per “pixel”, which channels,… • you can prioritize textures to keep in memory • glTexImage2D(GL_TEXTURE_2D, ….) to specify the texture data (s’, t’) (s, t) • textures must be square and size a power of 2 Texel space (the image itself) Texel color • OpenGL uses least recently used (LRU) if no priority is Parameter space Transformed • common sizes are 32x32, 64x64, 256x256 • enable texturing: glEnable(GL_TEXTURE_2D) (81, 74) assigned (0.9,0.8,0.7) parameter space • smaller uses less memory, and there is a finite amount of (0.32, 0.29) • state how the texture will be used: • texture binding (0.52, 0.49) texture memory on graphics cards • glTexEnvf(…) • which texture to use right now • specify texture coordinates for the polygon: • ok to use texture template sample code for project 4 • use glTexCoord2f(s,t) before each vertex: • switch between preloaded textures • http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=09 • glTexCoord2f(0,0); glVertex3f(x,y,z); Object color Final color (0.5,0.5,0.5) (0.45,0.4,0.35) 13 14 15 16

  2. Texture Mapping Texture Mapping Interpolation: Screen vs. World Space Texture Coordinate Interpolation • perspective correct interpolation • texture coordinates • texture coordinate interpolation • screen space interpolation incorrect • α , β , γ : • specified at vertices • perspective foreshortening problem • problem ignored with shading, but artifacts • barycentric coordinates of a point P in a triangle more visible with texturing glTexCoord2f(s,t); P 0 (x,y,z) • s0 , s1 , s2 : glVertexf(x,y,z); • texture coordinates of vertices V 0 (x’,y’) • w0 , w1 , w2 : • interpolated across triangle (like R,G,B,Z) • homogeneous coordinates of vertices • …well not quite! (s1,t1) (x1,y1,z1,w1) (s,t)? s / w s / w s / w (s2,t2) ( α , β , γ ) α ⋅ + β ⋅ + γ ⋅ V 1 (x’,y’) s 0 0 1 1 2 2 = (x2,y2,z2,w2) (s0,t0) / w / w / w α + β + γ 0 1 2 (x0,y0,z0,w0) P 1 (x,y,z) 17 18 19 20 Reconstruction MIPmapping MIPmaps MIPmap storage • multum in parvo -- many things in a small place • how to deal with: • only 1/3 more space required • prespecify a series of prefiltered texture maps of decreasing use “ “image pyramid image pyramid” ” to to precompute precompute use • pixels that are much larger than texels? resolutions averaged versions of the texture averaged versions of the texture • requires more texture storage • apply filtering, “averaging” • avoid shimmering and flashing as objects move • gluBuild2DMipmaps • automatically constructs a family of textures from original texture size down to 1x1 • pixels that are much smaller than texels ? Without MIP-mapping Without MIP-mapping • interpolate without with store whole pyramid in store whole pyramid in single block of memory single block of memory 21 22 23 24 With MIP-mapping With MIP-mapping Texture Parameters Bump Mapping: Normals As Texture Bump Mapping Bump Mapping • in addition to color can control other • object surface often not smooth – to recreate correctly need complex geometry model material/object properties • can control shape “effect” by locally perturbing surface • surface normal (bump mapping) normal • reflected color (environment mapping) • random perturbation • directional change over region 25 26 27 28 Embossing Displacement Mapping Environment Mapping Environment Mapping • used to model object that reflects • at transitions • bump mapping gets • cheap way to achieve reflective effect silhouettes wrong surrounding textures to the eye • rotate point’s surface normal by _ or - _ • generate image of surrounding • shadows wrong too • movie example: cyborg in Terminator 2 • map to object as texture • change surface • different approaches geometry instead • sphere, cube most popular • only recently • OpenGL support available with • GL_SPHERE_MAP, GL_CUBE_MAP realtime graphics • others possible too • need to subdivide surface 29 30 31 32

Recommend


More recommend