|
Ramlyn
|
I'm doing my first steps in scripting.
Tonight, reading in our forum, I found some posts about blend modes, but I couldn't find anything specific about the basic structure of a blend. Let's suppose I work on a Map Script. I have three inputs and I want to blend them. How would be the script? ( I'm sorry if it is an easy and silly question, but I think that the best way to learn is to see how the basic scripts are done ) |
|||
| Posted: December 13, 2014 1:35 pm | ||||
|
ThreeDee
|
You would take those three source inputs and use percentages to add the values together. Say you had R1, G1, B1, A1; R2, G2, B2, A2; R3, G3, B3, A3. To blend the Red channels in the proportion 30-20-50, would be:
R = R1*.30 + R2*.20 + R3*.50 |
|||
| Posted: December 13, 2014 4:56 pm | ||||
|
Sphinx.
|
FF provides some helpful functions for exactly that. Take a look here:
https://www.filterforge.com/more/help/...esAPI.html |
|||
| Posted: December 14, 2014 10:09 am | ||||
|
Ramlyn
|
Thanks ThreeDee.
So, ... if I let just "r = r1 + r2 ; r3", it should blend with 100% opacity. And, because no particular blending mode was added, the blend should be normal. Or not? I did this : ( 5 inputs ) function prepare() end; function get_sample(x, y) local r1, g1, b1, a1 = get_sample_map(x, y, INPUT01) local r2, g2, b2, a2 = get_sample_map(x, y, INPUT02) local r3, g3, b3, a3 = get_sample_map(x, y, INPUT03) local r4, g4, b4, a4 = get_sample_map(x, y, INPUT04) local r5, g5, b5, a5 = get_sample_map(x, y, INPUT05) r = r1 + r2 + r3 + r4 + r5 g = g1 + g2 + g3 + g4 + g5 b = b1 + b2 + b3 + b4 + b5 a = a1 + a2 + a3 + a4 + a5 return r, g, b, a end; The result should be the same as a multiblend with 100 opacity. Instead... it is not. Why? |
|||
| Posted: December 14, 2014 12:51 pm | ||||
|
Ramlyn
|
Thanks Sphinx. Yes, you're right.
I saw this page. But this is the case of only 2 sources with all blending modes. I was instead trying to understand how a simple blend/multiblend work. What do you think of my script? The result is surely a blend of the 5 inputs but, normally the source on the top should cover the others, instead in this script it doesn't. There is surely some kind of problem, but I don't get it. |
|||
| Posted: December 14, 2014 1:00 pm | ||||
|
Sphinx.
|
Yeah, there is a difference between the average or sum of multiple sources and blending (with an opacity factor). A real blending formula is not that simple really - It has to take into account opacity, alpha from foreground layer and alpha from background layer.
Even with multiple layers, you can still use the FF blending routines - you just have to "nest" things or think in intermediate results: start from the back and blend layer two onto layer 3. Consider that result your new "background" and blend layer one onto that. With more layers it is really just the same. Now the annoying thing about the FF routines / Lua is that the blends can't be called nested due to the multiple results... you can't pass the r,g,b,a result of the first blend onto the next directly, as the blend routine call is considered one parameter and not four by lua. Btw if you don't want to use the build in blending, here is a lua version:
|
|||
| Posted: December 14, 2014 1:26 pm | ||||
|
Ramlyn
|
Thanks for the explanation and the lua version.
So.. we have no function prepare, this means no numerical inputs ( sliders ). OPACITY is a Greyscale Map. FOREGROUND and BACKGROUND are Color Maps. BLEND_MODE looks like another Greyscale Map. But the script gives me error ( attempt to call a nil value ). Is it because of BLEND_MODE set as Greyscale Map? |
|||
| Posted: December 15, 2014 2:15 pm | ||||
|
Sphinx.
|
Oh right.. I forgot about the custom blendmode stuff. Simply comment out that block, i.e. the three lines after -- blendmode callback
|
|||
| Posted: December 16, 2014 6:56 am | ||||
Filter Forge has a thriving, vibrant, knowledgeable user community. Feel free to join us and have fun!
33,736 Registered Users
+14 new in 30 days!
153,582 Posts
+5 new in 7 days!
15,355 Topics
+5 new in 30 days!
16 unregistered users.