[Bf-blender-cvs] [7ccb299fb7d] temp-image-engine: Make sure textures are drawn in the right place.
Jeroen Bakker
noreply at git.blender.org
Wed Dec 7 14:28:45 CET 2022
Commit: 7ccb299fb7d17b13d7519cbe8eb15f43cefa1b7e
Author: Jeroen Bakker
Date: Wed Dec 7 08:28:26 2022 +0100
Branches: temp-image-engine
https://developer.blender.org/rB7ccb299fb7d17b13d7519cbe8eb15f43cefa1b7e
Make sure textures are drawn in the right place.
===================================================================
M source/blender/draw/engines/image/image_drawing_mode.hh
M source/blender/draw/engines/image/image_texture_info.hh
M source/blender/draw/engines/image/shaders/image_engine_color_frag.glsl
M source/blender/draw/engines/image/shaders/infos/engine_image_info.hh
===================================================================
diff --git a/source/blender/draw/engines/image/image_drawing_mode.hh b/source/blender/draw/engines/image/image_drawing_mode.hh
index fab1a046d49..15c8600a5cb 100644
--- a/source/blender/draw/engines/image/image_drawing_mode.hh
+++ b/source/blender/draw/engines/image/image_drawing_mode.hh
@@ -95,8 +95,6 @@ struct FullScreenTextures {
instance_data->texture_infos[1].dirty = true;
instance_data->texture_infos[2].dirty = true;
instance_data->texture_infos[3].dirty = true;
-
- instance_data->texture_infos[0].print_debug();
}
};
@@ -141,6 +139,7 @@ template<typename TextureMethod> class ScreenSpaceDrawingMode : public AbstractD
}
DRWShadingGroup *shgrp_sub = DRW_shgroup_create_sub(shgrp);
+ DRW_shgroup_uniform_ivec2_copy(shgrp_sub, "offset", info.offset());
DRW_shgroup_uniform_texture_ex(shgrp_sub, "imageTexture", info.texture, GPU_SAMPLER_DEFAULT);
DRW_shgroup_call_obmat(shgrp_sub, info.batch, image_mat);
}
@@ -466,10 +465,6 @@ template<typename TextureMethod> class ScreenSpaceDrawingMode : public AbstractD
BLI_rctf_transform_calc_m4_pivot_min(&tile_area, &texture_area, uv_to_texel.ptr());
invert_m4(uv_to_texel.ptr());
- print_rctf_id(&tile_area);
- print_rctf_id(&texture_area);
- print_m4_id(uv_to_texel.ptr());
-
rctf crop_rect;
rctf *crop_rect_ptr = nullptr;
eIMBTransformMode transform_mode;
@@ -482,8 +477,6 @@ template<typename TextureMethod> class ScreenSpaceDrawingMode : public AbstractD
transform_mode = IMB_TRANSFORM_MODE_CROP_SRC;
}
- // transform_mode = IMB_TRANSFORM_MODE_REGULAR;
-
IMB_transform(float_tile_buffer,
&texture_buffer,
transform_mode,
@@ -509,7 +502,6 @@ template<typename TextureMethod> class ScreenSpaceDrawingMode : public AbstractD
instance_data->partial_update.ensure_image(image);
instance_data->clear_dirty_flag();
instance_data->float_buffers.reset_usage_flags();
- printf("\n");
/* Step: Find out which screen space textures are needed to draw on the screen. Remove the
* screen space textures that aren't needed. */
diff --git a/source/blender/draw/engines/image/image_texture_info.hh b/source/blender/draw/engines/image/image_texture_info.hh
index ced1af0d945..6b30f4e0e07 100644
--- a/source/blender/draw/engines/image/image_texture_info.hh
+++ b/source/blender/draw/engines/image/image_texture_info.hh
@@ -7,6 +7,7 @@
#pragma once
+#include "BLI_math_vec_types.hh"
#include "BLI_rect.h"
#include "GPU_batch.h"
@@ -61,6 +62,17 @@ struct TextureInfo {
}
}
+ /**
+ * \brief return the offset of the texture with the area.
+ *
+ * A texture covers only a part of the area. The offset if the offset in screen coordinates
+ * between the area and the part that the texture covers.
+ */
+ int2 offset() const
+ {
+ return int2(clipping_bounds.xmin, clipping_bounds.ymin);
+ }
+
void print_debug()
{
print_rctf_id(&clipping_bounds);
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
index 0edc18836f0..23c2c1c2685 100644
--- a/source/blender/draw/engines/image/shaders/image_engine_color_frag.glsl
+++ b/source/blender/draw/engines/image/shaders/image_engine_color_frag.glsl
@@ -17,7 +17,7 @@ void main()
discard;
}
- vec4 tex_color = texelFetch(imageTexture, uvs_clamped, 0);
+ vec4 tex_color = texelFetch(imageTexture, uvs_clamped - offset, 0);
if ((drawFlags & IMAGE_DRAW_FLAG_APPLY_ALPHA) != 0) {
if (!imgPremultiplied) {
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 4ab714e0689..3e6673b79a2 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
@@ -10,6 +10,7 @@ GPU_SHADER_CREATE_INFO(image_engine_color_shader)
.fragment_out(0, Type::VEC4, "fragColor")
.push_constant(Type::VEC4, "shuffle")
.push_constant(Type::VEC2, "farNearDistances")
+ .push_constant(Type::IVEC2, "offset")
.push_constant(Type::INT, "drawFlags")
.push_constant(Type::BOOL, "imgPremultiplied")
.sampler(0, ImageType::FLOAT_2D, "imageTexture")
More information about the Bf-blender-cvs
mailing list