3D Nebula Graphics (How-to)

If you’re interested in finding a good way to implement a realistish looking nebula, look no further :stuck_out_tongue:

So searching for a good solution to making a cool looking nebula I found this video which explains a pretty neat techinique very well, imo. The trick appears to be using a small amount of big quads and additively blending them while a dot product adjusts their opacity to hide unwanted edges. See here if interested:

My results:
Pretty good I’d say:

Sometimes they spawn with a bit too many quads(some parameters need tweaking):

But this does look awesome from the inside:

I haven’t tried making any real huge ones yet but my implementation seems to perform quite well :smiley: I can provide code if needed, but It’s a bit amateurish haha


Awesome find!

1 Like

This is brilliant, and thanks for posting it here

You guys have helped me out so much that it’s only appropriate for me to give some back :slight_smile:

Some shots after I got the values under control, added some alternative cloud textures and made some ginormous ones:

There are still some corner cases where the edges might become visible again if the textures aren’t transparent enough so don’t give up if the effect doesn’t look as good the first time, maybe try again with other images, or edit them.

The material config:

		Material cloud = new Material(CPU.game.getAssetManager(),"Common/MatDefs/Misc/Unshaded.j3md");
		cloud.setTransparent(true); // not sure if this does anything but what the hell :)

Awesome effect, and great find!

One question though. The video mentions scaling the alpha with respect to the dot product of the camera vector to the quad normal. Are you doing that? I would imagine the best way to do that would be in the shader.

I’m looking to create a similar effect in my game, and wonder how you implemented this aspect. I’ll post screenshots and code of my own after I get it working.

I do like your texture much better than the one in the videos. It has a very interesting “stringy” look to it (I can’t think of a better word right now). May I ask how you created your textures, if you diverged any from the videos method for creating them? His method creates a very rainbowy nebula texture, and your textures seem like a very uniform color. I can think of a few ways to achieve what you did, but I’m curious how you did it.

Well as I have exactly zero experience with shaders I did it by cloning a template material for every quad and modifying the material parameters every frame. Here (pastebin) is the Nebula class I wrote. You can probably ignore the enable() and disable() methods as they build and erase the node for memory saving when it isn’t used. The cycle(tpf) method is the one you’re looking for but note that my game uses a system by which the player is always at (0,0,0) and the vector calculation takes that into consideration. I added a few comments and removed an interface I use since it’ll just make it less clear.

The reason my nebulae look uniform in color is because the textures are monochrome and the color is applied via the material. Since this is the case, the color opacity value is taken as the whole material opacity value. I like to have random colors since everything is procedurally generated. I might make some mixed color ones too though :smiley:

As with other textures I used Paint.NET and basicly messed around with the cloud generator and some plugins until the thing looked about decent. In the end I made 4 images:
This is what I use now and is shown in the second post. While I was testing out the code I used this image from google images, that is what you see in the first post.

Btw here is a video I made for the showcase and it has a second of nebula footage too if it helps in any way.

1 Like

Thats an awesome looking game. I like the ship building aspect of it. I’m also creating a space based game (I’m calling it Spaceship Game for now), and I just added the nebula effect as described in the video you posted. I did the alpha computation in the shader, and I also added a calculation to fade the nebula out before it hits the far clipping plane.

Spaceship Game nebula demo

I used that nebula texture, and wow, it is nice. Previously in my game I tried other methods for creating a nebula effect, but the camera angle to normal dot product is definately the way to go. It not only causes the nebula texture to fade as it approaches the side view, but it also causes it to fade as the camera approaches it. So it acts like fog in that respect.

1 Like

@dbugman very nice, very nice. I was going to say something about real nebulas being light years across in size, but who cares! In space games we need objects that the human brain can comprehend and which can be shown on the screen along with our spaceship, so well done :smile:

@dbugman Thanks, yours is pretty damn good looking too. It reminds me of FTL. I wish I could knew how to make shaders (it’s kinda hard to get started with the whole thing), that lens/solar flare is sweet.

The reason why the texture fades is that when the camera gets closer its vector will inevitably sway sideways no matter how close to the center you are, which is indeed pretty neat.

Funny thing is I have no idea why I named my game Lightspeed Patrol. I guess I got tired callling it “the space project thing”. And it’s not even about patrolling or lightspeed for that matter either haha

Also did I see a federation starship at 1:24? And I couldn’t help noticing in another video that the player ship is named SS Narada. I hope you don’t invite people onto it for negotiations :stuck_out_tongue:

@Hans_Norlov Hooray for no realism! As long as the gameplay ends up being fun I think we can be excused :smiley:

1 Like

Actually, in JME it’s kind of easy to get started. It’s that next step that’s a doozy. :smile:

Creating a basic mono-color shader is super easy and JME holds your hand for a lot of the hard stuff. I think someone even put together some decent tutorials. It’s totally worth at least starting so that you have a better understanding of where the complexity is and how things sort of work… even if you never write your own shaders for ‘real’.

Pspeed is right. You can watch these tutorial series to see that is really easy to make a simple shader.

With jme3.1, if I’m right, you can play with shader nodes visually on the sdk. Here a @nehon’s video.


@pspeed @NemesisMate I see, it’s good to know some tutorials exist. I’ll take a look as soon as I have some spare time :smile: The visual editing seems interesting, but I’m more of an eclipse man myself.

A cross between FTL and Eve online is exactly what I’m going for (with a tad of the sims)! Its going to be a third/first person space shooter based distributed MMO (that’s a mouthful) where anyone can stand up their own server and have their friends connect and servers will be connected to each other by warp points or jump gates. I’m hoping by making it distributed in that way I can keep it free to play (no cost overhead for running game servers), since I don’t plan on quitting my day job.

Spaceship Game Web Site with more screenshots and videos

I’m also trying to make it as open file format as possible, allowing anyone to create their own alien characters and look like whatever they want. I also want to make it so people can create their own ships or planets as well. Its still very much in the development phase, and I’m not 100% sure exactly how it will end up. But I love using JME to develop this, it literally is the greatest game engine ever (in my opinion)!

Lightspeed Patrol is a great name. And your game really looks awesome. I’ve gone through a million name ideas and none have stuck yet. They all seem to box me into an idea that I’m not ready to boxed into.

Shaders aren’t too bad to get started with, they’re a C like syntax, glsl, which is close to java. To get started, just look at one of the JME3 jar files where the shader files exist. You can pretty much copy Unshaded.vert, Unshaded.frag, and Unshaded.j3md and put them into your own asset folder. Here is the shader code I wrote to do the nebula, its based off of the “Unshaded” shader in JME3. So you can use it in the exact same way. I added one extra variable called “FadeDistance”. Basically it toggles whether or not to fade away with distance. Feel free to use and modify it in your own project.

If you’re interested in how I did the lense flare thing, I might just create a new topic to discuss that one. Its pretty simple, and yea it really adds a lot to a scene.

And yes, you did see a federation ship :smile:

1 Like

I’d love to see how you achieved the lens flare effect! And thanks for the other shaders too.

That’s pretty ambitious, I hope you manage to make it as cool as it sounds!

I almost ended up calling it Spaceflight Gamma, which might have been better or not. Hm decisions, decisions. Well I guess it’s important to keep an open mind. My advice: find something unique or unusual that nobody associates with another thing yet which should also help with search engines, to make your game more popular. Perhaps something vague or meaningless so you don’t get “boxed in” as you called it :stuck_out_tongue:

I’ve heard of glsl, but I never thought this is so standardised which is awesome. I’ll check that out, that’s the same technique i’ve used for Nifty gui xml files haha. All this time I never realised those were actually shaders, I thought they were some JME specific material definitions, and that the stuff that the filterpostprocessor runs are the real deal. Time to study this :smiley:


Another approach is to pick more abstract names. They have the added benefit of instant SEO for the keywords if you pick right.

Step 1: pick some random one or two word game name that kind of seems to evoke the imagery you want
Step 2: search for it in google, if you get lots of hits then repeat step 1.

Somehow you have to get your name in front of a lot of people no matter what. It might as well be something that ideally meets the following criteria:
-strange enough to be memorable
-normal enough to be easy to spell
-returns no google hits until you are the only thing

Random two minute silly example…
“Hmm… the name ‘zephyr’ seems kind of cool and means light wind… like the content is blowing through the galaxy.”
Search for “glactic zephyr”
“Hmmm… a couple Battlestar Galactica references… let’s try mangling the name a bit…”
Search for “zephyria galaxy”
Results: Google says “Did you mean: zephyr gallery”

Meets the criteria. Probably not a good name, though, but an example of the pattern.

Not that it really needs mentioning but to point out “Space Game” 10000% meets the first two requirements but fails in the worst way the third requirement. :slight_smile: Web searches for “spaceship game” will literally return every spaceship game ever created. :slight_smile:


You seem to have pretty much nailed that with Mythruna :smile:

Thanks… and it’s important to note: the name went through that exact process and was definitely not my original name. (Mythra was the working title up until that exercise.)

Edit: my company name: Simsilica was a luckier find as that was my first choice.

I’m still struggling with that. Mostly people name themselves “X Games” or “X Interactive” or something. I guess your method will be of help one day when I get obsessed with finding a name for it again