University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2010 Tamara Munzner Textures I Week 9, Fri.

Slides:



Advertisements
Similar presentations
Graphics Pipeline.
Advertisements

Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
Texture Mapping. Texturing  process that modifies the appearance of each point on a surface using an image or function  any aspect of appearance can.
Week 7 - Monday.  What did we talk about last time?  Specular shading  Aliasing and antialiasing.
Texture Mapping. Typical application: mapping images on geometry 3D geometry (quads mesh) + RGB texture 2D (color-map) =
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Textures II Week 8, Wed.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Textures I Week 8, Mon.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Viewing/Projections I.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Textures I Week 9, Wed.
Texture Mapping CPSC /24/03 Abhijeet Ghosh.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Visibility II Week 7,
OpenGL Texture Mapping
OpenGL Texture Mapping Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
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.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2010 Tamara Munzner Hidden Surfaces III Week.
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
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.
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 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.
CS 445 / 645 Introduction to Computer Graphics Lecture 19 Texture Maps Lecture 19 Texture Maps.
Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph - SIGGraph.
Week 2 - Friday.  What did we talk about last time?  Graphics rendering pipeline  Geometry Stage.
OpenGL Conclusions OpenGL Programming and Reference Guides, other sources CSCI 6360/4360.
3D Graphics for Game Programming Chapter IV Fragment Processing and Output Merging.
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.
TEXTURES & OTHER GOODIES Computer Graphics. glTexCoord2f(...); + =
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.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Textures II Week 9, Fri.
Computing & Information Sciences Kansas State University Lecture 12 of 42CIS 636/736: (Introduction to) Computer Graphics CIS 636/736 Computer Graphics.
11/5/2002 (c) University of Wisconsin, CS 559 Last Time Local Shading –Diffuse term –Specular term –All together –OpenGL brief overview.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
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.
Module 05 –Bump mapping Module 05 – Bump mapping Module 05 Advanced mapping techniques: Bump mapping.
CPSC 314 TEXTURE MAPPING UGRAD.CS.UBC.CA/~cs314 Glen Berseth (Based of Mikhail Bessmeltsev and Dinesh Pai)
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Viewing/Projections I.
Recap Last lecture we looked at local shading models –Diffuse and Phong specular terms –Flat and smooth shading Some things were glossed over –Light source.
Discrete Techniques.
© University of Wisconsin, CS559 Spring 2004
OpenGL Texture Mapping
The Graphics Rendering Pipeline
OpenGL Texture Mapping
© University of Wisconsin, CS559 Fall 2004
Introduction to Texture Mapping
(c) University of Wisconsin, CS 559
3D Game Programming Texture Mapping
Textures II Week 10, Mon Mar 22
Computer Graphics Practical Lesson 6
OpenGL Texture Mapping
OpenGL Texture Mapping
Advanced Computer Graphics: Texture
Programming Textures Lecture 15 Fri, Sep 28, 2007.
Adding Surface Detail 고려대학교 컴퓨터 그래픽스 연구실.
3D Game Programming Texture Mapping
Adding Surface Detail 고려대학교 컴퓨터 그래픽스 연구실.
OpenGL Texture Mapping
Presentation transcript:

University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2010 Tamara Munzner Textures I Week 9, Fri Mar 19

2 News extra TA office hours in lab for Q&A Mon 10-1, Tue 12:30-3:30 (Garrett) Tue 3:30-5, Wed 2-5 (Kai) Thu 12-3:30 (Shailen) Fri 2-4 (Kai)

3 Reading for Texture Mapping FCG Chap 11 Texture Mapping except 11.7 (except 11.8, 2nd ed) RB Chap Texture Mapping

4 Review: Back-face Culling y z eye VCS NDCS eye works to cull if y z

5 Review: Invisible Primitives why might a polygon be invisible? polygon outside the field of view / frustum solved by clipping polygon is backfacing solved by backface culling polygon is occluded by object(s) nearer the viewpoint solved by hidden surface removal

6 Review: Rendering Pipeline Geometry Database Geometry Database Model/View Transform. Model/View Transform. Lighting Perspective Transform. Perspective Transform. Clipping Scan Conversion Scan Conversion Depth Test Depth Test Texturing Blending Frame- buffer Frame- buffer

7 Review: Blending/Compositing how might you combine multiple elements? foreground color A, background color B

8 Premultiplying Colors specify opacity with alpha channel: (r,g,b,  )  =1: opaque,  =.5: translucent,  =0: transparent A over B C =  A + (1-  )B but what if B is also partially transparent? C =  A + (1-  )  B =  B +  A +  B -   B  =  + (1-  )  =  +  –  3 multiplies, different equations for alpha vs. RGB premultiplying by alpha C’ =  C, B’ =  B, A’ =  A C’ = B’ + A’ -  B’  =  +  –  1 multiply to find C, same equations for alpha and RGB

9 Texturing

10 Rendering Pipeline Geometry Database Geometry Database Model/View Transform. Model/View Transform. Lighting Perspective Transform. Perspective Transform. Clipping Scan Conversion Scan Conversion Depth Test Depth Test Texturing Blending Frame- buffer Frame- buffer Geometry Processing Rasterization Fragment Processing

11 Texture Mapping real life objects have nonuniform colors, normals to generate realistic objects, reproduce coloring & normal variations = texture can often replace complex geometric details

12 Texture Mapping introduced to increase realism lighting/shading models not enough hide geometric simplicity images convey illusion of geometry map a brick wall texture on a flat polygon create bumpy effect on surface associate 2D information with 3D surface point on surface corresponds to a point in texture “paint” image onto polygon

13 Color Texture Mapping define color (RGB) for each point on object surface two approaches surface texture map volumetric texture

14 Texture Coordinates texture image: 2D array of color values (texels) assigning texture coordinates (s,t) at vertex with object coordinates (x,y,z,w) use interpolated (s,t) for texel lookup at each pixel use value to modify a polygon’s color or other surface property specified by programmer or artist glTexCoord2f(s,t) glVertexf(x,y,z,w)

15 Texture Mapping Example + =

16 Example Texture Map glTexCoord2d(0,0); glVertex3d (0, -2, -2); glTexCoord2d(1,1); glVertex3d (0, 2, 2);

17 Fractional Texture Coordinates (0,0)(1,0) (0,1)(1,1) (0,0)(.25,0) (0,.5) (.25,.5) texture image

18 Texture Lookup: Tiling and Clamping what if s or t is outside the interval [0…1]? multiple choices use fractional part of texture coordinates cyclic repetition of texture to tile whole surface glTexParameteri( …, GL_TEXTURE_WRAP_S, GL_REPEAT, GL_TEXTURE_WRAP_T, GL_REPEAT,... ) clamp every component to range [0…1] re-use color values from texture image border glTexParameteri( …, GL_TEXTURE_WRAP_S, GL_CLAMP, GL_TEXTURE_WRAP_T, GL_CLAMP,... )

19 glTexCoord2d(1, 1); glVertex3d (x, y, z); (1,0) (0,0)(0,1) (1,1) Tiled Texture Map glTexCoord2d(4, 4); glVertex3d (x, y, z); (4,4) (0,4) (4,0) (0,0)

20 Demo Nate Robbins tutors texture

21 Texture Coordinate Transformation motivation change scale, orientation of texture on an object approach texture matrix stack transforms specified (or generated) tex coords glMatrixMode( GL_TEXTURE ); glLoadIdentity(); glRotate(); … more flexible than changing (s,t) coordinates [demo]

22 Texture Functions once have value from the texture map, can: directly use as surface color: GL_REPLACE throw away old color, lose lighting effects modulate surface color: GL_MODULATE multiply old color by new value, keep lighting info texturing happens after lighting, not relit use as surface color, modulate alpha: GL_DECAL like replace, but supports texture transparency blend surface color with another: GL_BLEND new value controls which of 2 colors to use indirection, new value not used directly for coloring specify with glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, ) [demo]

23 Texture Pipeline Texel color (0.9,0.8,0.7) (x, y, z) Object position (-2.3, 7.1, 17.7) (s, t) Parameter space (0.32, 0.29) Texel space (81, 74) (s’, t’) Transformed parameter space (0.52, 0.49) Final color (0.45,0.4,0.35) Object color (0.5,0.5,0.5)

24 Texture Objects and Binding texture object an OpenGL data type that keeps textures resident in memory and provides identifiers to easily access them provides efficiency gains over having to repeatedly load and reload a texture you can prioritize textures to keep in memory OpenGL uses least recently used (LRU) if no priority is assigned texture binding which texture to use right now switch between preloaded textures

25 Basic OpenGL Texturing create a texture object and fill it with texture data: glGenTextures(num, &indices) to get identifiers for the objects glBindTexture(GL_TEXTURE_2D, identifier) to bind following texture commands refer to the bound texture glTexParameteri(GL_TEXTURE_2D, …, …) to specify parameters for use when applying the texture glTexImage2D(GL_TEXTURE_2D, ….) to specify the texture data (the image itself) enable texturing: glEnable(GL_TEXTURE_2D) state how the texture will be used: glTexEnvf(…) specify texture coordinates for the polygon: use glTexCoord2f(s,t) before each vertex: glTexCoord2f(0,0); glVertex3f(x,y,z);

26 Low-Level Details large range of functions for controlling layout of texture data state how the data in your image is arranged e.g.: glPixelStorei(GL_UNPACK_ALIGNMENT, 1) tells OpenGL not to skip bytes at the end of a row you must state how you want the texture to be put in memory: how many bits per “pixel”, which channels,… textures must be square and size a power of 2 common sizes are 32x32, 64x64, 256x256 smaller uses less memory, and there is a finite amount of texture memory on graphics cards ok to use texture template sample code for project 4

27 Texture Mapping texture coordinates specified at vertices glTexCoord2f(s,t); glVertexf(x,y,z); interpolated across triangle (like R,G,B,Z) …well not quite!

28 Texture Mapping texture coordinate interpolation perspective foreshortening problem

29 Interpolation: Screen vs. World Space screen space interpolation incorrect problem ignored with shading, but artifacts more visible with texturing P 1 (x,y,z) V 0 (x’,y’) V 1 (x’,y’) P 0 (x,y,z)

30 Texture Coordinate Interpolation perspective correct interpolation , ,  : barycentric coordinates of a point P in a triangle s0, s1, s2 : texture coordinates of vertices w0, w1,w2 : homogeneous coordinates of vertices (s1,t1) (s0,t0) (s2,t2) (x1,y1,z1,w1) (x0,y0,z0,w0) (x2,y2,z2,w2)  (s,t)?

31 Reconstruction (image courtesy of Kiriakos Kutulakos, U Rochester)

32 Reconstruction how to deal with: pixels that are much larger than texels? apply filtering, “averaging” pixels that are much smaller than texels ? interpolate

33 MIPmapping Without MIP-mapping With MIP-mapping use “image pyramid” to precompute averaged versions of the texture store whole pyramid in single block of memory

34 MIPmaps multum in parvo -- many things in a small place prespecify a series of prefiltered texture maps of decreasing resolutions requires more texture storage avoid shimmering and flashing as objects move gluBuild2DMipmaps automatically constructs a family of textures from original texture size down to 1x1 withoutwith

35 MIPmap storage only 1/3 more space required

36 Texture Parameters in addition to color can control other material/object properties surface normal (bump mapping) reflected color (environment mapping)

37 Bump Mapping: Normals As Texture object surface often not smooth – to recreate correctly need complex geometry model can control shape “effect” by locally perturbing surface normal random perturbation directional change over region

38 Bump Mapping

39 Bump Mapping

40 Embossing at transitions rotate point’s surface normal by θ or - θ

41 Displacement Mapping bump mapping gets silhouettes wrong shadows wrong too change surface geometry instead only recently available with realtime graphics need to subdivide surface