Depth of Field Effect in VEX

calendar_today

13.04.2024

label

VEX, Rendering

mouse

Houdini 20.0

Description

Using two grids as sensor and focus plane along with VEX to render primitive colors to a grid with depth blur.

1 Code

The point wrangle sets random samples around each sensor pixel defined by sample_circle_uniform within an aperture radius. The intersect function shoots rays at the corresponding point on the focus plane. Once all primitive colors are stored inside the clr[] array, their average avg is exported as v@Cd.

C
        int samples = chi('samples');
float aper = chf('aperture');
int stoch = chi('stochastic');

vector clr[] = {};
for(int i = 0; i < samples; i++){
    float c = i / float(samples-1);
    vector2 u = set(1.0 - c, c);
    if(stoch == 1) u = rand(i@ptnum, i);
    vector2 a = sample_circle_uniform(u);
    vector pos = v@P + vector(a) * aper;
    vector dir = normalize(v@opinput1_P - pos);
    int prim_hit = intersect(2, pos, dir * 10.0, set(0), set(0));
    if(prim_hit >= 0){
        vector clr_hit = prim(2, 'Cd', prim_hit);
        append(clr, clr_hit);
    }
}

v@Cd = avg(clr);
    
download

Downloads

link

Related articles

favorite

390

label

VEX

Attribute to match across inputs

favorite

271

label

VEX

Sphere Packing / Dart Throwing Algorithm

favorite

295

label

VEX

Deintersecting spheres with Voronoi

favorite

331

label

VEX

Fitting Planes to Point Clouds

favorite

335

label

VEX

How to Analyze VEX Code

favorite

172

label

VEX

Monte Carlo Geometry Processing