30 const bool is_compositor =
b.tree_or_null() &&
b.tree_or_null()->type ==
NTREE_COMPOSIT;
34 b.add_input<
decl::Vector>(
"Vector"_ustr).default_input_type(default_input_type);
36 b.add_output<
decl::Color>(
"Color"_ustr).no_muted_links();
37 b.add_output<
decl::Float>(
"Factor"_ustr,
"Fac"_ustr).no_muted_links();
76 static const mf::Signature
signature = []() {
78 mf::SignatureBuilder builder{
"GradientFunction",
signature};
79 builder.single_input<
float3>(
"Vector");
80 builder.single_output<
ColorGeometry4f>(
"Color", mf::ParamFlag::SupportsUnusedOutput);
81 builder.single_output<
float>(
"Fac");
92 params.uninitialized_single_output_if_required<
ColorGeometry4f>(1,
"Color");
95 const bool compute_color = !r_color.
is_empty();
97 switch (gradient_type_) {
105 const float r = std::max(vector[i].
x, 0.0f);
112 const float r = std::min(std::max(vector[i].
x, 0.0f), 1.0f);
113 const float t = r * r;
114 fac[i] = (3.0f * t - 2.0f * t * r);
120 fac[i] = (vector[i].x + vector[i].y) * 0.5f;
127 fac[i] =
atan2f(vector[i].
y, vector[i].
x) / (
M_PI * 2.0f) + 0.5f;
136 const float r = std::max(0.999999f -
math::length(vector[i]), 0.0f);
146 fac[i] = std::max(0.999999f -
math::length(vector[i]), 0.0f);
159 static constexpr int8_t id = 0;
161 hash.add(gradient_type_);
176 const int gradient_type = tex->gradient_type;
177 NodeItem vector = get_input_link(
"Vector", NodeItem::Type::Vector2);
179 vector = texcoord_node();
181 NodeItem res = empty();
183 switch (gradient_type) {
192 res = vector[0].clamp();
193 res = res * res * (val(3.0f) - val(2.0f) * res);
196 res = (vector[0] + vector[1]) * val(0.5f);
199 res = vector[1].atan2(vector[0]) / val(
float(
M_PI * 2.0f)) + val(0.5f);
202 res = (val(1.0f) - vector.dotproduct(vector).sqrt()).
max(val(0.0f));
206 res = (val(1.0f) - vector.dotproduct(vector).sqrt()).
max(val(0.0f));
225 ntype.
ui_name =
"Gradient Texture";
227 "Generate interpolated color and intensity values based on the input vector";
230 ntype.
declare = file_ns::sh_node_tex_gradient_declare;
231 ntype.
draw_buttons = file_ns::node_shader_buts_tex_gradient;
232 ntype.
initfunc = file_ns::node_shader_init_tex_gradient;
235 ntype.
gpu_fn = file_ns::node_shader_gpu_tex_gradient;
#define NODE_CLASS_TEXTURE
#define SH_NODE_TEX_GRADIENT
#define BLI_assert_unreachable()
constexpr bool is_empty() const
const Signature & signature() const
void set_signature(const Signature *signature)
void construct_and_set_matching_fn(Args &&...args)
GradientFunction(int gradient_type)
void call(const IndexMask &mask, mf::Params params, mf::Context) const override
void hash_unique(UniqueHashBytes &hash) const override
void node_register_type(bNodeType &ntype)
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
T clamp(const T &a, const T &min, const T &max)
T length(const VecBase< T, Size > &a)
static void node_shader_init_tex_gradient(bNodeTree *, bNode *node)
static void sh_node_tex_gradient_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_tex_gradient(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void sh_node_gradient_tex_build_multi_function(NodeMultiFunctionBuilder &builder)
static void node_shader_buts_tex_gradient(ui::Layout &layout, bContext *, PointerRNA *ptr)
@ ITEM_R_SPLIT_EMPTY_NAME
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
GPUNodeLink * GPU_constant(const float *num)
void node_shader_gpu_tex_mapping(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *)
void node_shader_gpu_default_tex_coord(GPUMaterial *mat, bNode *node, GPUNodeLink **link)
void BKE_texture_mapping_default(struct TexMapping *texmap, int type)
void register_node_type_sh_tex_gradient()
@ NODE_DEFAULT_INPUT_POSITION_FIELD
@ NODE_DEFAULT_INPUT_UNIFORM_IMAGE_COORDINATES
@ SHD_BLEND_QUADRATIC_SPHERE
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
void node_free_standard_storage(bNode *node)
VecBase< float, 3 > float3
void BKE_texture_colormapping_default(struct ColorMapping *colormap)
void common_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
ColorMapping color_mapping
NodeMaterialXFunction materialx_fn
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
std::string ui_description
NodeGPUExecFunction gpu_fn
NodeMultiFunctionBuildFunction build_multi_function
void(*) initfunc(bNodeTree *ntree, bNode *node)
const char * enum_name_legacy
NodeDeclareFunction declare
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)