mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
Ladies and Gents, we have shader-powered smooth lighting!
This commit is contained in:
@@ -371,8 +371,6 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
}
|
||||
|
||||
|
||||
val testTex = Texture("assets/test_texture.tga")
|
||||
|
||||
private fun renderGame(batch: SpriteBatch) {
|
||||
Gdx.gl.glClearColor(.157f, .157f, .157f, 0f)
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
|
||||
@@ -397,8 +395,8 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
///////////////////
|
||||
// blur lightmap //
|
||||
///////////////////
|
||||
val blurIterations = 16 // ideally, 4 * radius; must be even number -- odd number will flip the image
|
||||
val blurRadius = 4f
|
||||
val blurIterations = 5 // ideally, 4 * radius; must be even/odd number -- odd/even number will flip the image
|
||||
val blurRadius = 4f // (5, 4f); using low numbers for pixel-y aesthetics
|
||||
|
||||
|
||||
|
||||
@@ -418,8 +416,6 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
var blurReadBuffer = lightmapFboB
|
||||
|
||||
|
||||
KeyToggler.forceSet(Input.Keys.F6, false)
|
||||
KeyToggler.forceSet(Input.Keys.F7, true)
|
||||
|
||||
|
||||
// initialise readBuffer with untreated lightmap
|
||||
@@ -433,21 +429,16 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
|
||||
blendNormal()
|
||||
batch.color = Color.WHITE
|
||||
//LightmapRenderer.draw(batch)
|
||||
|
||||
batch.draw(testTex, 0f, 0f)
|
||||
LightmapRenderer.draw(batch)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (TerrarumGDX.getConfigBoolean("smoothlighting")) {
|
||||
for (i in 0..blurIterations - 1) {
|
||||
blurWriteBuffer.inAction(camera, batch) {
|
||||
|
||||
batch.inUse {
|
||||
val texture = if (i == 0)
|
||||
testTex
|
||||
else
|
||||
blurReadBuffer.colorBufferTexture
|
||||
val texture = blurReadBuffer.colorBufferTexture
|
||||
|
||||
texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
|
||||
|
||||
@@ -472,15 +463,10 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TEST: passthru to writeBuffer
|
||||
/*blurWriteBuffer.inAction(camera, batch) {
|
||||
batch.inUse {
|
||||
batch.color = Color.WHITE
|
||||
batch.draw(testTex, 0f, 0f)
|
||||
}
|
||||
}*/
|
||||
else {
|
||||
blurWriteBuffer = blurReadBuffer
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -536,13 +522,10 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
setCameraPosition(0f, 0f)
|
||||
|
||||
val lightTex = blurWriteBuffer.colorBufferTexture // TODO zoom!
|
||||
if (KeyToggler.isOn(Input.Keys.F7)) blendNormal()
|
||||
if (KeyToggler.isOn(KEY_LIGHTMAP_RENDER)) blendNormal()
|
||||
else blendMul()
|
||||
batch.color = Color.WHITE
|
||||
//batch.draw(lightTex, 0f, 0f, lightTex.width * lightmapDownsample, lightTex.height * lightmapDownsample)
|
||||
|
||||
TerrarumGDX.fontGame.draw(batch, "Thumbnail:", 100f, 80f)
|
||||
batch.draw(lightTex, 100f, 100f, 100f, 100f)
|
||||
batch.draw(lightTex, 0f, 0f, lightTex.width * lightmapDownsample, lightTex.height * lightmapDownsample)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -43,9 +43,9 @@ fun main(args: Array<String>) {
|
||||
config.foregroundFPS = TerrarumGDX.RENDER_FPS
|
||||
config.backgroundFPS = TerrarumGDX.RENDER_FPS
|
||||
//config.vSyncEnabled = true
|
||||
config.resizable = false
|
||||
config.width = 512//1072
|
||||
config.height = 512//742
|
||||
config.resizable = true
|
||||
config.width = 1072
|
||||
config.height = 742
|
||||
config.backgroundFPS = 9999
|
||||
config.foregroundFPS = 9999
|
||||
//config.useGL30 = true
|
||||
|
||||
@@ -335,79 +335,6 @@ object LightmapRenderer {
|
||||
// loop x
|
||||
var x = this_x_start
|
||||
while (x < this_x_end) {
|
||||
// smoothing enabled and zoom is 0.75 or greater
|
||||
// (zoom of 0.5 should not smoothed, for performance)
|
||||
if (false && //TerrarumGDX.getConfigBoolean("smoothlighting") &&
|
||||
TerrarumGDX.ingame!!.screenZoom >= 0.75) {
|
||||
|
||||
val thisLightLevel = getLightForOpaque(x, y) ?: 0
|
||||
|
||||
if (x < this_x_end && thisLightLevel == 0
|
||||
&& getLightForOpaque(x, y - 1) == 0) {
|
||||
try {
|
||||
// coalesce zero intensity blocks to one
|
||||
var zeroLevelCounter = 1
|
||||
while (getLightForOpaque(x + zeroLevelCounter, y) == 0) {
|
||||
zeroLevelCounter += 1
|
||||
|
||||
if (x + zeroLevelCounter >= this_x_end) break
|
||||
}
|
||||
|
||||
batch.color = Color.BLACK
|
||||
batch.fillRect(
|
||||
(x.toFloat() * TILE_SIZE).round().toFloat(),
|
||||
(y.toFloat() * TILE_SIZE).round().toFloat(),
|
||||
(TILE_SIZE * zeroLevelCounter).toFloat(),
|
||||
(TILE_SIZE).toFloat()
|
||||
)
|
||||
|
||||
x += zeroLevelCounter - 1
|
||||
}
|
||||
catch (e: ArrayIndexOutOfBoundsException) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
/** a
|
||||
* +-+-+
|
||||
* |i|j|
|
||||
* b +-+-+ c
|
||||
* |k|l|
|
||||
* +-+-+
|
||||
* d
|
||||
*/
|
||||
val a = thisLightLevel maxBlend (getLightForOpaque(x, y - 1) ?: thisLightLevel)
|
||||
val d = thisLightLevel maxBlend (getLightForOpaque(x, y + 1) ?: thisLightLevel)
|
||||
val b = thisLightLevel maxBlend (getLightForOpaque(x - 1, y) ?: thisLightLevel)
|
||||
val c = thisLightLevel maxBlend (getLightForOpaque(x + 1, y) ?: thisLightLevel)
|
||||
|
||||
val colourMapItoL = IntArray(4)
|
||||
val colMean = (a linMix d) linMix (b linMix c)
|
||||
val colDelta = thisLightLevel colSub colMean
|
||||
|
||||
colourMapItoL[0] = a linMix b colAdd colDelta
|
||||
colourMapItoL[1] = a linMix c colAdd colDelta
|
||||
colourMapItoL[2] = b linMix d colAdd colDelta
|
||||
colourMapItoL[3] = c linMix d colAdd colDelta
|
||||
|
||||
for (iy in 0..1) {
|
||||
for (ix in 0..1) {
|
||||
batch.color = colourMapItoL[iy * 2 + ix].normaliseToColourHDR()
|
||||
batch.fillRect(
|
||||
(x.toFloat() * TILE_SIZE).round()
|
||||
+ ix * TILE_SIZE / 2f,
|
||||
(y.toFloat() * TILE_SIZE).round()
|
||||
+ iy * TILE_SIZE / 2f,
|
||||
(TILE_SIZE / 2f).ceil().toFloat(),
|
||||
(TILE_SIZE / 2f).ceil().toFloat()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// smoothing disabled
|
||||
else {
|
||||
try {
|
||||
val thisLightLevel = getLightForOpaque(x, y)
|
||||
|
||||
@@ -433,7 +360,6 @@ object LightmapRenderer {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
x++
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user