From e1826f488ab2e4b242aff5a4ac13102308d39454 Mon Sep 17 00:00:00 2001
From: Lissanro Rayen <Lissanro@Dragon.Studio>
Date: Tue, 1 Jan 2019 14:50:23 +0000
Subject: [PATCH] Physically based defaults for Eevee Bloom and Shutter

Some of Eevee's Bloom defaults are not very good for physically based rendering.
This patches fixes this and extends range for Clamp (so it would be possible to
clamp light sources brighter than the Sun if needed but keep the Sun unclipped).
Bloom Intensity is set to 0.05 by default and updated UI range allows easily set
smaller values to simulate higher quality lens. Bloom Intensity > 0.1 is not
realistic for clean lens but the user can enter manually much larger values
if needed. In Cycles shutter default value is 0.50, so for consistency set to 0.5
by default in Eevee too.

Bloom Intensity: 0.8 > 0.05
Bloom Intensity UI range: 0-10 > 0-0.1
Bloom Clamp: 1.0 > 0.0 (disabled by default)
Bloom Clamp manual range: 0-1000 > 0-100000
Bloom Clamp UI range: 0-10 > 0-1000
Shutter: 1.0 > 0.5
---
 source/blender/blenkernel/intern/scene.c             |  6 +++---
 source/blender/blenloader/intern/versioning_280.c    |  6 +++---
 .../engines/eevee/shaders/effect_bloom_frag.glsl     |  9 ++++++---
 source/blender/makesrna/intern/rna_scene.c           | 12 ++++++------
 4 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 1bae41ce035..f266a839c52 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -929,12 +929,12 @@ void BKE_scene_init(Scene *sce)
 	copy_v3_fl(sce->eevee.bloom_color, 1.0f);
 	sce->eevee.bloom_threshold = 0.8f;
 	sce->eevee.bloom_knee = 0.5f;
-	sce->eevee.bloom_intensity = 0.8f;
+	sce->eevee.bloom_intensity = 0.05f;
 	sce->eevee.bloom_radius = 6.5f;
-	sce->eevee.bloom_clamp = 1.0f;
+	sce->eevee.bloom_clamp = 0.0f;
 
 	sce->eevee.motion_blur_samples = 8;
-	sce->eevee.motion_blur_shutter = 1.0f;
+	sce->eevee.motion_blur_shutter = 0.5f;
 
 	sce->eevee.shadow_method = SHADOW_ESM;
 	sce->eevee.shadow_cube_size = 512;
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 572140a835e..5b6de3083ab 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -1420,12 +1420,12 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
 				copy_v3_fl(scene->eevee.bloom_color, 1.0f);
 				scene->eevee.bloom_threshold = 0.8f;
 				scene->eevee.bloom_knee = 0.5f;
-				scene->eevee.bloom_intensity = 0.8f;
+				scene->eevee.bloom_intensity = 0.05f;
 				scene->eevee.bloom_radius = 6.5f;
-				scene->eevee.bloom_clamp = 1.0f;
+				scene->eevee.bloom_clamp = 0.0f;
 
 				scene->eevee.motion_blur_samples = 8;
-				scene->eevee.motion_blur_shutter = 1.0f;
+				scene->eevee.motion_blur_shutter = 0.5f;
 
 				scene->eevee.shadow_method = SHADOW_ESM;
 				scene->eevee.shadow_cube_size = 512;
diff --git a/source/blender/draw/engines/eevee/shaders/effect_bloom_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_bloom_frag.glsl
index c3674c8f74c..71830cd3c4b 100644
--- a/source/blender/draw/engines/eevee/shaders/effect_bloom_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/effect_bloom_frag.glsl
@@ -164,9 +164,12 @@ vec4 step_blit(void)
 	/* Combine and apply the brightness response curve. */
 	m *= max(rq, br - curveThreshold.w) / max(1e-5, br);
 
-	/* Clamp pixel intensity */
-	br = max(1e-5, brightness(m));
-	m *= 1.0 - max(0.0, br - clampIntensity) / br;
+	/* Clamp pixel intensity if clamping enabled */
+	if(clampIntensity > 0.0)
+	{
+		br = max(1e-5, brightness(m));
+		m *= 1.0 - max(0.0, br - clampIntensity) / br;
+	}
 
 	return vec4(m, 1.0);
 }
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 114672017b7..9f86994288d 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -6177,16 +6177,16 @@ static void rna_def_scene_eevee(BlenderRNA *brna)
 
 	prop = RNA_def_property(srna, "bloom_clamp", PROP_FLOAT, PROP_FACTOR);
 	RNA_def_property_float_default(prop, 1.0f);
-	RNA_def_property_ui_text(prop, "Clamp", "Maximum intensity a bloom pixel can have");
-	RNA_def_property_range(prop, 0.0f, 1000.0f);
-	RNA_def_property_ui_range(prop, 0.0f, 10.0f, 1, 3);
+	RNA_def_property_ui_text(prop, "Clamp", "Maximum intensity a bloom pixel can have (0 to disabled)");
+	RNA_def_property_range(prop, 0.0f, 100000.0f);
+	RNA_def_property_ui_range(prop, 0.0f, 1000.0f, 1, 3);
 	RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_STATIC);
 
-	prop = RNA_def_property(srna, "bloom_intensity", PROP_FLOAT, PROP_UNSIGNED);
-	RNA_def_property_float_default(prop, 0.8f);
+	prop = RNA_def_property(srna, "bloom_intensity", PROP_FLOAT, PROP_FACTOR);
+	RNA_def_property_float_default(prop, 0.05f);
 	RNA_def_property_ui_text(prop, "Intensity", "Blend factor");
 	RNA_def_property_range(prop, 0.0f, 10000.0f);
-	RNA_def_property_ui_range(prop, 0.0f, 10.0f, 1, 3);
+	RNA_def_property_ui_range(prop, 0.0f, 0.1f, 1, 3);
 	RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_STATIC);
 
 	/* Motion blur */
-- 
2.19.1

