New SkyControl releases

I was able to make it work in my PBR scene using the solution provided here:

I am updating FilterColor with AmbientColor value getting from SkyControl.

Here is my code in case anyone interested

    /**
     * Wrapper state for SkyControl
     *
     * @author Ali-RS
     */
    public class SkyState extends BaseAppState {

        private TimeOfDay timeOfDay;
        private SkyControl sc;
        
        private final Vector4f pbrAmbient = new Vector4f(1, 1, 1, 1);
        private final MatParamOverride overrideFilterColor = new MatParamOverride(VarType.Vector4, "FilterColor", pbrAmbient);;

        public SkyState() {
        }

        public TimeOfDay getTimeOfDay() {
            return timeOfDay;
        }

        public SkyControl getSkyControl() {
            return sc;
        }

        @Override
        protected void initialize(Application app) {
            this.timeOfDay = new TimeOfDay(9);
            app.getStateManager().attach(timeOfDay);
            
            LightingState lightingState = getState(LightingState.class, true);

            sc = new SkyControl(app.getAssetManager(), app.getCamera(), 0.7f, StarsOption.Cube, true);
            Node rootNode = ((SimpleApplication) app).getRootNode();
            rootNode.addControl(sc);
            
            sc.setSunStyle("Textures/skies/suns/hazy-disc.png");
            sc.setCloudiness(1f);
            sc.setCloudsYOffset(0f);
            //sc.getSunAndStars().setObserverLatitude(0.2f);
            //sc.getUpdater().setMainMultiplier(2f);

            sc.getUpdater().setAmbientLight(lightingState.getAmbientLight());
            //sc.getUpdater().setMainLight(lightingState.getSun());

            String Clouds_L = "Textures/skies/Clouds_L.png";
            sc.getCloudLayer(0).setTexture(Clouds_L, 1f);
            sc.getCloudLayer(1).setTexture(Clouds_L, 1.5f);

            sc.setLunarDiameter(FastMath.DEG_TO_RAD * 8);
            sc.setSolarDiameter(FastMath.DEG_TO_RAD * 7);
            
            sc.setPhase(LunarPhase.FULL);

            int numSamples = app.getContext().getSettings().getSamples();
            BloomFilter bloom = Misc.getFpp(app.getViewPort(), app.getAssetManager(), numSamples)
                    .getFilter(BloomFilter.class);
            if (bloom != null) {
                sc.getUpdater().addBloomFilter(bloom);
            }
        }

        @Override
        protected void cleanup(Application app) {
            app.getStateManager().detach(timeOfDay);
            sc.getSpatial().removeControl(sc);
            timeOfDay = null;
            sc = null;
        }

        @Override
        protected void onEnable() {
            sc.setEnabled(true);
            sc.getSpatial().addMatParamOverride(overrideFilterColor);
        }

        @Override
        protected void onDisable() {
            sc.setEnabled(false);
            sc.getSpatial().removeMatParamOverride(overrideFilterColor);
        }

        @Override
        public void update(float tpf) {
            sc.getSunAndStars().setHour(timeOfDay.hour());
            ColorRGBA color = sc.getUpdater().getAmbientLight().getColor();
            pbrAmbient.set(color.r, color.g, color.b, color.a);
        }
    }
1 Like