needs more shader (for smoothing out lightmap render)

This commit is contained in:
minjaesong
2017-07-04 14:58:18 +09:00
parent 9027f85d1d
commit db2fd0c8e4
8 changed files with 89 additions and 24 deletions

16
assets/13.glsl Normal file
View File

@@ -0,0 +1,16 @@
vec4 blur13(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {
vec4 color = vec4(0.0);
vec2 off1 = vec2(1.411764705882353) * direction;
vec2 off2 = vec2(3.2941176470588234) * direction;
vec2 off3 = vec2(5.176470588235294) * direction;
color += texture2D(image, uv) * 0.1964825501511404;
color += texture2D(image, uv + (off1 / resolution)) * 0.2969069646728344;
color += texture2D(image, uv - (off1 / resolution)) * 0.2969069646728344;
color += texture2D(image, uv + (off2 / resolution)) * 0.09447039785044732;
color += texture2D(image, uv - (off2 / resolution)) * 0.09447039785044732;
color += texture2D(image, uv + (off3 / resolution)) * 0.010381362401148057;
color += texture2D(image, uv - (off3 / resolution)) * 0.010381362401148057;
return color;
}
#pragma glslify: export(blur13)

View File

@@ -1,11 +1,13 @@
precision mediump float; precision highp float;
uniform vec3 iResolution; uniform vec3 iResolution;
uniform sampler2D iChannel0; uniform sampler2D iChannel0;
uniform bool flip; uniform bool flip;
uniform vec2 direction; uniform vec2 direction;
#pragma glslify: blur = require('../') //uniform mat4 u_projTrans;
#pragma glslify: blur = require('13')
void main() { void main() {
vec2 uv = vec2(gl_FragCoord.xy / iResolution.xy); vec2 uv = vec2(gl_FragCoord.xy / iResolution.xy);

View File

@@ -81,6 +81,8 @@ object DefaultConfig {
jsonObject.addProperty("maxparticles", 768) jsonObject.addProperty("maxparticles", 768)
jsonObject.addProperty("fullframelightupdate", false)
return jsonObject return jsonObject
} }

View File

@@ -73,6 +73,8 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
val ZOOM_MIN = 0.5f val ZOOM_MIN = 0.5f
var worldDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width.div(ZOOM_MIN).ceilInt(), Gdx.graphics.height.div(ZOOM_MIN).ceilInt(), false) var worldDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width.div(ZOOM_MIN).ceilInt(), Gdx.graphics.height.div(ZOOM_MIN).ceilInt(), false)
var lightmapFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width.div(ZOOM_MIN).ceilInt(), Gdx.graphics.height.div(ZOOM_MIN).ceilInt(), false)
// lightmapFrameBuffer: used to smooth out lightmap using shader
//private lateinit var shader12BitCol: Shader // grab LibGDX if you want some shader //private lateinit var shader12BitCol: Shader // grab LibGDX if you want some shader
//private lateinit var shaderBlur: Shader //private lateinit var shaderBlur: Shader
@@ -354,7 +356,7 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
// app-related updates // // app-related updates //
///////////////////////// /////////////////////////
// determine if lightmap blending should be done // determine if smooth lighting should be done
TerrarumGDX.setConfig("smoothlighting", KeyToggler.isOn(KEY_LIGHTMAP_SMOOTH)) TerrarumGDX.setConfig("smoothlighting", KeyToggler.isOn(KEY_LIGHTMAP_SMOOTH))
@@ -372,29 +374,51 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
//camera.position.set(0f, 0f, 0f) // make camara work //camera.position.set(0f, 0f, 0f) // make camara work
//batch.projectionMatrix = camera.combined //batch.projectionMatrix = camera.combined
TerrarumGDX.GLOBAL_RENDER_TIMER += 1
// clean the shit beforehand // clean the shit beforehand
worldDrawFrameBuffer.inAction { worldDrawFrameBuffer.inAction {
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)
} }
lightmapFrameBuffer.inAction {
Gdx.gl.glClearColor(0f,0f,0f,0f)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
}
// Post-update; ones that needs everything is completed // // Post-update; ones that needs everything is completed //
FeaturesDrawer.render(batch) // FeaturesDrawer.render(batch) //
// update lightmap on every other frames, OR full-frame if the option is true
if (TerrarumGDX.getConfigBoolean("fullframelightupdate") or (TerrarumGDX.GLOBAL_RENDER_TIMER and 1 == 1)) { //
LightmapRenderer.fireRecalculateEvent() //
} //
// end of post-update // // end of post-update //
// now the actual drawing part // // now the actual drawing part //
worldDrawFrameBuffer.inAction { lightmapFrameBuffer.inAction {
// TODO gaussian blur p=8
//batch.shader = TerrarumGDX.shaderBlur
batch.inUse { batch.inUse {
// using custom code; this is obscure and tricky // using custom code for camera; this is obscure and tricky
camera.position.set(WorldCamera.gdxCamX, WorldCamera.gdxCamY, 0f) // make camara work camera.position.set(WorldCamera.gdxCamX, WorldCamera.gdxCamY, 0f) // make camara work
camera.update() camera.update()
batch.projectionMatrix = camera.combined batch.projectionMatrix = camera.combined
blendNormal()
LightmapRenderer.draw(batch)
}
}
worldDrawFrameBuffer.inAction {
batch.inUse {
// using custom code for camera; this is obscure and tricky
camera.position.set(WorldCamera.gdxCamX, WorldCamera.gdxCamY, 0f) // make camara work
camera.update()
batch.projectionMatrix = camera.combined
batch.color = Color.WHITE batch.color = Color.WHITE
blendNormal() blendNormal()
@@ -424,12 +448,23 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
FeaturesDrawer.drawEnvOverlay(batch) FeaturesDrawer.drawEnvOverlay(batch)
if (KeyToggler.isOn(Input.Keys.F7)) // mix lighpmap canvas to this canvas
blendNormal() if (!KeyToggler.isOn(Input.Keys.F6)) { // F6 do disable lightmap draw
else setCameraPosition(0f, 0f)
blendMul()
LightmapRenderer.fireRecalculateEvent() val lightTex = lightmapFrameBuffer.colorBufferTexture // TODO zoom!
LightmapRenderer.draw(batch) if (KeyToggler.isOn(Input.Keys.F7)) blendNormal()
else blendMul()
batch.draw(lightTex, 0f, 0f, Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat())
}
// move camera back to its former position
// using custom code for camera; this is obscure and tricky
camera.position.set(WorldCamera.gdxCamX, WorldCamera.gdxCamY, 0f) // make camara work
camera.update()
batch.projectionMatrix = camera.combined
////////////////////// //////////////////////
@@ -463,8 +498,8 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
WeatherMixer.render(batch) WeatherMixer.render(batch)
batch.color = Color.WHITE batch.color = Color.WHITE
val tex = worldDrawFrameBuffer.colorBufferTexture // TODO zoom! val worldTex = worldDrawFrameBuffer.colorBufferTexture // TODO zoom!
batch.draw(tex, 0f, 0f, Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat()) batch.draw(worldTex, 0f, 0f, Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat())

View File

@@ -3,6 +3,7 @@ package net.torvald.terrarum
import com.badlogic.gdx.ApplicationAdapter import com.badlogic.gdx.ApplicationAdapter
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Screen import com.badlogic.gdx.Screen
import com.badlogic.gdx.assets.loaders.ShaderProgramLoader
import com.badlogic.gdx.backends.lwjgl.LwjglApplication import com.badlogic.gdx.backends.lwjgl.LwjglApplication
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
@@ -14,6 +15,7 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont
import com.badlogic.gdx.graphics.g2d.CpuSpriteBatch import com.badlogic.gdx.graphics.g2d.CpuSpriteBatch
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.glutils.FrameBuffer import com.badlogic.gdx.graphics.glutils.FrameBuffer
import com.badlogic.gdx.graphics.glutils.ShaderProgram
import com.badlogic.gdx.graphics.glutils.ShapeRenderer import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import com.google.gson.JsonArray import com.google.gson.JsonArray
import com.google.gson.JsonPrimitive import com.google.gson.JsonPrimitive
@@ -234,6 +236,9 @@ object TerrarumGDX : ApplicationAdapter() {
val is32BitJVM = !System.getProperty("sun.arch.data.model").contains("64") val is32BitJVM = !System.getProperty("sun.arch.data.model").contains("64")
lateinit var shaderBlur: ShaderProgram
init { init {
println("[Terrarum] os.arch = $systemArch") // debug info println("[Terrarum] os.arch = $systemArch") // debug info
@@ -289,6 +294,9 @@ object TerrarumGDX : ApplicationAdapter() {
fontSmallNumbers = TinyAlphNum fontSmallNumbers = TinyAlphNum
shaderBlur = ShaderProgram(Gdx.files.internal("assets/blur.vert"), Gdx.files.internal("assets/blur.frag"))
ModMgr // invoke Module Manager, will also invoke BlockCodex ModMgr // invoke Module Manager, will also invoke BlockCodex
ItemCodex // invoke Item Codex ItemCodex // invoke Item Codex
@@ -302,6 +310,7 @@ object TerrarumGDX : ApplicationAdapter() {
override fun render() { override fun render() {
currentScreen.render(Gdx.graphics.deltaTime) currentScreen.render(Gdx.graphics.deltaTime)
GLOBAL_RENDER_TIMER += 1
} }
override fun pause() { override fun pause() {

View File

@@ -85,8 +85,6 @@ class UIItemInventoryElem(
if (item != null && itemImage != null) { if (item != null && itemImage != null) {
blendNormal() blendNormal()
//println("orgID: ${item!!.originalID}, nameKey: ${BlockCodex[item!!.originalID].nameKey}, itemOrgName: ${item!!.originalName}")
// item image // item image
batch.color = Color.WHITE batch.color = Color.WHITE
batch.draw(itemImage, posX + imgOffset, posY + imgOffset) batch.draw(itemImage, posX + imgOffset, posY + imgOffset)

View File

@@ -442,12 +442,12 @@ object BlocksDrawer {
LightmapRenderer.getHighestRGB(x + 1, y - 1) ?: 0 >= tileDrawLightThreshold || LightmapRenderer.getHighestRGB(x + 1, y - 1) ?: 0 >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x - 1, y + 1) ?: 0 >= tileDrawLightThreshold) LightmapRenderer.getHighestRGB(x - 1, y + 1) ?: 0 >= tileDrawLightThreshold)
{ {
// TODO coalesce non-lit black patches // FIXME bad scanlines bug
if (zeroTileCounter > 0) { if (zeroTileCounter > 0) {
batch.color = Color.BLACK /*batch.color = Color.BLACK
batch.fillRect(x * TILE_SIZEF, y * TILE_SIZEF, -zeroTileCounter * TILE_SIZEF, TILE_SIZEF) batch.fillRect(x * TILE_SIZEF, y * TILE_SIZEF, -zeroTileCounter * TILE_SIZEF, TILE_SIZEF)
batch.color = color batch.color = color
zeroTileCounter = 0 zeroTileCounter = 0*/
} }
@@ -508,6 +508,8 @@ object BlocksDrawer {
// draw black patch // draw black patch
else { else {
zeroTileCounter += 1 // unused for now zeroTileCounter += 1 // unused for now
batch.color = Color.BLACK
batch.fillRect(x * TILE_SIZEF, y * TILE_SIZEF, TILE_SIZEF, TILE_SIZEF)
} }
} // end if (not an air) } // end if (not an air)
} catch (e: NullPointerException) { } catch (e: NullPointerException) {
@@ -517,12 +519,13 @@ object BlocksDrawer {
// hit the end of the current scanline // hit the end of the current scanline
// FIXME bad scanlines bug // FIXME bad scanlines bug
if (x == for_x_end) { /*if (x == for_x_end) {
val x = x + 1 // because current tile is also counted
batch.color = Color.BLACK batch.color = Color.BLACK
batch.fillRect(x * TILE_SIZEF, y * TILE_SIZEF, -zeroTileCounter * TILE_SIZEF, TILE_SIZEF) batch.fillRect(x * TILE_SIZEF, y * TILE_SIZEF, -zeroTileCounter * TILE_SIZEF, TILE_SIZEF)
batch.color = color batch.color = color
zeroTileCounter = 0 zeroTileCounter = 0
} }*/
} }
} }

View File

@@ -334,7 +334,7 @@ object LightmapRenderer {
while (x < this_x_end) { while (x < this_x_end) {
// smoothing enabled and zoom is 0.75 or greater // smoothing enabled and zoom is 0.75 or greater
// (zoom of 0.5 should not smoothed, for performance) // (zoom of 0.5 should not smoothed, for performance)
if (TerrarumGDX.getConfigBoolean("smoothlighting") && if (false && //TerrarumGDX.getConfigBoolean("smoothlighting") &&
TerrarumGDX.ingame!!.screenZoom >= 0.75) { TerrarumGDX.ingame!!.screenZoom >= 0.75) {
val thisLightLevel = getLightForOpaque(x, y) ?: 0 val thisLightLevel = getLightForOpaque(x, y) ?: 0