From 6c8bead6ab5f00175bf78e7a1fcc47c723de92a1 Mon Sep 17 00:00:00 2001 From: Asuro Date: Sun, 1 Jun 2025 03:17:21 +0200 Subject: [PATCH] new dithering --- src/debug.ps1 | 2 + src/game/Level.cpp | 1 + src/game/Tools.cpp | 82 ++++++++++-------- .../compiled-shaders/dx11/dither/frag.bin | 4 +- .../compiled-shaders/glsl/dither/frag.bin | 4 +- src/game/data/static/puzzle.dat | Bin 19109 -> 19109 bytes src/game/data/static/uiconfig.dat | Bin 13984 -> 13984 bytes src/game/shaders/dither/frag.sc | 56 ++++++++---- tools/radsession.rad | 3 +- 9 files changed, 92 insertions(+), 60 deletions(-) create mode 100644 src/debug.ps1 diff --git a/src/debug.ps1 b/src/debug.ps1 new file mode 100644 index 0000000..ec8e382 --- /dev/null +++ b/src/debug.ps1 @@ -0,0 +1,2 @@ +.\build.ps1 +& raddbg.exe --ipc run diff --git a/src/game/Level.cpp b/src/game/Level.cpp index 23dd6ef..d4d6fee 100644 --- a/src/game/Level.cpp +++ b/src/game/Level.cpp @@ -402,6 +402,7 @@ namespace Game // World Tile tile.EData.Visible = IsActive; tile.EData.ModelH = staticCard.BaseModelHandle; + tile.EData.TextureHandle = staticCard.ModelTextureHandle; tile.EData.DotColor = visuals.TileDotColor; tile.EData.BaseColor = visuals.TileBaseColor; diff --git a/src/game/Tools.cpp b/src/game/Tools.cpp index 3f725f7..4f85842 100644 --- a/src/game/Tools.cpp +++ b/src/game/Tools.cpp @@ -289,14 +289,15 @@ namespace Tools ImGui::Separator(); - ImGui::Text("Entity Groups"); - ImGui::Checkbox("Cubes", &level.Cubes.IsEnabled); - ImGui::Checkbox("Tests", &level.Tests.IsEnabled); - ImGui::Checkbox("PuzzleTiles", &level.PuzzleTiles.IsEnabled); - ImGui::Checkbox("UIQuads", &level.UIQuads.IsEnabled); - ImGui::Checkbox("Level", &level.LevelEntities.IsEnabled); - - ImGui::Separator(); + if (ImGui::TreeNodeEx("Entity Groups")) + { + ImGui::Checkbox("Cubes", &level.Cubes.IsEnabled); + ImGui::Checkbox("Tests", &level.Tests.IsEnabled); + ImGui::Checkbox("PuzzleTiles", &level.PuzzleTiles.IsEnabled); + ImGui::Checkbox("UIQuads", &level.UIQuads.IsEnabled); + ImGui::Checkbox("Level", &level.LevelEntities.IsEnabled); + ImGui::TreePop(); + } bool uiconfigChanged = false; if (ImGui::TreeNodeEx("Game Tablet")) @@ -334,38 +335,42 @@ namespace Tools level.ReloadLevelEntities(); } - ImGui::Separator(); + if (ImGui::TreeNodeEx("Dithering")) + { + if (ImGui::Button("Dithergen")) + { + DitherGen(rendering.DitherTextures, rendering.DitherRecursion); + } + ImGui::SameLine(); + ImGui::SliderInt("Recursion", &rendering.DitherRecursion, 1, 4); + ImGui::Text("%ux%ux%u", + rendering.DitherTextures.DitherTexWH, + rendering.DitherTextures.DitherTexWH, + rendering.DitherTextures.DitherTexDepth); + if (!isValid(rendering.DitherTextures.PreviewTex)) + { + ImGui::Text("Invalid Texture"); + } + else + { + ImGui::Image( + rendering.DitherTextures.PreviewTex.idx, + {(float)rendering.DitherTextures.DitherTexWH, + (float)rendering.DitherTextures.DitherTexWH * rendering.DitherTextures.DitherTexDepth}); + } + if (isValid(rendering.DitherTextures.RampTex)) + { + ImGui::Image(rendering.DitherTextures.RampTex.idx, + {BX_COUNTOF(rendering.DitherTextures.BrightnessRamp), 8}); + } + ImGui::TreePop(); + } - if (ImGui::Button("Dithergen")) + if (ImGui::TreeNodeEx("Shader log")) { - DitherGen(rendering.DitherTextures, rendering.DitherRecursion); + ImGui::TextWrapped("%s", Game::GetShared().Dev.ShaderLog); + ImGui::TreePop(); } - ImGui::SameLine(); - ImGui::SliderInt("Recursion", &rendering.DitherRecursion, 1, 4); - ImGui::Text("%ux%ux%u", - rendering.DitherTextures.DitherTexWH, - rendering.DitherTextures.DitherTexWH, - rendering.DitherTextures.DitherTexDepth); - if (!isValid(rendering.DitherTextures.PreviewTex)) - { - ImGui::Text("Invalid Texture"); - } - else - { - ImGui::Image(rendering.DitherTextures.PreviewTex.idx, - {(float)rendering.DitherTextures.DitherTexWH, - (float)rendering.DitherTextures.DitherTexWH * rendering.DitherTextures.DitherTexDepth}); - } - if (isValid(rendering.DitherTextures.RampTex)) - { - ImGui::Image(rendering.DitherTextures.RampTex.idx, - {BX_COUNTOF(rendering.DitherTextures.BrightnessRamp), 8}); - } - Vec3 quadPos = level.UIQuads.Get({0}).EData.Transform.Position; - ImGui::Text("%f %f %f", quadPos.x, quadPos.y, quadPos.z); - - ImGui::Text("Shader log:"); - ImGui::TextWrapped("%s", Game::GetShared().Dev.ShaderLog); } ImGui::End(); } @@ -464,7 +469,8 @@ namespace Tools } Tools::ModelDropdown(card.BaseModelHandle); - Tools::TextureDropdown(card.BoardTextureHandle); + Tools::TextureDropdown(card.ModelTextureHandle, "World Texture"); + Tools::TextureDropdown(card.BoardTextureHandle, "UI Texture"); if (IsValid(card.BaseModelHandle)) { auto& mdl = rendering.Models[card.BaseModelHandle.ModelIdx]; diff --git a/src/game/compiled-shaders/dx11/dither/frag.bin b/src/game/compiled-shaders/dx11/dither/frag.bin index 1522cb9..a323aac 100644 --- a/src/game/compiled-shaders/dx11/dither/frag.bin +++ b/src/game/compiled-shaders/dx11/dither/frag.bin @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bb2b2a268ed60a1fed7d70ea01fd49707252b503dc2786a7bc664537dd6867e3 -size 3923 +oid sha256:d3e248466275e5c0a99c9704d3df112a8de305259dbb2dd5d65387fbcc5cd10a +size 9407 diff --git a/src/game/compiled-shaders/glsl/dither/frag.bin b/src/game/compiled-shaders/glsl/dither/frag.bin index 9941a31..9e42ee1 100644 --- a/src/game/compiled-shaders/glsl/dither/frag.bin +++ b/src/game/compiled-shaders/glsl/dither/frag.bin @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1c5e5755ec618e6575805bfd812444d5bd2dc5434a6c3b79419b1a01fd84e5c8 -size 13291 +oid sha256:9a0a87773eea48bf63115c4c769e0d8eb98190ba1af36dfc73bad98caae21f65 +size 13825 diff --git a/src/game/data/static/puzzle.dat b/src/game/data/static/puzzle.dat index 16a58bb330da751a5d4a18e77b371a1a2ec50b7b..006576113dea2f338ff67c9e69de6c701cab139b 100644 GIT binary patch delta 110 zcmZ2Fm2v4*#tqfVf=mp|oGGgR!GM8*nVD~Lk8&>?M0B#e$_yBDugVNDh$t6BS!T~- t1||juUWORHm=lv5H9B}8Qk)Dw*Kls!9H=Fsu=%}K7|X;`jmcBJ1OPK?AZq{s delta 116 zcmZ2Fm2v4*#tqfVlNFTNCi81@Ff%jrPVQ0e1@q-qW`OCv5L$qXp)9j!F#{6=10RFr zyubSeyY diff --git a/src/game/data/static/uiconfig.dat b/src/game/data/static/uiconfig.dat index 50b15c9a734d03f6d93c5ce691c115bb52656bcb..f11645f2647bf5554a4ccfb84ecc8f56d04a2c4f 100644 GIT binary patch delta 88 zcmZ3GyC8RifSOEa2ZvokH?!T3E1PT?7#i%g-y7M3=oKq8>?c1ocANacWPuzz!|Afe gdl?x}K!d%pOQ!wi`NfmvR68ecP)ph@tk7`5yiJ7w({7#i$%?$}{Bf1aHE@@32HCO9WUr8GrCb+d0a{+ij9u1Xi11x85$Fg~wiDftNi@?Ph6>Rz3jFA0#dS diff --git a/src/game/shaders/dither/frag.sc b/src/game/shaders/dither/frag.sc index 8ab72d8..e010f96 100644 --- a/src/game/shaders/dither/frag.sc +++ b/src/game/shaders/dither/frag.sc @@ -32,7 +32,7 @@ vec3 desaturate(vec3 color) float dither(float brightness, vec2 inputUv) { - float globalScale = 8; + float globalScale = 6; // constants float xRes = u_texInfo.z; @@ -59,10 +59,9 @@ float dither(float brightness, vec2 inputUv) // Figuring out how many dots we want float scaleExp = exp2(globalScale); float spacing = freq.y * scaleExp; - spacing *= dotsPerSide * 0.125; + spacing *= dotsPerSide * (1 / globalScale); // todo: just guessed that globalScale is the right variable here float brightnessSpacingMultiplier = pow(brightnessCurve * 2 + 0.001, -(1 - 0.5)); - // float brightnessSpacingMultiplier = 1; spacing *= brightnessSpacingMultiplier; float spacingLog = log2(spacing); @@ -77,35 +76,58 @@ float dither(float brightness, vec2 inputUv) float pattern = texture3D(s_ditherSampler, vec3(uv, subLayer)).r; - float contrast = 2 * scaleExp * brightnessSpacingMultiplier * 0.1; + float contrast = 0.5 * scaleExp * brightnessSpacingMultiplier * 0.1; contrast *= pow(freq.y / freq.x, 1.0); float baseVal = lerp(0.5, brightness, saturate(1.05 / (1 + contrast))); - float threshold = 1 - brightnessCurve + 0.6; + float threshold = 1 - brightnessCurve; return saturate((pattern - threshold) * contrast + baseVal); } +vec4 rgbToCmyk(vec3 rgb) +{ + return vec4(1.0, 1.0, 1.0, 1.0); +} + +vec3 cmykToRgb(vec4 cmyk) +{ + return vec3(1.0, 1.0, 1.0); +} + +vec2 rotateUV(vec2 uv, vec2 angle) +{ + return uv; +} + void main() { // setup + bool isTextured = u_dotColor.x < 0.02; float testRadius = 30.0; float testSpeed = 1.0; vec3 testOffset = vec3(0.0, 0.0, 50.0); vec3 lightPos = vec3(sin(u_time.x * testSpeed) * testRadius, 5.0, cos(u_time.x * testSpeed) * testRadius); - vec3 texColor = u_dotColor.x > 0.1 ? u_dotColor.xyz : texture2D(s_texColor, v_uv0).xyz; + vec3 baseColor = u_baseColor.xyz; + vec3 texColor = isTextured ? texture2D(s_texColor, v_uv0).xyz : u_dotColor.xyz; // lighting - // float brightness = calcBrightness(lightPos, v_wpos, v_normal); - float brightness = lerp(0.5, 0.9, calcBrightnessDirectional(vec3(0.5, 0.3, 1.0), v_normal)); - // float brightness = 0.5; - // brightness = lerp(0.2, 1.0, sin(u_time.x) * 0.5 + 0.5); + float brightness = lerp(0.2, 0.8, calcBrightnessDirectional(vec3(0.5, 0.3, 1.0), v_normal)); - float r = dither(brightness * texColor.r, v_uv0); - float g = dither(brightness * texColor.g, v_uv0); - float b = dither(brightness * texColor.b, v_uv0); - // vec3 finalColor = vec3(r, g, b); - vec3 ditheredColor = dither(brightness, v_uv0); - vec3 finalColor = mix(u_baseColor, texColor, ditheredColor); - gl_FragColor = vec4(finalColor, 1.0); + // dither + float r = dither(texColor.r * brightness, v_uv0); + float g = dither(texColor.g * brightness, v_uv0); + float b = dither(texColor.b * brightness, v_uv0); + vec3 ditheredColor = vec3(r,g,b); + + vec4 cmyk = rgbToCmyk(texColor * brightness); + cmyk.x = dither(cmyk.x, rotateUV(v_uv0, float2(0.966, 0.259))); + cmyk.y = dither(cmyk.y, rotateUV(v_uv0, float2(0.259, 0.966))); + cmyk.z = dither(cmyk.z, rotateUV(v_uv0, float2(1.000, 0.000))); + cmyk.w = dither(cmyk.w, rotateUV(v_uv0, float2(0.707, 0.707))); + // vec3 ditheredColor = cmykToRgb(cmyk); + // finalize + vec3 finalColor = mix(baseColor, ditheredColor, ditheredColor); + gl_FragColor = vec4(finalColor, 1.0); + // gl_FragColor = vec4(texColor * brightness, 1.0); } diff --git a/tools/radsession.rad b/tools/radsession.rad index fccb158..d818af7 100644 --- a/tools/radsession.rad +++ b/tools/radsession.rad @@ -1,12 +1,13 @@ // raddbg 0.9.19 project file +recent_file: path: "../src/game/rendering/dither.cpp" +recent_file: path: "../src/game/rendering/rendering.cpp" recent_file: path: "../src/game/entity.h" recent_file: path: "../src/game/level.cpp" recent_file: path: "../src/game/ui.cpp" recent_file: path: "../src/gen/generated.cpp" recent_file: path: "../src/engine/main.cpp" recent_file: path: "../src/game/setup.cpp" -recent_file: path: "../src/game/rendering/rendering.cpp" recent_file: path: "../src/dependency/imgui/imgui_widgets.cpp" recent_file: path: "../src/game/tools.cpp" recent_file: path: "../src/dependency/bgfx.cmake/bx/src/debug.cpp"