Implementation of Gray Scott reaction-diffusion algorithm in Houdini

Source: Internet
Author: User

This article is a long time ago learned a magic algorithm to the file, in the bus suddenly remembered, think it is necessary to carefully comb again, may be useful in the future.

First look at the picture and then say:

The Gray Scott reaction-diffusion algorithm, which simulates microscopic cell movements or similar effects, is very magical.

Theory Link: http://www.karlsims.com/rd.html

Principle: Simulates the interaction between two substances in a plane (temporary plane), the action is divided into reaction and diffusion.

Formula:

On the right hand side the first is diffusion, the second is the reaction, the third is the supply, the DA and DB are dispersion, ▽2A or B is the adjacent position diffusion array (), F and K are two very important external parameters, called feed and kill. Can be easily understood as a is the physical in the environment, two B and a can become three B, the process of the feed will be more a,k will also remove some B. I really want to live in a real environment.

|0.05| 0.2 |0.05|

| 0.2 | -1 | 0.2 |

|0.05| 0.2 |0.05|

The above is the array used by the Laplace equation, because the peripheral sum equals the inverse of the middle number, so the parameterization can be arbitrarily adjusted

In Houdini, use SOP solver to iterate the material changes of a and B, before entering the Solver, first define a and B values, generally a in the entire plane is 1.0,b randomly scattered open, so out of the effect, as I do the B random scatter:

At the same time using the noise method to randomly distribute feeds and kill values, you can certainly use fixed f and K, but random changes will make growth more natural and interesting. Here is a simple schematic of the detail panel:

It is worth noting that the feed and kill values are very sensitive, I myself test, also in a few very narrow interval will have growth effect, or CB will be very fast all die.

Add a new Vex node to preframe in Solver, with the following code:

#pragma label resx "Res X"#pragma label Resy "Res Y"#pragma label diff_a "diffusion a"#pragma label Diff_b "diffusion B"#pragma label weight "weight"#pragma range Weight 0.125 0.25#pragma label feed "feed"#pragma range Feed 0 1#pragma label kill "Kill"#pragma range kill 0 1#pragma label time_step "Sub Step"#pragma range Time_step 0#pragma hint CA invisible#pragma hint cb invisible//this fuction would diffusefloatLaplacianintPtnum;intResXintResy string attrib;floatWeight) {//| w_s | w | w_s |        //-----------------------        //| W |-1 | w |        //-----------------------        //| w_s | w | w_s | Weight        //| pt+w-1 | pt+w | pt+w+1 |        //-----------------------------        //| pt-1 | PT | pt+1 |        //-----------------------------        //| pt-w-1 | pt-w | pt-w+1 | Location        intVb=ResX * *Hb= 1;//detects boundaries        if((Ptnum%ResX== 0 ||(Ptnum%ResX==(resx- 1)) {HB*= -1;//Horizon}if(Ptnum<ResX||Ptnum>(Resy-1)*resx) {VB*= -1;//Vetical}floatN[]; Resize (n,9);floatWeight_second= 0.25 -Weight n[0]=Point0, attrib, ptnum-Vb- 1)*Weight_second;//Left bottomn[1]=Point0, attrib, ptnum-VB)*Weight//Bottomn[2]=Point0, attrib, ptnum-Vb+ 1)*Weight_second;//Right Bottomn[3]=Point0, attrib, ptnum- 1)*Weight// Leftn[4]=Point0, attrib, ptnum)*(-1.0);//Centern[5]=Point0, attrib, ptnum+ 1)*Weight// Rightn[6]=Point0, attrib, ptnum+Vb- 1)*Weight_second;//Left topn[7]=Point0, attrib, ptnum+VB)*Weight//Topn[8]=Point0, attrib, ptnum+Vb+ 1)*Weight_second;//Right Top        floatSum=0.0; foreachfloatI N) {sum+=I }returnsum;} Sopgray_scott (intResX=  +;intResy=  +;floatDiff_a= 1.0;floatDiff_b= 1.0;floatWeight= 0.15; ExportfloatFeed= 0.05; ExportfloatKill= 0.05;floatTime_step= 1.0; ExportfloatCa= 0.0; ExportfloatCb= 0.0; ){floatReact_rate=Ca*POW (CB,2);floatFeed_set=Feed*(1.0 -CA);floatKill_set=(Kill+Feed*cb//float substep = 1.0/(float) time_step;Ca+=(diff_a*Laplacian (Ptnum, ResX, Resy,"Ca", weight)-React_rate+Feed_set)*Time_step; Cb+=(Diff_b*Laplacian (Ptnum, ResX, Resy,"CB", weight)+React_rate-Kill_set)*Time_step;}

Finally, take a look at the different effects of different feeds and kill values:

feed = 0.051 Kill = 0.062

feed = 0.0367 Kill = 0.069

feed = 0.0561 Kill = 0.0636

Implementation of Gray Scott reaction-diffusion algorithm in Houdini

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.