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
72 lines
2.2 KiB
C++
72 lines
2.2 KiB
C++
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#include "BLI_assert.h"
|
|
#include "BLI_math_vector_types.hh"
|
|
|
|
#include "COM_input_single_value_operation.hh"
|
|
#include "COM_operation.hh"
|
|
#include "COM_result.hh"
|
|
#include "COM_utilities.hh"
|
|
|
|
namespace blender::compositor {
|
|
|
|
const StringRef InputSingleValueOperation::output_identifier_ = StringRef("Output");
|
|
|
|
InputSingleValueOperation::InputSingleValueOperation(Context &context, DInputSocket input_socket)
|
|
: Operation(context), input_socket_(input_socket)
|
|
{
|
|
const ResultType result_type = get_node_socket_result_type(input_socket_.bsocket());
|
|
Result result = context.create_result(result_type);
|
|
|
|
/* The result of an input single value operation is guaranteed to have a single user. */
|
|
result.set_initial_reference_count(1);
|
|
|
|
populate_result(result);
|
|
}
|
|
|
|
void InputSingleValueOperation::execute()
|
|
{
|
|
/* Allocate a single value for the result. */
|
|
Result &result = get_result();
|
|
result.allocate_single_value();
|
|
|
|
const bNodeSocket *bsocket = input_socket_.bsocket();
|
|
|
|
/* Set the value of the result to the default value of the input socket. */
|
|
switch (result.type()) {
|
|
case ResultType::Float:
|
|
result.set_single_value(bsocket->default_value_typed<bNodeSocketValueFloat>()->value);
|
|
break;
|
|
case ResultType::Int:
|
|
result.set_single_value(bsocket->default_value_typed<bNodeSocketValueInt>()->value);
|
|
break;
|
|
case ResultType::Vector:
|
|
result.set_single_value(
|
|
float4(float3(bsocket->default_value_typed<bNodeSocketValueVector>()->value), 0.0f));
|
|
break;
|
|
case ResultType::Color:
|
|
result.set_single_value(float4(bsocket->default_value_typed<bNodeSocketValueRGBA>()->value));
|
|
break;
|
|
case ResultType::Float2:
|
|
case ResultType::Float3:
|
|
case ResultType::Int2:
|
|
/* Those types are internal and needn't be handled by operations. */
|
|
BLI_assert_unreachable();
|
|
break;
|
|
}
|
|
}
|
|
|
|
Result &InputSingleValueOperation::get_result()
|
|
{
|
|
return Operation::get_result(output_identifier_);
|
|
}
|
|
|
|
void InputSingleValueOperation::populate_result(Result result)
|
|
{
|
|
Operation::populate_result(output_identifier_, result);
|
|
}
|
|
|
|
} // namespace blender::compositor
|