Image editor: Fix drawing artifacts with render results.

Use the input depth texture to determine if the color of the texture
should be shown.
This commit is contained in:
Jeroen Bakker 2022-01-31 11:59:16 +01:00
parent dfc959eed6
commit 869180548c
Notes: blender-bot 2023-02-14 08:58:01 +01:00
Referenced by issue #96097, Image, UV Editor: Repeat image not working.
3 changed files with 16 additions and 1 deletions

View File

@ -99,12 +99,14 @@ template<typename TextureMethod> class ScreenSpaceDrawingMode : public AbstractD
{
const ShaderParameters &sh_params = instance_data->sh_params;
GPUShader *shader = IMAGE_shader_image_get();
DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
DRWShadingGroup *shgrp = DRW_shgroup_create(shader, instance_data->passes.image_pass);
DRW_shgroup_uniform_vec2_copy(shgrp, "farNearDistances", sh_params.far_near);
DRW_shgroup_uniform_vec4_copy(shgrp, "shuffle", sh_params.shuffle);
DRW_shgroup_uniform_int_copy(shgrp, "drawFlags", sh_params.flags);
DRW_shgroup_uniform_bool_copy(shgrp, "imgPremultiplied", sh_params.use_premul_alpha);
DRW_shgroup_uniform_texture(shgrp, "depth_texture", dtxl->depth);
float image_mat[4][4];
unit_m4(image_mat);
for (int i = 0; i < SCREEN_SPACE_DRAWING_MODE_TEXTURE_LEN; i++) {
@ -151,9 +153,14 @@ template<typename TextureMethod> class ScreenSpaceDrawingMode : public AbstractD
const int tile_y = image_tile.get_tile_y_offset();
tile_user.tile = image_tile.get_tile_number();
if (!BKE_image_has_ibuf(image, &tile_user)) {
/* NOTE: `BKE_image_has_ibuf` doesn't work as it fails for render results. That could be a
* bug or a feature. For now we just acquire to determine if there is a texture. */
void *lock;
ImBuf *tile_buffer = BKE_image_acquire_ibuf(image, &tile_user, &lock);
if (tile_buffer == nullptr) {
continue;
}
BKE_image_release_ibuf(image, tile_buffer, lock);
DRWShadingGroup *shsub = DRW_shgroup_create_sub(shgrp);
float4 min_max_uv(tile_x, tile_y, tile_x + 1, tile_y + 1);
@ -461,8 +468,10 @@ template<typename TextureMethod> class ScreenSpaceDrawingMode : public AbstractD
DRW_view_set_active(instance_data->view);
DRW_draw_pass(instance_data->passes.depth_pass);
GPU_framebuffer_bind(dfbl->color_only_fb);
DRW_draw_pass(instance_data->passes.image_pass);
DRW_view_set_active(nullptr);
GPU_framebuffer_bind(dfbl->default_fb);
}
}; // namespace clipping

View File

@ -12,6 +12,11 @@
void main()
{
ivec2 uvs_clamped = ivec2(uv_screen);
float depth = texelFetch(depth_texture, uvs_clamped, 0).r;
if (depth == 1.0) {
discard;
}
vec4 tex_color = texelFetch(imageTexture, uvs_clamped, 0);
if ((drawFlags & IMAGE_DRAW_FLAG_APPLY_ALPHA) != 0) {

View File

@ -11,6 +11,7 @@ GPU_SHADER_CREATE_INFO(image_engine_color_shader)
.push_constant(Type::INT, "drawFlags")
.push_constant(Type::BOOL, "imgPremultiplied")
.sampler(0, ImageType::FLOAT_2D, "imageTexture")
.sampler(1, ImageType::DEPTH_2D, "depth_texture")
.vertex_source("image_engine_color_vert.glsl")
.fragment_source("image_engine_color_frag.glsl")
.additional_info("draw_modelmat")