more tooling

This commit is contained in:
Asuro
2025-02-28 02:21:41 +01:00
parent ceb4f69efc
commit 136a0e09a9
10 changed files with 79 additions and 45 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@
*.blend1
tools/remedy-session.rdbg
src/imgui.ini
*.log

View File

@@ -93,6 +93,7 @@ struct SharedDevData
{
uint32_t ChangedShaderCount = 0;
FileChangeNotification ChangedShaders[16];
char ShaderLog[2048]{0};
};
struct GameData

View File

@@ -1,6 +1,7 @@
#include <cstdlib>
#include <cwchar>
#include <fileapi.h>
#include <fstream>
#include <processthreadsapi.h>
#include <synchapi.h>
#define WIN32_LEAN_AND_MEAN
@@ -109,7 +110,17 @@ void FileChangeCheck(HANDLE dirHandle, FileChangeType changeType, const wchar_t*
}
else if (changeType == FileChangeType::Shader)
{
std::system("shadercompile.bat");
std::system("shadercompile.bat > shadercompile.log");
Sleep(1000);
std::ifstream shaderLogFile("shadercompile.log");
if (shaderLogFile.is_open())
{
shaderLogFile.seekg(0, std::ios::end);
uint32_t size = bx::min(BX_COUNTOF(Shared.Dev.ShaderLog), shaderLogFile.tellg());
shaderLogFile.seekg(0);
shaderLogFile.read(Shared.Dev.ShaderLog, size);
shaderLogFile.close();
}
}
else if (changeType == FileChangeType::CompiledShader)
{

View File

@@ -29,13 +29,21 @@ namespace Game
bgfx::setIndexBuffer(currentModel.IndexBuffer);
bgfx::setState(currentMaterial.State);
float TimeValues[4]{0.0f};
TimeValues[0] = GetInstance().Time.Now;
float timeValues[4]{0.0f};
timeValues[0] = GetInstance().Time.Now;
float texInfo[4]{0.0f};
texInfo[0] = currentMaterial.Textures[0].Info.width;
texInfo[1] = currentMaterial.Textures[0].Info.height;
texInfo[2] = rendering.DitherTextures.DitherTexWH;
texInfo[3] = rendering.DitherTextures.DitherTexDepth;
bgfx::setTexture(0, currentMaterial.Textures[0].SamplerHandle, currentMaterial.Textures[0].Handle);
bgfx::setTexture(1, rendering.DitherTextures.DitherSampler, rendering.DitherTextures.FinalTex);
bgfx::setTexture(2, rendering.DitherTextures.RampSampler, rendering.DitherTextures.RampTex);
bgfx::setUniform(currentMaterial.Uniforms[Material::UTime], TimeValues);
bgfx::setUniform(currentMaterial.Uniforms[Material::UTime], timeValues);
bgfx::setUniform(currentMaterial.Uniforms[Material::UDotColor], TestColor);
bgfx::setUniform(currentMaterial.Uniforms[Material::UTexInfo], texInfo);
bgfx::submit(currentMaterial.ViewID, currentMaterial.Shader);
}
@@ -189,7 +197,7 @@ namespace Game
{
player.FreeflyCamTransform.UpdateMatrix();
bgfx::setViewTransform(viewId, player.FreeflyCamTransform.M.M, proj);
bgfx::dbgTextPrintf(1, 0, 0b1100, "NOCLIP");
// bgfx::dbgTextPrintf(1, 0, 0b1100, "NOCLIP");
}
else
{

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -136,7 +136,6 @@ namespace Game
const bgfx::Memory* mem =
bgfx::makeRef(data->data + imageContainer.m_offset, data->size - imageContainer.m_offset);
// const bgfx::Memory* mem = bgfx::makeRef(imageContainer.m_data, imageContainer.m_size);
if (NULL != _info)
{
@@ -356,13 +355,13 @@ namespace Game
{
Log("BGFX setup succeded!");
}
bgfx::setDebug(BGFX_DEBUG_TEXT);
// bgfx::setDebug(BGFX_DEBUG_TEXT);
bgfx::setViewClear(MainViewID, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x3399FFff, 1.0f, 0);
bgfx::setViewRect(MainViewID, 0, 0, shared.Window.WindowWidth, shared.Window.WindowHeight);
DefaultSampler = bgfx::createUniform("s_texColor", bgfx::UniformType::Sampler);
Textures[0].Handle =
loadTexture(bx::FilePath{"models/body.dds"}, BGFX_TEXTURE_NONE | BGFX_SAMPLER_NONE, 0, nullptr, nullptr);
Textures[0].Handle = loadTexture(
bx::FilePath{"models/body.dds"}, BGFX_TEXTURE_NONE | BGFX_SAMPLER_NONE, 0, &Textures[0].Info, nullptr);
Textures[0].SamplerHandle = DefaultSampler;
LoadModels(Models, ModelCount);
@@ -499,8 +498,10 @@ namespace Game
}
if (isValid(DitherTextures.RampTex))
{
ImGui::Image(DitherTextures.RampTex.idx, {BX_COUNTOF(DitherTextures.BrightnessRamp), 1});
ImGui::Image(DitherTextures.RampTex.idx, {BX_COUNTOF(DitherTextures.BrightnessRamp), 8});
}
ImGui::Text("Shader log:");
ImGui::TextWrapped("%s", GetShared().Dev.ShaderLog);
}
ImGui::End();
}
@@ -508,12 +509,12 @@ namespace Game
GetInstance().GameLevel.Update();
GetInstance().GameLevel.Render(MainViewID, Models, Materials);
bgfx::dbgTextPrintf(1, 1, 0x0F, "Time: %.1fs", GetInstance().Time.Now);
for (int32_t i = 0; i < (int32_t)PerfCounterType::COUNT; ++i)
{
bgfx::dbgTextPrintf(
1, 2 + i, 0x0F, "%s Max: %.3fs", PerfCounterNames[i], shared.Window.PerfCounters[i].GetMax());
}
// bgfx::dbgTextPrintf(1, 1, 0x0F, "Time: %.1fs", GetInstance().Time.Now);
// for (int32_t i = 0; i < (int32_t)PerfCounterType::COUNT; ++i)
// {
// bgfx::dbgTextPrintf(
// 1, 2 + i, 0x0F, "%s Max: %.3fs", PerfCounterNames[i], shared.Window.PerfCounters[i].GetMax());
// }
// Finish Frame
imguiEndFrame();
@@ -556,6 +557,7 @@ namespace Game
BGFX_STATE_CULL_CCW | BGFX_STATE_MSAA;
mat.Uniforms[Material::UTime] = bgfx::createUniform("u_time", bgfx::UniformType::Vec4);
mat.Uniforms[Material::UDotColor] = bgfx::createUniform("u_testColor", bgfx::UniformType::Vec4);
mat.Uniforms[Material::UTexInfo] = bgfx::createUniform("u_texInfo", bgfx::UniformType::Vec4);
mat.Textures[0].Handle = tex;
mat.Textures[0].SamplerHandle = sampler;
mat.ViewID = view;

View File

@@ -28,6 +28,7 @@ namespace Game
{
bgfx::UniformHandle SamplerHandle;
bgfx::TextureHandle Handle;
bgfx::TextureInfo Info;
};
struct Model
@@ -44,6 +45,7 @@ namespace Game
{
UTime = 0,
UDotColor = 1,
UTexInfo = 2,
};
bgfx::ProgramHandle Shader;
@@ -68,9 +70,9 @@ namespace Game
struct DitherData
{
static constexpr uint32_t BrightnessBucketCount = 256;
Vec2 Points[1024];
Vec2 Points[4096];
uint32_t PointCount = 0;
Vec4 DitherTex[64 * 64 * 16];
Vec4 DitherTex[256 * 256 * 64];
uint32_t DitherTexWH = 0;
uint32_t DitherTexDepth = 0;
int32_t BrightnessBuckets[BrightnessBucketCount];

View File

@@ -10,6 +10,7 @@ SAMPLER3D(s_ditherSampler, 1);
SAMPLER2D(s_rampSampler, 2);
uniform vec4 u_time;
uniform vec4 u_testColor;
uniform vec4 u_texInfo;
float calcBrightness(vec3 lightPos, vec3 vertPos, vec3 normal)
{
@@ -28,27 +29,14 @@ vec3 desaturate(vec3 color)
return vec3_splat(dot(color, vec3(0.33, 0.34, 0.33)));
}
void main()
float dither(float brightness, vec2 inputUv)
{
// setup
float globalScale = 6.0;
float testRadius = 30.0;
float testSpeed = 1.0;
vec3 testOffset = vec3(0.0, 0.0, 50.0);
float3 lightPos = vec3(sin(u_time.x * testSpeed) * testRadius, 5.0, cos(u_time.x * testSpeed) * testRadius);
vec2 inputUv = v_uv0;
vec3 texColor = u_testColor.x > 0.1 ? u_testColor.xyz : texture2D(s_texColor, v_uv0).xyz;
// lighting
// float brightness = calcBrightness(lightPos, v_wpos, v_normal);
float brightness = lerp(0.5, 0.9, calcBrightnessDirectional(vec3(0.5, 0.3, 1.0), v_normal));
// float brightness = 0.5;
// brightness = lerp(0.2, 1.0, sin(u_time.x) * 0.5 + 0.5);
float globalScale = 8.0;
// constants
float dotsPerSide = 2;
float xRes = u_texInfo.z;
float dotsPerSide = xRes / 16;
float dotsTotal = dotsPerSide * dotsPerSide;
float xRes = 32;
float invXRes = 1 / xRes;
float zRes = dotsTotal;
float invZRes = 1 / zRes;
@@ -70,6 +58,7 @@ void main()
// Figuring out how many dots we want
float scaleExp = exp2(globalScale);
float spacing = freq.y * scaleExp;
spacing *= dotsPerSide * 0.125;
float brightnessSpacingMultiplier = pow(brightnessCurve * 2 + 0.001, -(1 - 0.5));
// float brightnessSpacingMultiplier = 1;
@@ -87,14 +76,34 @@ void main()
float pattern = texture3D(s_ditherSampler, vec3(uv, subLayer)).r;
float contrast = 12 * scaleExp * brightnessSpacingMultiplier * 0.1;
float contrast = 8 * scaleExp * brightnessSpacingMultiplier * 0.1;
contrast *= pow(freq.y / freq.x, 1.0);
float baseVal = lerp(0.5, brightness, saturate(1.05 / (1 + contrast)));
float threshold = 1 - brightnessCurve + 0.6;
vec3 thresholds = threshold.xxx / texColor;
// vec3 finalColor = saturate((pattern - thresholds) * contrast + baseVal);
vec3 finalColor = saturate((pattern - thresholds) * contrast + baseVal);
return saturate((pattern - threshold) * contrast + baseVal);
}
void main()
{
// setup
float testRadius = 30.0;
float testSpeed = 1.0;
vec3 testOffset = vec3(0.0, 0.0, 50.0);
float3 lightPos = vec3(sin(u_time.x * testSpeed) * testRadius, 5.0, cos(u_time.x * testSpeed) * testRadius);
vec3 texColor = u_testColor.x > 0.1 ? u_testColor.xyz : texture2D(s_texColor, v_uv0).xyz;
// lighting
// float brightness = calcBrightness(lightPos, v_wpos, v_normal);
float brightness = lerp(0.5, 0.9, calcBrightnessDirectional(vec3(0.5, 0.3, 1.0), v_normal));
// float brightness = 0.5;
// brightness = lerp(0.2, 1.0, sin(u_time.x) * 0.5 + 0.5);
float r = dither(brightness * texColor.r, v_uv0);
float g = dither(brightness * texColor.g, v_uv0);
float b = dither(brightness * texColor.b, v_uv0);
// float3 finalColor = vec3(r, g, b);
float3 finalColor = dither(brightness, v_uv0);
gl_FragColor = vec4(finalColor, 1.0);
// gl_FragColor = vec4(finalColor * 0.8 + subLayer * 0.2, 1.0);
// gl_FragColor = vec4(finalColor * 0.8 + vec3(uv % 1, 0.0) * 0.2, 1.0);