How to make a group based on camera view?

   378   6   2
User Avatar
Member
19 posts
Joined: 7月 2012
Offline
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?
User Avatar
Member
686 posts
Joined: 9月 2013
Offline
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;
}

Attachments:
group_visible_in_camera.hip (294.1 KB)

https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
User Avatar
Member
19 posts
Joined: 7月 2012
Offline
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?


Attachments:
2024-12-15 23_34_54-C__Users_markosovljanski_Desktop_WeaponADSUpgrade_WeaponADSTextures001.hip - Hou.jpg (108.0 KB)
2024-12-15 23_35_06-C__Users_markosovljanski_Desktop_WeaponADSUpgrade_WeaponADSTextures001.hip - Hou.jpg (22.2 KB)

User Avatar
Member
686 posts
Joined: 9月 2013
Offline
Couldn't this be just a viewport issue? Maybe try deleting the points in the 'visible' group and check again.
https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
User Avatar
Member
19 posts
Joined: 7月 2012
Offline
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.

Attachments:
2024-12-15 23_31_59-C__Users_markosovljanski_Desktop_WeaponADSUpgrade_WeaponADSTextures001.hip - Hou.jpg (99.3 KB)
Screenshot 2024-12-15 232840.jpg (218.0 KB)

User Avatar
Member
8822 posts
Joined: 7月 2007
Offline
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;
}
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
3 posts
Joined: 11月 2024
Offline
These comments helped me too!!!!!!!
  • Quick Links