Arnold USD

repository·master·Indexed 43 days ago

https://github.com/autodesk/arnold-usd

A collection of tools and components that integrate the Arnold renderer with Pixar's Universal Scene Description (USD) ecosystem. It includes a Hydra render delegate for rendering USD scenes in Hydra-based applications, an Arnold USD procedural for direct USD file parsing, and specialized USD schemas for Arnold-specific scene data.

Tokens
14.1K
Snippets
36
Records
65
Agent score
52%

What's inside Arnold USD

  1. Overview of Arnold USD components

    master

    Arnold USD provides a bridge between the Arnold renderer and Pixar's Universal Scene Description (USD). It consists of three primary components:

    1. Hydra Render Delegate: Allows Arnold to be used as a rendering backend within Hydra-based applications (like usdview). It supports RPrims (Mesh, Volume, Points), SPrims (Materials, Lights), and BPrims (Render Buffers, OpenVDB Assets).
    2. Arnold USD Procedural: Enables Arnold to parse and render USD scenes directly. It supports various UsdGeom primitives, UsdLux lights, and native USD shaders like UsdPreviewSurface.
    3. USD Schemas: Custom schemas designed to describe Arnold-specific scene data within the USD framework.
  2. Represent Arnold nodes as USD prims

    master

    Any Arnold node can be represented in USD by using a camel-cased node type prefixed with Arnold. Unlike attributes on native prims, the attribute names for these specific Arnold prim types are the direct Arnold parameter names and should not be namespaced.

    def ArnoldStandardSurface "my_shader" {}
    def ArnoldSetOperator "my_operator" {}
    def ArnoldPolymesh "my_mesh" {}
    def ArnoldSkydomeLight "my_light" {}
  3. Hydra Render Delegate features and limitations

    master

    The Hydra render delegate provides deep integration for rendering USD scenes via Arnold.

    Key Capabilities:

    • RPrim Support: Mesh (including primvars, normal translation, and subdivision), Volume, and Points.
    • SPrim Support: Arnold shaders (via info:id), UsdPreviewSurface translation, Lights (Distant, Sphere, Disk, Rect, Cylinder, Dome), and Light/Shadow linking.
    • Advanced Rendering: Motion Blur (Deformation, Transformation, and motion vectors), Point Instancers, and Deep render products.
    • AOVs: Support for Color, Depth, and primId (for selection).
    • Render Settings: Sampling, threading, CPU/GPU switching, and configurable defaults via environment variables.

    Limitations:

    • No support for periodic or pinned curves.
    • No field3d volume grids.
    • No normal maps on UsdPreviewSurface.
    • Only converging renders are supported (viewport blocking is not possible).
    • No coordsys support.
    • Face-varying primvars may not interpolate correctly.
  4. Arnold USD Procedural features and limitations

    master

    The Arnold USD procedural allows the Arnold renderer to interpret USD files directly.

    Supported Primitives:

    • UsdGeom: Mesh, Curves, BasisCurves, Points, Cube, Sphere, Cone, Cylinder, PointInstancer, Volume, and Camera.
    • UsdLux: Distant, Dome, Disk, Sphere, Rect, and Geometry lights (including textured lights).
    • Shaders: UsdPreviewSurface, UsdPrimVar*, UsdUVTexture, and Arnold shaders defined as UsdShade nodes.

    Key Capabilities:

    • Support for UsdPurpose, Light Linking, and multi-threaded parsing.
    • Support for Arnold-specific attributes (e.g., primvars:arnold:subdiv_iterations).
    • Support for UsdRender schema.

    Limitations:

    • Currently does not support Nurbs.
  5. Follow C++ naming conventions

    master

    Arnold USD follows USD's naming conventions for C++. When writing code, adhere to these rules for identifiers:

    • Classes: Use CamelCase and include a module-specific prefix (e.g., HdArnoldLight).
    • Structs: Use CamelCase. Structs used for compact data storage without visibility or member functions only need a module prefix if exposed in a header.
    • Functions: Use CamelCase.
      • Private or protected class functions must be prefixed with an underscore (e.g., _MyFunction).
      • Functions defined within an anonymous namespace in a source file must be prefixed with an underscore (e.g., _MyFunction).
    • Variables: Use camelCase.
      • Class variables must be prefixed with an underscore (e.g., _myVariable).
      • Struct variables should not be prefixed with an underscore.
    • Macros and Enums: Use ALL_UPPER_CASE.
    // Class with prefix
    class HdArnoldRenderDelegate;
    
    // Private function with underscore
    void _MyPrivateFunction();
    
    // Class variable with underscore
    int _myVariable;
    
    // Struct variable without underscore
    struct MyStruct {
        int myVariable;
    };
    
    // Macro/Enum
    #define UPDATE_CAMERA 1
    enum PartitionType { POINTS = 0 };
  6. Apply Arnold attributes to native USD prims

    master

    To add Arnold-specific parameters to native USD primitives (such as geometry or lights), you must set them as primvars within the arnold namespace.

    Attributes defined in the primvars:arnold: scope are translated as built-in attributes on the Arnold node. For example, primvars:arnold:max_bounces will be treated as arnold:max_bounces on the Arnold side. Other primvars in the arnold namespace will be converted as user data.

    def DomeLight "my_light"
    {
     float intensity=2
     int primvars:arnold:max_bounces=99
    }
  7. Document C++ code using Doxygen conventions

    master

    Arnold USD uses Doxygen for automated documentation generation. When documenting C++ code, follow these conventions:

    • Use triple slashes (///) for Doxygen comments.
    • Use ///< for documenting member variables/members.
    • The first line (ending with a dot . or a blank line) is treated as the brief one-line description.
    • Use the @ prefix for Doxygen commands and tags (e.g., @param, @return).
    • For classes, describe their responsibilities and dependencies.
    • For methods and functions, describe the purpose, every individual parameter, and the return value.
    • Every header file must include a short description after the license using the @file tag.
    /// Short description in one phrase.
    ///
    /// Optionally, here goes a much more detailed description of the function.
    /// This longer description can spawn multiple lines, include code samples, etc.
    ///
    /// @param a This is the first floating point number to be added
    /// @param b And this is the second number
    /// @return  The sum a + b
    float myAddFunction(float a, float b)
    {
       // ...
    }
  8. Build Arnold USD for Houdini

    master

    To build against Houdini libraries (18.0+), you must account for Houdini's specific naming conventions and library locations.

    Key Configuration Requirements

    • USD Library Prefix: Houdini prefixes standard USD library names with libpxr_. Set USD_LIB_PREFIX='libpxr_'.
    • Boost Naming:
      • On Linux/macOS: Boost libraries are prefixed with h. Set BOOST_LIB_NAME='hboost_%s'.
      • On Windows: Boost libraries are prefixed with h and suffixed with -mt. Set BOOST_LIB_NAME='hboost_%s-mt'.
    • Schemas: As of Houdini 18.0.287, Houdini does not ship usdGenSchema, so BUILD_SCHEMAS should be set to False.

    Example: Houdini 18.0.287 on macOS (custom.py)

    ARNOLD_PATH='/opt/solidAngle/arnold'
    
    WARN_LEVEL='warn-only'
    
    USD_PATH='./'
    USD_LIB='/Applications/Houdini/Houdini18.0.287/Frameworks/Houdini.framework/Versions/Current/Libraries'
    USD_INCLUDE='/Applications/Houdini/Houdini18.0.287/Frameworks/Houdini.framework/Versions/Current/Resources/toolkit/include'
    USD_BIN='/Applications/Houdini/Houdini18.0.287/Frameworks/Houdini.framework/Versions/Current/Resources/bin'
    USD_BUILD_MODE='shared_libs'
    USD_LIB_PREFIX='libpxr_'
    
    BOOST_INCLUDE='/Applications/Houdini/Houdini18.0.287/Frameworks/Houdini.framework/Versions/Current/Resources/toolkit/include/hboost'
    BOOST_LIB='/Applications/Houdini/Houdini18.0.287/Frameworks/Houdini.framework/Versions/Current/Libraries'
    BOOST_LIB_NAME='hboost_%s'
    
    PYTHON_INCLUDE='/Applications/Houdini/Houdini18.0.287/Frameworks/Python.framework/Versions/2.7/include/python2.7'
    PYTHON_LIB='/Applications/Houdini/Houdini18.0.287/Frameworks/Python.framework/Versions/2.7/lib'
    PYTHON_LIB_NAME='python2.7'
    
    BUILD_SCHEMAS=False
    BUILD_RENDER_DELEGATE=True
    BUILD_PROCEDURAL=True
    BUILD_TESTSUITE=True
    BUILD_DOCS=True
    
    PREFIX='/opt/solidAngle/arnold-usd'
  9. Define Arnold Shaders using UsdShade

    master

    Arnold shaders are implemented as UsdShade Shader prims. To correctly map them to Arnold:

    1. Set the info:id attribute to the Arnold shader name, prefixed with the arnold: namespace (e.g., arnold:standard_surface).
    2. Place all shader parameters within the inputs scope.

    Refer to the standard UsdShade Shader schemas for implementation details.

    def Shader "my_shader"
    {
        uniform token info:id = "arnold:standard_surface"
        color3f inputs:base_color = (0,0,1)
    }
  10. Configure environment variables for Arnold USD

    master

    To use the Arnold USD components, you must set several environment variables pointing to your <arnold-usd_dir> installation directory. This ensures the Arnold procedural, Python schema bindings, Hydra render delegate, Node Registry plugin, and USD schemas are correctly discovered by the system.

    Required Environment Variables:

    • Arnold Procedural: Add <arnold-usd_dir>/procedural to ARNOLD_PLUGIN_PATH.
    • Python Schema Bindings: Add <arnold-usd_dir>/lib/python to PYTHONPATH.
    • Hydra Render Delegate & Node Registry Plugin: Add <arnold-usd_dir>/plugin to PXR_PLUGINPATH_NAME.
    • USD Schemas: Add <arnold-usd_dir>/lib/usd to PXR_PLUGINPATH_NAME.
    • Shared Libraries: Add <arnold-usd_dir>/lib to your system library path:
      • Linux: LD_LIBRARY_PATH
      • Windows: PATH
      • macOS: DYLD_LIBRARY_PATH
  11. Adhere to C++ coding style and best practices

    master

    The project uses C++11 and follows the C++ Core Guidelines. Key style requirements include:

    • Formatting: Use the supplied .clang-format with clang-format 9.0.1. Indent with four (4) spaces; do not use tabs.
    • Line Width: Maximum column width is 120, though ~80 is preferred to match USD conventions.
    • Function Calls: No spaces between the function name and parenthesis, and no spaces inside the parenthesis (e.g., func(a, b);).
    • Modern C++:
      • Use const and constexpr whenever possible.
      • Use nullptr instead of NULL or 0 for pointers.
      • Use the override keyword for class functions.
      • Use C++ style casting (static_cast, reinterpret_cast) instead of C-style casts. const_cast is forbidden unless required by external library design.
      • Use C++ notation for includes (e.g., #include <cstring>).
    • Comments: Use C++ style comments // (with a following space). Do not use /* ... */.
    • Control Flow: Brackets {} are always required for every block of code, even for single-line statements.
    // Correct usage examples
    const float b = 5.0f;
    constexpr float c = 5.0f;
    A* a = nullptr;
    
    class Child : public Parent {
    public:
        void MyFunc() override;
    };
    
    if (statement) {
        OneLineFunction();
    }
    
    // Correct casting
    constexpr float d = static_cast<int>(a);