mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-17 00:56:07 +09:00
using weaker and faster fullscreen blurring; this is a style choice
This commit is contained in:
31
assets/shaders/boxdown.frag
Normal file
31
assets/shaders/boxdown.frag
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#version 120
|
||||||
|
#ifdef GL_ES
|
||||||
|
precision mediump float;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
varying vec4 v_color;
|
||||||
|
varying vec2 v_texCoords;
|
||||||
|
uniform sampler2D u_texture;
|
||||||
|
|
||||||
|
// recommended value: n / vec2(fbo_width, fbo_height) where n is something like {0.5, 1, 2, 4, ... }
|
||||||
|
// that, or simply 0.5, depending on how your uv coord works
|
||||||
|
uniform vec2 halfpixel = vec2(0.0, 0.0);
|
||||||
|
|
||||||
|
vec2 doublex = vec2(2.0, 0.0);
|
||||||
|
vec2 doubley = vec2(0.0, 2.0);
|
||||||
|
vec2 twister = vec2(1.0, -1.0);
|
||||||
|
vec2 boolean = vec2(1.0, 0.0);
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec4 sum = texture2D(u_texture, v_texCoords) +
|
||||||
|
texture2D(u_texture, v_texCoords + halfpixel) +
|
||||||
|
texture2D(u_texture, v_texCoords - halfpixel) +
|
||||||
|
texture2D(u_texture, v_texCoords + halfpixel * twister) +
|
||||||
|
texture2D(u_texture, v_texCoords - halfpixel * twister) +
|
||||||
|
texture2D(u_texture, v_texCoords + halfpixel * boolean.xy) +
|
||||||
|
texture2D(u_texture, v_texCoords - halfpixel * boolean.xy) +
|
||||||
|
texture2D(u_texture, v_texCoords + halfpixel * boolean.yx) +
|
||||||
|
texture2D(u_texture, v_texCoords - halfpixel * boolean.yx) ;
|
||||||
|
|
||||||
|
gl_FragColor = sum / 9.0;
|
||||||
|
}
|
||||||
31
assets/shaders/boxup.frag
Normal file
31
assets/shaders/boxup.frag
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#version 120
|
||||||
|
#ifdef GL_ES
|
||||||
|
precision mediump float;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
varying vec4 v_color;
|
||||||
|
varying vec2 v_texCoords;
|
||||||
|
uniform sampler2D u_texture;
|
||||||
|
|
||||||
|
// recommended value: n / vec2(fbo_width, fbo_height) where n is something like {0.5, 1, 2, 4, ... }
|
||||||
|
// that, or simply 0.5, depending on how your uv coord works
|
||||||
|
uniform vec2 halfpixel = vec2(0.0, 0.0);
|
||||||
|
|
||||||
|
vec2 doublex = vec2(2.0, 0.0);
|
||||||
|
vec2 doubley = vec2(0.0, 2.0);
|
||||||
|
vec2 twister = vec2(1.0, -1.0);
|
||||||
|
vec2 boolean = vec2(1.0, 0.0);
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec4 sum = texture2D(u_texture, v_texCoords) +
|
||||||
|
texture2D(u_texture, v_texCoords + halfpixel) +
|
||||||
|
texture2D(u_texture, v_texCoords - halfpixel) +
|
||||||
|
texture2D(u_texture, v_texCoords + halfpixel * twister) +
|
||||||
|
texture2D(u_texture, v_texCoords - halfpixel * twister) +
|
||||||
|
texture2D(u_texture, v_texCoords + halfpixel * boolean.xy) +
|
||||||
|
texture2D(u_texture, v_texCoords - halfpixel * boolean.xy) +
|
||||||
|
texture2D(u_texture, v_texCoords + halfpixel * boolean.yx) +
|
||||||
|
texture2D(u_texture, v_texCoords - halfpixel * boolean.yx) ;
|
||||||
|
|
||||||
|
gl_FragColor = sum / 9.0;
|
||||||
|
}
|
||||||
@@ -8,10 +8,10 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion
|
|||||||
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.ShaderProgram
|
||||||
import com.badlogic.gdx.utils.Disposable
|
import com.badlogic.gdx.utils.Disposable
|
||||||
|
import com.badlogic.gdx.utils.GdxRuntimeException
|
||||||
import net.torvald.random.HQRNG
|
import net.torvald.random.HQRNG
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.App.measureDebugTime
|
import net.torvald.terrarum.App.measureDebugTime
|
||||||
import net.torvald.terrarum.App.printdbg
|
|
||||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZEF
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZEF
|
||||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
@@ -677,12 +677,22 @@ object IngameRenderer : Disposable {
|
|||||||
|
|
||||||
private const val KAWASE_POWER = 0.667f
|
private const val KAWASE_POWER = 0.667f
|
||||||
|
|
||||||
|
private var blurtex0 = Texture(16, 16, Pixmap.Format.RGBA8888)
|
||||||
|
private var blurtex1 = Texture(16, 16, Pixmap.Format.RGBA8888)
|
||||||
|
private var blurtex2 = Texture(16, 16, Pixmap.Format.RGBA8888)
|
||||||
|
private var blurtex3 = Texture(16, 16, Pixmap.Format.RGBA8888)
|
||||||
|
private var blurtex4 = Texture(16, 16, Pixmap.Format.RGBA8888)
|
||||||
|
|
||||||
|
|
||||||
fun processKawaseBlur(outFbo: FrameBuffer) {
|
fun processKawaseBlur(outFbo: FrameBuffer) {
|
||||||
|
|
||||||
|
blurtex0.dispose()
|
||||||
|
|
||||||
// initialise readBuffer with untreated lightmap
|
// initialise readBuffer with untreated lightmap
|
||||||
outFbo.inAction(camera, batch) {
|
outFbo.inAction(camera, batch) {
|
||||||
val texture = LightmapRenderer.draw()
|
blurtex0 = LightmapRenderer.draw()
|
||||||
texture.bind(0)
|
blurtex0.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
|
||||||
|
blurtex0.bind(0)
|
||||||
shaderPassthru.bind()
|
shaderPassthru.bind()
|
||||||
shaderPassthru.setUniformMatrix("u_projTrans", camera.combined)
|
shaderPassthru.setUniformMatrix("u_projTrans", camera.combined)
|
||||||
shaderPassthru.setUniformi("u_texture", 0)
|
shaderPassthru.setUniformi("u_texture", 0)
|
||||||
@@ -690,8 +700,9 @@ object IngameRenderer : Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fboBlurHalf.inAction(camera, batch) {
|
fboBlurHalf.inAction(camera, batch) {
|
||||||
val texture = outFbo.colorBufferTexture
|
blurtex1 = outFbo.colorBufferTexture
|
||||||
texture.bind(0)
|
blurtex1.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
|
||||||
|
blurtex1.bind(0)
|
||||||
shaderKawaseDown.bind()
|
shaderKawaseDown.bind()
|
||||||
shaderKawaseDown.setUniformMatrix("u_projTrans", camera.combined)
|
shaderKawaseDown.setUniformMatrix("u_projTrans", camera.combined)
|
||||||
shaderKawaseDown.setUniformi("u_texture", 0)
|
shaderKawaseDown.setUniformi("u_texture", 0)
|
||||||
@@ -700,8 +711,9 @@ object IngameRenderer : Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fboBlurQuarter.inAction(camera, batch) {
|
fboBlurQuarter.inAction(camera, batch) {
|
||||||
val texture = fboBlurHalf.colorBufferTexture
|
blurtex2 = fboBlurHalf.colorBufferTexture
|
||||||
texture.bind(0)
|
blurtex2.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
|
||||||
|
blurtex2.bind(0)
|
||||||
shaderKawaseDown.bind()
|
shaderKawaseDown.bind()
|
||||||
shaderKawaseDown.setUniformMatrix("u_projTrans", camera.combined)
|
shaderKawaseDown.setUniformMatrix("u_projTrans", camera.combined)
|
||||||
shaderKawaseDown.setUniformi("u_texture", 0)
|
shaderKawaseDown.setUniformi("u_texture", 0)
|
||||||
@@ -710,8 +722,9 @@ object IngameRenderer : Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fboBlurHalf.inAction(camera, batch) {
|
fboBlurHalf.inAction(camera, batch) {
|
||||||
val texture = fboBlurQuarter.colorBufferTexture
|
blurtex3 = fboBlurQuarter.colorBufferTexture
|
||||||
texture.bind(0)
|
blurtex3.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
|
||||||
|
blurtex3.bind(0)
|
||||||
shaderKawaseUp.bind()
|
shaderKawaseUp.bind()
|
||||||
shaderKawaseUp.setUniformMatrix("u_projTrans", camera.combined)
|
shaderKawaseUp.setUniformMatrix("u_projTrans", camera.combined)
|
||||||
shaderKawaseUp.setUniformi("u_texture", 0)
|
shaderKawaseUp.setUniformi("u_texture", 0)
|
||||||
@@ -721,8 +734,8 @@ object IngameRenderer : Disposable {
|
|||||||
|
|
||||||
// TODO apply dithering on this specific draw call
|
// TODO apply dithering on this specific draw call
|
||||||
outFbo.inAction(camera, batch) {
|
outFbo.inAction(camera, batch) {
|
||||||
val texture = fboBlurHalf.colorBufferTexture
|
blurtex4 = fboBlurHalf.colorBufferTexture
|
||||||
texture.bind(0)
|
blurtex4.bind(0)
|
||||||
shaderKawaseUp.bind()
|
shaderKawaseUp.bind()
|
||||||
shaderKawaseUp.setUniformMatrix("u_projTrans", camera.combined)
|
shaderKawaseUp.setUniformMatrix("u_projTrans", camera.combined)
|
||||||
shaderKawaseUp.setUniformi("u_texture", 0)
|
shaderKawaseUp.setUniformi("u_texture", 0)
|
||||||
@@ -732,76 +745,6 @@ object IngameRenderer : Disposable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun processNoBlur() {
|
|
||||||
lightmapFboB.inAction(camera, batch) {
|
|
||||||
val texture = LightmapRenderer.draw()
|
|
||||||
texture.bind(0)
|
|
||||||
|
|
||||||
shaderPassthru.bind()
|
|
||||||
shaderPassthru.setUniformMatrix("u_projTrans", camera.combined)
|
|
||||||
shaderPassthru.setUniformi("u_texture", 0)
|
|
||||||
blurWriteQuad.render(shaderPassthru, GL20.GL_TRIANGLES)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun processBlur(lightmapFboA: FrameBuffer, lightmapFboB: FrameBuffer) {
|
|
||||||
var blurWriteBuffer = lightmapFboA
|
|
||||||
var blurReadBuffer = lightmapFboB
|
|
||||||
|
|
||||||
|
|
||||||
// buffers must be cleared beforehand
|
|
||||||
|
|
||||||
|
|
||||||
// initialise readBuffer with untreated lightmap
|
|
||||||
blurReadBuffer.inAction(camera, batch) {
|
|
||||||
val texture = LightmapRenderer.draw()
|
|
||||||
texture.bind(0)
|
|
||||||
|
|
||||||
shaderPassthru.bind()
|
|
||||||
shaderPassthru.setUniformMatrix("u_projTrans", camera.combined)
|
|
||||||
shaderPassthru.setUniformi("u_texture", 0)
|
|
||||||
blurWriteQuad.render(shaderPassthru, GL20.GL_TRIANGLES)
|
|
||||||
}
|
|
||||||
|
|
||||||
// do blurring
|
|
||||||
for (i in 0 until 4) {
|
|
||||||
val blurRadius = (4f / lightmapDownsample) * (1 shl i.ushr(1))
|
|
||||||
|
|
||||||
blurWriteBuffer.inAction(camera, batch) {
|
|
||||||
|
|
||||||
|
|
||||||
blurTex.texture = blurReadBuffer.colorBufferTexture
|
|
||||||
blurTex.texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
|
|
||||||
blurTex.texture.bind(0)
|
|
||||||
App.getCurrentDitherTex().bind(1) // order is important!
|
|
||||||
|
|
||||||
shaderBlur.bind()
|
|
||||||
shaderBlur.setUniformMatrix("u_projTrans", camera.combined)
|
|
||||||
shaderBlur.setUniformi("rnd", rng.nextInt(8192), rng.nextInt(8192))
|
|
||||||
shaderBlur.setUniformi("u_pattern", 1)
|
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
// swap
|
|
||||||
val t = blurWriteBuffer
|
|
||||||
blurWriteBuffer = blurReadBuffer
|
|
||||||
blurReadBuffer = t
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
blendNormal(batch)
|
|
||||||
}
|
|
||||||
|
|
||||||
private var init = false
|
private var init = false
|
||||||
|
|
||||||
fun resize(width: Int, height: Int) {
|
fun resize(width: Int, height: Int) {
|
||||||
@@ -914,6 +857,12 @@ object IngameRenderer : Disposable {
|
|||||||
lightmapFboA.dispose()
|
lightmapFboA.dispose()
|
||||||
lightmapFboB.dispose()
|
lightmapFboB.dispose()
|
||||||
|
|
||||||
|
try { blurtex0.dispose() } catch (e: GdxRuntimeException) {}
|
||||||
|
// try { blurtex1.dispose() } catch (e: GdxRuntimeException) {}
|
||||||
|
// try { blurtex2.dispose() } catch (e: GdxRuntimeException) {}
|
||||||
|
// try { blurtex3.dispose() } catch (e: GdxRuntimeException) {}
|
||||||
|
// try { blurtex4.dispose() } catch (e: GdxRuntimeException) {}
|
||||||
|
|
||||||
fboBlurHalf.dispose()
|
fboBlurHalf.dispose()
|
||||||
fboBlurQuarter.dispose()
|
fboBlurQuarter.dispose()
|
||||||
|
|
||||||
|
|||||||
@@ -6,14 +6,10 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
|||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||||
import com.badlogic.gdx.utils.Disposable
|
import com.badlogic.gdx.utils.Disposable
|
||||||
import com.badlogic.gdx.utils.GdxRuntimeException
|
|
||||||
import com.badlogic.gdx.utils.ScreenUtils
|
|
||||||
import net.torvald.random.HQRNG
|
import net.torvald.random.HQRNG
|
||||||
import net.torvald.terrarum.App
|
import net.torvald.terrarum.App
|
||||||
import net.torvald.terrarum.App.printdbg
|
|
||||||
import net.torvald.terrarum.CommonResourcePool
|
import net.torvald.terrarum.CommonResourcePool
|
||||||
import net.torvald.terrarum.inAction
|
import net.torvald.terrarum.inAction
|
||||||
import net.torvald.terrarum.modulebasegame.IngameRenderer
|
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
import org.lwjgl.opengl.GL20
|
import org.lwjgl.opengl.GL20
|
||||||
|
|
||||||
@@ -35,8 +31,8 @@ object Toolkit : Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private val shaderKawaseDown = App.loadShaderFromFile("assets/shaders/4096.vert", "assets/shaders/kawasedown.frag")
|
private val shaderKawaseDown = App.loadShaderFromFile("assets/shaders/4096.vert", "assets/shaders/boxdown.frag")
|
||||||
private val shaderKawaseUp = App.loadShaderFromFile("assets/shaders/4096.vert", "assets/shaders/kawaseup.frag")
|
private val shaderKawaseUp = App.loadShaderFromFile("assets/shaders/4096.vert", "assets/shaders/boxup.frag")
|
||||||
|
|
||||||
private lateinit var fboBlur: FrameBuffer
|
private lateinit var fboBlur: FrameBuffer
|
||||||
private lateinit var fboBlurHalf: FrameBuffer
|
private lateinit var fboBlurHalf: FrameBuffer
|
||||||
@@ -80,7 +76,10 @@ object Toolkit : Disposable {
|
|||||||
shaderKawaseUp.dispose()
|
shaderKawaseUp.dispose()
|
||||||
shaderKawaseDown.dispose()
|
shaderKawaseDown.dispose()
|
||||||
|
|
||||||
try { blurIntexture.dispose() } catch (e: GdxRuntimeException) {}
|
// try { blurtex0.dispose() } catch (e: GdxRuntimeException) {}
|
||||||
|
// try { blurtex1.dispose() } catch (e: GdxRuntimeException) {}
|
||||||
|
// try { blurtex2.dispose() } catch (e: GdxRuntimeException) {}
|
||||||
|
// try { blurtex3.dispose() } catch (e: GdxRuntimeException) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
val drawWidth: Int
|
val drawWidth: Int
|
||||||
@@ -152,17 +151,31 @@ object Toolkit : Disposable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var blurIntexture = Texture(16, 16, Pixmap.Format.RGBA8888)
|
// private var blurtex0 = Texture(16, 16, Pixmap.Format.RGBA8888)
|
||||||
|
private var blurtex1 = Texture(16, 16, Pixmap.Format.RGBA8888)
|
||||||
|
private var blurtex2 = Texture(16, 16, Pixmap.Format.RGBA8888)
|
||||||
|
private var blurtex3 = Texture(16, 16, Pixmap.Format.RGBA8888)
|
||||||
|
|
||||||
fun blurEntireScreen(batch: SpriteBatch, camera: OrthographicCamera, blurRadius0: Float, x: Int, y: Int, w: Int, h: Int) {
|
fun blurEntireScreen(batch: SpriteBatch, camera: OrthographicCamera, blurRadius0: Float, x: Int, y: Int, w: Int, h: Int) {
|
||||||
|
|
||||||
batch.end()
|
batch.end()
|
||||||
|
|
||||||
val blurRadius = blurRadius0 * 2f
|
val blurRadius = blurRadius0
|
||||||
blurIntexture = Texture(Pixmap.createFromFrameBuffer(x, y, w, h))
|
|
||||||
|
|
||||||
fboBlurHalf.inAction(camera, batch) {
|
// blurtex0.dispose()
|
||||||
blurIntexture.bind(0)
|
// blurtex1.dispose()
|
||||||
|
// blurtex2.dispose()
|
||||||
|
// blurtex3.dispose()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val pixmap = Pixmap.createFromFrameBuffer(x, y, w, h)
|
||||||
|
val texture: Texture = Texture(pixmap)
|
||||||
|
val t = TextureRegion(texture, 0, h, w, -h)
|
||||||
|
pixmap.dispose()
|
||||||
|
|
||||||
|
|
||||||
|
/*fboBlurHalf.inAction(camera, batch) {
|
||||||
|
t.texture.bind(0)
|
||||||
shaderKawaseDown.bind()
|
shaderKawaseDown.bind()
|
||||||
shaderKawaseDown.setUniformMatrix("u_projTrans", camera.combined)
|
shaderKawaseDown.setUniformMatrix("u_projTrans", camera.combined)
|
||||||
shaderKawaseDown.setUniformi("u_texture", 0)
|
shaderKawaseDown.setUniformi("u_texture", 0)
|
||||||
@@ -171,8 +184,8 @@ object Toolkit : Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fboBlurQuarter.inAction(camera, batch) {
|
fboBlurQuarter.inAction(camera, batch) {
|
||||||
val texture = fboBlurHalf.colorBufferTexture
|
blurtex1 = fboBlurHalf.colorBufferTexture
|
||||||
texture.bind(0)
|
blurtex1.bind(0)
|
||||||
shaderKawaseDown.bind()
|
shaderKawaseDown.bind()
|
||||||
shaderKawaseDown.setUniformMatrix("u_projTrans", camera.combined)
|
shaderKawaseDown.setUniformMatrix("u_projTrans", camera.combined)
|
||||||
shaderKawaseDown.setUniformi("u_texture", 0)
|
shaderKawaseDown.setUniformi("u_texture", 0)
|
||||||
@@ -181,8 +194,8 @@ object Toolkit : Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fboBlurHalf.inAction(camera, batch) {
|
fboBlurHalf.inAction(camera, batch) {
|
||||||
val texture = fboBlurQuarter.colorBufferTexture
|
blurtex2 = fboBlurQuarter.colorBufferTexture
|
||||||
texture.bind(0)
|
blurtex2.bind(0)
|
||||||
shaderKawaseUp.bind()
|
shaderKawaseUp.bind()
|
||||||
shaderKawaseUp.setUniformMatrix("u_projTrans", camera.combined)
|
shaderKawaseUp.setUniformMatrix("u_projTrans", camera.combined)
|
||||||
shaderKawaseUp.setUniformi("u_texture", 0)
|
shaderKawaseUp.setUniformi("u_texture", 0)
|
||||||
@@ -192,8 +205,30 @@ object Toolkit : Disposable {
|
|||||||
|
|
||||||
// TODO apply dithering on this specific draw call
|
// TODO apply dithering on this specific draw call
|
||||||
fboBlur.inAction(camera, batch) {
|
fboBlur.inAction(camera, batch) {
|
||||||
val texture = fboBlurHalf.colorBufferTexture
|
blurtex3 = fboBlurHalf.colorBufferTexture
|
||||||
texture.bind(0)
|
blurtex3.bind(0)
|
||||||
|
shaderKawaseUp.bind()
|
||||||
|
shaderKawaseUp.setUniformMatrix("u_projTrans", camera.combined)
|
||||||
|
shaderKawaseUp.setUniformi("u_texture", 0)
|
||||||
|
shaderKawaseUp.setUniformf("halfpixel", blurRadius / fboBlurHalf.width, blurRadius / fboBlurHalf.height)
|
||||||
|
blurWriteQuad.render(shaderKawaseUp, GL20.GL_TRIANGLES)
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
fboBlurHalf.inAction(camera, batch) {
|
||||||
|
t.texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
|
||||||
|
t.texture.bind(0)
|
||||||
|
shaderKawaseDown.bind()
|
||||||
|
shaderKawaseDown.setUniformMatrix("u_projTrans", camera.combined)
|
||||||
|
shaderKawaseDown.setUniformi("u_texture", 0)
|
||||||
|
shaderKawaseDown.setUniformf("halfpixel", blurRadius / fboBlurHalf.width, blurRadius / fboBlurHalf.height)
|
||||||
|
blurWriteQuad2.render(shaderKawaseDown, GL20.GL_TRIANGLES)
|
||||||
|
}
|
||||||
|
|
||||||
|
fboBlur.inAction(camera, batch) {
|
||||||
|
blurtex3 = fboBlurHalf.colorBufferTexture
|
||||||
|
blurtex3.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
|
||||||
|
blurtex3.bind(0)
|
||||||
shaderKawaseUp.bind()
|
shaderKawaseUp.bind()
|
||||||
shaderKawaseUp.setUniformMatrix("u_projTrans", camera.combined)
|
shaderKawaseUp.setUniformMatrix("u_projTrans", camera.combined)
|
||||||
shaderKawaseUp.setUniformi("u_texture", 0)
|
shaderKawaseUp.setUniformi("u_texture", 0)
|
||||||
@@ -201,13 +236,13 @@ object Toolkit : Disposable {
|
|||||||
blurWriteQuad.render(shaderKawaseUp, GL20.GL_TRIANGLES)
|
blurWriteQuad.render(shaderKawaseUp, GL20.GL_TRIANGLES)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.texture.dispose()
|
||||||
|
|
||||||
blurIntexture.dispose()
|
|
||||||
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
|
||||||
|
|
||||||
batch.begin()
|
batch.begin()
|
||||||
batch.shader = null
|
batch.shader = null
|
||||||
batch.draw(fboBlur.colorBufferTexture, x.toFloat(), y.toFloat(), w.toFloat(), h.toFloat())
|
batch.draw(fboBlur.colorBufferTexture, x.toFloat(), y.toFloat())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun drawBaloon(batch: SpriteBatch, x: Float, y: Float, w: Float, h: Float) {
|
fun drawBaloon(batch: SpriteBatch, x: Float, y: Float, w: Float, h: Float) {
|
||||||
@@ -264,44 +299,47 @@ object Toolkit : Disposable {
|
|||||||
VertexAttribute.TexCoords(0)
|
VertexAttribute.TexCoords(0)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val fw = App.scr.width//MathUtils.nextPowerOfTwo(App.scr.width)
|
||||||
|
val fh = App.scr.height//MathUtils.nextPowerOfTwo(App.scr.height)
|
||||||
|
|
||||||
fboBlur = FrameBuffer(
|
fboBlur = FrameBuffer(
|
||||||
Pixmap.Format.RGBA8888,
|
Pixmap.Format.RGBA8888,
|
||||||
App.scr.width,
|
fw,
|
||||||
App.scr.height,
|
fh,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
fboBlurHalf = FrameBuffer(
|
fboBlurHalf = FrameBuffer(
|
||||||
Pixmap.Format.RGBA8888,
|
Pixmap.Format.RGBA8888,
|
||||||
App.scr.width / 2,
|
fw / 2,
|
||||||
App.scr.height / 2,
|
fh / 2,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
fboBlurQuarter = FrameBuffer(
|
fboBlurQuarter = FrameBuffer(
|
||||||
Pixmap.Format.RGBA8888,
|
Pixmap.Format.RGBA8888,
|
||||||
App.scr.width / 4,
|
fw / 4,
|
||||||
App.scr.height / 4,
|
fh / 4,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
|
||||||
blurWriteQuad.setVertices(floatArrayOf(
|
blurWriteQuad.setVertices(floatArrayOf(
|
||||||
0f,0f,0f, 1f,1f,1f,1f, 0f,1f,
|
0f,0f,0f, 1f,1f,1f,1f, 0f,1f,
|
||||||
App.scr.width.toFloat(),0f,0f, 1f,1f,1f,1f, 1f,1f,
|
fw.toFloat(),0f,0f, 1f,1f,1f,1f, 1f,1f,
|
||||||
App.scr.width.toFloat(), App.scr.height.toFloat(),0f, 1f,1f,1f,1f, 1f,0f,
|
fw.toFloat(), fh.toFloat(),0f, 1f,1f,1f,1f, 1f,0f,
|
||||||
0f, App.scr.height.toFloat(),0f, 1f,1f,1f,1f, 0f,0f))
|
0f, fh.toFloat(),0f, 1f,1f,1f,1f, 0f,0f))
|
||||||
blurWriteQuad.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))
|
blurWriteQuad.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))
|
||||||
|
|
||||||
blurWriteQuad2.setVertices(floatArrayOf(
|
blurWriteQuad2.setVertices(floatArrayOf(
|
||||||
0f,0f,0f, 1f,1f,1f,1f, 0f,1f,
|
0f,0f,0f, 1f,1f,1f,1f, 0f,1f,
|
||||||
App.scr.width.div(2).toFloat(),0f,0f, 1f,1f,1f,1f, 1f,1f,
|
fw.div(2).toFloat(),0f,0f, 1f,1f,1f,1f, 1f,1f,
|
||||||
App.scr.width.div(2).toFloat(), App.scr.height.div(2).toFloat(),0f, 1f,1f,1f,1f, 1f,0f,
|
fw.div(2).toFloat(), fh.div(2).toFloat(),0f, 1f,1f,1f,1f, 1f,0f,
|
||||||
0f, App.scr.height.div(2).toFloat(),0f, 1f,1f,1f,1f, 0f,0f))
|
0f, fh.div(2).toFloat(),0f, 1f,1f,1f,1f, 0f,0f))
|
||||||
blurWriteQuad2.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))
|
blurWriteQuad2.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))
|
||||||
|
|
||||||
blurWriteQuad4.setVertices(floatArrayOf(
|
blurWriteQuad4.setVertices(floatArrayOf(
|
||||||
0f,0f,0f, 1f,1f,1f,1f, 0f,1f,
|
0f,0f,0f, 1f,1f,1f,1f, 0f,1f,
|
||||||
App.scr.width.div(4).toFloat(),0f,0f, 1f,1f,1f,1f, 1f,1f,
|
fw.div(4).toFloat(),0f,0f, 1f,1f,1f,1f, 1f,1f,
|
||||||
App.scr.width.div(4).toFloat(), App.scr.height.div(4).toFloat(),0f, 1f,1f,1f,1f, 1f,0f,
|
fw.div(4).toFloat(), fh.div(4).toFloat(),0f, 1f,1f,1f,1f, 1f,0f,
|
||||||
0f, App.scr.height.div(4).toFloat(),0f, 1f,1f,1f,1f, 0f,0f))
|
0f, fh.div(4).toFloat(),0f, 1f,1f,1f,1f, 0f,0f))
|
||||||
blurWriteQuad4.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))
|
blurWriteQuad4.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user