Blender V4.3
node_composite_sunbeams.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2014 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "BLI_math_vector.hh"
10
11#include "UI_interface.hh"
12#include "UI_resources.hh"
13
14#include "GPU_shader.hh"
15
16#include "COM_node_operation.hh"
17#include "COM_utilities.hh"
18
20
22
24
26{
27 b.add_input<decl::Color>("Image")
28 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
29 .compositor_domain_priority(0);
30 b.add_output<decl::Color>("Image");
31}
32
33static void init(bNodeTree * /*ntree*/, bNode *node)
34{
35 NodeSunBeams *data = MEM_cnew<NodeSunBeams>(__func__);
36
37 data->source[0] = 0.5f;
38 data->source[1] = 0.5f;
39 node->storage = data;
40}
41
43{
44 uiItemR(layout, ptr, "source", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_EXPAND, "", ICON_NONE);
45 uiItemR(layout,
46 ptr,
47 "ray_length",
49 nullptr,
50 ICON_NONE);
51}
52
53using namespace blender::realtime_compositor;
54
56 public:
58
59 void execute() override
60 {
61 Result &input_image = get_input("Image");
62 Result &output_image = get_result("Image");
63
64 const int2 input_size = input_image.domain().size;
65 const int max_steps = int(node_storage(bnode()).ray_length * math::length(input_size));
66 if (max_steps == 0) {
67 input_image.pass_through(output_image);
68 return;
69 }
70
71 GPUShader *shader = context().get_shader("compositor_sun_beams");
72 GPU_shader_bind(shader);
73
74 GPU_shader_uniform_2fv(shader, "source", node_storage(bnode()).source);
75 GPU_shader_uniform_1i(shader, "max_steps", max_steps);
76
77 GPU_texture_filter_mode(input_image, true);
79 input_image.bind_as_texture(shader, "input_tx");
80
81 const Domain domain = compute_domain();
82 output_image.allocate_texture(domain);
83 output_image.bind_as_image(shader, "output_img");
84
85 compute_dispatch_threads_at_least(shader, domain.size);
86
88 output_image.unbind_as_image();
89 input_image.unbind_as_texture();
90 }
91};
92
94{
95 return new SunBeamsOperation(context, node);
96}
97
98} // namespace blender::nodes::node_composite_sunbeams_cc
99
101{
103
104 static blender::bke::bNodeType ntype;
105
106 cmp_node_type_base(&ntype, CMP_NODE_SUNBEAMS, "Sun Beams", NODE_CLASS_OP_FILTER);
107 ntype.declare = file_ns::cmp_node_sunbeams_declare;
108 ntype.draw_buttons = file_ns::node_composit_buts_sunbeams;
109 ntype.initfunc = file_ns::init;
112 ntype.get_compositor_operation = file_ns::get_compositor_operation;
113
115}
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1799
#define NODE_CLASS_OP_FILTER
Definition BKE_node.hh:408
void GPU_shader_uniform_2fv(GPUShader *sh, const char *name, const float data[2])
void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value)
void GPU_shader_bind(GPUShader *shader)
void GPU_shader_unbind()
void GPU_texture_extend_mode(GPUTexture *texture, GPUSamplerExtendMode extend_mode)
@ GPU_SAMPLER_EXTEND_MODE_CLAMP_TO_BORDER
void GPU_texture_filter_mode(GPUTexture *texture, bool use_filter)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
@ UI_ITEM_R_EXPAND
@ UI_ITEM_R_SLIDER
struct GPUShader GPUShader
void init()
GPUShader * get_shader(const char *info_name, ResultPrecision precision)
NodeOperation(Context &context, DNode node)
Result & get_input(StringRef identifier) const
Definition operation.cc:144
Result & get_result(StringRef identifier)
Definition operation.cc:46
void bind_as_image(GPUShader *shader, const char *image_name, bool read=false) const
Definition result.cc:264
void pass_through(Result &target)
Definition result.cc:289
const Domain & domain() const
Definition result.cc:712
void allocate_texture(Domain domain, bool from_pool=true)
Definition result.cc:204
void bind_as_texture(GPUShader *shader, const char *texture_name) const
Definition result.cc:253
local_group_size(16, 16) .push_constant(Type b
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:4632
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
T length(const VecBase< T, Size > &a)
static void node_composit_buts_sunbeams(uiLayout *layout, bContext *, PointerRNA *ptr)
static void cmp_node_sunbeams_declare(NodeDeclarationBuilder &b)
static NodeOperation * get_compositor_operation(Context &context, DNode node)
void compute_dispatch_threads_at_least(GPUShader *shader, int2 threads_range, int2 local_size=int2(16))
Definition utilities.cc:131
void register_node_type_cmp_sunbeams()
void cmp_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:46
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:58
Defines a node type.
Definition BKE_node.hh:218
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:324
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
PointerRNA * ptr
Definition wm_files.cc:4126