In this tutorial we will create a section passing through a simple object using material nodes. We'll then have a look at various ways of combining several sections into more complex cut-outs, useful for, for example, architectural sections.
- This node set-up was originally described in this thread on the Blender Artists forums. The Cross Section script might also be of interest.
Add a cube
In top view (Num7), add a cube (Space>Add>Mesh>Cube).
Just to make this simple object slightly more interesting, let's rescale it twice. Rotate (MMB drag) your view to see what you are doing. Under the 3D view, make sure "Median point" is selected as pivot and "Move object centers only" next to it is disabled.
Still in edit mode with everything selected, scale along the X axis (S>X>3), and along the Y axis (S>Y>2).
Create the section texture
Tab into object mode. Go to the material menu (F5) and click "Add new". Accept the default material and name.
- Then go to the texture menu (F6), click "Add new" and rename the texture "Section". Select Blend as material type and in the Color tab activate Colorband.
- The colorband we are going to create will serve as a mask that we are going to map onto the cube later. To get a crisp sharp section through the cube, we just need to move the two default colors to the center of the colorband in order to get a black transparent half and a white opaque half. So, move the left color to Pos 0.5. leave it black. Select the right color (change Cur:0 to Cur:1). move it to Pos 0.5 and change the color to White.
Three axes for visualisation
To make it easier to orient ourselves later, we'll add three cylinders representing the three coordinate axes in the render outputs.
In the example below all three cylinders are made a single object. This is not necessary of course. If you prefer to make them three separate objects, just tab into object mode before copy-rotating them. Then follow the instructions below. If you make them three separate objects you can also skip the vertex group part below; just assign materials to each separate object.
- In object mode and in top view, add a cylinder (Space>Add>Mesh>Cylinder) with, say, 16 vertices. As above, rescale it (S, Shift+Z, 0.1) (S, Z, 5).
- Copy-rotate it to create an X axis (Shift+D, R, Y, 90).
- Repeat to create a Y axis (Shift+D, R, Z, 90).
Let's create three vertex groups for these cylinders and add three simple materials to them.
- Go to the edit menu (F9). Still in edit mode, deselect everything (A). Place the mouse over the first Z-cylinder and hit L to select all linked vertices. In the Link and materials submenu, add a new vertex group, name it "Z", and hit Assign. Add a new material index, change its color to blue, and hit Assign.
- Deselect everything and repeat as above for the X and Y cylinders. Make them red and green respectively.
- Go to the material menu again (F5). In the Links and pipeline submenu, use the "3 mat 3" button to select the newly created materials and rename them Blue, Red, and Green respectively.
Now let's set up the nodes.
- First lets open the node editor. Assuming you are using the default Blender layout, in the top menu select the Material screen (or simply Ctrl+→). Open the node editor in one of the subwindows using the button in the lower left corner. All you will see at this time is a grey area, but don't worry. Open the material menu (F5) if not open already.
- Select the cube. In the Links and Pipeline subwindow click Nodes to activate nodes for this material and ZTransp to activate transparency.
- Drag (G) the Material and Output nodes and place them on the right part of the area. In the material node, select the material.
- On the left side, add a geometry input node (Space>Add>Input>Geometry).
- Add Mapping node (Space>Add>Vector>Mapping). It should automatically be connected to the Global connector of the Geometry node.
- Add a Texture node (Space>Add>Input>Texture). Use the tiny box to select the "Section" texture.
- All nodes are set up now. Connect the texture node's Value output to the Output node's Alpha input to complete the node system.
Moving the section around
Press F12 to render the scene. With the default settings in the mapping node, the section is passing along the Y axis. You can easily change this in the mapping node. Move the section along the axes by changing the value in the three top boxes. Rotate the section about the axes using the middle row. In my case I had to change the Z rot value to -135 to make the section face the camera.
Note: Keep in mind that the mapping moves the section before it rotates it. So, if you change the rotation first, moving the section can then lead to non-intuitive results. Additionally, geometrically our section is an endless plane, so rescaling it or moving it in some directions, is not going affect the result.
 Improving the setup
As you can see the inside of the cube is dark, as are the parts of the cylinders passing through the cube. Let's change this.
- With the cube still selected, in the shaders submenu enable TraShadow. This will allow transparent shadows to be cast on the inside of the cube.
- Select the cylinder object, and for each material enable TraShadow.
- If you want to make the cylinders all bright, disable Shadow for each material.
Adding more than one section
To add several sections,
- Copy the mapping and texture nodes. Plug the Global output of the geometry node into the second mapping node.
- Change the orientation of the second series of nodes. In the example given, the section was rotated 90 degrees about the Z axis.
- Add a mix node, and plug both texture nodes' color output into it.
- Add the value output of the first texture node into the Fac input of the mix node.
- Finally plug the mix node into the Alpha input of the ouput node.
Using different mix modes
More complex sections can be achieved by using combinations of different mix modes.
Here are two simple sections through a building. The first is passing along the X axis and the second along the Y axis.
These two simple sections can be combined into more interesting outputs using several methods.
With Multiply the values of both sections get multiplied. If one or both sections are black/transparent the resulting output is zero or transparent. Therefore, only the part of the building shared by both sections remains visible.
With Difference the values from both sections are subtracted from each other and the absolute value is returned. The resulting output is the parts of the building unique to either of the sections.
Finally, by plugging these two outputs into a third mix node set to Add, both outputs are combined into a single section.
To make the cut-out even more interesting keep adding sections using different mixing modes.
Here the previous output is combined with a third horizontal section. By choosing Multiply the transparency of this third sections cancels out the previous result making the top of the building transparent.