OpenGL Texturing. Content Texture target Texture environment Texture coordinate Texture parameter (filters, wrap) Texture object Texture transformation.

Slides:



Advertisements
Similar presentations
Projective Texture. Spring Projective Texture Texture projected on a scene as if by a projector Can also be used to generate spot light and shadows.
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.
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
Texture Mapping. Typical application: mapping images on geometry 3D geometry (quads mesh) + RGB texture 2D (color-map) =
Texture Mapping CPSC /24/03 Abhijeet Ghosh.
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.
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
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.
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 CSE167: Computer Graphics Instructor: Steve Rotenberg
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.
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 in OpenGL. Texture Mapping Imaging we are “pasting” a picture onto a model  Which part of the picture will be pasted onto which part.
Fall 2009 Revised1 Texture Mapping (Intermediate) Jyun-Ming Chen.
Texture Mapping Drawing Pictures on Polygons. Texture Mapping.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
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.
October 9, 2002Serguei A. Mokhov, 1 COMP471 – Computer Graphics OpenGL: Texture Mapping.
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 Programming Guide : Texture Mapping Yoo jin wook Korea Univ. Computer Graphics Lab.
Computing & Information Sciences Kansas State University Lecture 12 of 42CIS 636/736: (Introduction to) Computer Graphics CIS 636/736 Computer Graphics.
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.
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 Fall, 2016.
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
Introduction to Texture Mapping
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:

OpenGL Texturing

Content Texture target Texture environment Texture coordinate Texture parameter (filters, wrap) Texture object Texture transformation TexGen Multitexture Applications Light map 3D textures Projective texture Environment map Specular map 2Fall 2013 Revised

Steps in OpenGL Texture Mapping Specify (create) the texture Set texture parameters: Indicate how the texture is to be applied to each pixel Enable texture mapping Draw the scene, supplying both texture and geometric coordinates Works only in RGB mode 3Fall 2013 Revised

Texture Targets glTexImage1D() glTexImage2D() glTexImage3D() 4Fall 2013 Revised

Two Dimensional Texture glTexImage2D (GLenum target, GLint level, GLint components, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels) target : GL_TEXTURE_2D level : LOD number (0: base image) components : number of color components (1|2|3|4) Format : pixel data format Border: 0 or 1 Width & height  2 m + 2(border bit)  w and h can be different There are new extensions that removes this restriction 5Fall 2013 Revised

glTexImage*D supplement In GL version 1.1 or greater, pixels may be a null pointer. In this case texture memory is allocated to accommodate a texture of width width and height height. You can then download subtextures to initialize this texture memory. The image is undefined if the user tries to apply an uninitialized portion of the texture image to a primitive. 6Fall 2013 Revised

Setting Texture Environment glTexEnv{if}{v}(GLenum target, GLenum pname, TYPEparam); Setting how textures are to be interpreted: Target : GL_TEXTURE_ENV Pname: GL_TEXTURE_ENV_MODE Param: modes (DECAL|REPLACE|MODULATE|BLEND|ADD|…) 7Fall 2013 Revised

Texture Environment Modes GL_REPLACE GL_MODULATE (default) GL_DECAL GL_BLEND New environment modes: GL_ADD: C v = C f + C t GL_COMBINE (ARB, see here)here 8Fall 2013 Revised

GL_MODULATE Color of polygon affects the display of texture Tree: (r,g,b,a) a cutout = 0 Polygon: (1,0,0) 9Fall 2013 Revised

GL_BLEND Use with: glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, colorPtr) C c : texture environment color 10Fall 2013 Revised

GL_REPLACE Appearance solely determined by texture FOR TEXTURE CUT-OUTS Tree: (r,g,b,a) a cutout = 0 Polygon: (1,0,0) 11Fall 2013 Revised

GL_DECAL Cp: replace RGB: DECAL=REPLACE Tree: (r,g,b,a) a cutout = 0 Polygon: (1,0,0) 12Fall 2013 Revised

Texture + Lighting To show fragment color, use GL_MODULATE Apply specular color AFTER texture mapping: glLightModeli (GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); See FAQ FAQ GL_SINGLE_COLOR GL_SEPARATE_SPECULAR_COLOR 13Fall 2013 Revised

Texture Coordinates Texture coordinate: Associate texture location (in texture space) with vertices in the polygon glTexCoord2i (s, t);glVertex2i (x, y); Order cannot be reversed! [Think of TexCoord as state assignment] 14Fall 2013 Revised

Texture Coordinates of Quadrics Most quadric primitives have default setting for texture coordinates To turn on the default setting: gluQuadricTexture (qobj, GL_TRUE) 15Fall 2013 Revised

Ex: Textures on Quadrics 16Fall 2013 Revised

Deeper Look into Texturing 17 Each fragment got its texture coordinates from interpolation Then via table lookup, obtain its (interpolated) color values. Fall 2013 Revised

rasterization Polygon (in screen space) and texture coordinates (1,1) (1,0) (0,.75) (1,1) (1,0) (0,.75) Texture map (4x4) nearest linear Interpolate (s,t) and lookup (r,g,b,a) in the texture map Filters Texture Access and Lookup 18Fall 2013 Revised

Filters: Magnification & Minification Nature of problem: Mismatch between texels and pixels 19Fall 2013 Revised

Options Magnification GL_NEAREST GL_LINEAR Minification GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST GL_LINEAR_MIPMAP_NEAREST GL_NEAREST_MIPMAP_LINEAR GL_LINEAR_MIPMAP_LINEAR Chooses the mipmap that most closely matches the size of the pixel being textured Chooses the two mipmaps that most closely match the size of the pixel being textured Nearest: in Manhattan distance to the center of the pixel 20Fall 2013 Revised

Magnification Options GL_LINEAR Interpolate the texels More time consuming but more accurate GL_NEAREST Snap to the nearest texel 21Fall 2013 Revised

Problems of Minification Can use nearest neighbor or bilinear interpolation,but these two may cause severe aliasing problems Nearest NeighborBilinear Interpolation or ?? Texels Pixels No Influence 22Fall 2013 Revised

Problem with Minification without mipmap with mipmap 23Fall 2013 Revised

Mipmapping The most popular method of anti-aliasing for textures ‘Mip’ stands for “multum in parvo” = “many things in a small place” The texture is downsampled to a quarter of the original area. Mipmapping was invented by Lance Williams in 1983 and is described in his paper Pyramidal parametrics. 24Fall 2013 Revised

[Point Sampled Texture Aliasing] Note that the back row is a very poor representation of the true image Texture map Polygon far from the viewer in perspective projection Rasterized and textured 25Fall 2013 Revised

Minification Options glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR, GL_NEAREST, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_NEAREST_MIPMAP_NEAREST); Remarks: Mipmap selection is done per pixel Using not-yet-ready mipmap disables the texture mapping function. Remarks: Mipmap selection is done per pixel Using not-yet-ready mipmap disables the texture mapping function. 26Fall 2013 Revised

Mipmap Generation gluBuild2DMipmaps Storage overhead 27Fall 2013 Revised

Texture Wrap When the texture coordinates are outside [0,1] glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,param); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,param); param: GL_CLAMP|GL_REPEAT 28Fall 2013 Revised

Parameters for Wrapping GL_CLAMP use the border texel Diagonal: corner texel GL_REPEAT repeat the texels in [0,1] 29Fall 2013 Revised

Texture Object A texture object stores texture data and makes it readily available You can now control many textures and go back to textures that have been previously loaded into your texture resources Using texture objects is usually the fastest way to apply textures, resulting in big performance gains it is almost always much faster to bind (reuse) an existing texture object than it is to reload a texture image using glTexImage*D() 30Fall 2013 Revised

Texture Object API glGenTextures Allocate n textures (integer identifiers) glBindTexture Bind the current texture to specified identifier glDeleteTextures Free the allocated texture identifiers Reverse of glGenTextures 31Fall 2013 Revised

checker.c 32Fall 2013 Revised

texbind.c Once created, a named texture may be re-bound to the target of the matching dimensionality as often as needed. It isusually much faster to use glBindTexture to bind an existing named texture to one of the texture targets than it is to reload the texture image using glTexImage1D, glTexImage2D, or glTexImage3D. 33Fall 2013 Revised

Texture Objects Texture properties saved in texture objects: Minification and magnification filters, wrapping modes, border color and texture priority When a texture object is bound again, one may edit the contents of the bound texture object. Any commands that change the above properties will change the currently bound texture as well as the current texture state. Texture environment, texgen, etc. are NOT stored in texture objects These settings need to be repeated after texture binding. 34Fall 2013 Revised

Texture Loader (PNG, glpng.rar) Features Build mipmap Load and bind 2D textures Load image data (image loader) Handle transparent image (cut-out texture) Important API id = pngBind(filename, mipmap, trans, info, wrapst, minfilter, magfilter) pngSetStencil(red, green, blue) pngSetStandardOrientation(1)  OpenGL: origin (0,0) is at lower left corner pngLoad(filename, mipmap, trans, info) TEXTURE ID IS RETURNED TO YOU BY PNG LOADER 35Fall 2013 Revised

Texture Transforms Texture coordinates are multiplied by a 4 by 4 matrix before any texture mapping occurs. Texture animation: using this, you can make the texture slide over the surface, rotate around it, stretch and shrink, … All matrix operations apply: Push/Pop/Mult/ … 36Fall 2013 Revised

Texture Suite cloud explode smoke water fire 37Fall 2013 Revised

Automatic TEX ture Coordinate GEN eration void glTexGen{ifd}{v}(GLenum coord, GLenum pname, TYPEparam); Coord: GL_S, GL_T, GL_R, GL_Q Pname: GL_TEXTURE_GEN_MODE Type: GL_OBJECT_LINEAR, GL_EYE_LINEAR, or GL_SPHERE_MAP Used when the tex coords are too cumbersome to specify, or will be changed with time. Texture environment, texgen, etc. are NOT stored in texture objects. 38Fall 2013 Revised

1D Texture According to Height Continuous color gradation (0,1/32,2/32, …, 31/32) Discrete white lines (0,0,0,1,0,0,0,1, … ) 39Fall 2013 Revised

TexGen: Object/Eye_Linear for a vertex with object coordinates (x o,y o,z o,w o ), generated coordinate = p 1 x o + p 2 y o + p 3 z o + p 4 w o Meaning: when p 1, p 2, p 3 are normalized, this coord corresponds to signed distance Similarly, EYE_LINEAR applies to eye coordinates (0,0,-1,0)  (x o,y o,z o,w o ) Initially, all texture generation functions are set to GL_EYE_LINEAR and are disabled. Both s plane equations are (1, 0, 0, 0), both t plane equations are (0, 1, 0, 0), and all r and q plane equations are (0, 0, 0, 0). 40Fall 2013 Revised

Eye_linear (ref)ref Computing this distance in eye coordinates is a little tricky, since the plane and vertex must first be transformed to eye coordinates. if M is the modelview matrix at the time glTexGenfv( GLX, GL EYE PLANE, plane ) is called, then the transformed vertex V’ is V’ = M V, let’s call V’ = ( x e, y e, z e, w e ). The plane must also be transformed to get a new plane A’x + B’y + C’z + D’w = 0 We get (A’,B’,C’,D’) = (A,B,C,D)M −1 and M is the modelview matrix when glTexGen is invoked. The texture coordinate is then computed as A’x e + B’y e + C’z e + D’w e. 41Fall 2013 Revised

Eye_linear Summary 42Fall 2013 Revised

SphereMap Another mode of TexGen, SphereMap, will be explain in the “Environment Map” note. 43Fall 2013 Revised

Multi-Texture What this is about … Extension Wrangler (GLEW)GLEW 44Fall 2013 Revised

Glew – Extension Wrangler Include before Remember to add glewInit() After the first glutWindow is created

Error Message Version of glew library Sometimes you’ll see this error message when you run the program It is because the static library (in the EXE) and the DLL files are not the same version. Recompiling the application solves the problem

Usages of Multitexture 47Fall 2013 Revised

(First) ARB-approved extension (1998) Support up to 32 texture units* Texture matrix and texgen commands affect the active texture environment ARB_multitexture (ref)ref * glGetIntegerv (GL_MAX_TEXTURE_UNITS, &units); My platform has only 4! OpenGL 3.1 requires minimum of 16 texture units 48Fall 2013 Revised

Details OpenGL's multitexture support requires that every texture unit be fully functional and maintain state that is independent of any other texture units. Each texture unit has its own texture coordinate generation state, texture matrix state, texture enable state, and texture environment state. However, each texture unit within an OpenGL context shares the same set of texture objects. 49Fall 2013 Revised

Multi Texture 50Fall 2013 Revised

TexGen with Multitexture When the GL_ARB_multitexture extension is supported, glTexGen set the texture generation parameters for the currently active texture unit, selected with glActiveTexture.  TexUnit0: texture2D;(s,t) given TexUnit1: texture1D; texGen 51Fall 2013 Revised

Dynamic Texture CopyTexSubImage2D Replace a rectangular portion of 2D texture with pixels from the current READ_BUFFER This involves a read- back from GPU to CPU. Can you think of a way to move the dynamic texture around?! A better way of doing it: Render-to-texture (RTT) with framebuffer object (FBO) 52Fall 2013 Revised

glTexSubImage2D Replace part of the original image as new subimage Width and size of image need not be 2 n E.g., dynamic texture glTexSubImage2D (target, level, xoffset, yoffset, width, height, format, type, pixels) 53Fall 2013 Revised

Other Related Functions void glCopyTexImage2D(target, level, internalformat, x, y, width, height, border); defines a two-dimensional texture image with pixels from the current GL_READ_BUFFER. void glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height); docdoc replaces a rectangular portion of a two-dimensional texture image with pixels from the current GL_READ_BUFFER (rather than from main memory, as is the case for glTexSubImage2D). void glGetTexImage(target, level, format, type, void *pixels ); Get the content in the texture target into the array Similar to glCopyPixels 54Fall 2013 Revised

3D Textures 55Fall 2013 Revised

3D Perlin noise … 56Fall 2013 Revised

57 Light Maps Quake ( 雷神之錘, id software) was the first computer game to use light map

Fall 2013 Revised58

Spherical specular map obtained on a highly tesselated sphere` Apply this spheremap as “specular texture” on the teapot Specular Map 59Fall 2013 Revised

A more “cartoon-ish” specular map Fall 2013 Revised60

61Fall 2013 Revised