lightmap blurring simplified

This commit is contained in:
minjaesong
2021-12-12 20:39:12 +09:00
parent 5fb3e0b6b4
commit b7f7558192
9 changed files with 56 additions and 72 deletions

View File

@@ -45,7 +45,7 @@ Veuillez reconfigurer votre ordre de chargement sur :
private val maxtw = wot.maxOf { App.fontGameFBO.getWidth(it) } private val maxtw = wot.maxOf { App.fontGameFBO.getWidth(it) }
private val fbo = FrameBuffer(Pixmap.Format.RGBA8888, App.scr.width, App.scr.height, true) private val fbo = FrameBuffer(Pixmap.Format.RGBA8888, App.scr.width, App.scr.height, false)
private var init = false private var init = false

View File

@@ -51,7 +51,7 @@ object SanicLoadScreen : LoadScreenBase() {
App.fontGame.getWidth(Lang["ERROR_GENERIC_TEXT"]) App.fontGame.getWidth(Lang["ERROR_GENERIC_TEXT"])
), ),
App.fontGame.lineHeight.toInt(), App.fontGame.lineHeight.toInt(),
true false
) )
arrowObjTex = Texture(Gdx.files.internal("assets/graphics/test_loading_arrow_atlas.tga")) arrowObjTex = Texture(Gdx.files.internal("assets/graphics/test_loading_arrow_atlas.tga"))

View File

@@ -125,7 +125,7 @@ object IME {
if (langCode.isNotEmpty()) { if (langCode.isNotEmpty()) {
printdbg(this, "Icon order #${(k+1) / 20} - icons[\"$langCode\"] = iconSheet.get(1, ${k/20})") printdbg(this, "Icon order #${(k+1) / 20} - icons[\"$langCode\"] = iconSheet.get(1, ${k/20})")
iconSheet.get(1, k / 20).let { iconSheet.get(1, k / 20).let {
it.flip(false, true) it.flip(false, false)
icons["$langCode"] = it icons["$langCode"] = it
} }

View File

@@ -48,10 +48,9 @@ object IngameRenderer : Disposable {
private lateinit var blurWriteQuad: Mesh private lateinit var blurWriteQuad: Mesh
private lateinit var blurWriteQuad2: Mesh private lateinit var blurWriteQuad2: Mesh
private lateinit var blurWriteQuad4: Mesh // private lateinit var blurWriteQuad4: Mesh
private lateinit var lightmapFboA: FloatFrameBuffer private lateinit var lightmapFbo: FloatFrameBuffer
private lateinit var lightmapFboB: FloatFrameBuffer
private lateinit var fboRGB: FloatFrameBuffer private lateinit var fboRGB: FloatFrameBuffer
private lateinit var fboRGB_lightMixed: FloatFrameBuffer private lateinit var fboRGB_lightMixed: FloatFrameBuffer
private lateinit var fboA: FloatFrameBuffer private lateinit var fboA: FloatFrameBuffer
@@ -64,7 +63,7 @@ object IngameRenderer : Disposable {
private lateinit var blurTex: TextureRegion private lateinit var blurTex: TextureRegion
private lateinit var fboBlurHalf: FloatFrameBuffer private lateinit var fboBlurHalf: FloatFrameBuffer
private lateinit var fboBlurQuarter: FloatFrameBuffer // private lateinit var fboBlurQuarter: FloatFrameBuffer
// you must have lightMixed FBO; otherwise you'll be reading from unbaked FBO and it freaks out GPU // you must have lightMixed FBO; otherwise you'll be reading from unbaked FBO and it freaks out GPU
@@ -398,17 +397,13 @@ object IngameRenderer : Disposable {
private fun prepLightmapRGBA() { private fun prepLightmapRGBA() {
lightmapFboA.inAction(null, null) { lightmapFbo.inAction(null, null) {
clearBuffer()
Gdx.gl.glDisable(GL20.GL_BLEND)
}
lightmapFboB.inAction(null, null) {
clearBuffer() clearBuffer()
Gdx.gl.glDisable(GL20.GL_BLEND) Gdx.gl.glDisable(GL20.GL_BLEND)
} }
// processBlur(lightmapFboA, lightmapFboB) // processBlur(lightmapFboA, lightmapFboB)
processKawaseBlur(lightmapFboB) processKawaseBlur(lightmapFbo)
// processNoBlur() // processNoBlur()
@@ -660,19 +655,20 @@ object IngameRenderer : Disposable {
batch.projectionMatrix = camera.combined batch.projectionMatrix = camera.combined
} }
private const val KAWASE_POWER = 0.667f
private var blurtex0 = Texture(16, 16, Pixmap.Format.RGBA8888) private var blurtex0 = Texture(16, 16, Pixmap.Format.RGBA8888)
private var blurtex1 = Texture(16, 16, Pixmap.Format.RGBA8888) private lateinit var blurtex1: Texture
private var blurtex2 = Texture(16, 16, Pixmap.Format.RGBA8888) private lateinit var blurtex2: Texture
private var blurtex3 = Texture(16, 16, Pixmap.Format.RGBA8888) private lateinit var blurtex3: Texture
private var blurtex4 = Texture(16, 16, Pixmap.Format.RGBA8888) private lateinit var blurtex4: Texture
private const val KAWASE_POWER = 1.5f
fun processKawaseBlur(outFbo: FloatFrameBuffer) { fun processKawaseBlur(outFbo: FloatFrameBuffer) {
blurtex0.dispose() blurtex0.dispose()
// initialise readBuffer with untreated lightmap // initialise readBuffer with untreated lightmap
outFbo.inAction(camera, batch) { outFbo.inAction(camera, batch) {
blurtex0 = LightmapRenderer.draw() blurtex0 = LightmapRenderer.draw()
@@ -695,7 +691,7 @@ object IngameRenderer : Disposable {
blurWriteQuad2.render(shaderKawaseDown, GL20.GL_TRIANGLES) blurWriteQuad2.render(shaderKawaseDown, GL20.GL_TRIANGLES)
} }
fboBlurQuarter.inAction(camera, batch) { /*fboBlurQuarter.inAction(camera, batch) {
blurtex2 = fboBlurHalf.colorBufferTexture blurtex2 = fboBlurHalf.colorBufferTexture
blurtex2.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear) blurtex2.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
blurtex2.bind(0) blurtex2.bind(0)
@@ -715,11 +711,11 @@ object IngameRenderer : Disposable {
shaderKawaseUp.setUniformi("u_texture", 0) shaderKawaseUp.setUniformi("u_texture", 0)
shaderKawaseUp.setUniformf("halfpixel", KAWASE_POWER / fboBlurQuarter.width, KAWASE_POWER / fboBlurQuarter.height) shaderKawaseUp.setUniformf("halfpixel", KAWASE_POWER / fboBlurQuarter.width, KAWASE_POWER / fboBlurQuarter.height)
blurWriteQuad2.render(shaderKawaseUp, GL20.GL_TRIANGLES) blurWriteQuad2.render(shaderKawaseUp, GL20.GL_TRIANGLES)
} }*/
// TODO apply dithering on this specific draw call
outFbo.inAction(camera, batch) { outFbo.inAction(camera, batch) {
blurtex4 = fboBlurHalf.colorBufferTexture blurtex4 = fboBlurHalf.colorBufferTexture
blurtex4.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
blurtex4.bind(0) blurtex4.bind(0)
shaderKawaseUp.bind() shaderKawaseUp.bind()
shaderKawaseUp.setUniformMatrix("u_projTrans", camera.combined) shaderKawaseUp.setUniformMatrix("u_projTrans", camera.combined)
@@ -746,12 +742,12 @@ object IngameRenderer : Disposable {
VertexAttribute.ColorUnpacked(), VertexAttribute.ColorUnpacked(),
VertexAttribute.TexCoords(0) VertexAttribute.TexCoords(0)
) )
blurWriteQuad4 = Mesh( /*blurWriteQuad4 = Mesh(
true, 4, 6, true, 4, 6,
VertexAttribute.Position(), VertexAttribute.Position(),
VertexAttribute.ColorUnpacked(), VertexAttribute.ColorUnpacked(),
VertexAttribute.TexCoords(0) VertexAttribute.TexCoords(0)
) )*/
init = true init = true
} }
else { else {
@@ -759,45 +755,39 @@ object IngameRenderer : Disposable {
fboRGB_lightMixed.dispose() fboRGB_lightMixed.dispose()
fboA.dispose() fboA.dispose()
fboA_lightMixed.dispose() fboA_lightMixed.dispose()
lightmapFboA.dispose() lightmapFbo.dispose()
lightmapFboB.dispose()
fboBlurHalf.dispose() fboBlurHalf.dispose()
fboBlurQuarter.dispose() //fboBlurQuarter.dispose()
} }
fboRGB = FloatFrameBuffer(width, height, true) fboRGB = FloatFrameBuffer(width, height, false)
fboRGB_lightMixed = FloatFrameBuffer(width, height, true) fboRGB_lightMixed = FloatFrameBuffer(width, height, false)
fboA = FloatFrameBuffer(width, height, true) fboA = FloatFrameBuffer(width, height, false)
fboA_lightMixed = FloatFrameBuffer(width, height, true) fboA_lightMixed = FloatFrameBuffer(width, height, false)
fboMixedOut = FloatFrameBuffer(width, height, true) fboMixedOut = FloatFrameBuffer(width, height, false)
lightmapFboA = FloatFrameBuffer( lightmapFbo = FloatFrameBuffer(
LightmapRenderer.lightBuffer.width * LightmapRenderer.DRAW_TILE_SIZE.toInt(), LightmapRenderer.lightBuffer.width * LightmapRenderer.DRAW_TILE_SIZE.toInt(),
LightmapRenderer.lightBuffer.height * LightmapRenderer.DRAW_TILE_SIZE.toInt(), LightmapRenderer.lightBuffer.height * LightmapRenderer.DRAW_TILE_SIZE.toInt(),
true false
)
lightmapFboB = FloatFrameBuffer(
LightmapRenderer.lightBuffer.width * LightmapRenderer.DRAW_TILE_SIZE.toInt(),
LightmapRenderer.lightBuffer.height * LightmapRenderer.DRAW_TILE_SIZE.toInt(),
true
) )
rgbTex = TextureRegion(fboRGB_lightMixed.colorBufferTexture) rgbTex = TextureRegion(fboRGB_lightMixed.colorBufferTexture)
aTex = TextureRegion(fboA_lightMixed.colorBufferTexture) aTex = TextureRegion(fboA_lightMixed.colorBufferTexture)
lightTex = TextureRegion(lightmapFboB.colorBufferTexture) lightTex = TextureRegion(lightmapFbo.colorBufferTexture)
blurTex = TextureRegion() blurTex = TextureRegion()
mixedOutTex = TextureRegion(fboMixedOut.colorBufferTexture) mixedOutTex = TextureRegion(fboMixedOut.colorBufferTexture)
fboBlurHalf = FloatFrameBuffer( fboBlurHalf = FloatFrameBuffer(
LightmapRenderer.lightBuffer.width * LightmapRenderer.DRAW_TILE_SIZE.toInt() / 2, LightmapRenderer.lightBuffer.width * LightmapRenderer.DRAW_TILE_SIZE.toInt() / 2,
LightmapRenderer.lightBuffer.height * LightmapRenderer.DRAW_TILE_SIZE.toInt() / 2, LightmapRenderer.lightBuffer.height * LightmapRenderer.DRAW_TILE_SIZE.toInt() / 2,
true false
) )
fboBlurQuarter = FloatFrameBuffer( /*fboBlurQuarter = FloatFrameBuffer(
LightmapRenderer.lightBuffer.width * LightmapRenderer.DRAW_TILE_SIZE.toInt() / 4, LightmapRenderer.lightBuffer.width * LightmapRenderer.DRAW_TILE_SIZE.toInt() / 4,
LightmapRenderer.lightBuffer.height * LightmapRenderer.DRAW_TILE_SIZE.toInt() / 4, LightmapRenderer.lightBuffer.height * LightmapRenderer.DRAW_TILE_SIZE.toInt() / 4,
true false
) )*/
BlocksDrawer.resize(width, height) BlocksDrawer.resize(width, height)
LightmapRenderer.resize(width, height) LightmapRenderer.resize(width, height)
@@ -805,47 +795,42 @@ object IngameRenderer : Disposable {
blurWriteQuad.setVertices(floatArrayOf( blurWriteQuad.setVertices(floatArrayOf(
0f,0f,0f, 1f,1f,1f,1f, 0f,1f, 0f,0f,0f, 1f,1f,1f,1f, 0f,1f,
lightmapFboA.width.toFloat(),0f,0f, 1f,1f,1f,1f, 1f,1f, lightmapFbo.width.toFloat(),0f,0f, 1f,1f,1f,1f, 1f,1f,
lightmapFboA.width.toFloat(),lightmapFboA.height.toFloat(),0f, 1f,1f,1f,1f, 1f,0f, lightmapFbo.width.toFloat(),lightmapFbo.height.toFloat(),0f, 1f,1f,1f,1f, 1f,0f,
0f,lightmapFboA.height.toFloat(),0f, 1f,1f,1f,1f, 0f,0f)) 0f,lightmapFbo.height.toFloat(),0f, 1f,1f,1f,1f, 0f,0f))
blurWriteQuad.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0)) blurWriteQuad.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))
blurWriteQuad2.setVertices(floatArrayOf( blurWriteQuad2.setVertices(floatArrayOf(
0f,0f,0f, 1f,1f,1f,1f, 0f,1f, 0f,0f,0f, 1f,1f,1f,1f, 0f,1f,
lightmapFboA.width.div(2).toFloat(),0f,0f, 1f,1f,1f,1f, 1f,1f, lightmapFbo.width.div(2).toFloat(),0f,0f, 1f,1f,1f,1f, 1f,1f,
lightmapFboA.width.div(2).toFloat(),lightmapFboA.height.div(2).toFloat(),0f, 1f,1f,1f,1f, 1f,0f, lightmapFbo.width.div(2).toFloat(),lightmapFbo.height.div(2).toFloat(),0f, 1f,1f,1f,1f, 1f,0f,
0f,lightmapFboA.height.div(2).toFloat(),0f, 1f,1f,1f,1f, 0f,0f)) 0f,lightmapFbo.height.div(2).toFloat(),0f, 1f,1f,1f,1f, 0f,0f))
blurWriteQuad2.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0)) blurWriteQuad2.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))
blurWriteQuad4.setVertices(floatArrayOf( /*blurWriteQuad4.setVertices(floatArrayOf(
0f,0f,0f, 1f,1f,1f,1f, 0f,1f, 0f,0f,0f, 1f,1f,1f,1f, 0f,1f,
lightmapFboA.width.div(4).toFloat(),0f,0f, 1f,1f,1f,1f, 1f,1f, lightmapFbo.width.div(4).toFloat(),0f,0f, 1f,1f,1f,1f, 1f,1f,
lightmapFboA.width.div(4).toFloat(),lightmapFboA.height.div(4).toFloat(),0f, 1f,1f,1f,1f, 1f,0f, lightmapFbo.width.div(4).toFloat(),lightmapFbo.height.div(4).toFloat(),0f, 1f,1f,1f,1f, 1f,0f,
0f,lightmapFboA.height.div(4).toFloat(),0f, 1f,1f,1f,1f, 0f,0f)) 0f,lightmapFbo.height.div(4).toFloat(),0f, 1f,1f,1f,1f, 0f,0f))
blurWriteQuad4.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0)) blurWriteQuad4.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))*/
} }
override fun dispose() { override fun dispose() {
blurWriteQuad.dispose() blurWriteQuad.dispose()
blurWriteQuad2.dispose() blurWriteQuad2.dispose()
blurWriteQuad4.dispose() //blurWriteQuad4.dispose()
fboRGB.dispose() fboRGB.dispose()
fboA.dispose() fboA.dispose()
fboRGB_lightMixed.dispose() fboRGB_lightMixed.dispose()
fboA_lightMixed.dispose() fboA_lightMixed.dispose()
fboMixedOut.dispose() fboMixedOut.dispose()
lightmapFboA.dispose() lightmapFbo.dispose()
lightmapFboB.dispose()
try { blurtex0.dispose() } catch (e: GdxRuntimeException) {} try { blurtex0.dispose() } catch (e: GdxRuntimeException) {}
// try { blurtex1.dispose() } catch (e: GdxRuntimeException) {}
// try { blurtex2.dispose() } catch (e: GdxRuntimeException) {}
// try { blurtex3.dispose() } catch (e: GdxRuntimeException) {}
// try { blurtex4.dispose() } catch (e: GdxRuntimeException) {}
fboBlurHalf.dispose() fboBlurHalf.dispose()
fboBlurQuarter.dispose() //fboBlurQuarter.dispose()
LightmapRenderer.dispose() LightmapRenderer.dispose()
BlocksDrawer.dispose() BlocksDrawer.dispose()

View File

@@ -29,7 +29,6 @@ import net.torvald.terrarum.ui.Movement
import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItem import net.torvald.terrarum.ui.UIItem
import net.torvald.terrarum.utils.RandomWordsName
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import java.time.Instant import java.time.Instant
import java.time.format.DateTimeFormatter import java.time.format.DateTimeFormatter
@@ -137,7 +136,7 @@ class UILoadDemoSavefiles(val remoCon: UIRemoCon) : UICanvas() {
private var scrollAnimCounter = 0f private var scrollAnimCounter = 0f
private val scrollAnimLen = 0.1f private val scrollAnimLen = 0.1f
private var sliderFBO = FrameBuffer(Pixmap.Format.RGBA8888, uiWidth + 10, height, true) private var sliderFBO = FrameBuffer(Pixmap.Format.RGBA8888, uiWidth + 10, height, false)
private var showSpinner = false private var showSpinner = false
@@ -450,7 +449,7 @@ class UILoadDemoSavefiles(val remoCon: UIRemoCon) : UICanvas() {
uiScroll = 0f uiScroll = 0f
sliderFBO.dispose() sliderFBO.dispose()
sliderFBO = FrameBuffer(Pixmap.Format.RGBA8888, uiWidth + 10, height, true) sliderFBO = FrameBuffer(Pixmap.Format.RGBA8888, uiWidth + 10, height, false)
} }
private fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) { private fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) {

View File

@@ -298,17 +298,17 @@ object Toolkit : Disposable {
fboBlur = FloatFrameBuffer( fboBlur = FloatFrameBuffer(
fw, fw,
fh, fh,
true false
) )
fboBlurHalf = FloatFrameBuffer( fboBlurHalf = FloatFrameBuffer(
fw / 2, fw / 2,
fh / 2, fh / 2,
true false
) )
fboBlurQuarter = FloatFrameBuffer( fboBlurQuarter = FloatFrameBuffer(
fw / 4, fw / 4,
fh / 4, fh / 4,
true false
) )
blurWriteQuad.setVertices(floatArrayOf( blurWriteQuad.setVertices(floatArrayOf(

View File

@@ -36,7 +36,7 @@ class UIItemSpinner(
override val height = 24 override val height = 24
private val buttonW = 30 private val buttonW = 30
private val fbo = FrameBuffer(Pixmap.Format.RGBA8888, width - 2*buttonW - 6, height - 4, true) private val fbo = FrameBuffer(Pixmap.Format.RGBA8888, width - 2*buttonW - 6, height - 4, false)
var value = initialValue.coerceIn(min, max) var value = initialValue.coerceIn(min, max)
private var fboUpdateLatch = true private var fboUpdateLatch = true

View File

@@ -99,7 +99,7 @@ class UIItemTextLineInput(
Pixmap.Format.RGBA8888, Pixmap.Format.RGBA8888,
width - 2 * UI_TEXT_MARGIN - 2 * (WIDTH_ONEBUTTON + 3), width - 2 * UI_TEXT_MARGIN - 2 * (WIDTH_ONEBUTTON + 3),
height - 2 * UI_TEXT_MARGIN, height - 2 * UI_TEXT_MARGIN,
true false
) )
var isActive: Boolean = false // keep it false by default! var isActive: Boolean = false // keep it false by default!
@@ -283,7 +283,7 @@ class UIItemTextLineInput(
else if (keycodes.containsSome(Input.Keys.ENTER, Input.Keys.NUMPAD_ENTER)) { else if (keycodes.containsSome(Input.Keys.ENTER, Input.Keys.NUMPAD_ENTER)) {
endComposing() endComposing()
println("END COMPOSING!!") // println("END COMPOSING!!")
} }
// accept: // accept:
// - literal "<" // - literal "<"

View File

@@ -44,7 +44,7 @@ class UIItemTextSelector(
override val height = 24 override val height = 24
private val buttonW = 30 private val buttonW = 30
private val fbo = FrameBuffer(Pixmap.Format.RGBA8888, width - 2*buttonW - 6, height - 4, true) private val fbo = FrameBuffer(Pixmap.Format.RGBA8888, width - 2*buttonW - 6, height - 4, false)
var selection = initialSelection var selection = initialSelection
private var fboUpdateLatch = true private var fboUpdateLatch = true