Shouldn't createSky's sphereRadius be a float instead of an int?

I’m developing a game in RC2, and I’ve been struggling to understand a bug where the viewport occasionally goes to solid background color for no obvious reason. I’ve narrowed it down to the sphereRadius of the cube-mapped sky I’m using. The Javadoc for SkyFactory indicates that the sphereRadius should match the camera’s near plane. Part of the problem is that my camera’s near plane is at 0.01 world units, and the sphereRadius parameter is an int, so the best I can do is sphereRadius=1.

From browsing, it appears that the only use of sphereRadius is to construct a Sphere, and the Sphere constructor expects a float in that position. Could we change the createSky() interfaces (or add new ones) to accept a float value for sphereRadius?

I don’t think this should cause the problem you describe. Can you explain how you determined that this is the issue?

As far as I understand it, everything in the sky bucket is rendered at a distance of 1 (in view space) anyway, ie: right at the far plane.

I’m not sure whether the bug in my game is caused by sphereRadius. There seem to be other factors at work which I haven’t isolated yet. I raised the interface issue here because: (1) the method interface and the Javadoc have me confused about how I should set sphereRadius, and (2) I have a simple test program which exhibits similar symptoms depending on the value of sphereRadius, and its frustrating to be limited to integer values in my testing.

Regarding (2): in my test code, if I use sphereRadius=1 for a scene that contains nothing but cube-mapped sky, I see a circular piece of the sky surrounded by background color when the camera’s direction is (0.0, 0.0, -1.0), and the view changes to all background color the instant the camera’s direction changes. If I increase sphereRadius to 2, I see sky everywhere I turn the camera. If I then set the near plane of the camera frustrum to 3.0, I see only the background color everywhere I look. I’d appreciate some insight into this behavior.

Regarding (1) I’d appreciate advice on how to set sphereRadius in my game. If the sky is rendered at the distance of the far plane, what is the use of this parameter?

If you have some test code then post it. Someone familiar with the sky box stuff will be able to spot your issue, I guess.

I thought the radius was to control how distorted the mesh looks. Anyway, from malfunctioning test code it will be easier to get to the bottom of things. The sky working or not shouldn’t be affected by camera direction.

[java]package mygame;

import com.jme3.math.Vector3f;
import com.jme3.scene.Spatial;
import com.jme3.texture.Texture;
import com.jme3.util.SkyFactory;


  • A simple JME3 app to demonstrate rendering “blackouts” which occur with a

  • cube-mapped sky.
    public class Main2 extends SimpleApplication {

    public static void main(String[] args) {
    Main app = new Main();

    public void simpleInitApp() {
    int sphereRadius = 1;
    Texture side = assetManager.loadTexture(“Interface/Logo/Monkey.png”);
    Spatial sky = SkyFactory.createSky(assetManager, side, side, side,
    side, side, side, Vector3f.UNIT_XYZ, sphereRadius);

What happens if you use a radius of 10? …which is what all of the non-radius-taking methods do internally.

With a sphereRadius of 10 in the test program, the sky is completely visible.

If I then move the near plane of the camera frustrum to 10f world units, I see a circular piece of the sky surrounded by background color.

In the game I’m developing, if I set sphereRadius to 10, the viewport still goes to solid background color under some circumstances.

I think the javadoc that says your near plane should be the same as the sphere radius is erroneous. So stop doing that.

If you actually want your near plane to be 10 for some reason then the sky may have problems anyway… or try using an even bigger radius. What was happening is that the sky was being clipped by the near plane.

I don’t know why it doesn’t work in your actual game. Since you have it working in the test program then now you have something to compare it to, at least.

I’ve been struggling to develop a simple test code which reproduces the bug I see in my game. It seems to have to do with the combination of a cube-mapped sky and all other textures in the view having lit textures. If I add an unlit geometry, the bug goes away. Does that ring a bell, by any chance?

Not really. Many of the tests use a sky and lit objects together without issue. I guess we’d have to see a failing test case to help further.

I’ve contributed a JavaDoc correction here.

It would still be interesting to figure out what actually is wrong in your case. Hope we can make progress there.

I’m still working on it.

@pspeed please see this new thread