ParticleSystem and texture UV offset/scale?


I’m trying to make a particle system whose texture is taken from a sprite atlas. I’m doing it the naive way one might expect to work:

var ps = new ParticleSystem(name, capacity, scene)
var tex = // create texture..
tex.uOffset = 0.5
tex.uScale = 0.5
ps.particleTexture = tex

and so on. But the UV properties seem to be ignored for particle systems.

Is there some other way to do this, or is it not possible?

Playing around in the inspector I was not able to do this as well. Reading around on the forums I found some ideas. Perhaps a SolidParticleSystem? (SPS)

This might be what you are looking for: Animating Particles | Babylon.js Documentation

1 Like

I saw that, but it looks like it requires the sprite atlas to be constructed in one very specific way. I was hoping there might be a general solution I could use with existing assets?

I do not think that this is actually possible Adding @Deltakosh ?

1 Like

A thing is not impossible.

sorry for my bad english actually -> currently :slight_smile:

Actually is close from “Actuellement” in french which means currently… so hard :wink:

1 Like

Hey, so you would like your particle to pick a subset of the texture correct?
And each particle could have a different one?

I see a few options:

Hi DK, the goal is to choose a subset of the texture, and then the particleSystem would show that subset on all of its particles.

It looks like maybe the only current way to do this is with animated systems, like:

sys.isAnimationSheetEnabled = true
sys.spriteCellHeight = 32
sys.spriteCellWidth = 32
sys.startSpriteCellID = 
    sys.endSpriteCellID = 123 // or whatever

However that only works for sprite assets constructed one particular way. It won’t work if e.g. your sprites are not all the same size.

Yes I agree
other way (you may not like it):

  • Create a procedural texture (with nme or manually) that will extract from a given texture only a subset of it
  • Set that procedural texture to update only once (to pay the extraction cost only once)
  • Use that texture
  • Enjoy
1 Like