Blender V4.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
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(1500.0f)
19 .min(800.0f)
20 .max(12000.0f)
22 b.add_output<decl::Color>("Color");
23}
24
26 bNode *node,
27 bNodeExecData * /*execdata*/,
28 GPUNodeStack *in,
29 GPUNodeStack *out)
30{
31 const int size = CM_TABLE + 1;
32 float *data = static_cast<float *>(MEM_mallocN(sizeof(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
74 ntype.declare = file_ns::node_declare;
76 ntype.gpu_fn = file_ns::node_shader_gpu_blackbody;
77 ntype.build_multi_function = file_ns::sh_node_blackbody_build_multi_function;
78 ntype.materialx_fn = file_ns::node_shader_materialx;
79
81}
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:410
#define SH_NODE_BLACKBODY
Definition BKE_node.hh:964
#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:193
void set_matching_fn(const mf::MultiFunction *fn)
local_group_size(16, 16) .push_constant(Type b
void *(* MEM_mallocN)(size_t len, const char *str)
Definition mallocn.cc:44
void node_type_size_preset(bNodeType *ntype, eNodeSizePreset size)
Definition node.cc:4614
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
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
Definition BLI_color.hh:337
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void register_node_type_sh_blackbody()
void sh_fn_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
Defines a node type.
Definition BKE_node.hh:218
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:320
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:318
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:336
NodeDeclareFunction declare
Definition BKE_node.hh:347