Clipping SOP in camera direction

   1786   4   2
User Avatar
Member
8 posts
Joined: 4月 2021
Offline
Hi. I'm trying to use the Clip SOP to divide my geometry. I want this geometry to divide facing the camera so I'll have separate planes of my geometry facing the camera one at a time. Like plane one will be closest to the camera, plane two will be right behind, plane three will be behind that, etc. Does anyone know how I might be able to do this?

There is an option to change the clip direction but I'd just be eyeballing it. I'd hope there's a way to pull the camera direction and place it in the clip direction boxes. I'm a vex newbie so maybe there's something that would work with that but everything I've tried is either breaking or it doesn't do what I want it to do.
User Avatar
Member
4693 posts
Joined: 2月 2012
Offline
Hi,

I wouldn't bother with the Clip SOP. It's much easier and faster to generate a center line for the camera with a given number of points and use it with Voronoi Split SOP to split your geometry at once into multiple parts.

You can use VEX to do this in a Detail Wrangle:

string cam = chs("cam");
float near = -ch("near") - 0.0000001;
float far = -ch("far");

vector pnear = fromNDC ( cam, set ( 0.5, 0.5, near ) );
vector pfar = fromNDC ( cam, set ( 0.5, 0.5, far ) );
vector dir = normalize ( pfar - pnear );

pnear += dir * ch("s") * 0.5;
pfar -= dir * ch("s") * 0.5;

addpoint ( 0, pnear );
addpoint ( 0, pfar );

addprim ( geoself ( ), "polyline", 0, 1 );

Then I resample it using this expression for Segments:

ch("../create_center_line/zones") - 1

If you want uneven splitting, you can even shift the positions of the points using a ramp parameter.

Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
8041 posts
Joined: 9月 2011
Offline
animatrix_
I wouldn't bother with the Clip SOP. It's much easier and faster to generate a center line for the camera with a given number of points and use it with Voronoi Split SOP to split your geometry at once into multiple parts.

Doesn't that split on the half way point between points? That sounds unintuitive and difficult to control without doing a bunch of math. The OP said they didn't want to use VEX. The old dumb slow clip is easier to 'see' how it works.

To get the clip direction from the camera, no vex is needed.

Right click origin parameter and select "Reference->Scene Data". Then find the camera and select Translate under Transforms->World. Right click a direction axis parameter and select "Reference->Scene Data" again. Find the camera and select Direction -> -Z. This will fill in the three axis parameters with the reference to the camera's world Z direction. Then adjust distance to set the clipping plane distance.

Attachments:
reference_translate.png (211.6 KB)
reference_direction.png (178.2 KB)

User Avatar
Member
8 posts
Joined: 4月 2021
Offline
animatrix_
Hi,

I wouldn't bother with the Clip SOP. It's much easier and faster to generate a center line for the camera with a given number of points and use it with Voronoi Split SOP to split your geometry at once into multiple parts.

You can use VEX to do this in a Detail Wrangle:

string cam = chs("cam");
float near = -ch("near") - 0.0000001;
float far = -ch("far");

vector pnear = fromNDC ( cam, set ( 0.5, 0.5, near ) );
vector pfar = fromNDC ( cam, set ( 0.5, 0.5, far ) );
vector dir = normalize ( pfar - pnear );

pnear += dir * ch("s") * 0.5;
pfar -= dir * ch("s") * 0.5;

addpoint ( 0, pnear );
addpoint ( 0, pfar );

addprim ( geoself ( ), "polyline", 0, 1 );

Then I resample it using this expression for Segments:

ch("../create_center_line/zones") - 1

If you want uneven splitting, you can even shift the positions of the points using a ramp parameter.

Thanks very much for this! I'm not trying to stay away from VEX per-se but I would like to be able to figure stuff out and learn rather than copy-pasting someone else's work. Thanks so much for this and I'll be looking at this code to try and decipher what you've done here.
User Avatar
Member
8 posts
Joined: 4月 2021
Offline
jsmack
animatrix_
I wouldn't bother with the Clip SOP. It's much easier and faster to generate a center line for the camera with a given number of points and use it with Voronoi Split SOP to split your geometry at once into multiple parts.

Doesn't that split on the half way point between points? That sounds unintuitive and difficult to control without doing a bunch of math. The OP said they didn't want to use VEX. The old dumb slow clip is easier to 'see' how it works.

To get the clip direction from the camera, no vex is needed.

Right click origin parameter and select "Reference->Scene Data". Then find the camera and select Translate under Transforms->World. Right click a direction axis parameter and select "Reference->Scene Data" again. Find the camera and select Direction -> -Z. This will fill in the three axis parameters with the reference to the camera's world Z direction. Then adjust distance to set the clipping plane distance.

This is exactly what I was looking for! Yeah... It's a bit of math and manual bananas on my end with this method but I'm still learning. This referencing scene data is great! I can do so much with this!!
  • Quick Links