Skip to content

Commit b812789

Browse files
Fix incorrect implementations of splittb, ramptb, and ramp4 (AcademySoftwareFoundation#2721)
When the input value ('V' in MaterialX spec, texcoord.y in the GLSL and OSL code) is below the 'center' input value, then the output should be the bottom value ('valueb'), otherwise if it is above then the output should be the top value ('valuet'). Given a default 'center' value of 0.5, it means that a texcoord.y value of 0.0 should yield 'valueb' as the output, and a texcoord.y value of 1.0 should yield 'valuet' as the output. The glsl and OSL code seem to do the opposite: mix in GLSL (and similarly in OSL) returns the first argument value when the third argument is 0.0. The third argument here is a call to mx_aastep(center, texcoord.y) which internlly uses smoothstep. For a default 'center' value of 0.5, a texcoord.y value of 0.0 yields 0.0 so the third argument to mix() is 0.0, meaning the first argument to mix() is returned. texcoord.y being 0.0 is below 'center' of 0.5 so the MaterialX spec states that 'valueb' should be returned, and yet the returned first argument to mix() is 'valuet'. Similarly, when texcoord.y is 1.0 being above a 'center' value of 0.5 the MaterilX spec states that 'valuet' should be returned, and yet this glsl implementtion returns 'valueb' in this case. The same applies to `ramptb` and `ramp4` nodes, and also in the MDL backend. This commit fixes this issue at the source OSL, GLSL and MDL files for `splittb` and `ramptb` nodes, and the node-graph implementation for `ramp4` node.
1 parent f296eaa commit b812789

File tree

11 files changed

+45
-45
lines changed

11 files changed

+45
-45
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
void mx_ramptb_float(float valuet, float valueb, vec2 texcoord, out float result)
22
{
3-
result = mix (valuet, valueb, clamp(texcoord.y, 0.0, 1.0) );
3+
result = mix (valueb, valuet, clamp(texcoord.y, 0.0, 1.0) );
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
void mx_ramptb_vector2(vec2 valuet, vec2 valueb, vec2 texcoord, out vec2 result)
22
{
3-
result = mix (valuet, valueb, clamp(texcoord.y, 0.0, 1.0) );
3+
result = mix (valueb, valuet, clamp(texcoord.y, 0.0, 1.0) );
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
void mx_ramptb_vector3(vec3 valuet, vec3 valueb, vec2 texcoord, out vec3 result)
22
{
3-
result = mix (valuet, valueb, clamp(texcoord.y, 0.0, 1.0) );
3+
result = mix (valueb, valuet, clamp(texcoord.y, 0.0, 1.0) );
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
void mx_ramptb_vector4(vec4 valuet, vec4 valueb, vec2 texcoord, out vec4 result)
22
{
3-
result = mix (valuet, valueb, clamp(texcoord.y, 0.0, 1.0) );
3+
result = mix (valueb, valuet, clamp(texcoord.y, 0.0, 1.0) );
44
}

libraries/stdlib/genglsl/mx_splittb_float.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
void mx_splittb_float(float valuet, float valueb, float center, vec2 texcoord, out float result)
44
{
5-
result = mix(valuet, valueb, mx_aastep(center, texcoord.y));
5+
result = mix(valueb, valuet, mx_aastep(center, texcoord.y));
66
}

libraries/stdlib/genglsl/mx_splittb_vector2.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
void mx_splittb_vector2(vec2 valuet, vec2 valueb, float center, vec2 texcoord, out vec2 result)
44
{
5-
result = mix(valuet, valueb, mx_aastep(center, texcoord.y));
5+
result = mix(valueb, valuet, mx_aastep(center, texcoord.y));
66
}

libraries/stdlib/genglsl/mx_splittb_vector3.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
void mx_splittb_vector3(vec3 valuet, vec3 valueb, float center, vec2 texcoord, out vec3 result)
44
{
5-
result = mix(valuet, valueb, mx_aastep(center, texcoord.y));
5+
result = mix(valueb, valuet, mx_aastep(center, texcoord.y));
66
}

libraries/stdlib/genglsl/mx_splittb_vector4.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
void mx_splittb_vector4(vec4 valuet, vec4 valueb, float center, vec2 texcoord, out vec4 result)
44
{
5-
result = mix(valuet, valueb, mx_aastep(center, texcoord.y));
5+
result = mix(valueb, valuet, mx_aastep(center, texcoord.y));
66
}

libraries/stdlib/genosl/stdlib_genosl_impl.mtlx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@
100100
<implementation name="IM_ramplr_vector4_genosl" nodedef="ND_ramplr_vector4" target="genosl" sourcecode="mix({{valuel}}, {{valuer}}, clamp({{texcoord}}.x, 0, 1))" />
101101

102102
<!-- <ramptb> -->
103-
<implementation name="IM_ramptb_float_genosl" nodedef="ND_ramptb_float" target="genosl" sourcecode="mix({{valuet}}, {{valueb}}, clamp({{texcoord}}.y, 0, 1))" />
104-
<implementation name="IM_ramptb_color3_genosl" nodedef="ND_ramptb_color3" target="genosl" sourcecode="mix({{valuet}}, {{valueb}}, clamp({{texcoord}}.y, 0, 1))" />
105-
<implementation name="IM_ramptb_color4_genosl" nodedef="ND_ramptb_color4" target="genosl" sourcecode="mix({{valuet}}, {{valueb}}, clamp({{texcoord}}.y, 0, 1))" />
106-
<implementation name="IM_ramptb_vector2_genosl" nodedef="ND_ramptb_vector2" target="genosl" sourcecode="mix({{valuet}}, {{valueb}}, clamp({{texcoord}}.y, 0, 1))" />
107-
<implementation name="IM_ramptb_vector3_genosl" nodedef="ND_ramptb_vector3" target="genosl" sourcecode="mix({{valuet}}, {{valueb}}, clamp({{texcoord}}.y, 0, 1))" />
108-
<implementation name="IM_ramptb_vector4_genosl" nodedef="ND_ramptb_vector4" target="genosl" sourcecode="mix({{valuet}}, {{valueb}}, clamp({{texcoord}}.y, 0, 1))" />
103+
<implementation name="IM_ramptb_float_genosl" nodedef="ND_ramptb_float" target="genosl" sourcecode="mix({{valueb}}, {{valuet}}, clamp({{texcoord}}.y, 0, 1))" />
104+
<implementation name="IM_ramptb_color3_genosl" nodedef="ND_ramptb_color3" target="genosl" sourcecode="mix({{valueb}}, {{valuet}}, clamp({{texcoord}}.y, 0, 1))" />
105+
<implementation name="IM_ramptb_color4_genosl" nodedef="ND_ramptb_color4" target="genosl" sourcecode="mix({{valueb}}, {{valuet}}, clamp({{texcoord}}.y, 0, 1))" />
106+
<implementation name="IM_ramptb_vector2_genosl" nodedef="ND_ramptb_vector2" target="genosl" sourcecode="mix({{valueb}}, {{valuet}}, clamp({{texcoord}}.y, 0, 1))" />
107+
<implementation name="IM_ramptb_vector3_genosl" nodedef="ND_ramptb_vector3" target="genosl" sourcecode="mix({{valueb}}, {{valuet}}, clamp({{texcoord}}.y, 0, 1))" />
108+
<implementation name="IM_ramptb_vector4_genosl" nodedef="ND_ramptb_vector4" target="genosl" sourcecode="mix({{valueb}}, {{valuet}}, clamp({{texcoord}}.y, 0, 1))" />
109109

110110
<!-- <splitlr> -->
111111
<implementation name="IM_splitlr_float_genosl" nodedef="ND_splitlr_float" target="genosl" sourcecode="mix({{valuel}}, {{valuer}}, aastep({{center}}, {{texcoord}}.x))" />
@@ -116,12 +116,12 @@
116116
<implementation name="IM_splitlr_vector4_genosl" nodedef="ND_splitlr_vector4" target="genosl" sourcecode="mix({{valuel}}, {{valuer}}, aastep({{center}}, {{texcoord}}.x))" />
117117

118118
<!-- <splittb> -->
119-
<implementation name="IM_splittb_float_genosl" nodedef="ND_splittb_float" target="genosl" sourcecode="mix({{valuet}}, {{valueb}}, aastep({{center}}, {{texcoord}}.y))" />
120-
<implementation name="IM_splittb_color3_genosl" nodedef="ND_splittb_color3" target="genosl" sourcecode="mix({{valuet}}, {{valueb}}, aastep({{center}}, {{texcoord}}.y))" />
121-
<implementation name="IM_splittb_color4_genosl" nodedef="ND_splittb_color4" target="genosl" sourcecode="mix({{valuet}}, {{valueb}}, aastep({{center}}, {{texcoord}}.y))" />
122-
<implementation name="IM_splittb_vector2_genosl" nodedef="ND_splittb_vector2" target="genosl" sourcecode="mix({{valuet}}, {{valueb}}, aastep({{center}}, {{texcoord}}.y))" />
123-
<implementation name="IM_splittb_vector3_genosl" nodedef="ND_splittb_vector3" target="genosl" sourcecode="mix({{valuet}}, {{valueb}}, aastep({{center}}, {{texcoord}}.y))" />
124-
<implementation name="IM_splittb_vector4_genosl" nodedef="ND_splittb_vector4" target="genosl" sourcecode="mix({{valuet}}, {{valueb}}, aastep({{center}}, {{texcoord}}.y))" />
119+
<implementation name="IM_splittb_float_genosl" nodedef="ND_splittb_float" target="genosl" sourcecode="mix({{valueb}}, {{valuet}}, aastep({{center}}, {{texcoord}}.y))" />
120+
<implementation name="IM_splittb_color3_genosl" nodedef="ND_splittb_color3" target="genosl" sourcecode="mix({{valueb}}, {{valuet}}, aastep({{center}}, {{texcoord}}.y))" />
121+
<implementation name="IM_splittb_color4_genosl" nodedef="ND_splittb_color4" target="genosl" sourcecode="mix({{valueb}}, {{valuet}}, aastep({{center}}, {{texcoord}}.y))" />
122+
<implementation name="IM_splittb_vector2_genosl" nodedef="ND_splittb_vector2" target="genosl" sourcecode="mix({{valueb}}, {{valuet}}, aastep({{center}}, {{texcoord}}.y))" />
123+
<implementation name="IM_splittb_vector3_genosl" nodedef="ND_splittb_vector3" target="genosl" sourcecode="mix({{valueb}}, {{valuet}}, aastep({{center}}, {{texcoord}}.y))" />
124+
<implementation name="IM_splittb_vector4_genosl" nodedef="ND_splittb_vector4" target="genosl" sourcecode="mix({{valueb}}, {{valuet}}, aastep({{center}}, {{texcoord}}.y))" />
125125

126126
<!-- <noise2d> -->
127127
<implementation name="IM_noise2d_float_genosl" nodedef="ND_noise2d_float" file="mx_noise2d_float.osl" function="mx_noise2d_float" target="genosl" />

libraries/stdlib/stdlib_ng.mtlx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,8 +1372,8 @@
13721372
<input name="mix" type="float" nodename="N_s_float" />
13731373
</mix>
13741374
<mix name="N_mix_float" type="float">
1375-
<input name="bg" type="float" nodename="N_mixtop_float" />
1376-
<input name="fg" type="float" nodename="N_mixbot_float" />
1375+
<input name="bg" type="float" nodename="N_mixbot_float" />
1376+
<input name="fg" type="float" nodename="N_mixtop_float" />
13771377
<input name="mix" type="float" nodename="N_t_float" />
13781378
</mix>
13791379
<output name="out" type="float" nodename="N_mix_float" />
@@ -1401,8 +1401,8 @@
14011401
<input name="mix" type="float" nodename="N_s_color3" />
14021402
</mix>
14031403
<mix name="N_mix_color3" type="color3">
1404-
<input name="bg" type="color3" nodename="N_mixtop_color3" />
1405-
<input name="fg" type="color3" nodename="N_mixbot_color3" />
1404+
<input name="bg" type="color3" nodename="N_mixbot_color3" />
1405+
<input name="fg" type="color3" nodename="N_mixtop_color3" />
14061406
<input name="mix" type="float" nodename="N_t_color3" />
14071407
</mix>
14081408
<output name="out" type="color3" nodename="N_mix_color3" />
@@ -1430,8 +1430,8 @@
14301430
<input name="mix" type="float" nodename="N_s_color4" />
14311431
</mix>
14321432
<mix name="N_mix_color4" type="color4">
1433-
<input name="bg" type="color4" nodename="N_mixtop_color4" />
1434-
<input name="fg" type="color4" nodename="N_mixbot_color4" />
1433+
<input name="bg" type="color4" nodename="N_mixbot_color4" />
1434+
<input name="fg" type="color4" nodename="N_mixtop_color4" />
14351435
<input name="mix" type="float" nodename="N_t_color4" />
14361436
</mix>
14371437
<output name="out" type="color4" nodename="N_mix_color4" />
@@ -1459,8 +1459,8 @@
14591459
<input name="mix" type="float" nodename="N_s_vector2" />
14601460
</mix>
14611461
<mix name="N_mix_vector2" type="vector2">
1462-
<input name="bg" type="vector2" nodename="N_mixtop_vector2" />
1463-
<input name="fg" type="vector2" nodename="N_mixbot_vector2" />
1462+
<input name="bg" type="vector2" nodename="N_mixbot_vector2" />
1463+
<input name="fg" type="vector2" nodename="N_mixtop_vector2" />
14641464
<input name="mix" type="float" nodename="N_t_vector2" />
14651465
</mix>
14661466
<output name="out" type="vector2" nodename="N_mix_vector2" />
@@ -1488,8 +1488,8 @@
14881488
<input name="mix" type="float" nodename="N_s_vector3" />
14891489
</mix>
14901490
<mix name="N_mix_vector3" type="vector3">
1491-
<input name="bg" type="vector3" nodename="N_mixtop_vector3" />
1492-
<input name="fg" type="vector3" nodename="N_mixbot_vector3" />
1491+
<input name="bg" type="vector3" nodename="N_mixbot_vector3" />
1492+
<input name="fg" type="vector3" nodename="N_mixtop_vector3" />
14931493
<input name="mix" type="float" nodename="N_t_vector3" />
14941494
</mix>
14951495
<output name="out" type="vector3" nodename="N_mix_vector3" />
@@ -1517,8 +1517,8 @@
15171517
<input name="mix" type="float" nodename="N_s_vector4" />
15181518
</mix>
15191519
<mix name="N_mix_vector4" type="vector4">
1520-
<input name="bg" type="vector4" nodename="N_mixtop_vector4" />
1521-
<input name="fg" type="vector4" nodename="N_mixbot_vector4" />
1520+
<input name="bg" type="vector4" nodename="N_mixbot_vector4" />
1521+
<input name="fg" type="vector4" nodename="N_mixtop_vector4" />
15221522
<input name="mix" type="float" nodename="N_t_vector4" />
15231523
</mix>
15241524
<output name="out" type="vector4" nodename="N_mix_vector4" />

0 commit comments

Comments
 (0)