Possible problem with ShaderGen node classification
I think I'm hitting another ShaderGen issue. I have a contrived example simplified from a real production example.
<?xml version="1.0"?>
<materialx version="1.38" colorspace="lin_rec709">
<nodedef name="ND_myNode" node="myNode">
<input name="in" type="float" value="0.5"/>
<output name="out_float" type="float"/>
<output name="out_surf" type="surfaceshader"/>
</nodedef>
<nodegraph name="NG_myNode" nodedef="ND_myNode">
<add name="intAdd" type="float">
<input name="in1" type="float" interfacename="in"/>
</add>
<oren_nayar_diffuse_bsdf name="intOrenNayar" type="BSDF">
<input name="weight" type="float" interfacename="in" />
<input name="color" type="color3" value="0.7,0.2,0.2" />
</oren_nayar_diffuse_bsdf>
<surface name="intSrf" type="surfaceshader">
<input name="bsdf" type="BSDF" nodename="intOrenNayar" />
</surface>
<output name="out_float" type="float" nodename="intAdd"/>
<output name="out_surf" type="surfaceshader" nodename="intSrf"/>
</nodegraph>
<myNode name="myNode" type="multioutput"/>
<surfacematerial name="Mtl" type="material">
<input name="surfaceshader" type="surfaceshader" nodename="myNode" output="out_surf" />
</surfacematerial>
</materialx>
I have a custom node that has multiple outputs, one of which is of type surfaceshader. When loading this in to MaterialXViewer it generates errors for both GLSL and MSL backends.
Error in compiling fragment shader:
ERROR: 0:221: '' : syntax error: incorrect preprocessor directive
ERROR: 0:221: '' : syntax error: unexpected tokens following #if preprocessor directive - expected a newline
ERROR: 0:266: '' : syntax error: incorrect preprocessor directive
ERROR: 0:266: '' : syntax error: unexpected tokens following #if preprocessor directive - expected a newline
Example file attached : classification_bug.mtlx.zip
I poked around a little to try and understand what's going on, and the shader error is related to a missing compiler define (DIRECTIONAL_ALBEDO_METHOD) being emitted here.
I think the real source of the issue is that the requiresLighting() function here returns false, when it should return true, and I think this is because the classification system in the shader gen either isn't properly accounting for nodes with multiple outputs, or perhaps isn't able to correctly introspect the nodes inside the nodegraph.
Before poking around too hard (and maybe breaking something), I was wondering if anyone else might have some insight, or information about how the system is intended to work. The only references to classification I could find in the documentation were related to the standard library nodes, and how they are organized.
Every atomic and compound node (graph) in a shading network can have 1 or more classifications. Atomic ones include classifying things like closures / shaders, texture etc.
After building the shading network, I believe way it's supposed to work is classifications get added to the graph based on all output sockets which are connected on a given ShaderGraph. In this case there should be 1 socket added and the classification list should contain the surfaceshader equivalent classification SURFACE. From what I see I think this should be done in ShaderGraph::finalize().
Hope this helps @niklasharrysson has more knowledge than I.