Blur on some objects (Fire/Explosion effect)

Started by Andrey8000, June 06, 2013, 12:45:51 PM

Previous topic - Next topic

Andrey8000

Hello, how can i make blur effect on some objects in JPCT-ae? I need it to create explosion effect in my game.
Or may be glow effect around object?

EgonOlsen

A blur effect requires render to texture and a custom shader for a post-processing blur effect. That can get complicated and performance will suffer on anything but the latest and greatest devices. A glow effect is easier and can be obtained by adding a bill boarded plane with a transparent texture and additive blending.

pigoto

If it helps, I just made a glow affect; I'm working on a sort of cloud thing.. which is hard to describe, but at the moment it's a ball of random glowing balls so might be similar to what you're after.

This is an object that glows:

class CloudParticleGlow extends Object3D {
private static final long serialVersionUID = 1L;
private static Object3D glow = null;
private static float offset = 1.8f;
    private static float zoffset = 0.4f;


CloudParticleGlow(String texture) {
    super(glow);
    glow = new Object3D(2);
glow.addTriangle( new SimpleVector( -offset, -offset, -zoffset ), 0, 0,
                           new SimpleVector( -offset, offset, -zoffset ), 0, 1,
                           new SimpleVector( offset, offset, -zoffset ), 1, 1,
                           TextureManager.getInstance().getTextureID( texture ) );
glow.addTriangle( new SimpleVector( offset, offset, -zoffset ), 1, 1,
                           new SimpleVector( offset, -offset, -zoffset ), 1, 0,
                           new SimpleVector( -offset, -offset, -zoffset ), 0, 0,
                           TextureManager.getInstance().getTextureID( texture ) );
   
glow.setBillboarding(Object3D.BILLBOARDING_ENABLED);
glow.setTransparency(5);
glow.setLighting(Object3D.LIGHTING_NO_LIGHTS);
glow.setAdditionalColor(new RGBColor(255, 255, 255));
glow.build();
  }

}


This is an invisible "container" that I made the parent of my glow object:

class CloudParticle extends Object3D {
private static final long serialVersionUID = 1L;
private static Object3D particle = null;

  static {
  particle = Primitives.getCone(0.3f);
  particle.setTransparencyMode(Object3D.TRANSPARENCY_MODE_ADD);
  particle.setTransparency(0);
  }

  CloudParticle() {
    super(particle);
  }

}


I created an array of each, with both arrays the same size; I make each Particle the parent to the equivalent Glow, and I make every first item in the particle array the parent of all other particles:

particles = new CloudParticle[particleCount];
glow = new CloudParticleGlow[particleCount];

for (int i = 0; i < particleCount; i++) {
String texture = "glowgreen";
switch (rand.nextInt(3)) {
case(0):
texture = "glowred";
break;
case(1):
texture = "glowblue";
break;
case(2):
texture = "gloworange";
break;
}

particles[i] = new CloudParticle();
glow[i] = new CloudParticleGlow(texture);
particles[i].addChild(glow[i]);
world.addObject(particles[i]);
world.addObject(glow[i]);

if (i > 0) {
particles[0].addChild(particles[i]);
}


I can then rotate or move an individual particle or all to move individual glows, or I can move the central particle to move everything.

This is in progress but I think with the right texture and movement could be expanded for fire / explosion.

[attachment deleted by admin]

Andrey8000

2 pigoto. It's great, but how about performance when so many objects?

EgonOlsen

You don't need that many objects to create a simple glow (like the glow of a light source). One plane is sufficient to create something like this:


pigoto

Yes there's quite a few objects in mine! I think the example I gave was using a high number as I was messing around. I've got about 20 of those particles to create a nice glowy cloud. I'm removing the cone now as I found it was a bit pointless and didn't quite do what I wanted so that will decrease it further.