mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 03:24:06 +09:00
dat blur
This commit is contained in:
37
assets/blur2.frag
Normal file
37
assets/blur2.frag
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#ifdef GL_ES
|
||||||
|
precision highp float;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
varying vec4 v_color;
|
||||||
|
varying vec2 v_texCoords;
|
||||||
|
uniform sampler2D u_texture;
|
||||||
|
|
||||||
|
|
||||||
|
uniform vec2 iResolution;
|
||||||
|
uniform float flip;
|
||||||
|
uniform vec2 direction;
|
||||||
|
|
||||||
|
vec4 blur(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec2 uv = vec2(gl_FragCoord.xy / iResolution.xy);
|
||||||
|
if (flip == 1.0) {
|
||||||
|
uv.y = 1.0 - uv.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
gl_FragColor = blur(u_texture, uv, iResolution.xy, direction);
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package net.torvald.terrarum
|
package net.torvald.terrarum
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Camera
|
import com.badlogic.gdx.graphics.*
|
||||||
import com.badlogic.gdx.graphics.Color
|
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
|
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||||
import net.torvald.terrarum.modulebasegame.IngameRenderer
|
import net.torvald.terrarum.modulebasegame.IngameRenderer
|
||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.UICanvas
|
||||||
|
|
||||||
@@ -54,28 +54,58 @@ class UIFakeBlurOverlay : UICanvas() {
|
|||||||
|
|
||||||
override var openCloseTime: Second = 0f
|
override var openCloseTime: Second = 0f
|
||||||
|
|
||||||
private val shaderBlur = App.loadShaderFromFile("assets/blur.vert", "assets/blur.frag")
|
private val shaderBlur = App.loadShaderFromFile("assets/blur.vert", "assets/blur2.frag")
|
||||||
|
|
||||||
init { }
|
private val blurRadius = 2f
|
||||||
|
|
||||||
private val blurRadius = 32f
|
|
||||||
private val darken = Color(0.5f, 0.5f, 0.5f, 1f)
|
private val darken = Color(0.5f, 0.5f, 0.5f, 1f)
|
||||||
|
private var fbo = FrameBuffer(Pixmap.Format.RGBA8888, width / 4, height / 4, true)
|
||||||
|
|
||||||
|
|
||||||
override fun updateUI(delta: Float) {}
|
override fun updateUI(delta: Float) {}
|
||||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||||
/*for (i in 0 until 5) {
|
for (i in 0 until 6) {
|
||||||
|
val scalar = blurRadius * (1 shl i.ushr(1))
|
||||||
|
|
||||||
batch.shader = shaderBlur
|
batch.shader = shaderBlur
|
||||||
shaderBlur.setUniformMatrix("u_projTrans", camera.combined)
|
shaderBlur.setUniformMatrix("u_projTrans", camera.combined)
|
||||||
shaderBlur.setUniformi("u_texture", 0)
|
shaderBlur.setUniformi("u_texture", 0)
|
||||||
shaderBlur.setUniformf("iResolution", width.toFloat(), height.toFloat())
|
shaderBlur.setUniformf("iResolution", width.toFloat(), height.toFloat())
|
||||||
IngameRenderer.shaderBlur.setUniformf("flip", 1f)
|
IngameRenderer.shaderBlur.setUniformf("flip", 1f)
|
||||||
if (i % 2 == 0)
|
if (i % 2 == 0)
|
||||||
IngameRenderer.shaderBlur.setUniformf("direction", blurRadius, 0f)
|
IngameRenderer.shaderBlur.setUniformf("direction", scalar, 0f)
|
||||||
else
|
else
|
||||||
IngameRenderer.shaderBlur.setUniformf("direction", 0f, blurRadius)
|
IngameRenderer.shaderBlur.setUniformf("direction", 0f, scalar)
|
||||||
|
|
||||||
|
val p = Pixmap.createFromFrameBuffer(0, 0, width, height)
|
||||||
|
val t = Texture(p); t.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
|
||||||
|
|
||||||
|
batch.draw(t, 0f, 0f)
|
||||||
|
batch.flush() // so I can safely dispose of the texture
|
||||||
|
|
||||||
|
t.dispose(); p.dispose()
|
||||||
|
}
|
||||||
|
|
||||||
|
// sample blurred but blocky texture, scale it down, and re-scale up to the main screen
|
||||||
|
batch.end()
|
||||||
|
val p = Pixmap.createFromFrameBuffer(0, 0, width, height)
|
||||||
|
val t = Texture(p); t.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
|
||||||
|
|
||||||
|
fbo.inAction(camera as OrthographicCamera, batch) {
|
||||||
|
batch.inUse {
|
||||||
|
batch.shader = null
|
||||||
|
batch.draw(t, 0f, 0f, fbo.width.toFloat(), fbo.height.toFloat())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
t.dispose(); p.dispose()
|
||||||
|
|
||||||
|
batch.begin()
|
||||||
|
|
||||||
|
val t2 = fbo.colorBufferTexture
|
||||||
|
t2.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
|
||||||
|
blendNormal(batch)
|
||||||
|
batch.draw(t2, 0f, 0f, width.toFloat(), height.toFloat())
|
||||||
|
|
||||||
|
|
||||||
batch.fillRect(0f, 0f, width.toFloat(), height.toFloat())
|
|
||||||
}*/
|
|
||||||
blendMul(batch)
|
blendMul(batch)
|
||||||
batch.color = darken
|
batch.color = darken
|
||||||
batch.fillRect(0f, 0f, width.toFloat(), height.toFloat())
|
batch.fillRect(0f, 0f, width.toFloat(), height.toFloat())
|
||||||
@@ -89,5 +119,6 @@ class UIFakeBlurOverlay : UICanvas() {
|
|||||||
override fun endClosing(delta: Float) {}
|
override fun endClosing(delta: Float) {}
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
shaderBlur.dispose()
|
shaderBlur.dispose()
|
||||||
|
fbo.dispose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -607,9 +607,6 @@ object IngameRenderer : Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun processBlur(lightmapFboA: FrameBuffer, lightmapFboB: FrameBuffer) {
|
fun processBlur(lightmapFboA: FrameBuffer, lightmapFboB: FrameBuffer) {
|
||||||
val blurIterations = 5 // ideally, 4 * radius; must be even/odd number -- odd/even number will flip the image
|
|
||||||
val blurRadius = 4f / lightmapDownsample // (5, 4f); using low numbers for pixel-y aesthetics
|
|
||||||
|
|
||||||
var blurWriteBuffer = lightmapFboA
|
var blurWriteBuffer = lightmapFboA
|
||||||
var blurReadBuffer = lightmapFboB
|
var blurReadBuffer = lightmapFboB
|
||||||
|
|
||||||
@@ -629,7 +626,9 @@ object IngameRenderer : Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// do blurring
|
// do blurring
|
||||||
for (i in 0 until blurIterations) {
|
for (i in 0 until 4) {
|
||||||
|
val blurRadius = (4f / lightmapDownsample) * (1 shl i.ushr(1))
|
||||||
|
|
||||||
blurWriteBuffer.inAction(camera, batch) {
|
blurWriteBuffer.inAction(camera, batch) {
|
||||||
|
|
||||||
blurTex.texture = blurReadBuffer.colorBufferTexture
|
blurTex.texture = blurReadBuffer.colorBufferTexture
|
||||||
|
|||||||
@@ -99,6 +99,8 @@ open class UIRemoCon(val parent: TitleScreen, treeRepresentation: QNDTreeNode<St
|
|||||||
currentRemoConContents = currentRemoConContents.parent!!
|
currentRemoConContents = currentRemoConContents.parent!!
|
||||||
currentlySelectedRemoConItem = currentRemoConContents.data
|
currentlySelectedRemoConItem = currentRemoConContents.data
|
||||||
remoConTray = generateNewRemoCon(currentRemoConContents)
|
remoConTray = generateNewRemoCon(currentRemoConContents)
|
||||||
|
|
||||||
|
parent.uiFakeBlurOverlay.setAsClose()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw NullPointerException("No parent node to return")
|
throw NullPointerException("No parent node to return")
|
||||||
@@ -143,7 +145,6 @@ open class UIRemoCon(val parent: TitleScreen, treeRepresentation: QNDTreeNode<St
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
it.second.setAsClose()
|
it.second.setAsClose()
|
||||||
parent.uiFakeBlurOverlay.setAsClose()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user