Texture Mapping. Mike Bailey.

Similar documents
Lecture 07: Buffers and Textures

Assignment #5: Scalar Field Visualization 3D: Direct Volume Rendering

Assignment #3: Scalar Field Visualization 3D: Cutting Plane, Wireframe Iso-surfacing, and Direct Volume Rendering

Lecture 22 Sections 8.8, 8.9, Wed, Oct 28, 2009

Computational Strategies

Textures. Texture Mapping. Bitmap Textures. Basic Texture Techniques

CS212. OpenGL Texture Mapping and Related

Graphics. Texture Mapping 고려대학교컴퓨터그래픽스연구실.

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

CS 432 Interactive Computer Graphics

CT5510: Computer Graphics. Texture Mapping

Texture Mapping. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Grafica Computazionale

OpenGL Texture Mapping. Objectives Introduce the OpenGL texture functions and options

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

Texture Mapping CSCI 4229/5229 Computer Graphics Fall 2016

CS335 Graphics and Multimedia. Slides adopted from OpenGL Tutorial

OpenCL / OpenGL Texture Interoperability: An Image Blurring Case Study

CSE 167: Introduction to Computer Graphics Lecture #7: Textures. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2018

Objectives. Texture Mapping and NURBS Week 7. The Limits of Geometric Modeling. Modeling an Orange. Three Types of Mapping. Modeling an Orange (2)

CMSC 425: Lecture 12 Texture Mapping Thursday, Mar 14, 2013

CSE 167: Introduction to Computer Graphics Lecture #8: Textures. Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016

Buffers. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

Texture Mapping and Sampling

CS452/552; EE465/505. Texture Mapping in WebGL

Computer Graphics. Bing-Yu Chen National Taiwan University

三維繪圖程式設計 3D Graphics Programming Design 第七章基礎材質張貼技術嘉大資工系盧天麒

ก ก ก.

CISC 3620 Lecture 7 Lighting and shading. Topics: Exam results Buffers Texture mapping intro Texture mapping basics WebGL texture mapping

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

Lighting and Texturing

CSE 167: Introduction to Computer Graphics Lecture #8: Textures. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2017

Lecture 5 3D graphics part 3

Computer Graphics Lighting

Computer Graphics Lighting. Why Do We Care About Lighting?

Discussion 3. PPM loading Texture rendering in OpenGL

Computer Graphics Texture Mapping

Computer Graphics. Three-Dimensional Graphics VI. Guoying Zhao 1 / 73

CS179: GPU Programming

Cap. 3 Textures. Mestrado em Engenharia Informática (6931) 1º ano, 1º semestre

Today. Texture mapping in OpenGL. Texture mapping. Basic shaders for texturing. Today. Computergrafik

CSE 167: Introduction to Computer Graphics Lecture #9: Textures. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2013

Overview. Goals. MipMapping. P5 MipMap Texturing. What are MipMaps. MipMapping in OpenGL. Generating MipMaps Filtering.

Texture Mapping. Texture Mapping. Map textures to surfaces. Trompe L Oeil ( Deceive the Eye ) The texture. Texture map

Texturing. Slides done bytomas Akenine-Möller and Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Texturas. Objectives. ! Introduce Mapping Methods. ! Consider two basic strategies. Computação Gráfica

New Concepts. Loading geometry from file Camera animation Advanced lighting and materials Texture mapping Display lists

Shading/Texturing. Dr. Scott Schaefer

Texture mapping. Computer Graphics CSE 167 Lecture 9

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

Texture and other Mappings

Imaging and Raster Primitives

Most device that are used to produce images are. dots (pixels) to display the image. This includes CRT monitors, LCDs, laser and dot-matrix

CSE 167: Lecture 11: Textures 2. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

MULTI-PASS VS SINGLE-PASS CUBEMAP

Texture Mapping. Computer Graphics, 2015 Lecture 9. Johan Nysjö Centre for Image analysis Uppsala University

General Purpose computation on GPUs. Liangjun Zhang 2/23/2005

Department of Computer Sciences Graphics Spring 2013 (Lecture 19) Bump Maps

Computer Graphics Texture Mapping

Texture Mapping and Special Effects

Performance OpenGL Programming (for whatever reason)

GPU Programming EE Midterm Examination

Steiner- Wallner- Podaras

Fog example. Fog is atmospheric effect. Better realism, helps determine distances

Texture Mapping 1/34

CSE 167: Introduction to Computer Graphics Lecture #6: Lights. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2014

Assignment #6 2D Vector Field Visualization Arrow Plot and LIC

INF3320 Computer Graphics and Discrete Geometry

Texture Mapping 1/34

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

Texturing. Slides done by Tomas Akenine-Möller and Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

+ = Texturing: Glue n-dimensional images onto geometrical objects. Texturing. Texture magnification. Texture coordinates. Bilinear interpolation

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3

CSE 167: Lecture #17: Volume Rendering. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

Lecture 5. Scan Conversion Textures hw2

Computergraphics Exercise 15/ Shading & Texturing

IntMu.Lab5. Download all the files available from

Introduction to OpenGL

SUMMARY. CS380: Introduction to Computer Graphics Texture Mapping Chapter 15. Min H. Kim KAIST School of Computing 18/05/03.

Mipmaps. Lecture 23 Subsection Fri, Oct 30, Hampden-Sydney College. Mipmaps. Robb T. Koether. Discrete Sampling.

VGP352 Week March-2008

-=Catmull's Texturing=1974. Part I of Texturing

FAKULTI TEKNOLOGI MAKLUMAT DAN KOMUNIKASI BITM INTERACTIVE COMPUTER GRAPHICS LAB SESSION 4. C++ - OpenGL

OpenGL. Jimmy Johansson Norrköping Visualization and Interaction Studio Linköping University

Methodology for Lecture

OpenGL: Open Graphics Library. Introduction to OpenGL Part II. How do I render a geometric primitive? What is OpenGL

OpenGL. 1 OpenGL OpenGL 1.2 3D. (euske) 1. Client-Server Model OpenGL

Chapter 9 Texture Mapping An Overview and an Example Steps in Texture Mapping A Sample Program Specifying the Texture Texture Proxy Replacing All or

QUESTION 1 [10] 2 COS340-A October/November 2009

Computer Graphics Programming

Announcements. Written Assignment 2 is out see the web page. Computer Graphics

Texture Mapping. Texture (images) lecture 16. Texture mapping Aliasing (and anti-aliasing) Adding texture improves realism.

Magnification and Minification

Discrete Techniques. 11 th Week, Define a buffer by its spatial resolution (n m) and its depth (or precision) k, the number of

OpenGL & Visualization

Lecture 2 2D transformations Introduction to OpenGL

Texturing Theory. Overview. All it takes is for the rendered image to look right. -Jim Blinn 11/10/2018

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

New topic for Java course: Introduction to 3D graphics programming

Transcription:

Texture Mapping 1 Mike Bailey mjb@cs.oregonstate.edu This work is licensed under a Creative Commons Attribution-NonCommercial- NoDerivatives 4.0 International License TextureMapping.pptx

The Basic Idea 2 Texture mapping is a computer graphics operation in which a separate image, referred to as the texture, is stretched onto a piece of 3D geometry and follows it however it is transformed. This image is also known as a texture map. This can be most any image. Some graphics hardware requires the image s pixel dimensions to be a power of two. (This restriction has been lifted on many graphics cards, but just to be safe.) The X and Y dimensions do not need to be the same power of two, just a power of two. So, a 128x512 image would be OK, a 129x511 image might not. Also, to prevent confusion, the texture pixels are not called pixels. A pixel is a dot in the final screen image. A dot in the texture image is called a texture element, or texel. Similarly, to avoid terminology confusion, a texture s width and height dimensions are not called X and Y. They are called S and T. A texture map is not generally indexed by its actual resolution coordinates. Instead, it is indexed by a coordinate system that is resolution-independent. The left side is always S=0., the right side is S=1., the bottom is T=0., and the top is T=1. Thus, you do not need to be aware of the texture s resolution when you are specifying coordinates that point into it. Think of S and T as a measure of what fraction of the way you are into the texture. T=1. S=0. S=1. T=0.

The Basic Idea 3 The mapping between the geometry of the 3D object and the S and T of the texture image works like this: (X2, Y2, S2,T2) T=1. (X3, Y3, S3,T3) (X0, Y1, S1,T1) S=0. S=1. (X4, Y4, S4,T4) Interpolated (S,T) = (.78,.67) (X0, Y0, S0,T0) 172 T=0. (.78,.67) in S and T = (199.68, 171.52) in texels 199 200 171 (199.68, 171.52) You specify an (s,t) pair at each vertex, along with the vertex coordinate. At the same time that OpenGL is interpolating the coordinates, colors, etc. inside the polygon, it is also interpolating the (s,t) coordinates. Then, when OpenGL goes to draw each pixel, it uses that pixel s interpolated (s,t) to lookup a color in the texture image.

Using a Texture: Assign an (s,t) to each vertex 4 Enable texture mapping: glenable( GL_TEXTURE_2D ); Draw your polygons, specifying s and t at each vertex: glbegin( GL_POLYGON ); gltexcoord2f( s0, t0 ); glnormal3f( nx0, ny0, nz0 ); glvertex3f( x0, y0, z0 ); gltexcoord2f( s1, t1 ); glnormal3f( nx1, ny1, nz1 ); glvertex3f( x1, y1, z1 ); glend( );... If this geometry is static (i.e., will never change), it is a good idea to put this all into a display list. Disable texture mapping: gldisable( GL_TEXTURE_2D );

Using a Texture: How do you know what (s,t) to assign to each vertex? 5 gltexcoord2f( s0, t0 ); The easiest way to figure out what s and t are at a particular vertex is to figure out what fraction across the object the vertex is living at. For a plane, (x,y,z)

Using a Texture: How do you know what (s,t) to assign to each vertex? 6 gltexcoord2f( s0, t0 ); Or, for a sphere, From the Sphere code: s = ( lng + M_PI ) / ( 2.*M_PI ); t = ( lat + M_PI/2. ) / M_PI;

Using a Texture: How do you know what (s,t) to assign to each vertex? 7 gltexcoord2f( s0, t0 ); Uh-oh. Now what? Here s where it gets tougher,??

You really are at the mercy of whoever did the modeling 8

Be careful where s abruptly transitions from 1. back to 0. 9

Reading in a Texture from a BMP File 10 unsigned char *BmpToTexture( ); unsigned char *Texture; int width, height; Texture = BmpToTexture( "filename.bmp", &width, &height ); This function can be found in the bmptotexture.cpp file. The file filename.bmp needs to be created by something that writes uncompressed 24-bit color BMP files, or converted to the uncompressed BMP format by a tool such as ImageMagick s convert or Adobe Photoshop.

11 Texture Wrapping Define the texture wrapping parameters. This will control what happens when a texture coordinate is greater than 1.0 or less than 0.0: gltexparameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap ); gltexparameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap ); where wrap is: GL_REPEAT specifies that this pattern will repeat (i.e., wrap-around) if transformed texture coordinates less than 0.0 or greater than 1.0 are encountered. GL_CLAMP specifies that the pattern will stick to the value at 0.0 or 1.0.

Texture Filtering 12 Define the texture filter parameters. This will control what happens when a texture is scaled up or down. gltexparameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter ); gltexparameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter ); where filter is: GL_NEAREST GL_LINEAR specifies that point sampling is to be used when the texture map needs to be magnified or minified. specifies that bilinear interpolation among the four nearest neighbors is to be used when the texture map needs to be magnified or minified. GL_NEAREST GL_LINEAR

13 Texture Environment This tells OpenGL what to do with the texel colors when it gets them: gltexenvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, mode ); There are several modes that can be used. Two of the most useful are: GL_REPLACE specifies that the 3-component texture will be applied as an opaque image on top of the polygon, replacing the polygon s specified color. GL_MODULATE specifies that the 3-component texture will be applied as piece of colored plastic on top of the polygon. The polygon s specified color shines through the plastic texture. This is very useful for applying lighting to textures: paint the polygon white with lighting and let it shine up through a texture. GL_REPLACE GL_MODULATE

Setting up the Texture 14 Download a texture and make it the current texture: int width, height;... unsigned char *Texture = BmpToTexture( "filename.bmp", &width, &height ); int level, ncomps, border;... glpixelstorei( GL_UNPACK_ALIGNMENT, 1 ); glteximage2d( GL_TEXTURE_2D, level, ncomps, width, height, border, GL_RGB, GL_UNSIGNED_BYTE, Texture ); where: level ncomps width height border Texture is used with mip-mapping. Use 0 for now. number of components in this texture: 3 if using RGB, 4 if using RGBA. width of this texture map, in pixels. height of this texture map, in pixels. width of the texture border, in pixels. Use 0 for now. the name of an array of unsigned characters holding the texel information. This function physically transfers the array of texels from the CPU to the GPU and makes it the current active texture. You can get away with specifying this ahead of time only if you are using a single texture. If you are using multiple textures, you must make each current in Display( ) right before you need it. See the section below about binding textures.

Texture Transformation 15 In addition to the Projection and ModelView matrices, OpenGL maintains a transformation for texture map coordinates S and T as well. You use all the same transformation routines you are used to: glrotatef( ), glscalef( ), gltranslatef( ), but you must first specify the Matrix Mode: glmatrixmode( GL_TEXTURE ); The only trick to this is to remember that you are transforming the texture coordinates, not the texture image. Transforming the texture image forward is the same as transforming the texture coordinates backwards: Scale = 0.5 Scale = 1. Scale = 2.

Texture Transformation 16 The only trick to this is to remember that you are transforming the texture coordinates, not the texture image. Transforming the texture image forward is the same as transforming the texture coordinates backwards: Angle = -45. Angle = 0. Angle = 45.

Texture Objects 17 The OpenGL glteximage2d function doesn t just use that texture, it downloads it from the CPU to the GPU, every time that call is made! After the download, this texture becomes the current texture image. glteximage2d( GL_TEXTURE_2D, level, ncomps, width, height, border, GL_RGB, GL_UNSIGNED_BYTE, Texture ); If your scene has only one texture, this is easy to manage. Just do it once and forget about it. But, if you have several textures, all to be used at different times on different objects, it will be important to maximize the efficiency of how you create, store, and manage those textures. In this case you should bind texture objects. Texture objects leave your textures on the graphics card and then re-uses them, which is always going to be faster than re-loading them.

Texture Objects 18 Create a texture object by generating a texture name and then bind the texture object to the texture data and texture properties. The first time you execute glbindtexture( ), you create the texture object. Subsequent times you do this, you are making that texture object current. So, for example, you might say: GLuint tex0, tex1;... glpixelstorei( GL_UNPACK_ALIGNMENT, 1 ); glgentextures( 1, &tex0 ); glgentextures( 1, &tex1 );... glbindtexture( GL_TEXTURE_2D, tex0 ); // assign binding handles // make tex0 texture current // and set its parameters gltexparameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); gltexparameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); gltexparameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); gltexparameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); gltexenvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE ); glteximage2d( GL_TEXTURE_2D, 0, 3, 256, 128, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureArray0 );

Texture Objects 19 glbindtexture( GL_TEXTURE_2D, tex1 ); // designate the tex1 texture as the current texture // and set its parameters 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); gltexenvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); glteximage2d( GL_TEXTURE_2D, 0, 3, 512, 512, 0, GL_RGB,GL_UNSIGNED_BYTE, TextureArray1 ); Then, later on in Display( ): glenable( GL_TEXTURE_2D ); glbindtexture( GL_TEXTURE_2D, tex0 ); glbegin( GL_QUADS );... glend( ); glbindtexture( GL_TEXTURE_2D, tex1 ); glbegin( GL_TRIANGLE_STRIP );... glend( );

What Does Binding Really Mean? 20 The OpenGL Rendering Context contains all the characteristic information necessary to produce an image from geometry. This includes the current transformations, colors, lighting, textures, where to send the display, etc. The OpenGL term binding refers to attaching or docking (a metaphor which I find to be more visually pleasing) an OpenGL object to the Context. You can then assign characteristics, and they will flow through the Context into the object. Before Binding After Binding

Some Great Uses for Texture Mapping you have seen in the Movies 21 Disney Feature Animation Disney Feature Animation Yes, these are older examples, but I especially like them because, at the time, the CG (and the textures) became part of the story-telling Disney Feature Animation

Some Great Uses for Texture Mapping you have seen in the Movies 22 Disney Feature Animation Disney Feature Animation

Extra Topic: Procedural Texture Mapping 23 Mandelzoom : In this case, the texture is a pure equation, so you never run out of resolution. We cover this in the shaders course: CS 457/557 z 2 + c z

Extra Topic: Procedural Texture Mapping 24 You can also create a texture from data on-the-fly. In this case, the fragment shader takes a grid of heights and uses cross-products to produces surface normal vectors for lighting. While this is procedural, the amount of height data is finite, so you can still run out of resolution We cover this in the shaders course: CS 457/557 Although this looks like an incredible amount of polygonal scene detail, the geometry for this scene consists of just a single quadrilateral