From e98c2feb85c123411076f9ebe7d4a3d8d3a4ef12 Mon Sep 17 00:00:00 2001 From: Arkadiusz Buras Date: Mon, 31 Aug 2015 13:19:36 +0200 Subject: [PATCH] Light shafts --- .../graphics/postprocessing/default.json | 17 +++++ .../graphics/postprocessing/final.frag.glsl | 10 +-- .../fix-light-scattering.frag.glsl | 41 ++++++++++++ .../graphics/shaders/helpers/shadow_map.glsl | 12 ++-- core/src/macbury/forge/Config.java | 3 +- core/src/macbury/forge/graphics/fbo/Fbo.java | 15 +++-- .../graphics/fbo/FrameBufferManager.java | 2 +- .../forge/graphics/skybox/DayNightSkybox.java | 16 ++++- core/src/macbury/forge/level/Level.java | 2 +- .../src/macbury/forge/level/env/LevelEnv.java | 9 +++ .../macbury/forge/shaders/DepthShader.java | 12 +++- .../UniformLightPositionOnScreen.java | 64 +++++++++++++++++++ .../forge/systems/WorldRenderingSystem.java | 59 ++++++++++++----- core/src/macbury/forge/time/TimeManager.java | 2 +- .../controllers/PostProcessingController.java | 45 +++++++++++++ .../macbury/forge/editor/views/MainMenu.java | 34 ++-------- .../forge/editor/windows/MainWindow.java | 2 +- 17 files changed, 276 insertions(+), 69 deletions(-) create mode 100644 core/assets/graphics/postprocessing/fix-light-scattering.frag.glsl create mode 100644 core/src/macbury/forge/shaders/uniforms/UniformLightPositionOnScreen.java diff --git a/core/assets/graphics/postprocessing/default.json b/core/assets/graphics/postprocessing/default.json index 93f218b..9e428a1 100644 --- a/core/assets/graphics/postprocessing/default.json +++ b/core/assets/graphics/postprocessing/default.json @@ -2,10 +2,26 @@ buffers: [ { width: 512, height: 512, format: "RGB888", filter: "Linear", wrap: "MirroredRepeat", depth: false, name: "my:small-color" }, { width: 512, height: 512, format: "RGB888", filter: "Linear", wrap: "ClampToEdge", depth: false, name: "my:blur" } + { width: 512, height: 512, format: "RGBA8888", filter: "Linear", wrap: "ClampToEdge", depth: false, name: "my:light-scattering" } ], steps: [ { copy: "forge:main-color", target: "my:small-color" }, + { + target: "my:light-scattering", + fragment: "fix-light-scattering", + customUniforms: { + u_mainTexture: "forge:light-scattering", + u_density: 0.80, + u_weight: 5.65, + u_exposure: 0.0034, + u_decay: 1.0, + u_numSamples: 50 + }, + uniforms: [ + "LightPositionOnScreen" + ] + }, { target: "my:blur", fragment: "blur", @@ -23,6 +39,7 @@ customUniforms: { u_mainTexture: "forge:main-color", u_blurTexture: "my:blur", + u_lightScatteringTexture: "my:light-scattering", u_blurMix: 0.25 } } diff --git a/core/assets/graphics/postprocessing/final.frag.glsl b/core/assets/graphics/postprocessing/final.frag.glsl index e3151e9..cdbcb39 100644 --- a/core/assets/graphics/postprocessing/final.frag.glsl +++ b/core/assets/graphics/postprocessing/final.frag.glsl @@ -1,7 +1,9 @@ varying vec2 v_texCoords; void main() { - vec4 mainColor = texture2D(u_mainTexture, v_texCoords); - vec4 vignetteColor = texture2D(u_vignetteTexture, v_texCoords); - vec4 blurColor = texture2D(u_blurTexture, v_texCoords); - gl_FragColor = mix(mainColor, blurColor, u_blurMix) * vignetteColor; + vec4 mainColor = texture2D(u_mainTexture, v_texCoords); + vec4 vignetteColor = texture2D(u_vignetteTexture, v_texCoords); + vec4 blurColor = texture2D(u_blurTexture, v_texCoords); + vec4 lightScatteringColor = texture2D(u_lightScatteringTexture, v_texCoords); + gl_FragColor = (mix(mainColor, blurColor, u_blurMix) + lightScatteringColor ) * vignetteColor; +// gl_FragColor = mix(mainColor, lightScatteringColor, 0.8f); } diff --git a/core/assets/graphics/postprocessing/fix-light-scattering.frag.glsl b/core/assets/graphics/postprocessing/fix-light-scattering.frag.glsl new file mode 100644 index 0000000..96ca414 --- /dev/null +++ b/core/assets/graphics/postprocessing/fix-light-scattering.frag.glsl @@ -0,0 +1,41 @@ + +varying vec2 v_texCoords; + +vec4 getSampleColor(vec2 coords) { + vec4 rawColor = texture2D(u_mainTexture, coords); + + if (rawColor.r >= 0.01f && rawColor.g == 0.0f && rawColor.b == 0.0f) { + return vec4(0.0f, 0.0f, 0.0f, 1.0f); + } else { + return rawColor; + } +} + +void main() { + vec4 finalColor = vec4(0.0f, 0.0f, 0.0f, 1.0f); + + if (u_lightDirDotViewDir < 0.0f) { + float lightDirDotViewDir = abs(u_lightDirDotViewDir); + vec2 texCoord = v_texCoords.st; + vec2 deltaTexCoord = (1.0 / float(u_numSamples)) * u_density * vec2(texCoord.xy - u_lightPositonOnScreen.xy); + float dist = length(deltaTexCoord.xy); + + float threshold = 0.01f; + if (dist > threshold) { + deltaTexCoord.xy /= dist / threshold; + } + + float illuminationDecay = 1.0f; + for(int i=0; i < int(u_numSamples); i++) { + texCoord -= deltaTexCoord; + vec4 sampleColor = getSampleColor(texCoord); + sampleColor *= illuminationDecay * u_weight; + finalColor += sampleColor; + illuminationDecay *= u_decay; + } + + finalColor *= u_exposure * lightDirDotViewDir; + } + + gl_FragColor = finalColor; +} diff --git a/core/assets/graphics/shaders/helpers/shadow_map.glsl b/core/assets/graphics/shaders/helpers/shadow_map.glsl index 91c696f..990d46b 100644 --- a/core/assets/graphics/shaders/helpers/shadow_map.glsl +++ b/core/assets/graphics/shaders/helpers/shadow_map.glsl @@ -3,14 +3,16 @@ float calculateDepth(vec4 position, vec4 eyePosition, float cameraFar) { } vec4 pack(float depth) { - const vec4 bias = vec4(1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0, 0.0); - vec4 color = vec4(depth, fract(depth * 255.0), fract(depth * 65025.0), fract(depth * 160581375.0)); - return color - (color.yzww * bias); + //const vec4 bias = vec4(1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0, 0.0); + //vec4 color = vec4(depth, fract(depth * 255.0), fract(depth * 65025.0), fract(depth * 160581375.0)); +// return color - (color.yzww * bias); + return vec4(depth, 0.0f, 0.0f, 1.0f); } float unpack(vec4 packedZValue) { - const vec4 bitShifts = vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 160581375.0); - return dot(packedZValue,bitShifts); + //const vec4 bitShifts = vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 160581375.0); + //return dot(packedZValue,bitShifts); + return packedZValue.r; } float shadowBias(vec3 normal, vec3 lightDir) { diff --git a/core/src/macbury/forge/Config.java b/core/src/macbury/forge/Config.java index 700e72b..96ddbae 100644 --- a/core/src/macbury/forge/Config.java +++ b/core/src/macbury/forge/Config.java @@ -15,7 +15,7 @@ public class Config extends KVStorage { public enum Key { ResolutionWidth, ResolutionHeight, Fullscreen, Debug, NearShadowMapSize, FarShadowMapSize, BloomTextureSize, ReflectionBufferSize, RefractionBufferSize, - GenerateWireframe, NearShadowDistance, RenderDebug, RenderDynamicOctree, RenderStaticOctree, RenderBoundingBox, RenderBulletDebug, Editor, + GenerateWireframe, NearShadowDistance, RenderDebug, RenderDynamicOctree, RenderStaticOctree, RenderBoundingBox, RenderBulletDebug, Editor, LightScatteringTextureSize } public enum RenderDebug { @@ -33,6 +33,7 @@ public void setDefaults() { putInt(Key.BloomTextureSize, 512); putInt(Key.ReflectionBufferSize, 512); putInt(Key.RefractionBufferSize, 512); + putInt(Key.LightScatteringTextureSize, 512); putInt(Key.NearShadowDistance, 10); putBool(Key.Fullscreen, false); putBool(Key.Debug, false); diff --git a/core/src/macbury/forge/graphics/fbo/Fbo.java b/core/src/macbury/forge/graphics/fbo/Fbo.java index ad5ee7c..6cc2374 100644 --- a/core/src/macbury/forge/graphics/fbo/Fbo.java +++ b/core/src/macbury/forge/graphics/fbo/Fbo.java @@ -4,11 +4,14 @@ * Created by macbury on 20.07.15. */ public class Fbo { - public final static String FRAMEBUFFER_MAIN_COLOR = "forge:main-color"; - public final static String FRAMEBUFFER_SUN_FAR_DEPTH = "forge:sun-far"; - public final static String FRAMEBUFFER_SUN_NEAR_DEPTH = "forge:sun-near"; + public final static String FRAMEBUFFER_SUN_FAR_DEPTH = "forge:sun-far"; + public final static String FRAMEBUFFER_SUN_NEAR_DEPTH = "forge:sun-near"; - public static final String FRAMEBUFFER_REFLECTIONS = "forge:reflections"; - public static final String FRAMEBUFFER_REFRACTIONS = "forge:refractions"; - public static final String FRAMEBUFFER_FINAL = "forge:final-color"; + public static final String FRAMEBUFFER_REFLECTIONS = "forge:reflections"; + public static final String FRAMEBUFFER_REFRACTIONS = "forge:refractions"; + + public static final String FRAMEBUFFER_LIGHT_SCATTERING = "forge:light-scattering"; + + public final static String FRAMEBUFFER_MAIN_COLOR = "forge:main-color"; + public static final String FRAMEBUFFER_FINAL = "forge:final-color"; } diff --git a/core/src/macbury/forge/graphics/fbo/FrameBufferManager.java b/core/src/macbury/forge/graphics/fbo/FrameBufferManager.java index c1ed0dc..6421797 100644 --- a/core/src/macbury/forge/graphics/fbo/FrameBufferManager.java +++ b/core/src/macbury/forge/graphics/fbo/FrameBufferManager.java @@ -190,7 +190,7 @@ public void begin(String fbIdn) { public void createDefaultFrameBuffers() { create(Fbo.FRAMEBUFFER_FINAL); create(Fbo.FRAMEBUFFER_MAIN_COLOR); - + create(Fbo.FRAMEBUFFER_LIGHT_SCATTERING, Pixmap.Format.RGBA8888, ForgE.config.getInt(Config.Key.LightScatteringTextureSize), ForgE.config.getInt(Config.Key.LightScatteringTextureSize), true, Texture.TextureWrap.ClampToEdge, Texture.TextureFilter.Nearest); create(Fbo.FRAMEBUFFER_REFLECTIONS, Pixmap.Format.RGBA8888, ForgE.config.getInt(Config.Key.ReflectionBufferSize), ForgE.config.getInt(Config.Key.ReflectionBufferSize), true, Texture.TextureWrap.Repeat, Texture.TextureFilter.Linear); create(Fbo.FRAMEBUFFER_REFRACTIONS, Pixmap.Format.RGBA8888, ForgE.config.getInt(Config.Key.RefractionBufferSize), ForgE.config.getInt(Config.Key.RefractionBufferSize), true, Texture.TextureWrap.Repeat, Texture.TextureFilter.Linear); createFloat(Fbo.FRAMEBUFFER_SUN_FAR_DEPTH, ForgE.config.getInt(Config.Key.FarShadowMapSize), ForgE.config.getInt(Config.Key.FarShadowMapSize), true, Texture.TextureWrap.ClampToEdge, Texture.TextureFilter.Nearest); diff --git a/core/src/macbury/forge/graphics/skybox/DayNightSkybox.java b/core/src/macbury/forge/graphics/skybox/DayNightSkybox.java index 46022f6..5095c70 100644 --- a/core/src/macbury/forge/graphics/skybox/DayNightSkybox.java +++ b/core/src/macbury/forge/graphics/skybox/DayNightSkybox.java @@ -50,6 +50,8 @@ public class DayNightSkybox extends Skybox { private Color fogColor = new Color(); private Color ambientColor = new Color(); private Color sunColor = new Color(); + private boolean renderOnlySun; + @Override public void update(float delta, Camera camera) { updateFogColor(); @@ -132,7 +134,8 @@ public void dispose() { @Override public void getRenderables(Array renderables, Pool pool) { //renderables.add(buildSunMoon()); - renderables.add(getCubeRenderable()); + if (!renderOnlySun) + renderables.add(getCubeRenderable()); } @@ -276,4 +279,15 @@ public Texture getSkyMapTexture() { return skyMapTexture; } + public void setRenderOnlySun(boolean renderOnlySun) { + this.renderOnlySun = renderOnlySun; + } + + public boolean isRenderOnlySun() { + return renderOnlySun; + } + + public void getLightPosition(Vector3 out) { + sunMonRenderable.worldTransform.getTranslation(out); + } } diff --git a/core/src/macbury/forge/level/Level.java b/core/src/macbury/forge/level/Level.java index cebbdc1..fe2caa8 100644 --- a/core/src/macbury/forge/level/Level.java +++ b/core/src/macbury/forge/level/Level.java @@ -67,7 +67,7 @@ public Level(LevelState state, TerrainGeometryProvider geometryProvider) { this.octree = OctreeNode.root(); this.batch = new VoxelBatch(renderContext, colorShaderProvider); - this.camera = new GameCamera(); + this.camera = env.mainCamera; this.frustrumDebugger = new FrustrumDebugAndRenderer(); frustrumDebugger.add(camera); frustrumDebugger.add(env.mainLight.getShadowCamera()); diff --git a/core/src/macbury/forge/level/env/LevelEnv.java b/core/src/macbury/forge/level/env/LevelEnv.java index a3ea9c4..3dba15a 100644 --- a/core/src/macbury/forge/level/env/LevelEnv.java +++ b/core/src/macbury/forge/level/env/LevelEnv.java @@ -8,6 +8,7 @@ import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.utils.Disposable; import macbury.forge.assets.assets.TextureAsset; +import macbury.forge.graphics.camera.GameCamera; import macbury.forge.graphics.light.OrthographicDirectionalLight; import macbury.forge.graphics.skybox.CubemapSkybox; import macbury.forge.graphics.skybox.Skybox; @@ -17,10 +18,16 @@ * Created by macbury on 28.10.14. */ public class LevelEnv implements Disposable { + public GameCamera mainCamera; public enum ClipMode { None, Reflection, Refraction } + + public enum DepthShaderMode { + Normal, OnlyFront + } + public Skybox skybox; public OrthographicDirectionalLight mainLight; public Color ambientLight; @@ -33,9 +40,11 @@ public enum ClipMode { public Vector3 gravity = new Vector3(0, -6f, 0); private Texture windDisplacementTexture; + public DepthShaderMode depthShaderMode = DepthShaderMode.Normal; public WaterEnv water; public LevelEnv() { + mainCamera = new GameCamera(); water = new WaterEnv(); skyColor = Color.valueOf("3498db"); fogColor = new Color(skyColor); diff --git a/core/src/macbury/forge/shaders/DepthShader.java b/core/src/macbury/forge/shaders/DepthShader.java index b43dc2b..0cdb51a 100644 --- a/core/src/macbury/forge/shaders/DepthShader.java +++ b/core/src/macbury/forge/shaders/DepthShader.java @@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.GL30; import com.badlogic.gdx.graphics.g3d.Renderable; import macbury.forge.graphics.batch.renderable.BaseRenderable; +import macbury.forge.level.env.LevelEnv; import macbury.forge.shaders.utils.RenderableBaseShader; /** @@ -19,11 +20,16 @@ public boolean canRender(Renderable instance) { public void beforeRender(Renderable renderable) { context.setDepthMask(true); context.setDepthTest(GL30.GL_LESS); - if (BaseRenderable.haveTransparency(renderable.material)) { - context.setCullFace(GL30.GL_NONE); + if (env.depthShaderMode == LevelEnv.DepthShaderMode.Normal) { + if (BaseRenderable.haveTransparency(renderable.material)) { + context.setCullFace(GL30.GL_NONE); + } else { + context.setCullFace(GL20.GL_FRONT); + } } else { - context.setCullFace(GL20.GL_FRONT); + context.setCullFace(GL20.GL_BACK); } + } @Override diff --git a/core/src/macbury/forge/shaders/uniforms/UniformLightPositionOnScreen.java b/core/src/macbury/forge/shaders/uniforms/UniformLightPositionOnScreen.java new file mode 100644 index 0000000..83403d3 --- /dev/null +++ b/core/src/macbury/forge/shaders/uniforms/UniformLightPositionOnScreen.java @@ -0,0 +1,64 @@ +package macbury.forge.shaders.uniforms; + +import com.badlogic.gdx.graphics.Camera; +import com.badlogic.gdx.graphics.g3d.utils.RenderContext; +import com.badlogic.gdx.graphics.glutils.ShaderProgram; +import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.math.Vector3; +import macbury.forge.ForgE; +import macbury.forge.graphics.skybox.DayNightSkybox; +import macbury.forge.level.env.LevelEnv; +import macbury.forge.shaders.utils.BaseUniform; + +/** + * Created by macbury on 31.08.15. + */ +public class UniformLightPositionOnScreen extends BaseUniform { + private static final String UNIFORM_POS_ON_SCREEN = "u_lightPositonOnScreen"; + private static final String UNIFORM_DOT_DIR_VIEW_NAME = "u_lightDirDotViewDir"; + + private static final float OFF_SCREEN_RENDER_RATIO = 2.0F; + private final static Vector3 tempVec = new Vector3(); + @Override + public void defineUniforms() { + define(UNIFORM_POS_ON_SCREEN, Vector2.class); + define(UNIFORM_DOT_DIR_VIEW_NAME, Float.class); + } + + @Override + public void bind(ShaderProgram shader, LevelEnv env, RenderContext context, Camera camera) { + if (ForgE.time.isDay()) { + shader.setUniformf( + UNIFORM_DOT_DIR_VIEW_NAME, + tempVec.set(env.mainLight.direction).dot(env.mainCamera.direction) + ); + } else { + shader.setUniformf( UNIFORM_DOT_DIR_VIEW_NAME, 1 ); + } + + + if (DayNightSkybox.class.isInstance(env.skybox)) { + DayNightSkybox dayNightSkybox = (DayNightSkybox)env.skybox; + dayNightSkybox.getLightPosition(tempVec); + env.mainCamera.project(tempVec); + + /*tempVec.x /= env.mainCamera.far; + tempVec.y /= env.mainCamera.far; + + tempVec.x = (tempVec.x + 1.0f) / 2.0f; + tempVec.y = (tempVec.y + 1.0f) / 2.0f; + //tempVec.z /= camera.far; +*/ + shader.setUniformf( + UNIFORM_POS_ON_SCREEN, + tempVec.x / env.mainCamera.viewportWidth, + tempVec.y / env.mainCamera.viewportHeight + ); + } + } + + @Override + public void dispose() { + + } +} diff --git a/core/src/macbury/forge/systems/WorldRenderingSystem.java b/core/src/macbury/forge/systems/WorldRenderingSystem.java index a6cb455..7ab98c8 100644 --- a/core/src/macbury/forge/systems/WorldRenderingSystem.java +++ b/core/src/macbury/forge/systems/WorldRenderingSystem.java @@ -14,6 +14,7 @@ import macbury.forge.components.RenderableComponent; import macbury.forge.graphics.camera.ICamera; import macbury.forge.graphics.light.OrthographicDirectionalLight; +import macbury.forge.graphics.skybox.DayNightSkybox; import macbury.forge.graphics.skybox.Skybox; import macbury.forge.graphics.batch.VoxelBatch; import macbury.forge.graphics.camera.GameCamera; @@ -65,6 +66,7 @@ public WorldRenderingSystem(Level level) { @Override public void update(float deltaTime) { + env.depthShaderMode = LevelEnv.DepthShaderMode.Normal; batch.setShaderProvider(depthShaderProvider); { renderSunDepth(); } @@ -73,8 +75,11 @@ public void update(float deltaTime) { renderReflections(); renderRefractions(); + env.water.clipMode = LevelEnv.ClipMode.None; + prepareElementsToRender(mainCamera); renderFinal(); } + renderLightScattering(); } private void renderSunDepth() { @@ -96,8 +101,10 @@ private void renderSunDepth() { */ sunLight.begin(mainCamera); { ForgE.fb.begin(Fbo.FRAMEBUFFER_SUN_FAR_DEPTH); { + prepareElementsToRender(sunLight.getShadowCamera()); renderBucketWith(false, false, sunLight.getShadowCamera()); - } ForgE.fb.end(); + } + ForgE.fb.end(); } sunLight.end(mainCamera); } @@ -110,6 +117,7 @@ private void renderReflections() { CameraUtils.invertPitch(mainCamera); mainCamera.update(true); ForgE.fb.begin(Fbo.FRAMEBUFFER_REFLECTIONS); { + prepareElementsToRender(mainCamera); renderBucketWith(true, false, mainCamera); } ForgE.fb.end(); @@ -120,20 +128,43 @@ private void renderReflections() { private void renderRefractions() { env.water.clipMode = LevelEnv.ClipMode.Refraction; - ForgE.fb.begin(Fbo.FRAMEBUFFER_REFRACTIONS); { + ForgE.fb.begin(Fbo.FRAMEBUFFER_REFRACTIONS); + { + prepareElementsToRender(mainCamera); renderBucketWith(false, false, mainCamera); } ForgE.fb.end(); } private void renderFinal() { - env.water.clipMode = LevelEnv.ClipMode.None; ForgE.fb.begin(Fbo.FRAMEBUFFER_MAIN_COLOR); { renderBucketWith(true, true, mainCamera); } ForgE.fb.end(); } - private void renderBucketWith(boolean withSkybox, boolean withWater, ICamera camera) { + private void renderLightScattering() { + env.depthShaderMode = LevelEnv.DepthShaderMode.OnlyFront; + ForgE.fb.begin(Fbo.FRAMEBUFFER_LIGHT_SCATTERING); { + ForgE.graphics.clearAll(Color.CLEAR); + batch.begin(mainCamera); { + batch.setShaderProvider(colorShaderProvider); { + if (DayNightSkybox.class.isInstance(skybox)) { + DayNightSkybox dayNightSkybox = (DayNightSkybox)skybox; + dayNightSkybox.setRenderOnlySun(true); + } + skybox.render(batch, env, mainCamera); + } + + batch.setShaderProvider(depthShaderProvider); { + batch.pushAll(terrain.visibleTerrainFaces); + batch.addAll(finalBucket); + batch.render(env); + } + } batch.end(); + } ForgE.fb.end(); + } + + private void prepareElementsToRender(ICamera camera) { finalBucket.clear(); octreeVisibleObjects.clear(); camera.extendFov(); { @@ -152,11 +183,16 @@ private void renderBucketWith(boolean withSkybox, boolean withWater, ICamera cam finalBucket.add(modelInstance); } } + } - batch.begin((Camera) camera); - { + private void renderBucketWith(boolean withSkybox, boolean withWater, ICamera camera) { + batch.begin((Camera) camera); { if (withSkybox) { ForgE.graphics.clearAll(env.skyColor); + if (DayNightSkybox.class.isInstance(skybox)) { + DayNightSkybox dayNightSkybox = (DayNightSkybox)skybox; + dayNightSkybox.setRenderOnlySun(false); + } skybox.render(batch, env, (Camera)camera); } else { ForgE.graphics.clearAll(Color.BLACK); @@ -170,15 +206,4 @@ private void renderBucketWith(boolean withSkybox, boolean withWater, ICamera cam } batch.end(); } - public void processEntity(Entity entity, float deltaTime) { - PositionComponent position = pm.get(entity); - RenderableComponent renderable = rm.get(entity); -/* - if (position.visible) { - ModelInstance modelInstance = renderable.getModelInstance(); - - position.applyWorldTransform(modelInstance.transform); - finalBucket.add(modelInstance); - }*/ - } } diff --git a/core/src/macbury/forge/time/TimeManager.java b/core/src/macbury/forge/time/TimeManager.java index 654b88d..17c0acc 100644 --- a/core/src/macbury/forge/time/TimeManager.java +++ b/core/src/macbury/forge/time/TimeManager.java @@ -31,7 +31,7 @@ public class TimeManager implements Disposable { public TimeManager() { this.duration = DEFAULT_TIME; days = 1; - this.timeSpeed = 10; + this.timeSpeed = 1000; } public void update() { diff --git a/editor/src/macbury/forge/editor/controllers/PostProcessingController.java b/editor/src/macbury/forge/editor/controllers/PostProcessingController.java index a1edcfb..69edb61 100644 --- a/editor/src/macbury/forge/editor/controllers/PostProcessingController.java +++ b/editor/src/macbury/forge/editor/controllers/PostProcessingController.java @@ -2,6 +2,7 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; +import macbury.forge.ForgE; import macbury.forge.editor.controllers.listeners.OnMapChangeListener; import macbury.forge.editor.reloader.DirectoryWatchJob; import macbury.forge.editor.reloader.DirectoryWatcher; @@ -9,11 +10,19 @@ import macbury.forge.graphics.postprocessing.PostProcessingManager; import macbury.forge.level.Level; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.IOException; + /** * Created by macbury on 31.08.15. */ public class PostProcessingController implements OnMapChangeListener, DirectoryWatchJob.DirectoryWatchJobListener { private Level currentLevel; + private JMenu fboMenu; public PostProcessingController(DirectoryWatcher directoryWatcher) { directoryWatcher.addListener(PostProcessingManager.STORAGE_DIR, this); @@ -22,6 +31,7 @@ public PostProcessingController(DirectoryWatcher directoryWatcher) { @Override public void onCloseMap(ProjectController controller, LevelEditorScreen screen) { currentLevel = null; + updateUI(); } @Override @@ -55,10 +65,45 @@ private void reloadPostProcessing() { if (currentLevel != null) { try { currentLevel.postProcessing.reload(); + updateUI(); System.gc(); } catch (Exception e) { e.printStackTrace(); } } } + + public void setMenu(JMenu fboMenu) { + this.fboMenu = fboMenu; + updateUI(); + } + + private void updateUI() { + fboMenu.removeAll(); + if (fboMenu != null) { + for (String frameBufferName : ForgE.fb.all().keys()) { + JMenuItem item = new JMenuItem(frameBufferName); + item.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + + Gdx.app.postRunnable(new Runnable() { + @Override + public void run() { + File screenshotFile = ForgE.fb.saveAsPng(frameBufferName).file(); + try { + Desktop.getDesktop().open(screenshotFile); + } catch (IOException e1) { + e1.printStackTrace(); + } + } + }); + + + } + }); + fboMenu.add(item); + } + } + } } diff --git a/editor/src/macbury/forge/editor/views/MainMenu.java b/editor/src/macbury/forge/editor/views/MainMenu.java index 89043e3..7649fc4 100644 --- a/editor/src/macbury/forge/editor/views/MainMenu.java +++ b/editor/src/macbury/forge/editor/views/MainMenu.java @@ -3,10 +3,7 @@ import com.badlogic.gdx.Gdx; import macbury.forge.Config; import macbury.forge.ForgE; -import macbury.forge.editor.controllers.BlocksController; -import macbury.forge.editor.controllers.DockFramesController; -import macbury.forge.editor.controllers.ProjectController; -import macbury.forge.editor.controllers.ShadersController; +import macbury.forge.editor.controllers.*; import macbury.forge.editor.controllers.listeners.OnMapChangeListener; import macbury.forge.editor.screens.LevelEditorScreen; @@ -25,6 +22,7 @@ public class MainMenu extends JPopupMenu implements OnMapChangeListener { private final BlocksController blocksController; private final DockFramesController dockFrameController; private final ShadersController shadersController; + private final PostProcessingController postProcessingController; public JCheckBoxMenuItem debugRenderDynamicOctree; public JCheckBoxMenuItem debugBoundingBox; public JRadioButtonMenuItem debugWireframeItem; @@ -35,13 +33,14 @@ public class MainMenu extends JPopupMenu implements OnMapChangeListener { private JRadioButtonMenuItem debugNormalsItem; private JRadioButtonMenuItem debugLightingItem; - public MainMenu(ProjectController projectController, BlocksController blocksController, DockFramesController dockFrameController, ShadersController shadersController) { + public MainMenu(ProjectController projectController, BlocksController blocksController, DockFramesController dockFrameController, ShadersController shadersController, PostProcessingController postProcessingController) { super(); this.controller = projectController; this.blocksController = blocksController; this.dockFrameController = dockFrameController; this.shadersController = shadersController; + this.postProcessingController = postProcessingController; //add(Box.createRigidArea(new Dimension(320,28))); } @@ -80,29 +79,8 @@ public void actionPerformed(ActionEvent e) { private void createExportFboMenu() { JMenu fboMenu = new JMenu("Export FBO"); - for (String frameBufferName : ForgE.fb.all().keys()) { - JMenuItem item = new JMenuItem(frameBufferName); - item.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - - Gdx.app.postRunnable(new Runnable() { - @Override - public void run() { - File screenshotFile = ForgE.fb.saveAsPng(frameBufferName).file(); - try { - Desktop.getDesktop().open(screenshotFile); - } catch (IOException e1) { - e1.printStackTrace(); - } - } - }); - - - } - }); - fboMenu.add(item); - } + postProcessingController.setMenu(fboMenu); + add(fboMenu); } diff --git a/editor/src/macbury/forge/editor/windows/MainWindow.java b/editor/src/macbury/forge/editor/windows/MainWindow.java index 1ff1b73..faf6a10 100644 --- a/editor/src/macbury/forge/editor/windows/MainWindow.java +++ b/editor/src/macbury/forge/editor/windows/MainWindow.java @@ -118,7 +118,7 @@ public MainWindow() { blocksController = new BlocksController(blockList, directoryWatcher, jobs, (ImagePanel) panelPrimaryBlock, (ImagePanel) panelSecondaryBlock); this.progressTaskDialog = new ProgressTaskDialog(); projectController = new ProjectController(); - mainMenu = new MainMenu(projectController, blocksController, dockFrameController, shadersController); + mainMenu = new MainMenu(projectController, blocksController, dockFrameController, shadersController, postProcessingController); eventsToolsController = new EventsController(this); terrainToolsController = new TerrainToolsController(terrainToolsToolbar, blocksController, inputProcessor, terrainInspectorPanel); playerController = new PlayerController(projectController, jobs);