Skip to content

Commit d1f2c9c

Browse files
committed
test
1 parent da7f9dd commit d1f2c9c

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

src/engine/renderer/glsl_source/cameraEffects_fp.glsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ vec3 TonemapLottes( vec3 color ) {
5555

5656
#if defined(HAVE_ARB_explicit_uniform_location) && defined(HAVE_ARB_shader_atomic_counters)
5757
layout(std140, binding = BIND_LUMINANCE) uniform ub_LuminanceUBO {
58-
uint luminanceU;
58+
uvec2 luminanceU;
5959
};
6060
#endif
6161

6262
float GetAverageLuminance( const in uint luminance ) {
63-
return float( luminanceU ) / ( u_TonemapParms2[1] * u_ViewWidth * u_ViewHeight );
63+
return float( luminance ) / ( u_TonemapParms2[1] * u_ViewWidth * u_ViewHeight );
6464
}
6565
#endif
6666

@@ -77,7 +77,7 @@ void main() {
7777
if( u_Tonemap ) {
7878
#if defined(HAVE_ARB_explicit_uniform_location) && defined(HAVE_ARB_shader_atomic_counters)
7979
if( u_TonemapAdaptiveExposure ) {
80-
const float l = GetAverageLuminance( luminanceU ) - 8;
80+
const float l = GetAverageLuminance( luminanceU.x ) - 8;
8181
color.rgb *= clamp( 0.18f / exp2( l * 0.8f + 0.1f ), 0.0f, 2.0f );
8282
}
8383
#endif

src/engine/renderer/glsl_source/clearFrameData_cp.glsl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3838

3939
layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
4040

41-
layout(std430, binding = BIND_LUMINANCE_STORAGE) writeonly buffer luminanceBuffer {
42-
uint luminance;
41+
layout(std430, binding = BIND_LUMINANCE_STORAGE) restrict buffer luminanceBuffer {
42+
uvec2 luminance;
4343
};
4444

4545
uniform uint u_Frame;
4646

4747
void main() {
48-
const uint globalInvocationID = GLOBAL_INVOCATION_ID;
49-
if( globalInvocationID >= 1 ) {
50-
return;
51-
}
52-
luminance = 0;
48+
const uint globalInvocationID = GLOBAL_INVOCATION_ID;
49+
if( globalInvocationID >= 1 ) {
50+
return;
51+
}
52+
luminance.x = uint( 0.15f * luminance.y + ( 1.0f - 0.15f ) * luminance.x );
5353
}

src/engine/renderer/glsl_source/luminanceReduction_cp.glsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ z: reserved
5050
w: reserved */
5151
uniform vec4 u_TonemapParms2;
5252

53-
layout (binding = BIND_LUMINANCE) uniform atomic_uint atomicLuminance;
53+
layout (binding = BIND_LUMINANCE) uniform atomic_uint atomicLuminance[2];
5454

5555
float ColorToLuminance( const in vec3 color ) {
5656
float luminance = dot( color.rgb, vec3( 0.2126f, 0.7152f, 0.0722f ) ); // sRGB luminance
@@ -78,9 +78,9 @@ void main() {
7878
const float luminanceSum = subgroupInclusiveAdd( luminance );
7979

8080
if( subgroupElect() ) {
81-
atomicCounterAddARB( atomicLuminance, FloatLuminanceToUint( luminanceSum ) );
81+
atomicCounterAddARB( atomicLuminance[1], FloatLuminanceToUint( luminanceSum ) );
8282
}
8383
#else
84-
atomicCounterAddARB( atomicLuminance, FloatLuminanceToUint( luminance ) );
84+
atomicCounterAddARB( atomicLuminance[1], FloatLuminanceToUint( luminance ) );
8585
#endif
8686
}

src/engine/renderer/tr_backend.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3214,8 +3214,8 @@ void RB_FXAA()
32143214
static void AdaptiveLightingReduction() {
32153215
luminanceBuffer.BindBufferBase( GL_SHADER_STORAGE_BUFFER, Util::ordinal( BufferBind::LUMINANCE_STORAGE ) );
32163216

3217-
gl_clearFrameDataShader->BindProgram( 0 );
3218-
gl_clearFrameDataShader->DispatchCompute( 1, 1, 1 );
3217+
// gl_clearFrameDataShader->BindProgram( 0 );
3218+
// gl_clearFrameDataShader->DispatchCompute( 1, 1, 1 );
32193219

32203220
luminanceBuffer.BindBufferBase( GL_ATOMIC_COUNTER_BUFFER, Util::ordinal( BufferBind::LUMINANCE ) );
32213221

@@ -3239,7 +3239,10 @@ static void AdaptiveLightingReduction() {
32393239

32403240
gl_luminanceReductionShader->DispatchCompute( globalWorkgroupX, globalWorkgroupY, 1 );
32413241

3242-
glMemoryBarrier( GL_UNIFORM_BARRIER_BIT );
3242+
glMemoryBarrier( GL_SHADER_STORAGE_BARRIER_BIT | GL_UNIFORM_BARRIER_BIT );
3243+
3244+
gl_clearFrameDataShader->BindProgram( 0 );
3245+
gl_clearFrameDataShader->DispatchCompute( 1, 1, 1 );
32433246
}
32443247

32453248
static void ComputeTonemapParams( const float contrast, const float highlightsCompressionSpeed,

src/engine/renderer/tr_vbo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,8 @@ void R_InitVBOs()
783783

784784
if ( glConfig2.adaptiveExposureAvailable ) {
785785
luminanceBuffer.GenBuffer();
786-
luminanceBuffer.BufferData( 1, nullptr, GL_DYNAMIC_COPY );
786+
uint32_t data[2] {};
787+
luminanceBuffer.BufferData( 2, data, GL_DYNAMIC_COPY );
787788
}
788789

789790
GL_CheckErrors();

0 commit comments

Comments
 (0)