diff --git a/src/game/Level.cpp b/src/game/Level.cpp index 3416fcd..4acc0a2 100644 --- a/src/game/Level.cpp +++ b/src/game/Level.cpp @@ -13,14 +13,6 @@ namespace Game Cubes.Setup(data.EntityStorage); if (Cubes.Count == 0) { - uint64_t state = 0 - | BGFX_STATE_WRITE_RGB - | BGFX_STATE_WRITE_A - | BGFX_STATE_WRITE_Z - | BGFX_STATE_DEPTH_TEST_LESS - | BGFX_STATE_CULL_CW - | BGFX_STATE_MSAA; - for (uint32_t yy = 0; yy < 11; ++yy) { for (uint32_t xx = 0; xx < 11; ++xx) @@ -48,10 +40,23 @@ namespace Game void Cube::Update() { - double time = GetInstance().Now; - bx::mtxRotateXY(Transform.M, time + TestX * 0.1f, time * 2 + TestY * .37f); - Transform.M[12] = -15.0f + float(TestX) * 3.0f; - Transform.M[13] = -15.0f + float(TestY) * 3.0f; - Transform.M[14] = 0.0f; + double globalTime = GetInstance().Now; + double time = TestY <= 5 ? globalTime * 0.1f : 0.0f; + if (TestX == 4 && TestY == 4) + { + bx::mtxTranslate(Transform.M, 0, 0, bx::lerp(2.0f, -30.0f, bx::sin(globalTime* 0.5f) * 0.5 + 0.5)); + } + 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); + } } } diff --git a/src/game/compiled-shaders/dx11/frag.bin b/src/game/compiled-shaders/dx11/frag.bin index 3f37315..940235e 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 df3a911..4aef9d4 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 25a5547..8246dee 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 018308d..46e13d7 100644 --- a/src/game/rendering/Rendering.cpp +++ b/src/game/rendering/Rendering.cpp @@ -124,7 +124,7 @@ namespace Game | BGFX_STATE_WRITE_A | BGFX_STATE_WRITE_Z | BGFX_STATE_DEPTH_TEST_LESS - | BGFX_STATE_CULL_CW + | BGFX_STATE_CULL_CCW | BGFX_STATE_MSAA; if (!GetInstance().IsInitialized) @@ -172,7 +172,7 @@ namespace Game bx::mtxLookAt(view, eye, at); float proj[16]; - bx::mtxProj(proj, 60.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, 100.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 6599465..2b3dfe3 100644 --- a/src/game/shaders/frag.sc +++ b/src/game/shaders/frag.sc @@ -3,16 +3,57 @@ $input v_uv0 #include "common.sh" -float circle(vec2 uv, vec2 center, float size) +float circle(vec2 uv, float radius) { - vec2 relPos = uv - center; - float distSq = relPos.x * relPos.x + relPos.y * relPos.y; - return sqrt(distSq) <= size ? 1.0 : 0.0; + radius *= 0.8; + float distSq = uv.x * uv.x + uv.y * uv.y; + float result = distSq > radius * radius; + return 1.0 - result; +} + +float circles(vec2 uv, float level, float subLevel) +{ + vec2 offsetUv = uv + (0.5 + level * 0.5); + vec2 bigUv = (offsetUv % 1.0) - 0.5; + float base = 0.0; + if (subLevel > 0.25) + { + vec2 smallUv = (((offsetUv + 0.25) % 2.0) * 2.0) - 0.5; + base += circle(smallUv, 0.5); + } + if (subLevel > 0.5) + { + vec2 smallUv = (((offsetUv - 0.75) % 2.0) * 2.0) - 0.5; + base += circle(smallUv, 0.5); + } + if (subLevel > 0.75) + { + vec2 smallUv = (((offsetUv + 1.25) % 2.0) * 2.0) - 0.5; + base += circle(smallUv, 0.5); + } + base += circle(bigUv, lerp(0.25, 0.5, 1.0 - subLevel)); + + return base; } void main() { - // gl_FragColor = circle(v_uv0, vec2(0.5, 0.5), 1.0); - float color = v_uv0.x < 0.5 && v_uv0.y < 0.5; - gl_FragColor = vec4(color, color, color, 1.0); + float2 dx = ddx(v_uv0); + float2 dy = ddy(v_uv0); + float2x2 mat = float2x2(dx, dy); + float4 vectorized = float4(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); + + float spacing = freq.y * exp2(2.0); + spacing *= 128.0; // TODO: check reference to see how to calculate this! + float spacingLog = log2(spacing); + int patternScaleLevel = floor(spacingLog); + float patternFractional = spacingLog - patternScaleLevel; + + vec2 uv = v_uv0 * exp2(patternScaleLevel); + gl_FragColor = circles(uv, patternScaleLevel, patternFractional); }