Approach 1: VDB + Gradient
// Adjust the VDB points based on gradient
float sign = volumesample(1, 0, v@P); // Sample the volume for a signed distance
vector grad = volumesamplev(2, 0, v@P); // Sample the gradient at the point
// If outside the volume (sign > 0), move the point away along the gradient
if (sign > 0) v@P -= sign * normalize(grad) * 1.1;
Explanation:
- Sample Volume:
volumesample(1, 0, v@P)
takes a volume (channel 1), mipmap level 0, and the point’s position (v@P
) to determine if the point is outside the volume (sign > 0
). - Sample Gradient:
volumesamplev(2, 0, v@P)
samples the gradient vector (channel 2) at the point’s position. This gradient indicates the direction of the closest surface. - Adjust Position: If the point is outside the volume, we move it to the surface along the normalized gradient direction (
normalize(grad)
)
Approach 2: VEX fixed box
float bounds = chf("bound_size");
if(abs(@P.x) > bounds / 2.0){
v@vel.x *= -1;
}
if(abs(@P.y) > bounds / 2.0){
v@vel.y *= -1;
}
if(abs(@P.z) > bounds / 2.0){
v@vel.z *= -1;
}