diff --git a/src/game/Entity.h b/src/game/Entity.h index c1e1745..7df44b3 100644 --- a/src/game/Entity.h +++ b/src/game/Entity.h @@ -3,8 +3,10 @@ #include "../gen/Generated.h" #include "Log.h" #include "Puzzle.h" // TODO: remove +#include "bgfx/bgfx.h" #include "rendering/Rendering.h" #include +#include #define ENTITY_HANDLE(X) \ struct X \ @@ -27,6 +29,7 @@ namespace Game Gen::TextureHandle TextureHandle; Gen::ModelHandle ModelH; bool Visible = true; + bool DebugBreakOnRender = false; void Render(const Model* models, const Material* materials, const Texture* textures); void LoadFromSaved(const Gen::SavedEntityRenderData& saved); @@ -140,6 +143,7 @@ namespace Game void Render(const Model* models, const Material* materials, const Texture* textures) { if (!IsEnabled) return; + bgfx::setMarker(typeid(T).name()); for (uint16_t i = 0; i < Count; ++i) { Get({i}).EData.Render(models, materials, textures); diff --git a/src/game/Level.cpp b/src/game/Level.cpp index 7ee610d..59bfb6e 100644 --- a/src/game/Level.cpp +++ b/src/game/Level.cpp @@ -8,6 +8,7 @@ #include "Puzzle.h" #include "UI.h" #include "bx/bx.h" +#include "bx/debug.h" #include "rendering/Rendering.h" #include "SDL3/SDL_mouse.h" @@ -28,6 +29,7 @@ namespace Game { void EntityRenderData::Render(const Model* models, const Material* materials, const Texture* textures) { + if (DebugBreakOnRender) bx::debugBreak(); if (models == nullptr || materials == nullptr || textures == nullptr) return; if (!Gen::IsValid(ModelH) || MaterialHandle >= EMaterial::EntryCount) return; if (!Visible) return; diff --git a/src/game/UI.cpp b/src/game/UI.cpp index 7fce876..ba23257 100644 --- a/src/game/UI.cpp +++ b/src/game/UI.cpp @@ -131,7 +131,6 @@ namespace Game quad.EData.TextureHandle = Puzzle::IsValid(card.RefCard) ? staticCards[card.RefCard.Idx].BoardTextureHandle : Gen::TextureHandle{0}; - quad.EData.TextureHandle = {4}; quad.EData.Transform.Scale = {UICardScale, UICardScale, UICardScale}; quad.EData.DotColor = {1.0f, 1.0f, 1.0f, 1.0f}; quad.EData.BaseColor = {1.0f, 1.0f, 1.0f, 1.0f}; diff --git a/src/game/compiled-shaders/dx11/dither/frag.bin b/src/game/compiled-shaders/dx11/dither/frag.bin index 5d9744c..1522cb9 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:56bdab695a0cbe39c7b9ac5be8017f0e0483b9fd5d89dde934a199b1e5002571 -size 3899 +oid sha256:bb2b2a268ed60a1fed7d70ea01fd49707252b503dc2786a7bc664537dd6867e3 +size 3923 diff --git a/src/game/compiled-shaders/dx11/dither/vert.bin b/src/game/compiled-shaders/dx11/dither/vert.bin index aa2065a..7ff93f5 100644 --- a/src/game/compiled-shaders/dx11/dither/vert.bin +++ b/src/game/compiled-shaders/dx11/dither/vert.bin @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:94e8596a84796ff4bc78d6112218cf3e4eb7656df839f511973a5624184e42fc -size 1410 +oid sha256:c38fba1a9ca80a3701e6bd34613df6735cef6c2e56b456d48f0fae7dbf20b4f4 +size 1482 diff --git a/src/game/compiled-shaders/dx11/normal/vert.bin b/src/game/compiled-shaders/dx11/normal/vert.bin index aa2065a..fe563c6 100644 --- a/src/game/compiled-shaders/dx11/normal/vert.bin +++ b/src/game/compiled-shaders/dx11/normal/vert.bin @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:94e8596a84796ff4bc78d6112218cf3e4eb7656df839f511973a5624184e42fc -size 1410 +oid sha256:d91fbffad30408534c24db576606e618b553832a20bb98a7693129794b31c549 +size 1482 diff --git a/src/game/compiled-shaders/glsl/dither/frag.bin b/src/game/compiled-shaders/glsl/dither/frag.bin new file mode 100644 index 0000000..9941a31 --- /dev/null +++ b/src/game/compiled-shaders/glsl/dither/frag.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1c5e5755ec618e6575805bfd812444d5bd2dc5434a6c3b79419b1a01fd84e5c8 +size 13291 diff --git a/src/game/compiled-shaders/glsl/dither/vert.bin b/src/game/compiled-shaders/glsl/dither/vert.bin new file mode 100644 index 0000000..8e42390 --- /dev/null +++ b/src/game/compiled-shaders/glsl/dither/vert.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b1aa4c030ee631fdb7df2230e92399302f6aab9153bdc3ceeb2c87c65bb4c8be +size 10657 diff --git a/src/game/compiled-shaders/glsl/normal/frag.bin b/src/game/compiled-shaders/glsl/normal/frag.bin new file mode 100644 index 0000000..8c177da --- /dev/null +++ b/src/game/compiled-shaders/glsl/normal/frag.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6cf01736bdc26b122556df50dfc22c2c68a3c78de43d3900d2f532a0143a3216 +size 12871 diff --git a/src/game/compiled-shaders/glsl/normal/vert.bin b/src/game/compiled-shaders/glsl/normal/vert.bin new file mode 100644 index 0000000..4820fd0 --- /dev/null +++ b/src/game/compiled-shaders/glsl/normal/vert.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0aad4aeea01c570517588b890b104ae6c977efb5aef14530ae4afba258f84692 +size 10657 diff --git a/src/game/data/puzzles/0.pzl b/src/game/data/puzzles/0.pzl index 37a50cc..72a394c 100644 --- a/src/game/data/puzzles/0.pzl +++ b/src/game/data/puzzles/0.pzl @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:46c1b936610d5d90fa7138d2ed06835a2deaf41fec7f16359953560cd56aafa0 +oid sha256:2144b5b8885d119aa1432060595728b0628a828a2115fb3d41099fccbb765363 size 11416 diff --git a/src/game/rendering/Rendering.cpp b/src/game/rendering/Rendering.cpp index 15a9022..c916982 100644 --- a/src/game/rendering/Rendering.cpp +++ b/src/game/rendering/Rendering.cpp @@ -325,7 +325,7 @@ namespace Game SharedData& shared = GetShared(); bgfx::Init init; - init.type = bgfx::RendererType::Direct3D12; + init.type = bgfx::RendererType::Direct3D11; #ifdef _DEBUG init.debug = true; // init.debug = false; diff --git a/src/game/shaders/dither/frag.sc b/src/game/shaders/dither/frag.sc index 192f72d..8ab72d8 100644 --- a/src/game/shaders/dither/frag.sc +++ b/src/game/shaders/dither/frag.sc @@ -42,19 +42,19 @@ float dither(float brightness, vec2 inputUv) float zRes = dotsTotal; float invZRes = 1 / zRes; - float2 rampLookupUv = vec2((0.5 * invXRes + (1 - invXRes) * brightness), 0.5); + vec2 rampLookupUv = vec2((0.5 * invXRes + (1 - invXRes) * brightness), 0.5); float brightnessCurve = texture2D(s_rampSampler, rampLookupUv).r; // Magic dot frequency calculation - float2 dx = ddx(inputUv); - float2 dy = ddy(inputUv); - float2x2 mat = float2x2(dx, dy); - float4 vectorized = float4(dx, dy); + vec2 dx = dFdx(inputUv); + vec2 dy = dFdy(inputUv); + mat2 mat = mat2(dx, dy); + vec4 vectorized = vec4(dx, dy); float qq = dot(vectorized, vectorized); float rr = determinant(mat); float discriminantSqr = max(0.0, qq*qq - 4.0*rr*rr); float discriminant = sqrt(discriminantSqr); - float2 freq = sqrt(float2(qq + discriminant, qq - discriminant) / 2.0); + vec2 freq = sqrt(vec2(qq + discriminant, qq - discriminant) / 2.0); // Figuring out how many dots we want float scaleExp = exp2(globalScale); @@ -66,7 +66,7 @@ float dither(float brightness, vec2 inputUv) spacing *= brightnessSpacingMultiplier; float spacingLog = log2(spacing); - int patternScaleLevel = floor(spacingLog); + int patternScaleLevel = int(floor(spacingLog)); float patternFractional = spacingLog - patternScaleLevel; vec2 uv = inputUv / exp2(patternScaleLevel); @@ -91,7 +91,7 @@ void main() float testRadius = 30.0; float testSpeed = 1.0; vec3 testOffset = vec3(0.0, 0.0, 50.0); - float3 lightPos = vec3(sin(u_time.x * testSpeed) * testRadius, 5.0, cos(u_time.x * testSpeed) * testRadius); + 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; // lighting @@ -103,9 +103,9 @@ void main() float r = dither(brightness * texColor.r, v_uv0); float g = dither(brightness * texColor.g, v_uv0); float b = dither(brightness * texColor.b, v_uv0); - // float3 finalColor = vec3(r, g, b); - float3 ditheredColor = dither(brightness, v_uv0); - float3 finalColor = mix(u_baseColor, texColor, ditheredColor); + // 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); } diff --git a/src/game/shaders/dither/vert.sc b/src/game/shaders/dither/vert.sc index 858e11b..2ecf038 100644 --- a/src/game/shaders/dither/vert.sc +++ b/src/game/shaders/dither/vert.sc @@ -9,5 +9,5 @@ void main() v_color0 = a_color0; v_uv0 = a_texcoord0; v_wpos = mul(u_model[0], vec4(a_position, 1.0)).xyz; - v_normal = normalize(mul(u_model[0], a_normal)); + v_normal = normalize(mul(u_model[0], vec4(a_normal, 1.0)).xyz); } diff --git a/src/game/shaders/normal/frag.sc b/src/game/shaders/normal/frag.sc index 79dd135..bae4229 100644 --- a/src/game/shaders/normal/frag.sc +++ b/src/game/shaders/normal/frag.sc @@ -42,19 +42,19 @@ float dither(float brightness, vec2 inputUv) float zRes = dotsTotal; float invZRes = 1 / zRes; - float2 rampLookupUv = vec2((0.5 * invXRes + (1 - invXRes) * brightness), 0.5); + vec2 rampLookupUv = vec2((0.5 * invXRes + (1 - invXRes) * brightness), 0.5); float brightnessCurve = texture2D(s_rampSampler, rampLookupUv).r; // Magic dot frequency calculation - float2 dx = ddx(inputUv); - float2 dy = ddy(inputUv); - float2x2 mat = float2x2(dx, dy); - float4 vectorized = float4(dx, dy); + vec2 dx = dFdx(inputUv); + vec2 dy = dFdy(inputUv); + mat2 mat = mat2(dx, dy); + vec4 vectorized = vec4(dx, dy); float qq = dot(vectorized, vectorized); float rr = determinant(mat); float discriminantSqr = max(0.0, qq*qq - 4.0*rr*rr); float discriminant = sqrt(discriminantSqr); - float2 freq = sqrt(float2(qq + discriminant, qq - discriminant) / 2.0); + vec2 freq = sqrt(vec2(qq + discriminant, qq - discriminant) / 2.0); // Figuring out how many dots we want float scaleExp = exp2(globalScale); @@ -66,7 +66,7 @@ float dither(float brightness, vec2 inputUv) spacing *= brightnessSpacingMultiplier; float spacingLog = log2(spacing); - int patternScaleLevel = floor(spacingLog); + int patternScaleLevel = int(floor(spacingLog)); float patternFractional = spacingLog - patternScaleLevel; vec2 uv = inputUv / exp2(patternScaleLevel); diff --git a/src/game/shaders/normal/vert.sc b/src/game/shaders/normal/vert.sc index 858e11b..0709593 100644 --- a/src/game/shaders/normal/vert.sc +++ b/src/game/shaders/normal/vert.sc @@ -9,5 +9,5 @@ void main() v_color0 = a_color0; v_uv0 = a_texcoord0; v_wpos = mul(u_model[0], vec4(a_position, 1.0)).xyz; - v_normal = normalize(mul(u_model[0], a_normal)); + v_normal = normalize(mul(u_model[0], vec4(a_normal, 0.0)).xyz); } diff --git a/src/shadercompile.ps1 b/src/shadercompile.ps1 index 8c6aa54..025aa11 100644 --- a/src/shadercompile.ps1 +++ b/src/shadercompile.ps1 @@ -3,15 +3,21 @@ $shadersDir = ".\game\shaders" $outputBaseDir = ".\game\compiled-shaders" $includeDir = ".\dependency\bgfx.cmake\bgfx\src" +function CompileForAPI { + param ([string]$API, [string]$ShaderProfile) + $outDir = "$outputBaseDir\$API\$DirectoryName" + New-Item -ItemType Directory -Path $outDir -Force -ErrorAction Stop | Out-Null + Write-Host "Frag: $API $ShaderProfile" + & $shadercPath -f "$DirectoryFull\vert.sc" -o "$outDir\vert.bin" -i $includeDir --type v --platform windows --profile $ShaderProfile + Write-Host "Vert: $API $ShaderProfile" + & $shadercPath -f "$DirectoryFull\frag.sc" -o "$outDir\frag.bin" -i $includeDir --type f --platform windows --profile $ShaderProfile +} + function Process-Directory { param ([string]$DirectoryFull, [string]$DirectoryName) Write-Host "Dir: $DirectoryName" - $outDir = "$outputBaseDir\dx11\$DirectoryName" - New-Item -ItemType Directory -Path $outDir -Force -ErrorAction Stop | Out-Null - Write-Host "Frag" - & $shadercPath -f "$DirectoryFull\vert.sc" -o "$outDir\vert.bin" -i $includeDir --type v --platform windows --profile s_5_0 - Write-Host "Vert" - & $shadercPath -f "$DirectoryFull\frag.sc" -o "$outDir\frag.bin" -i $includeDir --type f --platform windows --profile s_5_0 + CompileForAPI -API "dx11" -ShaderProfile "s_5_0" + CompileForAPI -API "glsl" -ShaderProfile "430" } $subdirectories = Get-ChildItem -Path $shadersDir -Directory -Recurse -ErrorAction Stop diff --git a/tools/minidef.exe b/tools/minidef.exe index 65f6b1b..77a0bc1 100644 --- a/tools/minidef.exe +++ b/tools/minidef.exe @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6f1ea8f1d8ea97e9a6ba272f6553e8b6cab415aa9384e7e028d7157d3ada3bec -size 217600 +oid sha256:f91d7e94592728777e6fde5a595e9179b26d9e61985e9434dcad8a92b03b158d +size 154112 diff --git a/tools/shaderc.exe b/tools/shaderc.exe index 422c68e..40d2fac 100644 --- a/tools/shaderc.exe +++ b/tools/shaderc.exe @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1415f006605ce1635950f57425164d308d9ce2e9222e4a2a50d33ce91d093384 -size 10283520 +oid sha256:51ed2f7ec5c1c1cc2ac10b7a7c4a042a40e32ffe41450d7c955fd2be29821cb0 +size 13214720 diff --git a/tools/texturec.exe b/tools/texturec.exe index cfb0da2..e493d7e 100644 --- a/tools/texturec.exe +++ b/tools/texturec.exe @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2b6984090d535c0293088f0a84fd9163b8707382a68c3286b801b4018992089c -size 1457152 +oid sha256:6b87635c6921cc2512ddf9b91a761e18d2040e07c37a372ffdd448bac0720061 +size 1454592