From d3a31311b9ba2108e292d05a91893396456b387c Mon Sep 17 00:00:00 2001 From: Aaron Carlisle Date: Wed, 29 Dec 2021 15:29:27 -0500 Subject: 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 --- source/blender/nodes/shader/CMakeLists.txt | 8 +- .../nodes/shader/nodes/node_shader_ies_light.c | 53 ----- .../nodes/shader/nodes/node_shader_ies_light.cc | 59 ++++++ .../shader/nodes/node_shader_tex_environment.c | 150 -------------- .../shader/nodes/node_shader_tex_environment.cc | 157 ++++++++++++++ .../nodes/shader/nodes/node_shader_tex_musgrave.cc | 6 +- .../nodes/shader/nodes/node_shader_tex_noise.cc | 6 +- .../shader/nodes/node_shader_tex_pointdensity.c | 82 -------- .../shader/nodes/node_shader_tex_pointdensity.cc | 88 ++++++++ .../nodes/shader/nodes/node_shader_tex_sky.c | 221 -------------------- .../nodes/shader/nodes/node_shader_tex_sky.cc | 227 +++++++++++++++++++++ .../nodes/shader/nodes/node_shader_tex_voronoi.cc | 8 +- .../nodes/shader/nodes/node_shader_tex_wave.cc | 6 +- .../shader/nodes/node_shader_tex_white_noise.cc | 6 +- 14 files changed, 551 insertions(+), 526 deletions(-) delete mode 100644 source/blender/nodes/shader/nodes/node_shader_ies_light.c create mode 100644 source/blender/nodes/shader/nodes/node_shader_ies_light.cc delete mode 100644 source/blender/nodes/shader/nodes/node_shader_tex_environment.c create mode 100644 source/blender/nodes/shader/nodes/node_shader_tex_environment.cc delete mode 100644 source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.c create mode 100644 source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.cc delete mode 100644 source/blender/nodes/shader/nodes/node_shader_tex_sky.c create mode 100644 source/blender/nodes/shader/nodes/node_shader_tex_sky.cc 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.c deleted file mode 100644 index 9cc5fd46181..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_ies_light.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2018 Blender Foundation. - * All rights reserved. - */ - -#include "../node_shader_util.h" - -/* **************** IES Light ******************** */ - -static bNodeSocketTemplate sh_node_tex_ies_in[] = { - {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - {SOCK_FLOAT, N_("Strength"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000000.0f, PROP_NONE}, - {-1, ""}, -}; - -static bNodeSocketTemplate sh_node_tex_ies_out[] = { - {SOCK_FLOAT, N_("Fac")}, - {-1, ""}, -}; - -static void node_shader_init_tex_ies(bNodeTree *UNUSED(ntree), bNode *node) -{ - NodeShaderTexIES *tex = MEM_callocN(sizeof(NodeShaderTexIES), "NodeShaderIESLight"); - node->storage = tex; -} - -/* node type definition */ -void register_node_type_sh_tex_ies(void) -{ - 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_storage( - &ntype, "NodeShaderTexIES", node_free_standard_storage, node_copy_standard_storage); - - nodeRegisterType(&ntype); -} diff --git a/source/blender/nodes/shader/nodes/node_shader_ies_light.cc b/source/blender/nodes/shader/nodes/node_shader_ies_light.cc new file mode 100644 index 00000000000..a8887e642b9 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_ies_light.cc @@ -0,0 +1,59 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2018 Blender Foundation. + * All rights reserved. + */ + +#include "../node_shader_util.h" + +namespace blender::nodes::node_shader_ies_light_cc { + +/* **************** IES Light ******************** */ + +static bNodeSocketTemplate sh_node_tex_ies_in[] = { + {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + {SOCK_FLOAT, N_("Strength"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000000.0f, PROP_NONE}, + {-1, ""}, +}; + +static bNodeSocketTemplate sh_node_tex_ies_out[] = { + {SOCK_FLOAT, N_("Fac")}, + {-1, ""}, +}; + +static void node_shader_init_tex_ies(bNodeTree *UNUSED(ntree), bNode *node) +{ + NodeShaderTexIES *tex = MEM_cnew("NodeShaderIESLight"); + node->storage = tex; +} + +} // namespace blender::nodes::node_shader_ies_light_cc + +/* node type definition */ +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, 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); + + nodeRegisterType(&ntype); +} diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c b/source/blender/nodes/shader/nodes/node_shader_tex_environment.c deleted file mode 100644 index ff08961b3e9..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - */ - -#include "../node_shader_util.h" - -/* **************** OUTPUT ******************** */ - -static bNodeSocketTemplate sh_node_tex_environment_in[] = { - {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - {-1, ""}, -}; - -static bNodeSocketTemplate sh_node_tex_environment_out[] = { - {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - {-1, ""}, -}; - -static void node_shader_init_tex_environment(bNodeTree *UNUSED(ntree), bNode *node) -{ - NodeTexEnvironment *tex = MEM_callocN(sizeof(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; - BKE_imageuser_default(&tex->iuser); - - node->storage = tex; -} - -static int node_shader_gpu_tex_environment(GPUMaterial *mat, - bNode *node, - bNodeExecData *UNUSED(execdata), - GPUNodeStack *in, - GPUNodeStack *out) -{ - Image *ima = (Image *)node->id; - NodeTexEnvironment *tex = 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; - 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. */ - if (true) { - sampler |= GPU_SAMPLER_MIPMAP; - } - - GPUNodeLink *outalpha; - - if (!ima) { - return GPU_stack_link(mat, node, "node_tex_environment_empty", in, out); - } - - if (!in[0].link) { - GPU_link(mat, "node_tex_environment_texco", GPU_builtin(GPU_VIEW_POSITION), &in[0].link); - node_shader_gpu_bump_tex_coord(mat, node, &in[0].link); - } - - node_shader_gpu_tex_mapping(mat, node, in, out); - - /* Compute texture coordinate. */ - if (tex->projection == SHD_PROJ_EQUIRECTANGULAR) { - GPU_link(mat, "node_tex_environment_equirectangular", in[0].link, &in[0].link); - /* To fix pole issue we clamp the v coordinate. */ - sampler &= ~GPU_SAMPLER_REPEAT_T; - /* Force the highest mipmap and don't do anisotropic filtering. - * This is to fix the artifact caused by derivatives discontinuity. */ - sampler &= ~(GPU_SAMPLER_MIPMAP | GPU_SAMPLER_ANISO); - } - else { - GPU_link(mat, "node_tex_environment_mirror_ball", in[0].link, &in[0].link); - /* Fix pole issue. */ - sampler &= ~GPU_SAMPLER_REPEAT; - } - - const char *gpu_fn; - static const char *names[] = { - "node_tex_image_linear", - "node_tex_image_cubic", - }; - - switch (tex->interpolation) { - case SHD_INTERP_LINEAR: - gpu_fn = names[0]; - break; - case SHD_INTERP_CLOSEST: - sampler &= ~(GPU_SAMPLER_FILTER | GPU_SAMPLER_MIPMAP); - gpu_fn = names[0]; - break; - default: - gpu_fn = names[1]; - break; - } - - /* Sample texture with correct interpolation. */ - GPU_link(mat, gpu_fn, in[0].link, GPU_image(mat, ima, iuser, sampler), &out[0].link, &outalpha); - - if (out[0].hasoutput) { - if (ELEM(ima->alpha_mode, IMA_ALPHA_IGNORE, IMA_ALPHA_CHANNEL_PACKED) || - IMB_colormanagement_space_name_is_data(ima->colorspace_settings.name)) { - /* Don't let alpha affect color output in these cases. */ - GPU_link(mat, "color_alpha_clear", out[0].link, &out[0].link); - } - else { - /* Always output with premultiplied alpha. */ - if (ima->alpha_mode == IMA_ALPHA_PREMUL) { - GPU_link(mat, "color_alpha_clear", out[0].link, &out[0].link); - } - else { - GPU_link(mat, "color_alpha_premultiply", out[0].link, &out[0].link); - } - } - } - - return true; -} - -/* node type definition */ -void register_node_type_sh_tex_environment(void) -{ - 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_storage( - &ntype, "NodeTexEnvironment", node_free_standard_storage, node_copy_standard_storage); - node_type_gpu(&ntype, node_shader_gpu_tex_environment); - ntype.labelfunc = node_image_label; - node_type_size_preset(&ntype, NODE_SIZE_LARGE); - - nodeRegisterType(&ntype); -} diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_environment.cc b/source/blender/nodes/shader/nodes/node_shader_tex_environment.cc new file mode 100644 index 00000000000..00bafd1a9d3 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_tex_environment.cc @@ -0,0 +1,157 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2005 Blender Foundation. + * All rights reserved. + */ + +#include "../node_shader_util.h" + +namespace blender::nodes::node_shader_tex_environment_cc { + +/* **************** OUTPUT ******************** */ + +static bNodeSocketTemplate sh_node_tex_environment_in[] = { + {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + {-1, ""}, +}; + +static bNodeSocketTemplate sh_node_tex_environment_out[] = { + {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, + {-1, ""}, +}; + +static void node_shader_init_tex_environment(bNodeTree *UNUSED(ntree), bNode *node) +{ + NodeTexEnvironment *tex = MEM_cnew("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; + BKE_imageuser_default(&tex->iuser); + + node->storage = tex; +} + +static int node_shader_gpu_tex_environment(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) +{ + Image *ima = (Image *)node->id; + 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 = (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. */ + if (true) { + sampler |= GPU_SAMPLER_MIPMAP; + } + + GPUNodeLink *outalpha; + + if (!ima) { + return GPU_stack_link(mat, node, "node_tex_environment_empty", in, out); + } + + if (!in[0].link) { + GPU_link(mat, "node_tex_environment_texco", GPU_builtin(GPU_VIEW_POSITION), &in[0].link); + node_shader_gpu_bump_tex_coord(mat, node, &in[0].link); + } + + node_shader_gpu_tex_mapping(mat, node, in, out); + + /* Compute texture coordinate. */ + if (tex->projection == SHD_PROJ_EQUIRECTANGULAR) { + GPU_link(mat, "node_tex_environment_equirectangular", in[0].link, &in[0].link); + /* To fix pole issue we clamp the v coordinate. */ + sampler &= ~GPU_SAMPLER_REPEAT_T; + /* Force the highest mipmap and don't do anisotropic filtering. + * This is to fix the artifact caused by derivatives discontinuity. */ + sampler &= ~(GPU_SAMPLER_MIPMAP | GPU_SAMPLER_ANISO); + } + else { + GPU_link(mat, "node_tex_environment_mirror_ball", in[0].link, &in[0].link); + /* Fix pole issue. */ + sampler &= ~GPU_SAMPLER_REPEAT; + } + + const char *gpu_fn; + static const char *names[] = { + "node_tex_image_linear", + "node_tex_image_cubic", + }; + + switch (tex->interpolation) { + case SHD_INTERP_LINEAR: + gpu_fn = names[0]; + break; + case SHD_INTERP_CLOSEST: + sampler &= ~(GPU_SAMPLER_FILTER | GPU_SAMPLER_MIPMAP); + gpu_fn = names[0]; + break; + default: + gpu_fn = names[1]; + break; + } + + /* Sample texture with correct interpolation. */ + GPU_link(mat, gpu_fn, in[0].link, GPU_image(mat, ima, iuser, sampler), &out[0].link, &outalpha); + + if (out[0].hasoutput) { + if (ELEM(ima->alpha_mode, IMA_ALPHA_IGNORE, IMA_ALPHA_CHANNEL_PACKED) || + IMB_colormanagement_space_name_is_data(ima->colorspace_settings.name)) { + /* Don't let alpha affect color output in these cases. */ + GPU_link(mat, "color_alpha_clear", out[0].link, &out[0].link); + } + else { + /* Always output with premultiplied alpha. */ + if (ima->alpha_mode == IMA_ALPHA_PREMUL) { + GPU_link(mat, "color_alpha_clear", out[0].link, &out[0].link); + } + else { + GPU_link(mat, "color_alpha_premultiply", out[0].link, &out[0].link); + } + } + } + + return true; +} + +} // namespace blender::nodes::node_shader_tex_environment_cc + +/* node type definition */ +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, 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, file_ns::node_shader_gpu_tex_environment); + ntype.labelfunc = node_image_label; + node_type_size_preset(&ntype, NODE_SIZE_LARGE); + + nodeRegisterType(&ntype); +} 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(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(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.c deleted file mode 100644 index 14cd1fd4c0c..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.c +++ /dev/null @@ -1,82 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2015 Blender Foundation. - * All rights reserved. - */ - -#include "../node_shader_util.h" - -#include "RE_texture.h" - -/* **************** OUTPUT ******************** */ - -static bNodeSocketTemplate sh_node_tex_pointdensity_in[] = { - {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - {-1, ""}, -}; - -static bNodeSocketTemplate sh_node_tex_pointdensity_out[] = { - {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - {SOCK_FLOAT, N_("Density"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f}, - {-1, ""}, -}; - -static void node_shader_init_tex_pointdensity(bNodeTree *UNUSED(ntree), bNode *node) -{ - NodeShaderTexPointDensity *point_density = MEM_callocN(sizeof(NodeShaderTexPointDensity), - "new pd node"); - point_density->resolution = 100; - point_density->radius = 0.3f; - point_density->space = SHD_POINTDENSITY_SPACE_OBJECT; - point_density->color_source = SHD_POINTDENSITY_COLOR_PARTAGE; - node->storage = point_density; -} - -static void node_shader_free_tex_pointdensity(bNode *node) -{ - NodeShaderTexPointDensity *point_density = node->storage; - PointDensity *pd = &point_density->pd; - RE_point_density_free(pd); - BKE_texture_pointdensity_free_data(pd); - memset(pd, 0, sizeof(*pd)); - MEM_freeN(point_density); -} - -static void node_shader_copy_tex_pointdensity(bNodeTree *UNUSED(dest_ntree), - bNode *dest_node, - const bNode *src_node) -{ - dest_node->storage = MEM_dupallocN(src_node->storage); - NodeShaderTexPointDensity *point_density = dest_node->storage; - PointDensity *pd = &point_density->pd; - memset(pd, 0, sizeof(*pd)); -} - -/* node type definition */ -void register_node_type_sh_tex_pointdensity(void) -{ - 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_storage(&ntype, - "NodeShaderTexPointDensity", - node_shader_free_tex_pointdensity, - node_shader_copy_tex_pointdensity); - - nodeRegisterType(&ntype); -} diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.cc b/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.cc new file mode 100644 index 00000000000..8e57be6ee8d --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.cc @@ -0,0 +1,88 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2015 Blender Foundation. + * All rights reserved. + */ + +#include "../node_shader_util.h" + +#include "RE_texture.h" + +namespace blender::nodes::node_shader_tex_pointdensity_cc { + +/* **************** OUTPUT ******************** */ + +static bNodeSocketTemplate sh_node_tex_pointdensity_in[] = { + {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + {-1, ""}, +}; + +static bNodeSocketTemplate sh_node_tex_pointdensity_out[] = { + {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, N_("Density"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f}, + {-1, ""}, +}; + +static void node_shader_init_tex_pointdensity(bNodeTree *UNUSED(ntree), bNode *node) +{ + NodeShaderTexPointDensity *point_density = MEM_cnew("new pd node"); + point_density->resolution = 100; + point_density->radius = 0.3f; + point_density->space = SHD_POINTDENSITY_SPACE_OBJECT; + point_density->color_source = SHD_POINTDENSITY_COLOR_PARTAGE; + node->storage = point_density; +} + +static void node_shader_free_tex_pointdensity(bNode *node) +{ + NodeShaderTexPointDensity *point_density = (NodeShaderTexPointDensity *)node->storage; + PointDensity *pd = &point_density->pd; + RE_point_density_free(pd); + BKE_texture_pointdensity_free_data(pd); + memset(pd, 0, sizeof(*pd)); + MEM_freeN(point_density); +} + +static void node_shader_copy_tex_pointdensity(bNodeTree *UNUSED(dest_ntree), + bNode *dest_node, + const bNode *src_node) +{ + dest_node->storage = MEM_dupallocN(src_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() +{ + 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, 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", + 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.c deleted file mode 100644 index 5c581528c14..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_tex_sky.c +++ /dev/null @@ -1,221 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - */ - -#include "../node_shader_util.h" -#include "sky_model.h" - -/* **************** OUTPUT ******************** */ - -static bNodeSocketTemplate sh_node_tex_sky_in[] = { - {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - {-1, ""}, -}; - -static bNodeSocketTemplate sh_node_tex_sky_out[] = { - {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - {-1, ""}, -}; - -static void node_shader_init_tex_sky(bNodeTree *UNUSED(ntree), bNode *node) -{ - NodeTexSky *tex = MEM_callocN(sizeof(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; - tex->sun_direction[1] = 0.0f; - tex->sun_direction[2] = 1.0f; - tex->turbidity = 2.2f; - tex->ground_albedo = 0.3f; - tex->sun_disc = true; - tex->sun_size = DEG2RADF(0.545f); - tex->sun_intensity = 1.0f; - tex->sun_elevation = DEG2RADF(15.0f); - tex->sun_rotation = 0.0f; - tex->altitude = 0.0f; - tex->air_density = 1.0f; - tex->dust_density = 1.0f; - tex->ozone_density = 1.0f; - tex->sky_model = SHD_SKY_NISHITA; - node->storage = tex; -} - -typedef 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) -{ - float ctheta = cosf(theta); - float cgamma = cosf(gamma); - - return (1.0 + lam[0] * expf(lam[1] / ctheta)) * - (1.0 + lam[2] * expf(lam[3] * gamma) + lam[4] * cgamma * cgamma); -} - -static void sky_precompute_old(SkyModelPreetham *sunsky, const float sun_angles[], float turbidity) -{ - float theta = sun_angles[0]; - float theta2 = theta * theta; - float theta3 = theta2 * theta; - float T = turbidity; - float T2 = T * T; - float chi = (4.0f / 9.0f - T / 120.0f) * (M_PI - 2.0f * theta); - - sunsky->radiance[0] = (4.0453f * T - 4.9710f) * tanf(chi) - 0.2155f * T + 2.4192f; - sunsky->radiance[0] *= 0.06f; - - sunsky->radiance[1] = (0.00166f * theta3 - 0.00375f * theta2 + 0.00209f * theta) * T2 + - (-0.02903f * theta3 + 0.06377f * theta2 - 0.03202f * theta + 0.00394f) * - T + - (0.11693f * theta3 - 0.21196f * theta2 + 0.06052f * theta + 0.25886f); - - sunsky->radiance[2] = (0.00275f * theta3 - 0.00610f * theta2 + 0.00317f * theta) * T2 + - (-0.04214f * theta3 + 0.08970f * theta2 - 0.04153f * theta + 0.00516f) * - T + - (0.15346f * theta3 - 0.26756f * theta2 + 0.06670f * theta + 0.26688f); - - sunsky->config_Y[0] = (0.1787f * T - 1.4630f); - sunsky->config_Y[1] = (-0.3554f * T + 0.4275f); - sunsky->config_Y[2] = (-0.0227f * T + 5.3251f); - sunsky->config_Y[3] = (0.1206f * T - 2.5771f); - sunsky->config_Y[4] = (-0.0670f * T + 0.3703f); - - sunsky->config_x[0] = (-0.0193f * T - 0.2592f); - sunsky->config_x[1] = (-0.0665f * T + 0.0008f); - sunsky->config_x[2] = (-0.0004f * T + 0.2125f); - sunsky->config_x[3] = (-0.0641f * T - 0.8989f); - sunsky->config_x[4] = (-0.0033f * T + 0.0452f); - - sunsky->config_y[0] = (-0.0167f * T - 0.2608f); - sunsky->config_y[1] = (-0.0950f * T + 0.0092f); - sunsky->config_y[2] = (-0.0079f * T + 0.2102f); - sunsky->config_y[3] = (-0.0441f * T - 1.6537f); - sunsky->config_y[4] = (-0.0109f * T + 0.0529f); - - sunsky->radiance[0] /= sky_perez_function(sunsky->config_Y, 0, theta); - sunsky->radiance[1] /= sky_perez_function(sunsky->config_x, 0, theta); - sunsky->radiance[2] /= sky_perez_function(sunsky->config_y, 0, theta); -} - -static int node_shader_gpu_tex_sky(GPUMaterial *mat, - bNode *node, - bNodeExecData *UNUSED(execdata), - GPUNodeStack *in, - GPUNodeStack *out) -{ - node_shader_gpu_default_tex_coord(mat, node, &in[0].link); - node_shader_gpu_tex_mapping(mat, node, in, out); - NodeTexSky *tex = (NodeTexSky *)node->storage; - float sun_angles[2]; /* [0]=theta=zenith angle [1]=phi=azimuth */ - sun_angles[0] = acosf(tex->sun_direction[2]); - sun_angles[1] = atan2f(tex->sun_direction[0], tex->sun_direction[1]); - - if (tex->sky_model == 0) { - /* Preetham */ - SkyModelPreetham sunsky; - sky_precompute_old(&sunsky, sun_angles, tex->turbidity); - XYZ_to_RGB xyz_to_rgb; - get_XYZ_to_RGB_for_gpu(&xyz_to_rgb); - return GPU_stack_link(mat, - node, - "node_tex_sky_preetham", - in, - out, - /* Pass config_Y/x/y as 3x(vec4+float) */ - GPU_uniform(&sunsky.config_Y[0]), - GPU_uniform(&sunsky.config_Y[4]), - GPU_uniform(&sunsky.config_x[0]), - GPU_uniform(&sunsky.config_x[4]), - GPU_uniform(&sunsky.config_y[0]), - GPU_uniform(&sunsky.config_y[4]), - GPU_uniform(sun_angles), - GPU_uniform(sunsky.radiance), - GPU_uniform(xyz_to_rgb.r), - GPU_uniform(xyz_to_rgb.g), - GPU_uniform(xyz_to_rgb.b)); - } - if (tex->sky_model == 1) { - /* Hosek / Wilkie */ - sun_angles[0] = fmin(M_PI_2, sun_angles[0]); /* clamp to horizon */ - SKY_ArHosekSkyModelState *sky_state = SKY_arhosek_xyz_skymodelstate_alloc_init( - tex->turbidity, tex->ground_albedo, fmax(0.0, M_PI_2 - sun_angles[0])); - /* Pass sky_state->configs[3][9] as 3*(vec4+vec4)+vec3 */ - float config_x07[8], config_y07[8], config_z07[8], config_xyz8[3]; - for (int i = 0; i < 8; ++i) { - config_x07[i] = (float)sky_state->configs[0][i]; - config_y07[i] = (float)sky_state->configs[1][i]; - config_z07[i] = (float)sky_state->configs[2][i]; - } - for (int i = 0; i < 3; ++i) { - config_xyz8[i] = (float)sky_state->configs[i][8]; - } - float radiance[3]; - for (int i = 0; i < 3; i++) { - radiance[i] = sky_state->radiances[i] * (2 * M_PI / 683); - } - SKY_arhosekskymodelstate_free(sky_state); - XYZ_to_RGB xyz_to_rgb; - get_XYZ_to_RGB_for_gpu(&xyz_to_rgb); - return GPU_stack_link(mat, - node, - "node_tex_sky_hosekwilkie", - in, - out, - GPU_uniform(&config_x07[0]), - GPU_uniform(&config_x07[4]), - GPU_uniform(&config_y07[0]), - GPU_uniform(&config_y07[4]), - GPU_uniform(&config_z07[0]), - GPU_uniform(&config_z07[4]), - GPU_uniform(config_xyz8), - GPU_uniform(sun_angles), - GPU_uniform(radiance), - GPU_uniform(xyz_to_rgb.r), - GPU_uniform(xyz_to_rgb.g), - GPU_uniform(xyz_to_rgb.b)); - } - - return GPU_stack_link(mat, node, "node_tex_sky_nishita", in, out); -} - -static void node_shader_update_sky(bNodeTree *ntree, bNode *node) -{ - bNodeSocket *sockVector = nodeFindSocket(node, SOCK_IN, "Vector"); - - NodeTexSky *tex = (NodeTexSky *)node->storage; - nodeSetSocketAvailability(ntree, sockVector, !(tex->sky_model == 2 && tex->sun_disc == 1)); -} - -/* node type definition */ -void register_node_type_sh_tex_sky(void) -{ - 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_size_preset(&ntype, NODE_SIZE_MIDDLE); - node_type_init(&ntype, 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); - /* remove Vector input for Nishita */ - node_type_update(&ntype, node_shader_update_sky); - - nodeRegisterType(&ntype); -} diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_sky.cc b/source/blender/nodes/shader/nodes/node_shader_tex_sky.cc new file mode 100644 index 00000000000..6067bcdbfcc --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_tex_sky.cc @@ -0,0 +1,227 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2005 Blender Foundation. + * All rights reserved. + */ + +#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[] = { + {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + {-1, ""}, +}; + +static bNodeSocketTemplate sh_node_tex_sky_out[] = { + {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, + {-1, ""}, +}; + +static void node_shader_init_tex_sky(bNodeTree *UNUSED(ntree), bNode *node) +{ + NodeTexSky *tex = MEM_cnew("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; + tex->sun_direction[1] = 0.0f; + tex->sun_direction[2] = 1.0f; + tex->turbidity = 2.2f; + tex->ground_albedo = 0.3f; + tex->sun_disc = true; + tex->sun_size = DEG2RADF(0.545f); + tex->sun_intensity = 1.0f; + tex->sun_elevation = DEG2RADF(15.0f); + tex->sun_rotation = 0.0f; + tex->altitude = 0.0f; + tex->air_density = 1.0f; + tex->dust_density = 1.0f; + tex->ozone_density = 1.0f; + tex->sky_model = SHD_SKY_NISHITA; + node->storage = tex; +} + +struct SkyModelPreetham { + float config_Y[5], config_x[5], config_y[5]; /* named after xyY color space */ + float radiance[3]; +}; + +static float sky_perez_function(const float *lam, float theta, float gamma) +{ + float ctheta = cosf(theta); + float cgamma = cosf(gamma); + + return (1.0 + lam[0] * expf(lam[1] / ctheta)) * + (1.0 + lam[2] * expf(lam[3] * gamma) + lam[4] * cgamma * cgamma); +} + +static void sky_precompute_old(SkyModelPreetham *sunsky, const float sun_angles[], float turbidity) +{ + float theta = sun_angles[0]; + float theta2 = theta * theta; + float theta3 = theta2 * theta; + float T = turbidity; + float T2 = T * T; + float chi = (4.0f / 9.0f - T / 120.0f) * (M_PI - 2.0f * theta); + + sunsky->radiance[0] = (4.0453f * T - 4.9710f) * tanf(chi) - 0.2155f * T + 2.4192f; + sunsky->radiance[0] *= 0.06f; + + sunsky->radiance[1] = (0.00166f * theta3 - 0.00375f * theta2 + 0.00209f * theta) * T2 + + (-0.02903f * theta3 + 0.06377f * theta2 - 0.03202f * theta + 0.00394f) * + T + + (0.11693f * theta3 - 0.21196f * theta2 + 0.06052f * theta + 0.25886f); + + sunsky->radiance[2] = (0.00275f * theta3 - 0.00610f * theta2 + 0.00317f * theta) * T2 + + (-0.04214f * theta3 + 0.08970f * theta2 - 0.04153f * theta + 0.00516f) * + T + + (0.15346f * theta3 - 0.26756f * theta2 + 0.06670f * theta + 0.26688f); + + sunsky->config_Y[0] = (0.1787f * T - 1.4630f); + sunsky->config_Y[1] = (-0.3554f * T + 0.4275f); + sunsky->config_Y[2] = (-0.0227f * T + 5.3251f); + sunsky->config_Y[3] = (0.1206f * T - 2.5771f); + sunsky->config_Y[4] = (-0.0670f * T + 0.3703f); + + sunsky->config_x[0] = (-0.0193f * T - 0.2592f); + sunsky->config_x[1] = (-0.0665f * T + 0.0008f); + sunsky->config_x[2] = (-0.0004f * T + 0.2125f); + sunsky->config_x[3] = (-0.0641f * T - 0.8989f); + sunsky->config_x[4] = (-0.0033f * T + 0.0452f); + + sunsky->config_y[0] = (-0.0167f * T - 0.2608f); + sunsky->config_y[1] = (-0.0950f * T + 0.0092f); + sunsky->config_y[2] = (-0.0079f * T + 0.2102f); + sunsky->config_y[3] = (-0.0441f * T - 1.6537f); + sunsky->config_y[4] = (-0.0109f * T + 0.0529f); + + sunsky->radiance[0] /= sky_perez_function(sunsky->config_Y, 0, theta); + sunsky->radiance[1] /= sky_perez_function(sunsky->config_x, 0, theta); + sunsky->radiance[2] /= sky_perez_function(sunsky->config_y, 0, theta); +} + +static int node_shader_gpu_tex_sky(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) +{ + node_shader_gpu_default_tex_coord(mat, node, &in[0].link); + node_shader_gpu_tex_mapping(mat, node, in, out); + NodeTexSky *tex = (NodeTexSky *)node->storage; + float sun_angles[2]; /* [0]=theta=zenith angle [1]=phi=azimuth */ + sun_angles[0] = acosf(tex->sun_direction[2]); + sun_angles[1] = atan2f(tex->sun_direction[0], tex->sun_direction[1]); + + if (tex->sky_model == 0) { + /* Preetham */ + SkyModelPreetham sunsky; + sky_precompute_old(&sunsky, sun_angles, tex->turbidity); + XYZ_to_RGB xyz_to_rgb; + get_XYZ_to_RGB_for_gpu(&xyz_to_rgb); + return GPU_stack_link(mat, + node, + "node_tex_sky_preetham", + in, + out, + /* Pass config_Y/x/y as 3x(vec4+float) */ + GPU_uniform(&sunsky.config_Y[0]), + GPU_uniform(&sunsky.config_Y[4]), + GPU_uniform(&sunsky.config_x[0]), + GPU_uniform(&sunsky.config_x[4]), + GPU_uniform(&sunsky.config_y[0]), + GPU_uniform(&sunsky.config_y[4]), + GPU_uniform(sun_angles), + GPU_uniform(sunsky.radiance), + GPU_uniform(xyz_to_rgb.r), + GPU_uniform(xyz_to_rgb.g), + GPU_uniform(xyz_to_rgb.b)); + } + if (tex->sky_model == 1) { + /* Hosek / Wilkie */ + sun_angles[0] = fmin(M_PI_2, sun_angles[0]); /* clamp to horizon */ + SKY_ArHosekSkyModelState *sky_state = SKY_arhosek_xyz_skymodelstate_alloc_init( + tex->turbidity, tex->ground_albedo, fmax(0.0, M_PI_2 - sun_angles[0])); + /* Pass sky_state->configs[3][9] as 3*(vec4+vec4)+vec3 */ + float config_x07[8], config_y07[8], config_z07[8], config_xyz8[3]; + for (int i = 0; i < 8; ++i) { + config_x07[i] = (float)sky_state->configs[0][i]; + config_y07[i] = (float)sky_state->configs[1][i]; + config_z07[i] = (float)sky_state->configs[2][i]; + } + for (int i = 0; i < 3; ++i) { + config_xyz8[i] = (float)sky_state->configs[i][8]; + } + float radiance[3]; + for (int i = 0; i < 3; i++) { + radiance[i] = sky_state->radiances[i] * (2 * M_PI / 683); + } + SKY_arhosekskymodelstate_free(sky_state); + XYZ_to_RGB xyz_to_rgb; + get_XYZ_to_RGB_for_gpu(&xyz_to_rgb); + return GPU_stack_link(mat, + node, + "node_tex_sky_hosekwilkie", + in, + out, + GPU_uniform(&config_x07[0]), + GPU_uniform(&config_x07[4]), + GPU_uniform(&config_y07[0]), + GPU_uniform(&config_y07[4]), + GPU_uniform(&config_z07[0]), + GPU_uniform(&config_z07[4]), + GPU_uniform(config_xyz8), + GPU_uniform(sun_angles), + GPU_uniform(radiance), + GPU_uniform(xyz_to_rgb.r), + GPU_uniform(xyz_to_rgb.g), + GPU_uniform(xyz_to_rgb.b)); + } + + return GPU_stack_link(mat, node, "node_tex_sky_nishita", in, out); +} + +static void node_shader_update_sky(bNodeTree *ntree, bNode *node) +{ + bNodeSocket *sockVector = nodeFindSocket(node, SOCK_IN, "Vector"); + + NodeTexSky *tex = (NodeTexSky *)node->storage; + 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() +{ + 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, 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, file_ns::node_shader_init_tex_sky); + node_type_storage(&ntype, "NodeTexSky", node_free_standard_storage, node_copy_standard_storage); + node_type_gpu(&ntype, file_ns::node_shader_gpu_tex_sky); + /* remove Vector input for Nishita */ + 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((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; -- cgit v1.2.3