Streaking the object mask along the reversed gradient to displace the height field areas above the rocks.
For heigth fields the volumegradient is the direction up the hill, thus negating the normalize(grad) is used to offset the sampling position downwards. The volumesample then checks if the mask is painted at that position with if(sample > 0.1). If it is painted, then the actual position (above the mask) is painted, as well, albeit with fading strength defined by u which is the division of current iteration by the total number of iterations.
vector grad = volumegradient(0, 'height', v@P);
vector pos = v@P - normalize(grad) * 2.5;
float sample = volumesample(0, 'mask', pos);
int iter = detail(1, 'iteration', 0);
int num = detail(1, 'numiterations', 0);
float u = 1.0 - iter / (num - 1.0);
if(sample > 0.1) f@mask = max(f@mask, 1.0 * u);
snow_accum.hipnc contains a more elegant approach:
int steps = chi('steps');
float w = chf('width');
float dist = 0.0;
if(f@mask < 0.5){
vector pos = v@P;
for(int i = 0; i < steps; i++){
vector grad = volumegradient(0, 'height', pos);
pos -= normalize(grad) * w;
float mask = volumesample(0, 'mask', pos);
if(mask > 0.5){
dist = 1.0 - i / (steps - 1.0);
break;
}
}
}
f@mask = max(f@mask, dist);