Page 1 of 1

More inputs for the "Blend" module

Posted: Wed Oct 06, 2021 5:17 pm
by TKS
Right now when I have to blend 4 images I have to use 3 "Blend" modules because it only accepts 2 inputs. With more images (or sources in general) a scene gets very crowded.

It would be much more convenient if I could connect all 4 (or more) images to one single "Blend" module, and it would blend the first with the second input, blend the result of this with the third input, blend the result of this with the fourth input and etc.etc.

Re: More inputs for the "Blend" module

Posted: Wed Oct 06, 2021 9:47 pm
by Terry Payman
Which blend are you choosing? A very simple ISF module could Add all the images and could easily accommodate (say) six inputs. It could more efficient to limit the module to four inputs, I haven't yet compared performance. Useful to have the module name indicate the maximum number of inputs that can be accommodated, eg "Add4.fs", as further inputs would be apparently be accepted by the module but would not be added into the output.

Re: More inputs for the "Blend" module

Posted: Wed Oct 06, 2021 11:06 pm
by Terry Payman
Attached is a module that can Add up to 6 inputs. On my system there's no performance penalty in having the extra inputs available but unused - it's only a matter of how many inputs are actually connected. With 6 connected inputs the performance is very close to having 4 inputs to 3 Blend modules.

Alpha of the inputs is ignored. Alpha of the output is 1.0

EDIT: This is a trivial and efficient example, demonstrating the ease with which multiple inputs can be accommodated. Here only a single (and simple) blend mode is implemented, but I expect the approach could be extended to other blend modes and to offer a choice of alternative modes.

Re: More inputs for the "Blend" module

Posted: Thu Oct 07, 2021 11:21 am
by TKS
Terry Payman wrote:Attached is a module that can Add up to 6 inputs.
That's actually quite simple to understand and to expand.
I think I remember that someone posted tons of different code to mix/average/whatever different inputs, so it should be doable for me to start with your Shader and add the different "Blend" modes I would probably need.

Thanks a lot :!:

Re: More inputs for the "Blend" module

Posted: Thu Oct 07, 2021 12:48 pm
by Terry Payman
You're welcome :D
I played around a bit further and I made the attached Difference blend module which could be more generally useful than an Add

Further thought on module naming: Starting names with "Blend" will make them easier to find.

I think this could be the source of the code you saw: https://magicmusicvisuals.com/forums/vi ... .php?t=153. I'd almost forgotten about this thread, and my conversation with Eric about the trade-off between versatility and performance. With 6 inputs this attached module is significantly more efficient than cascading 5 Blend modules (140fps vs 96fps on a stress test at 4k resolution), so it might be worth creating separate modules to suit each of your desired blend modes as well as combining all the modes into one module. In a specific instance you can then readily compare the blend options using the all-in-one blend module, perhaps then substituting a dedicated blend module if performance is critical.