@@ -274,6 +274,38 @@ ShaderPtr OslShaderGenerator::createShader(const string& name, ElementPtr elemen
274274 ShaderGraphPtr graph = ShaderGraph::create (nullptr , name, element, context);
275275 ShaderPtr shader = std::make_shared<Shader>(name, graph);
276276
277+ // Check if there are inputs with default geomprops assigned. In order to bind the
278+ // corresponding data to these inputs we insert geomprop nodes in the graph.
279+ bool geomNodeAdded = false ;
280+ for (ShaderGraphInputSocket* socket : graph->getInputSockets ())
281+ {
282+ if (!socket->getGeomProp ().empty ())
283+ {
284+ ConstDocumentPtr doc = element->getDocument ();
285+ GeomPropDefPtr geomprop = doc->getGeomPropDef (socket->getGeomProp ());
286+ if (geomprop)
287+ {
288+ // A default geomprop was assigned to this graph input.
289+ // For all internal connections to this input, break the connection
290+ // and assign a geomprop node that generates this data.
291+ // Note: If a geomprop node exists already it is reused,
292+ // so only a single node per geometry type is created.
293+ ShaderInputVec connections = socket->getConnections ();
294+ for (auto connection : connections)
295+ {
296+ connection->breakConnection ();
297+ graph->addDefaultGeomNode (connection, *geomprop, context);
298+ geomNodeAdded = true ;
299+ }
300+ }
301+ }
302+ }
303+ // If nodes were added we need to re-sort the nodes in topological order.
304+ if (geomNodeAdded)
305+ {
306+ graph->topologicalSort ();
307+ }
308+
277309 // Create our stage.
278310 ShaderStagePtr stage = createStage (Stage::PIXEL, *shader);
279311 stage->createUniformBlock (OSL::UNIFORMS);
0 commit comments