Convert Figma logo to code with AI

PixarAnimationStudios logoOpenSubdiv

An Open-Source subdivision surface library.

2,876
558
2,876
57

Top Related Projects

Mitsuba 2: A Retargetable Forward and Inverse Renderer

2,590

OpenVDB - Sparse volume data structure and tools

Unity Graphics - Including Scriptable Render Pipeline

Quick Overview

OpenSubdiv is an open-source library developed by Pixar Animation Studios for high-performance subdivision surface evaluation on massively parallel CPU and GPU architectures. It provides a set of interoperable APIs and tools that implement subdivision surfaces for film and game industry application developers.

Pros

  • High-performance subdivision surface evaluation on both CPU and GPU
  • Interoperable APIs for easy integration into existing pipelines
  • Supports various subdivision schemes (Catmull-Clark, Loop, Bilinear)
  • Backed by Pixar Animation Studios, ensuring industry-standard quality

Cons

  • Steep learning curve for beginners due to complex mathematical concepts
  • Limited documentation for advanced use cases
  • Requires understanding of parallel computing for optimal performance
  • May be overkill for simple 3D projects or small-scale applications

Code Examples

  1. Creating a simple mesh:
#include <opensubdiv/far/topologyDescriptor.h>
#include <opensubdiv/far/primvarRefiner.h>

OpenSubdiv::Far::TopologyDescriptor desc;
desc.numVertices = 4;
desc.numFaces = 1;
int vertsPerFace[] = {4};
int faceIndices[] = {0, 1, 2, 3};

desc.numVertsPerFace = vertsPerFace;
desc.vertIndicesPerFace = faceIndices;

OpenSubdiv::Far::TopologyRefiner * refiner =
    OpenSubdiv::Far::TopologyRefinerFactory<OpenSubdiv::Far::TopologyDescriptor>::Create(desc);
  1. Applying subdivision:
int maxLevel = 3;
refiner->RefineUniform(maxLevel);

std::vector<float> vertexBuffer;
OpenSubdiv::Far::PrimvarRefiner primvarRefiner(*refiner);

primvarRefiner.Interpolate(vertexBuffer, coarseVertices);
  1. Evaluating limit surface:
OpenSubdiv::Far::PatchTable const * patchTable =
    OpenSubdiv::Far::PatchTableFactory::Create(*refiner);

OpenSubdiv::Far::PatchMap patchMap(*patchTable);

float u = 0.5f, v = 0.5f;
int face = 0;
OpenSubdiv::Far::PatchTable::PatchHandle const * handle = patchMap.FindPatch(face, u, v);

float limitPoint[3];
patchTable->EvaluateLimit(handle, u, v, vertexBuffer.data(), limitPoint);

Getting Started

  1. Clone the repository:

    git clone https://github.com/PixarAnimationStudios/OpenSubdiv.git
    
  2. Build the library:

    cd OpenSubdiv
    mkdir build
    cd build
    cmake ..
    make
    
  3. Include the necessary headers in your project and link against the built libraries.

  4. Start using OpenSubdiv in your code by creating topology descriptors, refining meshes, and evaluating subdivision surfaces as shown in the code examples above.

Competitor Comparisons

Mitsuba 2: A Retargetable Forward and Inverse Renderer

Pros of Mitsuba2

  • More versatile rendering capabilities, including spectral rendering and advanced light transport algorithms
  • Supports Python bindings, allowing for easier integration with data science and machine learning workflows
  • Offers a wider range of material models and sensor types

Cons of Mitsuba2

  • Steeper learning curve due to its more complex architecture and broader feature set
  • Less specialized for subdivision surfaces compared to OpenSubdiv
  • May have higher computational requirements for certain rendering tasks

Code Comparison

OpenSubdiv (C++):

Far::TopologyRefiner * refiner = Far::TopologyRefinerFactory<Shape>::Create(
    shape,
    Far::TopologyRefinerFactory<Shape>::Options(
        Far::TopologyRefinerFactory<Shape>::CREASE_UNIFORM));

Mitsuba2 (Python):

scene = mi.load_file('scene.xml')
integrator = mi.load_dict({
    'type': 'path',
    'max_depth': 8
})
image = mi.render(scene, integrator=integrator)

The code snippets demonstrate the different focus areas of the two libraries. OpenSubdiv is specialized for subdivision surfaces, while Mitsuba2 provides a more general-purpose rendering framework with support for various integrators and scene descriptions.

2,590

OpenVDB - Sparse volume data structure and tools

Pros of OpenVDB

  • Specialized for volumetric data and sparse volume representations
  • Offers advanced level set operations and fluid simulations
  • Provides efficient data structures for large-scale voxel grids

Cons of OpenVDB

  • Steeper learning curve due to complex volumetric concepts
  • Less suitable for general-purpose subdivision surfaces
  • May require more computational resources for certain operations

Code Comparison

OpenVDB:

openvdb::initialize();
openvdb::FloatGrid::Ptr grid = openvdb::FloatGrid::create();
openvdb::FloatGrid::Accessor accessor = grid->getAccessor();
accessor.setValue(openvdb::Coord(0, 0, 0), 1.0f);

OpenSubdiv:

OpenSubdiv::Far::TopologyDescriptor desc;
desc.numVertices = numVerts;
desc.numFaces = numFaces;
OpenSubdiv::Far::TopologyRefiner* refiner = OpenSubdiv::Far::TopologyRefinerFactory<OpenSubdiv::Far::TopologyDescriptor>::Create(desc);

OpenVDB excels in volumetric data handling and fluid simulations, while OpenSubdiv focuses on efficient subdivision surface algorithms. OpenVDB's code demonstrates creating and manipulating voxel grids, whereas OpenSubdiv's code shows setting up topology for subdivision. Choose OpenVDB for volumetric work and OpenSubdiv for traditional subdivision surfaces.

Unity Graphics - Including Scriptable Render Pipeline

Pros of Graphics

  • Broader scope, covering various aspects of graphics rendering in Unity
  • More active development and frequent updates
  • Larger community and ecosystem within Unity's framework

Cons of Graphics

  • More complex and potentially overwhelming for beginners
  • Less specialized in subdivision surfaces compared to OpenSubdiv
  • May require more setup and integration within Unity projects

Code Comparison

OpenSubdiv (C++):

OpenSubdiv::Far::TopologyRefiner * refiner =
    OpenSubdiv::Far::TopologyRefinerFactory<OpenSubdiv::Far::TopologyDescriptor>::Create(
        desc, OpenSubdiv::Far::TopologyRefinerFactory<OpenSubdiv::Far::TopologyDescriptor>::Options(
            OpenSubdiv::Sdc::SCHEME_CATMARK, OpenSubdiv::Sdc::OPTIONS_NONE));

Graphics (C#):

public class CustomRenderPipelineAsset : RenderPipelineAsset
{
    protected override RenderPipeline CreatePipeline()
    {
        return new CustomRenderPipeline();
    }
}

OpenSubdiv focuses on subdivision surfaces, providing a specialized library for high-quality surface modeling. Graphics, on the other hand, offers a comprehensive rendering pipeline for Unity, covering various aspects of graphics programming. While OpenSubdiv excels in its niche, Graphics provides a more versatile toolkit for game development within the Unity ecosystem.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

OpenSubdiv

OpenSubdiv is a set of open source libraries that implement high performance subdivision surface (subdiv) evaluation on massively parallel CPU and GPU architectures. This codepath is optimized for drawing deforming subdivs with static topology at interactive framerates. The resulting limit surface matches Pixar's Renderman to numerical precision.

OpenSubdiv is covered by the Apache license, and is free to use for commercial or non-commercial use. This is the same code that Pixar uses internally for animated film production. Our intent is to encourage high performance accurate subdiv drawing by giving away the "good stuff".

Feel free to use it and let us know what you think.

For more details about OpenSubdiv, see Pixar Graphics Technologies.

LinuxWindowsmacOS
devBuild StatusBuild StatusBuild Status
releaseBuild StatusBuild StatusBuild Status

Documents

Forum

Prerequisite

For complete information, please refer OpenSubdiv documents: Building with CMake

  • General requirements:
LibMin VersionNote
CMake3.12Required
  • Osd optional requirements:
LibMin VersionNote
CUDA4.0cuda backend
TBB2018TBB backend
OpenCL1.1CL backend
DX11 SDKDX backend
Metal1.2Metal backend
  • Requirements for building optional examples:
LibMin VersionNote
GLFW3.0.0GL examples
Ptex2.0ptex viewers
Zlib(required for Ptex under windows)
  • Requirements for building documentation:
Lib
Docutils
Doxygen
Graphviz

Build example to run glViewer and other example programs with minimal dependency

All platforms:

  • Install cmake and GLFW

make sure GLFW install directories are configured as follows:

   ${GLFW_LOCATION}/include/GLFW/glfw3.h
   ${GLFW_LOCATION}/lib/libglfw3.a (linux)
   ${GLFW_LOCATION}/lib/glfw3.lib (windows)
  • Clone OpenSubdiv repository, and create a build directory.
   git clone https://github.com/PixarAnimationStudios/OpenSubdiv
   mkdir build
   cd build

Windows (Visual Studio)

cmake ^
    -G "Visual Studio 15 2017 Win64" ^
    -D NO_PTEX=1 -D NO_DOC=1 ^
    -D NO_OMP=1 -D NO_TBB=1 -D NO_CUDA=1 -D NO_OPENCL=1 -D NO_CLEW=1 ^
    -D "GLFW_LOCATION=*YOUR GLFW INSTALL LOCATION*" ^
    ..

cmake --build . --config Release --target install

Linux

cmake -D NO_PTEX=1 -D NO_DOC=1 \
      -D NO_OMP=1 -D NO_TBB=1 -D NO_CUDA=1 -D NO_OPENCL=1 -D NO_CLEW=1 \
      -D GLFW_LOCATION="*YOUR GLFW INSTALL LOCATION*" \
      ..

cmake --build . --config Release --target install

macOS

cmake -G Xcode -D NO_PTEX=1 -D NO_DOC=1 \
      -D NO_OMP=1 -D NO_TBB=1 -D NO_CUDA=1 -D NO_OPENCL=1 -D NO_CLEW=1 \
      -D GLFW_LOCATION="*YOUR GLFW INSTALL LOCATION*" \
      ..

cmake --build . --config Release --target install

iOS

SDKROOT=$(xcrun --sdk iphoneos --show-sdk-path) cmake -D NO_PTEX=1 -D NO_DOC=1 \
      -D NO_OMP=1 -D NO_TBB=1 -D NO_CUDA=1 -D NO_OPENCL=1 -D NO_CLEW=1 \
      -D CMAKE_TOOLCHAIN_FILE=../cmake/iOSToolchain.cmake -G Xcode \
      ..
  • This will produce an "OpenSubdiv.xcodeproj" that can be open and the targets 'mtlViewer' and 'mtlPtexViewer' (if NO_PTEX is ommitted and libPtex.a is installed in the iOS SDK) that can be run

Useful cmake options and environment variables

-DCMAKE_BUILD_TYPE=[Debug|Release]

-DCMAKE_INSTALL_PREFIX=[base path to install OpenSubdiv]
-DCMAKE_LIBDIR_BASE=[library directory basename (default: lib)]
-DCMAKE_TOOLCHAIN_FILE=[toolchain file for crossplatform builds]

-DCUDA_TOOLKIT_ROOT_DIR=[path to CUDA Toolkit]
-DOSD_CUDA_NVCC_FLAGS=[CUDA options, e.g. --gpu-architecture]

-DPTEX_LOCATION=[path to Ptex]
-DGLFW_LOCATION=[path to GLFW]
-DSTRINGIFY_LOCATION=[path to stringify utility]

-DNO_LIB=1        // disable the opensubdiv libs build (caveat emptor)
-DNO_EXAMPLES=1   // disable examples build
-DNO_TUTORIALS=1  // disable tutorials build
-DNO_REGRESSION=1 // disable regression tests build
-DNO_PTEX=1       // disable PTex support
-DNO_DOC=1        // disable documentation build
-DNO_OMP=1        // disable OpenMP
-DNO_TBB=1        // disable TBB
-DNO_CUDA=1       // disable CUDA
-DNO_OPENCL=1     // disable OpenCL
-DNO_OPENGL=1     // disable OpenGL
-DNO_CLEW=1       // disable CLEW wrapper library
-DNO_METAL=1      // disable Metal