unsuccessful experimentation
This commit is contained in:
@@ -1,6 +1,60 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "bx/timer.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
#define START_PERF() int64_t __perfStart = bx::getHPCounter();
|
||||||
|
#define END_PERF(counters, idx, frame) counters[(int32_t)idx].Write(bx::getHPCounter() - __perfStart, frame);
|
||||||
|
|
||||||
|
enum class PerfCounterType
|
||||||
|
{
|
||||||
|
WindowEvents,
|
||||||
|
GameDelta,
|
||||||
|
COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PerfCounter
|
||||||
|
{
|
||||||
|
static constexpr int32_t TimeWindow = 128;
|
||||||
|
int64_t Times[TimeWindow]{0};
|
||||||
|
void Write(int64_t value, uint64_t frameCounter)
|
||||||
|
{
|
||||||
|
Times[frameCounter % TimeWindow] = value;
|
||||||
|
}
|
||||||
|
float GetAverage()
|
||||||
|
{
|
||||||
|
int64_t sum = 0;
|
||||||
|
for (int32_t i = 0; i < TimeWindow; ++i)
|
||||||
|
{
|
||||||
|
sum += Times[i];
|
||||||
|
}
|
||||||
|
return (double)sum / bx::getHPFrequency();
|
||||||
|
}
|
||||||
|
float GetMin()
|
||||||
|
{
|
||||||
|
int64_t min = INT64_MAX;
|
||||||
|
for (int32_t i = 0; i < TimeWindow; ++i)
|
||||||
|
{
|
||||||
|
if (Times[i] < min)
|
||||||
|
{
|
||||||
|
min = Times[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (double)min / bx::getHPFrequency();
|
||||||
|
}
|
||||||
|
float GetMax()
|
||||||
|
{
|
||||||
|
int64_t max = 0;
|
||||||
|
for (int32_t i = 0; i < TimeWindow; ++i)
|
||||||
|
{
|
||||||
|
if (Times[i] > max)
|
||||||
|
{
|
||||||
|
max = Times[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (double)max / bx::getHPFrequency();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct SharedWindowData
|
struct SharedWindowData
|
||||||
{
|
{
|
||||||
void* Handle = nullptr;
|
void* Handle = nullptr;
|
||||||
@@ -12,6 +66,8 @@ struct SharedWindowData
|
|||||||
bool LastHeldMouseButtons[8]{false};
|
bool LastHeldMouseButtons[8]{false};
|
||||||
float MouseDeltaX = 0.0f;
|
float MouseDeltaX = 0.0f;
|
||||||
float MouseDeltaY = 0.0f;
|
float MouseDeltaY = 0.0f;
|
||||||
|
uint64_t FrameCounter = 0;
|
||||||
|
PerfCounter PerfCounters[(int32_t)PerfCounterType::COUNT] = {0};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FileChangeNotification
|
struct FileChangeNotification
|
||||||
@@ -39,9 +95,9 @@ struct GameData
|
|||||||
|
|
||||||
struct SharedData
|
struct SharedData
|
||||||
{
|
{
|
||||||
|
GameData Game;
|
||||||
SharedDevData Dev;
|
SharedDevData Dev;
|
||||||
SharedWindowData Window;
|
SharedWindowData Window;
|
||||||
GameData Game;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void (*Startup)(SharedData& shared);
|
typedef void (*Startup)(SharedData& shared);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "SDL3/SDL_events.h"
|
#include "SDL3/SDL_events.h"
|
||||||
#include "Shared.h"
|
#include "Shared.h"
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
|
#include "bx/timer.h"
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@ void EngineWindow::Startup(SharedWindowData& shared)
|
|||||||
|
|
||||||
void EngineWindow::Update(SharedWindowData& shared)
|
void EngineWindow::Update(SharedWindowData& shared)
|
||||||
{
|
{
|
||||||
|
START_PERF();
|
||||||
SDL_Event evt;
|
SDL_Event evt;
|
||||||
while (SDL_PollEvent(&evt))
|
while (SDL_PollEvent(&evt))
|
||||||
{
|
{
|
||||||
@@ -75,6 +77,7 @@ void EngineWindow::Update(SharedWindowData& shared)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
END_PERF(shared.PerfCounters, PerfCounterType::WindowEvents, shared.FrameCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EngineWindow::Shutdown()
|
void EngineWindow::Shutdown()
|
||||||
|
|||||||
@@ -4,12 +4,12 @@
|
|||||||
|
|
||||||
class EngineWindow
|
class EngineWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SDL_Window* Window;
|
SDL_Window* Window;
|
||||||
bool CloseRequested = false;
|
bool CloseRequested = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void Startup(SharedWindowData& Shared);
|
void Startup(SharedWindowData& Shared);
|
||||||
void Update(SharedWindowData& Shared);
|
void Update(SharedWindowData& Shared);
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -318,6 +318,7 @@ int main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
UpdateFunc();
|
UpdateFunc();
|
||||||
|
++Shared.Window.FrameCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShutdownFunc();
|
ShutdownFunc();
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ namespace Game
|
|||||||
{
|
{
|
||||||
double Now = 0.0;
|
double Now = 0.0;
|
||||||
double Delta = 0.0;
|
double Delta = 0.0;
|
||||||
uint32_t FrameCounter = 0;
|
int64_t NowHP = 0;
|
||||||
|
int64_t DeltaHP = 1000;
|
||||||
int64_t StartTime = 0;
|
int64_t StartTime = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -68,12 +68,6 @@ namespace Game
|
|||||||
void Level::Update()
|
void Level::Update()
|
||||||
{
|
{
|
||||||
PlayerData& player = GetInstance().Player;
|
PlayerData& player = GetInstance().Player;
|
||||||
if (GetKeyPressedNow(ScanCode::R))
|
|
||||||
{
|
|
||||||
Cubes.Count = 0;
|
|
||||||
Tests.Count = 0;
|
|
||||||
Setup(GetShared().Game);
|
|
||||||
}
|
|
||||||
|
|
||||||
float delta = GetInstance().Time.Delta;
|
float delta = GetInstance().Time.Delta;
|
||||||
constexpr float moveSpeed = 10.0f;
|
constexpr float moveSpeed = 10.0f;
|
||||||
@@ -126,8 +120,8 @@ namespace Game
|
|||||||
EData.Transform.Position = {0.0f, -1.0f, 0.0f};
|
EData.Transform.Position = {0.0f, -1.0f, 0.0f};
|
||||||
EData.Transform.Scale = {100.0f, 1.0f, 100.0f};
|
EData.Transform.Scale = {100.0f, 1.0f, 100.0f};
|
||||||
EData.TestColor[0] = 0.3f;
|
EData.TestColor[0] = 0.3f;
|
||||||
EData.TestColor[1] = 0.4f;
|
EData.TestColor[1] = 0.325f;
|
||||||
EData.TestColor[2] = 0.8f;
|
EData.TestColor[2] = 0.3f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
#include "Input.h"
|
||||||
#include "Instance.h"
|
#include "Instance.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Setup.h"
|
#include "Setup.h"
|
||||||
@@ -53,11 +54,21 @@ namespace Game
|
|||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
++GetInstance().Time.FrameCounter;
|
auto& inst = GetInstance();
|
||||||
double newNow = (bx::getHPCounter() - GetInstance().Time.StartTime) / (double)(bx::getHPFrequency());
|
int64_t newNowHP = bx::getHPCounter() - GetInstance().Time.StartTime;
|
||||||
GetInstance().Time.Delta = newNow - GetInstance().Time.Now;
|
inst.Time.DeltaHP = newNowHP - inst.Time.NowHP;
|
||||||
GetInstance().Time.Now = newNow;
|
inst.Time.NowHP = newNowHP;
|
||||||
|
inst.Time.Now = (double)inst.Time.NowHP / bx::getHPFrequency();
|
||||||
|
inst.Time.Delta = (double)inst.Time.DeltaHP / bx::getHPFrequency();
|
||||||
|
GetShared().Window.PerfCounters[(int32_t)PerfCounterType::GameDelta].Write(inst.Time.DeltaHP,
|
||||||
|
GetShared().Window.FrameCounter);
|
||||||
|
|
||||||
|
if (GetKeyPressedNow(ScanCode::R))
|
||||||
|
{
|
||||||
|
GetInstance().Size = 0;
|
||||||
|
Shutdown();
|
||||||
|
Setup(GetShared());
|
||||||
|
}
|
||||||
SetupInstance.Rendering.Update();
|
SetupInstance.Rendering.Update();
|
||||||
|
|
||||||
auto& win = GetShared().Window;
|
auto& win = GetShared().Window;
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -290,10 +290,14 @@ namespace Game
|
|||||||
GetInstance().GameLevel.Cubes.Render(Models, Materials);
|
GetInstance().GameLevel.Cubes.Render(Models, Materials);
|
||||||
GetInstance().GameLevel.Tests.Render(Models, Materials);
|
GetInstance().GameLevel.Tests.Render(Models, Materials);
|
||||||
|
|
||||||
bgfx::dbgTextPrintf(1, 1, 0x0F, "Time: %.1f", GetInstance().Time.Now);
|
bgfx::dbgTextPrintf(1, 1, 0x0F, "Time: %.1fs", GetInstance().Time.Now);
|
||||||
bgfx::dbgTextPrintf(1, 2, 0x0F, "Frame: %u", GetInstance().Time.FrameCounter);
|
bgfx::dbgTextPrintf(1,
|
||||||
|
2,
|
||||||
|
0x0F,
|
||||||
|
"Window Events: %.3fms",
|
||||||
|
GetShared().Window.PerfCounters[(int32_t)PerfCounterType::WindowEvents].GetMax());
|
||||||
bgfx::dbgTextPrintf(
|
bgfx::dbgTextPrintf(
|
||||||
1, 3, 0x0F, "Delta: %.3fms / %.0ffps", GetInstance().Time.Delta, 1.0 / GetInstance().Time.Delta);
|
1, 3, 0x0F, "Delta: %.3fms", GetShared().Window.PerfCounters[(int32_t)PerfCounterType::GameDelta].GetMax());
|
||||||
|
|
||||||
bgfx::frame();
|
bgfx::frame();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,11 @@ uniform vec4 u_testColor;
|
|||||||
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 = sqrt(distSq) / radius * 0.8;
|
||||||
float result = sqrt(distSq) / radius;
|
float result = sqrt(distSq) / radius;
|
||||||
// return result < 0.5;
|
// float clamped = clamp(1.0 - result, 0.0, 1.0);
|
||||||
return clamp(1.0 - result, 0.0, 1.0);
|
float clamped = clamp(1.5 - result, 0.0, 1.0);
|
||||||
|
return clamped;
|
||||||
}
|
}
|
||||||
|
|
||||||
float calcBrightness(vec3 lightPos, vec3 vertPos, vec3 normal)
|
float calcBrightness(vec3 lightPos, vec3 vertPos, vec3 normal)
|
||||||
@@ -65,8 +67,9 @@ void main()
|
|||||||
// float brightness = calcBrightness(lightPos, v_wpos, v_normal);
|
// float brightness = calcBrightness(lightPos, v_wpos, v_normal);
|
||||||
float brightness = calcBrightnessDirectional(vec3(0.5, 0.3, 1.0), v_normal);
|
float brightness = calcBrightnessDirectional(vec3(0.5, 0.3, 1.0), v_normal);
|
||||||
// brightness = 1.0;
|
// brightness = 1.0;
|
||||||
// brightness = 0.1 + brightness * 0.9;
|
// brightness = sin(u_time.x) * 0.5 + 0.5;
|
||||||
|
|
||||||
|
// Magic dot frequency calculation
|
||||||
float baseScale = 2.0;
|
float baseScale = 2.0;
|
||||||
float2 dx = ddx(v_uv0 * baseScale);
|
float2 dx = ddx(v_uv0 * baseScale);
|
||||||
float2 dy = ddy(v_uv0 * baseScale);
|
float2 dy = ddy(v_uv0 * baseScale);
|
||||||
@@ -78,24 +81,28 @@ void main()
|
|||||||
float discriminant = sqrt(discriminantSqr);
|
float discriminant = sqrt(discriminantSqr);
|
||||||
float2 freq = sqrt(float2(qq + discriminant, qq - discriminant) / 2.0);
|
float2 freq = sqrt(float2(qq + discriminant, qq - discriminant) / 2.0);
|
||||||
|
|
||||||
|
// Figuring out how many dots we want
|
||||||
float spacing = freq.y * exp2(2.0);
|
float spacing = freq.y * exp2(2.0);
|
||||||
spacing = 1.0 / spacing;
|
spacing = 1.0 / spacing;
|
||||||
spacing *= brightness; // TODO: check reference to see how to calculate this!
|
spacing *= brightness; // TODO: check reference to see how to calculate this!
|
||||||
float spacingLog = max(log2(spacing), 0.0);
|
float spacingLog = max(log2(spacing), 0.0);
|
||||||
int patternScaleLevel = floor(spacingLog);
|
int patternScaleLevel = floor(spacingLog);
|
||||||
float patternFractional = spacingLog - patternScaleLevel;
|
float patternFractional = spacingLog - patternScaleLevel;
|
||||||
|
|
||||||
vec2 uv = v_uv0 * exp2(patternScaleLevel);
|
vec2 uv = v_uv0 * exp2(patternScaleLevel);
|
||||||
float dither = circles(uv, patternScaleLevel, patternFractional, brightness);
|
|
||||||
|
// Coloring
|
||||||
vec3 texColor = u_testColor.x > 0.1 ? u_testColor.xyz : texture2D(s_texColor, v_uv0).xyz;
|
vec3 texColor = u_testColor.x > 0.1 ? u_testColor.xyz : texture2D(s_texColor, v_uv0).xyz;
|
||||||
vec3 color = desaturate(texColor) * 0.01 + dither * texColor * 0.95;
|
vec3 color;
|
||||||
vec3 smoothColor = brightness * u_testColor.xyz;
|
color.r = circles(uv, patternScaleLevel, patternFractional, brightness * texColor.r);
|
||||||
vec3 mixedColor = 0.1 * smoothColor + 0.9 * color;
|
color.g = circles(uv, patternScaleLevel, patternFractional, brightness * texColor.g);
|
||||||
// gl_FragColor = vec4(mixedColor, 1.0);
|
color.b = circles(uv, patternScaleLevel, patternFractional, brightness * texColor.b);
|
||||||
|
// color = circles(uv, patternScaleLevel, patternFractional, brightness) * texColor;
|
||||||
gl_FragColor = vec4(color, 1.0);
|
gl_FragColor = vec4(color, 1.0);
|
||||||
|
// vec3 smoothColor = brightness * u_testColor.xyz;
|
||||||
// gl_FragColor = brightness;
|
// gl_FragColor = brightness;
|
||||||
// gl_FragColor = dither;
|
// gl_FragColor = dither;
|
||||||
// gl_FragColor = u_testColor;
|
// gl_FragColor = u_testColor;
|
||||||
// gl_FragColor = texture2D(s_texColor, v_uv0);
|
// gl_FragColor = vec4(texColor, 1.0);
|
||||||
// gl_FragColor = vec4(v_normal, 1.0);
|
// gl_FragColor = vec4(v_normal, 1.0);
|
||||||
|
// gl_FragColor = vec4(uv, 0.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user