Modeling in Houdini using VDB SDF volumes

Tutorial / 14 May 2023

People in Modeler for Houdini Discord group were interested in SDF boolean operations. So, I created a simple example of SDF usage and shared 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 the Modeler 2023.4 plugin.

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

If you do not have a 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 the voxel grid).

Name and Attribute Edit String (to build a 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 interactively. However, in some cases, I needed narrower or smaller bevels and increased density to 0.01 voxel per unit in exchange for performance.
  2. After all operations, you can increase voxel density through the "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 changing the operation type: 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 the "Bounding Volume" parameter in the "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 there is not enough geometry, but through Volume deformation, 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 SOPs from constantly transferring data to LOPs. To do this, place the "Output" node inside the SOP and connect the geometry only when you want to transfer it to the LOP; otherwise, keep the geometry disconnected.
  2. The same goes for working inside the "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 a hierarchy of LOP primitives while still in SOPs. Hierarchy construction will occur from top to bottom, from leaf to root. At the beginning (for leaves), add a "Name" node to 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 the "Name" attribute, and in the Editor tab, set "*" (all existing names) in the "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 adding Attribute Edit String nodes with the same parameters to assign more parents or group primitives after merging. The last Attribute Edit String will have the "/*" name set in the "To" parameter and will close the path (for example, "/Gamepad/Triggers/Primitive1/Mesh").

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

Report

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 been interested in Python libraries for image processing. One such library is OpenCV. The pip-installable version of OpenCV mostly runs on a CPU and uses OpenCL to accelerate some functions. However, it is necessary to compile OpenCV with CUDA support to accelerate features like tracking and image warping. 

I recommend not skipping any steps in this article because it can lead to compilation errors or problems 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 cards from Nvidia for data processing. 

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

2. Installing cuDNN. 

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

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

To download cuDNN, register and sign in on the https://developer.nvidiathe.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 the 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, and include, lib folders from the 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 a Python package.

Download the 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 at the end of this article. 

Press Install.

3. Installing Numpy.

NumPy is a Python dependency often used 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

In this screenshot, NumPy is already installed in Python in the 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 the default location.

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

5. Download OpenCV sources

This is the 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 OpenCV. We're going to get CUDA modules from it.

Download OpenCV-contrib files and unpack them 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 a Build folder

We need some folders to Cmake generate project files into.

Create an empty folder, "Build," to store opencv project files for the 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 the "browse source" button and select the 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 the 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 the path to the 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 the Configure button again.

Now we can configure CUDA module variables:

CUDA_FAST_MATH : Check

You must check the Compute capability (version) specific to your graphic card here. For example, I have a graphic card, Nvidia RTX 3060, and its computing capability version is 8.6


CUDA_ARCH_BIN : 8.6

We don't need to debug the 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, 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 and 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 the OpenCV package in Houdini

We must 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 copies of the cv2 folder to any location and delete it. 

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

Launch Houdini.

Open Windows - Python Source Editor

Type the code:

import cv2

count = cv2.cuda.getCudaEnabledDeviceCount()

print(count)

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

 If this number is greater than 0, for example, 1, 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

Report