grouncontact

Integrating CG into uneven soil is an interesting challenge. On a recent show we had to integrate CG characters into plates which often had a grassy ground. For Comp it’s benefitial if you get masks from Rendering to aid the blending of the CG elements into the grass. If the ground the characters are walking on is flat this can easily be achieved with a standard PWorld AOV. It get’s a bit trickier though if the characters are walking up a hill or a similarly uneven surface, because the coordinates at which the character comes in contact with the ground are constantly changing. I’ve been trying to come up with a system to make a Comper’s life easier and found a relatively simple solution.

So here’s a simple example scene with a sphere and a bumpy ground:

01_scene

First of all I wanted to have a point on the sphere and a corresponding point on the groundplane right below that travels wherever the sphere moves. That way it’s easy to always get the closest distance of the ground to the sphere. A simple way to achieve this is to create a locator and constrain it to the sphere with a Closest Point Constraint. This will add 2 more locators to the scene: cpConstraintIn at the position where the locator was placed and cpConstraintPos which sticks to the surface of the sphere and is always on the closest point of the sphere to cpConsteraintIn.  The original locator that was created can be deleted. Depending on the scene a Point to Poly Constraint might be a more viable solution, such as when there’s a character moving over the ground, because it may be more desirable to have locators bound to each foot. In this case I chose a Closest Point Constraint because this will give the ability to rotate or scale the sphere and still have the system work eventually (a practical example would be a barrel rolling down a hill for example).
Now one can move the sphere slightly up so that both locators are right above each other and Point Constraint the X and Z axis of cpConstraintIn to cpConstraintPos with maintaining the offset so that cpConstraintIn always travels along wherever the sphere moves. To make cpConstraintIn stick to the bumpy groundplane it can be Geometry Constraint’ed to it. For now this should give you something like this:

Next thing that needs to be done is the coloration whenever both surfaces are coming closer to each other. I created a ramp as a perspective projection with white on the bottom and black on the top. Once again this could be done with a separate UV set instead of a projection but the projection approach gives the flexibility of being independend of the UV’s and have the system also work in situations when the object is rotating for example. To make sure that the part where the ground is is always white I placed the place3dTexture node (that got created when I created the ramp as a projection) so that the lower edge would be slightly below the cpConstraintIn locator. I then point constrained the place3dTexture from the ramp to this locator so that the white section would always be according to where the sphere might touch the ground.

04_3dmap

In the ramp one can now easily set the desired falloff and it should be all good to go:

The result can be piped into a custom AOV to deliver to comp for mixing it with a bit of noise and all that fancy stuff to make the elements sit properly in the plate.

Here’s a more practical example using point to poly constraints and a bit more effort being put into the setup: