CS212. OpenGL Texture Mapping and Related

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

CS335 Graphics and Multimedia. Slides adopted from OpenGL Tutorial

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

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

Computer Graphics. Bing-Yu Chen National Taiwan University

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

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

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

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

Imaging and Raster Primitives

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

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

Lecture 5. Scan Conversion Textures hw2

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

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

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

Texture Mapping CSCI 4229/5229 Computer Graphics Fall 2016

Lecture 07: Buffers and Textures

Texture Mapping. Mike Bailey.

CT5510: Computer Graphics. Texture Mapping

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

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

Lecture 5 3D graphics part 3

ก ก ก.

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

Texture Mapping and Sampling

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

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

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

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

Chapter 6 Texture Mapping

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

Grafica Computazionale

Texture Mapping and Special Effects

INF3320 Computer Graphics and Discrete Geometry

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

Steiner- Wallner- Podaras

Textures. Texture Mapping. Bitmap Textures. Basic Texture Techniques

Computational Strategies

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

INF3320 Computer Graphics and Discrete Geometry

CS179: GPU Programming

Magnification and Minification

Computer Graphics Texture Mapping

Discussion 3. PPM loading Texture rendering in OpenGL

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

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

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

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

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. Texture Mapping. Map textures to surfaces. Trompe L Oeil ( Deceive the Eye ) The texture. Texture map

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

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

Lighting and Texturing

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

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

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

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

Texture and other Mappings

Introduction to OpenGL. Prof. Dr.-Ing. Lars Linsen

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

Texture mapping. Computer Graphics CSE 167 Lecture 9

9.Texture Mapping. Chapter 9. Chapter Objectives

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

Textures. Datorgrafik 2006

Shading. Flat shading Gouraud shading Phong shading

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

Computer Graphics Texture Mapping

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

Texture Mapping Part 1

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

Computer Graphics

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

Shading/Texturing. Dr. Scott Schaefer

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

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

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

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

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

lecture 16 Texture mapping Aliasing (and anti-aliasing)

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

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

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

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

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

Computergraphics Exercise 15/ Shading & Texturing

Department of Computer Sciences Graphics Spring 2013 (Lecture 19) Bump Maps

3D Rasterization II COS 426

CS 130 Final. Fall 2015

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

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

OpenGL. Jimmy Johansson Norrköping Visualization and Interaction Studio Linköping University

Introduction to Computer Graphics with WebGL

Review of Tuesday. ECS 175 Chapter 3: Object Representation

Motivation. towards more realism. + Texture Mapping Texture Mapping

LSU EE Homework 3 Solution Due: 12 October 2015

Texture Mapping 1/34

OpenGL. 1 OpenGL OpenGL 1.2 3D. (euske) 1. Client-Server Model OpenGL

Transcription:

CS212 OpenGL Texture Mapping and Related

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

Texture Mapping y z x geometry screen t image s

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

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

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

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 (use 0, more later) components: number of color components 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);

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

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

Typical Code glbegin(gl_polygon); glnormal3f(u0, v0, w0); gltexcoord2f(s0, t0); glvertex3f(x0, y0, z0); glnormal3f(u1, v1, w1); gltexcoord2f(s1, t1); glvertex3f(x1, y1, z1);.. glend();

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

Texture Parameters OpenGL uses a variety of parameters that determine how texture is applied Wrapping parameters determine what happens of s and t outside of 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

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 texture s GL_REPEAT wrapping GL_CLAMP wrapping

Magnification and Minification More than one texel can cover a pixel (minification) or more than one pixel can cover a texel (magnification) Can use point sampling (nearest texel) or linear filtering ( 2 x 2 filter) to obtain texture values Texture Magnification Polygon Texture Minification Polygon

Filter Modes 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)

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_2D, level, ) GLU mipmap builder routines will build textures of all power of 2 resolutions from a given image glubuild2dmipmaps(gl_texture_2d,3,64,64, GL_RGB,GL_UNSIGNED_BYTE,my_texels);

Mipmap Modes point sampling with best mipmap gltexparameteri(gl_texture_2d, GL_TEXURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); linear filtering with best mipmap gltexparameteri(gl_texture_2d, GL_TEXURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); point sampling with linear filtering btw maps gltexparameteri(gl_texture_2d, GL_TEXURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); both linear gltexparameteri(gl_texture_2d, GL_TEXURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

Example point sampling linear filtering mipmapped point sampling mipmapped linear filtering

Texture and Shading Controls how texture is applied with regard to shading gltexenv{fi}[v]( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, param ) GL_TEXTURE_ENV_MODE modes GL_MODULATE: modulates with computed shade GL_BLEND: blends with an environmental color GL_REPLACE: use only texture color GL(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); Set blend color with GL_TEXTURE_ENV_COLOR

Perspective Correction Hint Proper texture mapping also depends on projection linear map works fine for ortho perspective needs correction Noticeable for polygons on edge glhint( GL_PERSPECTIVE_CORRECTION_HINT, hint ) where hint is one of GL_DONT_CARE GL_NICEST GL_FASTEST

Generating Texture Coordinates GL can generate texture coordinates automatically gltexgen{ifd}[v]() specify a plane generate texture coordinates based upon distance from the plane generation modes GL_OBJECT_LINEAR GL_EYE_LINEAR GL_SPHERE_MAP (used for environmental maps)

Environment Maps Use automatic texture coordinate generation gltexgen[if](gl_s,gl_texture_gen_mode, GL_SPHERE_MAP); gltexgen[if](gl_t,gl_texture_gen_mode, GL_SPHERE_MAP); glenable(gl_texture_gen_s); glenable(gl_texture_gen_t);

Texture Objects Texture is part of the OpenGL state If we have different textures for different objects, OpenGL will be moving large amounts data from processor memory to texture memory Recent versions of OpenGL have texture objects one image per texture object Texture memory can hold multiple texture objects

Applying Textures II 1. specify textures in texture objects 2. set texture filter 3. set texture function 4. set texture wrap mode 5. set optional perspective correction hint 6. bind texture object 7. enable texturing 8. supply texture coordinates for vertex coordinates can also be generated