The sky disapears, depending on the Camera's rotation


I’m currently working on the sky in my project. It’s a problem I had while using the DDS sample, and still have it now. Depending on the Camera’s rotation, the sky may completly disapear. My pretty blue sky turns gray. If I continue to rotate the camera up (or down), the sky reappears.

The problem occurs only when the camera is looking up, never when it’s looking down, and it only sensitive to the up/down rotation. Also, the higher my Camera is on the Y axis, the more it occurs.

I tried a cube sky texture and a sphere sky texture. Same problem. I use the SkyFactory with the following code :

[java] public static Spatial getSky()


if ( G.assetManager == null ) return null;

int skySize = 32;

Texture sphere = baseSkyTexture( skySize, 128, 128, 255 );

return SkyFactory.createSky( G.assetManager, sphere, true );


private static Texture baseSkyTexture( int skySize, int r, int g, int b )


Texture texture = new Texture2D( skySize, skySize, Image.Format.RGB8 );

ByteBuffer buffer = ByteBuffer.allocateDirect( skySize * skySize * 3 );

while ( buffer.hasRemaining() )


buffer.put( (byte) r );

buffer.put( (byte) g );

buffer.put( (byte) b );



texture.getImage().setData( 0, buffer );

return texture;


// — SKY —

rootNode.attachChild( S.getSky() );

// —


try to set the cullHint of the sky spatial to never

It’s already set to never inside the SkyFactory :

[java] Geometry sky = new Geometry(“Sky”, sphereMesh);




I modified the TestSkyLoading to show the problem… And simply added this line :

[java] cam.setLocation( new Vector3f( 0, 10, 0 ) );


The camera isn’t at (0,0,0) anymore, and when you look up, the sky disapears.

You can attach the sky to the viewport instead (viewPort.attachScene(sky)) because by default skies have no bounds so they dont effect the rootNode’s bound and so if the root node is culled then so is everything else regardless of the cull hint set on child nodes.

I can’t attach the sky to the viewport because then my water won’t have the sky’s reflection.

BUT you gave me a solution which works :

[java] rootNode.setCullHint( CullHint.Never );


The only problem is I have to change all my subNodes CullHint back to “Dynamic” (I suppose the default is Inherited).

Thank you for your help :smiley:

I forgot about the rootNode culling.

An easier way would be to scale you sky box by a 100 factor for example, this way no mater where you are in the scene the skybox will always be in the cam frustum.

And you won’t have to mess with your Spatials cullhint

Thank you nehon.

I will try your advice tonight. Maybe your team could fix it directly inside the SkyFactory object ?

@nehon : Scaling does work. Thank you very much for this !

The fun part is… with setLocalScale( 500f ) , If I move the camera above +500f on Y, then the bug reappears. (logic).

But the translation on X and Z won’t make it reappear. I can freely travel around my map and keep my pretty sky.

Smells like a bug somewhere :slight_smile:

No it’s not, it’s just something that appear when you are looking away from the root node and that the camera location is outside of the rootNode’s bounds ( which are the bound of the whole scene). This is very unlikely to occur, and i bet you got this problem because you are in a testing phase and that your scene is nearly empty.

The thing to understand is that the sky is a 10 world unit radius sphere at the center of the scene.

It appear far away because the sky bucket is rendered with a depth value of 1.0 ( the farthest). when checking culling, the bound are tested against the ones of the 10 world unit sphere so it’s very easy to get that out of the cam frustum.

Now…cullhint.never should be enough to prevent this glitch, but you get so out of the bounds that even the rootNode is culled. Again it’s very unlikely to occur in a full scale game.

Now maybe when setting the cullhint to never on a spatial it should propagate to its parent…but i guess this would yield unexpected results.

Thank you for the details.

The scene is not empty, but my game will be played as a god. The camera is very high in the sky (from close to the ground to a view from “heaven”). When you are very high and watch up (to check the sun’s location for exemple), the sky background disapears. Well not anymore thanks to your advice.

I have a question…

I implemented a quad to represent the sun. This quad is like the background… in the Sky Bucket, and never Culling.

When I move the camera, the quad moves with the scene, rendered after everything. All this is normal.

My question is, why is this 10x10 sphere used to render the sky always visible ? The sphere is still at (0,0,0) . When my camera is far away, what makes it render as if I was in the center of this sphere ? Is it a particularity of the sky.j3md shader ?

For my sun quad, I linked a node with the camera, so that quad moves with the camera. It works fine, but I’m curious about the sky now :slight_smile:

ozonegrif said:
My question is, why is this 10x10 sphere used to render the sky always visible ? The sphere is still at (0,0,0) . When my camera is far away, what makes it render as if I was in the center of this sphere ? Is it a particularity of the sky.j3md shader ?

As i said, the object is sent to the GPU with a 1.0 depth.
It's a trick really, let's say you have a far frustum of 1000, it acts like the sky is always at 1000 distance from your camera, no matter where you are.
That's why it looks like you are always at the center.