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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Bakker <jeroen@blender.org>2022-01-31 11:57:51 +0300
committerJeroen Bakker <jeroen@blender.org>2022-01-31 11:57:51 +0300
commitcfa235b89d686e00456e6d7af99442e5a73ffed8 (patch)
tree10c6bc17f305fc0b384fca8eb93c1445db525538 /source/blender/draw/engines/image/shaders
parent07514def194a78fbb70931d5fbd002248e8f3c34 (diff)
Image Editor: Fix background drawing of empty tiles.
Empty (UDIM) tiles where drawn with a transparency checkerboard. They should be rendered with a border background. The cause is that the image engine would select a single area that contained all tiles and draw them as being part of an image. The fix is to separate the color and depth part of the image engine shader and only draw the depths of tiles that are enabled.
Diffstat (limited to 'source/blender/draw/engines/image/shaders')
-rw-r--r--source/blender/draw/engines/image/shaders/image_engine_color_frag.glsl33
-rw-r--r--source/blender/draw/engines/image/shaders/image_engine_color_vert.glsl (renamed from source/blender/draw/engines/image/shaders/image_engine_vert.glsl)1
-rw-r--r--source/blender/draw/engines/image/shaders/image_engine_depth_frag.glsl16
-rw-r--r--source/blender/draw/engines/image/shaders/image_engine_depth_vert.glsl11
-rw-r--r--source/blender/draw/engines/image/shaders/image_engine_frag.glsl45
-rw-r--r--source/blender/draw/engines/image/shaders/infos/engine_image_info.hh26
6 files changed, 77 insertions, 55 deletions
diff --git a/source/blender/draw/engines/image/shaders/image_engine_color_frag.glsl b/source/blender/draw/engines/image/shaders/image_engine_color_frag.glsl
new file mode 100644
index 00000000000..fbb624e54ba
--- /dev/null
+++ b/source/blender/draw/engines/image/shaders/image_engine_color_frag.glsl
@@ -0,0 +1,33 @@
+#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)
+
+#define FAR_DISTANCE farNearDistances.x
+#define NEAR_DISTANCE farNearDistances.y
+
+void main()
+{
+ ivec2 uvs_clamped = ivec2(uv_screen);
+ vec4 tex_color = texelFetch(imageTexture, uvs_clamped, 0);
+
+ 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 = vec4(dot(tex_color, shuffle));
+ }
+ if ((drawFlags & IMAGE_DRAW_FLAG_SHOW_ALPHA) == 0) {
+ tex_color.a = 1.0;
+ }
+ fragColor = tex_color;
+}
diff --git a/source/blender/draw/engines/image/shaders/image_engine_vert.glsl b/source/blender/draw/engines/image/shaders/image_engine_color_vert.glsl
index deefab655d2..fb72a132613 100644
--- a/source/blender/draw/engines/image/shaders/image_engine_vert.glsl
+++ b/source/blender/draw/engines/image/shaders/image_engine_color_vert.glsl
@@ -4,7 +4,6 @@ void main()
{
vec3 image_pos = vec3(pos, 0.0);
uv_screen = image_pos.xy;
- uv_image = uv;
vec3 world_pos = point_object_to_world(image_pos);
vec4 position = point_world_to_ndc(world_pos);
diff --git a/source/blender/draw/engines/image/shaders/image_engine_depth_frag.glsl b/source/blender/draw/engines/image/shaders/image_engine_depth_frag.glsl
new file mode 100644
index 00000000000..88610fb97fd
--- /dev/null
+++ b/source/blender/draw/engines/image/shaders/image_engine_depth_frag.glsl
@@ -0,0 +1,16 @@
+#pragma BLENDER_REQUIRE(common_colormanagement_lib.glsl)
+
+#define Z_DEPTH_BORDER 1.0
+#define Z_DEPTH_IMAGE 0.75
+
+bool is_border(vec2 uv)
+{
+ return (uv.x < min_max_uv.x || uv.y < min_max_uv.y || uv.x >= min_max_uv.z ||
+ uv.y >= min_max_uv.w);
+}
+
+void main()
+{
+ bool border = is_border(uv_image);
+ gl_FragDepth = border ? Z_DEPTH_BORDER : Z_DEPTH_IMAGE;
+}
diff --git a/source/blender/draw/engines/image/shaders/image_engine_depth_vert.glsl b/source/blender/draw/engines/image/shaders/image_engine_depth_vert.glsl
new file mode 100644
index 00000000000..3181a85ff55
--- /dev/null
+++ b/source/blender/draw/engines/image/shaders/image_engine_depth_vert.glsl
@@ -0,0 +1,11 @@
+#pragma BLENDER_REQUIRE(common_view_lib.glsl)
+
+void main()
+{
+ vec3 image_pos = vec3(pos, 0.0);
+ uv_image = uv;
+
+ vec3 world_pos = point_object_to_world(image_pos);
+ vec4 position = point_world_to_ndc(world_pos);
+ gl_Position = position;
+}
diff --git a/source/blender/draw/engines/image/shaders/image_engine_frag.glsl b/source/blender/draw/engines/image/shaders/image_engine_frag.glsl
deleted file mode 100644
index b0ac7af457f..00000000000
--- a/source/blender/draw/engines/image/shaders/image_engine_frag.glsl
+++ /dev/null
@@ -1,45 +0,0 @@
-#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)
-
-#define Z_DEPTH_BORDER 1.0
-#define Z_DEPTH_IMAGE 0.75
-
-#define FAR_DISTANCE farNearDistances.x
-#define NEAR_DISTANCE farNearDistances.y
-
-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 = vec4(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;
-}
diff --git a/source/blender/draw/engines/image/shaders/infos/engine_image_info.hh b/source/blender/draw/engines/image/shaders/infos/engine_image_info.hh
index 1dd20a9a95b..86a79d13e40 100644
--- a/source/blender/draw/engines/image/shaders/infos/engine_image_info.hh
+++ b/source/blender/draw/engines/image/shaders/infos/engine_image_info.hh
@@ -1,21 +1,29 @@
#include "gpu_shader_create_info.hh"
-GPU_SHADER_INTERFACE_INFO(image_engine_iface, "")
- .smooth(Type::VEC2, "uv_screen")
- .smooth(Type::VEC2, "uv_image");
+GPU_SHADER_INTERFACE_INFO(image_engine_color_iface, "").smooth(Type::VEC2, "uv_screen");
-GPU_SHADER_CREATE_INFO(image_engine_shader)
+GPU_SHADER_CREATE_INFO(image_engine_color_shader)
.vertex_in(0, Type::VEC2, "pos")
- .vertex_in(1, Type::VEC2, "uv")
- .vertex_out(image_engine_iface)
+ .vertex_out(image_engine_color_iface)
.fragment_out(0, Type::VEC4, "fragColor")
.push_constant(Type::VEC4, "shuffle")
- .push_constant(Type::VEC2, "maxUv")
.push_constant(Type::VEC2, "farNearDistances")
.push_constant(Type::INT, "drawFlags")
.push_constant(Type::BOOL, "imgPremultiplied")
.sampler(0, ImageType::FLOAT_2D, "imageTexture")
- .vertex_source("image_engine_vert.glsl")
- .fragment_source("image_engine_frag.glsl")
+ .vertex_source("image_engine_color_vert.glsl")
+ .fragment_source("image_engine_color_frag.glsl")
+ .additional_info("draw_modelmat")
+ .do_static_compilation(true);
+
+GPU_SHADER_INTERFACE_INFO(image_engine_depth_iface, "").smooth(Type::VEC2, "uv_image");
+
+GPU_SHADER_CREATE_INFO(image_engine_depth_shader)
+ .vertex_in(0, Type::VEC2, "pos")
+ .vertex_in(1, Type::VEC2, "uv")
+ .vertex_out(image_engine_depth_iface)
+ .push_constant(Type::VEC4, "min_max_uv")
+ .vertex_source("image_engine_depth_vert.glsl")
+ .fragment_source("image_engine_depth_frag.glsl")
.additional_info("draw_modelmat")
.do_static_compilation(true);