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

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

Magnification and Minification

The Critical-Path Algorithm

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

Minimal Spanning Trees

Rotations and Translations

Shading Triangles. Lecture 37. Robb T. Koether. Hampden-Sydney College. Mon, Nov 30, 2015

Sampling Distribution Examples Sections 15.4, 15.5

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

Scheduling and Digraphs

The Traveling Salesman Problem Brute Force Method

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 27, 2013

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 26, 2014

Density Curves Sections

The Decreasing-Time Algorithm

Solving Recursive Sequences by Iteration

while Loops Lecture 13 Sections Robb T. Koether Wed, Sep 26, 2018 Hampden-Sydney College

Stack Applications. Lecture 27 Sections Robb T. Koether. Hampden-Sydney College. Wed, Mar 29, 2017

The Graphics Pipeline

The Pairwise-Comparison Method

Total Orders. Lecture 41 Section 8.5. Robb T. Koether. Hampden-Sydney College. Mon, Apr 8, 2013

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

Boolean Expressions. Lecture 31 Sections 6.6, 6.7. Robb T. Koether. Hampden-Sydney College. Wed, Apr 8, 2015

Boxplots. Lecture 17 Section Robb T. Koether. Hampden-Sydney College. Wed, Feb 10, 2010

CT5510: Computer Graphics. Texture Mapping

Street-Routing Problems

Recursive Descent Parsers

Texture Mapping CSCI 4229/5229 Computer Graphics Fall 2016

The Projection Matrix

The Traveling Salesman Problem Nearest-Neighbor Algorithm

Abstract Data Types. Lecture 23 Section 7.1. Robb T. Koether. Hampden-Sydney College. Wed, Oct 24, 2012

Discussion 3. PPM loading Texture rendering in OpenGL

The Graphics Pipeline

Steiner- Wallner- Podaras

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

XPath Lecture 34. Robb T. Koether. Hampden-Sydney College. Wed, Apr 11, 2012

Regular Expressions. Lecture 10 Sections Robb T. Koether. Hampden-Sydney College. Wed, Sep 14, 2016

Inheritance: The Fundamental Functions

Linked Lists. Lecture 16 Sections Robb T. Koether. Hampden-Sydney College. Wed, Feb 22, 2017

Binary Tree Applications

Implementing Linked Lists

PHP Queries and HTML Forms Lecture 23

The CYK Parsing Algorithm

LR Parsing - Conflicts

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

The Normal Distribution

Scope and Parameter Passing

The Projection Matrix

Displaying Distributions - Quantitative Variables

The Plurality-with-Elimination Method

The string Class. Lecture 21 Sections 2.9, 3.9, Robb T. Koether. Wed, Oct 17, Hampden-Sydney College

The Class Construct Part 1

Recursion. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 17, 2018

The Traveling Salesman Problem Cheapest-Link Algorithm

Scope and Parameter Passing

Building the Abstract Syntax Trees

Specular Reflection. Lecture 19. Robb T. Koether. Hampden-Sydney College. Wed, Oct 4, 2017

XML Attributes. Lecture 33. Robb T. Koether. Hampden-Sydney College. Wed, Apr 25, 2018

Triggers. Lecture 14. Robb T. Koether. Hampden-Sydney College. Wed, Feb 14, 2018

Pointers. Lecture 1 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 14, 2015

Shader Programs. Lecture 30 Subsections 2.8.2, Robb T. Koether. Hampden-Sydney College. Wed, Nov 16, 2011

XPath. Lecture 36. Robb T. Koether. Wed, Apr 16, Hampden-Sydney College. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, / 28

The Coefficient of Determination

CS212. OpenGL Texture Mapping and Related

Introduction to Compiler Design

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

Nondeterministic Programming in C++

Pointer Arithmetic. Lecture 4 Chapter 10. Robb T. Koether. Hampden-Sydney College. Wed, Jan 25, 2017

Function Definition Syntax Tree

Aggregation. Lecture 7 Section Robb T. Koether. Hampden-Sydney College. Wed, Jan 29, 2014

Recursive Linked Lists

Operators. Lecture 12 Section Robb T. Koether. Hampden-Sydney College. Fri, Feb 9, 2018

Ambient and Diffuse Light

Insertions, Deletions, and Updates

Recognition of Tokens

Texture mapping. Computer Graphics CSE 167 Lecture 9

Friends and Unary Operators

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

The Constructors. Lecture 7 Sections Robb T. Koether. Hampden-Sydney College. Wed, Feb 1, 2017

Webpage Navigation. Lecture 27. Robb T. Koether. Hampden-Sydney College. Mon, Apr 2, 2018

Basic CSS Lecture 17

Form Validation. Lecture 25. Robb T. Koether. Hampden-Sydney College. Wed, Mar 23, 2018

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

Function Usage. Lecture 15 Sections 6.3, 6.4. Robb T. Koether. Hampden-Sydney College. Mon, Oct 1, 2018

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

Texture and other Mappings

Stack Applications. Lecture 25 Sections Robb T. Koether. Hampden-Sydney College. Mon, Mar 30, 2015

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

Computer Graphics. Lecture 8 Antialiasing, Texture Mapping

Introduction to Databases

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

CS 432 Interactive Computer Graphics

Pointers. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Fri, Jan 18, 2013

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

The Model Stack. Lecture 8. Robb T. Koether. Hampden-Sydney College. Wed, Sep 6, 2017

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

XQuery FLOWR Expressions Lecture 35

DTDs and XML Attributes

List Iterators. Lecture 27 Section Robb T. Koether. Hampden-Sydney College. Wed, Apr 8, 2015

Transcription:

Mipmaps Lecture 35 Robb T. Koether Hampden-Sydney College Wed, Nov 18, 2015 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 1 / 31

Outline 1 Discrete Sampling 2 Mipmaps 3 Generating Mipmaps 4 Programming Mipmaps 5 Interpolating between Mipmaps 6 Assignment 20 7 Assignment 21 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 2 / 31

Discrete Sampling Suppose we are drawing a 2-dimensional black-and-white checkerboard pattern. Suppose that the surface is close enough to the camera and oriented just right that each texel matches exactly one pixel. Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 3 / 31

Discrete Sampling Consider one row of pixels and texels, where the pixels and texels are the same size. Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 4 / 31

Discrete Sampling Using the nearest texel, the pixels will be colored alternately black and white. Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 4 / 31

Discrete Sampling Using the nearest texel, the pixels will be colored alternately black and white. Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 4 / 31

Discrete Sampling What if the texels were somewhat smaller than the pixels? Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 5 / 31

Discrete Sampling What if the texels were somewhat smaller than the pixels? Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 5 / 31

Discrete Sampling What if the texels were somewhat smaller than the pixels? Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 5 / 31

Discrete Sampling What if the texels are almost half the size of the pixels? Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 6 / 31

Discrete Sampling What if the texels are almost half the size of the pixels? Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 6 / 31

Discrete Sampling Uh oh. Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 6 / 31

Discrete Sampling What will happen when the texels are exactly half the width of a pixel? Exactly one fourth? Exactly one third? Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 7 / 31

Outline 1 Discrete Sampling 2 Mipmaps 3 Generating Mipmaps 4 Programming Mipmaps 5 Interpolating between Mipmaps 6 Assignment 20 7 Assignment 21 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 8 / 31

Mipmaps Definition (Mipmap) A mipmap is a reduced copy of a texture, with the colors averaged. mip = multum in parvo = many things in a small place. Rather than use the nearest texels or the average of the four texels that happen to be nearest to the pixel, we can create smaller and smaller copies of the entire texture and use their texels. Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 9 / 31

Mipmaps If the original texture is 64 64, then we should create copies at the scales of 32 32, 16 16, 8 8, 4 4, 2 2, and 1 1. If the original texture is 64 16, then we should create copies at the scales of 32 8, 16 4, 8 2, 4 1, 2 1, and 1 1. Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 10 / 31

Mipmap Levels The original texture is level 0. The next level is level 1. And so on. Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 11 / 31

Mipmaps One texel Level 0 Mipmap - 64 64 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 12 / 31

Mipmaps One texel Level 1 Mipmap - 32 32 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 12 / 31

Mipmaps One texel Level 2 Mipmap - 16 16 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 12 / 31

Mipmaps One texel Level 3 Mipmap - 8 8 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 12 / 31

Mipmaps One texel Level 4 Mipmap - 4 4 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 12 / 31

Mipmaps One texel Level 5 Mipmap - 2 2 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 12 / 31

Mipmaps One texel Level 6 Mipmap - 1 1 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 12 / 31

Mipmaps One texel Level 0 Mipmap - 64 64 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 12 / 31

Mipmaps One texel Level 0 Mipmap - 64 64 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 12 / 31

Mipmaps One texel Level 1 Mipmap - 32 32 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 12 / 31

Mipmaps One texel Level 2 Mipmap - 16 15 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 12 / 31

Mipmaps One texel Level 3 Mipmap - 8 8 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 12 / 31

Mipmaps One texel Level 4 Mipmap - 4 4 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 12 / 31

Mipmaps One texel Level 5 Mipmap - 2 2 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 12 / 31

Mipmaps One texel Level 6 Mipmap - 1 1 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 12 / 31

Outline 1 Discrete Sampling 2 Mipmaps 3 Generating Mipmaps 4 Programming Mipmaps 5 Interpolating between Mipmaps 6 Assignment 20 7 Assignment 21 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 13 / 31

Generating Mipmaps If we hand-code a texture, then we also hand-code the mipmaps. (See demo.) The website http://online-converting.com/image/convert2dds/ includes an option to create mipmaps in the.dds file. Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 14 / 31

Outline 1 Discrete Sampling 2 Mipmaps 3 Generating Mipmaps 4 Programming Mipmaps 5 Interpolating between Mipmaps 6 Assignment 20 7 Assignment 21 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 15 / 31

Programming Mipmaps Mipmaps are implemented using the same function glteximage2d() that we used to set the original texture. The second parameter is the level. Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 16 / 31

Screen Shots Close-up of Level 0 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 17 / 31

Screen Shots Close-up of Level 1 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 17 / 31

Screen Shots Close-up of Level 2 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 17 / 31

Screen Shots Close-up of Level 3 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 17 / 31

Screen Shots Close-up of Levels 4, 5, and 6 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 17 / 31

Using Mipmaps When using mipmaps, we have two separate choices. Whether to use the nearest texel in a mipmap or to interpolate among the 4 nearest texels. Whether to use the nearest mipmap or to interpolate between the two nearest mipmaps. Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 18 / 31

Using Mipmaps Thus, the combinations of choices are Nearest texel and nearest mipmap Nearest texel and interpolate mipmaps Interpolate texels and nearest mipmap Interpolate texels and interpolate mipmaps Which is the most expensive? Which gives the best results? Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 19 / 31

Outline 1 Discrete Sampling 2 Mipmaps 3 Generating Mipmaps 4 Programming Mipmaps 5 Interpolating between Mipmaps 6 Assignment 20 7 Assignment 21 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 20 / 31

Interpolating Between Mipmaps Assume that a single color has been selected from each of the two nearest mipmaps (from either the nearest texel or an average of texels). Compute the scale factor r between the level 0 (original) mipmap and the polygon. Then compute λ = log 2 r. Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 21 / 31

Interpolating Between Mipmaps The value of λ tells us which mipmap to use. If λ = 0, use level 0. If λ = 1, use level 1. If λ = 2, use level 2, etc. What if λ = 1.5? Then we interpolate between level 1 and level 2. Different scale factors may be used for different regions of a single polygon. Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 22 / 31

Example Suppose λ = 1.3 and the level 1 mipmap color is yellow (1, 1, 0) and the level 2 mipmap color is cyan (0, 1, 1). Then the interpolated color is 0.7(1, 1, 0) + 0.3(0, 1, 1) = (0.7, 1.0, 0.3). Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 23 / 31

Interpolating Mipmaps Interpolating Mipmaps gltexparameteri(gl_texture_2d, GL_TEXTURE_MIN_FILTER, method); Use the gltexparameter*() function to set the method of applying mipmap filters. The third parameter is one of GL_NEAREST_MIPMAP_NEAREST GL_NEAREST_MIPMAP_LINEAR GL_LINEAR_MIPMAP_NEAREST GL_LINEAR_MIPMAP_LINEAR Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 24 / 31

Trilinear Interpolation If we interpolate bilinearly within mipmaps and then interpolate those values between mipmaps, we get trilinear interpolation. Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 25 / 31

Trilinear Interpolation How many individual interpolations are required? Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 26 / 31

Trilinear Interpolation 0.20 0.80 0.20 0.80 Four in the s direction. Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 26 / 31

Trilinear Interpolation 0.20 0.80 0.20 0.80 Four in the s direction. Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 26 / 31

Trilinear Interpolation 0.60 0.40 0.60 0.40 Two more in the t direction. Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 26 / 31

Trilinear Interpolation 0.60 0.40 0.60 0.40 Two more in the t direction. Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 26 / 31

Trilinear Interpolation 0.40 0.60 One more between the mipmap levels. Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 26 / 31

Trilinear Interpolation 0.40 0.60 One more between the mipmap levels. Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 26 / 31

Trilinear Interpolation A total of 7 interpolations are required. Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 27 / 31

Outline 1 Discrete Sampling 2 Mipmaps 3 Generating Mipmaps 4 Programming Mipmaps 5 Interpolating between Mipmaps 6 Assignment 20 7 Assignment 21 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 28 / 31

Assignment 20 Assignment 20 Add a water texture to the water. Add textures to the boat and its cabin. Turn in by Monday, November 30. Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 29 / 31

Outline 1 Discrete Sampling 2 Mipmaps 3 Generating Mipmaps 4 Programming Mipmaps 5 Interpolating between Mipmaps 6 Assignment 20 7 Assignment 21 Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 30 / 31

Assignment 21 Assignment 21 Add grass. (See handout.) Robb T. Koether (Hampden-Sydney College) Mipmaps Wed, Nov 18, 2015 31 / 31