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

Extend mix node to allow per channel mixing #1077

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
5 changes: 5 additions & 0 deletions libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,15 @@
<!-- <mix> -->
<implementation name="IM_mix_float_genglsl" nodedef="ND_mix_float" file="mx_mix.inline" target="genglsl" />
<implementation name="IM_mix_color3_genglsl" nodedef="ND_mix_color3" file="mx_mix.inline" target="genglsl" />
<implementation name="IM_mix_color3_color3_genglsl" nodedef="ND_mix_color3_color3" file="mx_mix.inline" target="genglsl" />
<implementation name="IM_mix_color4_genglsl" nodedef="ND_mix_color4" file="mx_mix.inline" target="genglsl" />
<implementation name="IM_mix_color4_color4_genglsl" nodedef="ND_mix_color4_color4" file="mx_mix.inline" target="genglsl" />
<implementation name="IM_mix_vector2_genglsl" nodedef="ND_mix_vector2" file="mx_mix.inline" target="genglsl" />
<implementation name="IM_mix_vector2_vector2_genglsl" nodedef="ND_mix_vector2_vector2" file="mx_mix.inline" target="genglsl" />
<implementation name="IM_mix_vector3_genglsl" nodedef="ND_mix_vector3" file="mx_mix.inline" target="genglsl" />
<implementation name="IM_mix_vector3_vector3_genglsl" nodedef="ND_mix_vector3_vector3" file="mx_mix.inline" target="genglsl" />
<implementation name="IM_mix_vector4_genglsl" nodedef="ND_mix_vector4" file="mx_mix.inline" target="genglsl" />
<implementation name="IM_mix_vector4_vector4_genglsl" nodedef="ND_mix_vector4_vector4" file="mx_mix.inline" target="genglsl" />
<implementation name="IM_mix_surfaceshader_genglsl" nodedef="ND_mix_surfaceshader" function="mx_mix_surfaceshader" file="mx_mix_surfaceshader.glsl" target="genglsl" />

<!-- ======================================================================== -->
Expand Down
5 changes: 5 additions & 0 deletions libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,15 @@
<!-- <mix> -->
<implementation name="IM_mix_float_genmdl" nodedef="ND_mix_float" sourcecode="math::lerp({{bg}}, {{fg}}, {{mix}})" target="genmdl" />
<implementation name="IM_mix_color3_genmdl" nodedef="ND_mix_color3" sourcecode="math::lerp({{bg}}, {{fg}}, {{mix}})" target="genmdl" />
<implementation name="IM_mix_color3_color3_genmdl" nodedef="ND_mix_color3_color3" sourcecode="math::lerp({{bg}}, {{fg}}, {{mix}})" target="genmdl" />
<implementation name="IM_mix_color4_genmdl" nodedef="ND_mix_color4" sourcecode="mx::stdlib::mx_mix_color4({{fg}}, {{bg}}, {{mix}})" target="genmdl" />
<implementation name="IM_mix_color4_color4_genmdl" nodedef="ND_mix_color4_color4" sourcecode="mx::stdlib::mx_mix_color4_color4({{fg}}, {{bg}}, {{mix}})" target="genmdl" />
<implementation name="IM_mix_vector2_genmdl" nodedef="ND_mix_vector2" sourcecode="math::lerp({{bg}}, {{fg}}, {{mix}})" target="genmdl" />
<implementation name="IM_mix_vector2_vector2_genmdl" nodedef="ND_mix_vector2_vector2" sourcecode="math::lerp({{bg}}, {{fg}}, {{mix}})" target="genmdl" />
<implementation name="IM_mix_vector3_genmdl" nodedef="ND_mix_vector3" sourcecode="math::lerp({{bg}}, {{fg}}, {{mix}})" target="genmdl" />
<implementation name="IM_mix_vector3_vector3_genmdl" nodedef="ND_mix_vector3_vector3" sourcecode="math::lerp({{bg}}, {{fg}}, {{mix}})" target="genmdl" />
<implementation name="IM_mix_vector4_genmdl" nodedef="ND_mix_vector4" sourcecode="math::lerp({{bg}}, {{fg}}, {{mix}})" target="genmdl" />
<implementation name="IM_mix_vector4_vector4_genmdl" nodedef="ND_mix_vector4_vector4" sourcecode="math::lerp({{bg}}, {{fg}}, {{mix}})" target="genmdl" />
<implementation name="IM_mix_surfaceshader_genmdl" nodedef="ND_mix_surfaceshader" sourcecode="mx::pbrlib::mx_mix_bsdf({{fg}}, {{bg}}, {{mix}})" target="genmdl" />

<!-- ======================================================================== -->
Expand Down
6 changes: 6 additions & 0 deletions libraries/stdlib/genosl/include/color4.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ color4 mix(color4 a, color4 b, float x )
mix(a.a, b.a, x));
}

color4 mix(color4 a, color4 b, color4 x )
{
return color4(mix(a.rgb, b.rgb, x.rgb),
mix(a.a, b.a, x.a));
}

float dot(color4 a, color b)
{
return dot(a.rgb, b);
Expand Down
5 changes: 5 additions & 0 deletions libraries/stdlib/genosl/include/vector2.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ vector2 mix(vector2 a, vector2 b, float x )
return vector2 (mix(a.x, b.x, x), mix(a.y, b.y, x));
}

vector2 mix(vector2 a, vector2 b, vector2 x )
{
return vector2 (mix(a.x, b.x, x.x), mix(a.y, b.y, x.y));
}

float dot(vector2 a, vector2 b)
{
return (a.x * b.x + a.y * b.y);
Expand Down
8 changes: 8 additions & 0 deletions libraries/stdlib/genosl/include/vector4.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ vector4 mix(vector4 value1, vector4 value2, float x )
mix( value1.w, value2.w, x));
}

vector4 mix(vector4 value1, vector4 value2, vector4 x )
{
return vector4 (mix( value1.x, value2.x, x.x),
mix( value1.y, value2.y, x.y),
mix( value1.z, value2.z, x.z),
mix( value1.w, value2.w, x.w));
}

vector vec4ToVec3(vector4 v)
{
return vector(v.x, v.y, v.z) / v.w;
Expand Down
5 changes: 5 additions & 0 deletions libraries/stdlib/genosl/stdlib_genosl_impl.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -602,10 +602,15 @@
<!-- <mix> -->
<implementation name="IM_mix_float_genosl" nodedef="ND_mix_float" file="mx_mix.inline" target="genosl" />
<implementation name="IM_mix_color3_genosl" nodedef="ND_mix_color3" file="mx_mix.inline" target="genosl" />
<implementation name="IM_mix_color3_color3_genosl" nodedef="ND_mix_color3_color3" file="mx_mix.inline" target="genosl" />
<implementation name="IM_mix_color4_genosl" nodedef="ND_mix_color4" file="mx_mix.inline" target="genosl" />
<implementation name="IM_mix_color4_color4_genosl" nodedef="ND_mix_color4_color4" file="mx_mix.inline" target="genosl" />
<implementation name="IM_mix_vector2_genosl" nodedef="ND_mix_vector2" file="mx_mix.inline" target="genosl" />
<implementation name="IM_mix_vector2_vector2_genosl" nodedef="ND_mix_vector2_vector2" file="mx_mix.inline" target="genosl" />
<implementation name="IM_mix_vector3_genosl" nodedef="ND_mix_vector3" file="mx_mix.inline" target="genosl" />
<implementation name="IM_mix_vector3_vector3_genosl" nodedef="ND_mix_vector3_vector3" file="mx_mix.inline" target="genosl" />
<implementation name="IM_mix_vector4_genosl" nodedef="ND_mix_vector4" file="mx_mix.inline" target="genosl" />
<implementation name="IM_mix_vector4_vector4_genosl" nodedef="ND_mix_vector4_vector4" file="mx_mix.inline" target="genosl" />
<implementation name="IM_mix_surfaceshader_genosl" nodedef="ND_mix_surfaceshader" file="mx_mix.inline" target="genosl" />

<!-- ======================================================================== -->
Expand Down
30 changes: 30 additions & 0 deletions libraries/stdlib/stdlib_defs.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -3222,30 +3222,60 @@
<input name="mix" type="float" value="0.0" />
<output name="out" type="color3" defaultinput="bg" />
</nodedef>
<nodedef name="ND_mix_color3_color3" node="mix" nodegroup="compositing">
<input name="fg" type="color3" value="0.0, 0.0, 0.0" />
<input name="bg" type="color3" value="0.0, 0.0, 0.0" />
<input name="mix" type="color3" value="0.0, 0.0, 0.0" />
<output name="out" type="color3" defaultinput="bg" />
</nodedef>
<nodedef name="ND_mix_color4" node="mix" nodegroup="compositing">
<input name="fg" type="color4" value="0.0, 0.0, 0.0, 0.0" />
<input name="bg" type="color4" value="0.0, 0.0, 0.0, 0.0" />
<input name="mix" type="float" value="0.0" />
<output name="out" type="color4" defaultinput="bg" />
</nodedef>
<nodedef name="ND_mix_color4_color4" node="mix" nodegroup="compositing">
<input name="fg" type="color4" value="0.0, 0.0, 0.0, 0.0" />
<input name="bg" type="color4" value="0.0, 0.0, 0.0, 0.0" />
<input name="mix" type="color4" value="0.0, 0.0, 0.0, 0.0" />
<output name="out" type="color4" defaultinput="bg" />
</nodedef>
<nodedef name="ND_mix_vector2" node="mix" nodegroup="compositing">
<input name="fg" type="vector2" value="0.0, 0.0" />
<input name="bg" type="vector2" value="0.0, 0.0" />
<input name="mix" type="float" value="0.0" />
<output name="out" type="vector2" defaultinput="bg" />
</nodedef>
<nodedef name="ND_mix_vector2_vector2" node="mix" nodegroup="compositing">
<input name="fg" type="vector2" value="0.0, 0.0" />
<input name="bg" type="vector2" value="0.0, 0.0" />
<input name="mix" type="vector2" value="0.0, 0.0" />
<output name="out" type="vector2" defaultinput="bg" />
</nodedef>
<nodedef name="ND_mix_vector3" node="mix" nodegroup="compositing">
<input name="fg" type="vector3" value="0.0, 0.0, 0.0" />
<input name="bg" type="vector3" value="0.0, 0.0, 0.0" />
<input name="mix" type="float" value="0.0" />
<output name="out" type="vector3" defaultinput="bg" />
</nodedef>
<nodedef name="ND_mix_vector3_vector3" node="mix" nodegroup="compositing">
<input name="fg" type="vector3" value="0.0, 0.0, 0.0" />
<input name="bg" type="vector3" value="0.0, 0.0, 0.0" />
<input name="mix" type="vector3" value="0.0, 0.0, 0.0" />
<output name="out" type="vector3" defaultinput="bg" />
</nodedef>
<nodedef name="ND_mix_vector4" node="mix" nodegroup="compositing">
<input name="fg" type="vector4" value="0.0, 0.0, 0.0, 0.0" />
<input name="bg" type="vector4" value="0.0, 0.0, 0.0, 0.0" />
<input name="mix" type="float" value="0.0" />
<output name="out" type="vector4" defaultinput="bg" />
</nodedef>
<nodedef name="ND_mix_vector4_vector4" node="mix" nodegroup="compositing">
<input name="fg" type="vector4" value="0.0, 0.0, 0.0, 0.0" />
<input name="bg" type="vector4" value="0.0, 0.0, 0.0, 0.0" />
<input name="mix" type="vector4" value="0.0, 0.0, 0.0, 0.0" />
<output name="out" type="vector4" defaultinput="bg" />
</nodedef>
<nodedef name="ND_mix_surfaceshader" node="mix" nodegroup="compositing">
<input name="fg" type="surfaceshader" value="" />
<input name="bg" type="surfaceshader" value="" />
Expand Down
36 changes: 34 additions & 2 deletions resources/Materials/TestSuite/stdlib/compositing/compositing.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,19 @@
</mix>
<output name="out" type="color3" nodename="mix1" />
</nodegraph>
<nodegraph name="mix_color4">
<nodegraph name="mix_color3_color3">
<mix name="mix1" type="color3">
<input name="fg" type="color3" value="1.0000, 0.0, 0.0" />
<input name="bg" type="color3" value="0.0, 1.0000, 0.0" />
<input name="mix" type="color3" value="0.5000, 0.5000, 0.5000" />
</mix>
<output name="out" type="color3" nodename="mix1" />
</nodegraph>
<nodegraph name="mix_color4_color4">
<mix name="mix1" type="color4">
<input name="fg" type="color4" value="1.0000, 0.0, 0.0, 1.0" />
<input name="bg" type="color4" value="0.0000, 1.0000, 0.0, 1.0" />
<input name="mix" type="float" value="0.5000" />
<input name="mix" type="color4" value="0.5000, 0.5000, 0.5000, 0.5000" />
</mix>
<output name="out" type="color4" nodename="mix1" />
</nodegraph>
Expand All @@ -298,6 +306,14 @@
</mix>
<output name="out" type="vector2" nodename="mix1" />
</nodegraph>
<nodegraph name="mix_vector2_vector2">
<mix name="mix1" type="vector2">
<input name="fg" type="vector2" value="1.0000, 0.0" />
<input name="bg" type="vector2" value="0.0, 1.0000" />
<input name="mix" type="vector2" value="0.5000, 0.5000" />
</mix>
<output name="out" type="vector2" nodename="mix1" />
</nodegraph>
<nodegraph name="mix_vector3">
<mix name="mix1" type="vector3">
<input name="fg" type="vector3" value="1.0000, 0.0, 0.0" />
Expand All @@ -306,6 +322,14 @@
</mix>
<output name="out" type="vector3" nodename="mix1" />
</nodegraph>
<nodegraph name="mix_vector3_vector3">
<mix name="mix1" type="vector3">
<input name="fg" type="vector3" value="1.0000, 0.0, 0.0" />
<input name="bg" type="vector3" value="0.0, 1.0000, 0.0" />
<input name="mix" type="vector3" value="0.5000, 0.5000, 0.5000" />
</mix>
<output name="out" type="vector3" nodename="mix1" />
</nodegraph>
<nodegraph name="mix_vector4">
<mix name="mix1" type="vector4">
<input name="fg" type="vector4" value="1.0000, 0.0, 0.0, 1.0" />
Expand All @@ -314,6 +338,14 @@
</mix>
<output name="out" type="vector4" nodename="mix1" />
</nodegraph>
<nodegraph name="mix_vector4_vector4">
<mix name="mix1" type="vector4">
<input name="fg" type="vector4" value="1.0000, 0.0, 0.0, 1.0" />
<input name="bg" type="vector4" value="0.0, 1.0000, 0.0, 1.0" />
<input name="mix" type="vector4" value="0.5000, 0.5000, 0.5000, 0.5000" />
</mix>
<output name="out" type="vector4" nodename="mix1" />
</nodegraph>
<nodegraph name="premult_color4">
<premult name="premult1" type="color4">
<input name="in" type="color4" value="1.0000, 0.0, 0.5000, 0.5000" />
Expand Down
12 changes: 12 additions & 0 deletions source/MaterialXGenMdl/mdl/materialx/stdlib.mdl
Original file line number Diff line number Diff line change
Expand Up @@ -3049,6 +3049,18 @@ export color4 mx_mix_color4(
return mk_color4(::math::lerp(mk_float4(mxp_bg), mk_float4(mxp_fg), float4(mxp_mix)));
}

export color4 mx_mix_color4_color4(
color4 mxp_fg = mk_color4(0.0, 0.0, 0.0, 0.0),
color4 mxp_bg = mk_color4(0.0, 0.0, 0.0, 0.0),
color4 mxp_mix = mk_color4(0.0, 0.0, 0.0, 0.0)
)
[[
anno::description("Node Group: compositing")
]]
{
return mk_color4(::math::lerp(mk_float4(mxp_bg), mk_float4(mxp_fg), mk_float4(mxp_mix)));
}

export material mx_mix_surfaceshader(
material mxp_fg [[ anno::unused() ]],
material mxp_bg,
Expand Down