00. VOLUME DISPLACE in a volume VOP
Add additioanl detasils to your smoke simulation or volume with a simple script
float pow_abs_turb(vector sample_point; float roughness; float lacunarity; int octaves; float exponent;){
float sum = 0;
float weight = 1.0;
vector samp_p = sample_point;
for(int i = 0; i<octaves+1; i++){
sum+= pow(abs(fit01(noise(samp_p),-1.0,1.0)), exponent) *weight;
samp_p *= lacunarity;
weight *= roughness;
}
return sum;
}
vector freq = chv("freq");
vector offset = chv("offset");
float scale = chf("scale");
float rough = chf("rough");
float lacun = chf("lacunarity");
int oct = chi("octaves");
float exp = chf("exp");
vector pos = v@P * freq + offset;
float val = pow_abs_turb(pos,rough,lacun,oct,exp);
vector grad = normalize(volumegradient(0,0,v@P));
f@density = volumesample(0,0,v@P - (grad * val * scale));
01. STICK TO SURFACE (custom function)
// custom function that return values which are the same as volumegradient and volumesample trick, just doesn't need a VDB input
vector move_to_surface_geo(int input; vector pos; export vector grad; export float sample){
int posprim;
vector primuv;
float sign = 0;
float dist = xyzdist(input, pos, posprim, primuv);
vector prim_pos = primuv(input, "P", posprim, primuv);
vector prim_n = primuv(input, "N", posprim, primuv);
grad = -normalize(prim_pos - pos);
sample = length(prim_pos - pos);
float dot = degrees(acos(dot(normalize(grad), normalize(prim_n))));
if(dot < 90){ sign = 1;} else {sign = -1;}
sample *= sign;
grad *= sign;
return prim_pos;
}