Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/shader/nodes/node_shader_attribute.cc
| /* SPDX-License-Identifier: GPL-2.0-or-later | /* SPDX-License-Identifier: GPL-2.0-or-later | ||||
| * Copyright 2005 Blender Foundation. All rights reserved. */ | * Copyright 2005 Blender Foundation. All rights reserved. */ | ||||
| #include "node_shader_util.hh" | #include "node_shader_util.hh" | ||||
| #include "NOD_geometry_exec.hh" | |||||
| #include "UI_interface.h" | #include "UI_interface.h" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| namespace blender::nodes::node_shader_attribute_cc { | namespace blender::nodes::node_shader_attribute_cc { | ||||
| static void node_declare(NodeDeclarationBuilder &b) | static void node_declare(NodeDeclarationBuilder &b) | ||||
| { | { | ||||
| b.add_output<decl::Color>(N_("Color")); | b.add_output<decl::Color>(N_("Color")); | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | static int node_shader_gpu_attribute(GPUMaterial *mat, | ||||
| int i; | int i; | ||||
| LISTBASE_FOREACH_INDEX (bNodeSocket *, sock, &node->outputs, i) { | LISTBASE_FOREACH_INDEX (bNodeSocket *, sock, &node->outputs, i) { | ||||
| node_shader_gpu_bump_tex_coord(mat, node, &out[i].link); | node_shader_gpu_bump_tex_coord(mat, node, &out[i].link); | ||||
| } | } | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| static void node_geo_exec(GeoNodeExecParams params) | |||||
| { | |||||
| const NodeShaderAttribute *attr = static_cast<const NodeShaderAttribute *>( | |||||
| params.node().storage); | |||||
| const bool is_varying = attr->type == SHD_ATTRIBUTE_GEOMETRY; | |||||
| if (is_varying) { | |||||
| if (params.output_is_required("Color")) { | |||||
| Field<ColorGeometry4f> field{AttributeFieldInput::Create<ColorGeometry4f>(attr->name)}; | |||||
| params.set_output("Color", std::move(field)); | |||||
| } | |||||
| if (params.output_is_required("Vector")) { | |||||
| Field<float3> field{AttributeFieldInput::Create<float3>(attr->name)}; | |||||
| params.set_output("Vector", std::move(field)); | |||||
| } | |||||
| if (params.output_is_required("Fac")) { | |||||
| Field<float> field{AttributeFieldInput::Create<float>(attr->name)}; | |||||
| params.set_output("Fac", std::move(field)); | |||||
| } | |||||
| if (params.output_is_required("Alpha")) { | |||||
| /* TODO: how to extract alpha channel? */ | |||||
| } | |||||
| } | |||||
| else { | |||||
| /* TODO: get from instancer/object. */ | |||||
| } | |||||
| } | |||||
| } // namespace blender::nodes::node_shader_attribute_cc | } // namespace blender::nodes::node_shader_attribute_cc | ||||
| /* node type definition */ | /* node type definition */ | ||||
| void register_node_type_sh_attribute() | void register_node_type_sh_attribute() | ||||
| { | { | ||||
| namespace file_ns = blender::nodes::node_shader_attribute_cc; | namespace file_ns = blender::nodes::node_shader_attribute_cc; | ||||
| static bNodeType ntype; | static bNodeType ntype; | ||||
| sh_node_type_base(&ntype, SH_NODE_ATTRIBUTE, "Attribute", NODE_CLASS_INPUT); | sh_fn_node_type_base(&ntype, SH_NODE_ATTRIBUTE, "Attribute", NODE_CLASS_INPUT); | ||||
| ntype.declare = file_ns::node_declare; | ntype.declare = file_ns::node_declare; | ||||
| ntype.draw_buttons = file_ns::node_shader_buts_attribute; | ntype.draw_buttons = file_ns::node_shader_buts_attribute; | ||||
| node_type_init(&ntype, file_ns::node_shader_init_attribute); | node_type_init(&ntype, file_ns::node_shader_init_attribute); | ||||
| node_type_storage( | node_type_storage( | ||||
| &ntype, "NodeShaderAttribute", node_free_standard_storage, node_copy_standard_storage); | &ntype, "NodeShaderAttribute", node_free_standard_storage, node_copy_standard_storage); | ||||
| node_type_gpu(&ntype, file_ns::node_shader_gpu_attribute); | node_type_gpu(&ntype, file_ns::node_shader_gpu_attribute); | ||||
| ntype.geometry_node_execute = file_ns::node_geo_exec; | |||||
| nodeRegisterType(&ntype); | nodeRegisterType(&ntype); | ||||
| } | } | ||||