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

Slides:



Advertisements
Similar presentations
Virtual Realism TEXTURE MAPPING. The Quest for Visual Realism.
Advertisements

Texture Mapping. Texturing  process that modifies the appearance of each point on a surface using an image or function  any aspect of appearance can.
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
Real-Time Rendering TEXTURING Lecture 02 Marina Gavrilova.
Texture Mapping. Typical application: mapping images on geometry 3D geometry (quads mesh) + RGB texture 2D (color-map) =
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.
Informationsteknologi Thursday, November 29, 2007Computer Graphics - Class 131 Today’s class Antialiasing Hidden surface removal Texture mapping.
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.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
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
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.
Fundamentals of Computer Graphics Part 9 Discrete Techniques prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared.
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. 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
ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny TA. Abhishek Gattani TA. Stephen
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 Drawing Pictures on Polygons. Texture Mapping.
TEXTURES & OTHER GOODIES Computer Graphics. glTexCoord2f(...); + =
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.
1 Graphics CSCI 343, Fall 2015 Lecture 25 Texture Mapping.
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.
Texture Mapping. For Further Reading Angel 7 th Ed: ­Chapter 7: 7.3 ~ 7.9 Beginning WebGL: ­Chapter 3 2.
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.
Viewing and Texture Mapping In OPENGL. VIEWING 1.One or more objects 2.A viewer with a projection surface 3.Projectors that go from the object(s) to.
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.
Madhulika (18010), Assistant Professor, LPU.
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
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Chapters VIII Image Texturing
Texture Motivation: to model realistic objects need surface detail: wood grain, stone roughness, scratches that affect shininess, grass, wall paper. Use.
3D Game Programming Texture Mapping
OpenGL Texture Mapping
OpenGL Texture Mapping
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:

Hofstra University1 Texture Motivation: to model realistic objects need surface detail: wood grain, stone roughness, scratches that affect shininess, grass, wall paper. Use geometry, model surface detail with polygons; good for large scale detail, too expensive otherwise. Improvement: map an image of the details onto simple geometry

Hofstra University2 The wall

Hofstra University3 The wall

Hofstra University4 The Wall: Brick

Hofstra University5 The Wall: Checkers

Hofstra University6 Texture Mapping s t x y z image geometry screen Ed Angel

Hofstra University7 Texture Mapping and the OpenGL Pipeline geometry pipeline vertices pixel pipeline image rasterizer Images and geometry flow through separate pipelines that join at the rasterizer “complex” textures do not affect geometric complexity Ed Angel

Hofstra University8 Texture mapping Texture mapping: adding surface detail by mapping texture patterns to the surface Technique developed by Catmull (1974), Blinn and Newell (1976).

Hofstra University9 Texture mapping methods 2D texture mapping: paint 2D pattern onto the surface Environmental (reflection) mapping Bump mapping: perturb surface normals to fool shading algorithms Procedural texture mapping, 3D texture

Hofstra University10 More Examples Jim Blinn

Hofstra University11 Environment Mapping Yoshihiro Mizutani and Kurt Reindel

Hofstra University12 2D texture mapping overview Texture array is a 2D image pattern With elements texels Value at a texel affects surface appearance The “texture map” determines how the pattern lies on the surface

Hofstra University13 2D texture mapping overview Rendering uses the texture mapping Find surface that is front most at current pixel Find the the surface patch corresponding to the pixel Find the part of the texture pattern corresponding to the surface patch Use that part of the texture pattern in setting the pixel color

Hofstra University14

Hofstra University15 2D texture mapping Source: 2D pattern from drawing, photo, procedure Destination: any surface, easier if surface given in parametric form The map from 2D texture coord to 3D object Texture mapping transformation: 2D screen coord  3D object coord  2D texture coord and back (see previous slide)

Hofstra University16 Mapping the 2D texture to the surface The map: 2D texture(s,t)  3D object(x,y,z) Mapping onto triangle is not difficult Mapping onto triangular mesh is more difficult (have to handle texture discontinuity) Mapping onto parametric surface is easier Alternative: use an intermediate parametric surface (cylinder, sphere)

Hofstra University17 Based on parametric texture coordinates glTexCoord*() specified at each vertex s t 1, 1 0, 1 0, 01, 0 (s, t) = (0.2, 0.8) (0.4, 0.2) (0.8, 0.4) A BC a b c Texture SpaceObject Space Mapping a Texture

Hofstra University18 Mapping texture onto parametric surface Point on the parametric surface

Hofstra University19 Mapping texture onto parametric surface using liner map The map from texture to the parametric coord using invertible linear map between the texture space (s,t) and the domain (u,v)

Hofstra University20 Mapping texture onto parametric surface, example Does not take into account curvature of surface Equal size texture patches are stretched to fit various areas

Hofstra University21 Mapping texture to a surface using an intermediate surface Two-step mapping Map the texture to a simple intermediate surface (sphere, cylinder, cube) Map the intermediate surface (with the texture) onto the surface being rendered

Hofstra University22 Two-step mapping example parametric form cylinder: x = r cos(2 PI u) y = r sin(2 PI u) z = v h 0<=u,v<=1 first step: u = s, v = t sphere cube

Hofstra University23 Two-step mapping example Second-step: map intermediate surface to the surface being rendered Various strategies: a, b, c

Hofstra University24 The texture mapping transformation

Hofstra University25 Texture mapping transformation Consider surface visible at current pixel. Find the patch on the surface that corresponds to it. Map screen coord of pixel corners back to object Find texels that map to the surface patch If multiple texels lie on patch combine them: weighted avg; supersampling with postfiltering

Hofstra University26 2DTexture mapping in OpenGL Pixel pipeline Texture map done at rasterization stage

Hofstra University27 Texture Mapping in OpenGL 1. Get hold of texture array 2. Create texture object (TO) and specify texture for it TO maintains the texture May have multiple TOs 3. Specify mode for applying texture to pixels possibilities for computing final using texture Replace (use the texture to paint): only texture Modulate (use the texture to modulate/scale the color): lighting and texture Constant RGB color blended in based on texture 4. Enable texture mapping Must enable before drawing 5. Draw the scene providing both texture and geometric coordinates Texture coordinates specify how the texture should be aligned on the fragments to which it is applied Indicate how out of range TC should be processed Does texture repeat to cover object or is it clamped to the vertices

Hofstra University28 GLuint texName; void init(void) { … load or create an image and store it in array, say image, of wize wxh, and type gl_type glGenTextures(1,&texName); glBindTexture(GL_TEXTURE_2D, texName); 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_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, w,h, 0, GL_RGBA, gl_type, image); } Example: Texture mapping initialization Name and create texture object for texture image Names and makes texture currently available Texture map specification: load the image and set parameters Texture map parameters: how texture to be wrapped and colors filtered if mismatch b/w texels and pixels

Hofstra University29 void display(void) { glClear color bufer and depth buffer bits glEnable(GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glBindTexture(GL_TEXTURE_2D, texName); glBegin(GL_QUAD); glTexCoord2f(0.0,0.0); glVertex3f(x1,y1,z1); glTexCoord2f(1.0,0.0); glVertex3f(x2,y2,z2); glTexCoord2f(1.0,1.0); glVertex3f(x3,y3,z3); glTexCoord2f(0.0,1.0); glVertex3f(x4,y4,z4); glEnd(); glFlush(); glDisable(GL_TEXTURE_2D); } Turn on texturing Set the drawing mode: here the texture will “ replace”, the polygons are drawn using only the color from the texture Bind previously created texture object to use it currently (activate it)

Hofstra University30 Create texture object and texture for it Texel values could be up to 4D (R,G,B,A) Texturing is expensive. Texture objects similar to display lists: faster to bind(reuse) stored texture than load with glTexImage*D( )

Hofstra University31 Using texture objects Create texture names, glGenTextures( ) Returns available id’s in second parameter which is passed by reference GLuint texName; glGenTextures(1, &texName ); Create and use texture objects: glBindTexture(GL_TEXTURE_2D, texName); When first use: new texture object is created and assigned the name; subsequent uses: activate the texture object

Hofstra University32 Using texture objects glBindTexture(), “sets” texture state, subsequent calls to glTexImage, glTexParameters,etc., store data in the active texture object The data may include: texture image (mipmaps), width, height,border, internal format, texture properties (minmag filters, wrapping modes,…)

Hofstra University33 2D texture mapping in OpenGL 1. Provide texture array that holds the 2D texture pattern Glubyte my_texels[512][512][3]; Fill the array either Generated by program or Read from image file Typically we keep multiple arrays with different texture patterns 2. Set the parameters for the texture map (glTexParameteri) to be used with glTexImage2D set up 3. Specify texture map: which texture array to use currently as 2D texture and set properties with glTexImage( ) The texture map will be stored in texture memory level and border give fine control glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, my_texels); tex im size border power of 2+b Which of the R,G,B,A components or intensity are selected for use. Level (of mipmap)

Hofstra University34 2D texture mapping in OpenGL Enable texture mapping glEnable(GL_TEXTURE_2D); glTexImage2D, specifies what texture image to use and sets some parameters and formats glTexCoord2*, specifies how the map will be applied. map from texture array to object. Texture coordinates s and t are between 0 and 1 (inclusive) Texture coordinates to vertices by the application program Directly, using glTexCoord2f(s, t) per vertex Automaticly, using glTexGen

Hofstra University35 Mapping texture coordinates to object glBegin(GL_QUADS); glTexCoord2f(0.0,0.0); glVertex3f(x1,y1,z1); glTexCoord2f(1.0,0.0); glVertex3f(x2,y2,z2); glTexCoord2f(1.0,1.0); glVertex3f(x3,y3,z3); glTexCoord2f(0.0,1.0); glVertex3f(x4,y4,z4); glEnd(); Example: map the array to polygon Specify texture map at vertices, texture map for the interior is interpolated Need to take special care How to distribute the texture pattern onto the object What to do if texture coordinates get out of range How to sample the texture (pick up the texel values)

Hofstra University36 OpenGL texture parameters How to deal with values of texture coordintes out of range glTexParameterf(GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_WRAP_T, GL_REPEAT); or GL_CLAMP Dealing with the texture sampling: The texture coordinates for interior polygon points are interpolated from the texture coordinates of the vertices, they are real valued, but the texture array has discrete elements with integer coordinates A pixel is mapped onto a curveliner patch of the texture pattern and one texture value per pixel has to be computed from all texels that overlap with the patch Mismatch between texel-pixel sizes The question is how to compute the texture value per pixel Point sampling : use the nearest texel. Prone to aliasing effects. Linear filtering: use weighted average of all textels overlapping with the patch Because the pixel and texel arrays are both finite, and the texture map is real-valued there is also the issue of mismatch between the corresponding texel and pixel areas correponding to each other according to the texture map

Hofstra University37 OpenGL texture parameters How to deal with values of texture coordinates out of range glTexParameterf(GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_WRAP_T, GL_REPEAT); or GL_CLAMP Dealing with the texture sampling: The texture coordinates for interior polygon points are interpolated from the texture coordinates of the vertices, they are real valued, but the texture array has discrete elements with integer coordinates A pixel is mapped onto a curveliner patch of the texture pattern and one texture value per pixel has to be computed from all texels that overlap with the patch Mismatch between texel-pixel sizes Magnification Minification

Hofstra University38 OpenGL texture parameters In OpenGL the parameters handling the texture sampling issues are GL_TEXTURE_MIN_FILTER GL_TEXTURE_MAG_FILTER Their values are GL_NEAREST (for point sampling) GL_LINEAR for linear filtering (weighted avg) The parameter values are assigned with glTexParameterf glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); or GL_LINEAR (deals better with aliasing)

Hofstra University39 OpenGL texture parameters Mipmapping: another approach to deal with the mismatch in pixel/texel size and aliasing A sequence of texture arrays at different resolutions is kept (full resolution, half, ¼, etc) glBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, mipmapw, mipmaph, GL_RGB, GL_INSIGNED_BYTE, my_texels); Mipmaps are set dierectly, using the level parameter in glTexImage2D Level 0 is full resolution glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, my_texels); Or automaticly, using glTexParametri glTexParametri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST) Or GL_NEAREST_MIPMAP_LINEAR

Hofstra University40 OpenGL texture parameters Interaction between texturing and shading glTexEnvi(GL_TEX_ENV_MODE, GL_MODULATE); or GL_DECAL Dealing with aliasing issues related to the perspective projection foreshothening glHINT(GL_PERSPECTIVE_CORRECTION, GL_NICEST);

Hofstra University41 Environment Mapping Yoshihiro Mizutani and Kurt Reindel

Hofstra University42 Environment Mapping II highly reflective Put texture on a highly reflective object by picking up texture from the environment in which the object is immersed. Realized as two-step process Project the environment (excluding the object) onto an intermediate surface. Place object back, and map texture from intermediate surface to object

Hofstra University43 Environment Mapping III: methods Sphere mapping Supported directly by OpenGL Cube mapping Supported by the NV GeForce 256 GPU OpenGL extension: EXT_texture_cube

Hofstra University44 Sphere Mapping Blinn and Newell’s method: for each environment mapped pixel compute the (viewer) reflection vector NV: Technical Brief: Perfecct reflections and Specular ….

Hofstra University45 Blinn-Newell: problems Borders Singularities at the poles (convergence)

Hofstra University46 Cubic mapping Intrtoduced by Greene in O mapping: put a camera in the environment center and then project the environment onto the sides of a cube centered at the camera position. Amounts to six scene renderings. More uniform sampling then B-N The normalized reflection vector determines which face to use for texturing. The reflection vector component with larges abs value determines the side e.g. [-0.2,0.5,-0.84] selects the –Z face

Hofstra University47 Bump mapping 2D Texture map creates odd looking rough surfaces Bump mapping: texture map that alters surface normals. Use texture array to set a function which perturbs surface normals Altered normals match a bumpy surface Applying illumination model to the new normals shades the bumps correctly

Hofstra University48 Bump mapping Bump map is in texture array: d(s,t) << 1 p point on the surface corresponding to texture coordinates s,t. N the normal at p p’ the bump point for p p’ = p + d(s,t)N We actually do not “bump” the surface, just the normal at p. N’ the normal at p’. This normal used by the illumination model at p.

Hofstra University49 Bump mapping How to get N’ : given two vectors tangent to the bumpy surface, N’ is their cross product The two vectors follow from the partial derivatives of the p’ equation wrt u,v p’ = p + d(s,t)N These partial derivatives expressed in terms of the derivatives of d(s,t) as s,t change