Welcome to mirror list, hosted at ThFree Co, Russian Federation.

compositor_edge_filter.glsl « compositor « shaders « gpu « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 67e27c2260227d124abb36fa0f06e7ee87d7f32e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#pragma BLENDER_REQUIRE(gpu_shader_compositor_texture_utilities.glsl)

void main()
{
  ivec2 texel = ivec2(gl_GlobalInvocationID.xy);

  /* Compute the dot product between the 3x3 window around the pixel and the edge detection kernel
   * in the X direction and Y direction. The Y direction kernel is computed by transposing the
   * given X direction kernel. */
  vec3 color_x = vec3(0);
  vec3 color_y = vec3(0);
  for (int j = 0; j < 3; j++) {
    for (int i = 0; i < 3; i++) {
      vec3 color = texture_load(input_tx, texel + ivec2(i - 1, j - 1)).rgb;
      color_x += color * kernel[j][i];
      color_y += color * kernel[i][j];
    }
  }

  /* Compute the channel-wise magnitude of the 2D vector composed from the X and Y edge detection
   * filter results. */
  vec3 magnitude = sqrt(color_x * color_x + color_y * color_y);

  /* Mix the channel-wise magnitude with the original color at the center of the kernel using the
   * input factor. */
  vec4 color = texture_load(input_tx, texel);
  magnitude = mix(color.rgb, magnitude, texture_load(factor_tx, texel).x);

  /* Store the channel-wise magnitude with the original alpha of the input. */
  imageStore(output_img, texel, vec4(magnitude, color.a));
}