27 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
28 .compositor_domain_priority(0);
35 .compositor_domain_priority(1);
64 if (this->
context().use_gpu()) {
114 output.allocate_texture(domain);
124 const int x = base_texel.x * 2;
125 const int y = base_texel.y * 2;
128 const int2 lower_right_texel =
int2(
x + 1,
y);
130 const int2 upper_right_texel =
int2(
x + 1,
y + 1);
132 auto compute_coordinates = [&](
const int2 &texel) ->
float2 {
143 return coordinates - displacement;
146 const float2 lower_left_coordinates = compute_coordinates(lower_left_texel);
147 const float2 lower_right_coordinates = compute_coordinates(lower_right_texel);
148 const float2 upper_left_coordinates = compute_coordinates(upper_left_texel);
149 const float2 upper_right_coordinates = compute_coordinates(upper_right_texel);
153 const float2 lower_x_gradient = (lower_right_coordinates - lower_left_coordinates) /
size.x;
154 const float2 left_y_gradient = (upper_left_coordinates - lower_left_coordinates) /
size.y;
155 const float2 right_y_gradient = (upper_right_coordinates - lower_right_coordinates) /
size.y;
156 const float2 upper_x_gradient = (upper_right_coordinates - upper_left_coordinates) /
size.x;
159 auto compute_pixel = [&](
const int2 &texel,
160 const float2 &coordinates,
162 const float2 &y_gradient) {
166 output.store_pixel(texel, displaced_color);
171 compute_pixel(lower_left_texel, lower_left_coordinates, lower_x_gradient, left_y_gradient);
172 if (lower_right_texel.x !=
size.x) {
174 lower_right_texel, lower_right_coordinates, lower_x_gradient, right_y_gradient);
176 if (upper_left_texel.y !=
size.y) {
177 compute_pixel(upper_left_texel, upper_left_coordinates, upper_x_gradient, left_y_gradient);
179 if (upper_right_texel.x !=
size.x && upper_right_texel.y !=
size.y) {
181 upper_right_texel, upper_right_coordinates, upper_x_gradient, right_y_gradient);
227 ntype.
ui_description =
"Displace pixel position using an offset vector";
230 ntype.
declare = file_ns::cmp_node_displace_declare;
#define NODE_CLASS_DISTORT
#define CMP_NODE_DISPLACE
void GPU_shader_bind(GPUShader *shader, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_texture_anisotropic_filter(GPUTexture *texture, bool use_aniso)
void GPU_texture_extend_mode(GPUTexture *texture, GPUSamplerExtendMode extend_mode)
@ GPU_SAMPLER_EXTEND_MODE_CLAMP_TO_BORDER
void GPU_texture_mipmap_mode(GPUTexture *texture, bool use_mipmap, bool use_filter)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
GPUShader * get_shader(const char *info_name, ResultPrecision precision)
NodeOperation(Context &context, DNode node)
Result & get_result(StringRef identifier)
Context & context() const
Result & get_input(StringRef identifier) const
virtual Domain compute_domain()
void share_data(const Result &source)
void allocate_texture(Domain domain, bool from_pool=true)
void unbind_as_texture() const
void bind_as_texture(GPUShader *shader, const char *texture_name) const
T load_pixel_extended(const int2 &texel) const
void bind_as_image(GPUShader *shader, const char *image_name, bool read=false) const
void unbind_as_image() const
float4 sample_ewa_zero(const float2 &coordinates, const float2 &x_gradient, const float2 &y_gradient) const
bool is_single_value() const
const T & get_single_value() const
int compositor_domain_priority() const
NodeOperation(Context &context, DNode node)
void node_register_type(bNodeType &ntype)
void compute_dispatch_threads_at_least(GPUShader *shader, int2 threads_range, int2 local_size=int2(16))
void parallel_for(const int2 range, const Function &function)
VecBase< T, Size > divide_ceil(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
static void cmp_node_displace_declare(NodeDeclarationBuilder &b)
static NodeOperation * get_compositor_operation(Context &context, DNode node)
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< float, 3 > float3
static void register_node_type_cmp_displace()
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
std::string ui_description
NodeGetCompositorOperationFunction get_compositor_operation
const char * enum_name_legacy
NodeDeclareFunction declare