Modeling in Houdini using VDB SDF volumes

Tutorial / 14 May 2023

I noticed that people Modeler for Houdini Discord group were interested in SDF boolean operations, so I decided to create a simple example of SDF usage and share some of my notes.

There are two versions of the same example file:

VDB_SDF_Modeling.hiplc - The original file, but it contains nodes from Modeler 2023.4 plugin.

VDB_SDF_Modeling_Stashed.hiplc - A copy of the first file in which I replaced all operations from the Modeler 2023.4 plugin with Stash nodes.

If you do not have Modeler plugin, then download the second file and you will still get an idea of boolean operations using SDF volumes.


The file contains examples of using the following nodes and operations:

VDB from Polygons (to convert polygonal geometry to SDF volume).

VDB Smooth SDF (to smooth edges of geometry similar to the results from polygonal round bevel).

VDB Resample (to change voxel density to increase object detail).

VDB Combine (to apply boolean operations: SDF Union, SDF Difference, SDF Intersection).

VDB Reshape SDF (to expand or narrow voxel shapes, similar to the Peak operation).

VDB Convert (to convert SDF into polygonal geometry).

Volume Deform (to deform voxel shapes by using Lattice from Volume node in conjunction with Bend node to deform point grid which represents voxel grid).

Name and Attribute Edit String (to build hierarchy of LOP primitives while working in SOP)


Notes about using SDF nodes:

  1. Increase voxel density only when necessary. Generally, I used a voxel size of 0.02 when converting geometry through VDB to Polygons and could move shapes interactivly. However, in some cases, I needed narrower or smaller bevels and increased density to 0.01 voxel per unit in exchange to performance.
  2. After all operations, you can also increase voxel density through VDB Resample to get a denser and more detailed polygonal mesh from Convert VDB.
  3. Use different smoothing modes to maintain performance. Instead of increasing the number of smoothing iterations in VDB Smooth SDF, try to change the type of operation: Mean Value for normal smoothing, Gaussian for strong smoothing, Mean Curvature Flow for weak smoothing or smoothing small details.
  4. If you need to place one object inside another, for example a button in a housing, use VDB Reshape SDF to expand the SDF before boolean subtraction.
  5. I didn't find a way to store color in SDF and pass it through boolean operations, so after converting to polygons by Convert VDB I used Bounding Volume parameter in Group node to select the area that I want to color using SDF volume.
  6. Deform objects in voxels through Volume deform instead of deforming them in polygons. This is convenient because the bend deformer when used on polygons will not be able to bend the area where not enough geometry, but through Volume deform, you bend a point grid, so you can bend and deform even each pair of voxels.

Notes on modeling in SOPs within LOPs:

  1. To improve performance, prevent SOP from the constant transferring of data to LOPs. To do this, place Output node inside the SOP and connect the geometry to it only when you want to transfer it to the LOP, otherwise keep geometry disconnected.
  2. The same goes for working inside Component Geometry node: connect geometry to the default, proxy, and simproxy output nodes only when necessary, otherwise, the entire node tree will be recalculated with every change.
  3. Start building hierarchy of LOP primitives while still in SOPs. Hierarchy construction will occur from top to bottom, from leaf to root. At the very beginning (for leaves), add Name node that will create the corresponding attribute and enter the geometry name into it, for example, Mesh. Then add an Attribute Edit String node, specify that you want to edit Name attribute, and in Editor tab, set "*" (all existing names) in From parameter. To the To parameter add the name of the LOP primitive where you want to place the geometry, like "Primitive/*". Thus, the Name attribute will become "Primitive/Mesh". Further, continue to add Attribute Edit String nodes with the same parameters to assign more parents or to group primitives after merging. The last Attribute Edit String will have "/*" name set in To parameter and will close the path (for example, "/Gamepad/Triggers/Primitive1/Mesh").

I've used the video as reference for the model.

Compile OpenCV with CUDA support for Python in Houdini on Windows 11

Tutorial / 08 May 2023

With the recent release of MLOPS for Houdini, I've got interested in Python libraries for image processing. One such library is OpenCV. The pip-installable version of OpenCV mostly runs on CPU and uses OpenCL to accelerate some functions. However, to accelerate features like tracking and image warping, it is necessary to compile OpenCV with CUDA support. 

I recommend to not skip any steps in this article because it can lead to compilation errors or problems with installing the compiled package. I've tried to shortcut on every step, so believe me :)

To start with, I'll briefly list what we'll need:

1. Installing the CUDA Toolkit

CUDA allows software to use graphic card from Nvidia for data processing. 

Download and install the CUDA Toolkit on your PC with an NVIDIA graphics card. I will be using CUDA 11.8 because this version is used by the MLOPS nodes at the time of writing this article. Use Express settings during installation, we're going to install cuDNN to folder of CUDA installation next.

2. Installing cuDNN. 

CuDNN is a GPU-accelerated library for deep neural networks. 

OpenCV supports DNN, so we need to install it to compile the package successfully. 

To download cuDNN, you will need to register and sign in on https://developer.nvidia.com website.

During registration, if you are not associated with any organization, then in the mandatory field "Organization name", specify "Individual". 

Click on Download cuDNN v8.9.1 (May 5th, 2023), for CUDA 11.x , then Local Installer for Windows (Zip)

Download archive to any folder for example, C:\Users\Aleksandr\Documents\Sources\  

Unpack and open the folder: ex. C:\Users\Aleksandr\Documents\Sources\cudnn-windows-x86_64-8.9.1.23_cuda11-archive\cudnn-windows-x86_64-8.9.1.23_cuda11-archive

To install cuDNN, you need to select and copy the bin, include, lib folders from downloaded cuDNN directory to the directory where CUDA Toolkit is installed: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8 by default. Copy all three folders with replacement.

Copy and replace bin,include,lib folders from cuDNN to root of CUDA/v11.8 folder.

3. Installing Visual Studio

OpenCV sources are written in C++, and we need Visual Studio software to compile them into python package.

Download Visual Studio Community 2022 version. 

Run VisualStudioSetup, after which the Visual Studio Installer will open. Here we should select all the necessary components.

First, we need to check "Desktop development with C++", 

and on the right, we will need the following optional components: 

  • MSVC v143 - VC 2022 C++ x64/x86 building tools
  • C++ ATL for the latest v143 build tools
  • Windows 11 SDK
  • Just-in-time debugger
  • C++ Profiler tools
  • C++ CMake tools for Windows
  • C++ Address Sanitizer

Second, we need "Python Development":

  • Python 3 (64-bit), 
  • Python Native development tools, 

This way we install Python inside Visual Studio and guarantee the creation of an OpenCV package in it at the very end of this article. 

Press Install.

3. Installing Numpy.

NumPy is python dependency which is often used in combination with OpenCV to manipulate and process images and videos efficiently. We need it to build OpenCV.

Open Command Prompt in Windows 11: 

Press Start - Type "CMD" - Command Prompt

Install Numpy through pip Python's package manager:

Type: py -m pip install numpy

Press Enter

On this screenshot NumPy is already installed to Python in Visual Studio folder

4. Install CMake

CMake automates the generation of build files for various platforms. We need it to generate Visual Studio project files from downloaded OpenCV sources.

Download Cmake and install it in default location.

Windows x64 Installer: cmake-3.26.3-windows-x86_64.msi

5. Download OpenCV sources

This is an original source code of the OpenCV project.

Download and unpack the OpenCV source files into any folder, for example: C:\Users\Aleksandr\Documents\Sources\opencv-4.7.0.

OpenCV-4.7.0 - Sources

6. Download OpenCV-contrib files

OpenCV-contrib is a repository of additional modules and extensions for the OpenCV. We're going to get CUDA modules from it.

Download OpenCV-contrib files and unpack it into any folder, for example: C:\Users\Aleksandr\Documents\Sources\opencv_contrib-4.7.0

GitHub - OpenCV/OpenCV_contrib - Tags - 4.7.0

7. Create Build folder

We need some folder to Cmake generate project files into.

Create empty folder "Build" where we're going to store opencv project files for building. For ex. C:\Users\Aleksandr\Documents\Sources\Build


8. Run Cmake

Press Start - run CMake

After that, the CMake window will open, where we will prepare the Visual Studio project for launch:

In "Where is the source code" press "browse source" button and select folder where we extracted opencv source code previously. For ex. C:\Users\Aleksandr\Documents\Sources\opencv-4.7.0

In "Where to build the binaries" press "browse build" and select Build folder which we created previously. For ex. C:\Users\Aleksandr\Documents\Sources\Build

Press Configure button.

Configure window - Optional platform for generation - select x64 - Press Finish

Type the next variables in the search field:

WITH_CUDA : Check
ENABLE_FAST_MATH : Check
BUILD_OPENEXR : Check
BUILD_opencv_world : Check

Also, we need to set path to folder where additional OpenCV modules (opencv_contrib-4.7.0\modules) are stored:

OPENCV_EXTRA_MODULES_PATH : C:/Users/Aleksandr/Documents/Sources/opencv_contrib-4.7.0/opencv_contrib-4.7.0/modules

Press Configure button again.

Now we can configure CUDA module variables:

CUDA_FAST_MATH : Check

Here you need to check Compute capability (version) specific for your graphic card. For example: I have a graphic card Nvidia RTX 3060 and its compute capability version is 8.6


CUDA_ARCH_BIN : 8.6

We don't need to debug project, so change the next variable to Release only:


CMAKE_CONFIGURATION_TYPES : Release

Press Configure.

Press Generate.

Press Open Project.


After that, there will be a configuration and the first launch of Visual Studio, and the OpenCV project will open, which we will compile.

9. Build and Install OpenCV in Visual Studio


When Visual Studio and the project open, in the right-hand window Solution Explorer, expand the CMakeTargets tab.

In the tab Right Click on ALL_BUILD - press BUILD

Wait, this building process may take a long time.

Next, Right Click on INSTALL - press BUILD

The result of the installation is a new cv2 folder in the Python directory of Visual Studio:

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\Lib\site-packages\cv2

10. Copy and check OpenCV package in Houdini

Now we need to copy the OpenCV package to the directory where Houdini's hython can find it.

If you are not using MLOPs, it can be a directory in your Houdini user preferences: C:\Users\Aleksandr\Documents\houdini19.5\scripts\python 

If you are using MLOPs, go to the folder where you store MLOPs data: $MLOPS/data/dependencies/python, for example: C:\Users\Aleksandr\Documents\GitHub\MLOPs\data\dependencies\python. Then backup copy of the cv2 folder to any location and delete it. 

Copy cv2 folder from C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\Lib\site-packages to target directory. 

Launch Houdini.

Open Windows - Python Source Editor

Type the code:

import cv2

count = cv2.cuda.getCudaEnabledDeviceCount()

print(count)

This code will output to the console the number of devices that support CUDA computations.

 If this number is greater than 0, for example 1, it means that you have successfully installed OpenCV with CUDA support in Houdini.

Related articles: 

How to build OpenCV with Cuda and cuDNN support in Windows – 2023

Quick and Easy OpenCV Python Installation with Cuda GPU in Under 10 Minutes