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

Similar documents
Sampling, Aliasing, & Mipmaps

Sampling, Aliasing, & Mipmaps

Theoretically Perfect Sensor

Theoretically Perfect Sensor

Sampling, Aliasing, & Mipmaps

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

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

Point-Based Rendering

Aliasing and Antialiasing. ITCS 4120/ Aliasing and Antialiasing

Reading. 18. Projections and Z-buffers. Required: Watt, Section , 6.3, 6.6 (esp. intro and subsections 1, 4, and 8 10), Further reading:

The main goal of Computer Graphics is to generate 2D images 2D images are continuous 2D functions (or signals)

Computer Graphics. Lecture 8 Antialiasing, Texture Mapping

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

3D Rasterization II COS 426

Motivation. The main goal of Computer Graphics is to generate 2D images. 2D images are continuous 2D functions (or signals)

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

Outline. Foundations of Computer Graphics (Spring 2012)

Outline. Sampling and Reconstruction. Sampling and Reconstruction. Foundations of Computer Graphics (Fall 2012)

To Do. Advanced Computer Graphics. Sampling and Reconstruction. Outline. Sign up for Piazza

Basics. Sampling and Reconstruction. Sampling and Reconstruction. Outline. (Spatial) Aliasing. Advanced Computer Graphics (Fall 2010)

Image Filtering, Warping and Sampling

Computer Graphics. Sampling Theory & Anti-Aliasing. Philipp Slusallek

Central Slice Theorem

Advanced Computer Graphics. Aliasing. Matthias Teschner. Computer Science Department University of Freiburg

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Image warping introduction

Direct Rendering. Direct Rendering Goals

Lecture 2: 2D Fourier transforms and applications

Perspective Projection and Texture Mapping

Image Warping and Morphing

Aliasing. Can t draw smooth lines on discrete raster device get staircased lines ( jaggies ):

CSL 859: Advanced Computer Graphics. Dept of Computer Sc. & Engg. IIT Delhi

DIGITAL IMAGE WARPING. abstract of Digital Image Warping. George Wolberg, IEEE Computer Society Press

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

Sampling and Reconstruction

Computer Graphics. - Texturing Methods -

Sampling II, Anti-aliasing, Texture Filtering

The simplest and most obvious method to go from a continuous to a discrete image is by point sampling,

Texture-Mapping Tricks. How Bad Does it Look? We've Seen this Sort of Thing Before. Sampling Texture Maps

Computer Vision 2. SS 18 Dr. Benjamin Guthier Professur für Bildverarbeitung. Computer Vision 2 Dr. Benjamin Guthier

Forward Image Warping

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

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

CS 431/636 Advanced Rendering Techniques

Forward Image Mapping

Image Processing, Warping, and Sampling

Reading. 2. Fourier analysis and sampling theory. Required: Watt, Section 14.1 Recommended:

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

INF3320 Computer Graphics and Discrete Geometry

Computer Graphics. - Rasterization - Philipp Slusallek

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

CS 130 Final. Fall 2015

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

Chapter 18. Geometric Operations

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

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

Drawing a Triangle (and an introduction to sampling)

Introduction to Computer Vision. Week 3, Fall 2010 Instructor: Prof. Ko Nishino

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

Point based Rendering

Point Sample Rendering

Drawing a Triangle (and an Intro to Sampling)

Overview. Spectral Processing of Point- Sampled Geometry. Introduction. Introduction. Fourier Transform. Fourier Transform

Recollection. Models Pixels. Model transformation Viewport transformation Clipping Rasterization Texturing + Lights & shadows

First Order Approximation for Texture Filtering

Lecture 6 Basic Signal Processing

EECS 556 Image Processing W 09. Interpolation. Interpolation techniques B splines

Scaled representations

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

Splatting (feed-forward) Fill the holes. Process for volume rendering. Footprint Evaluation for Volume Rendering. Feed Backward vs.

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

Sampling and Reconstruction

Image Acquisition + Histograms

Real-Time Graphics Architecture. Kurt Akeley Pat Hanrahan. Texture

To Do. Advanced Computer Graphics. Discrete Convolution. Outline. Outline. Implementing Discrete Convolution

Texture mapping. Computer Graphics CSE 167 Lecture 9

CS354 Computer Graphics Sampling and Aliasing

Computer Vision and Graphics (ee2031) Digital Image Processing I

EE795: Computer Vision and Intelligent Systems

3. Image formation, Fourier analysis and CTF theory. Paula da Fonseca

Footprint Area Sampled Texturing

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

Spatial Enhancement Definition

Texture Mapping and Sampling

Non-Linearly Quantized Moment Shadow Maps

TEXTURE MAPPING. DVA338 Computer Graphics Thomas Larsson, Afshin Ameri

Texture Mapping 1/34

Broad field that includes low-level operations as well as complex high-level algorithms

Computational Photography

Computational Aspects of MRI

Computer Graphics 7 - Texture mapping, bump mapping and antialiasing

KAISER FILTER FOR ANTIALIASING IN DIGITAL PHOTOGRAMMETRY

Soft shadows. Steve Marschner Cornell University CS 569 Spring 2008, 21 February

Anti-aliasing and sampling

Aliasing And Anti-Aliasing Sampling and Reconstruction

INF3320 Computer Graphics and Discrete Geometry

Outline. Visualization Discretization Sampling Quantization Representation Continuous Discrete. Noise

CS 354R: Computer Game Technology

Announcements. Mosaics. How to do it? Image Mosaics

Mosaics. Today s Readings

Transcription:

Computer Graphics Texture Filtering & Sampling Theory Hendrik Lensch

Overview Last time Texture Parameterization Procedural Shading Today Texturing Filtering

2D Texture Mapping Forward mapping Object surface parameterization Projective transformation Inverse mapping Find corresponding pre-image/footprint of each pixel in texture Integrate over pre-image

Forward Mapping Maps each texel to its position in the image Uniform sampling of texture space does not guarantee uniform sampling in screen space Possibly used if The texture-to-screen mapping is difficult to invert The texture image does not fit into memory Texture scanning: for v for u compute x(u,v) and y(u,v) copy TEX[u,v] to SCR[x,y] (or in general rasterize image of TEX[u,v])

Inverse Mapping Requires inverting the mapping transformation Preferable when the mapping is readily invertible and the texture image fits into memory The most common mapping method for each pixel in screen space, the pre-image of the pixel in texture space is found and its area is integrated over Screen scanning: for y for x compute u(x,y) and v(x,y) copy TEX[u,v] to SCR[x,y] (or in general integrate over image of SCR[u,v])

Pixel Pre-Image in Texture Space A square screen pixel that intersects a curved surface has a curvilinear quadrilateral pre-image in texture space. Most methods approximate the true mapping by a quadrilateral or parallelogram. Or they take multiple samples within a pixel. If pixels are instead regarded as circles, their pre-images are ellipses.

Inverse Mapping: Filtering Integration of Pre-image Integration over pixel footprint in texture space Aliasing Texture insufficiently sampled Incorrect pixel values Randomly changing pixels when moving

Filtering Magnification Map few texels onto many pixels Nearest: Take the nearest texel Bilinear interpolation: Interpolation between 4 nearest texels Need fractional accuracy of coordinates Minification Map many texels to one pixel Aliasing: Reconstructing high-frequency signals with low level frequency sampling Filtering Averaging over (many) associated texels Computationally expensive Texture Pixel Pixel Texture

Filtering Texture Minification Space-variant filtering Mapping from texture space (u,v) to screen space (x,y) not affine Filtering changes with position Space variant filtering methods Direct convolution Numerically compute the Integral Pre-filtering Precompute the integral for certain regions -- more efficient Approximate footprint with regions

Direct Convolution Convolution in texture space Texels weighted according to distance from pixel center (e.g. pyramidal filter kernel) Convolution in image space 1 Center the filter function on the pixel (in image space) and find its bounding rectangle. 2 Transform the rectangle to the texture space, where it is a quadrilateral. The sides of this rectangle are assumed to be straight. Find a bounding rectangle for this quadrilateral. 3 Map all pixels inside the texture space rectangle to screen space. 4 Form a weighted average of the mapped texture pixels using a twodimensional lookup table indexed by each sample s location within the pixel.

EWA Filtering Compensate aliasing artifacts due to perspective projection EWA Filter = low-pass filter warped reconstruction filter Projection Low-Pass Filter W x k Convolution r 1 Texture EWA texture resampling filter ρk r 0

EWA Filtering Four step algorithm 1) calculate the ellipse 2) choose filter 3) scan conversion in the ellipse 4) determine the color for the pixel.

Without Anti-aliasing checker board gets distorted

EWA Filtering elliptical filtering plus Gaussian

EWA Filtering Gaussian blur selected too large -> blurry image

EWA Splatting Reconstruction filter only: 6.25 fps EWA filter: 4.97 fps Low-pass filter only: 6.14 fps EWA filter: 3.79 fps

Analysis of EWA Filter Warped reconstruction kernel Low-pass filter Resampling filter Minification Magnification

Analysis of EWA Filter Shape of EWA Splat is dependent on distance from the view plane x r 1 r ( 2 2 1+ x + x ) 2 2 k 2 k 0 1 r 0 = + r 2 h r1 = + 2 u2 u2 r r h r 0 EWA splat r h r k u 2 Note that Low-pass filter radius Reconstruction filter radius Distance to the view plane ( 1. 0, 1. Cons tant) 2 2 1+ x + x 0 + 0 1

Adaptive EWA Filtering Warped reconstruction kernel Low-pass filter Resampling filter if u 2 > A use low-pass filter if A<u 2 < B use EWA filter if u 2 < B use reconstruction filter

Anisotropic Filtering Footprint Assembly on GPUs Integration Across Footprint of Pixel HW: Choose samples that best approximate footprint Weighted average of samples C`t Magazine

Texture Filtering in Hardware G70 G80 Source: Anandtech, 2006

Filtering Texture Minification Direct convolution methods are slow A pixel pre-image can be arbitrarily large along silhouettes or at the horizon of a textured plane Horizon pixels can require averaging over thousands of texture pixels Texture filtering cost grows in proportion to projected texture area Speed up The texture can be prefiltered so that during rendering only a few samples will be accessed for each screen pixel Two data structures are commonly used for prefiltering: Integrated arrays (summed area tables) Image pyramids (mipmaps) Space-variant filtering

Summed Area Tables Per texel, store sum from (0, 0) to (u, v) A B D C D Many bits per texel (sum!) Evaluation of 2D integrals in constant time! Ax Ay I ( x, y) dxdy = A B C + BxCy B A D D C

Integrated Arrays Footprint assembly Good for space variant filtering e.g. inclined view of terrain Approximation of the pixel area by rectangular texel-regions The more footprints the better accuracy Often fixed number of texels because of economical reasons

MipMapping Texture available in multiple resolutions Pre-processing step Rendering: select appropriate texture resolution Selection is usually per pixel!! Texel size(n) < extent of pixel footprint < texel size(n+1)

MipMapping II Multum In Parvo (MIP): much in little Hierarchical resolution pyramid Repeated averaging over 2x2 texels Rectangular arrangement (RGB) Reconstruction Tri-linear interpolation of 8 nearest texels u d v d v u

MipMap Example

MipMaps Why is MipMapping sometimes faster? Bottleneck is memory bandwidth Using of texture caches Texture minification required for far geometry No MipMap Random access to texture Always 4 new texels MipMap Next pixel at about one texel distance (1:1 mapping) Access to 8 texels at a time, but Most texels are still in the cache

Aliasing

The Digital Dilemma Nature: continuous signal (2D/3D/4D with time) Defined at every point Acquisition: sampling Rays, pixel/texel, spectral values, frames,... Representation: discrete data Discrete points, discretized values not Reconstruction: filtering Mimic continuous signal Display and perception: faithful Hopefully similar to the original signal, no artifacts

Sensors Sampling of signals Conversion of a continuous signal to discrete samples by integrating over the sensor field Required by physical processes R ( i, j) = E( x, y) P ( x, y) dx ij dy A ij Examples Photo receptors in the retina CCD or CMOS cells in a digital camera Virtual cameras in computer graphics Integration is too expensive and usually avoided Ray tracing: mathematically ideal point samples Origin of aliasing artifacts!

Aliasing Ray tracing Textured plane with one ray for each pixel (say, at pixel center) No texture filtering: equivalent to modeling with b/w tiles Checkerboard period becomes smaller than two pixels At the Nyquist limit Hits textured plane at only one point, black or white by chance

Spatial Frequency Frequency: period length of some structure in an image Unit [1/pixel] Range: -0.5 0.5 (-π π) Lowest frequency Image average Highest frequency: Nyquist limit In nature: defined by wavelength of light In graphics: defined by image resolution...

Nyquist Frequency Highest (spatial) frequency that can be represented Determined by image resolution (pixel size) Spatial frequency < Nyquist Spatial frequency = Nyquist 2 samples / period Spatial frequency > Nyquist Spatial frequency >> Nyquist

Fourier Transformation Any continuous function f(x) can be expressed as an integral over sine and cosine waves: F f ( k) = F [ f ( x) ]( k) = f ( x) 1 2πikx ( x) = F [ F( k) ]( x) = F( k) e dk x x Division into even and odd parts f 1 2 Transform of each part e 2πikx dx [ f ( x) ]( k) = E( x) cos( 2πkx) dx i O( x) sin( πkx)dx F 2 1 2 Analysis Synthesis ( x) = [ f ( x) + f ( x) ] + [ f ( x) f ( x) ] = E( x) +O( x)

Fourier Transformation Any periodic, continuous function can be expressed as the sum of an (infinite) number of sine or cosine waves: f(x)=σ k a k sin(2π*k*x) + b k cos(2π*k*x) Decomposition of signal into different frequency bands Spectral analysis k: frequency band k=0 mean value k=1 function period, lowest possible frequency k=1.5? not possible, periodic function f(x) = f(x+1) k max? band limit, no higher frequency present in signal a k,b k : (real-valued) Fourier coefficients Even function f(x)= f(-x): a k = 0 Odd function f(x)= -f(-x): b k = 0

Fourier Synthesis Example Periodic, uneven function: square wave f(x) = 0.5 0 < (x mod 2π) < π = -0.5 π< (x mod 2π) < 2π a 0 = 0 a 1 = 1 a 2 = 0 a 3 = 1/3 a 4 = 0 a 5 = 1/5 a 6 = 0 a 7 = 1/7 a 8 = 0 a 9 = 1/9 a k = sin(k*x)* f(x) dx f(x)=σ k a k sin(k*x)

Discrete Fourier Transform Equally-spaced function samples Function values known only at discrete points Physical measurements Pixel positions in an image! Fourier Analysis a k = 1/ N i sin(2π k i / N) f i, b k = 1/ N i cos(2π k i / N) f i Sum over all measurement points N k=0,1,2,,? Highest possible frequency? Nyquist frequency Sampling rate N i 2 samples / period 0.5 cycles per pixel k N/ 2

Spatial vs. Frequency Domain Examples (pixel vs cycles per pixel) Sine wave with positive offset Square wave Scanline of an image

2D Fourier Transform 2 separate 1D Fourier transformations along x- and y-direction Discontinuities: orthogonal direction in Fourier domain!

2D Fourier Transforms

Spatial vs. Frequency Domain Important basis functions Box sinc sin( xπ ) sinc( x) = xπ sinc(0) = 1 sinc( x) dx = 1 Wide box small sinc Negative values Infinite support Triangle sinc 2 Gauss Gauss

Spatial vs. Frequency Domain Transform behavior Example: box function Fourier transform: sinc Wide box: narrow sinc Narrow box: wide sinc

Convolution f(x) g(x) = - f( τ )g(x -τ )dτ Two functions f, g Shift one function against the other by x Multiply function values Integrate overlapping region Numerical convolution: Expensive operation For each x: integrate over non-zero domain

Convolution Examples Box functions Gauss functions

Convolution and Filtering Technical Realization In image domain Pixel mask with weights OpenGL: Convolution extension Problems (e.g. sinc) Large filter support Large mask A lot of computation Negative weights Negative light?

Convolution Theorem Convolution in image domain: multiplication in Fourier domain Convolution in Fourier domain: multiplication in image domain Multiplication much cheaper than convolution!. =

Filtering Low-pass filtering Convolution with sinc in spatial domain, or Multiplication with box in frequency domain High-pass filtering Only high frequencies Band-pass filtering Only intermediate frequencies Low-pass filtering in frequency domain: multiplication with box

Low-Pass Filtering Blurring

High-Pass Filtering Enhances discontinuities in image Useful for edge detection