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