Texture Mapping. Typical application: mapping images on geometry 3D geometry (quads mesh) + RGB texture 2D (color-map) =

Slides:



Advertisements
Similar presentations
Texture Mapping. Texturing  process that modifies the appearance of each point on a surface using an image or function  any aspect of appearance can.
Advertisements

1 Understanding of OpenGL TA: Dong Hyun Jeong Instructor : Dr. Kalpathi Subramanian Texture Mapping.
Real-Time Rendering TEXTURING Lecture 02 Marina Gavrilova.
Week 7 - Wednesday.  What did we talk about last time?  Transparency  Gamma correction  Started texturing.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Textures II Week 8, Wed.
Texture Mapping CPSC /24/03 Abhijeet Ghosh.
Hofstra University1 Texture Motivation: to model realistic objects need surface detail: wood grain, stone roughness, scratches that affect shininess, grass,
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.
1 Lecture 12 Texture Mapping uploading of the texture to the video memory the application of the texture onto geometry.
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.
Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping.
Texture Mapping A way of adding surface details Two ways can achieve the goal:  Surface detail polygons: create extra polygons to model object details.
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.
Texture Mapping. To add surface details… World of Warcraft, Blizzard Inc. More polygons (slow and hard to handle small details) Less polygons but with.
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.
Texture Mapping + Texture Object = Texture Mapped Object.
Fundamentals of Computer Graphics Part 9 Discrete Techniques prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared.
11/11/04© University of Wisconsin, CS559 Fall 2004 Last Time Shading Interpolation Texture mapping –Barycentric coordinates for triangles.
Texture Mapping. Scope Buffers Buffers Various of graphics image Various of graphics image Texture mapping Texture mapping.
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
09/09/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Event management Lag Group assignment has happened, like it or not.
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
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
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.
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.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
OpenGL Graphics Textures. Quiz You didn't see that coming!
Computer Graphics Bing-Yu Chen National Taiwan University.
1 Graphics CSCI 343, Fall 2015 Lecture 25 Texture Mapping.
第三课. Overview of this Section Concept of Texture Mapping ( 纹理映射 ) 2D Texture 3D Texture Environment Mapping Bump Mapping Others OpenGL Implementation.
Texture Mapping. For Further Reading Angel 7 th Ed: ­Chapter 7: 7.3 ~ 7.9 Beginning WebGL: ­Chapter 3 2.
CSc4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Texture Mapping.
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.
Texture Mapping Fall, 2016.
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
OpenGL Texture Mapping
Introduction to Computer Graphics with WebGL
Chapters VIII Image Texturing
Introduction to Texture Mapping
(c) University of Wisconsin, CS 559
Mipmaps Lecture 16 Mon, Oct 1, 2007.
3D Game Programming Texture Mapping
Computer Graphics Practical Lesson 6
OpenGL Texture Mapping
OpenGL Texture Mapping
Mipmaps Lecture 13 Wed, Oct 12, 2005.
Programming Textures Lecture 15 Fri, Sep 28, 2007.
Texture Mapping Ed Angel Professor Emeritus of Computer Science
3D Game Programming Texture Mapping
OpenGL Texture Mapping
Presentation transcript:

Texture Mapping

Typical application: mapping images on geometry 3D geometry (quads mesh) + RGB texture 2D (color-map) =

More examples

Texture Mapping The fragment operations can access a specialized RAM –The Texture RAM –Organized in a set of Textures Each texture is an array 1D, 2D o 3D of Texels (texture elements) of the same type

Texels Typical examples of texels: –each texel is a color (components: R-G-B, or R-G-B-A) The texture is a "color-map" –each texel is an alpha value the texture is an "alpha-map" –each texel is a normal (components: X-Y-Z) the texture is a "normal-map" or "bump-map" –each texel contains a specularity value the texture is a "shininess-map" –...

More examples +=

Texture Mapping: History 1974 introduced by Ed Catmull –In its Phd Thesis Only in 1992 (!) we have texture mapping hardware –Silicon Graphics RealityEngine 1992 on: increasingly used and integrated in graphic cards –First of all by low end graphic boards Today: a fundamental rendering primitive –the main image-based technique Ed Catmull (MEGA-MEGA- GURU)

Notation Texture 2D u v texel Texture Space (or "parametric space" or "u-v space") A Texture is defined In the region [0,1] x [0,1] of the "parametric space" 512 texels 1024 texels 1.0

Texture Mapping We associate to each vertex (of each triangle) its u,v coordinates in the texture space Screen Space x 0,y 0 x 2,y 2 x 1,y 1 u 0,v 0 u 1,v 1 u 2,v 2 Position of the 1st vertex Attributes of the 1st vertex u 0,v 0 u 1,v 1 u 2,v 2

Texture Mapping More precisely, we define a mapping between the 3D triangle 3D and a texture triangle Texture Space Screen Space

Texture Mapping each fragment has its own u,v coordinates in the texture space Texture Space Screen Space texture look-up

Texture Mapping Screen buffer Texture RAM interpolation texture coordinates texture coordinates interpolated including: texture coordinates (per vertex!) texture look-up Fragments & interpolated attributes Vertices & their attributes Projected Vertices & computed attributes Triangles rasterizer set- up Segments rasterizer set- up points rasterizer set- up vertex computation Fragment computations

Problem: linear interpolation of texture coordinates Not true for perspective projection! –It is only an approximation –It works fine to interpolate colors, normals,.. –Not applicable to interpolate texture coordinates... V1V1 V2V2 V3V3 p f(p) f( v 1 ) f( v 2 ) f( v 3 ) projection f p has barycentric coordinates a,b,c In the triangle v 1 v 2 v 3 f(p) has barycentric coordinates a,b,c in the triangle f(v 1 ) f(v 2 ) f(v 3 )

Problem: linear interpolation of texture coordinates Example: u v 1 1 u,v= (1,0) u 1,v 1 = (1,1) u 1,v 1 = (0,1) u 1,v 1 = (0,0)

Problem: linear interpolation of texture coordinates Example:

Solution: Perspective Correction p has barycentric coordinates c 0 c 1 c 2 V0V0 V2V2 V1V1 A 0,B 0... A 1,B 1... A 2,B 2... p p = c 0 v 0 + c 1 v 1 + c 2 v 2 Attributes of p: (not considering the “ perspective correction ") A p = c 0 A 0 + c 1 A 1 + c 2 A 2 B p = c 0 B 0 + c 1 B 1 + c 2 B 2 = ( x 0, y 0, z 0, w 0 )

Solution: Perspective Correction p has barycentric coordinates c 0 c 1 c 2 V0V0 V2V2 V1V1 A 0,B 0... A 1,B 1... A 2,B 2... p p = c 0 v 0 + c 1 v 1 + c 2 v 2 Attributes of p: (not considering the “ perspective correction ") w0w0 w1w1 A p = c 0 A 0 + c 1 A 1 + c 2 A 2 A0A0 w0w0 A1A1 w1w1 A2A2 w2w2 Ap =Ap = 1 11 w2w2 = ( x 0, y 0, z 0, w 0 )

Solution: Perspective Correction Screen buffer Original attribute A Apply transformations compute: A' = A / w and w' = 1 / w c 0 + c 1 + c 2 A0A0 w0w0 A1A1 w1w1 A2A2 w2w2 Ap =Ap = 1 w0w0 1 w1w1 1 w2w2 interpolate A' and w' Final fragment attribute: A' / w' c 0 + c 1 + c 2 Fragments & interpolated attributes Vertices & their attributes Projected Vertices & computed attributes Triangles rasterizer set- up Segments rasterizer set- up points rasterizer set- up vertex computation Fragment computations

Perspective Correction WithoutWith

Perspective Correction Texture mapping with perspective correction –Also known as Perfect texture mapping

Note: the texture must be loaded Screen buffer Texture RAM LOADLOAD Fragments & interpolated attributes Vertices & their attributes Projected Vertices & computed attributes Triangles rasterizer set- up Segments rasterizer set- up points rasterizer set- up vertex computation Fragment computations

Note: the texture must be loaded 1.From hard disk to main RAM memory (in the motherboard) 2.From main RAM memory to Texture RAM (on board of the graphics HW) Both steps are quite slow. It is not possible to accomplish them once per frame!

In OpenGL As an example: glEnable(GL_TEXTURE_2D); glBindTexture (GL_TEXTURE_2D, ID); glTexImage2D ( GL_TEXTURE_2D, 0, // mipmapping GL_RGB, // original format imageWidth, imageHeight, 0, // border GL_RGB, // RAM format GL_UNSIGNED_BYTE, imageData);

Assigning texture coordinates to vertices Screen buffer Texture RAM interpolation texture coordinates Interpolated texture coordinates including: coordinates texture (per vertex!) texture look-up including: texture coordinates (per vertex!) Fragments & interpolated attributes Vertices & their attributes Projected Vertices & computed attributes Triangles rasterizer set- up Segments rasterizer set- up points rasterizer set- up vertex computation Fragment computations

Assigning texture coordinates to vertices 2 possibilities: –Computing textures coordinates on the fly During the rendering… –Precomputing (and store them within the mesh) The choice is application-dependent!

Difficult problem: u-v mapping Associate texture coordinates to each vertex of the mesh –During preprocessing u v u v

Difficult problem: u-v mapping Hand-made or automated

In OpenGL Like any other attribute TexCoord2d( u,v )

Assigning texture coordinates to vertices Screen buffer Texture RAM interpolating texture coordinates texture coordinates interpolated texture look-up texture coordinates (transformed) including: texture coordinates Fragments & interpolated attributes Vertices & their attributes Projected Vertices & computed attributes Triangles rasterizer set- up Segments rasterizer set- up points rasterizer set- up vertex computation Fragment computations

Assigning texture coordinates to vertices 2 possibilities: –Computing textures coordinates on the fly During the rendering… –Precomputing (and store them within the mesh)

Assigning texture coordinates to vertices Screen buffer Texture RAM interpolating texture coordinates Interpolated texture coordinates texture look-up texture coordinates compute texture coordinates Using the position Fragments & interpolated attributes Vertices & their attributes Projected Vertices & computed attributes Triangles rasterizer set- up Segments rasterizer set- up points rasterizer set- up vertex computation Fragment computations

Automatically computed Idea: from (x,y,z) to (u,v) - Linearly Using object or view coordinate –(before or after the trasformation) Examples:

Automatically computed Even 1D 1D texture!

Assigning texture coordinates to vertices 2 possibilities: –Computing textures coordinates on the fly During the rendering… –Precomputing (and store them within the mesh)

Environment mapping: spherical Environment map: a texture containing the color of the environment “reflexed by each normal of the half-sphere”. The texture coordinate is the transformed normal!

Environment mapping: spherical Simulates a mirror-like object reflecting a far-away background simulates a complex material (fixed lighting)

Environment mapping: cube frontrightback below above left

Environment mapping: cube Screen buffer Texture RAM interpolating 3D texture coordinates interpolated coordinates 3D texture Project on the cube, look-up the corresponding face compute 3D Texture coordinates [-1,+1] x [-1,+1] x [-1,+1] As view ray reflexed by the normal Fragments & interpolated attributes Vertices & their attributes Projected Vertices & computed attributes Triangles rasterizer set- up Segments rasterizer set- up points rasterizer set- up vertex computation Fragment computations

Environment mapping: cube frontrightback below above left

Environment mapping: cube and spherical Spherical: –one texel for each direction in the half- sphere Projected on a circle –the texture coordinate is the normal –It has the "headlight“ effect: I can only rotate the object while the viewpoint does not change Cube –one texel for each direction in the sphere Projected on the surface of the cube –the texture coordinate is the view direction reflexed by the normal –The viewpoint can rotate around a steady object

Automated computation of texture coordinates glEnable(GL_TEXTURE_GEN_S); 1- abilitate: 2- choice of the mode: glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, mode ) S, T, R, Q mode = GL_OBJECT_LINEAR GL_EYE_LINEAR GL_SPHERE_MAP Computes the texture coordinates from the position in object coordinates (before the trasformation) Computes the texture coordinates from the position in view coordinates (after the MODEL-VIEW) The texture coordinates is the reflexed view ray (using the normal) (after the MODEL-VIEW)

Automated computation of texture coordinates glTexGenfv(GL_S, GL_EYE_PLANE, v); 3- choice of the plane S, T, R, Q EYE OBJECT or 4 elements vector The resulting texture coordinate = v T pos_vertex (It’s the distance from the plane!)

u Texture Look-up out of bounds: “clamp” mode if (u 1) u←1; if (v 1) v←1; 1 1 v

Texture Look-up out of bounds: “repeat” mode u v 1 1 u ← u – [ u ] v ← v – [ v ]

Repeated textures Typical use: Very space-efficient! Note: the texture must be TILEABLE

In OpenGL glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); or note: u and v treated separately Texture parameters. each texture loaded in memory has its own parameters.

Texture Look-up A fragment can have non-integer coordinates (in texels) Texture Space Screen Space texture look-up

pixel Texture Look-up Texture SpaceScreen Space pixel texel one pixel = less than one texel one pixel = more than one texel minification magnification

Magnification Solution 1: Use the texel containg the pixel (that is, the texel whose center is closest to the u,v coordinates of the fragment) Equivalent to rounding up the texel coordinates to the nearest integer "Nearest Filtering" u v

Magnification texture 128x128 Nearest Filtering: result "texels are visible !"

Magnification Solution 2: Compute the average of the four closest texels Bilinear Interpolation u v

Magnification texture 128x128 Bilinear Interpolation: result

Magnification Nearest filtering: –Texels are visible –Ok if texel borders are useful –More efficient Bilinear Interpolation –Usually provides better quality –Less efficient –Sometimes there is an “out-of-focus“ effect

Minification Nearest Filtering Bilinear interpolation Does not solve the problem

Minification: MIP-mapping MIP-map level 0 MIP-map level 1 MIP-map level 2 MIP-map level 3 MIP-map level 4 (only one texel) MIP-mapping: "Multum In Parvo"

Mipmap Math Define a scale factor,  =texels/pixel –  is the maximum between  x and  y –It can vary in the same triangle –Can be derived from the transformation matrices, computed for the Vertices and interpolated for the fragments The mipmap level to use is: log 2  –level 0 = maximum resolution –if level<0 what is the reason? –note: the level might not be an integer

Minification: MIP-mapping Bilinear interpolation MIP-mapping

Minification: MIP-mapping Other example

In OpenGL glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); or Choose the magnification filter:

In OpenGL glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mode ); mode = GL_NEAREST GL_LINEAR GL_NEAREST_MIPMAP_NEAREST GL_LINEAR_MIPMAP_NEAREST GL_NEAREST_MIPMAP_LINEAR GL_LINEAR_MIPMAP_LINEAR where Choose the minification filter: Trilinear interpolation

In OpenGL Load on the graphics card all the mipmapping levels. –One-by-one: glTexImage2D ( GL_TEXTURE_2D, i, // MIP-map level GL_RGB, // original format imageWidth, imageHeight, 0, // border GL_RGB, // RAM format GL_UNSIGNED_BYTE, imageData);

In OpenGL Load on the graphics card all the mipmapping levels. –All together (using the glu library): glTexImage2D ( GL_TEXTURE_2D, 0, // MIP-map level GL_RGB, // original format imageWidth, imageHeight, 0, // border GL_RGB, // RAM format GL_UNSIGNED_BYTE, imageData); gluBuild2DMipmaps (