- float smooth_l = textureOffset(smoothness_x_tex, tc, ivec2(-1, 0)).x;
- float smooth_r = texture(smoothness_x_tex, tc).x;
- float smooth_d = textureOffset(smoothness_y_tex, tc, ivec2( 0, -1)).x;
- float smooth_u = texture(smoothness_y_tex, tc).x;
+ //
+ // Note that we sample in-between two texels, which gives us the 0.5 *
+ // (x[-1] + x[0]) part for free. If one of the texels is a border
+ // texel, it will have zero alpha, and zero_if_outside_border() will
+ // set smoothness to zero.
+ float smooth_l = zero_if_outside_border(texture(diffusivity_tex, tc_left));
+ float smooth_r = zero_if_outside_border(textureOffset(diffusivity_tex, tc_left, ivec2(1, 0)));
+ float smooth_d = zero_if_outside_border(texture(diffusivity_tex, tc_down));
+ float smooth_u = zero_if_outside_border(textureOffset(diffusivity_tex, tc_down, ivec2(0, 1)));