Graphics Graphics Korea University 1 Jang Sumi Texture Mapping Environment Mapping Stencil Buffer
CGVR Graphics Korea University 2 1. Texture Mapping Mip-Mapping 2. Environment Mapping 3. Stencil Buffer 4. Demonstration Contents
CGVR Graphics Korea University 3 Basic Texturing Concepts Texture Addressing Modes Wrap, Mirror, Clamp, Border Color Texture coordinates Texture Filtering 1. Texture Mapping
CGVR Graphics Korea University 4 Basic Texturing Concepts Textures In real World object's smoothness or roughness Computer Graphics a bitmap of pixel colors that give an object the appearance of texture creating realism in computer-generated 3-D images
CGVR Graphics Korea University 5 Basic Texturing Concepts Textures 2D texture 3D texture
CGVR Graphics Korea University 6 Addressing Modes (Warp) Wrap Texture Address Mode repeat the texture on every integer junction (default mode)
CGVR Graphics Korea University 7 Addressing Modes (Warp) CF. Texture Wrap A texture wrapA flat wrapA cylindrical wrapA spherical wrap (cutaway view)
CGVR Graphics Korea University 8 Addressing Modes (Mirror) Mirror Texture Address Mode mirror the texture at every integer boundary
CGVR Graphics Korea University 9 Addressing Modes (Clamp) Clamp Texture Address Mode apply the texture once, then smear the color of edge pixels
CGVR Graphics Korea University 10 Addressing Modes (Border Color) Border Color Texture Address Mode use an arbitrary color (=border color) for any texture coordinates outside the range of 0.0 through 1.0, inclusive
CGVR Graphics Korea University 11 Addressing Modes (source code) IDirect3DDevice8::SetTextureStageState() Parameters 1 st : specify the desired texture stage identifier 2 nd : update the u-, v-, or w-addressing modes individually. 3 rd : determine which mode is being set. typedef enum _D3DTEXTUREADDRESS { D3DTADDRESS_WRAP= 1, D3DTADDRESS_MIRROR= 2, D3DTADDRESS_CLAM= 3, D3DTADDRESS_BORDER= 4, D3DTADDRESS_MIRRORONCE = 5, D3DTADDRESS_FORCE_DWORD= 0x7fffffff } D3DTEXTUREADDRESS;
CGVR Graphics Korea University 12 Texture Filtering Purpose Magnify or minify a texture When a texture is being mapped onto a primitive image that is larger or smaller than itself
CGVR Graphics Korea University 13 Texture Filtering Nearest Point Sampling A simple texture-mapping technique that places texels on a textured object. Performance If similar sizes fast and efficient If not chunky, aliased, or blurred result chunky
CGVR Graphics Korea University 14 Texture Filtering Linear Texture Filtering Computes a weighted average of the texels (above, below, left, right of the nearest sample point) +: shows better result than Nearest Point Sampling -: edges or a chunky result Pixel center Nearest Point SamplingLinear Texture Filtering
CGVR Graphics Korea University 15 Texture Filtering Anisotropic Texture Filtering
CGVR Graphics Korea University 16 Texture Filtering (Mip-Map) Texture Filtering with Mip-map Use sequence of textures Performance +: High quality -: Memory overhead
CGVR Graphics Korea University 17 Texture Filtering (Mip-Map) Mip-Map Result (1) The ugly 'bitty' look near the top is the moiré pattern in action. Same scene rendered using mip-mapping.
CGVR Graphics Korea University 18 Texture Filtering (Mip-Map) Mip-Map Result (2) This demonstrates where the different mip-map levels are used by inverting the texture colour at each level.
CGVR Graphics Korea University 19 Texture Filtering (Source) Mip-Map IDirect3DTexture8 * pMipMap; d3dDevice->CreateTexture(256, 256, 5, 0, D3DFMT_R8G8B8, D3DPOOL_MANAGED, &pMipMap); d3dDevice->SetTexture(0, pMipMap); d3dDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_POINT);
CGVR Graphics Korea University Environment Mapping Purpose simulates highly reflective surfaces without using ray tracing T-1000 knows all about environment mapping.
CGVR Graphics Korea University Environment Mapping Cubic Environment Mapping textures that contain image data representing the scene surrounding an object as if the object were in the center of a cube.
CGVR Graphics Korea University 22 Cubic Env. Mapping Cubic Environment Mapping (1) textures that contain image data representing the scene surrounding an object as if the object were in the center of a cube.
CGVR Graphics Korea University 23 Cubic Env. Mapping Cubic Environment Mapping (2)
CGVR Graphics Korea University 24 Cubic Env. Mapping Mipmapped Cubic Environment Maps IDirect3DCubeTexture8::GetCubeMapSurface
CGVR Graphics Korea University 25 Cubic Env. Mapping Texture Coordinates for Cubic Environment Maps Fomula: if D3DRS_LOCALVIEWER is TRUE else R is the reflection vector being computed E is the normalized Position -to-eye vector N is the camera-space vertex normal N Z is the world space reflection vector from either formula
CGVR Graphics Korea University 26 Cubic Env. Mapping DWORD dwFVF= D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVFTEX1 | D3DFVF_TEXCOORDSIZE3(0); m_d3dDevice->SetTextureStageState ( 2, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR | 1);
CGVR Graphics Korea University 27 Cubic Env. Mapping Creating Cubic Environment Map Surfaces IDirect3DDevice8::CreateCubeTexture LPDIRECT3DCUBETEXTURE8 m_pCubeMap; m_d3dDevice->CreateCubeTexture( 256, 1, D3DUSAGE_RENDERTARGET, D3DFMT_R8G8B8, D3DPOOL_DEFAULT, &m_pCubeMap );
CGVR Graphics Korea University 28 Cubic Env. Mapping Accessing Cubic Environment Map Faces IDirect3DCubeTexture8::GetCubeMapSurface LPDIRECT3DSURFACE8 pFace2; m_pCubeMap->GetCubeMapSurface( D3DCUBEMAP_FACE_POSITIVE_Y, 0, &pFace2);
CGVR Graphics Korea University 29 Spherical Environment Mapping 2-D representation of the full 360-degree view of the scene surrounding of an object as if taken through a fish-eye lens
CGVR Graphics Korea University 30 Spherical Environment Mapping Texture Coordinates for Spherical Environment Maps Formula u and v are the texture coordinates being computed Nx and Ny are the x and y components of the camera-space vertex normal.
CGVR Graphics Korea University 31 Spherical Environment Mapping Applying Spherical Environment Maps IDirect3DDevice8::SetTexture IDirect3DTexture8
CGVR Graphics Korea University Stencil Buffer Purpose mask pixels in an image The mask controls whether the pixel is drawn. This helps to reduce the workload and increases performance.
CGVR Graphics Korea University 33 Dissolve one image is gradually replaced by another Fade (in/out) Dissolve from/to a black or white image to a scene A special case of dissolving Swipe series of stencil masks 3. Stencil Buffer
CGVR Graphics Korea University Stencil Buffer Decaling control which pixels from a particular primitive image are drawn to the rendering target surface Compositing occlude an area of the rendering target surface Write some other texture to the occluded area Outline mask same shape but slightly smaller Silhouette stencil mask is the same size and shape as the primitive
CGVR Graphics Korea University Stencil Buffer How the Stencil Buffer Works 1. Stencil ReferenceAND Stencil Mask 2. Stencil Buffer ValueAND Stencil Mask 3. Compare the result of step 1 to the result of step 2, using the comparison function. (StencilRef & StencilMask) CompFunc (StencilBufferValue & StencilMask)
CGVR Graphics Korea University Stencil Buffer Source Code Comparison function typedef enum _D3DRENDERSTATETYPE { ……. D3DRS_STENCILFUNC …… }
CGVR Graphics Korea University Stencil Buffer typedef enum _D3DCMPFUNC { D3DCMP_NEVER = 1, D3DCMP_LESS = 2, D3DCMP_EQUAL = 3, D3DCMP_LESSEQUAL = 4, D3DCMP_GREATER = 5, D3DCMP_NOTEQUAL = 6, D3DCMP_GREATEREQUAL = 7, D3DCMP_ALWAYS = 8, D3DCMP_FORCE_DWORD = 0x7fffffff } D3DCMPFUNC;
CGVR Graphics Korea University Demonstration Cube Map
CGVR Graphics Korea University Demonstration Fish Eye
CGVR Graphics Korea University Demonstration Shadow Volume (Stencil buffer)Stencil Mirror
CGVR Graphics Korea University Demonstration Stencil Depth