Hi,
I am playing with particle effects in GUI node.
I used the trick that @nehon provided some time ago:
flame.setQueueBucket(Bucket.Gui);
flame.setFaceNormal(Vector3f.UNIT_Z);
The trick works great!
But I noticed that particle sizes look strange on some occasions and decided to make a simple test case.
import com.jme3.app.SimpleApplication;
import com.jme3.effect.ParticleEmitter;
import com.jme3.effect.ParticleMesh.Type;
import com.jme3.effect.shapes.EmitterSphereShape;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.queue.RenderQueue.Bucket;
import com.jme3.scene.Node;
public class TestExplosionGuiEffect extends SimpleApplication {
public static void main(String[] args) {
TestExplosionGuiEffect app = new TestExplosionGuiEffect();
app.start();
}
private ParticleEmitter createFlame() {
ParticleEmitter flame = new ParticleEmitter("Flame", Type.Point, 32);
flame.setSelectRandomImage(true);
flame.setStartColor(new ColorRGBA(1f, 0.4f, 0.05f, 1f));
flame.setEndColor(new ColorRGBA(.4f, .22f, .12f, 0f));
flame.setStartSize(30f);
flame.setEndSize(40f);
flame.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
flame.setParticlesPerSec(0);
flame.setLowLife(8f);
flame.setHighLife(10f);
flame.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 7, 0));
flame.getParticleInfluencer().setVelocityVariation(1f);
flame.setImagesX(2);
flame.setImagesY(2);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
mat.setBoolean("PointSprite", true);
flame.setMaterial(mat);
flame.setQueueBucket(Bucket.Gui);
flame.setFaceNormal(Vector3f.UNIT_Z);
return flame;
}
@Override
public void simpleInitApp() {
ParticleEmitter emit1 = createFlame();
ParticleEmitter emit2 = createFlame();
ParticleEmitter emit3 = createFlame();
ParticleEmitter emit4 = createFlame();
emit1.setLocalTranslation(cam.getWidth() * 1f / 3f, cam.getHeight() * 1f / 3f, 0);
emit2.setLocalTranslation(cam.getWidth() * 1f / 3f, cam.getHeight() * 2f / 3f, 0);
emit3.setLocalTranslation(cam.getWidth() * 2f / 3f, cam.getHeight() * 1f / 3f, 0);
emit4.setLocalTranslation(cam.getWidth() * 2f / 3f, cam.getHeight() * 2f / 3f, 0);
Node explosionEffect = new Node("explosionEffect");
explosionEffect.attachChild(emit1);
explosionEffect.attachChild(emit2);
explosionEffect.attachChild(emit3);
explosionEffect.attachChild(emit4);
renderManager.preloadScene(explosionEffect);
guiNode.attachChild(explosionEffect);
emit1.emitAllParticles();
emit2.emitAllParticles();
emit3.emitAllParticles();
emit4.emitAllParticles();
}
}
Note the 4 particle emitters are the same, but depending on their position on the screen, they are larger/smaller.
This only happens if point sprite particles are used, other cases work perfectly OK.
I suppose this is a bug in the particles shader. And since I am not at all a shader master, I am posting this here, so someone could take a look and maybe come up with a fix.
Thanks!
PS: This is JME 3.1.