Ejemplo n.º 1
0
  private void renderModels() {

    Shader.getCurrentShader().setProjectionMatrix(projectionMatrix);
    Shader.getCurrentShader().setViewMatrix(viewMatrix);

    for (int x = -10; x < 10; x += 8) {
      for (int z = -10; z < 10; z += 8) {
        Matrix4f m = new Matrix4f();
        m = m.translate(new Vector3f(x, 0, z));
        m = m.rotate(modelAngle.getY(), new Vector3f(0, 1, 0));
        Shader.getCurrentShader().setModelMatrix(m);
        bunny.draw();
      }
    }

    /*for (int x=-10; x<10; x+=10) {
        for (int z=-10; z<10; z+=10) {
            Matrix4f m=new Matrix4f();
            m=m.translate(new Vector3f(x, 0f, z));
            m=m.rotate(modelAngle.getY()+((x+10)*20+z)*0.1f, new Vector3f(0, 1, 0));
            Shader.getCurrentShader()
                    .setUniformMat4f(Shader.getCurrentShader().modelMatrixUniformId, m);
            bunny.draw();
        }
    }*/

    Shader.getCurrentShader().setModelMatrix(identity);
    terrain.draw();
  }
Ejemplo n.º 2
0
  private void setupLightViewMatrix() {

    viewMatrix = new Matrix4f();

    Matrix4f.rotate((float) (Math.PI / 2), new Vector3f(1, 0, 0), viewMatrix, viewMatrix);

    Matrix4f.translate(
        new Vector3f(
            lightSourcePosition.getX(), -lightSourcePosition.getY(), lightSourcePosition.getZ()),
        viewMatrix,
        viewMatrix);
  }
Ejemplo n.º 3
0
  private void setupViewMatrix(boolean reverseY) {

    viewMatrix = new Matrix4f();

    Matrix4f.rotate(
        (reverseY ? -1 : 1) * cameraAngle.getY(), new Vector3f(1, 0, 0), viewMatrix, viewMatrix);

    Matrix4f.rotate(cameraAngle.getX(), new Vector3f(0, 1, 0), viewMatrix, viewMatrix);

    Matrix4f.translate(
        reverseY ? new Vector3f(cameraPos.getX(), -cameraPos.getY(), cameraPos.getZ()) : cameraPos,
        viewMatrix,
        viewMatrix);
  }
Ejemplo n.º 4
0
  private void setupProjectionMatrix() {
    projectionMatrix = new Matrix4f();
    float fieldOfView = (float) (Math.PI * 2 * 60 / 360);
    float aspectRatio = (float) WIDTH / (float) HEIGHT;
    float near_plane = 0.1f;
    float far_plane = 1000f;

    float y_scale = this.coTangent(fieldOfView / 2f);
    float x_scale = y_scale / aspectRatio;
    float frustum_length = far_plane - near_plane;

    projectionMatrix.m00 = x_scale;
    projectionMatrix.m11 = y_scale;
    projectionMatrix.m22 = -((far_plane + near_plane) / frustum_length);
    projectionMatrix.m23 = -1;
    projectionMatrix.m32 = -((2 * near_plane * far_plane) / frustum_length);
    projectionMatrix.m33 = 0;
  }
Ejemplo n.º 5
0
  private void draw() {

    glEnable(GL_DEPTH_TEST);

    setupLightViewMatrix();
    lsvm = viewMatrix;
    distancesToLightSourceFBO.bindForWriting();

    GL11.glClearColor(1f, 0f, 0f, 1f);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    Shader.distance.enable();
    Shader.distance.setLightningPosition(lightSourcePosition);
    renderModels();
    Shader.distance.disable();
    distancesToLightSourceFBO.unbindForWriting();

    checkForGLError();

    setupViewMatrix(false);

    waterRefractionFBO.bindForWriting();
    renderClippedSceneWithLightning(-1000, 0);
    waterRefractionFBO.unbindForWriting();

    setupViewMatrix(true);
    waterReflectionFBO.bindForWriting();
    renderClippedSceneWithLightning(0, 1000);
    waterReflectionFBO.unbindForWriting();
    setupViewMatrix(false);

    renderClippedSceneWithLightning(-1000, 1000);

    Shader.waterMixdown.enable();
    Shader.waterMixdown.setTime((System.currentTimeMillis() % 16000) / 16000f);

    Shader.waterMixdown.setCameraPosition(cameraPos);
    Shader.waterMixdown.setLightningPosition(lightSourcePosition);

    Shader.waterMixdown.setProjectionMatrix(projectionMatrix);
    Shader.waterMixdown.setViewMatrix(viewMatrix);
    Shader.waterMixdown.setModelMatrix(identity);

    waterReflectionFBO.bindMOAR(0);
    waterRefractionFBO.bindMOAR(1);
    waterBumpMap.bindMOAR(2);

    plane.draw();

    Shader.waterMixdown.disable();

    Shader.plainShader.enable();

    Matrix4f projection = Matrix4f.orthographic(-3, 3, -3, 3, -1, 1);
    Shader.plainShader.setProjectionMatrix(projection);
    Shader.plainShader.setViewMatrix(identity);
    Shader.plainShader.setModelMatrix(new Matrix4f().translate(new Vector3f(-2, 2, 0)));

    Shader.plainShader.setClipAbove(1000);
    Shader.plainShader.setClipBelow(-1000);

    distancesToLightSourceFBO.bind();
    surface.draw();

    Shader.plainShader.disable();
  }
Ejemplo n.º 6
0
 static {
   identity.setIdentity();
   moted = moted.translate(new Vector3f(1f, 0f, 0f));
 }