Scott Benson's profile

Free Height (Displacement) Map Rig for Cinema 4D

Free C4D-Native Height Map Creation Rig

About
This rig is used to create an 8K x 8K (or any size) Linear 32-bit height map that can then be fed into a bump or displacement channel of a material. It started as a testing file for the Displacement in Cinema 4D/Octane guide series and then kind of grew from there.

This is a 100% vanilla Cinema 4D file. No plugins were used or needed, and it uses the built-in standard render engine (more specifically the depth pass).

License
This rig has been released as CC BY-SA (share alike), so you can use it freely for any personal or commercial products. If you make derivatives of it, share them with the same license.

If you want to throw some ETH at scottbenson.eth to say thanks, it’d be appreciated, but no pressure :)

What you can do with it
Use geometry to make model-independent height maps. Create detailed greeble tiles, logos, textures, patterns, or anything else that you’d want to make a generic height map for.

What you can’t do with it
Model-specific baking. This isn’t for making custom displacement textures that map specifically to the UVs of your characters or models.

Vector displacement (yet?).

How to Get It
The above Dropbox link contains a C4D file that you can just open in Cinema 4D. There’s also a custom layout (for S24, but it should work in most recent versions). You don’t need the layout to use the file, but it helps.

The Custom Layout
You can load the custom layout in C4D by going to the Window menu, choosing Customization, and then Load Layout. After it’s loaded, choose “Save Layout” from the same menu so you always have it. It’s mostly the default C4D S24 layout, but with a new viewport so you can place objects and interact with them like normal in 3D space, but also see a preview of what the 2D depth map will look like.

Once the file and layout are both loaded, click the blue User Data tag. This will bring up the rig controls in both Attributes managers. Click the lock icon on the top Attributes manager, and that will lock the rig controls there for easy access. The bottom Attributes manager stays unlocked so you can change attributes of the other selected objects as you build the scene.

Rig Options

The Depth and Size controls are for controlling how large the renderable area is of the final depth map. Render Mid Level Plane is for controlling whether you want to clip the depth map at 50% depth (polygons will only displace “up” along their normals, not both ways).
The rest of the options are scene visualizers that can be turned on and off to get a better sense of what the final depth map will look like.

Important Things to Know

The material on the geometry is not what will be rendered - this is solely there to help you visualize the height data and see if anything is clipping. What’s rendered is a generated grayscale depth pass that you can use in the displacement channel of another material.

In order to get smooth displacement along curved surfaces, the geometry is going to have to be pretty high resolution. If you’re making cylinders and cones and whatnot, always give them a lot more rotation segments than you normally would (try 500). Also consider using the subdivision surface object to smooth out irregular curved geometry more.

If you’re making spheres, you can use the “render perfect” option in the sphere object to create a smooth surface without having to up the segments too much. 

If you’re making ramps or other linear angled geometry, reduce the amount of segments and let the depth map do the interpolation.

How to Use the File

1. Download and open Height Map Maker.

2. If you’re using the custom layout (also in that link), make sure that’s loaded in and active.

3. Make sure the blue User Data Tag is selected so you can see the controls in the Attribute Manager. If you’re using the custom layout, you can lock these controls to one of the Attributes Managers.

4. Make or bring in geometry. Remove all the material tags and place it in the Your Geometry Here node. This will apply the gradient that maps to the Scene Depth slider in the controls and lights up out of bounds areas in orange or blue.

5. Set the Scene Size. This doesn’t affect the size of the render output (it’ll always be 8k or whatever you change it to in the Render settings). This just resizes the boundaries of the square tile relative to your geometry.

6. Set the Scene Depth. Figure out the highest and lowest points of the scene and change the Scene Depth accordingly.

7. Turn on and off the various Visualizers to quickly see if your geometry is properly located in your scene. None of these render or add data to the depth map, so they’re all optional.

8. Decide whether you want the Mid Level plane to render. This plane will produce a 50% gray field which (if displacement in your render engine is set up properly) will not displace any polygons at that level. This is useful if you only want polygons to displace “up” along their normals instead of both directions.

9. The Far Max plane doesn’t matter if it renders or not (anything at or beyond the far max area of the scene will render black anyway). It’s more of a visualization tool to help see what the final map will look like in the Parallel cam view.

10. Go to C4D’s Render Settings. In the Output section, choose the size of the final map. 8k is default and is probably fine for most applications. In the Save section, leave the Save checkbox OFF in the Regular Image section. You don’t want a normal image/beauty render here. Instead, pick a path and name for your depth map in the Multi-pass Image section.

11. Render!

Walkthrough - Creating a Bucky Tile

Bucky Pattern Example

Let’s say we want a pattern made up of a bunch of buckyballs.
 
After opening the scene and changing the layout, we’ll want to lock the user controls to the top attributes manager as described in the first section of this guide.

Scene Depth
Let’s drop in a platonic object, set it to Bucky, and then nest that platonic under the Your Geometry Here null.

We’ll notice a few things happen here. First off, when the platonic is first placed into the scene, it’s solid black (the lights are intentionally off in this rig). When we move it under the Your Geometry Here null, it suddenly lights up thanks to the luminance material on that null. If we were to bring geometry in from another scene, we’d need to remove the material tags from it so it doesn’t override this material.

The default buckyball is larger than the default setup of the rig, so there is going to be some clipping. Anything clipped above 100% in the depth map is shown in orange, and anything below 0% is shown in blue. If the geo is clipped, the depth map won’t look right when rendered.

As we start increasing the Scene Depth parameter, the blue and orange parts start to minimize. Once the depth hits ~200cm or so, the bucky fully fits within the height bounds of the rig, and there’s no orange or blue on it. This means the depth map will look like we’d expect it to. We could have just as easily reduced the size of the bucky to get the same effect.

Normally we can just eyeball this value and get it close enough to the top and bottom of the scene. If it needs to be exact, we’d have to figure out the exact Y value of the top of the geometry (96.362 cm in this case), and then double it (192.724) to get the exact Scene Depth value for this shape. For this example we’re just going to set it to an even 200cm.

Render Settings

Let’s do an initial render. The rig is set up with a Stage object which guarantees that the parallel depth cam is always the active one in the render, so regardless of other cameras we put in the scene, we’ll always end up with the correct depth map.

If we hit Ctl-B (or click the little clapboard/gear icon) we can get into the custom render settings for this rig and have a look around. Let's check out the Save section on the left.
First off, ignore the Regular Image (beauty pass) section of the render settings. We’re only interested in the depth pass here, which is under Multi Pass Image.

Most of the settings are already set up properly by default - 32 bit EXR with PIZ compression. This will create a relatively small file with the best quality. If needed, we could change this to 16 bit PNG or whatever the app we’re building this calls for.

In order to get to the compression settings for EXR, we need to hit the little carat next to the word “Format” to roll down the options.

After putting the file name and path into the File field (again, in the Multi Pass Image settings, NOT in the Regular image settings), we can close this window and hit Render to Picture Viewer.

First Render
What we end up with is a map that looks something like the one on the left. Since it’s a 32 bit EXR, the grays may look different depending on what we’re viewing it in, but it’s non-color data that’s a higher bit depth than a monitor, so it’s never really going to look accurate anyway. Fortunately, data channels like Displacement don’t care what it looks like, they just care about the data in the file.

Let’s make a new c4d file, create a 200x200cm plane, add the rendered map to the Displacement channel of a material and apply it to the plane. Depending on the engine used, the number of segments may have to be adjusted.

In the illustration above, the plane was given 1000x1000 subdivisions. The displacement height (or depth) is set to 200cm - same as our Scene Depth value. The displacement mid level value is set to 0.5.

This illustration uses Octane Render for C4D. It’s set to Texture displacement with a Gaussian filter applied with a radius of 5.

The top part looks fine, but since this is a 2D grayscale (not vector) height map, it can’t capture the data under the overhanging area, so the bottom part just takes the widest part of the bucky and extrudes it down for any value under 50%. If we change the overall displacement height, it’ll squash the whole thing. So how do we clip it off at 50% so we just see the top dome?

Turn on Render Mid Level Plane
Let's turn on the Render Mid Level Plane option in the Scene Controls Null. This will produce a 50% gray field that clips the displacement at the mid level. This means anything with values of gray below 50% won’t be created in the depth map, and polygons will only displace “up” along the normals instead of both ways.

It doesn’t matter if Render Far Max Plane is on or off - the whole scene is being clipped at 50%, the render won’t contain any black pixels anyway.

Adjusting the Scene Size

Let’s make a cloner and just throw the bucky into that. By default, the cloner creates a 3x3 grid of the bucky balls on the XZ axis. Each instance is 200x200px away from one another. If we were to render the scene now, we’d get the exact same result as last time, because none of the other bucky balls are in the rig's render area. We can turn on some of the visualizers like the Scene Size View to really see this.

We could shrink the bucky and reduce the distance between clones in the cloner, but in this case it’d be easier to just change the Scene Size. This won’t change the size of the rendered tile - it’ll still be 8k - it’ll just allow us to get more geometry into the scene. Since the camera is in a parallel projection, we don’t have to worry about it distorting anything, which is nice.
Let’s go ahead and change the Scene Size to 600cm. We can see in the top view that it now encompasses all nine of the buckyballs. The render will still be an 8k tile, but it now contains 9 buckyballs instead of one.

Let’s go ahead and render it out (don’t forget to change the file name).
If we apply the new map to the same 200x200 plane in our other file, we’ll see that the displacement is stretched. This is because we adjusted the scene size to 600cm, but kept the same 200cm depth we had.

We can either change the plane with our displacement material to 600x600cm, or lower the displacement height by 2/3 (bring it to 66.6667cm). Let’s make the plane larger.  When we go to apply it to different geometry like a cylinder, we’ll need to wing the tiling and height values until it looks right.

Going Down
Making polygons displace “up” is really easy - we can just slap geometry into the scene without worrying about overlaps or intersections and move it around until it looks right before taking a snapshot of it from a top view for the map. Pushing the displacement “down” into the model is a different story. There are a few ways to approach this.
If ALL of our displacement is going to recess into the model, then we can build the scene like we would if it was going up, and then just invert the depth map in our render engine of choice (Octane is shown above). With Render Mid Level Plane on, the areas of the map that are at the mid level are already at 50% gray, so they won’t change when the texture is inverted. Anything ‘higher’ than that will now be 'lower' instead.
If some of our displacement is going up and some is going down, and the different parts are easy enough to mask out, we can do the inverting procedurally via mixing and layering techniques in the engine, or just go into a 2D image editor like Photoshop and invert different sections.

If the scene is really complex with a lot of overlapping bits going up and down, we’ll have to plan out our modeling strategy. Sometimes booles are a quick way to do this, but other times it’s just going to be the grind of proper poly modeling that gets us through it.

Wrap Up

So that’s about it. Thanks for checking this out, and leave any comments and feedback below.
Free Height (Displacement) Map Rig for Cinema 4D
Published:

Free Height (Displacement) Map Rig for Cinema 4D

Published: