new dithering shaders

This commit is contained in:
minjaesong
2021-10-06 11:13:44 +09:00
parent 2c6dc8750a
commit fb13922ad9
11 changed files with 235 additions and 123 deletions

View File

@@ -32,6 +32,7 @@ import net.torvald.terrarum.modulebasegame.TerrarumIngame;
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory;
import net.torvald.terrarum.serialise.WriteConfig;
import net.torvald.terrarum.tvda.DiskSkimmer;
import net.torvald.terrarum.ui.Toolkit;
import net.torvald.terrarum.utils.JsonFetcher;
import net.torvald.terrarum.worlddrawer.CreateTileAtlas;
import net.torvald.terrarumsansbitmap.gdx.GameFontBase;
@@ -591,8 +592,9 @@ public class App implements ApplicationListener {
setCameraPosition(0f, 0f);
int drawWidth = Toolkit.INSTANCE.getDrawWidth();
int safetyTextLen = fontGame.getWidth(Lang.INSTANCE.get("APP_WARNING_HEALTH_AND_SAFETY", true));
int logoPosX = (scr.getWidth() - logo.getRegionWidth() - safetyTextLen) >>> 1;
int logoPosX = (drawWidth - logo.getRegionWidth() - safetyTextLen) >>> 1;
int logoPosY = Math.round(scr.getHeight() / 15f);
int textY = logoPosY + logo.getRegionHeight() - 16;
@@ -605,7 +607,7 @@ public class App implements ApplicationListener {
logoBatch.draw(logo, logoPosX, logoPosY + logo.getRegionHeight());
}
else {
logoBatch.draw(logo, (scr.getWidth() - logo.getRegionWidth()) / 2f,
logoBatch.draw(logo, (drawWidth - logo.getRegionWidth()) / 2f,
(scr.getHeight() - logo.getRegionHeight() * 2) / 2f + logo.getRegionHeight()
);
}
@@ -631,7 +633,7 @@ public class App implements ApplicationListener {
String s = Lang.INSTANCE.get("APP_CHINESE_HEALTHY_GAME_MSG_" + i, true);
fontGame.draw(logoBatch, s,
(scr.getWidth() - fontGame.getWidth(s)) >>> 1,
(drawWidth - fontGame.getWidth(s)) >>> 1,
Math.round(scr.getHeight() * 12f / 15f + fontGame.getLineHeight() * (i - 1))
);
}
@@ -642,12 +644,12 @@ public class App implements ApplicationListener {
Texture tex2 = CommonResourcePool.INSTANCE.getAsTexture("title_health2");
int virtualHeight = scr.getHeight() - logoPosY - logo.getRegionHeight() / 4;
int virtualHeightOffset = scr.getHeight() - virtualHeight;
logoBatch.draw(tex1, (scr.getWidth() - tex1.getWidth()) >>> 1, virtualHeightOffset + (virtualHeight >>> 1) - 16, tex1.getWidth(), -tex1.getHeight());
logoBatch.draw(tex2, (scr.getWidth() - tex2.getWidth()) >>> 1, virtualHeightOffset + (virtualHeight >>> 1) + 16 + tex2.getHeight(), tex2.getWidth(), -tex2.getHeight());
logoBatch.draw(tex1, (drawWidth - tex1.getWidth()) >>> 1, virtualHeightOffset + (virtualHeight >>> 1) - 16, tex1.getWidth(), -tex1.getHeight());
logoBatch.draw(tex2, (drawWidth - tex2.getWidth()) >>> 1, virtualHeightOffset + (virtualHeight >>> 1) + 16 + tex2.getHeight(), tex2.getWidth(), -tex2.getHeight());
}
else {
logoBatch.draw(logo, (scr.getWidth() - logo.getRegionWidth()) / 2f,
logoBatch.draw(logo, (drawWidth - logo.getRegionWidth()) / 2f,
(scr.getHeight() - logo.getRegionHeight() * 2) / 2f
);
}

View File

@@ -17,8 +17,8 @@ class ChunkLoadingLoadScreen(screenToBeLoaded: IngameInstance, private val world
private val world: GameWorld // must use Getter, as the field WILL BE redefined by the TerrarumIngame.enterCreateNewWorld() !
get() = screenToLoad!!.world
private var previewWidth = (App.scr.width * WorldgenLoadScreen.WIDTH_RATIO).roundToInt()
private var previewHeight = (App.scr.width * WorldgenLoadScreen.WIDTH_RATIO * worldheight / worldwidth).roundToInt()
private var previewWidth = (Toolkit.drawWidth * WorldgenLoadScreen.WIDTH_RATIO).roundToInt()
private var previewHeight = (Toolkit.drawWidth * WorldgenLoadScreen.WIDTH_RATIO * worldheight / worldwidth).roundToInt()
private lateinit var previewPixmap: Pixmap
private lateinit var previewTexture: Texture
@@ -40,6 +40,7 @@ class ChunkLoadingLoadScreen(screenToBeLoaded: IngameInstance, private val world
override fun render(delta: Float) {
gdxClearAndSetBlend(.094f, .094f, .094f, 0f)
val drawWidth = Toolkit.drawWidth
if (worldwidth != -1 && worldheight != -1) {
@@ -54,7 +55,7 @@ class ChunkLoadingLoadScreen(screenToBeLoaded: IngameInstance, private val world
App.batch.inUse {
it.color = Color.WHITE
val previewX = (App.scr.width - previewWidth).div(2f).round()
val previewX = (drawWidth - previewWidth).div(2f).round()
val previewY = (App.scr.height - previewHeight.times(1.5f)).div(2f).round()
Toolkit.drawBoxBorder(it, previewX.toInt() - 1, previewY.toInt() - 1, previewWidth + 2, previewHeight + 2)
it.draw(previewTexture,
@@ -64,7 +65,7 @@ class ChunkLoadingLoadScreen(screenToBeLoaded: IngameInstance, private val world
val text = messages.getHeadElem() ?: ""
App.fontGame.draw(it,
text,
(App.scr.width - App.fontGame.getWidth(text)).div(2f).round(),
(drawWidth - App.fontGame.getWidth(text)).div(2f).round(),
previewY + previewHeight + 98 - App.fontGame.lineHeight
)
}

View File

@@ -57,6 +57,7 @@ object IngameRenderer : Disposable {
val shaderRGBOnly: ShaderProgram
val shaderAtoGrey: ShaderProgram
val shaderPassthru = SpriteBatch.createDefaultShader()
val shaderAlphaDither: ShaderProgram
private val WIDTH = App.scr.width
private val HEIGHT = App.scr.height
@@ -98,11 +99,13 @@ object IngameRenderer : Disposable {
shaderBayer.setUniformf("rcount", 64f)
shaderBayer.setUniformf("gcount", 64f)
shaderBayer.setUniformf("bcount", 64f)
}
else {
shaderBayer = App.loadShaderFromFile("assets/4096.vert", "assets/passthrurgb.frag")
}
shaderAlphaDither = App.loadShaderFromFile("assets/4096.vert", "assets/alphadither.frag")
shaderBlendGlow = App.loadShaderFromFile("assets/blendGlow.vert", "assets/blendGlow.frag")
@@ -406,12 +409,16 @@ object IngameRenderer : Disposable {
batch.inUse {
moveCameraToWorldCoord()
actorsRenderBehind?.forEach { it.drawBody(batch) }
}
batch.shader = shaderAlphaDither
batch.inUse {
particlesContainer?.forEach { it.drawBody(batch) }
}
setCameraPosition(0f, 0f)
BlocksDrawer.drawTerrain(batch.projectionMatrix, false)
batch.shader = null
batch.inUse {
/////////////////
// draw actors //
@@ -739,6 +746,7 @@ object IngameRenderer : Disposable {
shaderRGBOnly.dispose()
shaderAtoGrey.dispose()
shaderPassthru.dispose()
shaderAlphaDither.dispose()
try {
fboRGBexport.dispose()

View File

@@ -34,8 +34,8 @@ class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, private val worldwidt
val COL_AIR = Color.BLACK
}
private val previewWidth = (App.scr.width * WIDTH_RATIO).roundToInt()
private val previewHeight = (App.scr.width * WIDTH_RATIO * worldheight / worldwidth).roundToInt()
private val previewWidth = (Toolkit.drawWidth * WIDTH_RATIO).roundToInt()
private val previewHeight = (Toolkit.drawWidth * WIDTH_RATIO * worldheight / worldwidth).roundToInt()
private lateinit var previewPixmap: Pixmap
private lateinit var previewTexture: Texture
@@ -57,6 +57,8 @@ class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, private val worldwidt
override fun render(delta: Float) {
gdxClearAndSetBlend(.094f, .094f, .094f, 0f)
val drawWidth = Toolkit.drawWidth
previewRenderCounter += delta
if (previewRenderCounter >= PREVIEW_UPDATE_RATE) {
previewRenderCounter -= PREVIEW_UPDATE_RATE
@@ -68,7 +70,7 @@ class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, private val worldwidt
App.batch.inUse {
it.color = Color.WHITE
val previewX = (App.scr.width - previewWidth).div(2f).round()
val previewX = (drawWidth - previewWidth).div(2f).round()
val previewY = (App.scr.height - previewHeight.times(1.5f)).div(2f).round()
Toolkit.drawBoxBorder(it, previewX.toInt()-1, previewY.toInt()-1, previewWidth+2, previewHeight+2)
it.draw(previewTexture,
@@ -78,7 +80,7 @@ class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, private val worldwidt
val text = messages.getHeadElem() ?: ""
App.fontGame.draw(it,
text,
(App.scr.width - App.fontGame.getWidth(text)).div(2f).round(),
(drawWidth - App.fontGame.getWidth(text)).div(2f).round(),
previewY + previewHeight + 98 - App.fontGame.lineHeight
)
}

View File

@@ -0,0 +1,18 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.App
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
/**
* Created by minjaesong on 2021-10-06.
*/
object StreamerMode : ConsoleCommand {
override fun execute(args: Array<String>) {
App.setConfig("fx_streamerslayout", !App.getConfigBoolean("fx_streamerslayout"))
}
override fun printUsage() {
Echo("Toggles Streamer Mode")
}
}

View File

@@ -23,7 +23,7 @@ object Toolkit : Disposable {
val DEFAULT_BOX_BORDER_COL = Color(1f, 1f, 1f, 0.2f)
private val shaderBlur = App.loadShaderFromFile("assets/blur.vert", "assets/blur2.frag")
val baloonTile = TextureRegionPack("assets/graphics/gui/message_black_tileable.tga", 36, 36)
val baloonTile = TextureRegionPack("assets/graphics/gui/message_black_tileable.tga", 36, 36, flipY = true)
init {