Texture Mapping. To add surface details… World of Warcraft, Blizzard Inc. More polygons (slow and hard to handle small details) Less polygons but with.

Slides:



Advertisements
Similar presentations
Hofstra University1 Texture Motivation: to model realistic objects need surface detail: wood grain, stone roughness, scratches that affect shininess, grass,
Advertisements

1 Understanding of OpenGL TA: Dong Hyun Jeong Instructor : Dr. Kalpathi Subramanian Texture Mapping.
TEXTURE MAPPING JEFF CHASTINE 1. TEXTURE MAPPING Applying an image (or a texture ) to geometry 2D images (rectangular) 3D images (volumetric – such as.
OpenGL Texture Mapping
CSC345: Advanced Graphics & Virtual Environments
OpenGL Texture Mapping
OpenGL Texture Mapping Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
OpenGL Texture Mapping April 16, Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Basic Stragegy Three steps to applying a texture.
CS 4731: Computer Graphics Lecture 17: Texturing Emmanuel Agu.
Texture Mapping A way of adding surface details Two ways can achieve the goal:  Surface detail polygons: create extra polygons to model object details.
Computer Graphics Texture Mapping Eriq Muhammad Adams
Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
2IV60 Computer Graphics set 10: Texture mapping Jack van Wijk TU/e.
11/11/04© University of Wisconsin, CS559 Fall 2004 Last Time Shading Interpolation Texture mapping –Barycentric coordinates for triangles.
1 SIC / CoC / Georgia Tech MAGIC Lab Rossignac Textures and shadows  Generation  Mipmap  Texture coordinates,
Texture Mapping. Scope Buffers Buffers Various of graphics image Various of graphics image Texture mapping Texture mapping.
Texture Mapping. Introduction What is Texture Mapping? Types of Texture Mapping –1D, 2D and 3D SDL and OpenGL.
Texture Mapping. Example Mappings Mapping Techniques Consider the problem of rendering a sphere in the examples The geometry is very simple - a sphere.
Texture Mapping Course: Computer Graphics Presented by Fan Chen
Computer Graphics Ben-Gurion University of the Negev Fall 2012.
Mapping method Texture Mapping Environmental mapping (sphere mapping) (cube mapping)
An Interactive Introduction to OpenGL Programming Ed Angel
CS 445 / 645 Introduction to Computer Graphics Lecture 19 Texture Maps Lecture 19 Texture Maps.
ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny TA. Abhishek Gattani TA. Stephen
Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph - SIGGraph.
CS380 LAB IV OpenGL Jonghyeob Lee Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Texture Mapping Fall, Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.
Texture Mapping. 2 Motivation A typical modern graphics card can handle 10s of millions of polygons a second. How many individual blades of grass are.
OpenGL Texture Mapping. 2 Objectives Introduce the OpenGL texture functions and options.
Texture Mapping Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CS 480/680 Computer Graphics OpenGL Texture Mapping Dr. Frederick C Harris, Jr. Fall 2011.
Texture Mapping Software College, Shandong University Instructor: Zhou Yuanfeng
Texture Mapping in OpenGL. Texture Mapping Imaging we are “pasting” a picture onto a model  Which part of the picture will be pasted onto which part.
Texture Mapping Drawing Pictures on Polygons. Texture Mapping.
TEXTURES & OTHER GOODIES Computer Graphics. glTexCoord2f(...); + =
111/17/ :24 UML Solution Involves Selection of Discrete Representation Values.
2 COEN Computer Graphics I Evening’s Goals n Discuss displaying and reading image primitives n Describe texture mapping n Discuss OpenGL modes and.
Texture Mapping. 2 3 Loading Textures void glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border,
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
OpenGL Programming Guide : Texture Mapping Yoo jin wook Korea Univ. Computer Graphics Lab.
Computer Graphics Bing-Yu Chen National Taiwan University.
1 Graphics CSCI 343, Fall 2015 Lecture 25 Texture Mapping.
Texture Mapping and NURBS Week 7 David Breen Department of Computer Science Drexel University Based on material from Ed Angel, University of New Mexico.
Details of Texture Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 1, 2003.
第三课. Overview of this Section Concept of Texture Mapping ( 纹理映射 ) 2D Texture 3D Texture Environment Mapping Bump Mapping Others OpenGL Implementation.
1 Chapter 7 Texture Mapping. 2 The Limits of Geometric Modeling Although graphics cards can render over 10 million polygons per second, that number is.
CS425 © 2003 Ray S. Babcock Pixels and Bitmaps ● OpenGL allows us to work directly with bits and groups of bits, or pixels, which flow down a parallel.
Texture Mapping CEng 477 Introduction to Computer Graphics.
Texture Mapping Sung-Eui Yoon (윤성의) CS380: Computer Graphics
Texture Mapping Fall, 2016.
Texture Mapping 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
Texture Mapping We can improve the realism of graphics models by mapping a texture pattern (image) onto the modeled object surface. We refer to this technique.
OpenGL Texture Mapping
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Advanced Graphics Algorithms Ying Zhu Georgia State University
Advanced Graphics Algorithms Ying Zhu Georgia State University
OpenGL Texture Mapping
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Assignment 3b Q&A.
Chapters VIII Image Texturing
Introduction to Texture Mapping
(c) University of Wisconsin, CS 559
3D Game Programming Texture Mapping
Computer Graphics Practical Lesson 6
OpenGL Texture Mapping
OpenGL Texture Mapping
Programming Textures Lecture 15 Fri, Sep 28, 2007.
3D Game Programming Texture Mapping
OpenGL Texture Mapping
Presentation transcript:

Texture Mapping

To add surface details… World of Warcraft, Blizzard Inc. More polygons (slow and hard to handle small details) Less polygons but with textures (much faster)

Advantages Texture mapping doesn’t affect geometry processing, such as transformation, clipping, projection, … It does affect rasterization, which is highly accelerated by hardware. Textures can be easily replaced for more details: texture mod in games. The Elder Scrolls: Skyrim Before mod After mod

Texture Representation Bitmap textures (supported by OpenGL) Procedural textures (used in advanced programs) Bitmap texture A 2D image, represented by a 2D array (width-by-height). Each pixel (or called texel) has a unique texture coordinate (s, t). s and t are defined from 0 to 1. Given (s, t), we can find a unique image value.

Texture Value Lookup To find the unique image value at (s, t): Nearest neighbor Bi-linear interpolation Other filters (s, t) is not exactly at the texel location. (1, 1)

Mapping from Texture to Polygon Texture mapping is performed in rasterization. Given texture coordinates at vertices, Calculate the texture coordinate (s, t) at each pixel, using linear interpolation Find the texture value using texture lookup Combine it with the illumination effect… (0.5, 0.5) (1, 0.5) (0.5, 1) (1, 1) (s, t)

Texture Mapping s t x y z 3D world Space 2D Screen Space Texture Space Projection Textue lookup

OpenGL Texture Mapping Steps in OpenGL Specify the texture: read/generate the image, assign it as a texture Specify texture mapping parameters: wrapping, filtering, … Enable OpenGL texture mapping (GL_TEXTURE_2D) Assign texture coordinates to vertices Draw your objects Disable OpenGL texture mapping

Specify Textures Load the texture from main memory into texture memory For example, The texture resolution must be power of 2. glTexImage2D(target, level, iformat, width, height, border, format, type, pointer); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, pointer); GLuByte pointer[64][64][3];

Fix Texture Size If the resolution is not power of 2: Pad zeros by yourself (remember to adjust texture coordinates for your vertices, or you will see the dark boundary). Or, resize the image using: GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void *dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, const void *dataOut)

Texture Mapping Parameters (1) (s, t) in the texture space are from 0 to 1. But what if vertices have texture coordinates beyond this range? For example, (1, 1) (0, 0) (2, 2) GL_REPEAT Texture (0, 0) (2, 2) GL_CLAMP glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)

Texture Mapping Parameters (2) Since a texture can be mapped arbitrarily to an image region, it can either be magnified or minified. Mag filter: To interpolate a value from neighboring texels Min filter: Combine multiple texels into a single value Magnification Screen Minification Screen

Without proper filtering, you get texture aliasing when the texture is minified.

Texture Mapping Parameters (3) OpenGL texture filtering: Nearest Neighbor (fast, but with aliasing) Bi-linear Interpolation (slow, but less aliasing) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)

Texture Color Blending Determine how to combine the texture color with the object color GL_MODULATE: multiply texture with object color GL_BLEND: linear combination of texture and object color GL_REPLACE: use texture color to replace object color For example, Remember to use GL_MODULATE (default) if you want to have the light effect. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)

Enable/Disable Textures glEnable(GL_TEXTURE_2D) Remember to disable texture mapping when drawing non-texture polygons. glDisable(GL_TEXTURE_2D)

Specify Texture Coordinates Define texture coordinates before each vertex Texture coordinates can be transformed as well, using a GL_TEXTURE matrix. Switch to: Apply 2D transformation Then draw your object Not necessary to use glBegin(GL_QUADS); glTexCoord2D(0, 0); glVertex3f(-1, 0, -1);... glEnd(); glMatrixMode(GL_TEXTURE);

Summary … glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); … glEnable(GL_TEXTURE_2D); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, img_pointer); glBegin(GL_TRIANGLES); glTexCoord2D(0, 0); glNormal3f(0, 1, 0); glVertex3f(-1, 0, -1); … glEnd(); glDisable(GL_TEXTURE_2D); …

Mip Map Mip map is a technique that helps improve the computational efficiency and avoid aliasing: Minification Original Image Mip Map

Multiple MipMap Textures in OpenGL … glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); … Gluint texture1, texture2; glGenTextures(1, &texture1); glBindTexture(GL_TEXTURE_2D, texture1); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, data1); glGenTextures(1, &texture2); glBindTexture(GL_TEXTURE_2D, texture2); gluBuild2DMipmaps(GL_TEXTURE_2D, 4, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data2); //To use them glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture1); Draw_Object_1(); glBindTexture(GL_TEXTURE_2D, texture2); Draw_Object_2(); Number of input channels

Surface Parameterization Find texture coordinates for a planar surface is trivial. However, finding texture coordinates for an arbitrarily curved surface is a research problem called: surface parameterization. It means parametrizing the surface using texture coordinates (s, t).

An Example 2D Texture 3D Earth

Planar Projection Vertex (x, y, z) -> Texture (x, y) Vertex (x, y, z) -> Texture (y, z) Vertex (x, y, z) -> Texture (x, z)

Planar Projection

Cylindrical Projection Project any 3D point onto a cylinder. The height and the angle become texture coordinates: (s, t).

Spherical Projection Project any 3D point onto a unit sphere. The spherical coordinates are texture coordinates: (s, t).

Parametric Surfaces Surfaces can also be created in a parametric way. Any 3D point on the surface are defined as functions of texture coordinates:

Rasterization Rasterization uses scanlines to interpolate a lot of things: Color (Gouraud shading) Depth (depth buffer) Texture coordinates For every scanline

Linear Texture Coordinate Interpolation It has artifact when using perspective projection and large polygons. Textures are warped! Very noticeable in animation.

Linear Texture Coordinate Interpolation This is because perspective projection has foreshortening effect. Linear interpolation in 2D does not consider this. In a 2D view In a 3D perspective view

Solution Let w be the homogenous coordinate. Interpolate (s/w, t/w, 1/w) to get three values: (a, b, c). The final result is: (a/c, b/c). (x 0, y 0, z 0, w 0 ) (s 0 /w 0, t 0 /w 0, 1/w 0 ) (x 1, y 1, z 1, w 1 ) (s 1 /w 1, t 1 /w 1, 1/w 1 ) (x 2, y 2, z 2, w 2 ) (s 2 /w 2, t 2 /w 2, 1/w 2 ) (a, b, c)

Perspective Correction Before CorrectionAfter Correction

Perspective Correction To enable perspective correction: Hint can be: GL_NICEST (with correction, sloow) GL_FASTEST (linear) GL_DONT_CARE (linear) glHint(GL_PERSPECTIVE_CORRECTION_HINT, hint)

Advanced Textures OpenGL only uses textures to change surface colors. But textures can have other usages. For example, the bump map that changes the surface normal. (The geometry stays the same. You can tell this from the silhouette.)

Bump Map

Displacement Map You can even change the geometry, by treating the texture as an offset map to the vertex position.

Environment Map You can surround the 3D space with a texture image too. You can consider the 3D space is contained in an infinite sphere, textured by an image.

Texture Animation Animate the texture over time Apply transformations to texture coordinates Change textures (but try to avoid multiple texture loadings) A fountain in the game “world of Warcraft”