From cdd09e71a5ca2dce2b8829be3f6ab1e96b43ddc2 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Mon, 11 Oct 2021 19:31:39 +0900 Subject: [PATCH] more random dither tex --- assets/LDR_512_RGBA_0.tga | 3 -- assets/dither_512_0.tga | 3 ++ assets/dither_512_1.tga | 3 ++ assets/dither_512_2.tga | 3 ++ assets/dither_512_3.tga | 3 ++ assets/dither_512_4.tga | 3 ++ assets/dither_512_5.tga | 3 ++ assets/dither_512_6.tga | 3 ++ assets/dither_512_7.tga | 3 ++ src/net/torvald/terrarum/App.java | 29 ++++++++++++++++--- src/net/torvald/terrarum/UIFakeGradOverlay.kt | 2 +- .../terrarum/modulebasegame/IngameRenderer.kt | 13 ++------- src/net/torvald/terrarum/ui/Toolkit.kt | 2 +- .../torvald/terrarum/weather/WeatherMixer.kt | 2 +- 14 files changed, 55 insertions(+), 20 deletions(-) delete mode 100644 assets/LDR_512_RGBA_0.tga create mode 100644 assets/dither_512_0.tga create mode 100644 assets/dither_512_1.tga create mode 100644 assets/dither_512_2.tga create mode 100644 assets/dither_512_3.tga create mode 100644 assets/dither_512_4.tga create mode 100644 assets/dither_512_5.tga create mode 100644 assets/dither_512_6.tga create mode 100644 assets/dither_512_7.tga diff --git a/assets/LDR_512_RGBA_0.tga b/assets/LDR_512_RGBA_0.tga deleted file mode 100644 index ec34f50d4..000000000 --- a/assets/LDR_512_RGBA_0.tga +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:2c83b05f6605e56a2f2af4a9c5b3821d11426e60517e3ec81f6edac87ecc6ffd -size 1048620 diff --git a/assets/dither_512_0.tga b/assets/dither_512_0.tga new file mode 100644 index 000000000..1f265e4d3 --- /dev/null +++ b/assets/dither_512_0.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:88fb8042914f4879ab89d08af798184173814f99de7d8cb0d30188fb0b1c3a1d +size 1048594 diff --git a/assets/dither_512_1.tga b/assets/dither_512_1.tga new file mode 100644 index 000000000..47e3017b7 --- /dev/null +++ b/assets/dither_512_1.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:79b17b40227a8dbe77530a3461db4d75efd91ffaa4dbb57457ed1b7b97dc8d1e +size 1048594 diff --git a/assets/dither_512_2.tga b/assets/dither_512_2.tga new file mode 100644 index 000000000..01e606ac4 --- /dev/null +++ b/assets/dither_512_2.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:290d8424446415652bfc446428616dc1eba1cb131ad7143ebe4e0e0c3ea5a312 +size 1048594 diff --git a/assets/dither_512_3.tga b/assets/dither_512_3.tga new file mode 100644 index 000000000..34c46ee7f --- /dev/null +++ b/assets/dither_512_3.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b08ae2fd248dda70205199cdaad97a3b813a6707be642633c09f1b34330d739f +size 1048594 diff --git a/assets/dither_512_4.tga b/assets/dither_512_4.tga new file mode 100644 index 000000000..7e764bc6c --- /dev/null +++ b/assets/dither_512_4.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4a93baf3445e9612ae2b0f03e093e01cadc2f1f3e39d456971d8807aef9f6dd7 +size 1048594 diff --git a/assets/dither_512_5.tga b/assets/dither_512_5.tga new file mode 100644 index 000000000..40962121d --- /dev/null +++ b/assets/dither_512_5.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:02e1e1866e03dfad0463532be76a4d02e139454a17c87e2ea98230db65619914 +size 1048594 diff --git a/assets/dither_512_6.tga b/assets/dither_512_6.tga new file mode 100644 index 000000000..59c61b476 --- /dev/null +++ b/assets/dither_512_6.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:df0be85f764a8b0cf889b030ba1d91cd4eb263197d9ea6e6bc8d1e07a9562d46 +size 1048594 diff --git a/assets/dither_512_7.tga b/assets/dither_512_7.tga new file mode 100644 index 000000000..aabebf35a --- /dev/null +++ b/assets/dither_512_7.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f2b14fa1f06256a1a5a29fc16ff56a9a42de65a12ef0a7aaa30e7997224faa9c +size 1048594 diff --git a/src/net/torvald/terrarum/App.java b/src/net/torvald/terrarum/App.java index 867b98a22..fc5dea69e 100644 --- a/src/net/torvald/terrarum/App.java +++ b/src/net/torvald/terrarum/App.java @@ -209,7 +209,7 @@ public class App implements ApplicationListener { - public static Texture ditherPattern; + public static Texture[] ditherPatterns = new Texture[8]; private static ShaderProgram shaderBayerSkyboxFill; // ONLY to be used by the splash screen public static ShaderProgram shaderHicolour; public static ShaderProgram shaderDebugDiff; @@ -401,7 +401,13 @@ public class App implements ApplicationListener { CommonResourcePool.INSTANCE.addToLoadingList("title_health2", () -> new Texture(Gdx.files.internal("./assets/graphics/gui/health_distance.tga"))); // set GL graphics constants - ditherPattern = new Texture(Gdx.files.internal("assets/LDR_512_RGBA_0.tga")); + for (int i = 0; i < ditherPatterns.length; i++) { + Texture t = new Texture(Gdx.files.internal("assets/dither_512_"+i+".tga")); + t.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Linear); + t.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat); + ditherPatterns[i] = t; + } + shaderBayerSkyboxFill = loadShaderFromFile("assets/4096.vert", "assets/4096_bayer_skyboxfill.frag"); shaderHicolour = loadShaderFromFile("assets/4096.vert", "assets/hicolour.frag"); shaderDebugDiff = loadShaderFromFile("assets/4096.vert", "assets/diff.frag"); @@ -579,8 +585,21 @@ public class App implements ApplicationListener { } + public static Texture getCurrentDitherTex() { + int hash = 31 + GLOBAL_RENDER_TIMER + 0x165667B1 + GLOBAL_RENDER_TIMER * 0xC2B2AE3D; + hash = Integer.rotateLeft(hash, 17) * 0x27D4EB2F; + hash ^= hash >>> 15; + hash *= 0x85EBCA77; + hash ^= hash >>> 13; + hash *= 0xC2B2AE3D; + hash ^= hash >>> 16; + hash = hash & 0x7FFFFFFF; + + return ditherPatterns[hash % ditherPatterns.length]; + } + private void drawSplash() { - ditherPattern.bind(0); + getCurrentDitherTex().bind(0); shaderBayerSkyboxFill.bind(); shaderBayerSkyboxFill.setUniformMatrix("u_projTrans", camera.combined); shaderBayerSkyboxFill.setUniformi("u_texture", 0); @@ -707,7 +726,9 @@ public class App implements ApplicationListener { ThreadExecutor.INSTANCE.killAll(); - ditherPattern.dispose(); + for (Texture texture : ditherPatterns) { + texture.dispose(); + } shaderBayerSkyboxFill.dispose(); shaderHicolour.dispose(); shaderDebugDiff.dispose(); diff --git a/src/net/torvald/terrarum/UIFakeGradOverlay.kt b/src/net/torvald/terrarum/UIFakeGradOverlay.kt index c5cb1ef92..9df20ddda 100644 --- a/src/net/torvald/terrarum/UIFakeGradOverlay.kt +++ b/src/net/torvald/terrarum/UIFakeGradOverlay.kt @@ -40,7 +40,7 @@ class UIFakeGradOverlay : UICanvas() { val dither = App.getConfigBoolean("fx_dither") if (dither) { - IngameRenderer.ditherPattern.bind(1) + App.getCurrentDitherTex().bind(1) Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it } diff --git a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt index 6231ca8f4..77b611853 100644 --- a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt +++ b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt @@ -58,13 +58,6 @@ object IngameRenderer : Disposable { private lateinit var lightTex: TextureRegion private lateinit var blurTex: TextureRegion - val ditherPattern = App.ditherPattern - - init { - ditherPattern.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Linear) - ditherPattern.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat) - } - // you must have lightMixed FBO; otherwise you'll be reading from unbaked FBO and it freaks out GPU inline fun isDither() = App.getConfigBoolean("fx_dither") @@ -479,7 +472,7 @@ object IngameRenderer : Disposable { gdxSetBlend() - ditherPattern.bind(1) + App.getCurrentDitherTex().bind(1) Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it batch.inUse { @@ -568,7 +561,7 @@ object IngameRenderer : Disposable { setCameraPosition(0f, 0f) val (xrem, yrem) = worldCamToRenderPos() - ditherPattern.bind(1) + App.getCurrentDitherTex().bind(1) Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it batch.inUse { @@ -688,7 +681,7 @@ object IngameRenderer : Disposable { blurTex.texture = blurReadBuffer.colorBufferTexture blurTex.texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear) blurTex.texture.bind(0) - ditherPattern.bind(1) // order is important! + App.getCurrentDitherTex().bind(1) // order is important! shaderBlur.bind() shaderBlur.setUniformMatrix("u_projTrans", camera.combined) diff --git a/src/net/torvald/terrarum/ui/Toolkit.kt b/src/net/torvald/terrarum/ui/Toolkit.kt index 96036973b..8082a283c 100644 --- a/src/net/torvald/terrarum/ui/Toolkit.kt +++ b/src/net/torvald/terrarum/ui/Toolkit.kt @@ -107,7 +107,7 @@ object Toolkit : Disposable { batch.end() - IngameRenderer.ditherPattern.bind(1) + App.getCurrentDitherTex().bind(1) Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it batch.begin() diff --git a/src/net/torvald/terrarum/weather/WeatherMixer.kt b/src/net/torvald/terrarum/weather/WeatherMixer.kt index b54d09d30..34ee7d55a 100644 --- a/src/net/torvald/terrarum/weather/WeatherMixer.kt +++ b/src/net/torvald/terrarum/weather/WeatherMixer.kt @@ -181,7 +181,7 @@ internal object WeatherMixer : RNGConsumer { val dither = App.getConfigBoolean("fx_dither") if (dither) { - IngameRenderer.ditherPattern.bind(1) + App.getCurrentDitherTex().bind(1) Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it }