mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 18:44:05 +09:00
temporal bayer dithering for particles
This commit is contained in:
@@ -94,6 +94,7 @@ open class ParticleBase(renderOrder: Actor.RenderOrder, var despawnUponCollision
|
|||||||
val oldColour = batch.color.cpy()
|
val oldColour = batch.color.cpy()
|
||||||
if (!flagDespawn) {
|
if (!flagDespawn) {
|
||||||
batch.shader = IngameRenderer.shaderBayerAlpha
|
batch.shader = IngameRenderer.shaderBayerAlpha
|
||||||
|
batch.shader.setUniformi("frame", App.GLOBAL_RENDER_TIMER.toInt() % 16)
|
||||||
batch.color = drawColour
|
batch.color = drawColour
|
||||||
drawBodyInGoodPosition(hitbox.startX.toFloat(), hitbox.startY.toFloat()) { x, y ->
|
drawBodyInGoodPosition(hitbox.startX.toFloat(), hitbox.startY.toFloat()) { x, y ->
|
||||||
drawJob(x, y)
|
drawJob(x, y)
|
||||||
|
|||||||
@@ -7,10 +7,29 @@ in vec2 v_texCoords;
|
|||||||
|
|
||||||
uniform sampler2D u_texture; // world texture, has alpha value that is meaningful
|
uniform sampler2D u_texture; // world texture, has alpha value that is meaningful
|
||||||
uniform float acount = 2.0;
|
uniform float acount = 2.0;
|
||||||
|
uniform int frame = 0;
|
||||||
|
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
const int bayer[4 * 4] = int[](0,8,2,10,12,4,14,6,3,11,1,9,15,7,13,5);
|
const int bayer[4 * 4] = int[](0,8,2,10,12,4,14,6,3,11,1,9,15,7,13,5);
|
||||||
|
const vec2 bayerOffset[4 * 4] = vec2[](
|
||||||
|
vec2(0,0),
|
||||||
|
vec2(3,2),
|
||||||
|
vec2(1,3),
|
||||||
|
vec2(3,0),
|
||||||
|
vec2(1,1),
|
||||||
|
vec2(2,3),
|
||||||
|
vec2(0,2),
|
||||||
|
vec2(2,1),
|
||||||
|
vec2(3,3),
|
||||||
|
vec2(1,0),
|
||||||
|
vec2(3,1),
|
||||||
|
vec2(0,3),
|
||||||
|
vec2(2,2),
|
||||||
|
vec2(0,1),
|
||||||
|
vec2(2,0),
|
||||||
|
vec2(1,2)
|
||||||
|
);
|
||||||
const float bayerSize = 4.0;
|
const float bayerSize = 4.0;
|
||||||
const float bayerDivider = bayerSize * bayerSize;
|
const float bayerDivider = bayerSize * bayerSize;
|
||||||
|
|
||||||
@@ -20,7 +39,9 @@ float nearestAlpha(float alpha) {
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec4 inColor = texture(u_texture, v_texCoords) * v_color;
|
vec4 inColor = texture(u_texture, v_texCoords) * v_color;
|
||||||
vec2 entry = mod(gl_FragCoord.xy, vec2(bayerSize, bayerSize));
|
vec2 entryOffset = bayerOffset[int(mod(frame, bayerDivider))];
|
||||||
|
vec2 entry = mod(gl_FragCoord.xy + entryOffset, vec2(bayerSize, bayerSize));
|
||||||
|
|
||||||
|
|
||||||
float alpha = nearestAlpha((inColor.a * 16.0 / 15.0) + (bayer[int(entry.y) * int(bayerSize) + int(entry.x)] / bayerDivider - 0.5));
|
float alpha = nearestAlpha((inColor.a * 16.0 / 15.0) + (bayer[int(entry.y) * int(bayerSize) + int(entry.x)] / bayerDivider - 0.5));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user