29
Distance fields imre paadik

imre paadik

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: imre paadik

Distance fieldsimre paadik

Page 2: imre paadik

Overview

● Signed distance fields

● Distance fields in computer graphics○ Textures

○ Geometry

Page 3: imre paadik

Overview

http://chimera.labs.oreilly.com/books/1234000001814/ch07.html#ch07_id36000844

Page 4: imre paadik

Overview

Page 5: imre paadik

Textures

● Different way of storing bitmap data

● Used with source imageo for every distance field value

value <=0● yes? draw pixel

● no ignore it

Page 6: imre paadik

Textures

● Distance fields creationo High resolution source image

Downsampled to acceptable size

Lot of information preserved

4k textures used to generate 64x64 distance field

Page 7: imre paadik

Textures

● Distance fields creationo Brute force

o O(N^2) complexity

o Mapped to 0f..1.0f range

o 0.5f decision point (draw or not to draw)

Page 8: imre paadik

Textures

Main application

● Font rendering

● Decals

● UI

Page 9: imre paadik

Textures

Font rendering

● No need to pre-rasterize all font sizes

● Bonus featureso Glow

o Drop shadow

o Outlining

o Antialias (smoothstep between distance field values)////// Antialiased text rendering //////

float4 ps( VS_OUTPUT IN) : COLOR

{

// get the alpha value from the distance field texture

float rawAlpha = tex2D( TextureSampler, IN.TilingCoords).a;

clip (rawAlpha - (0.5f-delta));

return float4(fillColour, smoothstep(0.5f-delta,0.5f+delta,rawAlpha) );

}

Page 10: imre paadik

Textures

Decals

Page 11: imre paadik

Textures

Used internally in Source Engine

Can be used with any engine!● http://bytewrangler.blogspot.nl/2011/10/signed-distance-fields.html

● http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaT

estedMagnification.pdf

● http://www.lems.brown.edu/vision/people/leymarie/Refs/CompVision/DT/D

Tpaper.pdf

Page 12: imre paadik

Geometry

● Unreal Engine 4o Distance Field Ambient Occlusion (DFAO) (4.3)

o Distance Field Specular Occlusion (4.5)

o Distance Field Soft Shadows (4.5)

Page 13: imre paadik

DFAO

● Precomputed distance field for every static

mesh

● Volume textures storing signed distance to

nearest surface

● Pure GPU feature, requires DX11.

Page 14: imre paadik

DFAO - OFF

Page 15: imre paadik

DFAO - ON

Page 16: imre paadik

DFAO - OFF

Page 17: imre paadik

DFAO - ON

Page 19: imre paadik

DFAO

Cons

● Meshes can only use uniform scaling

● Memory overhead

● GPU overhead (3.5ms - 6ms Radeon 7870)

● Rigid meshes only

Page 20: imre paadik

Specular Occlusion - OFF

Page 21: imre paadik

Specular Occlusion - ON

Page 22: imre paadik

Ray Traced Distance Field

Soft Shadows (RTDFSS :-) )

● Uses same DFAO data to compute efficient

area shadows

● Point & Spot lightso ‘Source Radius’ determine how large shadow

penumbras are

o Sharp at shadow contacts softer over distance

o Amazing quality (When using correct resolution)

Page 23: imre paadik

Ray Traced Distance Field

Soft Shadows (RTDFSS :-) )

Page 24: imre paadik

Ray Traced Distance Field

Soft Shadows (RTDFSS :-) )

Page 25: imre paadik

Ray Traced Distance Field

Soft Shadows (RTDFSS :-) )

Directional lights

● ‘Light Source Angle’ determine how large is

shadow penumbra

● No bias and self intersection problems as

shadowmaps

● Efficient when used with larger distances

● Even faster than shadowmapping

Page 26: imre paadik

Ray Traced Distance Field

Soft Shadows (RTDFSS :-) )

Page 27: imre paadik

How does this work?

● Signed distance fields representing mesh

surfaces

● Stores distance to the

nearest surface at

every point

● http://http.developer.nv

idia.com/GPUGems3/g

pugems3_ch34.html

Page 28: imre paadik

How does this work?

● Efficient ray tracing

Page 29: imre paadik

How does this work?

● Efficient cone tracing