#graphics #rendering #3d #ray-tracing #scene-description

nsi

High level bindings for Illumination Research’s Nodal Scene Interface for (offline) 3D renderers – ɴsɪ

28 releases

new 0.5.1 Jul 31, 2020
0.4.12 Jul 3, 2020
0.1.16 Mar 30, 2020

#24 in Graphics APIs

Download history 61/week @ 2020-04-08 47/week @ 2020-04-15 17/week @ 2020-04-22 4/week @ 2020-04-29 40/week @ 2020-05-13 49/week @ 2020-05-20 86/week @ 2020-05-27 148/week @ 2020-06-03 2/week @ 2020-06-10 38/week @ 2020-06-17 64/week @ 2020-07-01 74/week @ 2020-07-08 32/week @ 2020-07-15 55/week @ 2020-07-22

198 downloads per month

BSD-3-Clause

740KB
1.5K SLoC

ɴsɪ

High level Rust bindings for Illumination Research’s Nodal Scene Interface – ɴsɪ.

Build Documentation Crate Chat

This puts one of the most advanced 3D production offline renderers at your fingertips in Rust – 3Delight.

Moana Island, rendered with 3Delight|ɴsɪ The Moana Island Scene, provided courtesy of Walt Disney Pictures, rendered with 3Delight|ɴsɪ.

This is a huge scene (72GB of data) made of 31 million instances, 78 million polygons defining subdivison surface geometry and 2,300 Ptex textures. The above image was rendered in less than two minutes (wall time) using 3Delight Cloud.

Example

// Create a context to send the scene to.
let ctx = nsi::Context::new(&[])
    .expect("Could not create NSI context.");

// Create a dodecahedron.
let face_index: [u32; 60] =
    // 12 regular pentagon faces.
    [
         0, 16,  2, 10,  8,  0,  8,  4, 14, 12,
        16, 17,  1, 12,  0,  1,  9, 11,  3, 17,
         1, 12, 14,  5,  9,  2, 13, 15,  6, 10,
        13,  3, 17, 16,  2,  3, 11,  7, 15, 13,
         4,  8, 10,  6, 18, 14,  5, 19, 18,  4,
         5, 19,  7, 11,  9, 15,  7, 19, 18,  6,
    ];
let positions: [f32; 60] =
    // 20 points @ 3 vertices.
    [
         1.,     1.,     1.,     1.,     1.,    -1.,
         1.,    -1.,     1.,     1.,    -1.,    -1.,
        -1.,     1.,     1.,    -1.,     1.,    -1.,
        -1.,    -1.,     1.,    -1.,    -1.,    -1.,
         0.,     0.618,  1.618,  0.,     0.618, -1.618,
         0.,    -0.618,  1.618,  0.,    -0.618, -1.618,
         0.618,  1.618,  0.,     0.618, -1.618,  0.,
        -0.618,  1.618,  0.,    -0.618, -1.618,  0.,
         1.618,  0.,     0.618,  1.618,  0.,    -0.618,
        -1.618,  0.,     0.618, -1.618,  0.,    -0.618,
    ];

// Create a new mesh node and call it 'dodecahedron'.
ctx.create("dodecahedron", nsi::NodeType::Mesh, &[]);

// Connect the 'dodecahedron' node to the scene's root.
ctx.connect("dodecahedron", "", ".root", "objects", &[]);

// Define the geometry of the 'dodecahedron' node.
ctx.set_attribute(
    "dodecahedron",
    &[
        nsi::points!("P", &positions),
        nsi::unsigneds!("P.indices", &face_index),
        // 5 vertices per each face.
        nsi::unsigneds!("nvertices", &[5; 12]),
        // Render this as a subdivison surface.
        nsi::string!("subdivision.scheme",
            "catmull-clark"
        ),
        // Crease each of our 30 edges a bit.
        nsi::unsigneds!("subdivision.creasevertices",
            &face_index
        ),
        nsi::floats!(
            "subdivision.creasesharpness",
            &[10.; 30]
        ),
    ],
);

Also check out my Diffusion Limited Aggregation play-thingy for more example code (demonstrates render settings, sending OBJ meshes to the renderer via instancing, particle rendering, OSL shaders, environment (lights) and dumping a scene description to disk).

PRs are most welcome!

Dependencies

This crate depends on nsi-sys which in term requires a renderer that implements the ɴsɪ API. Currently the only renderer that does is 3Delight which, though commercial, has been and is free for personal use since over twenty years.

Note: The free version of 3Delight will render with up to 12 cores on your machine. For crazier projects you can use their cheap cloud rendering service that gives you access to unlimited CPU cores. When you register you get 1,000 cloud minutes for free which ain’t too shabby.

That being said – I hope this crate serves as inspiration for other people writing renderers, particularly in Rust, to adopt this API for scene description.

Prerequisites

Before you start it is suggested that you download a 3Delight package for your platform & install it (supported: Linux, macOS, Windows). This will set the $DELIGHT environment variable that the build script is looking for to find headers and the library to link against.

It will also install 3Delight Display which you can render to, progressively, as an alternative to writing images to disk. When working with this crate this is quite handy.

Features

The 3Delight dynamic library (lib3delight) can either be linked to during build or loaded at runtime. By default the lib is loaded at runtime. This has several advantages:

  1. If you ship your application or library you can ship it without the library. It can still run and will print an informative error if the library cannot be loaded.
  2. A user can install an updated version of the renderer and stuff will ‘just work’.
  • Dynamicall link against lib3delight.
    • lib3delight becomes a depdency. If it cannot't be found your lib/app will not load/start.
    • The feature is called link_lib3delight.
  • Download lib3delight during build.
    • lib3delight is downloaded during build. Note that this may be an outdated version. This feature mainly exists for CI purposes.
    • The feature is called download_lib3delight.

Getting Pixels

3Delight still uses the old RenderMan display driver API if you want to stream pixels directly to Rust, in-memory. There is a low-level wrapper for this API and a minimal Rust example display driver I cobbled together to get you started.

Documentation

Docs for the C, C++, Lua & Python bindings as well as an introduction and deep dive into the API can be found here.

Crate documentation can’t be built automatically for docs.rs yet (see above) but you can get local docs the usual way:

> cargo doc --open

Getting Help

I hang out on the 3Delight Discord server (I have the same user name as on GitHub). Look for me in the #3delight-lobby channel.

There is also a 3Delight Slack which has a dedicated, invitation only channel about ɴsɪ. If you have more advanced questions or want to add support for the ɴsɪ API/export to ɴsɪ to your renderer/DCC app/whatever ping me and I get you an invite.

Dependencies

~0.5–2.8MB
~61K SLoC