Skip to main content

Differentiable Render Pipelines with PyTorch.

Project description

Differentiable Render Pipelines diffrp

DiffRP aims to provide an easy-to-use programming interface for non-differentiable and differentiable rendering pipelines.

[Documentation] [Test Suite]

Teaser Rendered with DiffRP.

Installation

The package can be installed by:

pip install diffrp

Note

DiffRP depends on PyTorch (torch). The default version pip resolves to may not come with the cuda version you want. It is recommended to install PyTorch before you install DiffRP so you can choose the version you like.

DiffRP rendering is based on CUDA GPUs. You can develop without one, but a CUDA GPU is required to run the code.

Other Dependencies

If you use rasterization in DiffRP, you need to have the CUDA development kit set up as we use the nvdiffrast backend. See also https://nvlabs.github.io/nvdiffrast/#installation.

If you want to use hardware ray tracing in DiffRP, you need to install torchoptix by pip install torchoptix. See also the hardware and driver requirements https://github.com/eliphatfs/torchoptix?tab=readme-ov-file#requirements.

If you plan on using plugins in DiffRP (currently when you compute tangents), gcc is required in path. This is already fulfilled in most Linux and Mac distributions. For Windows I recommend the Strawberry Perl (https://strawberryperl.com/) distribution of gcc.

Get Started

Rendering attributes of a mesh programmingly is incredibly simple with DiffRP compared to conventional render engines like Blender and Unity.

In this section, we will get started to render a simple procedural mesh.

First, let's import what we would need:

import diffrp
import trimesh.creation
from diffrp.utils import *

We now create a icosphere and render the camera space normal map, where RGB color values in $[0, 1]$ map linearly to $[-1, 1]$ in normal XYZ vectors.

The first run may take some time due to compiling and importing the nvdiffrast backend. Following calls would be fast.

# create the mesh (cpu)
mesh = trimesh.creation.icosphere(radius=0.8)
# initialize the DiffRP scene
scene = diffrp.Scene()
# register the mesh, load vertices and faces arrays to GPU
scene.add_mesh_object(diffrp.MeshObject(diffrp.DefaultMaterial(), gpu_f32(mesh.vertices), gpu_i32(mesh.faces)))
# default camera at [0, 0, 3.2] looking backwards
camera = diffrp.PerspectiveCamera()
# create the SurfaceDeferredRenderSession, a deferred-rendering rasterization pipeline session
rp = diffrp.SurfaceDeferredRenderSession(scene, camera)
# convert output tensor to PIL Image and save
to_pil(rp.false_color_camera_space_normal()).save("procedural-normals.png")

Only 6 lines of code and we are done! The output should look like this:

Sample

The GPU buffers can be replaced by arbitrary tensors or parameters, and the process has been fully differentiable.

More

Please refer to the [Documentation] for more features!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

diffrp-0.2.7.tar.gz (2.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

diffrp-0.2.7-py3-none-any.whl (2.8 MB view details)

Uploaded Python 3

File details

Details for the file diffrp-0.2.7.tar.gz.

File metadata

  • Download URL: diffrp-0.2.7.tar.gz
  • Upload date:
  • Size: 2.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for diffrp-0.2.7.tar.gz
Algorithm Hash digest
SHA256 06c37819105cb8d2efdcbfbe64d8b1f89f0fe283a172456b09ace662ddae2775
MD5 fcfc03ed15a55bcc0522a1ef72cf8c27
BLAKE2b-256 4fe88af60ec0702fcc1c4325becfe95193195c7ad225ab37d865121ecad256b2

See more details on using hashes here.

File details

Details for the file diffrp-0.2.7-py3-none-any.whl.

File metadata

  • Download URL: diffrp-0.2.7-py3-none-any.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for diffrp-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 f09c526c4aefa31658adb557f1a05bd07778b9423025c58b860be2206a826fd8
MD5 e5aec48d793a25249a3431fc3c3d0244
BLAKE2b-256 dc9b13171f7c201e1d26468969d8e9480c06752f1f8ea79859cd059a7dbd7090

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page