Jump to content

Beginning with Particles


Josh

1,509 views

 Share

I wanted to work on something a bit different, and this sure is different. I've got a framework of a new particle system worked out. What's really special about this system is the amount of interactivity the particles will allow.

  • Particle-world collisions.
  • Particle-particle collisions (repulsion)
  • Particle-particle cohesion (fluids with surface tension)

Instead of just being a visual effect, I want our new particles to be fully interactive with physics so that particles can exert forces on objects. This will allow you to simulate fluids, smoke, and other effects in a realistic manner, not just dumb collision of particles bounding off walls. It should even be possible to simulate hydrophobic and hydrophillic liquids if you mix two together with different cohesion values.

Basically what I want is something like Nvidia Flow on the CPU and exerting forces on the world. So if you had water falling on a water wheel the wheel would move because of the forces, or a blast of wind could knock objects over without any special force fields or other fake effects.

I also have a technique worked out that will allow lighting of clouds and other masses of gas, with back-scattering.

Emitters can be instanced so if you have one really high-quality torch effect, for example, you can instance it and use it as much as you like without any additional computational cost per instance.

Particle emitters can be controlled with a Lua script or C++ actor. Two new functions are available, UpdateParticle() and EmitParticle(). Here is a script that controls particle behavior over time:

entity.particleVelocity = Vec3(0,0,1)
entity.particleAcceleration = Vec3(0,-1,0)
entity.inverseSquareFalloff = true
entity.particleRadiusBegin = 0.1
entity.particleRadiusEnd = 0.2
entity.particleColorBegin = Vec4(1,1,1,1)
entity.particleColorEnd = Vec4(1,1,1,0)
entity.particleMass = 1
entity.particleSpin = 5

function entity:Start()
    self.particleColorBeginHSL = HSL(self.particleColorBegin.rgb)
    self.particleColorEndHSL = HSL(self.particleColorEnd.rgb)
    local emitter = Emitter(self)
    if emitter == nil then return end
    local n
    for n = 1, #emitter.particles do
        emitter.particles[n].mass = self.particleMass
        emitter.particles[n].falloff = (n-1) / (#emitter.particles - 1)
    end
end

function entity:EmitParticle(index)
    local emitter = Emitter(self)
    if emitter == nil then return end
    emitter.particles[index].position = self:GetPosition(true)
    emitter.particles[index].velocity = TransformVector(self.particleVelocity,self,nil)
    emitter.particles[index].radius = self.particleRadiusBegin
    emitter.particles[index].color = self.particleColorBegin
end

function entity:UpdateParticle(index)
    local emitter = Emitter(self)
    if emitter == nil then return end
    emitter.particles[index].velocity = emitter.particles[index].velocity + self.particleAcceleration / 60
    local falloff = emitter.particles[index].falloff
    if self.inverseSquareFalloff then falloff = falloff * falloff end
    emitter.particles[index].color.rgb = RGB(self.particleColorBeginHSL * (1 - falloff) + self.particleColorEndHSL * falloff)
    emitter.particles[index].color.a = self.particleColorBegin.a * (1 - falloff) + self.particleColorEnd.a * falloff
    emitter.particles[index].radius = self.particleRadiusBegin * (1 - falloff) + self.particleRadiusEnd * falloff
    emitter.particles[index].rotation = emitter.particles[index].rotation + self.particleSpin / 60
end

A different script could be used to make particles emit from vertices of a model, to make the model appear to be on fire, or other effects. This will allow infinite customization to create any behavior you want.

Particle physics will be calculated on the physics thread so I expect them to be very fast.

  • Like 7
 Share

3 Comments


Recommended Comments

Would it be possible for emitters to be created via an editor and then have it's values saved to a json/binary file?

The particle editor in Leadwerks was really weak and pretty much had you had to code each effect to get most out of the system.

Link to comment

I see the "values" as being script-defined properties. I am offloading all the particle features and settings into Lua scripts so that there is no limit on the features particles can support..In LE4 we had fixed emission volumes, in the new engine you can add a script for a new emission shape of your own, or whatever you want.

Does that make more sense now?

Link to comment

Yeah. We can always write the particle script once and attach the script to a particle entity. I could do a wrapper function like LoadParticle(<scriptpath>) and have it return an emitter.

Still suggesting a visual editor in the future. Doesn't have to be in the 1.0 release, but it would be a lot more efficient in work flow. ?

Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...