예제 #1
0
  static void shadowStuff(RenderPass basePass, RenderPass lightPass, Texture shadowTexture) {
    Mat4 viewTransform = basePass.getView().getCameraMatrix();
    Mat4 lightTransform = lightPass.getView().getCameraMatrix();

    Mat4 homogenToTexCoord = new Mat4().translate(0.5f, 0.5f, 0.5f).scale(0.5, 0.5, 0.5);

    Mat4 viewToTexture = new Mat4();
    viewToTexture.mul(homogenToTexCoord);
    viewToTexture.mul(lightPass.getView().getProjectionMatrix());
    viewToTexture.mul_(new Mat4(lightTransform));
    viewToTexture.mul_(new Mat4(viewTransform).invert_());

    Mat4 lightToView = new Mat4();
    lightToView.mul_(new Mat4(viewTransform));
    lightToView.mul_(new Mat4(lightTransform).invert_());
    Vec3 lightPosVS = lightToView.transformAsPoint(new Vec3());

    Shader shader = createShader(viewToTexture);
    shader.putUniform(new Uniform("lightPosVS", Uniform.Type.VEC3, lightPosVS.toFloats()));
    for (Shape shape : basePass.getAllShapes()) {
      shape.getState().setShader(shader);
      shape.getState().setUnit(0, new Unit(shadowTexture));
    }

    Shader spotLightShader = new Shader(loadProgram("storeMoments"));
    for (Shape shape : lightPass.getAllShapes()) {
      shape.getState().setShader(spotLightShader);
    }
  }
예제 #2
0
 static float[] getTransposedFloats(Mat4 transform) {
   Mat4 m = new Mat4(transform);
   m.transpose();
   return m.toFloats();
 }