public void update(float tpf) {
    if (isSnowing) {
      snowParticleEmitter.setLocalTranslation(sim.getCar().getPosition());

      if (snowingPercentageHasChanged) {
        snowParticleEmitter.setPercentage(snowingPercentage);
        System.out.println("snowing intensity: " + snowingPercentage);
        snowingPercentageHasChanged = false;
      }
    }

    if (isRaining) {
      rainParticleEmitter.setLocalTranslation(sim.getCar().getPosition());

      if (rainingPercentageHasChanged) {
        rainParticleEmitter.setPercentage(rainingPercentage);
        System.out.println("raining intensity: " + rainingPercentage);
        rainingPercentageHasChanged = false;
      }
    }

    if (isFog) {
      if (fogPercentageHasChanged) {
        for (FogFilter fogFilter : fogFilterList)
          fogFilter.setFogDensity(2.0f * (fogPercentage / 100f));
        System.out.println("fog intensity: " + fogPercentage);
        fogPercentageHasChanged = false;
      }
    }
  }
Exemple #2
0
  public static FogFilter cloneFogFilter(FogFilter fogFilter) {
    FogFilter filterClone = new FogFilter();
    filterClone.setFogColor(fogFilter.getFogColor());
    filterClone.setFogDensity(fogFilter.getFogDensity());
    filterClone.setFogDistance(fogFilter.getFogDistance());
    filterClone.setName(fogFilter.getName() + " Clone");

    return filterClone;
  }
  public EffectCenter(Simulator sim) {
    this.sim = sim;
    AssetManager assetManager = sim.getAssetManager();

    WeatherSettings weatherSettings =
        Simulator.getDrivingTask().getScenarioLoader().getWeatherSettings();
    snowingPercentage =
        Math.max(
            weatherSettings.getSnowingPercentage(),
            -1); // use -1 to suppress construction of SnowParticleEmitter
    rainingPercentage =
        Math.max(
            weatherSettings.getRainingPercentage(),
            -1); // use -1 to suppress construction of RainParticleEmitter
    fogPercentage =
        Math.max(
            weatherSettings.getFogPercentage(), -1); // use -1 to suppress construction of FogFilter
    isSnowing = (snowingPercentage >= 0);
    isRaining = (rainingPercentage >= 0);
    isFog = (fogPercentage >= 0);
    isBloom = !Simulator.oculusRiftAttached; // switch off bloom filter when Oculus Rift is used
    isShadow = true;

    if (isSnowing) {
      // init snow
      snowParticleEmitter = new SnowParticleEmitter(assetManager, snowingPercentage);
      sim.getSceneNode().attachChild(snowParticleEmitter);
    }

    if (isRaining) {
      // init rain
      rainParticleEmitter = new RainParticleEmitter(assetManager, rainingPercentage);
      sim.getSceneNode().attachChild(rainParticleEmitter);
    }

    if (isFog || isBloom) {
      for (ViewPort viewPort : CameraFactory.getViewPortList()) {
        FilterPostProcessor processor = new FilterPostProcessor(assetManager);

        int numSamples = sim.getContext().getSettings().getSamples();
        if (numSamples > 0) processor.setNumSamples(numSamples);

        if (isFog) {
          FogFilter fogFilter = new FogFilter();
          fogFilter.setFogColor(new ColorRGBA(0.9f, 0.9f, 0.9f, 1.0f));
          fogFilter.setFogDistance(155);
          fogFilter.setFogDensity(2.0f * (fogPercentage / 100f));
          fogFilterList.add(fogFilter);
          processor.addFilter(fogFilter);
        }

        if (isBloom) {
          // ensure any object is set to glow, e.g. car chassis:
          // chassis.getMaterial().setColor("GlowColor", ColorRGBA.Orange);

          BloomFilter bloom = new BloomFilter(GlowMode.Objects);
          processor.addFilter(bloom);
        }

        viewPort.addProcessor(processor);
      }
    }

    if (isShadow) { // TODO
      DirectionalLight sun = new DirectionalLight();
      Vector3f sunLightDirection = new Vector3f(-0.2f, -0.9f, 0.2f); // TODO get from DT files
      sun.setDirection(sunLightDirection.normalizeLocal());

      ArrayList<ViewPort> viewPortList = CameraFactory.getViewPortList();

      if (sim.getNumberOfScreens() > 1) {
        int shadowMapSize = 4096;
        if (viewPortList.size() > 1) shadowMapSize = 1024;

        for (ViewPort viewPort : viewPortList) {
          DirectionalLightShadowRenderer dlsr =
              new DirectionalLightShadowRenderer(assetManager, shadowMapSize, 1);
          dlsr.setLight(sun);
          dlsr.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
          viewPort.addProcessor(dlsr);
        }

        shadowMapSize = 1024;
        DirectionalLightShadowRenderer dlsrBack =
            new DirectionalLightShadowRenderer(assetManager, shadowMapSize, 1);
        dlsrBack.setLight(sun);
        CameraFactory.getBackViewPort().addProcessor(dlsrBack);

        DirectionalLightShadowRenderer dlsrLeft =
            new DirectionalLightShadowRenderer(assetManager, shadowMapSize, 1);
        dlsrLeft.setLight(sun);
        CameraFactory.getLeftBackViewPort().addProcessor(dlsrLeft);

        DirectionalLightShadowRenderer dlsrRight =
            new DirectionalLightShadowRenderer(assetManager, shadowMapSize, 1);
        dlsrRight.setLight(sun);
        CameraFactory.getRightBackViewPort().addProcessor(dlsrRight);
      } else {
        // does not work with more than one screen
        for (ViewPort viewPort : viewPortList) {
          DirectionalLightShadowFilter dlsf =
              new DirectionalLightShadowFilter(assetManager, 1024, 3);
          dlsf.setLight(sun);
          dlsf.setLambda(1f);
          dlsf.setShadowIntensity(0.3f);
          dlsf.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
          dlsf.setEnabled(true);

          FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
          fpp.addFilter(dlsf);

          viewPort.addProcessor(fpp);
        }
      }
    }
  }