/* * Copyright 2016 MovingBlocks * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.terasology.rendering.dag.nodes; import org.terasology.assets.ResourceUrn; import org.terasology.config.Config; import org.terasology.config.RenderingConfig; import org.terasology.registry.In; import org.terasology.rendering.nui.properties.Range; import org.terasology.rendering.opengl.FBOConfig; import org.terasology.rendering.opengl.fbms.DisplayResolutionDependentFBOs; /** * This class is a thin facade in front of the BlurNode class it inherits from. * The term "late" is due to the fact that this type of nodes is used near the * end of the rendering process leading to an image shown on the user display. * * Given an input FBO a blurred version of it will be stored in the given output FBO. * Eventually the blurred version can be used for blur-based effects such as * Depth of Field. * * For more information on Blur: https://en.wikipedia.org/wiki/Box_blur * For more information on DoF: http://en.wikipedia.org/wiki/Depth_of_field */ public class LateBlurNode extends BlurNode { public static final ResourceUrn FIRST_LATE_BLUR_FBO = new ResourceUrn("engine:fbo.firstLateBlur"); public static final ResourceUrn SECOND_LATE_BLUR_FBO = new ResourceUrn("engine:fbo.secondLateBlur"); @Range(min = 0.0f, max = 16.0f) private static final float OVERALL_BLUR_RADIUS_FACTOR = 0.8f; @In private DisplayResolutionDependentFBOs displayResolutionDependentFBOs; @In private Config config; private RenderingConfig renderingConfig; /** * Initializes a LateBlurNode instance.This method must be called once shortly after instantiation * to fully initialize the node and make it ready for rendering. * * @param inputConfig an FBOConfig describing the input FBO, to be retrieved from an injected DisplayResolutionDependentFBOs instance. * @param outputConfig an FBOConfig describing the output FBO, to be retrieved from an injected DisplayResolutionDependentFBOs instance. * @param aLabel a String to label the instance's entry in output generated by the PerformanceMonitor */ public void initialise(FBOConfig inputConfig, FBOConfig outputConfig, String aLabel) { super.initialise(inputConfig, outputConfig, displayResolutionDependentFBOs, blurRadius, aLabel); // note: blurRadius is 0.0 at this stage. updateBlurRadius(); // only here blurRadius is properly set. } /** * This method establishes the conditions in which the blur will take place, by enabling or disabling the node. * * In this particular case the node is enabled if RenderingConfig.getBlurIntensity is not 0 - or blur is enabled. */ @Override protected void setupConditions() { renderingConfig = config.getRendering(); renderingConfig.subscribe(RenderingConfig.BLUR_INTENSITY, this); requiresCondition(() -> renderingConfig.getBlurIntensity() != 0); } /** * An instance of this class is a subscriber to an FBOManager and to the RenderingConfig. The first * invokes this method when FBOs have been regenerated (i.e. after resizing the display), while the * second does it when its BLUR_INTENSITY parameter changes. */ @Override public void update() { super.update(); updateBlurRadius(); } private void updateBlurRadius() { this.blurRadius = OVERALL_BLUR_RADIUS_FACTOR * Math.max(1, renderingConfig.getBlurIntensity()); } }