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

Add a 2d checkerboard pattern node #1328

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
11 changes: 11 additions & 0 deletions libraries/stdlib/stdlib_defs.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,17 @@
<output name="out" type="float" />
</nodedef>

<!--
Node: <checkerboard>
A 2D checkerboard pattern.
-->
<nodedef name="ND_checkerboard_float" node="checkerboard" nodegroup="procedural2d">
Copy link
Member

Choose a reason for hiding this comment

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

@crydalch The design of this node seems very reasonable to me, though it seems worthwhile to consider the idea of returning a color3 value instead of a float, with the two colors of the checkerboard specified as color1 and color2 inputs (defaulting to white and black).

I don't have a strong opinion on which design is better for MaterialX, but for reference here are a few examples of checkerboard nodes that use the color1/color2 approach:

https://docs.unity3d.com/Packages/[email protected]/manual/Checkerboard-Node.html
https://learn.foundry.com/mari/Content/reference_guide/nodes/Checkerboard.html
https://help.autodesk.com/view/ARNOL/ENU/?guid=arnold_user_guide_ac_texture_shaders_ac_texture_checkerboard_html

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to cover a reasonable "maximum" possible flexibility (which seems to be Arnold) and anything that supports less can restrict what inputs are modifiable / exposed. e.g. frequency in u and v allows for "stripe" textures to be created. A "customized" version of this would sync u and v values. Does this sound reasonable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like this idea @jstone-lucasfilm

An early version of the node did have color inputs/outputs, but I don't recall why I went away from that... but regardless, I'll make that change. Thank you for the suggestion and references.

<input name="freq" type="vector2" uiname="Frequency" value="8, 8" doc="The frequency of checkers, with higher values producing smaller squares. Default is (8, 8)." />
<input name="offset" type="vector2" uiname="Offset" value="0, 0" doc="Shift the pattern in 2d space. Default is (0, 0)." />
<input name="texcoord" type="vector2" uiname="Texture Coordinates" defaultgeomprop="UV0" doc="The input 2d space. Default is the first texture coordinates." />
<output name="out" type="float" />
</nodedef>

<!-- ======================================================================== -->
<!-- Geometric nodes -->
<!-- ======================================================================== -->
Expand Down
44 changes: 44 additions & 0 deletions libraries/stdlib/stdlib_ng.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,50 @@
<output name="out" type="float" nodename="N_range" />
</nodegraph>

<!--
<checkerboard>
A 2D checkerboard pattern.
-->

<nodegraph name="NG_checkerboard_float" nodedef="ND_checkerboard_float">
<separate2 name="N_mtlxseparate2" type="multioutput">
<input name="in" type="vector2" nodename="N_mtlxplace2d1" />
</separate2>
<modulo name="N_mtlxmodulo1" type="float">
<input name="in1" type="float" nodename="N_mtlxseparate2" output="outx" />
<input name="in2" type="float" value="2" />
</modulo>
<multiply name="N_mult" type="vector2">
<input name="in1" type="vector2" interfacename="texcoord" />
<input name="in2" type="vector2" interfacename="freq" />
</multiply>
<modulo name="N_mtlxmodulo2" type="float">
<input name="in1" type="float" nodename="N_mtlxseparate2" output="outy" />
<input name="in2" type="float" value="2" />
</modulo>
<floor name="N_mtlxfloor2" type="float">
<input name="in" type="float" nodename="N_mtlxmodulo1" />
</floor>
<floor name="N_mtlxfloor3" type="float">
<input name="in" type="float" nodename="N_mtlxmodulo2" />
</floor>
<add name="N_mtlxadd2" type="float">
<input name="in1" type="float" nodename="N_mtlxfloor2" />
<input name="in2" type="float" nodename="N_mtlxfloor3" />
</add>
<ifequal name="N_mtlxifequal2" type="float">
<input name="value1" type="float" nodename="N_mtlxadd2" />
<input name="value2" type="float" value="1" />
<input name="in1" type="float" value="1" />
<input name="in2" type="float" value="0" />
</ifequal>
<place2d name="N_mtlxplace2d1" type="vector2">
<input name="texcoord" type="vector2" nodename="N_mult" />
<input name="offset" type="vector2" interfacename="offset" />
</place2d>
<output name="out" type="float" nodename="N_mtlxifequal2" />
</nodegraph>

<!-- ======================================================================== -->
<!-- Geometric nodes -->
<!-- ======================================================================== -->
Expand Down