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

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

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. Computer Graphics CSE 167 Lecture 9

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

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

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

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

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

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

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

CSE 167: Lecture #8: Lighting. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

CS GPU and GPGPU Programming Lecture 11: GPU Texturing 1. Markus Hadwiger, KAUST

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

CS GPU and GPGPU Programming Lecture 12: GPU Texturing 1. Markus Hadwiger, KAUST

CT5510: Computer Graphics. Texture Mapping

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

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

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

CS GPU and GPGPU Programming Lecture 16+17: GPU Texturing 1+2. Markus Hadwiger, KAUST

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

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

Magnification and Minification

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

Lecture 07: Buffers and Textures

Computer Graphics. Lecture 8 Antialiasing, Texture Mapping

Texture Mapping and Sampling

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

INF3320 Computer Graphics and Discrete Geometry

CSE528 Computer Graphics: Theory, Algorithms, and Applications

CSE 167: Lecture #4: Vertex Transformation. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

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

3D Rasterization II COS 426

Computational Strategies

CS 432 Interactive Computer Graphics

Texture Mapping CSCI 4229/5229 Computer Graphics Fall 2016

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

Texture Mapping. Mike Bailey.

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

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

CSE 167: Introduction to Computer Graphics Lecture #4: Vertex Transformation

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

CS212. OpenGL Texture Mapping and Related

Reading. 18. Projections and Z-buffers. Required: Watt, Section , 6.3, 6.6 (esp. intro and subsections 1, 4, and 8 10), Further reading:

Shading/Texturing. Dr. Scott Schaefer

CS 130 Final. Fall 2015

Pipeline Operations. CS 4620 Lecture 10

Computer Graphics 7 - Texture mapping, bump mapping and antialiasing

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

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

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

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

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

Steiner- Wallner- Podaras

Textures and normals in ray tracing

CPSC / Texture Mapping

INF3320 Computer Graphics and Discrete Geometry

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. Three-Dimensional Graphics VI. Guoying Zhao 1 / 73

Lecture 5 3D graphics part 3

Textures. Texture Mapping. Bitmap Textures. Basic Texture Techniques

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

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

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

Texture Mapping. Michael Kazhdan ( /467) HB Ch. 14.8,14.9 FvDFH Ch. 16.3, , 16.6

AMCS / CS 247 Scientific Visualization Lecture 10: (GPU) Texture Mapping. Markus Hadwiger, KAUST

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

Computer Graphics Texture Mapping

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

Mipmaps. Lecture 35. Robb T. Koether. Hampden-Sydney College. Wed, Nov 18, 2015

TEXTURE MAPPING. DVA338 Computer Graphics Thomas Larsson, Afshin Ameri

+ = To Do. Texture Mapping. Adding Visual Detail. Parameterization. Option: Varieties of projections. Computer Graphics. geometry

Texture Mapping 1/34

Pipeline Operations. CS 4620 Lecture 14

Computer Graphics I Lecture 11

CSE 167: Introduction to Computer Graphics Lecture #10: View Frustum Culling

CS 354R: Computer Game Technology

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

Mattan Erez. The University of Texas at Austin

Textures. Texture coordinates. Introduce one more component to geometry

Perspective Projection and Texture Mapping

Module Contact: Dr Stephen Laycock, CMP Copyright of the University of East Anglia Version 1

CSE 167: Introduction to Computer Graphics Lecture #11: Visibility Culling

CSE 690: GPGPU. Lecture 2: Understanding the Fabric - Intro to Graphics. Klaus Mueller Stony Brook University Computer Science Department

How do we draw a picture?

Sampling, Aliasing, & Mipmaps

Spring 2012 Final. CS184 - Foundations of Computer Graphics. University of California at Berkeley

Sampling, Aliasing, & Mipmaps

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

Homework #2. Shading, Ray Tracing, and Texture Mapping

Topics and things to know about them:

+ = To Do. Adding Visual Detail. Texture Mapping. Parameterization. Option: Varieties of projections. Foundations of Computer Graphics (Fall 2012)

CS335 Graphics and Multimedia. Slides adopted from OpenGL Tutorial

CS 4620 Midterm, March 21, 2017

Recollection. Models Pixels. Model transformation Viewport transformation Clipping Rasterization Texturing + Lights & shadows

Review of Tuesday. ECS 175 Chapter 3: Object Representation

Shading. Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller/Fuhrmann

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

Rasterizing triangles

Texture Mapping 1/34

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

Transcription:

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

Announcements Project 2 due this Friday Midterm next Tuesday 2

Lecture Overview Types of Geometry Shading Texture Mapping 3

Types of Shading Per-triangle Per-vertex Per-pixel 4

Per-Triangle Shading A.k.a. flat shading Evaluate shading once per triangle Advantage Fast Disadvantage Faceted appearance 5

Per-Vertex Shading Known as Gouraud shading (Henri Gouraud, 1971) Interpolates vertex colors across triangles Advantages Fast Smoother surface appearance than with flat shading Disadvantage Problems with small highlights 6

Per-Pixel Shading A.k.a. Phong Interpolation (not to be confused with Phong Illumination Model) Rasterizer interpolates normals (instead of colors) across triangles Illumination model is evaluated at each pixel Simulates shading with normals of a curved surface Advantage Higher quality than Gouraud shading Disadvantage Slow 7 Source: Penny Rheingans, UMBC

Gouraud vs. Per-Pixel Shading Gouraud shading has problems with highlights when polygons are large More triangles improve the result, but reduce frame rate Gouraud Per-Pixel 8

Lecture Overview Texture Mapping Overview Wrapping Texture coordinates Anti-aliasing 9

Large Triangles Pros: Often sufficient for simple geometry Fast to render Cons: Per vertex colors look boring and computer-generated 10

Texture Mapping Map textures (images) onto surface polygons Same triangle count, much more realistic appearance 11

Texture Mapping Goal: map locations in texture to locations on 3D geometry Texture coordinate space Texture pixels (texels) have texture coordinates (s,t) Convention Bottom left corner of texture is at (s,t) = (0,0) Top right corner is at (s,t) = (1,1) (1,1) t (0,0) s Texture coordinates 12

Texture Mapping Store 2D texture coordinates s,t with each triangle vertex v 1 (s,t) = (0.65,0.75) (1,1) v 0 (s,t) = (0.6,0.4) (0.65,0.75) v 2 (s,t) = (0.4,0.45) Triangle in any space before projection t (0.4,0.45) (0.6,0.4) 13 (0,0) Texture coordinates s

Texture Mapping Each point on triangle gets color from its corresponding point in texture v 1 (s,t) = (0.65,0.75) (1,1) (0.65,0.75) v 0 (s,t) = (0.6,0.4) t (0.4,0.45) (0.6,0.4) v 2 (s,t) = (0.4,0.45) Triangle in any space before projection (0,0) Texture coordinates s 14

Texture Mapping Primitives Modeling and viewing transformation Shading Projection Rasterization Fragment processing Includes texture mapping Frame-buffer access (z-buffering) 15 Image

Texture Look-Up Given interpolated texture coordinates (s, t) at current pixel Closest four texels in texture space are at (s 0,t 0 ), (s 1,t 0 ), (s 0,t 1 ), (s 1,t 1 ) How to compute pixel color? t 1 t t 0 s 0 s s 1 16

Nearest-Neighbor Interpolation Use color of closest texel t 1 t t 0 s 0 s s 1 Simple, but low quality and aliasing 17

Bilinear Interpolation 1. Linear interpolation horizontally: Ratio in s direction r s : s s0 r s = s s 1 0 c top = tex(s 0,t 1 ) (1-r s ) + tex(s 1,t 1 ) r s c bot = tex(s 0, t 0 ) (1-r s ) + tex(s 1,t 0 ) r s t 1 t c top c bot t 0 s 0 s s 1 18

Bilinear Interpolation 2. Linear interpolation vertically Ratio in t direction r t : t t0 r t = t1 t0 c = c bot (1-r t ) + c top r t t 1 c top t c c bot t 0 s 0 s s 1 19

Texture Filtering in OpenGL GL_NEAREST: Nearest-Neighbor interpolation GL_LINEAR: Bilinear interpolation Example: gltexparameteri(gl_texture_2d, GL_TEXTURE_MIN_FILTER, GL_LINEAR); gltexparameteri(gl_texture_2d, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 20 Source: https://open.gl/textures

Lecture Overview Texture Mapping Wrapping Texture coordinates Anti-aliasing 21

Wrap Modes Texture image extends from [0,0] to [1,1] in texture space What if (s,t) texture coordinates are beyond that range? Texture wrap modes 22

Repeat Repeat the texture Creates discontinuities at edges unless texture is designed to line up (1,1) t (0,0) s Seamless brick wall texture (by Christopher Revoir) 23 Texture Space

Clamp Use edge value everywhere outside data range [0..1] Or use specified border color outside of range [0..1] (1,1) t (0,0) s 24 Texture Space

Wrap Modes in OpenGL Default: gltexparameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); gltexparameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); Options for wrap mode: GL_REPEAT GL_MIRRORED_REPEAT GL_CLAMP_TO_EDGE: repeats last pixel in the texture GL_CLAMP_TO_BORDER: requires border color to be set 25 Source: https://open.gl/textures

Lecture Overview Texture Mapping Wrapping Texture coordinates Anti-aliasing 26

Texture Coordinates What if texture extends across multiple polygons? Surface parameterization Mapping between 3D positions on surface and 2D texture coordinates Defined by texture coordinates of triangle vertices Options for mapping: Parametric Orthographic Projective Spherical Cylindrical Skin 27

Cylindrical Mapping Similar to spherical mapping, but with cylindrical coordinates 28

Spherical Mapping Use spherical coordinates Shrink-wrap sphere to object Texture map Mapping result 29

Orthographic Mapping Use linear transformation of object s xyz coordinates Example: 30 = w z y x t s 0 0 1 0 0 0 0 1 xyz in object space xyz in camera space

Parametric Mapping Surface given by parametric functions Very common in CAD Clamp (u,v) parameters to [0..1] and use as texture coordinates (s,t) 31

Lecture Overview Texture Mapping Wrapping Texture coordinates Anti-aliasing 32

Aliasing What could cause this aliasing effect? 33

Aliasing Sufficiently sampled, no aliasing Insufficiently sampled, aliasing Image: Robert L. Cook High frequencies in the input data can appear as lower frequencies in the sampled signal 34

Antialiasing: Intuition Pixel may cover large area on triangle in camera space Corresponds to many texels in texture space Need to compute average Image plane Camera space Texture space Texels Pixel area 35

Lecture Overview Texture Mapping Mip Mapping 36

Antialiasing Using Mip-Maps Averaging over texels is expensive Many texels as objects get smaller Large memory access and compuation cost Precompute filtered (averaged) textures Mip-maps Practical solution to aliasing problem Fast and simple Available in OpenGL, implemented in GPUs Reasonable quality 37

Mipmaps MIP stands for multum in parvo = much in little (Williams 1983) Before rendering Pre-compute and store down scaled versions of textures Reduce resolution by factors of two successively Use high quality filtering (averaging) scheme Increases memory cost by 1/3 1/3 = ¼+1/16+1/64+ Width and height of texture should be powers of two (nonpower of two supported since OpenGL 2.0) 38

Mipmaps Example: resolutions 512x512, 256x256, 128x128, 64x64, 32x32 pixels Level 1 39 Level 0 2 3 4 multum in parvo

Mipmaps One texel in level 4 is the average of 4 4 =256 texels in level 0 Level 1 40 Level 0 2 3 4 multum in parvo

Mipmaps Level 0 41 Level 1 Level 3 Level 2 Level 4

Rendering With Mipmaps Mipmapping Interpolate texture coordinates of each pixel as without mipmapping Compute approximate size of pixel in texture space Look up color in nearest mipmap E.g., if pixel corresponds to 10x10 texels use mipmap level 3 Use nearest neighbor or bilinear interpolation as before 42

Mipmapping Image plane Camera space Texture space Texels Pixel area 43 Mip-map level 0 Mip-map level 1 Mip-map level 2 Mip-map level 3

Nearest Mipmap, Nearest Neighbor Visible transition between mipmap levels 44

Nearest Mipmap, Bilinear Visible transition between mipmap levels 45

Trilinear Mipmapping Use two nearest mipmap levels E.g., if pixel corresponds to 10x10 texels, use mipmap levels 3 (8x8) and 4 (16x16) 2-Step approach: Step 1: perform bilinear interpolation in both mip-maps Step 2: linearly interpolate between the results Requires access to 8 texels for each pixel Supported by hardware without performance penalty 46

More Info Mipmapping tutorial w/source code: http://www.videotutorialsrock.com/opengl_tutorial/mipmapping/text.php 47