| On this page |
A stencil map is a texture that defines opaque and invisible areas. Any pixel with a value of 0 makes a polygon invisible to rays. You can change this pixel limit with a Stencil Threshold parameter.
Opacity maps, on the other hand, support grey shades to get semi-transparent (or semi-opaque) areas. With opacity maps it’s possible to create things like torn paper or tree leaves. The grey shades care for smooth edges and subtle light effects. The left image shows a part of the Houdini logo with aliased edges of a stencil map, while the opacity map on the right has a smooth appearance.
The nature of opacity maps speaks for their use when you want render foliage or grass. The flip side is that opacity maps require more resources and always invoke the shader engine. But sometimes its enough to have a pattern that looks as if it was made with a cookie cutter: clear and sharp edges with fully opaque or invisible areas. This is a typical use case for a stencil map.
Creating stencil maps ¶
Stencil maps have several requirements and what you typically find on the internet won’t work. If you want to create a stencil map in your image processing software, we recommend that you start with an 8-bit grey scale image. This mode will give you access to layers and you can apply effect filters.
You can try to use color transitions and gradients, but they're normally dithered during conversion and might lead to unwanted artifacts in the rendered image. You can adjust the map with a Stencil Threshold parameter on the Render Geometry Settings LOP, but normally won’t get the full level of detail. The images show the original map with subtle transitions and the rendered versions with different thresholds.
If you're happy with your artwork, convert it into an 8-bit indexed color image and save it as a BMP file. If you can see the stenciled pattern in the rendered image, you did everything right.
Basic usage ¶
You can use any object/geometry and it doesn’t even require a material. For the basic setup you’ll be using a SOP Create LOP with a
Grid SOP inside. Change the grid’s Scale to
2,2 to make it smaller.
Houdini’s base grid comes without UVs and you have to create them. For the grid, you can use the UV Flatten SOP, because it doesn’t flip the UVs. This can be important if you want to use a company logo for the stencil map. Stencil maps also support UDIMs.
Return to the stage level and lay down a Render Geometry Settings LOP.
-
On the Karma tab, expand the Shading section.
-
On the Stencil Map parameter, click the
button and choose Set or Create.
-
Drag the BMP file with the stencil map to the parameter. Alternatively, click the
Open floating file chooser button and choose a file from disk.
Warning
Stencil maps can only be in “decal” or “non-periodic mode”. So when you translate the UVs, the map will disappear. The only solution is to ensurce that the UV coordinates are strictly in the 0-1 range.
Materials ¶
Stencil maps are not part of any material definition. You can apply materials to your objects, but the stencil map will just ignore them and cut away what’s transparent. This also includes already existing opacity maps.
Note that it’s not possible to chain or merge multiple render geometry LOPs and “stack” stencil maps. Karma will always use the map from the last node.
Preview render ¶
To see a preview of the map, go to the upper right corner of the viewport and open the first dropdown menu (set to Persp, by default). From the menu, choose one of the Karma render delegates. Stencil maps work with both Karma CPU and Karma XPU.
Instances ¶
Stencil maps also work with instances, for example leaves on a tree or blades of grass. Stencil maps can significantly decrease render times, but at cost of slightly aliased edges. For backgrounds, or areas where you don’t need a high level of detail, this map type is perfectly suited.
The workflow is the same as with a single object and again the stencil map lives on a Render Geometry Settings LOP. The render geometry node must be downstream of the Copy to Points LOP. If necessary, use the render geometry node’s Primitive parameter to apply the maps only to selected items.