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

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

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 #9: Textures. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2013

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 #6: Lights. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2014

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

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

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

CS 432 Interactive Computer Graphics

CT5510: Computer Graphics. Texture Mapping

Texture Mapping 1/34

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

Lecture 07: Buffers and Textures

Texture Mapping 1/34

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

Discussion 3. PPM loading Texture rendering in OpenGL

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

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.

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

Texture Mapping. Mike Bailey.

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

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

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

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

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

INF3320 Computer Graphics and Discrete Geometry

Steiner- Wallner- Podaras

Texture Mapping and Sampling

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

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

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

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

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

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

Texture Mapping CSCI 4229/5229 Computer Graphics Fall 2016

INF3320 Computer Graphics and Discrete Geometry

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

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

Textures. Texture Mapping. Bitmap Textures. Basic Texture Techniques

Applying Textures. Lecture 27. Robb T. Koether. Hampden-Sydney College. Fri, Nov 3, 2017

Shading/Texturing. Dr. Scott Schaefer

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

Magnification and Minification

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

CS212. OpenGL Texture Mapping and Related

Texture and other Mappings

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

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

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

ก ก ก.

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

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

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

Computergraphics Exercise 15/ Shading & Texturing

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

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

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

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

Computer Graphics. Lecture 8 Antialiasing, Texture Mapping

Fog example. Fog is atmospheric effect. Better realism, helps determine distances

CS179: GPU Programming

Computational Strategies

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

CS 354R: Computer Game Technology

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

Sampling, Aliasing, & Mipmaps

Sampling, Aliasing, & Mipmaps

Lecture 5 3D graphics part 3

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

Motivation. towards more realism. + Texture Mapping Texture Mapping

Computer Graphics Texture Mapping

Sampling, Aliasing, & Mipmaps

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

Overview. By end of the week:

VGP353 Week 2. Agenda: Assignment #1 due Introduce shadow maps. Differences / similarities with shadow textures Added benefits Potential problems

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

Lighting and Texturing

Textures. Texture coordinates. Introduce one more component to geometry

Grafica Computazionale

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

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

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

Perspective Projection and Texture Mapping

Computer Graphics 7 - Texture mapping, bump mapping and antialiasing

Practical Texturing (WebGL) CS559 Fall 2016 Lecture 20 November 7th 2016

CS 130 Final. Fall 2015

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Programming Graphics Hardware

OUTLINE. Implementing Texturing What Can Go Wrong and How to Fix It Mipmapping Filtering Perspective Correction

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

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

Imaging and Raster Primitives

Mattan Erez. The University of Texas at Austin

CS 4620 Midterm, March 21, 2017

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

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

Transcription:

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

Announcements Project 2 is due this Friday at 2pm Next Tuesday during lecture: midterm #1 2

Faculty Mentor Program UC San Diego faculty members can support undergraduate research by participating in the 2017-18 Faculty Mentor Program (FMP) and providing an undergraduate an opportunity to serve as a research assistant. In addition to the research experience, students in the program receive two quarters of 199 credit (10h/week), attend training sessions and workshops conducted by Academic Enrichment Programs (AEP), and present their findings at the annual Spring FMP Symposium. Students participating in FMP must have junior or senior standing, and must meet GPA and other requirements. Those faculty members who have a student in mind can refer the student to AEP for formal placement. Faculty members working with more than one student can work with AEP to create a cohort experience for them. Early application is encouraged (students have an application deadline of November 1st). More information is available at fmp.ucsd.edu. 3

Matlab project at Shiley Eye Center My name is Rohan Verma, a third-year ophthalmology resident at UCSD Shiley Eye Institute. We are developing a software program using matlab that will ideally become a smartphone application. The goal is to automate the measurement of eyelid contour using iris registration (see attached figure and video). This would allow physicians (ophthalmologist and primary care) to take a photo using a smartphone and be able to determine if there is any abnormality in eyelid position. This would help with early identification of patients at risk of ocular morbidity given eyelid malposition. As well as, help with preoperative planning and patient education. We are looking for someone with programming skills in matlab and ios. Do you know of anyone interested? I feel your experience as the director for UCSD center for visual computing would be able to ideally help us. If so can you please disseminate the email and interested parties may respond to me at roverma@ucsd.edu 4

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

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

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

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 8

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) 9 (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 10

Texture Mapping Primitives Modeling and viewing transformation Shading Projection Rasterization Fragment processing Includes texture mapping Frame-buffer access (z-buffering) 11 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 12

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

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 14

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 15

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); Source: https://open.gl/textures 16

Lecture Overview Texture Mapping Wrapping Texture coordinates Anti-aliasing 17

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 18

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) 19 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 20 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 21 Source: https://open.gl/textures

Lecture Overview Texture Mapping Wrapping Texture coordinates Anti-aliasing 22

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: Cylindrical Spherical Orthographic Parametric Skin 23

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

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

Orthographic Mapping Use linear transformation of object s xyz coordinates Example: 26 = 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) 27

Skin Mapping 28

Lecture Overview Texture Mapping Wrapping Texture coordinates Anti-aliasing 29

Aliasing What could cause this aliasing effect? 30

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 31

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 32

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 33

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) 34

Mipmaps Example: resolutions 512x512, 256x256, 128x128, 64x64, 32x32 pixels Level 1 35 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 36 Level 0 2 3 4 multum in parvo

Mipmaps Level 0 Level 1 Level 2 37 Level 3 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 38

Mipmapping Image plane Camera space Texture space Texels Pixel area 39 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 40

Nearest Mipmap, Bilinear Visible transition between mipmap levels 41

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 42

Addendum: Anisotropic Filtering Method of enhancing the image quality of textures on surfaces that are at oblique viewing angles Different degrees or ratios of anisotropic filtering can be applied The degree refers to the maximum ratio of anisotropy supported by the filtering process. For example, 4:1 anisotropic filtering supports presampled textures up to four times wider than tall 43

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

OpenGL Example: Loading a Texture // Loads image as texture, returns ID of texture GLuint loadtexture(image* image) { GLuint textureid; glgentextures(1, &textureid); // Get unique ID for texture glbindtexture(gl_texture_2d, textureid); // Tell OpenGL which texture to edit gltexparameteri(gl_texture_2d, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // set bi-linear interpolation gltexparameteri(gl_texture_2d, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // for both filtering modes gltexparameteri(gl_texture_2d, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // set texture edge mode gltexparameteri(gl_texture_2d, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); Image* image = loadjpg( photo.jpg"); // load image from disk; uses third party Image library // Depending on the image library, the texture image may have to be flipped vertically // Load image into OpenGL texture in GPU memory: glteximage2d(gl_texture_2d, // Always GL_TEXTURE_2D for image textures 0, // 0 for now GL_RGB, // Format OpenGL uses for image without alpha channel image->width, image->height, // Width and height 0, // The border of the image GL_RGB, // GL_RGB, because pixels are stored in RGB format GL_UNSIGNED_BYTE, // GL_UNSIGNED_BYTE, because pixels are stored as unsigned numbers image->pixels); // The actual RGB image data } return textureid; // Return the ID of the texture 45

Vertex Shader #version 150 in vec3 vert; in vec2 verttexcoord; out vec2 fragtexcoord; void main() { // Pass the tex coord straight through to the fragment shader fragtexcoord = verttexcoord; } gl_position = vec4(vert, 1); 46

Fragment Shader #version 150 uniform sampler2d tex; // this is the texture in vec2 fragtexcoord; // these are the texture coordinates out vec4 finalcolor; // this is the output color of the pixel void main() { finalcolor = texture(tex, fragtexcoord); } 47