@@ -30,16 +30,13 @@ uniform FragInfo {
3030 // / bottom-right), or the circular cap radii for rounded superellipses in
3131 // / radii.xy (top octant in x, right octant in y).
3232 vec4 radii;
33- // / Gradient parameters packed to avoid shader-side uniform division :
33+ // / Gradient parameters:
3434 // / - Linear gradient:
3535 // / xy: Start point in local coordinates.
36- // / zw: Pre-scaled direction vector (delta / dot(delta, delta)), such
37- // / that dot(v_position - xy, zw) yields the [0, 1] parameter t.
36+ // / zw: Delta vector (end - start) in local coordinates.
3837 // / - Radial gradient:
3938 // / xy: Center point in local coordinates.
40- // / z: Inverse radius (1.0 / radius), such that
41- // / length(v_position - xy) * z yields the [0, 1] parameter t.
42- // / w: Unused (0.0).
39+ // / zw: Unused (0.0).
4340 vec4 gradient_coords;
4441
4542 // ===========================================================================
@@ -108,6 +105,10 @@ uniform FragInfo {
108105 // / Half the size of a single gradient texel in normalized texture
109106 // / coordinates along the gradient ramp (x axis).
110107 float half_texel;
108+ // / Inverse gradient length:
109+ // / - Linear gradient: 1.0 / dot(delta, delta)
110+ // / - Radial gradient: 1.0 / radius
111+ float inv_gradient_length;
111112}
112113frag_info;
113114
@@ -126,11 +127,12 @@ vec4 getColor() {
126127 if (frag_info.color_source_type < 1.5 ) {
127128 // Linear gradient
128129 t = dot (v_position - frag_info.gradient_coords.xy,
129- frag_info.gradient_coords.zw);
130+ frag_info.gradient_coords.zw) *
131+ frag_info.inv_gradient_length;
130132 } else {
131133 // Radial gradient
132134 t = length (v_position - frag_info.gradient_coords.xy) *
133- frag_info.gradient_coords.z ;
135+ frag_info.inv_gradient_length ;
134136 }
135137 vec4 gradient_color = IPSampleLinearWithTileMode(
136138 color_source_sampler, vec2 (t, 0.5 ), vec2 (frag_info.half_texel, 0.5 ),
0 commit comments