Function node support for blackbody shader node #114768
|
@ -33,6 +33,7 @@ class NODE_MT_geometry_node_GEO_COLOR(Menu):
|
|||
|
||||
def draw(self, _context):
|
||||
layout = self.layout
|
||||
node_add_menu.add_node_type(layout, "ShaderNodeBlackbody")
|
||||
node_add_menu.add_node_type(layout, "ShaderNodeValToRGB")
|
||||
node_add_menu.add_node_type(layout, "ShaderNodeRGBCurve")
|
||||
|
||||
layout.separator()
|
||||
|
|
|
@ -534,10 +534,12 @@ enum {
|
|||
/** \name Rendering Tables
|
||||
* \{ */
|
||||
|
||||
void IMB_colormanagement_blackbody_temperature_to_rgb(float r_dest[4], float value);
|
||||
Jacques Lucke
commented
It's not clear whether to pass a It's not clear whether to pass a `float[3]` or `float[4]` here, better be more specific.
Iliya Katushenock
commented
Also, just to consistency, if that function is not works with alpha directly, alpha should be filled as Also, just to consistency, if that function is not works with alpha directly, alpha should be filled as `1.0` in function node itself.
Kenzie
commented
I changed it to a more explicit c array reference similar to the copy_v3_v3 code. The original code set alpha to zero using I changed it to a more explicit c array reference similar to the copy_v3_v3 code. The original code set alpha to zero using `r_table[i * 4 + 3] = 0.0f;` this just replicates current behavior. Honestly this should probably be changed to set it to one but I was reluctant to make any changes. IMB_colormanagement_blackbody_temperature_to_rgb_table assumes a vec4 array (which goes unmarked) and alpha is seemingly unused but the padding seems necessary to fit the color ramp format.
Iliya Katushenock
commented
Geometry nodes should fill alpha by Geometry nodes should fill alpha by `1.0`, changes in image function is not necessary.
Kenzie
commented
I feel like a good course of action would be to correct the naming of the I feel like a good course of action would be to correct the naming of the `IMB_colormanagement_blackbody_temperature_to_rgb_table` (and single/wavelength functions) to "rgba" and possibly discuss setting the default for its outgoing alpha (which seems to be unused in shader nodes since alpha is often treated separately) to 1.0? For now I just keep existing behavior.
|
||||
void IMB_colormanagement_blackbody_temperature_to_rgb_table(float *r_table,
|
||||
int width,
|
||||
float min,
|
||||
float max);
|
||||
void IMB_colormanagement_wavelength_to_rgb(float r_dest[4], float value);
|
||||
void IMB_colormanagement_wavelength_to_rgb_table(float *r_table, int width);
|
||||
|
||||
/** \} */
|
||||
|
|
|
@ -4333,6 +4333,19 @@ static void blackbody_temperature_to_rec709(float rec709[3], float t)
|
|||
}
|
||||
}
|
||||
|
||||
void IMB_colormanagement_blackbody_temperature_to_rgb(float r_dest[4], float value)
|
||||
Kenzie
commented
It is a vec4, this is the format that IMB_colormanagement_wavelength_to_rgb_table already assumes. The naming of the original function seems misleading. It is a vec4, this is the format that IMB_colormanagement_wavelength_to_rgb_table already assumes. The naming of the original function seems misleading.
Iliya Katushenock
commented
Oh, yeah, i see\ Oh, yeah, i see\
|
||||
{
|
||||
float rec709[3];
|
||||
blackbody_temperature_to_rec709(rec709, value);
|
||||
|
||||
float rgb[3];
|
||||
IMB_colormanagement_rec709_to_scene_linear(rgb, rec709);
|
||||
clamp_v3(rgb, 0.0f, FLT_MAX);
|
||||
|
||||
copy_v3_v3(r_dest, rgb);
|
||||
r_dest[3] = 1.0f;
|
||||
}
|
||||
|
||||
void IMB_colormanagement_blackbody_temperature_to_rgb_table(float *r_table,
|
||||
const int width,
|
||||
const float min,
|
||||
|
@ -4340,16 +4353,7 @@ void IMB_colormanagement_blackbody_temperature_to_rgb_table(float *r_table,
|
|||
{
|
||||
for (int i = 0; i < width; i++) {
|
||||
float temperature = min + (max - min) / float(width) * float(i);
|
||||
|
||||
float rec709[3];
|
||||
blackbody_temperature_to_rec709(rec709, temperature);
|
||||
|
||||
float rgb[3];
|
||||
IMB_colormanagement_rec709_to_scene_linear(rgb, rec709);
|
||||
clamp_v3(rgb, 0.0f, FLT_MAX);
|
||||
|
||||
copy_v3_v3(&r_table[i * 4], rgb);
|
||||
r_table[i * 4 + 3] = 0.0f;
|
||||
IMB_colormanagement_blackbody_temperature_to_rgb(&r_table[i * 4], temperature);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4413,20 +4417,24 @@ static void wavelength_to_xyz(float xyz[3], float lambda_nm)
|
|||
}
|
||||
}
|
||||
|
||||
void IMB_colormanagement_wavelength_to_rgb(float r_dest[4], float value)
|
||||
{
|
||||
float xyz[3];
|
||||
wavelength_to_xyz(xyz, value);
|
||||
|
||||
float rgb[3];
|
||||
IMB_colormanagement_xyz_to_scene_linear(rgb, xyz);
|
||||
clamp_v3(rgb, 0.0f, FLT_MAX);
|
||||
|
||||
copy_v3_v3(r_dest, rgb);
|
||||
r_dest[3] = 1.0f;
|
||||
}
|
||||
|
||||
void IMB_colormanagement_wavelength_to_rgb_table(float *r_table, const int width)
|
||||
{
|
||||
for (int i = 0; i < width; i++) {
|
||||
float temperature = 380 + 400 / float(width) * float(i);
|
||||
|
||||
float xyz[3];
|
||||
wavelength_to_xyz(xyz, temperature);
|
||||
|
||||
float rgb[3];
|
||||
IMB_colormanagement_xyz_to_scene_linear(rgb, xyz);
|
||||
clamp_v3(rgb, 0.0f, FLT_MAX);
|
||||
|
||||
copy_v3_v3(&r_table[i * 4], rgb);
|
||||
r_table[i * 4 + 3] = 0.0f;
|
||||
float wavelength = 380 + 400 / float(width) * float(i);
|
||||
IMB_colormanagement_wavelength_to_rgb(&r_table[i * 4], wavelength);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,14 +2,19 @@
|
|||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#include "FN_multi_function_builder.hh"
|
||||
#include "NOD_multi_function.hh"
|
||||
#include "node_shader_util.hh"
|
||||
#include "node_util.hh"
|
||||
|
||||
#include "BLI_color.hh"
|
||||
#include "IMB_colormanagement.h"
|
||||
|
||||
namespace blender::nodes::node_shader_blackbody_cc {
|
||||
|
||||
static void node_declare(NodeDeclarationBuilder &b)
|
||||
{
|
||||
b.is_function_node();
|
||||
b.add_input<decl::Float>("Temperature").default_value(1500.0f).min(800.0f).max(12000.0f);
|
||||
b.add_output<decl::Color>("Color");
|
||||
}
|
||||
|
@ -31,6 +36,16 @@ static int node_shader_gpu_blackbody(GPUMaterial *mat,
|
|||
return GPU_stack_link(mat, node, "node_blackbody", in, out, ramp_texture, GPU_constant(&layer));
|
||||
}
|
||||
|
||||
static void sh_node_blackbody_build_multi_function(nodes::NodeMultiFunctionBuilder &builder)
|
||||
JacquesLucke marked this conversation as resolved
Jacques Lucke
commented
Just noticed, since this is a very simple function with a single input and output, you can also just use the Just noticed, since this is a very simple function with a single input and output, you can also just use the `mf::build::SI1_SO` utility to make the code simpler.
|
||||
{
|
||||
static auto fn = mf::build::SI1_SO<float, ColorGeometry4f>("Blackbody", [](float temperature) {
|
||||
float color[4];
|
||||
IMB_colormanagement_blackbody_temperature_to_rgb(color, temperature);
|
||||
return ColorGeometry4f(color);
|
||||
});
|
||||
builder.set_matching_fn(fn);
|
||||
}
|
||||
|
||||
NODE_SHADER_MATERIALX_BEGIN
|
||||
#ifdef WITH_MATERIALX
|
||||
{
|
||||
|
@ -57,10 +72,11 @@ void register_node_type_sh_blackbody()
|
|||
|
||||
static bNodeType ntype;
|
||||
|
||||
sh_node_type_base(&ntype, SH_NODE_BLACKBODY, "Blackbody", NODE_CLASS_CONVERTER);
|
||||
sh_fn_node_type_base(&ntype, SH_NODE_BLACKBODY, "Blackbody", NODE_CLASS_CONVERTER);
|
||||
ntype.declare = file_ns::node_declare;
|
||||
blender::bke::node_type_size_preset(&ntype, blender::bke::eNodeSizePreset::MIDDLE);
|
||||
ntype.gpu_fn = file_ns::node_shader_gpu_blackbody;
|
||||
ntype.build_multi_function = file_ns::sh_node_blackbody_build_multi_function;
|
||||
ntype.materialx_fn = file_ns::node_shader_materialx;
|
||||
|
||||
nodeRegisterType(&ntype);
|
||||
|
|
Order this to the beginning the respect alphabetical ordering.