[Solved] Rendering sky over fog using the Translucent bucket

Hi,

As I’m sure you’re all aware of by now, jMonkeyEngine’s FogFilter blocks out the skybox, because the sky uses the Sky bucket, which is infinitely far away (hence far enough away for fog to form).

To solve this, I would like to render a Skybox using the translucent bucket instead.

Spatial sky = SkyFactory.createSky(
        assetManager, "Textures/Skybox/ClearSky1.dds", false);
sky.setQueueBucket(Bucket.Translucent);
sky.setLocalScale(5000); //Do I need to scale it to make it bigger?
sky.setCullHint(Spatial.CullHint.Never);

Unfortunately this doesn’t work. The skybox does not render, and I get a black sky.

I am aware that using shader-based fog would be a solution, however I do not believe that it is necessary for the aims that I am trying to achieve.

I might try a box model, with the skybox on it, set that to be the same location as the camera, and then give it the translucent bucket. Would this work, or is there a better method?

Thanks,
Joe

Edit: Before you ask, Yes I have added a TranslucentBucketFilter, and yes other translucent objects render correctly.

I think there is nothing but pain and suffering down this path. The sky box is generally really small and designed to be rendered at infinity.

Note: shader based fog is better than full-screen-post-processing-fog in almost every conceivable way. Just saying.

Else if you really really really want to go down this path, put the sky in its own viewport behind the main viewport. It will always draw the full sky behind everything (slight performance drop) and it won’t be fogged by the FPP fog on the main frame.

I’m still going to go with the post-processor fog, mainly because I don’t have the time to learn how to make the fog shader-based.

I’ve tried making a separate ViewPort, but that hasn’t seemed to work:

ViewPort view2 = renderManager.createMainView("Sky", getCamera());
view2.setClearFlags(true, true, true);
view2.attachScene(sky);

Well, you have to manage the viewport. See any of 100 threads on the subject. Best way is with an app state. Search for “viewport app state” maybe.

You might want to create a preview port, though… else it will be drawn on top of your regular main viewport.

I decided ot be more efficient and forget different viewports of app-states. Instead, I am just creating a Spatial that is a box, has a sky texture, and is set to always be the position of the camera.

(Of course, I will need to find a properly textured skybox as well).

One question: At the moment, I am disabling back-face culling for ALL objects so that the Skybox is not culled. Is there any way that I can set the Spatial’s back faces to not be culled?

This issue is now completely solved. I’ll just put some information here for future readers who come across the same issue.

Here is my code:

sky = assetManager.loadModel("Models/skybox02.obj");
//SkyFactory.createSky(
        //assetManager, "Textures/Skybox/ClearSky1.dds", false);
Material mat = new Material(
        assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", assetManager.loadTexture("Models/skybox08.png"));
    mat.setColor("Color", ColorRGBA.White.mult(1.04f));
    mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Front); //So you see the inside of the box.
    sky.setMaterial(mat);
sky.setQueueBucket(Bucket.Translucent);
sky.setCullHint(CullHint.Never);
sky.setLocalTranslation(spawnLoc1);
sky.setLocalScale(-500); //My modeller sent the skybox the wrong way up!

Every frame, you must set the sky to be at the same location as the camera.

Make sure you have the TranslucentBucketFilter in your post-processing.

TranslucentBucketFilter translucent = new TranslucentBucketFilter();
fpp.addFilter(translucent);

Also, if you choose a skybox, make sure to have the back and sides of the skybox the same colour as your fog.


(Look into the distance, you will see the fog colour is the same as the sky)