MaterialX icon indicating copy to clipboard operation
MaterialX copied to clipboard

Add in application variable tracking for code generation

Open kwokcb opened this issue 1 year ago • 1 comments

Add the ability to track when applicable variables are handled during code generation.

  • Add in single new base method for calling each node implementations createVariables(). ShaderGenerator::createVariables().
  • Add in a callback on GenContext to allow custom tracking of application variables:: GenContext::setApplicationVariableHandler(). The callback is performed when ShaderGenerator::createVariables() is invoked.
  • For general filtering workflows including when callbacks are invoked add in geometric classification on ShaderNode.
  • Note: As unique path is also available this can be used to back-reference to the original document or compare against input / output blocks on a Shader.

Example

  • File with 3 geompropvalue nodes. One is connected to an upstream constant.:
<?xml version="1.0"?>
<materialx version="1.38">
  <geompropvalue name="geompropvalue" type="color3" > 
    <input name="geomprop" type="string" uniform="true" nodename="constant" />
  </geompropvalue>
  <geompropvalue name="geompropvalue1" type="color3" >
    <input name="geomprop" type="string" uniform="true" value="primvar_one" />
  </geompropvalue>
  <geompropvalue name="geompropvalue2" type="color3" >
    <input name="geomprop" type="string" uniform="true" value="primvar_two" />
  </geompropvalue>
  <multiply name="multiply" type="color3" >
    <input name="in1" type="color3" nodename="geompropvalue" />
    <input name="in2" type="color3" nodename="geompropvalue1" />
  </multiply>
  <add name="add" type="color3"  >
    <input name="in1" type="color3" nodename="multiply" />
    <input name="in2" type="color3" nodename="geompropvalue2" />
  </add>
  <standard_surface name="standard_surface" type="surfaceshader" >
    <input name="base_color" type="color3" nodename="add" />
  </standard_surface>
  <constant name="constant" type="string" >
    <input name="value" type="string" uniform="true" value="upstream_primvar" />
  </constant>
  <surfacematerial name="surfacematerial" type="material" >
    <input name="surfaceshader" type="surfaceshader" nodename="standard_surface" />
  </surfacematerial>
</materialx>

Example output:

When emitting geometric node: geompropvalue2
- geomprop: primvar_two, path: geompropvalue2/geomprop
Emit geometric node: geompropvalue1
- geomprop: primvar_one, path: geompropvalue1/geomprop
Emit geometric node: geompropvalue
- geomprop: upstream_primvar, path:  constant/value

kwokcb avatar Jul 29 '22 17:07 kwokcb

@ix-dcourtois , @niklasharrysson PR for review. Thanks. Note: @jstone-lucasfilm this is a proposed addition as a result of Slack discussion on being able to track application inputs used such as primvar names on geompropvalue. In this case without have to sub-class or override any methods on code generation classes.

kwokcb avatar Jul 29 '22 17:07 kwokcb

Hey @niklasharrysson , Thanks for looking this over -- there was no rush. @ix-dcourtois, let me know if you have anything to add to this as you looked at this code earlier and believe the geometry category was useful even though you have a derived generator approach. Thanks.

kwokcb avatar Aug 16 '22 23:08 kwokcb

Hi @kwokcb sorry I just got back from my holidays! I've tested the PR here, and it works well, nothing to add! (and yes, the additional GEOMETRIC classification makes things a lot more convenient/clear :))

ix-dcourtois avatar Aug 17 '22 07:08 ix-dcourtois

Hi @ix-dcourtois. Again no problems. I just wanted to do a sanity check. ( @jstone-lucasfilm, I leave the final review up to you :). ) Thanks.

kwokcb avatar Aug 17 '22 12:08 kwokcb