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.
This commit is contained in:
Omar Emara 2024-01-04 17:05:58 +02:00
parent 29be81ec23
commit 41ba876d78
3 changed files with 16 additions and 16 deletions

View File

@ -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

View File

@ -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);

View File

@ -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());