Skip to content

Commit a15508e

Browse files
committed
fixes histogram autoexposure
1 parent 42ed25a commit a15508e

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

26_Autoexposure/app_resources/median_luma_meter.comp.hlsl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ using PtrAccessor = BdaAccessor < uint32_t >;
1616

1717
[[vk::push_constant]] AutoexposurePushData pushData;
1818

19-
groupshared uint32_t sdata[WorkgroupSize];
19+
#define BIN_COUNT 1024
20+
21+
groupshared uint32_t sdata[BIN_COUNT];
2022
struct SharedAccessor
2123
{
2224
using type = uint32_t;
@@ -43,7 +45,7 @@ struct SharedAccessor
4345
struct TexAccessor
4446
{
4547
static float32_t3 toXYZ(float32_t3 srgbColor) {
46-
return mul(colorspace::sRGBtoXYZ, srgbColor);
48+
return dot(colorspace::sRGBtoXYZ[1], srgbColor);
4749
}
4850

4951
float32_t3 get(float32_t2 uv) {
@@ -66,7 +68,7 @@ void main(uint32_t3 ID : SV_GroupThreadID, uint32_t3 GroupID : SV_GroupID)
6668
SharedAccessor sdata;
6769
TexAccessor tex;
6870

69-
using LumaMeter = luma_meter::median_meter< WorkgroupSize, 8000, PtrAccessor, SharedAccessor, TexAccessor>;
71+
using LumaMeter = luma_meter::median_meter< WorkgroupSize, BIN_COUNT, PtrAccessor, SharedAccessor, TexAccessor>;
7072
LumaMeter meter = LumaMeter::create(pushData.lumaMinMax);
7173

7274
meter.sampleLuma(pushData.window, histo_accessor, tex, sdata, (float32_t2)(glsl::gl_WorkGroupID() * glsl::gl_WorkGroupSize()), pushData.viewportSize);

26_Autoexposure/app_resources/median_luma_tonemap.comp.hlsl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ using PtrAccessor = BdaAccessor < uint32_t >;
2121

2222
[[vk::push_constant]] AutoexposurePushData pushData;
2323

24-
groupshared uint32_t sdata[WorkgroupSize];
24+
#define BIN_COUNT 1024
25+
26+
groupshared uint32_t sdata[BIN_COUNT];
2527
struct SharedAccessor
2628
{
2729
using type = uint32_t;
@@ -72,7 +74,7 @@ void main(uint32_t3 ID : SV_GroupThreadID, uint32_t3 GroupID : SV_GroupID)
7274
SharedAccessor sdata;
7375
TexAccessor tex;
7476

75-
using LumaMeter = luma_meter::median_meter< WorkgroupSize, 8000, PtrAccessor, SharedAccessor, TexAccessor>;
77+
using LumaMeter = luma_meter::median_meter< WorkgroupSize, BIN_COUNT, PtrAccessor, SharedAccessor, TexAccessor>;
7678
LumaMeter meter = LumaMeter::create(pushData.lumaMinMax);
7779

7880
float32_t EV = meter.gatherLuma(histo_accessor, sdata);
@@ -84,10 +86,10 @@ void main(uint32_t3 ID : SV_GroupThreadID, uint32_t3 GroupID : SV_GroupID)
8486

8587
uint32_t2 pos = (glsl::gl_WorkGroupID() * glsl::gl_WorkGroupSize()).xy + coord;
8688
float32_t2 uv = (float32_t2)(pos) / pushData.viewportSize;
87-
float32_t3 color = colorspace::oetf::sRGB(tex.get(uv).rgb);
89+
float32_t3 color = colorspace::eotf::sRGB(tex.get(uv).rgb);
8890
float32_t3 CIEColor = mul(colorspace::sRGBtoXYZ, color);
8991
tonemapper::Reinhard<float32_t> reinhard = tonemapper::Reinhard<float32_t>::create(EV, 0.18, 0.85f);
9092
float32_t3 tonemappedColor = mul(colorspace::decode::XYZtoscRGB, reinhard(CIEColor));
9193

92-
textureOut[pos] = float32_t4(tonemappedColor, 1.0f);
94+
textureOut[pos] = float32_t4(colorspace::oetf::sRGB(tonemappedColor), 1.0f);
9395
}

26_Autoexposure/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class AutoexposureApp final : public SimpleWindowedApplication, public BuiltinRe
4141
"app_resources/median_luma_tonemap.comp.hlsl",
4242
"app_resources/present.frag.hlsl"
4343
};
44-
constexpr static inline MeteringMode MeterMode = MeteringMode::AVERAGE;
44+
constexpr static inline MeteringMode MeterMode = MeteringMode::MEDIAN;
4545
constexpr static inline uint32_t BinCount = 8000; // TODO: it's 8000 here why? gonna set it to workgroup size (1024) for now
4646
constexpr static inline uint32_t2 Dimensions = { 1280, 720 };
4747
constexpr static inline float32_t2 MeteringWindowScale = { 0.8f, 0.8f };

0 commit comments

Comments
 (0)