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

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

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

Textures. Datorgrafik 2006

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

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

CS212. OpenGL Texture Mapping and Related

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

Texture and other Mappings

Texture Mapping and Sampling

CT5510: Computer Graphics. Texture Mapping

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

Lecture 07: Buffers and Textures

INF3320 Computer Graphics and Discrete Geometry

Textures. Texture Mapping. Bitmap Textures. Basic Texture Techniques

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

Shading. Flat shading Gouraud shading Phong shading

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

Shading/Texturing. Dr. Scott Schaefer

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

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

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

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

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

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

Texture Mapping. Mike Bailey.

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

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

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

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

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

Textures. Texture coordinates. Introduce one more component to geometry

CS 354R: Computer Game Technology

CS 432 Interactive Computer Graphics

Grafica Computazionale

Computer Graphics. Bing-Yu Chen National Taiwan University

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

CS451Real-time Rendering Pipeline

3D Graphics and OpenGl. First Steps

INF3320 Computer Graphics and Discrete Geometry

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

Texture mapping. Computer Graphics CSE 167 Lecture 9

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

Texture Mapping 1/34

Texture Mapping and Special Effects

ก ก ก.

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

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

Discussion 3. PPM loading Texture rendering in OpenGL

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

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

Lecture 5 3D graphics part 3

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

Monday Morning. Graphics Hardware

CS179: GPU Programming

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

CSC 240 Computer Graphics. Fall 2015 Smith College

CS 450: COMPUTER GRAPHICS TEXTURE MAPPING SPRING 2015 DR. MICHAEL J. REALE

Computational Strategies

Department of Computer Engineering 3D Graphics in Games and Movies

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

CS335 Graphics and Multimedia. Slides adopted from OpenGL Tutorial

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

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

TSBK03 Screen-Space Ambient Occlusion

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

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

Overview. By end of the week:

Pipeline Operations. CS 4620 Lecture 14

CSCI E-74. Simulation and Gaming

Texture Mapping CSCI 4229/5229 Computer Graphics Fall 2016

Texture Mapping 1/34

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

Spring 2009 Prof. Hyesoon Kim

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

Spring 2011 Prof. Hyesoon Kim

Surface Graphics. 200 polys 1,000 polys 15,000 polys. an empty foot. - a mesh of spline patches:

Computer Graphics (CS 543) Lecture 10: Normal Maps, Parametrization, Tone Mapping

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

IntMu.Lab5. Download all the files available from

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

Computer Graphics Texture Mapping

Surface Rendering. Surface Rendering

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

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

Rasterization Overview

Computer Graphics 7 - Texture mapping, bump mapping and antialiasing

Imaging and Raster Primitives

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Programming Graphics Hardware

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

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

TDA362/DIT223 Computer Graphics EXAM (Same exam for both CTH- and GU students)

Lecture 5. Scan Conversion Textures hw2

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

Texture. Texture Mapping. Texture Mapping. CS 475 / CS 675 Computer Graphics. Lecture 11 : Texture

CS 475 / CS 675 Computer Graphics. Lecture 11 : Texture

Textures III. Week 10, Wed Mar 24

Transcription:

Texturing Slides done bytomas Akenine-Möller and Ulf Assarsson Chalmers University of Technology Texturing: Glue n-dimensional images onto geometrical objects Purpose: more realism, and this is a cheap way to do it Bump mapping Plus, we can do environment mapping And other things + = (0,1) Texture coordinates (1,1) (0,0) (1,0) (u,v) in [0,1] (u 2,v 2 ) (u 0,v 0 ) (u 1,v 1 ) What if (u,v) >1.0 or <0.0? To repeat textures, use just the fractional part Example: 5.3 -> 0.3 Repeat, mirror, clamp, border: Texture magnification What does the theory say sinc(x) is not feasible in real time Box filter (nearest-neighbor) is Poor quality (2,2) (-1,-1) Texture magnification Tent filter is feasible! Linear interpolation Looks better Simple in 1D: (1-t)*color0+t*color1 How about 2D? Bilinear interpolation Texture coordinates (p u,p v ) in [0,1] Texture images size: n*m texels Nearest neighbor would access: ( floor(n*u), floor(m*v) ) Interpolate 1D in x & y respectively 1

Bilinear interpolation Check out this formula at home t(u,v) accesses the texture map b(u,v) filtered texel Texture minification What does a pixel see? Theory (sinc) is too expensive Cheaper: average of texel inside a pixel Still too expensive, actually Mipmaps another level of approximation Prefilter texture maps as shown on next slide Mipmapping Image pyramid Half width and height when going upwards Average over 4 parent texels to form child texel Depending on amount of minification, determine which image to fetch from Compute d first, gives two images Bilinear interpolation in each v d u Mipmapping Interpolate between those bilinear values Gives trilinear interpolation Level n+1 (u 0,v 0,d 0 ) d Level n v u Constant time filtering: 8 texel accesses How to compute d? texel Computing d for mipmapping d log 2 b Approximate quad with square Gives overblur! pixel projected to texture space A approximative area of quadrilateral b A Anisotropic texture filtering 16 samples Even better: anisotropic texture filtering Approximate quad with several smaller mipmap samples 2

Mipmapping: Memory requirements Not twice the number of bytes! 1/4 1/64 1/16 Miscellaneous How to apply texturing: Modulate (multiply texture with lighting) Replace (just use texture color) Add, sub, etc (on newer hardware) More in the manuals, e.g. www.msdn.com 1/1 Rather 33% more not that much Modified Tomas Akenine-Mőller by Ulf Assarsson 2002 2004 Modulate Using textures in OpenGL Do once when loading texture: GLuint texid; glgentextures(1, &texid); glbindtexture(gl_texture_2d, texid); 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_LINEAR); gltexparameteri(gl_texture_2d, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // this is the nicest available mipmap // specify whether to modulate color from lighting or replacing color, by setting // GL_MODULATE or GL_DECAL. See OH 152 and MSDN-help for more options gltexenvf(gl_texture_env, GL_TEXTURE_ENV_MODE, GL_DECAL); // Using glu to autogenerate mipmaps (image is pointer to raw rgb-data) glubuild2dmipmaps(gl_texture_2d, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, image); Do every time you want to use this texture when drawing: glbindtexture(gl_texture_2d, texid); glenable(gl_texture_2d); // Now, draw your triangles with texture coordinates specified Automatic Texture Generation Instead of manually specifying texcoords e.g. by using gltexcoord() Do: gltexgeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR) GL_T, GL_R, Particularly useful for sphere mapping GL_EYE_LINEAR GL_SPHERE_MAP GL_NORMAL_MAP_ARB GL_REFLECTION_MAP_ARB GL_CUBE_MAP Light Maps Often used in games Can use multitexturing, or render wall using brick texture render wall using light texture and blending to the frame buffer + = 3

Light Maps example code // First, the quad is rendered with brick-texture and without lighting // The number 5 effectively causes the texture to be repeated 5 times over the surface glbindtexture(gl_texture_2d, texname[brickid]); glcolor3f(1.0, 1.0, 1.0); //Using GL_MODULATE, this light value is multiplied with the texture //lower values gives darkening glbegin(gl_quads); gltexcoord2f(0, 0); glvertex2f(-1, -1); gltexcoord2f(5, 0); glvertex2f(1, -1); gltexcoord2f(5, 5); glvertex2f(1, 1); gltexcoordf(0, 5); glvertex2f(-1, 1); glend(); // Render the quad again using the light map as texture and // use MODULATE to get multiplicative blending glenable(gl_blend); glblendfunc(gl_zero, GL_SRC_COLOR); // Gives brick(in the framebuffer) * lightmap(incoming) gldepthfunc(gl_lequal); // The default value GL_LESS would have depth-culled our new rendering // of the same quad glbindtexture(gl_texture_2d, texname[lightmapid]); //Finally, render the quad using only the lightmap glcolor3f(1.0, 1.0, 1.0); // (not really necessary since it is already set above) glbegin(gl_quads); gltexcoord2f(0, 0); glvertex2f(-1, -1); gltexcoord2f(1, 0); glvertex2f(1, -1); gltexcoord2f(1, 1); glvertex2f(1, 1); gltexcoord2f(0, 1); glvertex2f(-1, 1); glend(); Multitextures OpenGL 1.3 (aug 2001) Texture 0 Texture 1 c t,0 c t,1 Incoming Texture Texture Up to 8 color, c in Unit 0 Unit 1 texture units and finally from e.g. output to lighting and pixel glcolor c out,0 = c in * c t,0 for GL_MODULATE Light Maps multitexture version void wall() { glbegin(gl_quads); // First vertex: two texture coordinates for the brick-texture and lightmaptexture respectively (using texture unit 0 for brick-texture and texture unit 1 for the light map) glmultitexcoord2farb(gl_texture0_arb,0, 0); glmultitexcoord2farb(gl_texture1_arb,0, 0); glvertex2f(-1, -1); // Similar for the next 3 vertices. (5 effectively causes repetition 5 times) glmultitexcoord2farb(gl_texture0_arb,5, 0); glmultitexcoord2farb(gl_texture1_arb,1, 0); glvertex2f(1, -1); glmultitexcoord2farb(gl_texture0_arb,5, 5); glmultitexcoord2farb(gl_texture1_arb,1, 1); glvertex2f(1, 1); glmultitexcoord2farb(gl_texture0_arb,0, 5); glmultitexcoord2farb(gl_texture1_arb,0, 1); glvertex2f(-1, 1); glend(); } Light Maps multitexture version The display-function display(): // glactivetexture sets for which texture unit we currently modify parameters // First, texture unit 0 for the brick texture glactivetexturearb(gl_texture0_arb); gltexenvi(gl_texture_env, GL_TEXTURE_ENV_MODE, GL_DECAL); glbindtexture(gl_texture_2d, texname[brickid]); glenable(gl_texture_2d); // Then, texture unit 1 for the light map glactivetexturearb(gl_texture1_arb); gltexenvi(gl_texture_env,gl_texture_env_mode,gl_modulate); glbindtexture(gl_texture_2d, texname[lightmapid]); glenable(gl_texture_2d); // Just for purpose of illustration, we let the texture matrix translate the texture a little bit glmatrixmode(gl_texture); glpushmatrix(); gltranslatef(tx, ty, tz); wall(); glpopmatrix(); // restore the texture matrix gldisable(gl_texture_2d); glactivetexturearb(gl_texture0_arb); gldisable(gl_texture_2d); Environment mapping Sphere map example Assumes the environment is infinitely far away Sphere mapping For details, see OH 166-169 Cube mapping is the norm nowadays Advantages: no singularities as in sphere map Much less distortion Gives better result Not dependent on a view position Sphere map (texture) Sphere map applied on torus Modified Tomas Akenine-Mőller by Ulf Assarsson 2002 2004 4

Infinitesimally small reflective sphere (infinitely far away) i.e., orthographic view of a reflective unit sphere Create by: Photographing metal sphere Ray tracing Transforming cube map to sphere map Sphere Map Sphere Map Assume surface normals are available Then OpenGL can compute reflection vector at each pixel The texture coordinates s,t are given by: (see OH 169 for details) L R R 2 x 2 y Rx s 0.5 1 L Ry t 0.5 1 L R 1 2 z Sphere Map Cube mapping eye n y z x Simple math: compute reflection vector, r Largest abs-value of component, determines which cube face. Example: r=(5,-1,2) gives POS_X face Divide r by abs(5) gives (u,v)=(-1/5,2/5) Remap from [-1,1] to [0,1], i.e., ((u,v)+(1,1))/2 If your hardware has this feature, then it does all the work Bump mapping by Blinn in 1978 Inexpensive way of simulating wrinkles and bumps on geometry Too expensive to model these geometrically Instead let a texture modify the normal at each pixel, and then use this normal to compute lighting Bump mapping lighting How store normals in texture (bump map) n=(n x, n y, n z ) are in [-1,1] Add 1, mult 0.5: in [0,1] Mult by 255 (8 bit per color component) Can be stored in texture: geometry + = Bump map Bump mapped geometr Stores heights: can derive normals Tomas Akenine- 5

Bump mapping: example Other ways to do bump mapping on These are less expensive, and feasible on cheaper hardware More... 3D textures: Feasible on modern hardware as well Texture filtering is no longer trilinear Rather quadlinear (linear interpolation 4 times) Enables new possibilities Can store light in a room, for example Displacement Mapping Offsets the position per pixel or per vertex Offsetting per vertex is easy in vertex shader Offsetting per pixel is architecturally hard Cannot easily be done in fragment shader Can be done using Geometry Shader (e.g. Direct3D 10) by ray casting in the displacement map 2D texture vs 3D texture From http://www.ati.com/developer/shaderx/shaderx_3dtextures.pdf Displacement Mapping Uses a map to displace the surface at each position Can be done with a Geometry Shader Geometry Shader Example Generalized Displacement Maps Step 0: Process Vertices (VS) Step 1: Extrude Prisms (GS) Step 2: Raytrace! (PS) Vertex Shader Geometry Shader Pixel Shader 6

Rendering to Texture Sprites WGL_ARB_render_to_texture See OH 201 Many different ways: PBuffers NVIDIA: Linux and Windows FrameBufferObjects (FBO:s) ARB superbuffers, ARB_uber_buffers Pixel Buffer Objects = e.g. for updating textures Draw Buffers is multiple output buffers, usually 4 E.g for creating cube maps Direct3D 10 can draw all 6 cube sides in one rendering pass Sprites Billboards Animation Maps The sprites for Ryu: 2D images used in 3D environments Common for trees, explosions, clouds, lensflares Billboards Fix correct transparency by blending AND using alpha-test glenable(gl_alpha_test); glalphafunc(gl_greater, 0.1); Or: sort back-to-front and blend with depth writing disabled gldepthmask(0); Billboards Color Buffer Depth Buffer With blending Rotate them towards viewer Either by rotation matrix (see OH 288), or by orthographic projection OH 289-291 With alpha test 7

Perspective distorsion Which is preferred? Spheres often appear as ellipsoids when located in the periphery. Why? camera Exaggerated example If our eye was placed at the camera position, we would not see the distorsion. We are often positioned way behind the camera. This is the result billboards Real spheres Actually, viewpoint oriented is usually preferred since it most closely resembles the result using standard triangulated geometry Partikelsystem n axial billboarding The rotation axis is fixed and disregarding the view position Also called Impostors Particles Partikelsystem Particle Systems Particle Systems: see also OH 228-229 Boids (flock of birds), see OH 230 3 rules: 1. Separation:Avoid obstacles and getting to close to each other 2. Alignment (strive for same speed and direction as nearby boids 3. Cohesion: steer towards center of mass of nearby boids 8