Jump to content

Fade growth attribute after time and repeat from zero


EdwinFumano

Recommended Posts

Hey guys.

 

I have this infection setup but i would like to stop the infection and fade it out to 0 over some time.

Then start again at a different spot and repeat the whole thing. basically like an animated attrib noise but with a fade in/out(growth) to it. 

Any help would be awesome!

infect.gif

Infection.hiplc

Link to comment
Share on other sites

Hi @EdwinFumano,

you could calculate a bunch of eikonal distances using attribute fill inside a for loop and remap them as animation:
 

float speed = chf('speed');
float t = @Time * speed;

int i = floor(t);
float u = frac(t);
int n = npointsgroup(0, 'start');

string att = 'dist_' + itoa(i%n);
float dist = point(0, att, i@ptnum);

float mask = chramp('shape', dist - u + 1.0);
float fade = 1.0 - smooth(0.5, 1.0, u);

f@mask = mask * fade;
setdetailattrib(0, 'active_dist', att, 'set');

image.png.31938724871d116a9a07eaf8a2954818.png 

infection.hip

  • Like 3
Link to comment
Share on other sites

combine in Solver that setup and this setup.
 

float max_age = chf("infect_lifetime"); 
float fade_duration = chf("fade_duration");
if (@infect < 1) {
    string hdapath = "../../../..";
    float radius;
    if ((chi(hdapath + "/useradiusattrib") == 1) && haspointattrib(0, chs(hdapath + "/radiusattrib"))) {
        radius = point(0, chs(hdapath + "/radiusattrib"), @ptnum);
    } else {
        radius = chf(hdapath + "/radius");
    }

    float resist;
    if ((chi(hdapath + "/useresistattrib") == 1) && haspointattrib(0, chs(hdapath + "/resistattrib"))) {
        resist = point(0, chs(hdapath + "/resistattrib"), @ptnum);
    } else {
        resist = 0;
    }

    float strength = chf(hdapath + "/strength");

    int npts[] = nearpoints(0, @P, radius);

    float accum = 0;
    int cnt = 0;
    foreach (int npt; npts){
        float infection = point(0, "infect", npt);
        accum += infection * strength;
        cnt++;
    }

    float avginfect = accum / max(cnt, 1);
    @infect = clamp(@infect + avginfect * (1 - resist), 0, 1);
}


if (@infect > 0.01) {
    @infect_age += 1;
} else {
    @infect_age = 0;
}


if (@infect_age > max_age) {
    float t = fit(@infect_age, max_age, max_age + fade_duration, 1, 0);
    @infect = clamp(t, 0, 1);
}


if (@infect <= 0.01 && @infect_age > max_age + fade_duration) {
    @infect = 0;
    @infect_age = 0;

    
    if (rand(@ptnum + @Frame) < 0.91) {
        @infect = 0.1;
    }
}

 

Mp010dd.gif

image.png

  • Like 1
Link to comment
Share on other sites

18 hours ago, EdwinFumano said:

so there are multiple spots bulding up / fading at at the same time?

image.png.3690d63652bb0b627a3243f54e6ff3a2.png

Put the relevant parts of the code inside a loop to offset the time and increment the mask number with each iteration.

float speed = chf('speed');
int num = chi('infections');

float t = @Time * speed;
int n = npointsgroup(0, 'start');

float mask_collect = 0.0;

for(int k = 0; k < num; k++){
    t += 1.0 / float(num);
    int i = floor(t);
    float u = frac(t);
    
    string att = 'dist_' + itoa(i+k%n);
    float dist = point(0, att, i@ptnum);
    
    float mask = chramp('shape', dist - u + 1.0);
    float fade = 1.0 - smooth(0.5, 1.0, u);
    mask_collect = max(mask_collect, mask * fade);
} 

f@mask = mask_collect;

 

infection_multiple.hip

  • Like 1
Link to comment
Share on other sites

41 minutes ago, EdwinFumano said:

some of the points get more infected than others.

This could be due to the internal order of the point group. try shuffling starting points by randomly picking a point number out of the array:

int seed = chi('seed');

int pts[] = expandpointgroup(0, 'start');
int iter = detail(1, 'iteration', 0);

int pick = pts[int(rand(iter, seed) * len(pts))];

i@group_boundary = i@ptnum == pick;



 

infection_multiple_01.hip

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...