Author Topic: Point Sprites  (Read 1765 times)

Offline PeterRadkov

  • byte
  • *
  • Posts: 2
    • View Profile
Point Sprites
« on: December 01, 2011, 09:33:03 am »
Hi All,

  Is there support for point sprites in jPCT?
  Is there support for different blending modes as in Java3D?
  Is there support for something like Behaviors in Java3D?

Thanks.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: Point Sprites
« Reply #1 on: December 01, 2011, 10:01:11 am »
To keep it short:

  • No
  • Yes
  • No

Offline PeterRadkov

  • byte
  • *
  • Posts: 2
    • View Profile
Re: Point Sprites
« Reply #2 on: December 01, 2011, 11:01:52 am »
  Thanks a lot for the prompt reply.
  Another question - what would be a good approach to build effects rich arcade game like Gatling Gears with jPCT, approaching it from the effects side? Lots of smoke and explosions and destruction on a small (screen size) scale?
Would it involve heavy use of shaders? Would all the particles have to be modeled as quads in order to achieve good effects?

Thanks.

To keep it short:

  • No
  • Yes
  • No

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: Point Sprites
« Reply #3 on: December 01, 2011, 12:16:55 pm »
Personally, i'm using single billboarded objects that consist of one triangle only for this. You can find this approach in all my free sources that make use of particles like Robombs or Alien Runner. However, i'm very well aware that this isn't the optimal solution. It would be much more efficient to implement it in a way that one object contains all the particles instead, but that's so cumbersome to implement that i never did it. The current solution was fast enough (tm) for me so far...
IF one wants to do this, shaders might ease it a lot, because the billboards can be created in the shader instead of using some IVertexController or something so that it will be more efficient.
« Last Edit: December 02, 2011, 06:51:07 am by EgonOlsen »

Offline AGP

  • quad
  • ******
  • Posts: 1518
    • View Profile
Re: Point Sprites
« Reply #4 on: December 02, 2011, 01:59:06 am »
A minor nitpick: I think you meant it's not the "optimal" solution.

And an all- (or lots-) encompassing particles class would be really awesome (you could specify the texture of the particle and things like density and choose between different behaviors like spiraling up or or a wiggly movement or so). And of course you could set translation, rotation, and such. Just as long as the subject was brought up. :- )

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: Point Sprites
« Reply #5 on: December 02, 2011, 06:52:24 am »
A minor nitpick: I think you meant it's not the "optimal" solution.

And an all- (or lots-) encompassing particles class would be really awesome (you could specify the texture of the particle and things like density and choose between different behaviors like spiraling up or or a wiggly movement or so). And of course you could set translation, rotation, and such. Just as long as the subject was brought up. :- )
Thanks. Sometimes, i'm typing funny things without noticing it....and yes, i agree: A particle system would be nice...i'm still waiting for somebody to come up with an implementation... ;)

Offline AGP

  • quad
  • ******
  • Posts: 1518
    • View Profile
Re: Point Sprites
« Reply #6 on: December 02, 2011, 07:42:05 am »
That sounded like a challenge to me. If I weren't so busy right now I'd try my hand at it. But hey, if only we knew the developer of jpct... :- )

Offline AGP

  • quad
  • ******
  • Posts: 1518
    • View Profile
Re: Point Sprites
« Reply #7 on: December 02, 2011, 07:08:15 pm »
I made a quick LWJGL port of a fountain particle system. I skipped the texture bit (added a 1001 int value in place of a proper texture reference) for faster result.

Code: [Select]
/**
Simple LWJGL port of NatureWizard's fountain particle system (ORIGINAL CAN BE FOUND AT http://www.naturewizard.com/tutorial08.html)
Ported BY AGP (BR) ON Dec. 02, 2011
*/

import org.lwjgl.opengl.*;
import org.lwjgl.LWJGLException;

public class ParticleSystem {
     private Particle[] particle;
     public ParticleSystem() {

try {
     Display.setDisplayMode(new DisplayMode(800,600));
     Display.create();
}
catch (LWJGLException e) {System.out.println("Could not create display. ");e.printStackTrace();System.exit(1);}
particle = new Particle[10];

for (int i = 0; i < particle.length; i++)
     createParticle(i);
loop();
     }
     public void createParticle(int i) {
particle[i] = new Particle();
particle[i].lifetime= (float)Math.random()*500000.0f;
particle[i].decay=0.001f;
particle[i].r = 0.7f;
particle[i].g = 0.7f;
particle[i].b = 1.0f;
particle[i].xpos= 0.0f;
particle[i].ypos= 0.0f;
particle[i].zpos= 0.0f;
particle[i].xspeed = 0.0005f-((float)Math.random()*100)/100000.0f;
particle[i].yspeed = 0.01f-(float)Math.random()*100/100000.0f;
particle[i].zspeed = 0.0005f-(float)Math.random()*100/100000.0f;
particle[i].active = true;
     }
     public void evolveParticle() {
for (int i = 0; i < particle.length; i++) {      // evolve the particle parameters
     particle[i].lifetime-=particle[i].decay;
     particle[i].xpos+=particle[i].xspeed;
     particle[i].ypos+=particle[i].yspeed;
     particle[i].zpos+=particle[i].zspeed;
     particle[i].yspeed-=0.00007;
}
     }
     public void drawObjects() {
// rendering functions
GL11.glLoadIdentity();
GL11.glRotatef(50.0f,1.0f,0.0f,0.0f);         // show scene from top front
GL11.glBindTexture(GL11.GL_TEXTURE_2D,1001);          // choose particle texture
for (int i = 0; i < particle.length; i++){
     if (particle[i].ypos < 0.0f)
particle[i].lifetime = 0.0f;
     if (particle[i].active==true && particle[i].lifetime > 0.0f) {
GL11.glColor3f(particle[i].r,particle[i].g,particle[i].b);
GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
GL11.glTexCoord2f(0.0f, 1.0f); GL11.glVertex3f(particle[i].xpos+0.002f, particle[i].ypos+0.002f, particle[i].zpos+0.0f);     // top    right
GL11.glTexCoord2f(0.0f, 0.0f); GL11.glVertex3f(particle[i].xpos-0.002f, particle[i].ypos+0.002f, particle[i].zpos+0.0f);     // top    left
GL11.glTexCoord2f(1.0f, 1.0f); GL11.glVertex3f(particle[i].xpos+0.002f, particle[i].ypos-0.002f, particle[i].zpos+0.0f);     // bottom right
GL11.glTexCoord2f(1.0f, 0.0f); GL11.glVertex3f(particle[i].xpos-0.002f, particle[i].ypos-0.002f, particle[i].zpos+0.0f);     // bottom left
GL11.glEnd();
     }
     else createParticle(i);
}
evolveParticle();
     }
     private void loop() {
while (!Display.isCloseRequested()) {
     drawObjects();


     Display.update();
}
Display.destroy();
     }
     public static void main(String[] args) {

new ParticleSystem();
     }
}
class Particle {
     protected float lifetime;                       // total lifetime of the particle
     protected float decay;                          // decay speed of the particle
     protected float r,g,b;                          // color values of the particle
     protected float xpos,ypos,zpos;                 // position of the particle
     protected float xspeed,yspeed,zspeed;           // speed of the particle
     protected boolean active;
}


Offline AGP

  • quad
  • ******
  • Posts: 1518
    • View Profile
Re: Point Sprites
« Reply #8 on: December 02, 2011, 07:59:41 pm »
Also, there's a stupid part in which I multiplied the result of Math.random() by 100 and divided by 100,000 (just multiplying by .001 should produce the same effect, only a lot faster), but I wanted to keep the code similar to its C counterpart.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: Point Sprites
« Reply #9 on: December 03, 2011, 09:31:10 am »
This is not really applicable as it doesn't fit into jPCT's rendering pipeline, it uses immediate mode (slow, not available on Android) and because each particle is a set on individual draw calls, i doubt that it's actually faster than what you can achieve with simple implementation based on Object3Ds.

Offline AGP

  • quad
  • ******
  • Posts: 1518
    • View Profile
Re: Point Sprites
« Reply #10 on: December 03, 2011, 04:44:05 pm »
I know, I told you I'm busy. It was just a good, quick, exercise.