wip
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
#include "bx/constants.h"
|
||||||
|
#include "bx/math.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@@ -7,6 +9,31 @@ namespace
|
|||||||
Game::GameInstance* GameInst = nullptr;
|
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
|
namespace Game
|
||||||
{
|
{
|
||||||
SharedData& GetShared()
|
SharedData& GetShared()
|
||||||
|
|||||||
@@ -34,6 +34,9 @@ struct Quat
|
|||||||
float Y = 0.0f;
|
float Y = 0.0f;
|
||||||
float Z = 0.0f;
|
float Z = 0.0f;
|
||||||
float W = 1.0f;
|
float W = 1.0f;
|
||||||
|
|
||||||
|
static Quat FromEuler(float x, float y, float z);
|
||||||
|
static Quat FromEuler(Vec3 rot);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Mat4
|
struct Mat4
|
||||||
|
|||||||
@@ -5,6 +5,23 @@
|
|||||||
#include <bx/math.h>
|
#include <bx/math.h>
|
||||||
#include <bgfx/bgfx.h>
|
#include <bgfx/bgfx.h>
|
||||||
|
|
||||||
|
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
|
namespace Game
|
||||||
{
|
{
|
||||||
void Level::Setup(GameData& data)
|
void Level::Setup(GameData& data)
|
||||||
@@ -25,6 +42,8 @@ namespace Game
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Cube* floor = Cubes.New();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,23 +59,28 @@ namespace Game
|
|||||||
|
|
||||||
void Cube::Update()
|
void Cube::Update()
|
||||||
{
|
{
|
||||||
double globalTime = GetInstance().Now;
|
if (TestX >= 0 && TestY >= 0)
|
||||||
double time = TestY <= 5 ? globalTime * 0.1f : 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));
|
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
|
else
|
||||||
{
|
{
|
||||||
float rot[16]{0};
|
CreateTransform(Transform.M, {0.0f, -30.0f, 100.0f}, {}, {100.0f, 10.0f, 100.0f});
|
||||||
bx::mtxRotateXY(rot, time + TestX * 0.1f, time * 2 + TestY * .37f);
|
// Nothing for now
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ namespace Game
|
|||||||
|
|
||||||
struct Cube
|
struct Cube
|
||||||
{
|
{
|
||||||
int32_t TestX = 0;
|
int32_t TestX = -1;
|
||||||
int32_t TestY = 0;
|
int32_t TestY = -1;
|
||||||
Mat4 Transform;
|
Mat4 Transform;
|
||||||
uint16_t MaterialIdx = 0;
|
uint16_t MaterialIdx = 0;
|
||||||
uint16_t ModelIdx = 0;
|
uint16_t ModelIdx = 0;
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -172,7 +172,7 @@ namespace Game
|
|||||||
bx::mtxLookAt(view, eye, at);
|
bx::mtxLookAt(view, eye, at);
|
||||||
|
|
||||||
float proj[16];
|
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);
|
bgfx::setViewTransform(0, view, proj);
|
||||||
|
|
||||||
// Set view 0 default viewport.
|
// Set view 0 default viewport.
|
||||||
|
|||||||
@@ -6,9 +6,11 @@ $input v_uv0
|
|||||||
float circle(vec2 uv, float radius)
|
float circle(vec2 uv, float radius)
|
||||||
{
|
{
|
||||||
float distSq = uv.x * uv.x + uv.y * uv.y;
|
float distSq = uv.x * uv.x + uv.y * uv.y;
|
||||||
float result = distSq / (radius * radius);
|
// float result = distSq / (radius * radius);
|
||||||
return result < 1.0;
|
float result = sqrt(distSq) / radius / 2;
|
||||||
// return clamp(1.0 - result, 0.0, 1.0);
|
// 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)
|
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 step3 = clamp(step - 2, 0.0, 1.0);
|
||||||
|
|
||||||
float sum = 0.0;
|
float sum = 0.0;
|
||||||
sum += circle(baseUv, lerp(0.5, 0.25, subLevel));
|
// sum += circle(baseUv, lerp(0.5, 0.25, subLevel));
|
||||||
sum += circle(step1Uv, 0.25 * step1);
|
// sum += circle(step1Uv, 0.25 * step1);
|
||||||
sum += circle(step2Uv, 0.25 * step2);
|
// sum += circle(step2Uv, 0.25 * step2);
|
||||||
sum += circle(step3Uv, 0.25 * step3);
|
// 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);
|
return min(sum, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
float2 dx = ddx(v_uv0);
|
float baseScale = 4.0;
|
||||||
float2 dy = ddy(v_uv0);
|
float2 dx = ddx(v_uv0 * baseScale);
|
||||||
|
float2 dy = ddy(v_uv0 * baseScale);
|
||||||
float2x2 mat = float2x2(dx, dy);
|
float2x2 mat = float2x2(dx, dy);
|
||||||
float4 vectorized = float4(dx, dy);
|
float4 vectorized = float4(dx, dy);
|
||||||
float qq = dot(vectorized, vectorized);
|
float qq = dot(vectorized, vectorized);
|
||||||
@@ -47,7 +54,7 @@ void main()
|
|||||||
|
|
||||||
float spacing = freq.y * exp2(2.0);
|
float spacing = freq.y * exp2(2.0);
|
||||||
spacing *= 128.0; // TODO: check reference to see how to calculate this!
|
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);
|
int patternScaleLevel = floor(spacingLog);
|
||||||
float patternFractional = spacingLog - patternScaleLevel;
|
float patternFractional = spacingLog - patternScaleLevel;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user