On a GitHub Actions windows-latest runner, with Rhino installed by mcneel/setup-rhino3d and tests run through Rhino.Testing, this returns null on 8.36.26296.17001 and 9.0.26300.9401:
using var doc = RhinoDoc.CreateHeadless(null);
var material = new Rhino.DocObjects.Material { Name = "x" };
material.ToPhysicallyBased();
var rendered = RenderMaterial.FromMaterial(material, doc); // null
A plain material works, and the same test passes on my Windows PC, where Rhino 8 has been installed and in regular use for a while. NewContentFromTypeId(ContentUuids.PhysicallyBasedMaterialType, doc) also returns null, but this returns a PhysicallyBasedMaterial:
var plain = RenderMaterial.CreateBasicMaterial(new Rhino.DocObjects.Material(), doc);
var converted = plain.ConvertToPhysicallyBased(RenderTexture.TextureGeneration.Skip);
Does a fresh install lack something that first run sets up? Is converting the supported route in a headless doc? Possibly related to RH-81973, from Physically Based Material in Headless doc, where NewContentFromTypeId was suggested.
The Physically Based material type is registered by Rhino’s Commands plug-in, not by the core renderer. Until that plug-in has loaded, RenderMaterial.FromMaterial and NewContentFromTypeId(ContentUuids.PhysicallyBasedMaterialType, doc) have nothing to create a PBR material from, so they return null. A plain material doesn’t need that plug-in, which is why it works.
On a machine where Rhino has been run interactively, the plug-in is set to load at startup, so headless runs pick it up. A fresh install hasn’t recorded that yet, so a headless host like Rhino.Testing may never load it.
You can load it yourself in your test setup, before creating any materials:
About the conversion route: ConvertToPhysicallyBased returns a Rhino.DocObjects.PhysicallyBasedMaterial, which is a PBR view of a plain Material. It isn’t a RenderMaterial. That’s fine if you only need the PBR values, but it isn’t the same as getting a Physically Based render material from FromMaterial.
That was it, thanks Dale. Loading the Commands plug-in in our test setup fixed it on a fresh install, in both 8.36 and 9.0, and we were able to remove our plain-material fallback. Thanks for clarifying the conversion route too.