Skybox messing with textures

So here is how my sceneGraph is laid out



rootNode – (rootPass applied) – (bloompass applied)

–Skybox

–Sphere

–sceneNode

  — objects –(Some have normal maps)

  — objects




However, my problem arises because the Skybox is overlaying over my objects found below it in the scenegraph. (namely everything attached to sceneNode) What exactly could be causing this?



In the screenshot provided, the sphere is attached to the rootNode. However, the cutout in the sphere is cause by an asteroid object attached to the sceneNode. If i attach the sphere to the sceneNode, it does the same thing the asteroids are doing.



Here is a screenshot:

Thanks for supplying that diagram of the scenegraph… While I don't think its the root of your problem, it was still very nice to see someone take the time to color code the different levels  :D



Now, it looks to me like the sphere is falling partly in the skybox and partly outside of it.  Two easy solutions are to either make the skybox bigger or to bring the sphere closer :slight_smile:



P.S:  I absolutely love that skybox texture, so majestic!

Well I have two things to say, first of all, I cannot take credit for this skybox.



Check this out:

http://www.jmonkeyengine.com/forum/index.php?topic=13738.0



Secondly, its not that the sphere is falling outside the skybox, it is that the stuff between the camera and the sphere is cutting out holes in the sphere with the skybox texture. :slight_smile:



I have

        skybox.setTextureCombineMode(TextureCombineMode.Replace);



however, everything below the skybox is messed up in that way still.



thanks for the compliments though even tho i dont necessarily deserve it :slight_smile:

sBook you were very close to guessing my problem.



Upon further testing, I found this to be the root of my problem:

        ZBufferState zState = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
        zState.setEnabled(false);
        skybox.setRenderState(zState);



i was initializing the skybox the same way as in TestIsland.java, however, it seems to not like having stuff below it.
With that code upon, it would override, as seen above, everything below rootNode, even if the skybox was attached deeper into the node heirarchy. however, if i take that off, it will render the stuff below in the hierarchy, except after the below objects leave the bounds of the skybox, they disappear again (while the rootNode based stuff stays fine not matter  what the distance)

So my question is, how can I have this skybox treat everything like how it is treating the rootNode and direct rootNode children?

Here is how I am initializing the skybox

        Texture north = TextureManager.loadTexture(Solar_System.class
                .getClassLoader().getResource(dir + "Space_front5.png"),
                Texture.MinificationFilter.BilinearNearestMipMap,
                Texture.MagnificationFilter.Bilinear);
        Texture south = TextureManager.loadTexture(Solar_System.class
                .getClassLoader().getResource(dir + "Space_back6.png"),
                Texture.MinificationFilter.BilinearNearestMipMap,
                Texture.MagnificationFilter.Bilinear);
        Texture east = TextureManager.loadTexture(Solar_System.class
                .getClassLoader().getResource(dir + "Space_right1.png"),
                Texture.MinificationFilter.BilinearNearestMipMap,
                Texture.MagnificationFilter.Bilinear);
        Texture west = TextureManager.loadTexture(Solar_System.class
                .getClassLoader().getResource(dir + "Space_left2.png"),
                Texture.MinificationFilter.BilinearNearestMipMap,
                Texture.MagnificationFilter.Bilinear);
        Texture up = TextureManager.loadTexture(Solar_System.class
                .getClassLoader().getResource(dir + "Space_top3.png"),
                Texture.MinificationFilter.BilinearNearestMipMap,
                Texture.MagnificationFilter.Bilinear);
        Texture down = TextureManager.loadTexture(Solar_System.class
                .getClassLoader().getResource(dir + "Space_bottom4.png"),
                Texture.MinificationFilter.BilinearNearestMipMap,
                Texture.MagnificationFilter.Bilinear);

        skybox.setTexture(Skybox.Face.North, east);
        skybox.setTexture(Skybox.Face.West, north);
        skybox.setTexture(Skybox.Face.South, west);
        skybox.setTexture(Skybox.Face.East, south);
        skybox.setTexture(Skybox.Face.Up, up);
        skybox.setTexture(Skybox.Face.Down, down);
      try {
         GameTaskQueueManager.getManager().update(new Callable<Object>() {
            @Override
            public Object call() throws Exception {
               skybox.preloadTextures();
               return null;
            }
         }).get();
      } catch (InterruptedException e) {
         e.printStackTrace();
      } catch (ExecutionException e) {
         e.printStackTrace();
      }

        CullState cullState = DisplaySystem.getDisplaySystem().getRenderer().createCullState();
        cullState.setCullFace(CullState.Face.None);
        cullState.setEnabled(true);
        skybox.setRenderState(cullState);

        //ZBufferState zState = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
        //zState.setEnabled(false);
        //skybox.setRenderState(zState);

        skybox.setLightCombineMode(Spatial.LightCombineMode.Off);
        skybox.setCullHint(Spatial.CullHint.Never);
        skybox.setTextureCombineMode(TextureCombineMode.Off);
        skybox.updateRenderState();

        skybox.lockBounds();
       
        rootNode.attachChild(skybox);

I still do not know what was causing this problem but i fixed it by putting the skybox here:



rootNode

–LensFlare

–sceneNode

  --Objects

     --Objects

  --Objects

  --skyNode

     --SkyBox



My only problem now is that sometimes the skyBox is culled… but I am sure I can fix that…

can you try to render the skybox manually before rendering the rootNode?

I assume you use GameStates? Just dont add the skynode to the rootNode,

override the gamestate's (or SimpleGame's) render-method with something like

this:


...
skybox.draw(display.getRenderer();
super.render(time);
...


the jme skybox already has a ZBuffer set, so that it is drawn behind everything else.


        ZBufferState zbuff = display.getRenderer().createZBufferState();
        zbuff.setWritable(false);
        zbuff.setEnabled(true);
        zbuff.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);
        setRenderState(zbuff);


Do you overwrite this ZBuffer?

to disable the culling you can set a CullHint 

setCullHint(CullHint.Never);