mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 11:34:05 +09:00
lightmap downsample works, sampling bug fixed with Filter.NEAREST, now having shrinkage issue
This commit is contained in:
@@ -74,7 +74,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
|||||||
val ZOOM_MINIMUM = 0.5f
|
val ZOOM_MINIMUM = 0.5f
|
||||||
|
|
||||||
companion object {
|
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) {
|
worldDrawFrameBuffer.inAction(null, null) {
|
||||||
Gdx.gl.glClearColor(0f,0f,0f,0f)
|
Gdx.gl.glClearColor(0f,0f,0f,0f)
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
|
||||||
@@ -524,9 +520,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
|||||||
|
|
||||||
BlocksDrawer.renderWall(batch)
|
BlocksDrawer.renderWall(batch)
|
||||||
actorsRenderBehind.forEach { it.drawBody(batch) }
|
actorsRenderBehind.forEach { it.drawBody(batch) }
|
||||||
actorsRenderBehind.forEach { it.drawGlow(batch) }
|
|
||||||
particlesContainer.forEach { it.drawBody(batch) }
|
particlesContainer.forEach { it.drawBody(batch) }
|
||||||
particlesContainer.forEach { it.drawGlow(batch) }
|
|
||||||
BlocksDrawer.renderTerrain(batch)
|
BlocksDrawer.renderTerrain(batch)
|
||||||
|
|
||||||
/////////////////
|
/////////////////
|
||||||
@@ -604,7 +598,9 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
|||||||
//////////////////////
|
//////////////////////
|
||||||
// draw actor glows //
|
// draw actor glows //
|
||||||
//////////////////////
|
//////////////////////
|
||||||
|
|
||||||
|
actorsRenderBehind.forEach { it.drawGlow(batch) }
|
||||||
|
particlesContainer.forEach { it.drawGlow(batch) }
|
||||||
actorsRenderMiddle.forEach { it.drawGlow(batch) }
|
actorsRenderMiddle.forEach { it.drawGlow(batch) }
|
||||||
actorsRenderMidTop.forEach { it.drawGlow(batch) }
|
actorsRenderMidTop.forEach { it.drawGlow(batch) }
|
||||||
player?.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 worldTex = worldDrawFrameBuffer.colorBufferTexture // WORLD: light_color must be applied beforehand
|
||||||
val glowTex = worldGlowFrameBuffer.colorBufferTexture // GLOW: light_uvlight 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)
|
//Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0)
|
||||||
worldTex.bind(0)
|
worldTex.bind(0)
|
||||||
glowTex.bind(1)
|
glowTex.bind(1)
|
||||||
@@ -702,6 +701,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
|||||||
|
|
||||||
|
|
||||||
val blendedTex = worldBlendFrameBuffer.colorBufferTexture
|
val blendedTex = worldBlendFrameBuffer.colorBufferTexture
|
||||||
|
blendedTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
batch.shader = null
|
batch.shader = null
|
||||||
blendNormal()
|
blendNormal()
|
||||||
@@ -1454,15 +1454,15 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
|||||||
*/
|
*/
|
||||||
override fun resize(width: Int, height: Int) {
|
override fun resize(width: Int, height: Int) {
|
||||||
worldDrawFrameBuffer.dispose()
|
worldDrawFrameBuffer.dispose()
|
||||||
worldDrawFrameBuffer = FrameBuffer(worldFBOformat, width, height, true)
|
worldDrawFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, true)
|
||||||
worldGlowFrameBuffer.dispose()
|
worldGlowFrameBuffer.dispose()
|
||||||
worldGlowFrameBuffer = FrameBuffer(worldFBOformat, width, height, true)
|
worldGlowFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, true)
|
||||||
worldBlendFrameBuffer.dispose()
|
worldBlendFrameBuffer.dispose()
|
||||||
worldBlendFrameBuffer = FrameBuffer(worldFBOformat, width, height, true)
|
worldBlendFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, true)
|
||||||
lightmapFboA.dispose()
|
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.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.dispose()
|
||||||
//lightmapUvFboA = FrameBuffer(lightUvFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), true)
|
//lightmapUvFboA = FrameBuffer(lightUvFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), true)
|
||||||
//lightmapUvFboB.dispose()
|
//lightmapUvFboB.dispose()
|
||||||
|
|||||||
@@ -247,6 +247,9 @@ object Terrarum : ApplicationAdapter() {
|
|||||||
lateinit var shaderBlendGlow: ShaderProgram
|
lateinit var shaderBlendGlow: ShaderProgram
|
||||||
|
|
||||||
|
|
||||||
|
lateinit var textureWhiteSquare: Texture
|
||||||
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
println("[Terrarum] os.arch = $systemArch") // debug info
|
println("[Terrarum] os.arch = $systemArch") // debug info
|
||||||
|
|
||||||
@@ -299,6 +302,10 @@ object Terrarum : ApplicationAdapter() {
|
|||||||
fontSmallNumbers = TinyAlphNum
|
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
|
ShaderProgram.pedantic = false
|
||||||
shaderBlur = ShaderProgram(Gdx.files.internal("assets/blur.vert"), Gdx.files.internal("assets/blur.frag"))
|
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"))
|
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
|
// ShapeRenderer alternative for rects
|
||||||
fun SpriteBatch.fillRect(x: Float, y: Float, w: Float, h: Float) {
|
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) {
|
inline fun SpriteBatch.drawStraightLine(x: Float, y: Float, p2: Float, thickness: Float, isVertical: Boolean) {
|
||||||
if (!isVertical)
|
if (!isVertical)
|
||||||
|
|||||||
@@ -86,7 +86,9 @@ object BlocksDrawer {
|
|||||||
gzTmpFName.forEach { File(it).delete() }
|
gzTmpFName.forEach { File(it).delete() }
|
||||||
|
|
||||||
tilesTerrain = TextureRegionPack(Texture(terrainPixMap), TILE_SIZE, TILE_SIZE)
|
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 = TextureRegionPack(Texture(wirePixMap), TILE_SIZE, TILE_SIZE)
|
||||||
|
tilesWire.texture.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
||||||
|
|
||||||
// also dispose unused temp files
|
// also dispose unused temp files
|
||||||
//terrainPixMap.dispose() // commented: tileItemWall needs it
|
//terrainPixMap.dispose() // commented: tileItemWall needs it
|
||||||
|
|||||||
@@ -381,11 +381,12 @@ object LightmapRenderer {
|
|||||||
batch.color = (getLightForOpaque(x, y) ?: Color(0f,0f,0f,0f)).normaliseToAlphaHDR()
|
batch.color = (getLightForOpaque(x, y) ?: Color(0f,0f,0f,0f)).normaliseToAlphaHDR()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
batch.fillRect(
|
batch.fillRect(
|
||||||
(x * DRAW_TILE_SIZE).round().toFloat(),
|
x * DRAW_TILE_SIZE,
|
||||||
(y * DRAW_TILE_SIZE).round().toFloat(),
|
y * DRAW_TILE_SIZE,
|
||||||
DRAW_TILE_SIZE.ceil() * sameLevelCounter + 1f,
|
(DRAW_TILE_SIZE * sameLevelCounter).ceil().toFloat(),// + 1f,
|
||||||
DRAW_TILE_SIZE.ceil() + 1f
|
DRAW_TILE_SIZE.ceil().toFloat()// + 1f
|
||||||
)
|
)
|
||||||
|
|
||||||
x += sameLevelCounter - 1
|
x += sameLevelCounter - 1
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package net.torvald.terrarum.worlddrawer
|
|||||||
|
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.terrarum.Terrarum
|
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.gameactors.roundInt
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
import net.torvald.terrarum.round
|
import net.torvald.terrarum.round
|
||||||
@@ -40,16 +42,16 @@ object WorldCamera {
|
|||||||
|
|
||||||
// position - (WH / 2)
|
// position - (WH / 2)
|
||||||
x = (// X only: ROUNDWORLD implementation
|
x = (// X only: ROUNDWORLD implementation
|
||||||
(player?.hitbox?.centeredX?.toFloat() ?: 0f) - width / 2).roundInt()
|
(player?.hitbox?.centeredX?.toFloat() ?: 0f) - width / 2).floorInt()
|
||||||
y = (FastMath.clamp(
|
y = (FastMath.clamp(
|
||||||
(player?.hitbox?.centeredY?.toFloat() ?: 0f) - height / 2,
|
(player?.hitbox?.centeredY?.toFloat() ?: 0f) - height / 2,
|
||||||
TILE_SIZE.toFloat(),
|
TILE_SIZE.toFloat(),
|
||||||
world!!.height * TILE_SIZE - height - TILE_SIZE.toFloat()
|
world!!.height * TILE_SIZE - height - TILE_SIZE.toFloat()
|
||||||
)).roundInt()
|
)).floorInt()
|
||||||
|
|
||||||
|
|
||||||
gdxCamX = x + (width / 2f).round()
|
gdxCamX = x + (width / 2f).floor()
|
||||||
gdxCamY = y + (height / 2f).round()
|
gdxCamY = y + (height / 2f).floor()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user