Author Topic: Blur on some objects (Fire/Explosion effect)  (Read 1092 times)

Offline Andrey8000

  • byte
  • *
  • Posts: 13
    • View Profile
Blur on some objects (Fire/Explosion effect)
« on: June 06, 2013, 12:45:51 pm »
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?

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Blur on some objects (Fire/Explosion effect)
« Reply #1 on: June 06, 2013, 01:07:06 pm »
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.

Offline pigoto

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Blur on some objects (Fire/Explosion effect)
« Reply #2 on: June 07, 2013, 03:47:08 am »
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:

Code: [Select]
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:

Code: [Select]
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:

Code: [Select]
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]

Offline Andrey8000

  • byte
  • *
  • Posts: 13
    • View Profile
Re: Blur on some objects (Fire/Explosion effect)
« Reply #3 on: June 07, 2013, 12:41:22 pm »
2 pigoto. It's great, but how about performance when so many objects?

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Blur on some objects (Fire/Explosion effect)
« Reply #4 on: June 07, 2013, 01:10:58 pm »
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:


Offline pigoto

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Blur on some objects (Fire/Explosion effect)
« Reply #5 on: June 07, 2013, 02:35:38 pm »
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.