Exemplo n.º 1
0
  /** Render water reflection RTT */
  private void renderReflection(final Vector4 clipPlane) {
    if (renderList.isEmpty()) {
      return;
    }

    reflectionTime += tpf;
    if (reflectionTime < reflectionThrottle) {
      return;
    }
    reflectionTime = 0;

    if (aboveWater) {
      camLocation.set(cam.getLocation());

      double planeDistance = waterPlane.pseudoDistance(camLocation);
      calcVect.set(waterPlane.getNormal()).multiplyLocal(planeDistance * 2.0f);
      camReflectPos.set(camLocation.subtractLocal(calcVect));

      camLocation.set(cam.getLocation()).addLocal(cam.getDirection());
      planeDistance = waterPlane.pseudoDistance(camLocation);
      calcVect.set(waterPlane.getNormal()).multiplyLocal(planeDistance * 2.0f);
      camReflectDir
          .set(camLocation.subtractLocal(calcVect))
          .subtractLocal(camReflectPos)
          .normalizeLocal();

      camLocation.set(cam.getLocation()).addLocal(cam.getUp());
      planeDistance = waterPlane.pseudoDistance(camLocation);
      calcVect.set(waterPlane.getNormal()).multiplyLocal(planeDistance * 2.0f);
      camReflectUp
          .set(camLocation.subtractLocal(calcVect))
          .subtractLocal(camReflectPos)
          .normalizeLocal();

      camReflectLeft.set(camReflectUp).crossLocal(camReflectDir).normalizeLocal();

      tRenderer.getCamera().setLocation(camReflectPos);
      tRenderer.getCamera().setDirection(camReflectDir);
      tRenderer.getCamera().setUp(camReflectUp);
      tRenderer.getCamera().setLeft(camReflectLeft);
    } else {
      tRenderer.getCamera().setLocation(cam.getLocation());
      tRenderer.getCamera().setDirection(cam.getDirection());
      tRenderer.getCamera().setUp(cam.getUp());
      tRenderer.getCamera().setLeft(cam.getLeft());
    }

    if (skyBox != null) {
      tmpLocation.set(skyBox.getTranslation());
      skyBox.setTranslation(tRenderer.getCamera().getLocation());
      skyBox.updateGeometricState(0.0f);
      skyBox.getSceneHints().setCullHint(CullHint.Never);
    }

    texArray.clear();
    if (doBlurReflection) {
      texArray.add(textureReflect);
    } else {
      texArray.add(textureReflectBlur);
    }

    tRenderer.getCamera().setProjectionMode(ProjectionMode.Custom);
    tRenderer.getCamera().setProjectionMatrix(cam.getProjectionMatrix());
    tRenderer.render(skyBox, texArray, Renderer.BUFFER_COLOR_AND_DEPTH);

    if (skyBox != null) {
      skyBox.getSceneHints().setCullHint(CullHint.Always);
    }

    modifyProjectionMatrix(clipPlane);

    tRenderer.render(renderList, texArray, Renderer.BUFFER_NONE);

    if (doBlurReflection) {
      blurReflectionTexture();
    }

    if (skyBox != null) {
      skyBox.setTranslation(tmpLocation);
      skyBox.updateGeometricState(0.0f);
      skyBox.getSceneHints().setCullHint(CullHint.Never);
    }
  }