Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/shader/nodes/node_shader_volume_principled.c
- This file was moved from source/blender/nodes/shader/nodes/node_shader_volume_principled.cc.
| Show All 11 Lines | |||||
| * You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
| * along with this program; if not, write to the Free Software Foundation, | * along with this program; if not, write to the Free Software Foundation, | ||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
| * | * | ||||
| * The Original Code is Copyright (C) 2005 Blender Foundation. | * The Original Code is Copyright (C) 2005 Blender Foundation. | ||||
| * All rights reserved. | * All rights reserved. | ||||
| */ | */ | ||||
| #include "node_shader_util.hh" | #include "../node_shader_util.h" | ||||
| /* **************** OUTPUT ******************** */ | /* **************** OUTPUT ******************** */ | ||||
| namespace blender::nodes::node_shader_volume_principled_cc { | static bNodeSocketTemplate sh_node_volume_principled_in[] = { | ||||
| {SOCK_RGBA, N_("Color"), 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f}, | |||||
| static void node_declare(NodeDeclarationBuilder &b) | {SOCK_STRING, N_("Color Attribute"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, | ||||
| { | {SOCK_FLOAT, N_("Density"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, | ||||
| b.add_input<decl::Color>(N_("Color")).default_value({0.5f, 0.5f, 0.5f, 1.0f}); | {SOCK_STRING, N_("Density Attribute"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, | ||||
| b.add_input<decl::String>(N_("Color Attribute")); | {SOCK_FLOAT, N_("Anisotropy"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_FACTOR}, | ||||
| b.add_input<decl::Float>(N_("Density")).default_value(1.0f).min(0.0f).max(1000.0f); | {SOCK_RGBA, N_("Absorption Color"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, | ||||
| b.add_input<decl::String>(N_("Density Attribute")); | {SOCK_FLOAT, N_("Emission Strength"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1000.0f}, | ||||
| b.add_input<decl::Float>(N_("Anisotropy")).min(-1.0f).max(1.0f).subtype(PROP_FACTOR); | {SOCK_RGBA, N_("Emission Color"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, | ||||
| b.add_input<decl::Color>(N_("Absorption Color")); | {SOCK_FLOAT, N_("Blackbody Intensity"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, | ||||
| b.add_input<decl::Float>(N_("Emission Strength")).min(0.0f).max(1000.0f); | {SOCK_RGBA, N_("Blackbody Tint"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, | ||||
| b.add_input<decl::Color>(N_("Emission Color")).default_value({1.0f, 1.0f, 1.0f, 1.0f}); | {SOCK_FLOAT, N_("Temperature"), 1000.0f, 0.0f, 0.0f, 0.0f, 0.0f, 6500.0f}, | ||||
| b.add_input<decl::Float>(N_("Blackbody Intensity")).min(0.0f).max(1.0f).subtype(PROP_FACTOR); | {SOCK_STRING, N_("Temperature Attribute"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, | ||||
| b.add_input<decl::Color>(N_("Blackbody Tint")).default_value({1.0f, 1.0f, 1.0f, 1.0f}); | {-1, ""}, | ||||
| b.add_input<decl::Float>(N_("Temperature")).default_value(1000.0f).min(0.0f).max(6500.0f); | }; | ||||
| b.add_input<decl::String>(N_("Temperature Attribute")); | |||||
| b.add_output<decl::Shader>(N_("Volume")); | static bNodeSocketTemplate sh_node_volume_principled_out[] = { | ||||
| } | {SOCK_SHADER, N_("Volume")}, | ||||
| {-1, ""}, | |||||
| }; | |||||
| static void node_shader_init_volume_principled(bNodeTree *UNUSED(ntree), bNode *node) | static void node_shader_init_volume_principled(bNodeTree *UNUSED(ntree), bNode *node) | ||||
| { | { | ||||
| LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { | LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { | ||||
| if (STREQ(sock->name, "Density Attribute")) { | if (STREQ(sock->name, "Density Attribute")) { | ||||
| strcpy(((bNodeSocketValueString *)sock->default_value)->value, "density"); | strcpy(((bNodeSocketValueString *)sock->default_value)->value, "density"); | ||||
| } | } | ||||
| else if (STREQ(sock->name, "Temperature Attribute")) { | else if (STREQ(sock->name, "Temperature Attribute")) { | ||||
| strcpy(((bNodeSocketValueString *)sock->default_value)->value, "temperature"); | strcpy(((bNodeSocketValueString *)sock->default_value)->value, "temperature"); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static int node_shader_gpu_volume_principled(GPUMaterial *mat, | static int node_shader_gpu_volume_principled(GPUMaterial *mat, | ||||
| bNode *node, | bNode *node, | ||||
| bNodeExecData *UNUSED(execdata), | bNodeExecData *UNUSED(execdata), | ||||
| GPUNodeStack *in, | GPUNodeStack *in, | ||||
| GPUNodeStack *out) | GPUNodeStack *out) | ||||
| { | { | ||||
| /* Test if blackbody intensity is enabled. */ | /* Test if blackbody intensity is enabled. */ | ||||
| bool use_blackbody = (in[8].link || in[8].vec[0] != 0.0f); | bool use_blackbody = (in[8].link || in[8].vec[0] != 0.0f); | ||||
| /* Get volume attributes. */ | /* Get volume attributes. */ | ||||
| GPUNodeLink *density = nullptr, *color = nullptr, *temperature = nullptr; | GPUNodeLink *density = NULL, *color = NULL, *temperature = NULL; | ||||
| LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { | LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { | ||||
| if (sock->typeinfo->type != SOCK_STRING) { | if (sock->typeinfo->type != SOCK_STRING) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| bNodeSocketValueString *value = (bNodeSocketValueString *)sock->default_value; | bNodeSocketValueString *value = sock->default_value; | ||||
| const char *attribute_name = value->value; | const char *attribute_name = value->value; | ||||
| if (attribute_name[0] == '\0') { | if (attribute_name[0] == '\0') { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (STREQ(sock->name, "Density Attribute")) { | if (STREQ(sock->name, "Density Attribute")) { | ||||
| density = GPU_volume_grid(mat, attribute_name, GPU_VOLUME_DEFAULT_1); | density = GPU_volume_grid(mat, attribute_name, GPU_VOLUME_DEFAULT_1); | ||||
| } | } | ||||
| Show All 18 Lines | if (!temperature) { | ||||
| static float one = 1.0f; | static float one = 1.0f; | ||||
| temperature = GPU_constant(&one); | temperature = GPU_constant(&one); | ||||
| } | } | ||||
| /* Create blackbody spectrum. */ | /* Create blackbody spectrum. */ | ||||
| const int size = CM_TABLE + 1; | const int size = CM_TABLE + 1; | ||||
| float *data, layer; | float *data, layer; | ||||
| if (use_blackbody) { | if (use_blackbody) { | ||||
| data = (float *)MEM_mallocN(sizeof(float) * size * 4, "blackbody texture"); | data = MEM_mallocN(sizeof(float) * size * 4, "blackbody texture"); | ||||
| blackbody_temperature_to_rgb_table(data, size, 965.0f, 12000.0f); | blackbody_temperature_to_rgb_table(data, size, 965.0f, 12000.0f); | ||||
| } | } | ||||
| else { | else { | ||||
| data = (float *)MEM_callocN(sizeof(float) * size * 4, "blackbody black"); | data = MEM_callocN(sizeof(float) * size * 4, "blackbody black"); | ||||
| } | } | ||||
| GPUNodeLink *spectrummap = GPU_color_band(mat, size, data, &layer); | GPUNodeLink *spectrummap = GPU_color_band(mat, size, data, &layer); | ||||
| return GPU_stack_link(mat, | return GPU_stack_link(mat, | ||||
| node, | node, | ||||
| "node_volume_principled", | "node_volume_principled", | ||||
| in, | in, | ||||
| out, | out, | ||||
| density, | density, | ||||
| color, | color, | ||||
| temperature, | temperature, | ||||
| spectrummap, | spectrummap, | ||||
| GPU_constant(&layer)); | GPU_constant(&layer)); | ||||
| } | } | ||||
| } // namespace blender::nodes::node_shader_volume_principled_cc | |||||
| /* node type definition */ | /* node type definition */ | ||||
| void register_node_type_sh_volume_principled() | void register_node_type_sh_volume_principled(void) | ||||
| { | { | ||||
| namespace file_ns = blender::nodes::node_shader_volume_principled_cc; | |||||
| static bNodeType ntype; | static bNodeType ntype; | ||||
| sh_node_type_base(&ntype, SH_NODE_VOLUME_PRINCIPLED, "Principled Volume", NODE_CLASS_SHADER, 0); | sh_node_type_base(&ntype, SH_NODE_VOLUME_PRINCIPLED, "Principled Volume", NODE_CLASS_SHADER, 0); | ||||
| ntype.declare = file_ns::node_declare; | node_type_socket_templates(&ntype, sh_node_volume_principled_in, sh_node_volume_principled_out); | ||||
| node_type_size_preset(&ntype, NODE_SIZE_LARGE); | node_type_size_preset(&ntype, NODE_SIZE_LARGE); | ||||
| node_type_init(&ntype, file_ns::node_shader_init_volume_principled); | node_type_init(&ntype, node_shader_init_volume_principled); | ||||
| node_type_storage(&ntype, "", nullptr, nullptr); | node_type_storage(&ntype, "", NULL, NULL); | ||||
| node_type_gpu(&ntype, file_ns::node_shader_gpu_volume_principled); | node_type_gpu(&ntype, node_shader_gpu_volume_principled); | ||||
| nodeRegisterType(&ntype); | nodeRegisterType(&ntype); | ||||
| } | } | ||||