Skip to content

Commit ae3fb9c

Browse files
Fixes alpha blending issue in hextiledimage_color4 (#2786)
Fixes the alpha blending issue in `hextiledimage_color4` reported [here](https://academysoftwarefdn.slack.com/archives/C0230LWBE2X/p1771037354472909). This PR includes corresponding fixes in GLSL, OSL, and MDL implementations.
1 parent abb2d44 commit ae3fb9c

3 files changed

Lines changed: 7 additions & 24 deletions

File tree

libraries/stdlib/genglsl/mx_hextiledimage.glsl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,9 @@ void mx_hextiledimage_color4(
6969
cw = mix(vec3(1.0), cw, vec3(falloff_contrast));
7070

7171
vec3 w = mx_hextile_compute_blend_weights(cw, tile_data.weights, falloff);
72-
73-
// alpha
74-
float a = (c1.a + c2.a + c3.a) / 3.0;
75-
if (falloff != 0.5)
76-
{
77-
a = mx_schlick_gain(a, falloff);
78-
}
72+
vec3 aw = mx_hextile_compute_blend_weights(vec3(1.0), tile_data.weights, falloff);
7973

8074
// blend
8175
result.rgb = w.x * c1.rgb + w.y * c2.rgb + w.z * c3.rgb;
82-
result.a = a;
76+
result.a = aw.x * c1.a + aw.y * c2.a + aw.z * c3.a;
8377
}

libraries/stdlib/genosl/mx_hextiledimage_color4.osl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,9 @@ void mx_hextiledimage_color4(
5151
// Luminance-based blend weights
5252
cw = mix(vector(1.0), cw, vector(falloffcontrast));
5353
vector w = mx_hextile_compute_blend_weights(cw, tile_data.weights, falloff);
54-
55-
// Alpha (average with optional falloff adjustment)
56-
float a = (alpha[0] + alpha[1] + alpha[2]) / 3.0;
57-
if (falloff != 0.5)
58-
{
59-
a = mx_schlick_gain(a, falloff);
60-
}
54+
vector aw = mx_hextile_compute_blend_weights(vector(1.0), tile_data.weights, falloff);
6155

6256
// Blend colors
6357
result.rgb = w[0] * c[0] + w[1] * c[1] + w[2] * c[2];
64-
result.a = a;
58+
result.a = aw[0] * alpha[0] + aw[1] * alpha[1] + aw[2] * alpha[2];
6559
}

source/MaterialXGenMdl/mdl/materialx/stdlib_1_6.mdl

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -777,16 +777,11 @@ export core::color4 mx_hextiledimage_color4(
777777
cw = math::lerp(float3(1.0), cw, float3(mxp_falloff_contrast));
778778

779779
float3 w = hextile::mx_hextile_compute_blend_weights(cw, tile_data.weights, mxp_falloff);
780-
781-
// alpha
782-
float a = (c1.a + c2.a + c3.a) / 3.0;
783-
if (mxp_falloff != 0.5)
784-
{
785-
a = hextile::mx_schlick_gain(a, mxp_falloff);
786-
}
780+
float3 aw = hextile::mx_hextile_compute_blend_weights(float3(1.0), tile_data.weights, mxp_falloff);
787781

788782
// blend
789-
return core::mk_color4(w.x * c1.rgb + w.y * c2.rgb + w.z * c3.rgb, a);
783+
return core::mk_color4(w.x * c1.rgb + w.y * c2.rgb + w.z * c3.rgb,
784+
aw.x * c1.a + aw.y * c2.a + aw.z * c3.a);
790785
}
791786

792787
export float mx_constant_float(

0 commit comments

Comments
 (0)