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

engine_image_frag.glsl « shaders « image « engines « draw « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 298487baab243b301d4af993d0519a0196004be6 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma BLENDER_REQUIRE(common_colormanagement_lib.glsl)

/* Keep in sync with image_engine.c */
#define IMAGE_DRAW_FLAG_SHOW_ALPHA (1 << 0)
#define IMAGE_DRAW_FLAG_APPLY_ALPHA (1 << 1)
#define IMAGE_DRAW_FLAG_SHUFFLING (1 << 2)
#define IMAGE_DRAW_FLAG_DEPTH (1 << 3)

uniform sampler2D imageTexture;

uniform bool imgPremultiplied;
uniform int drawFlags;
uniform vec2 farNearDistances;
uniform vec4 color;
uniform vec4 shuffle;

/* Maximum UV range.
 * Negative UV coordinates and UV coordinates beyond maxUV would draw a border. */
uniform vec2 maxUv;

#define FAR_DISTANCE farNearDistances.x
#define NEAR_DISTANCE farNearDistances.y

#define Z_DEPTH_BORDER 1.0
#define Z_DEPTH_IMAGE 0.75

in vec2 uv_screen;
in vec2 uv_image;

out vec4 fragColor;

bool is_border(vec2 uv)
{
  return (uv.x < 0.0 || uv.y < 0.0 || uv.x > maxUv.x || uv.y > maxUv.y);
}

void main()
{
  ivec2 uvs_clamped = ivec2(uv_screen);
  vec4 tex_color = texelFetch(imageTexture, uvs_clamped, 0);

  bool border = is_border(uv_image);
  if (!border) {
    if ((drawFlags & IMAGE_DRAW_FLAG_APPLY_ALPHA) != 0) {
      if (!imgPremultiplied) {
        tex_color.rgb *= tex_color.a;
      }
    }
    if ((drawFlags & IMAGE_DRAW_FLAG_DEPTH) != 0) {
      tex_color = smoothstep(FAR_DISTANCE, NEAR_DISTANCE, tex_color);
    }

    if ((drawFlags & IMAGE_DRAW_FLAG_SHUFFLING) != 0) {
      tex_color = color * dot(tex_color, shuffle);
    }
    if ((drawFlags & IMAGE_DRAW_FLAG_SHOW_ALPHA) == 0) {
      tex_color.a = 1.0;
    }
  }
  fragColor = tex_color;
  gl_FragDepth = border ? Z_DEPTH_BORDER : Z_DEPTH_IMAGE;
}