vibrancy is applied to the world only, as it should be

This commit is contained in:
minjaesong
2023-09-13 15:09:31 +09:00
parent f34a9db24c
commit 79892f2525
8 changed files with 102 additions and 79 deletions

View File

@@ -191,4 +191,25 @@ public class HQRNG extends Random {
state0 = 1L;
}
/**
* Returns a random value whose probability is distributed in triangular manner, of which 0.5 is the most and 0.0 and 1.0 are the least likely.
*/
public double nextTriangular() {
return (nextDouble() + nextDouble()) / 2.0;
}
/**
* Returns a random value whose probability is distributed in triangular manner, of which 0.0 is the most and 1.0 is the least likely.
*/
public double nextBrown() {
return Math.abs(nextDouble() + nextDouble() - 1);
}
/**
* Returns a random value whose probability is distributed in triangular manner, of which 1.0 is the most and 0.0 is the least likely.
*/
public double nextBlue() {
return 1.0 - nextBrown();
}
}

View File

@@ -237,13 +237,6 @@ object TerrarumPostProcessor : Disposable {
else
shaderPostNoDither
val (vo, vg) = INGAME.world.weatherbox.let {
if (it.currentWeather.identifier == "titlescreen")
1f to 1f
else
it.currentVibrancy.x to it.currentVibrancy.y
}
App.getCurrentDitherTex().bind(1)
fbo.colorBufferTexture.bind(0)
@@ -253,7 +246,6 @@ object TerrarumPostProcessor : Disposable {
shader.setUniformi("rnd", rng.nextInt(8192), rng.nextInt(8192))
shader.setUniformi("u_pattern", 1)
shader.setUniformf("quant", shaderQuant[App.getConfigInt("displaycolourdepth")] ?: 255f)
shader.setUniformf("vibrancy", 1f, vo, vg, 1f)
shader.setUniformMatrix4fv("swizzler", swizzler, rng.nextInt(24), 16*4)
App.fullscreenQuad.render(shader, GL20.GL_TRIANGLE_FAN)

View File

@@ -7,6 +7,7 @@ import net.torvald.terrarum.*
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.Fluid
import net.torvald.terrarum.concurrent.ThreadExecutor
import net.torvald.terrarum.gameactors.ActorID
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.itemproperties.ItemRemapTable

View File

@@ -88,6 +88,8 @@ object IngameRenderer : Disposable {
val shaderForActors: ShaderProgram
val shaderDemultiply: ShaderProgram
val shaderVibrancy: ShaderProgram
private val WIDTH = App.scr.width
private val HEIGHT = App.scr.height
private val WIDTHF = WIDTH.toFloat()
@@ -131,6 +133,8 @@ object IngameRenderer : Disposable {
shaderKawaseDown = App.loadShaderFromClasspath("shaders/default.vert", "shaders/kawasedown.frag")
shaderKawaseUp = App.loadShaderFromClasspath("shaders/default.vert", "shaders/kawaseup.frag")
shaderVibrancy = App.loadShaderFromClasspath("shaders/default.vert", "shaders/vibrancy.frag")
if (!shaderBlendGlow.isCompiled) {
Gdx.app.log("shaderBlendGlow", shaderBlendGlow.log)
exitProcess(1)
@@ -352,17 +356,20 @@ object IngameRenderer : Disposable {
blendNormalStraightAlpha(batch)
batch.inUse {
// it's no use applying dithering here: colours are no longer "floats" once they're written to the FBO
// proof: disable dithering on skybox and enable dither here -- banding is still visible
// it would work if GDX supported HDR, or GL_RGBA32F as a texture format, but alas.
// but mixedOutTex is still needed for the screen capturing
//batch.shader = if (App.getConfigBoolean("fx_dither")) IngameRenderer.shaderBayer else null
batch.shader = null
batch.drawFlipped(mixedOutTex, 0f, 0f)
val (vo, vg) = world.weatherbox.let {
if (it.currentWeather.identifier == "titlescreen")
1f to 1f
else
it.currentVibrancy.x to it.currentVibrancy.y
}
mixedOutTex.texture.bind(0)
shaderVibrancy.bind()
shaderVibrancy.setUniformMatrix("u_projTrans", camera.combined)
shaderVibrancy.setUniformi("u_texture", 0)
shaderVibrancy.setUniformf("vibrancy", 1f, vo, vg, 1f)
fullscreenQuad.render(shaderVibrancy, GL20.GL_TRIANGLE_FAN)
///////////////////////////////////////////////////////////////////////
@@ -899,6 +906,8 @@ object IngameRenderer : Disposable {
shaderForActors.dispose()
shaderDemultiply.dispose()
shaderVibrancy.dispose()
if (::fboRGBexport.isInitialized) fboRGBexport.tryDispose()
}

View File

@@ -7,6 +7,7 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.App
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.TerrarumAppConfiguration
import net.torvald.terrarum.ccE
@@ -249,7 +250,7 @@ class ConsoleWindow : UICanvas() {
override fun doOpening(delta: Float) {
Terrarum.ingame?.let {
println("Game was paused beforehand: ${it.paused}")
// printdbg(this, "Game was paused beforehand: ${it.paused}")
if (!it.paused) {
iMadeTheGameToPause = true
it.pause()
@@ -257,7 +258,7 @@ class ConsoleWindow : UICanvas() {
else {
iMadeTheGameToPause = false
}
println("I made the game to pause: $iMadeTheGameToPause")
// printdbg(this, "I made the game to pause: $iMadeTheGameToPause")
}
/*openingTimeCounter += delta
drawOffY = MovementInterpolator.fastPullOut(openingTimeCounter.toFloat() / openCloseTime.toFloat(),
@@ -282,10 +283,10 @@ class ConsoleWindow : UICanvas() {
}
override fun endClosing(delta: Float) {
println("Close -- I made the game to pause: $iMadeTheGameToPause")
// printdbg(this, "Close -- I made the game to pause: $iMadeTheGameToPause")
if (iMadeTheGameToPause) {
Terrarum.ingame?.resume()
println("Close -- resume game")
// printdbg(this, "Close -- resume game")
}
iMadeTheGameToPause = false
Terrarum.ingame?.setTooltipMessage(null)

View File

@@ -41,20 +41,6 @@ const vec4 matrixNormaliser = vec4(0.5 / 256.0);
const vec2 patternsize = vec2(1.0/512.0, 1.0/512.0);
const mat4 rgb_to_ycocg = mat4(
0.25, 1.0, -0.5, 0.0,
0.5, 0.0, 1.0, 0.0,
0.25, -1.0, -0.5, 0.0,
0.0, 0.0, 0.0, 1.0
);
const mat4 ycocg_to_rgb = mat4(
1.0, 1.0, 1.0, 0.0,
0.5, 0.0, -0.5, 0.0,
-0.5, 0.5, -0.5, 0.0,
0.0, 0.0, 0.0, 1.0
);
vec4 nearestColour(vec4 inColor) {
return floor(quantVec * inColor) * invQuant;
@@ -65,23 +51,9 @@ vec4 getDitherredDot(vec4 inColor) {
return nearestColour(fma(bayerThreshold, invQuant, inColor));
}
uniform vec4 vibrancy = vec4(1.0);//vec4(1.0, 1.4, 1.2, 1.0);
void main(void) {
// convert input RGB into YCoCg
vec4 incolour = texture(u_texture, v_texCoords);
vec4 yog = rgb_to_ycocg * incolour; // vec4(Y, Co, Cg, A) where Y,A=[0,1]; Co,Cg=[-1,1]
// Do colour-grading magic
vec4 sgn = sign(yog);
vec4 absval = abs(yog);
vec4 raised = pow(absval, boolean.yyyy / vibrancy);
vec4 newColour = sgn * raised;
// Dither the output
vec4 graded = ycocg_to_rgb * newColour;
vec4 selvec = getDitherredDot(graded);
vec4 selvec = getDitherredDot(incolour);
vec4 outcol = fma(selvec, boolean.yyyx, boolean.xxxy); // use quantised RGB but not the A
fragColor = outcol;

View File

@@ -28,37 +28,9 @@ uniform float quant = 255.0; // 64 steps -> 63.0; 256 steps -> 255.0
const vec2 boolean = vec2(0.0, 1.0);
const mat4 rgb_to_ycocg = mat4(
0.25, 1.0, -0.5, 0.0,
0.5, 0.0, 1.0, 0.0,
0.25, -1.0, -0.5, 0.0,
0.0, 0.0, 0.0, 1.0
);
const mat4 ycocg_to_rgb = mat4(
1.0, 1.0, 1.0, 0.0,
0.5, 0.0, -0.5, 0.0,
-0.5, 0.5, -0.5, 0.0,
0.0, 0.0, 0.0, 1.0
);
uniform vec4 vibrancy = vec4(1.0);//vec4(1.0, 1.4, 1.2, 1.0);
out vec4 fragColor;
void main(void) {
// convert input RGB into YCoCg
vec4 incolour = texture(u_texture, v_texCoords);
vec4 yog = rgb_to_ycocg * incolour; // vec4(Y, Co, Cg, A) where Y,A=[0,1]; Co,Cg=[-1,1]
// Do colour-grading magic
vec4 sgn = sign(yog);
vec4 absval = abs(yog);
vec4 raised = pow(absval, boolean.yyyy / vibrancy);
vec4 newColour = sgn * raised;
// Dither the output
vec4 graded = ycocg_to_rgb * newColour;
fragColor = fma(graded, boolean.yyyx, boolean.xxxy); // use quantised RGB but not the A
fragColor = fma(incolour, boolean.yyyx, boolean.xxxy); // use quantised RGB but not the A
}

55
src/shaders/vibrancy.frag Normal file
View File

@@ -0,0 +1,55 @@
#version 400
#ifdef GL_ES
precision mediump float;
#endif
vec4 gammaIn(vec4 col) {
return pow(col, vec4(2.2));
}
vec4 gammaOut(vec4 col) {
return pow(col, vec4(1.0 / 2.2));
}
in vec4 v_color; // unused!
in vec2 v_texCoords;
uniform sampler2D u_texture;
const vec2 boolean = vec2(0.0, 1.0);
const mat4 rgb_to_ycocg = mat4(
0.25, 1.0, -0.5, 0.0,
0.5, 0.0, 1.0, 0.0,
0.25, -1.0, -0.5, 0.0,
0.0, 0.0, 0.0, 1.0
);
const mat4 ycocg_to_rgb = mat4(
1.0, 1.0, 1.0, 0.0,
0.5, 0.0, -0.5, 0.0,
-0.5, 0.5, -0.5, 0.0,
0.0, 0.0, 0.0, 1.0
);
uniform vec4 vibrancy = vec4(1.0);//vec4(1.0, 1.4, 1.2, 1.0);
out vec4 fragColor;
void main(void) {
// convert input RGB into YCoCg
vec4 incolour = texture(u_texture, v_texCoords);
vec4 yog = rgb_to_ycocg * incolour; // vec4(Y, Co, Cg, A) where Y,A=[0,1]; Co,Cg=[-1,1]
// Do colour-grading magic
vec4 sgn = sign(yog);
vec4 absval = abs(yog);
vec4 raised = pow(absval, boolean.yyyy / vibrancy);
vec4 newColour = sgn * raised;
// Dither the output
vec4 graded = ycocg_to_rgb * newColour;
fragColor = fma(graded, boolean.yyyx, boolean.xxxy); // use quantised RGB but not the A
}