Add an OSPRay material via Python


Is there a way to add an OSPRay material via Python? I’m working on a pvpython script for an automated workflow but the materials aren’t in the default list. I found some online that I like but I’m expecting multiple users to use the script from a variety of locations so being able to add materials through Python would really simplify things. FYI: I’m hoping to not have to create a .json file and then read that in.


1 Like


i’d be very interested in this capability as well. Please let me know if you figure out a workflow for this.

You can load a material file via Python commands like:

materialLibrary1 = GetMaterialLibrary()
materialLibrary1.LoadMaterials = <file>

That’s the best I have so far so my solution will likely be write out a json file with the two materials I need and then load that in. The Python Trace feature should capture everything else you need to properly set path tracer materials. If I figure out something better I’ll let you know…

1 Like

At the ParaView level, there isn’t an API to programmatically add new materials yet other than by loading new ones from file. There is at the VTK level though, so it shouldn’t be very difficult to punch a hole down and do it. The following is a sketch for how we can go about it.

This c++ test at the VTK level demonstrates creating new materials from scratch by making calls on the VTK level vtkOSPRayMaterialLibrary class.

This class at the ParaView implementation level is a handle for the underlying VTK level instance. It adds the feature of loading the default materials at startup time. It does not expose any way to access the contained VTK level instance - yet. Alternatively we could add a passthrough API to construct new materials here. This is the primary thing that needs to be done.

This class at the ParaView proxy level manages the implementation level handle, and makes it do the right thing in client/server sessions. Most likely nothing needs to be done with this other than expose the implementation level’s extended API in the rendering.xml file. We do have to at least check and make sure that whatever we do does work correctly in client server configurations though, most likely by calling Synchronize() here.

Also I might add that adding this feature would be a good start on the concept of adding a GUI to let you define new materials within ParaView, although I really think that is best left to a dedicated mini application.


I have a prototype that let the user create materials interactively with a dock widget and use ParaView proxy so python can be used.
I didn’t have time to finish it though because it was more difficult to handle textures properly and I was running out of time/funding.

Note that it is already possible in ParaView 5.8 to create OBJMaterial or Principled materials interactively (or with python) but some properties are not exposed yet.

Principled is probably the most generic and powerful material so I recommend using it.
The exposed properties of Principled in ParaView are baseColor, metallic, diffuse, roughness, specular, baseNormal, opacity.
For example, the following image has been produced using different Principled materials, using only ParaView GUI, without json material library:

1 Like

Hi Michael,

Where can we find the Principled material editor in 5.8? I can’t find it anywhere.

Hi Vincent,
Sorry I didn’t mention it.

Everything can be configured under the Lighting group of the representation properties.
If you select Gouraud, the material is translated to OBJMaterial.
If you select PBR, it is Principled.
The baseColor uses the current Solid color (or the current color map), the opacity is configured under the Styling property group.


If you want to use a texture for roughness or metalness, you have to set the Material Texture in ORM format (roughness is the green channel, metalness is the blue channel)
This blog article on PBR/Principled materials is not focused on OSPRay but it might help:


@Michael the new GUI updates to allow direct interaction with OBJ and Principled materials is great. Especially for testing out textures, this is so much easier than making a ton of JSON files.

Is there a way to save out these materials created through the GUI by chance?

Not yet, sorry!

Ok I see! I already used PBR but I did not know it was actually an OSPRAY principled material in the background…

Is this method independent of OSPRay? So,does it use a GPU for rendering?

Yes, PBR is independent of OSPRay, it is an OpenGL implementation of the Principled material.

Thanks your reply.
This function looks like blender’s default material shader node( Principled BSDF )similar,but Paraview does not support directly read has produced good Disney principled material, for example .exr format file, could you tell me how can I add materials to the model in Paraview, or are there tutorials on this?

You will be able to open .hdr files in ParaView 5.9
There is no plan to support .exr files yet.

That’s great. Thank you very much for the work you’ve done.