Houdini Q&A: “How do I create a smooth path through rugged terrain procedurally?”
Carlos Donis Lemus is here to cut a swathe through Ying Cui’s Houdini confusion
Download the support files for this Houdini Q&A here.
Load the 3DWorld_Clearpath_on_Rugged_Terrainstart.hip file. I’ve created a couple of object nodes here to get you started – a Camera object, cam1, and a Geometry object, rugged_terrain. Dive into the rugged_terrain object by selecting it and pressing [Enter]. Stepping through the network, at the top, I’ve created a planar polygon grid (grid1) in the ZX plane. Set its size to 15×15 and rows/columns to 128 – this will help with detail when you deform it. To the right of the network add a texture node (texture1) and leave its defaults. This will give you UVs.
Next, add a point operator (point1). Using the UV[w] attribute ($MAPV), colour the grid red with a gradient from left to right by adding the expression 1-$MAPV in point1’s R field and zeroing out G and B. Do this a few more times (point2, point3 and point4), changing the expression to 1-$MAPU and just $MAPV or $MAPU to get the gradient from left to right or top to bottom and so on. Once you have all the gradients, do an attribcomposite (attribcomposite1), making sure you composite the Cd attribute.
Preparing the terrain in such a way that you can control the falloff of deformation will help you to define a method to flatten it later
In the Weights tab do four blends, because you have four regions to blend, and set them all to 1. Next, make sure that in the Operators tab you set Compositing Operation to Min. From here, a point SOP (point5) is used to take the original grid (grid1 – left input) and the gradient grid (attribcomposite1 – right input), and with an expression in the point5 SOP in its [R] field, pow(abs($CR2)*2,1), the color attribute from the composited gradient network is applied and enhanced into grid1.
As for the path, I created a curve SOP (curve1) that’s located to the right of point5. Selecting the node and setting its display flag to on (blue) will reveal that this is just a spline that I drew from the top viewport by placing points and then making sure that it was a NURBS curve. Now you can finish the setup. Press [Tab] and type ray – then select and place down the resulting ray SOP. Connect the output of point5 to ray1’s left input (first input). Connect curve1’s output to the right input of ray1 (second input). In ray1’s properties set the following: Method : Minimum Distance; Point Intersection Distance; and untick Transform Points.
Using a curve to plot your path, you can calculate the distance from the curve outwards, and flatten the terrain based on this attribute
Next, add a point SOP. Place it down and then connect the output of ray1 to the first input of point8. In point8’s Standard tab, set Keep Color to Add Color. Right-click Color and select Delete Channels from the pop-up menu. Enter pow($DIST,6)/6) into the R field (first), then zero out the others. Set the display flag to point8 so you can see the effect. You’re using the minimum distance attribute of the ray SOP to create another gradient outwards from the curve (path). Press [Tab] again and type attrib, then select attribComposite from the list. Connect point5’s output to attribComposite2 and point8’s output to attribComposite2 as well. Make sure you’re only compositing the Cd attribute using just two Weights and set the Operators – Compositing Operation to Min.
If you set the display flag on the last node in the chain – point7 – you’ll now see a smooth, clear path through the rugged terrain. The nodes in between attribComposite2 and point7 – mountain1 and point6 – do some special things as well. The mountain1 SOP deforms the terrain with some settings I’ve set up. The point6 SOP multiplies the point positions by the red colour channel (Cd attribute) and then by two, basically flattening any area where there’s no red, and keeping the highest peaks that have the most red or are closer to a full value of one. This is one technique that makes use of a couple of key SOPs such as attribute compositing, ray and some basic hscript expressions. Other methods can also be explored, though that will depend on what you need to achieve and how you need to achieve it. I suggest you experiment and explore because this will be a good basis for achieving such a task. Enjoy!
Carlos Donis Lemus is a CG supervisor at EA, specialising in procedural workflows, methods, tools and pipelines
Discover 20 great examples of print in 3D at our sister site, Creative Bloq.
on Monday, October 8th, 2012 at 3:27 pm under Guides, Technique, Tutorials.
You can subscribe to comments.
You can leave a comment, or trackback from your own site.