Skip to content

Autoexposure example restoration #728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
096e09d
Add luma_meter and tonemapper
nipunG314 Jul 19, 2024
4fd700f
Update submodule pointer
nipunG314 Jul 19, 2024
f93bb0f
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla …
nipunG314 Jul 20, 2024
6152f96
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla …
nipunG314 Jul 24, 2024
2311521
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla …
nipunG314 Jul 26, 2024
52e7ab2
Convert morton.h to hlsl
nipunG314 Aug 1, 2024
1cc26bd
Fix HLSL morton code
nipunG314 Aug 2, 2024
6922d0c
Create geom_luma_meter and computeLuma
nipunG314 Aug 5, 2024
6e6eb64
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla …
nipunG314 Aug 5, 2024
603a92f
Add gatherLuma method
nipunG314 Aug 7, 2024
810a6ac
Add getGatheredLuma()
nipunG314 Aug 8, 2024
69a73c1
Add reinhard and aces hlsl operators
nipunG314 Aug 8, 2024
72e0bc5
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla …
nipunG314 Aug 13, 2024
4c70cf5
cast mask values to correct type
nipunG314 Aug 13, 2024
d9d6dd8
Add create methods to tonemapper params
nipunG314 Aug 16, 2024
305f7e7
Remove getGatheredLuma from luma_meter
nipunG314 Aug 16, 2024
3f4f6e9
Separate LumaMeteringWindow into a common header
nipunG314 Aug 20, 2024
515512a
Simplify luma_meter naming
nipunG314 Aug 20, 2024
77f5756
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla …
nipunG314 Aug 20, 2024
1919e53
Simplify morton code
nipunG314 Aug 20, 2024
4c58238
Add missing comment
nipunG314 Aug 20, 2024
3c3f8b8
Refactor tonemapping operators
nipunG314 Aug 20, 2024
b0e0750
Small fixes
nipunG314 Aug 20, 2024
e8e46c9
Use promote to simplify code
nipunG314 Aug 21, 2024
ee5affe
Add static create to MeteringWindow
nipunG314 Aug 21, 2024
56389f4
Infer sample count from viewportSize
nipunG314 Aug 21, 2024
23771d1
Rename gatherLuma, add toXYZ method and templatize the float type
nipunG314 Aug 22, 2024
ac39039
Add uploadFloat, downloadFloat and gatherLuma
nipunG314 Aug 26, 2024
49a8049
Normalize tileOffset and coord to uv before computing Luma
nipunG314 Aug 27, 2024
8a10ae2
Simplify return statement
nipunG314 Sep 29, 2024
6b01b6d
Update submodule pointers
nipunG314 Dec 11, 2024
4129afe
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla …
nipunG314 Dec 11, 2024
f95f1c1
Update submodule pointer
nipunG314 Dec 11, 2024
1a58273
Update submodule pointer
nipunG314 Dec 13, 2024
b6e1f57
Update submodule pointer
nipunG314 Dec 13, 2024
5239c29
Update submodule pointer
nipunG314 Jan 14, 2025
0df9ba6
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla …
nipunG314 Jan 14, 2025
06c915e
stop rolling back my modules!
Jan 21, 2025
90d20c4
point submodule at head
Jan 21, 2025
26a4ed2
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla …
nipunG314 Feb 22, 2025
4edd38c
Add capabilities for atomic ops
nipunG314 Mar 13, 2025
f1e3e98
Fix luma_meter
nipunG314 Mar 13, 2025
ce2ca41
Merge branch 'autoexposue_ex' of github.com:Devsh-Graphics-Programmin…
nipunG314 Mar 13, 2025
f1b7d17
Add median_luma_meter
nipunG314 Mar 16, 2025
83ac633
Update submodule pointer
nipunG314 Mar 16, 2025
2b5e502
Make changes to luma_meter
nipunG314 Mar 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/nbl/asset/utils/IMeshPacker.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define __NBL_ASSET_I_MESH_PACKER_H_INCLUDED__

#include "nbl/asset/utils/IMeshManipulator.h"
#include "nbl/core/math/morton.h"
#include "nbl/builtin/hlsl/math/morton.hlsl"

namespace nbl
{
Expand Down
7 changes: 4 additions & 3 deletions include/nbl/asset/utils/IVirtualTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include <functional>

#include "nbl/core/math/morton.h"
#include "nbl/core/memory/memory.h"
#include "nbl/core/alloc/GeneralpurposeAddressAllocator.h"
#include "nbl/core/alloc/PoolAddressAllocator.h"
Expand All @@ -19,6 +18,8 @@
#include "nbl/asset/filters/CPaddedCopyImageFilter.h"
#include "nbl/asset/filters/CFillImageFilter.h"

#include "nbl/builtin/hlsl/math/morton.hlsl"

namespace nbl::asset
{

Expand Down Expand Up @@ -921,7 +922,7 @@ class IVirtualTexture : public core::IReferenceCounted, public IVirtualTextureBa
storage->incrTileCounter(neededPhysPages);

return offsetToTextureData(
page_tab_offset_t(core::morton2d_decode_x(addr), core::morton2d_decode_y(addr), pgtLayer),
page_tab_offset_t(hlsl::morton2d_decode_x(addr), hlsl::morton2d_decode_y(addr), pgtLayer),
extent,
_subres.levelCount,
_wrapu,
Expand All @@ -933,7 +934,7 @@ class IVirtualTexture : public core::IReferenceCounted, public IVirtualTextureBa
{
uint32_t sz = computeSquareSz(_addr.origsize_x, _addr.origsize_y);
sz *= sz;
const uint32_t addr = core::morton2d_encode(_addr.pgTab_x, _addr.pgTab_y);
const uint32_t addr = hlsl::morton2d_encode(_addr.pgTab_x, _addr.pgTab_y);

core::address_allocator_traits<pg_tab_addr_alctr_t>::multi_free_addr(m_pageTableLayerAllocators[_addr.pgTab_layer], 1u, &addr, &sz);

Expand Down
113 changes: 113 additions & 0 deletions include/nbl/builtin/hlsl/luma_meter/luma_meter.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Copyright (C) 2018-2024 - DevSH Graphics Programming Sp. z O.O.
// This file is part of the "Nabla Engine".
// For conditions of distribution and use, see copyright notice in nabla.h

#ifndef _NBL_BUILTIN_HLSL_LUMA_METER_INCLUDED_
#define _NBL_BUILTIN_HLSL_LUMA_METER_INCLUDED_

#include "nbl/builtin/hlsl/cpp_compat.hlsl"
#include "nbl/builtin/hlsl/glsl_compat/core.hlsl"
#include "nbl/builtin/hlsl/glsl_compat/subgroup_basic.hlsl"
#include "nbl/builtin/hlsl/workgroup/basic.hlsl"
#include "nbl/builtin/hlsl/workgroup/arithmetic.hlsl"
#include "nbl/builtin/hlsl/type_traits.hlsl"
#include "nbl/builtin/hlsl/math/morton.hlsl"
#include "nbl/builtin/hlsl/colorspace/EOTF.hlsl"
#include "nbl/builtin/hlsl/colorspace/OETF.hlsl"
#include "nbl/builtin/hlsl/colorspace/encodeCIEXYZ.hlsl"

namespace nbl
{
namespace hlsl
{
namespace luma_meter
{

struct LumaMeteringWindow
{
float32_t2 meteringWindowScale;
float32_t2 meteringWindowOffset;
};

template<uint32_t GroupSize, typename ValueAccessor, typename SharedAccessor, typename TexAccessor>
struct geom_luma_meter {
using this_t = geom_luma_meter<GroupSize, ValueAccessor, SharedAccessor, TexAccessor>;

static this_t create(NBL_REF_ARG(LumaMeteringWindow) window, float32_t lumaMinimum, float32_t lumaMaximum)
{
this_t retval;
retval.window = window;
retval.minLuma = lumaMinimum;
retval.maxLuma = lumaMaximum;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo, you've set the min and max equal to each other

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P.S. its also more useful to take a precomputed minLumaLog2 and lumaLog2Range (diff between log of max and log of min)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still outstanding for the geom meter

return retval;
}

float32_t reduction(float32_t value, NBL_REF_ARG(SharedAccessor) sdata)
{
return workgroup::reduction < plus < float32_t >, GroupSize >::
template __call <SharedAccessor>(value, sdata);
}

float32_t computeLuma(
NBL_REF_ARG(TexAccessor) tex,
uint32_t2 sampleCount,
uint32_t2 sampleIndex,
float32_t2 viewportSize
)
{
float32_t2 stride = window.meteringWindowScale / (sampleCount + float32_t2(1.0f, 1.0f));
float32_t2 samplePos = stride * sampleIndex;
float32_t2 uvPos = (samplePos + float32_t2(0.5f, 0.5f)) / viewportSize;
float32_t3 color = colorspace::oetf::sRGB(tex.get(uvPos));
float32_t luma = dot(colorspace::sRGBtoXYZ[1], color);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually require/expect a TexAccessor::toXYZ static member float32_t3x3 variable :P

think of it as the TexAccessor telling everyone what the colorspace of the image is

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


luma = clamp(luma, minLuma, maxLuma);

return log2(luma / minLuma) / log2(maxLuma / minLuma);
}

void gatherLuma(
NBL_REF_ARG(ValueAccessor) val,
NBL_REF_ARG(TexAccessor) tex,
NBL_REF_ARG(SharedAccessor) sdata,
uint32_t2 sampleCount,
float32_t2 viewportSize
)
{
uint32_t2 coord = {
morton2d_decode_x(glsl::gl_LocalInvocationIndex()),
morton2d_decode_y(glsl::gl_LocalInvocationIndex())
};
uint32_t tid = workgroup::SubgroupContiguousIndex();

uint32_t2 sampleIndex = coord * GroupSize + float32_t2(glsl::gl_SubgroupID() + 1, glsl::gl_SubgroupInvocationID() + 1);
float32_t luma = 0.0f;

if (sampleIndex.x <= sampleCount.x && sampleIndex.y <= sampleCount.y) {
luma = computeLuma(tex, sampleCount, sampleIndex, viewportSize);
float32_t lumaSum = reduction(luma, sdata);

sdata.workgroupExecutionAndMemoryBarrier();

if (tid == GroupSize - 1) {
uint32_t3 workGroupCount = glsl::gl_NumWorkGroups();
uint32_t fixedPointBitsLeft = 32 - uint32_t(ceil(log2(workGroupCount.x * workGroupCount.y * workGroupCount.z))) + glsl::gl_SubgroupSizeLog2();

uint32_t lumaSumBitPattern = uint32_t(clamp((lumaSum - log2(minLuma)) * (log2(maxLuma) - log2(minLuma)), 0.f, float32_t((1 << fixedPointBitsLeft) - 1)));

uint32_t3 workgroupSize = glsl::gl_WorkGroupSize();
uint32_t workgroupIndex = dot(uint32_t3(workgroupSize.y * workgroupSize.z, workgroupSize.z, 1), glsl::gl_WorkGroupID());

val.atomicAdd(workgroupIndex & ((1 << glsl::gl_SubgroupSizeLog2()) - 1), lumaSumBitPattern);
}
}
}

LumaMeteringWindow window;
float32_t minLuma, maxLuma;
};
}
}
}

#endif
Loading