dither on lighting and blurring, with an option to turn them off

This commit is contained in:
minjaesong
2021-10-09 20:34:53 +09:00
parent d4f75c1bd5
commit d28698b668
10 changed files with 1000 additions and 36 deletions

View File

@@ -55,8 +55,6 @@ class UIFakeBlurOverlay(val blurRadius: Float, val nodarken: Boolean) : UICanvas
override var openCloseTime: Second = 0f
private val shaderBlur = App.loadShaderFromFile("assets/blur.vert", "assets/blur.frag")
private val darken = Color(0.5f, 0.5f, 0.5f, 1f)
override fun updateUI(delta: Float) {}
@@ -79,6 +77,5 @@ class UIFakeBlurOverlay(val blurRadius: Float, val nodarken: Boolean) : UICanvas
override fun endOpening(delta: Float) {}
override fun endClosing(delta: Float) {}
override fun dispose() {
shaderBlur.dispose()
}
}

View File

@@ -17,7 +17,6 @@ import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.gameparticles.ParticleBase
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.weather.WeatherMixer
import net.torvald.terrarum.worlddrawer.BlocksDrawer
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
@@ -30,6 +29,11 @@ import kotlin.system.exitProcess
* This will be rendered to a postprocessor FBO.
*
* For the entire render path, see AppLoader.
*
* NOTE: config "fx_dither" only controls the skybox (which is capable of having more than 256 colours
* thanks to the hardware linear intp.) because this dithering shader is somewhat heavy.
*
* Actors' transparency (and not an UI) still uses its own lightweight ditherrer
*/
object IngameRenderer : Disposable {
/** for non-private use, use with care! */
@@ -53,12 +57,26 @@ object IngameRenderer : Disposable {
// 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")
val shaderBlur: ShaderProgram
val shaderBayer: ShaderProgram
val shaderBlendGlow: ShaderProgram
get() = if (isDither()) shaderBlurDither else shaderBlurRaw
val shaderRGBOnly: ShaderProgram
get() = if (isDither()) shaderRGBOnlyDither else shaderRGBOnlyRaw
val shaderAtoGrey: ShaderProgram
get() = if (isDither()) shaderAtoGreyDither else shaderAtoGreyRaw
val shaderBlurDither: ShaderProgram
val shaderBlurRaw: ShaderProgram
val shaderRGBOnlyDither: ShaderProgram
val shaderRGBOnlyRaw: ShaderProgram
val shaderAtoGreyDither: ShaderProgram
val shaderAtoGreyRaw: ShaderProgram
val shaderBayer: ShaderProgram
val shaderPassthru = SpriteBatch.createDefaultShader()
val shaderBlendGlow: ShaderProgram
val shaderAlphaDither: ShaderProgram
private val WIDTH = App.scr.width
@@ -70,9 +88,7 @@ object IngameRenderer : Disposable {
private var player: ActorWithBody? = null
var uiListToDraw: List<UICanvas?> = arrayListOf()
const val lightmapDownsample = 4f //2f: still has choppy look when the camera moves but unnoticeable when blurred
const val lightmapDownsample = 1f//4f //2f: still has choppy look when the camera moves but unnoticeable when blurred
private var debugMode = 0
@@ -92,14 +108,18 @@ object IngameRenderer : Disposable {
// these codes will run regardless of the invocation of the "initialise()" function
// the "initialise()" function will also be called
init {
shaderBlur = App.loadShaderFromFile("assets/blur.vert", "assets/blur.frag")
shaderBlurDither = App.loadShaderFromFile("assets/blur.vert", "assets/blur_dither.frag")
shaderRGBOnlyDither = App.loadShaderFromFile("assets/4096.vert", "assets/4096_bayer_rgb1.frag")
shaderAtoGreyDither = App.loadShaderFromFile("assets/4096.vert", "assets/4096_bayer_aaa1.frag")
shaderBlurRaw = App.loadShaderFromFile("assets/blur.vert", "assets/blur.frag")
shaderRGBOnlyRaw = App.loadShaderFromFile("assets/4096.vert", "assets/rgbonly.frag")
shaderAtoGreyRaw = App.loadShaderFromFile("assets/4096.vert", "assets/aonly.frag")
shaderBayer = App.loadShaderFromFile("assets/4096.vert", "assets/4096_bayer.frag") // always load the shader regardless of config because the config may cange
shaderAlphaDither = App.loadShaderFromFile("assets/4096.vert", "assets/alphadither.frag")
shaderBlendGlow = App.loadShaderFromFile("assets/blendGlow.vert", "assets/blendGlow.frag")
shaderRGBOnly = App.loadShaderFromFile("assets/4096.vert", "assets/rgbonly.frag")
shaderAtoGrey = App.loadShaderFromFile("assets/4096.vert", "assets/aonly.frag")
if (!shaderBlendGlow.isCompiled) {
@@ -108,7 +128,7 @@ object IngameRenderer : Disposable {
}
if (App.getConfigBoolean("fx_dither")) {
if (isDither()) {
if (!shaderBayer.isCompiled) {
Gdx.app.log("shaderBayer", shaderBayer.log)
exitProcess(1)
@@ -402,7 +422,7 @@ object IngameRenderer : Disposable {
fboRGB.inAction(camera, batch) {
batch.inUse {
batch.shader = null
batch.shader = shaderAlphaDither
batch.color = Color.WHITE
}
@@ -421,7 +441,7 @@ object IngameRenderer : Disposable {
setCameraPosition(0f, 0f)
BlocksDrawer.drawTerrain(batch.projectionMatrix, false)
batch.shader = null
batch.shader = shaderAlphaDither
batch.inUse {
/////////////////
// draw actors //
@@ -498,7 +518,7 @@ object IngameRenderer : Disposable {
fboA.inAction(camera, batch) {
batch.inUse {
batch.shader = null
batch.shader = shaderAlphaDither
batch.color = Color.WHITE
}
@@ -566,7 +586,7 @@ object IngameRenderer : Disposable {
fboRGB_lightMixed.inAction(camera, batch) {
batch.inUse {
batch.shader = null
batch.shader = shaderAlphaDither
batch.color = Color.WHITE
}
@@ -746,11 +766,16 @@ object IngameRenderer : Disposable {
batch.dispose()
shaderBlur.dispose()
shaderBlurDither.dispose()
shaderBlurRaw.dispose()
shaderRGBOnlyDither.dispose()
shaderRGBOnlyRaw.dispose()
shaderAtoGreyDither.dispose()
shaderAtoGreyRaw.dispose()
shaderBayer.dispose()
shaderBlendGlow.dispose()
shaderRGBOnly.dispose()
shaderAtoGrey.dispose()
shaderPassthru.dispose()
shaderAlphaDither.dispose()

View File

@@ -7,6 +7,7 @@ import com.badlogic.gdx.graphics.Pixmap
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.graphics.glutils.ShaderProgram
import com.badlogic.gdx.utils.Disposable
import net.torvald.terrarum.App
import net.torvald.terrarum.CommonResourcePool
@@ -22,7 +23,9 @@ 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 shaderBlur: ShaderProgram
get() = if (IngameRenderer.isDither()) IngameRenderer.shaderBlurDither else IngameRenderer.shaderBlurRaw
val baloonTile = TextureRegionPack("assets/graphics/gui/message_black_tileable.tga", 36, 36, flipY = true)

View File

@@ -55,14 +55,13 @@ class UIAutosaveNotifier : UICanvas() {
val offX = (App.scr.tvSafeGraphicsWidth * 1.25f).roundToInt().toFloat()
val offY = App.scr.tvSafeGraphicsHeight + 9f // +9 to align to quickslot and watch UI
val text = if (errored) Lang["ERROR_GENERIC_TEXT"] else Lang["MENU_IO_SAVING"]
val text = if (errored) Lang["ERROR_GENERIC_TEXT"].replace(".","") else Lang["MENU_IO_SAVING"]
batch.color = if (errored) errorCol else normalCol
if (!errored) batch.draw(spin, offX, offY)// else RED_X_SYMBOL
App.fontGame.draw(batch, text, offX + 30f, offY)
}
fun setAsError() {
println("ugh, diddums")
errored = true
}