Help needed to create a starfield in the scenegraph

Hello Monkeys,

I am trying to create a starfield background for a Space project I have in mind. However, I have not had much success with the cube skybox as it makes the stars look boxy and rather unrealistic.


I’d like to generate a star field of points in the scene graph. I’d like some 50K stars, I guess. Putting 50K points into SpaceScape gives a very nice starfield. I think Celestia has about 100K stars.

I’d like to know the best way to do this. Low memory consumption would be of interest.

Some of the ways I have thought of doing it are:

  1. Plot quads across the background. But since each quad becomes a spatial, that would be a lot of memory for the 50K stars I would like to generate.
  2. Mesh of dots - There appears to be methods to make a wireframe mesh. There are also methods to set the point size and line width. A point size of say two and a line width of zero might do the trick. That would possibly only mean one Vector3f for each dot. I would like confirmation on this one before trying to tackle a 50K-vertex mesh.
  3. The Line class seems to have a lot of other objects in it too which would consume memory if many lines were drawn. I was thinking of drawing small asterixes. For 50K stars, I would need about 150K lines.

    Other than that I have run out of ideas. So I hope someone can give me some advice on how to get a good result. Thanks.

I suggest using a particle emitter or point emitter, which is basically a mesh of dots.

Not sure about your requirements, but I would still suggest going image route. For stars alone, there are many options, but you will probably soon like to add nebulas etc.

Black backgrounds with dots are boring, even if more realistic :wink:

Particle emitters are images on quads…

Yeah you might want to check TestPointSprite, it might be what you’re looking for

Hi again Monkeys,

Many thanks for the tips on how to generate a star field, and yes, the particle emitter seemed to be quite promissing. By making a star texture and setting up the emitter, I was able to make jets of stars, star water falls and even a galaxy generator on a small scale. From there I was hoping to be able to map the particles out into my scenegraph, out to about 90% of “frustumFar”, but when I tried to do a …

particle.position = new Vector3f(x, y, z);

The IDE politely told me that the “position” variable was final and couldn’t be written to. Grrrrr.

Any chance of putting setters into the so we can set the particle position manually? Setters would also be good for color and size (in my case). As the stars are stationary, no need at this stage for velocities etc.

I have downloaded a star database of some 50K stars. I’d like to map these out around the “frustumFar” limit of my scene graph with texture size proportional to star brightness. That way it should be easy to make out constellations in the game, and thus navigate to some extent. I think it would be quite cool to look out your ship window to see ORION, or the Southern Cross off to the left.

The starfield node would be attached to the player and move with the players ship so as not to be lost from sight.

I was getting 700 frames per second on 10,000 (moving) stars, which I thought was pretty good.

If I can’t set the particle positions from code, then the particle emitter would seem to be useless (to me) as a starfield generator.

I could do it using quads set up as spatials, but I fear the memory requirement for that would be fairly hefty, and it may impact FPS. But I guess testing will settle that question.

For @abies:

Regarding games like EVE, Homeworld and the likes. Hasn’t it ever struck you as being strange that every scene in these games has fantastic nebulae and other exotic space anomalies. Almost no scenes are just stars, and yet, space … for the most part … is just stars. I often think the thirst for eye candy had blinded most to what reality actually is. I’d like to come closer to reality, if I can … something like Celestia, for me, would be fine.

I look forward to suggestions on this. Thankyou.

You can modify position like so:

[java]particle.position.set(x, y, z);[/java]

Fantastic … and while on the subject … how about changing color and size? Same way?

I should have looked at the Javadoc before posting a question. Sorry.

I have now seen from the javadoc that the color object can be manipulated by the object’s setters and getters, and the size float is not final. So that seems to be just what I need.

I have run a test on the starfield setting individual positions and the outcome was very pleasing.

BTW, I tried the whole setup using Quads as Geometry and it looked shockingly terrible, … and it ran at … 1 fps for 10.000 quads :frowning:

Well, I suspected as much. [note: my laptop was running on battery and had swapped from the ATI Radeon card to the Intel card when the test was done, that may have had a significant bearing on the low fps too].

Thanks for pointing me in the right direction and thanks for a cool API.

Yeah … The particles are much faster because its 1 object per many particles, while when using quads its 1 object per 1 particle essentially.

I’ve been trying to achieve a starfield effect too, and I’ve used the posts in this thread to point me in the right direction: using a particle emitter.

In order to achieve the effect of the stars being way off in the distance, I’ve iterated the particles, checked their position, and moved them to a random far away location if they are too close to the camera. Is this the most efficient way? Is there perhaps a better way of specifying a “hollow” section of my EmitterSphereShape, where the particles shouldn’t be initially generated?

I’ve also been thinking about how to move the starfield, but then I read this:

alfinete said:
The starfield node would be attached to the player and move with the players ship so as not to be lost from sight.

I'm intending on having a first person view, rather than third, so there won't be a "ship" as such. Should I just create an invisible node, keep it at the same position as the camera, and attach the starfield to that? Normally I'd go away and try this part before asking, but since I'm here I thought I might as well ask..! :D

Any advice is really appreciated as I'm still really trying to get my head around this stuff :)

Thanks a lot.


Actually I still wonder, what the initial problem with the Skybox is, if you create a good one it looks really great. That combined with a few particles for nearer stars so that the horizon changes and you are basically ready to go. (zoom in to see full detail of the image)

Depending on size you could either move it with the player, so you dont hit the edge, or you leave it static, so that from different parts of the space the constelations of the stars are different.

Thanks for the quick reply! My first attempt involved a skybox, but it looked pretty bad… :frowning: To be honest, the reason for that is probably just my lack of understanding. I guess I just assumed after reading this thread that skybox wasn’t suitable in this situation.

Ideally I’d like to use a skybox as it seems much lower maintenance! I will have another look at the docs and tutorials. I don’t suppose anyone has any useful “gotchas” for skybox? Or some useful resources?

Thanks so much for the help :slight_smile:

Yes … the skybox can look really nice and can run at good fps. However, the problem that led me away from the skybox was the fact that a “sun” I had created on a quad was “punching through” the sky box thus causing a square black hole in the skybox texture. It looked really bad. If you open the link to the photo on the first post of this thread, you will see what it looked like. The quad representing the sun was textured with a png image with transparency to represent the sun’s flare. The transparent areas of the quad were being shown as black, thus not showing through the colors of the starfield. I guess this is because the skybox is rendered first.

Now this was a while ago, so the jMEngine may have had that fixed. If so, it will be a nice viable alternative again. If not, then the starfield generation via particle emitter is the way to go … for me, at least.

For my app, I would need to have the sun seen against different parts of the sky box as the camera position moves to different parts of space.

I hope this helps you to understand the reason for the thread.

SpaceScape if you are on windows is my suggestions for starting a skybox(at least for space or at night skyboxes)

SpaceScape is really good, been using it for my fun project as well. Just make sure you export it in sufficient texture resolution (I recommend 1024x1024). :slight_smile: