mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 18:44:05 +09:00
better implementation of dithering which relies on external texture and it runs faster
This commit is contained in:
@@ -55,6 +55,13 @@ 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")
|
||||
@@ -469,6 +476,9 @@ object IngameRenderer : Disposable {
|
||||
|
||||
gdxSetBlend()
|
||||
|
||||
ditherPattern.bind(1)
|
||||
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it
|
||||
|
||||
batch.inUse {
|
||||
|
||||
blendNormal(batch)
|
||||
@@ -486,6 +496,7 @@ object IngameRenderer : Disposable {
|
||||
blendMul(batch)
|
||||
|
||||
batch.shader = shaderRGBOnly
|
||||
batch.shader.setUniformi("u_pattern", 1)
|
||||
batch.draw(lightTex,
|
||||
xrem, yrem,
|
||||
lightTex.regionWidth * lightmapDownsample,
|
||||
@@ -553,6 +564,9 @@ object IngameRenderer : Disposable {
|
||||
setCameraPosition(0f, 0f)
|
||||
val (xrem, yrem) = worldCamToRenderPos()
|
||||
|
||||
ditherPattern.bind(1)
|
||||
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it
|
||||
|
||||
batch.inUse {
|
||||
// draw world
|
||||
batch.draw(fboA.colorBufferTexture, 0f, 0f)
|
||||
@@ -567,6 +581,7 @@ object IngameRenderer : Disposable {
|
||||
blendMul(batch)
|
||||
|
||||
batch.shader = shaderAtoGrey
|
||||
batch.shader.setUniformi("u_pattern", 1)
|
||||
batch.draw(lightTex,
|
||||
xrem, yrem,
|
||||
lightTex.regionWidth * lightmapDownsample,
|
||||
@@ -664,12 +679,15 @@ object IngameRenderer : Disposable {
|
||||
|
||||
blurWriteBuffer.inAction(camera, batch) {
|
||||
|
||||
|
||||
blurTex.texture = blurReadBuffer.colorBufferTexture
|
||||
blurTex.texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
|
||||
blurTex.texture.bind(0)
|
||||
ditherPattern.bind(1) // order is important!
|
||||
|
||||
shaderBlur.bind()
|
||||
shaderBlur.setUniformMatrix("u_projTrans", camera.combined)
|
||||
shaderBlur.setUniformi("u_pattern", 1)
|
||||
shaderBlur.setUniformi("u_texture", 0)
|
||||
shaderBlur.setUniformf("iResolution",
|
||||
blurWriteBuffer.width.toFloat(), blurWriteBuffer.height.toFloat())
|
||||
|
||||
@@ -3,20 +3,18 @@ package net.torvald.terrarum.modulebasegame.gameactors
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.gdx.graphics.Cvec
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.spriteanimation.SpriteAnimation
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.BlockCodex
|
||||
import net.torvald.terrarum.CommonResourcePool
|
||||
import net.torvald.terrarum.ModMgr
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameactors.Hitbox
|
||||
import net.torvald.terrarum.gameactors.Luminous
|
||||
import net.torvald.terrarum.gameparticles.ParticleVanishingSprite
|
||||
import net.torvald.terrarum.gameparticles.ParticleVanishingText
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import java.util.*
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-06-17.
|
||||
@@ -45,7 +43,7 @@ internal class FixtureTikiTorch : FixtureBase, Luminous {
|
||||
TextureRegionPack(ModMgr.getGdxFile("basegame", "sprites/fixtures/tiki_torch.tga"), 16, 32)
|
||||
}
|
||||
CommonResourcePool.addToLoadingList("particles-tiki_smoke.tga") {
|
||||
TextureRegionPack(ModMgr.getGdxFile("basegame", "particles/tiki_smoke.tga"), 10, 10)
|
||||
TextureRegionPack(ModMgr.getGdxFile("basegame", "particles/bigger_smoke.tga"), 16, 16)
|
||||
}
|
||||
CommonResourcePool.loadAll()
|
||||
|
||||
@@ -70,7 +68,7 @@ internal class FixtureTikiTorch : FixtureBase, Luminous {
|
||||
if (spawnTimer >= nextDelay) {
|
||||
(Terrarum.ingame as TerrarumIngame).addParticle(ParticleVanishingSprite(
|
||||
CommonResourcePool.getAsTextureRegionPack("particles-tiki_smoke.tga"),
|
||||
0.25f, true, hitbox.centeredX, hitbox.startY, false, rng.nextInt(256)
|
||||
25f, true, hitbox.centeredX, hitbox.startY, false, rng.nextInt(256)
|
||||
))
|
||||
|
||||
spawnTimer -= nextDelay
|
||||
|
||||
Reference in New Issue
Block a user