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

Improvements to heighttonormal node #2165

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion documents/Specification/MaterialX.Specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -1776,7 +1776,7 @@ Convolution nodes have one input named "in", and apply a defined convolution fun

<a id="node-heighttonormal"> </a>

* **`heighttonormal`**: convert a scalar height map to a normal map of type vector3.
* **`heighttonormal`**: convert a scalar height map to a tangent-space normal map of type vector3. The output normal map is encoded with all channels in the [0-1] range, enabling its storage in unsigned image formats.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we be explicit here about what each component of the output tangent-space vector3 correspond to?

ie. is it (normal, tangent, bitangent) (N,T,B) or (T,B,N) or something else etc.... the code is already making an explicit choice here - would be good to have the language in the spec reflect that choice.

I believe Ole Gulbrandsen was asking for this language to be explicit somewhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a great suggestion, @ld-kerley, and feel free to propose this improvement in a new issue or PR!

Our implementations all use (T, B, N) as the output order, and it sounds wise to state this in our specification.

* `in` (float): the input value or nodename
* `scale` (float): the scale of normal map deflections relative to the gradient of the height map. Default is 1.0.

Expand Down
7 changes: 5 additions & 2 deletions libraries/stdlib/genosl/mx_heighttonormal_vector3.osl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
void mx_heighttonormal_vector3(float in, float scale, output vector result)
{
point htP = P + normalize(N) * in * scale;
result = normalize(calculatenormal(htP));
float dx = -Dx(in);
float dy = Dy(in);
float dz = max(scale, 1.0E-05) * sqrt(max(1.0 - dx*dx - dy*dy, 1.0E-05));
vector dir = normalize(vector(dx, dy, dz));
result = dir * vector(0.5) + vector(0.5);
}
2 changes: 1 addition & 1 deletion resources/Materials/TestSuite/_options.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<input name="extraLibraryPaths" type="string" value="" />

<!-- List of document paths for render tests -->
<input name="renderTestPaths" type="string" value="resources/Materials/Examples/StandardSurface,resources/Materials/TestSuite/stdlib/color_management,resources/Materials/TestSuite/stdlib/procedural,resources/Materials/TestSuite/pbrlib/surfaceshader,resources/Materials/TestSuite/nprlib" />
<input name="renderTestPaths" type="string" value="resources/Materials/Examples/StandardSurface,resources/Materials/TestSuite/stdlib/convolution,resources/Materials/TestSuite/stdlib/color_management,resources/Materials/TestSuite/stdlib/procedural,resources/Materials/TestSuite/pbrlib/surfaceshader,resources/Materials/TestSuite/nprlib" />

<!-- Enable reference quality rendering.
This option enables higher sample counts and supersampling in render tests,
Expand Down
14 changes: 7 additions & 7 deletions resources/Materials/TestSuite/stdlib/convolution/blur.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<input name="size" type="float" value="0.5" />
<input name="filtertype" type="string" value="gaussian" />
</blur>
<output name="blur_color3_out" type="color3" nodename="blur_color3" />
<output name="out" type="color3" nodename="blur_color3" />
</nodegraph>
<nodegraph name="blur_color4">
<tiledimage name="tiledimage1" type="color4">
Expand All @@ -23,7 +23,7 @@
<input name="size" type="float" value="0.5" />
<input name="filtertype" type="string" value="gaussian" />
</blur>
<output name="blur_color4_out" type="color4" nodename="blur_color4" />
<output name="out" type="color4" nodename="blur_color4" />
</nodegraph>
<nodegraph name="blur_float">
<image name="image1" type="float">
Expand All @@ -34,7 +34,7 @@
<input name="size" type="float" value="0.5" />
<input name="filtertype" type="string" value="box" />
</blur>
<output name="blur_float_out" type="float" nodename="blur_float" />
<output name="out" type="float" nodename="blur_float" />
</nodegraph>
<nodegraph name="blur_vector2">
<tiledimage name="tiledimage1" type="vector2">
Expand All @@ -45,7 +45,7 @@
<input name="size" type="float" value="0.5" />
<input name="filtertype" type="string" value="box" />
</blur>
<output name="blur_vector2_out" type="vector2" nodename="blur_vector2" />
<output name="out" type="vector2" nodename="blur_vector2" />
</nodegraph>
<nodegraph name="blur_vector3">
<tiledimage name="tiledimage1" type="vector3">
Expand All @@ -56,7 +56,7 @@
<input name="size" type="float" value="0.5" />
<input name="filtertype" type="string" value="box" />
</blur>
<output name="blur_vector3_out" type="vector3" nodename="blur_vector3" />
<output name="out" type="vector3" nodename="blur_vector3" />
</nodegraph>
<nodegraph name="blur_vector4">
<tiledimage name="tiledimage1" type="vector4">
Expand All @@ -67,7 +67,7 @@
<input name="size" type="float" value="0.5" />
<input name="filtertype" type="string" value="box" />
</blur>
<output name="blur_vector4_out" type="vector4" nodename="blur_vector4" />
<output name="out" type="vector4" nodename="blur_vector4" />
</nodegraph>
<nodegraph name="blur_cellnoise">
<texcoord name="texcoord1" type="vector2" />
Expand All @@ -83,6 +83,6 @@
<input name="size" type="float" value="0.5" />
<input name="filtertype" type="string" value="gaussian" />
</blur>
<output name="blur_cellnoise_out" type="float" nodename="blur_cellnoise" />
<output name="out" type="float" nodename="blur_cellnoise" />
</nodegraph>
</materialx>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<materialx version="1.39">
<nodegraph name="height_to_normal">
<nodegraph name="heighttonormal">
<input name="file" type="filename" uniform="true" value="resources/Images/plain_heightmap.png" />
<tiledimage name="tiledimage" type="float">
<input name="file" type="filename" uniform="true" interfacename="file" />
Expand All @@ -27,8 +27,8 @@
<UsdPreviewSurface name="UsdPreviewSurface" type="surfaceshader">
<input name="normal" type="vector3" nodename="bias" />
</UsdPreviewSurface>
<output name="height_to_normal_out" type="vector3" nodename="heighttonormal" />
<output name="standard_surface_out" type="surfaceshader" nodename="standard_surface" />
<output name="usd_preview_surface_out" type="surfaceshader" nodename="UsdPreviewSurface" />
<output name="vector3_out" type="vector3" nodename="heighttonormal" />
<output name="surface1_out" type="surfaceshader" nodename="standard_surface" />
<output name="surface2_out" type="surfaceshader" nodename="UsdPreviewSurface" />
</nodegraph>
</materialx>