diff --git a/src/game/Global.cpp b/src/game/Global.cpp index cf03445..a4293eb 100644 --- a/src/game/Global.cpp +++ b/src/game/Global.cpp @@ -1,4 +1,6 @@ #include "Global.h" +#include "bx/constants.h" +#include "bx/math.h" #include namespace @@ -7,6 +9,31 @@ namespace Game::GameInstance* GameInst = nullptr; } +Quat Quat::FromEuler(float x, float y, float z) +{ + x *= bx::kPi / 180.0f; + y *= bx::kPi / 180.0f; + z *= bx::kPi / 180.0f; + + float cX = bx::cos(x); + float cY = bx::cos(y); + float cZ = bx::cos(z); + float sX = bx::sin(x); + float sY = bx::sin(y); + float sZ = bx::sin(z); + + return Quat{ + cX * cY * cZ - sX * sY * sZ, + sY * cX * cZ - sX * sZ * cY, + sX * sY * cZ + sZ * cX * cY, + sX * cY * cZ + sY * sZ * cX }; +} + +Quat Quat::FromEuler(Vec3 rot) +{ + return Quat::FromEuler(rot.X, rot.Y, rot.Z); +} + namespace Game { SharedData& GetShared() diff --git a/src/game/Global.h b/src/game/Global.h index a9a9f61..f6936a5 100644 --- a/src/game/Global.h +++ b/src/game/Global.h @@ -34,6 +34,9 @@ struct Quat float Y = 0.0f; float Z = 0.0f; float W = 1.0f; + + static Quat FromEuler(float x, float y, float z); + static Quat FromEuler(Vec3 rot); }; struct Mat4 diff --git a/src/game/Level.cpp b/src/game/Level.cpp index 56f1c4f..b551055 100644 --- a/src/game/Level.cpp +++ b/src/game/Level.cpp @@ -5,6 +5,23 @@ #include #include +namespace +{ + void CreateTransform(float* out, Vec3 pos, Quat rot = {}, Vec3 scale = {1.0f, 1.0f, 1.0f}) + { + if (out == nullptr) return; + float rMat[16]{0}; + float tMat[16]{0}; + float sMat[16]{0}; + bx::mtxFromQuaternion(rMat, bx::Quaternion{rot.X, rot.Y, rot.Z, rot.W}); + bx::mtxTranslate(tMat, pos.X, pos.Y, pos.Z); + bx::mtxScale(sMat, scale.X, scale.Y, scale.Z); + float buf[16]{0}; + bx::mtxMul(buf, rMat, sMat); + bx::mtxMul(out, buf, tMat); + } +} + namespace Game { void Level::Setup(GameData& data) @@ -25,6 +42,8 @@ namespace Game } } } + + Cube* floor = Cubes.New(); } } @@ -40,23 +59,28 @@ namespace Game void Cube::Update() { - double globalTime = GetInstance().Now; - double time = TestY <= 5 ? globalTime * 0.1f : 0.0f; - if (TestX == 4 && TestY == 4) + if (TestX >= 0 && TestY >= 0) { - bx::mtxTranslate(Transform.M, 0, 0, bx::lerp(-20.0f, -32.0f, bx::sin(globalTime* 0.5f) * 0.5 + 0.5)); + double globalTime = GetInstance().Now; + double time = TestY <= 5 ? globalTime * 1.0f : 0.0f; + if (TestX == 4 && TestY == 4) + { + bx::mtxTranslate(Transform.M, 0, 0, bx::lerp(-20.0f, -32.0f, bx::sin(globalTime* 0.5f) * 0.5 + 0.5)); + } + else + { + float scale = 1.0f + TestX * 0.4f; + CreateTransform(Transform.M, + Vec3{TestX * 10.0f - 40.0f, TestY * 10.0f - 40.0f, (float)TestX}, + Quat::FromEuler(time * 10.0f + TestX, time * 5.0f * TestY, 0.0f), + {scale, scale, scale} + ); + } } else { - float rot[16]{0}; - bx::mtxRotateXY(rot, time + TestX * 0.1f, time * 2 + TestY * .37f); - float scale[16]{0}; - bx::mtxScale(scale, 1.0f + TestX * 0.4f); - float pos[16]{0}; - bx::mtxTranslate(pos, TestX * 10.0f - 40.0f, TestY * 10.0f - 40.0f, TestX); - float buf[16]{0}; - bx::mtxMul(buf, scale, rot); - bx::mtxMul(Transform.M, buf, pos); + CreateTransform(Transform.M, {0.0f, -30.0f, 100.0f}, {}, {100.0f, 10.0f, 100.0f}); + // Nothing for now } } } diff --git a/src/game/Level.h b/src/game/Level.h index e6e9b8e..579ef6a 100644 --- a/src/game/Level.h +++ b/src/game/Level.h @@ -11,8 +11,8 @@ namespace Game struct Cube { - int32_t TestX = 0; - int32_t TestY = 0; + int32_t TestX = -1; + int32_t TestY = -1; Mat4 Transform; uint16_t MaterialIdx = 0; uint16_t ModelIdx = 0; diff --git a/src/game/compiled-shaders/dx11/frag.bin b/src/game/compiled-shaders/dx11/frag.bin index 5b62834..ed22548 100644 Binary files a/src/game/compiled-shaders/dx11/frag.bin and b/src/game/compiled-shaders/dx11/frag.bin differ diff --git a/src/game/compiled-shaders/glsl/frag.bin b/src/game/compiled-shaders/glsl/frag.bin index bec58c9..6c70e3c 100644 Binary files a/src/game/compiled-shaders/glsl/frag.bin and b/src/game/compiled-shaders/glsl/frag.bin differ diff --git a/src/game/compiled-shaders/spirv/frag.bin b/src/game/compiled-shaders/spirv/frag.bin index 41ad20b..c867604 100644 Binary files a/src/game/compiled-shaders/spirv/frag.bin and b/src/game/compiled-shaders/spirv/frag.bin differ diff --git a/src/game/rendering/Rendering.cpp b/src/game/rendering/Rendering.cpp index 46e13d7..2987aec 100644 --- a/src/game/rendering/Rendering.cpp +++ b/src/game/rendering/Rendering.cpp @@ -172,7 +172,7 @@ namespace Game bx::mtxLookAt(view, eye, at); float proj[16]; - bx::mtxProj(proj, 75.0f, float(shared.Window.WindowWidth) / float(shared.Window.WindowHeight), 0.1f, 100.0f, bgfx::getCaps()->homogeneousDepth); + bx::mtxProj(proj, 75.0f, float(shared.Window.WindowWidth) / float(shared.Window.WindowHeight), 0.1f, 1000.0f, bgfx::getCaps()->homogeneousDepth); bgfx::setViewTransform(0, view, proj); // Set view 0 default viewport. diff --git a/src/game/shaders/frag.sc b/src/game/shaders/frag.sc index e6b6b39..2b6380f 100644 --- a/src/game/shaders/frag.sc +++ b/src/game/shaders/frag.sc @@ -6,9 +6,11 @@ $input v_uv0 float circle(vec2 uv, float radius) { float distSq = uv.x * uv.x + uv.y * uv.y; - float result = distSq / (radius * radius); - return result < 1.0; - // return clamp(1.0 - result, 0.0, 1.0); + // float result = distSq / (radius * radius); + float result = sqrt(distSq) / radius / 2; + // float result = sqrt(distSq) / radius; + // return result < 1.0; + return clamp(1.0 - result, 0.0, 1.0); } float circles(vec2 uv, float level, float subLevel) @@ -25,18 +27,23 @@ float circles(vec2 uv, float level, float subLevel) float step3 = clamp(step - 2, 0.0, 1.0); float sum = 0.0; - sum += circle(baseUv, lerp(0.5, 0.25, subLevel)); - sum += circle(step1Uv, 0.25 * step1); - sum += circle(step2Uv, 0.25 * step2); - sum += circle(step3Uv, 0.25 * step3); + // sum += circle(baseUv, lerp(0.5, 0.25, subLevel)); + // sum += circle(step1Uv, 0.25 * step1); + // sum += circle(step2Uv, 0.25 * step2); + // sum += circle(step3Uv, 0.25 * step3); + sum = circle(baseUv, lerp(0.5, 0.25, subLevel)); + sum = max(sum, circle(step1Uv, 0.25 * step1)); + sum = max(sum, circle(step2Uv, 0.25 * step2)); + sum = max(sum, circle(step3Uv, 0.25 * step3)); return min(sum, 1.0); } void main() { - float2 dx = ddx(v_uv0); - float2 dy = ddy(v_uv0); + float baseScale = 4.0; + float2 dx = ddx(v_uv0 * baseScale); + float2 dy = ddy(v_uv0 * baseScale); float2x2 mat = float2x2(dx, dy); float4 vectorized = float4(dx, dy); float qq = dot(vectorized, vectorized); @@ -47,7 +54,7 @@ void main() float spacing = freq.y * exp2(2.0); spacing *= 128.0; // TODO: check reference to see how to calculate this! - float spacingLog = log2(spacing); + float spacingLog = max(log2(spacing), 1.0); int patternScaleLevel = floor(spacingLog); float patternFractional = spacingLog - patternScaleLevel;