magical new dots
This commit is contained in:
@@ -193,16 +193,17 @@ namespace Game
|
||||
return handle;
|
||||
}
|
||||
|
||||
void DitherGen(DitherData& data)
|
||||
void DitherGen(DitherData& data, int32_t recursion)
|
||||
{
|
||||
constexpr int32_t MaxRecursion = 1;
|
||||
data.Points[0] = {0.0f, 0.0f};
|
||||
data.Points[1] = {0.5f, 0.5f};
|
||||
data.Points[2] = {0.5f, 0.0f};
|
||||
data.Points[3] = {0.0f, 0.5f};
|
||||
data.PointCount = 4;
|
||||
for (int32_t i = 0; i < data.BrightnessBucketCount; ++i)
|
||||
data.BrightnessBuckets[i] = 0;
|
||||
|
||||
for (int32_t recursionLevel = 0; recursionLevel < MaxRecursion; ++recursionLevel)
|
||||
for (int32_t recursionLevel = 0; recursionLevel < recursion; ++recursionLevel)
|
||||
{
|
||||
int32_t startCount = data.PointCount;
|
||||
float offset = bx::pow(0.5f, recursionLevel + 1);
|
||||
@@ -216,7 +217,7 @@ namespace Game
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t dotsPerSide = bx::round(bx::pow(2, MaxRecursion));
|
||||
uint64_t dotsPerSide = bx::round(bx::pow(2, recursion));
|
||||
data.DitherTexDepth = dotsPerSide * dotsPerSide;
|
||||
data.DitherTexWH = 16 * dotsPerSide;
|
||||
uint64_t texPixelCount = data.DitherTexWH * data.DitherTexWH * data.DitherTexDepth;
|
||||
@@ -257,12 +258,20 @@ namespace Game
|
||||
int32_t bucket = bx::clamp(uint32_t(val * DitherData::BrightnessBucketCount),
|
||||
0,
|
||||
DitherData::BrightnessBucketCount - 1);
|
||||
data.BrightnessBuckets[bucket] += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: brightness ramp
|
||||
// Brightness ramp
|
||||
int32_t sum = 0;
|
||||
for (int32_t i = 0; i < data.BrightnessBucketCount; ++i)
|
||||
{
|
||||
sum += data.BrightnessBuckets[data.BrightnessBucketCount - 1 - i];
|
||||
data.BrightnessRamp[i + 1] = sum / (float)texPixelCount;
|
||||
}
|
||||
|
||||
// Upload textures
|
||||
if (isValid(data.PreviewTex))
|
||||
{
|
||||
bgfx::destroy(data.PreviewTex);
|
||||
@@ -273,8 +282,14 @@ namespace Game
|
||||
bgfx::destroy(data.FinalTex);
|
||||
data.FinalTex = BGFX_INVALID_HANDLE;
|
||||
}
|
||||
if (isValid(data.RampTex))
|
||||
{
|
||||
bgfx::destroy(data.RampTex);
|
||||
data.RampTex = BGFX_INVALID_HANDLE;
|
||||
}
|
||||
const bgfx::Memory* memPreview = bgfx::makeRef(data.DitherTex, texPixelCount * sizeof(Vec4));
|
||||
const bgfx::Memory* memFinal = bgfx::makeRef(data.DitherTex, texPixelCount * sizeof(Vec4));
|
||||
const bgfx::Memory* memRamp = bgfx::makeRef(data.BrightnessRamp, sizeof(data.BrightnessRamp));
|
||||
data.PreviewTex = bgfx::createTexture2D(data.DitherTexWH,
|
||||
data.DitherTexWH * data.DitherTexDepth,
|
||||
false,
|
||||
@@ -289,10 +304,16 @@ namespace Game
|
||||
bgfx::TextureFormat::RGBA32F,
|
||||
0,
|
||||
memFinal);
|
||||
data.RampTex = bgfx::createTexture2D(
|
||||
BX_COUNTOF(data.BrightnessRamp), 1, false, 1, bgfx::TextureFormat::R32F, 0, memRamp);
|
||||
|
||||
if (!isValid(data.Sampler))
|
||||
if (!isValid(data.DitherSampler))
|
||||
{
|
||||
data.Sampler = bgfx::createUniform("s_ditherSampler", bgfx::UniformType::Sampler);
|
||||
data.DitherSampler = bgfx::createUniform("s_ditherSampler", bgfx::UniformType::Sampler);
|
||||
}
|
||||
if (!isValid(data.RampSampler))
|
||||
{
|
||||
data.RampSampler = bgfx::createUniform("s_rampSampler", bgfx::UniformType::Sampler);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,7 +399,7 @@ namespace Game
|
||||
{
|
||||
ImGui::LoadIniSettingsFromDisk("imgui.ini");
|
||||
}
|
||||
DitherGen(DitherTextures);
|
||||
DitherGen(DitherTextures, DitherRecursion);
|
||||
}
|
||||
|
||||
void GameRendering::Update()
|
||||
@@ -460,8 +481,10 @@ namespace Game
|
||||
}
|
||||
if (ImGui::Button("Dithergen"))
|
||||
{
|
||||
DitherGen(DitherTextures);
|
||||
DitherGen(DitherTextures, DitherRecursion);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::SliderInt("Recursion", &DitherRecursion, 1, 4);
|
||||
ImGui::Text(
|
||||
"%ux%ux%u", DitherTextures.DitherTexWH, DitherTextures.DitherTexWH, DitherTextures.DitherTexDepth);
|
||||
if (!isValid(DitherTextures.PreviewTex))
|
||||
@@ -474,10 +497,9 @@ namespace Game
|
||||
{(float)DitherTextures.DitherTexWH,
|
||||
(float)DitherTextures.DitherTexWH * DitherTextures.DitherTexDepth});
|
||||
}
|
||||
ImGui::Text("Brightness Buckets (TODO)");
|
||||
for (int32_t i = 0; i < DitherTextures.BrightnessBucketCount; ++i)
|
||||
if (isValid(DitherTextures.RampTex))
|
||||
{
|
||||
ImGui::Text("%u", DitherTextures.BrightnessBuckets[i]);
|
||||
ImGui::Image(DitherTextures.RampTex.idx, {BX_COUNTOF(DitherTextures.BrightnessRamp), 1});
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
Reference in New Issue
Block a user