Skip to content

A collection of custom operators to start exploring development in c++ for TouchDesigner.

License

Notifications You must be signed in to change notification settings

TouchDesigner/CustomOperatorSamples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Custom Operator Samples

We hope these custom operators can be a starting point to developing for anybody including members of the community only beginning with c++ development.

A collection of these operators can be found in the Samples/CPlusPlus folder of the TouchDesigner Installation. Others, which depend on more external libraries can be found on the Derivative github here: https://github.com/TouchDesigner

For discussions around this repository, please use our forum.

Tip: You can kick-start your custom operators projects by using the Cpp Pars Template Generator (cppParsTemplateGen) available in TouchDesigner's Palette to generate a Parameters class that will mimic the custom parameters of a reference COMP. For more informations, please visit the wiki.

Operators

Compiling Custom Operators

This text should be a small guide to getting started with compiling custom operators that can be found on github or elsewhere as pure source code. Often setting up your environment is the most difficult step followed by making accessible all libraries that might be necessary for successfully compiling other’s projects.

Installing Visual Studio Community Edition

  • Download the latest Visual Studio Community Edition from: https://visualstudio.microsoft.com/vs/community/
  • Start the installation process
  • In the Installer, select “Desktop Development with C++” and proceed with the installation process

alt_text

Installing the CUDA Toolkit

For some of the projects a CUDA Development environment is required. Which version much depends on the TouchDesigner version the operator is targeted at. Check https://docs.derivative.ca/CUDA for more information.

alt_text

Referencing CUDA libraries

  • After loading a project in Visual Studio, open the Project’s Properties via the Project>Properties or by hitting Alt+F7
  • Make sure to set the “Configuration“ Dropdown to “All Configurations”
  • In the Configuration Properties, navigate to C/C++ and edit the “Additional Include Directories” to make sure the value to the CUDA toolkit, $(CudaToolkitIncludeDir), is present.

alt_text

  • Still in the Configuration Properties, navigate to Linker and edit the “Additional Library Directories” to make sure the value to the CUDA toolkit, $(CudaToolkitIncludeDir), is present.

alt_text

Referencing openCV libraries

Some projects make use of various openCV modules. Which openCV release is required depends on the version used by the creator. Since TouchDesigner 2020.44130, openCV 4.5’s libraries are included in the TouchDesigner Installfolder at Samples\CPlusPlus\3rdParty. The solutions using openCV require an environmental variable called TOUCHDESIGNER_3RDPARTY_TOOLS_PATH which should point to the before mentioned 3rdParty path. Before building, add this variable via Windows' System Properties dialog.

alt_text

Using external openCV libraries

If you want to use a different openCV version, you can follow these instructions. If you additionally need CUDA support, follow instructions below to compile openCV with CUDA support.

  • Download the precompiled version of the openCV windows libraries from here: https://github.com/opencv/opencv/releases - there are self extracting archives available
  • Extract to a location on your computer
  • After loading a project in Visual Studio, open the Project’s Properties via the Project>Properties or by hitting Alt+F7
  • In the Configuration Properties, navigate to C/C++ and edit the “Additional Include Directories” to include the path to the folder containing the openCV libraries

alt_text

  • Still in the Configuration Properties, navigate to Linker and edit the “Additional Library Directories” to include the path to the folder containing the openCV libraries.

alt_text

  • Finally, make sure that all required libraries are correctly referenced under the Linker/Input section. Add any missing libraries to the list under “Additional Dependencies”.

alt_text

Note: By default, the binaries and libs shipped with TouchDesigner are "Release" binaries. The examples of this repository might fail to compile in the Debug configuration of Visual Studio. If you wish to compile with debug features, you should manually compile OpenCV with CUDA.

Compiling openCV with CUDA support (Not necessary for building these examples.)

Note: This is not necessary for compiling these operators - in fact TouchDesigner comes with all necessary binaries precompiled. We'll leave this guide here as the instructions were hard to find initialy.

Some other projects require the openCV windows libraries with CUDA modules included, yet as the available pre-built versions do not offer this support, openCV has to be recompiled with the required CUDA modules enabled. A good guide to follow can be found here: https://jamesbowley.co.uk/accelerate-opencv-4-3-0-build-with-cuda-and-python-bindings/

Prerequisites

  • Visual Studio (using Visual Studio 2019 in this example)
  • The sources for openCV and openCV Contrib
  • CMake
  • CUDA Toolkit
  • Optional: for video decoding on the gpu - Nvidia Video Codec SDK
  • Extract and copy the contents of the Interface directory to the include directory and the Lib directory to the lib directory inside your CUDA installation.
  • Optional: for DNN CUDA backend support - cuDNN
  • Extract and copy the bin, include and Lib directories to your CUDA installation

Generating openCV build files with CMake

The original instructions ask for running everything in a Command Prompt, arguably it’s easier to create a .bat file.

  • create a .bat file and open it in your editor:
set "openCvSource=PATH_TO_OPENCV_SOURCE"
set "openCVExtraModules=PATH_TO_OPENCV_CONTRIB_MODULES"
set "openCvBuild=%openCvSource%\build"
set "buildType=Release"
set "generator=Visual Studio 16 2019"
"C:\Program Files\CMake\bin\cmake.exe" -B"%openCvBuild%/" -H"%openCvSource%/" -G"%generator%" -DCMAKE_BUILD_TYPE=%buildType% -DOPENCV_EXTRA_MODULES_PATH="%openCVExtraModules%/" -DINSTALL_TESTS=ON -DINSTALL_C_EXAMPLES=ON -DBUILD_EXAMPLES=ON -DBUILD_opencv_world=ON -DWITH_CUDA=ON -DCUDA_TOOLKIT_ROOT_DIR="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2" -DCUDA_FAST_MATH=ON -DWITH_CUBLAS=ON -DCUDA_ARCH_PTX=7.5 -DWITH_NVCUVID=ON -DWITH_OPENGL=ON -DWITH_MFX=ON
  • run the bat file in a Terminal or Command Prompt
  • make changes to the configuration as required using the CMake GUI
  • open the OpenCV.sln in Visual Studio
  • In the Solution Explorer, expand CMakeTargets and right click on Install, selecting Build

Note: During the process of generating the build files with CMake, an error can occur when running on a ExFAT filesystem:

CMake Error: Problem extracting tar: e:/git/opencv/.cache/ippicv/879741a7946b814455eee6c6ffde2984-ippicv_2020_win_intel64_20191018_general.zip
CMake Error at cmake/OpenCVDownload.cmake:240 (message):
IPPICV: Unpack failed: 1

This can be resolved by using 7zip as explained here: https://stackoverflow.com/a/61489779

Specifying the Nvidia GPUs to generate Code for

Projects in this repositroy are setup to support all previous and future gpu hardware by compiling for virtual support for any pre pascal hardware and any post turing hardware. To make changes to this configuration:

  • In the Configuration Properties, navigate to CUDA C/C++ and edit the “Code Generation” entry to include all NVIDIA architectures to compile code for.
  • For a reference on GPU compilation and virtual as well as gpu features, please refer to https://docs.nvidia.com/cuda/archive/10.2/cuda-compiler-driver-nvcc/index.html#virtual-architectures
  • For best performance, when omitting older architectures, specify compute_xx,compute_xx for each omitted architecture. To support all future architecture, also add an additional compute_xx,compute_xx entry for the newest architecture. Here xx is referring to the 2 digit hardware architecture identifier.

alt_text

Fixes for openCV or CUDA version updates

Some newer TouchDesigner Versions might be delivered with an updated openCV and/or require a newer CUDA Version. In this case it is easiest to edit the solutions *.vcxproj file. The files are XML strucutred.

change the openCV version

Open the *.vcxproj file in a texteditor and search for the xml node <AdditionalDependencies>. In the value, there should be something like opencv_world451.lib.Change this file to the file available in your TouchDesigner install folder under Samples/CPlusPlus/3rdParty/opencv/lib/Win64. For example openCV version 4.5 would reference opencv_world450.lib while openCV version 4.5.1 would have to reference opencv_world451.lib. There should be at least 2 sections in the file where this is referenecd, once under Debug and once under Release.

change the CUDA version

open the *.vcxproj file in a texteditor and search for an xml node similar to <Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 11.2.props" />. Here change the version to the one currently used by your TouchDesigner build. This will have to be done in 2 places.

Loading Custom Operators in TouchDesigner

Please refer to the documentation here

Note: When compiling custom operators with a custom version of OpenCV (with or without CUDA) or other dependencies, you will need to place those dependencies next to your custom cpp operator .dlls

About

A collection of custom operators to start exploring development in c++ for TouchDesigner.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages