mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
lightmap drawing won't use spritebatch
This commit is contained in:
@@ -252,7 +252,7 @@ public class AppLoader implements ApplicationListener {
|
||||
|
||||
private static ShaderProgram shaderBayerSkyboxFill;
|
||||
public static ShaderProgram shaderHicolour;
|
||||
public static ShaderProgram shaderPassthru;
|
||||
public static ShaderProgram shaderPassthruRGB;
|
||||
public static ShaderProgram shaderColLUT;
|
||||
|
||||
public static Mesh fullscreenQuad;
|
||||
@@ -308,8 +308,8 @@ public class AppLoader implements ApplicationListener {
|
||||
// set GL graphics constants
|
||||
shaderBayerSkyboxFill = loadShader("assets/4096.vert", "assets/4096_bayer_skyboxfill.frag");
|
||||
shaderHicolour = loadShader("assets/4096.vert", "assets/hicolour.frag");
|
||||
shaderPassthru = loadShader("assets/4096.vert", "assets/passthru.frag");
|
||||
shaderColLUT = loadShader("assets/4096.vert", "assets/passthru.frag");
|
||||
shaderPassthruRGB = loadShader("assets/4096.vert", "assets/passthrurgb.frag");
|
||||
shaderColLUT = loadShader("assets/4096.vert", "assets/passthrurgb.frag");
|
||||
|
||||
fullscreenQuad = new Mesh(
|
||||
true, 4, 6,
|
||||
@@ -513,7 +513,7 @@ public class AppLoader implements ApplicationListener {
|
||||
|
||||
shaderBayerSkyboxFill.dispose();
|
||||
shaderHicolour.dispose();
|
||||
shaderPassthru.dispose();
|
||||
shaderPassthruRGB.dispose();
|
||||
shaderColLUT.dispose();
|
||||
|
||||
assetManager.dispose();
|
||||
|
||||
@@ -93,7 +93,7 @@ object PostProcessor {
|
||||
if (AppLoader.getConfigBoolean("fxdither"))
|
||||
AppLoader.shaderHicolour
|
||||
else
|
||||
AppLoader.shaderPassthru
|
||||
AppLoader.shaderPassthruRGB
|
||||
|
||||
fbo.colorBufferTexture.bind(0)
|
||||
|
||||
|
||||
@@ -295,7 +295,7 @@ object Terrarum : Screen {
|
||||
shaderSkyboxFill.end()
|
||||
}
|
||||
else {
|
||||
shaderBayer = AppLoader.loadShader("assets/4096.vert", "assets/passthru.frag")
|
||||
shaderBayer = AppLoader.loadShader("assets/4096.vert", "assets/passthrurgb.frag")
|
||||
shaderSkyboxFill = AppLoader.loadShader("assets/4096.vert", "assets/skyboxfill.frag")
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@ object IngameRenderer {
|
||||
lateinit var batch: SpriteBatch
|
||||
private lateinit var camera: OrthographicCamera
|
||||
|
||||
private lateinit var blurWriteQuad: Mesh
|
||||
|
||||
private lateinit var lightmapFboA: FrameBuffer
|
||||
private lateinit var lightmapFboB: FrameBuffer
|
||||
private lateinit var fboRGB: FrameBuffer
|
||||
@@ -45,6 +47,7 @@ object IngameRenderer {
|
||||
private val shaderBlendGlow = Terrarum.shaderBlendGlow
|
||||
private val shaderRGBOnly = Terrarum.shaderRGBOnly
|
||||
private val shaderAtoGrey = Terrarum.shaderAtoGrey
|
||||
private val shaderPassthru = SpriteBatch.createDefaultShader()
|
||||
|
||||
private val width = Terrarum.WIDTH
|
||||
private val height = Terrarum.HEIGHT
|
||||
@@ -490,44 +493,42 @@ object IngameRenderer {
|
||||
|
||||
// initialise readBuffer with untreated lightmap
|
||||
blurReadBuffer.inAction(camera, batch) {
|
||||
batch.inUse {
|
||||
blendDisable(batch)
|
||||
batch.color = Color.WHITE
|
||||
LightmapRenderer.draw(batch)
|
||||
}
|
||||
val texture = LightmapRenderer.draw()
|
||||
texture.bind(0)
|
||||
|
||||
shaderPassthru.begin()
|
||||
shaderPassthru.setUniformMatrix("u_projTrans", camera.combined)
|
||||
shaderPassthru.setUniformi("u_texture", 0)
|
||||
blurWriteQuad.render(shaderPassthru, GL20.GL_TRIANGLES)
|
||||
shaderPassthru.end()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// do blurring
|
||||
for (i in 0 until blurIterations) {
|
||||
blurWriteBuffer.inAction(camera, batch) {
|
||||
|
||||
batch.inUse {
|
||||
val texture = blurReadBuffer.colorBufferTexture
|
||||
val texture = blurReadBuffer.colorBufferTexture
|
||||
texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
|
||||
texture.bind(0)
|
||||
|
||||
texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
|
||||
shaderBlur.begin()
|
||||
shaderBlur.setUniformMatrix("u_projTrans", camera.combined)
|
||||
shaderBlur.setUniformi("u_texture", 0)
|
||||
shaderBlur.setUniformf("iResolution",
|
||||
blurWriteBuffer.width.toFloat(), blurWriteBuffer.height.toFloat())
|
||||
shaderBlur.setUniformf("flip", 1f)
|
||||
if (i % 2 == 0)
|
||||
shaderBlur.setUniformf("direction", blurRadius, 0f)
|
||||
else
|
||||
shaderBlur.setUniformf("direction", 0f, blurRadius)
|
||||
blurWriteQuad.render(shaderBlur, GL20.GL_TRIANGLES)
|
||||
shaderBlur.end()
|
||||
|
||||
|
||||
batch.shader = shaderBlur
|
||||
batch.shader.setUniformf("iResolution",
|
||||
blurWriteBuffer.width.toFloat(), blurWriteBuffer.height.toFloat())
|
||||
batch.shader.setUniformf("flip", 1f)
|
||||
if (i % 2 == 0)
|
||||
batch.shader.setUniformf("direction", blurRadius, 0f)
|
||||
else
|
||||
batch.shader.setUniformf("direction", 0f, blurRadius)
|
||||
|
||||
|
||||
batch.color = Color.WHITE
|
||||
batch.draw(texture, 0f, 0f)
|
||||
|
||||
|
||||
// swap
|
||||
val t = blurWriteBuffer
|
||||
blurWriteBuffer = blurReadBuffer
|
||||
blurReadBuffer = t
|
||||
}
|
||||
// swap
|
||||
val t = blurWriteBuffer
|
||||
blurWriteBuffer = blurReadBuffer
|
||||
blurReadBuffer = t
|
||||
}
|
||||
}
|
||||
|
||||
@@ -540,6 +541,13 @@ object IngameRenderer {
|
||||
|
||||
fun resize(width: Int, height: Int) {
|
||||
if (!init) {
|
||||
blurWriteQuad = Mesh(
|
||||
true, 4, 6,
|
||||
VertexAttribute.Position(),
|
||||
VertexAttribute.ColorUnpacked(),
|
||||
VertexAttribute.TexCoords(0)
|
||||
)
|
||||
|
||||
init = true
|
||||
}
|
||||
else {
|
||||
@@ -572,7 +580,13 @@ object IngameRenderer {
|
||||
LightmapRenderer.resize(width, height)
|
||||
|
||||
|
||||
//LightmapRenderer.fireRecalculateEvent()
|
||||
blurWriteQuad.setVertices(floatArrayOf(
|
||||
0f,0f,0f, 1f,1f,1f,1f, 0f,1f,
|
||||
lightmapFboA.width.toFloat(),0f,0f, 1f,1f,1f,1f, 1f,1f,
|
||||
lightmapFboA.width.toFloat(),lightmapFboA.height.toFloat(),0f, 1f,1f,1f,1f, 1f,0f,
|
||||
0f,lightmapFboA.height.toFloat(),0f, 1f,1f,1f,1f, 0f,0f))
|
||||
blurWriteQuad.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))
|
||||
|
||||
}
|
||||
|
||||
private val TILE_SIZEF = FeaturesDrawer.TILE_SIZE.toFloat()
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
package net.torvald.terrarum.worlddrawer
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.GL20
|
||||
import com.badlogic.gdx.graphics.Pixmap
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.*
|
||||
@@ -559,7 +556,7 @@ object LightmapRenderer {
|
||||
|
||||
private var _lightBufferAsTex: Texture = Texture(1, 1, Pixmap.Format.RGBA8888)
|
||||
|
||||
internal fun draw(batch: SpriteBatch) {
|
||||
internal fun draw(): Texture {
|
||||
|
||||
// when shader is not used: 0.5 ms on 6700K
|
||||
AppLoader.measureDebugTime("Renderer.LightToScreen") {
|
||||
@@ -600,12 +597,14 @@ object LightmapRenderer {
|
||||
_lightBufferAsTex = Texture(lightBuffer)
|
||||
_lightBufferAsTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
||||
|
||||
|
||||
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it
|
||||
/*Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it
|
||||
// we might not need shader here...
|
||||
//batch.draw(lightBufferAsTex, 0f, 0f, lightBufferAsTex.width.toFloat(), lightBufferAsTex.height.toFloat())
|
||||
batch.draw(_lightBufferAsTex, 0f, 0f, _lightBufferAsTex.width * DRAW_TILE_SIZE, _lightBufferAsTex.height * DRAW_TILE_SIZE)
|
||||
*/
|
||||
}
|
||||
|
||||
return _lightBufferAsTex
|
||||
}
|
||||
|
||||
fun dispose() {
|
||||
|
||||
Reference in New Issue
Block a user