mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
postprocessor for 3dlut colcorr; dithering should be managed in "dirty" way
dirty way: loads dithered/passthru shader according to the game's config (boolean fxdither)
This commit is contained in:
@@ -10,9 +10,9 @@ uniform sampler2D u_texture;
|
||||
|
||||
|
||||
// "steps" of R, G and B. Must be integer && equal or greater than 2
|
||||
uniform float rcount = 4.0;
|
||||
uniform float gcount = 4.0;
|
||||
uniform float bcount = 4.0;
|
||||
uniform float rcount = 64.0;
|
||||
uniform float gcount = 64.0;
|
||||
uniform float bcount = 64.0;
|
||||
uniform float acount = 1.0;
|
||||
|
||||
|
||||
@@ -65,15 +65,9 @@ vec4 nearestColour(vec4 incolor) {
|
||||
color.r = floor((rgbaCounts.r - 1.0) * color.r + 0.5) / (rgbaCounts.r - 1.0);
|
||||
color.g = floor((rgbaCounts.g - 1.0) * color.g + 0.5) / (rgbaCounts.g - 1.0);
|
||||
color.b = floor((rgbaCounts.b - 1.0) * color.b + 0.5) / (rgbaCounts.b - 1.0);
|
||||
color.a = 1.0;//floor((rgbaCounts.a - 1.0) * color.a + 0.5) / (rgbaCounts.a - 1.0);
|
||||
|
||||
if (rgbaCounts.a >= 2.0) {
|
||||
color.a = floor((rgbaCounts.a - 1.0) * color.a + 0.5) / (rgbaCounts.a - 1.0);
|
||||
}
|
||||
else {
|
||||
color.a = 1.0;
|
||||
}
|
||||
|
||||
return (color);
|
||||
return color;
|
||||
}
|
||||
|
||||
void main(void) {
|
||||
@@ -87,4 +81,5 @@ void main(void) {
|
||||
|
||||
gl_FragColor = nearestColour(inColor + spread * (bayer[int(entry.y) * int(bayerSize) + int(entry.x)] / bayerDivider - 0.5));
|
||||
//gl_FragColor = nearestColour(inColor);
|
||||
//gl_FragColor = inColor;
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.5 MiB |
14
assets/passthru.frag
Normal file
14
assets/passthru.frag
Normal file
@@ -0,0 +1,14 @@
|
||||
#version 120
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
|
||||
varying vec4 v_color;
|
||||
varying vec2 v_texCoords;
|
||||
uniform sampler2D u_texture;
|
||||
|
||||
|
||||
void main(void) {
|
||||
gl_FragColor = texture2D(u_texture, v_texCoords);
|
||||
}
|
||||
38
assets/skyboxfill.frag
Normal file
38
assets/skyboxfill.frag
Normal file
@@ -0,0 +1,38 @@
|
||||
#version 120
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
|
||||
varying vec4 v_color;
|
||||
varying vec2 v_texCoords;
|
||||
uniform sampler2D u_texture;
|
||||
|
||||
|
||||
uniform vec3 topColor;
|
||||
uniform vec3 bottomColor;
|
||||
uniform float parallax = 0.0; // +1.0: all top col, -1.0: all bototm col, 0.0: normal grad
|
||||
uniform float parallax_size = 1.0/3.0; // 0: no parallax
|
||||
|
||||
|
||||
|
||||
void main(void) {
|
||||
float scale = v_texCoords.y * (1.0 - parallax_size) + (parallax_size / 2.0) + (parallax * parallax_size / 2.0);
|
||||
|
||||
float inR = mix(bottomColor.r, topColor.r, scale);
|
||||
float inG = mix(bottomColor.g, topColor.g, scale);
|
||||
float inB = mix(bottomColor.b, topColor.b, scale);
|
||||
|
||||
gl_FragColor = vec4(inR, inG, inB, 1.0);
|
||||
}
|
||||
/*
|
||||
UV mapping coord.y
|
||||
|
||||
-+ <- 1.0 =
|
||||
D| = // parallax of +1
|
||||
i| = =
|
||||
s| = // parallax of 0
|
||||
p| = =
|
||||
.| = // parallax of -1
|
||||
-+ <- 0.0 =
|
||||
*/
|
||||
@@ -84,6 +84,13 @@ object DefaultConfig {
|
||||
|
||||
jsonObject.addProperty("useamericanunit", false) // Metric Masterrace -- Filthy imperials.
|
||||
|
||||
|
||||
// "fancy" graphics settings
|
||||
jsonObject.addProperty("fxdither", true)
|
||||
jsonObject.addProperty("fx3dlut", false)
|
||||
|
||||
|
||||
|
||||
return jsonObject
|
||||
}
|
||||
}
|
||||
|
||||
29
src/net/torvald/terrarum/PostProcessor.kt
Normal file
29
src/net/torvald/terrarum/PostProcessor.kt
Normal file
@@ -0,0 +1,29 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.GL20
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||
|
||||
object PostProcessor {
|
||||
|
||||
private val batch = SpriteBatch()
|
||||
|
||||
fun draw(screenTexHolder: FrameBuffer) {
|
||||
//Gdx.gl.glClearColor(.094f, .094f, .094f, 1f)
|
||||
//Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
|
||||
|
||||
|
||||
batch.shader = null
|
||||
batch.inUse {
|
||||
val texture = screenTexHolder.colorBufferTexture
|
||||
batch.shader.setUniformMatrix("u_projTrans", batch.projectionMatrix)
|
||||
batch.draw(texture, 0f, 0f, texture.width.toFloat(), texture.height.toFloat())
|
||||
}
|
||||
|
||||
|
||||
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -236,7 +236,7 @@ object Terrarum : Screen {
|
||||
|
||||
lateinit var shaderBlur: ShaderProgram
|
||||
lateinit var shaderBayer: ShaderProgram
|
||||
lateinit var shaderBayerSkyboxFill: ShaderProgram
|
||||
lateinit var shaderSkyboxFill: ShaderProgram
|
||||
lateinit var shaderBlendGlow: ShaderProgram
|
||||
lateinit var shaderRGBOnly: ShaderProgram
|
||||
lateinit var shaderAtoGrey: ShaderProgram
|
||||
@@ -384,14 +384,27 @@ object Terrarum : Screen {
|
||||
ShaderProgram.pedantic = false
|
||||
shaderBlur = ShaderProgram(Gdx.files.internal("assets/blur.vert"), Gdx.files.internal("assets/blur.frag"))
|
||||
|
||||
shaderBayer = ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/4096_bayer.frag"))
|
||||
shaderBayer.begin()
|
||||
shaderBayer.setUniformf("rcount", 16f)
|
||||
shaderBayer.setUniformf("gcount", 16f)
|
||||
shaderBayer.setUniformf("bcount", 16f)
|
||||
shaderBayer.end()
|
||||
|
||||
shaderBayerSkyboxFill = ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/4096_bayer_skyboxfill.frag"))
|
||||
if (getConfigBoolean("fxdither")) {
|
||||
shaderBayer = ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/4096_bayer.frag"))
|
||||
shaderBayer.begin()
|
||||
shaderBayer.setUniformf("rcount", 64f)
|
||||
shaderBayer.setUniformf("gcount", 64f)
|
||||
shaderBayer.setUniformf("bcount", 64f)
|
||||
shaderBayer.end()
|
||||
|
||||
shaderSkyboxFill = ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/4096_bayer_skyboxfill.frag"))
|
||||
shaderSkyboxFill.begin()
|
||||
shaderSkyboxFill.setUniformf("rcount", 64f)
|
||||
shaderSkyboxFill.setUniformf("gcount", 64f)
|
||||
shaderSkyboxFill.setUniformf("bcount", 64f)
|
||||
shaderSkyboxFill.end()
|
||||
}
|
||||
else {
|
||||
shaderBayer = ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/passthru.frag"))
|
||||
shaderSkyboxFill = ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/skyboxfill.frag"))
|
||||
}
|
||||
|
||||
|
||||
shaderBlendGlow = ShaderProgram(Gdx.files.internal("assets/blendGlow.vert"), Gdx.files.internal("assets/blendGlow.frag"))
|
||||
|
||||
@@ -405,14 +418,16 @@ object Terrarum : Screen {
|
||||
}
|
||||
|
||||
|
||||
if (!shaderBayer.isCompiled) {
|
||||
Gdx.app.log("shaderBayer", shaderBayer.log)
|
||||
System.exit(1)
|
||||
}
|
||||
if (getConfigBoolean("fxdither")) {
|
||||
if (!shaderBayer.isCompiled) {
|
||||
Gdx.app.log("shaderBayer", shaderBayer.log)
|
||||
System.exit(1)
|
||||
}
|
||||
|
||||
if (!shaderBayerSkyboxFill.isCompiled) {
|
||||
Gdx.app.log("shaderBayerSkyboxFill", shaderBayerSkyboxFill.log)
|
||||
System.exit(1)
|
||||
if (!shaderSkyboxFill.isCompiled) {
|
||||
Gdx.app.log("shaderSkyboxFill", shaderSkyboxFill.log)
|
||||
System.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -479,7 +494,7 @@ object Terrarum : Screen {
|
||||
|
||||
|
||||
shaderBayer.dispose()
|
||||
shaderBayerSkyboxFill.dispose()
|
||||
shaderSkyboxFill.dispose()
|
||||
shaderBlur.dispose()
|
||||
shaderBlendGlow.dispose()
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
|
||||
import com.badlogic.gdx.graphics.*;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
|
||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
||||
import net.torvald.terrarumsansbitmap.gdx.GameFontBase;
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack;
|
||||
@@ -97,6 +98,8 @@ public class TerrarumAppLoader implements ApplicationListener {
|
||||
private float loadTimer = 0f;
|
||||
private final float showupTime = 50f / 1000f;
|
||||
|
||||
private FrameBuffer renderFBO;
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
batch = new SpriteBatch();
|
||||
@@ -135,6 +138,11 @@ public class TerrarumAppLoader implements ApplicationListener {
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
renderFBO.begin();
|
||||
|
||||
Gdx.gl.glClearColor(0f,0f,0f,0f);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
|
||||
if (screen == null) {
|
||||
shaderBayerSkyboxFill.begin();
|
||||
shaderBayerSkyboxFill.setUniformMatrix("u_projTrans", camera.combined);
|
||||
@@ -169,6 +177,10 @@ public class TerrarumAppLoader implements ApplicationListener {
|
||||
else {
|
||||
screen.render(Gdx.graphics.getDeltaTime());
|
||||
}
|
||||
renderFBO.end();
|
||||
|
||||
|
||||
PostProcessor.INSTANCE.draw(renderFBO);
|
||||
|
||||
|
||||
GLOBAL_RENDER_TIMER += 1;
|
||||
@@ -181,6 +193,19 @@ public class TerrarumAppLoader implements ApplicationListener {
|
||||
Terrarum.INSTANCE.resize(width, height);
|
||||
if (screen != null) screen.resize(width, height);
|
||||
|
||||
|
||||
if (renderFBO == null ||
|
||||
(renderFBO.getWidth() != Terrarum.INSTANCE.getWIDTH() ||
|
||||
renderFBO.getHeight() != Terrarum.INSTANCE.getHEIGHT())
|
||||
) {
|
||||
renderFBO = new FrameBuffer(
|
||||
Pixmap.Format.RGBA8888,
|
||||
Terrarum.INSTANCE.getWIDTH(),
|
||||
Terrarum.INSTANCE.getHEIGHT(),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
System.out.println("[AppLoader] Resize event");
|
||||
}
|
||||
|
||||
|
||||
@@ -131,14 +131,14 @@ object WeatherMixer {
|
||||
|
||||
//Terrarum.textureWhiteSquare.bind(0)
|
||||
|
||||
Terrarum.shaderBayerSkyboxFill.begin()
|
||||
Terrarum.shaderBayerSkyboxFill.setUniformMatrix("u_projTrans", camera.combined)
|
||||
Terrarum.shaderBayerSkyboxFill.setUniformf("topColor", topCol.r, topCol.g, topCol.b)
|
||||
Terrarum.shaderBayerSkyboxFill.setUniformf("bottomColor", bottomCol.r, bottomCol.g, bottomCol.b)
|
||||
Terrarum.shaderBayerSkyboxFill.setUniformf("parallax", parallax)
|
||||
Terrarum.shaderBayerSkyboxFill.setUniformf("parallax_size", 1f/3f)
|
||||
Terrarum.fullscreenQuad.render(Terrarum.shaderBayerSkyboxFill, GL20.GL_TRIANGLES)
|
||||
Terrarum.shaderBayerSkyboxFill.end()
|
||||
Terrarum.shaderSkyboxFill.begin()
|
||||
Terrarum.shaderSkyboxFill.setUniformMatrix("u_projTrans", camera.combined)
|
||||
Terrarum.shaderSkyboxFill.setUniformf("topColor", topCol.r, topCol.g, topCol.b)
|
||||
Terrarum.shaderSkyboxFill.setUniformf("bottomColor", bottomCol.r, bottomCol.g, bottomCol.b)
|
||||
Terrarum.shaderSkyboxFill.setUniformf("parallax", parallax)
|
||||
Terrarum.shaderSkyboxFill.setUniformf("parallax_size", 1f/3f)
|
||||
Terrarum.fullscreenQuad.render(Terrarum.shaderSkyboxFill, GL20.GL_TRIANGLES)
|
||||
Terrarum.shaderSkyboxFill.end()
|
||||
|
||||
|
||||
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me
|
||||
|
||||
Reference in New Issue
Block a user