Old 11-23-2020, 05:43 PM   #1
ashcat_lt
Human being with feelings
 
Join Date: Dec 2012
Posts: 7,271
Default Slight better (??) blend modes

This will mix two video inputs together using one of 7 blend modes. It owes quite a lot to this thing from wwwmaze. Couple differences being:


--it explicitly overwrites the input to the track it's on with black so you don't accidentally get weird unintended bleedthrough. Put the things you want to mix on other tracks, and use the in1, in2 parameters to find them. Anything on the track with this plugin (or passed up from below) will be blacked out.
-----it allows you to choose from 64 different inputs rather than "only" 50.
--instead of referencing the blend modes as per the api, which includes like 13 that aren't really things, it only does the ones that actually do things.
-----it forces YUV mode so that modes 17-19 (5-7 here) actually work.
-----it rolls subtract right into the one mode control rather than a separate knob.
-----it includes "add inverse" which is significantly different from subtract. Could probably do the same thing by putting the "invert colors" preset on the in2 track and then just add, but...



Hope this helps somebody. It definitely helps me.


Code:
// ashcat_lt better blend modes
//@param1:blend 'blend' 0.5 0 1 0.5 0.01
//@param2:mode 'blend mode (normal, add, multiply, subtract, add inverse, average a, average b, difference' 0 0 7 0 1
//@param3:in1 'in 1 (-1=next video track)' -1 -1 50 0 1
//@param4:in2 'in 2 (-1=second next)' -1 -1 63 0 1

oldCS=colorspace;
colorspace='YV12';
gfx_set (0,0,0,1,0,-1);
gfx_fillrect (0,0,project_w,project_h);
gfx_blit(in1==-1 ? input_track(0) : in1);

temp = gfx_img_resize (temp,project_w,project_h);
gfx_dest = temp;

mode <= 1 ? //normal, add
 (gfx_blit (in2==-1 ? input_track(1) : in2);
  gfx_mode = mode;
  gfx_a = blend;);
mode == 2 ? //multiply
  (gfx_blit (in2==-1 ? input_track(1) : in2);
   gfx_mode = 3;
   gfx_a = blend;);
mode == 3 ? //subtract
  (gfx_blit (in2==-1 ? input_track(1) : in2);
   gfx_mode = 1;
   gfx_a = -1 * blend;);
mode == 4 ? //add inverse
 (gfx_mode = 0;
  gfx_set (1);  
  gfx_fillrect (0,0,project_w,project_h);
  gfx_mode = 1;
  gfx_a = -1;
  gfx_blit (in2==-1 ? input_track(1) : in2);
  gfx_a = blend;); 
mode == 5 ? //average a
 (gfx_blit (in2==-1 ? input_track(1) : in2);
  gfx_mode = 17;
  gfx_a = blend;);
mode == 6 ? //average b
 (gfx_blit (in2==-1 ? input_track(1) : in2);
  gfx_mode = 18;
  gfx_a = blend;);
mode == 7 ? //difference
 (gfx_blit (in2==-1 ? input_track(1) : in2);
  gfx_mode = 19;
  gfx_a = blend;);

gfx_dest = -1;
gfx_blit(temp);

colorspace=oldCS;
ashcat_lt is offline   Reply With Quote
Old 11-10-2021, 01:12 PM   #2
fuzzball
Human being with feelings
 
fuzzball's Avatar
 
Join Date: Dec 2020
Posts: 214
Default

Pretty cool. With blend=1 and blend mode=7 it creates some bizarre effects.
fuzzball is offline   Reply With Quote
Old 11-10-2021, 03:06 PM   #3
ashcat_lt
Human being with feelings
 
Join Date: Dec 2012
Posts: 7,271
Default

Yeah difference mode is one of my secret weapons in visual work for like ever. It’s amazing having it available for video, and frankly the main reason I built this.
ashcat_lt is offline   Reply With Quote
Old 11-11-2021, 06:26 PM   #4
papagirafe
Human being with feelings
 
papagirafe's Avatar
 
Join Date: Aug 2020
Location: Brasil
Posts: 679
Default

Thanks!

At last the various blend modes do make sense! My favorite is #7 for me too! That gave me an idea to try an undocumented feature suggested by some preset: negative alpha values. Here is a coll little experimental mod:

Code:
// ashcat_lt better blend modes
//@param blend 'blend' 0.5 0 1 0.5 0.01
//@param  mode 'blend mode (normal, add, multiply, subtract, add inverse, average a, average b, difference' 0 0 8 0 1
//@param in1 'in 1 (-1=next video track)' -1 -1 50 0 1
//@param in2 'in 2 (-1=second next)' -1 -1 63 0 1
//@param polarity 'blend polarity' 1 -1 1 0 2

blend*=polarity;
...(the rest is the same)
papagirafe is offline   Reply With Quote
Old 11-11-2021, 06:53 PM   #5
ashcat_lt
Human being with feelings
 
Join Date: Dec 2012
Posts: 7,271
Default

That’s a little redundant, I think. Mode 3 is already just mode 1 but with negative alpha. Mode 4 also uses negative alpha but in a slightly different way. I guess the other modes might do some things with negative alpha, but idk. Note that adding with negative alpha is not exactly the same thing as inverting and then adding, which is why I have the different modes.

Note also that the numbers I use in the parameter for mode do not actually correspond to the gfx_mode numbers used in the code itself. There are a number of unused and/or poorly documented gfx_modes, and I paired that all down to the few I found most useful and put them all on one knob without any blank spots.



----Edit 6/19/23
Working on extending and expanding this. Currently adding green-screen versions of the existing modes. Posting this code just to get it from one computer to another and hiding it in an edit in hopes of not bumping the thread.
Code:
// ashcat_lt better blend modes
//@param1:blend 'blend' 0.5 0 1 0.5 0.01
//@param2:mode 'blend mode (normal, add, multiply, subtract, add inverse, average a, average b, difference' 0 0 11 4 1
//@param3:_in2 'overlay (tracks below)' 1 0 64 32 1
//@param4:_in1 'background (tracks below)' 2 0 64 32 1



function gfx_alloc_trans (img*, w, h)
  local (o_colorspace)
  (o_colorspace = colorspace; 
   colorspace ='RGBA';
   img = gfx_img_resize (img, 0, 0, 1);
   img = gfx_img_resize (img, w, h, 0);
   colorspace = o_colorspace;
   img;
  );

function gfx_blit_to_trans (src*, x, y, w, h, src_x, src_y, src_w, src_h)
  local (o_colorspace, o_mode)
  (o_colorspace = colorspace; 
   colorspace ='RGBA';
   o_mode = gfx_mode;
   gfx_mode = 0;
   gfx_blit (src, 0, x, y, w, h, src_x, src_y, src_w, src_h);
   colorspace = o_colorspace;
   gfx_mode = o_mode;
   dest;
  );
function gfx_blit_from_trans (src*, x, y, w, h, src_x, src_y, src_w, src_h)
  local (o_colorspace, o_mode)
  (o_colorspace = colorspace;
   o_mode = gfx_mode;
   gfx_mode == 0 ? 
     (colorspace = 'RGBA';
      gfx_mode = 0x10000;):gfx_mode = gfx_mode|0x10000;
   gfx_blit (src, 0, x, y, w, h, src_x, src_y, src_w, src_h);
   colorspace = o_colorspace;
   gfx_mode = o_mode;
  );



w = project_w;
h = project_h;

oldCS=colorspace;
colorspace='YV12';

_in1 == 0 ? in1 = 0 : in1 = input_track (_in1 - 1);
_in2 == 0 ? in2 = 0 : in2 = input_track (_in2 - 1);


back = gfx_img_resize (back,project_w,project_h);
gfx_dest = back;
gfx_mode = 0;
gfx_a = 1;
gfx_blit (in1);
over = gfx_alloc_trans (over,project_w,project_h);
gfx_dest = over;

mode <= 1 ? //normal, add
 (gfx_blit (in2);
  _mode = mode;
  _a = blend;);
mode == 2 ? //multiply
  (gfx_blit (in2);
   _mode = 3;
   _a = blend;);
mode == 3 ? //subtract
  (gfx_blit (in2);
   _mode = 1;
   _a = -1 * blend;);
mode == 4 ? //add inverse
 (gfx_mode = 0;
  gfx_set (1);  
  gfx_fillrect (0,0,project_w,project_h);
  gfx_mode = 1;
  gfx_a = -1;
  gfx_blit (in2);
  _mode = 1;
  _a = blend;); 
mode == 5 ? //average a
 (gfx_blit (in2);
  _mode = 17;
  _a = blend;);
mode == 6 ? //average b
 (gfx_blit (in2);
  _mode = 18;
  _a = blend;);
mode == 7 ? //difference
 (gfx_blit (in2);
  _mode = 19;
  _a = blend;);
mode == 8 ? //green add
  (colorspace = 'RGBA';
   gfx_keyedblit (in2, 0, 0, w, h, 0, 0, 5.7,-3,0,0);
   colorspace = 'YV12';
   _mode = 1;
   _a = blend;
   );
mode == 9 ? //green multiply
  (colorspace = 'RGBA';
   gfx_keyedblit (in2, 0, 0, w, h, 0, 0, 5.7,-3,0,0);
   _mode = 3;
   _a = blend;
   );   
mode == 10 ? //green subtract
  (colorspace = 'RGBA';
   gfx_keyedblit (in2, 0, 0, w, h, 0, 0, 5.7,-3,0,0);
   _mode = 1;
      _a = -1 * blend;
   );   
mode == 11 ? //green add inverse
  (colorspace = 'RGBA';
   gfx_mode = 0;
   gfx_set (1);  
   gfx_fillrect (0,0,project_w,project_h);
   gfx_mode = 1;
   gfx_a = -1;
   gfx_keyedblit (in2, 0, 0, w, h, 0, 0, 5.7,-3,0,0);
   _mode = 1;
   _a = blend; 
   
   );   
gfx_dest = -1;
gfx_mode = 0;
gfx_a = 1;
gfx_blit(back);

//gfx_mode = 2;

gfx_mode = _mode;
gfx_a = _a;
gfx_blit_from_trans (over, 0, 0, w, h, 0, 0, w, h);
//gfx_blit(over);



colorspace=oldCS;

Last edited by ashcat_lt; 06-19-2023 at 10:52 AM.
ashcat_lt is offline   Reply With Quote
Old 11-12-2021, 05:33 AM   #6
papagirafe
Human being with feelings
 
papagirafe's Avatar
 
Join Date: Aug 2020
Location: Brasil
Posts: 679
Default

Quote:
Originally Posted by ashcat_lt View Post
That’s a little redundant, I think. Mode 3 is already just mode 1 but with negative alpha. Mode 4 also uses negative alpha but in a slightly different way. I guess the other modes might do some things with negative alpha, but idk. Note that adding with negative alpha is not exactly the same thing as inverting and then adding, which is why I have the different modes.

Note also that the numbers I use in the parameter for mode do not actually correspond to the gfx_mode numbers used in the code itself. There are a number of unused and/or poorly documented gfx_modes, and I paired that all down to the few I found most useful and put them all on one knob without any blank spots.
You're right! I was too eager to test new things after finishing an "intense" project and was just too just too tired to realize your preset was already doing that! I saw it in mode 3 this morning.
papagirafe is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 05:19 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.