3D Graphics for Game Programming (J. Han) Chapter VIII Image Texturing.

Slides:



Advertisements
Similar presentations
Technische Universität München Fakultät für Informatik Computer Graphics SS 2014 Sampling Rüdiger Westermann Lehrstuhl für Computer Graphik und Visualisierung.
Advertisements

CSE 781 Anti-aliasing for Texture Mapping. Quality considerations So far we just mapped one point – results in bad aliasing (resampling problems) We really.
03/16/2009Dinesh Manocha, COMP770 Texturing Surface’s texture: its look & feel Graphics: a process that takes a surface and modifies its appearance using.
Texture Mapping. Texturing  process that modifies the appearance of each point on a surface using an image or function  any aspect of appearance can.
David Luebke1/19/99 CS 551/651: Antialiasing David Luebke
Real-Time Rendering TEXTURING Lecture 02 Marina Gavrilova.
Texture Visual detail without geometry. Texture Mapping desire for heightened realism.
Week 7 - Wednesday.  What did we talk about last time?  Transparency  Gamma correction  Started texturing.
Computer Graphics Inf4/MSc Computer Graphics Lecture 13 Illumination I – Local Models.
Sampling, Aliasing, & Mipmaps
Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping.
Textures – Magnification and Minification Lecture 30 Mon, Nov 17, 2003.
© Chun-Fa Chang Sampling Theorem & Antialiasing. © Chun-Fa Chang Motivations “ My ray traced images have a lot more pixels than the TV screen. Why do.
1 Computer Graphics Week13 –Shading Models. Shading Models Flat Shading Model: In this technique, each surface is assumed to have one normal vector (usually.
Computer Graphics Inf4/MSc Computer Graphics Lecture 9 Antialiasing, Texture Mapping.
3D Computer Graphics: Textures. Textures: texels Texture is a way of assigning a diffuse color to a pixel – can be with 1, 2 or 3D- can use maps, interpolation.
Modelling and Simulation Types of Texture Mapping.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Computer Graphics Texture Mapping
11/11/04© University of Wisconsin, CS559 Fall 2004 Last Time Shading Interpolation Texture mapping –Barycentric coordinates for triangles.
1 Texture Mapping ©Anthony Steed Overview n Texture mapping Inverse and Forward Mapping Bilinear interpolation Perspective correction n Mipmapping.
Texture Mapping. Scope Buffers Buffers Various of graphics image Various of graphics image Texture mapping Texture mapping.
Graphics Graphics Korea University cgvr.korea.ac.kr 1 Texture Mapping 고려대학교 컴퓨터 그래픽스 연구실.
COLLEGE OF ENGINEERING UNIVERSITY OF PORTO COMPUTER GRAPHICS AND INTERFACES / GRAPHICS SYSTEMS JGB / AAS 1 Shading (Shading) & Smooth Shading Graphics.
Texture Mapping Course: Computer Graphics Presented by Fan Chen
UW EXTENSION CERTIFICATE PROGRAM IN GAME DEVELOPMENT 2 ND QUARTER: ADVANCED GRAPHICS Textures.
3D Graphics for Game Programming Chapter IV Fragment Processing and Output Merging.
Week 6 - Wednesday.  What did we talk about last time?  Light  Material  Sensors.
CS 480/680 Computer Graphics OpenGL Texture Mapping Dr. Frederick C Harris, Jr. Fall 2011.
1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing.
Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora.
CHAPTER 8 Color and Texture Mapping © 2008 Cengage Learning EMEA.
CS418 Computer Graphics John C. Hart
Texture Mapping May 4, Many slides are borrowed from UNC-CH COMP236 Course (Spring 2003) taught by Leonard McMillan
Texture Mapping. 2 3 Loading Textures void glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border,
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Texture Mapping CAP4730: Computational Structures in Computer Graphics.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
CS 325 Introduction to Computer Graphics 04 / 12 / 2010 Instructor: Michael Eckmann.
CS 450: COMPUTER GRAPHICS TEXTURE MAPPING SPRING 2015 DR. MICHAEL J. REALE.
Graphics Graphics Korea University 1 Jang Sumi Texture Mapping Environment Mapping Stencil Buffer.
CSCI 440.  So far we have learned how to  build shapes  create movement  change views  add simple lights  But, our objects still look very cartoonish.
GAM666 – Introduction To Game Programming ● Textures are simply 2D images which are spread over the triangles of a 3D shape ● Each vertex has texture coordinates.
Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition Chapter 12.
CSc4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Texture Mapping.
Texturing Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology.
Antialiasing. What is alias? Alias - A false signal in telecommunication links from beats between signal frequency and sampling frequency (from dictionary.com)
Week 7 - Wednesday CS361.
Chapter X Advanced Texturing
The Graphic PipeLine
Texture Mapping cgvr.korea.ac.kr.
OpenGL Texture Mapping
Sampling Theorem & Antialiasing
Chapters VIII Image Texturing
Interactive Graphics Algorithms Ying Zhu Georgia State University
Introduction to Texture Mapping
Chapter IX Bump Mapping
Chapter V Vertex Processing
Chapter XVI Texturing toward Global Illumination
3D Game Programming Texture Mapping
Chapter XIV Normal Mapping
Textures Lecture 11 Wed, Oct 5, 2005.
Chapter XV Shadow Mapping
Texture Mapping 고려대학교 컴퓨터 그래픽스 연구실.
OpenGL Texture Mapping
Advanced Computer Graphics: Texture
Mipmaps Lecture 13 Wed, Oct 12, 2005.
Adding Surface Detail 고려대학교 컴퓨터 그래픽스 연구실.
3D Game Programming Texture Mapping
Adding Surface Detail 고려대학교 컴퓨터 그래픽스 연구실.
Presentation transcript:

3D Graphics for Game Programming (J. Han) Chapter VIII Image Texturing

3D Graphics for Game Programming (J. Han) Texture Addressing Mode  The texture coordinates (u,v) are not necessarily in the range of [0,1]. The texture addressing mode handles (u,v)s outside the range.  Border: The out-of-range coordinates are rendered with a separately defined border color.  Wrap, repeat, or tile: The texture is tiled at every integer junction.  Mirror: The texture is mirrored or reflected at every integer junction. We have smooth transition at the boundaries.

3D Graphics for Game Programming (J. Han) Sampler State in Direct3D  The texture addressing mode can be set by invoking Direct3DDevice9::SetSamplerState method HRESULT SetSamplerState( DWORD Sampler, // texture number D3DSAMPLERSTATETYPE Type, DWORD Value ); typedef enum _D3DSAMPLERSTATETYPE { D3DSAMP_ADDRESSU = 1, // The default is D3DTADDRESS_WRAP D3DSAMP_ADDRESSV = 2, D3DSAMP_ADDRESSW = 3,// For 3D texturing D3DSAMP_BORDERCOLOR = 4, …. } D3DSAMPLERSTATETYPE; typedef enum D3DTEXTUREADDRESS { D3DTADDRESS_WRAP = 1, D3DTADDRESS_MIRROR = 2, D3DTADDRESS_CLAMP = 3, D3DTADDRESS_BORDER = 4,.. } D3DTEXTUREADDRESS, *LPD3DTEXTUREADDRESS;

3D Graphics for Game Programming (J. Han) Sampler State in Direct3D (cont’d)  The sampler state can be set directly by shaders. sampler Sampler = sampler_state // define the states of a sampler named Sampler { // g_pDev->SetTexture( 0, g_pTexture ); Texture = ; // texture name // g_pDev-> SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP ); ADDRESSU = WRAP; // g_pDev-> SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_MIRROR ); ADDRESSV = MIRROR; // … } typedef enum D3DTEXTUREADDRESS { D3DTADDRESS_WRAP = 1, D3DTADDRESS_MIRROR = 2, D3DTADDRESS_CLAMP = 3, D3DTADDRESS_BORDER = 4, D3DTADDRESS_MIRRORONCE = 5, D3DTADDRESS_FORCE_DWORD = 0x7fffffff, } D3DTEXTUREADDRESS, *LPD3DTEXTUREADDRESS;

3D Graphics for Game Programming (J. Han) Texture Filtering – Magnification & Minification  Consider a quad. For each fragment located at (x,y) in the screen, its texture coordinates (u,v) are mapped to the texel address (t x,t y ). We say that the fragment at (x,y) is projected onto (t x,t y ).  Note that (t x,t y ) are floating-point values in almost all cases.  Consequently, texels around (t x,t y ) are sampled. This sampling process is called texture filtering.  The screen-space quad may appear larger than the image texture, and therefore the texture is magnified so as to fit to the quad. There are more pixels than texels.

3D Graphics for Game Programming (J. Han) Texture Filtering – Magnification & Minification (cont’d)  In contrast, the screen-space quad may appear smaller than the image texture, and the texture is minified. The pixels are sparsely projected onto the texture space.  Summary  Magnification: more pixels than texels  Minification : less pixels than texels

3D Graphics for Game Programming (J. Han) Filtering for Magnification  Option 1: Nearest point sampling  A block of pixels can be mapped to a single texel.  Consequently, adjacent pixel blocks can change abruptly from one texel to the next texel, and a blocky image is often produced.

3D Graphics for Game Programming (J. Han) Filtering for Magnification (cont’d)  Option 2: Bilinear interpolation  It is preferred to nearest point sampling not only because the final result suffers much less from the blocky image problem but also because the graphics hardware is usually optimized for bilinear interpolation.

3D Graphics for Game Programming (J. Han) Filtering for Minification  Consider the following checker-board image texture.  If all pixels are surrounded by dark-gray texels, the textured primitive appears dark gray. If all pixels are surrounded by light-gray texels, the textured primitive appears light gray.

3D Graphics for Game Programming (J. Han) Mipmap  Why do we have the problem in minification? Simply put, it is because the texture is larger than the screen-space primitive and therefore many texels are not involved in filtering.  A solution - Decrease the texture size such that all texels are involved. The best case is that the screen-space primitive and the texture have the same size.  For decreasing the texture size, down-sampling is adopted.  Given an original texture of 2 l x 2 l resolution, a texture pyramid of (l + 1) levels is constructed, where the original texture is located at level 0.  The pyramid is called a mipmap.  The level to filter is named level of detail, and is denoted by λ.

3D Graphics for Game Programming (J. Han) Mipmapping (cont’d)  So far, we have regarded a pixel as a point located at the integer coordinates of the screen space. In reality, however, a pixel covers an area on the screen. For simplicity, take the area as square such that the entire screen can be considered to be tiled by an array of square pixels.  Then, a pixel's projection onto the texture space is not a `point' but an `area' centered at the texel address (t x,t y ). The projected area is called the footprint of the pixel.

3D Graphics for Game Programming (J. Han) Mipmapping (cont’d)  In the example, the quad and level-1 texture have the same size. A pixel's footprint covers 2x2 texels in level 0, but covers a single texel in level 1.  When a pixel footprint covers m x m texels of level-0 texture, λ is set to log 2 m.

3D Graphics for Game Programming (J. Han) Mipmapping (cont’d)  In the example, the screen-space quad and level-2 texture have the same size. A pixel's footprint covers exactly a single texel in level-2 texture, which is then filtered.  In this and previous examples, observe that all texels are involved in filtering.

3D Graphics for Game Programming (J. Han) Mipmapping (cont’d)  In the following example, λ = log 2 3 = , and so we see levels 1 and 2, more formally  λ  and  λ .

3D Graphics for Game Programming (J. Han) Mipmapping (cont’d)  Between  λ  and  λ , which one to choose?  We can take the nearest level.  We can take both of them and linearly interpolate the filtering results. If bilinear interpolation is performed at each level, this is called trilinear interpolation.

3D Graphics for Game Programming (J. Han) Mipmapping - Examples  Consider a mipmap of stripe texture, and a long thin quad.  When the quad is orthogonal to the view direction, the texturing result will be as follows.

3D Graphics for Game Programming (J. Han) Mipmapping – Examples (cont’d)  What if the quad is angled obliquely away from the viewer?  In general, for each pixel of the screen-space primitive, it is determined whether the texture is magnified or minified.  The black lines shown below partition the quad into the magnified and minified parts.  Magnification occurs at the lower part of the quad, and level-0 texture is used for texturing.  In contrast, minification occurs at the upper part of the quad, and the upper levels of the mipmap may be involved.

3D Graphics for Game Programming (J. Han) Mipmapping – Examples (cont’d)  Mipmapping is implemented in hardware. However, the graphics APIs allow us to control the mipmap filtering mechanism.  The major control is over magnification filter (MAGFILTER), minification filter (MINFILTER), and mipmap level selection (LEVEL).  MAGFILTER  Nearest point sampling (NEAREST)  Bilinear interpolation (BILINEAR)  MINFILTER  Nearest point sampling (NEAREST)  Bilinear interpolation (BILINEAR)  LEVEL  Nearest level (NEAREST)  Two levels to be linearly interpolated (LINEAR)

3D Graphics for Game Programming (J. Han) Mipmapping – Examples (cont’d)  Let us replace level-0 texture, just for the visualization purpose.

3D Graphics for Game Programming (J. Han) Mipmapping – Examples (cont’d) magnification minification area:2 level 0 level 0 level 0 level 1 e c d b a a b c d e

3D Graphics for Game Programming (J. Han) Mipmapping – Examples (cont’d)

3D Graphics for Game Programming (J. Han) Anisotropic Filtering  Consider a square pixel and its footprint in the texture space.  A pixel's footprint is an anisotropic quadrilateral in general.  To compute λ, traditional mipmapping algorithms often use the longest edge of the anisotropic footprint. Suppose that its length is m. Then, λ is set to log 2 m. Filtering the mipmap with such λ is equivalent to taking the isotropic footprint, the size of which is m x m.  Observe that the m x m–sized isotropic footprint contains blue texels whereas the anisotropic one does not. Consequently, the textured color of the pixel will be a blend of blue and white even though it is supposed to be just white.  This explains why the top part of the textured quad is over-blurred.  What is desired is anisotropic filtering, which filters only the area covered by the anisotropic footprint.

3D Graphics for Game Programming (J. Han) Anisotropic Filtering (cont’d)  Anisotropic filtering algorithm – an example with a parallelogram footprint  The anisotropic footprint is divided into smaller nearly-isotropic footprints, using the lengths of the longer edge and shorter edge.  Each of the isotropic footprints is processed separately, and is assigned a sample point.  The length of the shorter edge of the original footprint determines the level of detail λ.  For the directed level(s), each sample point is used for filtering.  All the results are averaged.

3D Graphics for Game Programming (J. Han) Anisotropic Filtering (cont’d)  Compare the results.  The top part of the quad – The textured image created only with trilinear interpolation appears blurry toward the horizon. In contrast, the anisotropic filtering preserves the sharpness of the image texture at the area.  The area covered by the low-level textures - The area of the quad affected by level-0 texture is expanded because λ is determined by the length of the anisotropic footprint's shorter edge, and therefore the lower levels of the mipmap are more frequently sampled.

3D Graphics for Game Programming (J. Han) Trilinear Interpolation vs. Anisotropic Filtering

3D Graphics for Game Programming (J. Han) Texturing and Lighting  Assume that the Phong model is used for lighting.  The diffuse reflectance m d was typically given as a constant.  In reality, however, m d varies over the surface of an object in most cases. Then, m d can be set to the color read from the texture, not a constant color.  Similarly, the specular reflectance m s can be read from another texture.