diff options
author | Aaron Carlisle <carlisle.b3d@gmail.com> | 2021-12-29 23:29:27 +0300 |
---|---|---|
committer | Aaron Carlisle <carlisle.b3d@gmail.com> | 2021-12-30 02:36:15 +0300 |
commit | d3a31311b9ba2108e292d05a91893396456b387c (patch) | |
tree | 889716b88fd7866d9d70b876a40ccd7f3cbc12d4 /source | |
parent | c0fdf16561034f85aadae8a513db16144609b821 (diff) |
Nodes: Convert shader, texture category nodes to c++
Also add/correct file namespace
This is needed to use new node APIs
Differential Revision: https://developer.blender.org/D13688
Diffstat (limited to 'source')
10 files changed, 73 insertions, 48 deletions
diff --git a/source/blender/nodes/shader/CMakeLists.txt b/source/blender/nodes/shader/CMakeLists.txt index e0e7a97bf50..0ba8c52e453 100644 --- a/source/blender/nodes/shader/CMakeLists.txt +++ b/source/blender/nodes/shader/CMakeLists.txt @@ -74,7 +74,7 @@ set(SRC nodes/node_shader_hair_info.c nodes/node_shader_holdout.c nodes/node_shader_hueSatVal.c - nodes/node_shader_ies_light.c + nodes/node_shader_ies_light.cc nodes/node_shader_invert.c nodes/node_shader_layer_weight.c nodes/node_shader_light_falloff.c @@ -106,14 +106,14 @@ set(SRC nodes/node_shader_tex_brick.cc nodes/node_shader_tex_checker.cc nodes/node_shader_tex_coord.c - nodes/node_shader_tex_environment.c + nodes/node_shader_tex_environment.cc nodes/node_shader_tex_gradient.cc nodes/node_shader_tex_image.cc nodes/node_shader_tex_magic.cc nodes/node_shader_tex_musgrave.cc nodes/node_shader_tex_noise.cc - nodes/node_shader_tex_pointdensity.c - nodes/node_shader_tex_sky.c + nodes/node_shader_tex_pointdensity.cc + nodes/node_shader_tex_sky.cc nodes/node_shader_tex_voronoi.cc nodes/node_shader_tex_wave.cc nodes/node_shader_tex_white_noise.cc diff --git a/source/blender/nodes/shader/nodes/node_shader_ies_light.c b/source/blender/nodes/shader/nodes/node_shader_ies_light.cc index 9cc5fd46181..a8887e642b9 100644 --- a/source/blender/nodes/shader/nodes/node_shader_ies_light.c +++ b/source/blender/nodes/shader/nodes/node_shader_ies_light.cc @@ -19,6 +19,8 @@ #include "../node_shader_util.h" +namespace blender::nodes::node_shader_ies_light_cc { + /* **************** IES Light ******************** */ static bNodeSocketTemplate sh_node_tex_ies_in[] = { @@ -34,18 +36,22 @@ static bNodeSocketTemplate sh_node_tex_ies_out[] = { static void node_shader_init_tex_ies(bNodeTree *UNUSED(ntree), bNode *node) { - NodeShaderTexIES *tex = MEM_callocN(sizeof(NodeShaderTexIES), "NodeShaderIESLight"); + NodeShaderTexIES *tex = MEM_cnew<NodeShaderTexIES>("NodeShaderIESLight"); node->storage = tex; } +} // namespace blender::nodes::node_shader_ies_light_cc + /* node type definition */ -void register_node_type_sh_tex_ies(void) +void register_node_type_sh_tex_ies() { + namespace file_ns = blender::nodes::node_shader_ies_light_cc; + static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_TEX_IES, "IES Texture", NODE_CLASS_TEXTURE, 0); - node_type_socket_templates(&ntype, sh_node_tex_ies_in, sh_node_tex_ies_out); - node_type_init(&ntype, node_shader_init_tex_ies); + node_type_socket_templates(&ntype, file_ns::sh_node_tex_ies_in, file_ns::sh_node_tex_ies_out); + node_type_init(&ntype, file_ns::node_shader_init_tex_ies); node_type_storage( &ntype, "NodeShaderTexIES", node_free_standard_storage, node_copy_standard_storage); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c b/source/blender/nodes/shader/nodes/node_shader_tex_environment.cc index ff08961b3e9..00bafd1a9d3 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_environment.cc @@ -19,6 +19,8 @@ #include "../node_shader_util.h" +namespace blender::nodes::node_shader_tex_environment_cc { + /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_tex_environment_in[] = { @@ -33,7 +35,7 @@ static bNodeSocketTemplate sh_node_tex_environment_out[] = { static void node_shader_init_tex_environment(bNodeTree *UNUSED(ntree), bNode *node) { - NodeTexEnvironment *tex = MEM_callocN(sizeof(NodeTexEnvironment), "NodeTexEnvironment"); + NodeTexEnvironment *tex = MEM_cnew<NodeTexEnvironment>("NodeTexEnvironment"); BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT); BKE_texture_colormapping_default(&tex->base.color_mapping); tex->projection = SHD_PROJ_EQUIRECTANGULAR; @@ -49,12 +51,12 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, GPUNodeStack *out) { Image *ima = (Image *)node->id; - NodeTexEnvironment *tex = node->storage; + NodeTexEnvironment *tex = (NodeTexEnvironment *)node->storage; /* We get the image user from the original node, since GPU image keeps * a pointer to it and the dependency refreshes the original. */ bNode *node_original = node->original ? node->original : node; - NodeTexImage *tex_original = node_original->storage; + NodeTexImage *tex_original = (NodeTexImage *)node_original->storage; ImageUser *iuser = &tex_original->iuser; eGPUSamplerState sampler = GPU_SAMPLER_REPEAT | GPU_SAMPLER_ANISO | GPU_SAMPLER_FILTER; /* TODO(fclem): For now assume mipmap is always enabled. */ @@ -132,17 +134,22 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, return true; } +} // namespace blender::nodes::node_shader_tex_environment_cc + /* node type definition */ -void register_node_type_sh_tex_environment(void) +void register_node_type_sh_tex_environment() { + namespace file_ns = blender::nodes::node_shader_tex_environment_cc; + static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_TEX_ENVIRONMENT, "Environment Texture", NODE_CLASS_TEXTURE, 0); - node_type_socket_templates(&ntype, sh_node_tex_environment_in, sh_node_tex_environment_out); - node_type_init(&ntype, node_shader_init_tex_environment); + node_type_socket_templates( + &ntype, file_ns::sh_node_tex_environment_in, file_ns::sh_node_tex_environment_out); + node_type_init(&ntype, file_ns::node_shader_init_tex_environment); node_type_storage( &ntype, "NodeTexEnvironment", node_free_standard_storage, node_copy_standard_storage); - node_type_gpu(&ntype, node_shader_gpu_tex_environment); + node_type_gpu(&ntype, file_ns::node_shader_gpu_tex_environment); ntype.labelfunc = node_image_label; node_type_size_preset(&ntype, NODE_SIZE_LARGE); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.cc b/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.cc index 65d07eac741..2e0dd28ac8c 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.cc @@ -23,7 +23,7 @@ NODE_STORAGE_FUNCS(NodeTexMusgrave) -namespace blender::nodes::node_shader_musgrave_cc { +namespace blender::nodes::node_shader_tex_musgrave_cc { static void sh_node_tex_musgrave_declare(NodeDeclarationBuilder &b) { @@ -529,11 +529,11 @@ static void sh_node_musgrave_build_multi_function( builder.construct_and_set_matching_fn<MusgraveFunction>(tex->dimensions, tex->musgrave_type); } -} // namespace blender::nodes::node_shader_musgrave_cc +} // namespace blender::nodes::node_shader_tex_musgrave_cc void register_node_type_sh_tex_musgrave() { - namespace file_ns = blender::nodes::node_shader_musgrave_cc; + namespace file_ns = blender::nodes::node_shader_tex_musgrave_cc; static bNodeType ntype; diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc b/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc index 4b98689be54..74b0ae73a9d 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc @@ -23,7 +23,7 @@ NODE_STORAGE_FUNCS(NodeTexNoise) -namespace blender::nodes::node_shader_noise_cc { +namespace blender::nodes::node_shader_tex_noise_cc { static void sh_node_tex_noise_declare(NodeDeclarationBuilder &b) { @@ -246,11 +246,11 @@ static void sh_node_noise_build_multi_function(blender::nodes::NodeMultiFunction builder.construct_and_set_matching_fn<NoiseFunction>(storage.dimensions); } -} // namespace blender::nodes::node_shader_noise_cc +} // namespace blender::nodes::node_shader_tex_noise_cc void register_node_type_sh_tex_noise() { - namespace file_ns = blender::nodes::node_shader_noise_cc; + namespace file_ns = blender::nodes::node_shader_tex_noise_cc; static bNodeType ntype; diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.c b/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.cc index 14cd1fd4c0c..8e57be6ee8d 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.cc @@ -21,6 +21,8 @@ #include "RE_texture.h" +namespace blender::nodes::node_shader_tex_pointdensity_cc { + /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_tex_pointdensity_in[] = { @@ -36,8 +38,7 @@ static bNodeSocketTemplate sh_node_tex_pointdensity_out[] = { static void node_shader_init_tex_pointdensity(bNodeTree *UNUSED(ntree), bNode *node) { - NodeShaderTexPointDensity *point_density = MEM_callocN(sizeof(NodeShaderTexPointDensity), - "new pd node"); + NodeShaderTexPointDensity *point_density = MEM_cnew<NodeShaderTexPointDensity>("new pd node"); point_density->resolution = 100; point_density->radius = 0.3f; point_density->space = SHD_POINTDENSITY_SPACE_OBJECT; @@ -47,7 +48,7 @@ static void node_shader_init_tex_pointdensity(bNodeTree *UNUSED(ntree), bNode *n static void node_shader_free_tex_pointdensity(bNode *node) { - NodeShaderTexPointDensity *point_density = node->storage; + NodeShaderTexPointDensity *point_density = (NodeShaderTexPointDensity *)node->storage; PointDensity *pd = &point_density->pd; RE_point_density_free(pd); BKE_texture_pointdensity_free_data(pd); @@ -60,23 +61,28 @@ static void node_shader_copy_tex_pointdensity(bNodeTree *UNUSED(dest_ntree), const bNode *src_node) { dest_node->storage = MEM_dupallocN(src_node->storage); - NodeShaderTexPointDensity *point_density = dest_node->storage; + NodeShaderTexPointDensity *point_density = (NodeShaderTexPointDensity *)dest_node->storage; PointDensity *pd = &point_density->pd; memset(pd, 0, sizeof(*pd)); } +} // namespace blender::nodes::node_shader_tex_pointdensity_cc + /* node type definition */ -void register_node_type_sh_tex_pointdensity(void) +void register_node_type_sh_tex_pointdensity() { + namespace file_ns = blender::nodes::node_shader_tex_pointdensity_cc; + static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_TEX_POINTDENSITY, "Point Density", NODE_CLASS_TEXTURE, 0); - node_type_socket_templates(&ntype, sh_node_tex_pointdensity_in, sh_node_tex_pointdensity_out); - node_type_init(&ntype, node_shader_init_tex_pointdensity); + node_type_socket_templates( + &ntype, file_ns::sh_node_tex_pointdensity_in, file_ns::sh_node_tex_pointdensity_out); + node_type_init(&ntype, file_ns::node_shader_init_tex_pointdensity); node_type_storage(&ntype, "NodeShaderTexPointDensity", - node_shader_free_tex_pointdensity, - node_shader_copy_tex_pointdensity); + file_ns::node_shader_free_tex_pointdensity, + file_ns::node_shader_copy_tex_pointdensity); nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_sky.c b/source/blender/nodes/shader/nodes/node_shader_tex_sky.cc index 5c581528c14..6067bcdbfcc 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_sky.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_sky.cc @@ -20,6 +20,8 @@ #include "../node_shader_util.h" #include "sky_model.h" +namespace blender::nodes::node_shader_tex_sky_cc { + /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_tex_sky_in[] = { @@ -34,7 +36,7 @@ static bNodeSocketTemplate sh_node_tex_sky_out[] = { static void node_shader_init_tex_sky(bNodeTree *UNUSED(ntree), bNode *node) { - NodeTexSky *tex = MEM_callocN(sizeof(NodeTexSky), "NodeTexSky"); + NodeTexSky *tex = MEM_cnew<NodeTexSky>("NodeTexSky"); BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT); BKE_texture_colormapping_default(&tex->base.color_mapping); tex->sun_direction[0] = 0.0f; @@ -55,10 +57,10 @@ static void node_shader_init_tex_sky(bNodeTree *UNUSED(ntree), bNode *node) node->storage = tex; } -typedef struct SkyModelPreetham { +struct SkyModelPreetham { float config_Y[5], config_x[5], config_y[5]; /* named after xyY color space */ float radiance[3]; -} SkyModelPreetham; +}; static float sky_perez_function(const float *lam, float theta, float gamma) { @@ -203,19 +205,23 @@ static void node_shader_update_sky(bNodeTree *ntree, bNode *node) nodeSetSocketAvailability(ntree, sockVector, !(tex->sky_model == 2 && tex->sun_disc == 1)); } +} // namespace blender::nodes::node_shader_tex_sky_cc + /* node type definition */ -void register_node_type_sh_tex_sky(void) +void register_node_type_sh_tex_sky() { + namespace file_ns = blender::nodes::node_shader_tex_sky_cc; + static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_TEX_SKY, "Sky Texture", NODE_CLASS_TEXTURE, 0); - node_type_socket_templates(&ntype, sh_node_tex_sky_in, sh_node_tex_sky_out); + node_type_socket_templates(&ntype, file_ns::sh_node_tex_sky_in, file_ns::sh_node_tex_sky_out); node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); - node_type_init(&ntype, node_shader_init_tex_sky); + node_type_init(&ntype, file_ns::node_shader_init_tex_sky); node_type_storage(&ntype, "NodeTexSky", node_free_standard_storage, node_copy_standard_storage); - node_type_gpu(&ntype, node_shader_gpu_tex_sky); + node_type_gpu(&ntype, file_ns::node_shader_gpu_tex_sky); /* remove Vector input for Nishita */ - node_type_update(&ntype, node_shader_update_sky); + node_type_update(&ntype, file_ns::node_shader_update_sky); nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc index c2667deb847..85601c60a2a 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc @@ -21,9 +21,9 @@ #include "BLI_noise.hh" -NODE_STORAGE_FUNCS(NodeTexVoronoi) +namespace blender::nodes::node_shader_tex_voronoi_cc { -namespace blender::nodes::node_shader_voronoi_cc { +NODE_STORAGE_FUNCS(NodeTexVoronoi) static void sh_node_tex_voronoi_declare(NodeDeclarationBuilder &b) { @@ -1336,11 +1336,11 @@ static void sh_node_voronoi_build_multi_function(blender::nodes::NodeMultiFuncti } } -} // namespace blender::nodes::node_shader_voronoi_cc +} // namespace blender::nodes::node_shader_tex_voronoi_cc void register_node_type_sh_tex_voronoi() { - namespace file_ns = blender::nodes::node_shader_voronoi_cc; + namespace file_ns = blender::nodes::node_shader_tex_voronoi_cc; static bNodeType ntype; diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_wave.cc b/source/blender/nodes/shader/nodes/node_shader_tex_wave.cc index 4160367646c..4864a14553c 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_wave.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_wave.cc @@ -21,7 +21,7 @@ #include "BLI_noise.hh" -namespace blender::nodes::node_shader_wave_cc { +namespace blender::nodes::node_shader_tex_wave_cc { static void sh_node_tex_wave_declare(NodeDeclarationBuilder &b) { @@ -212,11 +212,11 @@ static void sh_node_wave_tex_build_multi_function( tex->wave_type, tex->bands_direction, tex->rings_direction, tex->wave_profile); } -} // namespace blender::nodes::node_shader_wave_cc +} // namespace blender::nodes::node_shader_tex_wave_cc void register_node_type_sh_tex_wave() { - namespace file_ns = blender::nodes::node_shader_wave_cc; + namespace file_ns = blender::nodes::node_shader_tex_wave_cc; static bNodeType ntype; diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_white_noise.cc b/source/blender/nodes/shader/nodes/node_shader_tex_white_noise.cc index 696086f803a..3eb2d507266 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_white_noise.cc +++ b/source/blender/nodes/shader/nodes/node_shader_tex_white_noise.cc @@ -21,7 +21,7 @@ #include "BLI_noise.hh" -namespace blender::nodes::node_shader_white_noise_cc { +namespace blender::nodes::node_shader_tex_white_noise_cc { static void sh_node_tex_white_noise_declare(NodeDeclarationBuilder &b) { @@ -188,11 +188,11 @@ static void sh_node_noise_build_multi_function(blender::nodes::NodeMultiFunction builder.construct_and_set_matching_fn<WhiteNoiseFunction>((int)node.custom1); } -} // namespace blender::nodes::node_shader_white_noise_cc +} // namespace blender::nodes::node_shader_tex_white_noise_cc void register_node_type_sh_tex_white_noise() { - namespace file_ns = blender::nodes::node_shader_white_noise_cc; + namespace file_ns = blender::nodes::node_shader_tex_white_noise_cc; static bNodeType ntype; |