Graphics Texture Mapping Environment Mapping Stencil Buffer Jang
Graphics Texture Mapping Environment Mapping Stencil Buffer Jang Sumi 2002. 1. 29 1 Graphics Lab @ Korea University
Contents CGVR 1. Texture Mapping n Mip-Mapping 2. Environment Mapping 3. Stencil Buffer 4. Demonstration 2 Graphics Lab @ Korea University
1. Texture Mapping CGVR Basic Texturing Concepts n Texture Addressing Modes n n Wrap, Mirror, Clamp, Border Color Texture coordinates n Texture Filtering n 3 Graphics Lab @ Korea University
Basic Texturing Concepts n CGVR Textures n In real World object's smoothness or roughness n Computer Graphics a bitmap of pixel colors that give an object the appearance of texture creating realism in computer-generated 3 -D images 4 Graphics Lab @ Korea University
Basic Texturing Concepts n CGVR Textures n 2 D texture n 3 D texture 5 Graphics Lab @ Korea University
Addressing Modes (Warp) n CGVR Wrap Texture Address Mode n repeat the texture on every integer junction (default mode) 6 Graphics Lab @ Korea University
Addressing Modes (Warp) n CGVR CF. Texture Wrap A texture wrap A flat wrap 7 A cylindrical wrap A spherical wrap (cutaway view) Graphics Lab @ Korea University
Addressing Modes (Mirror) n CGVR Mirror Texture Address Mode n mirror the texture at every integer boundary 8 Graphics Lab @ Korea University
Addressing Modes (Clamp) n CGVR Clamp Texture Address Mode n apply the texture once, then smear the color of edge pixels 9 Graphics Lab @ Korea University
Addressing Modes (Border Color) n CGVR Border Color Texture Address Mode n use an arbitrary color (=border color) for any texture coordinates outside the range of 0. 0 through 1. 0, inclusive 10 Graphics Lab @ Korea University
Addressing Modes (source code) n CGVR IDirect 3 DDevice 8: : Set. Texture. Stage. State() n Parameters 1 st : specify the desired texture stage identifier o 2 nd : update the u-, v-, or w-addressing modes individually. o 3 rd : determine which mode is being set. o typedef enum _D 3 DTEXTUREADDRESS { D 3 DTADDRESS_WRAP = 1, D 3 DTADDRESS_MIRROR = 2, D 3 DTADDRESS_CLAM = 3, D 3 DTADDRESS_BORDER = 4, D 3 DTADDRESS_MIRRORONCE = 5, D 3 DTADDRESS_FORCE_DWORD= 0 x 7 fffffff } D 3 DTEXTUREADDRESS; 11 Graphics Lab @ Korea University
Texture Filtering n CGVR Purpose Magnify or minify a texture n When a texture is being mapped onto a primitive image that is larger or smaller than itself n 12 Graphics Lab @ Korea University
Texture Filtering n CGVR Nearest Point Sampling A simple texture-mapping technique that places texels on a textured object. n Performance n If similar sizes fast and efficient o If not chunky, aliased, or blurred result o chunky 13 Graphics Lab @ Korea University
Texture Filtering n CGVR Linear Texture Filtering n Computes a weighted average of the texels (above, below, left, right of the nearest sample point) + o o : shows better result than Nearest Point Sampling : edges or a chunky result Pixel center Nearest Point Sampling 14 Pixel center Linear Texture Filtering Graphics Lab @ Korea University
Texture Filtering n CGVR Anisotropic Texture Filtering 15 Graphics Lab @ Korea University
Texture Filtering (Mip-Map) n CGVR Texture Filtering with Mip-map Use sequence of textures n Performance n + : High quality o : Memory overhead o 16 Graphics Lab @ Korea University
Texture Filtering (Mip-Map) n CGVR Mip-Map Result (1) The ugly 'bitty' look near the top is the moiré pattern in action. 17 Same scene rendered using mip-mapping. Graphics Lab @ Korea University
Texture Filtering (Mip-Map) n CGVR Mip-Map Result (2) This demonstrates where the different mip-map levels are used by inverting the texture colour at each level. 18 Graphics Lab @ Korea University
Texture Filtering (Source) n CGVR Mip-Map IDirect 3 DTexture 8 * p. Mip. Map; n d 3 d. Device->Create. Texture(256, 5, 0, D 3 DFMT_R 8 G 8 B 8, D 3 DPOOL_MANAGED, &p. Mip. Map); n d 3 d. Device->Set. Texture(0, p. Mip. Map); n d 3 d. Device->Set. Texture. Stage. State(0, D 3 DTSS_MIPFILTER, D 3 DTEXF_POINT); n 19 Graphics Lab @ Korea University
2. Environment Mapping n CGVR Purpose n simulates highly reflective surfaces without using ray tracing T-1000 knows all about environment mapping. 20 Graphics Lab @ Korea University
2. Environment Mapping n CGVR Cubic Environment Mapping textures that contain image data representing the scene surrounding an object o as if the object were in the center of a cube. o 21 Graphics Lab @ Korea University
Cubic Env. Mapping n CGVR Cubic Environment Mapping (1) textures that contain image data representing the scene surrounding an object n as if the object were in the center of a cube. n 22 Graphics Lab @ Korea University
Cubic Env. Mapping n CGVR Cubic Environment Mapping (2) 23 Graphics Lab @ Korea University
Cubic Env. Mapping n CGVR Mipmapped Cubic Environment Maps o IDirect 3 DCube. Texture 8: : Get. Cube. Map. Surface 24 Graphics Lab @ Korea University
Cubic Env. Mapping n CGVR Texture Coordinates for Cubic Environment Maps n Fomula : if D 3 DRS_LOCALVIEWER is TRUE else R is the reflection vector being computed n E is the normalized Position -to-eye vector n N is the camera-space vertex normal n NZ is the world space reflection vector from either formula n 25 Graphics Lab @ Korea University
Cubic Env. Mapping CGVR n DWORD dw. FVF = D 3 DFVF_XYZ | D 3 DFVF_NORMAL | D 3 DFVFTEX 1 | D 3 DFVF_TEXCOORDSIZE 3(0); n m_d 3 d. Device->Set. Texture. Stage. State ( 2, D 3 DTSS_TEXCOORDINDEX, D 3 DTSS_TCI_CAMERASPACEREFLECTIONVECTOR | 1); 26 Graphics Lab @ Korea University
Cubic Env. Mapping n CGVR Creating Cubic Environment Map Surfaces n IDirect 3 DDevice 8: : Create. Cube. Texture n LPDIRECT 3 DCUBETEXTURE 8 m_p. Cube. Map; n m_d 3 d. Device->Create. Cube. Texture( 256, 1, D 3 DUSAGE_RENDERTARGET, D 3 DFMT_R 8 G 8 B 8, D 3 DPOOL_DEFAULT, &m_p. Cube. Map ); 27 Graphics Lab @ Korea University
Cubic Env. Mapping n CGVR Accessing Cubic Environment Map Faces IDirect 3 DCube. Texture 8: : Get. Cube. Map. Surface n LPDIRECT 3 DSURFACE 8 p. Face 2; m_p. Cube. Map->Get. Cube. Map. Surface( D 3 DCUBEMAP_FACE_POSITIVE_Y, 0, &p. Face 2); n 28 Graphics Lab @ Korea University
Spherical Environment Mapping n CGVR Spherical Environment Mapping 2 -D representation of the full 360 -degree view of the scene surrounding of an object n as if taken through a fish-eye lens n 29 Graphics Lab @ Korea University
Spherical Environment Mapping n CGVR Texture Coordinates for Spherical Environment Maps n Formula u and v are the texture coordinates being computed n Nx and Ny are the x and y components of the camera-space vertex normal. n 30 Graphics Lab @ Korea University
Spherical Environment Mapping n CGVR Applying Spherical Environment Maps IDirect 3 DDevice 8: : Set. Texture o IDirect 3 DTexture 8 o 31 Graphics Lab @ Korea University
3. Stencil Buffer n CGVR Purpose mask pixels in an image n The mask controls whether the pixel is drawn. n This helps to reduce the workload and increases performance. n 32 Graphics Lab @ Korea University
3. Stencil Buffer n Dissolve n n CGVR one image is gradually replaced by another Fade (in/out) Dissolve from/to a black or white image to a scene n A special case of dissolving n n Swipe n series of stencil masks 33 Graphics Lab @ Korea University
3. Stencil Buffer n Decaling n n CGVR control which pixels from a particular primitive image are drawn to the rendering target surface Compositing occlude an area of the rendering target surface n Write some other texture to the occluded area n n Outline n n mask same shape but slightly smaller Silhouette n stencil mask is the same size and shape as the primitive 34 Graphics Lab @ Korea University
3. Stencil Buffer n CGVR How the Stencil Buffer Works n 1. Stencil Reference AND Stencil Mask n 2. Stencil Buffer Value AND Stencil Mask n 3. Compare the result of step 1 to the result of step 2, using the comparison function. (Stencil. Ref & Stencil. Mask) Comp. Func (Stencil. Buffer. Value & Stencil. Mask) 35 Graphics Lab @ Korea University
3. Stencil Buffer n Source Code n Comparison o CGVR function typedef enum _D 3 DRENDERSTATETYPE { ……. D 3 DRS_STENCILFUNC …… } 36 Graphics Lab @ Korea University
3. Stencil Buffer o CGVR typedef enum _D 3 DCMPFUNC { D 3 DCMP_NEVER = 1, D 3 DCMP_LESS = 2, D 3 DCMP_EQUAL = 3, D 3 DCMP_LESSEQUAL = 4, D 3 DCMP_GREATER = 5, D 3 DCMP_NOTEQUAL = 6, D 3 DCMP_GREATEREQUAL = 7, D 3 DCMP_ALWAYS = 8, D 3 DCMP_FORCE_DWORD = 0 x 7 fffffff } D 3 DCMPFUNC; 37 Graphics Lab @ Korea University
4. Demonstration CGVR Cube Map 38 Graphics Lab @ Korea University
4. Demonstration CGVR Fish Eye 39 Graphics Lab @ Korea University
4. Demonstration Shadow Volume (Stencil buffer) 40 CGVR Stencil Mirror Graphics Lab @ Korea University
4. Demonstration CGVR Stencil Depth 41 Graphics Lab @ Korea University
- Slides: 41