Skip to content

Commit

Permalink
[HdSt] There is a mismatch between the default wrapS/wrapT values in …
Browse files Browse the repository at this point in the history
…MaterialX vs USD.

Set these default MaterialX texture values to match MaterialX when unauthored.

Fixes #1793

(Internal change: 2238296)
  • Loading branch information
klucknav authored and pixar-oss committed Jun 25, 2022
1 parent 976f770 commit d637490
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 14 deletions.
26 changes: 16 additions & 10 deletions pxr/imaging/hdSt/materialXFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,10 @@ HdSt_GenMaterialXShader(
static VtValue
_GetHdFilterValue(std::string const& mxInputValue)
{
if(mxInputValue == "closest") {
if (mxInputValue == "closest") {
return VtValue(HdStTextureTokens->nearestMipmapNearest);
}
// linear/cubic
return VtValue(HdStTextureTokens->linearMipmapLinear);
}

Expand All @@ -198,6 +199,7 @@ _GetHdSamplerValue(std::string const& mxInputValue)
if (mxInputValue == "mirror") {
return VtValue(HdStTextureTokens->mirror);
}
// periodic
return VtValue(HdStTextureTokens->repeat);
}

Expand Down Expand Up @@ -227,16 +229,19 @@ _GetHdTextureParameters(
(*hdTextureParams)[HdStTextureTokens->wrapT] =
_GetHdSamplerValue(mxInputValue);
}
}

// Properties specific to <tiledimage> nodes:
else if (mxInputName == "uvtiling" || mxInputName == "uvoffset" ||
mxInputName == "realworldimagesize" ||
mxInputName == "realworldtilesize") {
(*hdTextureParams)[HdStTextureTokens->wrapS] =
VtValue(HdStTextureTokens->repeat);
(*hdTextureParams)[HdStTextureTokens->wrapT] =
VtValue(HdStTextureTokens->repeat);
}
static void
_AddDefaultMtlxTextureValues(
std::map<TfToken, VtValue>* hdTextureParams)
{
// MaterialX uses repeat/periodic for the default wrap values, without
// this the texture will use the Hydra default useMetadata.
// Note that these will get overwritten by any authored values
(*hdTextureParams)[HdStTextureTokens->wrapS] =
VtValue(HdStTextureTokens->repeat);
(*hdTextureParams)[HdStTextureTokens->wrapT] =
VtValue(HdStTextureTokens->repeat);
}

// Find the HdNode and its corresponding NodePath in the given HdNetwork
Expand Down Expand Up @@ -394,6 +399,7 @@ _UpdateTextureNodes(

// Gather the Hydra Texture Parameters
std::map<TfToken, VtValue> hdParameters;
_AddDefaultMtlxTextureValues(&hdParameters);
for (auto const& currParam : hdTextureNode.parameters) {

// Get the MaterialX Input Value string
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#usda 1.0
(
upAxis = "Z"
)

def "TestMaterial" (
references = @texturedSphere.usda@
)
{
rel material:binding = </MaterialX/Materials/DefaultValTest>
}


def Scope "MaterialX" (
references = [
@./textureTest.mtlx@</MaterialX>,
]
)
{
}

def Xform "lights"
{
def DomeLight "DomeLight"
{
asset inputs:texture:file = @./StinsonBeach.hdr@
float xformOp:rotateX:Zup = 90
uniform token[] xformOpOrder = ["xformOp:rotateX:Zup"]
}
def SphereLight "Light"
{
float inputs:radius = 5
float inputs:intensity = 5
Vec3f xformOp:translate = (0, -20, 0)
uniform token[] xformOpOrder = ["xformOp:translate"]
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,41 @@
<?xml version="1.0"?>
<materialx version="1.38">
<nodegraph name="NG_imagetex">
<nodegraph name="NG_imagetex1">
<texcoord name="texcoord0" type="vector2" />
<image name="image0_color" type="color3" nodedef="ND_image_color3">
<input name="file" type="filename" uniform="true" value="./grid.png" />
<input name="texcoord" type="vector2" nodename="texcoord0" />
</image>
<output name="out_color_0" type="color3" nodename="image0_color" />
</nodegraph>
<standard_surface name="SR_test" type="surfaceshader">
<standard_surface name="SR_test1" type="surfaceshader">
<input name="base" type="float" value="1" />
<input name="base_color" type="color3" nodegraph="NG_imagetex" output="out_color_0" />
<input name="base_color" type="color3" nodegraph="NG_imagetex1" output="out_color_0" />
<input name="metalness" type="float" value="0" />
</standard_surface>
<surfacematerial name="TextureTest" type="material">
<input name="surfaceshader" type="surfaceshader" nodename="SR_test" />
<input name="surfaceshader" type="surfaceshader" nodename="SR_test1" />
</surfacematerial>

<nodegraph name="NG_imagetex2">
<texcoord name="texcoord0" type="vector2" />
<place2d name="place2d" type="vector2" >
<input name="texcoord" type="vector2" nodename="texcoord0" />
<input name="scale" type="vector2" value="0.1, 0.1" />
</place2d>
<image name="image0_color" type="color3" nodedef="ND_image_color3">
<input name="file" type="filename" uniform="true" value="./grid.png" />
<input name="texcoord" type="vector2" nodename="place2d" />
<input name="uaddressmode" type="string" value="mirror"/>
</image>
<output name="out_color_0" type="color3" nodename="image0_color" />
</nodegraph>
<standard_surface name="SR_test2" type="surfaceshader">
<input name="base" type="float" value="1" />
<input name="base_color" type="color3" nodegraph="NG_imagetex2" output="out_color_0" />
<input name="metalness" type="float" value="0" />
</standard_surface>
<surfacematerial name="DefaultValTest" type="material">
<input name="surfaceshader" type="surfaceshader" nodename="SR_test2" />
</surfacematerial>
</materialx>

0 comments on commit d637490

Please sign in to comment.