Esempio n. 1
0
  public void postQueue(RenderQueue rq) {
    GeometryList occluders = rq.getShadowQueueContent(ShadowMode.Cast);
    if (occluders.size() == 0) {
      noOccluders = true;
      return;
    } else {
      noOccluders = false;
    }

    GeometryList receivers = rq.getShadowQueueContent(ShadowMode.Receive);

    // update frustum points based on current camera
    Camera viewCam = viewPort.getCamera();
    ShadowUtil.updateFrustumPoints(
        viewCam, viewCam.getFrustumNear(), viewCam.getFrustumFar(), 1.0f, points);

    Vector3f frustaCenter = new Vector3f();
    for (Vector3f point : points) {
      frustaCenter.addLocal(point);
    }
    frustaCenter.multLocal(1f / 8f);

    // update light direction
    shadowCam.setProjectionMatrix(null);
    shadowCam.setParallelProjection(true);
    //        shadowCam.setFrustumPerspective(45, 1, 1, 20);

    shadowCam.lookAtDirection(direction, Vector3f.UNIT_Y);
    shadowCam.update();
    shadowCam.setLocation(frustaCenter);
    shadowCam.update();
    shadowCam.updateViewProjection();

    // render shadow casters to shadow map
    ShadowUtil.updateShadowCamera(occluders, receivers, shadowCam, points);

    Renderer r = renderManager.getRenderer();
    renderManager.setCamera(shadowCam, false);
    renderManager.setForcedMaterial(preshadowMat);

    r.setFrameBuffer(shadowFB);
    r.clearBuffers(false, true, false);
    viewPort.getQueue().renderShadowQueue(ShadowMode.Cast, renderManager, shadowCam, true);
    r.setFrameBuffer(viewPort.getOutputFrameBuffer());

    renderManager.setForcedMaterial(null);
    renderManager.setCamera(viewCam, false);
  }
Esempio n. 2
0
  /**
   * Updates a points arrays with the frustum corners of the provided camera.
   *
   * @param viewCam
   * @param points
   */
  public static void updateFrustumPoints2(Camera viewCam, Vector3f[] points) {
    int w = viewCam.getWidth();
    int h = viewCam.getHeight();
    float n = viewCam.getFrustumNear();
    float f = viewCam.getFrustumFar();

    points[0].set(viewCam.getWorldCoordinates(new Vector2f(0, 0), n));
    points[1].set(viewCam.getWorldCoordinates(new Vector2f(0, h), n));
    points[2].set(viewCam.getWorldCoordinates(new Vector2f(w, h), n));
    points[3].set(viewCam.getWorldCoordinates(new Vector2f(w, 0), n));

    points[4].set(viewCam.getWorldCoordinates(new Vector2f(0, 0), f));
    points[5].set(viewCam.getWorldCoordinates(new Vector2f(0, h), f));
    points[6].set(viewCam.getWorldCoordinates(new Vector2f(w, h), f));
    points[7].set(viewCam.getWorldCoordinates(new Vector2f(w, 0), f));
  }
  public void postQueue(RenderQueue rq) {
    Camera sceneCam = rm.getCurrentCamera();

    // update refraction cam
    refractionCam.setLocation(sceneCam.getLocation());
    refractionCam.setRotation(sceneCam.getRotation());
    refractionCam.setFrustum(
        sceneCam.getFrustumNear(),
        sceneCam.getFrustumFar(),
        sceneCam.getFrustumLeft(),
        sceneCam.getFrustumRight(),
        sceneCam.getFrustumTop(),
        sceneCam.getFrustumBottom());
    refractionCam.setParallelProjection(sceneCam.isParallelProjection());

    // update reflection cam
    WaterUtils.updateReflectionCam(reflectionCam, plane, sceneCam);

    // Rendering reflection and refraction
    rm.renderViewPort(reflectionView, savedTpf);
    rm.renderViewPort(refractionView, savedTpf);
    rm.getRenderer().setFrameBuffer(vp.getOutputFrameBuffer());
    rm.setCamera(sceneCam, false);
  }