KinoBloom
KinoBloom copied to clipboard
Potential divide by zero in Bloom shader
If you look inside Assets/Kino/Bloom/Shader/Bloom.cginc in the prefilter part:
// Under-threshold part: quadratic curve
half rq = clamp(br - _Curve.x, 0, _Curve.y);
rq = _Curve.z * rq * rq;
// Combine and apply the brightness response curve.
m *= max(rq, br - _Threshold) / max(br, 1e-5);
Half is a 16-bit floating number on some platforms (see Unity docs). The smallest "normal" number for a 16-bit float is 0.000061035, so 1e-5, or 0.00001 is either denormalized or flushed to zero, depending on the shader compiler, potentially resulting in nan values for fragments with calculated brightness of 0. I can confirm this happens on Nintendo Switch, probably some mobile platforms too. The areas with nan values in the prefilter texture will get passed down in the downsample/upsample passes and result in black rectangles in the final renderbuffer. Changing this value from 1e-5 to 6.2e-5 resolves the issue.
Thanks for pointing it out. I think this has been fixed in the post-processing stack. I'm not using this effect (KinoBloom) any more, but I'll fix it if there is any chance to update this for some reason.
Thanks for the fix, I'm still using it