Texture Mapping 1/34

Similar documents
Texture Mapping 1/34

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 Fall Quarter 2017

CT5510: Computer Graphics. Texture Mapping

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

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

Texture mapping. Computer Graphics CSE 167 Lecture 9

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

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

Discussion 3. PPM loading Texture rendering in OpenGL

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

CS 432 Interactive Computer Graphics

Texture and other Mappings

INF3320 Computer Graphics and Discrete Geometry

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

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

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

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

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

CS 428: Fall Introduction to. Texture mapping and filtering. Andrew Nealen, Rutgers, /18/2010 1

Lecture 07: Buffers and Textures

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

Computer Graphics. Lecture 8 Antialiasing, Texture Mapping

Shading/Texturing. Dr. Scott Schaefer

Review of Tuesday. ECS 175 Chapter 3: Object Representation

Texture Mapping and Sampling

Texture Mapping. Mike Bailey.

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

CS 130 Final. Fall 2015

Motivation. towards more realism. + Texture Mapping Texture Mapping

INF3320 Computer Graphics and Discrete Geometry

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

Textures. Texture coordinates. Introduce one more component to geometry

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

CS 354R: Computer Game Technology

Barycentric Coordinates and Parameterization

Shading. Flat shading Gouraud shading Phong shading

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

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

Computer Graphics 7 - Texture mapping, bump mapping and antialiasing

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

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

Computergraphics Exercise 15/ Shading & Texturing

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

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

Textures and normals in ray tracing

Overview. By end of the week:

CPSC / Texture Mapping

Texture Mapping. Texture (images) lecture 16. Texture mapping Aliasing (and anti-aliasing) Adding texture improves realism.

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

Lighting and Texturing

Sign up for crits! Announcments

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

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

Sampling, Aliasing, & Mipmaps

Surface Rendering. Surface Rendering

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

Introduction Rasterization Z-buffering Shading. Graphics 2012/2013, 4th quarter. Lecture 09: graphics pipeline (rasterization and shading)

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

Computer Graphics. Texture Filtering & Sampling Theory. Hendrik Lensch. Computer Graphics WS07/08 Texturing

lecture 16 Texture mapping Aliasing (and anti-aliasing)

CS 4620 Midterm, March 21, 2017

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

Computer Graphics. - Texturing Methods -

Homework 3: Programmable Shaders

CSE528 Computer Graphics: Theory, Algorithms, and Applications

3D Rasterization II COS 426

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

CPSC 436D Video Game Programming

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

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

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

Sampling, Aliasing, & Mipmaps

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

Sampling, Aliasing, & Mipmaps

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

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

Ptex: Per-face Texture Mapping for Production Rendering

COMP 175 COMPUTER GRAPHICS. Ray Casting. COMP 175: Computer Graphics April 26, Erik Anderson 09 Ray Casting

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

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

Rasterizing triangles

Textures. Texture Mapping. Bitmap Textures. Basic Texture Techniques

TEXTURE MAPPING. DVA338 Computer Graphics Thomas Larsson, Afshin Ameri

7. Texture Mapping. Idea. Examples Image Textures. Motivation. Textures can be images or procedures. Textures can be 2D or 3D

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

More Texture Mapping. Texture Mapping 1/46

The Rasterizer Stage. Texturing, Lighting, Testing and Blending

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

CS179: GPU Programming

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

Render-To-Texture Caching. D. Sim Dietrich Jr.

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

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

CMSC427 Advanced shading getting global illumination by local methods. Credit: slides Prof. Zwicker

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

Topics and things to know about them:

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

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Transcription:

Texture Mapping 1/34

Texture Mapping Offsets the modeling assumption that the BRDF doesn t change in u and v coordinates along the object s surface Store a reflectance as an image called a texture Map that image onto the object 2/36

Texture Coordinates A texture image is defined in a 2D coordinate system: (u, v) Each triangle vertex is assigned a (u,v) coordinate, so that one knows which part of the texture to stick on the triangle The texture is stuck onto the triangle by defining an (R,G,B) texture color for each pixel inside the triangle (0,1) (1,1) (0,0) (1,0) texture image 2 triangles 3/36

Texture Coordinates Calculate texture coordinates (u,v) for each pixel using barycentric interpolation of the texture coordinates of the triangle s vertices (u0, v0) α2 α1 α0 (u1, v1) (u2, v2) Pixel texture coordinates: (u,v) = α0(u0,v0) + α1(u1,v1) + α2(u2,v2) 4/36

Pixel RGB Color Given the pixel s (u,v) texture coordinates, find the pixel s color in the texture map - using interpolation! 5/36

Bilinear Interpolation First linearly interpolate in the u-direction, then linearly interpolate in the v-direction (or vice versa) b a 6/36

Bilinear Interpolation T(u, v) = (1-a)(1-b) T[i, j] + a (1-b) T[i+1, j] + (1-a)b T[i, j+1] + ab T[i+1, j+1] Bilinear interpolation is applied to each of the R, G, B (and alpha) channels, using the same weights 7/36

Screen Space vs. World Space Triangles change shape nonlinearly via perspective transformation, leading to different barycentric weights before and after the perspective transformation Interpolating in screen space results in texture distortion Interpolating in world space requires projecting all pixel locations backwards from screen space to world space, which is expensive 8/36

Texture Distortion Consider a single edge of a triangle Project this from world space to screen space 9/36

Texture Distortion Uniform increments along the edge in world space do not correspond to uniform increments along the edge in screen space Barycentric interpolation (which is linear) does not account for this nonlinearity 10/36

Mesh Refinement Refinement of the triangle mesh improves the result, because a nonlinear function can be approximated as a piecewise linear function if the intervals are small enough More and more triangles helps everything mostly, but is not very efficient (or desirable) T junction subdivision If the resolution varies, T-junctions cause problems too 11/36

Mesh Refinement Better-ish, but still looks bad 12/36

Screen Space Barycentric Interpolation Find the relationship between the barycentric weights in screen space and those in world space Use this relationship to compute the world space barycentric weights from the screen space barycentric weights This removes the need to inefficiently go back to world space to get the correct result 13/36

Screen Space Barycentric Interpolation Ignore the y direction coordinate for simplicity The world space coordinates of the end points of an edge are p w = x 1 p 1 w = x 2 z 2 1 z 2 The corresponding screen space end points are p 1 = hx 1 p z 2 = hx 2 1 z 2 The world space coordinates of a point on the edge are given by The corresponding screen space location of p w s is SCREEN_SPACE( p w s ) = h 1 s x + sx 1 2 1 s z 1 + sz 2 This same point corresponds to some value of interpolation in screen space with t: p w s = (1 s) x 1 z 1 + s x 2 z 2 1 t hx 1 z 1 + t hx 2 z 2 = h 1 s x 1 +sx 2 1 s z 1 +sz 2 14/36

Screen Space Barycentric Interpolation Solving this last equation for s gives a mapping from barycentric coordinates in screen space to barycentric coordinates in world space: s = tz 1 z 2 + t(z 1 z 2 ) Thus for each pixel, compute its barycentric weights in screen space to obtain t Then use the mapping from screen space barycentric weights t to world space barycentric weights s to find the world space barycentric weights Use these world space barycentric weights s to interpolate the texture coordinates form the triangle s vertices N.B. this is the formula for a segment, not for a triangle 15/36

For triangles Screen Space Barycentric Interpolation A pixel inside a screen space triangle has barycentric weights p α, β = αp 0 + βp 1 + (1 α β)p 2 Following all the steps in the previous slides (for triangles) we obtain the world space barycentric weights α w = z 1 z 2 α z 0 z 1 + z 1 α z 2 z 0 + z 0 β z 2 z 1 β w = z 0 z 2 β z 0 z 1 + z 1 α z 2 z 0 + z 0 β z 2 z 1 These world space barycentric weights α w, β w,(1 α w β w ) are used to interpolate the texture coordinates from the triangle vertices to that pixel Then then the color is looked up in the texture map as usual 16/36

Screen Space Barycentric Interpolation 17/36

Assigning Texture Coordinates Texture Mapping 18/36

Assigning Texture Texture Mapping Coordinates Typically assign coordinates one piece of the object at a time 19/36

Assigning Texture Coordinates For certain surfaces, the (u, v) texture coordinates can be generated procedurally Example: Cylinder map the u coordinate from [0, 1] to [0, 2 π] for Φ map the v coordinate from [0, 1] to [0, h] for y This wraps the image around the cylinder For more complex surfaces, (u, v) must be defined per vertex manually or by using proxy objects y Φ 20/36

Proxy Objects Step 1 Assign texture coordinates to intermediate/proxy objects: Example: Cylinder wrap texture around the outside of the cylinder not the top or bottom, in order to avoid distorting the texture Example: Cube unwrap the cube and map texture over the unwrapped cube the texture is seamless across some of the edges, but not necessarily others 21/36

Proxy Objects Step 2 Map texture coordinates from the intermediate/proxy object to the final object Three ways of mapping are generally used: Use the intermediate/proxy object s surface normal Use the target object s surface normal Use rays emanating from center of target object 22/36

Aliasing Texture Mapping 23/36

Aliasing When textures are viewed from a distance, you may get aliasing What we get What we want (more about aliasing in week 6) 24/36

Aliasing Texture mapping is point-sampling If the pixel sampling frequency is too low compared to the signal frequency (the texture resolution), aliasing occurs At an optimal distance, there is a 1 to 1 mapping from triangle pixels to texture pixels (texels) At a closer distance, each tringle pixel maps to a small part of a texture pixel, multiple pixels per texel (oversampling is fine) At a far distance, each triangle pixel maps to several texture pixels, but interpolation ignores all but the nearest texels so information is lost (averaging would be better) 25/36

MIP Maps Multum in Parvo: Much in little, many in small places Precomputes the texture maps at multiple resolutions, using averaging as a low pass filter When texture mapping, choose the image size that approximately gives a 1 to 1 pixel to texel correspondence The averaging bakes-in all the nearby pixels that otherwise would not be sampled correctly 26/36

MIP Maps 4 neighboring pixels of the higher level are averaged to form a single pixel in the lower level Starting at a base resolution, you can store EVERY coarser resolution in powers of 2 using only 1/3 additional space 1+1/4+1/16+. = 4/3 27/36

MIP Maps To use the MIP maps, look for the two MIP map images just above and below the screen space pixel resolution Use the standard bilinear interpolation on both the higher and lower resolution MIP map images Then use linear interpolation between those two bilinearly interpolated texture values, where the weights come from comparing the screen space resolution to that of the two MIP maps 28/36

MIP Maps 29/36

RIP Maps Consider texturing a horizontal plane which is at an oblique angle to the camera The texel sampling rate will be much smaller vertically than horizontally Using an averaged MIP map created to avoid aliasing in the vertical direction also averages in the horizontal direction causing unwanted blurring In MIP mapping, both texture axes are equally averaged RIP mapping is an anisotropic improvement to isotropic MIP mapping that coarsens both axes separately 30/36

RIP Maps RIP maps require 4 times the storage if we store every coarser resolution in each axial direction: (1+1/4+1/16+ )[1+2(1/2+1/4+1/8+ )]=4 MIP map RIP map 31/36

Homework & Resources Texture Mapping 32/36

OpenGL First load your image Input: any image source (as long as you know how to parse it) Output: unsigned byte array Bytes can encode data in many different ways, most common is RGB or RGBA (with each component an unsigned int = 4 bytes) Total data size for RGBA = width * height * 4 Data looks like RGBARGBARGBA... 33/36

OpenGL Gluint textureid; // identifier for our texture glgentextures(1, &textureid); // make room for our texture glbindtexture(gl_texture_2d, textureid); // tell GL which texture to edit glteximage2d(gl_texture_2d, level, components, width, height, border, format, type, data); level - for mip-maps. If you supply only one resolution, level should be 0. If you supply mip-maps with multiple resolutions, the highest resolution level should be 0, then 1, then 2, components - how texture is store (r,g,b, how much to allocate for each component) width, height, border format of input data, and the data itself glteximage2d(gl_texture_2d, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); 34/36

OpenGL Create Texture glactivetexture(gl_texturei); glbindtexture(gl_texture_2d, textureid); gluniform1i("diffusetexture, i); Render In GLSL: in vec2 fragmentuv; uniform sampler2d diffusetexture; vec4 texturecolor = texture(diffusetexture, fragmentuv); 35/36

Online Databases You can find a number of useful texture maps online. For example, you can find many different crate textures for boxes by searching for texture map crate using Google There are a number of websites containing different kinds of textures for different objects. Here are some examples: http://www.cgtextures.com/ http://www.textureking.com/ http://www.lughertexture.com/ http://www.mayang.com/textures/ http://www.marlinstudios.com/samples/samples.htm http://www.arroway-textures.com/ http://www.environment-textures.com/ http://www.3dtexture.net/ 36/36