diff --git a/Assets/common/shader_datas.arm b/Assets/common/shader_datas.arm index d27887a0..6a23d676 100644 Binary files a/Assets/common/shader_datas.arm and b/Assets/common/shader_datas.arm differ diff --git a/Shaders/common/histogram_pass.frag.glsl b/Shaders/common/histogram_pass.frag.glsl new file mode 100644 index 00000000..61bd8eff --- /dev/null +++ b/Shaders/common/histogram_pass.frag.glsl @@ -0,0 +1,17 @@ +#version 450 + +uniform sampler2D tex; + +in vec2 texCoord; +out vec4 fragColor; + +void main() { + const float autoExposureSpeed = 1.0; + fragColor.a = 0.01 * autoExposureSpeed; + fragColor.rgb = textureLod(tex, vec2(0.5, 0.5), 0.0).rgb + + textureLod(tex, vec2(0.2, 0.2), 0.0).rgb + + textureLod(tex, vec2(0.8, 0.2), 0.0).rgb + + textureLod(tex, vec2(0.2, 0.8), 0.0).rgb + + textureLod(tex, vec2(0.8, 0.8), 0.0).rgb; + fragColor.rgb /= 5.0; +} diff --git a/Sources/arm/render/RenderPathDeferred.hx b/Sources/arm/render/RenderPathDeferred.hx index 3c35e427..2b5509b5 100644 --- a/Sources/arm/render/RenderPathDeferred.hx +++ b/Sources/arm/render/RenderPathDeferred.hx @@ -471,9 +471,34 @@ class RenderPathDeferred { } #end + // Begin compositor + #if rp_autoexposure + { + { + var t = new RenderTargetRaw(); + t.name = "histogram"; + t.width = 1; + t.height = 1; + t.format = "RGBA64"; + path.createRenderTarget(t); + path.loadShader("shader_datas/histogram_pass/histogram_pass"); + } + + path.setTarget("histogram"); + path.bindTarget("taa", "tex"); + path.drawShader("shader_datas/histogram_pass/histogram_pass"); + } + #end + path.setTarget("buf"); path.bindTarget("tex", "tex"); + #if rp_autoexposure + { + path.bindTarget("histogram", "histogram"); + } + #end path.drawShader("shader_datas/compositor_pass/compositor_pass"); + // End compositor path.setTarget("buf"); var currentG = path.currentG; diff --git a/Sources/arm/ui/BoxPreferences.hx b/Sources/arm/ui/BoxPreferences.hx index bd8890b9..3bf7edbb 100644 --- a/Sources/arm/ui/BoxPreferences.hx +++ b/Sources/arm/ui/BoxPreferences.hx @@ -182,6 +182,10 @@ class BoxPreferences { UITrait.inst.vignetteStrength = ui.slider(h, "Vignette", 0.0, 1.0, true); if (h.changed) Context.ddirty = 2; + // var h = Id.handle({value: UITrait.inst.autoExposureStrength}); + // UITrait.inst.autoExposureStrength = ui.slider(h, "Auto Exposure", 0.0, 2.0, true); + // if (h.changed) Context.ddirty = 2; + #if arm_creator var h = Id.handle({value: UITrait.inst.vxaoExt}); UITrait.inst.vxaoExt = ui.slider(h, "VXAO Ext", 1.0, 10.0); diff --git a/Sources/arm/ui/UITrait.hx b/Sources/arm/ui/UITrait.hx index 0902e980..54e335c8 100644 --- a/Sources/arm/ui/UITrait.hx +++ b/Sources/arm/ui/UITrait.hx @@ -245,6 +245,7 @@ class UITrait { public var vxaoOffset = 1.5; public var vxaoAperture = 1.2; public var vignetteStrength = 0.4; + // public var autoExposureStrength = 1.0; public var textureExportPath = ""; public var headerHandle = new Handle({layout: Horizontal}); public var toolbarHandle = new Handle();