Texture Mapping Graphics scene tanpa texture -> cenderung polosan-> sepi. Untuk membuat permukaan yang kompleks, jika hanya menggunakan bentuk geometri.

Slides:



Advertisements
Similar presentations
Lecture 8 Transparency, Mirroring
Advertisements

Virtual Realism TEXTURE MAPPING. The Quest for Visual Realism.
Graphics Pipeline.
Introduction and Basic OpenGL functionality
03/16/2009Dinesh Manocha, COMP770 Texturing Surface’s texture: its look & feel Graphics: a process that takes a surface and modifies its appearance using.
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.
Real-Time Rendering TEXTURING Lecture 02 Marina Gavrilova.
ATEC Procedural Animation Introduction to Procedural Methods in 3D Computer Animation Dr. Midori Kitagawa.
Computer Graphics Bing-Yu Chen National Taiwan University.
Week 7 - Wednesday.  What did we talk about last time?  Transparency  Gamma correction  Started texturing.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Textures II Week 8, Wed.
Texture Mapping CPSC /24/03 Abhijeet Ghosh.
Computer Graphics (Spring 2008) COMS 4160, Lecture 19: Texture Mapping Many slides from Greg Humphreys, UVA and Rosalee.
(conventional Cartesian reference system)
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.
1 Computer Graphics Week13 –Shading Models. Shading Models Flat Shading Model: In this technique, each surface is assumed to have one normal vector (usually.
Computer Graphics Inf4/MSc Computer Graphics Lecture 9 Antialiasing, Texture Mapping.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
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
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. 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
Mapping method Texture Mapping Environmental mapping (sphere mapping) (cube mapping)
An Interactive Introduction to OpenGL Programming Ed Angel
UW EXTENSION CERTIFICATE PROGRAM IN GAME DEVELOPMENT 2 ND QUARTER: ADVANCED GRAPHICS Textures.
09/09/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Event management Lag Group assignment has happened, like it or not.
CS 638, Fall 2001 Today Project Stage 0.5 Environment mapping Light Mapping.
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.
CS 445 / 645: Introductory Computer Graphics Light.
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.
Advanced Computer Graphics Advanced Shaders CO2409 Computer Graphics Week 16.
Texture Mapping Drawing Pictures on Polygons. Texture Mapping.
Game Programming 06 The Rendering Engine
Computing & Information Sciences Kansas State University Lecture 10 of 42CIS 636/736: (Introduction to) Computer Graphics CIS 636/736 Computer Graphics.
Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora.
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.
Computing & Information Sciences Kansas State University Lecture 12 of 42CIS 636/736: (Introduction to) Computer Graphics CIS 636/736 Computer Graphics.
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.
Greg Humphreys CS445: Intro Graphics University of Virginia, Fall 2003 Texture Mapping Greg Humphreys University of Virginia CS 445, Fall 2003.
Texture Mapping CEng 477 Introduction to Computer Graphics.
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.
Week 7 - Wednesday CS361.
Texture Mapping Fall, 2016.
ATEC Procedural Animation
ATCM 3310 Procedural Animation
OpenGL Texture Mapping
OpenGL Texture Mapping
Chapters VIII Image Texturing
(c) University of Wisconsin, CS 559
3D Game Programming Texture Mapping
Procedural Animation Lecture 6: Mapping
ATCM 6317 Procedural Animation
OpenGL Texture Mapping
OpenGL Texture Mapping
3D Game Programming Texture Mapping
OpenGL Texture Mapping
Presentation transcript:

Texture Mapping Graphics scene tanpa texture -> cenderung polosan-> sepi. Untuk membuat permukaan yang kompleks, jika hanya menggunakan bentuk geometri maka akan sangat terbatas Gambar/citra bisa membantu memberikan efek ilusi pada permukaan Images painted onto polygons is called texture mapping

Texture Maps Images applied to polygons to enhance the visual effect of a scene

Texture Mapping Texture map is an image, two-dimensional array of color values (texels/texture pixel) Texels are specified by texture’s (u,v) space At each screen pixel, texel can be used to substitute a polygon’s surface property (color) We must map (u,v) space to polygon’s (s, t) space S T U V

Example Texture Map

Example Texture Map Applied to tilted polygon

Example Texture Map glVertex3d (s, s, s) glTexCoord2d(1,1);

The Art of 3D Computer Animation and Effects Isaac Kerlow

Texture Representation Bitmap (pixel map) textures (supported by OpenGL) Procedural textures (used in advanced rendering programs) Bitmap texture: A 2D image - represented by 2D array texture[height][width] Each pixel (or called texel ) by a unique pair texture coordinate (s, t) The s and t are usually normalized to a [0,1] range For any given (s,t) in the normalized range, there is a unique image value (i.e., a unique [red, green, blue] set ) s t (0,0) (1,1)

Map textures to surfaces Establish mapping from texture to surfaces (polygons): - Application program needs to specify texture coordinates for each corner of the polygon (0,0) (1,0) (1,1) The polygon can be in an arbitrary size

Texture Value Lookup (0,0) (1,0) For the given texture coordinates (u,v), we can find a unique image value from the texture map (1,1) How about coordinates that are not exactly at the intersection (pixel) positions? Nearest neighbor Linear Interpolation Other filters (0,0) (0.25,0) (0.5,0) (0.75,0) (1,0)

OpenGL texture mapping Steps in your program 1) Specify texture read or generate image Assign to texture 2) Specify texture mapping parameters Wrapping, filtering, etc. 3) Enable GL texture mapping (GL_TEXTURE_2D) 4) Assign texture coordinates to vertices 5) Draw your objects 6) Disable GL texture mapping (if you don’t need to perform texture mapping any more)

Specify textures Load the texture map from main memory to texture memory glTexImage2D(Glenum target, Glint level, Glint iformat, int width, int height, int border, Glenum format, Glenum type, Glvoid* img) Example: glTeximage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, myImage); (myImage is a 2D array: GLuByte myImage[64][64][3]; ) The dimensions of texture images must be powers of 2

Fix texture size If the dimensions of the texture map are not power of 2, you can Pad zeros 2) use gluScaleImage() 60 Ask OpenGL to filter the data for you to the right size – you can specify the output resolution that you want 100 128 Remember to adjust the texture coordinates for your polygon corners – you don’t want to Include black texels in your final picture 64

Texture mapping parameters What happen if the given texture coordinates (s,t) are outside [0,1] range? glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ) glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ) GL_Repeat (0,0) (2,2) (0,0) (2,2) GL_Clamp If (s >1) s = 1 If (t >1) t = 1 (0,0) (1,1) texture

Wrapping

Wrapping

Texture mapping parameters(2) Since a polygon can get transformed to arbitrary screen size, texels in the texture map can get magnified or minified. Filtering: interpolate a texel value from its neighbors or combine multiple texel values into a single one texture texture polygon projection polygon projection Magnification Minification

Texture mapping parameters(3) OpenGL texture filtering: 2) Linear interpolate the neighbors (better quality, slower) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) Nearest Neighbor (lower image quality) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); Or GL_TEXTURE_MAX_FILTER

Texture color blending Determine how to combine the texel color and the object color GL_MODULATE – multiply texture and object color GL_BLEND – blends with an environmental color GL_REPLACE – use texture color to replace object color Example: glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); Example: Texture is applied after lighting, so how do you adjust the texture’s brightness? Make the polygon white and light it normally Use glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) Then, texture color is multiplied by surface (fragment) color and appears lighted

Enable (Disable) Textures Enable texture – glEnable(GL_TEXTURE_2D) Disable texture – glDisable(GL_TEXTURE_2D) Remember to disable texture mapping when you draw non-textured polygons

Specify texture coordinates glVertex3d (s, s, s); glTexCoord2d(1,1); glVertex3d (-s, -s, -s); glTexCoord2d(0, 0);

Specify texture coordinates Give texture coordinates before defining each vertex glBegin(GL_QUADS); glTexCoord2D(0,0); glVertex3f(-0.5, 0, 0.5); … glEnd();

Transform texture coordinates All the texture coordinates are multiplied by Gl_TEXTURE matrix before in use To transform texture coordinates, you do: glMatrixMode(Gl_TEXTURE); Apply regular transformation functions Then you can draw the textured objects

Put it all together … 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_REPLACE); glEnable(GL_TEXTURE_2D); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, mytexture); Draw_picture1(); // define texture coordinates and vertices in the function ….

Projector Functions How do we map the texture onto a arbitrary (complex) object? Construct a mapping between the 3-D point to an intermediate surface Idea: Project each object point to the intermediate surface with a parallel or perspective projection The focal point is usually placed inside the object Plane Cylinder Sphere Cube courtesy of R. Wolfe Planar projector

Planar Projector u = x, v = y Orthographic projection onto XY plane: courtesy of R. Wolfe ...onto YZ plane ...onto XZ plane

Cylindrical Projector Convert rectangular coordinates (x, y, z) to cylindrical (r, µ, h), use only (h, µ) to index texture image courtesy of R. Wolfe

Spherical Projector Convert rectangular coordinates (x, y, z) to spherical (, f) courtesy of R. Wolfe

Parametric Surfaces A parameterized surface patch x = f(u, v), y = g(u, v), z = h(u, v) courtesy of R. Wolfe

Mipmaps Membuat texture dalam berbagai ukuran untuk menghaluskan penampakan objek yang jauh Ukuran dibedakan per level Level 0: original texture map Level 1: half size in width and height Define mipmaps glTexImage2D( GL_TEXTURE_2D, level, GL_RGB, …); Where level = 0, 1, 2, .. Automatically generate mipmaps gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, width, height, format, type, texels); For near objects For far objects For middle objects

MIPmap pre-filtering Prefilter repeatedly to ½ resolution Reduce resolution equally in all dimensions Stop at a single texel

MIPMAPS With versus without MIPMAP

Mipmap Filters Mipmap minification filters (Table 8.3) Example Code: GL_LINEAR_MIPMAP_NEAREST: use the nearest mipmap closest to the polygon resolution, and use linear filtering GL_LINEAR_MIPMAP_LINEAR: use linear interpolation between the two mipmaps closest to the polygon resolution, and use GL_LINEAR filtering in each mipmap Example Code: gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, 64, 64, GL_RGB, GL_UNSIGNED_BYTE, texImage); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);

Procedural Texture Mapping Instead of looking up an image, pass the texture coordinates to a function that computes the texture value on the fly Renderman, the Pixar rendering language, does this Available in a limited form with vertex shaders on current generation hardware Advantages: Near-infinite resolution with small storage cost Idea works for many other things Has the disadvantage of being slow in many cases

Other Types of Mapping Environment mapping looks up incoming illumination in a map Simulates reflections from shiny surfaces Bump-mapping memberi lighting pada texture sehingga permukaan seperti ada efek timbul Bukan geometri permukaan yang diubah, tapi hanya efek cahaya Displacement mapping mengubah geometri permukaan texture sehingga kesan timbul memang karena geometri permukaan yang diubah jadi timbul All are available in software renderers like RenderMan compliant renderers All these are becoming available in hardware

Bump Mapping Textures can be used to alter the surface normal of an object, but does not change the actual shape of the surface -- we are only shading it as if it were a different shape! This technique is called bump mapping. Since the actual shape of the object does not change, the silhouette edge of the object will not change. Bump Mapping also assumes that the Illumination model is applied at every pixel (as in Phong Shading). Swirly Bump Map Sphere w/Diffuse Texture & Bump Map Sphere w/Diffuse Texture

Bump Map Examples Bump Map Cylinder w/Diffuse Texture Map Cylinder w/Texture Map & Bump Map

Displacement Mapping We use the texture map to actually move the surface point (geometri memang benar-benar diubah jadi timbul). This is called displacement mapping. How is this fundamentally different than bump mapping? The geometry must be displaced before visibility is determined.

Environment Maps We use the direction of the reflected ray to index a texture map. We can simulate reflections. This approach is not completely accurate. It assumes that all reflected rays begin from the same point, and that all objects in the scene are the same distance from that point.

Environment Mapping

Environment Mapping The environment map may take one of several forms: Cubic mapping: map resides on 6 faces of a cube Spherical mapping: map resides on a sphere surrounding the object The map should contain a view of the world with the point of interest on the object as the eye The mapping can be computed at each pixel, or only at the vertices

Spherical Mapping Implemented in hardware Single texture map Problems: Highly non-uniform sampling Highly non-linear mapping

Cubic Mapping The map resides on the surfaces of a cube around the object Typically, align the faces of the cube with the coordinate axes To generate the map: For each face of the cube, render the world from the center of the object with the cube face as the image plane Rendering can be arbitrarily complex (it’s off-line) Or, take 6 photos of a real environment with a camera in the object’s position Actually, take many more photos from different places the object might be Warp them to approximate map for all intermediate points Remember Terminator 2? http://developer.nvidia.com/object/cube_map_ogl_tutorial.html

Cubic Map Example

OpenGL Spherical Map We can use automatically generated texture coordinates in OpenGL. For example, to generate the texture coordinates of spherical mapping // Build the environment as a texture object // Automatically generate the texture coordinates glTexGenf(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGenf(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); // Bind the environment texture … // Draw object Example

OpenGL Cubemap Texture Enabling and disabling the cube map texture is done as follows: glEnable(GL_TEXTURE_CUBE_MAP); glDisable(GL_TEXTURE_CUBE_MAP); glGenTextures(1,&cubemap_id); glBindTexture(GL_TEXTURE_CUBE_MAP,cubemap_id); Load images into a cube map. Each face in the example is a 64x64 RGB image. GLubyte face[6][64][64][3]; for (i=0; i<6; i++) {   glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,     0,                  //level     GL_RGB8,            //internal format     64,                 //width     64,                 //height     0,                  //border     GL_RGB,             //format     GL_UNSIGNED_BYTE,   //type     &face[i][0][0][0]); // pixel data }

OpenGL Implementation (cont.) We can use automatically generated texture coordinates in OpenGL glTexGenfv(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); glTexGenfv(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); glTexGenfv(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_GEN_R); // Bind the environment texture … // Draw object For the cube map to operate correctly, correct per-vertex normals must be supplied