Offscreenparticle

31
High-Speed, Off-Screen Particle GPU gems 3 OZ http://ozlael.egloos.com/

description

GPU Gems 3 - Chapter 23. High-Speed, Off-Screen Particles

Transcript of Offscreenparticle

Page 1: Offscreenparticle

High-Speed, Off-Screen ParticleGPU gems 3

OZhttp://ozlael.egloos.com/

Page 2: Offscreenparticle

Large particle system

● mushroom cloud, smoke, fire, explosion ...

● Many polygons

● Fill rate

● Frame rate

Page 3: Offscreenparticle

Motivation

● Off-screen Render Target

● Fraction of the Frame Buffer size

Page 4: Offscreenparticle

Low-Resolution

● Image of smoke and fog have only low frequencies

● Small number of samples without loss of visual quality

● Bad to high frequencies

Page 5: Offscreenparticle

Off-Screen Rendering

● Particles are rendered to an Off-Screen.

● Not require a same size of Frame Buffer.

● Not require a particular ratio of size.

● Trade-off

Page 6: Offscreenparticle

Off-Screen Depth Testing

● Requires Depth buffer

● Occlude the particles against opaque

● Depth testing

● Off-screen RT size

Page 7: Offscreenparticle

Off-Screen Depth Testing

● 1. Render all solid objects(a)

● 2. Downsample the resulting Depth Buffer

● 3. Render the particles to Off-screen RT, testing against the small depth buffer(b)

● 4. Composite the particle RT back onto the main Frame Buffer(c)

Page 8: Offscreenparticle

Off-Screen Depth Testing

Show how the depth test creates a silhuette of the solid objects

Page 9: Offscreenparticle

Acquiring Depth

● MRT

- All targets must have equal bit depths

- not compatible with MSAA

● Single RT in a separate pass

● Alpha channel of an RGBA target

- Use RGBA16 cause precision problem

- Memory footprint

- Can’t MSAA on GeForce 7

Page 10: Offscreenparticle

Acquiring Depth

● DirectX 10

- Directx access

- Shader Resource View

Page 11: Offscreenparticle

Our Engine

● Deferred Render System

● G-Buffer Depth

Page 12: Offscreenparticle

Point Sampling Depth

● Depth test will occlude the particle

● Make halo

Low Res.

High Res.

Page 13: Offscreenparticle

Point Sampling Depth

Page 14: Offscreenparticle

Maximum of Depth Samples

● Sample a spread of four depth values from the full-resolution depth

● Take the maximum one.

● Four samples fully cover the high-res.

● Shrinking the object silhouettes

Page 15: Offscreenparticle

Depth Testing and Soft Particles

● The Depth Test Implemented in the PS

float4 particlePS(VS_OUT vIn): COLOR { float myDepth = vIn.depth; float sceneDepth = tex2D(depthSampler, vIn.screenUV).x; if (myDepth > sceneDepth) discard; // Compute color, etc. . . . }

Page 16: Offscreenparticle

Depth Testing and Soft Particles

● Access to Depth, useful to Soft Particle

● saturate(( Z object - Z particle) * scale)

Page 17: Offscreenparticle

Depth Testing and Soft Particles

● Soft Particles Are better than

float4 particlePS(VS_OUT vIn): COLOR { float myDepth = vIn.depth; float sceneDepth = tex2D(depthSampler, vIn.screenUV).x; float zFade = saturate(scale * (myDepth - sceneDepth)); // Compute (r,g,b,a), etc. . . . return float4(r,g,b, a * zFade); }

Page 18: Offscreenparticle

Alpha Blending

Page 19: Offscreenparticle

Alpha Blending

● Store everything except Frame-buffer d

● d term : multiplied by the inverse of every alpha value blended.

Page 20: Offscreenparticle

Alpha Blending

● s term : If the target is initialized to zero,

conventional alpha-blend equation

Page 21: Offscreenparticle

Alpha Blending States

● AlphaBlendEnable = true;

● SrcBlend = SrcAlpha;

● DestBlend = InvSrcAlpha;

● SeparateAlphaBlendEnable = true;

● SrcBlendAlpha = Zero;

● DestBlendAlpha = InvSrcAlpha;

Page 22: Offscreenparticle

Additive Blending

● Common to additively blend particles

● Not be possible to combine both in a single Off-screen RT

Page 23: Offscreenparticle

Mixed -Resolution Rendering

● Still blocky

Page 24: Offscreenparticle

Blocky Problem

● Edges can be fixed with Edge detection.

● Standard Sobel filter

Page 25: Offscreenparticle

Sobel Mask

Page 26: Offscreenparticle

Composing with Stenciling

● Edge-detection selects pixels blocky

● Rendering the particles at the full Frame-buffer resolution only where edges occur.

Page 27: Offscreenparticle

Avoid Stencil Writes, Creating a Mask

Page 28: Offscreenparticle

Avoid Stencil Writes, Creating a Mask

● Stencil buffer mask areas of FrameBuffer

float4 composePS(VS_OUT2 vIn): COLOR {float4 edge = tex2D(edgesSampler, vIn.UV0.xy); if (edge.r == 0.0) { float4 col = tex2D(particlesRTSampler, vIn.UV1.xy); return rgba; } else { // Where we have an edge, abort to cause no stencil write. discard; }}

Page 29: Offscreenparticle

Result

Page 30: Offscreenparticle

Result

Image from : technology.blurst.com/

Page 31: Offscreenparticle

Result

This Ignore blocky problem