dithering on grad overlay

This commit is contained in:
minjaesong
2021-10-10 15:38:09 +09:00
parent e32dfa3560
commit f3c56f5d47
10 changed files with 79 additions and 16 deletions

17
assets/diff.frag Normal file
View File

@@ -0,0 +1,17 @@
#version 120
#ifdef GL_ES
precision mediump float;
#endif
#extension GL_EXT_gpu_shader4 : enable
varying vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
void main(void) {
vec4 inColor = texture2D(u_texture, v_texCoords);
ivec4 bytes = ivec4(255.0 * inColor);
ivec4 mask = ivec4(0x55);
gl_FragColor = (bytes ^ mask) / 255.0;
}

Binary file not shown.

BIN
assets/graphics/halfgrad.tga LFS Normal file

Binary file not shown.

Binary file not shown.

View File

@@ -218,6 +218,7 @@ public class App implements ApplicationListener {
public static Texture ditherPattern; public static Texture ditherPattern;
private static ShaderProgram shaderBayerSkyboxFill; // ONLY to be used by the splash screen private static ShaderProgram shaderBayerSkyboxFill; // ONLY to be used by the splash screen
public static ShaderProgram shaderHicolour; public static ShaderProgram shaderHicolour;
public static ShaderProgram shaderDebugDiff;
public static ShaderProgram shaderPassthruRGB; public static ShaderProgram shaderPassthruRGB;
public static ShaderProgram shaderColLUT; public static ShaderProgram shaderColLUT;
public static ShaderProgram shaderReflect; public static ShaderProgram shaderReflect;
@@ -409,6 +410,7 @@ public class App implements ApplicationListener {
ditherPattern = new Texture(Gdx.files.internal("assets/LDR_512_RGBA_0.tga")); ditherPattern = new Texture(Gdx.files.internal("assets/LDR_512_RGBA_0.tga"));
shaderBayerSkyboxFill = loadShaderFromFile("assets/4096.vert", "assets/4096_bayer_skyboxfill.frag"); shaderBayerSkyboxFill = loadShaderFromFile("assets/4096.vert", "assets/4096_bayer_skyboxfill.frag");
shaderHicolour = loadShaderFromFile("assets/4096.vert", "assets/hicolour.frag"); shaderHicolour = loadShaderFromFile("assets/4096.vert", "assets/hicolour.frag");
shaderDebugDiff = loadShaderFromFile("assets/4096.vert", "assets/diff.frag");
shaderPassthruRGB = SpriteBatch.createDefaultShader(); shaderPassthruRGB = SpriteBatch.createDefaultShader();
shaderColLUT = loadShaderFromFile("assets/4096.vert", "assets/passthrurgb.frag"); shaderColLUT = loadShaderFromFile("assets/4096.vert", "assets/passthrurgb.frag");
shaderReflect = loadShaderFromFile("assets/4096.vert", "assets/reflect.frag"); shaderReflect = loadShaderFromFile("assets/4096.vert", "assets/reflect.frag");
@@ -713,6 +715,7 @@ public class App implements ApplicationListener {
ditherPattern.dispose(); ditherPattern.dispose();
shaderBayerSkyboxFill.dispose(); shaderBayerSkyboxFill.dispose();
shaderHicolour.dispose(); shaderHicolour.dispose();
shaderDebugDiff.dispose();
shaderPassthruRGB.dispose(); shaderPassthruRGB.dispose();
shaderColLUT.dispose(); shaderColLUT.dispose();
shaderReflect.dispose(); shaderReflect.dispose();

View File

@@ -131,6 +131,8 @@ object PostProcessor : Disposable {
val shader: ShaderProgram? = val shader: ShaderProgram? =
if (App.getConfigBoolean("fx_retro")) if (App.getConfigBoolean("fx_retro"))
App.shaderHicolour App.shaderHicolour
else if (App.getConfigBoolean("fx_differential"))
App.shaderDebugDiff
else else
App.shaderPassthruRGB App.shaderPassthruRGB

View File

@@ -183,7 +183,11 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
// load a half-gradient texture that would be used throughout the titlescreen and its sub UIs // load a half-gradient texture that would be used throughout the titlescreen and its sub UIs
CommonResourcePool.addToLoadingList("title_halfgrad") { Texture(Gdx.files.internal("./assets/graphics/halfgrad.png")) } CommonResourcePool.addToLoadingList("title_halfgrad") {
val t = Texture(Gdx.files.internal("./assets/graphics/halfgrad.tga"))
t.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
t
}
CommonResourcePool.loadAll() CommonResourcePool.loadAll()

View File

@@ -1,9 +1,13 @@
package net.torvald.terrarum package net.torvald.terrarum
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.GL20
import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.random.HQRNG
import net.torvald.terrarum.modulebasegame.IngameRenderer
import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
@@ -24,12 +28,31 @@ class UIFakeGradOverlay : UICanvas() {
private val tex = CommonResourcePool.getAsTexture("title_halfgrad") private val tex = CommonResourcePool.getAsTexture("title_halfgrad")
private val renderng = HQRNG()
init { init {
setAsAlwaysVisible() setAsAlwaysVisible()
} }
override fun updateUI(delta: Float) {} override fun updateUI(delta: Float) {}
override fun renderUI(batch: SpriteBatch, camera: Camera) { override fun renderUI(batch: SpriteBatch, camera: Camera) {
batch.end()
val dither = App.getConfigBoolean("fx_dither")
if (dither) {
IngameRenderer.ditherPattern.bind(1)
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it
}
batch.begin()
batch.shader = if (dither) IngameRenderer.shaderBayer else null
if (dither) {
batch.shader.setUniformi("u_pattern", 1)
batch.shader.setUniformi("rnd", renderng.nextInt(8192), renderng.nextInt(8192))
}
blendMul(batch) blendMul(batch)
batch.draw(tex, 0f, 0f, App.scr.wf, App.scr.hf) batch.draw(tex, 0f, 0f, App.scr.wf, App.scr.hf)

View File

@@ -25,12 +25,26 @@ private fun addFile(disk: VirtualDisk, file: DiskEntry) {
if (!dir.contains(file.entryID)) dir.add(file.entryID) if (!dir.contains(file.entryID)) dir.add(file.entryID)
} }
abstract class SavingThread(private val ingame: TerrarumIngame) : Runnable {
abstract fun save()
override fun run() {
try {
save()
}
catch (e: Throwable) {
e.printStackTrace()
ingame.uiAutosaveNotifier.setAsError()
}
}
}
/** /**
* Created by minjaesong on 2021-09-14. * Created by minjaesong on 2021-09-14.
*/ */
class WorldSavingThread(val disk: VirtualDisk, val outFile: File, val ingame: TerrarumIngame, val hasThumbnail: Boolean, val isAuto: Boolean, val callback: () -> Unit) : Runnable { class WorldSavingThread(val disk: VirtualDisk, val outFile: File, val ingame: TerrarumIngame, val hasThumbnail: Boolean, val isAuto: Boolean, val callback: () -> Unit) : SavingThread(ingame) {
override fun run() { override fun save() {
disk.saveMode = 2 * isAuto.toInt() // no quick disk.saveMode = 2 * isAuto.toInt() // no quick
@@ -40,8 +54,10 @@ class WorldSavingThread(val disk: VirtualDisk, val outFile: File, val ingame: Te
} }
} }
val playersList: List<IngamePlayer> = listOf(ingame.actorContainerActive, ingame.actorContainerInactive).flatMap{ it.filter { it is IngamePlayer } } as List<IngamePlayer> val allTheActors = ingame.actorContainerActive.cloneToList() + ingame.actorContainerInactive.cloneToList()
val actorsList = listOf(ingame.actorContainerActive, ingame.actorContainerInactive).flatMap { it.filter { WriteWorld.actorAcceptable(it) } }
val playersList: List<IngamePlayer> = allTheActors.filter{ it is IngamePlayer } as List<IngamePlayer>
val actorsList = allTheActors.filter { WriteWorld.actorAcceptable(it) }
val layers = intArrayOf(0,1).map { ingame.world.getLayer(it) } val layers = intArrayOf(0,1).map { ingame.world.getLayer(it) }
val cw = ingame.world.width / LandUtil.CHUNK_W val cw = ingame.world.width / LandUtil.CHUNK_W
val ch = ingame.world.height / LandUtil.CHUNK_H val ch = ingame.world.height / LandUtil.CHUNK_H
@@ -182,9 +198,9 @@ class WorldSavingThread(val disk: VirtualDisk, val outFile: File, val ingame: Te
* *
* Created by minjaesong on 2021-10-08 * Created by minjaesong on 2021-10-08
*/ */
class PlayerSavingThread(val disk: VirtualDisk, val outFile: File, val ingame: TerrarumIngame, val hasThumbnail: Boolean, val isAuto: Boolean, val callback: () -> Unit) : Runnable { class PlayerSavingThread(val disk: VirtualDisk, val outFile: File, val ingame: TerrarumIngame, val hasThumbnail: Boolean, val isAuto: Boolean, val callback: () -> Unit) : SavingThread(ingame) {
override fun run() { override fun save() {
disk.saveMode = 2 * isAuto.toInt() // no quick disk.saveMode = 2 * isAuto.toInt() // no quick
disk.capacity = 0L disk.capacity = 0L

View File

@@ -178,15 +178,16 @@ internal object WeatherMixer : RNGConsumer {
skyboxTexture.dispose() skyboxTexture.dispose()
skyboxTexture = Texture(skyboxPixmap); skyboxTexture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear) skyboxTexture = Texture(skyboxPixmap); skyboxTexture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
val dither = App.getConfigBoolean("fx_dither")
if (App.getConfigBoolean("fx_dither")) { if (dither) {
IngameRenderer.ditherPattern.bind(1) IngameRenderer.ditherPattern.bind(1)
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it
} }
batch.inUse { batch.inUse {
it.shader = if (App.getConfigBoolean("fx_dither")) IngameRenderer.shaderBayer else null it.shader = if (dither) IngameRenderer.shaderBayer else null
if (App.getConfigBoolean("fx_dither")) { if (dither) {
it.shader.setUniformi("u_pattern", 1) it.shader.setUniformi("u_pattern", 1)
it.shader.setUniformi("rnd", renderng.nextInt(8192), renderng.nextInt(8192)) it.shader.setUniformi("rnd", renderng.nextInt(8192), renderng.nextInt(8192))
} }