mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-13 15:16:07 +09:00
killed old zoom so that framebuffer would render without hack
This commit is contained in:
@@ -1,19 +1,73 @@
|
|||||||
precision highp float;
|
#ifdef GL_ES
|
||||||
|
#define LOWP lowp
|
||||||
|
precision mediump float;
|
||||||
|
#else
|
||||||
|
#define LOWP
|
||||||
|
#endif
|
||||||
|
|
||||||
uniform vec3 iResolution;
|
varying vec4 v_color;
|
||||||
uniform sampler2D iChannel0;
|
varying vec2 v_texCoords;
|
||||||
uniform bool flip;
|
uniform sampler2D u_texture;
|
||||||
uniform vec2 direction;
|
|
||||||
|
|
||||||
//uniform mat4 u_projTrans;
|
varying vec4 vertexWorldPos;
|
||||||
|
uniform vec4 backColor;
|
||||||
#pragma glslify: blur = require('13')
|
|
||||||
|
|
||||||
|
uniform float width;
|
||||||
|
uniform float height;
|
||||||
void main() {
|
void main() {
|
||||||
vec2 uv = vec2(gl_FragCoord.xy / iResolution.xy);
|
vec2 tex;
|
||||||
if (flip) {
|
vec4 color2=vec4(0.0,0.0,0.0,0);
|
||||||
uv.y = 1.0 - uv.y;
|
|
||||||
}
|
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);
|
|
||||||
}
|
}
|
||||||
@@ -69,11 +69,15 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
|||||||
get() = playableActorDelegate?.actor
|
get() = playableActorDelegate?.actor
|
||||||
|
|
||||||
var screenZoom = 1.0f
|
var screenZoom = 1.0f
|
||||||
val ZOOM_MAX = 4.0f
|
val ZOOM_MAXIMUM = 4.0f
|
||||||
val ZOOM_MIN = 0.5f
|
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)
|
companion object {
|
||||||
var lightmapFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width.div(ZOOM_MIN).ceilInt(), Gdx.graphics.height.div(ZOOM_MIN).ceilInt(), false)
|
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
|
// 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
|
||||||
@@ -389,7 +393,7 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
|||||||
// 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
|
// 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() //
|
LightmapRenderer.fireRecalculateEvent() //
|
||||||
} //
|
} //
|
||||||
// end of post-update //
|
// end of post-update //
|
||||||
@@ -398,8 +402,12 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
|||||||
// now the actual drawing part //
|
// now the actual drawing part //
|
||||||
lightmapFrameBuffer.inAction {
|
lightmapFrameBuffer.inAction {
|
||||||
// TODO gaussian blur p=8
|
// 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.inUse {
|
||||||
|
batch.shader = null//TerrarumGDX.shaderBlur
|
||||||
|
|
||||||
|
|
||||||
// using custom code for camera; 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()
|
||||||
@@ -413,6 +421,8 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
|||||||
|
|
||||||
worldDrawFrameBuffer.inAction {
|
worldDrawFrameBuffer.inAction {
|
||||||
batch.inUse {
|
batch.inUse {
|
||||||
|
batch.shader = null
|
||||||
|
|
||||||
// using custom code for camera; 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()
|
||||||
@@ -449,17 +459,16 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
|||||||
|
|
||||||
|
|
||||||
// mix lighpmap canvas to this canvas
|
// 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)
|
setCameraPosition(0f, 0f)
|
||||||
|
|
||||||
val lightTex = lightmapFrameBuffer.colorBufferTexture // TODO zoom!
|
val lightTex = lightmapFrameBuffer.colorBufferTexture // TODO zoom!
|
||||||
if (KeyToggler.isOn(Input.Keys.F7)) blendNormal()
|
if (KeyToggler.isOn(Input.Keys.F7)) blendNormal()
|
||||||
else blendMul()
|
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
|
// move camera back to its former position
|
||||||
// using custom code for camera; 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
|
||||||
@@ -486,6 +495,8 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
|||||||
// draw to main screen //
|
// draw to main screen //
|
||||||
/////////////////////////
|
/////////////////////////
|
||||||
batch.inUse {
|
batch.inUse {
|
||||||
|
batch.shader = null
|
||||||
|
|
||||||
setCameraPosition(0f, 0f)
|
setCameraPosition(0f, 0f)
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
blendNormal()
|
blendNormal()
|
||||||
@@ -499,10 +510,12 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
|||||||
|
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
val worldTex = worldDrawFrameBuffer.colorBufferTexture // TODO zoom!
|
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 //
|
// debug informations //
|
||||||
@@ -1127,7 +1140,9 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
|||||||
|
|
||||||
override fun resize(width: Int, height: Int) {
|
override fun resize(width: Int, height: Int) {
|
||||||
worldDrawFrameBuffer.dispose()
|
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
|
// Set up viewport when window is resized
|
||||||
initViewPort(width, height)
|
initViewPort(width, height)
|
||||||
|
|||||||
@@ -294,6 +294,7 @@ object TerrarumGDX : ApplicationAdapter() {
|
|||||||
fontSmallNumbers = TinyAlphNum
|
fontSmallNumbers = TinyAlphNum
|
||||||
|
|
||||||
|
|
||||||
|
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"))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ internal object Zoom : ConsoleCommand {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zoom < TerrarumGDX.ingame!!.ZOOM_MIN) {
|
if (zoom < TerrarumGDX.ingame!!.ZOOM_MINIMUM) {
|
||||||
zoom = TerrarumGDX.ingame!!.ZOOM_MIN
|
zoom = TerrarumGDX.ingame!!.ZOOM_MINIMUM
|
||||||
}
|
}
|
||||||
else if (zoom > TerrarumGDX.ingame!!.ZOOM_MAX) {
|
else if (zoom > TerrarumGDX.ingame!!.ZOOM_MAXIMUM) {
|
||||||
zoom = TerrarumGDX.ingame!!.ZOOM_MAX
|
zoom = TerrarumGDX.ingame!!.ZOOM_MAXIMUM
|
||||||
}
|
}
|
||||||
|
|
||||||
TerrarumGDX.ingame!!.screenZoom = zoom
|
TerrarumGDX.ingame!!.screenZoom = zoom
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
|||||||
import net.torvald.terrarum.gameactors.Luminous
|
import net.torvald.terrarum.gameactors.Luminous
|
||||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
|
import net.torvald.terrarum.StateInGameGDX
|
||||||
import net.torvald.terrarum.TerrarumGDX
|
import net.torvald.terrarum.TerrarumGDX
|
||||||
import net.torvald.terrarum.gameactors.ActorWithPhysics
|
import net.torvald.terrarum.gameactors.ActorWithPhysics
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
@@ -32,9 +33,9 @@ object LightmapRenderer {
|
|||||||
|
|
||||||
// TODO resize(int, int) -aware
|
// 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
|
.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
|
.div(FeaturesDrawer.TILE_SIZE).ceil() + overscan_open * 2 + 3
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,6 +51,7 @@ object LightmapRenderer {
|
|||||||
private val OFFSET_B = 0
|
private val OFFSET_B = 0
|
||||||
|
|
||||||
private const val TILE_SIZE = FeaturesDrawer.TILE_SIZE
|
private const val TILE_SIZE = FeaturesDrawer.TILE_SIZE
|
||||||
|
private val DRAW_TILE_SIZE: Float = FeaturesDrawer.TILE_SIZE / StateInGameGDX.lightmapDownsample
|
||||||
|
|
||||||
// color model related constants
|
// color model related constants
|
||||||
const val MUL = 1024 // modify this to 1024 to implement 30-bit RGB
|
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.color = (getLightForOpaque(x, y) ?: 0).normaliseToColourHDR()
|
||||||
batch.fillRect(
|
batch.fillRect(
|
||||||
(x.toFloat() * TILE_SIZE).round().toFloat(),
|
(x * DRAW_TILE_SIZE).round().toFloat(),
|
||||||
(y.toFloat() * TILE_SIZE).round().toFloat(),
|
(y * DRAW_TILE_SIZE).round().toFloat(),
|
||||||
(TILE_SIZE.toFloat().ceil() * sameLevelCounter).toFloat(),
|
(DRAW_TILE_SIZE.ceil() * sameLevelCounter).toFloat(),
|
||||||
TILE_SIZE.toFloat().ceil().toFloat()
|
DRAW_TILE_SIZE.ceil().toFloat()
|
||||||
)
|
)
|
||||||
|
|
||||||
x += sameLevelCounter - 1
|
x += sameLevelCounter - 1
|
||||||
|
|||||||
Reference in New Issue
Block a user