From 120a70cf42cd790b575c2741d752004218152709 Mon Sep 17 00:00:00 2001 From: nefrace Date: Wed, 14 May 2025 23:26:47 +0300 Subject: [PATCH] Dithering --- assets/gfx/bluem0ld-1x.png | Bin 0 -> 82 bytes assets/gfx/fiery-plague-gb-1x.png | Bin 0 -> 82 bytes assets/gfx/look-of-horror-1x.png | Bin 0 -> 82 bytes assets/shaders/postprocess.glsl | 14 +++++++++++- house/main.odin | 36 +++++++++++++++++++----------- 5 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 assets/gfx/bluem0ld-1x.png create mode 100644 assets/gfx/fiery-plague-gb-1x.png create mode 100644 assets/gfx/look-of-horror-1x.png diff --git a/assets/gfx/bluem0ld-1x.png b/assets/gfx/bluem0ld-1x.png new file mode 100644 index 0000000000000000000000000000000000000000..81b9955eaf0d35e76ce36c3c18a18f795fd096ec GIT binary patch literal 82 zcmeAS@N?(olHy`uVBq!ia0vp^EI`c2!3HFM+VGzRQj(r7jv*C{$y26G`=!4i@ALxk gr)M54(LTw*AiIuP>_C;zCZHk)Pgg&ebxsLQ00Bc5#{d8T literal 0 HcmV?d00001 diff --git a/assets/gfx/fiery-plague-gb-1x.png b/assets/gfx/fiery-plague-gb-1x.png new file mode 100644 index 0000000000000000000000000000000000000000..e4804dac45d73ca37d3d064637f3593c7203ba8e GIT binary patch literal 82 zcmeAS@N?(olHy`uVBq!ia0vp^EI`c2!3HFM+VGzRQj(r7jv*C{$y0)^{Lw#m;P`?A g=Z-8maPlAngIE^hlOv_k3P42+p00i_>zopr04voPIsgCw literal 0 HcmV?d00001 diff --git a/assets/gfx/look-of-horror-1x.png b/assets/gfx/look-of-horror-1x.png new file mode 100644 index 0000000000000000000000000000000000000000..fbea2c2f71a24783d73615be6553e44258111f8c GIT binary patch literal 82 zcmeAS@N?(olHy`uVBq!ia0vp^EI`c2!3HFM+VGzRQj(r7jv*C{$xnhV{9k`8`>epf ge_YM{=lR(fG(1_27Gx#d1}b9kboFyt=akR{0Q`RzHUIzs literal 0 HcmV?d00001 diff --git a/assets/shaders/postprocess.glsl b/assets/shaders/postprocess.glsl index 8f6a90b..9e1fd3a 100644 --- a/assets/shaders/postprocess.glsl +++ b/assets/shaders/postprocess.glsl @@ -15,13 +15,25 @@ uniform vec4 colDiffuse; out vec4 finalColor; +const int bayer16[16] = int[16](0, 8, 2, 10, + 12, 4, 14, 6, + 3, 11, 1, 9, + 15, 7, 13, 5); + + void main() { vec4 texelColor = texture(texture0, fragTexCoord); float grey = 0.21 * texelColor.r + 0.71 * texelColor.g + 0.07 * texelColor.b ; + int col = int(mod(gl_FragCoord.x, 4)); + int row = int(mod(gl_FragCoord.y, 4)); + float threshold = float(bayer16[col + 4 * row]) / 16.0 - 0.5; + grey = clamp(grey + threshold * 0.04 + 0.15 , 0.01, 0.99); + vec2 paluv = vec2(grey, 0.5); vec4 paletteValue = texture(texture1, paluv); - finalColor.a = 1.0; + // finalColor.rgb = vec3(floor(grey * POSTERIZE) / POSTERIZE ); + // finalColor.rgb = floor(texelColor.rgb * POSTERIZE) / POSTERIZE; finalColor.rgb = paletteValue.rgb; diff --git a/house/main.odin b/house/main.odin index 70f9324..86ac6cf 100644 --- a/house/main.odin +++ b/house/main.odin @@ -51,10 +51,11 @@ main :: proc() { w, h := rl.GetScreenWidth(), rl.GetScreenHeight() - pixelize: i32 = 2 + pixelize: i32 = 3 target := rl.LoadRenderTexture(w / pixelize, h / pixelize) + posttarget := rl.LoadRenderTexture(w / pixelize, h / pixelize) - palette := rl.LoadTexture("assets/gfx/blood-crow-1x.png") + palette := rl.LoadTexture("assets/gfx/bluem0ld-1x.png") rl.SetTextureFilter(palette, .POINT) @@ -145,6 +146,8 @@ main :: proc() { w, h = rl.GetScreenWidth(), rl.GetScreenHeight() rl.UnloadRenderTexture(target) target = rl.LoadRenderTexture(w / pixelize, h / pixelize) + rl.UnloadRenderTexture(posttarget) + posttarget = rl.LoadRenderTexture(w / pixelize, h / pixelize) } rl.UpdateCamera(&cam, .FIRST_PERSON) delta := rl.GetFrameTime() @@ -197,27 +200,34 @@ main :: proc() { rl.EndShaderMode() rl.EndMode3D() rl.EndTextureMode() - rl.BeginDrawing() + // rl.BeginDrawing() + rl.BeginTextureMode(posttarget) rl.BeginShaderMode(posterizer) rl.SetShaderValueTexture(posterizer, poster_palette, palette) - rl.DrawTexturePro( - target.texture, - rl.Rectangle{0, f32(h / pixelize), f32(w / pixelize), -f32(h / pixelize)}, - {0, 0, f32(w), f32(h)}, - {}, - 0, - rl.WHITE, - ) // rl.DrawTexturePro( - // target.depth, + // target.texture, // rl.Rectangle{0, f32(h / pixelize), f32(w / pixelize), -f32(h / pixelize)}, // {0, 0, f32(w), f32(h)}, // {}, // 0, // rl.WHITE, // ) + rl.DrawTexture(target.texture, 0, 0, rl.WHITE) rl.EndShaderMode() - // rl.DrawTexture(palette, 0, 0, rl.WHITE) + rl.EndTextureMode() + + rl.BeginDrawing() + // rl.BeginTextureMode(posttarget) + // rl.BeginShaderMode(posterizer) + // rl.SetShaderValueTexture(posterizer, poster_palette, palette) + rl.DrawTexturePro( + posttarget.texture, + rl.Rectangle{0, 0, f32(w / pixelize), f32(h / pixelize)}, + {0, 0, f32(w), f32(h)}, + {}, + 0, + rl.WHITE, + ) rl.EndDrawing() } }