Search - User list
Full Version: How to make a group based on camera view?
Root » Technical Discussion » How to make a group based on camera view?
animquer
Does anyone know how to make a group based on camera view in Houdini? I found the way to select everything in camera frustum, but that's not what I want, I want to exclude the occluded geometry. There is a maskbyfeature sop that can use a light source with shadowing but if give it camera as input it doesn't have a proper direction and FOV of the camera. Sounds so simple yet I can't find anything reliable way to do it.
Does anyone know?
Konstantin Magnus
Hi animquer,

the VEX function toNDC() creates normal device coordinates, X and Y between 0.0 and 1.0 will be inside the frustum:

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;

To check for visibility, shoot rays from each mesh point towards the camera position:

if(in_frustum){
    matrix xform_cam = optransform(cam);
    vector pos_cam = cracktransform(0,0,0,0,0, xform_cam);
    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;
}
animquer
Konstantin Magnus
Hi animquer,

the VEX function toNDC() creates normal device coordinates, X and Y between 0.0 and 1.0 will be inside the frustum:

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;

To check for visibility, shoot rays from each mesh point towards the camera position:

if(in_frustum){
    matrix xform_cam = optransform(cam);
    vector pos_cam = cracktransform(0,0,0,0,0, xform_cam);
    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;
}

It doesn't quite work, I get random selections from it. It does respect the frustum, but something happens with a selection only one side of the model, also it depends on how close the camera is, some points just disappear from the selection.
This is a view from the camera. In my scene one side -Z of the object simply doesn't work it works in your scene. But also in your scene it also falls apart if you zoom move the camera out. I have no idea what is happening. Something with ray casting?


Konstantin Magnus
Couldn't this be just a viewport issue? Maybe try deleting the points in the 'visible' group and check again.
animquer
It was a viewport issue in part. The selection works, but with my camera it keeps selecting as if the camera is 90 degree rotated. I am trying to debug.
I got it, its because there is a transform in the obj level on the geometry, and a different transform on the camera. This is just how I imported my geometry from fbx. But how to I get rid of those transforms. I think only the rotation is the problem.
tamte
you may want to make sure you are expressing your camera position in the current object space, rather than disregarding the object transform

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;
}
Mellen Jack
These comments helped me too!!!!!!!
Laurencedodd
Fixed it,

ndc>=0.0 && ndc<=1.0 && ndc>=0.0 && ndc<=1.0;
if and were defining the x y , I added a ndc string, and that put in the z control.

Thanks
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB