Auto exposure fixes
This commit is contained in:
parent
44f1e115e9
commit
54bb309807
|
@ -288,38 +288,8 @@ void main() {
|
|||
#endif
|
||||
|
||||
#ifdef _AutoExposure
|
||||
vec3 expo = textureLod(histogram, vec2(0.5, 0.5), 0).rgb +
|
||||
textureLod(histogram, vec2(0.1, 0.9), 0).rgb +
|
||||
textureLod(histogram, vec2(0.9, 0.9), 0).rgb +
|
||||
textureLod(histogram, vec2(0.9, 0.1), 0).rgb +
|
||||
textureLod(histogram, vec2(0.9, 0.9), 0).rgb;
|
||||
fragColor.rgb *= 1.0 - min(length(expo) / 5, autoExposureStrength);
|
||||
#endif
|
||||
#ifdef _Hist // Auto-exposure
|
||||
if (texCoord.x < 0.1) fragColor.rgb = textureLod(histogram, vec2(0, 0), 9.0).rrr; // 512x512
|
||||
// float minBrightness = 0.03f;
|
||||
// float maxBrightness = 2.0f;
|
||||
// float minAdaptation = 0.60f;
|
||||
// float maxAdaptation = 0.9f;
|
||||
// float minFractionSum = minAdaptation * sumValue;
|
||||
// float maxFractionSum = maxAdaptation * sumValue;
|
||||
// float sumWithoutOutliers = 0.0f;
|
||||
// float sumWithoutOutliersRaw = 0.0f;
|
||||
// for (int i = 0; i < numHistogramBuckets; ++i) {
|
||||
// float localValue = luminanceHistogram[i];
|
||||
// float vmin = min(localValue, minFractionSum);
|
||||
// localValue -= vmin;
|
||||
// localValue = localValue - vmin;
|
||||
// minFractionSum -= vmin;
|
||||
// maxFractionSum -= vmin;
|
||||
// localValue = min(localValue, maxFractionSum);
|
||||
// maxFractionSum -= localValue;
|
||||
// float luminanceAtBucket = GetLuminanceAtBucket(i);
|
||||
// sumWithoutOutliers += luminanceAtBucket * localValue;
|
||||
// sumWithoutOutliersRaw += localValue;
|
||||
// }
|
||||
// float unclampedLuminance = sumWithoutOutliers / max(0.0001f, sumWithoutOutliersRaw);
|
||||
// float clampedLuminace = clamp(unclampedLuminance, minBrightness, maxBrightness);
|
||||
float expo = 1.3 - clamp(length(textureLod(histogram, vec2(0.5, 0.5), 0).rgb), 0.0, 1.0);
|
||||
fragColor.rgb *= pow(expo, autoExposureStrength);
|
||||
#endif
|
||||
|
||||
#ifdef _CToneFilmic
|
||||
|
|
17
Shaders/histogram_pass/histogram_pass.frag.glsl
Normal file
17
Shaders/histogram_pass/histogram_pass.frag.glsl
Normal file
|
@ -0,0 +1,17 @@
|
|||
#version 450
|
||||
|
||||
uniform sampler2D tex;
|
||||
|
||||
in vec2 texCoord;
|
||||
out vec4 fragColor;
|
||||
|
||||
void main() {
|
||||
const float speed = 0.01;
|
||||
fragColor.a = speed;
|
||||
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;
|
||||
}
|
17
Shaders/histogram_pass/histogram_pass.json
Normal file
17
Shaders/histogram_pass/histogram_pass.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"contexts": [
|
||||
{
|
||||
"name": "histogram_pass",
|
||||
"depth_write": false,
|
||||
"compare_mode": "always",
|
||||
"cull_mode": "none",
|
||||
"blend_source": "source_alpha",
|
||||
"blend_destination": "inverse_source_alpha",
|
||||
"blend_operation": "add",
|
||||
"links": [],
|
||||
"texture_params": [],
|
||||
"vertex_shader": "../include/pass.vert.glsl",
|
||||
"fragment_shader": "histogram_pass.frag.glsl"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -311,15 +311,15 @@ class RenderPathDeferred {
|
|||
{
|
||||
var t = new RenderTargetRaw();
|
||||
t.name = "histogram4";
|
||||
t.width = 0;
|
||||
t.height = 0;
|
||||
t.scale = 1 / 64;
|
||||
t.width = 1;
|
||||
t.height = 1;
|
||||
t.format = Inc.getHdrFormat();
|
||||
path.createRenderTarget(t);
|
||||
}
|
||||
|
||||
{
|
||||
path.loadShader("shader_datas/copy_pass/copy_pass");
|
||||
path.loadShader("shader_datas/histogram_pass/histogram_pass");
|
||||
}
|
||||
#end
|
||||
|
||||
|
@ -807,7 +807,6 @@ class RenderPathDeferred {
|
|||
// Begin compositor
|
||||
#if rp_autoexposure
|
||||
{
|
||||
// path.generateMipmaps("tex");
|
||||
path.setTarget("histogram0");
|
||||
path.bindTarget("tex", "tex");
|
||||
path.drawShader("shader_datas/copy_pass/copy_pass");
|
||||
|
@ -821,8 +820,8 @@ class RenderPathDeferred {
|
|||
path.bindTarget("histogram2", "tex");
|
||||
path.drawShader("shader_datas/copy_pass/copy_pass");
|
||||
path.setTarget("histogram4");
|
||||
path.bindTarget("histogram3", "tex");
|
||||
path.drawShader("shader_datas/copy_pass/copy_pass");
|
||||
path.bindTarget("tex", "tex");
|
||||
path.drawShader("shader_datas/histogram_pass/histogram_pass");
|
||||
}
|
||||
#end
|
||||
|
||||
|
|
|
@ -303,6 +303,7 @@ def build():
|
|||
if rpdat.rp_compositornodes and rpdat.rp_autoexposure:
|
||||
assets.add_khafile_def('rp_autoexposure')
|
||||
assets.add_shader_pass('copy_pass')
|
||||
assets.add_shader_pass('histogram_pass')
|
||||
|
||||
if rpdat.rp_dynres:
|
||||
assets.add_khafile_def('rp_dynres')
|
||||
|
|
|
@ -440,7 +440,7 @@ class ArmRPListItem(bpy.types.PropertyGroup):
|
|||
arm_volumetric_light_steps: IntProperty(name="Steps", default=20, min=0, update=assets.invalidate_shader_cache)
|
||||
arm_shadowmap_split: FloatProperty(name="Cascade Split", description="Split factor for cascaded shadow maps, higher factor favors detail on close surfaces", default=0.8, update=assets.invalidate_shader_cache)
|
||||
arm_shadowmap_bounds: FloatProperty(name="Cascade Bounds", description="Multiply cascade bounds to capture bigger area", default=1.0, update=assets.invalidate_compiled_data)
|
||||
arm_autoexposure_strength: FloatProperty(name="Auto Exposure Strength", default=0.7, update=assets.invalidate_shader_cache)
|
||||
arm_autoexposure_strength: FloatProperty(name="Auto Exposure Strength", default=1.0, update=assets.invalidate_shader_cache)
|
||||
arm_ssrs_ray_step: FloatProperty(name="Step", default=0.01, update=assets.invalidate_shader_cache)
|
||||
# Compositor
|
||||
arm_letterbox: BoolProperty(name="Letterbox", default=False, update=assets.invalidate_shader_cache)
|
||||
|
|
Loading…
Reference in a new issue