Old 10-06-2021, 06:14 PM   #1
papagirafe
Human being with feelings
 
papagirafe's Avatar
 
Join Date: Aug 2020
Location: Brasil
Posts: 679
Default FX: Random deformation grid

I came up with this idea of a cool deformation FX preset while coding another custom preset. Enjoy!



Code:
//FX: random deformations grid
//by Papagirafe
//@param1:divs 'divisions' 20  10 160 80 1
//@param2:ampl 'amplitude' 10 0 80 40  0.1
//@param3:freq 'frequency %' 20 0 100 50 0.1
//@param4:smooth 'smoothing' 1 0 1 0.5 1

function init_transform_table(t*,w,h) 
(
    incrx=w/divs;
    incry=h/divs;
    tx=t;ty=tx+1;i=0;x=0; y=0;
    loop(divs, 
      loop(divs, 
        rx=(rand(2)-1)*ampl*w;
        ry=(rand(2)-1)*ampl*h;
        tx[i]=x+rx+1; 
        ty[i]=y+ry+1; 
        i+=2;
        x+=incrx; 
        );
          y+=incry;
          x=0; 
    ); 
);  

project_wh_valid===0 ? input_info(0,project_w,project_h);
ampl/=1000; 
freq=freq/100*framerate;
update==0?init_transform_table(t,project_w, project_h);
freq?update=(update+1)%(framerate/freq):update=-1; 
gfx_set(0,0,0,1,smooth?0x100:0);
gfx_fillrect(0,0,project_w,project_h);
gfx_xformblit(0, 0,0,project_w,project_h, divs,divs, t, 0);

Last edited by papagirafe; 10-07-2021 at 06:04 AM. Reason: minor code update
papagirafe is offline   Reply With Quote
Old 10-13-2021, 06:50 AM   #2
papagirafe
Human being with feelings
 
papagirafe's Avatar
 
Join Date: Aug 2020
Location: Brasil
Posts: 679
Default

There is a scaling bug (which I don't fully understand yet) with the preset I published, so here is an corrected version with some code cleanup.

Code:
//FX: random deformations grid
//@param1:divs 'divisions' 40  10 160 80 1
//@param2:ampl 'amplitude' 10 0 80 40  0.1
//@param3:freq 'frequency %' 20 0 100 50 0.01
//@param4:smooth 'smoothing' 1 0 1 0.5 1

function init_transform_table(t*,w,h) 
(
    incrx=w/divs*1.04;
    incry=h/divs*1.04;
    i=0;x=0; y=0;
    loop(divs, 
      loop(divs, 
        t[i]=x+(rand(2)-1)*ampl*w; 
        t[i+1]=y+(rand(2)-1)*ampl*h; 
        i+=2;
        x+=incrx; 
        );
          y+=incry;
          x=0; 
    ); 
);  

project_wh_valid===0 ? input_info(0,project_w,project_h);
ampl/=1000; 
freq=freq/100*framerate;
update==0?init_transform_table(t,project_w, project_h);
freq?update=(update+1)%(framerate/freq):update=-1; 
gfx_set(0,0,0,1,smooth?0x100:0);
gfx_fillrect(0,0,project_w,project_h);
gfx_xformblit(0, 0,0,project_w,project_h, divs,divs, t, 0);

Last edited by papagirafe; 10-13-2021 at 06:53 AM. Reason: typos
papagirafe is offline   Reply With Quote
Old 03-03-2023, 07:59 AM   #3
antiClick
Human being with feelings
 
antiClick's Avatar
 
Join Date: Mar 2007
Location: Mediterrenean Sea
Posts: 977
Default

Thank you so much for this effect! It looks wonderful and it doesn't tax the cpu as much as I expected.

Just as a side note, I always found that these video fx should come nicely commented so that others can learn from it.
antiClick is offline   Reply With Quote
Old 03-03-2023, 10:03 AM   #4
papagirafe
Human being with feelings
 
papagirafe's Avatar
 
Join Date: Aug 2020
Location: Brasil
Posts: 679
Default

Quote:
Originally Posted by antiClick View Post
Thank you so much for this effect! It looks wonderful and it doesn't tax the cpu as much as I expected.

Just as a side note, I always found that these video fx should come nicely commented so that others can learn from it.
Wow! It's been a while I did this, one never knows when this becomes usefull for someone else´s project!

gfx_xformblit() always performs its magic very efficiently. You need to populate a transformation table by dividing your bitmap space into a mesh of x/y coordinates inside of it. Any deviation from the expected coordinate will induce a deformation.

This is discussed in this thread: https://forum.cockos.com/showthread.php?t=257394
Also I made another preset that distords the 4 corner coordinates to fix/alter the geometry of a video source: https://forum.cockos.com/showthread.php?t=261577
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 06:39 AM.


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