Texture Mapping Part 1

Similar documents
Texture Mapping. The Quest for Visual Realism. Photo-textures

Texture Mapping and Sampling

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

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

CS 130 Final. Fall 2015

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

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

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

CSE528 Computer Graphics: Theory, Algorithms, and Applications

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

CS212. OpenGL Texture Mapping and Related

Pipeline Operations. CS 4620 Lecture 14

CS 432 Interactive Computer Graphics

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

CS451Real-time Rendering Pipeline

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

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

Lecture 5 3D graphics part 3

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

CS 130 Exam I. Fall 2015

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

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Pipeline Operations. CS 4620 Lecture 10

Rasterization. COMP 575/770 Spring 2013

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

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

Computer Graphics Fundamentals. Jon Macey

4: Polygons and pixels

For each question, indicate whether the statement is true or false by circling T or F, respectively.

Drawing Fast The Graphics Pipeline

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

COMP30019 Graphics and Interaction Rendering pipeline & object modelling

Lecture outline. COMP30019 Graphics and Interaction Rendering pipeline & object modelling. Introduction to modelling


Shading Techniques Denbigh Starkey

Volume Shadows Tutorial Nuclear / the Lab

INF3320 Computer Graphics and Discrete Geometry

Clipping & Culling. Lecture 11 Spring Trivial Rejection Outcode Clipping Plane-at-a-time Clipping Backface Culling

Sign up for crits! Announcments

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

Homework #2. Shading, Projections, Texture Mapping, Ray Tracing, and Bezier Curves

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

Grafica Computazionale

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

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

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

Could you make the XNA functions yourself?

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

Shading. Flat shading Gouraud shading Phong shading

Viewing with Computers (OpenGL)

Topics and things to know about them:

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

Computing Visibility. Backface Culling for General Visibility. One More Trick with Planes. BSP Trees Ray Casting Depth Buffering Quiz

Parametric description

Lecture 07: Buffers and Textures

Graphics and Interaction Rendering pipeline & object modelling

Advanced Texture-Mapping Curves and Curved Surfaces. Pre-Lecture Business. Texture Modes. Texture Modes. Review quiz

CS 465 Program 4: Modeller

- Rasterization. Geometry. Scan Conversion. Rasterization

CSC 240 Computer Graphics. Fall 2015 Smith College

CS4620/5620: Lecture 14 Pipeline

3D Graphics and OpenGl. First Steps

The Rendering Pipeline (1)

Textures. Texture Mapping. Bitmap Textures. Basic Texture Techniques

CS Computer Graphics: Hidden Surface Removal

Texture Mapping. Mike Bailey.

CS 4620 Program 3: Pipeline

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

SUMMARY. CS380: Introduction to Computer Graphics Varying Variables Chapter 13. Min H. Kim KAIST School of Computing 18/04/26.

6.837 Introduction to Computer Graphics Assignment 5: OpenGL and Solid Textures Due Wednesday October 22, 2003 at 11:59pm

Shadows in the graphics pipeline

Texture and other Mappings

Computational Strategies

Computer Graphics Introduction. Taku Komura

Textures and UV Mapping in Blender

Computer Graphics I Lecture 11

Drawing Fast The Graphics Pipeline

Performance OpenGL Programming (for whatever reason)

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

PROFESSIONAL. WebGL Programming DEVELOPING 3D GRAPHICS FOR THE WEB. Andreas Anyuru WILEY. John Wiley & Sons, Ltd.

CS 4204 Computer Graphics

CS 498 VR. Lecture 20-4/11/18. go.illinois.edu/vrlect20

An Approach to Content Creation for Trainz

CS179: GPU Programming

COMP 161 Lecture Notes 16 Analyzing Search and Sort

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

The Traditional Graphics Pipeline

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

Level of Details in Computer Rendering

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

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

Welcome to COMP 770 (236) Introduction. Prerequisites. Prerequisites

3D Rasterization II COS 426

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

The Problem of Calculating Vertex Normals for Unevenly Subdivided Smooth Surfaces

Graphics Pipeline 2D Geometric Transformations

Illumination & Shading: Part 1

Computer Graphics 1. Chapter 7 (June 17th, 2010, 2-4pm): Shading and rendering. LMU München Medieninformatik Andreas Butz Computergraphik 1 SS2010

Computer Graphics. Prof. Feng Liu. Fall /14/2016

Transcription:

Texture Mapping Part 1 The Quest for Visual Realism Why Texture Map? How to do it How to do it right Spilling the beans Assignment #3 Lecture 17 Comp 236 Spring 2005 3/21/2005 Lecture 17 2 Decal Textures Simple OpenGL Example The concept is very simple! Specify a texture coordinate at each vertex (s, t) Canonical coordinates where s and t are between 0 and 1 def drawcube(): global cubetex if (cubetex == None): cubetex = Texture("mandrill.bmp") gldisable(gl_lighting) glenable(gl_texture_2d); glbindtexture(gl_texture_2d, cubetex.texid) glbegin(gl_quads) glcolor3d(0.0, 0.0, 1.0) gltexcoord2d(0, 1) glvertex3d( 1.0, 1.0, 1.0) gltexcoord2d(1, 1) glvertex3d(-1.0, 1.0, 1.0) gltexcoord2d(1, 0) glvertex3d(-1.0,-1.0, 1.0) gltexcoord2d(0, 0) glvertex3d( 1.0,-1.0, 1.0) glend() gldisable(gl_texture_2d)

OpenGL Texture Peculiarities Linear Interpolation of Textures The width and height of Textures in OpenGL must be powers of 2 The parameter space of each dimension of a texture ranges from [0,1) regardless of the texture s actual size. The behavior of texture indices outside of the range [0,1) is determined by the texture wrap options. gltexparameteri(gl_texture_2d, GL_TEXTURE_WRAP_S, GL_REPEAT) gltexparameteri(gl_texture_2d, GL_TEXTURE_WRAP_T, GL_REPEAT) gldisable(gl_lighting) glenable(gl_texture_2d); glbindtexture(gl_texture_2d, cubetex.texid) glbegin(gl_quads) glcolor3d(0.0, 0.0, 1.0) gltexcoord2d(-1, 2) glvertex3d( 1.0, 1.0, 1.0) gltexcoord2d( 2, 2) glvertex3d(-1.0, 1.0, 1.0) gltexcoord2d( 2, -1) glvertex3d(-1.0,-1.0, 1.0) gltexcoord2d(-1, -1) glvertex3d( 1.0,-1.0, 1.0) glend() gldisable(gl_texture_2d) gltexparameteri(gl_texture_2d, GL_TEXTURE_WRAP_S, GL_CLAMP) gltexparameteri(gl_texture_2d, GL_TEXTURE_WRAP_T, GL_CLAMP) 3/21/2005 Lecture 17 5 It used to be easy to get OpenGL to do this! At first, you might think that we could simply apply the linear interpolation methods that we used to interpolate colors in our triangle rasterizer. However, if you implement texturing this way, you don t get the expected results. Notice how the texture seems to bend and warp along the diagonal triangle edges. Letys take a closer look at what is going on. 3/21/2005 Lecture 17 6 Texture Index Interpolation Texture Interpolation Problem Interpolating texture indices is not as simple as the linear interpolation of colors that we discussed when rasterizing triangles. Let s look at an example. First, letys consider one edge from a given triangle. This edge and its projection onto our viewport lie in a single common plane. For the moment, letys look only at that plane, which is illustrated below: Notice that uniform steps on the image plane do not correspond to uniform steps along the edge. Without loss of generality, let s assume that the viewport is located 1 unit away from the center of projection.

Linear Interpolation in Screen Space Linear Interpolation in 3-Space Compare linear interpolation in screen space to interpolation in 3-space: 3/21/2005 Lecture 17 9 3/21/2005 Lecture 17 10 How to make them Mesh Still need to scan convert in screen space... so we need a mapping from t values to s values. We know that the all points on the 3-space edge project onto our screen-space line. Thus we can set up the following equality: Interpolating Parameters We can now use this expression for s to interpolate arbitrary parameters, such as texture indices (u, v), over our 3-space triangle. This is accomplished by substituting our solution for s given t into the parameter interpolation. and solve for s in terms of t giving: Unfortunately, at this point in the pipeline (after projection) we no longer have z 1 and z 2 lingering around (Why?). However, we do have w 1 = 1/z 1 and w 2 = 1/z 2. Therefore, if we premultiply all parameters that we wish to interpolate in 3- space by their corresponding w value and add a new plane equation to interpolate the w values themselves, we can interpolate the numerators and denominator in screen-space. We then need to perform a divide a each step to get to map the screen-space interpolants to their corresponding 3-space values. This is a simple modification to the triangle rasterizer that we developed in class.

Demonstration For obvious reasons this method of interpolation is called perspective-correct interpolation. The fact is, the name could be shortened to simply correct interpolation. You should be aware that not all 3-D graphics APIs implement perspective-correct interpolation. Dealing with Incorrect Interpolation You can reduce the perceived artifacts of non-perspective correct interpolation by subdividing the texture-mapped triangles into smaller triangles (why does this work?). But, fundamentally the screen-space interpolation of projected parameters is inherently flawed. 3/21/2005 Lecture 17 13 This is not a big deal anymore! Can you think of some another reason you might want to subdivide though? 3/21/2005 Lecture 17 14 Wait a Minute! When we did Gouraud shading, and discussed interpolating normals for Phong shading didn t we interpolate the values that we found at each vertex using screen-space interpolation? Didn t we just say that screen-space interpolation is wrong (I believe "inherently flawed" were my exact words)? Does that mean that Gouraud shading is wrong? Is linear interpolation of colors wrong? Is linear interpolation of normals in screen-space wrong? Is everything that I ve been telling you all one big lie? Has Comp 236 amounted to a total waste of time? Yes, Yes, Yes, Maybe No, you ve had lots of fun with purple cows! Traditional screen-space Gourand shading is wrong. However, you usually will not notice because the transition in colors is very smooth (And we donyt know what the right color should be anyway, all we care about is a pretty picture). There are some cases where the errors in Gourand shading become obvious. When switching between different levels-of-detail representations At "T" joints.

Assignment #3, Due 3/29 Two Basic Mesh Operations Imagine yourself as a cow Half edge collapses Find a vertex within a convex region Move it to one of its adjacent vertices Change in Tri count? Vertex count? Edge swaps Before After After Identify an edge within a convex quad region Swap diagonals of the quad Before 3/21/2005 Lecture 17 17 3/21/2005 Lecture 17 18 Next Time More Texture Mapping tricks