Monte Carlo Geometry Processing

calendar_today

19.07.2025

label

VEX

mouse

Houdini 19.5

Description

Monte Carlo Geometry Processing: A Grid-Free Approach to PDE-Based Methods on Volumetric Domains

1 Code Discussion

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.

C
        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);
    

2 Source

download

Downloads

smart_display

Videos

Monte Carlo Geometry Processing

link

Related articles

favorite

347

label

VEX

Attribute to match across inputs

favorite

232

label

VEX

Sphere Packing / Dart Throwing Algorithm

favorite

258

label

VEX

Deintersecting spheres with Voronoi

favorite

291

label

VEX

Fitting Planes to Point Clouds

favorite

301

label

VEX

How to analyze VEX code

favorite

132

label

VEX

Predicate Incircles from 3 points