Blender V5.3
node_shader_blackbody.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10#include "NOD_multi_function.hh"
11#include "node_shader_util.hh"
12
13#include "BLI_color_types.hh"
15
16namespace blender {
17
19
21{
22 b.is_function_node();
23 b.add_input<decl::Float>("Temperature"_ustr)
24 .default_value(6500.0f)
25 .min(800.0f)
26 .max(12000.0f)
28 b.add_output<decl::Color>("Color"_ustr);
29}
30
32 bNode *node,
33 bNodeExecData * /*execdata*/,
36{
37 const int size = CM_TABLE + 1;
38 float *data = MEM_new_array_uninitialized<float>(size * 4, "blackbody texture");
39
41
42 float layer;
43 GPUNodeLink *ramp_texture = GPU_color_band(mat, size, data, &layer);
44
45 return GPU_stack_link(mat, node, "node_blackbody", in, out, ramp_texture, GPU_constant(&layer));
46}
47
49{
50 static auto fn = mf::build::SI1_SO<float, ColorGeometry4f>("Blackbody", [](float temperature) {
51 float color[4];
53 return ColorGeometry4f(color);
54 });
55 builder.set_matching_fn(fn);
56}
57
59#ifdef WITH_MATERIALX
60{
61 NodeItem temperature = get_input_value("Temperature", NodeItem::Type::Float);
62
63 NodeItem res = create_node("blackbody", NodeItem::Type::Color3);
64 res.set_input("temperature", temperature);
65 return res;
66}
67#endif
69
70} // namespace nodes::node_shader_blackbody_cc
71
72/* node type definition */
74{
75 namespace file_ns = nodes::node_shader_blackbody_cc;
76
77 static bke::bNodeType ntype;
78
79 common_node_type_base(&ntype, "ShaderNodeBlackbody"_ustr, SH_NODE_BLACKBODY);
80 ntype.ui_name = "Blackbody";
81 ntype.ui_description = "Convert a blackbody temperature to an RGB value";
82 ntype.enum_name_legacy = "BLACKBODY";
84 ntype.declare = file_ns::node_declare;
86 ntype.gpu_fn = file_ns::node_shader_gpu_blackbody;
87 ntype.build_multi_function = file_ns::sh_node_blackbody_build_multi_function;
88 ntype.materialx_fn = file_ns::node_shader_materialx;
89
91}
92
93} // namespace blender
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:484
#define SH_NODE_BLACKBODY
#define CM_TABLE
void set_matching_fn(const mf::MultiFunction *fn)
#define layer
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static void sh_node_blackbody_build_multi_function(nodes::NodeMultiFunctionBuilder &builder)
static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_blackbody(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
BMesh Iterators.
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void register_node_type_sh_blackbody()
GPUNodeLink * GPU_color_band(GPUMaterial *mat, int size, float *pixels, float *r_row)
GPUNodeLink * GPU_constant(const float *num)
BMesh const char void * data
void IMB_colormanagement_blackbody_temperature_to_rgb(float r_dest[4], float value)
void IMB_colormanagement_blackbody_temperature_to_rgb_table(float *r_table, int width, float min, float max)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
@ PROP_COLOR_TEMPERATURE
Definition RNA_types.hh:347
void common_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
static constexpr int _160
Definition BKE_node.hh:246
Defines a node type.
Definition BKE_node.hh:265
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:375
std::string ui_description
Definition BKE_node.hh:271
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:373
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:382
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393