diff --git a/.gitattributes b/.gitattributes index b259806..c423759 100644 --- a/.gitattributes +++ b/.gitattributes @@ -7,3 +7,4 @@ *.pzl filter=lfs diff=lfs merge=lfs -text *.exe filter=lfs diff=lfs merge=lfs -text *.glb filter=lfs diff=lfs merge=lfs -text +*.ktx filter=lfs diff=lfs merge=lfs -text diff --git a/assets/textures/test.png b/assets/textures/test.png new file mode 100644 index 0000000..4e8f70b --- /dev/null +++ b/assets/textures/test.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d8aa4a1c47291d80f0e85c60433ce5910c55a2a951c04ce21b598e67fdc9f8e7 +size 114814 diff --git a/src/assetcompile.ps1 b/src/assetcompile.ps1 new file mode 100644 index 0000000..40d4019 --- /dev/null +++ b/src/assetcompile.ps1 @@ -0,0 +1,10 @@ + +$texturecPath = ".\cmake-build\texturec.exe" +$textureAssetDir = "..\assets\textures" +$outputBaseDir = ".\textures" + +Get-ChildItem -Path $textureAssetDir -File | ForEach-Object { + $outName = Join-Path -Path $outputBaseDir -ChildPath ($_.BaseName + ".ktx") + Write-Host $_.FullName $outName + & "$texturecPath" -f $_.FullName -o $outName -t RGBA8 +} diff --git a/src/engine/main.cpp b/src/engine/main.cpp index 2276b2b..7bc1060 100644 --- a/src/engine/main.cpp +++ b/src/engine/main.cpp @@ -302,7 +302,7 @@ int main() Shared.Game.EntityStorageSize = 1024 * 1024; Shared.Game.EntityStorage = VirtualAllocEx( GetCurrentProcess(), NULL, Shared.Game.EntityStorageSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); - Shared.Game.TransientStorageSize = 1024 * 1024 * 100; + Shared.Game.TransientStorageSize = 1024 * 1024 * 1024; Shared.Game.TransientStorage = VirtualAllocEx( GetCurrentProcess(), NULL, Shared.Game.TransientStorageSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); StartupFunc(Shared); diff --git a/src/game/Gen.cpp b/src/game/Gen.cpp index 0e3de66..67486e2 100644 --- a/src/game/Gen.cpp +++ b/src/game/Gen.cpp @@ -10,6 +10,10 @@ namespace Generated { return h.Idx != UINT32_MAX; } + bool IsValid(const TextureHandle& h) + { + return h.TextureIdx != UINT16_MAX && IsValid(h.Asset); + } bool operator==(const AssetHandle& lhs, const AssetHandle& rhs) { return lhs.Idx == rhs.Idx; diff --git a/src/game/Gen.h b/src/game/Gen.h index 923f467..1dba32d 100644 --- a/src/game/Gen.h +++ b/src/game/Gen.h @@ -5,6 +5,7 @@ namespace Generated { bool IsValid(const AssetHandle& h); bool IsValid(const ModelHandle& h); + bool IsValid(const TextureHandle& h); bool operator==(const AssetHandle& lhs, const AssetHandle& rhs); bool operator==(const ModelHandle& lhs, const ModelHandle& rhs); diff --git a/src/game/Global.cpp b/src/game/Global.cpp index cf20e97..64c5d35 100644 --- a/src/game/Global.cpp +++ b/src/game/Global.cpp @@ -132,7 +132,7 @@ Vec3 Transform::GlobalToLocalDirection(Vec3 global) UpdateMatrix(); float in[4]{global.x, global.y, global.z, 0.0f}; float out[4]{0.0f}; - bx::vec4MulMtx(out, in, MI.M); + bx::vec4MulMtx(out, in, MI.Transpose().M); return {out[0], out[1], out[2]}; } bx::Vec3 Transform::GlobalToLocalPoint(Vec3 global) @@ -148,8 +148,7 @@ Vec3 Transform::LocalToGlobalDirection(Vec3 local) UpdateMatrix(); float in[4]{local.x, local.y, local.z, 0.0f}; float out[4]{0.0f}; - Mat4 test = M.Transpose(); - bx::vec4MulMtx(out, in, test.M); + bx::vec4MulMtx(out, in, M.Transpose().M); return {out[0], out[1], out[2]}; } bx::Vec3 Transform::LocalToGlobalPoint(Vec3 local) diff --git a/src/game/Level.cpp b/src/game/Level.cpp index 1a9e354..0c73baa 100644 --- a/src/game/Level.cpp +++ b/src/game/Level.cpp @@ -22,9 +22,9 @@ namespace Game { - void EntityRenderData::Render(const Model* models, const Material* materials) + void EntityRenderData::Render(const Model* models, const Material* materials, const Texture* textures) { - if (models == nullptr || materials == nullptr) return; + if (models == nullptr || materials == nullptr || textures == nullptr) return; if (!Generated::IsValid(ModelH) || MaterialHandle == EMaterial::UNDEFINED) return; if (!Visible) return; auto& rendering = GameRendering::Get(); @@ -46,12 +46,20 @@ namespace Game timeValues[0] = GetInstance().Time.Now; float texInfo[4]{0.0f}; - texInfo[0] = currentMaterial.Textures[0].Info.width; - texInfo[1] = currentMaterial.Textures[0].Info.height; + texInfo[0] = textures[0].Info.width; + texInfo[1] = textures[0].Info.height; texInfo[2] = rendering.DitherTextures.DitherTexWH; texInfo[3] = rendering.DitherTextures.DitherTexDepth; - bgfx::setTexture(0, currentMaterial.Textures[0].SamplerHandle, currentMaterial.Textures[0].Handle); + bgfx::UniformHandle sampler = rendering.DefaultSampler; + bgfx::TextureHandle tex = rendering.Textures[0].RenderHandle; + if (IsValid(TextureHandle)) + { + sampler = textures[TextureHandle.TextureIdx].SamplerHandle; + tex = textures[TextureHandle.TextureIdx].RenderHandle; + } + + bgfx::setTexture(0, sampler, tex); bgfx::setTexture(1, rendering.DitherTextures.DitherSampler, rendering.DitherTextures.FinalTex); bgfx::setTexture(2, rendering.DitherTextures.RampSampler, rendering.DitherTextures.RampTex); bgfx::setUniform(currentMaterial.Uniforms[Material::UTime], timeValues); @@ -248,7 +256,7 @@ namespace Game END_PERF(GetShared().Window.PerfCounters, PerfCounterType::GameLevelUpdate, GetShared().Window.FrameCounter); } - void Level::Render(uint16_t viewId, const Model* models, const Material* materials) + void Level::Render(uint16_t viewId, const Model* models, const Material* materials, const Texture* textures) { ZoneScopedN("Level Render"); auto& shared = GetShared(); @@ -275,10 +283,10 @@ namespace Game bgfx::touch(viewId); - Cubes.Render(models, materials); - Tests.Render(models, materials); - PuzzleTiles.Render(models, materials); - UIQuads.Render(models, materials); + Cubes.Render(models, materials, textures); + Tests.Render(models, materials, textures); + PuzzleTiles.Render(models, materials, textures); + UIQuads.Render(models, materials, textures); } void Cube::Setup() @@ -335,10 +343,18 @@ namespace Game void WorldPuzzle::Update() { Transform& camTransform = GetInstance().Player.PlayerCamTransform; + camTransform.UpdateMatrixForCam(); Vec3 cameraPos = camTransform.GetPosition() * -1; Level& level = GetInstance().GameLevel; auto& staticCards = Puzzle::GetStaticPuzzleData().Cards; + Transform boardTransform; + boardTransform.Rotation = camTransform.Rotation.Inverse(); + Vec3 fw = {camTransform.M.M[2], camTransform.M.M[6], camTransform.M.M[10]}; + Vec3 pos = camTransform.GetPosition() * -1; + pos += fw; + boardTransform.SetPosition(pos); + for (int8_t y = 0; y < Data.HeightTiles / Puzzle::Config::CardSize; ++y) { for (int8_t x = 0; x < Data.WidthTiles / Puzzle::Config::CardSize; ++x) @@ -352,6 +368,8 @@ namespace Game quad.EData.Visible = IsValid; tile.EData.ModelH = IsValid ? staticCards[card.RefCard.Idx].ModelHandle : staticCards[0].ModelHandle; + quad.EData.TextureHandle = + IsValid ? staticCards[card.RefCard.Idx].BoardTextureHandle : Generated::TextureHandle{}; Vec3 cardPos = { (float)card.Position.X * Puzzle::Config::CardScaleWorld, -5.0f, @@ -364,14 +382,9 @@ namespace Game tile.EData.Transform.SetPosition(cardPos); bx::mtxRotateY(tile.EData.Transform.Rotation.M, card.Rotation * bx::kPi * 0.5f); - camTransform.UpdateMatrixForCam(); - Vec3 fw = {camTransform.M.M[2], camTransform.M.M[6], camTransform.M.M[10]}; - Vec3 pos = camTransform.GetPosition() * -1; - pos += fw; - pos += Vec3{cardPos.x, cardPos.z, 0.0f} * 0.025f; - quad.EData.Transform.SetPosition(pos); + quad.EData.Transform = boardTransform; + quad.EData.Transform.TranslateLocal(Vec3{(float)card.Position.X, (float)card.Position.Y, 0.0f} * 0.21f); quad.EData.Transform.Scale = {0.1f, 0.1f, 0.1f}; - quad.EData.Transform.Rotation = camTransform.Rotation.Inverse(); quad.EData.Transform.Rotate(Vec3{bx::kPi * 0.5f, 0.0f, 0.0f}); } } diff --git a/src/game/Level.h b/src/game/Level.h index 593be4e..b452a1d 100644 --- a/src/game/Level.h +++ b/src/game/Level.h @@ -21,10 +21,11 @@ namespace Game Vec4 BaseColor{0.0f, 0.0f, 0.0f, 1.0f}; Transform Transform; EMaterial MaterialHandle = EMaterial::UNDEFINED; + Generated::TextureHandle TextureHandle; Generated::ModelHandle ModelH; bool Visible = true; - void Render(const Model* models, const Material* materials); + void Render(const Model* models, const Material* materials, const Texture* textures); }; ENTITY_HANDLE(CubeHandle); @@ -118,12 +119,12 @@ namespace Game return Data[handle.Idx]; } - void Render(const Model* models, const Material* materials) + void Render(const Model* models, const Material* materials, const Texture* textures) { if (!IsEnabled) return; for (uint16_t i = 0; i < Count; ++i) { - Get({i}).EData.Render(models, materials); + Get({i}).EData.Render(models, materials, textures); } } }; @@ -156,6 +157,6 @@ namespace Game public: void Setup(GameData& data); void Update(); - void Render(uint16_t ViewID, const Model* models, const Material* materials); + void Render(uint16_t ViewID, const Model* models, const Material* materials, const Texture* textures); }; } // namespace Game diff --git a/src/game/Tools.cpp b/src/game/Tools.cpp index cf00a77..8a8f8ee 100644 --- a/src/game/Tools.cpp +++ b/src/game/Tools.cpp @@ -24,7 +24,7 @@ namespace Tools { auto& R = Game::GameRendering::Get(); const char* name = GetAssetPath(modelHandle.Asset); - if (ImGui::BeginCombo("Models", name)) + if (ImGui::BeginCombo("Model", name)) { for (int32_t i = 0; i < R.ModelCount; ++i) { @@ -36,4 +36,29 @@ namespace Tools ImGui::EndCombo(); } } + + void TextureDropdown(Generated::TextureHandle& texHandle) + { + auto& R = Game::GameRendering::Get(); + const char* name = GetAssetPath(texHandle.Asset); + if (ImGui::BeginCombo("Texture", name)) + { + for (int32_t i = 0; i < R.MaxTextures; ++i) + { + if (!IsValid(R.Textures[i].TexHandle)) continue; + ImGui::PushID(i); + ImVec2 pos = ImGui::GetCursorScreenPos(); + if (ImGui::Selectable("", i == texHandle.TextureIdx, ImGuiSelectableFlags_AllowOverlap, {0, 64})) + { + texHandle = R.Textures[i].TexHandle; + } + ImGui::SetCursorScreenPos(pos); + ImGui::Image(R.Textures[i].RenderHandle.idx, {64, 64}); + ImGui::SameLine(); + ImGui::Text("%s", GetAssetPath(R.Textures[i].TexHandle.Asset)); + ImGui::PopID(); + } + ImGui::EndCombo(); + } + } } // namespace Tools diff --git a/src/game/Tools.h b/src/game/Tools.h index d17a012..a694051 100644 --- a/src/game/Tools.h +++ b/src/game/Tools.h @@ -4,4 +4,5 @@ namespace Tools { void ModelDropdown(Generated::ModelHandle& modelHandle); + void TextureDropdown(Generated::TextureHandle& texHandle); } // namespace Tools diff --git a/src/game/compiled-shaders/dx11/normal/frag.bin b/src/game/compiled-shaders/dx11/normal/frag.bin index 7d526d3..48388c6 100644 --- a/src/game/compiled-shaders/dx11/normal/frag.bin +++ b/src/game/compiled-shaders/dx11/normal/frag.bin @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a7816b117c34da40d016175cd3968a4012ea3a8a502eb3d7fc46df0266cba904 -size 630 +oid sha256:dd40aa82e0bfed74a83f63fff92d8f20a59b4df5b8357f0583c6304b84b5ac02 +size 540 diff --git a/src/game/data/puzzles/0.pzl b/src/game/data/puzzles/0.pzl index 2bb71ee..f4536c7 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:4947c3539ee4bef2783ae0632897b501b4eb3d5d248f23d8a7fe175d807cae89 +oid sha256:73d48d31ff063d48c57887ef7463fa9fdc458200915a6b07451d5f0f0c242a32 size 5820 diff --git a/src/game/data/static/puzzle.dat b/src/game/data/static/puzzle.dat index c6e81e4..40483b0 100644 Binary files a/src/game/data/static/puzzle.dat and b/src/game/data/static/puzzle.dat differ diff --git a/src/game/mini.def b/src/game/mini.def index 45f60c6..71074ff 100644 --- a/src/game/mini.def +++ b/src/game/mini.def @@ -40,12 +40,18 @@ type Mat4 type AssetHandle { - u32 Idx Default("UINT32_MAX") + u32 Idx Default("UINT32_MAX") } type ModelHandle { - u16 ModelIdx Default("UINT16_MAX") + u16 ModelIdx Default("UINT16_MAX") + AssetHandle Asset +} + +type TextureHandle +{ + u16 TextureIdx Default("UINT16_MAX") AssetHandle Asset } @@ -71,7 +77,7 @@ type StaticPuzzleCard { PuzzleElementType Elements Arr(4) ModelHandle ModelHandle - + TextureHandle BoardTextureHandle } type StaticPuzzleCardHandle diff --git a/src/game/rendering/Rendering.cpp b/src/game/rendering/Rendering.cpp index 37a779d..cb7e314 100644 --- a/src/game/rendering/Rendering.cpp +++ b/src/game/rendering/Rendering.cpp @@ -8,6 +8,7 @@ #include "SDL3/SDL_events.h" #include "backends/imgui_impl_sdl3.h" +#include "bgfx/c99/bgfx.h" #include "bgfx/defines.h" #include "bgfx/platform.h" #include "bx/bx.h" @@ -53,6 +54,10 @@ namespace Game long fileSizeX = appendZero ? fileSize + 1 : fileSize; void* rawMem = AllocateScratch(fileSizeX); + if (rawMem == nullptr) + { + LOG_ERROR("Failed to load file, exceeded scratch memory! %s", path); + } const bgfx::Memory* mem = bgfx::makeRef(rawMem, fileSizeX); fread(mem->data, 1, fileSize, file); if (appendZero) @@ -64,6 +69,7 @@ namespace Game return mem; } + LOG_WARN("File inaccessible! %s", path); return nullptr; } @@ -126,7 +132,7 @@ namespace Game bx::Error err; const bgfx::Memory* data = loadFile(_filePath.getCPtr()); - if (data == nullptr) + if (data == nullptr || data->data == nullptr || data->size == 0) { LOG_WARN("Failed to find image %s", _filePath.getCPtr()); return handle; @@ -367,14 +373,11 @@ namespace Game { LOG("BGFX setup succeded!"); } - // bgfx::setDebug(BGFX_DEBUG_TEXT); bgfx::setViewClear(MainViewID, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x3399FFff, 1.0f, 0); bgfx::setViewRect(MainViewID, 0, 0, shared.Window.WindowWidth, shared.Window.WindowHeight); DefaultSampler = bgfx::createUniform("s_texColor", bgfx::UniformType::Sampler); - Textures[0].Handle = loadTexture( - bx::FilePath{"models/body.dds"}, BGFX_TEXTURE_NONE | BGFX_SAMPLER_NONE, 0, &Textures[0].Info, nullptr); - Textures[0].SamplerHandle = DefaultSampler; + LoadTextures(); LoadModels(Models, ModelCount); ReloadShaders(); @@ -586,6 +589,22 @@ namespace Game ImGui::TextWrapped("%s", GetShared().Dev.ShaderLog); } ImGui::End(); + if (ImGui::Begin("Textures")) + { + if (ImGui::Button("Reload")) + { + LoadTextures(); + } + for (int32_t i = 0; i < MaxTextures; ++i) + { + if (!isValid(Textures[i].RenderHandle)) continue; + ImGui::Text("%i", i); + float width = bx::min(ImGui::GetContentRegionAvail().x, Textures[i].Info.width); + float height = bx::min(ImGui::GetContentRegionAvail().x, Textures[i].Info.height); + ImGui::Image(Textures[i].RenderHandle.idx, {width, height}); + } + } + ImGui::End(); if (ImGui::Begin("Puzzles")) { if (ImGui::Button("Add")) @@ -660,6 +679,7 @@ namespace Game } Tools::ModelDropdown(card.ModelHandle); + Tools::TextureDropdown(card.BoardTextureHandle); for (int8_t y = 0; y < Puzzle::Config::CardSize; ++y) { ImGui::PushID(y); @@ -687,12 +707,72 @@ namespace Game ImGui::End(); } + void GameRendering::LoadTextures() + { + for (int32_t i = 0; i < MaxTextures; ++i) + { + Textures[i] = {}; + } + + bx::Error err; + bx::DirectoryReader reader{}; + if (!reader.open("textures", &err) || !err.isOk()) + { + LOG_ERROR("Failed to read textures dir: %s", err.getMessage()); + } + bx::FileInfo info; + int32_t textureFilePathCount = 0; + bx::FilePath textureFilePaths[GameRendering::MaxTextures]; + while (err.isOk()) + { + int32_t res = reader.read(&info, sizeof(info), &err); + if (res == 0) break; // EOF + if (res != sizeof(info)) + { + LOG_ERROR("Dir iter error: %s", err.getMessage()); + break; + } + const bx::StringView ext = info.filePath.getExt(); + bool isDDS = bx::strCmp(ext, ".dds") == 0; + bool isKTX = bx::strCmp(ext, ".ktx") == 0; + if ((isDDS || isKTX) && !ext.isEmpty() && info.type == bx::FileType::File) + { + if (textureFilePathCount >= GameRendering::MaxTextures) + { + LOG_ERROR("Texture limit reached!"); + break; + } + textureFilePaths[textureFilePathCount] = info.filePath; + textureFilePathCount++; + } + } + LOG("Found %u textures!", textureFilePathCount); + + for (int32_t i = 0; i < textureFilePathCount; ++i) + { + bx::FilePath fullPath{"textures"}; + fullPath.join(textureFilePaths[i]); + Textures[i].RenderHandle = + loadTexture(fullPath, BGFX_TEXTURE_NONE | BGFX_SAMPLER_NONE, 0, &Textures[i].Info, nullptr); + Textures[i].SamplerHandle = DefaultSampler; + Textures[i].TexHandle.TextureIdx = i; + Textures[i].TexHandle.Asset.Idx = CrcPath(fullPath.getCPtr()); + auto& debug = GetInstance().DebugData; + if (debug.AssetCount < debug.MaxAssets) + { + debug.AssetHandles[debug.AssetCount] = Textures[i].TexHandle.Asset; + bx::strCopy(debug.AssetHandlePaths[debug.AssetCount], + sizeof(debug.AssetHandlePaths[debug.AssetCount]), + fullPath.getCPtr()); + ++debug.AssetCount; + } + } + } + void GameRendering::ReloadShaders() { - Materials[(uint16_t)EMaterial::Default] = Material::LoadFromShader( - "dither/vert", "dither/frag", MainViewID, Textures[0].Handle, Textures[0].SamplerHandle); - Materials[(uint16_t)EMaterial::UI] = Material::LoadFromShader( - "normal/vert", "normal/frag", MainViewID, Textures[0].Handle, Textures[0].SamplerHandle); + Materials[(uint16_t)EMaterial::Default] = Material::LoadFromShader("dither/vert", "dither/frag", MainViewID); + Materials[(uint16_t)EMaterial::UI] = Material::LoadFromShader("normal/vert", "normal/frag", MainViewID); } void GameRendering::Update() @@ -733,7 +813,7 @@ namespace Game ImGui::End(); GetInstance().GameLevel.Update(); - GetInstance().GameLevel.Render(MainViewID, Models, Materials); + GetInstance().GameLevel.Render(MainViewID, Models, Materials, Textures); // Finish Frame { @@ -771,8 +851,7 @@ namespace Game Instance = nullptr; } - Material Material::LoadFromShader( - const char* vertPath, const char* fragPath, uint16_t view, bgfx::TextureHandle tex, bgfx::UniformHandle sampler) + Material Material::LoadFromShader(const char* vertPath, const char* fragPath, uint16_t view) { BX_ASSERT(vertPath != nullptr && fragPath != nullptr, "Invalid shader path!"); bgfx::ShaderHandle vertexShader = loadShader(vertPath); @@ -786,8 +865,6 @@ namespace Game mat.Uniforms[Material::UDotColor] = bgfx::createUniform("u_testColor", bgfx::UniformType::Vec4); mat.Uniforms[Material::UTexInfo] = bgfx::createUniform("u_texInfo", bgfx::UniformType::Vec4); mat.Uniforms[Material::UBaseColor] = bgfx::createUniform("u_baseColor", bgfx::UniformType::Vec4); - mat.Textures[0].Handle = tex; - mat.Textures[0].SamplerHandle = sampler; mat.ViewID = view; return mat; } diff --git a/src/game/rendering/Rendering.h b/src/game/rendering/Rendering.h index 3e41595..5e5c46c 100644 --- a/src/game/rendering/Rendering.h +++ b/src/game/rendering/Rendering.h @@ -27,15 +27,16 @@ namespace Game struct Texture { - bgfx::UniformHandle SamplerHandle; - bgfx::TextureHandle Handle; + bgfx::UniformHandle SamplerHandle = {bgfx::kInvalidHandle}; + bgfx::TextureHandle RenderHandle = {bgfx::kInvalidHandle}; bgfx::TextureInfo Info; + Generated::TextureHandle TexHandle; }; struct Model { - bgfx::VertexBufferHandle VertexBuffer; - bgfx::IndexBufferHandle IndexBuffer; + bgfx::VertexBufferHandle VertexBuffer = {bgfx::kInvalidHandle}; + bgfx::IndexBufferHandle IndexBuffer = {bgfx::kInvalidHandle}; bgfx::VertexLayout VertLayout; Generated::ModelHandle Handle; }; @@ -52,14 +53,9 @@ namespace Game bgfx::ProgramHandle Shader; bgfx::UniformHandle Uniforms[8]; - Texture Textures[4]; uint64_t State = 0; uint32_t ViewID = 0; - static Material LoadFromShader(const char* vertPath, - const char* fragPath, - uint16_t view, - bgfx::TextureHandle = BGFX_INVALID_HANDLE, - bgfx::UniformHandle sampler = BGFX_INVALID_HANDLE); + static Material LoadFromShader(const char* vertPath, const char* fragPath, uint16_t view); }; enum class UIVisibilityState @@ -99,6 +95,7 @@ namespace Game { public: static constexpr uint32_t MaxModels = 64; + static constexpr uint32_t MaxTextures = 64; static GameRendering& Get(); public: @@ -107,7 +104,7 @@ namespace Game public: bgfx::UniformHandle DefaultSampler; - Texture Textures[8]; + Texture Textures[MaxTextures]; Material Materials[8]; uint32_t ModelCount = 0; Model Models[MaxModels]; @@ -125,6 +122,7 @@ namespace Game void Update(); void HandleEvents(); void RenderDebugUI(); + void LoadTextures(); void ReloadShaders(); void Shutdown(); Generated::ModelHandle GetModelHandleFromPath(const char* path); diff --git a/src/game/shaders/normal/frag.sc b/src/game/shaders/normal/frag.sc index 9975f90..170b8ea 100644 --- a/src/game/shaders/normal/frag.sc +++ b/src/game/shaders/normal/frag.sc @@ -87,26 +87,7 @@ float dither(float brightness, vec2 inputUv) void main() { - // setup - 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 texColor = u_testColor.x > 0.1 ? u_testColor.xyz : texture2D(s_texColor, v_uv0).xyz; - - // lighting - // float brightness = calcBrightness(lightPos, v_wpos, v_normal); + vec3 rawTex = texture2D(s_texColor, v_uv0).xyz; 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 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); - gl_FragColor = vec4(finalColor, 1.0); - gl_FragColor = vec4(texColor, 1.0); - + gl_FragColor = vec4(rawTex, 1.0); } diff --git a/src/gen/Generated.cpp b/src/gen/Generated.cpp index c4d535f..b4559ca 100644 --- a/src/gen/Generated.cpp +++ b/src/gen/Generated.cpp @@ -162,6 +162,26 @@ namespace Generated } return isOk; } + bool Save(const TextureHandle* obj, uint32_t count, Serializer& serializer) + { + bool isOk = true; + for (uint32_t i = 0; i < count; ++i) + { + isOk = Save(&obj[i].TextureIdx, 1, serializer) && isOk; + isOk = Save(&obj[i].Asset, 1, serializer) && isOk; + } + return isOk; + } + bool Load(TextureHandle* obj, uint32_t count, Deserializer& serializer) + { + bool isOk = true; + for (uint32_t i = 0; i < count; ++i) + { + isOk = Load(&obj[i].TextureIdx, 1, serializer) && isOk; + isOk = Load(&obj[i].Asset, 1, serializer) && isOk; + } + return isOk; + } bool Save(const PuzPos* obj, uint32_t count, Serializer& serializer) { bool isOk = true; @@ -189,6 +209,7 @@ namespace Generated { isOk = Save(obj[i].Elements, 4, serializer) && isOk; isOk = Save(&obj[i].ModelHandle, 1, serializer) && isOk; + isOk = Save(&obj[i].BoardTextureHandle, 1, serializer) && isOk; } return isOk; } @@ -199,6 +220,7 @@ namespace Generated { isOk = Load(obj[i].Elements, 4, serializer) && isOk; isOk = Load(&obj[i].ModelHandle, 1, serializer) && isOk; + isOk = Load(&obj[i].BoardTextureHandle, 1, serializer) && isOk; } return isOk; } diff --git a/src/gen/Generated.h b/src/gen/Generated.h index 211707a..b22aac5 100644 --- a/src/gen/Generated.h +++ b/src/gen/Generated.h @@ -103,6 +103,12 @@ namespace Generated uint16_t ModelIdx = UINT16_MAX; AssetHandle Asset = {}; }; + struct TextureHandle + { + static constexpr uint32_t Hash = 1633273761; + uint16_t TextureIdx = UINT16_MAX; + AssetHandle Asset = {}; + }; struct PuzPos { static constexpr uint32_t Hash = 1834398141; @@ -111,9 +117,10 @@ namespace Generated }; struct StaticPuzzleCard { - static constexpr uint32_t Hash = 2851442461; + static constexpr uint32_t Hash = 431895198; PuzzleElementType::Enum Elements[4] = {}; ModelHandle ModelHandle = {}; + TextureHandle BoardTextureHandle = {}; }; struct StaticPuzzleCardHandle { @@ -122,7 +129,7 @@ namespace Generated }; struct StaticPuzzleData { - static constexpr uint32_t Hash = 4204694691; + static constexpr uint32_t Hash = 1497693577; StaticPuzzleCard Cards[64] = {}; }; struct PuzzleCardStack @@ -170,6 +177,8 @@ namespace Generated bool Load(AssetHandle* obj, uint32_t count, Deserializer& serializer); bool Save(const ModelHandle* obj, uint32_t count, Serializer& serializer); bool Load(ModelHandle* obj, uint32_t count, Deserializer& serializer); + bool Save(const TextureHandle* obj, uint32_t count, Serializer& serializer); + bool Load(TextureHandle* obj, uint32_t count, Deserializer& serializer); bool Save(const PuzPos* obj, uint32_t count, Serializer& serializer); bool Load(PuzPos* obj, uint32_t count, Deserializer& serializer); bool Save(const StaticPuzzleCard* obj, uint32_t count, Serializer& serializer); diff --git a/src/models/body.dds b/src/models/body.dds deleted file mode 100644 index a898866..0000000 --- a/src/models/body.dds +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:98579e3e2e29a3484d34991c8c0d5b6e2fd82885490c6ce52e7b6c1da614f362 -size 8388756 diff --git a/src/shadercompile.ps1 b/src/shadercompile.ps1 index 8d6e753..8c6aa54 100644 --- a/src/shadercompile.ps1 +++ b/src/shadercompile.ps1 @@ -1,4 +1,4 @@ -$shadercPath = ".\cmake-build\shaderc.exe" +$shadercPath = "..\tools\shaderc.exe" $shadersDir = ".\game\shaders" $outputBaseDir = ".\game\compiled-shaders" $includeDir = ".\dependency\bgfx.cmake\bgfx\src" diff --git a/src/textures/body.ktx b/src/textures/body.ktx new file mode 100644 index 0000000..286a330 --- /dev/null +++ b/src/textures/body.ktx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9229dc1d388d4ff5926b553e2f3ca1687b3ff06b7f049b946e8b52b1ed9f52bc +size 67108932 diff --git a/src/textures/test.ktx b/src/textures/test.ktx new file mode 100644 index 0000000..140dbd1 --- /dev/null +++ b/src/textures/test.ktx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5f1b9e4a1c4a50cbaaf832cb22771391bba5554be116e8cb4152318eabc41efc +size 4194372 diff --git a/tools/shaderc.exe b/tools/shaderc.exe new file mode 100644 index 0000000..422c68e --- /dev/null +++ b/tools/shaderc.exe @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1415f006605ce1635950f57425164d308d9ce2e9222e4a2a50d33ce91d093384 +size 10283520 diff --git a/tools/texturec.exe b/tools/texturec.exe new file mode 100644 index 0000000..cfb0da2 --- /dev/null +++ b/tools/texturec.exe @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2b6984090d535c0293088f0a84fd9163b8707382a68c3286b801b4018992089c +size 1457152