texture loading!
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -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
|
||||
|
||||
BIN
assets/textures/test.png
LFS
Normal file
BIN
assets/textures/test.png
LFS
Normal file
Binary file not shown.
10
src/assetcompile.ps1
Normal file
10
src/assetcompile.ps1
Normal file
@@ -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
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -4,4 +4,5 @@
|
||||
namespace Tools
|
||||
{
|
||||
void ModelDropdown(Generated::ModelHandle& modelHandle);
|
||||
void TextureDropdown(Generated::TextureHandle& texHandle);
|
||||
} // namespace Tools
|
||||
|
||||
Binary file not shown.
BIN
src/game/data/puzzles/0.pzl
LFS
BIN
src/game/data/puzzles/0.pzl
LFS
Binary file not shown.
Binary file not shown.
@@ -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
|
||||
|
||||
@@ -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<float>(ImGui::GetContentRegionAvail().x, Textures[i].Info.width);
|
||||
float height = bx::min<float>(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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
BIN
src/models/body.dds
LFS
BIN
src/models/body.dds
LFS
Binary file not shown.
@@ -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"
|
||||
|
||||
BIN
src/textures/body.ktx
LFS
Normal file
BIN
src/textures/body.ktx
LFS
Normal file
Binary file not shown.
BIN
src/textures/test.ktx
LFS
Normal file
BIN
src/textures/test.ktx
LFS
Normal file
Binary file not shown.
BIN
tools/shaderc.exe
LFS
Normal file
BIN
tools/shaderc.exe
LFS
Normal file
Binary file not shown.
BIN
tools/texturec.exe
LFS
Normal file
BIN
tools/texturec.exe
LFS
Normal file
Binary file not shown.
Reference in New Issue
Block a user