killed old zoom so that framebuffer would render without hack

This commit is contained in:
minjaesong
2017-07-04 20:11:54 +09:00
parent 4a6f88ea29
commit ecc883f9ca
5 changed files with 106 additions and 34 deletions

View File

@@ -1,19 +1,73 @@
precision highp float;
#ifdef GL_ES
#define LOWP lowp
precision mediump float;
#else
#define LOWP
#endif
uniform vec3 iResolution;
uniform sampler2D iChannel0;
uniform bool flip;
uniform vec2 direction;
varying vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
//uniform mat4 u_projTrans;
#pragma glslify: blur = require('13')
varying vec4 vertexWorldPos;
uniform vec4 backColor;
uniform float width;
uniform float height;
void main() {
vec2 uv = vec2(gl_FragCoord.xy / iResolution.xy);
if (flip) {
uv.y = 1.0 - uv.y;
}
vec2 tex;
vec4 color2=vec4(0.0,0.0,0.0,0);
float stepx=(1.0/width)*4.0;
float stepy=(1.0/height)*4.0;
vec4 color;
tex.x=v_texCoords.x+stepx;
tex.y=v_texCoords.y+stepy;
color=v_color * texture2D(u_texture, tex);
color2.r+=color.r;
color2.g+=color.g;
color2.b+=color.b;
color2.a+=color.a;
tex.x=v_texCoords.x-stepx;
tex.y=v_texCoords.y+stepy;
color=v_color * texture2D(u_texture, tex);
color2.r+=color.r;
color2.g+=color.g;
color2.b+=color.b;
color2.a+=color.a;
tex.x=v_texCoords.x-stepx;
tex.y=v_texCoords.y-stepy;
color=v_color * texture2D(u_texture, tex);
color2.r+=color.r;
color2.g+=color.g;
color2.b+=color.b;
color2.a+=color.a;
tex.x=v_texCoords.x+stepx;
tex.y=v_texCoords.y-stepy;
color=v_color * texture2D(u_texture, tex);
color2.r+=color.r;
color2.g+=color.g;
color2.b+=color.b;
color2.a+=color.a;
tex.x=v_texCoords.x;
tex.y=v_texCoords.y;
color=v_color * texture2D(u_texture, tex);
color2.r+=color.r;
color2.g+=color.g;
color2.b+=color.b;
color2.a+=color.a;
color2.r/=5.0;
color2.g/=5.0;
color2.b/=5.0;
color2.a/=5.0;
gl_FragColor = color2;
gl_FragColor = blur(iChannel0, uv, iResolution.xy, direction);
}

View File

@@ -69,11 +69,15 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
get() = playableActorDelegate?.actor
var screenZoom = 1.0f
val ZOOM_MAX = 4.0f
val ZOOM_MIN = 0.5f
val ZOOM_MAXIMUM = 4.0f
val ZOOM_MINIMUM = 0.5f
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)
companion object {
val lightmapDownsample = 1f // have no fucking idea why downsampling wrecks camera and render
}
var worldDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width, Gdx.graphics.height, false)
var lightmapFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width.div(lightmapDownsample).ceilInt(), Gdx.graphics.height.div(lightmapDownsample).ceilInt(), false)
// lightmapFrameBuffer: used to smooth out lightmap using shader
//private lateinit var shader12BitCol: Shader // grab LibGDX if you want some shader
@@ -389,7 +393,7 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
// Post-update; ones that needs everything is completed //
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)) { //
if (TerrarumGDX.getConfigBoolean("fullframelightupdate") or (TerrarumGDX.GLOBAL_RENDER_TIMER % 2 == 1)) { //
LightmapRenderer.fireRecalculateEvent() //
} //
// end of post-update //
@@ -398,8 +402,12 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
// now the actual drawing part //
lightmapFrameBuffer.inAction {
// TODO gaussian blur p=8
//batch.shader = TerrarumGDX.shaderBlur
TerrarumGDX.shaderBlur.setUniformf("width", lightmapFrameBuffer.width.toFloat())
TerrarumGDX.shaderBlur.setUniformf("height", lightmapFrameBuffer.height.toFloat())
batch.inUse {
batch.shader = null//TerrarumGDX.shaderBlur
// using custom code for camera; this is obscure and tricky
camera.position.set(WorldCamera.gdxCamX, WorldCamera.gdxCamY, 0f) // make camara work
camera.update()
@@ -413,6 +421,8 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
worldDrawFrameBuffer.inAction {
batch.inUse {
batch.shader = null
// using custom code for camera; this is obscure and tricky
camera.position.set(WorldCamera.gdxCamX, WorldCamera.gdxCamY, 0f) // make camara work
camera.update()
@@ -449,17 +459,16 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
// mix lighpmap canvas to this canvas
if (!KeyToggler.isOn(Input.Keys.F6)) { // F6 do disable lightmap draw
if (!KeyToggler.isOn(Input.Keys.F6)) { // F6 to disable lightmap draw
setCameraPosition(0f, 0f)
val lightTex = lightmapFrameBuffer.colorBufferTexture // TODO zoom!
if (KeyToggler.isOn(Input.Keys.F7)) blendNormal()
else blendMul()
batch.draw(lightTex, 0f, 0f, Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat())
batch.draw(lightTex, 0f, 0f, lightTex.width * lightmapDownsample, lightTex.height * lightmapDownsample)
}
// 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
@@ -486,6 +495,8 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
// draw to main screen //
/////////////////////////
batch.inUse {
batch.shader = null
setCameraPosition(0f, 0f)
batch.color = Color.WHITE
blendNormal()
@@ -499,10 +510,12 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
batch.color = Color.WHITE
val worldTex = worldDrawFrameBuffer.colorBufferTexture // TODO zoom!
batch.draw(worldTex, 0f, 0f, Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat())
batch.draw(worldTex, 0f, 0f, worldTex.width.toFloat(), worldTex.height.toFloat())
batch.color = Color.RED
batch.fillRect(0f, 0f, 16f, 16f)
////////////////////////
// debug informations //
@@ -1127,7 +1140,9 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
override fun resize(width: Int, height: Int) {
worldDrawFrameBuffer.dispose()
worldDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width.div(ZOOM_MIN).ceilInt(), Gdx.graphics.height.div(ZOOM_MIN).ceilInt(), false)
worldDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, width, height, false)
lightmapFrameBuffer.dispose()
lightmapFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, width.div(lightmapDownsample).ceilInt(), height.div(lightmapDownsample).ceilInt(), false)
// Set up viewport when window is resized
initViewPort(width, height)

View File

@@ -294,6 +294,7 @@ object TerrarumGDX : ApplicationAdapter() {
fontSmallNumbers = TinyAlphNum
ShaderProgram.pedantic = false
shaderBlur = ShaderProgram(Gdx.files.internal("assets/blur.vert"), Gdx.files.internal("assets/blur.frag"))

View File

@@ -18,11 +18,11 @@ internal object Zoom : ConsoleCommand {
return
}
if (zoom < TerrarumGDX.ingame!!.ZOOM_MIN) {
zoom = TerrarumGDX.ingame!!.ZOOM_MIN
if (zoom < TerrarumGDX.ingame!!.ZOOM_MINIMUM) {
zoom = TerrarumGDX.ingame!!.ZOOM_MINIMUM
}
else if (zoom > TerrarumGDX.ingame!!.ZOOM_MAX) {
zoom = TerrarumGDX.ingame!!.ZOOM_MAX
else if (zoom > TerrarumGDX.ingame!!.ZOOM_MAXIMUM) {
zoom = TerrarumGDX.ingame!!.ZOOM_MAXIMUM
}
TerrarumGDX.ingame!!.screenZoom = zoom

View File

@@ -7,6 +7,7 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import net.torvald.terrarum.gameactors.Luminous
import net.torvald.terrarum.blockproperties.BlockCodex
import com.jme3.math.FastMath
import net.torvald.terrarum.StateInGameGDX
import net.torvald.terrarum.TerrarumGDX
import net.torvald.terrarum.gameactors.ActorWithPhysics
import net.torvald.terrarum.gameworld.GameWorld
@@ -32,9 +33,9 @@ object LightmapRenderer {
// TODO resize(int, int) -aware
val LIGHTMAP_WIDTH = TerrarumGDX.ingame!!.ZOOM_MIN.inv().times(Gdx.graphics.width)
val LIGHTMAP_WIDTH = TerrarumGDX.ingame!!.ZOOM_MINIMUM.inv().times(Gdx.graphics.width)
.div(FeaturesDrawer.TILE_SIZE).ceil() + overscan_open * 2 + 3
val LIGHTMAP_HEIGHT = TerrarumGDX.ingame!!.ZOOM_MIN.inv().times(Gdx.graphics.height)
val LIGHTMAP_HEIGHT = TerrarumGDX.ingame!!.ZOOM_MINIMUM.inv().times(Gdx.graphics.height)
.div(FeaturesDrawer.TILE_SIZE).ceil() + overscan_open * 2 + 3
/**
@@ -50,6 +51,7 @@ object LightmapRenderer {
private val OFFSET_B = 0
private const val TILE_SIZE = FeaturesDrawer.TILE_SIZE
private val DRAW_TILE_SIZE: Float = FeaturesDrawer.TILE_SIZE / StateInGameGDX.lightmapDownsample
// color model related constants
const val MUL = 1024 // modify this to 1024 to implement 30-bit RGB
@@ -418,10 +420,10 @@ object LightmapRenderer {
batch.color = (getLightForOpaque(x, y) ?: 0).normaliseToColourHDR()
batch.fillRect(
(x.toFloat() * TILE_SIZE).round().toFloat(),
(y.toFloat() * TILE_SIZE).round().toFloat(),
(TILE_SIZE.toFloat().ceil() * sameLevelCounter).toFloat(),
TILE_SIZE.toFloat().ceil().toFloat()
(x * DRAW_TILE_SIZE).round().toFloat(),
(y * DRAW_TILE_SIZE).round().toFloat(),
(DRAW_TILE_SIZE.ceil() * sameLevelCounter).toFloat(),
DRAW_TILE_SIZE.ceil().toFloat()
)
x += sameLevelCounter - 1