lightmap downsample works, sampling bug fixed with Filter.NEAREST, now having shrinkage issue

This commit is contained in:
minjaesong
2017-07-12 14:33:59 +09:00
parent 448c5f0fca
commit ed5997d5b4
5 changed files with 34 additions and 22 deletions

View File

@@ -74,7 +74,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
val ZOOM_MINIMUM = 0.5f
companion object {
val lightmapDownsample = 1f
val lightmapDownsample = 2f //2f: still has choppy look when the camera moves but unnoticeable when blurred
}
@@ -488,10 +488,6 @@ class Ingame(val batch: SpriteBatch) : Screen {
///////////////////
// blur lightmap //
///////////////////
worldDrawFrameBuffer.inAction(null, null) {
Gdx.gl.glClearColor(0f,0f,0f,0f)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
@@ -524,9 +520,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
BlocksDrawer.renderWall(batch)
actorsRenderBehind.forEach { it.drawBody(batch) }
actorsRenderBehind.forEach { it.drawGlow(batch) }
particlesContainer.forEach { it.drawBody(batch) }
particlesContainer.forEach { it.drawGlow(batch) }
BlocksDrawer.renderTerrain(batch)
/////////////////
@@ -604,7 +598,9 @@ class Ingame(val batch: SpriteBatch) : Screen {
//////////////////////
// draw actor glows //
//////////////////////
actorsRenderBehind.forEach { it.drawGlow(batch) }
particlesContainer.forEach { it.drawGlow(batch) }
actorsRenderMiddle.forEach { it.drawGlow(batch) }
actorsRenderMidTop.forEach { it.drawGlow(batch) }
player?.drawGlow(batch)
@@ -645,6 +641,9 @@ class Ingame(val batch: SpriteBatch) : Screen {
val worldTex = worldDrawFrameBuffer.colorBufferTexture // WORLD: light_color must be applied beforehand
val glowTex = worldGlowFrameBuffer.colorBufferTexture // GLOW: light_uvlight must be applied beforehand
worldTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
glowTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
//Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0)
worldTex.bind(0)
glowTex.bind(1)
@@ -702,6 +701,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
val blendedTex = worldBlendFrameBuffer.colorBufferTexture
blendedTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
batch.color = Color.WHITE
batch.shader = null
blendNormal()
@@ -1454,15 +1454,15 @@ class Ingame(val batch: SpriteBatch) : Screen {
*/
override fun resize(width: Int, height: Int) {
worldDrawFrameBuffer.dispose()
worldDrawFrameBuffer = FrameBuffer(worldFBOformat, width, height, true)
worldDrawFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, true)
worldGlowFrameBuffer.dispose()
worldGlowFrameBuffer = FrameBuffer(worldFBOformat, width, height, true)
worldGlowFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, true)
worldBlendFrameBuffer.dispose()
worldBlendFrameBuffer = FrameBuffer(worldFBOformat, width, height, true)
worldBlendFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, true)
lightmapFboA.dispose()
lightmapFboA = FrameBuffer(lightFBOformat, width.div(lightmapDownsample.toInt()), height.div(lightmapDownsample.toInt()), true)
lightmapFboA = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), true)
lightmapFboB.dispose()
lightmapFboB = FrameBuffer(lightFBOformat, width.div(lightmapDownsample.toInt()), height.div(lightmapDownsample.toInt()), true)
lightmapFboB = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), true)
//lightmapUvFboA.dispose()
//lightmapUvFboA = FrameBuffer(lightUvFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), true)
//lightmapUvFboB.dispose()

View File

@@ -247,6 +247,9 @@ object Terrarum : ApplicationAdapter() {
lateinit var shaderBlendGlow: ShaderProgram
lateinit var textureWhiteSquare: Texture
init {
println("[Terrarum] os.arch = $systemArch") // debug info
@@ -299,6 +302,10 @@ object Terrarum : ApplicationAdapter() {
fontSmallNumbers = TinyAlphNum
textureWhiteSquare = Texture(Gdx.files.internal("assets/graphics/ortho_line_tex_2px.tga"))
textureWhiteSquare.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
ShaderProgram.pedantic = false
shaderBlur = ShaderProgram(Gdx.files.internal("assets/blur.vert"), Gdx.files.internal("assets/blur.frag"))
shader4096 = ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/4096.frag"))
@@ -567,7 +574,7 @@ fun Float.round(): Float {
// ShapeRenderer alternative for rects
fun SpriteBatch.fillRect(x: Float, y: Float, w: Float, h: Float) {
this.draw(net.torvald.terrarum.worlddrawer.BlocksDrawer.tilesTerrain.get(1, 0), x, y, w, h)
this.draw(Terrarum.textureWhiteSquare, x, y, w, h)
}
inline fun SpriteBatch.drawStraightLine(x: Float, y: Float, p2: Float, thickness: Float, isVertical: Boolean) {
if (!isVertical)

View File

@@ -86,7 +86,9 @@ object BlocksDrawer {
gzTmpFName.forEach { File(it).delete() }
tilesTerrain = TextureRegionPack(Texture(terrainPixMap), TILE_SIZE, TILE_SIZE)
tilesTerrain.texture.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
tilesWire = TextureRegionPack(Texture(wirePixMap), TILE_SIZE, TILE_SIZE)
tilesWire.texture.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
// also dispose unused temp files
//terrainPixMap.dispose() // commented: tileItemWall needs it

View File

@@ -381,11 +381,12 @@ object LightmapRenderer {
batch.color = (getLightForOpaque(x, y) ?: Color(0f,0f,0f,0f)).normaliseToAlphaHDR()
}
batch.fillRect(
(x * DRAW_TILE_SIZE).round().toFloat(),
(y * DRAW_TILE_SIZE).round().toFloat(),
DRAW_TILE_SIZE.ceil() * sameLevelCounter + 1f,
DRAW_TILE_SIZE.ceil() + 1f
x * DRAW_TILE_SIZE,
y * DRAW_TILE_SIZE,
(DRAW_TILE_SIZE * sameLevelCounter).ceil().toFloat(),// + 1f,
DRAW_TILE_SIZE.ceil().toFloat()// + 1f
)
x += sameLevelCounter - 1

View File

@@ -2,6 +2,8 @@ package net.torvald.terrarum.worlddrawer
import com.jme3.math.FastMath
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.floor
import net.torvald.terrarum.gameactors.floorInt
import net.torvald.terrarum.gameactors.roundInt
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.round
@@ -40,16 +42,16 @@ object WorldCamera {
// position - (WH / 2)
x = (// X only: ROUNDWORLD implementation
(player?.hitbox?.centeredX?.toFloat() ?: 0f) - width / 2).roundInt()
(player?.hitbox?.centeredX?.toFloat() ?: 0f) - width / 2).floorInt()
y = (FastMath.clamp(
(player?.hitbox?.centeredY?.toFloat() ?: 0f) - height / 2,
TILE_SIZE.toFloat(),
world!!.height * TILE_SIZE - height - TILE_SIZE.toFloat()
)).roundInt()
)).floorInt()
gdxCamX = x + (width / 2f).round()
gdxCamY = y + (height / 2f).round()
gdxCamX = x + (width / 2f).floor()
gdxCamY = y + (height / 2f).floor()
}
}
}