4 out float smoothness_x, smoothness_y;
5 const float eps_sq = 0.001 * 0.001;
7 uniform sampler2D flow_tex, diff_flow_tex;
9 // Relative weighting of smoothness term.
12 // This must be a macro, since the offset needs to be a constant expression.
13 #define get_flow(x_offs, y_offs) \
14 (textureOffset(flow_tex, tc, ivec2((x_offs), (y_offs))).xy + \
15 textureOffset(diff_flow_tex, tc, ivec2((x_offs), (y_offs))).xy)
17 float diffusivity(float u_x, float u_y, float v_x, float v_y)
19 return alpha * inversesqrt(u_x * u_x + u_y * u_y + v_x * v_x + v_y * v_y + eps_sq);
24 float g, g_right, g_up;
26 // These are shared between some of the diffusivities.
27 vec2 flow_0_0 = get_flow(0, 0);
28 vec2 flow_1_1 = get_flow(1, 1);
30 // Find diffusivity (g) for this pixel, using central differences.
32 vec2 uv_x = get_flow(1, 0) - get_flow(-1, 0);
33 vec2 uv_y = get_flow(0, 1) - get_flow( 0, -1);
34 g = diffusivity(uv_x.x, uv_y.x, uv_x.y, uv_y.y);
37 // Now find diffusivity for the pixel to the right.
39 vec2 uv_x = get_flow(2, 0) - flow_0_0;
40 vec2 uv_y = flow_1_1 - get_flow( 1, -1);
41 g_right = diffusivity(uv_x.x, uv_y.x, uv_x.y, uv_y.y);
46 vec2 uv_x = flow_1_1 - get_flow(-1, 1);
47 vec2 uv_y = get_flow(0, 2) - flow_0_0;
48 g_up = diffusivity(uv_x.x, uv_y.x, uv_x.y, uv_y.y);
51 smoothness_x = 0.5 * (g + g_right);
52 smoothness_y = 0.5 * (g + g_up);