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

Similar documents
CS212. OpenGL Texture Mapping and Related

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

CS335 Graphics and Multimedia. Slides adopted from OpenGL Tutorial

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

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

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

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

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

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

Computer Graphics. Bing-Yu Chen National Taiwan University

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

CS 432 Interactive Computer Graphics

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

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

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

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

Lecture 07: Buffers and Textures

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

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

Imaging and Raster Primitives

Texture Mapping. Mike Bailey.

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

Lecture 5 3D graphics part 3

CT5510: Computer Graphics. Texture Mapping

Texture Mapping CSCI 4229/5229 Computer Graphics Fall 2016

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

Texture Mapping and Sampling

Lecture 5. Scan Conversion Textures hw2

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

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

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

INF3320 Computer Graphics and Discrete Geometry

Computer Graphics Texture Mapping

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

Magnification and Minification

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

Texture and other Mappings

Textures. Texture Mapping. Bitmap Textures. Basic Texture Techniques

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

Grafica Computazionale

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

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

Shading. Flat shading Gouraud shading Phong shading

CS179: GPU Programming

Texture mapping. Computer Graphics CSE 167 Lecture 9

Workshop 3D capture, modelling and augmented reality Capture 3D, modélisation et réalité augmentée

INF3320 Computer Graphics and Discrete Geometry

Chapter 9 Texture Mapping An Overview and an Example Steps in Texture Mapping A Sample Program Specifying the Texture Texture Proxy Replacing All or

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

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

Computer Graphics Texture Mapping

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

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

Computational Strategies

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

Texture Mapping and Special Effects

Texture Mapping Part 1

Steiner- Wallner- Podaras

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

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

Lighting and Texturing

ก ก ก.

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

lecture 16 Texture mapping Aliasing (and anti-aliasing)

Shading/Texturing. Dr. Scott Schaefer

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

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

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

Introduction to Computer Graphics with WebGL

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

QUESTION 1 [10] 2 COS340-A October/November 2009

CS 130 Final. Fall 2015

9.Texture Mapping. Chapter 9. Chapter Objectives

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

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

3D Rasterization II COS 426

Review of Tuesday. ECS 175 Chapter 3: Object Representation

Assignment #5: Scalar Field Visualization 3D: Direct Volume Rendering

Computer Graphics

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

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

Computergraphics Exercise 15/ Shading & Texturing

Motivation. towards more realism. + Texture Mapping Texture Mapping

Discussion 3. PPM loading Texture rendering in OpenGL

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

Computer Graphics Programming

Chapter 6 Texture Mapping

TEXTURE MAPPING. DVA338 Computer Graphics Thomas Larsson, Afshin Ameri

Computer graphics Labs: OpenGL (1/3) Geometric transformations and projections

11494 Interactive and GPU Computing Lab. 6-06/05/2015. Textures

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

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

Assignment #3: Scalar Field Visualization 3D: Cutting Plane, Wireframe Iso-surfacing, and Direct Volume Rendering

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

Texture. No Textures

Building Models. Objectives. Introduce simple data structures for building polygonal models. OpenGL vertex arrays. Vertex lists Edge lists

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

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

Texture Mapping 1/34

Transcription:

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

Basic Strategy Three steps to applying a texture 1. 2. 3. specify the texture read or generate image assign to texture enable texturing assign texture coordinates to vertices Proper mapping function is left to application specify texture parameters wrapping, filtering 2

Texture Mapping y z x geometry t screen image s 3

Texture Example The texture (below) is a 256 x 256 image that has been mapped to a rectangular polygon which is viewed in perspective 4

Texture Mapping and the OpenGL Pipeline Images and geometry flow through separate pipelines that join at the rasterizer complex textures do not affect geometric complexity vertices geometry pipeline rasterizer image pixel pipeline 5

Specify Texture Image Define a texture image from an array of texels (texture elements) in CPU memory Glubyte my_texels[512][512]; Define as any other pixel map Scan Via application code Enable texture mapping glenable(gl_texture_2d) OpenGL supports 1-4 dimensional texture maps 6

Define Image as a Texture glteximage2d( target, level, components, w, h, border, format, type, texels ); target: type of texture, e.g. GL_TEXTURE_2D level: used for mipmapping (discussed later) components: elements per texel w, h: width and height of texels in pixels border: used for smoothing (discussed later) format and type: describe texels texels: pointer to texel array glteximage2d(gl_texture_2d, 0, 3, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, my_texels); 7

Converting A Texture Image OpenGL requires texture dimensions to be powers of 2 If dimensions of image are not powers of 2 gluscaleimage( format, w_in, h_in, type_in, *data_in, w_out, h_out, type_out, *data_out ); data_in is source image data_out is for destination image Image interpolated and filtered during scaling 8

Mapping a Texture Based on parametric texture coordinates gltexcoord*() specified at each vertex t 0, 1 Texture Space 1, 1 (s, t) = (0.2, 0.8) A a b 0, 0 Object Space c (0.4, 0.2) B 1, 0 s C (0.8, 0.4) 9

Typical Code glbegin(gl_polygon); glcolor3f(r0, g0, b0); glnormal3f(u0, v0, w0); gltexcoord2f(s0, t0); glvertex3f(x0, y0, z0); glcolor3f(r1, g1, b1); glnormal3f(u1, v1, w1); gltexcoord2f(s1, t1); glvertex3f(x1, y1, z1);.. glend(); Note that we can use vertex arrays to increase efficiency 10

Interpolation OpenGL uses bilinear interpolation to find proper texels from specified texture coordinates Can be distortions texture stretched good selection of tex coordinates poor selection of tex coordinates over trapezoid showing effects of bilinear interpolation 11

Texture Parameters OpenGL: a variety of parameter that determine how texture is applied Wrapping parameters determine what happens if s and t are outside the (0,1) range Filter modes allow us to use area averaging instead of point samples Mipmapping allows us to use textures at multiple resolutions Environment parameters determine how texture mapping interacts with shading 12

Wrapping Mode Clamping: if s,t > 1 use 1, if s,t < 0 use 0 Wrapping: use s,t modulo 1 gltexparameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ) gltexparameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ) t s texture GL_REPEAT wrapping GL_CLAMP wrapping 13

Wrapping Mode Clamp in s and t Repeat in s and t Clamp in s, Repeat in t 14

Magnification and Minification Texel smaller than pixel more than one texel can cover a pixel (minification) Texel larger than pixel - more than one pixel can cover a texel (magnification) Can use point sampling (nearest texel -fastest) or linear filtering ( 2 x 2 filter less aliasing) to obtain texture values Texture Polygon Magnification Texture Polygon Minification 15

Filter Modes Modes determined by gltexparameteri( target, type, mode ) gltexparameteri(gl_texture_2d, GL_TEXURE_MAG_FILTER, GL_NEAREST); gltexparameteri(gl_texture_2d, GL_TEXURE_MIN_FILTER, GL_LINEAR); Note that linear filtering requires a border of an extra texel for filtering at edges (border = 1) 16

Mipmapped Textures Mipmapping allows for prefiltered texture maps of decreasing resolutions Lessens interpolation errors for smaller textured objects Declare mipmap level during texture definition glteximage2d( GL_TEXTURE_*D, level, ) GLU mipmap builder routines will build all the textures from a given image glubuild*dmipmaps( ) * is 2, 3, 4 in above 17

Example point sampling mipmapped point sampling linear filtering mipmapped linear filtering 18

Examples 7E/07/textureCube1 7E/07/textureCubev2 7E/07/textureCubev4 19

Example-Planet Earth 20

Planet Earth-Picture 21

Possible Solution function triangle(a, b, c) { pointsarray.push(a[0],a[1],a[2]); pointsarray.push(b); pointsarray.push(c); // normals are vectors normalsarray.push(a[0],a[1], a[2], 0.0); normalsarray.push(b[0],b[1], b[2], 0.0); normalsarray.push(c[0],c[1], c[2], 0.0); //texture coordinates texcoordsarray.push(spherical(a)); texcoordsarray.push(spherical(b)); texcoordsarray.push(spherical(c)); index += 3; } } 22

Finding Texture Coordinates 23

Position to spherical coordinates unction sphereical(a){ /* radius = sqrt(x^2 + y^2 + z^2) polar = arccos(z/radius) azimuthal = atan2(y, x) Radius = 1 */ longitude=math.atan2(a[1],a[0]); latitude=math.acos(a[3]) return vec2(longitude, latitude) } 24

Longitude and Latitude 25

Texture Mapping 26

Planet Earth-Mapping 27

Moon-Mapping 28