Render Point Sprites without emitter or factory

I want to display a single point sprite, with a given texture, at a given location.

I’ve looked through the tutorials and documentation, but they all seem to use a ParticleEmitter or ParticleFactory to generate many sprites - For what I want, I’ll be rendering many particles, but all at specific locations, and I’d like to add them one by one. Is there example code to create and render a single point sprite at a given location, and is it significantly slower than using an emitter?

There are no examples. You have to make your own Mesh of type Points. http://hub.jmonkeyengine.org/javadoc/com/jme3/scene/Mesh.Mode.html#Points

Then give it a Particle.j3md material with the right texture, etc…

You can look at the code to the particle stuff to see how to setup the other mesh buffers that the particle material expects. (Or if you know how then you can write your own shader but it’s easier just to use the existing one).

As I recall, you will need Position, Size, TextureCoord (with a Vec4 to define two corners instead of the normal Vec2), and Color.

Oh, and you will have to set the Quadratic float on the Material to something. I think I set mine to 6. This somehow controls how fast the sprites scale with distance.

1 Like

Thanks! That worked, and it looks great. One more problem, though: All the particles except one are red, and the one nearest the camera is green. I looked at Particle.jm3d and I don’t see how to edit the color if it’s not specified in the texture; the texture I’m using is grayscale, and I tried it both with a grayscale (8-bit) texture and a 24-bit texture.

Do you have a Color buffer in your mesh?

1 Like

I didn’t, but now I do, and it works fine! Thanks for the help! :smiley:

So, another unrelated problem: can these sprites on a point mesh not be “picked”? And if not, how else will I determine what object the player is clicking on?

You have to do picking yourself. There is no mesh to pick, really. Points are unpickable using standard collision detection.

Can I ask why you used points sprites to begin with instead of quads or something?

1 Like

Yeah, just use billboarded quads and then picking becomes easy (although they use more resources than the point sprites).

1 Like

I’m using point sprites at the moment because, as far as I can tell, they’re the fastest way to display sprites at given locations constantly facing the player. If Ray.distanceSquared(Vector3f point) does what I think it does, I should be able to implement picking very easily, but I have no idea if it’ll be anywhere near as fast as OGL picking.

Given that I’ll have anywhere from 1000-10000 sprites to interact with, in terms of performance, should I use quads or just implement picking?

btw, thanks!

@ShivanHunter said: I'm using point sprites at the moment because, as far as I can tell, they're the fastest way to display sprites at given locations constantly facing the player. If Ray.distanceSquared(Vector3f point) does what I think it does, I should be able to implement picking very easily, but I have no idea if it'll be anywhere near as fast as OGL picking.

Given that I’ll have anywhere from 1000-10000 sprites to interact with, in terms of performance, should I use quads or just implement picking?

btw, thanks!

You could batch the quads and it would be lighting fast… but you’d have to implement the billboarding in a .vert shader. You could do it in code on the CPU but it would be much slower.