# Houdini

## Dot Product to Cull Points and Establish a Gradient

Here’s another super-simple trick you can perform with the dot product of two vectors. If you create two nulls and get the vector between them, you can compare that with the vector from any point to the first null using a dot product. Any value less than zero is past the plane of the first control normal to the second. That doesn’t read well, but the result is straightforward, you are using the controls to act like a normal and cull points.

Furthermore, the distance between those two nulls acts as a handy scale factor to color points in a gradient between the two. Here for instance we’ve “cut” a sphere in half…

The structure is very simple as you can see in the network view. The wrangle is also very simple. Thanks to Tokeru for inspiration and the basic structure of this wrangle.

```vector p1, p2, v1, v2;

p1 = point(1,'P',0); //control null 1
p2 = point(2,'P',0); //control null 2

v1 = normalize(p2-p1);
//vector between control nulls

v2 = @P-p1;
//vector from current eval point to control 1

f@angle = dot(v2, v1);
//The dot product of the two, indicates 'perpendicularity'

if (@angle <= 0){
removepoint(0,@ptnum);}
//Cull out any points past p1

float dist = distance(p1,p2);
@Cd = dot(v2,v1)/dist;
//The distance between the two can also act as a gradient
```

This works, but there’s a far simpler approach to take using the matrix transforms mentioned a few posts earlier. Transform the points to the origin of a control object’s local space (you saved that wrangle as an asset, right?) and then you can use very simple logic – in this case let’s delete any point greater than zero in z.

```if ( @P.z > 0) {
removepoint(0,@ptnum);
}
```

Translate the points back to their original world position (in that other wrangle you saved as an asset, right?) and bam, you have a super easy tool to cull points according to a control object. Or make a gradient, or whatever else you want.

## Dot Product and Edges in Vex

Getting the dot product of two vectors is infinitely useful, and easy in Vex. In this example I get a vector pointing from scattered particles to the camera and then get their dot product with the surface normal at that point. This gives you a very good idea of whether the surface is facing or perpendicular to the camera at any given point.

In this case, I simply cull any point which isn’t close to a value of zero, indicating the surface is perpendicular to the camera. If instead I culled particles that were less than zero I would be removing all back-facing (occluded) particles, which is perhaps more useful but less visually interesting. Since I am left with only particles near the edges of the geometry it’s easy to connect them with lines and get an “edge detection” kind of look.

Here’s the Vex wrangle I used. Note an earlier polyframe node gave me point normals on the scattered points to work with.

```float threshold = chf("Threshold");
//User input threshold

vector camPos = point(1, "P", 0);
//The position of the imported camera

vector toCam = normalize(camPos - @P);
//A vector from each point to the camera)

//@N = toCam;
//Use to visualize toCam as normals

f@angle = dot(toCam, @N);
//The dot product of the normal and toCam vectors.

if (@angle > threshold || @angle < -1*threshold){
removepoint(0,@ptnum);
}
```

I’ve used this edge culling in production a few times, to create anime style speedlines and particle effects like rain strikes and halos. Culling particles behind geometry is of course also handy, though raycast solutions are much cleaner for that kind of thing. Next, we’ll use a simple dot product calculation to cull points and create a gradient effect.

## HUD elements

I’ve made a small (but growing) library of assets to help generate and animate HUD-style graphics. Here are a few early results…

## Experiment

Took a few of the basic assets I’ve made so far and applied them together to get this abstract shell-like shape. Yep.

## Houdini Exploration Continues

Various test images as I play around… Mantra and Houdini.

## Vex and VOPs – A Twist Deformer (Part 2)

So twisting some points around the origin was easy, but not useful as a generalized tool since you really need to place the twist anywhere it’s needed in world space.

The trick to this is to create and store a transformation matrix based on the origin of your control object, then move your deforming geometry to the origin via the inverse of that matrix. Then, after performing the deformation, apply the stored transformation matrix to move your deformed geometry back to where it was in world space.

Getting the vex wrangle right took me a fair amount of teeth pulling because I’m so new, and frankly it feels like it could be reduced to something a lot simpler. Email me if you see a better or cleaner way! Here’s what I ended up with:

```// Create vectors to fill matrix using the second node input's transform
vector translate = set(`chs(opinputpath(".", 1)+"/tx")`,`chs(opinputpath(".", 1)+"/ty")`,`chs(opinputpath(".", 1)+"/tz")`);
vector rotate = set(`chs(opinputpath(".", 1)+"/rx")`,`chs(opinputpath(".", 1)+"/ry")`,`chs(opinputpath(".", 1)+"/rz")`);
vector scale = {1,1,1}; // I'm not worrying about scale...

// Build the transform matrix of the control object
matrix xform = invert(maketransform(0, 0, translate, rotate, scale));

// Apply the matrix to the current points to move them to the origin centered on control object
@P *= xform;

4@xform_matrix = xform;
```

Yeah so there you go, that takes up a pointwrangle before the deform VOP and then a little wrangle after it returns the points to world space:

```@P *= invert(4@xform_matrix);
```

Here’s a houdini take on that original twist scene using this setup:

## Vex and VOPs – A Twist Deformer

Now let’s do something a bit more demanding. We will replicate the twist deformer I made in ICE in VOPs, and then use some vex wrangles to allow a control object to place the twist deformation anywhere on the object in world space. Here’s the actual twist deform VOP, with a little extra to make the twist into a whirlpool funnel shape:

Pretty straightforward, the VOP takes a radius of points around the origin and pull them down in Y as well as rotates them around the origin, with a falloff based on distance and ramps to allow for user control.

## Nodes Aplenty, and Mantra too

Making a hexagonal sphere is easy enough, just hit a polygonal sphere with a divide SOP and viola. Hit that with a wireframe SOP and an attribute wrangle to ramp the color and alpha and, well, it’s just a hexagonal sphere. But it’s a good chance to hop into Mantra and fiddle with settings. Oh, this DoF rendering is nice. Thumbs up for Mantra I know that everyone has their favorite flavor of the month renderer but I have to say Mantra strikes me as a real workhorse. I like it.

Yep, it’s a hexagonal sphere. Tadah. Let’s hit that with the connect points SOP/wrangle asset I made for the spirals…

Well that’s pretty much what you’d expect. I love how effective the few assets I’ve made are. Now an asset itself, expect to see this hexagonal sphere again, I’m enamored with it.

## Hello, Houdini.

Ok, so Houdini. Like most people I found the initial experience daunting. Cinema 4d is like a warm blanket, Houdini is completely the opposite having a lot of cryptic nodes to learn, many of which have evolved far beyond what they were first intended to do. Being a proceduralist that part of Houdini was amazing to first explore, but there’s a lot of ground to cover and caveats everywhere that can only be worked through by getting hands-on with every inch of this software.

Wheee! This is both fun and completely daunting.

But ok, I’m getting comfortable. VOPs was a no brainer for an ICE guy so I started there and that quickly turned me on to VEX and lovely attribute wrangles. First up, let’s make some lines, and then make some spirals. W00T.

Yep, phyllotaxis and phi resurface. Same concepts, new toolset. For a while I’ll be covering similar ground to prior posts as I rebuild much of my ICE production toolset as Houdini Assets. Now I have a set of .hip assets to create different kinds of spirals, connect lines to points and the like. Stuff in everyone’s toolbox I would think… should I share simple stuff like that here? I’ll probably make a wrangle cheatsheet for little stuff like this and share that.