vkoskiv / c-ray

c-ray is a small, simple path tracer written in C
MIT License
805 stars 43 forks source link

Add an NSI C binding #103

Open virtualritz opened 3 years ago

virtualritz commented 3 years ago

NSI is a replacement for RenderMan Ri/RIB that was developed by Illumination Research for their 3Delight renderer.

3Delight used to be RenderMan compliant from 1999–2019.

The NSI API is completely open and very minimal. It's a single header.

An NSI parser will be made OSS soon too. But it's fine to just have the C-API at the beginning. It's just 11 functions.

Having the C-API implemented for c-ray will instantly allow you to hook up the renderer to these apps:

All of the NSI plug-ins for these apps are OSS and hosted here: https://gitlab.com/3Delight

vkoskiv commented 3 years ago

Very cool! Now I know what I'm doing this weekend πŸ˜„

virtualritz commented 3 years ago

You will be the first 'other' renderer to add an NSI API. πŸ˜„ I sent you an invite for the 3Delight slack per Twitter PM.

virtualritz commented 3 years ago

So the caveats.

Scene Edits

The NSI API supports scene edits via NSIRenderControl("sync",...). To support this, too, you will need to add this bit that I saw on your todo list

But this is not mandatory. The DCC plug-ins have support for IPR viewport rendering which won't work w/o scene edits but that feature can probably be isolated with some #ifdefs to make everything work if this feature is not implemented.

Shaders

NSI's shading system is built around the idea that the renderer supports OpenShadingLanguage (OSL) to describe shader graphs. Integrating OSL is no weekend project.

Again, that being said: the API makes no assumptions in that regard. It's just that shaders are assumed to exist outside the renderer.

Workarounds:

  1. 3Delight ships with a set of artist friendly OSL shaders and these are well integrated with the DCC plug-ins. The most used one is a Disney Principled based Uber shader called dlPrincipled. They also recently added an implementation of Autodesk Standard Surface – dlStandard. If you map what you have in the renderer to these two shaders and intercept dlTexture nodes plugged directly into their slots you will have something that is 90% useful w/o adding OSL support. A bit of a hack but should be good enough. Same for lights which are just geometry with a surface shader emitting, in OSL. It's based on reality – it doesn't have a concept of a light as something special.

  2. A bit more work: in your version/fork of the DCC plugins you can expose shader nodes only mirroring what your renderer supports.

Subdivision Surface Support

NSI also supports subdivision surfaces via extra attributes on the mesh node.

Workaround: ignore these attributes and just render the control cage as a polygon mesh.

If you wanted to add support for subdivs, Pixar's OpenSubdiv is a painless dependency (as in: as painless as it gets in C/C++ land). It uses CMake, can be built with the (default) CPU backend only and then has no further dependencies. Add it as a git submodule and a bit of CMake and you should be good to go.

Being C++ It uses some template classes that require a specialization, each, to be usable.

You can grab specializations that expose a C-only API from an OpenSubdiv Rust wrapper.

In general, if you are interested in using C++ dependencies but with a C-API, watch this project – C++--.

odil24 commented 3 years ago

Hmm. So whith this can we integrate to Blender also?

virtualritz commented 3 years ago

There is no NSI Blender plug-in yet. 3Delight have said they want to do one, at some point.

That said, no one stops you from making a plugin yourself. A good start may be the source code of the Appleseed or Cycles integration as they will cover the OSL part.

NSI was developed with both VFX production demands for a scene description and plugin developers mind.

This is not easy as these two groups sometimes have orthogonal requirements.

RenderMan RIB/the RenderMan Interface was the industry standard for many years but it can't serve this purpose any more, with the demands of today's productions. USD is both an asset container and a scene description. But it is not there yet and also didn't concern itself with the requirements of plugin developers.

odil24 commented 3 years ago

Thanks for info.

Regards, Odilkhan Yakubov.

Ρ‡Ρ‚, 15 Апр 2021, 15:42 Moritz MΕ“ller @.***>:

There is no NSI Blender plug-in yet. 3Delight have said they want to do one, at some point.

That said, no one stops you from making a plugin yourself. A good start may be the source code of the Appleseed or Cycles integration as they will cover the OSL part.

NSI was developed with both VFX production demands for a scene description and plugin developers mind.

β€” You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/vkoskiv/c-ray/issues/103#issuecomment-820324792, or unsubscribe https://github.com/notifications/unsubscribe-auth/APKRYHBSEMIGOY2YBPEQFCTTI27JZANCNFSM4252RMLQ .