Blender V5.0
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
7#include "node_shader_util.hh"
8
9#include "BLI_color.hh"
11
13
15{
16 b.is_function_node();
17 b.add_input<decl::Float>("Temperature")
18 .default_value(6500.0f)
19 .min(800.0f)
20 .max(12000.0f)
22 b.add_output<decl::Color>("Color");
23}
24
26 bNode *node,
27 bNodeExecData * /*execdata*/,
30{
31 const int size = CM_TABLE + 1;
32 float *data = MEM_malloc_arrayN<float>(size * 4, "blackbody texture");
33
35
36 float layer;
37 GPUNodeLink *ramp_texture = GPU_color_band(mat, size, data, &layer);
38
39 return GPU_stack_link(mat, node, "node_blackbody", in, out, ramp_texture, GPU_constant(&layer));
40}
41
43{
44 static auto fn = mf::build::SI1_SO<float, ColorGeometry4f>("Blackbody", [](float temperature) {
45 float color[4];
47 return ColorGeometry4f(color);
48 });
49 builder.set_matching_fn(fn);
50}
51
53#ifdef WITH_MATERIALX
54{
55 NodeItem temperature = get_input_value("Temperature", NodeItem::Type::Float);
56
57 NodeItem res = create_node("blackbody", NodeItem::Type::Color3);
58 res.set_input("temperature", temperature);
59 return res;
60}
61#endif
63
64} // namespace blender::nodes::node_shader_blackbody_cc
65
66/* node type definition */
68{
70
71 static blender::bke::bNodeType ntype;
72
73 common_node_type_base(&ntype, "ShaderNodeBlackbody", SH_NODE_BLACKBODY);
74 ntype.ui_name = "Blackbody";
75 ntype.ui_description = "Convert a blackbody temperature to an RGB value";
76 ntype.enum_name_legacy = "BLACKBODY";
78 ntype.declare = file_ns::node_declare;
80 ntype.gpu_fn = file_ns::node_shader_gpu_blackbody;
81 ntype.build_multi_function = file_ns::sh_node_blackbody_build_multi_function;
82 ntype.materialx_fn = file_ns::node_shader_materialx;
83
85}
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:453
#define SH_NODE_BLACKBODY
#define CM_TABLE
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
GPUNodeLink * GPU_constant(const float *num)
GPUNodeLink * GPU_color_band(GPUMaterial *mat, int size, float *pixels, float *r_row)
void IMB_colormanagement_blackbody_temperature_to_rgb_table(float *r_table, int width, float min, float max)
void IMB_colormanagement_blackbody_temperature_to_rgb(float r_dest[4], float value)
@ PROP_COLOR_TEMPERATURE
Definition RNA_types.hh:290
BMesh const char void * data
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
void set_matching_fn(const mf::MultiFunction *fn)
#define in
#define out
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
Definition mallocn.cc:133
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
void node_type_size_preset(bNodeType &ntype, eNodeSizePreset size)
Definition node.cc:5396
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)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void register_node_type_sh_blackbody()
void common_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:238
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:344
std::string ui_description
Definition BKE_node.hh:244
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:342
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:351
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362