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

Commit 40aea76

Browse files
committed
Fixed bloom iteration count not being properly computed
1 parent fc10e4f commit 40aea76

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

PostProcessing/Runtime/Effects/Bloom.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,19 @@ public override void Render(PostProcessRenderContext context)
8787
// Apply auto exposure adjustment in the prefiltering pass
8888
sheet.properties.SetTexture(ShaderIDs.AutoExposureTex, context.autoExposureTexture);
8989

90-
// Determine the iteration count
91-
float logh = Mathf.Log(context.height, 2f) + Mathf.Min(settings.diffusion.value, 10f) - 10f;
92-
int logh_i = Mathf.FloorToInt(logh);
93-
int iterations = Mathf.Clamp(logh_i, 1, k_MaxPyramidSize);
94-
float sampleScale = 0.5f + logh - logh_i;
95-
sheet.properties.SetFloat(ShaderIDs.SampleScale, sampleScale);
96-
9790
// Do bloom on a half-res buffer, full-res doesn't bring much and kills performances on
9891
// fillrate limited platforms
9992
int tw = context.width / 2;
10093
int th = context.height / 2;
10194

95+
// Determine the iteration count
96+
int s = Mathf.Max(tw, th);
97+
float logs = Mathf.Log(s, 2f) + Mathf.Min(settings.diffusion.value, 10f) - 10f;
98+
int logs_i = Mathf.FloorToInt(logs);
99+
int iterations = Mathf.Clamp(logs_i, 1, k_MaxPyramidSize);
100+
float sampleScale = 0.5f + logs - logs_i;
101+
sheet.properties.SetFloat(ShaderIDs.SampleScale, sampleScale);
102+
102103
// Prefiltering parameters
103104
float lthresh = Mathf.GammaToLinearSpace(settings.threshold.value);
104105
float knee = lthresh * settings.softKnee.value + 1e-5f;
@@ -122,7 +123,8 @@ public override void Render(PostProcessRenderContext context)
122123
cmd.BlitFullscreenTriangle(last, mipDown, sheet, pass);
123124

124125
last = mipDown;
125-
tw /= 2; th /= 2;
126+
tw = Mathf.Max(tw / 2, 1);
127+
th = Mathf.Max(th / 2, 1);
126128
}
127129

128130
// Upsample

0 commit comments

Comments
 (0)