cubemap filtering with cubemapgen -...

27
Cubemap Filtering with Cubemap Filtering with CubeMapGen CubeMapGen Thorsten Scheuermann John Isidoro 3D Application Research Group

Upload: others

Post on 30-Apr-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

Cubemap Filtering with Cubemap Filtering with CubeMapGenCubeMapGenThorsten ScheuermannJohn Isidoro3D Application Research Group

Page 2: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

2GDC 2005: Cubemap Filtering With CubeMapGen

OutlineOutline

>CubeMapGen tool

>Angular extent filtering

>Edge fixup methods

>Pre-filtered per-pixel glossy reflections

>Examples

Page 3: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

3GDC 2005: Cubemap Filtering With CubeMapGen

Cubemap UsesCubemap Uses

>Cube mapping has become ubiquitous

>Good for any directional lookup table> Diffuse

> Specular (a.k.a. environment map)

> Glossy Specular

>Dynamic cubemaps

Page 4: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

4GDC 2005: Cubemap Filtering With CubeMapGen

Cubemap Filtering IssuesCubemap Filtering Issues

> Cube map is defined over spherical domain

> Standard mipmapping tools process each face independently

> No filtering across faces

> Fail to take the solid angle of cube map texels into account

> Can introduce artifacts and discontinuities at face seams

> Graphics hardware generally does not support Bi/Trilinear cubemap filtering across cube faces

> Lots of game developers complained about the seam issues Example of seam

artifacts on lowermiplevels

Page 5: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

5GDC 2005: Cubemap Filtering With CubeMapGen

CubeMapGenCubeMapGen ToolTool

> CubeMapGen is a tool for cubemap filtering and mip-chain generation> To be released as standalone tool, command-line tool, HDRShop plugin,

library, source code> Available on http://www.ati.com/developer

Page 6: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

6GDC 2005: Cubemap Filtering With CubeMapGen

CubeMapGenCubeMapGen OverviewOverview

>CubeMapGen addresses the two main filtering issues that remain troublesome for cube map users

> Missing bi/trilinear filtering across cube faces in HW> Mipmap generation for each cubemap face in isolation

>CubeMapGen helps to addresses these issues with a couple of techniques

> Angular extent filtering> Edge averaging/fixup

>Pure software solution compatible with all hardware> This is just a cubemap preprocessing step

Page 7: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

7GDC 2005: Cubemap Filtering With CubeMapGen

CubeMapGenCubeMapGen Feature List (1)Feature List (1)

>Performs all filtering operations in HDR space (32-bit float)

>Angular extent filtering allows for filtering across faces

> Disc, Cone, Angular Gaussian, and Cosine filtering modes

> All texels within angular extent are used when computing average

> Optional weighting of texels by their solid angles

>Edge and Corner averaging to obscure cube edge seams

> Adjustable edge fixup band to help obscure effect of edge averaging

Page 8: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

8GDC 2005: Cubemap Filtering With CubeMapGen

CubeMapGenCubeMapGen Feature List (2)Feature List (2)

>Adjustable pre-filtering of base miplevel (0-180 degree kernel)

> E.g. for blurred reflections

>Imports and exports 8/16 bit uint and 16/32bit float pixel formats

> Supports .hdr .pfm .bmp .jpg .png .dds .dib

> Adjustable Degamma/Gamma and Output Intensity Scaling

>Command Line Interface for use in scripting and as a preprocess tool

Page 9: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

9GDC 2005: Cubemap Filtering With CubeMapGen

CubeMapGenCubeMapGen DemoDemo

Page 10: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

10GDC 2005: Cubemap Filtering With CubeMapGen

Angular Extent FilteringAngular Extent Filtering

Center tapvector

θAngular extent

Center tapvector

θ

Angular extent

> Angular extent filtering processes all taps within a given angle of the 3D center tap vector

> Filter extent is not texel size dependant> Instead, filter extent has constant solid angle

> e.g. Filter may (and should) encompass a different number of texels for different centertap vectors

> Allows for filter kernels that span across cube face edges

Page 11: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

11GDC 2005: Cubemap Filtering With CubeMapGen

Angular Filter TypesAngular Filter Types

Disc FilterDisc Filter

Angular GaussianAngular Gaussian

Cone FilterCone Filter

Cosine Filter Cosine Filter

Page 12: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

12GDC 2005: Cubemap Filtering With CubeMapGen

Disc FilterDisc Filter

> Equal weights for all taps within a specified angle of the center tap

Page 13: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

13GDC 2005: Cubemap Filtering With CubeMapGen

Cone FilterCone Filter

> Linear falloff based on angle from center tap

Page 14: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

14GDC 2005: Cubemap Filtering With CubeMapGen

Angular Gaussian FilterAngular Gaussian Filter

> Gaussian falloff based on angle from center tap

> 3 standard deviations within specified extent angle

Page 15: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

15GDC 2005: Cubemap Filtering With CubeMapGen

Cosine FilterCosine Filter

> Falloff based on cosine of angle from center tap

> Most useful to compute diffuse lighting cubemaps

> Incorporates the hemisphere cosine term

> Use a filter angle of 180°

Page 16: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

16GDC 2005: Cubemap Filtering With CubeMapGen

Implementation DetailsImplementation Details

>Filtering performed on CPU>For each output texel:

> Determine bounding box regions for angular extent in each face on input cubemap

> Process all texels within each bounding box region> Test against threshold determined by extent angle> Weight using solid angle and weights of chosen filter function> Accumulate sum of weighted texels, and sum of weights

>Every texel within angular extent is processed> Important for HDR imagery: Single very bright texels can

significantly influence the filtered result

Page 17: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

17GDC 2005: Cubemap Filtering With CubeMapGen

Edge Averaging and Edge Averaging and FixupFixup

>Idea: make texels on each side of a cubemap edge match to hide artifacts due to hardware not filtering across edges

>Apply fixup in region around edge> Fade out using linear or hermite (smoothstep) falloff

>Two fixup modes:> Pull: Add weighted edge texel adjustment amount to texels

in fixup band

> Average: Lerp between original and average edge texel color based on distance from edge

>Special support for DXTC compression> Accounts for neighboring block across faces

Page 18: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

18GDC 2005: Cubemap Filtering With CubeMapGen

Edge Edge FixupFixup Example (Pull)Example (Pull)

.75

.50

.25

.75

.50

.25

Cube Face EdgeIntensity Value

Texel Intensity Values

Cube Face Edge

Fraction of averaging

amount for 4 texel fixup

band

Fixup regionFixup region

Page 19: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

19GDC 2005: Cubemap Filtering With CubeMapGen

2x2 2x2 MiplevelMiplevel (Standard)(Standard)

> 2x2 mip-level without edge fixup and no filtering across faces> Strong edge artifacts. 2x2 miplevel is unusable by itself.

Page 20: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

20GDC 2005: Cubemap Filtering With CubeMapGen

2x2 2x2 MiplevelMiplevel ((CubeMapGenCubeMapGen))

> CubeMapGen’s edge fixup ability allows for the 2x2 mip level to be used as a diffuse environment lighting term

Page 21: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

21GDC 2005: Cubemap Filtering With CubeMapGen

4x4 4x4 MiplevelMiplevel (Standard)(Standard)

> Edge filtering artifacts make the 4x4 miplevel from standard mip filtering algorithms only useful for traditional mipmappingpurposes

Page 22: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

22GDC 2005: Cubemap Filtering With CubeMapGen

4x4 4x4 MiplevelMiplevel ((CubeMapGenCubeMapGen))

> CubeMapGen generates cubemaps with a 4x4 miplevel that can also be used for rough metal shaders

Page 23: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

23GDC 2005: Cubemap Filtering With CubeMapGen

Other Other MiplevelsMiplevels ((CubeMapGenCubeMapGen))

4x44x4 8x88x8 16x1616x16 32x3232x32

Page 24: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

24GDC 2005: Cubemap Filtering With CubeMapGen

PerPer--pixel Roughnesspixel Roughness

>Different mip levels can be used for shiny surfaces with different surface roughness

> Rougher surface → more blurry reflection

> Use MaxMipLevel texture sampler state to clamp miplevel, not texCUBEbias(…)

>Per-pixel miplevel clamping:> Pack miplevel index into alpha channel

of each cubemap mipmap

> Use it to determine bias amount fortexCUBEbias(…) and simulatemiplevel clamping in shader

> Or use texCUBElod(…) on PS 3.0

>Example

Page 25: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

25GDC 2005: Cubemap Filtering With CubeMapGen

PerPer--pixel Gloss Shader Examplepixel Gloss Shader Example

float fNumMipLevels; // number of mip-levels in cubemapfloat fBlurScale = 4.0; // scale factor for blurriness

float4 main(float2 inUV : TEXCOORD0, float3 inNormal : TEXCOORD1, float3 inView : TEXCOORD2) : COLOR0

{// Surface roughness stored in alpha of base mapfloat4 cBase = tex2D(tBase, inUV);float fRoughness = cBase.a;

float3 R = reflect (normalize(inView), normalize(inNormal));

// Each cubemap stores miplevel index in alpha (scaled by 16/255).// Determine mip-LOD levels from 0 to fNumMipLevels (minification)float fMipLevelMinification = (255.0/16.0) * texCUBE(tCube, R).a;

// Determine mip-LOD levels from -fNumMipLevels to 0 (magnification)float fMipLevelMagnification = (255.0/16.0) *

texCUBEbias(tCube, float4(R, fNumMipLevels-1.0)).a;[…]

Page 26: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

26GDC 2005: Cubemap Filtering With CubeMapGen

PerPer--pixel Gloss Shader Examplepixel Gloss Shader Example

[…] float fMipLevel = 0;

//choose between magnification and minification rangeif(fMipLevelMinification == 0) { // 0 is the largest (base) miplevel// the whole cubemap is being magnified, compute "logical" miplevel// (which is negative)fMipLevel = fMipLevelMagnification - (fNumMipLevels - 1.0);

}else {// the cubemap is being minifiedfMipLevel = fMipLevelMinification;

}

// compute final mip bias to clamp miplevelfloat fMipBias = max(fGlossScale * fRoughness - fMipLevel, 0.0);

float4 cRefl = texCUBEbias(tCube, float4(R, fMipBias));

return cBase * cRefl;}

Page 27: Cubemap Filtering with CubeMapGen - AMDdeveloper.amd.com/wordpress/media/2012/10/GDC2005_CubeMapG… · GDC 2005: Cubemap Filtering With CubeMapGen. 6. CubeMapGen Overview > CubeMapGen

27GDC 2005: Cubemap Filtering With CubeMapGen

AcknowledgementsAcknowledgements

>CubeMapGen was thought up and developed by John Isidoro

> I’m merely presenting his work here today

>Lightprobe examples courtesy of Paul Debevec: http://www.debevec.org/Probes