Skip to main content

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!

Metadata

Release files for diffrp 0.2.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for diffrp 0.2.7
File Size Uploaded
diffrp-0.2.7.tar.gz 2.8 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for diffrp 0.2.7
File Interpreter ABI Platform
diffrp-0.2.7-py3-none-any.whl Python 3 none any Details

Total release size: 5.6 MB

Release files / diffrp-0.2.7.tar.gz

Download URL diffrp-0.2.7.tar.gz
Size 2.8 MB
Tags Source
SHA-256 checksum
How to use checksums
06c37819105cb8d2efdcbfbe64d8b1f89f0fe283a172456b09ace662ddae2775
BLAKE2b-256 checksum
How to use checksums
4fe88af60ec0702fcc1c4325becfe95193195c7ad225ab37d865121ecad256b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Release files / diffrp-0.2.7-py3-none-any.whl

Download URL diffrp-0.2.7-py3-none-any.whl
Size 2.8 MB
Tags Python 3
SHA-256 checksum
How to use checksums
f09c526c4aefa31658adb557f1a05bd07778b9423025c58b860be2206a826fd8
BLAKE2b-256 checksum
How to use checksums
dc9b13171f7c201e1d26468969d8e9480c06752f1f8ea79859cd059a7dbd7090
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.2.7 This release

2 release files

0.2.6

2 release files

0.2.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page