Group Points by Camera Visibility

calendar_today

14.12.2024

label

VEX, Rendering

mouse

Houdini 20.5

Description

A point wrangle grouping points inside a camera's frustum with an extra check for visibility / occlusion.

1 Code

toNDC() creates normal device coordinates, X and Y between 0.0 and 1.0 will be inside the frustum. To check for visibility, intersect() shoots a ray from each mesh point towards the camera position.

C
        string cam = chs('camera');
vector ndc = toNDC(cam, v@P);

int in_frustum = ndc[0]>=0.0 && ndc[0]<=1.0 && ndc[1]>=0.0 && ndc[1]<=1.0;

i@group_visible = 0;

if(in_frustum){
    vector pos_cam = ptransform( cam, "space:object", {0,0,0} );
    vector dir_cam = pos_cam - v@P;
    vector pos_ray = v@P + normalize(dir_cam) * 1e-3;
    int pr_hit = intersect(0, pos_ray, dir_cam, set(0), set(0));
    i@group_visible = pr_hit < 0;
}
    

2 Screen Space Area

Added an example about procedurally selecting primitives by their area in screen space / normal device coordinates.

download

Downloads

link

Related articles

favorite

348

label

VEX

Attribute to match across inputs

favorite

232

label

VEX

Sphere Packing / Dart Throwing Algorithm

favorite

261

label

VEX

Deintersecting spheres with Voronoi

favorite

292

label

VEX

Fitting Planes to Point Clouds

favorite

302

label

VEX

How to analyze VEX code

favorite

140

label

VEX

Monte Carlo Geometry Processing