Advanced Graphics Programing Techniques Using OpenGL Section 6 Texture Mapping (page 40 77) 1
6 Texture Mapping(1) 2
6 Texture Mapping(2) ( ) ( ) OpenGL 3
6.1 Texture Basics 4
6.1.1 The Texture Image(1) (texel: texture elements) 1D, 2D, 3D(OpenGL1.2), 4D(SGI ) glteximage{1, 2, 3}D OpenGL TIFF, JPG 5
6.1.1 The Texture Image(2) glcopyteximage2d 2 6
6.1.1 The Texture Image(3) (OpenGL1.1) -> GL_LUMINANCE 16 -> GL_RGB4 7
6.1.2 Texture Coordinates(1) 1. 2. 3. 4. 8
6.1.2 Texture Coordinates(2) 3 (s, t, r, q) s t r, q 9
6.1.2 Texture Coordinates(3) [0.. 1] [0.. 1] (clamp): [0.. 1] ( ) (repeat): ( ) OpenGL1.2 clamp to edge 10
6.1.2 Texture Coordinates(4) Q. A. ( ) 3D VRML Wavefront OBJ 3D 11
6.1.2 Texture Coordinates(5) Sloan, Weinstein, Brederson[90] (intrinsic texture properties) (user-guided highlights) importance map 12
6.1.3 Texture Coordinate Generation and Transformation OpenGL ( texgen) ( ) 4x4 13
6.1.4 Filtering(1) ( ) 14
6.1.4 Filtering(2) OpenGL Magnification(1 ) Minification(1 ) ( ) 15
6.1.4 Filtering(3) Magnification 4 Minification 4 ( 8 ) SGIS_texture_filter4 4x4 16
6.1.4 Filtering(4) (1) Level-of-Detail(LODs) ( 0) 1x1 17
6.1.4 Filtering(5) (2) glubuild{1,2,3}dmipmaps GLU 18
6.1.4 Filtering(6) (3) OpenGL LODs ( ) (selecting) OpenGL LOD 19
6.1.4 Filtering(7) (4) OpenGL Disable (OpenGL1.0, 1.1) GLU 20
6.1.5 Texture Environment(1) (gltex-env 21
6.1.5 Texture Environment(2) GL_MODULATE GL_REPLACE( ) GL_DECAL GL_BLEND (imcoming) 22
6.1.6 Texture Objects(1) OpenGL texture objects (OpenGL1.1) 23
6.1.6 Texture Objects(2) ( ) ( ) 24
6.1.6 Texture Objects(3) 32bit glgentexures ( ) GL_TEXTURE_{1,2,3}D glbindtextures (bind) 25
6.1.6 Texture Objects(4) glteximage, gltexparameter, glgettexparameter, glgettexlevelparameter, glgettexim-age (1D,2D,3D) 26
6.1.6 Texture Objects(5) glbindtexture 27
6.1.6 Texture Obejcts(6) : 3 1 28
6.2 Multitexture(1) OpenGL (state) 29
6.2 Multitexture(2) Quake Unreal (section 10.2) ( 2 ) 30
6.2 Multitexture(3) ARB_multitexture (OpenGL1.2.1) Architecture Review Board(ARB) ARB OpenGL OpenGL 31
6.2.1 Multitexture API Overview(1) : 2D 0 1D 1 glactivetexturearb(gl_texture0_arb); glenable(gl_texture_2d); glactivetexturearb(gl_texture1_arb); glenable(gl_texture_1d); 32
6.2.1 Multitexture API Overview(2) glactivetexturearb gltexgen glteximage2d gltexparametergldisable glgetintegerv glmatrixmode glpushmatrix glpopmatrix 33
6.2.1 Multitexture API Overview(3) glgetintegerv GL_MAX_TEXTURE_UNITS_ARB 2 32 34
6.2.1 Multitexture API Overview(4) glmultitexcoord2farb(gl_texture0_arb, s0, t0); glmultitexcoord4farb(gl_texture1_arb, s1, t1, r1, q1); glmultitexcoord1iarb(gl_texture2_arb, s2); glvertex3f(x, y, z); 35
6.2.1 Multitexture API Overview(5) (vertex arrays) glclientactivetexturearb(gl_texture0_arb); gldisableclientstate(gl_texture_coord_array); glclientactivetexturearb(gl_texture1_arb); gltexcoordpointer(2, GL_FLOAT, 0, tex_array_ptr); glenableclientstate(gl_texture_coord_array); 36
6.2.1 Multitexture API Overview(6) (state) push pop push pop glpushattrib glpopattrib glpushclientattrib glpopclientattrib 37
6.2.2 Multitexture Texture Environments EXT_multitexture (incoming) 38
6.3 Merging Textures with Specular Highlights(1) EXT_separate_specular_color color sum 39
6.3 Merging Textures with Specular Highlights(2) (OpenGL1.2) gllightmodeli(gl_light_model_color_co NTROL, GL_SEPARATE_SPECULAR_COLOR); gllightmodeli(gl_light_model_color_co NTROL, GL_SINGLE_COLOR); 40
6.3 Merging Textures with Specular Highlights(3) color sum (secondary color) Disable 41
6.3 Merging Textures with Specular Highlights(4) EXT_secondary_color glsecondarycolor3fext gldisable(gl_lighting); glenable(gl_color_sum_ext); /* enable color sum with explicit secondary color */ glcolor4f(0, 0.3, 0.5); /* explicit primary color (RGBA) */ glsecondarycolor3fext(1, 1, 0.8); /* explicit secondary color (RGB) */ 42
6.4 Texture Borders and Tiling(1) OpenGL ( ) OpenGL 43
6.4 Texture Borders and Tiling(2) OpenGL 1 44
6.4 Texture Borders and Tiling(3) : 3 4 45
6.4 Texture Borders and Tiling(3) 0.0 or 1.0 50% 46
6.5 Mipmap Generation(1) glubuild2dmipmaps ( ) 47
6.5 Mipmap Generation(2) Mitchell and Netravali (family) ( ) 48
6.5 Mipmap Generation(3) GLU (LOD 0) 2 2 49
6.5 Mipmap Generation(4) CPU OpenGL GL_LINEAR minification 1/4 ( ) LOD 1 50
6.6 Texture Map Limits(1) (vertualize) 51
6.6 Texture Map Limits(2) : 52
6.7 Anisotropic Texture Filtering(1) OpenGL minification (isotropic) s,t 53
6.7 Anisotropic Texture Filtering(2) minification footprint ( ) 1 s t footprint 54
6.7 Anisotropic Texture Filtering(3) t ( ) footprint 0 footprint 55
6.8 Paging Textures(1) 56
6.8 Paging Textures(2) 57
6.8 Paging Textures(3) 1. 2. 3. GL_LINEAR [0.0, 1.0] 58
6.8 Paging Textures(4) 1. 2. (s,t) 0 3.GL_SKIP_PIXELS GL_SKIP_ROWS glteximage2d 59
6.8.1 Texture Subloading(1) 60
6.8.1 Texture Subloading(2) GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T GL_REPEAT( ) 61
6.8.1 Texture Subloading(3) 1. 2. 3. GL_SKIP_PIXELS GL_SKIP_ROWS gltexsubimage 62
6.8.1 Texture Subloading(4) OpenGL (paged) 32 16 63
6.8.2 Paging Images in System Memory(1) (offset) 2 64
6.8.2 Paging Images in System Memory(2) 2 (roam) 65
6.8.3 Implementing High Resolution Textured Terrain(1) clip mapping(tanner, Migdal, and Jones [94]) SGI InfiniteReality SGIX_clipmap 32,768 x 32,768 clip map 66
6.9 Transparency Mapping and Trimming with Alpha(1) (matte) 1 0 GL_EQUALS 0 GL_LESS 0.05 67
6.9 Transparency Mapping and Trimming with Alpha(2) 0 68
6.9 Transparency Mapping and Trimming with Alpha(3) (trim) 69
6.10 Billboads(1) 70
6.10 Billboads(2) M r 0 1 0 Veye = M 1 0 r Vfront = ( 0,0,1) r Vright = ( 0,1,0) r r cos? = Veye V r r sin? = V V front ( ) eye right z R M up +y (MR) 71
6.10 Billboads(3) A v r r axis = Vup V r r cos? = Vup V v sin? = axis billboard billboard ( ) MAR z up +y 72
6.10 Billboads(4) ( ) A v r r axis = Vup V r r cos? = Vup V v sin? = axis r r Valignment = V alignment alignment billboard r ( V eye r V billboard r ) V eye 73
6.11 Rendering Text(1) 2D : : 74
6.11 Rendering Text(2) GL_INTENSITY GL_MODULATE e.g. 75
6.12 Texture Mosaicing e.g. 76
6.13 Texture Coordinate Generation gltexcoord OpenGL 2 OpenGL 77
6.14 Color Coding and Contouring(1) 1D 50 50-800 800-1000 5% 75% 20% 1D 78
6.14 Color Coding and Contouring(2) GL_REPEAT GL_OBJCT_LINEAR GL_EYE_LINEAR 79
6.16 Projective Textures OpenGL s,t s,t,r,q q w r 3D OpenGL r=0, q=1 80
6.16.1 How to Project Texture(1) 3 1. 2. ( or ) 3. glulookat,glfrustum,gluperspective 81
6.16.1 How to Project Texture(2) OpenGL 82
6.16.1 How to Project Texture(3) (NDC) x,y,z -1 1 ( s,t,r ) 83
6.16.1 How to Project Texture(4) NDC NDC s,t 1/2 1/2 84
6.16.1 How to Project Texture(5) glmatrixmode(gl TEXTURE) glloadidentity( )( ) gltranslatef(.5f,.5f, 0.f) glscalef(.5f,.5f, 1.f) ( NDC ) (glfrustum ) (glulookat ) 85
6.17 Enviroment Mapping(1) OpenGL (spherical) 1 86
6.17 Enviroment Mapping(2) GL_SPHERE_MAP ( ) Phong section 10.4 11.2.1 87
6.18 Image Warping and Dewarping 88
6.19 3D Textures s, t, r [0.. 1] 2D 89
6.19.1 Using 3D Textures 90
6.21 Procedural Texture Generation (filtered noise functions) 91
6.21.1 Filtered Noise Function(1) ( -1 1) 1 92
6.21.1 Filtered Noise Function(2) value noise gradient noise gradient noise RenderMan shading language 93
6.21.2 Generating Noise Functions(1) OpenGL 94
6.21.2 Generating Noise Functions(2) value noise gradient noise 95
6.21.3 High Resolution Filtering 96
6.21.5 Other Noise Functions sparse convolution noise spot noise 97
6.21.6 Turbulence(1) OpenGL 1. glaccum(gl_load, 1.0); 2. glaccum(gl_add, -0.5); 3. glaccum(gl_mult, 2.0); 4. glaccum(gl_return, 1.0); 5. 6. glaccum(gl_return, -1.0); 7. GL_ONE step 5 98
6.21.6 Turbulence(2) GL_ADD GL_MULT [0, 1] [-1, 1] [0, 1] GL_RETURN 0 GL_RETURN 0 GL_RETURN GL_RETURN 99
6.21.7 Example: Image Warping 2D (distort) ( ) 100
6.21.8 Generating 3D Noise 2D 3D : 1 64x64x64 r=0.0, r=1.0 2 0 1 62 101
6.21.9 Generating 2D Noise to Simulate 3D Noise 2D 2D 2D spot noise 2D 3D 102
6.21.10 Trade-offs Between 3D and 2D Techniques 3D 3D 2D 103
Reference SIGGRAPH '99 Cources Advanced Graphics Programming Techniques Using OpenGL Lighting and Shading Techniques for Interactive Applications http://reality.sgi.com/blythe/sig99/ 104