1

i want to draw a particle system on Android, where the particles are continuously flowing from a specified point. without shaders i'm able to get that by checking for life of particle. if life is zero then reset the position to the center.

how to achieve the same with shaders?? i took a lifetime variable to keep track whether particle is alive. once particle is dead, i want reposition particle around the specified point. this lifetime will be random for each particle, is there any way i can achieve this with shaders??

to make my question easy to understand, for example i want to implement NeHe lesson 19 (Please see DrawGLScene of lesson 19)with Shader....

Full code of my work can be found below for reference

1)No Shaders

2)With Shaders

sravan
  • 138
  • 1
  • 10
  • First explain why you need the previous position, it is not clear how it is relevant to the the rest of the info you provided – ognian May 25 '11 at 04:59
  • without using shaders, i updated position of each particle in for loop and i maintained a variable 'life', when life hits zero, i reset position to center(from where the particles are flowing). if you like to see the code, i'll post it – sravan May 25 '11 at 08:17
  • i used a thread to update the positions of particles, thread maintains the 30FPS update speed – sravan May 25 '11 at 08:40
  • if the center position is common for all particles, then can't you just push it as an uniform? posting some code always helps – ognian May 25 '11 at 09:30
  • i have updated question, added code part – sravan May 25 '11 at 10:11
  • Is `rnd()` a helper function for getting a random number? If so, why do you need the previous position when you return to a random position when life<=0 ? – ognian May 25 '11 at 10:50
  • with rnd(), i'm just making sure that the particle do not start at same position(i just dont want to fix on center position). `rnd(min,max)` to use a bit of variation in starting position around the center point. variation is not huge, as you can see its between 0 to 0.5 – sravan May 25 '11 at 11:00
  • for reference please follow the links for full code:::[particles No Shader](http://code.google.com/p/sravan-work/source/browse/#svn%2Ftrunk%2FOpenGL%20ES2%2Fparticle_test)............... [With Shader](http://code.google.com/p/sravan-work/source/browse/#svn%2Ftrunk%2FOpenGL%20ES2%2Fes2particles) – sravan May 26 '11 at 01:26

2 Answers2

2

Thanx everybody,

i found out a solution after struggle for total sat'day...

now i'm doing all the calculation in vertex shader based on time

i'm calculating the time at particle will die and mod with current time will give the modified time frame...

basically each particle will live its life time again n again

code can be found at google code directory

Thanq one all for trying to solve my problem

sravan
  • 138
  • 1
  • 10
0

You have to update LifeTime of particple in Draw function on every draw and then pass it to shader with GLES20.glVertexAttribPointer as "attribute float a_lifetime;" ,for example.

look at this source SOURCE

Yuriy Vikulov
  • 2,469
  • 5
  • 25
  • 32
  • thanx, i took the same idea from the source you have mentioned, but my question was, once lifetime hit zero how to re-position the particle at the center (for continuous flow of particles), since lifetime will be random in my case. so each particle will die at different time, so need to spawn(position them to origin) them individually – sravan May 27 '11 at 08:19