move vec to generated

This commit is contained in:
Asuro
2025-03-30 19:45:48 +02:00
parent b006d14197
commit 052fc2cc07
16 changed files with 662 additions and 289 deletions

View File

@@ -6,12 +6,52 @@
#include <cassert>
#include <cstdint>
using namespace Generated;
namespace
{
SharedData* SharedInstance = nullptr;
Game::GameInstance* GameInst = nullptr;
} // namespace
namespace Game
{
SharedData& GetShared()
{
assert(SharedInstance != nullptr);
return *SharedInstance;
}
void SetShared(SharedData& instance)
{
SharedInstance = &instance;
}
GameInstance& GetInstance()
{
assert(GameInst != nullptr);
return *GameInst;
}
void SetInstance(Game::GameInstance& instance)
{
GameInst = &instance;
}
void* AllocateScratch(size_t byteCount, size_t align)
{
size_t offset = GetInstance().UsedScratchAmount;
uint8_t* base = static_cast<uint8_t*>(GetShared().Game.TransientStorage);
uint8_t* current = base + offset;
size_t offsetAligned = ((offset + align - 1) / align) * align;
uint8_t* ptrAligned = base + offsetAligned;
size_t newOffset = offsetAligned + byteCount;
if (newOffset > GetShared().Game.TransientStorageSize) return nullptr;
GetInstance().UsedScratchAmount = newOffset;
return reinterpret_cast<void*>(ptrAligned);
}
} // namespace Game
void Transform::CreateTransform(float* out, bx::Vec3 pos, bx::Quaternion rot, bx::Vec3 scale)
{
if (out == nullptr) return;
@@ -82,49 +122,12 @@ void Transform::UpdateMatrix()
bx::mtxInverse(MI.M, M.M);
}
namespace Game
{
SharedData& GetShared()
{
assert(SharedInstance != nullptr);
return *SharedInstance;
}
void SetShared(SharedData& instance)
{
SharedInstance = &instance;
}
GameInstance& GetInstance()
{
assert(GameInst != nullptr);
return *GameInst;
}
void SetInstance(Game::GameInstance& instance)
{
GameInst = &instance;
}
void* AllocateScratch(size_t byteCount, size_t align)
{
size_t offset = GetInstance().UsedScratchAmount;
uint8_t* base = static_cast<uint8_t*>(GetShared().Game.TransientStorage);
uint8_t* current = base + offset;
size_t offsetAligned = ((offset + align - 1) / align) * align;
uint8_t* ptrAligned = base + offsetAligned;
size_t newOffset = offsetAligned + byteCount;
if (newOffset > GetShared().Game.TransientStorageSize) return nullptr;
GetInstance().UsedScratchAmount = newOffset;
return reinterpret_cast<void*>(ptrAligned);
}
} // namespace Game
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.Transpose().M);
bx::vec4MulMtx(out, in, Transpose(MI).M);
return {out[0], out[1], out[2]};
}
Vec3 Transform::GlobalToLocalPoint(Vec3 global)
@@ -140,7 +143,7 @@ Vec3 Transform::LocalToGlobalDirection(Vec3 local)
UpdateMatrix();
float in[4]{local.x, local.y, local.z, 0.0f};
float out[4]{0.0f};
bx::vec4MulMtx(out, in, M.Transpose().M);
bx::vec4MulMtx(out, in, Transpose(M).M);
return {out[0], out[1], out[2]};
}
Vec3 Transform::LocalToGlobalPoint(Vec3 local)
@@ -159,24 +162,286 @@ Vec3 Transform::GetPosition()
{
return {Position.x, Position.y, Position.z};
}
Mat4 Mat4::Inverse()
// Vec4
Vec4& operator+=(Vec4& lhs, const Vec4& rhs)
{
lhs.x += rhs.x;
lhs.y += rhs.y;
lhs.z += rhs.z;
lhs.w += rhs.w;
return lhs;
}
Vec4 operator+(const Vec4& lhs, const Vec4& rhs)
{
Vec4 out = lhs;
return out += rhs;
}
Vec4& operator+=(Vec4& lhs, float rhs)
{
lhs.x += rhs;
lhs.y += rhs;
lhs.z += rhs;
lhs.w += rhs;
return lhs;
}
Vec4 operator+(Vec4& lhs, float rhs)
{
Vec4 out = lhs;
return out += rhs;
}
Vec4& operator-=(Vec4& lhs, const Vec4& rhs)
{
lhs.x -= rhs.x;
lhs.y -= rhs.y;
lhs.z -= rhs.z;
lhs.w -= rhs.w;
return lhs;
}
Vec4 operator-(const Vec4& lhs, const Vec4& rhs)
{
Vec4 out = lhs;
return out -= rhs;
}
Vec4& operator-=(Vec4& lhs, float rhs)
{
lhs.x -= rhs;
lhs.y -= rhs;
lhs.z -= rhs;
lhs.w -= rhs;
return lhs;
}
Vec4 operator-(const Vec4& lhs, float rhs)
{
Vec4 out = lhs;
return out -= rhs;
}
Vec4& operator*=(Vec4& lhs, float rhs)
{
lhs.x *= rhs;
lhs.y *= rhs;
lhs.z *= rhs;
lhs.w *= rhs;
return lhs;
}
Vec4 operator*(const Vec4& lhs, float rhs)
{
Vec4 out = lhs;
return out *= rhs;
}
Vec4& operator/=(Vec4& lhs, float rhs)
{
lhs.x /= rhs;
lhs.y /= rhs;
lhs.z /= rhs;
lhs.w /= rhs;
return lhs;
}
Vec4 operator/(const Vec4& lhs, float rhs)
{
Vec4 out = lhs;
return out /= rhs;
}
// Vec3
Vec3& operator+=(Vec3& lhs, const Vec3& rhs)
{
lhs.x += rhs.x;
lhs.y += rhs.y;
lhs.z += rhs.z;
return lhs;
}
Vec3 operator+(const Vec3& lhs, const Vec3& rhs)
{
Vec3 out = lhs;
return out += rhs;
}
Vec3& operator+=(Vec3& lhs, float rhs)
{
lhs.x += rhs;
lhs.y += rhs;
lhs.z += rhs;
return lhs;
}
Vec3 operator+(Vec3& lhs, float rhs)
{
Vec3 out = lhs;
return out += rhs;
}
Vec3& operator-=(Vec3& lhs, const Vec3& rhs)
{
lhs.x -= rhs.x;
lhs.y -= rhs.y;
lhs.z -= rhs.z;
return lhs;
}
Vec3 operator-(const Vec3& lhs, const Vec3& rhs)
{
Vec3 out = lhs;
return out -= rhs;
}
Vec3& operator-=(Vec3& lhs, float rhs)
{
lhs.x -= rhs;
lhs.y -= rhs;
lhs.z -= rhs;
return lhs;
}
Vec3 operator-(const Vec3& lhs, float rhs)
{
Vec3 out = lhs;
return out -= rhs;
}
Vec3& operator*=(Vec3& lhs, float rhs)
{
lhs.x *= rhs;
lhs.y *= rhs;
lhs.z *= rhs;
return lhs;
}
Vec3 operator*(const Vec3& lhs, float rhs)
{
Vec3 out = lhs;
return out *= rhs;
}
Vec3& operator/=(Vec3& lhs, float rhs)
{
lhs.x /= rhs;
lhs.y /= rhs;
lhs.z /= rhs;
return lhs;
}
Vec3 operator/(const Vec3& lhs, float rhs)
{
Vec3 out = lhs;
return out /= rhs;
}
// Vec2
Vec2& operator+=(Vec2& lhs, const Vec2& rhs)
{
lhs.x += rhs.x;
lhs.y += rhs.y;
return lhs;
}
Vec2 operator+(const Vec2& lhs, const Vec2& rhs)
{
Vec2 out = lhs;
return out += rhs;
}
Vec2& operator+=(Vec2& lhs, float rhs)
{
lhs.x += rhs;
lhs.y += rhs;
return lhs;
}
Vec2 operator+(Vec2& lhs, float rhs)
{
Vec2 out = lhs;
return out += rhs;
}
Vec2& operator-=(Vec2& lhs, const Vec2& rhs)
{
lhs.x -= rhs.x;
lhs.y -= rhs.y;
return lhs;
}
Vec2 operator-(const Vec2& lhs, const Vec2& rhs)
{
Vec2 out = lhs;
return out -= rhs;
}
Vec2& operator-=(Vec2& lhs, float rhs)
{
lhs.x -= rhs;
lhs.y -= rhs;
return lhs;
}
Vec2 operator-(const Vec2& lhs, float rhs)
{
Vec2 out = lhs;
return out -= rhs;
}
Vec2& operator*=(Vec2& lhs, float rhs)
{
lhs.x *= rhs;
lhs.y *= rhs;
return lhs;
}
Vec2 operator*(const Vec2& lhs, float rhs)
{
Vec2 out = lhs;
return out *= rhs;
}
Vec2& operator/=(Vec2& lhs, float rhs)
{
lhs.x /= rhs;
lhs.y /= rhs;
return lhs;
}
Vec2 operator/(const Vec2& lhs, float rhs)
{
Vec2 out = lhs;
return out /= rhs;
}
Mat4 Inverse(const Mat4& mat)
{
Mat4 result;
bx::mtxInverse(result.M, M);
bx::mtxInverse(result.M, &mat.M[0]);
return result;
}
Mat4 Mat4::Transpose()
Mat4 Transpose(const Mat4& mat)
{
Mat4 result;
bx::mtxTranspose(result.M, M);
bx::mtxTranspose(result.M, &mat.M[0]);
return result;
}
Vec4 Mat4::Mul(const Vec4& vec)
Vec4 Mul(const Mat4& mat, const Vec4& vec)
{
Vec4 out;
bx::vec4MulMtx(&out.x, &vec.x, &M[0]);
bx::vec4MulMtx(&out.x, &vec.x, &mat.M[0]);
return out;
}
float Magnitude(const Vec4& vec)
{
return bx::sqrt(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z + vec.w * vec.w);
}
float Magnitude(const Vec3& vec)
{
return bx::sqrt(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z);
}
float Magnitude(const Vec2& vec)
{
return bx::sqrt(vec.x * vec.x + vec.y * vec.y);
}
Vec4 Normalized(const Vec4& vec)
{
Vec4 res = vec;
return res /= Magnitude(vec);
}
Vec3 Normalized(const Vec3& vec)
{
Vec3 res = vec;
return res /= Magnitude(vec);
}
Vec2 Normalized(const Vec2& vec)
{
Vec2 res = vec;
return res /= Magnitude(vec);
}
float DotProduct(Vec3 a, Vec3 b)
{
return a.x * b.x + a.y * b.y + a.z * b.z;
@@ -191,8 +456,8 @@ Vec3 CrossProduct(Vec3 a, Vec3 b)
Vec3 CrossProductFromPlane(Vec3 a, Vec3 b, Vec3 c)
{
// TODO: normalize might not be necessary
Vec3 lineA = (b - a).Normalize();
Vec3 lineB = (c - a).Normalize();
Vec3 lineA = Normalized(b - a);
Vec3 lineB = Normalized(c - a);
return CrossProduct(lineA, lineB);
}
bool RayPlaneIntersect(Vec3 l1, Vec3 l2, Vec3 p1, Vec3 p2, Vec3 p3, Vec3& out)

View File

@@ -1,214 +1,215 @@
#pragma once
#include "Gen.h"
#include "bx/math.h"
#include <cfloat>
struct Vec2
{
float x = 0.0f;
float y = 0.0f;
using namespace Generated;
// struct Vec2
// {
// float x = 0.0f;
// float y = 0.0f;
Vec2& operator+=(const Vec2& rhs)
{
x += rhs.x;
y += rhs.y;
return *this;
}
// Vec2& operator+=(const Vec2& rhs)
// {
// x += rhs.x;
// y += rhs.y;
// return *this;
// }
friend Vec2 operator+(Vec2 lhs, const Vec2& rhs)
{
lhs += rhs;
return lhs;
}
// friend Vec2 operator+(Vec2 lhs, const Vec2& rhs)
// {
// lhs += rhs;
// return lhs;
// }
Vec2& operator+=(const float& rhs)
{
x += rhs;
y += rhs;
return *this;
}
// Vec2& operator+=(const float& rhs)
// {
// x += rhs;
// y += rhs;
// return *this;
// }
friend Vec2 operator+(Vec2 lhs, const float& rhs)
{
lhs += rhs;
return lhs;
}
// friend Vec2 operator+(Vec2 lhs, const float& rhs)
// {
// lhs += rhs;
// return lhs;
// }
Vec2& operator-=(const Vec2& rhs)
{
x -= rhs.x;
y -= rhs.y;
return *this;
}
// Vec2& operator-=(const Vec2& rhs)
// {
// x -= rhs.x;
// y -= rhs.y;
// return *this;
// }
friend Vec2 operator-(Vec2 lhs, const Vec2& rhs)
{
lhs -= rhs;
return lhs;
}
// friend Vec2 operator-(Vec2 lhs, const Vec2& rhs)
// {
// lhs -= rhs;
// return lhs;
// }
Vec2& operator-=(const float& rhs)
{
x -= rhs;
y -= rhs;
return *this;
}
// Vec2& operator-=(const float& rhs)
// {
// x -= rhs;
// y -= rhs;
// return *this;
// }
friend Vec2 operator-(Vec2 lhs, const float& rhs)
{
lhs -= rhs;
return lhs;
}
// friend Vec2 operator-(Vec2 lhs, const float& rhs)
// {
// lhs -= rhs;
// return lhs;
// }
Vec2& operator*=(const float rhs)
{
x *= rhs;
y *= rhs;
return *this;
}
// Vec2& operator*=(const float rhs)
// {
// x *= rhs;
// y *= rhs;
// return *this;
// }
friend Vec2 operator*(Vec2 lhs, const float rhs)
{
lhs *= rhs;
return lhs;
}
// friend Vec2 operator*(Vec2 lhs, const float rhs)
// {
// lhs *= rhs;
// return lhs;
// }
Vec2& operator/=(const float rhs)
{
x /= rhs;
y /= rhs;
return *this;
}
// Vec2& operator/=(const float rhs)
// {
// x /= rhs;
// y /= rhs;
// return *this;
// }
friend Vec2 operator/(Vec2 lhs, const float rhs)
{
lhs /= rhs;
return lhs;
}
// friend Vec2 operator/(Vec2 lhs, const float rhs)
// {
// lhs /= rhs;
// return lhs;
// }
float Magnitude()
{
return bx::sqrt(x * x + y * y);
}
// float Magnitude()
// {
// return bx::sqrt(x * x + y * y);
// }
Vec2 Normalize()
{
float mag = Magnitude();
if (mag < FLT_EPSILON) return {};
return {x / mag, y / mag};
}
};
// Vec2 Normalize()
// {
// float mag = Magnitude();
// if (mag < FLT_EPSILON) return {};
// return {x / mag, y / mag};
// }
// };
struct Vec3
{
float x = 0.0f;
float y = 0.0f;
float z = 0.0f;
// struct Vec3
// {
// float x = 0.0f;
// float y = 0.0f;
// float z = 0.0f;
Vec3& operator+=(const Vec3& rhs)
{
x += rhs.x;
y += rhs.y;
z += rhs.z;
return *this;
}
// Vec3& operator+=(const Vec3& rhs)
// {
// x += rhs.x;
// y += rhs.y;
// z += rhs.z;
// return *this;
// }
friend Vec3 operator+(Vec3 lhs, const Vec3& rhs)
{
lhs += rhs;
return lhs;
}
// friend Vec3 operator+(Vec3 lhs, const Vec3& rhs)
// {
// lhs += rhs;
// return lhs;
// }
Vec3& operator-=(const Vec3& rhs)
{
x -= rhs.x;
y -= rhs.y;
z -= rhs.z;
return *this;
}
// Vec3& operator-=(const Vec3& rhs)
// {
// x -= rhs.x;
// y -= rhs.y;
// z -= rhs.z;
// return *this;
// }
friend Vec3 operator-(Vec3 lhs, const Vec3& rhs)
{
lhs -= rhs;
return lhs;
}
// friend Vec3 operator-(Vec3 lhs, const Vec3& rhs)
// {
// lhs -= rhs;
// return lhs;
// }
Vec3& operator*=(const float rhs)
{
x *= rhs;
y *= rhs;
z *= rhs;
return *this;
}
// Vec3& operator*=(const float rhs)
// {
// x *= rhs;
// y *= rhs;
// z *= rhs;
// return *this;
// }
friend Vec3 operator*(Vec3 lhs, const float rhs)
{
lhs *= rhs;
return lhs;
}
// friend Vec3 operator*(Vec3 lhs, const float rhs)
// {
// lhs *= rhs;
// return lhs;
// }
Vec3& operator/=(const float rhs)
{
x /= rhs;
y /= rhs;
z /= rhs;
return *this;
}
// Vec3& operator/=(const float rhs)
// {
// x /= rhs;
// y /= rhs;
// z /= rhs;
// return *this;
// }
friend Vec3 operator/(Vec3 lhs, const float rhs)
{
lhs /= rhs;
return lhs;
}
// friend Vec3 operator/(Vec3 lhs, const float rhs)
// {
// lhs /= rhs;
// return lhs;
// }
float Magnitude()
{
return bx::sqrt(x * x + y * y + z * z);
}
// float Magnitude()
// {
// return bx::sqrt(x * x + y * y + z * z);
// }
Vec3 Normalize()
{
float mag = Magnitude();
if (mag < FLT_EPSILON) return {};
return {x / mag, y / mag, z / mag};
}
};
// Vec3 Normalize()
// {
// float mag = Magnitude();
// if (mag < FLT_EPSILON) return {};
// return {x / mag, y / mag, z / mag};
// }
// };
struct Vec4
{
float x = 0.0f;
float y = 0.0f;
float z = 0.0f;
float w = 0.0f;
};
// struct Vec4
// {
// float x = 0.0f;
// float y = 0.0f;
// float z = 0.0f;
// float w = 0.0f;
// };
struct Mat3
{
// clang-format off
float M[9]{
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f,
};
// clang-format on
};
// struct Mat3
// {
// // clang-format off
// float M[9]{
// 1.0f, 0.0f, 0.0f,
// 0.0f, 1.0f, 0.0f,
// 0.0f, 0.0f, 1.0f,
// };
// // clang-format on
// };
struct Mat4
{
// clang-format off
float M[16]{
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0,
};
// clang-format on
Mat4 Inverse();
Mat4 Transpose();
Vec4 Mul(const Vec4& vec);
};
// struct Mat4
// {
// // clang-format off
// float M[16]{
// 1.0, 0.0, 0.0, 0.0,
// 0.0, 1.0, 0.0, 0.0,
// 0.0, 0.0, 1.0, 0.0,
// 0.0, 0.0, 0.0, 1.0,
// };
// // clang-format on
// Mat4 Inverse();
// Mat4 Transpose();
// Vec4 Mul(const Vec4& vec);
// };
//
inline int32_t SetFlags(int32_t in, int32_t flags)
{
return in | flags;
@@ -257,6 +258,67 @@ struct Transform
void UpdateMatrixForCam();
};
Vec4& operator+=(Vec4& lhs, const Vec4& rhs);
Vec4 operator+(const Vec4& lhs, const Vec4& rhs);
Vec4& operator+=(Vec4& lhs, float rhs);
Vec4 operator+(Vec4& lhs, float rhs);
Vec4& operator-=(Vec4& lhs, const Vec4& rhs);
Vec4 operator-(const Vec4& lhs, const Vec4& rhs);
Vec4& operator-=(Vec4& lhs, float rhs);
Vec4 operator-(const Vec4& lhs, float rhs);
Vec4& operator*=(Vec4& lhs, float rhs);
Vec4 operator*(const Vec4& lhs, float rhs);
Vec4& operator/=(Vec4& lhs, float rhs);
Vec4 operator/(const Vec4& lhs, float rhs);
Vec3& operator+=(Vec3& lhs, const Vec3& rhs);
Vec3 operator+(const Vec3& lhs, const Vec3& rhs);
Vec3& operator+=(Vec3& lhs, float rhs);
Vec3 operator+(Vec3& lhs, float rhs);
Vec3& operator-=(Vec3& lhs, const Vec3& rhs);
Vec3 operator-(const Vec3& lhs, const Vec3& rhs);
Vec3& operator-=(Vec3& lhs, float rhs);
Vec3 operator-(const Vec3& lhs, float rhs);
Vec3& operator*=(Vec3& lhs, float rhs);
Vec3 operator*(const Vec3& lhs, float rhs);
Vec3& operator/=(Vec3& lhs, float rhs);
Vec3 operator/(const Vec3& lhs, float rhs);
Vec2& operator+=(Vec2& lhs, const Vec2& rhs);
Vec2 operator+(const Vec2& lhs, const Vec2& rhs);
Vec2& operator+=(Vec2& lhs, float rhs);
Vec2 operator+(Vec2& lhs, float rhs);
Vec2& operator-=(Vec2& lhs, const Vec2& rhs);
Vec2 operator-(const Vec2& lhs, const Vec2& rhs);
Vec2& operator-=(Vec2& lhs, float rhs);
Vec2 operator-(const Vec2& lhs, float rhs);
Vec2& operator*=(Vec2& lhs, float rhs);
Vec2 operator*(const Vec2& lhs, float rhs);
Vec2& operator/=(Vec2& lhs, float rhs);
Vec2 operator/(const Vec2& lhs, float rhs);
float Magnitude(const Vec4& vec);
float Magnitude(const Vec3& vec);
float Magnitude(const Vec2& vec);
Vec4 Normalized(const Vec4& vec);
Vec3 Normalized(const Vec3& vec);
Vec2 Normalized(const Vec2& vec);
Mat4 Inverse(const Mat4& mat);
Mat4 Transpose(const Mat4& mat);
Vec4 Mul(const Mat4& mat, const Vec4& vec);
float DotProduct(Vec3 a, Vec3 b);
Vec3 CrossProduct(Vec3 a, Vec3 b);
Vec3 CrossProductFromPlane(Vec3 a, Vec3 b, Vec3 c);
bool RayPlaneIntersect(Vec3 l1, Vec3 l2, Vec3 p1, Vec3 p2, Vec3 p3, Vec3& out);

View File

@@ -21,6 +21,8 @@
#include <cstdint>
#include <tracy/Tracy.hpp>
using namespace Generated;
namespace Game
{
void EntityRenderData::Render(const Model* models, const Material* materials, const Texture* textures)
@@ -66,7 +68,7 @@ namespace Game
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);
bgfx::setUniform(currentMaterial.Uniforms[Material::UDotColor], &TestColor.x);
bgfx::setUniform(currentMaterial.Uniforms[Material::UDotColor], &DotColor.x);
bgfx::setUniform(currentMaterial.Uniforms[Material::UTexInfo], texInfo);
bgfx::setUniform(currentMaterial.Uniforms[Material::UBaseColor], &BaseColor.x);
@@ -154,10 +156,6 @@ namespace Game
Cubes.Get(PlayerOutsideViewCube).Setup();
}
if (Tests.Count == 0)
{
Tests.Get(Tests.New()).Setup();
}
UIQuads.Count = 0;
PuzzleTiles.Count = 0;
for (int32_t i = 0; i < BX_COUNTOF(Puzzles); ++i)
@@ -343,7 +341,7 @@ namespace Game
mousePos *= 2.0f;
mousePos -= 1.0f;
Vec4 mousePosView = {mousePos.x, -mousePos.y, 0.0f, 1.0f};
Vec4 mousePosCam4 = GetInstance().Player.ProjectionInverse.Mul(mousePosView);
Vec4 mousePosCam4 = Mul(GetInstance().Player.ProjectionInverse, mousePosView);
Vec3 mousePosCam = Vec3{
mousePosCam4.x /= mousePosCam4.w,
mousePosCam4.y /= mousePosCam4.w,
@@ -381,12 +379,13 @@ namespace Game
quad.EData.Visible = isValid;
quad.EData.TextureHandle =
isValid ? staticCards[card.RefCard.Idx].BoardTextureHandle : Generated::TextureHandle{};
quad.EData.DotColor = card.IsLocked ? Vec4{0.0f, 0.0f, 0.0f, 0.0f} : Vec4{1.0f, 1.0f, 1.0f, 1.0f};
quad.EData.Transform = boardTransform;
quad.EData.Transform.TranslateLocal(Vec3{(float)card.Position.X, (float)card.Position.Y, 0.0f} *
UICardOffset);
quad.EData.Transform.Scale = {0.1f, 0.1f, 0.1f};
quad.EData.Transform.Rotate(Vec3{bx::kPi * 0.5f, 0.0f, (1.0f + card.Rotation * 0.5f) * bx::kPi});
quad.EData.Transform.Rotate(Vec3{bx::kPi * 0.5f, 0.0f, (1.0f - card.Rotation * 0.5f) * bx::kPi});
Vec3 quadPosWorld = quad.EData.Transform.GetPosition();
Vec3 quadXWorld = quad.EData.Transform.LocalToGlobalPoint({1, 0, 0});

View File

@@ -21,7 +21,7 @@ namespace Game
{
struct EntityRenderData
{
Vec4 TestColor{1.0f, 1.0f, 1.0f, 1.0f};
Vec4 DotColor{1.0f, 1.0f, 1.0f, 1.0f};
Vec4 BaseColor{0.0f, 0.0f, 0.0f, 1.0f};
Transform Transform;
EMaterial MaterialHandle = EMaterial::UNDEFINED;

View File

@@ -1,12 +1,15 @@
#include "Global.h"
#include "Instance.h"
#include "Mesh.h"
#include "Puzzle.h"
#include "Tools.h"
#include "bx/timer.h"
#include <imgui.h>
#include <tracy/Tracy.hpp>
using namespace Generated;
namespace
{
constexpr int32_t FrameTimeBufSize = 512;
@@ -193,20 +196,21 @@ namespace Tools
Vec3 quadPos = level.UIQuads.Get({0}).EData.Transform.GetPosition();
ImGui::Text("%f %f %f", quadPos.x, quadPos.y, quadPos.z);
if (ImGui::ColorEdit3("Base Color", &rendering.DefaultBaseColor.x))
auto& puzzleVisuals = Puzzle::GetStaticPuzzleData().Visuals;
if (ImGui::ColorEdit3("Tile Base Color", &puzzleVisuals.TileBaseColor.x))
{
auto& tiles = level.PuzzleTiles;
for (int32_t i = 0; i < tiles.Count; ++i)
{
tiles.Data[i].EData.BaseColor = rendering.DefaultBaseColor;
tiles.Data[i].EData.BaseColor = puzzleVisuals.TileBaseColor;
}
}
if (ImGui::ColorEdit3("Dot Color", &rendering.DefaultTileColor.x))
if (ImGui::ColorEdit3("Tile Dot Color", &puzzleVisuals.TileDotColor.x))
{
auto& tiles = level.PuzzleTiles;
for (int32_t i = 0; i < tiles.Count; ++i)
{
tiles.Data[i].EData.TestColor = rendering.DefaultTileColor;
tiles.Data[i].EData.DotColor = puzzleVisuals.TileDotColor;
}
}

Binary file not shown.

View File

@@ -1,22 +1,22 @@
type Vec2
{
f32 X
f32 Y
f32 x
f32 y
}
type Vec3
{
f32 X
f32 Y
f32 Z
f32 x
f32 y
f32 z
}
type Vec4
{
f32 X
f32 Y
f32 Z
f32 W
f32 x
f32 y
f32 z
f32 w
}
type Mat3
@@ -85,9 +85,17 @@ type StaticPuzzleCardHandle
u16 Idx Default("UINT16_MAX")
}
type PuzzleVisualSettings
{
Vec4 TileBaseColor
Vec4 TileDotColor
Vec4 DisabledCardTint
}
type StaticPuzzleData
{
StaticPuzzleCard Cards Arr(64)
PuzzleVisualSettings Visuals
}
type PuzzleCardStack

View File

@@ -1,6 +1,8 @@
#include "../Log.h"
#include "Dither.h"
using namespace Generated;
void DitherGen(DitherData& data, int32_t recursion)
{
data.Points[0] = {0.0f, 0.0f};
@@ -55,7 +57,7 @@ void DitherGen(DitherData& data, int32_t recursion)
{
Vec2 vec = point - data.Points[i];
Vec2 wrappedVec{bx::mod(vec.x + 0.5f, 1.0f) - 0.5f, bx::mod(vec.y + 0.5f, 1.0f) - 0.5f};
float curDist = wrappedVec.Magnitude();
float curDist = Magnitude(wrappedVec);
dist = bx::min(dist, curDist);
}

View File

@@ -463,7 +463,7 @@ namespace Game
mat.State = 0 | BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_WRITE_Z | BGFX_STATE_DEPTH_TEST_LESS |
BGFX_STATE_CULL_CCW | BGFX_STATE_MSAA;
mat.Uniforms[Material::UTime] = bgfx::createUniform("u_time", bgfx::UniformType::Vec4);
mat.Uniforms[Material::UDotColor] = bgfx::createUniform("u_testColor", bgfx::UniformType::Vec4);
mat.Uniforms[Material::UDotColor] = bgfx::createUniform("u_dotColor", 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.ViewID = view;

View File

@@ -95,8 +95,6 @@ namespace Game
uint16_t MainViewID = 10;
float LastShaderLoadTime = 0.0f;
int32_t DitherRecursion = 1;
Vec4 DefaultBaseColor;
Vec4 DefaultTileColor;
public:
void Setup();

View File

@@ -9,7 +9,7 @@ SAMPLER2D(s_texColor, 0);
SAMPLER3D(s_ditherSampler, 1);
SAMPLER2D(s_rampSampler, 2);
uniform vec4 u_time;
uniform vec4 u_testColor;
uniform vec4 u_dotColor;
uniform vec4 u_texInfo;
uniform vec4 u_baseColor;
@@ -92,7 +92,7 @@ void main()
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;
vec3 texColor = u_dotColor.x > 0.1 ? u_dotColor.xyz : texture2D(s_texColor, v_uv0).xyz;
// lighting
// float brightness = calcBrightness(lightPos, v_wpos, v_normal);

View File

@@ -9,7 +9,7 @@ SAMPLER2D(s_texColor, 0);
SAMPLER3D(s_ditherSampler, 1);
SAMPLER2D(s_rampSampler, 2);
uniform vec4 u_time;
uniform vec4 u_testColor;
uniform vec4 u_dotColor;
uniform vec4 u_texInfo;
uniform vec4 u_baseColor;
@@ -89,6 +89,7 @@ void main()
{
vec2 uv = vec2(1.0 - v_uv0.x, v_uv0.y);
vec3 rawTex = texture2D(s_texColor, uv).xyz;
vec3 col = rawTex * u_dotColor.xyz;
float brightness = lerp(0.5, 0.9, calcBrightnessDirectional(vec3(0.5, 0.3, 1.0), v_normal));
gl_FragColor = vec4(rawTex, 1.0);
gl_FragColor = vec4(col * brightness, 1.0);
}