08 texture antialiasing
play

08 Texture Antialiasing Steve Marschner CS5625 Spring 2016 Overview - PowerPoint PPT Presentation

08 Texture Antialiasing Steve Marschner CS5625 Spring 2016 Overview Basic sampling problem Texture mapping defines a signal in image space That signal needs to be filtered: convolved with a filter Approximating this drives all the


  1. 08 Texture Antialiasing Steve Marschner CS5625 Spring 2016

  2. Overview Basic sampling problem • Texture mapping defines a signal in image space • That signal needs to be filtered: convolved with a filter • Approximating this drives all the basic algorithms Antialiasing nonlinear shading • Basic sampling su ffi ces only if pixel and texture are linearly related • Normal mapping is the most important nonlinearity

  3. Texture mapping from 0 to infinity When you go close…

  4. Texture mapping from 0 to infinity When you go far…

  5. Solution: pixel filtering Problem: Perspective produces very high image frequencies Solution • Would like to render textures with one (few) samples/pixel • Need to filter first!

  6. Solution: pixel filtering point sampling area averaging

  7. Pixel filtering in texture space Sampling is happening in image space • therefore the sampling filter is defined in image space • sample is a weighted average over a pixel-sized area • uniform, predictable, friendly problem! Signal is defined in texture space • mapping between image and texture is nonuniform • each sample is a weighted average over a di ff erent sized and shaped area • irregular, unpredictable, unfriendly! This is a change of variable • integrate over texture coordinates rather than image coordinates

  8. Pixel footprints image space texture space

  9. How does area map over distance? At optimal viewing distance: • One-to-one mapping between pixel area and texel area When closer • Each pixel is a small part of the texel • magnification When farther • Each pixel could include many texels • “minification” upsampling downsampling magnification minification

  10. How to get a handle on pixel footprint We have a nonlinear mapping to deal with R 2 : u 7! x ( u ) R 2 ! I • image position as a function of texture coordinates: I • but that is too hard Instead use a local linear approximation • hinges on the derivative of u = (u,v) wrt. x = (x,y) u ( x + ∆ x ) ≈ u ( x ) + ∂ u ∂ x ∆ x " ∂ u ∂ u # ∂ u Matrix derivative, 
 ∂ x ∂ y ∂ x = or Jacobian ∂ v ∂ v ∂ x ∂ y

  11. Sizing up the situation with the Jacobian image space texture space � ∂ u � ∂ y , ∂ v � ∂ u � ∂ x , ∂ v ∂ y ∂ x ( 0 , 1 ) ( 1 , 0 ) y v x ψ ( x ) x u

  12. How to tell minification from magnification Di ff erence is the size of the derivative • but what is “size”? � � ∂ u • area: determinant of Jacobian: � � � � ∂ x � � • max-stretch: 2-norm of Jacobian (requires a singular-value computation) • Frobenius norm of matrix (RMS of 4 entries, easy to compute) • max dimension of bounding box of quadrilateral footprint: max-abs of 4 entries (conservative) Take your pick; magnification is when size is more than about 1

  13. Solutions for Minification For magnification, use a good image interpolation method • bilinear (usual) or bicubic filter (fancier, smoother) are good picks • nearest neighbor (box filter) will give you Minecraft-style blockies For minification, use a good sampling filter to average • box (simple, though not usually easier) • gaussian (good choice) Challenge is to approximate the integral e ffi ciently! • mipmaps • multi-sample anisotropic filtering (based on mipmap)

  14. Mipmap image pyramid MIP Maps • Multum in Parvo: Much in little, many in small places • Proposed by Lance Williams Stores pre-filtered versions 
 of texture Supports very fast lookup • but only of circular filters 
 at certain scales [Akenine-Möller & Haines 2002]

  15. Filtering by Averaging Each pixel in a level corresponds to 4 pixels in lower level • Average • Gaussian filtering

  16. Using the MIP Map Find the MIP Map level where the pixel has a 1-to-1 mapping How? • Find largest side of pixel footprint in texture space • Pick level where that side corresponds to a texel • Compute derivatives to find pixel footprint • x derivative: • y derivative:

  17. Given derivatives: what is level? Derivatives • Available in pixel shader (except where there is dynamic branching)

  18. Using the MIP Map In level, find texel and • Return the texture value: point sampling (but still better)! • Bilinear interpolation • Trilinear interpolation Level i+1 Level i

  19. Memory Usage What happens to size of texture?

  20. MIPMAP Multi-resolution image pyramid • Pre-sampled computation of MIPMAP • 1/3 more memory Bilinear or Trilinear interpolation

  21. Point sampling point sampled mini fj cation mipmap mini fj cation

  22. Reference: gaussian sampling by point sampled 512x supersampling mini fj cation mipmap mini fj cation

  23. Texture minification 
 with a mipmap

  24. Texture minification: supersampling vs. mipmap

  25. How to do better? RIP maps and summed-area tables • can look up axis-aligned rectangular areas • diagonals still a big problem! Elliptical Weighted Average (EWA) filter • perform multiple lookups • accumulate using filtering weights • MIP map pyramid still helps!

  26. ellipse testing can be done with one function evaluation begin (this is faster than point-in-quadrilateral testing, which < Find bounding box around ellipse: ul.u.u2, vl.v.v2 > requires substitution into four line equations). The func- NUM = 0. DEN - 0. tion for this test is a quadratic in the texture coordinates DDQ = 2.*A u and v: U = ul-UO Q(u,v) = Au2 + Buv+ Cv2 1* scan the box */ for v-vl to v2 do begin where u = 0, v = 0 is the center of the ellipse. This V = v-VO function is an elliptical paraboloid. Points inside the DQ = A*(2.*U+l.)+B*V /* =Q(U+I,V)-Q(U,V) *1 ellipse satisfy Q (u,v) < Ffor some threshold F. In texture Q = (C*V+B*U)*V+A*U*U space the contours of Q are concentric ellipses (Figure 8), for u=ul to u2 do begin but when mapped to screen space, they are nearly circu- 1* ignore pixel if Q out of range *1 lar. Since Q is parabolic it is proportional to r2, where r is if Q<F then begin the distance from the center of a pixel in screen space. WEIGHT = WTAB[floor(Q)] This radius r is just the parameter needed when indexing 1* read and weight texture pixel */ a kernel, so Q can serve two purposes: inclusion testing - NUM+WEIGHT*texture[v,u] NUM and kernel indexing. /* DEN is denominator (for normalization) */ The kernel f(r) is stored in a weight lookup table, = DEN+WEIGHT DEN WTAB. Rather than index WTAB by r, which would end necessitate the calculation of r =V at each pixel, we Q = Q+DQ DQ = DQ+DDQ define end WTAB[ Q]=f( \fQ) end return(NUM/DEN) so that the array can be indexed directly by Q. Warping a lookup table for computational efficiency is end a useful trick that has been applied by others3"7 A good kernel to use is the Gaussian f(r) = e-ar, shown in Figure 9, for which WTAB[Q] = e-aQ. The Gaussian is preferred This implementation can be optimized further by re- to the theoretically optimal sinc kernel because it decays moving redundant calculations from the v loop and, with much more quickly. By properly scaling A, B, C, and F, the proper checking, by using integer variables throughout. length of the WTAB array can be controlled to minimize quantization artifacts (several thousand entries have The EWA filter computes the weighted average of proven sufficient). The parameters F and a can be tuned elliptical areas incrementally, requiring one floating-point to adjust the filter cutoff radius and the degree of pixel multiply, four floating-point adds, one integerization, and overlap. one table lookup per texture pixel. Blinn et al.'s method, To evaluate Q efficiently, we employ the method of which is the most similar to EWA, appears to have EWA filtering (attributed to Greene & Heckbert, but they didn’t work out the MIP map part) finite differences. Since Q is quadratic, two additions suffice to update Q from one pixel to the next? The following pseudocode implements the EWA filter for monochrome pictures (it is easily modified for color). Integer variables are lowercase; floating-point variables Treat pixel as circular are uppercase. • e.g. Gaussian filter 1* Let texture[v,uJ be a 2-dimensional array holding texture *1 Use linear apx. for distortion < Compute texture space ellipse center (UO,VO) from screen coordinates (x,y) > • circular pixel maps to elliptical footprint • ellipse dimensions calc’d from quadratic au av . Compute (Ux,Vx) and (Uy,Vy) = tax, ax J ay. .] ai a Loop over texels inside ellipse /* Now find ellipse corresponding to a circular pixel: */ - Vx*Vx+Vy*Vy A B - -2.*(Ux*Vx+Uy*Vy) • actually over bounding rect C - UX*UX+Uy*Uy - Ux*Vy-Uy*Vx F • weight by filter value and accumulate - F*F F < scale A, B, C, and F equally so that F - WTAB length > Select appropriate MIP map level Greene & Heckbert ‘86 /* Ellipse is AU2+BUV+CV2=F, where U=u-UO, V=v-VO *1 • so that minor radius is 1–2 texels Figure 8. Contours of elliptical paraboloid Q and box EWA(UO,VO,A,B,C,F) around Q = F. Dots are centers of texture space pixels. June 1986 25

  27. Texture minification: 
 supersampled vs. EWA

Recommend


More recommend