From 41ba876d788e858166b3bdf9e4886c546512c34c Mon Sep 17 00:00:00 2001 From: Omar Emara Date: Thu, 4 Jan 2024 17:05:58 +0200 Subject: [PATCH] Fix: Compositor Texture node ignores Z component The compositor Texture node ignores the Z component. Fix that by defaulting to zero Z and considering the offset and scale in the node. --- .../cached_resources/COM_cached_texture.hh | 14 +++++++------- .../cached_resources/intern/cached_texture.cc | 14 +++++++------- .../composite/nodes/node_composite_texture.cc | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/source/blender/compositor/realtime_compositor/cached_resources/COM_cached_texture.hh b/source/blender/compositor/realtime_compositor/cached_resources/COM_cached_texture.hh index d0a7d71b730..5b6ef90f8c6 100644 --- a/source/blender/compositor/realtime_compositor/cached_resources/COM_cached_texture.hh +++ b/source/blender/compositor/realtime_compositor/cached_resources/COM_cached_texture.hh @@ -27,10 +27,10 @@ class Context; class CachedTextureKey { public: int2 size; - float2 offset; - float2 scale; + float3 offset; + float3 scale; - CachedTextureKey(int2 size, float2 offset, float2 scale); + CachedTextureKey(int2 size, float3 offset, float3 scale); uint64_t hash() const; }; @@ -52,8 +52,8 @@ class CachedTexture : public CachedResource { Tex *texture, bool use_color_management, int2 size, - float2 offset, - float2 scale); + float3 offset, + float3 scale); ~CachedTexture(); @@ -82,8 +82,8 @@ class CachedTextureContainer : CachedResourceContainer { Tex *texture, bool use_color_management, int2 size, - float2 offset, - float2 scale); + float3 offset, + float3 scale); }; } // namespace blender::realtime_compositor diff --git a/source/blender/compositor/realtime_compositor/cached_resources/intern/cached_texture.cc b/source/blender/compositor/realtime_compositor/cached_resources/intern/cached_texture.cc index 0a455b8291f..c9e93f18e9f 100644 --- a/source/blender/compositor/realtime_compositor/cached_resources/intern/cached_texture.cc +++ b/source/blender/compositor/realtime_compositor/cached_resources/intern/cached_texture.cc @@ -32,7 +32,7 @@ namespace blender::realtime_compositor { * Cached Texture Key. */ -CachedTextureKey::CachedTextureKey(int2 size, float2 offset, float2 scale) +CachedTextureKey::CachedTextureKey(int2 size, float3 offset, float3 scale) : size(size), offset(offset), scale(scale) { } @@ -55,8 +55,8 @@ CachedTexture::CachedTexture(Context &context, Tex *texture, bool use_color_management, int2 size, - float2 offset, - float2 scale) + float3 offset, + float3 scale) { ImagePool *image_pool = BKE_image_pool_new(); BKE_texture_fetch_images_for_pool(texture, image_pool); @@ -68,9 +68,9 @@ CachedTexture::CachedTexture(Context &context, for (const int64_t x : IndexRange(size.x)) { /* Compute the coordinates in the [-1, 1] range and add 0.5 to evaluate the texture at the * center of pixels in case it was interpolated. */ - float2 coordinates = ((float2(x, y) + 0.5f) / float2(size)) * 2.0f - 1.0f; + const float2 pixel_coordinates = ((float2(x, y) + 0.5f) / float2(size)) * 2.0f - 1.0f; /* Note that it is expected that the offset is scaled by the scale. */ - coordinates = (coordinates + offset) * scale; + const float3 coordinates = (float3(pixel_coordinates, 0.0f) + offset) * scale; TexResult texture_result; BKE_texture_get_value_ex( texture, coordinates, &texture_result, image_pool, use_color_management); @@ -152,8 +152,8 @@ CachedTexture &CachedTextureContainer::get(Context &context, Tex *texture, bool use_color_management, int2 size, - float2 offset, - float2 scale) + float3 offset, + float3 scale) { const CachedTextureKey key(size, offset, scale); diff --git a/source/blender/nodes/composite/nodes/node_composite_texture.cc b/source/blender/nodes/composite/nodes/node_composite_texture.cc index 4d0391f228c..3b9fa48ec43 100644 --- a/source/blender/nodes/composite/nodes/node_composite_texture.cc +++ b/source/blender/nodes/composite/nodes/node_composite_texture.cc @@ -59,8 +59,8 @@ class TextureOperation : public NodeOperation { get_texture(), true, domain.size, - get_input("Offset").get_vector_value_default(float4(0.0f)).xy(), - get_input("Scale").get_vector_value_default(float4(0.0f)).xy()); + get_input("Offset").get_vector_value_default(float4(0.0f)).xyz(), + get_input("Scale").get_vector_value_default(float4(1.0f)).xyz()); if (color_result.should_compute()) { color_result.wrap_external(cached_texture.color_texture());