1 Particle Systems for Games Particle System 3D MIM, hyeon.

Slides:



Advertisements
Similar presentations
Cs /11/2003 Page 1 Special Image Effects Particle Systems Fog Lens Flares Shadows Programmable Shaders.
Advertisements

This terms course Last term we both worked on learning 2 things –Processing –The concepts of graphics etc. This term will focus more on the basic concepts.
Ray tracing. New Concepts The recursive ray tracing algorithm Generating eye rays Non Real-time rendering.
Soft Particles Petter Börjesson, Mattias Thell. Particle Effects Smoke, fire, explosions, clouds, etc Camera-aligned 2D quads – Gives the illusion of.
Week 7 - Monday.  What did we talk about last time?  Specular shading  Aliasing and antialiasing.
UFCFX5-15-3Mobile Device Development Particle Systems.
Rotation and Torque Lecture 09 Thursday: 12 February 2004.
Computer Science – Game DesignUC Santa Cruz Today Publish/Subscribe Design Pattern Delegates Sprite movement Particles.
Particle Systems 1 Adapted from: E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012.
Particle Systems and Fuzzy Shapes Presented by Dan Cogswell.
Introduction to Shader Programming
Particle Systems GPU Graphics. Sample Particle System Fire and SmokeWater.
Game Physics Chris Miles. The Goal To learn how to create game objects with realistic physics models To learn how to simulate aspects of reality in order.
Particle Systems Final Exam Study Guide Game Design Experience Professor Jim Whitehead March 16, 2009 Creative Commons Attribution 3.0 (Except copyrighted.
Triangles, Translations Game Design Experience Professor Jim Whitehead March 2, 2009 Creative Commons Attribution 3.0 (Except copyrighted images) creativecommons.org/licenses/by/3.0.
Cornell CS 468Andrew Butts 1 Implementing Particle Systems CS 468 Spring 2004 Andrew Butts.
1cs426-winter-2008 Notes. 2 Velocity fields  Velocity field could be a combination of pre-designed velocity elements E.g. explosions, vortices, …  Or.
Computer Science – Game DesignUC Santa Cruz Adapted from Jim Whitehead’s slides Shaders Feb 18, 2011 Creative Commons Attribution 3.0 (Except copyrighted.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Beyond Meshes Spring 2012.
SE320: Introduction to Computer Games Week 8: Game Programming Gazihan Alankus.
Erdem Alpay Ala Nawaiseh. Why Shadows? Real world has shadows More control of the game’s feel  dramatic effects  spooky effects Without shadows the.
Dakota Humphries (Project Lead) Thomas Impellitteri (Tech Lead) Daryl McGhee II (Design Lead) Keith Rosier (Asset Lead)
Physically Based Animation and Modeling
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Procedural Terrain with Stochastic Trees. WITH MAX MORRIS, CORY GAGEL, MARK WOULFE.
CS 480/680 Computer Graphics Representation Dr. Frederick C Harris, Jr. Fall 2012.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
Geometric Objects and Transformations. Coordinate systems rial.html.
Geometric Transforms Changing coordinate systems.
Description, Classes, Interfaces, Hierarchy, Specifics George Georgiev Telerik Software Academy academy.telerik.com Technical Trainer itgeorge.net.
9.3. P ARTICLE S YSTEMS Development of a particle system.
Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
CS 638, Fall 2001 Multi-Pass Rendering The pipeline takes one triangle at a time, so only local information, and pre-computed maps, are available Multi-Pass.
Computer Science Term 1, 2006 Tutorial 3 Assignment 4 – Special Effects.
Introduction to XNA Graphics Programming Asst. Prof. Rujchai Ung-arunyawee COE, KKU.
Scalar Quantities Scalar quantities are measurements that have only magnitude (size) but no direction. Examples of scalar quantities are; Distance Speed.
11 Working with Images Session Session Overview  Find out more about image manipulation and scaling when drawing using XNA  Start to implement.
CSC505 Particle Systems. CSC505 Object Representations So far we have represented (rendered) objects with –Lines –Polygons (triangles) –Curves These techniques.
11 Making a Sprite Session 4.2. Session Overview  Describe the principle of a game sprite, and see how to create a sprite in an XNA game  Learn more.
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
Particle Systems (Motion Machines of 2D Objects with Textures) Matthew K. Bowles Advanced Computer Graphics Spring 2004.
Simple Classes. ADTs A specification for a real world data item –defines types and valid ranges –defines valid operations on the data. Specification is.
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
Dakota Humphries (Project Lead) Thomas Impellitteri (Tech Lead) Daryl McGhee II (Design Lead) Keith Rosier (Asset Lead)
Point Sprites Course Information CVG: Programming 4 My Name: Mark Walsh Website: Recommended.
Sky Boxes and Vector Math 2 Course Information CVG: Programming 4 My Name: Mark Walsh Website:
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Graphics Graphics Korea University cgvr.korea.ac.kr 1 7. Speed-up Techniques Presented by SooKyun Kim.
Multimedia Programming 21: Particle Animation Departments of Digital Contents Sang Il Park.
11/24/ :45 Graphics II Shadow Maps Reflections Session 5.
Particles and their home in Geometry Shaders Paul Taylor 2010.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
Playing with Sprites. XNA Game Lifecycle In the faceBall demo program we bounced a smiley face around the graphical display against a background image.
GameDevClub CODE CHEAT SHEET NOTE: ALL OF THE CODE IS CASE-SENSITIVE AND THE SYNTAX IS STRICT SO A LOT OF YOUR ERRORS WILL PROBABLY COME FROM TYPOS If.
Real-Time Dynamic Shadow Algorithms Evan Closson CSE 528.
Particle Systems Reference: Reeves W.: "Particle Systems -- A Technique for Modelling a Class of Fuzzy Objets", Computer Graphics, 17(3), pp ,
Graphics for Games Particle Systems CO2301 Games Development 1 Week 23.
11 Adding a Bread Bat Session Session Overview  We have created a cheese sprite that bounces around the display  We now need to create a bread.
Computer Graphics I, Fall 2010 Transformations.
The Stingray Example Program CMT3311. Stingray - an example 2D game May be useful as a simple case study Most 2D games need to solve generic problems.
2D Graphics and Animations in Unity 3D
UMBC Graphics for Games
Physically Based Animation and Modeling
CO1301: Games Concepts Lecture 22 Particle Systems
Development of a particle system
Particle Systems - A Technique for Modeling a Class of Fuzzy Objects
CO Games Concepts Week 22 Particle systems
Game Programming Algorithms and Techniques
Presentation transcript:

1 Particle Systems for Games Particle System 3D MIM, hyeon

2 Particle System -William T. Reeves, Particle Systems : A Technique for Modeling a Class of Fuzzy Objects, SIGGRAPH 83. – Star Trek II - The Wrath of Khan The Genesis Demo sequence, 400 Particle Systems, 750,000 Particles

3 Revised by hyeon Particle Types Big particles Particles that have an area greater than a pixel Small Particles Smaller than a pixel Particles have no geometry Games usually use big particles in smaller quantities. Small particles are more for off-line effects.

4 Revised by hyeon 2D vs. 3D particles 2D Particles Easy to make using sprite system in XNA. Kinda the default version 3D Particles Particles are placed in space More complicated to implement as we will see 2D is easy and is the basis for the XNA examples. But, the particles don’t move when you move things on the screen!

5 Revised by hyeon What makes up a particle Position Where the particle is on the screen Velocity How fast it is moving. A vector in pixels. private Vector2 position; private Vector2 velocity; These are the basics, but there are other things that are very common.

6 Revised by hyeon

7

8

9

10 Revised by hyeon

11 Revised by hyeon

12 Revised by hyeon More complete particle public class Particle { private Vector2 position; private Vector2 velocity; private Vector2 acceleration; private float lifetime; private float age; private float scale; private float orientation; private float angularVelocity; /// /// Position of the particle in space /// public Vector2 Position { get { return position; } set { position = value; } } /// /// 2D particle velocity /// public Vector2 Velocity { get { return velocity; } set { velocity = value; } } // and more access properties…

13 Revised by hyeon Lifetime private float lifetime; private float age; Particles have a lifetime. They exist for a specific period of time, then disappear. They will fade out over the lifetime.

14 Revised by hyeon Scale and orientation Scale is how big particle is Orientation is angle to draw it Angular velocity is any spin private float scale; private float orientation; private float angularVelocity;

15 Revised by hyeon Initialization Function public void Initialize(Vector2 position, Vector2 velocity, Vector2 acceleration, float lifetime, float scale, float rotationSpeed, float orientation) { // set the values to the requested values this.Position = position; this.Velocity = velocity; this.Acceleration = acceleration; this.Lifetime = lifetime; this.Scale = scale; this.AngularVelocity = rotationSpeed; this.Age = 0.0f; this.Orientation = orientation; }

16 Revised by hyeon Particle updates (Euler Steps) /// /// Update for the particle. Does an Euler step. /// /// Time step public void Update(float delta) { // Update velocity Velocity += Acceleration * delta; // Update position Position += Velocity * delta; // Update orientation Orientation += AngularVelocity * delta; // Update age Age += delta; }

17 1 차 테일러 - 절단 오차 (truncation error)

18 Adaptive stepsize 두 구간 Δt Δt/2 et = |v1 - v2| h_new = h_old*sqrt(eto/et); dtnew = dt * sqrt(eto/et); 새 구간의 크기 if(dtnew < dt) // 더 작다면 루젠 쿠타 4 차

19 Revised by hyeon The ParticleSystem class We have a list of active particles. We add to it when we generate particles and we iterate over it to draw the particles. Note that there may be many particles created and destroyed at a rapid rate. Managed code systems use garbage collection. They don’t like things that allocate and deallocate at a very high rate of speed. This can cause pauses as the garbage collector churns! We’re going to keep a fixed number of particles that we just reuse rather than creating new ones all of the time. There will be live particles and available particles. Any suggested data structures? Note that lifetimes may vary.

20 Elements in the Particle System Particle System has role of managing and drawing particles – Features Scale Position of emitter Texture – Method Create and Dispose Particles Update Particles Render Particles

21 Revised by hyeon Lists of particles // The list of live particles private LinkedList liveParticles = new LinkedList (); // A list of available particles private LinkedList availableParticles = new LinkedList (); private void Initialize() { InitializeConstants(); for (int i = 0; i < howManyEffects * maxNumParticles; i++) { availableParticles.AddLast(new Particle()); } howManyEffects is how many active explosions or smoke puffs active at any time. maxNumParticles is the maximum particles for an effect.

22 Revised by hyeon Initializing Particles protected virtual void InitializeParticle(Particle p, Vector2 where) { // Determine the initial particle direction Vector2 direction = PickParticleDirection(); // pick some random values for our particle float velocity = RandomBetween(minInitialSpeed, maxInitialSpeed); float acceleration = RandomBetween(minAcceleration, maxAcceleration); float lifetime = RandomBetween(minLifetime, maxLifetime); float scale = RandomBetween(minScale, maxScale); float rotationSpeed = RandomBetween(minRotationSpeed, maxRotationSpeed); float orientation = RandomBetween(0, (float)Math.PI * 2); // then initialize it with those random values. initialize will save those, // and make sure it is marked as active. p.Initialize( where, velocity * direction, acceleration * direction, lifetime, scale, rotationSpeed, orientation); }

23 Revised by hyeon Update public void Update(double deltaTime) { float delta = (float)deltaTime; for (LinkedListNode node = liveParticles.First; node != null; ) { LinkedListNode nextNode = node.Next; node.Value.Update(delta); if(!node.Value.Active) { liveParticles.Remove(node); availableParticles.AddLast(node); } node = nextNode; }

24 Revised by hyeon Implementation

25 Revised by hyeon 3D Particles The same basic concepts apply, except that you have to:  Position, velocity, acceleration are all 3D, now  Draw texture mapped rectangles for particles  Use the alpha blending and turn off writing the depth buffer  Billboard the particles to face the viewer at all times 3D Particles will stay at the correct world position as you rotate the camera and are sensitive to occlusion

26 Particle and PointSprite Before DX 8.0, using Billboard ( always looks up the camera) Constructed by four vertices

27 Revised by hyeon Billboarding Forcing something to always face the view. Or more precisely: Forcing something to always face in direction (0, 0, 1) in the view coordinate system. Before we do anything, our particle texture is facing in the direction (0, 0, 1). W is a translation only, not a rotation. Any ideas?

28 Revised by hyeon Billboarding The view matrix will rotate us from the direction we want to be. We’ll just pre-rotate in the opposite direction. Matrix invView = camera.View; invView.Translation = Vector3.Zero; invView = Matrix.Invert(invView); Matrix world = Matrix.CreateScale(scale) * Matrix.CreateRotationZ(p.Orientation) * invView * Matrix.CreateTranslation(p.Position); effect.Parameters["World"].SetValue(world);

29 Revised by hyeon PointSprite

30 Revised by hyeon Draw – the Particle loop foreach (Particle3d p in liveParticles) { // Life time as a value from 0 to 1 float normalizedLifetime = p.Age / p.Lifetime; float alpha = 4 * normalizedLifetime * (1 - normalizedLifetime); // make particles grow as they age. they'll start at 75% of their size, // and increase to 100% once they're finished. float scale = p.Scale * (.75f +.25f * normalizedLifetime); Matrix world = Matrix.CreateScale(scale) * Matrix.CreateRotationZ(p.Orientation) * invView * Matrix.CreateTranslation(p.Position); effect.Parameters["World"].SetValue(world); effect.Parameters["Alpha"].SetValue(alpha); effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); device.DrawUserIndexedPrimitives (PrimitiveType.TriangleList, vertices, 0, vertices.Length, indices, 0, indices.Length / 3); pass.End(); } effect.End(); }

31 Revised by hyeon Particles also useful for  Fog with varying densities  Fountains  Rain  Snow  Dust  Clouds  Falling leaves  Blood spray  Etc…

32 Revised by hyeon Other things you can do Gravity – Just add an acceleration of (0, -980, 0). Bounce – If Y goes below a certain amount, mirror the Y for the position and reverse the Y for the velocity. Bounce with loss – After you bounce, multiply the velocity by a constant < 1 Energy – Add a value to the particle to indicate it’s energy. Lose energy over time and change the color based on the energy. Particles can be emitted in a shape. Replace your character with a bunch of particles in her shape, then let gravity do what it does best.