Simplify softlight glow blending math.#110239
Conversation
|
Is there really a problem with Otherwise the function looks correct but the form is a bit odd. Personally I'd move to use the more widely known version (unless there's a precision benefit or smth that I'm unaware of) for the left side: (color.r + (2.0f * glow.r - 1.0f) * (((16.0f * color.r - 12.0f) * color.r + 4.0f) * color.r - color.r))If you want to be space efficient combine the common parts and place the condition in the middle: (color.r + (2.0f * glow.r - 1.0f) * ((color.r <= 0.25f ? ((16.0f * color.r - 12.0f) * color.r + 4.0f) * color.r : sqrt(color.r)) - color.r))EDIT: Concentrated on the functions at first but if you want to simplify further: glow = glow * vec3(0.5f) + vec3(0.5f);
(2.0f * glow.r - 1.0f);these lines are inverse of one another, so the combined function (the short version for example) could become: (color.r + glow.r * ((color.r <= 0.25f ? ((16.0f * color.r - 12.0f) * color.r + 4.0f) * color.r : sqrt(color.r)) - color.r)) |
Ah, I think you're right; I had just seen (0,undefined) in the graphing calculator and blindly trusted it instead of checking the math myself. |
|
Let's look at the case where glow.r is < 0.5. Assume Before: After |
Glow can never be below 0.5 as it is first clamped to 0 to 1 range and then 0.5 is added. The path for below 0.5 is completely unnecessary as we only want to use the part of soft-light blending that lightens (i.e > 0.5 range). Edit: For further clarity: even in your example it doesn't make sense that glow 0.4 + color 0.8 would result in darker color (0.768) i.e. negative glow. |
|
Aaaaaaah right. I should have read the surrounding code |
d630297 to
0331163
Compare
Wow, I didn't intend to nerd-snipe like this, but this new function looks great to me! I've pushed the changes to this PR with you as co-author. |
0331163 to
b683cc6
Compare
b683cc6 to
ff5707b
Compare
|
I've included the changes from this PR in #110671 and added co-authors to it as well. |
Co-authored-by: Hei <40064911+Lielay9@users.noreply.github.com>
ff5707b to
65c16ed
Compare
|
Superseded by #110671 |
Would someone mind checking my math on this one? It seems that the softlight blend mode has a number of math operations that will never happen.
I've taken a screenshot with this blend mode before and after the change and it resulted in the exact same render.
(I also fixed a comment in another file that incorrectly references the "softlight" term.)
Edit: I've updated the PR to use a better simplification from @Lielay9