Particle System - How to Store Particle Age?

Warning! Some information on this page is older than 3 years now. I keep it for reference, but it probably doesn't reflect my current knowledge and beliefs.

Dec 2012

Particle System - How to Store Particle Age?

Particle effects are nice because they are simple and look interesting. Besides, coding it is fun. So I code it again :) Particle systems can have state (when parameters of each particle are calculated based on previous values and time step) or stateless (when parameters are always recalculated from scratch using fixed function and current time). My current particle system has the state.

Today a question came to my mind about how to store age of a particle to delete it after some expiration time, determined by the emitter and also unique for each particle. First, let's think for a moment about the operations we need to perform on this data. We need to: 1. increment age by time step 2. check if particle expired and should be deleted.

If that was all, the solution would be simple. It would be enough to store just one number, let's call it TimeLeft. Assigned to the particle life duration at the beginning, it would be:

Step with dt: TimeLeft = TimeLeft - dt
Delete if: TimeLeft <= 0

But what if we additionally want to determine the progress of the particle lifetime, e.g. to interpolate its color of other parameters depending on it? The progress can be expressed in seconds (or whatever time unit we use) or in percent (0..1). My first idea was to simply store two numbers, expressed in seconds: Age and MaxAge. Age would be initialized to 0 and MaxAge to particle lifetime duration. Then:

Step with dt: Age = Age + dt
Delete if: Age > MaxAge
Progress: Age
Percent progress: Age / MaxAge

Looks OK, but it involves costly division. So I came up with an idea of pre-dividing everything here by MaxAge, thus defining new parameters: AgeNorm = Age / MaxAge (which goes from 0 to 1 during particle lifetime) and AgeIncrement = 1 / MaxAge. Then it gives:

Step with dt: AgeNorm = AgeNorm + dt * AgeIncrement
Delete if: AgeNorm > 1
Progress: Age / AgeIncrement
Percent progress: AgeNorm

This needs additional multiplication during time step and division when we want to determine progress in seconds. But as I consider progress in percent more useful than the absolute progress value in seconds, that's my solution of choice for now.

Comments (1) | Tags: math rendering | Author: Adam Sawicki | Share


2016-03-29 08:56:54
my first time to Shanghai, to help me find a dozen dollars hostel, please?"So, to accompany her to find hostels. At 7:00 pm was staying in a cheap hostel but also 40 yuan a night. I want to leave, she let go, her eyes riveted on me, repeated the phrase: "? I first came to Shanghai, you spend time with me, please" like to see her, I could not help students from compassion heart of. I inserted through the team in Jiangxi Province. Twenty years of joint swelling and pain can not walk, the production team with a dray uncle sent me to commune health centers for treatment. Now the little girl and I was not also the case with what? A single person, in need of help, I can not ask her? I went to apply for a stay formalities, she lives upstairs, I live downstairs. I went to the supermarket to buy two sets of towels, toothbrush, toothpaste, they have to spend to stay.After dinner, I go with her to the supermarket plaza. The first time I saw so many customers, bustling crowd, her age girl wearing Western style fashion, she was very envious. The first elevator ride elevators and stairs room, gesticulating see so many people standing looking at her surprised. First sat on a long bench enjoying central air conditioning blowing cool breezes, her temperament is particularly comfortable. She opened the door panel of the soul, to tell me her story. Her surname situation, 24 years old this year, who lives in Jiangxi Nanshan District, poor economic conditions at home, and nothing good local place to make moneI heard that Shanghai life is better, earn more, she charmed one day to see. The village has seen young men and women to go to Guangzhou, Shanghai to work, she echocardiography. But mother does not agree, do not trust her to go out alone. That day, she and her mother had a big fight. At night, while sleeping parents left home alone, by car, by train, they go to work in Shanghai Pudong cousin. In Shanghai, because the address does not have to call home to ask, he said, can not find the address of the first to come back, her mother fell ill in bed, so he had to return. In the road to the train station, a brother lie to her on the bus, turn a long time to ask for 100 dollars. In the car, but also hands and feet, touched her breasts. She was afraid. Later I met, I feel like her cousin, honest, caring, considerate. Come here and opened the eyes, I feel very happy. I said, you yearn for Fu-life is right. Now your mother sick, certainly you do not worry. You can go home and talk to my mother, reassured her, and then you come to Shanghai. A girl is not easy to Shanghai to work, to learn skills, to adapt to the urban environment as soon as possible, but also pay attention to protect themselves. As long as they work hard, work hard, you will succeed.Back to Hostel has 10 points. In her room,

Post comment

Nick *
Your name or nickname
Your contact information (optional, will not be shown)
Text *
Content of your comment
Calculate *
(* - required field)
STAT NO AD [Stat] [Admin] [STAT NO AD] [pub] [Mirror] Copyright © 2004-2017 Adam Sawicki
Copyright © 2004-2017 Adam Sawicki