2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2022-08-10 09:14:22 +02:00
|
|
|
|
2023-09-25 15:12:52 +02:00
|
|
|
#include "BLI_assert.h"
|
2023-01-04 00:14:55 +01:00
|
|
|
#include "BLI_math_vector_types.hh"
|
2022-08-10 09:14:22 +02:00
|
|
|
|
2025-03-20 12:19:43 +02:00
|
|
|
#include "DNA_node_types.h"
|
|
|
|
|
|
2022-08-10 09:14:22 +02:00
|
|
|
#include "COM_input_single_value_operation.hh"
|
|
|
|
|
#include "COM_operation.hh"
|
|
|
|
|
#include "COM_result.hh"
|
|
|
|
|
#include "COM_utilities.hh"
|
|
|
|
|
|
2024-12-17 11:39:04 +01:00
|
|
|
namespace blender::compositor {
|
2022-08-10 09:14:22 +02:00
|
|
|
|
|
|
|
|
const StringRef InputSingleValueOperation::output_identifier_ = StringRef("Output");
|
|
|
|
|
|
|
|
|
|
InputSingleValueOperation::InputSingleValueOperation(Context &context, DInputSocket input_socket)
|
|
|
|
|
: Operation(context), input_socket_(input_socket)
|
|
|
|
|
{
|
2022-08-31 12:15:57 +02:00
|
|
|
const ResultType result_type = get_node_socket_result_type(input_socket_.bsocket());
|
2025-03-20 12:19:43 +02:00
|
|
|
this->populate_result(context.create_result(result_type));
|
2022-08-10 09:14:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InputSingleValueOperation::execute()
|
|
|
|
|
{
|
2025-03-20 12:19:43 +02:00
|
|
|
Result &result = this->get_result();
|
2022-08-10 09:14:22 +02:00
|
|
|
result.allocate_single_value();
|
|
|
|
|
|
2025-03-20 12:19:43 +02:00
|
|
|
switch (input_socket_->type) {
|
|
|
|
|
case SOCK_FLOAT: {
|
|
|
|
|
const float value = input_socket_->default_value_typed<bNodeSocketValueFloat>()->value;
|
|
|
|
|
result.set_single_value(value);
|
Compositor: Support node integer sockets
This patch adds support for using integer sockets in compositor nodes.
This involves updating the Result class, node tree compiler, implicit
conversion operation, multi-function procedure operation, shader
operation, and some operations that supports multiple types.
Shader operation internally treats integers as floats, doing conversion
to and from int when reading and writing. That's because the GPUMaterial
compiler doesn't support integers. This is also the same workaround used
by the shader system. Though the GPU module are eyeing adding support
for integers, so we will update the code once they do that.
Domain realization is not yet supported for integer types, but this is
an internal limitation so far, as we do not plan to add nodes that
outputs integers soon. We are not yet sure how realization should happen
with regards to interpolation and we do not have base functions to
sample integer images, that's why I decided to delay its implementation
when it is actually needed.
Pull Request: https://projects.blender.org/blender/blender/pulls/132599
2025-01-06 10:09:26 +01:00
|
|
|
break;
|
2025-03-20 12:19:43 +02:00
|
|
|
}
|
|
|
|
|
case SOCK_INT: {
|
|
|
|
|
const int value = input_socket_->default_value_typed<bNodeSocketValueInt>()->value;
|
|
|
|
|
result.set_single_value(value);
|
2022-08-10 09:14:22 +02:00
|
|
|
break;
|
2025-03-20 12:19:43 +02:00
|
|
|
}
|
2025-03-21 12:03:09 +01:00
|
|
|
case SOCK_BOOLEAN: {
|
|
|
|
|
const bool value = input_socket_->default_value_typed<bNodeSocketValueBoolean>()->value;
|
|
|
|
|
result.set_single_value(value);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2025-03-20 12:19:43 +02:00
|
|
|
case SOCK_VECTOR: {
|
2025-06-23 14:34:37 +02:00
|
|
|
switch (input_socket_->default_value_typed<bNodeSocketValueVector>()->dimensions) {
|
|
|
|
|
case 2: {
|
|
|
|
|
const float2 value = input_socket_->default_value_typed<bNodeSocketValueVector>()->value;
|
|
|
|
|
result.set_single_value(value);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 3: {
|
|
|
|
|
const float3 value = input_socket_->default_value_typed<bNodeSocketValueVector>()->value;
|
|
|
|
|
result.set_single_value(value);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 4: {
|
|
|
|
|
const float4 value = input_socket_->default_value_typed<bNodeSocketValueVector>()->value;
|
|
|
|
|
result.set_single_value(value);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
BLI_assert_unreachable();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-08-10 09:14:22 +02:00
|
|
|
break;
|
2025-03-20 12:19:43 +02:00
|
|
|
}
|
|
|
|
|
case SOCK_RGBA: {
|
|
|
|
|
const float4 value = input_socket_->default_value_typed<bNodeSocketValueRGBA>()->value;
|
|
|
|
|
result.set_single_value(value);
|
2025-02-20 10:38:40 +01:00
|
|
|
break;
|
2025-03-20 12:19:43 +02:00
|
|
|
}
|
2025-07-18 11:08:30 +02:00
|
|
|
case SOCK_MENU: {
|
|
|
|
|
const int32_t value = input_socket_->default_value_typed<bNodeSocketValueMenu>()->value;
|
|
|
|
|
result.set_single_value(value);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2025-03-20 12:19:43 +02:00
|
|
|
default:
|
2023-09-25 15:12:52 +02:00
|
|
|
BLI_assert_unreachable();
|
|
|
|
|
break;
|
2022-08-10 09:14:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Result &InputSingleValueOperation::get_result()
|
|
|
|
|
{
|
|
|
|
|
return Operation::get_result(output_identifier_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InputSingleValueOperation::populate_result(Result result)
|
|
|
|
|
{
|
|
|
|
|
Operation::populate_result(output_identifier_, result);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-17 11:39:04 +01:00
|
|
|
} // namespace blender::compositor
|