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

Update overlay node logic to match reference #1539

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 @@ -1496,7 +1496,7 @@ Blend nodes take two 1-4 channel inputs and apply the same operator to all chann
| **`burn`** | 1-(1-B)/F | float, color<em>N</em> |
| **`dodge`** | B/(1-F) | float, color<em>N</em> |
| **`screen`** | 1-(1-F)(1-B) | float, color<em>N</em> |
| **`overlay`** | 2FB if F&lt;0.5;<br> 1-(1-F)(1-B) if F>=0.5 | float, color<em>N</em> |
| **`overlay`** | 2FB if B&lt;0.5;<br> 1-2(1-F)(1-B) if B>=0.5 | float, color<em>N</em> |


#### Merge Nodes
Expand Down
25 changes: 0 additions & 25 deletions libraries/stdlib/genglsl/mx_overlay.glsl

This file was deleted.

6 changes: 0 additions & 6 deletions libraries/stdlib/genglsl/mx_overlay_color3.glsl

This file was deleted.

6 changes: 0 additions & 6 deletions libraries/stdlib/genglsl/mx_overlay_color4.glsl

This file was deleted.

5 changes: 0 additions & 5 deletions libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,6 @@
<implementation name="IM_screen_color3_genglsl" nodedef="ND_screen_color3" target="genglsl" sourcecode="({{mix}}*((1.0 - (1.0 - {{fg}}) * (1.0 - {{bg}})))) + ((1.0-{{mix}})*{{bg}})" />
<implementation name="IM_screen_color4_genglsl" nodedef="ND_screen_color4" target="genglsl" sourcecode="({{mix}}*((1.0 - (1.0 - {{fg}}) * (1.0 - {{bg}})))) + ((1.0-{{mix}})*{{bg}})" />

<!-- <overlay> -->
<implementation name="IM_overlay_float_genglsl" nodedef="ND_overlay_float" target="genglsl" sourcecode="({{fg}} < 0.5) ? ({{mix}}*2.0*{{fg}}*{{bg}}) + ((1.0-{{mix}})*{{bg}}) : ({{mix}}*(1.0-(1.0-{{fg}})*(1.0-{{bg}}))) + ((1.0-{{mix}})*{{bg}})" />
<implementation name="IM_overlay_color3_genglsl" nodedef="ND_overlay_color3" file="mx_overlay_color3.glsl" function="mx_overlay_color3" target="genglsl" />
<implementation name="IM_overlay_color4_genglsl" nodedef="ND_overlay_color4" file="mx_overlay_color4.glsl" function="mx_overlay_color4" target="genglsl" />

<!-- <disjointover> -->
<implementation name="IM_disjointover_color4_genglsl" nodedef="ND_disjointover_color4" file="mx_disjointover_color4.glsl" function="mx_disjointover_color4" target="genglsl" />

Expand Down
5 changes: 0 additions & 5 deletions libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -568,11 +568,6 @@
<implementation name="IM_screen_color3_genmdl" nodedef="ND_screen_color3" sourcecode="({{mix}}*((1.0 - (1.0 - {{fg}}) * (1 - {{bg}})))) + ((1.0-{{mix}})*{{bg}})" target="genmdl" />
<implementation name="IM_screen_color4_genmdl" nodedef="ND_screen_color4" sourcecode="mx::stdlib::mx_screen_color4({{fg}}, {{bg}}, {{mix}})" target="genmdl" />

<!-- <overlay> -->
<implementation name="IM_overlay_float_genmdl" nodedef="ND_overlay_float" sourcecode="mx::stdlib::mx_overlay_float({{fg}}, {{bg}}, {{mix}})" target="genmdl" />
<implementation name="IM_overlay_color3_genmdl" nodedef="ND_overlay_color3" sourcecode="mx::stdlib::mx_overlay_color3({{fg}}, {{bg}}, {{mix}})" target="genmdl" />
<implementation name="IM_overlay_color4_genmdl" nodedef="ND_overlay_color4" sourcecode="mx::stdlib::mx_overlay_color4({{fg}}, {{bg}}, {{mix}})" target="genmdl" />

<!-- <disjointover> -->
<implementation name="IM_disjointover_color4_genmdl" nodedef="ND_disjointover_color4" sourcecode="mx::stdlib::mx_disjointover_color4({{fg}}, {{bg}}, {{mix}})" target="genmdl" />

Expand Down
5 changes: 0 additions & 5 deletions libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,6 @@
<implementation name="IM_screen_color3_genmsl" nodedef="ND_screen_color3" target="genmsl" sourcecode="({{mix}}*((1.0 - (1.0 - {{fg}}) * (1.0 - {{bg}})))) + ((1.0-{{mix}})*{{bg}})" />
<implementation name="IM_screen_color4_genmsl" nodedef="ND_screen_color4" target="genmsl" sourcecode="({{mix}}*((1.0 - (1.0 - {{fg}}) * (1.0 - {{bg}})))) + ((1.0-{{mix}})*{{bg}})" />

<!-- <overlay> -->
<implementation name="IM_overlay_float_genmsl" nodedef="ND_overlay_float" target="genmsl" sourcecode="({{fg}} < 0.5) ? ({{mix}}*2.0*{{fg}}*{{bg}}) + ((1.0-{{mix}})*{{bg}}) : ({{mix}}*(1.0-(1.0-{{fg}})*(1.0-{{bg}}))) + ((1.0-{{mix}})*{{bg}})" />
<implementation name="IM_overlay_color3_genmsl" nodedef="ND_overlay_color3" file="../genglsl/mx_overlay_color3.glsl" function="mx_overlay_color3" target="genmsl" />
<implementation name="IM_overlay_color4_genmsl" nodedef="ND_overlay_color4" file="../genglsl/mx_overlay_color4.glsl" function="mx_overlay_color4" target="genmsl" />

<!-- <disjointover> -->
<implementation name="IM_disjointover_color4_genmsl" nodedef="ND_disjointover_color4" file="../genglsl/mx_disjointover_color4.glsl" function="mx_disjointover_color4" target="genmsl" />

Expand Down
16 changes: 0 additions & 16 deletions libraries/stdlib/genosl/mx_overlay_color3.osl

This file was deleted.

22 changes: 0 additions & 22 deletions libraries/stdlib/genosl/mx_overlay_color4.osl

This file was deleted.

5 changes: 0 additions & 5 deletions libraries/stdlib/genosl/stdlib_genosl_impl.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -561,11 +561,6 @@
<implementation name="IM_screen_color3_genosl" nodedef="ND_screen_color3" target="genosl" sourcecode="({{mix}}*((1.0 - (1.0 - {{fg}}) * (1 - {{bg}})))) + ((1.0-{{mix}})*{{bg}})" />
<implementation name="IM_screen_color4_genosl" nodedef="ND_screen_color4" target="genosl" sourcecode="({{mix}}*((1.0 - (1.0 - {{fg}}) * (1 - {{bg}})))) + ((1.0-{{mix}})*{{bg}})" />

<!-- <overlay> -->
<implementation name="IM_overlay_float_genosl" nodedef="ND_overlay_float" target="genosl" sourcecode="({{fg}} < 0.5) ? ({{mix}}*2.0*{{fg}}*{{bg}}) + ((1.0-{{mix}})*{{bg}}) : ({{mix}}*(1.0-(1.0-{{fg}})*(1.0-{{bg}}))) + ((1.0-{{mix}})*{{bg}})" />
<implementation name="IM_overlay_color3_genosl" nodedef="ND_overlay_color3" file="mx_overlay_color3.osl" function="mx_overlay_color3" target="genosl" />
<implementation name="IM_overlay_color4_genosl" nodedef="ND_overlay_color4" file="mx_overlay_color4.osl" function="mx_overlay_color4" target="genosl" />

<!-- <disjointover> -->
<implementation name="IM_disjointover_color4_genosl" nodedef="ND_disjointover_color4" file="mx_disjointover_color4.osl" function="mx_disjointover_color4" target="genosl" />

Expand Down
4 changes: 2 additions & 2 deletions libraries/stdlib/stdlib_defs.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -3343,8 +3343,8 @@
<!--
Node: <overlay>
Take two 1-4 channel inputs and apply the same operator to all channels:
2FB if F<0.5;
1-(1-F)(1-B) if F>=0.5
2FB if B<0.5;
jstone-lucasfilm marked this conversation as resolved.
Show resolved Hide resolved
1-2(1-F)(1-B) if B>=0.5
-->
<nodedef name="ND_overlay_float" node="overlay" nodegroup="compositing">
<input name="fg" type="float" value="0.0" />
Expand Down
112 changes: 112 additions & 0 deletions libraries/stdlib/stdlib_ng.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -3391,6 +3391,118 @@
<!-- Compositing nodes -->
<!-- ======================================================================== -->

<!--
Node: <overlay>
Overlay is a compositing node which is a combination of multiply and screen.
-->
<nodegraph name="NG_overlay_float" nodedef="ND_overlay_float">
<output name="out" type="float" nodename="N_mix" />
<ifgreatereq name="N_ifgreatereq0_overlay_r" type="float" nodedef="ND_ifgreatereq_float">
<input name="value1" type="float" interfacename="bg" />
<input name="value2" type="float" value="0.5" />
<input name="in1" type="float" nodename="N_subtract_lower_one" />
<input name="in2" type="float" nodename="N_multiply_upper_two" />
</ifgreatereq>
<multiply name="N_multiply_upper_fg_bg" type="float" nodedef="ND_multiply_float">
<input name="in1" type="float" interfacename="fg" />
<input name="in2" type="float" interfacename="bg" />
</multiply>
<multiply name="N_multiply_upper_two" type="float" nodedef="ND_multiply_float">
<input name="in1" type="float" nodename="N_multiply_upper_fg_bg" />
<input name="in2" type="float" value="2" />
</multiply>
<subtract name="N_subtract_lower_one_bg" type="float" nodedef="ND_subtract_float">
<input name="in1" type="float" value="1" />
<input name="in2" type="float" interfacename="bg" />
</subtract>
<subtract name="N_subtract_lower_one_fg" type="float" nodedef="ND_subtract_float">
<input name="in1" type="float" value="1" />
<input name="in2" type="float" interfacename="fg" />
</subtract>
<multiply name="N_multiply_lower_fg_bg" type="float" nodedef="ND_multiply_float">
<input name="in1" type="float" nodename="N_subtract_lower_one_bg" />
<input name="in2" type="float" nodename="N_subtract_lower_one_fg" />
</multiply>
<subtract name="N_subtract_lower_one" type="float" nodedef="ND_subtract_float">
<input name="in1" type="float" value="1" />
<input name="in2" type="float" nodename="N_multiply_lower_two" />
</subtract>
<mix name="N_mix" type="float" nodedef="ND_mix_float">
<input name="fg" type="float" nodename="N_ifgreatereq0_overlay_r" />
<input name="bg" type="float" interfacename="bg" />
<input name="mix" type="float" interfacename="mix" />
</mix>
<multiply name="N_multiply_lower_two" type="float" nodedef="ND_multiply_float">
<input name="in1" type="float" nodename="N_multiply_lower_fg_bg" />
<input name="in2" type="float" value="2" />
</multiply>
</nodegraph>
<nodegraph name="NG_overlay_color3" nodedef="ND_overlay_color3">
<output name="out" type="color3" nodename="N_combine" />
<separate3 name="N_split_color3_fg" type="multioutput" nodedef="ND_separate3_color3">
<input name="in" type="color3" interfacename="fg" />
</separate3>
<separate3 name="N_split_color3_bg" type="multioutput" nodedef="ND_separate3_color3">
<input name="in" type="color3" interfacename="bg" />
</separate3>
<combine3 name="N_combine" type="color3" nodedef="ND_combine3_color3">
<input name="in1" type="float" nodename="N_overlay_r" />
<input name="in2" type="float" nodename="N_overlay_g" />
<input name="in3" type="float" nodename="N_overlay_b" />
</combine3>
<overlay name="N_overlay_r" type="float" nodedef="ND_overlay_float">
<input name="fg" type="float" nodename="N_split_color3_fg" output="outr" />
<input name="bg" type="float" nodename="N_split_color3_bg" output="outr" />
<input name="mix" type="float" interfacename="mix" />
</overlay>
<overlay name="N_overlay_g" type="float" nodedef="ND_overlay_float">
<input name="fg" type="float" nodename="N_split_color3_fg" output="outg" />
<input name="bg" type="float" nodename="N_split_color3_bg" output="outg" />
<input name="mix" type="float" interfacename="mix" />
</overlay>
<overlay name="N_overlay_b" type="float" nodedef="ND_overlay_float">
<input name="fg" type="float" nodename="N_split_color3_fg" output="outb" />
<input name="bg" type="float" nodename="N_split_color3_bg" output="outb" />
<input name="mix" type="float" interfacename="mix" />
</overlay>
</nodegraph>
<nodegraph name="NG_overlay_color4" nodedef="ND_overlay_color4">
<output name="out" type="color4" nodename="N_combine" />
<separate4 name="N_split_fg" type="multioutput" nodedef="ND_separate4_color4">
<input name="in" type="color4" interfacename="fg" />
</separate4>
<separate4 name="N_split_bg" type="multioutput" nodedef="ND_separate4_color4">
<input name="in" type="color4" interfacename="bg" />
</separate4>
<overlay name="N_overlay_r" type="float" nodedef="ND_overlay_float">
<input name="fg" type="float" nodename="N_split_fg" output="outr" />
<input name="bg" type="float" nodename="N_split_bg" output="outr" />
<input name="mix" type="float" interfacename="mix" />
</overlay>
<overlay name="N_overlay_g" type="float" nodedef="ND_overlay_float">
<input name="fg" type="float" nodename="N_split_fg" output="outg" />
<input name="bg" type="float" nodename="N_split_bg" output="outg" />
<input name="mix" type="float" interfacename="mix" />
</overlay>
<overlay name="N_overlay_b" type="float" nodedef="ND_overlay_float">
<input name="fg" type="float" nodename="N_split_fg" output="outb" />
<input name="bg" type="float" nodename="N_split_bg" output="outb" />
<input name="mix" type="float" interfacename="mix" />
</overlay>
<overlay name="N_overlay_a" type="float" nodedef="ND_overlay_float">
<input name="fg" type="float" nodename="N_split_fg" output="outa" />
<input name="bg" type="float" nodename="N_split_bg" output="outa" />
<input name="mix" type="float" interfacename="mix" />
</overlay>
<combine4 name="N_combine" type="color4" nodedef="ND_combine4_color4">
<input name="in1" type="float" nodename="N_overlay_r" />
<input name="in2" type="float" nodename="N_overlay_g" />
<input name="in3" type="float" nodename="N_overlay_b" />
<input name="in4" type="float" nodename="N_overlay_a" />
</combine4>
</nodegraph>


<!-- ======================================================================== -->
<!-- Conditional nodes -->
<!-- ======================================================================== -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,24 +183,24 @@
</nodegraph>
<nodegraph name="overlay_float">
<overlay name="overlay1" type="float">
<input name="fg" type="float" value="0.5000" />
<input name="bg" type="float" value="0.5000" />
<input name="fg" type="float" value="0.2" />
<input name="bg" type="float" value="0.6" />
<input name="mix" type="float" value="0.5000" />
</overlay>
<output name="out" type="float" nodename="overlay1" />
</nodegraph>
<nodegraph name="overlay_color3">
<overlay name="overlay1" type="color3">
<input name="fg" type="color3" value="0.5000, 0.0, 0.0" />
<input name="bg" type="color3" value="0.5000, 1.0000, 0.0" />
<input name="fg" type="color3" value="0.2, 0.6, 0.6" />
<input name="bg" type="color3" value="0.8, 0.2, 0.4" />
<input name="mix" type="float" value="0.5000" />
</overlay>
<output name="out" type="color3" nodename="overlay1" />
</nodegraph>
<nodegraph name="overlay_color4">
<overlay name="overlay1" type="color4">
<input name="fg" type="color4" value="0.5000, 0.0, 0.0, 1.0" />
<input name="bg" type="color4" value="0.5000, 1.0000, 0.0, 1.0000" />
<input name="fg" type="color4" value="0.6, 0.8, 0.8, 1.0" />
<input name="bg" type="color4" value="0.6, 0.2, 0.4, 1.0" />
<input name="mix" type="float" value="0.5000" />
</overlay>
<output name="out" type="color4" nodename="overlay1" />
Expand Down
60 changes: 0 additions & 60 deletions source/MaterialXGenMdl/mdl/materialx/stdlib.mdl
Original file line number Diff line number Diff line change
Expand Up @@ -2777,66 +2777,6 @@ export color4 mx_screen_color4(
return color4(rgb,a);
}

float mx_overlay(float mxp_fg, float mxp_bg)
{
return (mxp_fg < 0.5) ? (2 * mxp_fg * mxp_bg) : (1 - (1 - mxp_fg) * (1 - mxp_bg));
}
float2 mx_overlay(float2 mxp_fg, float2 mxp_bg) [[ anno::unused() ]]
{
return float2(
mx_overlay(mxp_fg.x, mxp_bg.x),
mx_overlay(mxp_fg.y, mxp_bg.y)
);
}
color mx_overlay(color mxp_fg, color mxp_bg)
{
float3 fg(mxp_fg);
float3 bg(mxp_bg);
return color(
mx_overlay(fg.x, bg.x),
mx_overlay(fg.y, bg.y),
mx_overlay(fg.z, bg.z)
);
}

export float mx_overlay_float(
float mxp_fg = 0.0,
float mxp_bg = 0.0,
float mxp_mix = 1.0
)
[[
anno::description("Node Group: compositing")
]]
{
return mxp_mix * mx_overlay(mxp_fg, mxp_bg) + (1-mxp_mix) * mxp_bg;
}

export color mx_overlay_color3(
color mxp_fg = color(0.0),
color mxp_bg = color(0.0),
float mxp_mix = 1.0
)
[[
anno::description("Node Group: compositing")
]]
{
return mxp_mix * mx_overlay(mxp_fg, mxp_bg) + (1-mxp_mix) * mxp_bg;
}

export color4 mx_overlay_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),
float mxp_mix = float(1.0)
)
[[
anno::description("Node Group: compositing")
]]
{
color rgb = mxp_mix * mx_overlay(mxp_fg.rgb, mxp_bg.rgb) + (1-mxp_mix) * mxp_bg.rgb;
float a = mxp_mix * mx_overlay(mxp_fg.a , mxp_bg.a ) + (1-mxp_mix) * mxp_bg.a;
return color4(rgb,a);
}

export color4 mx_disjointover_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),
Expand Down