private void update(Window window, Matrix4f viewMatrix, Scene scene) { SceneLight sceneLight = scene.getSceneLight(); DirectionalLight directionalLight = sceneLight != null ? sceneLight.getDirectionalLight() : null; for (int i = 0; i < NUM_CASCADES; i++) { ShadowCascade shadowCascade = shadowCascades.get(i); shadowCascade.update(window, viewMatrix, directionalLight); } }
private void update(Window window, Matrix4f viewMatrix, Scene scene) { SceneLight sceneLight = scene.getSceneLight(); DirectionalLight directionalLight = sceneLight != null ? sceneLight.getDirectionalLight() : null; for (int i = 0; i < NUM_CASCADES; i++) { ShadowCascade shadowCascade = shadowCascades.get(i); shadowCascade.update(window, viewMatrix, directionalLight); } }
private void update(Window window, Matrix4f viewMatrix, Scene scene) { SceneLight sceneLight = scene.getSceneLight(); DirectionalLight directionalLight = sceneLight != null ? sceneLight.getDirectionalLight() : null; for (int i = 0; i < NUM_CASCADES; i++) { ShadowCascade shadowCascade = shadowCascades.get(i); shadowCascade.update(window, viewMatrix, directionalLight); } }
private void update(Window window, Matrix4f viewMatrix, Scene scene) { SceneLight sceneLight = scene.getSceneLight(); DirectionalLight directionalLight = sceneLight != null ? sceneLight.getDirectionalLight() : null; for (int i = 0; i < NUM_CASCADES; i++) { ShadowCascade shadowCascade = shadowCascades.get(i); shadowCascade.update(window, viewMatrix, directionalLight); } }
@Override public void update(float interval, MouseInput mouseInput, Window window) { if (mouseInput.isRightButtonPressed()) { // Update camera based on mouse Vector2f rotVec = mouseInput.getDisplVec(); camera.moveRotation(rotVec.x * MOUSE_SENSITIVITY, rotVec.y * MOUSE_SENSITIVITY, 0); sceneChanged = true; } // Update camera position camera.movePosition(cameraInc.x * CAMERA_POS_STEP, cameraInc.y * CAMERA_POS_STEP, cameraInc.z * CAMERA_POS_STEP); lightAngle += angleInc; if (lightAngle < 0) { lightAngle = 0; } else if (lightAngle > 180) { lightAngle = 180; } float zValue = (float) Math.cos(Math.toRadians(lightAngle)); float yValue = (float) Math.sin(Math.toRadians(lightAngle)); Vector3f lightDirection = this.scene.getSceneLight().getDirectionalLight().getDirection(); lightDirection.x = 0; lightDirection.y = yValue; lightDirection.z = zValue; lightDirection.normalize(); // Update view matrix camera.updateViewMatrix(); }
@Override public void update(float interval, MouseInput mouseInput, Window window) { if (mouseInput.isRightButtonPressed()) { // Update camera based on mouse Vector2f rotVec = mouseInput.getDisplVec(); camera.moveRotation(rotVec.x * MOUSE_SENSITIVITY, rotVec.y * MOUSE_SENSITIVITY, 0); sceneChanged = true; } // Update camera position camera.movePosition(cameraInc.x * CAMERA_POS_STEP, cameraInc.y * CAMERA_POS_STEP, cameraInc.z * CAMERA_POS_STEP); lightAngle += angleInc; if (lightAngle < 0) { lightAngle = 0; } else if (lightAngle > 180) { lightAngle = 180; } float zValue = (float) Math.cos(Math.toRadians(lightAngle)); float yValue = (float) Math.sin(Math.toRadians(lightAngle)); Vector3f lightDirection = this.scene.getSceneLight().getDirectionalLight().getDirection(); lightDirection.x = 0; lightDirection.y = yValue; lightDirection.z = zValue; lightDirection.normalize(); // Update view matrix camera.updateViewMatrix(); }
@Override public void update(float interval, MouseInput mouseInput) { // Update camera based on mouse if (mouseInput.isRightButtonPressed()) { Vector2f rotVec = mouseInput.getDisplVec(); camera.moveRotation(rotVec.x * MOUSE_SENSITIVITY, rotVec.y * MOUSE_SENSITIVITY, 0); } // Update camera position Vector3f prevPos = new Vector3f(camera.getPosition()); camera.movePosition(cameraInc.x * CAMERA_POS_STEP, cameraInc.y * CAMERA_POS_STEP, cameraInc.z * CAMERA_POS_STEP); // Check if there has been a collision. If true, set the y position to // the maximum height float height = terrain != null ? terrain.getHeight(camera.getPosition()) : -Float.MAX_VALUE; if (camera.getPosition().y <= height) { camera.setPosition(prevPos.x, prevPos.y, prevPos.z); } // Update directional light direction, intensity and colour SceneLight sceneLight = scene.getSceneLight(); DirectionalLight directionalLight = sceneLight.getDirectionalLight(); double angRad = Math.toRadians(lightAngle); directionalLight.getDirection().x = (float) Math.sin(angRad); directionalLight.getDirection().y = (float) Math.cos(angRad); }
private void renderDepthMap(Window window, Camera camera, Scene scene) { // Setup view port to match the texture size glBindFramebuffer(GL_FRAMEBUFFER, shadowMap.getDepthMapFBO()); glViewport(0, 0, ShadowMap.SHADOW_MAP_WIDTH, ShadowMap.SHADOW_MAP_HEIGHT); glClear(GL_DEPTH_BUFFER_BIT); depthShaderProgram.bind(); DirectionalLight light = scene.getSceneLight().getDirectionalLight(); Vector3f lightDirection = light.getDirection(); float lightAngleX = (float)Math.toDegrees(Math.acos(lightDirection.z)); float lightAngleY = (float)Math.toDegrees(Math.asin(lightDirection.x)); float lightAngleZ = 0; Matrix4f lightViewMatrix = transformation.updateLightViewMatrix(new Vector3f(lightDirection).mul(light.getShadowPosMult()), new Vector3f(lightAngleX, lightAngleY, lightAngleZ)); DirectionalLight.OrthoCoords orthCoords = light.getOrthoCoords(); Matrix4f orthoProjMatrix = transformation.updateOrthoProjectionMatrix(orthCoords.left, orthCoords.right, orthCoords.bottom, orthCoords.top, orthCoords.near, orthCoords.far); depthShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix); Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes(); for (Mesh mesh : mapMeshes.keySet()) { mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> { Matrix4f modelLightViewMatrix = transformation.buildModelViewMatrix(gameItem, lightViewMatrix); depthShaderProgram.setUniform("modelLightViewMatrix", modelLightViewMatrix); } ); } // Unbind depthShaderProgram.unbind(); glBindFramebuffer(GL_FRAMEBUFFER, 0); }
private void renderDepthMap(Window window, Camera camera, Scene scene) { // Setup view port to match the texture size glBindFramebuffer(GL_FRAMEBUFFER, shadowMap.getDepthMapFBO()); glViewport(0, 0, ShadowMap.SHADOW_MAP_WIDTH, ShadowMap.SHADOW_MAP_HEIGHT); glClear(GL_DEPTH_BUFFER_BIT); depthShaderProgram.bind(); DirectionalLight light = scene.getSceneLight().getDirectionalLight(); Vector3f lightDirection = light.getDirection(); float lightAngleX = (float)Math.toDegrees(Math.acos(lightDirection.z)); float lightAngleY = (float)Math.toDegrees(Math.asin(lightDirection.x)); float lightAngleZ = 0; Matrix4f lightViewMatrix = transformation.updateLightViewMatrix(new Vector3f(lightDirection).mul(light.getShadowPosMult()), new Vector3f(lightAngleX, lightAngleY, lightAngleZ)); DirectionalLight.OrthoCoords orthCoords = light.getOrthoCoords(); Matrix4f orthoProjMatrix = transformation.updateOrthoProjectionMatrix(orthCoords.left, orthCoords.right, orthCoords.bottom, orthCoords.top, orthCoords.near, orthCoords.far); depthShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix); Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes(); for (Mesh mesh : mapMeshes.keySet()) { mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> { Matrix4f modelLightViewMatrix = transformation.buildModelViewMatrix(gameItem, lightViewMatrix); depthShaderProgram.setUniform("modelLightViewMatrix", modelLightViewMatrix); } ); } // Unbind depthShaderProgram.unbind(); glBindFramebuffer(GL_FRAMEBUFFER, 0); }
private void renderDepthMap(Window window, Camera camera, Scene scene) { // Setup view port to match the texture size glBindFramebuffer(GL_FRAMEBUFFER, shadowMap.getDepthMapFBO()); glViewport(0, 0, ShadowMap.SHADOW_MAP_WIDTH, ShadowMap.SHADOW_MAP_HEIGHT); glClear(GL_DEPTH_BUFFER_BIT); depthShaderProgram.bind(); DirectionalLight light = scene.getSceneLight().getDirectionalLight(); Vector3f lightDirection = light.getDirection(); float lightAngleX = (float)Math.toDegrees(Math.acos(lightDirection.z)); float lightAngleY = (float)Math.toDegrees(Math.asin(lightDirection.x)); float lightAngleZ = 0; Matrix4f lightViewMatrix = transformation.updateLightViewMatrix(new Vector3f(lightDirection).mul(light.getShadowPosMult()), new Vector3f(lightAngleX, lightAngleY, lightAngleZ)); DirectionalLight.OrthoCoords orthCoords = light.getOrthoCoords(); Matrix4f orthoProjMatrix = transformation.updateOrthoProjectionMatrix(orthCoords.left, orthCoords.right, orthCoords.bottom, orthCoords.top, orthCoords.near, orthCoords.far); depthShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix); Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes(); for (Mesh mesh : mapMeshes.keySet()) { mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> { Matrix4f modelLightViewMatrix = transformation.buildModelViewMatrix(gameItem, lightViewMatrix); depthShaderProgram.setUniform("modelLightViewMatrix", modelLightViewMatrix); } ); } // Unbind depthShaderProgram.unbind(); glBindFramebuffer(GL_FRAMEBUFFER, 0); }
private void renderDepthMap(Window window, Camera camera, Scene scene) { if (scene.isRenderShadows()) { // Setup view port to match the texture size glBindFramebuffer(GL_FRAMEBUFFER, shadowMap.getDepthMapFBO()); glViewport(0, 0, ShadowMap.SHADOW_MAP_WIDTH, ShadowMap.SHADOW_MAP_HEIGHT); glClear(GL_DEPTH_BUFFER_BIT); depthShaderProgram.bind(); DirectionalLight light = scene.getSceneLight().getDirectionalLight(); Vector3f lightDirection = light.getDirection(); float lightAngleX = (float) Math.toDegrees(Math.acos(lightDirection.z)); float lightAngleY = (float) Math.toDegrees(Math.asin(lightDirection.x)); float lightAngleZ = 0; Matrix4f lightViewMatrix = transformation.updateLightViewMatrix(new Vector3f(lightDirection).mul(light.getShadowPosMult()), new Vector3f(lightAngleX, lightAngleY, lightAngleZ)); DirectionalLight.OrthoCoords orthCoords = light.getOrthoCoords(); Matrix4f orthoProjMatrix = transformation.updateOrthoProjectionMatrix(orthCoords.left, orthCoords.right, orthCoords.bottom, orthCoords.top, orthCoords.near, orthCoords.far); depthShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix); renderNonInstancedMeshes(scene, depthShaderProgram, null, lightViewMatrix); renderInstancedMeshes(scene, depthShaderProgram, null, lightViewMatrix); // Unbind depthShaderProgram.unbind(); glBindFramebuffer(GL_FRAMEBUFFER, 0); } }
private void renderDepthMap(Window window, Camera camera, Scene scene) { if (scene.isRenderShadows()) { // Setup view port to match the texture size glBindFramebuffer(GL_FRAMEBUFFER, shadowMap.getDepthMapFBO()); glViewport(0, 0, ShadowMap.SHADOW_MAP_WIDTH, ShadowMap.SHADOW_MAP_HEIGHT); glClear(GL_DEPTH_BUFFER_BIT); depthShaderProgram.bind(); DirectionalLight light = scene.getSceneLight().getDirectionalLight(); Vector3f lightDirection = light.getDirection(); float lightAngleX = (float) Math.toDegrees(Math.acos(lightDirection.z)); float lightAngleY = (float) Math.toDegrees(Math.asin(lightDirection.x)); float lightAngleZ = 0; Matrix4f lightViewMatrix = transformation.updateLightViewMatrix(new Vector3f(lightDirection).mul(light.getShadowPosMult()), new Vector3f(lightAngleX, lightAngleY, lightAngleZ)); DirectionalLight.OrthoCoords orthCoords = light.getOrthoCoords(); Matrix4f orthoProjMatrix = transformation.updateOrthoProjectionMatrix(orthCoords.left, orthCoords.right, orthCoords.bottom, orthCoords.top, orthCoords.near, orthCoords.far); depthShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix); renderNonInstancedMeshes(scene, depthShaderProgram, null, lightViewMatrix); renderInstancedMeshes(scene, depthShaderProgram, null, lightViewMatrix); // Unbind depthShaderProgram.unbind(); glBindFramebuffer(GL_FRAMEBUFFER, 0); } }
private void renderDepthMap(Window window, Camera camera, Scene scene) { if (scene.isRenderShadows()) { // Setup view port to match the texture size glBindFramebuffer(GL_FRAMEBUFFER, shadowMap.getDepthMapFBO()); glViewport(0, 0, ShadowMap.SHADOW_MAP_WIDTH, ShadowMap.SHADOW_MAP_HEIGHT); glClear(GL_DEPTH_BUFFER_BIT); depthShaderProgram.bind(); DirectionalLight light = scene.getSceneLight().getDirectionalLight(); Vector3f lightDirection = light.getDirection(); float lightAngleX = (float) Math.toDegrees(Math.acos(lightDirection.z)); float lightAngleY = (float) Math.toDegrees(Math.asin(lightDirection.x)); float lightAngleZ = 0; Matrix4f lightViewMatrix = transformation.updateLightViewMatrix(new Vector3f(lightDirection).mul(light.getShadowPosMult()), new Vector3f(lightAngleX, lightAngleY, lightAngleZ)); DirectionalLight.OrthoCoords orthCoords = light.getOrthoCoords(); Matrix4f orthoProjMatrix = transformation.updateOrthoProjectionMatrix(orthCoords.left, orthCoords.right, orthCoords.bottom, orthCoords.top, orthCoords.near, orthCoords.far); depthShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix); renderNonInstancedMeshes(scene, depthShaderProgram, null, lightViewMatrix); renderInstancedMeshes(scene, depthShaderProgram, null, lightViewMatrix); // Unbind depthShaderProgram.unbind(); glBindFramebuffer(GL_FRAMEBUFFER, 0); } }
private void renderDepthMap(Window window, Camera camera, Scene scene) { if (scene.isRenderShadows()) { // Setup view port to match the texture size glBindFramebuffer(GL_FRAMEBUFFER, shadowMap.getDepthMapFBO()); glViewport(0, 0, ShadowMap.SHADOW_MAP_WIDTH, ShadowMap.SHADOW_MAP_HEIGHT); glClear(GL_DEPTH_BUFFER_BIT); depthShaderProgram.bind(); DirectionalLight light = scene.getSceneLight().getDirectionalLight(); Vector3f lightDirection = light.getDirection(); float lightAngleX = (float) Math.toDegrees(Math.acos(lightDirection.z)); float lightAngleY = (float) Math.toDegrees(Math.asin(lightDirection.x)); float lightAngleZ = 0; Matrix4f lightViewMatrix = transformation.updateLightViewMatrix(new Vector3f(lightDirection).mul(light.getShadowPosMult()), new Vector3f(lightAngleX, lightAngleY, lightAngleZ)); DirectionalLight.OrthoCoords orthCoords = light.getOrthoCoords(); Matrix4f orthoProjMatrix = transformation.updateOrthoProjectionMatrix(orthCoords.left, orthCoords.right, orthCoords.bottom, orthCoords.top, orthCoords.near, orthCoords.far); depthShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix); renderNonInstancedMeshes(scene, depthShaderProgram, null, lightViewMatrix); renderInstancedMeshes(scene, depthShaderProgram, null, lightViewMatrix); // Unbind depthShaderProgram.unbind(); glBindFramebuffer(GL_FRAMEBUFFER, 0); } }
private void renderDepthMap(Window window, Camera camera, Scene scene) { if (scene.isRenderShadows()) { // Setup view port to match the texture size glBindFramebuffer(GL_FRAMEBUFFER, shadowMap.getDepthMapFBO()); glViewport(0, 0, ShadowMap.SHADOW_MAP_WIDTH, ShadowMap.SHADOW_MAP_HEIGHT); glClear(GL_DEPTH_BUFFER_BIT); depthShaderProgram.bind(); DirectionalLight light = scene.getSceneLight().getDirectionalLight(); Vector3f lightDirection = light.getDirection(); float lightAngleX = (float) Math.toDegrees(Math.acos(lightDirection.z)); float lightAngleY = (float) Math.toDegrees(Math.asin(lightDirection.x)); float lightAngleZ = 0; Matrix4f lightViewMatrix = transformation.updateLightViewMatrix(new Vector3f(lightDirection).mul(light.getShadowPosMult()), new Vector3f(lightAngleX, lightAngleY, lightAngleZ)); DirectionalLight.OrthoCoords orthCoords = light.getOrthoCoords(); Matrix4f orthoProjMatrix = transformation.updateOrthoProjectionMatrix(orthCoords.left, orthCoords.right, orthCoords.bottom, orthCoords.top, orthCoords.near, orthCoords.far); depthShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix); renderNonInstancedMeshes(scene, depthShaderProgram, null, lightViewMatrix); renderInstancedMeshes(scene, depthShaderProgram, null, lightViewMatrix); // Unbind depthShaderProgram.unbind(); glBindFramebuffer(GL_FRAMEBUFFER, 0); } }
private void renderDepthMap(Window window, Camera camera, Scene scene) { if (scene.isRenderShadows()) { // Setup view port to match the texture size glBindFramebuffer(GL_FRAMEBUFFER, shadowMap.getDepthMapFBO()); glViewport(0, 0, ShadowMap.SHADOW_MAP_WIDTH, ShadowMap.SHADOW_MAP_HEIGHT); glClear(GL_DEPTH_BUFFER_BIT); depthShaderProgram.bind(); DirectionalLight light = scene.getSceneLight().getDirectionalLight(); Vector3f lightDirection = light.getDirection(); float lightAngleX = (float) Math.toDegrees(Math.acos(lightDirection.z)); float lightAngleY = (float) Math.toDegrees(Math.asin(lightDirection.x)); float lightAngleZ = 0; Matrix4f lightViewMatrix = transformation.updateLightViewMatrix(new Vector3f(lightDirection).mul(light.getShadowPosMult()), new Vector3f(lightAngleX, lightAngleY, lightAngleZ)); DirectionalLight.OrthoCoords orthCoords = light.getOrthoCoords(); Matrix4f orthoProjMatrix = transformation.updateOrthoProjectionMatrix(orthCoords.left, orthCoords.right, orthCoords.bottom, orthCoords.top, orthCoords.near, orthCoords.far); depthShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix); renderNonInstancedMeshes(scene, true, depthShaderProgram, null, lightViewMatrix); renderInstancedMeshes(scene, true, depthShaderProgram, null, lightViewMatrix); // Unbind depthShaderProgram.unbind(); glBindFramebuffer(GL_FRAMEBUFFER, 0); } }
private void renderDepthMap(Window window, Camera camera, Scene scene) { if (scene.isRenderShadows()) { // Setup view port to match the texture size glBindFramebuffer(GL_FRAMEBUFFER, shadowMap.getDepthMapFBO()); glViewport(0, 0, ShadowMap.SHADOW_MAP_WIDTH, ShadowMap.SHADOW_MAP_HEIGHT); glClear(GL_DEPTH_BUFFER_BIT); depthShaderProgram.bind(); DirectionalLight light = scene.getSceneLight().getDirectionalLight(); Vector3f lightDirection = light.getDirection(); float lightAngleX = (float) Math.toDegrees(Math.acos(lightDirection.z)); float lightAngleY = (float) Math.toDegrees(Math.asin(lightDirection.x)); float lightAngleZ = 0; Matrix4f lightViewMatrix = transformation.updateLightViewMatrix(new Vector3f(lightDirection).mul(light.getShadowPosMult()), new Vector3f(lightAngleX, lightAngleY, lightAngleZ)); DirectionalLight.OrthoCoords orthCoords = light.getOrthoCoords(); Matrix4f orthoProjMatrix = transformation.updateOrthoProjectionMatrix(orthCoords.left, orthCoords.right, orthCoords.bottom, orthCoords.top, orthCoords.near, orthCoords.far); depthShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix); renderNonInstancedMeshes(scene, depthShaderProgram, null, lightViewMatrix); renderInstancedMeshes(scene, depthShaderProgram, null, lightViewMatrix); // Unbind depthShaderProgram.unbind(); glBindFramebuffer(GL_FRAMEBUFFER, 0); } }
private void renderDepthMap(Window window, Camera camera, Scene scene) { if (scene.isRenderShadows()) { // Setup view port to match the texture size glBindFramebuffer(GL_FRAMEBUFFER, shadowMap.getDepthMapFBO()); glViewport(0, 0, ShadowMap.SHADOW_MAP_WIDTH, ShadowMap.SHADOW_MAP_HEIGHT); glClear(GL_DEPTH_BUFFER_BIT); depthShaderProgram.bind(); DirectionalLight light = scene.getSceneLight().getDirectionalLight(); Vector3f lightDirection = light.getDirection(); float lightAngleX = (float) Math.toDegrees(Math.acos(lightDirection.z)); float lightAngleY = (float) Math.toDegrees(Math.asin(lightDirection.x)); float lightAngleZ = 0; Matrix4f lightViewMatrix = transformation.updateLightViewMatrix(new Vector3f(lightDirection).mul(light.getShadowPosMult()), new Vector3f(lightAngleX, lightAngleY, lightAngleZ)); DirectionalLight.OrthoCoords orthCoords = light.getOrthoCoords(); Matrix4f orthoProjMatrix = transformation.updateOrthoProjectionMatrix(orthCoords.left, orthCoords.right, orthCoords.bottom, orthCoords.top, orthCoords.near, orthCoords.far); depthShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix); renderNonInstancedMeshes(scene, depthShaderProgram, null, lightViewMatrix); renderInstancedMeshes(scene, depthShaderProgram, null, lightViewMatrix); // Unbind depthShaderProgram.unbind(); glBindFramebuffer(GL_FRAMEBUFFER, 0); } }
private void renderDepthMap(Window window, Camera camera, Scene scene) { if (scene.isRenderShadows()) { // Setup view port to match the texture size glBindFramebuffer(GL_FRAMEBUFFER, shadowMap.getDepthMapFBO()); glViewport(0, 0, ShadowMap.SHADOW_MAP_WIDTH, ShadowMap.SHADOW_MAP_HEIGHT); glClear(GL_DEPTH_BUFFER_BIT); depthShaderProgram.bind(); DirectionalLight light = scene.getSceneLight().getDirectionalLight(); Vector3f lightDirection = light.getDirection(); float lightAngleX = (float) Math.toDegrees(Math.acos(lightDirection.z)); float lightAngleY = (float) Math.toDegrees(Math.asin(lightDirection.x)); float lightAngleZ = 0; Matrix4f lightViewMatrix = transformation.updateLightViewMatrix(new Vector3f(lightDirection).mul(light.getShadowPosMult()), new Vector3f(lightAngleX, lightAngleY, lightAngleZ)); DirectionalLight.OrthoCoords orthCoords = light.getOrthoCoords(); Matrix4f orthoProjMatrix = transformation.updateOrthoProjectionMatrix(orthCoords.left, orthCoords.right, orthCoords.bottom, orthCoords.top, orthCoords.near, orthCoords.far); depthShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix); renderNonInstancedMeshes(scene, depthShaderProgram, null, lightViewMatrix); renderInstancedMeshes(scene, depthShaderProgram, null, lightViewMatrix); // Unbind depthShaderProgram.unbind(); glBindFramebuffer(GL_FRAMEBUFFER, 0); } }
private void renderFog(Window window, Camera camera, Scene scene) { fogShaderProgram.bind(); Matrix4f viewMatrix = camera.getViewMatrix(); Matrix4f projectionMatrix = window.getProjectionMatrix(); fogShaderProgram.setUniform("modelMatrix", bufferPassModelMatrix); fogShaderProgram.setUniform("viewMatrix", viewMatrix); fogShaderProgram.setUniform("projectionMatrix", projectionMatrix); // Bind the scene buffer texture and the the depth texture of the G-Buffer glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, gBuffer.getPositionTexture()); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, gBuffer.getDepthTexture()); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, sceneBuffer.getTextureId()); fogShaderProgram.setUniform("positionsText", 0); fogShaderProgram.setUniform("depthText", 1); fogShaderProgram.setUniform("sceneText", 2); fogShaderProgram.setUniform("screenSize", (float) gBuffer.getWidth(), (float)gBuffer.getHeight()); fogShaderProgram.setUniform("fog", scene.getFog()); SceneLight sceneLight = scene.getSceneLight(); fogShaderProgram.setUniform("ambientLight", sceneLight.getAmbientLight()); DirectionalLight dirLight = sceneLight.getDirectionalLight(); fogShaderProgram.setUniform("lightColour", dirLight.getColor()); fogShaderProgram.setUniform("lightIntensity", dirLight.getIntensity()); bufferPassMesh.render(); fogShaderProgram.unbind(); }