RealTime AntiAliasing Matt Pickering Introduction Antialiasing Something youve

  • Slides: 33
Download presentation
Real-Time Anti-Aliasing Matt Pickering

Real-Time Anti-Aliasing Matt Pickering

Introduction �Anti-aliasing �Something you’ve probably encountered before �Why would we want to use anti-aliasing?

Introduction �Anti-aliasing �Something you’ve probably encountered before �Why would we want to use anti-aliasing? �How is it done?

Overview �What is aliasing? �What causes it? �Using anti-aliasing to solve the problem �The

Overview �What is aliasing? �What causes it? �Using anti-aliasing to solve the problem �The techniques we can use � Pros and cons � Code stuff �Texture filtering �The future of anti-aliasing �Summary �Resources

Background �Aliasing can affect any kind of signal processing �Signal processing is a field

Background �Aliasing can affect any kind of signal processing �Signal processing is a field of electrical engineering and applied mathematics �Not just images �Audio �Sensor data �Radio transmissions �Etc.

Context �We want to view a digital image �(The rendered frame of our game)

Context �We want to view a digital image �(The rendered frame of our game) �Image gets reconstructed by display device �Bottleneck �Our eyes and brain are also part of the reconstruction process

Description �Bottleneck: �Reconstruction resolution is too low �Detail is lost or distortion occurs �The

Description �Bottleneck: �Reconstruction resolution is too low �Detail is lost or distortion occurs �The distorted/low resolution image is an alias of the original

Description �Pre-aliasing �Aliasing that happens during sampling �Post-aliasing �Aliasing that happens during reconstruction

Description �Pre-aliasing �Aliasing that happens during sampling �Post-aliasing �Aliasing that happens during reconstruction

Spatial Aliasing �Display device limitations What we want What we get

Spatial Aliasing �Display device limitations What we want What we get

Spatial Aliasing �Limited resolution What we want What we get

Spatial Aliasing �Limited resolution What we want What we get

Temporal Aliasing �We can only show so many frames per second… �If objects in

Temporal Aliasing �We can only show so many frames per second… �If objects in our scene are being transformed (moving/rotating) faster than our sample rate (frames per second) �We get temporal aliasing �Objects appear to jump or stutter instead of moving smoothly

Temporal Aliasing �Example: �Spoked wheel/propeller �“Wagon-wheel effect” �Appears to rotate much slower than it

Temporal Aliasing �Example: �Spoked wheel/propeller �“Wagon-wheel effect” �Appears to rotate much slower than it really is, or even appear to rotate backwards

Aliasing �Insufficient resolution �Insufficient sample rate

Aliasing �Insufficient resolution �Insufficient sample rate

Anti-Aliasing �We want a way to “fool” the viewer into thinking the jagged edges

Anti-Aliasing �We want a way to “fool” the viewer into thinking the jagged edges and distortions in our scene are actually nice and smooth �How?

Techniques �FSAA �Super-sampling �Multi-sampling �Basic principle:

Techniques �FSAA �Super-sampling �Multi-sampling �Basic principle:

Super-sampling �Brute force � 4 x super-sampling @ 800 x 600 = 1600 x

Super-sampling �Brute force � 4 x super-sampling @ 800 x 600 = 1600 x 1200 �So for every pixel on the 800 x 600 screen �We’re effectively drawing 4 “sub-pixel” samples � Those 4 sub-pixels are then combined � We get the final pixel colour for the 800 x 600 screen

Super-sampling �Visualising super-sampling: �We want to draw the red objects �The small squares are

Super-sampling �Visualising super-sampling: �We want to draw the red objects �The small squares are our pixels �The pixels that are part red, part white get averaged into a shade of orange.

Super-sampling �Pros: �We get higher sampling resolution for the entire image �Cons: �It’s extremely

Super-sampling �Pros: �We get higher sampling resolution for the entire image �Cons: �It’s extremely expensive to make the image much larger than we actually want it to be, then scale it down by combining samples �Consider 16 x SSAA @ 1920 x 1080… � 30720 x 17280 samples! �

Multi-sampling �Optimisation over super-sampling �For 4 x MSAA we still create just as many

Multi-sampling �Optimisation over super-sampling �For 4 x MSAA we still create just as many sub-pixels �But the pixel pipeline isn’t run for each sample �Instead, we first do the same calculation as rasterization: � If the edge of a polygon covers the centre of a pixel � Then that colour is the same as the polygon �Then, the percentage of the sampling points covered by the polygon is multiplied by that colour �This gives us the final colour for the pixel

Multi-sampling �Visualising multi-sampling: �Middle sample �Same as rasterization �Sub-pixel samples � 2 sub-pixels are

Multi-sampling �Visualising multi-sampling: �Middle sample �Same as rasterization �Sub-pixel samples � 2 sub-pixels are covered �Final colour = 50% of poly colour

Multi-sampling �Pros: �Much lower overheads �Cons: �Multi-sampling extends the rasterized area to include all

Multi-sampling �Pros: �Much lower overheads �Cons: �Multi-sampling extends the rasterized area to include all pixels in which at least some sampling points are covered �Even if the pixel centre is not covered! �This means that if a polygon edge covers some subpixels samples, but not the pixel centre, a sample gets taken from beyond the UV boundaries of the polygon

Centroid Multi-sampling �We can avoid these artefacts: �“Centroid multi-sampling” �This simply moves the centre

Centroid Multi-sampling �We can avoid these artefacts: �“Centroid multi-sampling” �This simply moves the centre sampling point to be between the sample points that are covered by the polygon.

Anti-Aliasing – Direct. X

Anti-Aliasing – Direct. X

Anti-Aliasing – Shaders �HLSL: �Assembly shader:

Anti-Aliasing – Shaders �HLSL: �Assembly shader:

Texture Filtering �It’s not just our polygons that have trouble being represented on a

Texture Filtering �It’s not just our polygons that have trouble being represented on a screen at an angle �The texture on the polygon is a grid-like arrangement of texels �If the texture is rotated or scaled, it won’t map to our screen pixels accurately, and we’ll get aliasing �Solution: �Mip-mapping

Bilinear/Trilinear Filtering �Bilinear Filtering �We can have multiple mip-maps being drawn on one large

Bilinear/Trilinear Filtering �Bilinear Filtering �We can have multiple mip-maps being drawn on one large object (like terrain) �Problem: � We’re only blending pixels from within each mip-map � Very obvious seam between mip-map levels �Trilinear Filtering �Solution: � Blend with the neighbouring mip-map levels as well

Anisotropic Filtering �AA makes object edges look better �AF makes object interiors look better

Anisotropic Filtering �AA makes object edges look better �AF makes object interiors look better �Surfaces at oblique viewing angles IDirect 3 DDevice 9: : Set. Sampler. State() Texture index Mag/Min/Mip filter D 3 DTEXTF_ANISOTROPIC

Temporal Anti-aliasing �Remember we talked about stuff moving/rotating too fast? �How do we fix

Temporal Anti-aliasing �Remember we talked about stuff moving/rotating too fast? �How do we fix that? �Sample at least 2 x as fast as the fastest moving object � Nyquist Frequency � So we either need very high framerates, or lower detail objects � (Not really an option) �Cheat � Store frames we’ve already drawn � Blend them with the current frame (post processing) � Basic motion blur – can cause “ghosting”

Future �MLAA �Still experimental, complicated, being developed by Intel � Post-processed anti-aliasing �Uses shape

Future �MLAA �Still experimental, complicated, being developed by Intel � Post-processed anti-aliasing �Uses shape recognition to identify edges � Breaks edges down into L-shapes � Connect midpoint of secondary edge with the end point of primary edge � This gives us an area �Calculates blending weights � C_new = (1 – area) * C_old + area * C_opposite � This is an approximation of MLAA �Blend each pixel with its neighbours using calculated weights

Morphological Anti-Aliasing

Morphological Anti-Aliasing

Summary � We get aliasing when : � We can’t represent an image with

Summary � We get aliasing when : � We can’t represent an image with a high enough resolution � We can’t sample fast enough � There’s 2 main strategies for dealing with this � Super-sampling � Draw a big image, then downsample by taking average colours � Multi-sampling � Only sample colour once per pixel, then multiply colour by % of covered subpixels � Texture filtering � Mip-mapping � Bilinear/Trilinear � Anisotropic filtering � Motion blur � MLAA

References MSAA in Direct. X SDK Sample Browser includes an anti-aliasing sample + documentation

References MSAA in Direct. X SDK Sample Browser includes an anti-aliasing sample + documentation http: //www. directxtutorial. com/Tutorial 11/B-A/BA 2. aspx http: //msdn. microsoft. com/en-us/library/bb 173422(VS. 85). aspx http: //msdn. microsoft. com/en-us/library/bb 206250(VS. 85). aspx http: //www. chadvernon. com/blog/resources/managed-directx-2/texture-compression-filters-and-transformations/ AA in general http: //www. extremetech. com/article 2/0, 2845, 2136956, 00. asp http: //www. pantherproducts. co. uk/Articles/Graphics/anti_aliasing. shtml http: //www. bit-tech. net/hardware/2005/07/04/aliasing_filtering/1 Moiré pattern http: //en. wikipedia. org/wiki/Moir%C 3%A 9_pattern MSAA http: //alt. 3 dcenter. org/artikel/multisampling_anti-aliasing/index 7_e. php MLAA http: //www. eurogamer. net/articles/digitalfoundry-saboteur-aa-blog-entry http: //www. realtimerendering. com/blog/morphological-antialiasing/ http: //igm. univ-mlv. fr/~biri/mlaa-gpu/ http: //www. youtube. com/watch? v=Z 8 UG 7 g 8 NRcw http: //visual-computing. intel-research. net/publications/papers/2009/mlaa. pdf

References � � � � � “Wagon-wheel effect” – this is cool http: //www.

References � � � � � “Wagon-wheel effect” – this is cool http: //www. youtube. com/watch? v=j. HS 9 JGk. EOm. A http: //www. youtube. com/watch? v=r. VSh-au_9 a. M http: //www. youtube. com/watch? v=LVwmtw. ZLG 88 http: //www. youtube. com/watch? v=T 055 cp-JFUA http: //www. youtube. com/watch? v=oq. UNd 5 w. PGb. U Motion blur/Temporal AA http: //blogs. msdn. com/b/shawnhar/archive/2007/08/21/motion-blur. aspx http: //www. eurogamer. net/articles/digitalfoundry-halo-reach-tech-analysis-article? page=3 Texture filtering http: //blogs. msdn. com/b/shawnhar/archive/2009/09/08/texture-filtering. aspx Nyquist frequency http: //www. youtube. com/watch? v=Fy 9 d. Jg. GCWZI Basic summaries of AA/AF http: //www. youtube. com/watch? v=OLf 03 IMLs. LI&NR http: //www. youtube. com/watch? v=YM 3 ie. QHRYOc Oldskool article on AF http: //www. nvnews. net/previews/geforce 3/anisotropic. shtml

Questions?

Questions?