mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-06 08:38:30 +09:00
temporal dithering test
This commit is contained in:
@@ -21,8 +21,9 @@ varying vec4 v_color;
|
|||||||
varying vec2 v_texCoords;
|
varying vec2 v_texCoords;
|
||||||
uniform sampler2D u_texture;
|
uniform sampler2D u_texture;
|
||||||
uniform sampler2D u_pattern;
|
uniform sampler2D u_pattern;
|
||||||
|
uniform ivec2 rnd = ivec2(0,0);
|
||||||
|
|
||||||
float quant = 63.0; // 64 steps -> 63.0; 256 steps -> 255.0
|
float quant = 127.0; // 64 steps -> 63.0; 256 steps -> 255.0
|
||||||
vec4 quantiser = vec4(quant);
|
vec4 quantiser = vec4(quant);
|
||||||
vec4 quantiserDivider = vec4(1.0 / quant);
|
vec4 quantiserDivider = vec4(1.0 / quant);
|
||||||
|
|
||||||
@@ -36,8 +37,8 @@ vec4 nearestColour(vec4 inColor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vec4 getDitherredDot(vec4 inColor) {
|
vec4 getDitherredDot(vec4 inColor) {
|
||||||
vec4 bayerThreshold = vec4(texture2D(u_pattern, gl_FragCoord.xy * patternsize) - 0.5);
|
vec4 bayerThreshold = vec4(texture2D(u_pattern, (gl_FragCoord.xy + rnd) * patternsize) - 0.5);
|
||||||
return nearestColour(inColor + bayerThreshold * quantiserDivider);
|
return nearestColour(bayerThreshold * quantiserDivider + inColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,8 +13,9 @@ varying vec4 v_color;
|
|||||||
varying vec2 v_texCoords;
|
varying vec2 v_texCoords;
|
||||||
uniform sampler2D u_texture;
|
uniform sampler2D u_texture;
|
||||||
uniform sampler2D u_pattern;
|
uniform sampler2D u_pattern;
|
||||||
|
uniform ivec2 rnd = ivec2(0,0);
|
||||||
|
|
||||||
float quant = 63.0; // 64 steps -> 63.0; 256 steps -> 255.0
|
float quant = 127.0; // 64 steps -> 63.0; 256 steps -> 255.0
|
||||||
vec4 quantiser = vec4(quant);
|
vec4 quantiser = vec4(quant);
|
||||||
vec4 quantiserDivider = vec4(1.0 / quant);
|
vec4 quantiserDivider = vec4(1.0 / quant);
|
||||||
|
|
||||||
@@ -28,8 +29,8 @@ vec4 nearestColour(vec4 inColor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vec4 getDitherredDot(vec4 inColor) {
|
vec4 getDitherredDot(vec4 inColor) {
|
||||||
vec4 bayerThreshold = vec4(texture2D(u_pattern, gl_FragCoord.xy * patternsize) - 0.5);
|
vec4 bayerThreshold = vec4(texture2D(u_pattern, (gl_FragCoord.xy + rnd) * patternsize) - 0.5);
|
||||||
return nearestColour(inColor + bayerThreshold * quantiserDivider);
|
return nearestColour(bayerThreshold * quantiserDivider + inColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,8 +13,9 @@ varying vec4 v_color;
|
|||||||
varying vec2 v_texCoords;
|
varying vec2 v_texCoords;
|
||||||
uniform sampler2D u_texture;
|
uniform sampler2D u_texture;
|
||||||
uniform sampler2D u_pattern;
|
uniform sampler2D u_pattern;
|
||||||
|
uniform ivec2 rnd = ivec2(0,0);
|
||||||
|
|
||||||
float quant = 63.0; // 64 steps -> 63.0; 256 steps -> 255.0
|
float quant = 127.0; // 64 steps -> 63.0; 256 steps -> 255.0
|
||||||
vec4 quantiser = vec4(quant);
|
vec4 quantiser = vec4(quant);
|
||||||
vec4 quantiserDivider = vec4(1.0 / quant);
|
vec4 quantiserDivider = vec4(1.0 / quant);
|
||||||
|
|
||||||
@@ -28,8 +29,8 @@ vec4 nearestColour(vec4 inColor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vec4 getDitherredDot(vec4 inColor) {
|
vec4 getDitherredDot(vec4 inColor) {
|
||||||
vec4 bayerThreshold = vec4(texture2D(u_pattern, gl_FragCoord.xy * patternsize) - 0.5);
|
vec4 bayerThreshold = vec4(texture2D(u_pattern, (gl_FragCoord.xy + rnd) * patternsize) - 0.5);
|
||||||
return nearestColour(inColor + bayerThreshold * quantiserDivider);
|
return nearestColour(bayerThreshold * quantiserDivider + inColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,9 @@ varying vec4 v_color;
|
|||||||
varying vec2 v_texCoords;
|
varying vec2 v_texCoords;
|
||||||
uniform sampler2D u_texture;
|
uniform sampler2D u_texture;
|
||||||
uniform sampler2D u_pattern;
|
uniform sampler2D u_pattern;
|
||||||
|
uniform ivec2 rnd = ivec2(0,0);
|
||||||
|
|
||||||
float quant = 63.0; // 64 steps -> 63.0; 256 steps -> 255.0
|
float quant = 127.0; // 64 steps -> 63.0; 256 steps -> 255.0
|
||||||
vec4 quantiser = vec4(quant);
|
vec4 quantiser = vec4(quant);
|
||||||
vec4 quantiserDivider = vec4(1.0 / quant);
|
vec4 quantiserDivider = vec4(1.0 / quant);
|
||||||
|
|
||||||
@@ -26,8 +27,8 @@ vec4 nearestColour(vec4 inColor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vec4 getDitherredDot(vec4 inColor) {
|
vec4 getDitherredDot(vec4 inColor) {
|
||||||
vec4 bayerThreshold = vec4(texture2D(u_pattern, gl_FragCoord.xy * patternsize) - 0.5);
|
vec4 bayerThreshold = vec4(texture2D(u_pattern, (gl_FragCoord.xy + rnd) * patternsize) - 0.5);
|
||||||
return nearestColour(inColor + bayerThreshold * quantiserDivider);
|
return nearestColour(bayerThreshold * quantiserDivider + inColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ 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 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.TerrarumAppConfiguration.TILE_SIZE
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||||
@@ -66,6 +67,8 @@ object IngameRenderer : Disposable {
|
|||||||
|
|
||||||
inline fun isDither() = App.getConfigBoolean("fx_dither")
|
inline fun isDither() = App.getConfigBoolean("fx_dither")
|
||||||
|
|
||||||
|
private val rng = HQRNG()
|
||||||
|
|
||||||
val shaderBlur: ShaderProgram
|
val shaderBlur: ShaderProgram
|
||||||
get() = if (isDither()) shaderBlurDither else shaderBlurRaw
|
get() = if (isDither()) shaderBlurDither else shaderBlurRaw
|
||||||
val shaderRGBOnly: ShaderProgram
|
val shaderRGBOnly: ShaderProgram
|
||||||
@@ -496,6 +499,7 @@ object IngameRenderer : Disposable {
|
|||||||
blendMul(batch)
|
blendMul(batch)
|
||||||
|
|
||||||
batch.shader = shaderRGBOnly
|
batch.shader = shaderRGBOnly
|
||||||
|
batch.shader.setUniformi("rnd", rng.nextInt(8192), rng.nextInt(8192))
|
||||||
batch.shader.setUniformi("u_pattern", 1)
|
batch.shader.setUniformi("u_pattern", 1)
|
||||||
batch.draw(lightTex,
|
batch.draw(lightTex,
|
||||||
xrem, yrem,
|
xrem, yrem,
|
||||||
@@ -581,6 +585,7 @@ object IngameRenderer : Disposable {
|
|||||||
blendMul(batch)
|
blendMul(batch)
|
||||||
|
|
||||||
batch.shader = shaderAtoGrey
|
batch.shader = shaderAtoGrey
|
||||||
|
batch.shader.setUniformi("rnd", rng.nextInt(8192), rng.nextInt(8192))
|
||||||
batch.shader.setUniformi("u_pattern", 1)
|
batch.shader.setUniformi("u_pattern", 1)
|
||||||
batch.draw(lightTex,
|
batch.draw(lightTex,
|
||||||
xrem, yrem,
|
xrem, yrem,
|
||||||
@@ -687,6 +692,7 @@ object IngameRenderer : Disposable {
|
|||||||
|
|
||||||
shaderBlur.bind()
|
shaderBlur.bind()
|
||||||
shaderBlur.setUniformMatrix("u_projTrans", camera.combined)
|
shaderBlur.setUniformMatrix("u_projTrans", camera.combined)
|
||||||
|
shaderBlur.setUniformi("rnd", rng.nextInt(8192), rng.nextInt(8192))
|
||||||
shaderBlur.setUniformi("u_pattern", 1)
|
shaderBlur.setUniformi("u_pattern", 1)
|
||||||
shaderBlur.setUniformi("u_texture", 0)
|
shaderBlur.setUniformi("u_texture", 0)
|
||||||
shaderBlur.setUniformf("iResolution",
|
shaderBlur.setUniformf("iResolution",
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ 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.ShaderProgram
|
import com.badlogic.gdx.graphics.glutils.ShaderProgram
|
||||||
import com.badlogic.gdx.utils.Disposable
|
import com.badlogic.gdx.utils.Disposable
|
||||||
|
import net.torvald.random.HQRNG
|
||||||
import net.torvald.terrarum.App
|
import net.torvald.terrarum.App
|
||||||
import net.torvald.terrarum.CommonResourcePool
|
import net.torvald.terrarum.CommonResourcePool
|
||||||
import net.torvald.terrarum.fillRect
|
import net.torvald.terrarum.fillRect
|
||||||
@@ -39,6 +40,7 @@ object Toolkit : Disposable {
|
|||||||
CommonResourcePool.loadAll()
|
CommonResourcePool.loadAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val rng = HQRNG()
|
||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
baloonTile.dispose()
|
baloonTile.dispose()
|
||||||
@@ -114,6 +116,7 @@ object Toolkit : Disposable {
|
|||||||
|
|
||||||
batch.shader = shaderBlur
|
batch.shader = shaderBlur
|
||||||
shaderBlur.setUniformMatrix("u_projTrans", camera.combined)
|
shaderBlur.setUniformMatrix("u_projTrans", camera.combined)
|
||||||
|
shaderBlur.setUniformi("rnd", rng.nextInt(8192), rng.nextInt(8192))
|
||||||
shaderBlur.setUniformi("u_texture", 0)
|
shaderBlur.setUniformi("u_texture", 0)
|
||||||
shaderBlur.setUniformi("u_pattern", 1)
|
shaderBlur.setUniformi("u_pattern", 1)
|
||||||
shaderBlur.setUniformf("iResolution", w.toFloat(), h.toFloat())
|
shaderBlur.setUniformf("iResolution", w.toFloat(), h.toFloat())
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ internal object WeatherMixer : RNGConsumer {
|
|||||||
|
|
||||||
override val RNG = HQRNG()
|
override val RNG = HQRNG()
|
||||||
|
|
||||||
|
private val renderng = HQRNG()
|
||||||
|
|
||||||
var globalLightOverridden = false
|
var globalLightOverridden = false
|
||||||
|
|
||||||
var weatherList: HashMap<String, ArrayList<BaseModularWeather>>
|
var weatherList: HashMap<String, ArrayList<BaseModularWeather>>
|
||||||
@@ -186,6 +188,7 @@ internal object WeatherMixer : RNGConsumer {
|
|||||||
it.shader = if (App.getConfigBoolean("fx_dither")) IngameRenderer.shaderBayer else null
|
it.shader = if (App.getConfigBoolean("fx_dither")) IngameRenderer.shaderBayer else null
|
||||||
if (App.getConfigBoolean("fx_dither")) {
|
if (App.getConfigBoolean("fx_dither")) {
|
||||||
it.shader.setUniformi("u_pattern", 1)
|
it.shader.setUniformi("u_pattern", 1)
|
||||||
|
it.shader.setUniformi("rnd", renderng.nextInt(8192), renderng.nextInt(8192))
|
||||||
}
|
}
|
||||||
it.draw(skyboxTexture, 0f, -App.scr.halfhf, App.scr.wf, App.scr.hf * 2f) // because of how the linear filter works, we extend the image by two
|
it.draw(skyboxTexture, 0f, -App.scr.halfhf, App.scr.wf, App.scr.hf * 2f) // because of how the linear filter works, we extend the image by two
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user