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

Similar documents
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

Textures. Datorgrafik 2006

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

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

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

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

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Texture Mapping and Sampling

INF3320 Computer Graphics and Discrete Geometry

CS 432 Interactive Computer Graphics

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

CT5510: Computer Graphics. Texture Mapping

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

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

Steiner- Wallner- Podaras

CS452/552; EE465/505. Image Processing Frame Buffer Objects

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

Texture mapping. Computer Graphics CSE 167 Lecture 9

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

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

Textures. Texture Mapping. Bitmap Textures. Basic Texture Techniques

Discussion 3. PPM loading Texture rendering in OpenGL

Texture Mapping. Mike Bailey.

Lecture 07: Buffers and Textures

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

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

CS 354R: Computer Game Technology

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

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

Computer Graphics Texture Mapping

Textures. Texture coordinates. Introduce one more component to geometry

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

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

CS 179 GPU Programming

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

Shading/Texturing. Dr. Scott Schaefer

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

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

CS212. OpenGL Texture Mapping and Related

Computer Graphics. Bing-Yu Chen National Taiwan University

Department of Computer Engineering 3D Graphics in Games and Movies

Grafica Computazionale

Introduction to Computer Graphics with WebGL

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

INF3320 Computer Graphics and Discrete Geometry

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

Picking (In WebGL) Picking idea

Monday Morning. Graphics Hardware

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

CS335 Graphics and Multimedia. Slides adopted from OpenGL Tutorial

CS451Real-time Rendering Pipeline

Computer Graphics 7 - Texture mapping, bump mapping and antialiasing

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

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

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

Magnification and Minification

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

Pipeline Operations. CS 4620 Lecture 14

Texture and other Mappings

Computergraphics Exercise 15/ Shading & Texturing

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

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

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

TSBK03 Screen-Space Ambient Occlusion

Overview. By end of the week:

ก ก ก.

Texture Mapping CSCI 4229/5229 Computer Graphics Fall 2016

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

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

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

Texture Mapping and Special Effects

Lecture 5 3D graphics part 3

Texture Mapping 1/34

Rasterization Overview

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

Computer Graphics Texture Mapping

Textures III. Week 10, Wed Mar 24

Programming Graphics Hardware

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

Surface Rendering. Surface Rendering

Perspective Projection and Texture Mapping

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

CS 4620 Program 3: Pipeline

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

Spring 2011 Prof. Hyesoon Kim

Computer Graphics. Lecture 9 Environment mapping, Mirroring

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

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

CS179: GPU Programming

Spring 2009 Prof. Hyesoon Kim

Chapter IV Fragment Processing and Output Merging. 3D Graphics for Game Programming

Pipeline Operations. CS 4620 Lecture 10

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

3D Rasterization II COS 426

Mattan Erez. The University of Texas at Austin

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

Transcription:

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

Texturing: Glue n-dimensional images onto geometrical objects l Purpose: more realism, and this is a cheap way to do it Bump mapping Plus, we can do environment mapping And other things + = 2

(2,2) Texture coordinates (0,1) (1,1) (0,0) (1,0) (u,v) in [0,1] (u 0,v 0 ) 3 (-1,-1) (u 2,v 2 ) l What if (u,v) >1.0 or <0.0? (u 1,v 1 ) l To repeat textures, use just the fractional part Example: 5.3 -> 0.3 l Repeat, mirror, clamp, border:

Texture magnification l What does the theory say l sinc(x) is not feasible in real time l Box filter (nearest-neighbor) is l Poor quality 4

Texture magnification l Tent filter is feasible! l Linear interpolation l Looks better l Simple in 1D: l (1-t)*color0+t*color1 l How about 2D? 5

Bilinear interpolation l Texture coordinates (p u,p v ) in [0,1] l Texture images size: n*m texels l Nearest neighbor would access: ( floor(n*u+0.5), floor(m*v+0.5) ) l Interpolate 1D in x & y respectively 6

Bilinear interpolation weights l Check out this formula at home l t(u,v) accesses the texture map l b(u,v) filtered texel 7

Texture minification What does a pixel see? l Theory (sinc) is too expensive l Cheaper: average of texel inside a pixel l Still too expensive, actually 8 l Mipmaps another level of approximation Prefilter texture maps as shown on next slide

9 Mipmapping l Image pyramid l Half width and height when going upwards l Average over 4 parent texels to form child texel l Depending on amount of minification, determine which image to fetch from l Compute d first, gives two images Bilinear interpolation in each v d u

Mipmapping l Interpolate between those bilinear values Gives trilinear interpolation Level n+1 (u 0,v 0,d 0 ) d v u Level n l Constant time filtering: 8 texel accesses 10 l How to compute d?

Computing d for mipmapping texel pixel projected to texture space A = approximative area of quadrilateral b = A l Approximate quad with square l Gives overblur! d = log 2 b l Even better: anisotropic texture filtering Approximate quad with several smaller mipmap samples 11

Anisotropic texture filtering 16 samples 12

Mipmapping: Memory requirements l Not twice the number of bytes! 1/4 1/16 1/64 1/1 13 l Rather 33% more not that much Modified by Ulf Assarsson 2004

Miscellaneous l How to apply texturing: Add, sub, etc as you like, using fragment shaders. Common alternatives: Modulate (multiply texture with lighting) Replace (just use texture color) 14

15 Modulate

Using textures in OpenGL Do once when loading texture: texture = ilutglloadimage("flake.ppm"); // Here, we use DevIL glactivetexture(gl_texture0); glbindtexture(gl_texture_2d, texture); glgeneratemipmap(gl_texture_2d); gltexparameterf(gl_texture_2d, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16); //Indicates that the active texture should be repeated over the surface gltexparameteri(gl_texture_2d, GL_TEXTURE_WRAP_S, GL_REPEAT); gltexparameteri(gl_texture_2d, GL_TEXTURE_WRAP_T, GL_REPEAT); // Sets the type of mipmap interpolation to be used on magnifying and // minifying the active texture. These are the nicest available options. gltexparameteri(gl_texture_2d, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gltexparameteri(gl_texture_2d, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); Do every time you want to use this texture when drawing: glactivetexture(gl_texture0); glbindtexture(gl_texture_2d, texture); // Now, draw your triangles with texture coordinates specified 16

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 + = Example 17

Environment mapping Department of Computer Engineering

Environment mapping 19 l Assumes the environment is infinitely far away l Sphere mapping For details, see OH 166-169 l 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 Modified by Ulf Assarsson 2004

Department of Computer Engineering Sphere map example Sphere map (texture) Sphere map applied on torus

Example Department of Computer Engineering

Sphere Map 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 22

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 2 x Rx s = 0.5 L Ry t = 0.5 L + R 2 y + 1 + 1 + ( R + ) z 1 2 23

Sphere Map 24

Cube mapping eye n y z x 25 l l l 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) l Remap from [-1,1] to [0,1], i.e., ((u,v)+(1,1))/2 l Your hardware does all the work. You just have to compute the reflection vector. (See lab 4)

Department of Computer Engineering 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 + = geometry Bump map Bump mapped geometr Stores heights: can derive normals

Department of Computer Engineering 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:

Bump mapping: example 28 l Other ways to do bump mapping on These are less expensive, and feasible on cheaper hardware

Bump mapping vs normal mapping Normal mapping (Normals are stored direction in model space. I.e., as including both face orientation plus distorsion. ) 29 Bump mapping (Normals are stored as distorsion of face orientation. The same bump map can be tiled/repeated and reused for many faces with different orientation)

30 More... l 3D textures: Feasible on modern hardware as well Texture filtering is no longer trilinear Rather quadlinear (linear interpolation 4 times) Enables new possibilities l Can store light in a room, for example l Displacement Mapping Offsets the position per pixel or per vertex l Offsetting per vertex is easy in vertex shader l 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 31

32 From http://www.ati.com/developer/shaderx/shaderx_3dtextures.pdf

Precomputed Light fields 33 Max Payne 2 by Remedy Entertainment Samuli Laine and Janne Kontkanen

Displacement Mapping l Uses a map to displace the surface at each position 34

Rendering to Texture //******************************************** // Create a Frame Buffer Object (FBO) that we first render to and then use as a texture //******************************************** glgenframebuffersext(1, &framebuffer); // generate framebuffer id glbindframebufferext(gl_framebuffer, framebuffer); // following commands will affect framebuffer // Create a texture for the frame buffer, with specified filtering, rgba-format and size glgentextures( 1, &texframebuffer ); glbindtexture( GL_TEXTURE_2D, texframebuffer ); // following commands will affect texframebuffer gltexparameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); gltexparameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glteximage2d( GL_TEXTURE_2D, 0, 4, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL ); // Create a depth buffer for our FBO glgenrenderbuffers(1, &depthbuffer); // get the ID to a new Renderbuffer glbindrenderbuffer(gl_renderbuffer, depthbuffer); glrenderbufferstorage(gl_renderbuffer, GL_DEPTH_COMPONENT, 512, 512); (See also Lab 5) // Set rendering of the default color0-buffer to go into the texture glframebuffertexture2d(gl_framebuffer, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texframebuffer, 0); glframebufferrenderbufferext(gl_framebuffer, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthbuffer); // Associate our created depth buffer with the FBO Or simply use: glcopytexsubimage 35

Sprites GLbyte M[64]=! {!127,0,0,127, 127,0,0,127, 127,0,0,127, 127,0,0,127,!!0,127,0,0, 0,127,0,127, 0,127,0,127, 0,127,0,0,!!0,0,127,0, 0,0,127,127, 0,0,127,127, 0,0,127,0,!!127,127,0,0, 127,127,0,127, 127,127,0,127, 127,127,0,0};!! void display(void) {!!glclearcolor(0.0,1.0,1.0,1.0);!!glclear(gl_color_buffer_bit);!!glenable (GL_BLEND);!!glBlendFunc (GL_SRC_ALPHA,!GL_ONE_MINUS_SRC_ALPHA);!!glRasterPos2d(xpos1,ypos1);!!glPixelZoom(8.0,8.0);!!glDrawPixels(width,height,!!!GL_RGBA,!GL_BYTE, M);!!!!glPixelZoom(1.0,1.0);!!glutSwapBuffers();! }! 36

Sprites Animation Maps The sprites for Ryu: 37

Billboards 2D images used in 3D environments Common for trees, explosions, clouds, lensflares 38

Department of Computer Engineering With courtesy of DICE: RalliSport Challenge 2

Billboards Rotate them towards viewer Either by rotation matrix (see OH 288), or by orthographic projection 40

Billboards Fix correct transparency by blending AND using alpha-test In fragment shader: if (color.a < 0.1) discard; Or: sort back-to-front and blend Depth writing can then preferrably be disabled gldepthmask(0); Color Buffer Depth Buffer With blending With alpha test 41

Perspective distorsion 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. 42

Which is preferred? This is the result billboards Real spheres Actually, viewpoint oriented is usually preferred since it most closely resembles the result using standard triangulated geometry 43

n axial billboarding The rotation axis is fixed and disregarding the view position Also called Impostors 44

Department of Computer Engineering Partikelsystem Particles

Partikelsystem Department of Computer Engineering

Particle Systems 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 47