Group primitives visible to camera (VEX)

Here’s a script that will create a primitive group of all the primitives that are visible to camera. The script doesn’t do a perfect job so in most cases it’s necessary to use a group expand node to expand the group a few steps.

To use the script, copy and paste this code to a primitive wrangle and wire the geometry in the first input. Create the parameters with the “create spare parameters“ button and select the camera in the scene with the parameter “id“. The script will output a group “hit“ marking the primitives that are visible to camera.

//primitive wrangle
string op_path = chsop("id"); //path to camera

matrix xform = optransform(op_path);

float x = getcomp(xform,3,0);
float y = getcomp(xform,3,1);
float z = getcomp(xform,3,2);

vector c_pos = set(x,y,z); //camera pos
vector dir = v@P-c_pos;
dir *= 2;

vector hitpos;
vector uv;

int intersect = intersect(0,c_pos,dir,hitpos,uv);
setprimgroup(0,"hit",intersect,1);
Previous
Previous

Camera culling instanced scatter

Next
Next

Group points inside camera view in Houdini with VEX (camera culling)