- 
                Notifications
    
You must be signed in to change notification settings  - Fork 67
 
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
base: master
Are you sure you want to change the base?
Changes from 14 commits
096e09d
              4fd700f
              f93bb0f
              6152f96
              2311521
              52e7ab2
              1cc26bd
              6922d0c
              6e6eb64
              603a92f
              810a6ac
              69a73c1
              72e0bc5
              4c70cf5
              d9d6dd8
              305f7e7
              3f4f6e9
              515512a
              77f5756
              1919e53
              4c58238
              3c3f8b8
              b0e0750
              e8e46c9
              ee5affe
              56389f4
              23771d1
              ac39039
              49a8049
              8a10ae2
              6b01b6d
              4129afe
              f95f1c1
              1a58273
              b6e1f57
              5239c29
              0df9ba6
              06c915e
              90d20c4
              26a4ed2
              4edd38c
              f1e3e98
              ce2ca41
              f1b7d17
              83ac633
              2b5e502
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| +0 −12 | 23_Autoexposure/CMakeLists.txt | |
| +0 −177 | 23_Autoexposure/main.cpp | |
| +25 −0 | 26_Autoexposure/CMakeLists.txt | |
| +19 −0 | 26_Autoexposure/app_resources/present.frag.hlsl | |
| +0 −0 | 26_Autoexposure/config.json.template | |
| +644 −0 | 26_Autoexposure/main.cpp | |
| +0 −0 | 26_Autoexposure/pipeline.groovy | |
| +1 −2 | 35_GeometryCreator/CMakeLists.txt | |
| +1 −0 | CMakeLists.txt | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| // 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/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) | ||
                
      
                  devshgraphicsprogramming marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| { | ||
| this_t retval; | ||
| retval.window = window; | ||
| retval.minLuma = lumaMinimum; | ||
| retval.maxLuma = lumaMaximum; | ||
                
       | 
||
| 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; | ||
                
      
                  devshgraphicsprogramming marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| float32_t2 uvPos = (samplePos + float32_t2(0.5f, 0.5f)) / viewportSize; | ||
                
      
                  devshgraphicsprogramming marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| float32_t3 color = colorspace::eotf::sRGB(tex.get(uvPos)); | ||
| float32_t luma = dot(colorspace::sRGBtoXYZ[1], color); | ||
                
       | 
||
| 
     | 
||
| luma = clamp(luma, minLuma, maxLuma); | ||
| 
     | 
||
| return log2(luma / minLuma) / log2(maxLuma / minLuma); | ||
                
      
                  devshgraphicsprogramming marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| } | ||
| 
     | 
||
| void gatherLuma( | ||
                
      
                  devshgraphicsprogramming marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| 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(); | ||
                
      
                  devshgraphicsprogramming marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| 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) { | ||
                
      
                  devshgraphicsprogramming marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| luma = computeLuma(tex, sampleCount, sampleIndex, viewportSize); | ||
| float32_t lumaSum = reduction(luma, sdata); | ||
| 
     | 
||
| sdata.workgroupExecutionAndMemoryBarrier(); | ||
                
      
                  devshgraphicsprogramming marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| 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); | ||
                
      
                  devshgraphicsprogramming marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| } | ||
| } | ||
| } | ||
| 
     | 
||
| float32_t getGatheredLuma( | ||
| NBL_REF_ARG(ValueAccessor) val, | ||
| uint32_t2 sampleCount | ||
| ) | ||
| { | ||
| uint32_t lumaSumBitPattern = val.get(glsl::gl_SubgroupInvocationID()); | ||
| float32_t lumaSumValue = float32_t(lumaSumBitPattern) / (log2(maxLuma) - log2(minLuma)) + log2(minLuma); | ||
| return glsl::subgroupAdd(lumaSumValue) / (sampleCount.x * sampleCount.y); | ||
| } | ||
| 
     | 
||
| LumaMeteringWindow window; | ||
                
      
                  devshgraphicsprogramming marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| float32_t minLuma, maxLuma; | ||
| }; | ||
| } | ||
| } | ||
| } | ||
| 
     | 
||
| #endif | ||
Uh oh!
There was an error while loading. Please reload this page.