almost works but dae fucking jitter again

This commit is contained in:
minjaesong
2017-09-12 23:52:16 +09:00
parent 82ddfeb6ee
commit 7ffb417618
3 changed files with 72 additions and 58 deletions

View File

@@ -29,6 +29,8 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen {
var camera = OrthographicCamera(Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat()) var camera = OrthographicCamera(Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat())
private val processBlurBatch = SpriteBatch()
// invert Y // invert Y
fun initViewPort(width: Int, height: Int) { fun initViewPort(width: Int, height: Int) {
// Set Y to point downwards // Set Y to point downwards
@@ -100,8 +102,9 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen {
private val gradWhiteBottom = Color(0xd8d8d8ff.toInt()) private val gradWhiteBottom = Color(0xd8d8d8ff.toInt())
private val lightFBOformat = Pixmap.Format.RGB888 private val lightFBOformat = Pixmap.Format.RGB888
var lightmapFboA = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(Ingame.lightmapDownsample.toInt()), Terrarum.HEIGHT.div(Ingame.lightmapDownsample.toInt()), false) lateinit var lightmapFboA: FrameBuffer
var lightmapFboB = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(Ingame.lightmapDownsample.toInt()), Terrarum.HEIGHT.div(Ingame.lightmapDownsample.toInt()), false) lateinit var lightmapFboB: FrameBuffer
private var lightmapInitialised = false // to avoid nullability of lightmapFBO
lateinit var logo: TextureRegion lateinit var logo: TextureRegion
@@ -110,6 +113,9 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen {
private lateinit var worldFBO: FrameBuffer private lateinit var worldFBO: FrameBuffer
private val TILE_SIZE = FeaturesDrawer.TILE_SIZE
private val TILE_SIZEF = TILE_SIZE.toFloat()
private fun loadThingsWhileIntroIsVisible() { private fun loadThingsWhileIntroIsVisible() {
demoWorld = ReadLayerData(FileInputStream(ModMgr.getFile("basegame", "demoworld"))) demoWorld = ReadLayerData(FileInputStream(ModMgr.getFile("basegame", "demoworld")))
@@ -172,8 +178,6 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen {
worldFBO = FrameBuffer(Pixmap.Format.RGBA8888, Terrarum.WIDTH, Terrarum.HEIGHT, false) worldFBO = FrameBuffer(Pixmap.Format.RGBA8888, Terrarum.WIDTH, Terrarum.HEIGHT, false)
} }
private var blurWriteBuffer = lightmapFboA
private var blurReadBuffer = lightmapFboB
private val introUncoverTime: Second = 0.3f private val introUncoverTime: Second = 0.3f
private var introUncoverDeltaCounter = 0f private var introUncoverDeltaCounter = 0f
@@ -224,8 +228,7 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen {
fun renderScreen() { fun renderScreen() {
// render and blur lightmap processBlur(LightmapRendererNew.DRAW_FOR_RGB)
///////////processBlur(LightmapRendererNew.DRAW_FOR_RGB)
//camera.setToOrtho(true, Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat()) //camera.setToOrtho(true, Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat())
// render world // render world
@@ -291,24 +294,43 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen {
FeaturesDrawer.drawEnvOverlay(batch) FeaturesDrawer.drawEnvOverlay(batch)
///////////////////
// draw lightmap // // draw lightmap //
///////////////////
setCameraPosition(0f, 0f) setCameraPosition(0f, 0f)
//batch.shader = Terrarum.shaderBayer //batch.shader = Terrarum.shaderBayer
//batch.shader.setUniformf("rcount", 64f) //batch.shader.setUniformf("rcount", 64f)
//batch.shader.setUniformf("gcount", 64f) //batch.shader.setUniformf("gcount", 64f)
//batch.shader.setUniformf("bcount", 64f) // de-banding //batch.shader.setUniformf("bcount", 64f) // de-banding
//val lightTex = blurWriteBuffer.colorBufferTexture
//lightTex.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
//blendMul()
blendNormal()
batch.shader = null batch.shader = null
//processBlur(LightmapRendererNew.DRAW_FOR_RGB)
val lightTex = lightmapFboB.colorBufferTexture // A or B? flipped in Y means you chose wrong buffer; use one that works correctly
lightTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest) // blocky feeling for A E S T H E T I C S
blendMul()
batch.color = Color.WHITE batch.color = Color.WHITE
/*batch.draw(lightTex, val xrem = -(WorldCamera.x % TILE_SIZEF)
0f, 0f, val yrem = -(WorldCamera.y % TILE_SIZEF)
//lightTex.width * Ingame.lightmapDownsample, lightTex.height * Ingame.lightmapDownsample batch.draw(lightTex,
lightTex.width.toFloat(), lightTex.height.toFloat() if (xrem == 0f) -TILE_SIZEF else xrem,
)*/ if (yrem == 0f) -TILE_SIZEF else yrem,
LightmapRendererNew.draw(batch, LightmapRendererNew.DRAW_FOR_RGB) lightTex.width * Ingame.lightmapDownsample, lightTex.height * Ingame.lightmapDownsample
//lightTex.width.toFloat(), lightTex.height.toFloat() // for debugging
)
// FIXME dae fucking jitter
//////////////////////
// Draw other shits //
//////////////////////
batch.shader = null batch.shader = null
@@ -374,11 +396,23 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen {
uiMenu.setPosition(0, UITitleRemoConRoot.menubarOffY) uiMenu.setPosition(0, UITitleRemoConRoot.menubarOffY)
} }
lightmapFboA.dispose() if (lightmapInitialised) {
lightmapFboA = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(Ingame.lightmapDownsample.toInt()), Terrarum.HEIGHT.div(Ingame.lightmapDownsample.toInt()), false) lightmapFboA.dispose()
lightmapFboB.dispose() lightmapFboB.dispose()
lightmapFboB = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(Ingame.lightmapDownsample.toInt()), Terrarum.HEIGHT.div(Ingame.lightmapDownsample.toInt()), false) }
lightmapFboA = FrameBuffer(
lightFBOformat,
LightmapRendererNew.lightBuffer.width * LightmapRendererNew.DRAW_TILE_SIZE.toInt(),
LightmapRendererNew.lightBuffer.height * LightmapRendererNew.DRAW_TILE_SIZE.toInt(),
false
)
lightmapFboB = FrameBuffer(
lightFBOformat,
LightmapRendererNew.lightBuffer.width * LightmapRendererNew.DRAW_TILE_SIZE.toInt(),
LightmapRendererNew.lightBuffer.height * LightmapRendererNew.DRAW_TILE_SIZE.toInt(),
false
)
lightmapInitialised = true // are you the first time?
} }
override fun dispose() { override fun dispose() {
@@ -400,8 +434,8 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen {
val blurIterations = 5 // ideally, 4 * radius; must be even/odd number -- odd/even number will flip the image val blurIterations = 5 // ideally, 4 * radius; must be even/odd number -- odd/even number will flip the image
val blurRadius = 4f / Ingame.lightmapDownsample // (5, 4f); using low numbers for pixel-y aesthetics val blurRadius = 4f / Ingame.lightmapDownsample // (5, 4f); using low numbers for pixel-y aesthetics
blurWriteBuffer = lightmapFboA var blurWriteBuffer = lightmapFboA
blurReadBuffer = lightmapFboB var blurReadBuffer = lightmapFboB
lightmapFboA.inAction(null, null) { lightmapFboA.inAction(null, null) {
@@ -418,17 +452,7 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen {
// initialise readBuffer with untreated lightmap // initialise readBuffer with untreated lightmap
blurReadBuffer.inAction(camera, batch) { blurReadBuffer.inAction(camera, batch) {
batch.inUse { batch.inUse {
// using custom code for camera; this is obscure and tricky blendNormal(batch)
camera.position.set(
(WorldCamera.gdxCamX / Ingame.lightmapDownsample).round(),
(WorldCamera.gdxCamY / Ingame.lightmapDownsample).round(),
0f
) // make camara work
camera.update()
batch.projectionMatrix = camera.combined
blendNormal()
batch.color = Color.WHITE batch.color = Color.WHITE
LightmapRendererNew.draw(batch, LightmapRendererNew.DRAW_FOR_RGB) LightmapRendererNew.draw(batch, LightmapRendererNew.DRAW_FOR_RGB)
} }
@@ -438,17 +462,7 @@ class FuckingWorldRenderer(val batch: SpriteBatch) : Screen {
// initialise readBuffer with untreated lightmap // initialise readBuffer with untreated lightmap
blurReadBuffer.inAction(camera, batch) { blurReadBuffer.inAction(camera, batch) {
batch.inUse { batch.inUse {
// using custom code for camera; this is obscure and tricky blendNormal(batch)
camera.position.set(
(WorldCamera.gdxCamX / Ingame.lightmapDownsample).round(),
(WorldCamera.gdxCamY / Ingame.lightmapDownsample).round(),
0f
) // make camara work
camera.update()
batch.projectionMatrix = camera.combined
blendNormal()
batch.color = Color.WHITE batch.color = Color.WHITE
LightmapRendererNew.draw(batch, LightmapRendererNew.DRAW_FOR_ALPHA) LightmapRendererNew.draw(batch, LightmapRendererNew.DRAW_FOR_ALPHA)
} }

View File

@@ -773,21 +773,21 @@ infix fun Color.mul(other: Color): Color = this.cpy().mul(other)
fun blendMul() { fun blendMul(batch: SpriteBatch? = null) {
Terrarum.batch.enableBlending() (batch ?: Terrarum.batch).enableBlending()
Terrarum.batch.setBlendFunction(GL20.GL_DST_COLOR, GL20.GL_ONE_MINUS_SRC_ALPHA) (batch ?: Terrarum.batch).setBlendFunction(GL20.GL_DST_COLOR, GL20.GL_ONE_MINUS_SRC_ALPHA)
Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD) // batch.flush does not touch blend equation Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD) // batch.flush does not touch blend equation
} }
fun blendNormal() { fun blendNormal(batch: SpriteBatch? = null) {
Terrarum.batch.enableBlending() (batch ?: Terrarum.batch).enableBlending()
Terrarum.batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA) (batch ?: Terrarum.batch).setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)
Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD) // batch.flush does not touch blend equation Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD) // batch.flush does not touch blend equation
} }
fun blendScreen() { fun blendScreen(batch: SpriteBatch? = null) {
Terrarum.batch.enableBlending() (batch ?: Terrarum.batch).enableBlending()
Terrarum.batch.setBlendFunction(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_COLOR) (batch ?: Terrarum.batch).setBlendFunction(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_COLOR)
Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD) // batch.flush does not touch blend equation Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD) // batch.flush does not touch blend equation
} }

View File

@@ -56,7 +56,7 @@ object LightmapRendererNew {
private val AIR = Block.AIR private val AIR = Block.AIR
private const val TILE_SIZE = FeaturesDrawer.TILE_SIZE private const val TILE_SIZE = FeaturesDrawer.TILE_SIZE
private val DRAW_TILE_SIZE: Float = FeaturesDrawer.TILE_SIZE / Ingame.lightmapDownsample val DRAW_TILE_SIZE: Float = FeaturesDrawer.TILE_SIZE / Ingame.lightmapDownsample
// color model related constants // color model related constants
const val MUL = 1024 // modify this to 1024 to implement 30-bit RGB const val MUL = 1024 // modify this to 1024 to implement 30-bit RGB
@@ -366,8 +366,8 @@ object LightmapRendererNew {
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me
// we might not need shader here... // we might not need shader here...
batch.draw(lightBufferAsTex, 0f, 0f, lightBufferAsTex.width.toFloat(), lightBufferAsTex.height.toFloat()) //batch.draw(lightBufferAsTex, 0f, 0f, lightBufferAsTex.width.toFloat(), lightBufferAsTex.height.toFloat())
//batch.draw(lightBufferAsTex, 0f, 0f, lightBufferAsTex.width * DRAW_TILE_SIZE, lightBufferAsTex.height * TILE_SIZE.toFloat()) batch.draw(lightBufferAsTex, 0f, 0f, lightBufferAsTex.width * DRAW_TILE_SIZE, lightBufferAsTex.height * DRAW_TILE_SIZE)
//lightBufferAsTex.dispose() //lightBufferAsTex.dispose()