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

gpu_shader_compositor_blur_common.glsl « library « compositor « shaders « gpu « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e404c03bbb0c3a228cfd682227662bf02d373224 (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
32
/* Preprocess the input of the blur filter by squaring it in its alpha straight form, assuming the
 * given color is alpha premultiplied. */
vec4 gamma_correct_blur_input(vec4 color)
{
  /* Unpremultiply alpha. */
  color.rgb /= color.a > 0.0 ? color.a : 1.0;

  /* Square color channel if it is positive, otherwise zero it. */
  color.rgb *= mix(color.rgb, vec3(0.0), lessThan(color.rgb, vec3(0.0)));

  /* Premultiply alpha to undo previous alpha unpremultiplication. */
  color.rgb *= color.a > 0.0 ? color.a : 1.0;

  return color;
}

/* Postprocess the output of the blur filter by taking its square root it in its alpha straight
 * form, assuming the given color is alpha premultiplied. This essential undoes the processing done
 * by the gamma_correct_blur_input function. */
vec4 gamma_uncorrect_blur_output(vec4 color)
{
  /* Unpremultiply alpha. */
  color.rgb /= color.a > 0.0 ? color.a : 1.0;

  /* Take the square root of the color channel if it is positive, otherwise zero it. */
  color.rgb = mix(sqrt(color.rgb), vec3(0.0), lessThan(color.rgb, vec3(0.0)));

  /* Premultiply alpha to undo previous alpha unpremultiplication. */
  color.rgb *= color.a > 0.0 ? color.a : 1.0;

  return color;
}