Top Banner
Relic’s FX System: Making Big Battles Come Alive Daniel Barrero, PhD Senior Graphics Programmer Relic Entertainment - THQ Korea Game Conference – KGC 2012 – October 8 2012
49

Relic's FX System

Jun 14, 2015

Download

Technology

Daniel Barrero

Presentation at KGC2012 about the Architecture and Optimization techniques used to make the Relic FX System as used in the Company of Heroes and Dawn Of War Series, and many other Relic Games.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Relic's FX System

Relic’s FX System:Making Big Battles Come Alive

Daniel Barrero, PhDSenior Graphics Programmer

Relic Entertainment - THQ

Korea Game Conference – KGC 2012 – October 8 2012

Page 2: Relic's FX System

• Video/Screenshots of fx

Introduction

Page 3: Relic's FX System

Relic’s FX System Lineage

Influenced ByDirect Descendant

Custom Port

Page 4: Relic's FX System

FX System: More than a Few Good Particles

• FX Systems are at the core particle systems, for our purposes we require it to:• Allow multiple particle types at the same time• Be Fast and scale performance based on available resources• Allow wildly different particle behaviors• Multiple ways to generate particles• Easy to use by content creators• Able to interact easily with gameplay• Be able to be used for wildly different types of game worlds

Page 5: Relic's FX System

Relic’s FX System Features

• Broad variety of particle types• Hierarchical Particle System• Cascading FX (Trigger other FX and game actions)• FX Batching ( just 1 to 2 render calls to render everything )• Multiple Particle Behavior environments• Lit particles• Soft/Volumetric Particles• Explicit draw particle order within a particle system• Forward and Deferred renderer support.• Automatic texture atlas generation on load• Animated texture support• Efficient memory management• In camera and Post-Processing FX

Page 6: Relic's FX System

System Architecture

• Object oriented style systemFX Type

FX Combo FX Particle FX Emitters

• FX Types hold the information for the effect, FX Objects are instanced based on that information when a FX gets triggered and hold the specific instance mutable state information.

Page 7: Relic's FX System

Hierarchical Particle System

• The FX Combo type is one of the core building blocks of the hierarchical particle system.– It can have up to 8 children of any FX Type, including more

combos.

Page 8: Relic's FX System

Hierarchical Particle System

• The FX Combo type is one of the core building blocks of the hierarchical particle system.– It can have up to 8 children of any FX Type, including more

combos.– It’s properties indicate how, when and where children are

created.

Page 9: Relic's FX System

Hierarchical Particle System

• The FX Combo type is one of the core building blocks of the hierarchical particle system.– It can have up to 8 children of any FX Type, including more

combos.– It’s properties indicate how, when and where children are

created.– Children properties with the same name as the combo are

relative to it’s parent, similarly root combo properties are relative to the action or object that triggered the effect.

Page 10: Relic's FX System

Hierarchical Particle System

• The second key building block of the hierarchical particle system is the ability for any FX Type other than a combo to trigger a single child effect of any other FX type.

Page 11: Relic's FX System

FX Particle Types

• Standard Geometric Particles:• FX Ring: just a simple standard textured quad.

• The most common type of particle. E.g. Smoke, Explosions, Clouds, Ground effects, UI…

Page 12: Relic's FX System

FX Particle Types

• Standard Geometric Particles:• FX Beam: a long stripped rectangle that goes from a point

of origin to a specific destination point following a curve.• E.g. a Laser beam

Page 13: Relic's FX System

FX Particle Types

• Standard Geometric Particles:• FX Trail: A curved flat shape that follows the path created

by the movement of the fx emitter. • E.g. A constantly growing ribbon like Homeworld engine trails

Page 14: Relic's FX System

FX Particle Types

• Standard Geometric Particles:• FX Streamer: A long stripped rectangle that goes from a

point of origin up in a given direction up to a given distance. • E.g. Laser sword or flame thrower.

Page 15: Relic's FX System

FX Particle Types

• Standard Geometric Particles:• FX Mesh: Generates the indicated mesh and attaches to a

particle that controls the look and position of the mesh.• Useful for debris, rockets, 3D UI elements,...

Page 16: Relic's FX System

Particle Types

• Post-Processing and non directly visible particles:• FX Distortion : An axis aligned quad that applies a post-

processing distortion effect mostly used to simulate heat and pressure waves.

• FX Lens Flare : Generates a lens flare effect applied as a post-processing effect in the screen area covered by the effect.

• FX Light: Generates a dynamic point light in the world for the duration of the effect.

• FX Audio: Creates an audio source with the indicated sound at the particle position.

Page 17: Relic's FX System

Particle Rendering: Blend Modes

• Having an explicit draw particle order within a particle system allows having per particle alpha blended or additive blending modes:

Additive:

Alpha Blend:

Particle Background

+ =

+ =*

Screen

*

ParticleAlpha

ParticleInv-Alpha

Page 18: Relic's FX System

FX Particle Types: Lighting

• Lighting style affects particle triangulation.– E.g for a FX Ring:

Unlit / Flat

Lit (Pyramid)

Geometry Render

Page 19: Relic's FX System

• Orientation relative to world or parent.• Billboarding:– Spherical – World Axis Constrained

• Follow Terrain

Particle Rendering: Orientation

Page 20: Relic's FX System

Particle Generation

• A single FX Type can be triggered either directly or from other FX Types – E.g. a single ring.

• Using the FX Spray type to generate sets of FX Types with a common given behavior.– E.g a column of smoke– FX Sprays can be spawned by any other FX Type

Page 21: Relic's FX System

Particle Behavior

• FX Visuals are separate from specific FX behavior.

FX Type FX Environment

Full Physics SimulationSimple Dynamics

• Each FX Type can have a different FX Environment allowing particles in a single effect to react differently to their environment.

Animation Curves

Page 22: Relic's FX System

Particle Behavior

• Animation Curves:– Any particle parameter can be animated using key

framed animation.

Page 23: Relic's FX System

Particle Behavior

• Simple Dynamics:– We use Newtonian physics and Verlet integration on all simulation

environments to compute new particle positions.– For ground collisions we calculate collisions directly against the

terrain height map.– For collisions against objects first collisions are computed against

the animated bounding boxes then against the actual object polygons if precise intersections are requested.

• Full Physics Simulation:– FX Meshes being standard world objects, are able to use the

standard game physics (Havok) to compute precise collisions against the environment if set up to do so.

Page 24: Relic's FX System

Pipeline: FXEditor

• FX Editor is where individual effects get created.

Page 25: Relic's FX System

Pipeline: Object Editor

• FX get hooked up with game actions in this tool.

Page 26: Relic's FX System

Pipeline: Object Editor

• FX get hooked up with game actions in this tool.– Allows triggering FX from game data and gameplay

events using a Data-Command-Action pattern.• Is an event based state machine system that is

completely data driven.• Allows attaching FX to markers in objects and to trigger

other fx based on game states data.

Page 27: Relic's FX System

Making it Fast

• Problem: There can be thousands of particles of different types, blending modes and textures that need to be created and updated every frame.• Straight forward approach to render each particle

separately produces too many render calls and context switches.

• Updating and generating so many particles can take a lot of time in the CPU

Page 28: Relic's FX System

Making it Fast

• Solution to reduce CPU cost:– Keep particle dynamics as simple as possible:• That means fake complex physics behaviors as much as

possible with simple particle animations as much as possible and only use physics simulation for particles that really need it.

– Multithread the particle update• Every frame the FX Manager spawns as many jobs as

there are root FX Objects (FX Objects with no other FX Type as parent).

Page 29: Relic's FX System

Making it Fast: Batching

• Solution to Render Cost: Batch Particles• Add all particle triangles to a single dynamic fat vertex and

index buffers regardless of particle type.

• Dynamic vertex buffer works as a circular buffer.• We do only 1 or 2 render calls per frame for all effects

combined! (max 21845 particle triangles per render call)

Page 30: Relic's FX System

Making it Fast : Batching

• Solution to Render Cost: Batch Particle• Pack FX textures in a texture atlas at load time to

use a single shader and avoid texture switches.• Texture atlas is a cube map in d3d9 level HW

Page 31: Relic's FX System

Making it Fast : Batching

• Supporting different modes in the same shader pass and using a unique blend state:– FX Textures are all pre-multiplied alpha.– Blend state is set to a custom additive + blend

state:– Screen Color = Particle Color + Screen Color * Particle Alpha

• Use separate alpha blend state:– Screen Color = Particle Alpha * Inv Particle Alpha + Screen

Alpha

Page 32: Relic's FX System

Making it Fast: Batching

• Supporting different modes in the same shader pass and using a unique blend state:– In shader code we compute the particle color and

alpha depending on blend mode requested:

Page 33: Relic's FX System

Making it Fast : Deferred Rendering

• Render in a buffer the nearest and furthest depth values during the depth pre-pass or the GBuffer pass.

• Render the FX on a separate lower res buffer using alpha blending using the near and far values to determine if an effect should be drawn in the buffer or not.

• Blend the FX buffer as full screen post-processing pass.

Page 34: Relic's FX System

Making it Fast : Weather FX

• Besides the hierarchical system there is a specific separate System just for weather FX:– Solve a very specific problem in a very efficient

way:• Falling Rain and Snow• Rain Splashes

– Can be implemented in the CPU or completely on the GPU on recent hardware

Page 35: Relic's FX System

Making it Fast : Weather FX

Page 36: Relic's FX System

Making it Fast : Weather FX

Observations: • Rain drops are only visible when close to the camera:• Particles only need to be computed inside the view

frustum close to the camera:• Easier to reuse particles thus simplifying memory

management by using a circular buffer for the particles.

• There is really only one type of particle needed• Textured Quads

Page 37: Relic's FX System

Making it Fast : Weather FX

Observations (cont): • It is really hard to see what specific falling drop

produce a specific splash on an object at normal speed:

• Means falling rain and rain splashes can use different non interdependant techiques for particle generation.

Page 38: Relic's FX System

Making it Fast : Weather FX

Falling Rain and Snow Overall algorithm:• First Emit particles on an area in top of the view frustum

and close to the camera.

Page 39: Relic's FX System

Making it Fast : Weather FX

Falling Rain and Snow Overall algorithm:• First Emit particles on an area in top of the view frustum

and close to the camera.• Calculate new positions for all particles

Page 40: Relic's FX System

Making it Fast : Weather FX

Falling Rain and Snow Overall algorithm:• First Emit particles on an area in top of the view frustum

and close to the camera.• Calculate new positions for all particles• If particle is outside of the view volume mark as dead and

reuse.

• Problem: moving the camera will show more particles on one side until new particles are generated on the side of the direction of the movement.

Page 41: Relic's FX System

Making it Fast : Weather FX

Falling Rain and Snow Overall algorithm:• Solution: treat particles as an animated volumetric

texture• If a particle goes out of the volume in one of the sides, just

change the position as if it wrapped around the other side of the volume.

Page 42: Relic's FX System

• Volume particle tiling CPU code:

Making it Fast : Weather FX

• Volume particle tiling GPU (Vertex Shader) code

Page 43: Relic's FX System

Making it Fast : Weather FX

Falling Rain and Snow Overall algorithm:• Solution: treat particles as an animated volumetric

texture• If a particle goes out of the volume in one of the sides, just

change the position as if it wrapped around the other side of the volume.

• If a particle goes out of the volume in the bottom then reuse as a new particle.

Page 44: Relic's FX System

Optimizations: Weather FX

• Rain Splashes algorithm • Also treats splashes as an animated volumetric texture

that tiles in world space.

Page 45: Relic's FX System

Optimizations: Weather FX

• Rain Splashes algorithm • Generate random positions on the horizontal plane instead

of the top of the camera:

Page 46: Relic's FX System

Optimizations: Weather FX

• Rain Splashes algorithm • Generate random positions on the horizontal plane instead

of the top of the camera.• Trace a ray at that particle point from a high altitude and

find first intersection with the terrain or objects allowed to have splashes.

• Emit Splash particle

at that point.

Page 47: Relic's FX System

Optimizations: Weather FX

• Problem: If camera moves then splashes would move over the terrain.

• Solution: Let splash particles generated play their animation while they are visible by the camera once dead or out of the view frustum reuse for new particle in another position.

Page 48: Relic's FX System

Acknowledgements• Thanks to all the great FX Artists that keep

pushing the limit of what the FX system can do and keep us busy with more ideas of how to make it better.

• Thanks to all the countless programmers that have worked on the FX System its tools and pipeline over the years.

Page 49: Relic's FX System

Thank you

• Questions?

• Contact Information:• [email protected]• http://danielbarrero.com