Monte Carlo Geometry Processing: A Grid-Free Approach to PDE-Based Methods on Volumetric Domains
This VEX code performs a "random walk" color sampling. The sample()
function queries a point cloud (input 1) for the closest point's color and its distance. The walk()
function then uses this information to simulate a random journey, taking steps based on the sampled data. Finally, the main loop executes multiple such walk()
iterations for each point, averaging the resulting colors from the point cloud.
int iter = chi('iterations');
int steps = chi('steps');
function vector4 sample(vector pos){
float dists[];
int pts[] = pcfind(1, 'P', pos, 1.0, 1, dists);
vector clr = point(1, 'Cd', pts[0]);
return set(clr.r, clr.g, clr.b, dists[0]);
}
function vector walk(vector pos; int steps, pt, seed){
vector p = pos;
vector4 c = vector4(0.0);
for(int i = 0; i < steps; i++){
c = sample(p);
if(c[3] < 1e-4) break;
vector2 u = rand(pt * seed, i);
p += sample_circle_uniform(u) * c[3];
}
return set(c.r, c.g, c.b);
}
vector clr = vector(0.0);
for(int k = 0; k < iter; k++){
clr += walk(v@P, steps, i@ptnum, k);
}
v@Cd = clr / float(iter);
Paper by Keenan Crane: https://www.cs.cmu.edu/~kmcrane/Projects/MonteCarloGeometryProcessing/index.html
Tutorial by Entagma: https://entagma.com/advanced-setups-18-implementing-monte-carlo-geometry-processing-in-vex/