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:
authorHabib Gahbiche <zazizizou>2022-03-17 01:27:52 +0300
committerHabib Gahbiche <habibgahbiche@gmail.com>2022-03-17 01:28:36 +0300
commit33409f9f1cd42e899f2706fe7878e5e89b50d617 (patch)
tree1b33eac06e04867add023aa5e88c8cf577e5dc01 /source/blender/draw/engines/image
parent22de21bef1a31718d45e89aedc574055a5983b7d (diff)
Compositor: Support backdrop offset for the Viewer node
This is only part of the experimental "Full Frame" mode (disabled by default). See T88150. Currently the viewer node uses buffer paddings to display image offset in the backdrop as a temporal solution implemented for {D12466}. This solution is inefficient memory and performance-wise. Another issue is that the paddings are part the image when saved. This patch instead sets the offset in the Viewer node image as variables and makes the backdrop take it into account when drawing the image or any related gizmo. Reviewed By: jbakker Differential Revision: https://developer.blender.org/D12750
Diffstat (limited to 'source/blender/draw/engines/image')
-rw-r--r--source/blender/draw/engines/image/image_drawing_mode.hh1
-rw-r--r--source/blender/draw/engines/image/image_engine.cc7
-rw-r--r--source/blender/draw/engines/image/image_instance_data.hh2
-rw-r--r--source/blender/draw/engines/image/image_space.hh1
-rw-r--r--source/blender/draw/engines/image/image_space_image.hh33
-rw-r--r--source/blender/draw/engines/image/image_space_node.hh9
6 files changed, 33 insertions, 20 deletions
diff --git a/source/blender/draw/engines/image/image_drawing_mode.hh b/source/blender/draw/engines/image/image_drawing_mode.hh
index 46482ab6668..af3ec24d085 100644
--- a/source/blender/draw/engines/image/image_drawing_mode.hh
+++ b/source/blender/draw/engines/image/image_drawing_mode.hh
@@ -129,7 +129,6 @@ template<typename TextureMethod> class ScreenSpaceDrawingMode : public AbstractD
{
GPUShader *shader = IMAGE_shader_depth_get();
DRWShadingGroup *shgrp = DRW_shgroup_create(shader, instance_data.passes.depth_pass);
-
float image_mat[4][4];
unit_m4(image_mat);
diff --git a/source/blender/draw/engines/image/image_engine.cc b/source/blender/draw/engines/image/image_engine.cc
index e972d21cda4..09efaea3e71 100644
--- a/source/blender/draw/engines/image/image_engine.cc
+++ b/source/blender/draw/engines/image/image_engine.cc
@@ -99,8 +99,11 @@ class ImageEngine {
/* Setup the matrix to go from screen UV coordinates to UV texture space coordinates. */
float image_resolution[2] = {image_buffer ? image_buffer->x : 1024.0f,
image_buffer ? image_buffer->y : 1024.0f};
- space->init_ss_to_texture_matrix(
- draw_ctx->region, image_resolution, instance_data->ss_to_texture);
+ float image_display_offset[2] = {(float)instance_data->image->display_offset_x,
+ (float)instance_data->image->display_offset_y};
+ space->init_ss_to_texture_matrix(draw_ctx->region,
+ image_display_offset,
+ image_resolution, instance_data->ss_to_texture);
const Scene *scene = DRW_context_state_get()->scene;
instance_data->sh_params.update(space.get(), scene, instance_data->image, image_buffer);
diff --git a/source/blender/draw/engines/image/image_instance_data.hh b/source/blender/draw/engines/image/image_instance_data.hh
index 682b93a80b3..02ca86312c6 100644
--- a/source/blender/draw/engines/image/image_instance_data.hh
+++ b/source/blender/draw/engines/image/image_instance_data.hh
@@ -21,7 +21,7 @@
/**
* \brief max allowed textures to use by the ScreenSpaceDrawingMode.
*
- * 4 textures are used to reduce uploading screen space textures when translating the image.
+ * 1 texture is used to reduce uploading screen space textures when translating the image.
*/
constexpr int SCREEN_SPACE_DRAWING_MODE_TEXTURE_LEN = 1;
diff --git a/source/blender/draw/engines/image/image_space.hh b/source/blender/draw/engines/image/image_space.hh
index 7a11d14b567..a2f923a7118 100644
--- a/source/blender/draw/engines/image/image_space.hh
+++ b/source/blender/draw/engines/image/image_space.hh
@@ -77,6 +77,7 @@ class AbstractSpaceAccessor {
* (0..1) to texture space UV coordinates.
*/
virtual void init_ss_to_texture_matrix(const ARegion *region,
+ const float image_display_offset[2],
const float image_resolution[2],
float r_uv_to_texture[4][4]) const = 0;
diff --git a/source/blender/draw/engines/image/image_space_image.hh b/source/blender/draw/engines/image/image_space_image.hh
index 40aa117514c..7c15d780d07 100644
--- a/source/blender/draw/engines/image/image_space_image.hh
+++ b/source/blender/draw/engines/image/image_space_image.hh
@@ -148,20 +148,29 @@ class SpaceImageAccessor : public AbstractSpaceAccessor {
}
void init_ss_to_texture_matrix(const ARegion *region,
- const float UNUSED(image_resolution[2]),
+ const float image_display_offset[2],
+ const float image_resolution[2],
float r_uv_to_texture[4][4]) const override
{
- unit_m4(r_uv_to_texture);
- float scale_x = 1.0 / BLI_rctf_size_x(&region->v2d.cur);
- float scale_y = 1.0 / BLI_rctf_size_y(&region->v2d.cur);
- float translate_x = scale_x * -region->v2d.cur.xmin;
- float translate_y = scale_y * -region->v2d.cur.ymin;
-
- r_uv_to_texture[0][0] = scale_x;
- r_uv_to_texture[1][1] = scale_y;
- r_uv_to_texture[3][0] = translate_x;
- r_uv_to_texture[3][1] = translate_y;
- }
+ float zoom_x = image_resolution[0] * sima->zoom;
+ float zoom_y = image_resolution[1] * sima ->zoom;
+ float image_offset_x = (region->winx - zoom_x) / 2 + sima->xof + image_display_offset[0];
+ float image_offset_y = (region->winy - zoom_y) / 2 + sima->yof + image_display_offset[1];
+
+ unit_m4(r_uv_to_texture);
+ float scale_x = 1.0 / BLI_rctf_size_x(&region->v2d.cur);
+ float scale_y = 1.0 / BLI_rctf_size_y(&region->v2d.cur);
+ float offset_x = 1.0 / image_resolution[0] * image_offset_x;
+ float offset_y = 1.0 / image_resolution[1] * image_offset_y;
+
+ float translate_x = scale_x * (-region->v2d.cur.xmin + offset_x);
+ float translate_y = scale_y * (-region->v2d.cur.ymin + offset_y);
+
+ r_uv_to_texture[0][0] = scale_x;
+ r_uv_to_texture[1][1] = scale_y;
+ r_uv_to_texture[3][0] = translate_x;
+ r_uv_to_texture[3][1] = translate_y;
+ }
};
} // namespace blender::draw::image_engine
diff --git a/source/blender/draw/engines/image/image_space_node.hh b/source/blender/draw/engines/image/image_space_node.hh
index 6f38dcb86aa..4057f7b78cf 100644
--- a/source/blender/draw/engines/image/image_space_node.hh
+++ b/source/blender/draw/engines/image/image_space_node.hh
@@ -99,6 +99,7 @@ class SpaceNodeAccessor : public AbstractSpaceAccessor {
* screen.
*/
void init_ss_to_texture_matrix(const ARegion *region,
+ const float image_display_offset[2],
const float image_resolution[2],
float r_uv_to_texture[4][4]) const override
{
@@ -107,10 +108,10 @@ class SpaceNodeAccessor : public AbstractSpaceAccessor {
mul_v2_v2fl(display_resolution, image_resolution, snode->zoom);
const float scale_x = display_resolution[0] / region->winx;
const float scale_y = display_resolution[1] / region->winy;
- const float translate_x = ((region->winx - display_resolution[0]) * 0.5f + snode->xof) /
- region->winx;
- const float translate_y = ((region->winy - display_resolution[1]) * 0.5f + snode->yof) /
- region->winy;
+ const float translate_x = ((region->winx - display_resolution[0]) * 0.5f + snode->xof + image_display_offset[0]) /
+ region->winx ;
+ const float translate_y = ((region->winy - display_resolution[1]) * 0.5f + snode->yof + image_display_offset[1]) /
+ region->winy;
r_uv_to_texture[0][0] = scale_x;
r_uv_to_texture[1][1] = scale_y;