Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAYA-111898 - MaterialX UV0 defaultgeomprop to st primvar #1533

Merged
merged 4 commits into from
Jul 5, 2021

Conversation

JGamache-autodesk
Copy link
Collaborator

MaterialX has a lot of node definitions that use a UV0 defaultgeomprop to automatically connect to UV stream at index zero. Since USD is name based, and we specified a canonical naming scheme for UV sets in PR #1528, we can insert a geompropvalue primvar reader that will allow that shader to work.
MaterialX can also specify a UV stream by index using a "texcoord" geometry node. For these, we substitute a geompropvalue primvar reader that refers to the primvar name we assigned for that index: UV2 -> st2

MaterialX has a lot of node definitions that use a UV0 defaultgeomprop to automatically connect to UV stream at index zero. Since USD is name based, and we specified a canonical naming scheme for UV sets in PR #1528, we can insert a geompropvalue primvar reader that will allow that shader to work.
MaterialX can also specify a UV stream by index using a "texcoord" geometry node. For these, we substitute a geompropvalue primvar reader that refers to the primvar name we assigned for that index: UV2 -> st2
(ND_texcoord_vector3)
// Color at vertices also affect topo, but we have not locked a naming scheme to go from index
// based to name based as we did for UV sets. We will mark them as topo-affecting, but there is
// nothing we can do to link them correctly to a primvar without specifying a naming scheme.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also specify a primvar naming scheme for these as well?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any scheme existing out there already?

{
uniform token info:id = "ND_noise2d_float"
float inputs:amplitude = 0.5
float2 inputs:texcoord.connect = </pCube1/Looks/standardSurface2SG/MayaNG_standardSurface2SG/UV1.outputs:out>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicitly connected to a texcoord reader for UV at index 1.

def Shader "UV1"
{
uniform token info:id = "ND_texcoord_vector2"
int inputs:index = 1
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be replaced with geompropvalue for "st1".

uniform token info:id = "ND_ramptb_color3"
color3f inputs:valuet = (0.0, 1.0, 0.5)
color3f inputs:valueb = (1.0, 0.5, 0.0)
color3f outputs:out
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unconnected texcoord input. Will be auto-connected to an auto-added ST_reader node that reads primvar "st".

asset inputs:file = @grid.png@
string inputs:uaddressmode = "periodic"
string inputs:vaddressmode = "periodic"
color4f outputs:out
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also has an unconnected texcoord reader that will auto-connect to the same ST_reader as the ramp1 node.

@@ -0,0 +1,107 @@
#usda 1.0
(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the "HDVP2_DEBUG_MATERIAL" TF_DEBUG flag is set, you will see the corrected MaterialX document printed in the output:

<?xml version="1.0"?>
<materialx version="1.38" xmlns:xi="http://www.w3.org/2001/XInclude">
  <standard_surface name="SR_USD_Mtlx_VP2_Material" type="surfaceshader">
    <input name="base_color" type="color3" output="base_color_out" nodegraph="NG_Maya" />
  </standard_surface>
  <surfacematerial name="USD_Mtlx_VP2_Material" type="material">
    <input name="surfaceshader" type="surfaceshader" nodename="SR_USD_Mtlx_VP2_Material" />
  </surfacematerial>
  <nodegraph name="NG_Maya">
    <mix name="N1" type="color3">
      <input name="bg" type="color3" nodename="N6" />
      <input name="fg" type="color3" nodename="N5" />
      <input name="mix" type="float" nodename="N2" />
    </mix>
    <swizzle name="N6" type="color3">
      <input name="channels" type="string" value="rgb" />
      <input name="in" type="color4" nodename="N7" />
    </swizzle>
    <image name="N7" type="color4">
      <input name="texcoord" type="vector2" defaultgeomprop="UV0" uiname="Texture Coordinates" nodename="ST_reader" />
    </image>
    <ramptb name="N5" type="color3">
      <input name="texcoord" type="vector2" defaultgeomprop="UV0" nodename="ST_reader" />
    </ramptb>
    <add name="N2" type="float">
      <input name="in1" type="float" nodename="N3" />
    </add>
    <noise2d name="N3" type="float">
      <input name="texcoord" type="vector2" nodename="N4" />
    </noise2d>
    <output name="base_color_out" type="color3" nodename="N1" />
    <geompropvalue name="ST_reader" type="vector2">
      <input name="geomprop" type="string" value="st" uniform="true" />
    </geompropvalue>
    <geompropvalue name="N4" type="vector2">
      <input name="geomprop" type="string" value="st1" uniform="true" />
    </geompropvalue>
  </nodegraph>
</materialx>

// Points and normals always are at the beginning of vertex requirements:
addPrimvar(HdTokens->points);
addPrimvar(HdTokens->normals);
// Then add required primvars *in order*:
Copy link
Collaborator Author

@JGamache-autodesk JGamache-autodesk Jun 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MaterialX unit test had st and st1 swapped 50% of the time. This makes sure the order stays correct.

@JGamache-autodesk JGamache-autodesk added the ready-for-merge Development process is finished, PR is ready for merge label Jul 5, 2021
(ND_texcoord_vector3)
// Color at vertices also affect topo, but we have not locked a naming scheme to go from index
// based to name based as we did for UV sets. We will mark them as topo-affecting, but there is
// nothing we can do to link them correctly to a primvar without specifying a naming scheme.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any scheme existing out there already?

@kxl-adsk kxl-adsk merged commit b98c683 into dev Jul 5, 2021
@kxl-adsk kxl-adsk deleted the t_gamaj/MAYA-111898/materialx_uv0_to_st branch July 5, 2021 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge Development process is finished, PR is ready for merge vp2renderdelegate Related to VP2RenderDelegate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants