Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit 78361ca

Browse files
committed
Added a clamp parameter to bloom
1 parent 5191508 commit 78361ca

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this package will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [InDev]
8+
9+
### Added
10+
- Bloom now comes with a **Clamp** parameter to limit the amount of bloom that comes with ultra-bright pixels.
11+
712
## [2.0.6-preview]
813

914
### Fixed

PostProcessing/Editor/Effects/BloomEditor.cs

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public sealed class BloomEditor : PostProcessEffectEditor<Bloom>
88
SerializedParameterOverride m_Intensity;
99
SerializedParameterOverride m_Threshold;
1010
SerializedParameterOverride m_SoftKnee;
11+
SerializedParameterOverride m_Clamp;
1112
SerializedParameterOverride m_Diffusion;
1213
SerializedParameterOverride m_AnamorphicRatio;
1314
SerializedParameterOverride m_Color;
@@ -21,6 +22,7 @@ public override void OnEnable()
2122
m_Intensity = FindParameterOverride(x => x.intensity);
2223
m_Threshold = FindParameterOverride(x => x.threshold);
2324
m_SoftKnee = FindParameterOverride(x => x.softKnee);
25+
m_Clamp = FindParameterOverride(x => x.clamp);
2426
m_Diffusion = FindParameterOverride(x => x.diffusion);
2527
m_AnamorphicRatio = FindParameterOverride(x => x.anamorphicRatio);
2628
m_Color = FindParameterOverride(x => x.color);
@@ -37,6 +39,7 @@ public override void OnInspectorGUI()
3739
PropertyField(m_Intensity);
3840
PropertyField(m_Threshold);
3941
PropertyField(m_SoftKnee);
42+
PropertyField(m_Clamp);
4043
PropertyField(m_Diffusion);
4144
PropertyField(m_AnamorphicRatio);
4245
PropertyField(m_Color);

PostProcessing/Runtime/Effects/Bloom.cs

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public sealed class Bloom : PostProcessEffectSettings
2020
[Range(0f, 1f), Tooltip("Makes transition between under/over-threshold gradual (0 = hard threshold, 1 = soft threshold).")]
2121
public FloatParameter softKnee = new FloatParameter { value = 0.5f };
2222

23+
[Tooltip("Clamps pixels to control the bloom amount.")]
24+
public FloatParameter clamp = new FloatParameter { value = 65472f };
25+
2326
[Range(1f, 10f), Tooltip("Changes the extent of veiling effects. For maximum quality stick to integer values. Because this value changes the internal iteration count, animating it isn't recommended as it may introduce small hiccups in the perceived radius.")]
2427
public FloatParameter diffusion = new FloatParameter { value = 7f };
2528

@@ -122,6 +125,7 @@ public override void Render(PostProcessRenderContext context)
122125
float knee = lthresh * settings.softKnee.value + 1e-5f;
123126
var threshold = new Vector4(lthresh, lthresh - knee, knee * 2f, 0.25f / knee);
124127
sheet.properties.SetVector(ShaderIDs.Threshold, threshold);
128+
sheet.properties.SetVector(ShaderIDs.Params, new Vector4(settings.clamp, 0f, 0f, 0f));
125129

126130
int qualityOffset = settings.fastMode ? 1 : 0;
127131

PostProcessing/Shaders/Builtins/Bloom.shader

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Shader "Hidden/PostProcessing/Bloom"
1414
float _SampleScale;
1515
float4 _ColorIntensity;
1616
float4 _Threshold; // x: threshold value (linear), y: threshold - knee, z: knee * 2, w: 0.25 / knee
17+
float4 _Params; // x: clamp, yzw: unused
1718

1819
// ----------------------------------------------------------------------------------------
1920
// Prefilter
@@ -23,6 +24,7 @@ Shader "Hidden/PostProcessing/Bloom"
2324
half autoExposure = SAMPLE_TEXTURE2D(_AutoExposureTex, sampler_AutoExposureTex, uv).r;
2425
color *= autoExposure;
2526
color = QuadraticThreshold(color, _Threshold.x, _Threshold.yzw);
27+
color = min(_Params.x, color); // clamp to max
2628
return color;
2729
}
2830

0 commit comments

Comments
 (0)