2d sun at the sky


I want a 2d image of the sun at the sun position at the sky.
My solution is to attach a picture at the guiNode and tranform the world position to screen position.
But the problem is, that the sun is visible through the whole world because its on the guiNode.
I tried Bucket.Sky but thereby the sun disappears

any solution to get a 2d sun at the sky?


pic = new Picture(“Sun”);
pic.setImage(assetManager, “Textures/sun.png”, false);




public void simpleUpdate(float tpf)

Vector3f pos = cam.getScreenCoordinates(sun.getDirection());
pic.setPosition(pos.x, pos.y);


Don’t put it in the gui node as it’s not a gui element. Put it in the sky but position it properly in the scene. Make sure to use the billboard control so it always faces the camera.

ok thank you. now I use the billboard control and I have attached the sun geometry (now Quad) to the billboard Node. but the problem still exists.

billboard.setQueueBucket(Bucket.Translucent); // visible through all
billboard.setQueueBucket(Bucket.Sky); // quad disappears

You also have to make sure to position your quad somewhere that it can be seen. I can’t see that code so I can’t offer any more advice.

-.- it works if I disable the fog post processing shader. are there any ways to get this work with fog shader enabled?

@alrik said: -.- it works if I disable the fog post processing shader. are there any ways to get this work with fog shader enabled?

Not really. Fog as a post-processing effect has a few problems, things like this being one of them. It is indiscriminate since it operates on the whole rendered scene.

You can modify the Fog Filter to exclude the sky by making a minor alteration to the frag shader.

if (z == 1.0) discard;

This is assuming that the depth is referenced by a variable named z… could be depth… or something similar. Anyways… use a local copy of the filter and the above line before the frag color is set and it will do what you are looking for.

EDIT: This is something that should already be part of the Filter (or at least I thought it was added way back when…) If it was… there should be a boolean uniform that can be set via the filter.


…you probably mean fogVal as the view depth.

I guess if fogVal == 1.0 was discarded it might also unfog things that just happened to be at the far plane.

To the OP, if you are going to modify shaders then it’s probably better in the long run just to add fog to the regular shaders and avoid the extra post-processing pass and its limitations.

ok thanks, so I have to implement the fog to the regular shader on my own