[Solved] Simple sky with color gradient


In my previous 3D projects, which were not using JMonkeyEngine, i used to do a simple color gradient for the sky, generally it was more white near the horizon and more blue in the zenith.
This allowed me to do a nice progressive day/night cycle. When done i add some geometries : the sun, moon, stars, cloud to it and i manage their position/transparency to have my full sky system.

For JMonkeyEngine, i found only two way so far to define sky color :

  • Background color, same color everywhere, it allows change over time but is uniform.
  • SkyBox or SkySphere, i don’t want that, a texture is static, or it involve complex things like manipulating texture’s data at every frame.

Is there a simple way i missed to do a colored gradient sky dome, like the regular OpenGL one ?

Thanks in advance

Sorry, I can’t answer your question directly but it should be possible to create such a sky by using Shaders. Could be that someone already did something like that, if not you may have to write it yourself… This is probably not the easiest way so I am also listening for alternatives :slight_smile:


You can also use the SkyControl library written by Sgold:

Here the Topic : New SkyControl releases - #72 by sgold


1 Like

See: [atmospheric scattering shader - Recherche Google]

SkyControl is also good.

Or make your own SkyDome with a “color buffer” (put in the colors that you want to have).

With onboard methods: No (probably).

1 Like

There are at least three implementations I know of that use this as the base of their math. The good ones, anyway.

Couldn’t one use a sphere and vertex coloring to achieve a gradient?
Might not be the best choice though since it lacks control and doesn’t fulfill regular sky properties (being equidistant)

1 Like

As others have mentioned, you have a few options.

If you like the more artistic approach, then I recommend using a sky geometry and your own texture. You can manipulate the texture coordinates and/or vertex colors to get sunrise/sunset, etc… This is what Mythruna uses because I wanted artistic control of all of the colors.

On the other end of the spectrum, if you want “real” atmospheric style math as jayfella mentions then you can pretty much just add my SimFX SkyState to your application and call it a day. (once you’ve added the right libraries of course)

stateManager.attach(new LightingState());
stateManager.attach(new SkyState());

You can control time of day, angle of sun, etc… even all of the atmospheric scattering parameters. It has an infinite ground disk you can turn on and you can use the scattered lighting material if you want your objects to also have atmospherics.

There are no clouds or stars (yet).

I think SkyControl is kind of in between these. Proper day/night transitions and stars and stuff… but more of an artistic approach to the sky colors I guess.


I see what you did there… :wink:

1 Like

Well i selected the color buffer solution, for now it fullfill my needs as i can make the same thing as i had on previous technologies.

But the others solutions exposed are very nice, and i might switch to actual atmospheric scattering solution in future !

For those in the same situation, here is an example of simple mesh with only two color and only 8 triangles:

    Mesh skyMesh = new Mesh();
    skyMesh.setBuffer(VertexBuffer.Type.Position, 3, new float[]{
        0, 1, 0,   0, -1, 0,
        1, 0, 0,   0, 0, -1,   -1, 0, 0,   0, 0, 1
    skyMesh.setBuffer(VertexBuffer.Type.Index, 3, new short[]{
        1, 2, 3,   3, 2, 0,
        1, 3, 4,   4, 3, 0,
        1, 4, 5,   5, 4, 0,
        1, 5, 2,   2, 5, 0,

    skyMesh.setBuffer(VertexBuffer.Type.Color, 4, new float[]{
        0, 0, 1, 1f,   1, 1, 1, 1f,
        1, 1, 1, 1,   1, 1, 1, 1,   1, 1, 1, 1,   1, 1, 1, 1});

    Geometry skyGeometry = new Geometry("mesh", skyMesh);
    Material skyMaterial = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    skyMaterial.setBoolean("VertexColor", true);

I position it at camera’s location at every update and i have my sky working !
Of course i’ll make it more detailed to have more colors and make it more round.

Thanks a lot for answers !