'The Magic of Houdini': Ye Ole Copy SOP

In the latest excerpt from the book The Magic of Houdini, Will Cunningham welcomes all users to Copy SOP.

All images from The Magic of Houdini by Will Cunningham. Reprinted with permission.

This is the next in a series of excerpts from the Thomson Course Technology book The Magic of Houdini by Will Cunningham. In the next few months VFXWorld readers will learn the basics of the dominant tool that has been used in the creation of some of the most awe-inspiring animation and cinematic effects ever made.

Welcome to the Copy SOP! It rocketh all planes of the multiverse and has at one point, early in its history, brought peace to the warring tribes of the Dantooine System. In fact, I feel it deserves a poem

Oh Copy SOP Oh beacon of hope to the seven cities Please do continue the peace in the lands of Dantooine Please do rocketh the multiverse, if you know what I mean

I feel better having said that and I hope you do, too. If you havent gathered already, the Copy SOP is an amazing piece of ingenuity. Lets see why. Append a Copy SOP to the switch node. Notice that this node has two inputs. MMB on the left input and it reads: Primitives to Copy. Do the same on the right input and it reads: Template to Copy To. Make sure the left input is connected to the stamp node and that the right input is connected to the scatter node. Your network should now look like Figure 1.

[Figure 1] The state of the network.

So, what did it do? It copied what is coming into the left input to every point coming into the right input. So, one line is being copied to every point in the scatter node. Though, looking in the viewport, things look a little screwy. There are two problems, which are scale and orientation. The lines are way too big for the terrain and they arent being copied with the correct orientation. They are inheriting the point normal information that you set earlier because the Rotate to Normal toggle is on, but you can easily see the ones in front are laying down flat in a swirl as you did to the point normals. You can fix the orientation of the line before it is fed into the copy node. Turn on the Footprint (the burgundy one) flag on the convert node so that you can see the terrain as you continue working.

  • 1. RMB on the left input of the copy node and insert a Transform SOP. Leave the Display flag on the copy node and make sure the transform node is selected so you adjust its parameters. As always, youll immediately see the changes you make cook down the chain. First, change the Uniform Scale to 0.1 to get the lines at a better scale. Now, change the Rotate in X to 90. You now have appropriately sized trees or grass or whatever and they are also correctly inheriting the point normal attribute. The problem was that the copy node expects the input to be facing down the positive Z axis when it copies using the Rotate to Normal option.

2. Notice that all the lines are exactly the same size. This doesnt make it look very natural, as it is unlikely you would find everything to be the same size in real life. You can use the Copy operation to randomly add variation to the copies, and this, as they say, eeeez zeeee spice of life! First, lets get the stamping working and then youll determine a good range of scale for the copies. In the transform node (which is probably called xform1), enter stamp (../copy1, height, 0.1) in the Uniform Scale field.

Bring up a Textport and type exhelp stamp to get help on the stamp() expression. You reference what nodes are going to do the stamping, the name of the variable to be stamped and a default value in case that variable isnt found.

[Figure 2] The Stamp tab of the copy node.

  • 3. In the copy node, go to the Stamp tab and type height in the first Variable field. Toggle on Stamp Inputs and see what happened in the viewport. All the lines disappeared because the value of height is currently zero. Move the slider back and forth and youll see that it sets the Uniform Scale of every copy to that value. Now, lets make it more interesting by using a simple expression instead of a constant value. Type rand($PT) * 0.1 in the Value 1 field and check out what happens. Every point that comes in through the right input of the copy node has a unique point number, which can be accessed through the local variable PT. You can then use that point number as a seed for the rand() expression, which will return a random value between 0 and 1 based on the seed. So, every copy has randomly set Uniform Scale from 0 to 1. You then multiply that by 0.1 to get them all back down to a better range of scale. So the final range is from 0 to 0.1. Look around the geometry and youll see that some lines are very small and some of the larger lines must have resolved to around 0.1. Figure 2 shows the Stamp tab and what you entered.

houdini03_fig0554.jpg

[Figure 3] The current state of the network. 

houdini04_fig0555.jpg

[Figure 4] The Quick Render button (first on the left) has the blue icon. 
  • 4. You want to see both the trees and the terrain underneath them. Append a Merge SOP to the end of the network chain. You use a merge to bring together various network branches into one branch. Even though a merge node has just one input, it can accept any number of inputs. LMB on its input and LMB on the output of the convert node. This will create a connection that passes down the geometry information from the convert node to the merge node. As always, make sure the Display flag is in the right place and now youll see the trees and the hilly terrain. Turn off the footprint flag on the convert node; the network should now look like Figure 3.

5. Lets do a quick render to preview the work when rendered. RMB and hold on the quick render button which is the blue icon in the lower-left of the Viewer pane (as shown in Figure 4) and choose View: Mantra. This is a simple way to get a low quality preview render of what is displayed in the viewport. You can see that the lines look a little strange. The problem is that the Mantra renderer recognizes that you are trying to render a line primitive and so automatically attaches a width attribute (or characteristic) to them. By default, it chooses a value of 1, which is obviously too big for the scene.

6. Append an AttribCreate SOP below the merge node and rename it attribWidth. Type width in the Name field and enter 0.001 in the value1 field. Remember that you just hold your pointer over the Value label to figure out what each of the channel names are. The value1 channel is on the far left. Now, lets do another test render. Houdini will remember what the last chosen output driver was. Each of the choices you see when you RMB and hold is an output driver. Chapter 13, Render Outputs, goes into more detail on them. Because you already chose the View: Mantra driver, you can just LMB click on it and Houdini will choose it again. This time, the lines look a better.

  • 7. Remember from earlier that you want to wire an L-system into the switch node so that you can preview a less dense geometry and then render a more dense one. Lay down an L-system SOP and wire it into the switch node. Set the Display flag to the L-system node and choose Bush in the Presets menu. There are quite a number of interesting presets for this operators. Most just change the rule set, which changes how the system is created. Some also animate various parameters like the crack and lighting presets. L-systems are a great tool for mimicking the various kinds of branching behavior found in nature. I highly recommend reading the Houdini help on this node as it is very informative and comes with a number of exercises to get you going. When you are done investigating, make sure to choose the Bush preset.

8. Set the Display flag on the switch node. Using the Select Input field, you can cycle through the connected inputs and decide which you want to pass down the chain. Note that the numbering starts with zero, so that choosing zero will pass through the first input. In this setup, zero will pass through the line geometry and one will pass through the bush. So, when you are working with the network, it will be set to 0. At render time, a simple pre-render script could change it to 1, and then a post-render script could change it back to 0. Set the input to 0 before you continue.

You arent going to mess with the render scripts themselves, that topic is covered in the Chapter 13. Lets do take a Textport moment though and check out the Hscript command that would be used.

9. Bring up a Textport window and go into the terrain Object. Remember to navigate the directory structure is a simple thing. First, you have to figure out where you are. The prompt will tell you. It may currently read /-> which means you are at the root level. Type ls and youll see all the root level directories, assuming of course that you are at the root level. Type cd obj/terrain to jump into the Object context and then into the terrain Object.

To set a parameter on a node, you use the opparm command. Type opparm switch1 input 1in the Textport and press Enter. Its quite simple. Give the name of the node, and then the name of the parameter, and then the value you want to set. Look over at the switch node and youll see youve just changed the input to 1. Press the Up arrow and change the command to opparm switch1 input 0 and again check out the switch input. It has been set back to 0. Its that easy!

10. To end this exercise on a responsible note, append a Null SOP at the end and rename it displayRender. Figure 5 shows the final state of the network.

11. But wait! This is, after all, Houdini. Go back and change the switch to pass through the second input. The trees everything will automatically update using the trees instead of the lines. Oh, glory be!

Find out more about how to apply each of Houdinis features to your projects as you take on modeling, character animation, particle effects animation, dynamic simulation animation, shading, digital asset creation and rendering. The Magic of Houdini by Will Cunninham. Boston, MA: Thomson Course Technology, 2006. 355 pages with illustrations. ISBN: 1-59863-082-2 ($49.95). Check back to VFXWorld frequently to read new excerpts.

Will Cunningham began his trek by studying both traditional art subjects and 3D computer software at the Academy of Entertainment and Technology. After his studies, he was hired as a Houdini technical intern by Side Effects, the developers of the Houdini software package. Eager to create effects for the big screen, he then jumped into production with BlackBox Digital on the feature, The Prince and Me. Shortly thereafter, he also began teaching Introduction to Houdini at the Academy and has since taught both the introductory and intermediate Houdini courses. In the fall of 2004, he was awarded a fellowship grant by Santa Monica College to support his efforts in creating this book. Over the years, Will has worked for a number of production studios on a variety of projects, including The Chronicles of Narnia: The Lion, the Witch and the Wardrobe, Open Season and Ghost Rider. Currently, he is enjoying effects challenges and learning opportunities at Sony Pictures Imageworks.