# Difference between revisions of "HoudiniExperiments"

### Occlusion Vop Sop

Surprised to see there's no definitive answer for this (occlusion sop) either within houdini or on odforce; an odforce search turns up various answers about writing out point clouds, c++, bit slow, avoid, etc. My super low-brow understanding of how point-based occlusion works in prman made me think there should be a simple(ish) vop network to do this.

edit: Actually there's a thread on doing it here ( http://forums.odforce.net/topic/20792-learning-vopsop/page-10?hl=vops#entry124867 ), but I'm trying very hard to not look at the examples, and work it out myself! :)

The result isn't correct, but it's interesting. Density map? Curvature map? Not sure.

Anyway, here's the idea:

1. Use measure sop to calculate area per primitive promote that to point
2. Vop network that runs this loop per point:
1. Get the nearest n points within a certain distance
2. Loop over each found point and get its position, area, normal
3. accumulate the distance * area * dot product of this points normal vs the found points normal
3. output the final result and scale/gamma to taste

By accumulating the distance, near points should occlude more, far points occlude less. Except already I can see I have my logic wrong, my code should be reversed, damnit. Anyway, scale that by the area, again, bigger primitives occlude more, smaller less. Finally compare normal; the idea that prims that face each other get maximum occlusion, but perpendicular ones get none (eg,a point that has a polygon above it, edge-on, shouldn't occlude.... right?)

Like I said, the result isn't correct, but feels like it has potential. Hmm.

This uses 'nearpoints' and a loop, I'm sure pcfilter could be used instead to get the result even faster and lazier. Can't work it out though. And yes, of course I could just use a mantra occlusion shader and bake it, but where's the fun in that?

#### Second attempt

This looks better!

This logic makes a little more sense; for each point, get a random ray direction within a cone (using the normal as the center of the cone), use intersect() to trace a ray out from that point along the ray. If it hits something, darken the point, if it doesn't hit something, ignore. The intserect() call can return all sorts of interesting info about the point it hit, which is a shame as I immediately throw away all that info, and just record if it hit something or not.

After about an hour of swearing at it, realised why it wasn't working; you need to add a little offset to the source point, otherwise intersect just hits the prim the point belongs to, and everything is occluded. That's the @P+(raydir*.001) bit in the intersect call.

```vector hit, raydir;
float u, v, conewidth;
int hitprim;
@Cd = 1;

float maxdist = ch('maxdist');
int rays = chi('rays');

for (int i = 0; i<rays; i++ ) {
raydir = sample_direction_cone(@N*maxdist,conewidth,vector2(rand(@Time+i)));
hitprim = intersect(0,@P+(raydir*0.01), raydir, hit, u, v);
if (hitprim==-1) {
@Cd *= 1;
} else {
@Cd*=1-(1/float(rays));
}

}

@Cd = pow(@Cd, ch('gamma'));
```

### Generic rolling cubes

An extension of the 'cubes marching' example on the Houdini#Cubes_marching page, but modified so that that the cubes can roll over arbitrary surfaces.

It's close, but needs some work to make it proper sexy. I got lazy and used a 'find shortest path' sop to generate a path, but spent more time cleaning it up than on the actual effect. Anyway, getting clean normals for the system to work with is a chore, I had to do some manual editing to get them consistent.

The idea is if the path has well defined normals, we can use that to drive the lift-off-surface part, as well as the rotation axis (the rotation axis is cross(@v,@N) rather than cross(@v,{0,1,0}). You can see it gets a little twitchy on abrupt direction changes, feels like there should be a clean way to drive it. Parking it for now.

### Misc

#### Clouds

- File:clouds_v04.hipnc - fluffy

- File:clouds_v05.hipnc - toned down displacement, much finer vdbtoparticles resolution

#### Points down veins

Grains fail: File:points_down_veins_grains.hip

Take 2, with pop attract and grains:

Take 3, using toadstorms wiser method to create paths from single tree structure with 'find shortest paths' sop. Download scene: File:points_down_veins_grains_v03.hip

Take 4. Classic itch I can't help but scratch...