cs 380 - gpu and gpgpu programming lecture 12: gpu texturing 2

20
CS 380 - GPU and GPGPU Programming Lecture 12: GPU Texturing 2 Markus Hadwiger, KAUST

Upload: others

Post on 04-Nov-2021

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 380 - GPU and GPGPU Programming Lecture 12: GPU Texturing 2

CS 380 - GPU and GPGPU ProgrammingLecture 12: GPU Texturing 2

Markus Hadwiger, KAUST

Page 2: CS 380 - GPU and GPGPU Programming Lecture 12: GPU Texturing 2

2

Reading Assignment #7 (until Mar. 16)

Read (required):

• Interpolation for Polygon Texture Mapping and Shading,Paul Heckbert and Henry Moreton

http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.48.7886

• MIP-Map Level Selection for Texture Mappinghttp://ieeexplore.ieee.org/xpl/login.jsp?tp=&arnumber=765326

Read (optional):• Frame buffer objects extension specification

http://www.opengl.org/registry/specs/ARB/framebuffer_object.txt

Page 3: CS 380 - GPU and GPGPU Programming Lecture 12: GPU Texturing 2

3

Magnification (Bilinear Filtering Example)

Original image

Nearest neighbor Bilinear filteringVienna University of Technology

Page 4: CS 380 - GPU and GPGPU Programming Lecture 12: GPU Texturing 2

4

Texture Reconstruction: Magnification

Bilinear reconstruction for texture magnification (D<0)("upsampling")

Weight adjacent texels by distance to pixel position

Texture space u

-v

X

T(u+du,v+dv) = du·dv·T(u+1,v+1)+ du·(1–dv)·T(u+1,v)+ (1-du)·dv·T(u,v+1)+ (1-du)·(1-dv)·T(u,v)

du

dv(u,v) (u+1,v)

(u+1,v+1)(u,v+1)

Vienna University of Technology

Page 5: CS 380 - GPU and GPGPU Programming Lecture 12: GPU Texturing 2

5

Texture Aliasing: Minification

Problem: One pixel in image space covers many texels

Vienna University of Technology

Page 6: CS 380 - GPU and GPGPU Programming Lecture 12: GPU Texturing 2

6

Texture Aliasing: Minification

Caused by undersampling: texture information is lost

Texture space

Image spaceVienna University of Technology

Page 7: CS 380 - GPU and GPGPU Programming Lecture 12: GPU Texturing 2

7

Texture Anti-Aliasing: Minification

A good pixel value is the weighted mean of the pixel area projected into texture space

Texture space u

v

Image space

Pixel

XX

Vienna University of Technology

Page 8: CS 380 - GPU and GPGPU Programming Lecture 12: GPU Texturing 2

8

Texture Anti-Aliasing: MIP Mapping

MIP Mapping (“Multum In Parvo”)Texture size is reduced by factors of 2(downsampling = "many things in a small place")Simple (4 pixel average) and memory efficientLast image is only ONE texel

Vienna University of TechnologyTotal size = 4/3

Page 9: CS 380 - GPU and GPGPU Programming Lecture 12: GPU Texturing 2

Eduard Gröller, Stefan Jeschke 9

Texture Anti-Aliasing: MIP Mapping

MIP Mapping AlgorithmD := ld(max(d1,d2))T0 := value from texture D0= trunc (D)

Use bilinear interpolation

d1

d2

Bilinear interpolation Trilinear interpolation

X

"Mip Map level"

Page 10: CS 380 - GPU and GPGPU Programming Lecture 12: GPU Texturing 2

MIP-Map Level Computation

Markus Hadwiger, KAUST 10

• Use the partial derivatives of texture coordinates with respect to screen space coordinates

• This is the Jacobian matrix

• Area of parallelogram is theabsolute value of the Jacobian determinant (the Jacobian)

=

Page 11: CS 380 - GPU and GPGPU Programming Lecture 12: GPU Texturing 2

MIP-Map Level Computation (OpenGL)

Markus Hadwiger, KAUST 11

• OpenGL 4.5 core specification, pp. 241-243

• Does not use area of parallelogram but greater hypotenuse [Heckbert, 1983]

• Approximation without square-roots

Page 12: CS 380 - GPU and GPGPU Programming Lecture 12: GPU Texturing 2

MIP-Map Level Interpolation

Markus Hadwiger, KAUST 12

• Level of detail value is fractional!

• Use fractional part to blend (lin.) between two adjacent mipmap levels

Page 13: CS 380 - GPU and GPGPU Programming Lecture 12: GPU Texturing 2

13

Texture Anti-Aliasing: MIP Mapping

Trilinear interpolation:T1 := value from texture D1 = D0+1 (bilin.interpolation)Pixel value := (D1–D)·T0 + (D–D0)·T1

Linear interpolation between successive MIP MapsAvoids "Mip banding" (but doubles texture lookups)

Vienna University of Technology

Page 14: CS 380 - GPU and GPGPU Programming Lecture 12: GPU Texturing 2

14

Texture Anti-Aliasing: MIP Mapping

Other example for bilinear vs. trilinear filtering

Vienna University of Technology

Page 15: CS 380 - GPU and GPGPU Programming Lecture 12: GPU Texturing 2

15

Anti-Aliasing: Anisotropic Filtering

Anisotropic filteringView-dependent filter kernelImplementation: summed area table, "RIP Mapping", footprint assembly, elliptical weighted average (EWA)

Texture space

Vienna University of Technology

Page 16: CS 380 - GPU and GPGPU Programming Lecture 12: GPU Texturing 2

Anisotropic Filtering: Footprint Assembly

Markus Hadwiger, KAUST 16

Page 17: CS 380 - GPU and GPGPU Programming Lecture 12: GPU Texturing 2

17

Anti-Aliasing: Anisotropic Filtering

Example

Vienna University of Technology

Page 18: CS 380 - GPU and GPGPU Programming Lecture 12: GPU Texturing 2

Vienna University of Technology 18

Texture Anti-aliasing

Basically, everything done in hardwaregluBuild2DMipmaps()generates MIPmapsSet parameters in glTexParameter()

GL_TEXTURE_MAG_FILTER: GL_NEAREST, GL_LINEAR, …GL_TEXTURE_MIN_FILTER: GL_LINEAR_MIPMAP_NEAREST

Anisotropic filtering is an extension:GL_EXT_texture_filter_anisotropic

Number of samples can be varied (4x,8x,16x)Vendor specific support and extensions

Page 19: CS 380 - GPU and GPGPU Programming Lecture 12: GPU Texturing 2

Vienna University of Technology 19

Texture Coordinates

Specified manually (glMultiTexCoord())Using classical OpenGL texture coordinate generation

Linear: from object or eye space vertex coordsSpecial texturing modes (env-maps)Can be further modified with texture matrix

E.g., to add texture animationCan use 3rd or 4th texture coordinate for projective texturing!

Shader allows complex texture lookups!

Page 20: CS 380 - GPU and GPGPU Programming Lecture 12: GPU Texturing 2

Thank you.