Texture Mapping Kurt Akeley CS248 Lecture 10 25 October 2007

Slides:



Advertisements
Similar presentations
Technische Universität München Fakultät für Informatik Computer Graphics SS 2014 Sampling Rüdiger Westermann Lehrstuhl für Computer Graphik und Visualisierung.
Advertisements

Graphics Pipeline.
RealityEngine Graphics Kurt Akeley Silicon Graphics Computer Systems.
Texture Mapping. Texturing  process that modifies the appearance of each point on a surface using an image or function  any aspect of appearance can.
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 Visual detail without geometry. Texture Mapping desire for heightened realism.
Week 7 - Wednesday.  What did we talk about last time?  Transparency  Gamma correction  Started texturing.
3D Graphics for Game Programming (J. Han) Chapter VIII Image Texturing.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Textures I Week 8, Mon.
Rasterization and Ray Tracing in Real-Time Applications (Games) Andrew Graff.
Sampling, Aliasing, & Mipmaps
Texture Mapping CPSC /24/03 Abhijeet Ghosh.
OpenGL Kurt Akeley CS248 Lecture 2 27 September 2007
Advanced Computer Graphics (Spring 2005) COMS 4162, Lecture 5: Image Processing 2: Warping Ravi Ramamoorthi
Viewing and Perspective Kurt Akeley CS248 Lecture 9 23 October 2007
OpenGL Texture Mapping
OpenGL Texture Mapping Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Multisample Antialiasing Kurt Akeley CS248 Lecture 6 11 October 2007
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.
Pre-Filter Antialiasing Kurt Akeley CS248 Lecture 4 4 October 2007
Illumination and Direct Reflection Kurt Akeley CS248 Lecture 12 1 November 2007
Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping.
1 Texturing. 2 What is Texturing? 3 Texture Mapping Definition: mapping a function onto a surface; function can be:  1, 2, or 3D  sampled (image) or.
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
Computer Graphics Texture Mapping
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.
Texture Mapping. Scope Buffers Buffers Various of graphics image Various of graphics image Texture mapping Texture mapping.
Graphics Graphics Korea University cgvr.korea.ac.kr 1 Texture Mapping 고려대학교 컴퓨터 그래픽스 연구실.
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.
Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph - SIGGraph.
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.
CS 480/680 Computer Graphics OpenGL Texture Mapping Dr. Frederick C Harris, Jr. Fall 2011.
Texture Mapping Drawing Pictures on Polygons. Texture Mapping.
Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora.
CS418 Computer Graphics John C. Hart
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,
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
11/5/2002 (c) University of Wisconsin, CS 559 Last Time Local Shading –Diffuse term –Specular term –All together –OpenGL brief overview.
CSCI 440.  So far we have learned how to  build shapes  create movement  change views  add simple lights  But, our objects still look very cartoonish.
COMPUTER GRAPHICS CS 482 – FALL 2015 SEPTEMBER 29, 2015 RENDERING RASTERIZATION RAY CASTING PROGRAMMABLE SHADERS.
Details of Texture Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 1, 2003.
CSc4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Texture Mapping.
Texturing CMSC 435/ What is Texturing? 2 Texture Mapping Definition: mapping a function onto a surface; function can be: – 1, 2, or 3D – sampled.
Antialiasing. What is alias? Alias - A false signal in telecommunication links from beats between signal frequency and sampling frequency (from dictionary.com)
Week 7 - Wednesday CS361.
Texture Mapping cgvr.korea.ac.kr.
OpenGL Texture Mapping
OpenGL Texture Mapping
Chapters VIII Image Texturing
Interactive Graphics Algorithms Ying Zhu Georgia State University
© University of Wisconsin, CS559 Fall 2004
Introduction to Texture Mapping
(c) University of Wisconsin, CS 559
3D Game Programming Texture Mapping
OpenGL Texture Mapping
OpenGL Texture Mapping
Adding Surface Detail 고려대학교 컴퓨터 그래픽스 연구실.
3D Game Programming Texture Mapping
Adding Surface Detail 고려대학교 컴퓨터 그래픽스 연구실.
OpenGL Texture Mapping
Presentation transcript:

Texture Mapping Kurt Akeley CS248 Lecture October

CS248 Lecture 10Kurt Akeley, Fall 2007 Texture mapping demo

CS248 Lecture 10Kurt Akeley, Fall 2007 Texture mapping Paints images onto triangles Paints images onto points, lines, and other images

CS248 Lecture 10Kurt Akeley, Fall 2007 Complete OpenGL pipeline Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations Framebuffer Texture memory Pixel assembly (unpack) Pixel operations Pixel pack Vertex pipelinePixel pipeline Texture mapping ties the vertex and pixel pipelines together Application

CS248 Lecture 10Kurt Akeley, Fall 2007 Texture mapping Paints images onto triangles Paints images onto points, lines, and other images Ties the vertex and pixel pipelines together n Rendered images can be used as textures n To modify the rendering of new images –That can be used as textures … Implements general functions of one, two, or three parameters n Specified as 1-D, 2-D, or 3-D tables (aka texture images) n With interpolated (aka filtered) lookup Drives the hardware architecture of GPUs n Multi-thread latency hiding n “shader” programmability Adds many capabilities to OpenGL n Volume rendering n Alternate color spaces n Shadows …

CS248 Lecture 10Kurt Akeley, Fall 2007 Complete OpenGL pipeline Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations Framebuffer Texture memory Pixel assembly (unpack) Pixel operations Pixel pack Vertex pipelinePixel pipeline Application

CS248 Lecture 10Kurt Akeley, Fall 2007 Fundamentals of texture mapping Texture mapping requires specification of n The texture image n The mapping from object to texture coordinates n The sampling mechanism n The application of the resulting value(s)

CS248 Lecture 10Kurt Akeley, Fall 2007 The OpenGL Pipeline (texture mapping example)

CS248 Lecture 10Kurt Akeley, Fall 2007 OpenGL textured-quad code LoadTexture(“Textures\\rooster.tga”, 1);// lots hidden here glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 1); glClearColor(1, 1, 1, 1);// white glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glOrtho(0, 100, 0, 100, -1, 1); glColor3f(1, 1, 1);// white glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(0, 0);glVertex2i(11, 31); glTexCoord2f(0, 1);glVertex2i(37, 71); glTexCoord2f(1, 0);glVertex2i(91, 38); glTexCoord2f(1, 1);glVertex2i(65, 71); glEnd(); glFlush(); Texture mapping is not corrected for perspective!

CS248 Lecture 10Kurt Akeley, Fall 2007 Texture image specification Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations Framebuffer Texture memory Pixel assembly (unpack) Pixel operations Pixel pack Vertex pipelinePixel pipeline Application struct { float r,g,b,a; } pixel; Scale and offset Color table lookup Optional: Convolution Histogram Min/max computation Unpack from memory format into canonical format (pixel structures)

CS248 Lecture 10Kurt Akeley, Fall 2007 Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations Framebuffer Texture memory Pixel assembly (unpack) Pixel operations Pixel pack Vertex pipelinePixel pipeline Application struct { float x o,y o,z o,w o ; float nx o,ny o,nz o ; float r,g,b,a; float s o,t o,r o,q o ; } vertex; struct { float 11,31,0,1; float 0,0,1; float 1,1,1,1; float 0,0,0,1; } vertex; glColor3f(1,1,1); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(0, 0); glVertex2i(11, 31);

CS248 Lecture 10Kurt Akeley, Fall 2007 Vertex operations Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations Framebuffer Texture memory Pixel assembly (unpack) Pixel operations Pixel pack Vertex pipelinePixel pipeline Application struct { float x c,y c,z c,w c ; float r,g,b,a; float s c,t c,r c,q c ; } clipvertex;

CS248 Lecture 10Kurt Akeley, Fall 2007 Primitive assembly Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations Framebuffer Texture memory Pixel assembly (unpack) Pixel operations Pixel pack Vertex pipelinePixel pipeline Application struct { float x c,y c,z c,w c ; float r,g,b,a; float s c,t c,r c,q c ; } clipvertex; struct { clipvertex v0,v1,v2; } triangle;

CS248 Lecture 10Kurt Akeley, Fall 2007 Primitive operations Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations Framebuffer Texture memory Pixel assembly (unpack) Pixel operations Pixel pack Vertex pipelinePixel pipeline Application struct { float x w,y w,z w,w c ; float r,g,b,a; float s c,t c,r c,q c ; } winvertex; struct { winvertex v0,v1,v2; } triangle;

CS248 Lecture 10Kurt Akeley, Fall 2007 Rasterization Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations Framebuffer Texture memory Pixel assembly (unpack) Pixel operations Pixel pack Vertex pipelinePixel pipeline Application struct { float x w,y w,z w,w c ; float r,g,b,a; float s c,t c,r c,q c ; } winvertex; struct { winvertex v0,v1,v2; } triangle;

CS248 Lecture 10Kurt Akeley, Fall 2007 Perspective-correct attribute evaluation (x 0, y 0, w 0, f 0 ) (x 1, y 1, w 1, f 1 ) (x 2, y 2, w 2, f 2 ) (x, y, f ) a2a2 a1a1 a0a0 All w ’s are w c ’s

CS248 Lecture 10Kurt Akeley, Fall 2007 Perspective-correct tex coord evaluation (x 0, y 0, w 0, s 0 ) (x 1, y 1, w 1, s 1 ) (x 2, y 2, w 2, s 2 ) (x, y, s ) a2a2 a1a1 a0a0 w c ’s, s c ’s, q c ’s x w ’s, y w ’s Texture coordinates homogenized here Supports image remapping (from q-specified warp to render-specified warp)

CS248 Lecture 10Kurt Akeley, Fall 2007 Rasterization Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations Framebuffer Texture memory Pixel assembly (unpack) Pixel operations Pixel pack Vertex pipelinePixel pipeline Application struct { float x w,y w,z w ; float r,g,b,a; float s w,t w,r w ; } fragment;

CS248 Lecture 10Kurt Akeley, Fall 2007 Fragment operations Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations Framebuffer Texture memory Pixel assembly (unpack) Pixel operations Pixel pack Vertex pipelinePixel pipeline Application struct { float x w,y w,z w ; float r,g,b,a; float s w,t w,r w ; } fragment;

CS248 Lecture 10Kurt Akeley, Fall 2007 Texture lookup struct { float x w,y w,z w ; float r,g,b,a; float s w,t w,r w ; } fragment; struct { float r t,g t,b t,a t ; } color; If s w or t w is outside the range [0, 1] : - Clamp to edge color - Clamp to border color - Wrap repeatedly - Wrap with mirror reflections swsw twtw

CS248 Lecture 10Kurt Akeley, Fall 2007 Texture application struct { float x w,y w,z w ; float r,g,b,a; float s w,t w,r w ; } fragment; struct { float r t,g t,b t,a t ; } color; swsw twtw struct { float x w,y w,z w ; float r’,g’,b’,a’; } fragment; GL_MODULATE: Alternatives include: - GL_REPLACE - GL_BLEND - GL_ADD

CS248 Lecture 10Kurt Akeley, Fall 2007 Fragment / framebuffer operations Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations Framebuffer Texture memory Pixel assembly (unpack) Pixel operations Pixel pack Vertex pipelinePixel pipeline Application struct { float x w,y w,z w ; float r’,g’,b’,a’; } fragment;

CS248 Lecture 10Kurt Akeley, Fall 2007 OpenGL textured-quad code LoadTexture(“Textures\\rooster.tga”, 1);// lots hidden here glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 1); glClearColor(1, 1, 1, 1);// white glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glOrtho(0, 100, 0, 100, -1, 1); glColor3f(1, 1, 1);// white glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(0, 0);glVertex2i(11, 31); glTexCoord2f(0, 1);glVertex2i(37, 71); glTexCoord2f(1, 0);glVertex2i(91, 38); glTexCoord2f(1, 1);glVertex2i(65, 71); glEnd(); glFlush(); run

CS248 Lecture 10Kurt Akeley, Fall 2007 Texture Sampling

CS248 Lecture 10Kurt Akeley, Fall 2007 Texel coordinates struct { float x w,y w,z w ; float r,g,b,a; float s w,t w,r w ; } fragment; struct { float r t,g t,b t,a t ; } color; 02n2n 0 2m2m For this image n = m = swsw twtw u v

CS248 Lecture 10Kurt Akeley, Fall 2007 Image resampling We are resampling the texture image at the pixel rate We have seen resampling before …

CS248 Lecture 10Kurt Akeley, Fall 2007 Supersample antialiasing Supersampling algorithm: 1. Over-sample, e.g., at 4x the pixel rate 2. Reconstruct at the over-sampled rate 3. Band-limit to match the pixel rate 4. Resample at the pixel rate to yield pixel values 5. Reconstruct to display

CS248 Lecture 10Kurt Akeley, Fall 2007 Texture resampling (to avoid aliasing) Texture resampling algorithm: 1. Over-sample, e.g., at 4x the pixel rate 2. Reconstruct at the texture-sample rate 3. Band-limit to match the pixel rate 4. Resample at the pixel rate to yield pixel values 5. Reconstruct to display

CS248 Lecture 10Kurt Akeley, Fall 2007 Supersampling optimizations The over-sample reconstruction convolution and the band-limiting convolution steps can be combined: n Convolution is associative (f * g) * h = f * (g * h) And g and h are constant n f * (g * h) = f * filter The filter convolution can be reduced to a simple weighted sum of sample values: n The result is sampled at pixel rate n So only values at pixel centers are needed n These are weighted sums of the 4x samples

CS248 Lecture 10Kurt Akeley, Fall 2007 Texture resampling optimizations The reconstruction convolution and the band-limiting convolution steps can be combined: n Convolution is associative (f * g) * h = f * (g * h) And g and h are constant n f * (g * h) = f * filter The filter convolution can be reduced to a simple weighted sum of sample values: n The result is sampled at pixel rate n So only values at pixel centers are needed n These are weighted sums of the texels How many texels need to be summed to get a good answer?

CS248 Lecture 10Kurt Akeley, Fall 2007 Size of the filter n typically differs for every fragment!

CS248 Lecture 10Kurt Akeley, Fall 2007 Magnification One pixel corresponds to less than one texel Resulting image is “larger” (more pixels than corresponding texels) Efficient to implement: Rule 1

CS248 Lecture 10Kurt Akeley, Fall 2007 Minification One pixel corresponds to many texels Resulting image is “smaller” (fewer pixels than corresponding texels) Difficult to implement efficiently Could require visiting every texel in the entire texture image!

CS248 Lecture 10Kurt Akeley, Fall 2007 Two approaches to antialiasing Supersampling Pre-filtering

CS248 Lecture 10Kurt Akeley, Fall 2007 MIPmap pre-filtering Prefilter repeatedly to ½ resolution Reduce resolution equally in all dimensions Stop at a single texel

CS248 Lecture 10Kurt Akeley, Fall 2007 MIPmap filtering Choose the pre-filtered images that most closely match the pixel sample rate Sample each of these images Combine the resulting values with a MIPmap filter whose weights are determined by the fractional value of p Notes: n Any filter can be chosen for the in-image sampling n Usually a bilinear filter is chosen for the MIPmap filter n Hence two pre-filtered images are chosen and sampled n Choose the single nearest MIPmap level improves preformance n But violates rule 1 ! n Four or more MIPmap levels can also be chosen

CS248 Lecture 10Kurt Akeley, Fall 2007 Tri-linear filtering A horrible term! Usually means sampling a 2-D MIPmapped texture image using bilinear interpolation for both the in-image filtering and the MIPmap filtering OpenGL allows separate specification of in-image and MIPmap filters

CS248 Lecture 10Kurt Akeley, Fall D and 3-D textures Spatial rates typically differ in different dimensions: This conservative approach will result in image blurring Can we do better?

CS248 Lecture 10Kurt Akeley, Fall 2007 RIPmap pre-filtering

CS248 Lecture 10Kurt Akeley, Fall 2007 Anisotropic texture filtering Combine pre-filtering and supersampling Typical algorithm: n Pre-filter to MIPmap images n Supersample the pixel area n For each sample perform a full MIPmap sample operation n Combine the MIPmap samples using pixel-customized filter weights

CS248 Lecture 10Kurt Akeley, Fall 2007 Summary Texture mapping is a powerful, general-purpose mechanism n It’s not just painting pictures onto triangles! Texture mapping requires specification of n The texture image n The mapping from object to texture coordinates n The sampling mechanism n The application of the resulting value(s) Of these, sampling is the greatest challenge n Use pre-filtering and supersampling approaches to n Avoid aliasing n Avoid blurring n Maintain high performance

CS248 Lecture 10Kurt Akeley, Fall 2007 Assignments Tuesday 30 October n Kurt will be out of town n Saturday morning until Tuesday late n Lecture with be given by Andrew Adams Reading assignment for Tuesday’s class n Work through the tutorial at: n Project 3: n Write a computer-graphics game n Will be assigned this coming Tuesday Office hours today ?

CS248 Lecture 10Kurt Akeley, Fall 2007 End