diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:17:24 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:21:24 +0300 |
commit | e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch) | |
tree | 8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/nodes | |
parent | b3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff) |
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.
For details on usage and instructions for migrating branches
without conflicts, see:
https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/nodes')
209 files changed, 10818 insertions, 9535 deletions
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt index f58c43cf44f..b76a87d7132 100644 --- a/source/blender/nodes/CMakeLists.txt +++ b/source/blender/nodes/CMakeLists.txt @@ -19,277 +19,277 @@ # ***** END GPL LICENSE BLOCK ***** set(INC - . - composite - intern - shader - texture - ../blenkernel - ../blenlib - ../blentranslation - ../depsgraph - ../gpu - ../imbuf - ../makesdna - ../makesrna - ../render/extern/include - ../../../intern/guardedalloc - ../../../intern/glew-mx + . + composite + intern + shader + texture + ../blenkernel + ../blenlib + ../blentranslation + ../depsgraph + ../gpu + ../imbuf + ../makesdna + ../makesrna + ../render/extern/include + ../../../intern/guardedalloc + ../../../intern/glew-mx ) set(INC_SYS - ${GLEW_INCLUDE_PATH} + ${GLEW_INCLUDE_PATH} ) set(SRC - composite/nodes/node_composite_alphaOver.c - composite/nodes/node_composite_bilateralblur.c - composite/nodes/node_composite_blur.c - composite/nodes/node_composite_bokehblur.c - composite/nodes/node_composite_bokehimage.c - composite/nodes/node_composite_boxmask.c - composite/nodes/node_composite_brightness.c - composite/nodes/node_composite_channelMatte.c - composite/nodes/node_composite_chromaMatte.c - composite/nodes/node_composite_colorMatte.c - composite/nodes/node_composite_colorSpill.c - composite/nodes/node_composite_colorbalance.c - composite/nodes/node_composite_colorcorrection.c - composite/nodes/node_composite_common.c - composite/nodes/node_composite_composite.c - composite/nodes/node_composite_cornerpin.c - composite/nodes/node_composite_crop.c - composite/nodes/node_composite_cryptomatte.c - composite/nodes/node_composite_curves.c - composite/nodes/node_composite_defocus.c - composite/nodes/node_composite_despeckle.c - composite/nodes/node_composite_diffMatte.c - composite/nodes/node_composite_dilate.c - composite/nodes/node_composite_directionalblur.c - composite/nodes/node_composite_displace.c - composite/nodes/node_composite_distanceMatte.c - composite/nodes/node_composite_doubleEdgeMask.c - composite/nodes/node_composite_ellipsemask.c - composite/nodes/node_composite_filter.c - composite/nodes/node_composite_flip.c - composite/nodes/node_composite_gamma.c - composite/nodes/node_composite_glare.c - composite/nodes/node_composite_hueSatVal.c - composite/nodes/node_composite_huecorrect.c - composite/nodes/node_composite_idMask.c - composite/nodes/node_composite_image.c - composite/nodes/node_composite_inpaint.c - composite/nodes/node_composite_invert.c - composite/nodes/node_composite_keying.c - composite/nodes/node_composite_keyingscreen.c - composite/nodes/node_composite_lensdist.c - composite/nodes/node_composite_levels.c - composite/nodes/node_composite_lummaMatte.c - composite/nodes/node_composite_mapRange.c - composite/nodes/node_composite_mapUV.c - composite/nodes/node_composite_mapValue.c - composite/nodes/node_composite_mask.c - composite/nodes/node_composite_math.c - composite/nodes/node_composite_mixrgb.c - composite/nodes/node_composite_movieclip.c - composite/nodes/node_composite_moviedistortion.c - composite/nodes/node_composite_normal.c - composite/nodes/node_composite_normalize.c - composite/nodes/node_composite_outputFile.c - composite/nodes/node_composite_pixelate.c - composite/nodes/node_composite_planetrackdeform.c - composite/nodes/node_composite_premulkey.c - composite/nodes/node_composite_rgb.c - composite/nodes/node_composite_rotate.c - composite/nodes/node_composite_scale.c - composite/nodes/node_composite_sepcombHSVA.c - composite/nodes/node_composite_sepcombRGBA.c - composite/nodes/node_composite_sepcombYCCA.c - composite/nodes/node_composite_sepcombYUVA.c - composite/nodes/node_composite_setalpha.c - composite/nodes/node_composite_splitViewer.c - composite/nodes/node_composite_stabilize2d.c - composite/nodes/node_composite_sunbeams.c - composite/nodes/node_composite_switch.c - composite/nodes/node_composite_switchview.c - composite/nodes/node_composite_texture.c - composite/nodes/node_composite_tonemap.c - composite/nodes/node_composite_trackpos.c - composite/nodes/node_composite_transform.c - composite/nodes/node_composite_translate.c - composite/nodes/node_composite_valToRgb.c - composite/nodes/node_composite_value.c - composite/nodes/node_composite_vecBlur.c - composite/nodes/node_composite_viewer.c - composite/nodes/node_composite_zcombine.c + composite/nodes/node_composite_alphaOver.c + composite/nodes/node_composite_bilateralblur.c + composite/nodes/node_composite_blur.c + composite/nodes/node_composite_bokehblur.c + composite/nodes/node_composite_bokehimage.c + composite/nodes/node_composite_boxmask.c + composite/nodes/node_composite_brightness.c + composite/nodes/node_composite_channelMatte.c + composite/nodes/node_composite_chromaMatte.c + composite/nodes/node_composite_colorMatte.c + composite/nodes/node_composite_colorSpill.c + composite/nodes/node_composite_colorbalance.c + composite/nodes/node_composite_colorcorrection.c + composite/nodes/node_composite_common.c + composite/nodes/node_composite_composite.c + composite/nodes/node_composite_cornerpin.c + composite/nodes/node_composite_crop.c + composite/nodes/node_composite_cryptomatte.c + composite/nodes/node_composite_curves.c + composite/nodes/node_composite_defocus.c + composite/nodes/node_composite_despeckle.c + composite/nodes/node_composite_diffMatte.c + composite/nodes/node_composite_dilate.c + composite/nodes/node_composite_directionalblur.c + composite/nodes/node_composite_displace.c + composite/nodes/node_composite_distanceMatte.c + composite/nodes/node_composite_doubleEdgeMask.c + composite/nodes/node_composite_ellipsemask.c + composite/nodes/node_composite_filter.c + composite/nodes/node_composite_flip.c + composite/nodes/node_composite_gamma.c + composite/nodes/node_composite_glare.c + composite/nodes/node_composite_hueSatVal.c + composite/nodes/node_composite_huecorrect.c + composite/nodes/node_composite_idMask.c + composite/nodes/node_composite_image.c + composite/nodes/node_composite_inpaint.c + composite/nodes/node_composite_invert.c + composite/nodes/node_composite_keying.c + composite/nodes/node_composite_keyingscreen.c + composite/nodes/node_composite_lensdist.c + composite/nodes/node_composite_levels.c + composite/nodes/node_composite_lummaMatte.c + composite/nodes/node_composite_mapRange.c + composite/nodes/node_composite_mapUV.c + composite/nodes/node_composite_mapValue.c + composite/nodes/node_composite_mask.c + composite/nodes/node_composite_math.c + composite/nodes/node_composite_mixrgb.c + composite/nodes/node_composite_movieclip.c + composite/nodes/node_composite_moviedistortion.c + composite/nodes/node_composite_normal.c + composite/nodes/node_composite_normalize.c + composite/nodes/node_composite_outputFile.c + composite/nodes/node_composite_pixelate.c + composite/nodes/node_composite_planetrackdeform.c + composite/nodes/node_composite_premulkey.c + composite/nodes/node_composite_rgb.c + composite/nodes/node_composite_rotate.c + composite/nodes/node_composite_scale.c + composite/nodes/node_composite_sepcombHSVA.c + composite/nodes/node_composite_sepcombRGBA.c + composite/nodes/node_composite_sepcombYCCA.c + composite/nodes/node_composite_sepcombYUVA.c + composite/nodes/node_composite_setalpha.c + composite/nodes/node_composite_splitViewer.c + composite/nodes/node_composite_stabilize2d.c + composite/nodes/node_composite_sunbeams.c + composite/nodes/node_composite_switch.c + composite/nodes/node_composite_switchview.c + composite/nodes/node_composite_texture.c + composite/nodes/node_composite_tonemap.c + composite/nodes/node_composite_trackpos.c + composite/nodes/node_composite_transform.c + composite/nodes/node_composite_translate.c + composite/nodes/node_composite_valToRgb.c + composite/nodes/node_composite_value.c + composite/nodes/node_composite_vecBlur.c + composite/nodes/node_composite_viewer.c + composite/nodes/node_composite_zcombine.c - composite/node_composite_tree.c - composite/node_composite_util.c + composite/node_composite_tree.c + composite/node_composite_util.c - shader/nodes/node_shader_add_shader.c - shader/nodes/node_shader_ambient_occlusion.c - shader/nodes/node_shader_attribute.c - shader/nodes/node_shader_background.c - shader/nodes/node_shader_bevel.c - shader/nodes/node_shader_blackbody.c - shader/nodes/node_shader_brightness.c - shader/nodes/node_shader_bsdf_anisotropic.c - shader/nodes/node_shader_bsdf_diffuse.c - shader/nodes/node_shader_bsdf_glass.c - shader/nodes/node_shader_bsdf_glossy.c - shader/nodes/node_shader_bsdf_hair.c - shader/nodes/node_shader_bsdf_hair_principled.c - shader/nodes/node_shader_bsdf_principled.c - shader/nodes/node_shader_bsdf_refraction.c - shader/nodes/node_shader_bsdf_toon.c - shader/nodes/node_shader_bsdf_translucent.c - shader/nodes/node_shader_bsdf_transparent.c - shader/nodes/node_shader_bsdf_velvet.c - shader/nodes/node_shader_bump.c - shader/nodes/node_shader_camera.c - shader/nodes/node_shader_common.c - shader/nodes/node_shader_curves.c - shader/nodes/node_shader_displacement.c - shader/nodes/node_shader_eevee_specular.c - shader/nodes/node_shader_emission.c - shader/nodes/node_shader_fresnel.c - shader/nodes/node_shader_gamma.c - shader/nodes/node_shader_geometry.c - shader/nodes/node_shader_hair_info.c - shader/nodes/node_shader_holdout.c - shader/nodes/node_shader_hueSatVal.c - shader/nodes/node_shader_ies_light.c - shader/nodes/node_shader_invert.c - shader/nodes/node_shader_layer_weight.c - shader/nodes/node_shader_light_falloff.c - shader/nodes/node_shader_light_path.c - shader/nodes/node_shader_mapping.c - shader/nodes/node_shader_math.c - shader/nodes/node_shader_mixRgb.c - shader/nodes/node_shader_mix_shader.c - shader/nodes/node_shader_normal.c - shader/nodes/node_shader_normal_map.c - shader/nodes/node_shader_object_info.c - shader/nodes/node_shader_output_light.c - shader/nodes/node_shader_output_linestyle.c - shader/nodes/node_shader_output_material.c - shader/nodes/node_shader_output_world.c - shader/nodes/node_shader_particle_info.c - shader/nodes/node_shader_rgb.c - shader/nodes/node_shader_script.c - shader/nodes/node_shader_sepcombHSV.c - shader/nodes/node_shader_sepcombRGB.c - shader/nodes/node_shader_sepcombXYZ.c - shader/nodes/node_shader_shaderToRgb.c - shader/nodes/node_shader_squeeze.c - shader/nodes/node_shader_subsurface_scattering.c - shader/nodes/node_shader_tangent.c - shader/nodes/node_shader_tex_brick.c - shader/nodes/node_shader_tex_checker.c - shader/nodes/node_shader_tex_coord.c - shader/nodes/node_shader_tex_environment.c - shader/nodes/node_shader_tex_gradient.c - shader/nodes/node_shader_tex_image.c - shader/nodes/node_shader_tex_magic.c - shader/nodes/node_shader_tex_musgrave.c - shader/nodes/node_shader_tex_noise.c - shader/nodes/node_shader_tex_pointdensity.c - shader/nodes/node_shader_tex_sky.c - shader/nodes/node_shader_tex_voronoi.c - shader/nodes/node_shader_tex_wave.c - shader/nodes/node_shader_uvAlongStroke.c - shader/nodes/node_shader_uvmap.c - shader/nodes/node_shader_valToRgb.c - shader/nodes/node_shader_value.c - shader/nodes/node_shader_vectMath.c - shader/nodes/node_shader_vectTransform.c - shader/nodes/node_shader_vector_displacement.c - shader/nodes/node_shader_volume_absorption.c - shader/nodes/node_shader_volume_principled.c - shader/nodes/node_shader_volume_scatter.c - shader/nodes/node_shader_wavelength.c - shader/nodes/node_shader_wireframe.c - shader/node_shader_tree.c - shader/node_shader_util.c + shader/nodes/node_shader_add_shader.c + shader/nodes/node_shader_ambient_occlusion.c + shader/nodes/node_shader_attribute.c + shader/nodes/node_shader_background.c + shader/nodes/node_shader_bevel.c + shader/nodes/node_shader_blackbody.c + shader/nodes/node_shader_brightness.c + shader/nodes/node_shader_bsdf_anisotropic.c + shader/nodes/node_shader_bsdf_diffuse.c + shader/nodes/node_shader_bsdf_glass.c + shader/nodes/node_shader_bsdf_glossy.c + shader/nodes/node_shader_bsdf_hair.c + shader/nodes/node_shader_bsdf_hair_principled.c + shader/nodes/node_shader_bsdf_principled.c + shader/nodes/node_shader_bsdf_refraction.c + shader/nodes/node_shader_bsdf_toon.c + shader/nodes/node_shader_bsdf_translucent.c + shader/nodes/node_shader_bsdf_transparent.c + shader/nodes/node_shader_bsdf_velvet.c + shader/nodes/node_shader_bump.c + shader/nodes/node_shader_camera.c + shader/nodes/node_shader_common.c + shader/nodes/node_shader_curves.c + shader/nodes/node_shader_displacement.c + shader/nodes/node_shader_eevee_specular.c + shader/nodes/node_shader_emission.c + shader/nodes/node_shader_fresnel.c + shader/nodes/node_shader_gamma.c + shader/nodes/node_shader_geometry.c + shader/nodes/node_shader_hair_info.c + shader/nodes/node_shader_holdout.c + shader/nodes/node_shader_hueSatVal.c + shader/nodes/node_shader_ies_light.c + shader/nodes/node_shader_invert.c + shader/nodes/node_shader_layer_weight.c + shader/nodes/node_shader_light_falloff.c + shader/nodes/node_shader_light_path.c + shader/nodes/node_shader_mapping.c + shader/nodes/node_shader_math.c + shader/nodes/node_shader_mixRgb.c + shader/nodes/node_shader_mix_shader.c + shader/nodes/node_shader_normal.c + shader/nodes/node_shader_normal_map.c + shader/nodes/node_shader_object_info.c + shader/nodes/node_shader_output_light.c + shader/nodes/node_shader_output_linestyle.c + shader/nodes/node_shader_output_material.c + shader/nodes/node_shader_output_world.c + shader/nodes/node_shader_particle_info.c + shader/nodes/node_shader_rgb.c + shader/nodes/node_shader_script.c + shader/nodes/node_shader_sepcombHSV.c + shader/nodes/node_shader_sepcombRGB.c + shader/nodes/node_shader_sepcombXYZ.c + shader/nodes/node_shader_shaderToRgb.c + shader/nodes/node_shader_squeeze.c + shader/nodes/node_shader_subsurface_scattering.c + shader/nodes/node_shader_tangent.c + shader/nodes/node_shader_tex_brick.c + shader/nodes/node_shader_tex_checker.c + shader/nodes/node_shader_tex_coord.c + shader/nodes/node_shader_tex_environment.c + shader/nodes/node_shader_tex_gradient.c + shader/nodes/node_shader_tex_image.c + shader/nodes/node_shader_tex_magic.c + shader/nodes/node_shader_tex_musgrave.c + shader/nodes/node_shader_tex_noise.c + shader/nodes/node_shader_tex_pointdensity.c + shader/nodes/node_shader_tex_sky.c + shader/nodes/node_shader_tex_voronoi.c + shader/nodes/node_shader_tex_wave.c + shader/nodes/node_shader_uvAlongStroke.c + shader/nodes/node_shader_uvmap.c + shader/nodes/node_shader_valToRgb.c + shader/nodes/node_shader_value.c + shader/nodes/node_shader_vectMath.c + shader/nodes/node_shader_vectTransform.c + shader/nodes/node_shader_vector_displacement.c + shader/nodes/node_shader_volume_absorption.c + shader/nodes/node_shader_volume_principled.c + shader/nodes/node_shader_volume_scatter.c + shader/nodes/node_shader_wavelength.c + shader/nodes/node_shader_wireframe.c + shader/node_shader_tree.c + shader/node_shader_util.c - texture/nodes/node_texture_at.c - texture/nodes/node_texture_bricks.c - texture/nodes/node_texture_checker.c - texture/nodes/node_texture_common.c - texture/nodes/node_texture_compose.c - texture/nodes/node_texture_coord.c - texture/nodes/node_texture_curves.c - texture/nodes/node_texture_decompose.c - texture/nodes/node_texture_distance.c - texture/nodes/node_texture_hueSatVal.c - texture/nodes/node_texture_image.c - texture/nodes/node_texture_invert.c - texture/nodes/node_texture_math.c - texture/nodes/node_texture_mixRgb.c - texture/nodes/node_texture_output.c - texture/nodes/node_texture_proc.c - texture/nodes/node_texture_rotate.c - texture/nodes/node_texture_scale.c - texture/nodes/node_texture_texture.c - texture/nodes/node_texture_translate.c - texture/nodes/node_texture_valToNor.c - texture/nodes/node_texture_valToRgb.c - texture/nodes/node_texture_viewer.c - texture/node_texture_tree.c - texture/node_texture_util.c + texture/nodes/node_texture_at.c + texture/nodes/node_texture_bricks.c + texture/nodes/node_texture_checker.c + texture/nodes/node_texture_common.c + texture/nodes/node_texture_compose.c + texture/nodes/node_texture_coord.c + texture/nodes/node_texture_curves.c + texture/nodes/node_texture_decompose.c + texture/nodes/node_texture_distance.c + texture/nodes/node_texture_hueSatVal.c + texture/nodes/node_texture_image.c + texture/nodes/node_texture_invert.c + texture/nodes/node_texture_math.c + texture/nodes/node_texture_mixRgb.c + texture/nodes/node_texture_output.c + texture/nodes/node_texture_proc.c + texture/nodes/node_texture_rotate.c + texture/nodes/node_texture_scale.c + texture/nodes/node_texture_texture.c + texture/nodes/node_texture_translate.c + texture/nodes/node_texture_valToNor.c + texture/nodes/node_texture_valToRgb.c + texture/nodes/node_texture_viewer.c + texture/node_texture_tree.c + texture/node_texture_util.c - intern/node_common.c - intern/node_exec.c - intern/node_socket.c - intern/node_util.c + intern/node_common.c + intern/node_exec.c + intern/node_socket.c + intern/node_util.c - composite/node_composite_util.h - shader/node_shader_util.h - texture/node_texture_util.h + composite/node_composite_util.h + shader/node_shader_util.h + texture/node_texture_util.h - NOD_common.h - NOD_composite.h - NOD_shader.h - NOD_socket.h - NOD_static_types.h - NOD_texture.h - intern/node_common.h - intern/node_exec.h - intern/node_util.h + NOD_common.h + NOD_composite.h + NOD_shader.h + NOD_socket.h + NOD_static_types.h + NOD_texture.h + intern/node_common.h + intern/node_exec.h + intern/node_util.h ) set(LIB ) if(WITH_PYTHON) - list(APPEND INC - ../python - ) - list(APPEND INC_SYS - ${PYTHON_INCLUDE_DIRS} - ) - add_definitions(-DWITH_PYTHON) + list(APPEND INC + ../python + ) + list(APPEND INC_SYS + ${PYTHON_INCLUDE_DIRS} + ) + add_definitions(-DWITH_PYTHON) endif() if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) + add_definitions(-DWITH_INTERNATIONAL) endif() if(WITH_IMAGE_OPENEXR) - add_definitions(-DWITH_OPENEXR) + add_definitions(-DWITH_OPENEXR) endif() if(WITH_COMPOSITOR) - list(APPEND INC - ../compositor - ) - add_definitions(-DWITH_COMPOSITOR) + list(APPEND INC + ../compositor + ) + add_definitions(-DWITH_COMPOSITOR) endif() add_definitions(${GL_DEFINITIONS}) if(WITH_FREESTYLE) - add_definitions(-DWITH_FREESTYLE) + add_definitions(-DWITH_FREESTYLE) endif() blender_add_lib(bf_nodes "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/nodes/NOD_common.h b/source/blender/nodes/NOD_common.h index e49bc023f72..7bbdc2129cd 100644 --- a/source/blender/nodes/NOD_common.h +++ b/source/blender/nodes/NOD_common.h @@ -32,7 +32,6 @@ void register_node_type_reroute(void); void register_node_type_group_input(void); void register_node_type_group_output(void); - /* internal functions for editor */ struct bNodeSocket *node_group_find_input_socket(struct bNode *groupnode, const char *identifier); struct bNodeSocket *node_group_find_output_socket(struct bNode *groupnode, const char *identifier); @@ -43,4 +42,4 @@ struct bNodeSocket *node_group_output_find_socket(struct bNode *node, const char void node_group_input_verify(struct bNodeTree *ntree, struct bNode *node, struct ID *id); void node_group_output_verify(struct bNodeTree *ntree, struct bNode *node, struct ID *id); -#endif /* __NOD_COMMON_H__ */ +#endif /* __NOD_COMMON_H__ */ diff --git a/source/blender/nodes/NOD_composite.h b/source/blender/nodes/NOD_composite.h index 85f4c81610b..e6d9ed6f70e 100644 --- a/source/blender/nodes/NOD_composite.h +++ b/source/blender/nodes/NOD_composite.h @@ -28,7 +28,6 @@ extern struct bNodeTreeType *ntreeType_Composite; - /* ****************** types array for all composite nodes ****************** */ void register_node_tree_type_cmp(void); @@ -133,7 +132,12 @@ void register_node_type_cmp_planetrackdeform(void); void register_node_type_cmp_cornerpin(void); void node_cmp_rlayers_outputs(struct bNodeTree *ntree, struct bNode *node); -void node_cmp_rlayers_register_pass(struct bNodeTree *ntree, struct bNode *node, struct Scene *scene, struct ViewLayer *view_layer, const char *name, int type); +void node_cmp_rlayers_register_pass(struct bNodeTree *ntree, + struct bNode *node, + struct Scene *scene, + struct ViewLayer *view_layer, + const char *name, + int type); const char *node_cmp_rlayers_sock_to_pass(int sock_index); void register_node_type_cmp_custom_group(bNodeType *ntype); diff --git a/source/blender/nodes/NOD_shader.h b/source/blender/nodes/NOD_shader.h index 9e6fa0706d1..ead42779bc0 100644 --- a/source/blender/nodes/NOD_shader.h +++ b/source/blender/nodes/NOD_shader.h @@ -28,7 +28,6 @@ extern struct bNodeTreeType *ntreeType_Shader; - /* the type definitions array */ /* ****************** types array for all shaders ****************** */ diff --git a/source/blender/nodes/NOD_socket.h b/source/blender/nodes/NOD_socket.h index 967ef37d56d..b1b1a0e40c6 100644 --- a/source/blender/nodes/NOD_socket.h +++ b/source/blender/nodes/NOD_socket.h @@ -21,7 +21,6 @@ * \ingroup nodes */ - #ifndef __NOD_SOCKET_H__ #define __NOD_SOCKET_H__ @@ -36,7 +35,10 @@ struct bNode; struct bNodeTree; -struct bNodeSocket *node_add_socket_from_template(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocketTemplate *stemp, int in_out); +struct bNodeSocket *node_add_socket_from_template(struct bNodeTree *ntree, + struct bNode *node, + struct bNodeSocketTemplate *stemp, + int in_out); void node_verify_socket_templates(struct bNodeTree *ntree, struct bNode *node); diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h index ea642303ef6..f27c50ae736 100644 --- a/source/blender/nodes/NOD_static_types.h +++ b/source/blender/nodes/NOD_static_types.h @@ -253,4 +253,4 @@ DefNode(TextureNode, TEX_NODE_PROC+TEX_DISTNOISE, 0, "TEX_DI /* undefine macros */ #undef DefNode -/* clang-format on */ + /* clang-format on */ diff --git a/source/blender/nodes/NOD_texture.h b/source/blender/nodes/NOD_texture.h index 799957e58f0..eaa4952e7e6 100644 --- a/source/blender/nodes/NOD_texture.h +++ b/source/blender/nodes/NOD_texture.h @@ -28,7 +28,6 @@ extern struct bNodeTreeType *ntreeType_Texture; - /* ****************** types array for all texture nodes ****************** */ void register_node_tree_type_tex(void); diff --git a/source/blender/nodes/composite/node_composite_tree.c b/source/blender/nodes/composite/node_composite_tree.c index 5ef698c553b..53fdde5baf2 100644 --- a/source/blender/nodes/composite/node_composite_tree.c +++ b/source/blender/nodes/composite/node_composite_tree.c @@ -21,7 +21,6 @@ * \ingroup nodes */ - #include <stdio.h> #include "DNA_color_types.h" @@ -48,187 +47,196 @@ # include "COM_compositor.h" #endif -static void composite_get_from_context(const bContext *C, bNodeTreeType *UNUSED(treetype), bNodeTree **r_ntree, ID **r_id, ID **r_from) +static void composite_get_from_context(const bContext *C, + bNodeTreeType *UNUSED(treetype), + bNodeTree **r_ntree, + ID **r_id, + ID **r_from) { - Scene *scene = CTX_data_scene(C); + Scene *scene = CTX_data_scene(C); - *r_from = NULL; - *r_id = &scene->id; - *r_ntree = scene->nodetree; + *r_from = NULL; + *r_id = &scene->id; + *r_ntree = scene->nodetree; } static void foreach_nodeclass(Scene *UNUSED(scene), void *calldata, bNodeClassCallback func) { - func(calldata, NODE_CLASS_INPUT, N_("Input")); - func(calldata, NODE_CLASS_OUTPUT, N_("Output")); - func(calldata, NODE_CLASS_OP_COLOR, N_("Color")); - func(calldata, NODE_CLASS_OP_VECTOR, N_("Vector")); - func(calldata, NODE_CLASS_OP_FILTER, N_("Filter")); - func(calldata, NODE_CLASS_CONVERTOR, N_("Convertor")); - func(calldata, NODE_CLASS_MATTE, N_("Matte")); - func(calldata, NODE_CLASS_DISTORT, N_("Distort")); - func(calldata, NODE_CLASS_GROUP, N_("Group")); - func(calldata, NODE_CLASS_INTERFACE, N_("Interface")); - func(calldata, NODE_CLASS_LAYOUT, N_("Layout")); + func(calldata, NODE_CLASS_INPUT, N_("Input")); + func(calldata, NODE_CLASS_OUTPUT, N_("Output")); + func(calldata, NODE_CLASS_OP_COLOR, N_("Color")); + func(calldata, NODE_CLASS_OP_VECTOR, N_("Vector")); + func(calldata, NODE_CLASS_OP_FILTER, N_("Filter")); + func(calldata, NODE_CLASS_CONVERTOR, N_("Convertor")); + func(calldata, NODE_CLASS_MATTE, N_("Matte")); + func(calldata, NODE_CLASS_DISTORT, N_("Distort")); + func(calldata, NODE_CLASS_GROUP, N_("Group")); + func(calldata, NODE_CLASS_INTERFACE, N_("Interface")); + func(calldata, NODE_CLASS_LAYOUT, N_("Layout")); } static void free_node_cache(bNodeTree *UNUSED(ntree), bNode *node) { - bNodeSocket *sock; + bNodeSocket *sock; - for (sock = node->outputs.first; sock; sock = sock->next) { - if (sock->cache) { - sock->cache = NULL; - } - } + for (sock = node->outputs.first; sock; sock = sock->next) { + if (sock->cache) { + sock->cache = NULL; + } + } } static void free_cache(bNodeTree *ntree) { - bNode *node; - for (node = ntree->nodes.first; node; node = node->next) - free_node_cache(ntree, node); + bNode *node; + for (node = ntree->nodes.first; node; node = node->next) + free_node_cache(ntree, node); } /* local tree then owns all compbufs */ static void localize(bNodeTree *UNUSED(localtree), bNodeTree *ntree) { - bNode *node; - bNodeSocket *sock; - - for (node = ntree->nodes.first; node; node = node->next) { - /* ensure new user input gets handled ok */ - node->need_exec = 0; - node->new_node->original = node; - - /* move over the compbufs */ - /* right after ntreeCopyTree() oldsock pointers are valid */ - - if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) { - if (node->id) { - if (node->flag & NODE_DO_OUTPUT) - node->new_node->id = (ID *)node->id; - else - node->new_node->id = NULL; - } - } - - for (sock = node->outputs.first; sock; sock = sock->next) { - sock->new_sock->cache = sock->cache; - sock->cache = NULL; - sock->new_sock->new_sock = sock; - } - } + bNode *node; + bNodeSocket *sock; + + for (node = ntree->nodes.first; node; node = node->next) { + /* ensure new user input gets handled ok */ + node->need_exec = 0; + node->new_node->original = node; + + /* move over the compbufs */ + /* right after ntreeCopyTree() oldsock pointers are valid */ + + if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) { + if (node->id) { + if (node->flag & NODE_DO_OUTPUT) + node->new_node->id = (ID *)node->id; + else + node->new_node->id = NULL; + } + } + + for (sock = node->outputs.first; sock; sock = sock->next) { + sock->new_sock->cache = sock->cache; + sock->cache = NULL; + sock->new_sock->new_sock = sock; + } + } } static void local_sync(bNodeTree *localtree, bNodeTree *ntree) { - BKE_node_preview_sync_tree(ntree, localtree); + BKE_node_preview_sync_tree(ntree, localtree); } static void local_merge(Main *bmain, bNodeTree *localtree, bNodeTree *ntree) { - bNode *lnode; - bNodeSocket *lsock; - - /* move over the compbufs and previews */ - BKE_node_preview_merge_tree(ntree, localtree, true); - - for (lnode = localtree->nodes.first; lnode; lnode = lnode->next) { - if (ntreeNodeExists(ntree, lnode->new_node)) { - if (ELEM(lnode->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) { - if (lnode->id && (lnode->flag & NODE_DO_OUTPUT)) { - /* image_merge does sanity check for pointers */ - BKE_image_merge(bmain, (Image *)lnode->new_node->id, (Image *)lnode->id); - } - } - else if (lnode->type == CMP_NODE_MOVIEDISTORTION) { - /* special case for distortion node: distortion context is allocating in exec function - * and to achieve much better performance on further calls this context should be - * copied back to original node */ - if (lnode->storage) { - if (lnode->new_node->storage) - BKE_tracking_distortion_free(lnode->new_node->storage); - - lnode->new_node->storage = BKE_tracking_distortion_copy(lnode->storage); - } - } - - for (lsock = lnode->outputs.first; lsock; lsock = lsock->next) { - if (ntreeOutputExists(lnode->new_node, lsock->new_sock)) { - lsock->new_sock->cache = lsock->cache; - lsock->cache = NULL; - lsock->new_sock = NULL; - } - } - } - } + bNode *lnode; + bNodeSocket *lsock; + + /* move over the compbufs and previews */ + BKE_node_preview_merge_tree(ntree, localtree, true); + + for (lnode = localtree->nodes.first; lnode; lnode = lnode->next) { + if (ntreeNodeExists(ntree, lnode->new_node)) { + if (ELEM(lnode->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) { + if (lnode->id && (lnode->flag & NODE_DO_OUTPUT)) { + /* image_merge does sanity check for pointers */ + BKE_image_merge(bmain, (Image *)lnode->new_node->id, (Image *)lnode->id); + } + } + else if (lnode->type == CMP_NODE_MOVIEDISTORTION) { + /* special case for distortion node: distortion context is allocating in exec function + * and to achieve much better performance on further calls this context should be + * copied back to original node */ + if (lnode->storage) { + if (lnode->new_node->storage) + BKE_tracking_distortion_free(lnode->new_node->storage); + + lnode->new_node->storage = BKE_tracking_distortion_copy(lnode->storage); + } + } + + for (lsock = lnode->outputs.first; lsock; lsock = lsock->next) { + if (ntreeOutputExists(lnode->new_node, lsock->new_sock)) { + lsock->new_sock->cache = lsock->cache; + lsock->cache = NULL; + lsock->new_sock = NULL; + } + } + } + } } static void update(bNodeTree *ntree) { - ntreeSetOutput(ntree); + ntreeSetOutput(ntree); - ntree_update_reroute_nodes(ntree); + ntree_update_reroute_nodes(ntree); - if (ntree->update & NTREE_UPDATE_NODES) { - /* clean up preview cache, in case nodes have been removed */ - BKE_node_preview_remove_unused(ntree); - } + if (ntree->update & NTREE_UPDATE_NODES) { + /* clean up preview cache, in case nodes have been removed */ + BKE_node_preview_remove_unused(ntree); + } } static void composite_node_add_init(bNodeTree *UNUSED(bnodetree), bNode *bnode) { - /* Composite node will only show previews for input classes - * by default, other will be hidden - * but can be made visible with the show_preview option */ - if (bnode->typeinfo->nclass != NODE_CLASS_INPUT) { - bnode->flag &= ~NODE_PREVIEW; - } + /* Composite node will only show previews for input classes + * by default, other will be hidden + * but can be made visible with the show_preview option */ + if (bnode->typeinfo->nclass != NODE_CLASS_INPUT) { + bnode->flag &= ~NODE_PREVIEW; + } } bNodeTreeType *ntreeType_Composite; void register_node_tree_type_cmp(void) { - bNodeTreeType *tt = ntreeType_Composite = MEM_callocN(sizeof(bNodeTreeType), "compositor node tree type"); - - tt->type = NTREE_COMPOSIT; - strcpy(tt->idname, "CompositorNodeTree"); - strcpy(tt->ui_name, N_("Compositor")); - tt->ui_icon = 0; /* defined in drawnode.c */ - strcpy(tt->ui_description, N_("Compositing nodes")); - - tt->free_cache = free_cache; - tt->free_node_cache = free_node_cache; - tt->foreach_nodeclass = foreach_nodeclass; - tt->localize = localize; - tt->local_sync = local_sync; - tt->local_merge = local_merge; - tt->update = update; - tt->get_from_context = composite_get_from_context; - tt->node_add_init = composite_node_add_init; - - tt->ext.srna = &RNA_CompositorNodeTree; - - ntreeTypeAdd(tt); + bNodeTreeType *tt = ntreeType_Composite = MEM_callocN(sizeof(bNodeTreeType), + "compositor node tree type"); + + tt->type = NTREE_COMPOSIT; + strcpy(tt->idname, "CompositorNodeTree"); + strcpy(tt->ui_name, N_("Compositor")); + tt->ui_icon = 0; /* defined in drawnode.c */ + strcpy(tt->ui_description, N_("Compositing nodes")); + + tt->free_cache = free_cache; + tt->free_node_cache = free_node_cache; + tt->foreach_nodeclass = foreach_nodeclass; + tt->localize = localize; + tt->local_sync = local_sync; + tt->local_merge = local_merge; + tt->update = update; + tt->get_from_context = composite_get_from_context; + tt->node_add_init = composite_node_add_init; + + tt->ext.srna = &RNA_CompositorNodeTree; + + ntreeTypeAdd(tt); } -extern void *COM_linker_hack; /* Quiet warning. */ +extern void *COM_linker_hack; /* Quiet warning. */ void *COM_linker_hack = NULL; -void ntreeCompositExecTree(Scene *scene, bNodeTree *ntree, RenderData *rd, int rendering, int do_preview, +void ntreeCompositExecTree(Scene *scene, + bNodeTree *ntree, + RenderData *rd, + int rendering, + int do_preview, const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, const char *view_name) { #ifdef WITH_COMPOSITOR - COM_execute(rd, scene, ntree, rendering, view_settings, display_settings, view_name); + COM_execute(rd, scene, ntree, rendering, view_settings, display_settings, view_name); #else - UNUSED_VARS(scene, ntree, rd, rendering, view_settings, display_settings, view_name); + UNUSED_VARS(scene, ntree, rd, rendering, view_settings, display_settings, view_name); #endif - UNUSED_VARS(do_preview); + UNUSED_VARS(do_preview); } /* *********************************************** */ @@ -243,155 +251,158 @@ void ntreeCompositExecTree(Scene *scene, bNodeTree *ntree, RenderData *rd, int r */ void ntreeCompositUpdateRLayers(bNodeTree *ntree) { - bNode *node; - - if (ntree == NULL) return; + bNode *node; - for (node = ntree->nodes.first; node; node = node->next) { - if (node->type == CMP_NODE_R_LAYERS) - node_cmp_rlayers_outputs(ntree, node); - } + if (ntree == NULL) + return; + for (node = ntree->nodes.first; node; node = node->next) { + if (node->type == CMP_NODE_R_LAYERS) + node_cmp_rlayers_outputs(ntree, node); + } } -void ntreeCompositRegisterPass(bNodeTree *ntree, Scene *scene, ViewLayer *view_layer, const char *name, int type) +void ntreeCompositRegisterPass( + bNodeTree *ntree, Scene *scene, ViewLayer *view_layer, const char *name, int type) { - bNode *node; + bNode *node; - if (ntree == NULL) return; - - for (node = ntree->nodes.first; node; node = node->next) { - if (node->type == CMP_NODE_R_LAYERS) - node_cmp_rlayers_register_pass(ntree, node, scene, view_layer, name, type); - } + if (ntree == NULL) + return; + for (node = ntree->nodes.first; node; node = node->next) { + if (node->type == CMP_NODE_R_LAYERS) + node_cmp_rlayers_register_pass(ntree, node, scene, view_layer, name, type); + } } /* called from render pipeline, to tag render input and output */ /* need to do all scenes, to prevent errors when you re-render 1 scene */ void ntreeCompositTagRender(Scene *curscene) { - Scene *sce; - - /* XXX Think using G_MAIN here is valid, since you want to update current file's scene nodes, - * not the ones in temp main generated for rendering? - * This is still rather weak though, ideally render struct would store own main AND original G_MAIN... */ - for (sce = G_MAIN->scenes.first; sce; sce = sce->id.next) { - if (sce->nodetree) { - bNode *node; - - for (node = sce->nodetree->nodes.first; node; node = node->next) { - if (node->id == (ID *)curscene || node->type == CMP_NODE_COMPOSITE) - nodeUpdate(sce->nodetree, node); - else if (node->type == CMP_NODE_TEXTURE) /* uses scene sizex/sizey */ - nodeUpdate(sce->nodetree, node); - } - } - } + Scene *sce; + + /* XXX Think using G_MAIN here is valid, since you want to update current file's scene nodes, + * not the ones in temp main generated for rendering? + * This is still rather weak though, ideally render struct would store own main AND original G_MAIN... */ + for (sce = G_MAIN->scenes.first; sce; sce = sce->id.next) { + if (sce->nodetree) { + bNode *node; + + for (node = sce->nodetree->nodes.first; node; node = node->next) { + if (node->id == (ID *)curscene || node->type == CMP_NODE_COMPOSITE) + nodeUpdate(sce->nodetree, node); + else if (node->type == CMP_NODE_TEXTURE) /* uses scene sizex/sizey */ + nodeUpdate(sce->nodetree, node); + } + } + } } static int node_animation_properties(bNodeTree *ntree, bNode *node) { - bNodeSocket *sock; - const ListBase *lb; - Link *link; - PointerRNA ptr; - PropertyRNA *prop; - - /* check to see if any of the node's properties have fcurves */ - RNA_pointer_create((ID *)ntree, &RNA_Node, node, &ptr); - lb = RNA_struct_type_properties(ptr.type); - - for (link = lb->first; link; link = link->next) { - prop = (PropertyRNA *)link; - - if (RNA_property_animated(&ptr, prop)) { - nodeUpdate(ntree, node); - return 1; - } - } - - /* now check node sockets */ - for (sock = node->inputs.first; sock; sock = sock->next) { - RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr); - prop = RNA_struct_find_property(&ptr, "default_value"); - - if (RNA_property_animated(&ptr, prop)) { - nodeUpdate(ntree, node); - return 1; - } - } - - return 0; + bNodeSocket *sock; + const ListBase *lb; + Link *link; + PointerRNA ptr; + PropertyRNA *prop; + + /* check to see if any of the node's properties have fcurves */ + RNA_pointer_create((ID *)ntree, &RNA_Node, node, &ptr); + lb = RNA_struct_type_properties(ptr.type); + + for (link = lb->first; link; link = link->next) { + prop = (PropertyRNA *)link; + + if (RNA_property_animated(&ptr, prop)) { + nodeUpdate(ntree, node); + return 1; + } + } + + /* now check node sockets */ + for (sock = node->inputs.first; sock; sock = sock->next) { + RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr); + prop = RNA_struct_find_property(&ptr, "default_value"); + + if (RNA_property_animated(&ptr, prop)) { + nodeUpdate(ntree, node); + return 1; + } + } + + return 0; } /* tags nodes that have animation capabilities */ int ntreeCompositTagAnimated(bNodeTree *ntree) { - bNode *node; - int tagged = 0; - - if (ntree == NULL) return 0; - - for (node = ntree->nodes.first; node; node = node->next) { - - tagged = node_animation_properties(ntree, node); - - /* otherwise always tag these node types */ - if (node->type == CMP_NODE_IMAGE) { - Image *ima = (Image *)node->id; - if (ima && BKE_image_is_animated(ima)) { - nodeUpdate(ntree, node); - tagged = 1; - } - } - else if (node->type == CMP_NODE_TIME) { - nodeUpdate(ntree, node); - tagged = 1; - } - /* here was tag render layer, but this is called after a render, so re-composites fail */ - else if (node->type == NODE_GROUP) { - if (ntreeCompositTagAnimated((bNodeTree *)node->id)) { - nodeUpdate(ntree, node); - } - } - else if (ELEM(node->type, CMP_NODE_MOVIECLIP, CMP_NODE_TRANSFORM)) { - nodeUpdate(ntree, node); - tagged = 1; - } - else if (node->type == CMP_NODE_MASK) { - nodeUpdate(ntree, node); - tagged = 1; - } - } - - return tagged; + bNode *node; + int tagged = 0; + + if (ntree == NULL) + return 0; + + for (node = ntree->nodes.first; node; node = node->next) { + + tagged = node_animation_properties(ntree, node); + + /* otherwise always tag these node types */ + if (node->type == CMP_NODE_IMAGE) { + Image *ima = (Image *)node->id; + if (ima && BKE_image_is_animated(ima)) { + nodeUpdate(ntree, node); + tagged = 1; + } + } + else if (node->type == CMP_NODE_TIME) { + nodeUpdate(ntree, node); + tagged = 1; + } + /* here was tag render layer, but this is called after a render, so re-composites fail */ + else if (node->type == NODE_GROUP) { + if (ntreeCompositTagAnimated((bNodeTree *)node->id)) { + nodeUpdate(ntree, node); + } + } + else if (ELEM(node->type, CMP_NODE_MOVIECLIP, CMP_NODE_TRANSFORM)) { + nodeUpdate(ntree, node); + tagged = 1; + } + else if (node->type == CMP_NODE_MASK) { + nodeUpdate(ntree, node); + tagged = 1; + } + } + + return tagged; } - /* called from image window preview */ void ntreeCompositTagGenerators(bNodeTree *ntree) { - bNode *node; + bNode *node; - if (ntree == NULL) return; + if (ntree == NULL) + return; - for (node = ntree->nodes.first; node; node = node->next) { - if (ELEM(node->type, CMP_NODE_R_LAYERS, CMP_NODE_IMAGE)) - nodeUpdate(ntree, node); - } + for (node = ntree->nodes.first; node; node = node->next) { + if (ELEM(node->type, CMP_NODE_R_LAYERS, CMP_NODE_IMAGE)) + nodeUpdate(ntree, node); + } } /* XXX after render animation system gets a refresh, this call allows composite to end clean */ void ntreeCompositClearTags(bNodeTree *ntree) { - bNode *node; + bNode *node; - if (ntree == NULL) return; + if (ntree == NULL) + return; - for (node = ntree->nodes.first; node; node = node->next) { - node->need_exec = 0; - if (node->type == NODE_GROUP) - ntreeCompositClearTags((bNodeTree *)node->id); - } + for (node = ntree->nodes.first; node; node = node->next) { + node->need_exec = 0; + if (node->type == NODE_GROUP) + ntreeCompositClearTags((bNodeTree *)node->id); + } } diff --git a/source/blender/nodes/composite/node_composite_util.c b/source/blender/nodes/composite/node_composite_util.c index 323cca70083..1ba81330d72 100644 --- a/source/blender/nodes/composite/node_composite_util.c +++ b/source/blender/nodes/composite/node_composite_util.c @@ -23,30 +23,29 @@ #include "node_composite_util.h" - bool cmp_node_poll_default(bNodeType *UNUSED(ntype), bNodeTree *ntree) { - return STREQ(ntree->idname, "CompositorNodeTree"); + return STREQ(ntree->idname, "CompositorNodeTree"); } void cmp_node_update_default(bNodeTree *UNUSED(ntree), bNode *node) { - bNodeSocket *sock; - for (sock = node->outputs.first; sock; sock = sock->next) { - if (sock->cache) { - //free_compbuf(sock->cache); - //sock->cache = NULL; - } - } - node->need_exec = 1; + bNodeSocket *sock; + for (sock = node->outputs.first; sock; sock = sock->next) { + if (sock->cache) { + //free_compbuf(sock->cache); + //sock->cache = NULL; + } + } + node->need_exec = 1; } void cmp_node_type_base(bNodeType *ntype, int type, const char *name, short nclass, short flag) { - node_type_base(ntype, type, name, nclass, flag); + node_type_base(ntype, type, name, nclass, flag); - ntype->poll = cmp_node_poll_default; - ntype->updatefunc = cmp_node_update_default; - ntype->insert_link = node_insert_link_default; - ntype->update_internal_links = node_update_internal_links_default; + ntype->poll = cmp_node_poll_default; + ntype->updatefunc = cmp_node_update_default; + ntype->insert_link = node_insert_link_default; + ntype->update_internal_links = node_update_internal_links_default; } diff --git a/source/blender/nodes/composite/node_composite_util.h b/source/blender/nodes/composite/node_composite_util.h index d1f6e46b6f3..c7785682865 100644 --- a/source/blender/nodes/composite/node_composite_util.h +++ b/source/blender/nodes/composite/node_composite_util.h @@ -21,7 +21,6 @@ * \ingroup nodes */ - #ifndef __NODE_COMPOSITE_UTIL_H__ #define __NODE_COMPOSITE_UTIL_H__ @@ -50,10 +49,11 @@ /* only for forward declarations */ #include "NOD_composite.h" -#define CMP_SCALE_MAX 12000 +#define CMP_SCALE_MAX 12000 bool cmp_node_poll_default(struct bNodeType *ntype, struct bNodeTree *ntree); void cmp_node_update_default(struct bNodeTree *UNUSED(ntree), struct bNode *node); -void cmp_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag); +void cmp_node_type_base( + struct bNodeType *ntype, int type, const char *name, short nclass, short flag); -#endif /* __NODE_COMPOSITE_UTIL_H__ */ +#endif /* __NODE_COMPOSITE_UTIL_H__ */ diff --git a/source/blender/nodes/composite/nodes/node_composite_alphaOver.c b/source/blender/nodes/composite/nodes/node_composite_alphaOver.c index 0ad273ac6b8..e0e842a7df3 100644 --- a/source/blender/nodes/composite/nodes/node_composite_alphaOver.c +++ b/source/blender/nodes/composite/nodes/node_composite_alphaOver.c @@ -25,29 +25,30 @@ /* **************** ALPHAOVER ******************** */ static bNodeSocketTemplate cmp_node_alphaover_in[] = { - { SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_alphaover_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; static void node_alphaover_init(bNodeTree *UNUSED(ntree), bNode *node) { - node->storage = MEM_callocN(sizeof(NodeTwoFloats), "NodeTwoFloats"); + node->storage = MEM_callocN(sizeof(NodeTwoFloats), "NodeTwoFloats"); } void register_node_type_cmp_alphaover(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_ALPHAOVER, "Alpha Over", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, cmp_node_alphaover_in, cmp_node_alphaover_out); - node_type_init(&ntype, node_alphaover_init); - node_type_storage(&ntype, "NodeTwoFloats", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_ALPHAOVER, "Alpha Over", NODE_CLASS_OP_COLOR, 0); + node_type_socket_templates(&ntype, cmp_node_alphaover_in, cmp_node_alphaover_out); + node_type_init(&ntype, node_alphaover_init); + node_type_storage( + &ntype, "NodeTwoFloats", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_bilateralblur.c b/source/blender/nodes/composite/nodes/node_composite_bilateralblur.c index b009e1d8128..8c46349e091 100644 --- a/source/blender/nodes/composite/nodes/node_composite_bilateralblur.c +++ b/source/blender/nodes/composite/nodes/node_composite_bilateralblur.c @@ -25,33 +25,32 @@ /* **************** BILATERALBLUR ******************** */ static bNodeSocketTemplate cmp_node_bilateralblur_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_RGBA, 1, N_("Determinator"), 1.0f, 1.0f, 1.0f, 1.0f}, - { -1, 0, "" } -}; + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_RGBA, 1, N_("Determinator"), 1.0f, 1.0f, 1.0f, 1.0f}, + {-1, 0, ""}}; -static bNodeSocketTemplate cmp_node_bilateralblur_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" } -}; +static bNodeSocketTemplate cmp_node_bilateralblur_out[] = {{SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}}; static void node_composit_init_bilateralblur(bNodeTree *UNUSED(ntree), bNode *node) { - NodeBilateralBlurData *nbbd = MEM_callocN(sizeof(NodeBilateralBlurData), "node bilateral blur data"); - node->storage = nbbd; - nbbd->iter = 1; - nbbd->sigma_color = 0.3; - nbbd->sigma_space = 5.0; + NodeBilateralBlurData *nbbd = MEM_callocN(sizeof(NodeBilateralBlurData), + "node bilateral blur data"); + node->storage = nbbd; + nbbd->iter = 1; + nbbd->sigma_color = 0.3; + nbbd->sigma_space = 5.0; } void register_node_type_cmp_bilateralblur(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_BILATERALBLUR, "Bilateral Blur", NODE_CLASS_OP_FILTER, 0); - node_type_socket_templates(&ntype, cmp_node_bilateralblur_in, cmp_node_bilateralblur_out); - node_type_init(&ntype, node_composit_init_bilateralblur); - node_type_storage(&ntype, "NodeBilateralBlurData", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_BILATERALBLUR, "Bilateral Blur", NODE_CLASS_OP_FILTER, 0); + node_type_socket_templates(&ntype, cmp_node_bilateralblur_in, cmp_node_bilateralblur_out); + node_type_init(&ntype, node_composit_init_bilateralblur); + node_type_storage( + &ntype, "NodeBilateralBlurData", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_blur.c b/source/blender/nodes/composite/nodes/node_composite_blur.c index fa455fcd412..535b5db9a46 100644 --- a/source/blender/nodes/composite/nodes/node_composite_blur.c +++ b/source/blender/nodes/composite/nodes/node_composite_blur.c @@ -22,35 +22,31 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" /* **************** BLUR ******************** */ static bNodeSocketTemplate cmp_node_blur_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Size"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, - { -1, 0, "" } -}; -static bNodeSocketTemplate cmp_node_blur_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" } -}; + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Size"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, + {-1, 0, ""}}; +static bNodeSocketTemplate cmp_node_blur_out[] = {{SOCK_RGBA, 0, N_("Image")}, {-1, 0, ""}}; static void node_composit_init_blur(bNodeTree *UNUSED(ntree), bNode *node) { - NodeBlurData *data = MEM_callocN(sizeof(NodeBlurData), "node blur data"); - data->filtertype = R_FILTER_GAUSS; - node->storage = data; + NodeBlurData *data = MEM_callocN(sizeof(NodeBlurData), "node blur data"); + data->filtertype = R_FILTER_GAUSS; + node->storage = data; } void register_node_type_cmp_blur(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_BLUR, "Blur", NODE_CLASS_OP_FILTER, NODE_PREVIEW); - node_type_socket_templates(&ntype, cmp_node_blur_in, cmp_node_blur_out); - node_type_init(&ntype, node_composit_init_blur); - node_type_storage(&ntype, "NodeBlurData", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_BLUR, "Blur", NODE_CLASS_OP_FILTER, NODE_PREVIEW); + node_type_socket_templates(&ntype, cmp_node_blur_in, cmp_node_blur_out); + node_type_init(&ntype, node_composit_init_blur); + node_type_storage( + &ntype, "NodeBlurData", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_bokehblur.c b/source/blender/nodes/composite/nodes/node_composite_bokehblur.c index 08cd1f2de28..c2fc1b74699 100644 --- a/source/blender/nodes/composite/nodes/node_composite_bokehblur.c +++ b/source/blender/nodes/composite/nodes/node_composite_bokehblur.c @@ -22,36 +22,32 @@ * \ingroup cmpnodes */ - #include "../node_composite_util.h" /* **************** BLUR ******************** */ static bNodeSocketTemplate cmp_node_bokehblur_in[] = { - { SOCK_RGBA, 1, N_("Image"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 1, N_("Bokeh"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Size"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 10.0f}, - { SOCK_FLOAT, 1, N_("Bounding box"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; + {SOCK_RGBA, 1, N_("Image"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 1, N_("Bokeh"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Size"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 10.0f}, + {SOCK_FLOAT, 1, N_("Bounding box"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, + {-1, 0, ""}}; static bNodeSocketTemplate cmp_node_bokehblur_out[] = { - { SOCK_RGBA, 0, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; + {SOCK_RGBA, 0, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, {-1, 0, ""}}; static void node_composit_init_bokehblur(bNodeTree *UNUSED(ntree), bNode *node) { - node->custom3 = 4.0f; - node->custom4 = 16.0f; + node->custom3 = 4.0f; + node->custom4 = 16.0f; } void register_node_type_cmp_bokehblur(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_BOKEHBLUR, "Bokeh Blur", NODE_CLASS_OP_FILTER, 0); - node_type_socket_templates(&ntype, cmp_node_bokehblur_in, cmp_node_bokehblur_out); - node_type_init(&ntype, node_composit_init_bokehblur); + cmp_node_type_base(&ntype, CMP_NODE_BOKEHBLUR, "Bokeh Blur", NODE_CLASS_OP_FILTER, 0); + node_type_socket_templates(&ntype, cmp_node_bokehblur_in, cmp_node_bokehblur_out); + node_type_init(&ntype, node_composit_init_bokehblur); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_bokehimage.c b/source/blender/nodes/composite/nodes/node_composite_bokehimage.c index 31237584c46..b35d3d73faa 100644 --- a/source/blender/nodes/composite/nodes/node_composite_bokehimage.c +++ b/source/blender/nodes/composite/nodes/node_composite_bokehimage.c @@ -22,35 +22,35 @@ * \ingroup cmpnodes */ - #include "../node_composite_util.h" /* **************** Bokeh image Tools ******************** */ static bNodeSocketTemplate cmp_node_bokehimage_out[] = { - { SOCK_RGBA, 0, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; static void node_composit_init_bokehimage(bNodeTree *UNUSED(ntree), bNode *node) { - NodeBokehImage *data = MEM_callocN(sizeof(NodeBokehImage), "NodeBokehImage"); - data->angle = 0.0f; - data->flaps = 5; - data->rounding = 0.0f; - data->catadioptric = 0.0f; - data->lensshift = 0.0f; - node->storage = data; + NodeBokehImage *data = MEM_callocN(sizeof(NodeBokehImage), "NodeBokehImage"); + data->angle = 0.0f; + data->flaps = 5; + data->rounding = 0.0f; + data->catadioptric = 0.0f; + data->lensshift = 0.0f; + node->storage = data; } void register_node_type_cmp_bokehimage(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_BOKEHIMAGE, "Bokeh Image", NODE_CLASS_INPUT, NODE_PREVIEW); - node_type_socket_templates(&ntype, NULL, cmp_node_bokehimage_out); - node_type_init(&ntype, node_composit_init_bokehimage); - node_type_storage(&ntype, "NodeBokehImage", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_BOKEHIMAGE, "Bokeh Image", NODE_CLASS_INPUT, NODE_PREVIEW); + node_type_socket_templates(&ntype, NULL, cmp_node_bokehimage_out); + node_type_init(&ntype, node_composit_init_bokehimage); + node_type_storage( + &ntype, "NodeBokehImage", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_boxmask.c b/source/blender/nodes/composite/nodes/node_composite_boxmask.c index 071d0941113..326f4a026da 100644 --- a/source/blender/nodes/composite/nodes/node_composite_boxmask.c +++ b/source/blender/nodes/composite/nodes/node_composite_boxmask.c @@ -21,40 +21,36 @@ * \ingroup cmpnodes */ - #include "../node_composite_util.h" /* **************** SCALAR MATH ******************** */ static bNodeSocketTemplate cmp_node_boxmask_in[] = { - { SOCK_FLOAT, 1, N_("Mask"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Value"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; + {SOCK_FLOAT, 1, N_("Mask"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Value"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + {-1, 0, ""}}; static bNodeSocketTemplate cmp_node_boxmask_out[] = { - { SOCK_FLOAT, 0, N_("Mask"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; + {SOCK_FLOAT, 0, N_("Mask"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, {-1, 0, ""}}; static void node_composit_init_boxmask(bNodeTree *UNUSED(ntree), bNode *node) { - NodeBoxMask *data = MEM_callocN(sizeof(NodeBoxMask), "NodeBoxMask"); - data->x = 0.5; - data->y = 0.5; - data->width = 0.2; - data->height = 0.1; - data->rotation = 0.0; - node->storage = data; + NodeBoxMask *data = MEM_callocN(sizeof(NodeBoxMask), "NodeBoxMask"); + data->x = 0.5; + data->y = 0.5; + data->width = 0.2; + data->height = 0.1; + data->rotation = 0.0; + node->storage = data; } void register_node_type_cmp_boxmask(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_MASK_BOX, "Box Mask", NODE_CLASS_MATTE, 0); - node_type_socket_templates(&ntype, cmp_node_boxmask_in, cmp_node_boxmask_out); - node_type_init(&ntype, node_composit_init_boxmask); - node_type_storage(&ntype, "NodeBoxMask", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_MASK_BOX, "Box Mask", NODE_CLASS_MATTE, 0); + node_type_socket_templates(&ntype, cmp_node_boxmask_in, cmp_node_boxmask_out); + node_type_init(&ntype, node_composit_init_boxmask); + node_type_storage(&ntype, "NodeBoxMask", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_brightness.c b/source/blender/nodes/composite/nodes/node_composite_brightness.c index dba8d30df68..14c4dc099c9 100644 --- a/source/blender/nodes/composite/nodes/node_composite_brightness.c +++ b/source/blender/nodes/composite/nodes/node_composite_brightness.c @@ -21,35 +21,33 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" - /* **************** Brigh and contrsast ******************** */ static bNodeSocketTemplate cmp_node_brightcontrast_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Bright"), 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("Contrast"), 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Bright"), 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("Contrast"), 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_brightcontrast_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; static void node_composit_init_brightcontrast(bNodeTree *UNUSED(ntree), bNode *node) { - node->custom1 = 1; + node->custom1 = 1; } void register_node_type_cmp_brightcontrast(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_BRIGHTCONTRAST, "Bright/Contrast", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, cmp_node_brightcontrast_in, cmp_node_brightcontrast_out); - node_type_init(&ntype, node_composit_init_brightcontrast); + cmp_node_type_base(&ntype, CMP_NODE_BRIGHTCONTRAST, "Bright/Contrast", NODE_CLASS_OP_COLOR, 0); + node_type_socket_templates(&ntype, cmp_node_brightcontrast_in, cmp_node_brightcontrast_out); + node_type_init(&ntype, node_composit_init_brightcontrast); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_channelMatte.c b/source/blender/nodes/composite/nodes/node_composite_channelMatte.c index 9468169e2a8..39fa5140cfd 100644 --- a/source/blender/nodes/composite/nodes/node_composite_channelMatte.c +++ b/source/blender/nodes/composite/nodes/node_composite_channelMatte.c @@ -21,45 +21,44 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" - /* ******************* Channel Matte Node ********************************* */ static bNodeSocketTemplate cmp_node_channel_matte_in[] = { - {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - {-1, 0, ""}, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_channel_matte_out[] = { - {SOCK_RGBA, 0, N_("Image")}, - {SOCK_FLOAT, 0, N_("Matte")}, - {-1, 0, ""}, + {SOCK_RGBA, 0, N_("Image")}, + {SOCK_FLOAT, 0, N_("Matte")}, + {-1, 0, ""}, }; static void node_composit_init_channel_matte(bNodeTree *UNUSED(ntree), bNode *node) { - NodeChroma *c = MEM_callocN(sizeof(NodeChroma), "node chroma"); - node->storage = c; - c->t1 = 1.0f; - c->t2 = 0.0f; - c->t3 = 0.0f; - c->fsize = 0.0f; - c->fstrength = 0.0f; - c->algorithm = 1; /*max channel limiting */ - c->channel = 1; /* limit by red */ - node->custom1 = 1; /* RGB channel */ - node->custom2 = 2; /* Green Channel */ + NodeChroma *c = MEM_callocN(sizeof(NodeChroma), "node chroma"); + node->storage = c; + c->t1 = 1.0f; + c->t2 = 0.0f; + c->t3 = 0.0f; + c->fsize = 0.0f; + c->fstrength = 0.0f; + c->algorithm = 1; /*max channel limiting */ + c->channel = 1; /* limit by red */ + node->custom1 = 1; /* RGB channel */ + node->custom2 = 2; /* Green Channel */ } void register_node_type_cmp_channel_matte(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_CHANNEL_MATTE, "Channel Key", NODE_CLASS_MATTE, NODE_PREVIEW); - node_type_socket_templates(&ntype, cmp_node_channel_matte_in, cmp_node_channel_matte_out); - node_type_init(&ntype, node_composit_init_channel_matte); - node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base( + &ntype, CMP_NODE_CHANNEL_MATTE, "Channel Key", NODE_CLASS_MATTE, NODE_PREVIEW); + node_type_socket_templates(&ntype, cmp_node_channel_matte_in, cmp_node_channel_matte_out); + node_type_init(&ntype, node_composit_init_channel_matte); + node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_chromaMatte.c b/source/blender/nodes/composite/nodes/node_composite_chromaMatte.c index eda217067e1..a15c6781f7d 100644 --- a/source/blender/nodes/composite/nodes/node_composite_chromaMatte.c +++ b/source/blender/nodes/composite/nodes/node_composite_chromaMatte.c @@ -21,41 +21,40 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" /* ******************* Chroma Key ********************************************************** */ static bNodeSocketTemplate cmp_node_chroma_in[] = { - {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - {SOCK_RGBA, 1, N_("Key Color"), 1.0f, 1.0f, 1.0f, 1.0f}, - {-1, 0, ""}, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_RGBA, 1, N_("Key Color"), 1.0f, 1.0f, 1.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_chroma_out[] = { - {SOCK_RGBA, 0, N_("Image")}, - {SOCK_FLOAT, 0, N_("Matte")}, - {-1, 0, ""}, + {SOCK_RGBA, 0, N_("Image")}, + {SOCK_FLOAT, 0, N_("Matte")}, + {-1, 0, ""}, }; static void node_composit_init_chroma_matte(bNodeTree *UNUSED(ntree), bNode *node) { - NodeChroma *c = MEM_callocN(sizeof(NodeChroma), "node chroma"); - node->storage = c; - c->t1 = DEG2RADF(30.0f); - c->t2 = DEG2RADF(10.0f); - c->t3 = 0.0f; - c->fsize = 0.0f; - c->fstrength = 1.0f; + NodeChroma *c = MEM_callocN(sizeof(NodeChroma), "node chroma"); + node->storage = c; + c->t1 = DEG2RADF(30.0f); + c->t2 = DEG2RADF(10.0f); + c->t3 = 0.0f; + c->fsize = 0.0f; + c->fstrength = 1.0f; } void register_node_type_cmp_chroma_matte(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_CHROMA_MATTE, "Chroma Key", NODE_CLASS_MATTE, NODE_PREVIEW); - node_type_socket_templates(&ntype, cmp_node_chroma_in, cmp_node_chroma_out); - node_type_init(&ntype, node_composit_init_chroma_matte); - node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_CHROMA_MATTE, "Chroma Key", NODE_CLASS_MATTE, NODE_PREVIEW); + node_type_socket_templates(&ntype, cmp_node_chroma_in, cmp_node_chroma_out); + node_type_init(&ntype, node_composit_init_chroma_matte); + node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_colorMatte.c b/source/blender/nodes/composite/nodes/node_composite_colorMatte.c index cb13603ea34..559bcbd02bf 100644 --- a/source/blender/nodes/composite/nodes/node_composite_colorMatte.c +++ b/source/blender/nodes/composite/nodes/node_composite_colorMatte.c @@ -21,41 +21,40 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" /* ******************* Color Key ********************************************************** */ static bNodeSocketTemplate cmp_node_color_in[] = { - {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - {SOCK_RGBA, 1, N_("Key Color"), 1.0f, 1.0f, 1.0f, 1.0f}, - {-1, 0, ""}, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_RGBA, 1, N_("Key Color"), 1.0f, 1.0f, 1.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_color_out[] = { - {SOCK_RGBA, 0, N_("Image")}, - {SOCK_FLOAT, 0, N_("Matte")}, - {-1, 0, ""}, + {SOCK_RGBA, 0, N_("Image")}, + {SOCK_FLOAT, 0, N_("Matte")}, + {-1, 0, ""}, }; static void node_composit_init_color_matte(bNodeTree *UNUSED(ntree), bNode *node) { - NodeChroma *c = MEM_callocN(sizeof(NodeChroma), "node color"); - node->storage = c; - c->t1 = 0.01f; - c->t2 = 0.1f; - c->t3 = 0.1f; - c->fsize = 0.0f; - c->fstrength = 1.0f; + NodeChroma *c = MEM_callocN(sizeof(NodeChroma), "node color"); + node->storage = c; + c->t1 = 0.01f; + c->t2 = 0.1f; + c->t3 = 0.1f; + c->fsize = 0.0f; + c->fstrength = 1.0f; } void register_node_type_cmp_color_matte(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_COLOR_MATTE, "Color Key", NODE_CLASS_MATTE, NODE_PREVIEW); - node_type_socket_templates(&ntype, cmp_node_color_in, cmp_node_color_out); - node_type_init(&ntype, node_composit_init_color_matte); - node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_COLOR_MATTE, "Color Key", NODE_CLASS_MATTE, NODE_PREVIEW); + node_type_socket_templates(&ntype, cmp_node_color_in, cmp_node_color_out); + node_type_init(&ntype, node_composit_init_color_matte); + node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_colorSpill.c b/source/blender/nodes/composite/nodes/node_composite_colorSpill.c index 10009dd4e1c..d47cf72f086 100644 --- a/source/blender/nodes/composite/nodes/node_composite_colorSpill.c +++ b/source/blender/nodes/composite/nodes/node_composite_colorSpill.c @@ -25,35 +25,36 @@ /* ******************* Color Spill Supression ********************************* */ static bNodeSocketTemplate cmp_node_color_spill_in[] = { - {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - {SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_FACTOR}, - {-1, 0, ""}, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_FACTOR}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_color_spill_out[] = { - {SOCK_RGBA, 0, N_("Image")}, - {-1, 0, ""}, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; static void node_composit_init_color_spill(bNodeTree *UNUSED(ntree), bNode *node) { - NodeColorspill *ncs = MEM_callocN(sizeof(NodeColorspill), "node colorspill"); - node->storage = ncs; - node->custom1 = 2; /* green channel */ - node->custom2 = 0; /* simple limit algo*/ - ncs->limchan = 0; /* limit by red */ - ncs->limscale = 1.0f; /* limit scaling factor */ - ncs->unspill = 0; /* do not use unspill */ + NodeColorspill *ncs = MEM_callocN(sizeof(NodeColorspill), "node colorspill"); + node->storage = ncs; + node->custom1 = 2; /* green channel */ + node->custom2 = 0; /* simple limit algo*/ + ncs->limchan = 0; /* limit by red */ + ncs->limscale = 1.0f; /* limit scaling factor */ + ncs->unspill = 0; /* do not use unspill */ } void register_node_type_cmp_color_spill(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_COLOR_SPILL, "Color Spill", NODE_CLASS_MATTE, 0); - node_type_socket_templates(&ntype, cmp_node_color_spill_in, cmp_node_color_spill_out); - node_type_init(&ntype, node_composit_init_color_spill); - node_type_storage(&ntype, "NodeColorspill", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_COLOR_SPILL, "Color Spill", NODE_CLASS_MATTE, 0); + node_type_socket_templates(&ntype, cmp_node_color_spill_in, cmp_node_color_spill_out); + node_type_init(&ntype, node_composit_init_color_spill); + node_type_storage( + &ntype, "NodeColorspill", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_colorbalance.c b/source/blender/nodes/composite/nodes/node_composite_colorbalance.c index 221b1e5192a..b0fbade8da4 100644 --- a/source/blender/nodes/composite/nodes/node_composite_colorbalance.c +++ b/source/blender/nodes/composite/nodes/node_composite_colorbalance.c @@ -25,14 +25,14 @@ /* ******************* Color Balance ********************************* */ static bNodeSocketTemplate cmp_node_colorbalance_in[] = { - {SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_FACTOR}, - {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - {-1, 0, ""}, + {SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_colorbalance_out[] = { - {SOCK_RGBA, 0, N_("Image")}, - {-1, 0, ""}, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; /* Sync functions update formula parameters for other modes, such that the result is comparable. @@ -42,51 +42,52 @@ static bNodeSocketTemplate cmp_node_colorbalance_out[] = { void ntreeCompositColorBalanceSyncFromLGG(bNodeTree *UNUSED(ntree), bNode *node) { - NodeColorBalance *n = node->storage; - int c; + NodeColorBalance *n = node->storage; + int c; - for (c = 0; c < 3; ++c) { - n->slope[c] = (2.0f - n->lift[c]) * n->gain[c]; - n->offset[c] = (n->lift[c] - 1.0f) * n->gain[c]; - n->power[c] = (n->gamma[c] != 0.0f) ? 1.0f / n->gamma[c] : 1000000.0f; - } + for (c = 0; c < 3; ++c) { + n->slope[c] = (2.0f - n->lift[c]) * n->gain[c]; + n->offset[c] = (n->lift[c] - 1.0f) * n->gain[c]; + n->power[c] = (n->gamma[c] != 0.0f) ? 1.0f / n->gamma[c] : 1000000.0f; + } } void ntreeCompositColorBalanceSyncFromCDL(bNodeTree *UNUSED(ntree), bNode *node) { - NodeColorBalance *n = node->storage; - int c; + NodeColorBalance *n = node->storage; + int c; - for (c = 0; c < 3; ++c) { - float d = n->slope[c] + n->offset[c]; - n->lift[c] = (d != 0.0f ? n->slope[c] + 2.0f * n->offset[c] / d : 0.0f); - n->gain[c] = d; - n->gamma[c] = (n->power[c] != 0.0f) ? 1.0f / n->power[c] : 1000000.0f; - } + for (c = 0; c < 3; ++c) { + float d = n->slope[c] + n->offset[c]; + n->lift[c] = (d != 0.0f ? n->slope[c] + 2.0f * n->offset[c] / d : 0.0f); + n->gain[c] = d; + n->gamma[c] = (n->power[c] != 0.0f) ? 1.0f / n->power[c] : 1000000.0f; + } } static void node_composit_init_colorbalance(bNodeTree *UNUSED(ntree), bNode *node) { - NodeColorBalance *n = node->storage = MEM_callocN(sizeof(NodeColorBalance), "node colorbalance"); + NodeColorBalance *n = node->storage = MEM_callocN(sizeof(NodeColorBalance), "node colorbalance"); - n->lift[0] = n->lift[1] = n->lift[2] = 1.0f; - n->gamma[0] = n->gamma[1] = n->gamma[2] = 1.0f; - n->gain[0] = n->gain[1] = n->gain[2] = 1.0f; + n->lift[0] = n->lift[1] = n->lift[2] = 1.0f; + n->gamma[0] = n->gamma[1] = n->gamma[2] = 1.0f; + n->gain[0] = n->gain[1] = n->gain[2] = 1.0f; - n->slope[0] = n->slope[1] = n->slope[2] = 1.0f; - n->offset[0] = n->offset[1] = n->offset[2] = 0.0f; - n->power[0] = n->power[1] = n->power[2] = 1.0f; + n->slope[0] = n->slope[1] = n->slope[2] = 1.0f; + n->offset[0] = n->offset[1] = n->offset[2] = 0.0f; + n->power[0] = n->power[1] = n->power[2] = 1.0f; } void register_node_type_cmp_colorbalance(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_COLORBALANCE, "Color Balance", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, cmp_node_colorbalance_in, cmp_node_colorbalance_out); - node_type_size(&ntype, 400, 200, 400); - node_type_init(&ntype, node_composit_init_colorbalance); - node_type_storage(&ntype, "NodeColorBalance", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_COLORBALANCE, "Color Balance", NODE_CLASS_OP_COLOR, 0); + node_type_socket_templates(&ntype, cmp_node_colorbalance_in, cmp_node_colorbalance_out); + node_type_size(&ntype, 400, 200, 400); + node_type_init(&ntype, node_composit_init_colorbalance); + node_type_storage( + &ntype, "NodeColorBalance", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_colorcorrection.c b/source/blender/nodes/composite/nodes/node_composite_colorcorrection.c index 0d7fe67764d..c333553577d 100644 --- a/source/blender/nodes/composite/nodes/node_composite_colorcorrection.c +++ b/source/blender/nodes/composite/nodes/node_composite_colorcorrection.c @@ -23,56 +23,57 @@ #include "node_composite_util.h" - /* ******************* Color Balance ********************************* */ static bNodeSocketTemplate cmp_node_colorcorrection_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Mask"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { -1, 0, ""}, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Mask"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_colorcorrection_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, ""}, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; static void node_composit_init_colorcorrection(bNodeTree *UNUSED(ntree), bNode *node) { - NodeColorCorrection *n = node->storage = MEM_callocN(sizeof(NodeColorCorrection), "node colorcorrection"); - n->startmidtones = 0.2f; - n->endmidtones = 0.7f; - n->master.contrast = 1.0f; - n->master.gain = 1.0f; - n->master.gamma = 1.0f; - n->master.lift = 0.0f; - n->master.saturation = 1.0f; - n->midtones.contrast = 1.0f; - n->midtones.gain = 1.0f; - n->midtones.gamma = 1.0f; - n->midtones.lift = 0.0f; - n->midtones.saturation = 1.0f; - n->shadows.contrast = 1.0f; - n->shadows.gain = 1.0f; - n->shadows.gamma = 1.0f; - n->shadows.lift = 0.0f; - n->shadows.saturation = 1.0f; - n->highlights.contrast = 1.0f; - n->highlights.gain = 1.0f; - n->highlights.gamma = 1.0f; - n->highlights.lift = 0.0f; - n->highlights.saturation = 1.0f; - node->custom1 = 7; // red + green + blue enabled + NodeColorCorrection *n = node->storage = MEM_callocN(sizeof(NodeColorCorrection), + "node colorcorrection"); + n->startmidtones = 0.2f; + n->endmidtones = 0.7f; + n->master.contrast = 1.0f; + n->master.gain = 1.0f; + n->master.gamma = 1.0f; + n->master.lift = 0.0f; + n->master.saturation = 1.0f; + n->midtones.contrast = 1.0f; + n->midtones.gain = 1.0f; + n->midtones.gamma = 1.0f; + n->midtones.lift = 0.0f; + n->midtones.saturation = 1.0f; + n->shadows.contrast = 1.0f; + n->shadows.gain = 1.0f; + n->shadows.gamma = 1.0f; + n->shadows.lift = 0.0f; + n->shadows.saturation = 1.0f; + n->highlights.contrast = 1.0f; + n->highlights.gain = 1.0f; + n->highlights.gamma = 1.0f; + n->highlights.lift = 0.0f; + n->highlights.saturation = 1.0f; + node->custom1 = 7; // red + green + blue enabled } void register_node_type_cmp_colorcorrection(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_COLORCORRECTION, "Color Correction", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, cmp_node_colorcorrection_in, cmp_node_colorcorrection_out); - node_type_size(&ntype, 400, 200, 600); - node_type_init(&ntype, node_composit_init_colorcorrection); - node_type_storage(&ntype, "NodeColorCorrection", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_COLORCORRECTION, "Color Correction", NODE_CLASS_OP_COLOR, 0); + node_type_socket_templates(&ntype, cmp_node_colorcorrection_in, cmp_node_colorcorrection_out); + node_type_size(&ntype, 400, 200, 600); + node_type_init(&ntype, node_composit_init_colorcorrection); + node_type_storage( + &ntype, "NodeColorCorrection", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_common.c b/source/blender/nodes/composite/nodes/node_composite_common.c index 480b9f1e989..78254cc7404 100644 --- a/source/blender/nodes/composite/nodes/node_composite_common.c +++ b/source/blender/nodes/composite/nodes/node_composite_common.c @@ -34,39 +34,40 @@ void register_node_type_cmp_group(void) { - static bNodeType ntype; + static bNodeType ntype; - /* NB: cannot use sh_node_type_base for node group, because it would map the node type - * to the shared NODE_GROUP integer type id. - */ - node_type_base_custom(&ntype, "CompositorNodeGroup", "Group", NODE_CLASS_GROUP, NODE_CONST_OUTPUT); - ntype.type = NODE_GROUP; - ntype.poll = cmp_node_poll_default; - ntype.poll_instance = node_group_poll_instance; - ntype.insert_link = node_insert_link_default; - ntype.update_internal_links = node_update_internal_links_default; - ntype.ext.srna = RNA_struct_find("CompositorNodeGroup"); - BLI_assert(ntype.ext.srna != NULL); - RNA_struct_blender_type_set(ntype.ext.srna, &ntype); + /* NB: cannot use sh_node_type_base for node group, because it would map the node type + * to the shared NODE_GROUP integer type id. + */ + node_type_base_custom( + &ntype, "CompositorNodeGroup", "Group", NODE_CLASS_GROUP, NODE_CONST_OUTPUT); + ntype.type = NODE_GROUP; + ntype.poll = cmp_node_poll_default; + ntype.poll_instance = node_group_poll_instance; + ntype.insert_link = node_insert_link_default; + ntype.update_internal_links = node_update_internal_links_default; + ntype.ext.srna = RNA_struct_find("CompositorNodeGroup"); + BLI_assert(ntype.ext.srna != NULL); + RNA_struct_blender_type_set(ntype.ext.srna, &ntype); - node_type_socket_templates(&ntype, NULL, NULL); - node_type_size(&ntype, 140, 60, 400); - node_type_label(&ntype, node_group_label); - node_type_update(&ntype, NULL, node_group_verify); + node_type_socket_templates(&ntype, NULL, NULL); + node_type_size(&ntype, 140, 60, 400); + node_type_label(&ntype, node_group_label); + node_type_update(&ntype, NULL, node_group_verify); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } void register_node_type_cmp_custom_group(bNodeType *ntype) { - /* These methods can be overriden but need a default implementation otherwise. */ - if (ntype->poll == NULL) { - ntype->poll = cmp_node_poll_default; - } - if (ntype->insert_link == NULL) { - ntype->insert_link = node_insert_link_default; - } - if (ntype->update_internal_links == NULL) { - ntype->update_internal_links = node_update_internal_links_default; - } + /* These methods can be overriden but need a default implementation otherwise. */ + if (ntype->poll == NULL) { + ntype->poll = cmp_node_poll_default; + } + if (ntype->insert_link == NULL) { + ntype->insert_link = node_insert_link_default; + } + if (ntype->update_internal_links == NULL) { + ntype->update_internal_links = node_update_internal_links_default; + } } diff --git a/source/blender/nodes/composite/nodes/node_composite_composite.c b/source/blender/nodes/composite/nodes/node_composite_composite.c index fbddeac4094..9a79d2da6ce 100644 --- a/source/blender/nodes/composite/nodes/node_composite_composite.c +++ b/source/blender/nodes/composite/nodes/node_composite_composite.c @@ -25,21 +25,21 @@ /* **************** COMPOSITE ******************** */ static bNodeSocketTemplate cmp_node_composite_in[] = { - { SOCK_RGBA, 1, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Alpha"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("Z"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Alpha"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("Z"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, + {-1, 0, ""}, }; void register_node_type_cmp_composite(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_COMPOSITE, "Composite", NODE_CLASS_OUTPUT, NODE_PREVIEW); - node_type_socket_templates(&ntype, cmp_node_composite_in, NULL); + cmp_node_type_base(&ntype, CMP_NODE_COMPOSITE, "Composite", NODE_CLASS_OUTPUT, NODE_PREVIEW); + node_type_socket_templates(&ntype, cmp_node_composite_in, NULL); - /* Do not allow muting for this node. */ - node_type_internal_links(&ntype, NULL); + /* Do not allow muting for this node. */ + node_type_internal_links(&ntype, NULL); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_cornerpin.c b/source/blender/nodes/composite/nodes/node_composite_cornerpin.c index f6320af4885..40523c4886e 100644 --- a/source/blender/nodes/composite/nodes/node_composite_cornerpin.c +++ b/source/blender/nodes/composite/nodes/node_composite_cornerpin.c @@ -21,30 +21,29 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" static bNodeSocketTemplate inputs[] = { - { SOCK_RGBA, 1, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_VECTOR, 1, N_("Upper Left"), 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_VECTOR, 1, N_("Upper Right"), 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_VECTOR, 1, N_("Lower Left"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_VECTOR, 1, N_("Lower Right"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {SOCK_VECTOR, 1, N_("Upper Left"), 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {SOCK_VECTOR, 1, N_("Upper Right"), 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {SOCK_VECTOR, 1, N_("Lower Left"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {SOCK_VECTOR, 1, N_("Lower Right"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate outputs[] = { - { SOCK_RGBA, 0, N_("Image")}, - { SOCK_FLOAT, 0, N_("Plane")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {SOCK_FLOAT, 0, N_("Plane")}, + {-1, 0, ""}, }; void register_node_type_cmp_cornerpin(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_CORNERPIN, "Corner Pin", NODE_CLASS_DISTORT, 0); - node_type_socket_templates(&ntype, inputs, outputs); + cmp_node_type_base(&ntype, CMP_NODE_CORNERPIN, "Corner Pin", NODE_CLASS_DISTORT, 0); + node_type_socket_templates(&ntype, inputs, outputs); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_crop.c b/source/blender/nodes/composite/nodes/node_composite_crop.c index e89fd4cdb2b..d3a7b47386a 100644 --- a/source/blender/nodes/composite/nodes/node_composite_crop.c +++ b/source/blender/nodes/composite/nodes/node_composite_crop.c @@ -21,38 +21,37 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" /* **************** Crop ******************** */ static bNodeSocketTemplate cmp_node_crop_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_crop_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; static void node_composit_init_crop(bNodeTree *UNUSED(ntree), bNode *node) { - NodeTwoXYs *nxy = MEM_callocN(sizeof(NodeTwoXYs), "node xy data"); - node->storage = nxy; - nxy->x1 = 0; - nxy->x2 = 0; - nxy->y1 = 0; - nxy->y2 = 0; + NodeTwoXYs *nxy = MEM_callocN(sizeof(NodeTwoXYs), "node xy data"); + node->storage = nxy; + nxy->x1 = 0; + nxy->x2 = 0; + nxy->y1 = 0; + nxy->y2 = 0; } void register_node_type_cmp_crop(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_CROP, "Crop", NODE_CLASS_DISTORT, 0); - node_type_socket_templates(&ntype, cmp_node_crop_in, cmp_node_crop_out); - node_type_init(&ntype, node_composit_init_crop); - node_type_storage(&ntype, "NodeTwoXYs", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_CROP, "Crop", NODE_CLASS_DISTORT, 0); + node_type_socket_templates(&ntype, cmp_node_crop_in, cmp_node_crop_out); + node_type_init(&ntype, node_composit_init_crop); + node_type_storage(&ntype, "NodeTwoXYs", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_cryptomatte.c b/source/blender/nodes/composite/nodes/node_composite_cryptomatte.c index 1569d27017e..729252f0937 100644 --- a/source/blender/nodes/composite/nodes/node_composite_cryptomatte.c +++ b/source/blender/nodes/composite/nodes/node_composite_cryptomatte.c @@ -31,264 +31,264 @@ BLI_INLINE float hash_to_float(uint32_t hash) { - uint32_t mantissa = hash & ((1 << 23) - 1); - uint32_t exponent = (hash >> 23) & ((1 << 8) - 1); - exponent = MAX2(exponent, (uint32_t)1); - exponent = MIN2(exponent, (uint32_t)254); - exponent = exponent << 23; - uint32_t sign = (hash >> 31); - sign = sign << 31; - uint32_t float_bits = sign | exponent | mantissa; - float f; - /* Bit casting relies on equal size for both types. */ - BLI_STATIC_ASSERT(sizeof(float) == sizeof(uint32_t), "float and uint32_t are not the same size") - memcpy(&f, &float_bits, sizeof(float)); - return f; + uint32_t mantissa = hash & ((1 << 23) - 1); + uint32_t exponent = (hash >> 23) & ((1 << 8) - 1); + exponent = MAX2(exponent, (uint32_t)1); + exponent = MIN2(exponent, (uint32_t)254); + exponent = exponent << 23; + uint32_t sign = (hash >> 31); + sign = sign << 31; + uint32_t float_bits = sign | exponent | mantissa; + float f; + /* Bit casting relies on equal size for both types. */ + BLI_STATIC_ASSERT(sizeof(float) == sizeof(uint32_t), "float and uint32_t are not the same size") + memcpy(&f, &float_bits, sizeof(float)); + return f; } static void cryptomatte_add(NodeCryptomatte *n, float f) { - /* Turn the number into a string. */ - char number[32]; - BLI_snprintf(number, sizeof(number), "<%.9g>", f); - - /* Search if we already have the number. */ - if (n->matte_id && strlen(n->matte_id) != 0) { - size_t start = 0; - const size_t end = strlen(n->matte_id); - size_t token_len = 0; - while (start < end) { - /* Ignore leading whitespace. */ - while (start < end && n->matte_id[start] == ' ') { - ++start; - } - - /* Find the next seprator. */ - char *token_end = strchr(n->matte_id + start, ','); - if (token_end == NULL || token_end == n->matte_id + start) { - token_end = n->matte_id + end; - } - /* Be aware that token_len still contains any trailing white space. */ - token_len = token_end - (n->matte_id + start); - - /* If this has a leading bracket, assume a raw floating point number and look for the closing bracket. */ - if (n->matte_id[start] == '<') { - if (strncmp(n->matte_id + start, number, strlen(number)) == 0) { - /* This number is already there, so continue. */ - return; - } - } - else { - /* Remove trailing white space */ - size_t name_len = token_len; - while (n->matte_id[start + name_len] == ' ' && name_len > 0) { - name_len--; - } - /* Calculate the hash of the token and compare. */ - uint32_t hash = BLI_hash_mm3((const unsigned char *)(n->matte_id + start), name_len, 0); - if (f == hash_to_float(hash)) { - return; - } - } - start += token_len + 1; - } - } - - DynStr *new_matte = BLI_dynstr_new(); - if (!new_matte) { - return; - } - - if (n->matte_id) { - BLI_dynstr_append(new_matte, n->matte_id); - MEM_freeN(n->matte_id); - } - - if (BLI_dynstr_get_len(new_matte) > 0) { - BLI_dynstr_append(new_matte, ","); - } - BLI_dynstr_append(new_matte, number); - n->matte_id = BLI_dynstr_get_cstring(new_matte); - BLI_dynstr_free(new_matte); + /* Turn the number into a string. */ + char number[32]; + BLI_snprintf(number, sizeof(number), "<%.9g>", f); + + /* Search if we already have the number. */ + if (n->matte_id && strlen(n->matte_id) != 0) { + size_t start = 0; + const size_t end = strlen(n->matte_id); + size_t token_len = 0; + while (start < end) { + /* Ignore leading whitespace. */ + while (start < end && n->matte_id[start] == ' ') { + ++start; + } + + /* Find the next seprator. */ + char *token_end = strchr(n->matte_id + start, ','); + if (token_end == NULL || token_end == n->matte_id + start) { + token_end = n->matte_id + end; + } + /* Be aware that token_len still contains any trailing white space. */ + token_len = token_end - (n->matte_id + start); + + /* If this has a leading bracket, assume a raw floating point number and look for the closing bracket. */ + if (n->matte_id[start] == '<') { + if (strncmp(n->matte_id + start, number, strlen(number)) == 0) { + /* This number is already there, so continue. */ + return; + } + } + else { + /* Remove trailing white space */ + size_t name_len = token_len; + while (n->matte_id[start + name_len] == ' ' && name_len > 0) { + name_len--; + } + /* Calculate the hash of the token and compare. */ + uint32_t hash = BLI_hash_mm3((const unsigned char *)(n->matte_id + start), name_len, 0); + if (f == hash_to_float(hash)) { + return; + } + } + start += token_len + 1; + } + } + + DynStr *new_matte = BLI_dynstr_new(); + if (!new_matte) { + return; + } + + if (n->matte_id) { + BLI_dynstr_append(new_matte, n->matte_id); + MEM_freeN(n->matte_id); + } + + if (BLI_dynstr_get_len(new_matte) > 0) { + BLI_dynstr_append(new_matte, ","); + } + BLI_dynstr_append(new_matte, number); + n->matte_id = BLI_dynstr_get_cstring(new_matte); + BLI_dynstr_free(new_matte); } static void cryptomatte_remove(NodeCryptomatte *n, float f) { - if (n->matte_id == NULL || strlen(n->matte_id) == 0) { - /* Empty string, nothing to remove. */ - return; - } - - /* This will be the new string without the removed key. */ - DynStr *new_matte = BLI_dynstr_new(); - if (!new_matte) { - return; - } - - /* Turn the number into a string. */ - static char number[32]; - BLI_snprintf(number, sizeof(number), "<%.9g>", f); - - /* Search if we already have the number. */ - size_t start = 0; - const size_t end = strlen(n->matte_id); - size_t token_len = 0; - bool is_first = true; - while (start < end) { - bool skip = false; - /* Ignore leading whitespace or commas. */ - while (start < end && ((n->matte_id[start] == ' ') || (n->matte_id[start] == ','))) { - ++start; - } - - /* Find the next seprator. */ - char *token_end = strchr(n->matte_id + start + 1, ','); - if (token_end == NULL || token_end == n->matte_id + start) { - token_end = n->matte_id + end; - } - /* Be aware that token_len still contains any trailing white space. */ - token_len = token_end - (n->matte_id + start); - - if (token_len == 1) { - skip = true; - } - /* If this has a leading bracket, assume a raw floating point number and look for the closing bracket. */ - else if (n->matte_id[start] == '<') { - if (strncmp(n->matte_id + start, number, strlen(number)) == 0) { - /* This number is already there, so skip it. */ - skip = true; - } - } - else { - /* Remove trailing white space */ - size_t name_len = token_len; - while (n->matte_id[start + name_len] == ' ' && name_len > 0) { - name_len--; - } - /* Calculate the hash of the token and compare. */ - uint32_t hash = BLI_hash_mm3((const unsigned char *)(n->matte_id + start), name_len, 0); - if (f == hash_to_float(hash)) { - skip = true; - } - } - if (!skip) { - if (is_first) { - is_first = false; - } - else { - BLI_dynstr_append(new_matte, ", "); - } - BLI_dynstr_nappend(new_matte, n->matte_id + start, token_len); - } - start += token_len + 1; - } - - if (n->matte_id) { - MEM_freeN(n->matte_id); - n->matte_id = NULL; - } - if (BLI_dynstr_get_len(new_matte) > 0) { - n->matte_id = BLI_dynstr_get_cstring(new_matte); - } - BLI_dynstr_free(new_matte); + if (n->matte_id == NULL || strlen(n->matte_id) == 0) { + /* Empty string, nothing to remove. */ + return; + } + + /* This will be the new string without the removed key. */ + DynStr *new_matte = BLI_dynstr_new(); + if (!new_matte) { + return; + } + + /* Turn the number into a string. */ + static char number[32]; + BLI_snprintf(number, sizeof(number), "<%.9g>", f); + + /* Search if we already have the number. */ + size_t start = 0; + const size_t end = strlen(n->matte_id); + size_t token_len = 0; + bool is_first = true; + while (start < end) { + bool skip = false; + /* Ignore leading whitespace or commas. */ + while (start < end && ((n->matte_id[start] == ' ') || (n->matte_id[start] == ','))) { + ++start; + } + + /* Find the next seprator. */ + char *token_end = strchr(n->matte_id + start + 1, ','); + if (token_end == NULL || token_end == n->matte_id + start) { + token_end = n->matte_id + end; + } + /* Be aware that token_len still contains any trailing white space. */ + token_len = token_end - (n->matte_id + start); + + if (token_len == 1) { + skip = true; + } + /* If this has a leading bracket, assume a raw floating point number and look for the closing bracket. */ + else if (n->matte_id[start] == '<') { + if (strncmp(n->matte_id + start, number, strlen(number)) == 0) { + /* This number is already there, so skip it. */ + skip = true; + } + } + else { + /* Remove trailing white space */ + size_t name_len = token_len; + while (n->matte_id[start + name_len] == ' ' && name_len > 0) { + name_len--; + } + /* Calculate the hash of the token and compare. */ + uint32_t hash = BLI_hash_mm3((const unsigned char *)(n->matte_id + start), name_len, 0); + if (f == hash_to_float(hash)) { + skip = true; + } + } + if (!skip) { + if (is_first) { + is_first = false; + } + else { + BLI_dynstr_append(new_matte, ", "); + } + BLI_dynstr_nappend(new_matte, n->matte_id + start, token_len); + } + start += token_len + 1; + } + + if (n->matte_id) { + MEM_freeN(n->matte_id); + n->matte_id = NULL; + } + if (BLI_dynstr_get_len(new_matte) > 0) { + n->matte_id = BLI_dynstr_get_cstring(new_matte); + } + BLI_dynstr_free(new_matte); } static bNodeSocketTemplate outputs[] = { - { SOCK_RGBA, 0, N_("Image")}, - { SOCK_FLOAT, 0, N_("Matte")}, - { SOCK_RGBA, 0, N_("Pick")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {SOCK_FLOAT, 0, N_("Matte")}, + {SOCK_RGBA, 0, N_("Pick")}, + {-1, 0, ""}, }; void ntreeCompositCryptomatteSyncFromAdd(bNodeTree *UNUSED(ntree), bNode *node) { - NodeCryptomatte *n = node->storage; - if (n->add[0] != 0.0f) { - cryptomatte_add(n, n->add[0]); - n->add[0] = 0.0f; - n->add[1] = 0.0f; - n->add[2] = 0.0f; - } + NodeCryptomatte *n = node->storage; + if (n->add[0] != 0.0f) { + cryptomatte_add(n, n->add[0]); + n->add[0] = 0.0f; + n->add[1] = 0.0f; + n->add[2] = 0.0f; + } } void ntreeCompositCryptomatteSyncFromRemove(bNodeTree *UNUSED(ntree), bNode *node) { - NodeCryptomatte *n = node->storage; - if (n->remove[0] != 0.0f) { - cryptomatte_remove(n, n->remove[0]); - n->remove[0] = 0.0f; - n->remove[1] = 0.0f; - n->remove[2] = 0.0f; - } + NodeCryptomatte *n = node->storage; + if (n->remove[0] != 0.0f) { + cryptomatte_remove(n, n->remove[0]); + n->remove[0] = 0.0f; + n->remove[1] = 0.0f; + n->remove[2] = 0.0f; + } } bNodeSocket *ntreeCompositCryptomatteAddSocket(bNodeTree *ntree, bNode *node) { - NodeCryptomatte *n = node->storage; - char sockname[32]; - n->num_inputs++; - BLI_snprintf(sockname, sizeof(sockname), "Crypto %.2d", n->num_inputs - 1); - bNodeSocket *sock = nodeAddStaticSocket(ntree, node, SOCK_IN, SOCK_RGBA, PROP_NONE, NULL, sockname); - return sock; + NodeCryptomatte *n = node->storage; + char sockname[32]; + n->num_inputs++; + BLI_snprintf(sockname, sizeof(sockname), "Crypto %.2d", n->num_inputs - 1); + bNodeSocket *sock = nodeAddStaticSocket( + ntree, node, SOCK_IN, SOCK_RGBA, PROP_NONE, NULL, sockname); + return sock; } int ntreeCompositCryptomatteRemoveSocket(bNodeTree *ntree, bNode *node) { - NodeCryptomatte *n = node->storage; - if (n->num_inputs < 2) { - return 0; - } - bNodeSocket *sock = node->inputs.last; - nodeRemoveSocket(ntree, node, sock); - n->num_inputs--; - return 1; + NodeCryptomatte *n = node->storage; + if (n->num_inputs < 2) { + return 0; + } + bNodeSocket *sock = node->inputs.last; + nodeRemoveSocket(ntree, node, sock); + n->num_inputs--; + return 1; } static void init(bNodeTree *ntree, bNode *node) { - NodeCryptomatte *user = MEM_callocN(sizeof(NodeCryptomatte), "cryptomatte user"); - node->storage = user; + NodeCryptomatte *user = MEM_callocN(sizeof(NodeCryptomatte), "cryptomatte user"); + node->storage = user; + nodeAddStaticSocket(ntree, node, SOCK_IN, SOCK_RGBA, PROP_NONE, "image", "Image"); - nodeAddStaticSocket(ntree, node, SOCK_IN, SOCK_RGBA, PROP_NONE, "image", "Image"); - - /* Add three inputs by default, as recommended by the Cryptomatte specification. */ - ntreeCompositCryptomatteAddSocket(ntree, node); - ntreeCompositCryptomatteAddSocket(ntree, node); - ntreeCompositCryptomatteAddSocket(ntree, node); + /* Add three inputs by default, as recommended by the Cryptomatte specification. */ + ntreeCompositCryptomatteAddSocket(ntree, node); + ntreeCompositCryptomatteAddSocket(ntree, node); + ntreeCompositCryptomatteAddSocket(ntree, node); } static void node_free_cryptomatte(bNode *node) { - NodeCryptomatte *nc = node->storage; + NodeCryptomatte *nc = node->storage; - if (nc) { - if (nc->matte_id) { - MEM_freeN(nc->matte_id); - } + if (nc) { + if (nc->matte_id) { + MEM_freeN(nc->matte_id); + } - MEM_freeN(nc); - } + MEM_freeN(nc); + } } static void node_copy_cryptomatte(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, bNode *src_node) { - NodeCryptomatte *src_nc = src_node->storage; - NodeCryptomatte *dest_nc = MEM_dupallocN(src_nc); + NodeCryptomatte *src_nc = src_node->storage; + NodeCryptomatte *dest_nc = MEM_dupallocN(src_nc); - if (src_nc->matte_id) - dest_nc->matte_id = MEM_dupallocN(src_nc->matte_id); + if (src_nc->matte_id) + dest_nc->matte_id = MEM_dupallocN(src_nc->matte_id); - dest_node->storage = dest_nc; + dest_node->storage = dest_nc; } void register_node_type_cmp_cryptomatte(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_CRYPTOMATTE, "Cryptomatte", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, NULL, outputs); - node_type_init(&ntype, init); - node_type_storage(&ntype, "NodeCryptomatte", node_free_cryptomatte, node_copy_cryptomatte); - nodeRegisterType(&ntype); + cmp_node_type_base(&ntype, CMP_NODE_CRYPTOMATTE, "Cryptomatte", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, NULL, outputs); + node_type_init(&ntype, init); + node_type_storage(&ntype, "NodeCryptomatte", node_free_cryptomatte, node_copy_cryptomatte); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_curves.c b/source/blender/nodes/composite/nodes/node_composite_curves.c index b1c59bf0b17..7b2e7329432 100644 --- a/source/blender/nodes/composite/nodes/node_composite_curves.c +++ b/source/blender/nodes/composite/nodes/node_composite_curves.c @@ -21,98 +21,93 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" - /* **************** CURVE Time ******************** */ /* custom1 = sfra, custom2 = efra */ static bNodeSocketTemplate cmp_node_time_out[] = { - { SOCK_FLOAT, 0, N_("Fac")}, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("Fac")}, + {-1, 0, ""}, }; static void node_composit_init_curves_time(bNodeTree *UNUSED(ntree), bNode *node) { - node->custom1 = 1; - node->custom2 = 250; - node->storage = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + node->custom1 = 1; + node->custom2 = 250; + node->storage = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); } void register_node_type_cmp_curve_time(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_TIME, "Time", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, NULL, cmp_node_time_out); - node_type_size(&ntype, 140, 100, 320); - node_type_init(&ntype, node_composit_init_curves_time); - node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); + cmp_node_type_base(&ntype, CMP_NODE_TIME, "Time", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, NULL, cmp_node_time_out); + node_type_size(&ntype, 140, 100, 320); + node_type_init(&ntype, node_composit_init_curves_time); + node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } - - /* **************** CURVE VEC ******************** */ static bNodeSocketTemplate cmp_node_curve_vec_in[] = { - { SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE}, - { -1, 0, "" }, + {SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_curve_vec_out[] = { - { SOCK_VECTOR, 0, N_("Vector")}, - { -1, 0, "" }, + {SOCK_VECTOR, 0, N_("Vector")}, + {-1, 0, ""}, }; static void node_composit_init_curve_vec(bNodeTree *UNUSED(ntree), bNode *node) { - node->storage = curvemapping_add(3, -1.0f, -1.0f, 1.0f, 1.0f); + node->storage = curvemapping_add(3, -1.0f, -1.0f, 1.0f, 1.0f); } void register_node_type_cmp_curve_vec(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_CURVE_VEC, "Vector Curves", NODE_CLASS_OP_VECTOR, 0); - node_type_socket_templates(&ntype, cmp_node_curve_vec_in, cmp_node_curve_vec_out); - node_type_size(&ntype, 200, 140, 320); - node_type_init(&ntype, node_composit_init_curve_vec); - node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); + cmp_node_type_base(&ntype, CMP_NODE_CURVE_VEC, "Vector Curves", NODE_CLASS_OP_VECTOR, 0); + node_type_socket_templates(&ntype, cmp_node_curve_vec_in, cmp_node_curve_vec_out); + node_type_size(&ntype, 200, 140, 320); + node_type_init(&ntype, node_composit_init_curve_vec); + node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } - /* **************** CURVE RGB ******************** */ static bNodeSocketTemplate cmp_node_curve_rgb_in[] = { - { SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_FACTOR}, - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_RGBA, 1, N_("Black Level"), 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 1, N_("White Level"), 1.0f, 1.0f, 1.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_FACTOR}, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_RGBA, 1, N_("Black Level"), 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 1, N_("White Level"), 1.0f, 1.0f, 1.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_curve_rgb_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; static void node_composit_init_curve_rgb(bNodeTree *UNUSED(ntree), bNode *node) { - node->storage = curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f); + node->storage = curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f); } void register_node_type_cmp_curve_rgb(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_CURVE_RGB, "RGB Curves", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, cmp_node_curve_rgb_in, cmp_node_curve_rgb_out); - node_type_size(&ntype, 200, 140, 320); - node_type_init(&ntype, node_composit_init_curve_rgb); - node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); + cmp_node_type_base(&ntype, CMP_NODE_CURVE_RGB, "RGB Curves", NODE_CLASS_OP_COLOR, 0); + node_type_socket_templates(&ntype, cmp_node_curve_rgb_in, cmp_node_curve_rgb_out); + node_type_size(&ntype, 200, 140, 320); + node_type_init(&ntype, node_composit_init_curve_rgb); + node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_defocus.c b/source/blender/nodes/composite/nodes/node_composite_defocus.c index 96949657bcf..d5e64c56519 100644 --- a/source/blender/nodes/composite/nodes/node_composite_defocus.c +++ b/source/blender/nodes/composite/nodes/node_composite_defocus.c @@ -27,40 +27,40 @@ /* ************ qdn: Defocus node ****************** */ static bNodeSocketTemplate cmp_node_defocus_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Z"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Z"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_defocus_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; static void node_composit_init_defocus(bNodeTree *UNUSED(ntree), bNode *node) { - /* qdn: defocus node */ - NodeDefocus *nbd = MEM_callocN(sizeof(NodeDefocus), "node defocus data"); - nbd->bktype = 0; - nbd->rotation = 0.0f; - nbd->preview = 1; - nbd->gamco = 0; - nbd->samples = 16; - nbd->fstop = 128.f; - nbd->maxblur = 16; - nbd->bthresh = 1.f; - nbd->scale = 1.f; - nbd->no_zbuf = 1; - node->storage = nbd; + /* qdn: defocus node */ + NodeDefocus *nbd = MEM_callocN(sizeof(NodeDefocus), "node defocus data"); + nbd->bktype = 0; + nbd->rotation = 0.0f; + nbd->preview = 1; + nbd->gamco = 0; + nbd->samples = 16; + nbd->fstop = 128.f; + nbd->maxblur = 16; + nbd->bthresh = 1.f; + nbd->scale = 1.f; + nbd->no_zbuf = 1; + node->storage = nbd; } void register_node_type_cmp_defocus(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_DEFOCUS, "Defocus", NODE_CLASS_OP_FILTER, 0); - node_type_socket_templates(&ntype, cmp_node_defocus_in, cmp_node_defocus_out); - node_type_init(&ntype, node_composit_init_defocus); - node_type_storage(&ntype, "NodeDefocus", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_DEFOCUS, "Defocus", NODE_CLASS_OP_FILTER, 0); + node_type_socket_templates(&ntype, cmp_node_defocus_in, cmp_node_defocus_out); + node_type_init(&ntype, node_composit_init_defocus); + node_type_storage(&ntype, "NodeDefocus", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_despeckle.c b/source/blender/nodes/composite/nodes/node_composite_despeckle.c index 4c5ab27b6cd..f57dd6b6766 100644 --- a/source/blender/nodes/composite/nodes/node_composite_despeckle.c +++ b/source/blender/nodes/composite/nodes/node_composite_despeckle.c @@ -25,28 +25,28 @@ /* **************** FILTER ******************** */ static bNodeSocketTemplate cmp_node_despeckle_in[] = { - { SOCK_FLOAT, 1, N_("Fac"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Fac"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_despeckle_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; static void node_composit_init_despeckle(bNodeTree *UNUSED(ntree), bNode *node) { - node->custom3 = 0.5f; - node->custom4 = 0.5f; + node->custom3 = 0.5f; + node->custom4 = 0.5f; } void register_node_type_cmp_despeckle(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_DESPECKLE, "Despeckle", NODE_CLASS_OP_FILTER, NODE_PREVIEW); - node_type_socket_templates(&ntype, cmp_node_despeckle_in, cmp_node_despeckle_out); - node_type_init(&ntype, node_composit_init_despeckle); + cmp_node_type_base(&ntype, CMP_NODE_DESPECKLE, "Despeckle", NODE_CLASS_OP_FILTER, NODE_PREVIEW); + node_type_socket_templates(&ntype, cmp_node_despeckle_in, cmp_node_despeckle_out); + node_type_init(&ntype, node_composit_init_despeckle); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_diffMatte.c b/source/blender/nodes/composite/nodes/node_composite_diffMatte.c index 6163d433349..20b5b009f72 100644 --- a/source/blender/nodes/composite/nodes/node_composite_diffMatte.c +++ b/source/blender/nodes/composite/nodes/node_composite_diffMatte.c @@ -21,38 +21,38 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" /* ******************* channel Difference Matte ********************************* */ static bNodeSocketTemplate cmp_node_diff_matte_in[] = { - {SOCK_RGBA, 1, N_("Image 1"), 1.0f, 1.0f, 1.0f, 1.0f}, - {SOCK_RGBA, 1, N_("Image 2"), 1.0f, 1.0f, 1.0f, 1.0f}, - {-1, 0, ""}, + {SOCK_RGBA, 1, N_("Image 1"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_RGBA, 1, N_("Image 2"), 1.0f, 1.0f, 1.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_diff_matte_out[] = { - {SOCK_RGBA, 0, N_("Image")}, - {SOCK_FLOAT, 0, N_("Matte")}, - {-1, 0, ""}, + {SOCK_RGBA, 0, N_("Image")}, + {SOCK_FLOAT, 0, N_("Matte")}, + {-1, 0, ""}, }; static void node_composit_init_diff_matte(bNodeTree *UNUSED(ntree), bNode *node) { - NodeChroma *c = MEM_callocN(sizeof(NodeChroma), "node chroma"); - node->storage = c; - c->t1 = 0.1f; - c->t2 = 0.1f; + NodeChroma *c = MEM_callocN(sizeof(NodeChroma), "node chroma"); + node->storage = c; + c->t1 = 0.1f; + c->t2 = 0.1f; } void register_node_type_cmp_diff_matte(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_DIFF_MATTE, "Difference Key", NODE_CLASS_MATTE, NODE_PREVIEW); - node_type_socket_templates(&ntype, cmp_node_diff_matte_in, cmp_node_diff_matte_out); - node_type_init(&ntype, node_composit_init_diff_matte); - node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base( + &ntype, CMP_NODE_DIFF_MATTE, "Difference Key", NODE_CLASS_MATTE, NODE_PREVIEW); + node_type_socket_templates(&ntype, cmp_node_diff_matte_in, cmp_node_diff_matte_out); + node_type_init(&ntype, node_composit_init_diff_matte); + node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_dilate.c b/source/blender/nodes/composite/nodes/node_composite_dilate.c index e0ccfb6ec10..f46df1d7d78 100644 --- a/source/blender/nodes/composite/nodes/node_composite_dilate.c +++ b/source/blender/nodes/composite/nodes/node_composite_dilate.c @@ -21,36 +21,30 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" - /* **************** Dilate/Erode ******************** */ static bNodeSocketTemplate cmp_node_dilateerode_in[] = { - { SOCK_FLOAT, 1, N_("Mask"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { -1, 0, "" } -}; -static bNodeSocketTemplate cmp_node_dilateerode_out[] = { - { SOCK_FLOAT, 0, N_("Mask")}, - { -1, 0, "" } -}; + {SOCK_FLOAT, 1, N_("Mask"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, {-1, 0, ""}}; +static bNodeSocketTemplate cmp_node_dilateerode_out[] = {{SOCK_FLOAT, 0, N_("Mask")}, {-1, 0, ""}}; static void node_composit_init_dilateerode(bNodeTree *UNUSED(ntree), bNode *node) { - NodeDilateErode *data = MEM_callocN(sizeof(NodeDilateErode), "NodeDilateErode"); - data->falloff = PROP_SMOOTH; - node->storage = data; + NodeDilateErode *data = MEM_callocN(sizeof(NodeDilateErode), "NodeDilateErode"); + data->falloff = PROP_SMOOTH; + node->storage = data; } void register_node_type_cmp_dilateerode(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_DILATEERODE, "Dilate/Erode", NODE_CLASS_OP_FILTER, 0); - node_type_socket_templates(&ntype, cmp_node_dilateerode_in, cmp_node_dilateerode_out); - node_type_init(&ntype, node_composit_init_dilateerode); - node_type_storage(&ntype, "NodeDilateErode", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_DILATEERODE, "Dilate/Erode", NODE_CLASS_OP_FILTER, 0); + node_type_socket_templates(&ntype, cmp_node_dilateerode_in, cmp_node_dilateerode_out); + node_type_init(&ntype, node_composit_init_dilateerode); + node_type_storage( + &ntype, "NodeDilateErode", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_directionalblur.c b/source/blender/nodes/composite/nodes/node_composite_directionalblur.c index b0996d76cc1..b0f610cb942 100644 --- a/source/blender/nodes/composite/nodes/node_composite_directionalblur.c +++ b/source/blender/nodes/composite/nodes/node_composite_directionalblur.c @@ -21,36 +21,31 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" static bNodeSocketTemplate cmp_node_dblur_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.f}, - { -1, 0, "" } -}; + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.f}, {-1, 0, ""}}; -static bNodeSocketTemplate cmp_node_dblur_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" } -}; +static bNodeSocketTemplate cmp_node_dblur_out[] = {{SOCK_RGBA, 0, N_("Image")}, {-1, 0, ""}}; static void node_composit_init_dblur(bNodeTree *UNUSED(ntree), bNode *node) { - NodeDBlurData *ndbd = MEM_callocN(sizeof(NodeDBlurData), "node dblur data"); - node->storage = ndbd; - ndbd->iter = 1; - ndbd->center_x = 0.5; - ndbd->center_y = 0.5; + NodeDBlurData *ndbd = MEM_callocN(sizeof(NodeDBlurData), "node dblur data"); + node->storage = ndbd; + ndbd->iter = 1; + ndbd->center_x = 0.5; + ndbd->center_y = 0.5; } void register_node_type_cmp_dblur(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_DBLUR, "Directional Blur", NODE_CLASS_OP_FILTER, 0); - node_type_socket_templates(&ntype, cmp_node_dblur_in, cmp_node_dblur_out); - node_type_init(&ntype, node_composit_init_dblur); - node_type_storage(&ntype, "NodeDBlurData", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_DBLUR, "Directional Blur", NODE_CLASS_OP_FILTER, 0); + node_type_socket_templates(&ntype, cmp_node_dblur_in, cmp_node_dblur_out); + node_type_init(&ntype, node_composit_init_dblur); + node_type_storage( + &ntype, "NodeDBlurData", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_displace.c b/source/blender/nodes/composite/nodes/node_composite_displace.c index 6eb93632e43..939d9feba5e 100644 --- a/source/blender/nodes/composite/nodes/node_composite_displace.c +++ b/source/blender/nodes/composite/nodes/node_composite_displace.c @@ -21,30 +21,28 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" - /* **************** Displace ******************** */ static bNodeSocketTemplate cmp_node_displace_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_VECTOR, 1, N_("Vector"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_TRANSLATION}, - { SOCK_FLOAT, 1, N_("X Scale"), 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("Y Scale"), 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f, PROP_NONE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_VECTOR, 1, N_("Vector"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_TRANSLATION}, + {SOCK_FLOAT, 1, N_("X Scale"), 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("Y Scale"), 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_displace_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; void register_node_type_cmp_displace(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_DISPLACE, "Displace", NODE_CLASS_DISTORT, 0); - node_type_socket_templates(&ntype, cmp_node_displace_in, cmp_node_displace_out); + cmp_node_type_base(&ntype, CMP_NODE_DISPLACE, "Displace", NODE_CLASS_DISTORT, 0); + node_type_socket_templates(&ntype, cmp_node_displace_in, cmp_node_displace_out); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_distanceMatte.c b/source/blender/nodes/composite/nodes/node_composite_distanceMatte.c index 8c149076fa8..a14ec9ccf35 100644 --- a/source/blender/nodes/composite/nodes/node_composite_distanceMatte.c +++ b/source/blender/nodes/composite/nodes/node_composite_distanceMatte.c @@ -21,39 +21,38 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" /* ******************* channel Distance Matte ********************************* */ static bNodeSocketTemplate cmp_node_distance_matte_in[] = { - {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - {SOCK_RGBA, 1, N_("Key Color"), 1.0f, 1.0f, 1.0f, 1.0f}, - {-1, 0, ""}, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_RGBA, 1, N_("Key Color"), 1.0f, 1.0f, 1.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_distance_matte_out[] = { - {SOCK_RGBA, 0, N_("Image")}, - {SOCK_FLOAT, 0, N_("Matte")}, - {-1, 0, ""}, + {SOCK_RGBA, 0, N_("Image")}, + {SOCK_FLOAT, 0, N_("Matte")}, + {-1, 0, ""}, }; static void node_composit_init_distance_matte(bNodeTree *UNUSED(ntree), bNode *node) { - NodeChroma *c = MEM_callocN(sizeof(NodeChroma), "node chroma"); - node->storage = c; - c->channel = 1; - c->t1 = 0.1f; - c->t2 = 0.1f; + NodeChroma *c = MEM_callocN(sizeof(NodeChroma), "node chroma"); + node->storage = c; + c->channel = 1; + c->t1 = 0.1f; + c->t2 = 0.1f; } void register_node_type_cmp_distance_matte(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_DIST_MATTE, "Distance Key", NODE_CLASS_MATTE, NODE_PREVIEW); - node_type_socket_templates(&ntype, cmp_node_distance_matte_in, cmp_node_distance_matte_out); - node_type_init(&ntype, node_composit_init_distance_matte); - node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_DIST_MATTE, "Distance Key", NODE_CLASS_MATTE, NODE_PREVIEW); + node_type_socket_templates(&ntype, cmp_node_distance_matte_in, cmp_node_distance_matte_out); + node_type_init(&ntype, node_composit_init_distance_matte); + node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_doubleEdgeMask.c b/source/blender/nodes/composite/nodes/node_composite_doubleEdgeMask.c index 04effdc152e..e4a82a35890 100644 --- a/source/blender/nodes/composite/nodes/node_composite_doubleEdgeMask.c +++ b/source/blender/nodes/composite/nodes/node_composite_doubleEdgeMask.c @@ -23,24 +23,41 @@ #include "node_composite_util.h" /* **************** Double Edge Mask ******************** */ - static bNodeSocketTemplate cmp_node_doubleedgemask_in[] = { - { SOCK_FLOAT, 1, "Inner Mask", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f, PROP_NONE}, // inner mask socket definition - { SOCK_FLOAT, 1, "Outer Mask", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f, PROP_NONE}, // outer mask socket definition - { -1, 0, "" }, // input socket array terminator + {SOCK_FLOAT, + 1, + "Inner Mask", + 0.8f, + 0.8f, + 0.8f, + 1.0f, + 0.0f, + 1.0f, + PROP_NONE}, // inner mask socket definition + {SOCK_FLOAT, + 1, + "Outer Mask", + 0.8f, + 0.8f, + 0.8f, + 1.0f, + 0.0f, + 1.0f, + PROP_NONE}, // outer mask socket definition + {-1, 0, ""}, // input socket array terminator }; static bNodeSocketTemplate cmp_node_doubleedgemask_out[] = { - { SOCK_FLOAT, 0, "Mask"}, // output socket definition - { -1, 0, "" }, // output socket array terminator + {SOCK_FLOAT, 0, "Mask"}, // output socket definition + {-1, 0, ""}, // output socket array terminator }; void register_node_type_cmp_doubleedgemask(void) { - static bNodeType ntype; // allocate a node type data structure + static bNodeType ntype; // allocate a node type data structure - cmp_node_type_base(&ntype, CMP_NODE_DOUBLEEDGEMASK, "Double Edge Mask", NODE_CLASS_MATTE, 0); - node_type_socket_templates(&ntype, cmp_node_doubleedgemask_in, cmp_node_doubleedgemask_out); - node_type_socket_templates(&ntype, cmp_node_doubleedgemask_in, cmp_node_doubleedgemask_out); + cmp_node_type_base(&ntype, CMP_NODE_DOUBLEEDGEMASK, "Double Edge Mask", NODE_CLASS_MATTE, 0); + node_type_socket_templates(&ntype, cmp_node_doubleedgemask_in, cmp_node_doubleedgemask_out); + node_type_socket_templates(&ntype, cmp_node_doubleedgemask_in, cmp_node_doubleedgemask_out); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_ellipsemask.c b/source/blender/nodes/composite/nodes/node_composite_ellipsemask.c index ccebe3a1e1e..69795cdee77 100644 --- a/source/blender/nodes/composite/nodes/node_composite_ellipsemask.c +++ b/source/blender/nodes/composite/nodes/node_composite_ellipsemask.c @@ -21,41 +21,38 @@ * \ingroup cmpnodes */ - #include "../node_composite_util.h" /* **************** SCALAR MATH ******************** */ static bNodeSocketTemplate cmp_node_ellipsemask_in[] = { - { SOCK_FLOAT, 1, N_("Mask"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Value"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; + {SOCK_FLOAT, 1, N_("Mask"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Value"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + {-1, 0, ""}}; static bNodeSocketTemplate cmp_node_ellipsemask_out[] = { - { SOCK_FLOAT, 0, N_("Mask"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; + {SOCK_FLOAT, 0, N_("Mask"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, {-1, 0, ""}}; static void node_composit_init_ellipsemask(bNodeTree *UNUSED(ntree), bNode *node) { - NodeEllipseMask *data = MEM_callocN(sizeof(NodeEllipseMask), "NodeEllipseMask"); - data->x = 0.5; - data->y = 0.5; - data->width = 0.2; - data->height = 0.1; - data->rotation = 0.0; - node->storage = data; + NodeEllipseMask *data = MEM_callocN(sizeof(NodeEllipseMask), "NodeEllipseMask"); + data->x = 0.5; + data->y = 0.5; + data->width = 0.2; + data->height = 0.1; + data->rotation = 0.0; + node->storage = data; } void register_node_type_cmp_ellipsemask(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_MASK_ELLIPSE, "Ellipse Mask", NODE_CLASS_MATTE, 0); - node_type_socket_templates(&ntype, cmp_node_ellipsemask_in, cmp_node_ellipsemask_out); - node_type_size(&ntype, 260, 110, 320); - node_type_init(&ntype, node_composit_init_ellipsemask); - node_type_storage(&ntype, "NodeEllipseMask", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_MASK_ELLIPSE, "Ellipse Mask", NODE_CLASS_MATTE, 0); + node_type_socket_templates(&ntype, cmp_node_ellipsemask_in, cmp_node_ellipsemask_out); + node_type_size(&ntype, 260, 110, 320); + node_type_init(&ntype, node_composit_init_ellipsemask); + node_type_storage( + &ntype, "NodeEllipseMask", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_filter.c b/source/blender/nodes/composite/nodes/node_composite_filter.c index a685116839d..0362fd51d78 100644 --- a/source/blender/nodes/composite/nodes/node_composite_filter.c +++ b/source/blender/nodes/composite/nodes/node_composite_filter.c @@ -21,27 +21,26 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" /* **************** FILTER ******************** */ static bNodeSocketTemplate cmp_node_filter_in[] = { - { SOCK_FLOAT, 1, N_("Fac"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Fac"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_filter_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; void register_node_type_cmp_filter(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_FILTER, "Filter", NODE_CLASS_OP_FILTER, NODE_PREVIEW); - node_type_socket_templates(&ntype, cmp_node_filter_in, cmp_node_filter_out); - node_type_label(&ntype, node_filter_label); + cmp_node_type_base(&ntype, CMP_NODE_FILTER, "Filter", NODE_CLASS_OP_FILTER, NODE_PREVIEW); + node_type_socket_templates(&ntype, cmp_node_filter_in, cmp_node_filter_out); + node_type_label(&ntype, node_filter_label); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_flip.c b/source/blender/nodes/composite/nodes/node_composite_flip.c index 06485ae58ee..668922426f6 100644 --- a/source/blender/nodes/composite/nodes/node_composite_flip.c +++ b/source/blender/nodes/composite/nodes/node_composite_flip.c @@ -21,26 +21,25 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" /* **************** Flip ******************** */ static bNodeSocketTemplate cmp_node_flip_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_flip_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; void register_node_type_cmp_flip(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_FLIP, "Flip", NODE_CLASS_DISTORT, 0); - node_type_socket_templates(&ntype, cmp_node_flip_in, cmp_node_flip_out); + cmp_node_type_base(&ntype, CMP_NODE_FLIP, "Flip", NODE_CLASS_DISTORT, 0); + node_type_socket_templates(&ntype, cmp_node_flip_in, cmp_node_flip_out); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_gamma.c b/source/blender/nodes/composite/nodes/node_composite_gamma.c index a912387660a..bf624d423d8 100644 --- a/source/blender/nodes/composite/nodes/node_composite_gamma.c +++ b/source/blender/nodes/composite/nodes/node_composite_gamma.c @@ -21,27 +21,26 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" /* **************** Gamma Tools ******************** */ static bNodeSocketTemplate cmp_node_gamma_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Gamma"), 1.0f, 0.0f, 0.0f, 0.0f, 0.001f, 10.0f, PROP_UNSIGNED}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Gamma"), 1.0f, 0.0f, 0.0f, 0.0f, 0.001f, 10.0f, PROP_UNSIGNED}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_gamma_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; void register_node_type_cmp_gamma(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_GAMMA, "Gamma", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, cmp_node_gamma_in, cmp_node_gamma_out); + cmp_node_type_base(&ntype, CMP_NODE_GAMMA, "Gamma", NODE_CLASS_OP_COLOR, 0); + node_type_socket_templates(&ntype, cmp_node_gamma_in, cmp_node_gamma_out); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_glare.c b/source/blender/nodes/composite/nodes/node_composite_glare.c index f28c80c9367..42b3d5e08de 100644 --- a/source/blender/nodes/composite/nodes/node_composite_glare.c +++ b/source/blender/nodes/composite/nodes/node_composite_glare.c @@ -21,43 +21,42 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" static bNodeSocketTemplate cmp_node_glare_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_glare_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; static void node_composit_init_glare(bNodeTree *UNUSED(ntree), bNode *node) { - NodeGlare *ndg = MEM_callocN(sizeof(NodeGlare), "node glare data"); - ndg->quality = 1; - ndg->type = 2; - ndg->iter = 3; - ndg->colmod = 0.25; - ndg->mix = 0; - ndg->threshold = 1; - ndg->star_45 = true; - ndg->streaks = 4; - ndg->angle_ofs = 0.0f; - ndg->fade = 0.9; - ndg->size = 8; - node->storage = ndg; + NodeGlare *ndg = MEM_callocN(sizeof(NodeGlare), "node glare data"); + ndg->quality = 1; + ndg->type = 2; + ndg->iter = 3; + ndg->colmod = 0.25; + ndg->mix = 0; + ndg->threshold = 1; + ndg->star_45 = true; + ndg->streaks = 4; + ndg->angle_ofs = 0.0f; + ndg->fade = 0.9; + ndg->size = 8; + node->storage = ndg; } void register_node_type_cmp_glare(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_GLARE, "Glare", NODE_CLASS_OP_FILTER, 0); - node_type_socket_templates(&ntype, cmp_node_glare_in, cmp_node_glare_out); - node_type_init(&ntype, node_composit_init_glare); - node_type_storage(&ntype, "NodeGlare", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_GLARE, "Glare", NODE_CLASS_OP_FILTER, 0); + node_type_socket_templates(&ntype, cmp_node_glare_in, cmp_node_glare_out); + node_type_init(&ntype, node_composit_init_glare); + node_type_storage(&ntype, "NodeGlare", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_hueSatVal.c b/source/blender/nodes/composite/nodes/node_composite_hueSatVal.c index f02dba62114..647b6d3feb5 100644 --- a/source/blender/nodes/composite/nodes/node_composite_hueSatVal.c +++ b/source/blender/nodes/composite/nodes/node_composite_hueSatVal.c @@ -21,30 +21,28 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" - /* **************** Hue Saturation ******************** */ static bNodeSocketTemplate cmp_node_hue_sat_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Hue"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("Saturation"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("Value"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Hue"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Saturation"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Value"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_hue_sat_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; void register_node_type_cmp_hue_sat(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_HUE_SAT, "Hue Saturation Value", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, cmp_node_hue_sat_in, cmp_node_hue_sat_out); + cmp_node_type_base(&ntype, CMP_NODE_HUE_SAT, "Hue Saturation Value", NODE_CLASS_OP_COLOR, 0); + node_type_socket_templates(&ntype, cmp_node_hue_sat_in, cmp_node_hue_sat_out); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_huecorrect.c b/source/blender/nodes/composite/nodes/node_composite_huecorrect.c index 6b16f8df8bd..7fcaae0bd9c 100644 --- a/source/blender/nodes/composite/nodes/node_composite_huecorrect.c +++ b/source/blender/nodes/composite/nodes/node_composite_huecorrect.c @@ -21,45 +21,44 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" static bNodeSocketTemplate cmp_node_huecorrect_in[] = { - { SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_huecorrect_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; static void node_composit_init_huecorrect(bNodeTree *UNUSED(ntree), bNode *node) { - CurveMapping *cumapping = node->storage = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); - int c; + CurveMapping *cumapping = node->storage = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + int c; - cumapping->preset = CURVE_PRESET_MID9; + cumapping->preset = CURVE_PRESET_MID9; - for (c = 0; c < 3; c++) { - CurveMap *cuma = &cumapping->cm[c]; - curvemap_reset(cuma, &cumapping->clipr, cumapping->preset, CURVEMAP_SLOPE_POSITIVE); - } + for (c = 0; c < 3; c++) { + CurveMap *cuma = &cumapping->cm[c]; + curvemap_reset(cuma, &cumapping->clipr, cumapping->preset, CURVEMAP_SLOPE_POSITIVE); + } - /* default to showing Saturation */ - cumapping->cur = 1; + /* default to showing Saturation */ + cumapping->cur = 1; } void register_node_type_cmp_huecorrect(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_HUECORRECT, "Hue Correct", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, cmp_node_huecorrect_in, cmp_node_huecorrect_out); - node_type_size(&ntype, 320, 140, 500); - node_type_init(&ntype, node_composit_init_huecorrect); - node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); + cmp_node_type_base(&ntype, CMP_NODE_HUECORRECT, "Hue Correct", NODE_CLASS_OP_COLOR, 0); + node_type_socket_templates(&ntype, cmp_node_huecorrect_in, cmp_node_huecorrect_out); + node_type_size(&ntype, 320, 140, 500); + node_type_init(&ntype, node_composit_init_huecorrect); + node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_idMask.c b/source/blender/nodes/composite/nodes/node_composite_idMask.c index 6db70413539..d15b587a2cb 100644 --- a/source/blender/nodes/composite/nodes/node_composite_idMask.c +++ b/source/blender/nodes/composite/nodes/node_composite_idMask.c @@ -21,27 +21,25 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" - /* **************** ID Mask ******************** */ static bNodeSocketTemplate cmp_node_idmask_in[] = { - { SOCK_FLOAT, 1, N_("ID value"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("ID value"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_idmask_out[] = { - { SOCK_FLOAT, 0, N_("Alpha")}, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("Alpha")}, + {-1, 0, ""}, }; void register_node_type_cmp_idmask(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_ID_MASK, "ID Mask", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, cmp_node_idmask_in, cmp_node_idmask_out); + cmp_node_type_base(&ntype, CMP_NODE_ID_MASK, "ID Mask", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, cmp_node_idmask_in, cmp_node_idmask_out); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_image.c b/source/blender/nodes/composite/nodes/node_composite_image.c index 37652daa312..d4278b3b540 100644 --- a/source/blender/nodes/composite/nodes/node_composite_image.c +++ b/source/blender/nodes/composite/nodes/node_composite_image.c @@ -38,429 +38,540 @@ /* **************** IMAGE (and RenderResult, multilayer image) ******************** */ static bNodeSocketTemplate cmp_node_rlayers_out[] = { - { SOCK_RGBA, 0, N_("Image"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Alpha"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_(RE_PASSNAME_Z), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 0, N_(RE_PASSNAME_NORMAL), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 0, N_(RE_PASSNAME_UV), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 0, N_(RE_PASSNAME_VECTOR), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, N_(RE_PASSNAME_DEPRECATED), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, N_(RE_PASSNAME_DEPRECATED), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, N_(RE_PASSNAME_DEPRECATED), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, N_(RE_PASSNAME_SHADOW), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, N_(RE_PASSNAME_AO), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, N_(RE_PASSNAME_DEPRECATED), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, N_(RE_PASSNAME_DEPRECATED), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, N_(RE_PASSNAME_DEPRECATED), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_(RE_PASSNAME_INDEXOB), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_(RE_PASSNAME_INDEXMA), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_(RE_PASSNAME_MIST), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, N_(RE_PASSNAME_EMIT), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, N_(RE_PASSNAME_ENVIRONMENT), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, N_(RE_PASSNAME_DIFFUSE_DIRECT), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, N_(RE_PASSNAME_DIFFUSE_INDIRECT), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, N_(RE_PASSNAME_DIFFUSE_COLOR), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, N_(RE_PASSNAME_GLOSSY_DIRECT), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, N_(RE_PASSNAME_GLOSSY_INDIRECT), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, N_(RE_PASSNAME_GLOSSY_COLOR), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, N_(RE_PASSNAME_TRANSM_DIRECT), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, N_(RE_PASSNAME_TRANSM_INDIRECT), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, N_(RE_PASSNAME_TRANSM_COLOR), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, N_(RE_PASSNAME_SUBSURFACE_DIRECT), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, N_(RE_PASSNAME_SUBSURFACE_INDIRECT), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 0, N_(RE_PASSNAME_SUBSURFACE_COLOR), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Alpha"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_(RE_PASSNAME_Z), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_VECTOR, 0, N_(RE_PASSNAME_NORMAL), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_VECTOR, 0, N_(RE_PASSNAME_UV), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_VECTOR, 0, N_(RE_PASSNAME_VECTOR), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 0, N_(RE_PASSNAME_DEPRECATED), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 0, N_(RE_PASSNAME_DEPRECATED), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 0, N_(RE_PASSNAME_DEPRECATED), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 0, N_(RE_PASSNAME_SHADOW), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 0, N_(RE_PASSNAME_AO), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 0, N_(RE_PASSNAME_DEPRECATED), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 0, N_(RE_PASSNAME_DEPRECATED), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 0, N_(RE_PASSNAME_DEPRECATED), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_(RE_PASSNAME_INDEXOB), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_(RE_PASSNAME_INDEXMA), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_(RE_PASSNAME_MIST), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 0, N_(RE_PASSNAME_EMIT), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 0, N_(RE_PASSNAME_ENVIRONMENT), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 0, N_(RE_PASSNAME_DIFFUSE_DIRECT), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 0, N_(RE_PASSNAME_DIFFUSE_INDIRECT), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 0, N_(RE_PASSNAME_DIFFUSE_COLOR), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 0, N_(RE_PASSNAME_GLOSSY_DIRECT), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 0, N_(RE_PASSNAME_GLOSSY_INDIRECT), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 0, N_(RE_PASSNAME_GLOSSY_COLOR), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 0, N_(RE_PASSNAME_TRANSM_DIRECT), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 0, N_(RE_PASSNAME_TRANSM_INDIRECT), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 0, N_(RE_PASSNAME_TRANSM_COLOR), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 0, N_(RE_PASSNAME_SUBSURFACE_DIRECT), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 0, N_(RE_PASSNAME_SUBSURFACE_INDIRECT), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 0, N_(RE_PASSNAME_SUBSURFACE_COLOR), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; -static void cmp_node_image_add_pass_output(bNodeTree *ntree, bNode *node, - const char *name, const char *passname, - int rres_index, int type, int is_rlayers, - LinkNodePair *available_sockets, int *prev_index) +static void cmp_node_image_add_pass_output(bNodeTree *ntree, + bNode *node, + const char *name, + const char *passname, + int rres_index, + int type, + int is_rlayers, + LinkNodePair *available_sockets, + int *prev_index) { - bNodeSocket *sock; - int sock_index = BLI_findstringindex(&node->outputs, name, offsetof(bNodeSocket, name)); - - if (sock_index < 0) { - /* The first 31 sockets always are the legacy hardcoded sockets. - * Any dynamically allocated sockets follow afterwards, and are sorted in the order in which they were stored in the RenderResult. - * Therefore, we remember the index of the last matched socket. New sockets are placed behind the previously traversed one, but always after the first 31. */ - int after_index = *prev_index; - if (is_rlayers && after_index < 30) - after_index = 30; - - if (rres_index >= 0) { - sock = node_add_socket_from_template(ntree, node, &cmp_node_rlayers_out[rres_index], SOCK_OUT); - } - else { - sock = nodeAddStaticSocket(ntree, node, SOCK_OUT, type, PROP_NONE, name, name); - } - /* extra socket info */ - NodeImageLayer *sockdata = MEM_callocN(sizeof(NodeImageLayer), "node image layer"); - sock->storage = sockdata; - - BLI_strncpy(sockdata->pass_name, passname, sizeof(sockdata->pass_name)); - - sock_index = BLI_listbase_count(&node->outputs) - 1; - if (sock_index != after_index + 1) { - bNodeSocket *after_sock = BLI_findlink(&node->outputs, after_index); - BLI_remlink(&node->outputs, sock); - BLI_insertlinkafter(&node->outputs, after_sock, sock); - } - } - else { - sock = BLI_findlink(&node->outputs, sock_index); - NodeImageLayer *sockdata = sock->storage; - if (sockdata) { - BLI_strncpy(sockdata->pass_name, passname, sizeof(sockdata->pass_name)); - } - } - - BLI_linklist_append(available_sockets, sock); - *prev_index = sock_index; + bNodeSocket *sock; + int sock_index = BLI_findstringindex(&node->outputs, name, offsetof(bNodeSocket, name)); + + if (sock_index < 0) { + /* The first 31 sockets always are the legacy hardcoded sockets. + * Any dynamically allocated sockets follow afterwards, and are sorted in the order in which they were stored in the RenderResult. + * Therefore, we remember the index of the last matched socket. New sockets are placed behind the previously traversed one, but always after the first 31. */ + int after_index = *prev_index; + if (is_rlayers && after_index < 30) + after_index = 30; + + if (rres_index >= 0) { + sock = node_add_socket_from_template( + ntree, node, &cmp_node_rlayers_out[rres_index], SOCK_OUT); + } + else { + sock = nodeAddStaticSocket(ntree, node, SOCK_OUT, type, PROP_NONE, name, name); + } + /* extra socket info */ + NodeImageLayer *sockdata = MEM_callocN(sizeof(NodeImageLayer), "node image layer"); + sock->storage = sockdata; + + BLI_strncpy(sockdata->pass_name, passname, sizeof(sockdata->pass_name)); + + sock_index = BLI_listbase_count(&node->outputs) - 1; + if (sock_index != after_index + 1) { + bNodeSocket *after_sock = BLI_findlink(&node->outputs, after_index); + BLI_remlink(&node->outputs, sock); + BLI_insertlinkafter(&node->outputs, after_sock, sock); + } + } + else { + sock = BLI_findlink(&node->outputs, sock_index); + NodeImageLayer *sockdata = sock->storage; + if (sockdata) { + BLI_strncpy(sockdata->pass_name, passname, sizeof(sockdata->pass_name)); + } + } + + BLI_linklist_append(available_sockets, sock); + *prev_index = sock_index; } -static void cmp_node_image_create_outputs(bNodeTree *ntree, bNode *node, LinkNodePair *available_sockets) +static void cmp_node_image_create_outputs(bNodeTree *ntree, + bNode *node, + LinkNodePair *available_sockets) { - Image *ima = (Image *)node->id; - ImBuf *ibuf; - int prev_index = -1; - if (ima) { - ImageUser *iuser = node->storage; - ImageUser load_iuser = {NULL}; - int offset = BKE_image_sequence_guess_offset(ima); - - /* It is possible that image user in this node is not - * properly updated yet. In this case loading image will - * fail and sockets detection will go wrong. - * - * So we manually construct image user to be sure first - * image from sequence (that one which is set as filename - * for image datablock) is used for sockets detection - */ - load_iuser.ok = 1; - load_iuser.framenr = offset; - - /* make sure ima->type is correct */ - ibuf = BKE_image_acquire_ibuf(ima, &load_iuser, NULL); - - if (ima->rr) { - RenderLayer *rl = BLI_findlink(&ima->rr->layers, iuser->layer); - - if (rl) { - RenderPass *rpass; - for (rpass = rl->passes.first; rpass; rpass = rpass->next) { - int type; - if (rpass->channels == 1) - type = SOCK_FLOAT; - else - type = SOCK_RGBA; - - cmp_node_image_add_pass_output(ntree, node, rpass->name, rpass->name, -1, type, false, available_sockets, &prev_index); - /* Special handling for the Combined pass to ensure compatibility. */ - if (STREQ(rpass->name, RE_PASSNAME_COMBINED)) { - cmp_node_image_add_pass_output(ntree, node, "Alpha", rpass->name, -1, SOCK_FLOAT, false, available_sockets, &prev_index); - } - } - BKE_image_release_ibuf(ima, ibuf, NULL); - return; - } - } - } - - cmp_node_image_add_pass_output(ntree, node, "Image", RE_PASSNAME_COMBINED, -1, SOCK_RGBA, false, available_sockets, &prev_index); - cmp_node_image_add_pass_output(ntree, node, "Alpha", RE_PASSNAME_COMBINED, -1, SOCK_FLOAT, false, available_sockets, &prev_index); - - if (ima) { - if (!ima->rr) { - cmp_node_image_add_pass_output(ntree, node, RE_PASSNAME_Z, RE_PASSNAME_Z, -1, SOCK_FLOAT, false, available_sockets, &prev_index); - } - BKE_image_release_ibuf(ima, ibuf, NULL); - } + Image *ima = (Image *)node->id; + ImBuf *ibuf; + int prev_index = -1; + if (ima) { + ImageUser *iuser = node->storage; + ImageUser load_iuser = {NULL}; + int offset = BKE_image_sequence_guess_offset(ima); + + /* It is possible that image user in this node is not + * properly updated yet. In this case loading image will + * fail and sockets detection will go wrong. + * + * So we manually construct image user to be sure first + * image from sequence (that one which is set as filename + * for image datablock) is used for sockets detection + */ + load_iuser.ok = 1; + load_iuser.framenr = offset; + + /* make sure ima->type is correct */ + ibuf = BKE_image_acquire_ibuf(ima, &load_iuser, NULL); + + if (ima->rr) { + RenderLayer *rl = BLI_findlink(&ima->rr->layers, iuser->layer); + + if (rl) { + RenderPass *rpass; + for (rpass = rl->passes.first; rpass; rpass = rpass->next) { + int type; + if (rpass->channels == 1) + type = SOCK_FLOAT; + else + type = SOCK_RGBA; + + cmp_node_image_add_pass_output(ntree, + node, + rpass->name, + rpass->name, + -1, + type, + false, + available_sockets, + &prev_index); + /* Special handling for the Combined pass to ensure compatibility. */ + if (STREQ(rpass->name, RE_PASSNAME_COMBINED)) { + cmp_node_image_add_pass_output(ntree, + node, + "Alpha", + rpass->name, + -1, + SOCK_FLOAT, + false, + available_sockets, + &prev_index); + } + } + BKE_image_release_ibuf(ima, ibuf, NULL); + return; + } + } + } + + cmp_node_image_add_pass_output(ntree, + node, + "Image", + RE_PASSNAME_COMBINED, + -1, + SOCK_RGBA, + false, + available_sockets, + &prev_index); + cmp_node_image_add_pass_output(ntree, + node, + "Alpha", + RE_PASSNAME_COMBINED, + -1, + SOCK_FLOAT, + false, + available_sockets, + &prev_index); + + if (ima) { + if (!ima->rr) { + cmp_node_image_add_pass_output(ntree, + node, + RE_PASSNAME_Z, + RE_PASSNAME_Z, + -1, + SOCK_FLOAT, + false, + available_sockets, + &prev_index); + } + BKE_image_release_ibuf(ima, ibuf, NULL); + } } typedef struct RLayerUpdateData { - LinkNodePair *available_sockets; - int prev_index; + LinkNodePair *available_sockets; + int prev_index; } RLayerUpdateData; -void node_cmp_rlayers_register_pass(bNodeTree *ntree, bNode *node, Scene *scene, ViewLayer *view_layer, const char *name, int type) +void node_cmp_rlayers_register_pass( + bNodeTree *ntree, bNode *node, Scene *scene, ViewLayer *view_layer, const char *name, int type) { - RLayerUpdateData *data = node->storage; - - if (scene == NULL || view_layer == NULL || data == NULL || node->id != (ID *)scene) { - return; - } - - ViewLayer *node_view_layer = BLI_findlink(&scene->view_layers, node->custom1); - if (node_view_layer != view_layer) { - return; - } - - /* Special handling for the Combined pass to ensure compatibility. */ - if (STREQ(name, RE_PASSNAME_COMBINED)) { - cmp_node_image_add_pass_output(ntree, node, "Image", name, -1, type, true, data->available_sockets, &data->prev_index); - cmp_node_image_add_pass_output(ntree, node, "Alpha", name, -1, SOCK_FLOAT, true, data->available_sockets, &data->prev_index); - } - else { - cmp_node_image_add_pass_output(ntree, node, name, name, -1, type, true, data->available_sockets, &data->prev_index); - } + RLayerUpdateData *data = node->storage; + + if (scene == NULL || view_layer == NULL || data == NULL || node->id != (ID *)scene) { + return; + } + + ViewLayer *node_view_layer = BLI_findlink(&scene->view_layers, node->custom1); + if (node_view_layer != view_layer) { + return; + } + + /* Special handling for the Combined pass to ensure compatibility. */ + if (STREQ(name, RE_PASSNAME_COMBINED)) { + cmp_node_image_add_pass_output( + ntree, node, "Image", name, -1, type, true, data->available_sockets, &data->prev_index); + cmp_node_image_add_pass_output(ntree, + node, + "Alpha", + name, + -1, + SOCK_FLOAT, + true, + data->available_sockets, + &data->prev_index); + } + else { + cmp_node_image_add_pass_output( + ntree, node, name, name, -1, type, true, data->available_sockets, &data->prev_index); + } } -static void cmp_node_rlayer_create_outputs_cb(void *UNUSED(userdata), Scene *scene, ViewLayer *view_layer, - const char *name, int UNUSED(channels), const char *UNUSED(chanid), int type) +static void cmp_node_rlayer_create_outputs_cb(void *UNUSED(userdata), + Scene *scene, + ViewLayer *view_layer, + const char *name, + int UNUSED(channels), + const char *UNUSED(chanid), + int type) { - /* Register the pass in all scenes that have a render layer node for this layer. - * Since multiple scenes can be used in the compositor, the code must loop over all scenes - * and check whether their nodetree has a node that needs to be updated. */ - /* NOTE: using G_MAIN seems valid here, - * unless we want to register that for every other temp Main we could generate??? */ - ntreeCompositRegisterPass(scene->nodetree, scene, view_layer, name, type); - - for (Scene *sce = G_MAIN->scenes.first; sce; sce = sce->id.next) { - if (sce->nodetree && sce != scene) { - ntreeCompositRegisterPass(sce->nodetree, scene, view_layer, name, type); - } - } + /* Register the pass in all scenes that have a render layer node for this layer. + * Since multiple scenes can be used in the compositor, the code must loop over all scenes + * and check whether their nodetree has a node that needs to be updated. */ + /* NOTE: using G_MAIN seems valid here, + * unless we want to register that for every other temp Main we could generate??? */ + ntreeCompositRegisterPass(scene->nodetree, scene, view_layer, name, type); + + for (Scene *sce = G_MAIN->scenes.first; sce; sce = sce->id.next) { + if (sce->nodetree && sce != scene) { + ntreeCompositRegisterPass(sce->nodetree, scene, view_layer, name, type); + } + } } -static void cmp_node_rlayer_create_outputs(bNodeTree *ntree, bNode *node, LinkNodePair *available_sockets) +static void cmp_node_rlayer_create_outputs(bNodeTree *ntree, + bNode *node, + LinkNodePair *available_sockets) { - Scene *scene = (Scene *)node->id; - - if (scene) { - RenderEngineType *engine_type = RE_engines_find(scene->r.engine); - if (engine_type && engine_type->update_render_passes) { - ViewLayer *view_layer = BLI_findlink(&scene->view_layers, node->custom1); - if (view_layer) { - RLayerUpdateData *data = MEM_mallocN(sizeof(RLayerUpdateData), "render layer update data"); - data->available_sockets = available_sockets; - data->prev_index = -1; - node->storage = data; - - RenderEngine *engine = RE_engine_create(engine_type); - RE_engine_update_render_passes(engine, scene, view_layer, cmp_node_rlayer_create_outputs_cb, NULL); - RE_engine_free(engine); - - MEM_freeN(data); - node->storage = NULL; - - return; - } - } - } - - int prev_index = -1; - cmp_node_image_add_pass_output(ntree, node, "Image", RE_PASSNAME_COMBINED, RRES_OUT_IMAGE, SOCK_RGBA, true, available_sockets, &prev_index); - cmp_node_image_add_pass_output(ntree, node, "Alpha", RE_PASSNAME_COMBINED, RRES_OUT_ALPHA, SOCK_FLOAT, true, available_sockets, &prev_index); + Scene *scene = (Scene *)node->id; + + if (scene) { + RenderEngineType *engine_type = RE_engines_find(scene->r.engine); + if (engine_type && engine_type->update_render_passes) { + ViewLayer *view_layer = BLI_findlink(&scene->view_layers, node->custom1); + if (view_layer) { + RLayerUpdateData *data = MEM_mallocN(sizeof(RLayerUpdateData), "render layer update data"); + data->available_sockets = available_sockets; + data->prev_index = -1; + node->storage = data; + + RenderEngine *engine = RE_engine_create(engine_type); + RE_engine_update_render_passes( + engine, scene, view_layer, cmp_node_rlayer_create_outputs_cb, NULL); + RE_engine_free(engine); + + MEM_freeN(data); + node->storage = NULL; + + return; + } + } + } + + int prev_index = -1; + cmp_node_image_add_pass_output(ntree, + node, + "Image", + RE_PASSNAME_COMBINED, + RRES_OUT_IMAGE, + SOCK_RGBA, + true, + available_sockets, + &prev_index); + cmp_node_image_add_pass_output(ntree, + node, + "Alpha", + RE_PASSNAME_COMBINED, + RRES_OUT_ALPHA, + SOCK_FLOAT, + true, + available_sockets, + &prev_index); } /* XXX make this into a generic socket verification function for dynamic socket replacement (multilayer, groups, static templates) */ static void cmp_node_image_verify_outputs(bNodeTree *ntree, bNode *node, bool rlayer) { - bNodeSocket *sock, *sock_next; - LinkNodePair available_sockets = {NULL, NULL}; - int sock_index; - - /* XXX make callback */ - if (rlayer) - cmp_node_rlayer_create_outputs(ntree, node, &available_sockets); - else - cmp_node_image_create_outputs(ntree, node, &available_sockets); - - /* Get rid of sockets whose passes are not available in the image. - * If sockets that are not available would be deleted, the connections to them would be lost - * when e.g. opening a file (since there's no render at all yet). - * Therefore, sockets with connected links will just be set as unavailable. - * - * Another important detail comes from compatibility with the older socket model, where there - * was a fixed socket per pass type that was just hidden or not. Therefore, older versions expect - * the first 31 passes to belong to a specific pass type. - * So, we keep those 31 always allocated before the others as well, even if they have no links attached. */ - sock_index = 0; - for (sock = node->outputs.first; sock; sock = sock_next, sock_index++) { - sock_next = sock->next; - if (BLI_linklist_index(available_sockets.list, sock) >= 0) { - sock->flag &= ~(SOCK_UNAVAIL | SOCK_HIDDEN); - } - else { - bNodeLink *link; - for (link = ntree->links.first; link; link = link->next) { - if (link->fromsock == sock) break; - } - if (!link && (!rlayer || sock_index > 30)) { - MEM_freeN(sock->storage); - nodeRemoveSocket(ntree, node, sock); - } - else { - sock->flag |= SOCK_UNAVAIL; - } - } - } - - BLI_linklist_free(available_sockets.list, NULL); + bNodeSocket *sock, *sock_next; + LinkNodePair available_sockets = {NULL, NULL}; + int sock_index; + + /* XXX make callback */ + if (rlayer) + cmp_node_rlayer_create_outputs(ntree, node, &available_sockets); + else + cmp_node_image_create_outputs(ntree, node, &available_sockets); + + /* Get rid of sockets whose passes are not available in the image. + * If sockets that are not available would be deleted, the connections to them would be lost + * when e.g. opening a file (since there's no render at all yet). + * Therefore, sockets with connected links will just be set as unavailable. + * + * Another important detail comes from compatibility with the older socket model, where there + * was a fixed socket per pass type that was just hidden or not. Therefore, older versions expect + * the first 31 passes to belong to a specific pass type. + * So, we keep those 31 always allocated before the others as well, even if they have no links attached. */ + sock_index = 0; + for (sock = node->outputs.first; sock; sock = sock_next, sock_index++) { + sock_next = sock->next; + if (BLI_linklist_index(available_sockets.list, sock) >= 0) { + sock->flag &= ~(SOCK_UNAVAIL | SOCK_HIDDEN); + } + else { + bNodeLink *link; + for (link = ntree->links.first; link; link = link->next) { + if (link->fromsock == sock) + break; + } + if (!link && (!rlayer || sock_index > 30)) { + MEM_freeN(sock->storage); + nodeRemoveSocket(ntree, node, sock); + } + else { + sock->flag |= SOCK_UNAVAIL; + } + } + } + + BLI_linklist_free(available_sockets.list, NULL); } static void cmp_node_image_update(bNodeTree *ntree, bNode *node) { - /* avoid unnecessary updates, only changes to the image/image user data are of interest */ - if (node->update & NODE_UPDATE_ID) - cmp_node_image_verify_outputs(ntree, node, false); + /* avoid unnecessary updates, only changes to the image/image user data are of interest */ + if (node->update & NODE_UPDATE_ID) + cmp_node_image_verify_outputs(ntree, node, false); - cmp_node_update_default(ntree, node); + cmp_node_update_default(ntree, node); } static void node_composit_init_image(bNodeTree *ntree, bNode *node) { - ImageUser *iuser = MEM_callocN(sizeof(ImageUser), "node image user"); - node->storage = iuser; - iuser->frames = 1; - iuser->sfra = 1; - iuser->ok = 1; - iuser->flag |= IMA_ANIM_ALWAYS; - - /* setup initial outputs */ - cmp_node_image_verify_outputs(ntree, node, false); + ImageUser *iuser = MEM_callocN(sizeof(ImageUser), "node image user"); + node->storage = iuser; + iuser->frames = 1; + iuser->sfra = 1; + iuser->ok = 1; + iuser->flag |= IMA_ANIM_ALWAYS; + + /* setup initial outputs */ + cmp_node_image_verify_outputs(ntree, node, false); } static void node_composit_free_image(bNode *node) { - bNodeSocket *sock; + bNodeSocket *sock; - /* free extra socket info */ - for (sock = node->outputs.first; sock; sock = sock->next) - MEM_freeN(sock->storage); + /* free extra socket info */ + for (sock = node->outputs.first; sock; sock = sock->next) + MEM_freeN(sock->storage); - MEM_freeN(node->storage); + MEM_freeN(node->storage); } -static void node_composit_copy_image(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, bNode *src_node) +static void node_composit_copy_image(bNodeTree *UNUSED(dest_ntree), + bNode *dest_node, + bNode *src_node) { - bNodeSocket *sock; + bNodeSocket *sock; - dest_node->storage = MEM_dupallocN(src_node->storage); + dest_node->storage = MEM_dupallocN(src_node->storage); - /* copy extra socket info */ - for (sock = src_node->outputs.first; sock; sock = sock->next) - sock->new_sock->storage = MEM_dupallocN(sock->storage); + /* copy extra socket info */ + for (sock = src_node->outputs.first; sock; sock = sock->next) + sock->new_sock->storage = MEM_dupallocN(sock->storage); } void register_node_type_cmp_image(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_IMAGE, "Image", NODE_CLASS_INPUT, NODE_PREVIEW); - node_type_init(&ntype, node_composit_init_image); - node_type_storage(&ntype, "ImageUser", node_composit_free_image, node_composit_copy_image); - node_type_update(&ntype, cmp_node_image_update, NULL); - node_type_label(&ntype, node_image_label); + cmp_node_type_base(&ntype, CMP_NODE_IMAGE, "Image", NODE_CLASS_INPUT, NODE_PREVIEW); + node_type_init(&ntype, node_composit_init_image); + node_type_storage(&ntype, "ImageUser", node_composit_free_image, node_composit_copy_image); + node_type_update(&ntype, cmp_node_image_update, NULL); + node_type_label(&ntype, node_image_label); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } - /* **************** RENDER RESULT ******************** */ void node_cmp_rlayers_outputs(bNodeTree *ntree, bNode *node) { - cmp_node_image_verify_outputs(ntree, node, true); + cmp_node_image_verify_outputs(ntree, node, true); } const char *node_cmp_rlayers_sock_to_pass(int sock_index) { - const char *sock_to_passname[] = { - RE_PASSNAME_COMBINED, RE_PASSNAME_COMBINED, - RE_PASSNAME_Z, RE_PASSNAME_NORMAL, RE_PASSNAME_UV, RE_PASSNAME_VECTOR, RE_PASSNAME_DEPRECATED, - RE_PASSNAME_DEPRECATED, RE_PASSNAME_DEPRECATED, RE_PASSNAME_SHADOW, RE_PASSNAME_AO, - RE_PASSNAME_DEPRECATED, RE_PASSNAME_DEPRECATED, RE_PASSNAME_DEPRECATED, - RE_PASSNAME_INDEXOB, RE_PASSNAME_INDEXMA, RE_PASSNAME_MIST, RE_PASSNAME_EMIT, RE_PASSNAME_ENVIRONMENT, - RE_PASSNAME_DIFFUSE_DIRECT, RE_PASSNAME_DIFFUSE_INDIRECT, RE_PASSNAME_DIFFUSE_COLOR, - RE_PASSNAME_GLOSSY_DIRECT, RE_PASSNAME_GLOSSY_INDIRECT, RE_PASSNAME_GLOSSY_COLOR, - RE_PASSNAME_TRANSM_DIRECT, RE_PASSNAME_TRANSM_INDIRECT, RE_PASSNAME_TRANSM_COLOR, - RE_PASSNAME_SUBSURFACE_DIRECT, RE_PASSNAME_SUBSURFACE_INDIRECT, RE_PASSNAME_SUBSURFACE_COLOR, - }; - if (sock_index > 30) { - return NULL; - } - return sock_to_passname[sock_index]; + const char *sock_to_passname[] = { + RE_PASSNAME_COMBINED, + RE_PASSNAME_COMBINED, + RE_PASSNAME_Z, + RE_PASSNAME_NORMAL, + RE_PASSNAME_UV, + RE_PASSNAME_VECTOR, + RE_PASSNAME_DEPRECATED, + RE_PASSNAME_DEPRECATED, + RE_PASSNAME_DEPRECATED, + RE_PASSNAME_SHADOW, + RE_PASSNAME_AO, + RE_PASSNAME_DEPRECATED, + RE_PASSNAME_DEPRECATED, + RE_PASSNAME_DEPRECATED, + RE_PASSNAME_INDEXOB, + RE_PASSNAME_INDEXMA, + RE_PASSNAME_MIST, + RE_PASSNAME_EMIT, + RE_PASSNAME_ENVIRONMENT, + RE_PASSNAME_DIFFUSE_DIRECT, + RE_PASSNAME_DIFFUSE_INDIRECT, + RE_PASSNAME_DIFFUSE_COLOR, + RE_PASSNAME_GLOSSY_DIRECT, + RE_PASSNAME_GLOSSY_INDIRECT, + RE_PASSNAME_GLOSSY_COLOR, + RE_PASSNAME_TRANSM_DIRECT, + RE_PASSNAME_TRANSM_INDIRECT, + RE_PASSNAME_TRANSM_COLOR, + RE_PASSNAME_SUBSURFACE_DIRECT, + RE_PASSNAME_SUBSURFACE_INDIRECT, + RE_PASSNAME_SUBSURFACE_COLOR, + }; + if (sock_index > 30) { + return NULL; + } + return sock_to_passname[sock_index]; } static void node_composit_init_rlayers(const bContext *C, PointerRNA *ptr) { - Scene *scene = CTX_data_scene(C); - bNode *node = ptr->data; - int sock_index = 0; + Scene *scene = CTX_data_scene(C); + bNode *node = ptr->data; + int sock_index = 0; - node->id = &scene->id; + node->id = &scene->id; - for (bNodeSocket *sock = node->outputs.first; sock; sock = sock->next, sock_index++) { - NodeImageLayer *sockdata = MEM_callocN(sizeof(NodeImageLayer), "node image layer"); - sock->storage = sockdata; + for (bNodeSocket *sock = node->outputs.first; sock; sock = sock->next, sock_index++) { + NodeImageLayer *sockdata = MEM_callocN(sizeof(NodeImageLayer), "node image layer"); + sock->storage = sockdata; - BLI_strncpy(sockdata->pass_name, node_cmp_rlayers_sock_to_pass(sock_index), sizeof(sockdata->pass_name)); - } + BLI_strncpy(sockdata->pass_name, + node_cmp_rlayers_sock_to_pass(sock_index), + sizeof(sockdata->pass_name)); + } } static bool node_composit_poll_rlayers(bNodeType *UNUSED(ntype), bNodeTree *ntree) { - if (STREQ(ntree->idname, "CompositorNodeTree")) { - Scene *scene; - - /* XXX ugly: check if ntree is a local scene node tree. - * Render layers node can only be used in local scene->nodetree, - * since it directly links to the scene. - */ - for (scene = G.main->scenes.first; scene; scene = scene->id.next) - if (scene->nodetree == ntree) - break; - - return (scene != NULL); - } - return false; + if (STREQ(ntree->idname, "CompositorNodeTree")) { + Scene *scene; + + /* XXX ugly: check if ntree is a local scene node tree. + * Render layers node can only be used in local scene->nodetree, + * since it directly links to the scene. + */ + for (scene = G.main->scenes.first; scene; scene = scene->id.next) + if (scene->nodetree == ntree) + break; + + return (scene != NULL); + } + return false; } static void node_composit_free_rlayers(bNode *node) { - bNodeSocket *sock; - - /* free extra socket info */ - for (sock = node->outputs.first; sock; sock = sock->next) { - if (sock->storage) { - MEM_freeN(sock->storage); - } - } + bNodeSocket *sock; + + /* free extra socket info */ + for (sock = node->outputs.first; sock; sock = sock->next) { + if (sock->storage) { + MEM_freeN(sock->storage); + } + } } -static void node_composit_copy_rlayers(bNodeTree *UNUSED(dest_ntree), bNode *UNUSED(dest_node), bNode *src_node) +static void node_composit_copy_rlayers(bNodeTree *UNUSED(dest_ntree), + bNode *UNUSED(dest_node), + bNode *src_node) { - bNodeSocket *sock; - - /* copy extra socket info */ - for (sock = src_node->outputs.first; sock; sock = sock->next) { - if (sock->storage) { - sock->new_sock->storage = MEM_dupallocN(sock->storage); - } - } + bNodeSocket *sock; + + /* copy extra socket info */ + for (sock = src_node->outputs.first; sock; sock = sock->next) { + if (sock->storage) { + sock->new_sock->storage = MEM_dupallocN(sock->storage); + } + } } static void cmp_node_rlayers_update(bNodeTree *ntree, bNode *node) { - cmp_node_image_verify_outputs(ntree, node, true); + cmp_node_image_verify_outputs(ntree, node, true); - cmp_node_update_default(ntree, node); + cmp_node_update_default(ntree, node); } void register_node_type_cmp_rlayers(void) { - static bNodeType ntype; - - cmp_node_type_base(&ntype, CMP_NODE_R_LAYERS, "Render Layers", NODE_CLASS_INPUT, NODE_PREVIEW); - node_type_socket_templates(&ntype, NULL, cmp_node_rlayers_out); - ntype.initfunc_api = node_composit_init_rlayers; - ntype.poll = node_composit_poll_rlayers; - node_type_storage(&ntype, NULL, node_composit_free_rlayers, node_composit_copy_rlayers); - node_type_update(&ntype, cmp_node_rlayers_update, NULL); - node_type_init(&ntype, node_cmp_rlayers_outputs); - node_type_size_preset(&ntype, NODE_SIZE_LARGE); - - nodeRegisterType(&ntype); + static bNodeType ntype; + + cmp_node_type_base(&ntype, CMP_NODE_R_LAYERS, "Render Layers", NODE_CLASS_INPUT, NODE_PREVIEW); + node_type_socket_templates(&ntype, NULL, cmp_node_rlayers_out); + ntype.initfunc_api = node_composit_init_rlayers; + ntype.poll = node_composit_poll_rlayers; + node_type_storage(&ntype, NULL, node_composit_free_rlayers, node_composit_copy_rlayers); + node_type_update(&ntype, cmp_node_rlayers_update, NULL); + node_type_init(&ntype, node_cmp_rlayers_outputs); + node_type_size_preset(&ntype, NODE_SIZE_LARGE); + + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_inpaint.c b/source/blender/nodes/composite/nodes/node_composite_inpaint.c index b5fb1b95e9f..036abd800f5 100644 --- a/source/blender/nodes/composite/nodes/node_composite_inpaint.c +++ b/source/blender/nodes/composite/nodes/node_composite_inpaint.c @@ -21,27 +21,20 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" - /* **************** Inpaint/ ******************** */ static bNodeSocketTemplate cmp_node_inpaint_in[] = { - {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketTemplate cmp_node_inpaint_out[] = { - {SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" } -}; + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, {-1, 0, ""}}; +static bNodeSocketTemplate cmp_node_inpaint_out[] = {{SOCK_RGBA, 0, N_("Image")}, {-1, 0, ""}}; void register_node_type_cmp_inpaint(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_INPAINT, "Inpaint", NODE_CLASS_OP_FILTER, 0); - node_type_socket_templates(&ntype, cmp_node_inpaint_in, cmp_node_inpaint_out); + cmp_node_type_base(&ntype, CMP_NODE_INPAINT, "Inpaint", NODE_CLASS_OP_FILTER, 0); + node_type_socket_templates(&ntype, cmp_node_inpaint_in, cmp_node_inpaint_out); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_invert.c b/source/blender/nodes/composite/nodes/node_composite_invert.c index 7f60180110a..e5ebe6e0423 100644 --- a/source/blender/nodes/composite/nodes/node_composite_invert.c +++ b/source/blender/nodes/composite/nodes/node_composite_invert.c @@ -25,29 +25,25 @@ /* **************** INVERT ******************** */ static bNodeSocketTemplate cmp_node_invert_in[] = { - { SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_RGBA, 1, N_("Color"), 1.0f, 1.0f, 1.0f, 1.0f}, - { -1, 0, "" } -}; + {SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_RGBA, 1, N_("Color"), 1.0f, 1.0f, 1.0f, 1.0f}, + {-1, 0, ""}}; -static bNodeSocketTemplate cmp_node_invert_out[] = { - { SOCK_RGBA, 0, N_("Color")}, - { -1, 0, "" } -}; +static bNodeSocketTemplate cmp_node_invert_out[] = {{SOCK_RGBA, 0, N_("Color")}, {-1, 0, ""}}; static void node_composit_init_invert(bNodeTree *UNUSED(ntree), bNode *node) { - node->custom1 |= CMP_CHAN_RGB; + node->custom1 |= CMP_CHAN_RGB; } /* custom1 = mix type */ void register_node_type_cmp_invert(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_INVERT, "Invert", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, cmp_node_invert_in, cmp_node_invert_out); - node_type_init(&ntype, node_composit_init_invert); + cmp_node_type_base(&ntype, CMP_NODE_INVERT, "Invert", NODE_CLASS_OP_COLOR, 0); + node_type_socket_templates(&ntype, cmp_node_invert_in, cmp_node_invert_out); + node_type_init(&ntype, node_composit_init_invert); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_keying.c b/source/blender/nodes/composite/nodes/node_composite_keying.c index 39b04c24133..0b29244aa70 100644 --- a/source/blender/nodes/composite/nodes/node_composite_keying.c +++ b/source/blender/nodes/composite/nodes/node_composite_keying.c @@ -32,46 +32,47 @@ /* **************** Translate ******************** */ static bNodeSocketTemplate cmp_node_keying_in[] = { - { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 1, "Key Color", 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_FLOAT, 1, "Garbage Matte", 0.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_FLOAT, 1, "Core Matte", 0.0f, 1.0f, 1.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 1, "Key Color", 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_FLOAT, 1, "Garbage Matte", 0.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_FLOAT, 1, "Core Matte", 0.0f, 1.0f, 1.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_keying_out[] = { - { SOCK_RGBA, 0, "Image"}, - { SOCK_FLOAT, 0, "Matte"}, - { SOCK_FLOAT, 0, "Edges"}, - { -1, 0, "" }, + {SOCK_RGBA, 0, "Image"}, + {SOCK_FLOAT, 0, "Matte"}, + {SOCK_FLOAT, 0, "Edges"}, + {-1, 0, ""}, }; static void node_composit_init_keying(bNodeTree *UNUSED(ntree), bNode *node) { - NodeKeyingData *data; + NodeKeyingData *data; - data = MEM_callocN(sizeof(NodeKeyingData), "node keying data"); + data = MEM_callocN(sizeof(NodeKeyingData), "node keying data"); - data->screen_balance = 0.5f; - data->despill_balance = 0.5f; - data->despill_factor = 1.0f; - data->edge_kernel_radius = 3; - data->edge_kernel_tolerance = 0.1f; - data->clip_white = 1.0f; - data->clip_black = 0.0f; - data->clip_white = 1.0f; + data->screen_balance = 0.5f; + data->despill_balance = 0.5f; + data->despill_factor = 1.0f; + data->edge_kernel_radius = 3; + data->edge_kernel_tolerance = 0.1f; + data->clip_white = 1.0f; + data->clip_black = 0.0f; + data->clip_white = 1.0f; - node->storage = data; + node->storage = data; } void register_node_type_cmp_keying(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_KEYING, "Keying", NODE_CLASS_MATTE, 0); - node_type_socket_templates(&ntype, cmp_node_keying_in, cmp_node_keying_out); - node_type_init(&ntype, node_composit_init_keying); - node_type_storage(&ntype, "NodeKeyingData", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_KEYING, "Keying", NODE_CLASS_MATTE, 0); + node_type_socket_templates(&ntype, cmp_node_keying_in, cmp_node_keying_out); + node_type_init(&ntype, node_composit_init_keying); + node_type_storage( + &ntype, "NodeKeyingData", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_keyingscreen.c b/source/blender/nodes/composite/nodes/node_composite_keyingscreen.c index 8f1bfbfb002..a481c111396 100644 --- a/source/blender/nodes/composite/nodes/node_composite_keyingscreen.c +++ b/source/blender/nodes/composite/nodes/node_composite_keyingscreen.c @@ -31,27 +31,28 @@ /* **************** Translate ******************** */ static bNodeSocketTemplate cmp_node_keyingscreen_out[] = { - { SOCK_RGBA, 0, "Screen"}, - { -1, 0, "" }, + {SOCK_RGBA, 0, "Screen"}, + {-1, 0, ""}, }; static void node_composit_init_keyingscreen(bNodeTree *UNUSED(ntree), bNode *node) { - NodeKeyingScreenData *data; + NodeKeyingScreenData *data; - data = MEM_callocN(sizeof(NodeKeyingScreenData), "node keyingscreen data"); + data = MEM_callocN(sizeof(NodeKeyingScreenData), "node keyingscreen data"); - node->storage = data; + node->storage = data; } void register_node_type_cmp_keyingscreen(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_KEYINGSCREEN, "Keying Screen", NODE_CLASS_MATTE, 0); - node_type_socket_templates(&ntype, NULL, cmp_node_keyingscreen_out); - node_type_init(&ntype, node_composit_init_keyingscreen); - node_type_storage(&ntype, "NodeKeyingScreenData", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_KEYINGSCREEN, "Keying Screen", NODE_CLASS_MATTE, 0); + node_type_socket_templates(&ntype, NULL, cmp_node_keyingscreen_out); + node_type_init(&ntype, node_composit_init_keyingscreen); + node_type_storage( + &ntype, "NodeKeyingScreenData", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_lensdist.c b/source/blender/nodes/composite/nodes/node_composite_lensdist.c index 3e4364f691f..5c5668cd034 100644 --- a/source/blender/nodes/composite/nodes/node_composite_lensdist.c +++ b/source/blender/nodes/composite/nodes/node_composite_lensdist.c @@ -21,36 +21,35 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" static bNodeSocketTemplate cmp_node_lensdist_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Distort"), 0.f, 0.f, 0.f, 0.f, -0.999f, 1.f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("Dispersion"), 0.f, 0.f, 0.f, 0.f, 0.f, 1.f, PROP_NONE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Distort"), 0.f, 0.f, 0.f, 0.f, -0.999f, 1.f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("Dispersion"), 0.f, 0.f, 0.f, 0.f, 0.f, 1.f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_lensdist_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; static void node_composit_init_lensdist(bNodeTree *UNUSED(ntree), bNode *node) { - NodeLensDist *nld = MEM_callocN(sizeof(NodeLensDist), "node lensdist data"); - nld->jit = nld->proj = nld->fit = 0; - node->storage = nld; + NodeLensDist *nld = MEM_callocN(sizeof(NodeLensDist), "node lensdist data"); + nld->jit = nld->proj = nld->fit = 0; + node->storage = nld; } - void register_node_type_cmp_lensdist(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_LENSDIST, "Lens Distortion", NODE_CLASS_DISTORT, 0); - node_type_socket_templates(&ntype, cmp_node_lensdist_in, cmp_node_lensdist_out); - node_type_init(&ntype, node_composit_init_lensdist); - node_type_storage(&ntype, "NodeLensDist", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_LENSDIST, "Lens Distortion", NODE_CLASS_DISTORT, 0); + node_type_socket_templates(&ntype, cmp_node_lensdist_in, cmp_node_lensdist_out); + node_type_init(&ntype, node_composit_init_lensdist); + node_type_storage( + &ntype, "NodeLensDist", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_levels.c b/source/blender/nodes/composite/nodes/node_composite_levels.c index 296194f5102..3accfeb1617 100644 --- a/source/blender/nodes/composite/nodes/node_composite_levels.c +++ b/source/blender/nodes/composite/nodes/node_composite_levels.c @@ -21,34 +21,32 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" - /* **************** LEVELS ******************** */ static bNodeSocketTemplate cmp_node_view_levels_in[] = { - { SOCK_RGBA, 1, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_view_levels_out[] = { - {SOCK_FLOAT, 0, N_("Mean")}, - {SOCK_FLOAT, 0, N_("Std Dev")}, - {-1, 0, ""}, + {SOCK_FLOAT, 0, N_("Mean")}, + {SOCK_FLOAT, 0, N_("Std Dev")}, + {-1, 0, ""}, }; static void node_composit_init_view_levels(bNodeTree *UNUSED(ntree), bNode *node) { - node->custom1 = 1; /*All channels*/ + node->custom1 = 1; /*All channels*/ } void register_node_type_cmp_view_levels(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_VIEW_LEVELS, "Levels", NODE_CLASS_OUTPUT, NODE_PREVIEW); - node_type_socket_templates(&ntype, cmp_node_view_levels_in, cmp_node_view_levels_out); - node_type_init(&ntype, node_composit_init_view_levels); + cmp_node_type_base(&ntype, CMP_NODE_VIEW_LEVELS, "Levels", NODE_CLASS_OUTPUT, NODE_PREVIEW); + node_type_socket_templates(&ntype, cmp_node_view_levels_in, cmp_node_view_levels_out); + node_type_init(&ntype, node_composit_init_view_levels); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_lummaMatte.c b/source/blender/nodes/composite/nodes/node_composite_lummaMatte.c index db01397369c..66c7a5403ad 100644 --- a/source/blender/nodes/composite/nodes/node_composite_lummaMatte.c +++ b/source/blender/nodes/composite/nodes/node_composite_lummaMatte.c @@ -21,38 +21,36 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" - /* ******************* Luma Matte Node ********************************* */ static bNodeSocketTemplate cmp_node_luma_matte_in[] = { - {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - {-1, 0, ""}, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_luma_matte_out[] = { - {SOCK_RGBA, 0, N_("Image")}, - {SOCK_FLOAT, 0, N_("Matte")}, - {-1, 0, ""}, + {SOCK_RGBA, 0, N_("Image")}, + {SOCK_FLOAT, 0, N_("Matte")}, + {-1, 0, ""}, }; static void node_composit_init_luma_matte(bNodeTree *UNUSED(ntree), bNode *node) { - NodeChroma *c = MEM_callocN(sizeof(NodeChroma), "node chroma"); - node->storage = c; - c->t1 = 1.0f; - c->t2 = 0.0f; + NodeChroma *c = MEM_callocN(sizeof(NodeChroma), "node chroma"); + node->storage = c; + c->t1 = 1.0f; + c->t2 = 0.0f; } void register_node_type_cmp_luma_matte(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_LUMA_MATTE, "Luminance Key", NODE_CLASS_MATTE, NODE_PREVIEW); - node_type_socket_templates(&ntype, cmp_node_luma_matte_in, cmp_node_luma_matte_out); - node_type_init(&ntype, node_composit_init_luma_matte); - node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_LUMA_MATTE, "Luminance Key", NODE_CLASS_MATTE, NODE_PREVIEW); + node_type_socket_templates(&ntype, cmp_node_luma_matte_in, cmp_node_luma_matte_out); + node_type_init(&ntype, node_composit_init_luma_matte); + node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_mapRange.c b/source/blender/nodes/composite/nodes/node_composite_mapRange.c index a7df95a5713..4f70d9c5f5d 100644 --- a/source/blender/nodes/composite/nodes/node_composite_mapRange.c +++ b/source/blender/nodes/composite/nodes/node_composite_mapRange.c @@ -21,29 +21,28 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" /* **************** MAP VALUE ******************** */ static bNodeSocketTemplate cmp_node_map_range_in[] = { - { SOCK_FLOAT, 1, N_("Value"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("From Min"), 0.0f, 1.0f, 1.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("From Max"), 1.0f, 1.0f, 1.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("To Min"), 0.0f, 1.0f, 1.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("To Max"), 1.0f, 1.0f, 1.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Value"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("From Min"), 0.0f, 1.0f, 1.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("From Max"), 1.0f, 1.0f, 1.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("To Min"), 0.0f, 1.0f, 1.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("To Max"), 1.0f, 1.0f, 1.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_map_range_out[] = { - { SOCK_FLOAT, 0, N_("Value")}, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("Value")}, + {-1, 0, ""}, }; void register_node_type_cmp_map_range(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_MAP_RANGE, "Map Range", NODE_CLASS_OP_VECTOR, 0); - node_type_socket_templates(&ntype, cmp_node_map_range_in, cmp_node_map_range_out); + cmp_node_type_base(&ntype, CMP_NODE_MAP_RANGE, "Map Range", NODE_CLASS_OP_VECTOR, 0); + node_type_socket_templates(&ntype, cmp_node_map_range_in, cmp_node_map_range_out); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_mapUV.c b/source/blender/nodes/composite/nodes/node_composite_mapUV.c index aa3370d99fb..062d111dd70 100644 --- a/source/blender/nodes/composite/nodes/node_composite_mapUV.c +++ b/source/blender/nodes/composite/nodes/node_composite_mapUV.c @@ -21,27 +21,26 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" /* **************** Map UV ******************** */ static bNodeSocketTemplate cmp_node_mapuv_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_VECTOR, 1, N_("UV"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_VECTOR, 1, N_("UV"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_mapuv_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; void register_node_type_cmp_mapuv(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_MAP_UV, "Map UV", NODE_CLASS_DISTORT, 0); - node_type_socket_templates(&ntype, cmp_node_mapuv_in, cmp_node_mapuv_out); + cmp_node_type_base(&ntype, CMP_NODE_MAP_UV, "Map UV", NODE_CLASS_DISTORT, 0); + node_type_socket_templates(&ntype, cmp_node_mapuv_in, cmp_node_mapuv_out); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_mapValue.c b/source/blender/nodes/composite/nodes/node_composite_mapValue.c index 5eff355c76d..08deb73f05f 100644 --- a/source/blender/nodes/composite/nodes/node_composite_mapValue.c +++ b/source/blender/nodes/composite/nodes/node_composite_mapValue.c @@ -21,32 +21,31 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" /* **************** MAP VALUE ******************** */ static bNodeSocketTemplate cmp_node_map_value_in[] = { - { SOCK_FLOAT, 1, N_("Value"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Value"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_map_value_out[] = { - { SOCK_FLOAT, 0, N_("Value")}, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("Value")}, + {-1, 0, ""}, }; static void node_composit_init_map_value(bNodeTree *UNUSED(ntree), bNode *node) { - node->storage = BKE_texture_mapping_add(TEXMAP_TYPE_POINT); + node->storage = BKE_texture_mapping_add(TEXMAP_TYPE_POINT); } void register_node_type_cmp_map_value(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_MAP_VALUE, "Map Value", NODE_CLASS_OP_VECTOR, 0); - node_type_socket_templates(&ntype, cmp_node_map_value_in, cmp_node_map_value_out); - node_type_init(&ntype, node_composit_init_map_value); - node_type_storage(&ntype, "TexMapping", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_MAP_VALUE, "Map Value", NODE_CLASS_OP_VECTOR, 0); + node_type_socket_templates(&ntype, cmp_node_map_value_in, cmp_node_map_value_out); + node_type_init(&ntype, node_composit_init_map_value); + node_type_storage(&ntype, "TexMapping", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_mask.c b/source/blender/nodes/composite/nodes/node_composite_mask.c index 69f2931d236..fb50c99fa94 100644 --- a/source/blender/nodes/composite/nodes/node_composite_mask.c +++ b/source/blender/nodes/composite/nodes/node_composite_mask.c @@ -27,41 +27,38 @@ /* **************** Translate ******************** */ -static bNodeSocketTemplate cmp_node_mask_out[] = { - { SOCK_FLOAT, 0, "Mask"}, - { -1, 0, "" } -}; +static bNodeSocketTemplate cmp_node_mask_out[] = {{SOCK_FLOAT, 0, "Mask"}, {-1, 0, ""}}; static void node_composit_init_mask(bNodeTree *UNUSED(ntree), bNode *node) { - NodeMask *data = MEM_callocN(sizeof(NodeMask), "NodeMask"); - data->size_x = data->size_y = 256; - node->storage = data; + NodeMask *data = MEM_callocN(sizeof(NodeMask), "NodeMask"); + data->size_x = data->size_y = 256; + node->storage = data; - node->custom2 = 16; /* samples */ - node->custom3 = 0.5f; /* shutter */ + node->custom2 = 16; /* samples */ + node->custom3 = 0.5f; /* shutter */ } static void node_mask_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen) { - if (node->id != NULL) { - BLI_strncpy(label, node->id->name + 2, maxlen); - } - else { - BLI_strncpy(label, IFACE_("Mask"), maxlen); - } + if (node->id != NULL) { + BLI_strncpy(label, node->id->name + 2, maxlen); + } + else { + BLI_strncpy(label, IFACE_("Mask"), maxlen); + } } void register_node_type_cmp_mask(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_MASK, "Mask", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, NULL, cmp_node_mask_out); - node_type_init(&ntype, node_composit_init_mask); - node_type_label(&ntype, node_mask_label); + cmp_node_type_base(&ntype, CMP_NODE_MASK, "Mask", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, NULL, cmp_node_mask_out); + node_type_init(&ntype, node_composit_init_mask); + node_type_label(&ntype, node_mask_label); - node_type_storage(&ntype, "NodeMask", node_free_standard_storage, node_copy_standard_storage); + node_type_storage(&ntype, "NodeMask", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_math.c b/source/blender/nodes/composite/nodes/node_composite_math.c index 00d9dda8dcc..21a85b2168f 100644 --- a/source/blender/nodes/composite/nodes/node_composite_math.c +++ b/source/blender/nodes/composite/nodes/node_composite_math.c @@ -21,29 +21,23 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" /* **************** SCALAR MATH ******************** */ static bNodeSocketTemplate cmp_node_math_in[] = { - { SOCK_FLOAT, 1, N_("Value"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("Value"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, - { -1, 0, "" } -}; - -static bNodeSocketTemplate cmp_node_math_out[] = { - { SOCK_FLOAT, 0, N_("Value")}, - { -1, 0, "" } -}; + {SOCK_FLOAT, 1, N_("Value"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("Value"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, + {-1, 0, ""}}; +static bNodeSocketTemplate cmp_node_math_out[] = {{SOCK_FLOAT, 0, N_("Value")}, {-1, 0, ""}}; void register_node_type_cmp_math(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_MATH, "Math", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, cmp_node_math_in, cmp_node_math_out); - node_type_label(&ntype, node_math_label); + cmp_node_type_base(&ntype, CMP_NODE_MATH, "Math", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, cmp_node_math_in, cmp_node_math_out); + node_type_label(&ntype, node_math_label); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_mixrgb.c b/source/blender/nodes/composite/nodes/node_composite_mixrgb.c index a808a5faaa9..2c324c7c5f0 100644 --- a/source/blender/nodes/composite/nodes/node_composite_mixrgb.c +++ b/source/blender/nodes/composite/nodes/node_composite_mixrgb.c @@ -25,24 +25,24 @@ /* **************** MIX RGB ******************** */ static bNodeSocketTemplate cmp_node_mix_rgb_in[] = { - { SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_mix_rgb_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; /* custom1 = mix type */ void register_node_type_cmp_mix_rgb(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, NODE_PREVIEW); - node_type_socket_templates(&ntype, cmp_node_mix_rgb_in, cmp_node_mix_rgb_out); - node_type_label(&ntype, node_blend_label); + cmp_node_type_base(&ntype, CMP_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, NODE_PREVIEW); + node_type_socket_templates(&ntype, cmp_node_mix_rgb_in, cmp_node_mix_rgb_out); + node_type_label(&ntype, node_blend_label); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_movieclip.c b/source/blender/nodes/composite/nodes/node_composite_movieclip.c index db8a1d52205..e871b764a82 100644 --- a/source/blender/nodes/composite/nodes/node_composite_movieclip.c +++ b/source/blender/nodes/composite/nodes/node_composite_movieclip.c @@ -26,34 +26,35 @@ #include "BKE_context.h" static bNodeSocketTemplate cmp_node_movieclip_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { SOCK_FLOAT, 0, N_("Alpha")}, - { SOCK_FLOAT, 1, N_("Offset X")}, - { SOCK_FLOAT, 1, N_("Offset Y")}, - { SOCK_FLOAT, 1, N_("Scale")}, - { SOCK_FLOAT, 1, N_("Angle")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {SOCK_FLOAT, 0, N_("Alpha")}, + {SOCK_FLOAT, 1, N_("Offset X")}, + {SOCK_FLOAT, 1, N_("Offset Y")}, + {SOCK_FLOAT, 1, N_("Scale")}, + {SOCK_FLOAT, 1, N_("Angle")}, + {-1, 0, ""}, }; static void init(const bContext *C, PointerRNA *ptr) { - bNode *node = ptr->data; - Scene *scene = CTX_data_scene(C); - MovieClipUser *user = MEM_callocN(sizeof(MovieClipUser), "node movie clip user"); + bNode *node = ptr->data; + Scene *scene = CTX_data_scene(C); + MovieClipUser *user = MEM_callocN(sizeof(MovieClipUser), "node movie clip user"); - node->id = (ID *)scene->clip; - node->storage = user; - user->framenr = 1; + node->id = (ID *)scene->clip; + node->storage = user; + user->framenr = 1; } void register_node_type_cmp_movieclip(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_MOVIECLIP, "Movie Clip", NODE_CLASS_INPUT, NODE_PREVIEW); - node_type_socket_templates(&ntype, NULL, cmp_node_movieclip_out); - ntype.initfunc_api = init; - node_type_storage(&ntype, "MovieClipUser", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_MOVIECLIP, "Movie Clip", NODE_CLASS_INPUT, NODE_PREVIEW); + node_type_socket_templates(&ntype, NULL, cmp_node_movieclip_out); + ntype.initfunc_api = init; + node_type_storage( + &ntype, "MovieClipUser", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_moviedistortion.c b/source/blender/nodes/composite/nodes/node_composite_moviedistortion.c index 9366be94227..144fe5c44aa 100644 --- a/source/blender/nodes/composite/nodes/node_composite_moviedistortion.c +++ b/source/blender/nodes/composite/nodes/node_composite_moviedistortion.c @@ -28,55 +28,55 @@ /* **************** Translate ******************** */ static bNodeSocketTemplate cmp_node_moviedistortion_in[] = { - { SOCK_RGBA, 1, N_("Image"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_moviedistortion_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; static void label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen) { - if (node->custom1 == 0) - BLI_strncpy(label, IFACE_("Undistortion"), maxlen); - else - BLI_strncpy(label, IFACE_("Distortion"), maxlen); + if (node->custom1 == 0) + BLI_strncpy(label, IFACE_("Undistortion"), maxlen); + else + BLI_strncpy(label, IFACE_("Distortion"), maxlen); } static void init(const bContext *C, PointerRNA *ptr) { - bNode *node = ptr->data; - Scene *scene = CTX_data_scene(C); + bNode *node = ptr->data; + Scene *scene = CTX_data_scene(C); - node->id = (ID *)scene->clip; + node->id = (ID *)scene->clip; } static void storage_free(bNode *node) { - if (node->storage) - BKE_tracking_distortion_free(node->storage); + if (node->storage) + BKE_tracking_distortion_free(node->storage); - node->storage = NULL; + node->storage = NULL; } static void storage_copy(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, bNode *src_node) { - if (src_node->storage) - dest_node->storage = BKE_tracking_distortion_copy(src_node->storage); + if (src_node->storage) + dest_node->storage = BKE_tracking_distortion_copy(src_node->storage); } void register_node_type_cmp_moviedistortion(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_MOVIEDISTORTION, "Movie Distortion", NODE_CLASS_DISTORT, 0); - node_type_socket_templates(&ntype, cmp_node_moviedistortion_in, cmp_node_moviedistortion_out); - node_type_label(&ntype, label); + cmp_node_type_base(&ntype, CMP_NODE_MOVIEDISTORTION, "Movie Distortion", NODE_CLASS_DISTORT, 0); + node_type_socket_templates(&ntype, cmp_node_moviedistortion_in, cmp_node_moviedistortion_out); + node_type_label(&ntype, label); - ntype.initfunc_api = init; - node_type_storage(&ntype, NULL, storage_free, storage_copy); + ntype.initfunc_api = init; + node_type_storage(&ntype, NULL, storage_free, storage_copy); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_normal.c b/source/blender/nodes/composite/nodes/node_composite_normal.c index fd256dd32f3..f4a432a1125 100644 --- a/source/blender/nodes/composite/nodes/node_composite_normal.c +++ b/source/blender/nodes/composite/nodes/node_composite_normal.c @@ -21,27 +21,26 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" /* **************** NORMAL ******************** */ static bNodeSocketTemplate cmp_node_normal_in[] = { - { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_DIRECTION}, - { -1, 0, "" }, + {SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_DIRECTION}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_normal_out[] = { - { SOCK_VECTOR, 0, N_("Normal"), 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f, PROP_DIRECTION}, - { SOCK_FLOAT, 0, N_("Dot")}, - { -1, 0, "" }, + {SOCK_VECTOR, 0, N_("Normal"), 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f, PROP_DIRECTION}, + {SOCK_FLOAT, 0, N_("Dot")}, + {-1, 0, ""}, }; void register_node_type_cmp_normal(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_NORMAL, "Normal", NODE_CLASS_OP_VECTOR, 0); - node_type_socket_templates(&ntype, cmp_node_normal_in, cmp_node_normal_out); + cmp_node_type_base(&ntype, CMP_NODE_NORMAL, "Normal", NODE_CLASS_OP_VECTOR, 0); + node_type_socket_templates(&ntype, cmp_node_normal_in, cmp_node_normal_out); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_normalize.c b/source/blender/nodes/composite/nodes/node_composite_normalize.c index 9ebe31b5c92..7036bd7ff0d 100644 --- a/source/blender/nodes/composite/nodes/node_composite_normalize.c +++ b/source/blender/nodes/composite/nodes/node_composite_normalize.c @@ -21,26 +21,19 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" - /* **************** NORMALIZE single channel, useful for Z buffer ******************** */ static bNodeSocketTemplate cmp_node_normalize_in[] = { - { SOCK_FLOAT, 1, N_("Value"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { -1, 0, "" } -}; -static bNodeSocketTemplate cmp_node_normalize_out[] = { - { SOCK_FLOAT, 0, N_("Value")}, - { -1, 0, "" } -}; + {SOCK_FLOAT, 1, N_("Value"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, {-1, 0, ""}}; +static bNodeSocketTemplate cmp_node_normalize_out[] = {{SOCK_FLOAT, 0, N_("Value")}, {-1, 0, ""}}; void register_node_type_cmp_normalize(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_NORMALIZE, "Normalize", NODE_CLASS_OP_VECTOR, 0); - node_type_socket_templates(&ntype, cmp_node_normalize_in, cmp_node_normalize_out); + cmp_node_type_base(&ntype, CMP_NODE_NORMALIZE, "Normalize", NODE_CLASS_OP_VECTOR, 0); + node_type_socket_templates(&ntype, cmp_node_normalize_in, cmp_node_normalize_out); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_outputFile.c b/source/blender/nodes/composite/nodes/node_composite_outputFile.c index a7e3023cfcf..624065fa96d 100644 --- a/source/blender/nodes/composite/nodes/node_composite_outputFile.c +++ b/source/blender/nodes/composite/nodes/node_composite_outputFile.c @@ -21,7 +21,6 @@ * \ingroup cmpnodes */ - #include <string.h> #include "BLI_utildefines.h" #include "BLI_string_utils.h" @@ -34,222 +33,247 @@ #include "intern/openexr/openexr_multi.h" - /* **************** OUTPUT FILE ******************** */ /* find unique path */ static bool unique_path_unique_check(void *arg, const char *name) { - struct {ListBase *lb; bNodeSocket *sock; } *data = arg; - bNodeSocket *sock; - for (sock = data->lb->first; sock; sock = sock->next) { - if (sock != data->sock) { - NodeImageMultiFileSocket *sockdata = sock->storage; - if (STREQ(sockdata->path, name)) - return true; - } - } - return false; + struct { + ListBase *lb; + bNodeSocket *sock; + } *data = arg; + bNodeSocket *sock; + for (sock = data->lb->first; sock; sock = sock->next) { + if (sock != data->sock) { + NodeImageMultiFileSocket *sockdata = sock->storage; + if (STREQ(sockdata->path, name)) + return true; + } + } + return false; } -void ntreeCompositOutputFileUniquePath(ListBase *list, bNodeSocket *sock, const char defname[], char delim) +void ntreeCompositOutputFileUniquePath(ListBase *list, + bNodeSocket *sock, + const char defname[], + char delim) { - NodeImageMultiFileSocket *sockdata; - struct {ListBase *lb; bNodeSocket *sock; } data; - data.lb = list; - data.sock = sock; - - /* See if we are given an empty string */ - if (ELEM(NULL, sock, defname)) - return; - - sockdata = sock->storage; - BLI_uniquename_cb(unique_path_unique_check, &data, defname, delim, sockdata->path, sizeof(sockdata->path)); + NodeImageMultiFileSocket *sockdata; + struct { + ListBase *lb; + bNodeSocket *sock; + } data; + data.lb = list; + data.sock = sock; + + /* See if we are given an empty string */ + if (ELEM(NULL, sock, defname)) + return; + + sockdata = sock->storage; + BLI_uniquename_cb( + unique_path_unique_check, &data, defname, delim, sockdata->path, sizeof(sockdata->path)); } /* find unique EXR layer */ static bool unique_layer_unique_check(void *arg, const char *name) { - struct {ListBase *lb; bNodeSocket *sock; } *data = arg; - bNodeSocket *sock; - for (sock = data->lb->first; sock; sock = sock->next) { - if (sock != data->sock) { - NodeImageMultiFileSocket *sockdata = sock->storage; - if (STREQ(sockdata->layer, name)) - return true; - } - } - return false; + struct { + ListBase *lb; + bNodeSocket *sock; + } *data = arg; + bNodeSocket *sock; + for (sock = data->lb->first; sock; sock = sock->next) { + if (sock != data->sock) { + NodeImageMultiFileSocket *sockdata = sock->storage; + if (STREQ(sockdata->layer, name)) + return true; + } + } + return false; } -void ntreeCompositOutputFileUniqueLayer(ListBase *list, bNodeSocket *sock, const char defname[], char delim) +void ntreeCompositOutputFileUniqueLayer(ListBase *list, + bNodeSocket *sock, + const char defname[], + char delim) { - NodeImageMultiFileSocket *sockdata; - struct {ListBase *lb; bNodeSocket *sock; } data; - data.lb = list; - data.sock = sock; - - /* See if we are given an empty string */ - if (ELEM(NULL, sock, defname)) - return; - - sockdata = sock->storage; - BLI_uniquename_cb(unique_layer_unique_check, &data, defname, delim, sockdata->layer, sizeof(sockdata->layer)); + NodeImageMultiFileSocket *sockdata; + struct { + ListBase *lb; + bNodeSocket *sock; + } data; + data.lb = list; + data.sock = sock; + + /* See if we are given an empty string */ + if (ELEM(NULL, sock, defname)) + return; + + sockdata = sock->storage; + BLI_uniquename_cb( + unique_layer_unique_check, &data, defname, delim, sockdata->layer, sizeof(sockdata->layer)); } -bNodeSocket *ntreeCompositOutputFileAddSocket(bNodeTree *ntree, bNode *node, const char *name, ImageFormatData *im_format) +bNodeSocket *ntreeCompositOutputFileAddSocket(bNodeTree *ntree, + bNode *node, + const char *name, + ImageFormatData *im_format) { - NodeImageMultiFile *nimf = node->storage; - bNodeSocket *sock = nodeAddStaticSocket(ntree, node, SOCK_IN, SOCK_RGBA, PROP_NONE, NULL, name); - - /* create format data for the input socket */ - NodeImageMultiFileSocket *sockdata = MEM_callocN(sizeof(NodeImageMultiFileSocket), "socket image format"); - sock->storage = sockdata; - - BLI_strncpy_utf8(sockdata->path, name, sizeof(sockdata->path)); - ntreeCompositOutputFileUniquePath(&node->inputs, sock, name, '_'); - BLI_strncpy_utf8(sockdata->layer, name, sizeof(sockdata->layer)); - ntreeCompositOutputFileUniqueLayer(&node->inputs, sock, name, '_'); - - if (im_format) { - sockdata->format = *im_format; - if (BKE_imtype_is_movie(sockdata->format.imtype)) { - sockdata->format.imtype = R_IMF_IMTYPE_OPENEXR; - } - } - else - BKE_imformat_defaults(&sockdata->format); - /* use node data format by default */ - sockdata->use_node_format = true; - - nimf->active_input = BLI_findindex(&node->inputs, sock); - - return sock; + NodeImageMultiFile *nimf = node->storage; + bNodeSocket *sock = nodeAddStaticSocket(ntree, node, SOCK_IN, SOCK_RGBA, PROP_NONE, NULL, name); + + /* create format data for the input socket */ + NodeImageMultiFileSocket *sockdata = MEM_callocN(sizeof(NodeImageMultiFileSocket), + "socket image format"); + sock->storage = sockdata; + + BLI_strncpy_utf8(sockdata->path, name, sizeof(sockdata->path)); + ntreeCompositOutputFileUniquePath(&node->inputs, sock, name, '_'); + BLI_strncpy_utf8(sockdata->layer, name, sizeof(sockdata->layer)); + ntreeCompositOutputFileUniqueLayer(&node->inputs, sock, name, '_'); + + if (im_format) { + sockdata->format = *im_format; + if (BKE_imtype_is_movie(sockdata->format.imtype)) { + sockdata->format.imtype = R_IMF_IMTYPE_OPENEXR; + } + } + else + BKE_imformat_defaults(&sockdata->format); + /* use node data format by default */ + sockdata->use_node_format = true; + + nimf->active_input = BLI_findindex(&node->inputs, sock); + + return sock; } int ntreeCompositOutputFileRemoveActiveSocket(bNodeTree *ntree, bNode *node) { - NodeImageMultiFile *nimf = node->storage; - bNodeSocket *sock = BLI_findlink(&node->inputs, nimf->active_input); - int totinputs = BLI_listbase_count(&node->inputs); + NodeImageMultiFile *nimf = node->storage; + bNodeSocket *sock = BLI_findlink(&node->inputs, nimf->active_input); + int totinputs = BLI_listbase_count(&node->inputs); - if (!sock) - return 0; + if (!sock) + return 0; - if (nimf->active_input == totinputs - 1) - --nimf->active_input; + if (nimf->active_input == totinputs - 1) + --nimf->active_input; - /* free format data */ - MEM_freeN(sock->storage); + /* free format data */ + MEM_freeN(sock->storage); - nodeRemoveSocket(ntree, node, sock); - return 1; + nodeRemoveSocket(ntree, node, sock); + return 1; } void ntreeCompositOutputFileSetPath(bNode *node, bNodeSocket *sock, const char *name) { - NodeImageMultiFileSocket *sockdata = sock->storage; - BLI_strncpy_utf8(sockdata->path, name, sizeof(sockdata->path)); - ntreeCompositOutputFileUniquePath(&node->inputs, sock, name, '_'); + NodeImageMultiFileSocket *sockdata = sock->storage; + BLI_strncpy_utf8(sockdata->path, name, sizeof(sockdata->path)); + ntreeCompositOutputFileUniquePath(&node->inputs, sock, name, '_'); } void ntreeCompositOutputFileSetLayer(bNode *node, bNodeSocket *sock, const char *name) { - NodeImageMultiFileSocket *sockdata = sock->storage; - BLI_strncpy_utf8(sockdata->layer, name, sizeof(sockdata->layer)); - ntreeCompositOutputFileUniqueLayer(&node->inputs, sock, name, '_'); + NodeImageMultiFileSocket *sockdata = sock->storage; + BLI_strncpy_utf8(sockdata->layer, name, sizeof(sockdata->layer)); + ntreeCompositOutputFileUniqueLayer(&node->inputs, sock, name, '_'); } /* XXX uses initfunc_api callback, regular initfunc does not support context yet */ static void init_output_file(const bContext *C, PointerRNA *ptr) { - Scene *scene = CTX_data_scene(C); - bNodeTree *ntree = ptr->id.data; - bNode *node = ptr->data; - NodeImageMultiFile *nimf = MEM_callocN(sizeof(NodeImageMultiFile), "node image multi file"); - ImageFormatData *format = NULL; - node->storage = nimf; - - if (scene) { - RenderData *rd = &scene->r; - - BLI_strncpy(nimf->base_path, rd->pic, sizeof(nimf->base_path)); - nimf->format = rd->im_format; - if (BKE_imtype_is_movie(nimf->format.imtype)) { - nimf->format.imtype = R_IMF_IMTYPE_OPENEXR; - } - - format = &nimf->format; - } - else - BKE_imformat_defaults(&nimf->format); - - /* add one socket by default */ - ntreeCompositOutputFileAddSocket(ntree, node, "Image", format); + Scene *scene = CTX_data_scene(C); + bNodeTree *ntree = ptr->id.data; + bNode *node = ptr->data; + NodeImageMultiFile *nimf = MEM_callocN(sizeof(NodeImageMultiFile), "node image multi file"); + ImageFormatData *format = NULL; + node->storage = nimf; + + if (scene) { + RenderData *rd = &scene->r; + + BLI_strncpy(nimf->base_path, rd->pic, sizeof(nimf->base_path)); + nimf->format = rd->im_format; + if (BKE_imtype_is_movie(nimf->format.imtype)) { + nimf->format.imtype = R_IMF_IMTYPE_OPENEXR; + } + + format = &nimf->format; + } + else + BKE_imformat_defaults(&nimf->format); + + /* add one socket by default */ + ntreeCompositOutputFileAddSocket(ntree, node, "Image", format); } static void free_output_file(bNode *node) { - bNodeSocket *sock; + bNodeSocket *sock; - /* free storage data in sockets */ - for (sock = node->inputs.first; sock; sock = sock->next) { - MEM_freeN(sock->storage); - } + /* free storage data in sockets */ + for (sock = node->inputs.first; sock; sock = sock->next) { + MEM_freeN(sock->storage); + } - MEM_freeN(node->storage); + MEM_freeN(node->storage); } static void copy_output_file(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, bNode *src_node) { - bNodeSocket *src_sock, *dest_sock; + bNodeSocket *src_sock, *dest_sock; - dest_node->storage = MEM_dupallocN(src_node->storage); + dest_node->storage = MEM_dupallocN(src_node->storage); - /* duplicate storage data in sockets */ - for (src_sock = src_node->inputs.first, dest_sock = dest_node->inputs.first; src_sock && dest_sock; src_sock = src_sock->next, dest_sock = dest_sock->next) { - dest_sock->storage = MEM_dupallocN(src_sock->storage); - } + /* duplicate storage data in sockets */ + for (src_sock = src_node->inputs.first, dest_sock = dest_node->inputs.first; + src_sock && dest_sock; + src_sock = src_sock->next, dest_sock = dest_sock->next) { + dest_sock->storage = MEM_dupallocN(src_sock->storage); + } } static void update_output_file(bNodeTree *ntree, bNode *node) { - bNodeSocket *sock, *sock_next; - PointerRNA ptr; - - /* XXX fix for #36706: remove invalid sockets added with bpy API. - * This is not ideal, but prevents crashes from missing storage. - * FileOutput node needs a redesign to support this properly. - */ - for (sock = node->inputs.first; sock; sock = sock_next) { - sock_next = sock->next; - if (sock->storage == NULL) { - nodeRemoveSocket(ntree, node, sock); - } - } - for (sock = node->outputs.first; sock; sock = sock_next) { - sock_next = sock->next; - nodeRemoveSocket(ntree, node, sock); - } - - cmp_node_update_default(ntree, node); - - /* automatically update the socket type based on linked input */ - for (sock = node->inputs.first; sock; sock = sock->next) { - if (sock->link) { - RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr); - RNA_enum_set(&ptr, "type", sock->link->fromsock->type); - } - } + bNodeSocket *sock, *sock_next; + PointerRNA ptr; + + /* XXX fix for #36706: remove invalid sockets added with bpy API. + * This is not ideal, but prevents crashes from missing storage. + * FileOutput node needs a redesign to support this properly. + */ + for (sock = node->inputs.first; sock; sock = sock_next) { + sock_next = sock->next; + if (sock->storage == NULL) { + nodeRemoveSocket(ntree, node, sock); + } + } + for (sock = node->outputs.first; sock; sock = sock_next) { + sock_next = sock->next; + nodeRemoveSocket(ntree, node, sock); + } + + cmp_node_update_default(ntree, node); + + /* automatically update the socket type based on linked input */ + for (sock = node->inputs.first; sock; sock = sock->next) { + if (sock->link) { + RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr); + RNA_enum_set(&ptr, "type", sock->link->fromsock->type); + } + } } void register_node_type_cmp_output_file(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_OUTPUT_FILE, "File Output", NODE_CLASS_OUTPUT, NODE_PREVIEW); - node_type_socket_templates(&ntype, NULL, NULL); - ntype.initfunc_api = init_output_file; - node_type_storage(&ntype, "NodeImageMultiFile", free_output_file, copy_output_file); - node_type_update(&ntype, update_output_file, NULL); + cmp_node_type_base(&ntype, CMP_NODE_OUTPUT_FILE, "File Output", NODE_CLASS_OUTPUT, NODE_PREVIEW); + node_type_socket_templates(&ntype, NULL, NULL); + ntype.initfunc_api = init_output_file; + node_type_storage(&ntype, "NodeImageMultiFile", free_output_file, copy_output_file); + node_type_update(&ntype, update_output_file, NULL); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_pixelate.c b/source/blender/nodes/composite/nodes/node_composite_pixelate.c index ca9159acf0e..be20ba6dcc1 100644 --- a/source/blender/nodes/composite/nodes/node_composite_pixelate.c +++ b/source/blender/nodes/composite/nodes/node_composite_pixelate.c @@ -21,27 +21,20 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" - /* **************** Pixelate ******************** */ static bNodeSocketTemplate cmp_node_pixelate_in[] = { - { SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { -1, 0, "" } -}; -static bNodeSocketTemplate cmp_node_pixelate_out[] = { - { SOCK_RGBA, 0, N_("Color")}, - { -1, 0, "" } -}; + {SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, {-1, 0, ""}}; +static bNodeSocketTemplate cmp_node_pixelate_out[] = {{SOCK_RGBA, 0, N_("Color")}, {-1, 0, ""}}; void register_node_type_cmp_pixelate(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_PIXELATE, "Pixelate", NODE_CLASS_OP_FILTER, 0); - node_type_socket_templates(&ntype, cmp_node_pixelate_in, cmp_node_pixelate_out); + cmp_node_type_base(&ntype, CMP_NODE_PIXELATE, "Pixelate", NODE_CLASS_OP_FILTER, 0); + node_type_socket_templates(&ntype, cmp_node_pixelate_in, cmp_node_pixelate_out); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_planetrackdeform.c b/source/blender/nodes/composite/nodes/node_composite_planetrackdeform.c index 2e274f036cc..3b6094d7083 100644 --- a/source/blender/nodes/composite/nodes/node_composite_planetrackdeform.c +++ b/source/blender/nodes/composite/nodes/node_composite_planetrackdeform.c @@ -21,36 +21,36 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" static bNodeSocketTemplate cmp_node_planetrackdeform_in[] = { - { SOCK_RGBA, 1, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { -1, 0, "" } -}; + {SOCK_RGBA, 1, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, {-1, 0, ""}}; static bNodeSocketTemplate cmp_node_planetrackdeform_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { SOCK_FLOAT, 0, N_("Plane")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {SOCK_FLOAT, 0, N_("Plane")}, + {-1, 0, ""}, }; static void init(bNodeTree *UNUSED(ntree), bNode *node) { - NodePlaneTrackDeformData *data = MEM_callocN(sizeof(NodePlaneTrackDeformData), "node plane track deform data"); - data->motion_blur_samples = 16; - data->motion_blur_shutter = 0.5f; - node->storage = data; + NodePlaneTrackDeformData *data = MEM_callocN(sizeof(NodePlaneTrackDeformData), + "node plane track deform data"); + data->motion_blur_samples = 16; + data->motion_blur_shutter = 0.5f; + node->storage = data; } void register_node_type_cmp_planetrackdeform(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_PLANETRACKDEFORM, "Plane Track Deform", NODE_CLASS_DISTORT, 0); - node_type_socket_templates(&ntype, cmp_node_planetrackdeform_in, cmp_node_planetrackdeform_out); - node_type_init(&ntype, init); - node_type_storage(&ntype, "NodePlaneTrackDeformData", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base( + &ntype, CMP_NODE_PLANETRACKDEFORM, "Plane Track Deform", NODE_CLASS_DISTORT, 0); + node_type_socket_templates(&ntype, cmp_node_planetrackdeform_in, cmp_node_planetrackdeform_out); + node_type_init(&ntype, init); + node_type_storage( + &ntype, "NodePlaneTrackDeformData", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_premulkey.c b/source/blender/nodes/composite/nodes/node_composite_premulkey.c index 273c61f88ec..4746596efec 100644 --- a/source/blender/nodes/composite/nodes/node_composite_premulkey.c +++ b/source/blender/nodes/composite/nodes/node_composite_premulkey.c @@ -21,26 +21,25 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" /* **************** Premul and Key Alpha Convert ******************** */ static bNodeSocketTemplate cmp_node_premulkey_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_premulkey_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; void register_node_type_cmp_premulkey(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_PREMULKEY, "Alpha Convert", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, cmp_node_premulkey_in, cmp_node_premulkey_out); + cmp_node_type_base(&ntype, CMP_NODE_PREMULKEY, "Alpha Convert", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, cmp_node_premulkey_in, cmp_node_premulkey_out); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_rgb.c b/source/blender/nodes/composite/nodes/node_composite_rgb.c index 85f6f617ef7..b551a8158a8 100644 --- a/source/blender/nodes/composite/nodes/node_composite_rgb.c +++ b/source/blender/nodes/composite/nodes/node_composite_rgb.c @@ -21,22 +21,21 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" /* **************** RGB ******************** */ static bNodeSocketTemplate cmp_node_rgb_out[] = { - { SOCK_RGBA, 0, N_("RGBA"), 0.5f, 0.5f, 0.5f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("RGBA"), 0.5f, 0.5f, 0.5f, 1.0f}, + {-1, 0, ""}, }; void register_node_type_cmp_rgb(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_RGB, "RGB", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, NULL, cmp_node_rgb_out); - node_type_size_preset(&ntype, NODE_SIZE_SMALL); + cmp_node_type_base(&ntype, CMP_NODE_RGB, "RGB", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, NULL, cmp_node_rgb_out); + node_type_size_preset(&ntype, NODE_SIZE_SMALL); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_rotate.c b/source/blender/nodes/composite/nodes/node_composite_rotate.c index b43e1da5583..b60347a459a 100644 --- a/source/blender/nodes/composite/nodes/node_composite_rotate.c +++ b/source/blender/nodes/composite/nodes/node_composite_rotate.c @@ -21,33 +21,32 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" /* **************** Rotate ******************** */ static bNodeSocketTemplate cmp_node_rotate_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Degr"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f, PROP_ANGLE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Degr"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f, PROP_ANGLE}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_rotate_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; static void node_composit_init_rotate(bNodeTree *UNUSED(ntree), bNode *node) { - node->custom1 = 1; /* Bilinear Filter*/ + node->custom1 = 1; /* Bilinear Filter*/ } void register_node_type_cmp_rotate(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_ROTATE, "Rotate", NODE_CLASS_DISTORT, 0); - node_type_socket_templates(&ntype, cmp_node_rotate_in, cmp_node_rotate_out); - node_type_init(&ntype, node_composit_init_rotate); + cmp_node_type_base(&ntype, CMP_NODE_ROTATE, "Rotate", NODE_CLASS_DISTORT, 0); + node_type_socket_templates(&ntype, cmp_node_rotate_in, cmp_node_rotate_out); + node_type_init(&ntype, node_composit_init_rotate); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_scale.c b/source/blender/nodes/composite/nodes/node_composite_scale.c index 4bd9b5e5db7..1a0268f2a3e 100644 --- a/source/blender/nodes/composite/nodes/node_composite_scale.c +++ b/source/blender/nodes/composite/nodes/node_composite_scale.c @@ -21,47 +21,42 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" /* **************** Scale ******************** */ static bNodeSocketTemplate cmp_node_scale_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("X"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, CMP_SCALE_MAX, PROP_NONE}, - { SOCK_FLOAT, 1, N_("Y"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, CMP_SCALE_MAX, PROP_NONE}, - { -1, 0, "" } -}; -static bNodeSocketTemplate cmp_node_scale_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" } -}; + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("X"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, CMP_SCALE_MAX, PROP_NONE}, + {SOCK_FLOAT, 1, N_("Y"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, CMP_SCALE_MAX, PROP_NONE}, + {-1, 0, ""}}; +static bNodeSocketTemplate cmp_node_scale_out[] = {{SOCK_RGBA, 0, N_("Image")}, {-1, 0, ""}}; static void node_composite_update_scale(bNodeTree *UNUSED(ntree), bNode *node) { - bNodeSocket *sock; - bool use_xy_scale = ELEM(node->custom1, CMP_SCALE_RELATIVE, CMP_SCALE_ABSOLUTE); - - /* Only show X/Y scale factor inputs for modes using them! */ - for (sock = node->inputs.first; sock; sock = sock->next) { - if (STR_ELEM(sock->name, "X", "Y")) { - if (use_xy_scale) { - sock->flag &= ~SOCK_UNAVAIL; - } - else { - sock->flag |= SOCK_UNAVAIL; - } - } - } + bNodeSocket *sock; + bool use_xy_scale = ELEM(node->custom1, CMP_SCALE_RELATIVE, CMP_SCALE_ABSOLUTE); + + /* Only show X/Y scale factor inputs for modes using them! */ + for (sock = node->inputs.first; sock; sock = sock->next) { + if (STR_ELEM(sock->name, "X", "Y")) { + if (use_xy_scale) { + sock->flag &= ~SOCK_UNAVAIL; + } + else { + sock->flag |= SOCK_UNAVAIL; + } + } + } } void register_node_type_cmp_scale(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_SCALE, "Scale", NODE_CLASS_DISTORT, 0); - node_type_socket_templates(&ntype, cmp_node_scale_in, cmp_node_scale_out); - node_type_update(&ntype, node_composite_update_scale, NULL); + cmp_node_type_base(&ntype, CMP_NODE_SCALE, "Scale", NODE_CLASS_DISTORT, 0); + node_type_socket_templates(&ntype, cmp_node_scale_in, cmp_node_scale_out); + node_type_update(&ntype, node_composite_update_scale, NULL); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_sepcombHSVA.c b/source/blender/nodes/composite/nodes/node_composite_sepcombHSVA.c index 9cb249bab71..691042ed31c 100644 --- a/source/blender/nodes/composite/nodes/node_composite_sepcombHSVA.c +++ b/source/blender/nodes/composite/nodes/node_composite_sepcombHSVA.c @@ -21,53 +21,50 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" - /* **************** SEPARATE HSVA ******************** */ static bNodeSocketTemplate cmp_node_sephsva_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_sephsva_out[] = { - { SOCK_FLOAT, 0, N_("H")}, - { SOCK_FLOAT, 0, N_("S")}, - { SOCK_FLOAT, 0, N_("V")}, - { SOCK_FLOAT, 0, N_("A")}, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("H")}, + {SOCK_FLOAT, 0, N_("S")}, + {SOCK_FLOAT, 0, N_("V")}, + {SOCK_FLOAT, 0, N_("A")}, + {-1, 0, ""}, }; void register_node_type_cmp_sephsva(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_SEPHSVA, "Separate HSVA", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, cmp_node_sephsva_in, cmp_node_sephsva_out); + cmp_node_type_base(&ntype, CMP_NODE_SEPHSVA, "Separate HSVA", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, cmp_node_sephsva_in, cmp_node_sephsva_out); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } - /* **************** COMBINE HSVA ******************** */ static bNodeSocketTemplate cmp_node_combhsva_in[] = { - { SOCK_FLOAT, 1, N_("H"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("S"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("V"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("A"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("H"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("S"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("V"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("A"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_combhsva_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; void register_node_type_cmp_combhsva(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_COMBHSVA, "Combine HSVA", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, cmp_node_combhsva_in, cmp_node_combhsva_out); + cmp_node_type_base(&ntype, CMP_NODE_COMBHSVA, "Combine HSVA", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, cmp_node_combhsva_in, cmp_node_combhsva_out); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_sepcombRGBA.c b/source/blender/nodes/composite/nodes/node_composite_sepcombRGBA.c index ffa034883d8..e832024c22f 100644 --- a/source/blender/nodes/composite/nodes/node_composite_sepcombRGBA.c +++ b/source/blender/nodes/composite/nodes/node_composite_sepcombRGBA.c @@ -21,53 +21,50 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" /* **************** SEPARATE RGBA ******************** */ static bNodeSocketTemplate cmp_node_seprgba_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_seprgba_out[] = { - { SOCK_FLOAT, 0, N_("R")}, - { SOCK_FLOAT, 0, N_("G")}, - { SOCK_FLOAT, 0, N_("B")}, - { SOCK_FLOAT, 0, N_("A")}, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("R")}, + {SOCK_FLOAT, 0, N_("G")}, + {SOCK_FLOAT, 0, N_("B")}, + {SOCK_FLOAT, 0, N_("A")}, + {-1, 0, ""}, }; void register_node_type_cmp_seprgba(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_SEPRGBA, "Separate RGBA", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, cmp_node_seprgba_in, cmp_node_seprgba_out); + cmp_node_type_base(&ntype, CMP_NODE_SEPRGBA, "Separate RGBA", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, cmp_node_seprgba_in, cmp_node_seprgba_out); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } - - /* **************** COMBINE RGBA ******************** */ static bNodeSocketTemplate cmp_node_combrgba_in[] = { - { SOCK_FLOAT, 1, N_("R"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("G"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("B"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("A"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("R"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("G"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("B"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("A"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_combrgba_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; void register_node_type_cmp_combrgba(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_COMBRGBA, "Combine RGBA", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, cmp_node_combrgba_in, cmp_node_combrgba_out); + cmp_node_type_base(&ntype, CMP_NODE_COMBRGBA, "Combine RGBA", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, cmp_node_combrgba_in, cmp_node_combrgba_out); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_sepcombYCCA.c b/source/blender/nodes/composite/nodes/node_composite_sepcombYCCA.c index 103a9c51a89..82d35dc6118 100644 --- a/source/blender/nodes/composite/nodes/node_composite_sepcombYCCA.c +++ b/source/blender/nodes/composite/nodes/node_composite_sepcombYCCA.c @@ -21,66 +21,58 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" - /* **************** SEPARATE YCCA ******************** */ static bNodeSocketTemplate cmp_node_sepycca_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketTemplate cmp_node_sepycca_out[] = { - { SOCK_FLOAT, 0, N_("Y")}, - { SOCK_FLOAT, 0, N_("Cb")}, - { SOCK_FLOAT, 0, N_("Cr")}, - { SOCK_FLOAT, 0, N_("A")}, - { -1, 0, "" } -}; + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, {-1, 0, ""}}; +static bNodeSocketTemplate cmp_node_sepycca_out[] = {{SOCK_FLOAT, 0, N_("Y")}, + {SOCK_FLOAT, 0, N_("Cb")}, + {SOCK_FLOAT, 0, N_("Cr")}, + {SOCK_FLOAT, 0, N_("A")}, + {-1, 0, ""}}; static void node_composit_init_mode_sepycca(bNodeTree *UNUSED(ntree), bNode *node) { - node->custom1 = 1; /* BLI_YCC_ITU_BT709 */ + node->custom1 = 1; /* BLI_YCC_ITU_BT709 */ } void register_node_type_cmp_sepycca(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_SEPYCCA, "Separate YCbCrA", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, cmp_node_sepycca_in, cmp_node_sepycca_out); - node_type_init(&ntype, node_composit_init_mode_sepycca); + cmp_node_type_base(&ntype, CMP_NODE_SEPYCCA, "Separate YCbCrA", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, cmp_node_sepycca_in, cmp_node_sepycca_out); + node_type_init(&ntype, node_composit_init_mode_sepycca); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } - - /* **************** COMBINE YCCA ******************** */ static bNodeSocketTemplate cmp_node_combycca_in[] = { - { SOCK_FLOAT, 1, N_("Y"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("Cb"), 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("Cr"), 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("A"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Y"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("Cb"), 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("Cr"), 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("A"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_combycca_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; static void node_composit_init_mode_combycca(bNodeTree *UNUSED(ntree), bNode *node) { - node->custom1 = 1; /* BLI_YCC_ITU_BT709 */ + node->custom1 = 1; /* BLI_YCC_ITU_BT709 */ } void register_node_type_cmp_combycca(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_COMBYCCA, "Combine YCbCrA", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, cmp_node_combycca_in, cmp_node_combycca_out); - node_type_init(&ntype, node_composit_init_mode_combycca); + cmp_node_type_base(&ntype, CMP_NODE_COMBYCCA, "Combine YCbCrA", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, cmp_node_combycca_in, cmp_node_combycca_out); + node_type_init(&ntype, node_composit_init_mode_combycca); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_sepcombYUVA.c b/source/blender/nodes/composite/nodes/node_composite_sepcombYUVA.c index d8022080ef1..b3277da2586 100644 --- a/source/blender/nodes/composite/nodes/node_composite_sepcombYUVA.c +++ b/source/blender/nodes/composite/nodes/node_composite_sepcombYUVA.c @@ -21,54 +21,46 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" - /* **************** SEPARATE YUVA ******************** */ static bNodeSocketTemplate cmp_node_sepyuva_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketTemplate cmp_node_sepyuva_out[] = { - { SOCK_FLOAT, 0, N_("Y")}, - { SOCK_FLOAT, 0, N_("U")}, - { SOCK_FLOAT, 0, N_("V")}, - { SOCK_FLOAT, 0, N_("A")}, - { -1, 0, "" } -}; + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, {-1, 0, ""}}; +static bNodeSocketTemplate cmp_node_sepyuva_out[] = {{SOCK_FLOAT, 0, N_("Y")}, + {SOCK_FLOAT, 0, N_("U")}, + {SOCK_FLOAT, 0, N_("V")}, + {SOCK_FLOAT, 0, N_("A")}, + {-1, 0, ""}}; void register_node_type_cmp_sepyuva(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_SEPYUVA, "Separate YUVA", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, cmp_node_sepyuva_in, cmp_node_sepyuva_out); + cmp_node_type_base(&ntype, CMP_NODE_SEPYUVA, "Separate YUVA", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, cmp_node_sepyuva_in, cmp_node_sepyuva_out); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } - - /* **************** COMBINE YUVA ******************** */ static bNodeSocketTemplate cmp_node_combyuva_in[] = { - { SOCK_FLOAT, 1, N_("Y"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("U"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("V"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("A"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Y"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("U"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("V"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("A"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_combyuva_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; void register_node_type_cmp_combyuva(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_COMBYUVA, "Combine YUVA", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, cmp_node_combyuva_in, cmp_node_combyuva_out); + cmp_node_type_base(&ntype, CMP_NODE_COMBYUVA, "Combine YUVA", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, cmp_node_combyuva_in, cmp_node_combyuva_out); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_setalpha.c b/source/blender/nodes/composite/nodes/node_composite_setalpha.c index 0ef738f0bda..519f2742bc8 100644 --- a/source/blender/nodes/composite/nodes/node_composite_setalpha.c +++ b/source/blender/nodes/composite/nodes/node_composite_setalpha.c @@ -21,26 +21,25 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" /* **************** SET ALPHA ******************** */ static bNodeSocketTemplate cmp_node_setalpha_in[] = { - { SOCK_RGBA, 1, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Alpha"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Alpha"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_setalpha_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; void register_node_type_cmp_setalpha(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_SETALPHA, "Set Alpha", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, cmp_node_setalpha_in, cmp_node_setalpha_out); + cmp_node_type_base(&ntype, CMP_NODE_SETALPHA, "Set Alpha", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, cmp_node_setalpha_in, cmp_node_setalpha_out); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_splitViewer.c b/source/blender/nodes/composite/nodes/node_composite_splitViewer.c index d15fee2b716..8e577271ae1 100644 --- a/source/blender/nodes/composite/nodes/node_composite_splitViewer.c +++ b/source/blender/nodes/composite/nodes/node_composite_splitViewer.c @@ -21,7 +21,6 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" #include "BKE_image.h" @@ -29,33 +28,34 @@ /* **************** SPLIT VIEWER ******************** */ static bNodeSocketTemplate cmp_node_splitviewer_in[] = { - { SOCK_RGBA, 1, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 1, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 1, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; static void node_composit_init_splitviewer(bNodeTree *UNUSED(ntree), bNode *node) { - ImageUser *iuser = MEM_callocN(sizeof(ImageUser), "node image user"); - node->storage = iuser; - iuser->sfra = 1; - iuser->ok = 1; - node->custom1 = 50; /* default 50% split */ + ImageUser *iuser = MEM_callocN(sizeof(ImageUser), "node image user"); + node->storage = iuser; + iuser->sfra = 1; + iuser->ok = 1; + node->custom1 = 50; /* default 50% split */ - node->id = (ID *)BKE_image_verify_viewer(G.main, IMA_TYPE_COMPOSITE, "Viewer Node"); + node->id = (ID *)BKE_image_verify_viewer(G.main, IMA_TYPE_COMPOSITE, "Viewer Node"); } void register_node_type_cmp_splitviewer(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_SPLITVIEWER, "Split Viewer", NODE_CLASS_OUTPUT, NODE_PREVIEW); - node_type_socket_templates(&ntype, cmp_node_splitviewer_in, NULL); - node_type_init(&ntype, node_composit_init_splitviewer); - node_type_storage(&ntype, "ImageUser", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base( + &ntype, CMP_NODE_SPLITVIEWER, "Split Viewer", NODE_CLASS_OUTPUT, NODE_PREVIEW); + node_type_socket_templates(&ntype, cmp_node_splitviewer_in, NULL); + node_type_init(&ntype, node_composit_init_splitviewer); + node_type_storage(&ntype, "ImageUser", node_free_standard_storage, node_copy_standard_storage); - /* Do not allow muting for this node. */ - node_type_internal_links(&ntype, NULL); + /* Do not allow muting for this node. */ + node_type_internal_links(&ntype, NULL); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_stabilize2d.c b/source/blender/nodes/composite/nodes/node_composite_stabilize2d.c index 631e463b14e..55d4ada0ca1 100644 --- a/source/blender/nodes/composite/nodes/node_composite_stabilize2d.c +++ b/source/blender/nodes/composite/nodes/node_composite_stabilize2d.c @@ -28,33 +28,33 @@ /* **************** Translate ******************** */ static bNodeSocketTemplate cmp_node_stabilize2d_in[] = { - { SOCK_RGBA, 1, N_("Image"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_stabilize2d_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; static void init(const bContext *C, PointerRNA *ptr) { - bNode *node = ptr->data; - Scene *scene = CTX_data_scene(C); + bNode *node = ptr->data; + Scene *scene = CTX_data_scene(C); - node->id = (ID *)scene->clip; + node->id = (ID *)scene->clip; - /* default to bilinear, see node_sampler_type_items in rna_nodetree.c */ - node->custom1 = 1; + /* default to bilinear, see node_sampler_type_items in rna_nodetree.c */ + node->custom1 = 1; } void register_node_type_cmp_stabilize2d(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_STABILIZE2D, "Stabilize 2D", NODE_CLASS_DISTORT, 0); - node_type_socket_templates(&ntype, cmp_node_stabilize2d_in, cmp_node_stabilize2d_out); - ntype.initfunc_api = init; + cmp_node_type_base(&ntype, CMP_NODE_STABILIZE2D, "Stabilize 2D", NODE_CLASS_DISTORT, 0); + node_type_socket_templates(&ntype, cmp_node_stabilize2d_in, cmp_node_stabilize2d_out); + ntype.initfunc_api = init; - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_sunbeams.c b/source/blender/nodes/composite/nodes/node_composite_sunbeams.c index cc949eded38..cdea27efdfc 100644 --- a/source/blender/nodes/composite/nodes/node_composite_sunbeams.c +++ b/source/blender/nodes/composite/nodes/node_composite_sunbeams.c @@ -24,32 +24,33 @@ #include "node_composite_util.h" static bNodeSocketTemplate inputs[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate outputs[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; static void init(bNodeTree *UNUSED(ntree), bNode *node) { - NodeSunBeams *data = MEM_callocN(sizeof(NodeSunBeams), "sun beams node"); + NodeSunBeams *data = MEM_callocN(sizeof(NodeSunBeams), "sun beams node"); - data->source[0] = 0.5f; - data->source[1] = 0.5f; + data->source[0] = 0.5f; + data->source[1] = 0.5f; - node->storage = data; + node->storage = data; } void register_node_type_cmp_sunbeams(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_SUNBEAMS, "Sun Beams", NODE_CLASS_OP_FILTER, 0); - node_type_socket_templates(&ntype, inputs, outputs); - node_type_init(&ntype, init); - node_type_storage(&ntype, "NodeSunBeams", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_SUNBEAMS, "Sun Beams", NODE_CLASS_OP_FILTER, 0); + node_type_socket_templates(&ntype, inputs, outputs); + node_type_init(&ntype, init); + node_type_storage( + &ntype, "NodeSunBeams", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_switch.c b/source/blender/nodes/composite/nodes/node_composite_switch.c index 8ae4934f704..e4c44c5e340 100644 --- a/source/blender/nodes/composite/nodes/node_composite_switch.c +++ b/source/blender/nodes/composite/nodes/node_composite_switch.c @@ -25,23 +25,23 @@ /* **************** MIX RGB ******************** */ static bNodeSocketTemplate cmp_node_switch_in[] = { - { SOCK_RGBA, 1, N_("Off"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 1, N_("On"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Off"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 1, N_("On"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_switch_out[] = { - { SOCK_RGBA, 0, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; /* custom1 = mix type */ void register_node_type_cmp_switch(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_SWITCH, "Switch", NODE_CLASS_LAYOUT, 0); - node_type_socket_templates(&ntype, cmp_node_switch_in, cmp_node_switch_out); - node_type_size_preset(&ntype, NODE_SIZE_SMALL); - nodeRegisterType(&ntype); + cmp_node_type_base(&ntype, CMP_NODE_SWITCH, "Switch", NODE_CLASS_LAYOUT, 0); + node_type_socket_templates(&ntype, cmp_node_switch_in, cmp_node_switch_out); + node_type_size_preset(&ntype, NODE_SIZE_SMALL); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_switchview.c b/source/blender/nodes/composite/nodes/node_composite_switchview.c index b15e35e17ac..483185fa76b 100644 --- a/source/blender/nodes/composite/nodes/node_composite_switchview.c +++ b/source/blender/nodes/composite/nodes/node_composite_switchview.c @@ -27,118 +27,120 @@ /* **************** SWITCH VIEW ******************** */ static bNodeSocketTemplate cmp_node_switch_view_out[] = { - { SOCK_RGBA, 0, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; -static bNodeSocket *ntreeCompositSwitchViewAddSocket(bNodeTree *ntree, bNode *node, const char *name) +static bNodeSocket *ntreeCompositSwitchViewAddSocket(bNodeTree *ntree, + bNode *node, + const char *name) { - bNodeSocket *sock = nodeAddStaticSocket(ntree, node, SOCK_IN, SOCK_RGBA, PROP_NONE, NULL, name); - return sock; + bNodeSocket *sock = nodeAddStaticSocket(ntree, node, SOCK_IN, SOCK_RGBA, PROP_NONE, NULL, name); + return sock; } static void cmp_node_switch_view_sanitycheck(bNodeTree *ntree, bNode *node) { - bNodeSocket *sock; + bNodeSocket *sock; - if (!BLI_listbase_is_empty(&node->inputs)) - return; + if (!BLI_listbase_is_empty(&node->inputs)) + return; - sock = ntreeCompositSwitchViewAddSocket(ntree, node, "No View"); - sock->flag |= SOCK_HIDDEN; + sock = ntreeCompositSwitchViewAddSocket(ntree, node, "No View"); + sock->flag |= SOCK_HIDDEN; } static void cmp_node_switch_view_update(bNodeTree *ntree, bNode *node) { - bNodeSocket *sock; - SceneRenderView *srv; - Scene *scene = (Scene *)node->id; - - /* only update when called from the operator button */ - if (node->update != NODE_UPDATE_OPERATOR) - return; - - if (scene == NULL) { - nodeRemoveAllSockets(ntree, node); - /* make sure there is always one socket */ - cmp_node_switch_view_sanitycheck(ntree, node); - return; - } - - /* remove the views that were removed */ - sock = node->inputs.last; - while (sock) { - srv = BLI_findstring(&scene->r.views, sock->name, offsetof(SceneRenderView, name)); - - if (srv == NULL) { - bNodeSocket *sock_del = sock; - sock = sock->prev; - nodeRemoveSocket(ntree, node, sock_del); - } - else { - if (srv->viewflag & SCE_VIEW_DISABLE) - sock->flag |= SOCK_HIDDEN; - else - sock->flag &= ~SOCK_HIDDEN; - - sock = sock->prev; - } - } - - /* add the new views */ - for (srv = scene->r.views.first; srv; srv = srv->next) { - sock = BLI_findstring(&node->inputs, srv->name, offsetof(bNodeSocket, name)); - - if (sock == NULL) - sock = ntreeCompositSwitchViewAddSocket(ntree, node, srv->name); - - if (srv->viewflag & SCE_VIEW_DISABLE) - sock->flag |= SOCK_HIDDEN; - else - sock->flag &= ~SOCK_HIDDEN; - } - - /* make sure there is always one socket */ - cmp_node_switch_view_sanitycheck(ntree, node); + bNodeSocket *sock; + SceneRenderView *srv; + Scene *scene = (Scene *)node->id; + + /* only update when called from the operator button */ + if (node->update != NODE_UPDATE_OPERATOR) + return; + + if (scene == NULL) { + nodeRemoveAllSockets(ntree, node); + /* make sure there is always one socket */ + cmp_node_switch_view_sanitycheck(ntree, node); + return; + } + + /* remove the views that were removed */ + sock = node->inputs.last; + while (sock) { + srv = BLI_findstring(&scene->r.views, sock->name, offsetof(SceneRenderView, name)); + + if (srv == NULL) { + bNodeSocket *sock_del = sock; + sock = sock->prev; + nodeRemoveSocket(ntree, node, sock_del); + } + else { + if (srv->viewflag & SCE_VIEW_DISABLE) + sock->flag |= SOCK_HIDDEN; + else + sock->flag &= ~SOCK_HIDDEN; + + sock = sock->prev; + } + } + + /* add the new views */ + for (srv = scene->r.views.first; srv; srv = srv->next) { + sock = BLI_findstring(&node->inputs, srv->name, offsetof(bNodeSocket, name)); + + if (sock == NULL) + sock = ntreeCompositSwitchViewAddSocket(ntree, node, srv->name); + + if (srv->viewflag & SCE_VIEW_DISABLE) + sock->flag |= SOCK_HIDDEN; + else + sock->flag &= ~SOCK_HIDDEN; + } + + /* make sure there is always one socket */ + cmp_node_switch_view_sanitycheck(ntree, node); } static void init_switch_view(const bContext *C, PointerRNA *ptr) { - Scene *scene = CTX_data_scene(C); - bNodeTree *ntree = ptr->id.data; - bNode *node = ptr->data; - SceneRenderView *srv; - bNodeSocket *sock; - int nr; + Scene *scene = CTX_data_scene(C); + bNodeTree *ntree = ptr->id.data; + bNode *node = ptr->data; + SceneRenderView *srv; + bNodeSocket *sock; + int nr; - /* store scene for updates */ - node->id = (ID *)scene; + /* store scene for updates */ + node->id = (ID *)scene; - if (scene) { - RenderData *rd = &scene->r; + if (scene) { + RenderData *rd = &scene->r; - for (nr = 0, srv = rd->views.first; srv; srv = srv->next, nr++) { - sock = ntreeCompositSwitchViewAddSocket(ntree, node, srv->name); + for (nr = 0, srv = rd->views.first; srv; srv = srv->next, nr++) { + sock = ntreeCompositSwitchViewAddSocket(ntree, node, srv->name); - if ((srv->viewflag & SCE_VIEW_DISABLE)) - sock->flag |= SOCK_HIDDEN; - } - } + if ((srv->viewflag & SCE_VIEW_DISABLE)) + sock->flag |= SOCK_HIDDEN; + } + } - /* make sure there is always one socket */ - cmp_node_switch_view_sanitycheck(ntree, node); + /* make sure there is always one socket */ + cmp_node_switch_view_sanitycheck(ntree, node); } void register_node_type_cmp_switch_view(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_SWITCH_VIEW, "Switch View", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, NULL, cmp_node_switch_view_out); + cmp_node_type_base(&ntype, CMP_NODE_SWITCH_VIEW, "Switch View", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, NULL, cmp_node_switch_view_out); - ntype.initfunc_api = init_switch_view; + ntype.initfunc_api = init_switch_view; - node_type_update(&ntype, cmp_node_switch_view_update, NULL); + node_type_update(&ntype, cmp_node_switch_view_update, NULL); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_texture.c b/source/blender/nodes/composite/nodes/node_composite_texture.c index e3d80d8e790..bc6b5f4f5fb 100644 --- a/source/blender/nodes/composite/nodes/node_composite_texture.c +++ b/source/blender/nodes/composite/nodes/node_composite_texture.c @@ -21,27 +21,26 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" /* **************** TEXTURE ******************** */ static bNodeSocketTemplate cmp_node_texture_in[] = { - { SOCK_VECTOR, 1, N_("Offset"), 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_TRANSLATION}, - { SOCK_VECTOR, 1, N_("Scale"), 1.0f, 1.0f, 1.0f, 1.0f, -10.0f, 10.0f, PROP_XYZ}, - { -1, 0, "" }, + {SOCK_VECTOR, 1, N_("Offset"), 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_TRANSLATION}, + {SOCK_VECTOR, 1, N_("Scale"), 1.0f, 1.0f, 1.0f, 1.0f, -10.0f, 10.0f, PROP_XYZ}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_texture_out[] = { - { SOCK_FLOAT, 0, N_("Value")}, - { SOCK_RGBA, 0, N_("Color")}, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("Value")}, + {SOCK_RGBA, 0, N_("Color")}, + {-1, 0, ""}, }; void register_node_type_cmp_texture(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_TEXTURE, "Texture", NODE_CLASS_INPUT, NODE_PREVIEW); - node_type_socket_templates(&ntype, cmp_node_texture_in, cmp_node_texture_out); + cmp_node_type_base(&ntype, CMP_NODE_TEXTURE, "Texture", NODE_CLASS_INPUT, NODE_PREVIEW); + node_type_socket_templates(&ntype, cmp_node_texture_in, cmp_node_texture_out); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_tonemap.c b/source/blender/nodes/composite/nodes/node_composite_tonemap.c index 4f365496a8c..27c73989da2 100644 --- a/source/blender/nodes/composite/nodes/node_composite_tonemap.c +++ b/source/blender/nodes/composite/nodes/node_composite_tonemap.c @@ -21,42 +21,41 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" static bNodeSocketTemplate cmp_node_tonemap_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_tonemap_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; static void node_composit_init_tonemap(bNodeTree *UNUSED(ntree), bNode *node) { - NodeTonemap *ntm = MEM_callocN(sizeof(NodeTonemap), "node tonemap data"); - ntm->type = 1; - ntm->key = 0.18; - ntm->offset = 1; - ntm->gamma = 1; - ntm->f = 0; - ntm->m = 0; // actual value is set according to input - // default a of 1 works well with natural HDR images, but not always so for cgi. - // Maybe should use 0 or at least lower initial value instead - ntm->a = 1; - ntm->c = 0; - node->storage = ntm; + NodeTonemap *ntm = MEM_callocN(sizeof(NodeTonemap), "node tonemap data"); + ntm->type = 1; + ntm->key = 0.18; + ntm->offset = 1; + ntm->gamma = 1; + ntm->f = 0; + ntm->m = 0; // actual value is set according to input + // default a of 1 works well with natural HDR images, but not always so for cgi. + // Maybe should use 0 or at least lower initial value instead + ntm->a = 1; + ntm->c = 0; + node->storage = ntm; } void register_node_type_cmp_tonemap(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_TONEMAP, "Tonemap", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, cmp_node_tonemap_in, cmp_node_tonemap_out); - node_type_init(&ntype, node_composit_init_tonemap); - node_type_storage(&ntype, "NodeTonemap", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_TONEMAP, "Tonemap", NODE_CLASS_OP_COLOR, 0); + node_type_socket_templates(&ntype, cmp_node_tonemap_in, cmp_node_tonemap_out); + node_type_init(&ntype, node_composit_init_tonemap); + node_type_storage(&ntype, "NodeTonemap", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_trackpos.c b/source/blender/nodes/composite/nodes/node_composite_trackpos.c index ffbe583155d..0547fb878e3 100644 --- a/source/blender/nodes/composite/nodes/node_composite_trackpos.c +++ b/source/blender/nodes/composite/nodes/node_composite_trackpos.c @@ -21,31 +21,31 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" static bNodeSocketTemplate cmp_node_trackpos_out[] = { - { SOCK_FLOAT, 0, N_("X")}, - { SOCK_FLOAT, 0, N_("Y")}, - { SOCK_VECTOR, 0, N_("Speed"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_VELOCITY}, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("X")}, + {SOCK_FLOAT, 0, N_("Y")}, + {SOCK_VECTOR, 0, N_("Speed"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_VELOCITY}, + {-1, 0, ""}, }; static void init(bNodeTree *UNUSED(ntree), bNode *node) { - NodeTrackPosData *data = MEM_callocN(sizeof(NodeTrackPosData), "node track position data"); + NodeTrackPosData *data = MEM_callocN(sizeof(NodeTrackPosData), "node track position data"); - node->storage = data; + node->storage = data; } void register_node_type_cmp_trackpos(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_TRACKPOS, "Track Position", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, NULL, cmp_node_trackpos_out); - node_type_init(&ntype, init); - node_type_storage(&ntype, "NodeTrackPosData", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_TRACKPOS, "Track Position", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, NULL, cmp_node_trackpos_out); + node_type_init(&ntype, init); + node_type_storage( + &ntype, "NodeTrackPosData", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_transform.c b/source/blender/nodes/composite/nodes/node_composite_transform.c index 7819944d50b..70c27dac4ce 100644 --- a/source/blender/nodes/composite/nodes/node_composite_transform.c +++ b/source/blender/nodes/composite/nodes/node_composite_transform.c @@ -26,25 +26,25 @@ /* **************** Transform ******************** */ static bNodeSocketTemplate cmp_node_transform_in[] = { - { SOCK_RGBA, 1, N_("Image"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("X"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f}, - { SOCK_FLOAT, 1, N_("Y"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f}, - { SOCK_FLOAT, 1, N_("Angle"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f, PROP_ANGLE}, - { SOCK_FLOAT, 1, N_("Scale"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, CMP_SCALE_MAX}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("X"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f}, + {SOCK_FLOAT, 1, N_("Y"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f}, + {SOCK_FLOAT, 1, N_("Angle"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f, PROP_ANGLE}, + {SOCK_FLOAT, 1, N_("Scale"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, CMP_SCALE_MAX}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_transform_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; void register_node_type_cmp_transform(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_TRANSFORM, "Transform", NODE_CLASS_DISTORT, 0); - node_type_socket_templates(&ntype, cmp_node_transform_in, cmp_node_transform_out); + cmp_node_type_base(&ntype, CMP_NODE_TRANSFORM, "Transform", NODE_CLASS_DISTORT, 0); + node_type_socket_templates(&ntype, cmp_node_transform_in, cmp_node_transform_out); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_translate.c b/source/blender/nodes/composite/nodes/node_composite_translate.c index e2973eaf037..a56014dce1f 100644 --- a/source/blender/nodes/composite/nodes/node_composite_translate.c +++ b/source/blender/nodes/composite/nodes/node_composite_translate.c @@ -21,37 +21,36 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" - /* **************** Translate ******************** */ static bNodeSocketTemplate cmp_node_translate_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("X"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("Y"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f, PROP_NONE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("X"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("Y"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_translate_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; static void node_composit_init_translate(bNodeTree *UNUSED(ntree), bNode *node) { - NodeTranslateData *data = MEM_callocN(sizeof(NodeTranslateData), "node translate data"); - node->storage = data; + NodeTranslateData *data = MEM_callocN(sizeof(NodeTranslateData), "node translate data"); + node->storage = data; } void register_node_type_cmp_translate(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_TRANSLATE, "Translate", NODE_CLASS_DISTORT, 0); - node_type_socket_templates(&ntype, cmp_node_translate_in, cmp_node_translate_out); - node_type_init(&ntype, node_composit_init_translate); - node_type_storage(&ntype, "NodeTranslateData", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_TRANSLATE, "Translate", NODE_CLASS_DISTORT, 0); + node_type_socket_templates(&ntype, cmp_node_translate_in, cmp_node_translate_out); + node_type_init(&ntype, node_composit_init_translate); + node_type_storage( + &ntype, "NodeTranslateData", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_valToRgb.c b/source/blender/nodes/composite/nodes/node_composite_valToRgb.c index c135dac98d3..407ad502d79 100644 --- a/source/blender/nodes/composite/nodes/node_composite_valToRgb.c +++ b/source/blender/nodes/composite/nodes/node_composite_valToRgb.c @@ -21,58 +21,54 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" - /* **************** VALTORGB ******************** */ static bNodeSocketTemplate cmp_node_valtorgb_in[] = { - { SOCK_FLOAT, 1, N_("Fac"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Fac"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_valtorgb_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { SOCK_FLOAT, 0, N_("Alpha")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {SOCK_FLOAT, 0, N_("Alpha")}, + {-1, 0, ""}, }; static void node_composit_init_valtorgb(bNodeTree *UNUSED(ntree), bNode *node) { - node->storage = BKE_colorband_add(true); + node->storage = BKE_colorband_add(true); } void register_node_type_cmp_valtorgb(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, cmp_node_valtorgb_in, cmp_node_valtorgb_out); - node_type_size(&ntype, 240, 200, 320); - node_type_init(&ntype, node_composit_init_valtorgb); - node_type_storage(&ntype, "ColorBand", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, cmp_node_valtorgb_in, cmp_node_valtorgb_out); + node_type_size(&ntype, 240, 200, 320); + node_type_init(&ntype, node_composit_init_valtorgb); + node_type_storage(&ntype, "ColorBand", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } - - /* **************** RGBTOBW ******************** */ static bNodeSocketTemplate cmp_node_rgbtobw_in[] = { - { SOCK_RGBA, 1, N_("Image"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_rgbtobw_out[] = { - { SOCK_FLOAT, 0, N_("Val"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("Val"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; void register_node_type_cmp_rgbtobw(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, cmp_node_rgbtobw_in, cmp_node_rgbtobw_out); - node_type_size_preset(&ntype, NODE_SIZE_SMALL); + cmp_node_type_base(&ntype, CMP_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, cmp_node_rgbtobw_in, cmp_node_rgbtobw_out); + node_type_size_preset(&ntype, NODE_SIZE_SMALL); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_value.c b/source/blender/nodes/composite/nodes/node_composite_value.c index ecccb5d563e..9bfffee450a 100644 --- a/source/blender/nodes/composite/nodes/node_composite_value.c +++ b/source/blender/nodes/composite/nodes/node_composite_value.c @@ -21,22 +21,21 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" /* **************** VALUE ******************** */ static bNodeSocketTemplate cmp_node_value_out[] = { - { SOCK_FLOAT, 0, N_("Value"), 0.5f, 0, 0, 0, -FLT_MAX, FLT_MAX, PROP_NONE}, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("Value"), 0.5f, 0, 0, 0, -FLT_MAX, FLT_MAX, PROP_NONE}, + {-1, 0, ""}, }; void register_node_type_cmp_value(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_VALUE, "Value", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, NULL, cmp_node_value_out); - node_type_size_preset(&ntype, NODE_SIZE_SMALL); + cmp_node_type_base(&ntype, CMP_NODE_VALUE, "Value", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, NULL, cmp_node_value_out); + node_type_size_preset(&ntype, NODE_SIZE_SMALL); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_vecBlur.c b/source/blender/nodes/composite/nodes/node_composite_vecBlur.c index a21b5350d38..f1f44d07084 100644 --- a/source/blender/nodes/composite/nodes/node_composite_vecBlur.c +++ b/source/blender/nodes/composite/nodes/node_composite_vecBlur.c @@ -21,39 +21,34 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" - /* **************** VECTOR BLUR ******************** */ static bNodeSocketTemplate cmp_node_vecblur_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Z"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_VECTOR, 1, N_("Speed"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_VELOCITY}, - { -1, 0, "" } -}; -static bNodeSocketTemplate cmp_node_vecblur_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" } -}; + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Z"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, + {SOCK_VECTOR, 1, N_("Speed"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_VELOCITY}, + {-1, 0, ""}}; +static bNodeSocketTemplate cmp_node_vecblur_out[] = {{SOCK_RGBA, 0, N_("Image")}, {-1, 0, ""}}; static void node_composit_init_vecblur(bNodeTree *UNUSED(ntree), bNode *node) { - NodeBlurData *nbd = MEM_callocN(sizeof(NodeBlurData), "node blur data"); - node->storage = nbd; - nbd->samples = 32; - nbd->fac = 1.0f; + NodeBlurData *nbd = MEM_callocN(sizeof(NodeBlurData), "node blur data"); + node->storage = nbd; + nbd->samples = 32; + nbd->fac = 1.0f; } /* custom1: itterations, custom2: maxspeed (0 = nolimit) */ void register_node_type_cmp_vecblur(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_VECBLUR, "Vector Blur", NODE_CLASS_OP_FILTER, 0); - node_type_socket_templates(&ntype, cmp_node_vecblur_in, cmp_node_vecblur_out); - node_type_init(&ntype, node_composit_init_vecblur); - node_type_storage(&ntype, "NodeBlurData", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_VECBLUR, "Vector Blur", NODE_CLASS_OP_FILTER, 0); + node_type_socket_templates(&ntype, cmp_node_vecblur_in, cmp_node_vecblur_out); + node_type_init(&ntype, node_composit_init_vecblur); + node_type_storage( + &ntype, "NodeBlurData", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_viewer.c b/source/blender/nodes/composite/nodes/node_composite_viewer.c index 7248f80a646..b7b7ed4c16a 100644 --- a/source/blender/nodes/composite/nodes/node_composite_viewer.c +++ b/source/blender/nodes/composite/nodes/node_composite_viewer.c @@ -21,43 +21,40 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" #include "BKE_image.h" #include "BKE_global.h" - /* **************** VIEWER ******************** */ static bNodeSocketTemplate cmp_node_viewer_in[] = { - { SOCK_RGBA, 1, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Alpha"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("Z"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, - { -1, 0, "" } -}; + {SOCK_RGBA, 1, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Alpha"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("Z"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, + {-1, 0, ""}}; static void node_composit_init_viewer(bNodeTree *UNUSED(ntree), bNode *node) { - ImageUser *iuser = MEM_callocN(sizeof(ImageUser), "node image user"); - node->storage = iuser; - iuser->sfra = 1; - iuser->ok = 1; - node->custom3 = 0.5f; - node->custom4 = 0.5f; - - node->id = (ID *)BKE_image_verify_viewer(G.main, IMA_TYPE_COMPOSITE, "Viewer Node"); + ImageUser *iuser = MEM_callocN(sizeof(ImageUser), "node image user"); + node->storage = iuser; + iuser->sfra = 1; + iuser->ok = 1; + node->custom3 = 0.5f; + node->custom4 = 0.5f; + + node->id = (ID *)BKE_image_verify_viewer(G.main, IMA_TYPE_COMPOSITE, "Viewer Node"); } void register_node_type_cmp_viewer(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_VIEWER, "Viewer", NODE_CLASS_OUTPUT, NODE_PREVIEW); - node_type_socket_templates(&ntype, cmp_node_viewer_in, NULL); - node_type_init(&ntype, node_composit_init_viewer); - node_type_storage(&ntype, "ImageUser", node_free_standard_storage, node_copy_standard_storage); + cmp_node_type_base(&ntype, CMP_NODE_VIEWER, "Viewer", NODE_CLASS_OUTPUT, NODE_PREVIEW); + node_type_socket_templates(&ntype, cmp_node_viewer_in, NULL); + node_type_init(&ntype, node_composit_init_viewer); + node_type_storage(&ntype, "ImageUser", node_free_standard_storage, node_copy_standard_storage); - node_type_internal_links(&ntype, NULL); + node_type_internal_links(&ntype, NULL); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_zcombine.c b/source/blender/nodes/composite/nodes/node_composite_zcombine.c index dfda0d1e4a6..c22030d62f0 100644 --- a/source/blender/nodes/composite/nodes/node_composite_zcombine.c +++ b/source/blender/nodes/composite/nodes/node_composite_zcombine.c @@ -21,31 +21,29 @@ * \ingroup cmpnodes */ - #include "node_composite_util.h" - /* **************** Z COMBINE ******************** */ - /* lazy coder note: node->custom2 is abused to send signal */ +/* lazy coder note: node->custom2 is abused to send signal */ static bNodeSocketTemplate cmp_node_zcombine_in[] = { - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Z"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 10000.0f, PROP_NONE}, - { SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Z"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 10000.0f, PROP_NONE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Z"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 10000.0f, PROP_NONE}, + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Z"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 10000.0f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate cmp_node_zcombine_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { SOCK_FLOAT, 0, N_("Z")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {SOCK_FLOAT, 0, N_("Z")}, + {-1, 0, ""}, }; void register_node_type_cmp_zcombine(void) { - static bNodeType ntype; + static bNodeType ntype; - cmp_node_type_base(&ntype, CMP_NODE_ZCOMBINE, "Z Combine", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, cmp_node_zcombine_in, cmp_node_zcombine_out); + cmp_node_type_base(&ntype, CMP_NODE_ZCOMBINE, "Z Combine", NODE_CLASS_OP_COLOR, 0); + node_type_socket_templates(&ntype, cmp_node_zcombine_in, cmp_node_zcombine_out); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/intern/node_common.c b/source/blender/nodes/intern/node_common.c index 88fdc53c856..d9ea6425b01 100644 --- a/source/blender/nodes/intern/node_common.c +++ b/source/blender/nodes/intern/node_common.c @@ -43,280 +43,280 @@ #include "NOD_common.h" enum { - REFINE_FORWARD = 1 << 0, - REFINE_BACKWARD = 1 << 1, + REFINE_FORWARD = 1 << 0, + REFINE_BACKWARD = 1 << 1, }; /**** Group ****/ bNodeSocket *node_group_find_input_socket(bNode *groupnode, const char *identifier) { - bNodeSocket *sock; - for (sock = groupnode->inputs.first; sock; sock = sock->next) - if (STREQ(sock->identifier, identifier)) - return sock; - return NULL; + bNodeSocket *sock; + for (sock = groupnode->inputs.first; sock; sock = sock->next) + if (STREQ(sock->identifier, identifier)) + return sock; + return NULL; } bNodeSocket *node_group_find_output_socket(bNode *groupnode, const char *identifier) { - bNodeSocket *sock; - for (sock = groupnode->outputs.first; sock; sock = sock->next) - if (STREQ(sock->identifier, identifier)) - return sock; - return NULL; + bNodeSocket *sock; + for (sock = groupnode->outputs.first; sock; sock = sock->next) + if (STREQ(sock->identifier, identifier)) + return sock; + return NULL; } /* groups display their internal tree name as label */ void node_group_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen) { - BLI_strncpy(label, (node->id) ? node->id->name + 2 : IFACE_("Missing Data-Block"), maxlen); + BLI_strncpy(label, (node->id) ? node->id->name + 2 : IFACE_("Missing Data-Block"), maxlen); } bool node_group_poll_instance(bNode *node, bNodeTree *nodetree) { - if (node->typeinfo->poll(node->typeinfo, nodetree)) { - bNodeTree *grouptree = (bNodeTree *)node->id; - if (grouptree) - return nodeGroupPoll(nodetree, grouptree); - else - return true; /* without a linked node tree, group node is always ok */ - } - else - return false; + if (node->typeinfo->poll(node->typeinfo, nodetree)) { + bNodeTree *grouptree = (bNodeTree *)node->id; + if (grouptree) + return nodeGroupPoll(nodetree, grouptree); + else + return true; /* without a linked node tree, group node is always ok */ + } + else + return false; } int nodeGroupPoll(bNodeTree *nodetree, bNodeTree *grouptree) { - bNode *node; - int valid = 1; - - /* unspecified node group, generally allowed - * (if anything, should be avoided on operator level) - */ - if (grouptree == NULL) - return 1; - - if (nodetree == grouptree) - return 0; - - for (node = grouptree->nodes.first; node; node = node->next) { - if (node->typeinfo->poll_instance && !node->typeinfo->poll_instance(node, nodetree)) { - valid = 0; - break; - } - } - return valid; + bNode *node; + int valid = 1; + + /* unspecified node group, generally allowed + * (if anything, should be avoided on operator level) + */ + if (grouptree == NULL) + return 1; + + if (nodetree == grouptree) + return 0; + + for (node = grouptree->nodes.first; node; node = node->next) { + if (node->typeinfo->poll_instance && !node->typeinfo->poll_instance(node, nodetree)) { + valid = 0; + break; + } + } + return valid; } /* used for both group nodes and interface nodes */ -static bNodeSocket *group_verify_socket(bNodeTree *ntree, bNode *gnode, bNodeSocket *iosock, ListBase *verify_lb, int in_out) +static bNodeSocket *group_verify_socket( + bNodeTree *ntree, bNode *gnode, bNodeSocket *iosock, ListBase *verify_lb, int in_out) { - bNodeSocket *sock; + bNodeSocket *sock; - for (sock = verify_lb->first; sock; sock = sock->next) { - if (STREQ(sock->identifier, iosock->identifier)) - break; - } - if (sock) { - strcpy(sock->name, iosock->name); + for (sock = verify_lb->first; sock; sock = sock->next) { + if (STREQ(sock->identifier, iosock->identifier)) + break; + } + if (sock) { + strcpy(sock->name, iosock->name); - if (iosock->typeinfo->interface_verify_socket) - iosock->typeinfo->interface_verify_socket(ntree, iosock, gnode, sock, "interface"); - } - else { - sock = nodeAddSocket(ntree, gnode, in_out, iosock->idname, iosock->identifier, iosock->name); + if (iosock->typeinfo->interface_verify_socket) + iosock->typeinfo->interface_verify_socket(ntree, iosock, gnode, sock, "interface"); + } + else { + sock = nodeAddSocket(ntree, gnode, in_out, iosock->idname, iosock->identifier, iosock->name); - if (iosock->typeinfo->interface_init_socket) - iosock->typeinfo->interface_init_socket(ntree, iosock, gnode, sock, "interface"); - } + if (iosock->typeinfo->interface_init_socket) + iosock->typeinfo->interface_init_socket(ntree, iosock, gnode, sock, "interface"); + } - /* remove from list temporarily, to distinguish from orphaned sockets */ - BLI_remlink(verify_lb, sock); + /* remove from list temporarily, to distinguish from orphaned sockets */ + BLI_remlink(verify_lb, sock); - return sock; + return sock; } /* used for both group nodes and interface nodes */ -static void group_verify_socket_list(bNodeTree *ntree, bNode *gnode, - ListBase *iosock_lb, ListBase *verify_lb, int in_out) +static void group_verify_socket_list( + bNodeTree *ntree, bNode *gnode, ListBase *iosock_lb, ListBase *verify_lb, int in_out) { - bNodeSocket *iosock, *sock, *nextsock; - - /* step by step compare */ - - iosock = iosock_lb->first; - for (; iosock; iosock = iosock->next) { - /* abusing new_sock pointer for verification here! only used inside this function */ - iosock->new_sock = group_verify_socket(ntree, gnode, iosock, verify_lb, in_out); - } - /* leftovers are removed */ - for (sock = verify_lb->first; sock; sock = nextsock) { - nextsock = sock->next; - nodeRemoveSocket(ntree, gnode, sock); - } - /* and we put back the verified sockets */ - iosock = iosock_lb->first; - for (; iosock; iosock = iosock->next) { - if (iosock->new_sock) { - BLI_addtail(verify_lb, iosock->new_sock); - iosock->new_sock = NULL; - } - } + bNodeSocket *iosock, *sock, *nextsock; + + /* step by step compare */ + + iosock = iosock_lb->first; + for (; iosock; iosock = iosock->next) { + /* abusing new_sock pointer for verification here! only used inside this function */ + iosock->new_sock = group_verify_socket(ntree, gnode, iosock, verify_lb, in_out); + } + /* leftovers are removed */ + for (sock = verify_lb->first; sock; sock = nextsock) { + nextsock = sock->next; + nodeRemoveSocket(ntree, gnode, sock); + } + /* and we put back the verified sockets */ + iosock = iosock_lb->first; + for (; iosock; iosock = iosock->next) { + if (iosock->new_sock) { + BLI_addtail(verify_lb, iosock->new_sock); + iosock->new_sock = NULL; + } + } } /* make sure all group node in ntree, which use ngroup, are sync'd */ void node_group_verify(struct bNodeTree *ntree, struct bNode *node, struct ID *id) { - /* check inputs and outputs, and remove or insert them */ - if (id == node->id) { - if (id == NULL) { - nodeRemoveAllSockets(ntree, node); - } - else { - bNodeTree *ngroup = (bNodeTree *)node->id; - group_verify_socket_list(ntree, node, &ngroup->inputs, &node->inputs, SOCK_IN); - group_verify_socket_list(ntree, node, &ngroup->outputs, &node->outputs, SOCK_OUT); - } - } + /* check inputs and outputs, and remove or insert them */ + if (id == node->id) { + if (id == NULL) { + nodeRemoveAllSockets(ntree, node); + } + else { + bNodeTree *ngroup = (bNodeTree *)node->id; + group_verify_socket_list(ntree, node, &ngroup->inputs, &node->inputs, SOCK_IN); + group_verify_socket_list(ntree, node, &ngroup->outputs, &node->outputs, SOCK_OUT); + } + } } /**** FRAME ****/ static void node_frame_init(bNodeTree *UNUSED(ntree), bNode *node) { - NodeFrame *data = (NodeFrame *)MEM_callocN(sizeof(NodeFrame), "frame node storage"); - node->storage = data; + NodeFrame *data = (NodeFrame *)MEM_callocN(sizeof(NodeFrame), "frame node storage"); + node->storage = data; - data->flag |= NODE_FRAME_SHRINK; + data->flag |= NODE_FRAME_SHRINK; - data->label_size = 20; + data->label_size = 20; } void register_node_type_frame(void) { - /* frame type is used for all tree types, needs dynamic allocation */ - bNodeType *ntype = MEM_callocN(sizeof(bNodeType), "frame node type"); + /* frame type is used for all tree types, needs dynamic allocation */ + bNodeType *ntype = MEM_callocN(sizeof(bNodeType), "frame node type"); - node_type_base(ntype, NODE_FRAME, "Frame", NODE_CLASS_LAYOUT, NODE_BACKGROUND); - node_type_init(ntype, node_frame_init); - node_type_storage(ntype, "NodeFrame", node_free_standard_storage, node_copy_standard_storage); - node_type_size(ntype, 150, 100, 0); + node_type_base(ntype, NODE_FRAME, "Frame", NODE_CLASS_LAYOUT, NODE_BACKGROUND); + node_type_init(ntype, node_frame_init); + node_type_storage(ntype, "NodeFrame", node_free_standard_storage, node_copy_standard_storage); + node_type_size(ntype, 150, 100, 0); - ntype->needs_free = 1; - nodeRegisterType(ntype); + ntype->needs_free = 1; + nodeRegisterType(ntype); } - /* **************** REROUTE ******************** */ /* simple, only a single input and output here */ static void node_reroute_update_internal_links(bNodeTree *ntree, bNode *node) { - bNodeLink *link; - - /* Security check! */ - if (!ntree) - return; - - link = MEM_callocN(sizeof(bNodeLink), "internal node link"); - link->fromnode = node; - link->fromsock = node->inputs.first; - link->tonode = node; - link->tosock = node->outputs.first; - /* internal link is always valid */ - link->flag |= NODE_LINK_VALID; - BLI_addtail(&node->internal_links, link); + bNodeLink *link; + + /* Security check! */ + if (!ntree) + return; + + link = MEM_callocN(sizeof(bNodeLink), "internal node link"); + link->fromnode = node; + link->fromsock = node->inputs.first; + link->tonode = node; + link->tosock = node->outputs.first; + /* internal link is always valid */ + link->flag |= NODE_LINK_VALID; + BLI_addtail(&node->internal_links, link); } static void node_reroute_init(bNodeTree *ntree, bNode *node) { - /* Note: Cannot use socket templates for this, since it would reset the socket type - * on each file read via the template verification procedure. - */ - nodeAddStaticSocket(ntree, node, SOCK_IN, SOCK_RGBA, PROP_NONE, "Input", "Input"); - nodeAddStaticSocket(ntree, node, SOCK_OUT, SOCK_RGBA, PROP_NONE, "Output", "Output"); + /* Note: Cannot use socket templates for this, since it would reset the socket type + * on each file read via the template verification procedure. + */ + nodeAddStaticSocket(ntree, node, SOCK_IN, SOCK_RGBA, PROP_NONE, "Input", "Input"); + nodeAddStaticSocket(ntree, node, SOCK_OUT, SOCK_RGBA, PROP_NONE, "Output", "Output"); } void register_node_type_reroute(void) { - /* frame type is used for all tree types, needs dynamic allocation */ - bNodeType *ntype = MEM_callocN(sizeof(bNodeType), "frame node type"); + /* frame type is used for all tree types, needs dynamic allocation */ + bNodeType *ntype = MEM_callocN(sizeof(bNodeType), "frame node type"); - node_type_base(ntype, NODE_REROUTE, "Reroute", NODE_CLASS_LAYOUT, 0); - node_type_init(ntype, node_reroute_init); - node_type_internal_links(ntype, node_reroute_update_internal_links); + node_type_base(ntype, NODE_REROUTE, "Reroute", NODE_CLASS_LAYOUT, 0); + node_type_init(ntype, node_reroute_init); + node_type_internal_links(ntype, node_reroute_update_internal_links); - ntype->needs_free = 1; - nodeRegisterType(ntype); + ntype->needs_free = 1; + nodeRegisterType(ntype); } static void node_reroute_inherit_type_recursive(bNodeTree *ntree, bNode *node, int flag) { - bNodeSocket *input = node->inputs.first; - bNodeSocket *output = node->outputs.first; - bNodeLink *link; - int type = SOCK_FLOAT; - const char *type_idname = nodeStaticSocketType(type, PROP_NONE); - - /* XXX it would be a little bit more efficient to restrict actual updates - * to rerout nodes connected to an updated node, but there's no reliable flag - * to indicate updated nodes (node->update is not set on linking). - */ - - node->done = 1; - - /* recursive update */ - for (link = ntree->links.first; link; link = link->next) { - bNode *fromnode = link->fromnode; - bNode *tonode = link->tonode; - if (!tonode || !fromnode) - continue; - if (nodeLinkIsHidden(link)) - continue; - - if (flag & REFINE_FORWARD) { - if (tonode == node && fromnode->type == NODE_REROUTE && !fromnode->done) - node_reroute_inherit_type_recursive(ntree, fromnode, REFINE_FORWARD); - } - if (flag & REFINE_BACKWARD) { - if (fromnode == node && tonode->type == NODE_REROUTE && !tonode->done) - node_reroute_inherit_type_recursive(ntree, tonode, REFINE_BACKWARD); - } - } - - /* determine socket type from unambiguous input/output connection if possible */ - if (input->limit == 1 && input->link) { - type = input->link->fromsock->type; - type_idname = nodeStaticSocketType(type, PROP_NONE); - } - else if (output->limit == 1 && output->link) { - type = output->link->tosock->type; - type_idname = nodeStaticSocketType(type, PROP_NONE); - } - - if (input->type != type) { - bNodeSocket *ninput = nodeAddSocket(ntree, node, SOCK_IN, type_idname, "input", "Input"); - for (link = ntree->links.first; link; link = link->next) { - if (link->tosock == input) { - link->tosock = ninput; - ninput->link = link; - } - } - nodeRemoveSocket(ntree, node, input); - } - - if (output->type != type) { - bNodeSocket *noutput = nodeAddSocket(ntree, node, SOCK_OUT, type_idname, "output", "Output"); - for (link = ntree->links.first; link; link = link->next) { - if (link->fromsock == output) { - link->fromsock = noutput; - } - } - nodeRemoveSocket(ntree, node, output); - } - - nodeUpdateInternalLinks(ntree, node); + bNodeSocket *input = node->inputs.first; + bNodeSocket *output = node->outputs.first; + bNodeLink *link; + int type = SOCK_FLOAT; + const char *type_idname = nodeStaticSocketType(type, PROP_NONE); + + /* XXX it would be a little bit more efficient to restrict actual updates + * to rerout nodes connected to an updated node, but there's no reliable flag + * to indicate updated nodes (node->update is not set on linking). + */ + + node->done = 1; + + /* recursive update */ + for (link = ntree->links.first; link; link = link->next) { + bNode *fromnode = link->fromnode; + bNode *tonode = link->tonode; + if (!tonode || !fromnode) + continue; + if (nodeLinkIsHidden(link)) + continue; + + if (flag & REFINE_FORWARD) { + if (tonode == node && fromnode->type == NODE_REROUTE && !fromnode->done) + node_reroute_inherit_type_recursive(ntree, fromnode, REFINE_FORWARD); + } + if (flag & REFINE_BACKWARD) { + if (fromnode == node && tonode->type == NODE_REROUTE && !tonode->done) + node_reroute_inherit_type_recursive(ntree, tonode, REFINE_BACKWARD); + } + } + + /* determine socket type from unambiguous input/output connection if possible */ + if (input->limit == 1 && input->link) { + type = input->link->fromsock->type; + type_idname = nodeStaticSocketType(type, PROP_NONE); + } + else if (output->limit == 1 && output->link) { + type = output->link->tosock->type; + type_idname = nodeStaticSocketType(type, PROP_NONE); + } + + if (input->type != type) { + bNodeSocket *ninput = nodeAddSocket(ntree, node, SOCK_IN, type_idname, "input", "Input"); + for (link = ntree->links.first; link; link = link->next) { + if (link->tosock == input) { + link->tosock = ninput; + ninput->link = link; + } + } + nodeRemoveSocket(ntree, node, input); + } + + if (output->type != type) { + bNodeSocket *noutput = nodeAddSocket(ntree, node, SOCK_OUT, type_idname, "output", "Output"); + for (link = ntree->links.first; link; link = link->next) { + if (link->fromsock == output) { + link->fromsock = noutput; + } + } + nodeRemoveSocket(ntree, node, output); + } + + nodeUpdateInternalLinks(ntree, node); } /* Global update function for Reroute node types. @@ -324,256 +324,255 @@ static void node_reroute_inherit_type_recursive(bNodeTree *ntree, bNode *node, i */ void ntree_update_reroute_nodes(bNodeTree *ntree) { - bNode *node; + bNode *node; - /* clear tags */ - for (node = ntree->nodes.first; node; node = node->next) - node->done = 0; + /* clear tags */ + for (node = ntree->nodes.first; node; node = node->next) + node->done = 0; - for (node = ntree->nodes.first; node; node = node->next) - if (node->type == NODE_REROUTE && !node->done) - node_reroute_inherit_type_recursive(ntree, node, REFINE_FORWARD | REFINE_BACKWARD); + for (node = ntree->nodes.first; node; node = node->next) + if (node->type == NODE_REROUTE && !node->done) + node_reroute_inherit_type_recursive(ntree, node, REFINE_FORWARD | REFINE_BACKWARD); } static bool node_is_connected_to_output_recursive(bNodeTree *ntree, bNode *node) { - bNodeLink *link; - - /* avoid redundant checks, and infinite loops in case of cyclic node links */ - if (node->done) - return false; - node->done = 1; - - /* main test, done before child loop so it catches output nodes themselves as well */ - if (node->typeinfo->nclass == NODE_CLASS_OUTPUT && node->flag & NODE_DO_OUTPUT) - return true; - - /* test all connected nodes, first positive find is sufficient to return true */ - for (link = ntree->links.first; link; link = link->next) { - if (link->fromnode == node) { - if (node_is_connected_to_output_recursive(ntree, link->tonode)) - return true; - } - } - return false; + bNodeLink *link; + + /* avoid redundant checks, and infinite loops in case of cyclic node links */ + if (node->done) + return false; + node->done = 1; + + /* main test, done before child loop so it catches output nodes themselves as well */ + if (node->typeinfo->nclass == NODE_CLASS_OUTPUT && node->flag & NODE_DO_OUTPUT) + return true; + + /* test all connected nodes, first positive find is sufficient to return true */ + for (link = ntree->links.first; link; link = link->next) { + if (link->fromnode == node) { + if (node_is_connected_to_output_recursive(ntree, link->tonode)) + return true; + } + } + return false; } bool BKE_node_is_connected_to_output(bNodeTree *ntree, bNode *node) { - bNode *tnode; + bNode *tnode; - /* clear flags */ - for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) - tnode->done = 0; + /* clear flags */ + for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) + tnode->done = 0; - return node_is_connected_to_output_recursive(ntree, node); + return node_is_connected_to_output_recursive(ntree, node); } void BKE_node_tree_unlink_id(ID *id, struct bNodeTree *ntree) { - bNode *node; + bNode *node; - for (node = ntree->nodes.first; node; node = node->next) { - if (node->id == id) { - node->id = NULL; - } - } + for (node = ntree->nodes.first; node; node = node->next) { + if (node->id == id) { + node->id = NULL; + } + } } /**** GROUP_INPUT / GROUP_OUTPUT ****/ static void node_group_input_init(bNodeTree *ntree, bNode *node) { - node_group_input_verify(ntree, node, (ID *)ntree); + node_group_input_verify(ntree, node, (ID *)ntree); } bNodeSocket *node_group_input_find_socket(bNode *node, const char *identifier) { - bNodeSocket *sock; - for (sock = node->outputs.first; sock; sock = sock->next) - if (STREQ(sock->identifier, identifier)) - return sock; - return NULL; + bNodeSocket *sock; + for (sock = node->outputs.first; sock; sock = sock->next) + if (STREQ(sock->identifier, identifier)) + return sock; + return NULL; } void node_group_input_verify(bNodeTree *ntree, bNode *node, ID *id) { - /* check inputs and outputs, and remove or insert them */ - if (id == (ID *)ntree) { - /* value_in_out inverted for interface nodes to get correct socket value_property */ - group_verify_socket_list(ntree, node, &ntree->inputs, &node->outputs, SOCK_OUT); - - /* add virtual extension socket */ - nodeAddSocket(ntree, node, SOCK_OUT, "NodeSocketVirtual", "__extend__", ""); - } + /* check inputs and outputs, and remove or insert them */ + if (id == (ID *)ntree) { + /* value_in_out inverted for interface nodes to get correct socket value_property */ + group_verify_socket_list(ntree, node, &ntree->inputs, &node->outputs, SOCK_OUT); + + /* add virtual extension socket */ + nodeAddSocket(ntree, node, SOCK_OUT, "NodeSocketVirtual", "__extend__", ""); + } } static void node_group_input_update(bNodeTree *ntree, bNode *node) { - bNodeSocket *extsock = node->outputs.last; - bNodeLink *link, *linknext, *exposelink; - /* Adding a tree socket and verifying will remove the extension socket! - * This list caches the existing links from the extension socket - * so they can be recreated after verification. - */ - ListBase tmplinks; - - /* find links from the extension socket and store them */ - BLI_listbase_clear(&tmplinks); - for (link = ntree->links.first; link; link = linknext) { - linknext = link->next; - if (nodeLinkIsHidden(link)) - continue; - - if (link->fromsock == extsock) { - bNodeLink *tlink = MEM_callocN(sizeof(bNodeLink), "temporary link"); - *tlink = *link; - BLI_addtail(&tmplinks, tlink); - - nodeRemLink(ntree, link); - } - } - - /* find valid link to expose */ - exposelink = NULL; - for (link = tmplinks.first; link; link = link->next) { - /* XXX Multiple sockets can be connected to the extension socket at once, - * in that case the arbitrary first link determines name and type. - * This could be improved by choosing the "best" type among all links, - * whatever that means. - */ - if (link->tosock->type != SOCK_CUSTOM) { - exposelink = link; - break; - } - } - - if (exposelink) { - bNodeSocket *gsock, *newsock; - - gsock = ntreeAddSocketInterfaceFromSocket(ntree, exposelink->tonode, exposelink->tosock); - - node_group_input_verify(ntree, node, (ID *)ntree); - newsock = node_group_input_find_socket(node, gsock->identifier); - - /* redirect links from the extension socket */ - for (link = tmplinks.first; link; link = link->next) { - nodeAddLink(ntree, node, newsock, link->tonode, link->tosock); - } - - } - - BLI_freelistN(&tmplinks); + bNodeSocket *extsock = node->outputs.last; + bNodeLink *link, *linknext, *exposelink; + /* Adding a tree socket and verifying will remove the extension socket! + * This list caches the existing links from the extension socket + * so they can be recreated after verification. + */ + ListBase tmplinks; + + /* find links from the extension socket and store them */ + BLI_listbase_clear(&tmplinks); + for (link = ntree->links.first; link; link = linknext) { + linknext = link->next; + if (nodeLinkIsHidden(link)) + continue; + + if (link->fromsock == extsock) { + bNodeLink *tlink = MEM_callocN(sizeof(bNodeLink), "temporary link"); + *tlink = *link; + BLI_addtail(&tmplinks, tlink); + + nodeRemLink(ntree, link); + } + } + + /* find valid link to expose */ + exposelink = NULL; + for (link = tmplinks.first; link; link = link->next) { + /* XXX Multiple sockets can be connected to the extension socket at once, + * in that case the arbitrary first link determines name and type. + * This could be improved by choosing the "best" type among all links, + * whatever that means. + */ + if (link->tosock->type != SOCK_CUSTOM) { + exposelink = link; + break; + } + } + + if (exposelink) { + bNodeSocket *gsock, *newsock; + + gsock = ntreeAddSocketInterfaceFromSocket(ntree, exposelink->tonode, exposelink->tosock); + + node_group_input_verify(ntree, node, (ID *)ntree); + newsock = node_group_input_find_socket(node, gsock->identifier); + + /* redirect links from the extension socket */ + for (link = tmplinks.first; link; link = link->next) { + nodeAddLink(ntree, node, newsock, link->tonode, link->tosock); + } + } + + BLI_freelistN(&tmplinks); } void register_node_type_group_input(void) { - /* used for all tree types, needs dynamic allocation */ - bNodeType *ntype = MEM_callocN(sizeof(bNodeType), "node type"); + /* used for all tree types, needs dynamic allocation */ + bNodeType *ntype = MEM_callocN(sizeof(bNodeType), "node type"); - node_type_base(ntype, NODE_GROUP_INPUT, "Group Input", NODE_CLASS_INTERFACE, 0); - node_type_size(ntype, 140, 80, 400); - node_type_init(ntype, node_group_input_init); - node_type_update(ntype, node_group_input_update, node_group_input_verify); + node_type_base(ntype, NODE_GROUP_INPUT, "Group Input", NODE_CLASS_INTERFACE, 0); + node_type_size(ntype, 140, 80, 400); + node_type_init(ntype, node_group_input_init); + node_type_update(ntype, node_group_input_update, node_group_input_verify); - ntype->needs_free = 1; - nodeRegisterType(ntype); + ntype->needs_free = 1; + nodeRegisterType(ntype); } static void node_group_output_init(bNodeTree *ntree, bNode *node) { - node_group_output_verify(ntree, node, (ID *)ntree); + node_group_output_verify(ntree, node, (ID *)ntree); } bNodeSocket *node_group_output_find_socket(bNode *node, const char *identifier) { - bNodeSocket *sock; - for (sock = node->inputs.first; sock; sock = sock->next) - if (STREQ(sock->identifier, identifier)) - return sock; - return NULL; + bNodeSocket *sock; + for (sock = node->inputs.first; sock; sock = sock->next) + if (STREQ(sock->identifier, identifier)) + return sock; + return NULL; } void node_group_output_verify(bNodeTree *ntree, bNode *node, ID *id) { - /* check inputs and outputs, and remove or insert them */ - if (id == (ID *)ntree) { - /* value_in_out inverted for interface nodes to get correct socket value_property */ - group_verify_socket_list(ntree, node, &ntree->outputs, &node->inputs, SOCK_IN); - - /* add virtual extension socket */ - nodeAddSocket(ntree, node, SOCK_IN, "NodeSocketVirtual", "__extend__", ""); - } + /* check inputs and outputs, and remove or insert them */ + if (id == (ID *)ntree) { + /* value_in_out inverted for interface nodes to get correct socket value_property */ + group_verify_socket_list(ntree, node, &ntree->outputs, &node->inputs, SOCK_IN); + + /* add virtual extension socket */ + nodeAddSocket(ntree, node, SOCK_IN, "NodeSocketVirtual", "__extend__", ""); + } } static void node_group_output_update(bNodeTree *ntree, bNode *node) { - bNodeSocket *extsock = node->inputs.last; - bNodeLink *link, *linknext, *exposelink; - /* Adding a tree socket and verifying will remove the extension socket! - * This list caches the existing links to the extension socket - * so they can be recreated after verification. - */ - ListBase tmplinks; - - /* find links to the extension socket and store them */ - BLI_listbase_clear(&tmplinks); - for (link = ntree->links.first; link; link = linknext) { - linknext = link->next; - if (nodeLinkIsHidden(link)) - continue; - - if (link->tosock == extsock) { - bNodeLink *tlink = MEM_callocN(sizeof(bNodeLink), "temporary link"); - *tlink = *link; - BLI_addtail(&tmplinks, tlink); - - nodeRemLink(ntree, link); - } - } - - /* find valid link to expose */ - exposelink = NULL; - for (link = tmplinks.first; link; link = link->next) { - /* XXX Multiple sockets can be connected to the extension socket at once, - * in that case the arbitrary first link determines name and type. - * This could be improved by choosing the "best" type among all links, - * whatever that means. - */ - if (link->fromsock->type != SOCK_CUSTOM) { - exposelink = link; - break; - } - } - - if (exposelink) { - bNodeSocket *gsock, *newsock; - - /* XXX what if connecting virtual to virtual socket?? */ - gsock = ntreeAddSocketInterfaceFromSocket(ntree, exposelink->fromnode, exposelink->fromsock); - - node_group_output_verify(ntree, node, (ID *)ntree); - newsock = node_group_output_find_socket(node, gsock->identifier); - - /* redirect links to the extension socket */ - for (link = tmplinks.first; link; link = link->next) { - nodeAddLink(ntree, link->fromnode, link->fromsock, node, newsock); - } - } - - BLI_freelistN(&tmplinks); + bNodeSocket *extsock = node->inputs.last; + bNodeLink *link, *linknext, *exposelink; + /* Adding a tree socket and verifying will remove the extension socket! + * This list caches the existing links to the extension socket + * so they can be recreated after verification. + */ + ListBase tmplinks; + + /* find links to the extension socket and store them */ + BLI_listbase_clear(&tmplinks); + for (link = ntree->links.first; link; link = linknext) { + linknext = link->next; + if (nodeLinkIsHidden(link)) + continue; + + if (link->tosock == extsock) { + bNodeLink *tlink = MEM_callocN(sizeof(bNodeLink), "temporary link"); + *tlink = *link; + BLI_addtail(&tmplinks, tlink); + + nodeRemLink(ntree, link); + } + } + + /* find valid link to expose */ + exposelink = NULL; + for (link = tmplinks.first; link; link = link->next) { + /* XXX Multiple sockets can be connected to the extension socket at once, + * in that case the arbitrary first link determines name and type. + * This could be improved by choosing the "best" type among all links, + * whatever that means. + */ + if (link->fromsock->type != SOCK_CUSTOM) { + exposelink = link; + break; + } + } + + if (exposelink) { + bNodeSocket *gsock, *newsock; + + /* XXX what if connecting virtual to virtual socket?? */ + gsock = ntreeAddSocketInterfaceFromSocket(ntree, exposelink->fromnode, exposelink->fromsock); + + node_group_output_verify(ntree, node, (ID *)ntree); + newsock = node_group_output_find_socket(node, gsock->identifier); + + /* redirect links to the extension socket */ + for (link = tmplinks.first; link; link = link->next) { + nodeAddLink(ntree, link->fromnode, link->fromsock, node, newsock); + } + } + + BLI_freelistN(&tmplinks); } void register_node_type_group_output(void) { - /* used for all tree types, needs dynamic allocation */ - bNodeType *ntype = MEM_callocN(sizeof(bNodeType), "node type"); + /* used for all tree types, needs dynamic allocation */ + bNodeType *ntype = MEM_callocN(sizeof(bNodeType), "node type"); - node_type_base(ntype, NODE_GROUP_OUTPUT, "Group Output", NODE_CLASS_INTERFACE, 0); - node_type_size(ntype, 140, 80, 400); - node_type_init(ntype, node_group_output_init); - node_type_update(ntype, node_group_output_update, node_group_output_verify); + node_type_base(ntype, NODE_GROUP_OUTPUT, "Group Output", NODE_CLASS_INTERFACE, 0); + node_type_size(ntype, 140, 80, 400); + node_type_init(ntype, node_group_output_init); + node_type_update(ntype, node_group_output_update, node_group_output_verify); - ntype->needs_free = 1; - nodeRegisterType(ntype); + ntype->needs_free = 1; + nodeRegisterType(ntype); } diff --git a/source/blender/nodes/intern/node_common.h b/source/blender/nodes/intern/node_common.h index 14342d31204..c3314ae3c28 100644 --- a/source/blender/nodes/intern/node_common.h +++ b/source/blender/nodes/intern/node_common.h @@ -21,7 +21,6 @@ * \ingroup nodes */ - #ifndef __NODE_COMMON_H__ #define __NODE_COMMON_H__ diff --git a/source/blender/nodes/intern/node_exec.c b/source/blender/nodes/intern/node_exec.c index 97d93ee0fa5..ed3dbf4515b 100644 --- a/source/blender/nodes/intern/node_exec.c +++ b/source/blender/nodes/intern/node_exec.c @@ -21,7 +21,6 @@ * \ingroup nodes */ - #include "DNA_node_types.h" #include "BLI_listbase.h" @@ -35,275 +34,281 @@ #include "node_exec.h" #include "node_util.h" - /* supported socket types in old nodes */ int node_exec_socket_use_stack(bNodeSocket *sock) { - /* NOTE: INT supported as FLOAT. Only for EEVEE. */ - return ELEM(sock->type, SOCK_INT, SOCK_FLOAT, SOCK_VECTOR, SOCK_RGBA, SOCK_SHADER); + /* NOTE: INT supported as FLOAT. Only for EEVEE. */ + return ELEM(sock->type, SOCK_INT, SOCK_FLOAT, SOCK_VECTOR, SOCK_RGBA, SOCK_SHADER); } /* for a given socket, find the actual stack entry */ bNodeStack *node_get_socket_stack(bNodeStack *stack, bNodeSocket *sock) { - if (stack && sock && sock->stack_index >= 0) - return stack + sock->stack_index; - return NULL; + if (stack && sock && sock->stack_index >= 0) + return stack + sock->stack_index; + return NULL; } void node_get_stack(bNode *node, bNodeStack *stack, bNodeStack **in, bNodeStack **out) { - bNodeSocket *sock; - - /* build pointer stack */ - if (in) { - for (sock = node->inputs.first; sock; sock = sock->next) { - *(in++) = node_get_socket_stack(stack, sock); - } - } - - if (out) { - for (sock = node->outputs.first; sock; sock = sock->next) { - *(out++) = node_get_socket_stack(stack, sock); - } - } + bNodeSocket *sock; + + /* build pointer stack */ + if (in) { + for (sock = node->inputs.first; sock; sock = sock->next) { + *(in++) = node_get_socket_stack(stack, sock); + } + } + + if (out) { + for (sock = node->outputs.first; sock; sock = sock->next) { + *(out++) = node_get_socket_stack(stack, sock); + } + } } static void node_init_input_index(bNodeSocket *sock, int *index) { - /* Only consider existing link if from socket is valid! */ - if (sock->link && sock->link->fromsock && sock->link->fromsock->stack_index >= 0) { - sock->stack_index = sock->link->fromsock->stack_index; - } - else { - if (node_exec_socket_use_stack(sock)) - sock->stack_index = (*index)++; - else - sock->stack_index = -1; - } + /* Only consider existing link if from socket is valid! */ + if (sock->link && sock->link->fromsock && sock->link->fromsock->stack_index >= 0) { + sock->stack_index = sock->link->fromsock->stack_index; + } + else { + if (node_exec_socket_use_stack(sock)) + sock->stack_index = (*index)++; + else + sock->stack_index = -1; + } } static void node_init_output_index(bNodeSocket *sock, int *index, ListBase *internal_links) { - if (internal_links) { - bNodeLink *link; - /* copy the stack index from internally connected input to skip the node */ - for (link = internal_links->first; link; link = link->next) { - if (link->tosock == sock) { - sock->stack_index = link->fromsock->stack_index; - /* set the link pointer to indicate that this socket - * should not overwrite the stack value! - */ - sock->link = link; - break; - } - } - /* if not internally connected, assign a new stack index anyway to avoid bad stack access */ - if (!link) { - if (node_exec_socket_use_stack(sock)) - sock->stack_index = (*index)++; - else - sock->stack_index = -1; - } - } - else { - if (node_exec_socket_use_stack(sock)) - sock->stack_index = (*index)++; - else - sock->stack_index = -1; - } + if (internal_links) { + bNodeLink *link; + /* copy the stack index from internally connected input to skip the node */ + for (link = internal_links->first; link; link = link->next) { + if (link->tosock == sock) { + sock->stack_index = link->fromsock->stack_index; + /* set the link pointer to indicate that this socket + * should not overwrite the stack value! + */ + sock->link = link; + break; + } + } + /* if not internally connected, assign a new stack index anyway to avoid bad stack access */ + if (!link) { + if (node_exec_socket_use_stack(sock)) + sock->stack_index = (*index)++; + else + sock->stack_index = -1; + } + } + else { + if (node_exec_socket_use_stack(sock)) + sock->stack_index = (*index)++; + else + sock->stack_index = -1; + } } /* basic preparation of socket stacks */ -static struct bNodeStack *setup_stack(bNodeStack *stack, bNodeTree *ntree, bNode *node, bNodeSocket *sock) +static struct bNodeStack *setup_stack(bNodeStack *stack, + bNodeTree *ntree, + bNode *node, + bNodeSocket *sock) { - bNodeStack *ns = node_get_socket_stack(stack, sock); - if (!ns) - return NULL; - - /* don't mess with remote socket stacks, these are initialized by other nodes! */ - if (sock->link) - return ns; - - ns->sockettype = sock->type; - - switch (sock->type) { - case SOCK_FLOAT: - ns->vec[0] = node_socket_get_float(ntree, node, sock); - break; - case SOCK_VECTOR: - node_socket_get_vector(ntree, node, sock, ns->vec); - break; - case SOCK_RGBA: - node_socket_get_color(ntree, node, sock, ns->vec); - break; - } - - return ns; + bNodeStack *ns = node_get_socket_stack(stack, sock); + if (!ns) + return NULL; + + /* don't mess with remote socket stacks, these are initialized by other nodes! */ + if (sock->link) + return ns; + + ns->sockettype = sock->type; + + switch (sock->type) { + case SOCK_FLOAT: + ns->vec[0] = node_socket_get_float(ntree, node, sock); + break; + case SOCK_VECTOR: + node_socket_get_vector(ntree, node, sock, ns->vec); + break; + case SOCK_RGBA: + node_socket_get_color(ntree, node, sock, ns->vec); + break; + } + + return ns; } -bNodeTreeExec *ntree_exec_begin(bNodeExecContext *context, bNodeTree *ntree, bNodeInstanceKey parent_key) +bNodeTreeExec *ntree_exec_begin(bNodeExecContext *context, + bNodeTree *ntree, + bNodeInstanceKey parent_key) { - bNodeTreeExec *exec; - bNode *node; - bNodeExec *nodeexec; - bNodeInstanceKey nodekey; - bNodeSocket *sock; - bNodeStack *ns; - int index; - bNode **nodelist; - int totnodes, n; - /* XXX texnodes have threading issues with muting, have to disable it there ... */ - - /* ensure all sock->link pointers and node levels are correct */ - /* Using global main here is likely totally wrong, not sure what to do about that one though... - * We cannot even check ntree is in global main, since most of the time it won't be (thanks to ntree design)!!! */ - ntreeUpdateTree(G.main, ntree); - - /* get a dependency-sorted list of nodes */ - ntreeGetDependencyList(ntree, &nodelist, &totnodes); - - /* XXX could let callbacks do this for specialized data */ - exec = MEM_callocN(sizeof(bNodeTreeExec), "node tree execution data"); - /* backpointer to node tree */ - exec->nodetree = ntree; - - /* set stack indices */ - index = 0; - for (n = 0; n < totnodes; ++n) { - node = nodelist[n]; - - node->stack_index = index; - - /* init node socket stack indexes */ - for (sock = node->inputs.first; sock; sock = sock->next) - node_init_input_index(sock, &index); - - if (node->flag & NODE_MUTED || node->type == NODE_REROUTE) { - for (sock = node->outputs.first; sock; sock = sock->next) - node_init_output_index(sock, &index, &node->internal_links); - } - else { - for (sock = node->outputs.first; sock; sock = sock->next) - node_init_output_index(sock, &index, NULL); - } - } - - /* allocated exec data pointers for nodes */ - exec->totnodes = totnodes; - exec->nodeexec = MEM_callocN(exec->totnodes * sizeof(bNodeExec), "node execution data"); - /* allocate data pointer for node stack */ - exec->stacksize = index; - exec->stack = MEM_callocN(exec->stacksize * sizeof(bNodeStack), "bNodeStack"); - - /* all non-const results are considered inputs */ - for (n = 0; n < exec->stacksize; ++n) - exec->stack[n].hasinput = 1; - - /* prepare all nodes for execution */ - for (n = 0, nodeexec = exec->nodeexec; n < totnodes; ++n, ++nodeexec) { - node = nodeexec->node = nodelist[n]; - nodeexec->freeexecfunc = node->typeinfo->freeexecfunc; - - /* tag inputs */ - for (sock = node->inputs.first; sock; sock = sock->next) { - /* disable the node if an input link is invalid */ - if (sock->link && !(sock->link->flag & NODE_LINK_VALID)) - node->need_exec = 0; - - ns = setup_stack(exec->stack, ntree, node, sock); - if (ns) - ns->hasoutput = 1; - } - - /* tag all outputs */ - for (sock = node->outputs.first; sock; sock = sock->next) { - /* ns = */ setup_stack(exec->stack, ntree, node, sock); - } - - nodekey = BKE_node_instance_key(parent_key, ntree, node); - nodeexec->data.preview = context->previews ? BKE_node_instance_hash_lookup(context->previews, nodekey) : NULL; - if (node->typeinfo->initexecfunc) - nodeexec->data.data = node->typeinfo->initexecfunc(context, node, nodekey); - } - - if (nodelist) - MEM_freeN(nodelist); - - return exec; + bNodeTreeExec *exec; + bNode *node; + bNodeExec *nodeexec; + bNodeInstanceKey nodekey; + bNodeSocket *sock; + bNodeStack *ns; + int index; + bNode **nodelist; + int totnodes, n; + /* XXX texnodes have threading issues with muting, have to disable it there ... */ + + /* ensure all sock->link pointers and node levels are correct */ + /* Using global main here is likely totally wrong, not sure what to do about that one though... + * We cannot even check ntree is in global main, since most of the time it won't be (thanks to ntree design)!!! */ + ntreeUpdateTree(G.main, ntree); + + /* get a dependency-sorted list of nodes */ + ntreeGetDependencyList(ntree, &nodelist, &totnodes); + + /* XXX could let callbacks do this for specialized data */ + exec = MEM_callocN(sizeof(bNodeTreeExec), "node tree execution data"); + /* backpointer to node tree */ + exec->nodetree = ntree; + + /* set stack indices */ + index = 0; + for (n = 0; n < totnodes; ++n) { + node = nodelist[n]; + + node->stack_index = index; + + /* init node socket stack indexes */ + for (sock = node->inputs.first; sock; sock = sock->next) + node_init_input_index(sock, &index); + + if (node->flag & NODE_MUTED || node->type == NODE_REROUTE) { + for (sock = node->outputs.first; sock; sock = sock->next) + node_init_output_index(sock, &index, &node->internal_links); + } + else { + for (sock = node->outputs.first; sock; sock = sock->next) + node_init_output_index(sock, &index, NULL); + } + } + + /* allocated exec data pointers for nodes */ + exec->totnodes = totnodes; + exec->nodeexec = MEM_callocN(exec->totnodes * sizeof(bNodeExec), "node execution data"); + /* allocate data pointer for node stack */ + exec->stacksize = index; + exec->stack = MEM_callocN(exec->stacksize * sizeof(bNodeStack), "bNodeStack"); + + /* all non-const results are considered inputs */ + for (n = 0; n < exec->stacksize; ++n) + exec->stack[n].hasinput = 1; + + /* prepare all nodes for execution */ + for (n = 0, nodeexec = exec->nodeexec; n < totnodes; ++n, ++nodeexec) { + node = nodeexec->node = nodelist[n]; + nodeexec->freeexecfunc = node->typeinfo->freeexecfunc; + + /* tag inputs */ + for (sock = node->inputs.first; sock; sock = sock->next) { + /* disable the node if an input link is invalid */ + if (sock->link && !(sock->link->flag & NODE_LINK_VALID)) + node->need_exec = 0; + + ns = setup_stack(exec->stack, ntree, node, sock); + if (ns) + ns->hasoutput = 1; + } + + /* tag all outputs */ + for (sock = node->outputs.first; sock; sock = sock->next) { + /* ns = */ setup_stack(exec->stack, ntree, node, sock); + } + + nodekey = BKE_node_instance_key(parent_key, ntree, node); + nodeexec->data.preview = context->previews ? + BKE_node_instance_hash_lookup(context->previews, nodekey) : + NULL; + if (node->typeinfo->initexecfunc) + nodeexec->data.data = node->typeinfo->initexecfunc(context, node, nodekey); + } + + if (nodelist) + MEM_freeN(nodelist); + + return exec; } void ntree_exec_end(bNodeTreeExec *exec) { - bNodeExec *nodeexec; - int n; + bNodeExec *nodeexec; + int n; - if (exec->stack) - MEM_freeN(exec->stack); + if (exec->stack) + MEM_freeN(exec->stack); - for (n = 0, nodeexec = exec->nodeexec; n < exec->totnodes; ++n, ++nodeexec) { - if (nodeexec->freeexecfunc) - nodeexec->freeexecfunc(nodeexec->data.data); - } + for (n = 0, nodeexec = exec->nodeexec; n < exec->totnodes; ++n, ++nodeexec) { + if (nodeexec->freeexecfunc) + nodeexec->freeexecfunc(nodeexec->data.data); + } - if (exec->nodeexec) - MEM_freeN(exec->nodeexec); + if (exec->nodeexec) + MEM_freeN(exec->nodeexec); - MEM_freeN(exec); + MEM_freeN(exec); } /**** Material/Texture trees ****/ bNodeThreadStack *ntreeGetThreadStack(bNodeTreeExec *exec, int thread) { - ListBase *lb = &exec->threadstack[thread]; - bNodeThreadStack *nts; - - for (nts = lb->first; nts; nts = nts->next) { - if (!nts->used) { - nts->used = true; - break; - } - } - - if (!nts) { - nts = MEM_callocN(sizeof(bNodeThreadStack), "bNodeThreadStack"); - nts->stack = MEM_dupallocN(exec->stack); - nts->used = true; - BLI_addtail(lb, nts); - } - - return nts; + ListBase *lb = &exec->threadstack[thread]; + bNodeThreadStack *nts; + + for (nts = lb->first; nts; nts = nts->next) { + if (!nts->used) { + nts->used = true; + break; + } + } + + if (!nts) { + nts = MEM_callocN(sizeof(bNodeThreadStack), "bNodeThreadStack"); + nts->stack = MEM_dupallocN(exec->stack); + nts->used = true; + BLI_addtail(lb, nts); + } + + return nts; } void ntreeReleaseThreadStack(bNodeThreadStack *nts) { - nts->used = 0; + nts->used = 0; } bool ntreeExecThreadNodes(bNodeTreeExec *exec, bNodeThreadStack *nts, void *callerdata, int thread) { - bNodeStack *nsin[MAX_SOCKET] = {NULL}; /* arbitrary... watch this */ - bNodeStack *nsout[MAX_SOCKET] = {NULL}; /* arbitrary... watch this */ - bNodeExec *nodeexec; - bNode *node; - int n; - - /* nodes are presorted, so exec is in order of list */ - - for (n = 0, nodeexec = exec->nodeexec; n < exec->totnodes; ++n, ++nodeexec) { - node = nodeexec->node; - if (node->need_exec) { - node_get_stack(node, nts->stack, nsin, nsout); - /* Handle muted nodes... - * If the mute func is not set, assume the node should never be muted, - * and hence execute it! - */ - if (node->typeinfo->execfunc && !(node->flag & NODE_MUTED)) - node->typeinfo->execfunc(callerdata, thread, node, &nodeexec->data, nsin, nsout); - } - } - - /* signal to that all went OK, for render */ - return true; + bNodeStack *nsin[MAX_SOCKET] = {NULL}; /* arbitrary... watch this */ + bNodeStack *nsout[MAX_SOCKET] = {NULL}; /* arbitrary... watch this */ + bNodeExec *nodeexec; + bNode *node; + int n; + + /* nodes are presorted, so exec is in order of list */ + + for (n = 0, nodeexec = exec->nodeexec; n < exec->totnodes; ++n, ++nodeexec) { + node = nodeexec->node; + if (node->need_exec) { + node_get_stack(node, nts->stack, nsin, nsout); + /* Handle muted nodes... + * If the mute func is not set, assume the node should never be muted, + * and hence execute it! + */ + if (node->typeinfo->execfunc && !(node->flag & NODE_MUTED)) + node->typeinfo->execfunc(callerdata, thread, node, &nodeexec->data, nsin, nsout); + } + } + + /* signal to that all went OK, for render */ + return true; } diff --git a/source/blender/nodes/intern/node_exec.h b/source/blender/nodes/intern/node_exec.h index 145bee149d1..336a8f26ec3 100644 --- a/source/blender/nodes/intern/node_exec.h +++ b/source/blender/nodes/intern/node_exec.h @@ -21,7 +21,6 @@ * \ingroup nodes */ - #ifndef __NODE_EXEC_H__ #define __NODE_EXEC_H__ @@ -41,48 +40,61 @@ struct bNodeTree; /* Node execution data */ typedef struct bNodeExec { - struct bNode *node; /* backpointer to node */ - bNodeExecData data; + struct bNode *node; /* backpointer to node */ + bNodeExecData data; - NodeFreeExecFunction freeexecfunc; /* free function, stored in exec itself to avoid dangling node pointer access */ + NodeFreeExecFunction + freeexecfunc; /* free function, stored in exec itself to avoid dangling node pointer access */ } bNodeExec; /* Execution Data for each instance of node tree execution */ typedef struct bNodeTreeExec { - struct bNodeTree *nodetree; /* backpointer to node tree */ + struct bNodeTree *nodetree; /* backpointer to node tree */ - int totnodes; /* total node count */ - struct bNodeExec *nodeexec; /* per-node execution data */ + int totnodes; /* total node count */ + struct bNodeExec *nodeexec; /* per-node execution data */ - int stacksize; - struct bNodeStack *stack; /* socket data stack */ - /* only used by material and texture trees to keep one stack for each thread */ - ListBase *threadstack; /* one instance of the stack for each thread */ + int stacksize; + struct bNodeStack *stack; /* socket data stack */ + /* only used by material and texture trees to keep one stack for each thread */ + ListBase *threadstack; /* one instance of the stack for each thread */ } bNodeTreeExec; /* stores one stack copy for each thread (material and texture trees) */ typedef struct bNodeThreadStack { - struct bNodeThreadStack *next, *prev; - struct bNodeStack *stack; - bool used; + struct bNodeThreadStack *next, *prev; + struct bNodeStack *stack; + bool used; } bNodeThreadStack; int node_exec_socket_use_stack(struct bNodeSocket *sock); struct bNodeStack *node_get_socket_stack(struct bNodeStack *stack, struct bNodeSocket *sock); -void node_get_stack(struct bNode *node, struct bNodeStack *stack, struct bNodeStack **in, struct bNodeStack **out); - -struct bNodeTreeExec *ntree_exec_begin(struct bNodeExecContext *context, struct bNodeTree *ntree, bNodeInstanceKey parent_key); +void node_get_stack(struct bNode *node, + struct bNodeStack *stack, + struct bNodeStack **in, + struct bNodeStack **out); + +struct bNodeTreeExec *ntree_exec_begin(struct bNodeExecContext *context, + struct bNodeTree *ntree, + bNodeInstanceKey parent_key); void ntree_exec_end(struct bNodeTreeExec *exec); struct bNodeThreadStack *ntreeGetThreadStack(struct bNodeTreeExec *exec, int thread); void ntreeReleaseThreadStack(struct bNodeThreadStack *nts); -bool ntreeExecThreadNodes(struct bNodeTreeExec *exec, struct bNodeThreadStack *nts, void *callerdata, int thread); - -struct bNodeTreeExec *ntreeShaderBeginExecTree_internal(struct bNodeExecContext *context, struct bNodeTree *ntree, bNodeInstanceKey parent_key); +bool ntreeExecThreadNodes(struct bNodeTreeExec *exec, + struct bNodeThreadStack *nts, + void *callerdata, + int thread); + +struct bNodeTreeExec *ntreeShaderBeginExecTree_internal(struct bNodeExecContext *context, + struct bNodeTree *ntree, + bNodeInstanceKey parent_key); void ntreeShaderEndExecTree_internal(struct bNodeTreeExec *exec); -struct bNodeTreeExec *ntreeTexBeginExecTree_internal(struct bNodeExecContext *context, struct bNodeTree *ntree, bNodeInstanceKey parent_key); +struct bNodeTreeExec *ntreeTexBeginExecTree_internal(struct bNodeExecContext *context, + struct bNodeTree *ntree, + bNodeInstanceKey parent_key); void ntreeTexEndExecTree_internal(struct bNodeTreeExec *exec); #endif diff --git a/source/blender/nodes/intern/node_socket.c b/source/blender/nodes/intern/node_socket.c index 351e579d924..9fe6e0bcecb 100644 --- a/source/blender/nodes/intern/node_socket.c +++ b/source/blender/nodes/intern/node_socket.c @@ -41,439 +41,443 @@ struct Main; -struct bNodeSocket *node_add_socket_from_template(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocketTemplate *stemp, int in_out) +struct bNodeSocket *node_add_socket_from_template(struct bNodeTree *ntree, + struct bNode *node, + struct bNodeSocketTemplate *stemp, + int in_out) { - bNodeSocket *sock = nodeAddStaticSocket(ntree, node, in_out, stemp->type, stemp->subtype, stemp->identifier, stemp->name); - - sock->flag |= stemp->flag; - - /* initialize default_value */ - switch (stemp->type) { - case SOCK_FLOAT: - { - bNodeSocketValueFloat *dval = sock->default_value; - dval->value = stemp->val1; - dval->min = stemp->min; - dval->max = stemp->max; - break; - } - case SOCK_INT: - { - bNodeSocketValueInt *dval = sock->default_value; - dval->value = (int)stemp->val1; - dval->min = (int)stemp->min; - dval->max = (int)stemp->max; - break; - } - case SOCK_BOOLEAN: - { - bNodeSocketValueBoolean *dval = sock->default_value; - dval->value = (int)stemp->val1; - break; - } - case SOCK_VECTOR: - { - bNodeSocketValueVector *dval = sock->default_value; - dval->value[0] = stemp->val1; - dval->value[1] = stemp->val2; - dval->value[2] = stemp->val3; - dval->min = stemp->min; - dval->max = stemp->max; - break; - } - case SOCK_RGBA: - { - bNodeSocketValueRGBA *dval = sock->default_value; - dval->value[0] = stemp->val1; - dval->value[1] = stemp->val2; - dval->value[2] = stemp->val3; - dval->value[3] = stemp->val4; - break; - } - } - - return sock; + bNodeSocket *sock = nodeAddStaticSocket( + ntree, node, in_out, stemp->type, stemp->subtype, stemp->identifier, stemp->name); + + sock->flag |= stemp->flag; + + /* initialize default_value */ + switch (stemp->type) { + case SOCK_FLOAT: { + bNodeSocketValueFloat *dval = sock->default_value; + dval->value = stemp->val1; + dval->min = stemp->min; + dval->max = stemp->max; + break; + } + case SOCK_INT: { + bNodeSocketValueInt *dval = sock->default_value; + dval->value = (int)stemp->val1; + dval->min = (int)stemp->min; + dval->max = (int)stemp->max; + break; + } + case SOCK_BOOLEAN: { + bNodeSocketValueBoolean *dval = sock->default_value; + dval->value = (int)stemp->val1; + break; + } + case SOCK_VECTOR: { + bNodeSocketValueVector *dval = sock->default_value; + dval->value[0] = stemp->val1; + dval->value[1] = stemp->val2; + dval->value[2] = stemp->val3; + dval->min = stemp->min; + dval->max = stemp->max; + break; + } + case SOCK_RGBA: { + bNodeSocketValueRGBA *dval = sock->default_value; + dval->value[0] = stemp->val1; + dval->value[1] = stemp->val2; + dval->value[2] = stemp->val3; + dval->value[3] = stemp->val4; + break; + } + } + + return sock; } -static bNodeSocket *verify_socket_template(bNodeTree *ntree, bNode *node, int in_out, ListBase *socklist, bNodeSocketTemplate *stemp) +static bNodeSocket *verify_socket_template( + bNodeTree *ntree, bNode *node, int in_out, ListBase *socklist, bNodeSocketTemplate *stemp) { - bNodeSocket *sock; - - for (sock = socklist->first; sock; sock = sock->next) { - if (STREQLEN(sock->name, stemp->name, NODE_MAXSTR)) - break; - } - if (sock) { - if (sock->type != stemp->type) { - nodeModifySocketType(ntree, node, sock, stemp->type, stemp->subtype); - } - sock->limit = (stemp->limit == 0 ? (in_out == SOCK_IN ? 1 : 0xFFF) : stemp->limit); - sock->flag |= stemp->flag; - } - else { - /* no socket for this template found, make a new one */ - sock = node_add_socket_from_template(ntree, node, stemp, in_out); - } - - /* remove the new socket from the node socket list first, - * will be added back after verification. */ - BLI_remlink(socklist, sock); - - return sock; + bNodeSocket *sock; + + for (sock = socklist->first; sock; sock = sock->next) { + if (STREQLEN(sock->name, stemp->name, NODE_MAXSTR)) + break; + } + if (sock) { + if (sock->type != stemp->type) { + nodeModifySocketType(ntree, node, sock, stemp->type, stemp->subtype); + } + sock->limit = (stemp->limit == 0 ? (in_out == SOCK_IN ? 1 : 0xFFF) : stemp->limit); + sock->flag |= stemp->flag; + } + else { + /* no socket for this template found, make a new one */ + sock = node_add_socket_from_template(ntree, node, stemp, in_out); + } + + /* remove the new socket from the node socket list first, + * will be added back after verification. */ + BLI_remlink(socklist, sock); + + return sock; } -static void verify_socket_template_list(bNodeTree *ntree, bNode *node, int in_out, ListBase *socklist, bNodeSocketTemplate *stemp_first) +static void verify_socket_template_list(bNodeTree *ntree, + bNode *node, + int in_out, + ListBase *socklist, + bNodeSocketTemplate *stemp_first) { - bNodeSocket *sock, *nextsock; - bNodeSocketTemplate *stemp; - - /* no inputs anymore? */ - if (stemp_first == NULL) { - for (sock = (bNodeSocket *)socklist->first; sock; sock = nextsock) { - nextsock = sock->next; - nodeRemoveSocket(ntree, node, sock); - } - } - else { - /* step by step compare */ - stemp = stemp_first; - while (stemp->type != -1) { - stemp->sock = verify_socket_template(ntree, node, in_out, socklist, stemp); - stemp++; - } - /* leftovers are removed */ - for (sock = (bNodeSocket *)socklist->first; sock; sock = nextsock) { - nextsock = sock->next; - nodeRemoveSocket(ntree, node, sock); - } - - /* and we put back the verified sockets */ - stemp = stemp_first; - if (socklist->first) { - /* some dynamic sockets left, store the list start - * so we can add static sockets infront of it. - */ - sock = socklist->first; - while (stemp->type != -1) { - /* put static sockets infront of dynamic */ - BLI_insertlinkbefore(socklist, sock, stemp->sock); - stemp++; - } - } - else { - while (stemp->type != -1) { - BLI_addtail(socklist, stemp->sock); - stemp++; - } - } - } + bNodeSocket *sock, *nextsock; + bNodeSocketTemplate *stemp; + + /* no inputs anymore? */ + if (stemp_first == NULL) { + for (sock = (bNodeSocket *)socklist->first; sock; sock = nextsock) { + nextsock = sock->next; + nodeRemoveSocket(ntree, node, sock); + } + } + else { + /* step by step compare */ + stemp = stemp_first; + while (stemp->type != -1) { + stemp->sock = verify_socket_template(ntree, node, in_out, socklist, stemp); + stemp++; + } + /* leftovers are removed */ + for (sock = (bNodeSocket *)socklist->first; sock; sock = nextsock) { + nextsock = sock->next; + nodeRemoveSocket(ntree, node, sock); + } + + /* and we put back the verified sockets */ + stemp = stemp_first; + if (socklist->first) { + /* some dynamic sockets left, store the list start + * so we can add static sockets infront of it. + */ + sock = socklist->first; + while (stemp->type != -1) { + /* put static sockets infront of dynamic */ + BLI_insertlinkbefore(socklist, sock, stemp->sock); + stemp++; + } + } + else { + while (stemp->type != -1) { + BLI_addtail(socklist, stemp->sock); + stemp++; + } + } + } } void node_verify_socket_templates(bNodeTree *ntree, bNode *node) { - bNodeType *ntype = node->typeinfo; - /* Don't try to match socket lists when there are no templates. - * This prevents dynamically generated sockets to be removed, like for - * group, image or render layer nodes. We have an explicit check for the - * render layer node since it still has fixed sockets too. - */ - if (ntype) { - if (ntype->inputs && ntype->inputs[0].type >= 0) - verify_socket_template_list(ntree, node, SOCK_IN, &node->inputs, ntype->inputs); - if (ntype->outputs && ntype->outputs[0].type >= 0 && node->type != CMP_NODE_R_LAYERS) - verify_socket_template_list(ntree, node, SOCK_OUT, &node->outputs, ntype->outputs); - } + bNodeType *ntype = node->typeinfo; + /* Don't try to match socket lists when there are no templates. + * This prevents dynamically generated sockets to be removed, like for + * group, image or render layer nodes. We have an explicit check for the + * render layer node since it still has fixed sockets too. + */ + if (ntype) { + if (ntype->inputs && ntype->inputs[0].type >= 0) + verify_socket_template_list(ntree, node, SOCK_IN, &node->inputs, ntype->inputs); + if (ntype->outputs && ntype->outputs[0].type >= 0 && node->type != CMP_NODE_R_LAYERS) + verify_socket_template_list(ntree, node, SOCK_OUT, &node->outputs, ntype->outputs); + } } - void node_socket_init_default_value(bNodeSocket *sock) { - int type = sock->typeinfo->type; - int subtype = sock->typeinfo->subtype; - - if (sock->default_value) - return; /* already initialized */ - - switch (type) { - case SOCK_FLOAT: - { - bNodeSocketValueFloat *dval = MEM_callocN(sizeof(bNodeSocketValueFloat), "node socket value float"); - dval->subtype = subtype; - dval->value = 0.0f; - dval->min = -FLT_MAX; - dval->max = FLT_MAX; - - sock->default_value = dval; - break; - } - case SOCK_INT: - { - bNodeSocketValueInt *dval = MEM_callocN(sizeof(bNodeSocketValueInt), "node socket value int"); - dval->subtype = subtype; - dval->value = 0; - dval->min = INT_MIN; - dval->max = INT_MAX; - - sock->default_value = dval; - break; - } - case SOCK_BOOLEAN: - { - bNodeSocketValueBoolean *dval = MEM_callocN(sizeof(bNodeSocketValueBoolean), "node socket value bool"); - dval->value = false; - - sock->default_value = dval; - break; - } - case SOCK_VECTOR: - { - static float default_value[] = { 0.0f, 0.0f, 0.0f }; - bNodeSocketValueVector *dval = MEM_callocN(sizeof(bNodeSocketValueVector), "node socket value vector"); - dval->subtype = subtype; - copy_v3_v3(dval->value, default_value); - dval->min = -FLT_MAX; - dval->max = FLT_MAX; - - sock->default_value = dval; - break; - } - case SOCK_RGBA: - { - static float default_value[] = { 0.0f, 0.0f, 0.0f, 1.0f }; - bNodeSocketValueRGBA *dval = MEM_callocN(sizeof(bNodeSocketValueRGBA), "node socket value color"); - copy_v4_v4(dval->value, default_value); - - sock->default_value = dval; - break; - } - case SOCK_STRING: - { - bNodeSocketValueString *dval = MEM_callocN(sizeof(bNodeSocketValueString), "node socket value string"); - dval->subtype = subtype; - dval->value[0] = '\0'; - - sock->default_value = dval; - break; - } - } + int type = sock->typeinfo->type; + int subtype = sock->typeinfo->subtype; + + if (sock->default_value) + return; /* already initialized */ + + switch (type) { + case SOCK_FLOAT: { + bNodeSocketValueFloat *dval = MEM_callocN(sizeof(bNodeSocketValueFloat), + "node socket value float"); + dval->subtype = subtype; + dval->value = 0.0f; + dval->min = -FLT_MAX; + dval->max = FLT_MAX; + + sock->default_value = dval; + break; + } + case SOCK_INT: { + bNodeSocketValueInt *dval = MEM_callocN(sizeof(bNodeSocketValueInt), + "node socket value int"); + dval->subtype = subtype; + dval->value = 0; + dval->min = INT_MIN; + dval->max = INT_MAX; + + sock->default_value = dval; + break; + } + case SOCK_BOOLEAN: { + bNodeSocketValueBoolean *dval = MEM_callocN(sizeof(bNodeSocketValueBoolean), + "node socket value bool"); + dval->value = false; + + sock->default_value = dval; + break; + } + case SOCK_VECTOR: { + static float default_value[] = {0.0f, 0.0f, 0.0f}; + bNodeSocketValueVector *dval = MEM_callocN(sizeof(bNodeSocketValueVector), + "node socket value vector"); + dval->subtype = subtype; + copy_v3_v3(dval->value, default_value); + dval->min = -FLT_MAX; + dval->max = FLT_MAX; + + sock->default_value = dval; + break; + } + case SOCK_RGBA: { + static float default_value[] = {0.0f, 0.0f, 0.0f, 1.0f}; + bNodeSocketValueRGBA *dval = MEM_callocN(sizeof(bNodeSocketValueRGBA), + "node socket value color"); + copy_v4_v4(dval->value, default_value); + + sock->default_value = dval; + break; + } + case SOCK_STRING: { + bNodeSocketValueString *dval = MEM_callocN(sizeof(bNodeSocketValueString), + "node socket value string"); + dval->subtype = subtype; + dval->value[0] = '\0'; + + sock->default_value = dval; + break; + } + } } void node_socket_copy_default_value(bNodeSocket *to, const bNodeSocket *from) { - /* sanity check */ - if (to->type != from->type) - return; - - /* make sure both exist */ - if (!from->default_value) - return; - node_socket_init_default_value(to); - - switch (from->typeinfo->type) { - case SOCK_FLOAT: - { - bNodeSocketValueFloat *toval = to->default_value; - bNodeSocketValueFloat *fromval = from->default_value; - *toval = *fromval; - break; - } - case SOCK_INT: - { - bNodeSocketValueInt *toval = to->default_value; - bNodeSocketValueInt *fromval = from->default_value; - *toval = *fromval; - break; - } - case SOCK_BOOLEAN: - { - bNodeSocketValueBoolean *toval = to->default_value; - bNodeSocketValueBoolean *fromval = from->default_value; - *toval = *fromval; - break; - } - case SOCK_VECTOR: - { - bNodeSocketValueVector *toval = to->default_value; - bNodeSocketValueVector *fromval = from->default_value; - *toval = *fromval; - break; - } - case SOCK_RGBA: - { - bNodeSocketValueRGBA *toval = to->default_value; - bNodeSocketValueRGBA *fromval = from->default_value; - *toval = *fromval; - break; - } - case SOCK_STRING: - { - bNodeSocketValueString *toval = to->default_value; - bNodeSocketValueString *fromval = from->default_value; - *toval = *fromval; - break; - } - } - - to->flag |= (from->flag & SOCK_HIDE_VALUE); + /* sanity check */ + if (to->type != from->type) + return; + + /* make sure both exist */ + if (!from->default_value) + return; + node_socket_init_default_value(to); + + switch (from->typeinfo->type) { + case SOCK_FLOAT: { + bNodeSocketValueFloat *toval = to->default_value; + bNodeSocketValueFloat *fromval = from->default_value; + *toval = *fromval; + break; + } + case SOCK_INT: { + bNodeSocketValueInt *toval = to->default_value; + bNodeSocketValueInt *fromval = from->default_value; + *toval = *fromval; + break; + } + case SOCK_BOOLEAN: { + bNodeSocketValueBoolean *toval = to->default_value; + bNodeSocketValueBoolean *fromval = from->default_value; + *toval = *fromval; + break; + } + case SOCK_VECTOR: { + bNodeSocketValueVector *toval = to->default_value; + bNodeSocketValueVector *fromval = from->default_value; + *toval = *fromval; + break; + } + case SOCK_RGBA: { + bNodeSocketValueRGBA *toval = to->default_value; + bNodeSocketValueRGBA *fromval = from->default_value; + *toval = *fromval; + break; + } + case SOCK_STRING: { + bNodeSocketValueString *toval = to->default_value; + bNodeSocketValueString *fromval = from->default_value; + *toval = *fromval; + break; + } + } + + to->flag |= (from->flag & SOCK_HIDE_VALUE); } -static void standard_node_socket_interface_init_socket(bNodeTree *UNUSED(ntree), bNodeSocket *stemp, bNode *UNUSED(node), bNodeSocket *sock, const char *UNUSED(data_path)) +static void standard_node_socket_interface_init_socket(bNodeTree *UNUSED(ntree), + bNodeSocket *stemp, + bNode *UNUSED(node), + bNodeSocket *sock, + const char *UNUSED(data_path)) { - /* initialize the type value */ - sock->type = sock->typeinfo->type; - - /* XXX socket interface 'type' value is not used really, - * but has to match or the copy function will bail out - */ - stemp->type = stemp->typeinfo->type; - /* copy default_value settings */ - node_socket_copy_default_value(sock, stemp); + /* initialize the type value */ + sock->type = sock->typeinfo->type; + + /* XXX socket interface 'type' value is not used really, + * but has to match or the copy function will bail out + */ + stemp->type = stemp->typeinfo->type; + /* copy default_value settings */ + node_socket_copy_default_value(sock, stemp); } /* copies settings that are not changed for each socket instance */ -static void standard_node_socket_interface_verify_socket(bNodeTree *UNUSED(ntree), bNodeSocket *stemp, bNode *UNUSED(node), bNodeSocket *sock, const char *UNUSED(data_path)) +static void standard_node_socket_interface_verify_socket(bNodeTree *UNUSED(ntree), + bNodeSocket *stemp, + bNode *UNUSED(node), + bNodeSocket *sock, + const char *UNUSED(data_path)) { - /* sanity check */ - if (sock->type != stemp->typeinfo->type) - return; - - /* make sure both exist */ - if (!stemp->default_value) - return; - node_socket_init_default_value(sock); - - switch (stemp->typeinfo->type) { - case SOCK_FLOAT: - { - bNodeSocketValueFloat *toval = sock->default_value; - bNodeSocketValueFloat *fromval = stemp->default_value; - toval->min = fromval->min; - toval->max = fromval->max; - break; - } - case SOCK_INT: - { - bNodeSocketValueInt *toval = sock->default_value; - bNodeSocketValueInt *fromval = stemp->default_value; - toval->min = fromval->min; - toval->max = fromval->max; - break; - } - case SOCK_VECTOR: - { - bNodeSocketValueVector *toval = sock->default_value; - bNodeSocketValueVector *fromval = stemp->default_value; - toval->min = fromval->min; - toval->max = fromval->max; - break; - } - } + /* sanity check */ + if (sock->type != stemp->typeinfo->type) + return; + + /* make sure both exist */ + if (!stemp->default_value) + return; + node_socket_init_default_value(sock); + + switch (stemp->typeinfo->type) { + case SOCK_FLOAT: { + bNodeSocketValueFloat *toval = sock->default_value; + bNodeSocketValueFloat *fromval = stemp->default_value; + toval->min = fromval->min; + toval->max = fromval->max; + break; + } + case SOCK_INT: { + bNodeSocketValueInt *toval = sock->default_value; + bNodeSocketValueInt *fromval = stemp->default_value; + toval->min = fromval->min; + toval->max = fromval->max; + break; + } + case SOCK_VECTOR: { + bNodeSocketValueVector *toval = sock->default_value; + bNodeSocketValueVector *fromval = stemp->default_value; + toval->min = fromval->min; + toval->max = fromval->max; + break; + } + } } -static void standard_node_socket_interface_from_socket(bNodeTree *UNUSED(ntree), bNodeSocket *stemp, bNode *UNUSED(node), bNodeSocket *sock) +static void standard_node_socket_interface_from_socket(bNodeTree *UNUSED(ntree), + bNodeSocket *stemp, + bNode *UNUSED(node), + bNodeSocket *sock) { - /* initialize settings */ - stemp->type = stemp->typeinfo->type; - node_socket_copy_default_value(stemp, sock); + /* initialize settings */ + stemp->type = stemp->typeinfo->type; + node_socket_copy_default_value(stemp, sock); } static bNodeSocketType *make_standard_socket_type(int type, int subtype) { - extern void ED_init_standard_node_socket_type(bNodeSocketType *); + extern void ED_init_standard_node_socket_type(bNodeSocketType *); - const char *socket_idname = nodeStaticSocketType(type, subtype); - const char *interface_idname = nodeStaticSocketInterfaceType(type, subtype); - bNodeSocketType *stype; - StructRNA *srna; + const char *socket_idname = nodeStaticSocketType(type, subtype); + const char *interface_idname = nodeStaticSocketInterfaceType(type, subtype); + bNodeSocketType *stype; + StructRNA *srna; - stype = MEM_callocN(sizeof(bNodeSocketType), "node socket C type"); - BLI_strncpy(stype->idname, socket_idname, sizeof(stype->idname)); + stype = MEM_callocN(sizeof(bNodeSocketType), "node socket C type"); + BLI_strncpy(stype->idname, socket_idname, sizeof(stype->idname)); - /* set the RNA type - * uses the exact same identifier as the socket type idname */ - srna = stype->ext_socket.srna = RNA_struct_find(socket_idname); - BLI_assert(srna != NULL); - /* associate the RNA type with the socket type */ - RNA_struct_blender_type_set(srna, stype); + /* set the RNA type + * uses the exact same identifier as the socket type idname */ + srna = stype->ext_socket.srna = RNA_struct_find(socket_idname); + BLI_assert(srna != NULL); + /* associate the RNA type with the socket type */ + RNA_struct_blender_type_set(srna, stype); - /* set the interface RNA type */ - srna = stype->ext_interface.srna = RNA_struct_find(interface_idname); - BLI_assert(srna != NULL); - /* associate the RNA type with the socket type */ - RNA_struct_blender_type_set(srna, stype); + /* set the interface RNA type */ + srna = stype->ext_interface.srna = RNA_struct_find(interface_idname); + BLI_assert(srna != NULL); + /* associate the RNA type with the socket type */ + RNA_struct_blender_type_set(srna, stype); - /* extra type info for standard socket types */ - stype->type = type; - stype->subtype = subtype; + /* extra type info for standard socket types */ + stype->type = type; + stype->subtype = subtype; - /* XXX bad-level call! needed for setting draw callbacks */ - ED_init_standard_node_socket_type(stype); + /* XXX bad-level call! needed for setting draw callbacks */ + ED_init_standard_node_socket_type(stype); - stype->interface_init_socket = standard_node_socket_interface_init_socket; - stype->interface_from_socket = standard_node_socket_interface_from_socket; - stype->interface_verify_socket = standard_node_socket_interface_verify_socket; + stype->interface_init_socket = standard_node_socket_interface_init_socket; + stype->interface_from_socket = standard_node_socket_interface_from_socket; + stype->interface_verify_socket = standard_node_socket_interface_verify_socket; - return stype; + return stype; } static bNodeSocketType *make_socket_type_virtual(void) { - extern void ED_init_node_socket_type_virtual(bNodeSocketType *); + extern void ED_init_node_socket_type_virtual(bNodeSocketType *); - const char *socket_idname = "NodeSocketVirtual"; - bNodeSocketType *stype; - StructRNA *srna; + const char *socket_idname = "NodeSocketVirtual"; + bNodeSocketType *stype; + StructRNA *srna; - stype = MEM_callocN(sizeof(bNodeSocketType), "node socket C type"); - BLI_strncpy(stype->idname, socket_idname, sizeof(stype->idname)); + stype = MEM_callocN(sizeof(bNodeSocketType), "node socket C type"); + BLI_strncpy(stype->idname, socket_idname, sizeof(stype->idname)); - /* set the RNA type - * uses the exact same identifier as the socket type idname */ - srna = stype->ext_socket.srna = RNA_struct_find(socket_idname); - BLI_assert(srna != NULL); - /* associate the RNA type with the socket type */ - RNA_struct_blender_type_set(srna, stype); + /* set the RNA type + * uses the exact same identifier as the socket type idname */ + srna = stype->ext_socket.srna = RNA_struct_find(socket_idname); + BLI_assert(srna != NULL); + /* associate the RNA type with the socket type */ + RNA_struct_blender_type_set(srna, stype); - /* extra type info for standard socket types */ - stype->type = SOCK_CUSTOM; + /* extra type info for standard socket types */ + stype->type = SOCK_CUSTOM; - ED_init_node_socket_type_virtual(stype); + ED_init_node_socket_type_virtual(stype); - return stype; + return stype; } - void register_standard_node_socket_types(void) { - /* draw callbacks are set in drawnode.c to avoid bad-level calls */ + /* draw callbacks are set in drawnode.c to avoid bad-level calls */ - nodeRegisterSocketType(make_standard_socket_type(SOCK_FLOAT, PROP_NONE)); - nodeRegisterSocketType(make_standard_socket_type(SOCK_FLOAT, PROP_UNSIGNED)); - nodeRegisterSocketType(make_standard_socket_type(SOCK_FLOAT, PROP_PERCENTAGE)); - nodeRegisterSocketType(make_standard_socket_type(SOCK_FLOAT, PROP_FACTOR)); - nodeRegisterSocketType(make_standard_socket_type(SOCK_FLOAT, PROP_ANGLE)); - nodeRegisterSocketType(make_standard_socket_type(SOCK_FLOAT, PROP_TIME)); + nodeRegisterSocketType(make_standard_socket_type(SOCK_FLOAT, PROP_NONE)); + nodeRegisterSocketType(make_standard_socket_type(SOCK_FLOAT, PROP_UNSIGNED)); + nodeRegisterSocketType(make_standard_socket_type(SOCK_FLOAT, PROP_PERCENTAGE)); + nodeRegisterSocketType(make_standard_socket_type(SOCK_FLOAT, PROP_FACTOR)); + nodeRegisterSocketType(make_standard_socket_type(SOCK_FLOAT, PROP_ANGLE)); + nodeRegisterSocketType(make_standard_socket_type(SOCK_FLOAT, PROP_TIME)); - nodeRegisterSocketType(make_standard_socket_type(SOCK_INT, PROP_NONE)); - nodeRegisterSocketType(make_standard_socket_type(SOCK_INT, PROP_UNSIGNED)); - nodeRegisterSocketType(make_standard_socket_type(SOCK_INT, PROP_PERCENTAGE)); - nodeRegisterSocketType(make_standard_socket_type(SOCK_INT, PROP_FACTOR)); + nodeRegisterSocketType(make_standard_socket_type(SOCK_INT, PROP_NONE)); + nodeRegisterSocketType(make_standard_socket_type(SOCK_INT, PROP_UNSIGNED)); + nodeRegisterSocketType(make_standard_socket_type(SOCK_INT, PROP_PERCENTAGE)); + nodeRegisterSocketType(make_standard_socket_type(SOCK_INT, PROP_FACTOR)); - nodeRegisterSocketType(make_standard_socket_type(SOCK_BOOLEAN, PROP_NONE)); + nodeRegisterSocketType(make_standard_socket_type(SOCK_BOOLEAN, PROP_NONE)); - nodeRegisterSocketType(make_standard_socket_type(SOCK_VECTOR, PROP_NONE)); - nodeRegisterSocketType(make_standard_socket_type(SOCK_VECTOR, PROP_TRANSLATION)); - nodeRegisterSocketType(make_standard_socket_type(SOCK_VECTOR, PROP_DIRECTION)); - nodeRegisterSocketType(make_standard_socket_type(SOCK_VECTOR, PROP_VELOCITY)); - nodeRegisterSocketType(make_standard_socket_type(SOCK_VECTOR, PROP_ACCELERATION)); - nodeRegisterSocketType(make_standard_socket_type(SOCK_VECTOR, PROP_EULER)); - nodeRegisterSocketType(make_standard_socket_type(SOCK_VECTOR, PROP_XYZ)); + nodeRegisterSocketType(make_standard_socket_type(SOCK_VECTOR, PROP_NONE)); + nodeRegisterSocketType(make_standard_socket_type(SOCK_VECTOR, PROP_TRANSLATION)); + nodeRegisterSocketType(make_standard_socket_type(SOCK_VECTOR, PROP_DIRECTION)); + nodeRegisterSocketType(make_standard_socket_type(SOCK_VECTOR, PROP_VELOCITY)); + nodeRegisterSocketType(make_standard_socket_type(SOCK_VECTOR, PROP_ACCELERATION)); + nodeRegisterSocketType(make_standard_socket_type(SOCK_VECTOR, PROP_EULER)); + nodeRegisterSocketType(make_standard_socket_type(SOCK_VECTOR, PROP_XYZ)); - nodeRegisterSocketType(make_standard_socket_type(SOCK_RGBA, PROP_NONE)); + nodeRegisterSocketType(make_standard_socket_type(SOCK_RGBA, PROP_NONE)); - nodeRegisterSocketType(make_standard_socket_type(SOCK_STRING, PROP_NONE)); + nodeRegisterSocketType(make_standard_socket_type(SOCK_STRING, PROP_NONE)); - nodeRegisterSocketType(make_standard_socket_type(SOCK_SHADER, PROP_NONE)); + nodeRegisterSocketType(make_standard_socket_type(SOCK_SHADER, PROP_NONE)); - nodeRegisterSocketType(make_socket_type_virtual()); + nodeRegisterSocketType(make_socket_type_virtual()); } diff --git a/source/blender/nodes/intern/node_util.c b/source/blender/nodes/intern/node_util.c index 069a5bb599e..a4a39caf8df 100644 --- a/source/blender/nodes/intern/node_util.c +++ b/source/blender/nodes/intern/node_util.c @@ -47,164 +47,163 @@ void node_free_curves(bNode *node) { - curvemapping_free(node->storage); + curvemapping_free(node->storage); } void node_free_standard_storage(bNode *node) { - if (node->storage) { - MEM_freeN(node->storage); - } + if (node->storage) { + MEM_freeN(node->storage); + } } void node_copy_curves(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, bNode *src_node) { - dest_node->storage = curvemapping_copy(src_node->storage); + dest_node->storage = curvemapping_copy(src_node->storage); } void node_copy_standard_storage(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, bNode *src_node) { - dest_node->storage = MEM_dupallocN(src_node->storage); + dest_node->storage = MEM_dupallocN(src_node->storage); } -void *node_initexec_curves(bNodeExecContext *UNUSED(context), bNode *node, bNodeInstanceKey UNUSED(key)) +void *node_initexec_curves(bNodeExecContext *UNUSED(context), + bNode *node, + bNodeInstanceKey UNUSED(key)) { - curvemapping_initialize(node->storage); - return NULL; /* unused return */ + curvemapping_initialize(node->storage); + return NULL; /* unused return */ } - /**** Labels ****/ void node_blend_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen) { - const char *name; - RNA_enum_name(rna_enum_ramp_blend_items, node->custom1, &name); - BLI_strncpy(label, IFACE_(name), maxlen); + const char *name; + RNA_enum_name(rna_enum_ramp_blend_items, node->custom1, &name); + BLI_strncpy(label, IFACE_(name), maxlen); } void node_image_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen) { - /* if there is no loaded image, return an empty string, and let nodeLabel() fill in the proper type translation. */ - BLI_strncpy(label, (node->id) ? node->id->name + 2 : "", maxlen); + /* if there is no loaded image, return an empty string, and let nodeLabel() fill in the proper type translation. */ + BLI_strncpy(label, (node->id) ? node->id->name + 2 : "", maxlen); } void node_math_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen) { - const char *name; - RNA_enum_name(rna_enum_node_math_items, node->custom1, &name); - BLI_strncpy(label, IFACE_(name), maxlen); + const char *name; + RNA_enum_name(rna_enum_node_math_items, node->custom1, &name); + BLI_strncpy(label, IFACE_(name), maxlen); } void node_vect_math_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen) { - const char *name; - RNA_enum_name(rna_enum_node_vec_math_items, node->custom1, &name); - BLI_strncpy(label, IFACE_(name), maxlen); + const char *name; + RNA_enum_name(rna_enum_node_vec_math_items, node->custom1, &name); + BLI_strncpy(label, IFACE_(name), maxlen); } void node_filter_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen) { - const char *name; - RNA_enum_name(rna_enum_node_filter_items, node->custom1, &name); - BLI_strncpy(label, IFACE_(name), maxlen); + const char *name; + RNA_enum_name(rna_enum_node_filter_items, node->custom1, &name); + BLI_strncpy(label, IFACE_(name), maxlen); } - /*** Link Insertion ***/ /* test if two sockets are interchangeable */ static bool node_link_socket_match(bNodeSocket *a, bNodeSocket *b) { - /* check if sockets are of the same type */ - if (a->typeinfo != b->typeinfo) { - return false; - } - - /* tests if alphabetic prefix matches - * this allows for imperfect matches, such as numeric suffixes, - * like Color1/Color2 - */ - int prefix_len = 0; - char *ca = a->name, *cb = b->name; - for (; *ca != '\0' && *cb != '\0'; ++ca, ++cb) { - /* end of common prefix? */ - if (*ca != *cb) { - /* prefix delimited by non-alphabetic char */ - if (isalpha(*ca) || isalpha(*cb)) - return false; - break; - } - ++prefix_len; - } - return prefix_len > 0; + /* check if sockets are of the same type */ + if (a->typeinfo != b->typeinfo) { + return false; + } + + /* tests if alphabetic prefix matches + * this allows for imperfect matches, such as numeric suffixes, + * like Color1/Color2 + */ + int prefix_len = 0; + char *ca = a->name, *cb = b->name; + for (; *ca != '\0' && *cb != '\0'; ++ca, ++cb) { + /* end of common prefix? */ + if (*ca != *cb) { + /* prefix delimited by non-alphabetic char */ + if (isalpha(*ca) || isalpha(*cb)) + return false; + break; + } + ++prefix_len; + } + return prefix_len > 0; } static int node_count_links(bNodeTree *ntree, bNodeSocket *sock) { - bNodeLink *link; - int count = 0; - for (link = ntree->links.first; link; link = link->next) { - if (link->fromsock == sock) - ++count; - if (link->tosock == sock) - ++count; - } - return count; + bNodeLink *link; + int count = 0; + for (link = ntree->links.first; link; link = link->next) { + if (link->fromsock == sock) + ++count; + if (link->tosock == sock) + ++count; + } + return count; } /* find an eligible socket for linking */ static bNodeSocket *node_find_linkable_socket(bNodeTree *ntree, bNode *node, bNodeSocket *cur) { - /* link swapping: try to find a free slot with a matching name */ - - bNodeSocket *first = cur->in_out == SOCK_IN ? node->inputs.first : node->outputs.first; - bNodeSocket *sock; - - sock = cur->next ? cur->next : first; /* wrap around the list end */ - while (sock != cur) { - if (!nodeSocketIsHidden(sock) && node_link_socket_match(sock, cur)) { - int link_count = node_count_links(ntree, sock); - /* take +1 into account since we would add a new link */ - if (link_count + 1 <= sock->limit) - return sock; /* found a valid free socket we can swap to */ - } - - sock = sock->next ? sock->next : first; /* wrap around the list end */ - } - return NULL; + /* link swapping: try to find a free slot with a matching name */ + + bNodeSocket *first = cur->in_out == SOCK_IN ? node->inputs.first : node->outputs.first; + bNodeSocket *sock; + + sock = cur->next ? cur->next : first; /* wrap around the list end */ + while (sock != cur) { + if (!nodeSocketIsHidden(sock) && node_link_socket_match(sock, cur)) { + int link_count = node_count_links(ntree, sock); + /* take +1 into account since we would add a new link */ + if (link_count + 1 <= sock->limit) + return sock; /* found a valid free socket we can swap to */ + } + + sock = sock->next ? sock->next : first; /* wrap around the list end */ + } + return NULL; } void node_insert_link_default(bNodeTree *ntree, bNode *node, bNodeLink *link) { - bNodeSocket *sock = link->tosock; - bNodeLink *tlink, *tlink_next; - - /* inputs can have one link only, outputs can have unlimited links */ - if (node != link->tonode) - return; - - for (tlink = ntree->links.first; tlink; tlink = tlink_next) { - bNodeSocket *new_sock; - tlink_next = tlink->next; - - if (sock != tlink->tosock) - continue; - - new_sock = node_find_linkable_socket(ntree, node, sock); - if (new_sock && new_sock != sock) { - /* redirect existing link */ - tlink->tosock = new_sock; - } - else if (!new_sock) { - /* no possible replacement, remove tlink */ - nodeRemLink(ntree, tlink); - tlink = NULL; - } - } + bNodeSocket *sock = link->tosock; + bNodeLink *tlink, *tlink_next; + + /* inputs can have one link only, outputs can have unlimited links */ + if (node != link->tonode) + return; + + for (tlink = ntree->links.first; tlink; tlink = tlink_next) { + bNodeSocket *new_sock; + tlink_next = tlink->next; + + if (sock != tlink->tosock) + continue; + + new_sock = node_find_linkable_socket(ntree, node, sock); + if (new_sock && new_sock != sock) { + /* redirect existing link */ + tlink->tosock = new_sock; + } + else if (!new_sock) { + /* no possible replacement, remove tlink */ + nodeRemLink(ntree, tlink); + tlink = NULL; + } + } } - /**** Internal Links (mute and disconnect) ****/ /* common datatype priorities, works for compositor, shader and texture nodes alike @@ -214,184 +213,223 @@ void node_insert_link_default(bNodeTree *ntree, bNode *node, bNodeLink *link) */ static int node_datatype_priority(eNodeSocketDatatype from, eNodeSocketDatatype to) { - switch (to) { - case SOCK_RGBA: - switch (from) { - case SOCK_RGBA: return 4; - case SOCK_FLOAT: return 3; - case SOCK_INT: return 2; - case SOCK_BOOLEAN: return 1; - default: return -1; - } - case SOCK_VECTOR: - switch (from) { - case SOCK_VECTOR: return 4; - case SOCK_FLOAT: return 3; - case SOCK_INT: return 2; - case SOCK_BOOLEAN: return 1; - default: return -1; - } - case SOCK_FLOAT: - switch (from) { - case SOCK_FLOAT: return 5; - case SOCK_INT: return 4; - case SOCK_BOOLEAN: return 3; - case SOCK_RGBA: return 2; - case SOCK_VECTOR: return 1; - default: return -1; - } - case SOCK_INT: - switch (from) { - case SOCK_INT: return 5; - case SOCK_FLOAT: return 4; - case SOCK_BOOLEAN: return 3; - case SOCK_RGBA: return 2; - case SOCK_VECTOR: return 1; - default: return -1; - } - case SOCK_BOOLEAN: - switch (from) { - case SOCK_BOOLEAN: return 5; - case SOCK_INT: return 4; - case SOCK_FLOAT: return 3; - case SOCK_RGBA: return 2; - case SOCK_VECTOR: return 1; - default: return -1; - } - case SOCK_SHADER: - switch (from) { - case SOCK_SHADER: return 1; - default: return -1; - } - case SOCK_STRING: - switch (from) { - case SOCK_STRING: return 1; - default: return -1; - } - default: return -1; - } + switch (to) { + case SOCK_RGBA: + switch (from) { + case SOCK_RGBA: + return 4; + case SOCK_FLOAT: + return 3; + case SOCK_INT: + return 2; + case SOCK_BOOLEAN: + return 1; + default: + return -1; + } + case SOCK_VECTOR: + switch (from) { + case SOCK_VECTOR: + return 4; + case SOCK_FLOAT: + return 3; + case SOCK_INT: + return 2; + case SOCK_BOOLEAN: + return 1; + default: + return -1; + } + case SOCK_FLOAT: + switch (from) { + case SOCK_FLOAT: + return 5; + case SOCK_INT: + return 4; + case SOCK_BOOLEAN: + return 3; + case SOCK_RGBA: + return 2; + case SOCK_VECTOR: + return 1; + default: + return -1; + } + case SOCK_INT: + switch (from) { + case SOCK_INT: + return 5; + case SOCK_FLOAT: + return 4; + case SOCK_BOOLEAN: + return 3; + case SOCK_RGBA: + return 2; + case SOCK_VECTOR: + return 1; + default: + return -1; + } + case SOCK_BOOLEAN: + switch (from) { + case SOCK_BOOLEAN: + return 5; + case SOCK_INT: + return 4; + case SOCK_FLOAT: + return 3; + case SOCK_RGBA: + return 2; + case SOCK_VECTOR: + return 1; + default: + return -1; + } + case SOCK_SHADER: + switch (from) { + case SOCK_SHADER: + return 1; + default: + return -1; + } + case SOCK_STRING: + switch (from) { + case SOCK_STRING: + return 1; + default: + return -1; + } + default: + return -1; + } } /* select a suitable input socket for an output */ static bNodeSocket *select_internal_link_input(bNode *node, bNodeSocket *output) { - bNodeSocket *selected = NULL, *input; - int i; - int sel_priority = -1; - bool sel_is_linked = false; - - for (input = node->inputs.first, i = 0; input; input = input->next, ++i) { - int priority = node_datatype_priority(input->type, output->type); - bool is_linked = (input->link != NULL); - bool preferred; - - if (nodeSocketIsHidden(input) || /* ignore hidden sockets */ - input->flag & SOCK_NO_INTERNAL_LINK || /* ignore if input is not allowed for internal connections */ - priority < 0 || /* ignore incompatible types */ - priority < sel_priority) /* ignore if we already found a higher priority input */ - { - continue; - } - - /* determine if this input is preferred over the currently selected */ - preferred = (priority > sel_priority) || /* prefer higher datatype priority */ - (is_linked && !sel_is_linked); /* prefer linked over unlinked */ - - if (preferred) { - selected = input; - sel_is_linked = is_linked; - sel_priority = priority; - } - } - - return selected; + bNodeSocket *selected = NULL, *input; + int i; + int sel_priority = -1; + bool sel_is_linked = false; + + for (input = node->inputs.first, i = 0; input; input = input->next, ++i) { + int priority = node_datatype_priority(input->type, output->type); + bool is_linked = (input->link != NULL); + bool preferred; + + if (nodeSocketIsHidden(input) || /* ignore hidden sockets */ + input->flag & + SOCK_NO_INTERNAL_LINK || /* ignore if input is not allowed for internal connections */ + priority < 0 || /* ignore incompatible types */ + priority < sel_priority) /* ignore if we already found a higher priority input */ + { + continue; + } + + /* determine if this input is preferred over the currently selected */ + preferred = (priority > sel_priority) || /* prefer higher datatype priority */ + (is_linked && !sel_is_linked); /* prefer linked over unlinked */ + + if (preferred) { + selected = input; + sel_is_linked = is_linked; + sel_priority = priority; + } + } + + return selected; } void node_update_internal_links_default(bNodeTree *ntree, bNode *node) { - bNodeLink *link; - bNodeSocket *output, *input; - - /* sanity check */ - if (!ntree) - return; - - /* use link pointer as a tag for handled sockets (for outputs is unused anyway) */ - for (output = node->outputs.first; output; output = output->next) - output->link = NULL; - - for (link = ntree->links.first; link; link = link->next) { - if (nodeLinkIsHidden(link)) - continue; - - output = link->fromsock; - if (link->fromnode != node || output->link) - continue; - if (nodeSocketIsHidden(output) || output->flag & SOCK_NO_INTERNAL_LINK) - continue; - output->link = link; /* not really used, just for tagging handled sockets */ - - /* look for suitable input */ - input = select_internal_link_input(node, output); - - if (input) { - bNodeLink *ilink = MEM_callocN(sizeof(bNodeLink), "internal node link"); - ilink->fromnode = node; - ilink->fromsock = input; - ilink->tonode = node; - ilink->tosock = output; - /* internal link is always valid */ - ilink->flag |= NODE_LINK_VALID; - BLI_addtail(&node->internal_links, ilink); - } - } - - /* clean up */ - for (output = node->outputs.first; output; output = output->next) - output->link = NULL; + bNodeLink *link; + bNodeSocket *output, *input; + + /* sanity check */ + if (!ntree) + return; + + /* use link pointer as a tag for handled sockets (for outputs is unused anyway) */ + for (output = node->outputs.first; output; output = output->next) + output->link = NULL; + + for (link = ntree->links.first; link; link = link->next) { + if (nodeLinkIsHidden(link)) + continue; + + output = link->fromsock; + if (link->fromnode != node || output->link) + continue; + if (nodeSocketIsHidden(output) || output->flag & SOCK_NO_INTERNAL_LINK) + continue; + output->link = link; /* not really used, just for tagging handled sockets */ + + /* look for suitable input */ + input = select_internal_link_input(node, output); + + if (input) { + bNodeLink *ilink = MEM_callocN(sizeof(bNodeLink), "internal node link"); + ilink->fromnode = node; + ilink->fromsock = input; + ilink->tonode = node; + ilink->tosock = output; + /* internal link is always valid */ + ilink->flag |= NODE_LINK_VALID; + BLI_addtail(&node->internal_links, ilink); + } + } + + /* clean up */ + for (output = node->outputs.first; output; output = output->next) + output->link = NULL; } - /**** Default value RNA access ****/ float node_socket_get_float(bNodeTree *ntree, bNode *UNUSED(node), bNodeSocket *sock) { - PointerRNA ptr; - RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr); - return RNA_float_get(&ptr, "default_value"); + PointerRNA ptr; + RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr); + return RNA_float_get(&ptr, "default_value"); } void node_socket_set_float(bNodeTree *ntree, bNode *UNUSED(node), bNodeSocket *sock, float value) { - PointerRNA ptr; - RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr); - RNA_float_set(&ptr, "default_value", value); + PointerRNA ptr; + RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr); + RNA_float_set(&ptr, "default_value", value); } void node_socket_get_color(bNodeTree *ntree, bNode *UNUSED(node), bNodeSocket *sock, float *value) { - PointerRNA ptr; - RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr); - RNA_float_get_array(&ptr, "default_value", value); + PointerRNA ptr; + RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr); + RNA_float_get_array(&ptr, "default_value", value); } -void node_socket_set_color(bNodeTree *ntree, bNode *UNUSED(node), bNodeSocket *sock, const float *value) +void node_socket_set_color(bNodeTree *ntree, + bNode *UNUSED(node), + bNodeSocket *sock, + const float *value) { - PointerRNA ptr; - RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr); - RNA_float_set_array(&ptr, "default_value", value); + PointerRNA ptr; + RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr); + RNA_float_set_array(&ptr, "default_value", value); } void node_socket_get_vector(bNodeTree *ntree, bNode *UNUSED(node), bNodeSocket *sock, float *value) { - PointerRNA ptr; - RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr); - RNA_float_get_array(&ptr, "default_value", value); + PointerRNA ptr; + RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr); + RNA_float_get_array(&ptr, "default_value", value); } -void node_socket_set_vector(bNodeTree *ntree, bNode *UNUSED(node), bNodeSocket *sock, const float *value) +void node_socket_set_vector(bNodeTree *ntree, + bNode *UNUSED(node), + bNodeSocket *sock, + const float *value) { - PointerRNA ptr; - RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr); - RNA_float_set_array(&ptr, "default_value", value); + PointerRNA ptr; + RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr); + RNA_float_set_array(&ptr, "default_value", value); } diff --git a/source/blender/nodes/intern/node_util.h b/source/blender/nodes/intern/node_util.h index 00b2063804b..ec5cd074922 100644 --- a/source/blender/nodes/intern/node_util.h +++ b/source/blender/nodes/intern/node_util.h @@ -21,7 +21,6 @@ * \ingroup nodes */ - #ifndef __NODE_UTIL_H__ #define __NODE_UTIL_H__ @@ -44,12 +43,12 @@ struct bNodeTree; /* data for initializing node execution */ typedef struct bNodeExecContext { - struct bNodeInstanceHash *previews; + struct bNodeInstanceHash *previews; } bNodeExecContext; typedef struct bNodeExecData { - void *data; /* custom data storage */ - struct bNodePreview *preview; /* optional preview image */ + void *data; /* custom data storage */ + struct bNodePreview *preview; /* optional preview image */ } bNodeExecData; /**** Storage Data ****/ @@ -57,9 +56,15 @@ typedef struct bNodeExecData { extern void node_free_curves(struct bNode *node); extern void node_free_standard_storage(struct bNode *node); -extern void node_copy_curves(struct bNodeTree *dest_ntree, struct bNode *dest_node, struct bNode *src_node); -extern void node_copy_standard_storage(struct bNodeTree *dest_ntree, struct bNode *dest_node, struct bNode *src_node); -extern void *node_initexec_curves(struct bNodeExecContext *context, struct bNode *node, bNodeInstanceKey key); +extern void node_copy_curves(struct bNodeTree *dest_ntree, + struct bNode *dest_node, + struct bNode *src_node); +extern void node_copy_standard_storage(struct bNodeTree *dest_ntree, + struct bNode *dest_node, + struct bNode *src_node); +extern void *node_initexec_curves(struct bNodeExecContext *context, + struct bNode *node, + bNodeInstanceKey key); /**** Labels ****/ @@ -69,16 +74,30 @@ void node_math_label(struct bNodeTree *ntree, struct bNode *node, char *label, i void node_vect_math_label(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen); void node_filter_label(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen); - /*** Link Handling */ void node_insert_link_default(struct bNodeTree *ntree, struct bNode *node, struct bNodeLink *link); void node_update_internal_links_default(struct bNodeTree *ntree, struct bNode *node); float node_socket_get_float(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocket *sock); -void node_socket_set_float(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocket *sock, float value); -void node_socket_get_color(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocket *sock, float *value); -void node_socket_set_color(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocket *sock, const float *value); -void node_socket_get_vector(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocket *sock, float *value); -void node_socket_set_vector(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocket *sock, const float *value); +void node_socket_set_float(struct bNodeTree *ntree, + struct bNode *node, + struct bNodeSocket *sock, + float value); +void node_socket_get_color(struct bNodeTree *ntree, + struct bNode *node, + struct bNodeSocket *sock, + float *value); +void node_socket_set_color(struct bNodeTree *ntree, + struct bNode *node, + struct bNodeSocket *sock, + const float *value); +void node_socket_get_vector(struct bNodeTree *ntree, + struct bNode *node, + struct bNodeSocket *sock, + float *value); +void node_socket_set_vector(struct bNodeTree *ntree, + struct bNode *node, + struct bNodeSocket *sock, + const float *value); #endif diff --git a/source/blender/nodes/shader/node_shader_tree.c b/source/blender/nodes/shader/node_shader_tree.c index 9f01d2ab254..816c56713d0 100644 --- a/source/blender/nodes/shader/node_shader_tree.c +++ b/source/blender/nodes/shader/node_shader_tree.c @@ -21,7 +21,6 @@ * \ingroup nodes */ - #include <string.h> #include "DNA_light_types.h" @@ -58,141 +57,144 @@ #include "node_util.h" #include "node_shader_util.h" - typedef struct nTreeTags { - float ssr_id, sss_id; + float ssr_id, sss_id; } nTreeTags; static void ntree_shader_tag_nodes(bNodeTree *ntree, bNode *output_node, nTreeTags *tags); static bool shader_tree_poll(const bContext *C, bNodeTreeType *UNUSED(treetype)) { - Scene *scene = CTX_data_scene(C); - const char *engine_id = scene->r.engine; + Scene *scene = CTX_data_scene(C); + const char *engine_id = scene->r.engine; - /* allow empty engine string too, this is from older versions that didn't have registerable engines yet */ - return (engine_id[0] == '\0' || - STREQ(engine_id, RE_engine_id_CYCLES) || - !BKE_scene_use_shading_nodes_custom(scene)); + /* allow empty engine string too, this is from older versions that didn't have registerable engines yet */ + return (engine_id[0] == '\0' || STREQ(engine_id, RE_engine_id_CYCLES) || + !BKE_scene_use_shading_nodes_custom(scene)); } -static void shader_get_from_context(const bContext *C, bNodeTreeType *UNUSED(treetype), bNodeTree **r_ntree, ID **r_id, ID **r_from) +static void shader_get_from_context(const bContext *C, + bNodeTreeType *UNUSED(treetype), + bNodeTree **r_ntree, + ID **r_id, + ID **r_from) { - SpaceNode *snode = CTX_wm_space_node(C); - Scene *scene = CTX_data_scene(C); - ViewLayer *view_layer = CTX_data_view_layer(C); - Object *ob = OBACT(view_layer); - - if (snode->shaderfrom == SNODE_SHADER_OBJECT) { - if (ob) { - *r_from = &ob->id; - if (ob->type == OB_LAMP) { - *r_id = ob->data; - *r_ntree = ((Light *)ob->data)->nodetree; - } - else { - Material *ma = give_current_material(ob, ob->actcol); - if (ma) { - *r_id = &ma->id; - *r_ntree = ma->nodetree; - } - } - } - } + SpaceNode *snode = CTX_wm_space_node(C); + Scene *scene = CTX_data_scene(C); + ViewLayer *view_layer = CTX_data_view_layer(C); + Object *ob = OBACT(view_layer); + + if (snode->shaderfrom == SNODE_SHADER_OBJECT) { + if (ob) { + *r_from = &ob->id; + if (ob->type == OB_LAMP) { + *r_id = ob->data; + *r_ntree = ((Light *)ob->data)->nodetree; + } + else { + Material *ma = give_current_material(ob, ob->actcol); + if (ma) { + *r_id = &ma->id; + *r_ntree = ma->nodetree; + } + } + } + } #ifdef WITH_FREESTYLE - else if (snode->shaderfrom == SNODE_SHADER_LINESTYLE) { - FreestyleLineStyle *linestyle = BKE_linestyle_active_from_view_layer(view_layer); - if (linestyle) { - *r_from = NULL; - *r_id = &linestyle->id; - *r_ntree = linestyle->nodetree; - } - } + else if (snode->shaderfrom == SNODE_SHADER_LINESTYLE) { + FreestyleLineStyle *linestyle = BKE_linestyle_active_from_view_layer(view_layer); + if (linestyle) { + *r_from = NULL; + *r_id = &linestyle->id; + *r_ntree = linestyle->nodetree; + } + } #endif - else { /* SNODE_SHADER_WORLD */ - if (scene->world) { - *r_from = NULL; - *r_id = &scene->world->id; - *r_ntree = scene->world->nodetree; - } - } + else { /* SNODE_SHADER_WORLD */ + if (scene->world) { + *r_from = NULL; + *r_id = &scene->world->id; + *r_ntree = scene->world->nodetree; + } + } } static void foreach_nodeclass(Scene *UNUSED(scene), void *calldata, bNodeClassCallback func) { - func(calldata, NODE_CLASS_INPUT, N_("Input")); - func(calldata, NODE_CLASS_OUTPUT, N_("Output")); - func(calldata, NODE_CLASS_SHADER, N_("Shader")); - func(calldata, NODE_CLASS_TEXTURE, N_("Texture")); - func(calldata, NODE_CLASS_OP_COLOR, N_("Color")); - func(calldata, NODE_CLASS_OP_VECTOR, N_("Vector")); - func(calldata, NODE_CLASS_CONVERTOR, N_("Convertor")); - func(calldata, NODE_CLASS_SCRIPT, N_("Script")); - func(calldata, NODE_CLASS_GROUP, N_("Group")); - func(calldata, NODE_CLASS_INTERFACE, N_("Interface")); - func(calldata, NODE_CLASS_LAYOUT, N_("Layout")); + func(calldata, NODE_CLASS_INPUT, N_("Input")); + func(calldata, NODE_CLASS_OUTPUT, N_("Output")); + func(calldata, NODE_CLASS_SHADER, N_("Shader")); + func(calldata, NODE_CLASS_TEXTURE, N_("Texture")); + func(calldata, NODE_CLASS_OP_COLOR, N_("Color")); + func(calldata, NODE_CLASS_OP_VECTOR, N_("Vector")); + func(calldata, NODE_CLASS_CONVERTOR, N_("Convertor")); + func(calldata, NODE_CLASS_SCRIPT, N_("Script")); + func(calldata, NODE_CLASS_GROUP, N_("Group")); + func(calldata, NODE_CLASS_INTERFACE, N_("Interface")); + func(calldata, NODE_CLASS_LAYOUT, N_("Layout")); } static void localize(bNodeTree *localtree, bNodeTree *UNUSED(ntree)) { - bNode *node, *node_next; + bNode *node, *node_next; - /* replace muted nodes and reroute nodes by internal links */ - for (node = localtree->nodes.first; node; node = node_next) { - node_next = node->next; + /* replace muted nodes and reroute nodes by internal links */ + for (node = localtree->nodes.first; node; node = node_next) { + node_next = node->next; - if (node->flag & NODE_MUTED || node->type == NODE_REROUTE) { - nodeInternalRelink(localtree, node); - ntreeFreeLocalNode(localtree, node); - } - } + if (node->flag & NODE_MUTED || node->type == NODE_REROUTE) { + nodeInternalRelink(localtree, node); + ntreeFreeLocalNode(localtree, node); + } + } } static void local_sync(bNodeTree *localtree, bNodeTree *ntree) { - BKE_node_preview_sync_tree(ntree, localtree); + BKE_node_preview_sync_tree(ntree, localtree); } static void local_merge(Main *UNUSED(bmain), bNodeTree *localtree, bNodeTree *ntree) { - BKE_node_preview_merge_tree(ntree, localtree, true); + BKE_node_preview_merge_tree(ntree, localtree, true); } static void update(bNodeTree *ntree) { - ntreeSetOutput(ntree); + ntreeSetOutput(ntree); - ntree_update_reroute_nodes(ntree); + ntree_update_reroute_nodes(ntree); - if (ntree->update & NTREE_UPDATE_NODES) { - /* clean up preview cache, in case nodes have been removed */ - BKE_node_preview_remove_unused(ntree); - } + if (ntree->update & NTREE_UPDATE_NODES) { + /* clean up preview cache, in case nodes have been removed */ + BKE_node_preview_remove_unused(ntree); + } } bNodeTreeType *ntreeType_Shader; void register_node_tree_type_sh(void) { - bNodeTreeType *tt = ntreeType_Shader = MEM_callocN(sizeof(bNodeTreeType), "shader node tree type"); - - tt->type = NTREE_SHADER; - strcpy(tt->idname, "ShaderNodeTree"); - strcpy(tt->ui_name, N_("Shader Editor")); - tt->ui_icon = 0; /* defined in drawnode.c */ - strcpy(tt->ui_description, N_("Shader nodes")); - - tt->foreach_nodeclass = foreach_nodeclass; - tt->localize = localize; - tt->local_sync = local_sync; - tt->local_merge = local_merge; - tt->update = update; - tt->poll = shader_tree_poll; - tt->get_from_context = shader_get_from_context; - - tt->ext.srna = &RNA_ShaderNodeTree; - - ntreeTypeAdd(tt); + bNodeTreeType *tt = ntreeType_Shader = MEM_callocN(sizeof(bNodeTreeType), + "shader node tree type"); + + tt->type = NTREE_SHADER; + strcpy(tt->idname, "ShaderNodeTree"); + strcpy(tt->ui_name, N_("Shader Editor")); + tt->ui_icon = 0; /* defined in drawnode.c */ + strcpy(tt->ui_description, N_("Shader nodes")); + + tt->foreach_nodeclass = foreach_nodeclass; + tt->localize = localize; + tt->local_sync = local_sync; + tt->local_merge = local_merge; + tt->update = update; + tt->poll = shader_tree_poll; + tt->get_from_context = shader_get_from_context; + + tt->ext.srna = &RNA_ShaderNodeTree; + + ntreeTypeAdd(tt); } /* GPU material from shader nodes */ @@ -203,8 +205,7 @@ static void ntree_shader_link_builtin_normal(bNodeTree *ntree, bNode *displacement_node, bNodeSocket *displacement_socket); -static bNodeSocket *ntree_shader_node_find_input(bNode *node, - const char *identifier); +static bNodeSocket *ntree_shader_node_find_input(bNode *node, const char *identifier); static bNode *ntree_group_output_node(bNodeTree *ntree); @@ -213,101 +214,98 @@ static bNode *ntree_shader_relink_output_from_group(bNodeTree *ntree, bNode *sh_output_node, int target) { - int i; - bNodeTree *group_ntree = (bNodeTree *)group_node->id; - - int sock_len = BLI_listbase_count(&sh_output_node->inputs); - bNodeSocket **group_surface_sockets = BLI_array_alloca(group_surface_sockets, sock_len); - - /* Create output sockets to plug output connection to. */ - i = 0; - for (bNodeSocket *sock = sh_output_node->inputs.first; sock; sock = sock->next, ++i) { - group_surface_sockets[i] = - ntreeAddSocketInterface(group_ntree, - SOCK_OUT, - sock->typeinfo->idname, - sock->name); - } - - bNode *group_output_node = ntree_group_output_node(group_ntree); - - /* If no group output node is present, we need to create one. */ - if (group_output_node == NULL) { - group_output_node = nodeAddStaticNode(NULL, group_ntree, NODE_GROUP_OUTPUT); - } - - /* Need to update tree so all node instances nodes gets proper sockets. */ - node_group_verify(ntree, group_node, &group_ntree->id); - node_group_output_verify(group_ntree, group_output_node, &group_ntree->id); - ntreeUpdateTree(G.main, group_ntree); - - /* Remove other shader output nodes so that only the new one can be selected as active. */ - for (bNode *node = ntree->nodes.first; node; node = node->next) { - if (ELEM(node->type, SH_NODE_OUTPUT_MATERIAL, - SH_NODE_OUTPUT_WORLD, - SH_NODE_OUTPUT_LIGHT)) - { - ntreeFreeLocalNode(ntree, node); - } - } - - /* Create new shader output node outside the group. */ - bNode *new_output_node = nodeAddStaticNode(NULL, ntree, sh_output_node->type); - new_output_node->custom1 = target; - - i = 0; - for (bNodeSocket *sock = sh_output_node->inputs.first; sock; sock = sock->next, ++i) { - if (sock->link != NULL) { - /* Link the shader output node incoming link to the group output sockets */ - bNodeSocket *group_output_node_surface_input_sock = nodeFindSocket(group_output_node, - SOCK_IN, - group_surface_sockets[i]->identifier); - nodeAddLink(group_ntree, - sock->link->fromnode, sock->link->fromsock, - group_output_node, group_output_node_surface_input_sock); - - /* Link the group output sockets to the new shader output node. */ - bNodeSocket *group_node_surface_output = nodeFindSocket(group_node, - SOCK_OUT, - group_surface_sockets[i]->identifier); - bNodeSocket *output_node_surface_input = ntree_shader_node_find_input(new_output_node, sock->name); - - nodeAddLink(ntree, - group_node, group_node_surface_output, - new_output_node, output_node_surface_input); - } - } - - ntreeUpdateTree(G.main, group_ntree); - ntreeUpdateTree(G.main, ntree); - - return new_output_node; + int i; + bNodeTree *group_ntree = (bNodeTree *)group_node->id; + + int sock_len = BLI_listbase_count(&sh_output_node->inputs); + bNodeSocket **group_surface_sockets = BLI_array_alloca(group_surface_sockets, sock_len); + + /* Create output sockets to plug output connection to. */ + i = 0; + for (bNodeSocket *sock = sh_output_node->inputs.first; sock; sock = sock->next, ++i) { + group_surface_sockets[i] = ntreeAddSocketInterface( + group_ntree, SOCK_OUT, sock->typeinfo->idname, sock->name); + } + + bNode *group_output_node = ntree_group_output_node(group_ntree); + + /* If no group output node is present, we need to create one. */ + if (group_output_node == NULL) { + group_output_node = nodeAddStaticNode(NULL, group_ntree, NODE_GROUP_OUTPUT); + } + + /* Need to update tree so all node instances nodes gets proper sockets. */ + node_group_verify(ntree, group_node, &group_ntree->id); + node_group_output_verify(group_ntree, group_output_node, &group_ntree->id); + ntreeUpdateTree(G.main, group_ntree); + + /* Remove other shader output nodes so that only the new one can be selected as active. */ + for (bNode *node = ntree->nodes.first; node; node = node->next) { + if (ELEM(node->type, SH_NODE_OUTPUT_MATERIAL, SH_NODE_OUTPUT_WORLD, SH_NODE_OUTPUT_LIGHT)) { + ntreeFreeLocalNode(ntree, node); + } + } + + /* Create new shader output node outside the group. */ + bNode *new_output_node = nodeAddStaticNode(NULL, ntree, sh_output_node->type); + new_output_node->custom1 = target; + + i = 0; + for (bNodeSocket *sock = sh_output_node->inputs.first; sock; sock = sock->next, ++i) { + if (sock->link != NULL) { + /* Link the shader output node incoming link to the group output sockets */ + bNodeSocket *group_output_node_surface_input_sock = nodeFindSocket( + group_output_node, SOCK_IN, group_surface_sockets[i]->identifier); + nodeAddLink(group_ntree, + sock->link->fromnode, + sock->link->fromsock, + group_output_node, + group_output_node_surface_input_sock); + + /* Link the group output sockets to the new shader output node. */ + bNodeSocket *group_node_surface_output = nodeFindSocket( + group_node, SOCK_OUT, group_surface_sockets[i]->identifier); + bNodeSocket *output_node_surface_input = ntree_shader_node_find_input(new_output_node, + sock->name); + + nodeAddLink(ntree, + group_node, + group_node_surface_output, + new_output_node, + output_node_surface_input); + } + } + + ntreeUpdateTree(G.main, group_ntree); + ntreeUpdateTree(G.main, ntree); + + return new_output_node; } static bNode *ntree_shader_output_node_from_group(bNodeTree *ntree, int target) { - bNode *output_node = NULL; - - /* Search if node groups do not contain valid output nodes (recursively). */ - for (bNode *node = ntree->nodes.first; node; node = node->next) { - if (!ELEM(node->type, NODE_GROUP, NODE_CUSTOM_GROUP)) { - continue; - } - if (node->id != NULL) { - output_node = ntree_shader_output_node_from_group((bNodeTree *)node->id, target); - - if (output_node == NULL) { - output_node = ntreeShaderOutputNode((bNodeTree *)node->id, target); - } - - if (output_node != NULL) { - /* Output is inside this group node. Create relink to make the output outside the group. */ - output_node = ntree_shader_relink_output_from_group(ntree, node, output_node, target); - break; - } - } - } - return output_node; + bNode *output_node = NULL; + + /* Search if node groups do not contain valid output nodes (recursively). */ + for (bNode *node = ntree->nodes.first; node; node = node->next) { + if (!ELEM(node->type, NODE_GROUP, NODE_CUSTOM_GROUP)) { + continue; + } + if (node->id != NULL) { + output_node = ntree_shader_output_node_from_group((bNodeTree *)node->id, target); + + if (output_node == NULL) { + output_node = ntreeShaderOutputNode((bNodeTree *)node->id, target); + } + + if (output_node != NULL) { + /* Output is inside this group node. Create relink to make the output outside the group. */ + output_node = ntree_shader_relink_output_from_group(ntree, node, output_node, target); + break; + } + } + } + return output_node; } /* Find an output node of the shader tree. @@ -319,49 +317,42 @@ static bNode *ntree_shader_output_node_from_group(bNodeTree *ntree, int target) */ bNode *ntreeShaderOutputNode(bNodeTree *ntree, int target) { - /* Make sure we only have single node tagged as output. */ - ntreeSetOutput(ntree); - - /* Find output node that matches type and target. If there are - * multiple, we prefer exact target match and active nodes. */ - bNode *output_node = NULL; - - for (bNode *node = ntree->nodes.first; node; node = node->next) { - if (!ELEM(node->type, SH_NODE_OUTPUT_MATERIAL, - SH_NODE_OUTPUT_WORLD, - SH_NODE_OUTPUT_LIGHT)) - { - continue; - } - - if (node->custom1 == SHD_OUTPUT_ALL) { - if (output_node == NULL) { - output_node = node; - } - else if (output_node->custom1 == SHD_OUTPUT_ALL) { - if ((node->flag & NODE_DO_OUTPUT) && - !(output_node->flag & NODE_DO_OUTPUT)) - { - output_node = node; - } - } - } - else if (node->custom1 == target) { - if (output_node == NULL) { - output_node = node; - } - else if (output_node->custom1 == SHD_OUTPUT_ALL) { - output_node = node; - } - else if ((node->flag & NODE_DO_OUTPUT) && - !(output_node->flag & NODE_DO_OUTPUT)) - { - output_node = node; - } - } - } - - return output_node; + /* Make sure we only have single node tagged as output. */ + ntreeSetOutput(ntree); + + /* Find output node that matches type and target. If there are + * multiple, we prefer exact target match and active nodes. */ + bNode *output_node = NULL; + + for (bNode *node = ntree->nodes.first; node; node = node->next) { + if (!ELEM(node->type, SH_NODE_OUTPUT_MATERIAL, SH_NODE_OUTPUT_WORLD, SH_NODE_OUTPUT_LIGHT)) { + continue; + } + + if (node->custom1 == SHD_OUTPUT_ALL) { + if (output_node == NULL) { + output_node = node; + } + else if (output_node->custom1 == SHD_OUTPUT_ALL) { + if ((node->flag & NODE_DO_OUTPUT) && !(output_node->flag & NODE_DO_OUTPUT)) { + output_node = node; + } + } + } + else if (node->custom1 == target) { + if (output_node == NULL) { + output_node = node; + } + else if (output_node->custom1 == SHD_OUTPUT_ALL) { + output_node = node; + } + else if ((node->flag & NODE_DO_OUTPUT) && !(output_node->flag & NODE_DO_OUTPUT)) { + output_node = node; + } + } + } + + return output_node; } /* Find the active output node of a group nodetree. @@ -370,154 +361,147 @@ bNode *ntreeShaderOutputNode(bNodeTree *ntree, int target) */ static bNode *ntree_group_output_node(bNodeTree *ntree) { - /* Make sure we only have single node tagged as output. */ - ntreeSetOutput(ntree); - - /* Find output node that matches type and target. If there are - * multiple, we prefer exact target match and active nodes. */ - bNode *output_node = NULL; - - for (bNode *node = ntree->nodes.first; node; node = node->next) { - if ((node->type == NODE_GROUP_OUTPUT) && - (node->flag & NODE_DO_OUTPUT)) - { - output_node = node; - } - } - - return output_node; + /* Make sure we only have single node tagged as output. */ + ntreeSetOutput(ntree); + + /* Find output node that matches type and target. If there are + * multiple, we prefer exact target match and active nodes. */ + bNode *output_node = NULL; + + for (bNode *node = ntree->nodes.first; node; node = node->next) { + if ((node->type == NODE_GROUP_OUTPUT) && (node->flag & NODE_DO_OUTPUT)) { + output_node = node; + } + } + + return output_node; } /* Find socket with a specified identifier. */ -static bNodeSocket *ntree_shader_node_find_socket(ListBase *sockets, - const char *identifier) +static bNodeSocket *ntree_shader_node_find_socket(ListBase *sockets, const char *identifier) { - for (bNodeSocket *sock = sockets->first; sock != NULL; sock = sock->next) { - if (STREQ(sock->identifier, identifier)) { - return sock; - } - } - return NULL; + for (bNodeSocket *sock = sockets->first; sock != NULL; sock = sock->next) { + if (STREQ(sock->identifier, identifier)) { + return sock; + } + } + return NULL; } /* Find input socket with a specified identifier. */ -static bNodeSocket *ntree_shader_node_find_input(bNode *node, - const char *identifier) +static bNodeSocket *ntree_shader_node_find_input(bNode *node, const char *identifier) { - return ntree_shader_node_find_socket(&node->inputs, identifier); + return ntree_shader_node_find_socket(&node->inputs, identifier); } /* Find output socket with a specified identifier. */ -static bNodeSocket *ntree_shader_node_find_output(bNode *node, - const char *identifier) +static bNodeSocket *ntree_shader_node_find_output(bNode *node, const char *identifier) { - return ntree_shader_node_find_socket(&node->outputs, identifier); + return ntree_shader_node_find_socket(&node->outputs, identifier); } static void ntree_shader_unlink_hidden_value_sockets(bNode *group_node, bNodeSocket *isock) { - bNodeTree *group_ntree = (bNodeTree *)group_node->id; - bNode *node; - bool removed_link = false; - - for (node = group_ntree->nodes.first; node; node = node->next) { - for (bNodeSocket *sock = node->inputs.first; sock; sock = sock->next) { - if ((sock->flag & SOCK_HIDE_VALUE) == 0) - continue; - /* If socket is linked to a group input node and sockets id match. */ - if (sock && sock->link && sock->link->fromnode->type == NODE_GROUP_INPUT) { - if (STREQ(isock->identifier, sock->link->fromsock->identifier)) { - nodeRemLink(group_ntree, sock->link); - removed_link = true; - } - } - } - } - - if (removed_link) { - ntreeUpdateTree(G.main, group_ntree); - } + bNodeTree *group_ntree = (bNodeTree *)group_node->id; + bNode *node; + bool removed_link = false; + + for (node = group_ntree->nodes.first; node; node = node->next) { + for (bNodeSocket *sock = node->inputs.first; sock; sock = sock->next) { + if ((sock->flag & SOCK_HIDE_VALUE) == 0) + continue; + /* If socket is linked to a group input node and sockets id match. */ + if (sock && sock->link && sock->link->fromnode->type == NODE_GROUP_INPUT) { + if (STREQ(isock->identifier, sock->link->fromsock->identifier)) { + nodeRemLink(group_ntree, sock->link); + removed_link = true; + } + } + } + } + + if (removed_link) { + ntreeUpdateTree(G.main, group_ntree); + } } /* Node groups once expanded looses their input sockets values. * To fix this, link value/rgba nodes into the sockets and copy the group sockets values. */ static void ntree_shader_groups_expand_inputs(bNodeTree *localtree) { - bNode *value_node, *group_node; - bNodeSocket *value_socket; - bNodeSocketValueVector *src_vector; - bNodeSocketValueRGBA *src_rgba, *dst_rgba; - bNodeSocketValueFloat *src_float, *dst_float; - bNodeSocketValueInt *src_int; - bool link_added = false; - - for (group_node = localtree->nodes.first; group_node; group_node = group_node->next) { - - if (!(ELEM(group_node->type, NODE_GROUP, NODE_CUSTOM_GROUP)) || group_node->id == NULL) - continue; - - /* Do it recursively. */ - ntree_shader_groups_expand_inputs((bNodeTree *)group_node->id); - - bNodeSocket *group_socket = group_node->inputs.first; - for (; group_socket; group_socket = group_socket->next) { - if (group_socket->link != NULL) - continue; - - /* Detect the case where an input is plugged into a hidden value socket. - * In this case we should just remove the link to trigger the socket default override. */ - ntree_shader_unlink_hidden_value_sockets(group_node, group_socket); - - switch (group_socket->type) { - case SOCK_VECTOR: - value_node = nodeAddStaticNode(NULL, localtree, SH_NODE_RGB); - value_socket = ntree_shader_node_find_output(value_node, "Color"); - BLI_assert(value_socket != NULL); - src_vector = group_socket->default_value; - dst_rgba = value_socket->default_value; - copy_v3_v3(dst_rgba->value, src_vector->value); - dst_rgba->value[3] = 1.0f; /* should never be read */ - break; - case SOCK_RGBA: - value_node = nodeAddStaticNode(NULL, localtree, SH_NODE_RGB); - value_socket = ntree_shader_node_find_output(value_node, "Color"); - BLI_assert(value_socket != NULL); - src_rgba = group_socket->default_value; - dst_rgba = value_socket->default_value; - copy_v4_v4(dst_rgba->value, src_rgba->value); - break; - case SOCK_INT: - /* HACK: Support as float. */ - value_node = nodeAddStaticNode(NULL, localtree, SH_NODE_VALUE); - value_socket = ntree_shader_node_find_output(value_node, "Value"); - BLI_assert(value_socket != NULL); - src_int = group_socket->default_value; - dst_float = value_socket->default_value; - dst_float->value = (float)(src_int->value); - break; - case SOCK_FLOAT: - value_node = nodeAddStaticNode(NULL, localtree, SH_NODE_VALUE); - value_socket = ntree_shader_node_find_output(value_node, "Value"); - BLI_assert(value_socket != NULL); - src_float = group_socket->default_value; - dst_float = value_socket->default_value; - dst_float->value = src_float->value; - break; - default: - continue; - } - - nodeAddLink(localtree, - value_node, value_socket, - group_node, group_socket); - - link_added = true; - } - } - - if (link_added) { - ntreeUpdateTree(G.main, localtree); - } + bNode *value_node, *group_node; + bNodeSocket *value_socket; + bNodeSocketValueVector *src_vector; + bNodeSocketValueRGBA *src_rgba, *dst_rgba; + bNodeSocketValueFloat *src_float, *dst_float; + bNodeSocketValueInt *src_int; + bool link_added = false; + + for (group_node = localtree->nodes.first; group_node; group_node = group_node->next) { + + if (!(ELEM(group_node->type, NODE_GROUP, NODE_CUSTOM_GROUP)) || group_node->id == NULL) + continue; + + /* Do it recursively. */ + ntree_shader_groups_expand_inputs((bNodeTree *)group_node->id); + + bNodeSocket *group_socket = group_node->inputs.first; + for (; group_socket; group_socket = group_socket->next) { + if (group_socket->link != NULL) + continue; + + /* Detect the case where an input is plugged into a hidden value socket. + * In this case we should just remove the link to trigger the socket default override. */ + ntree_shader_unlink_hidden_value_sockets(group_node, group_socket); + + switch (group_socket->type) { + case SOCK_VECTOR: + value_node = nodeAddStaticNode(NULL, localtree, SH_NODE_RGB); + value_socket = ntree_shader_node_find_output(value_node, "Color"); + BLI_assert(value_socket != NULL); + src_vector = group_socket->default_value; + dst_rgba = value_socket->default_value; + copy_v3_v3(dst_rgba->value, src_vector->value); + dst_rgba->value[3] = 1.0f; /* should never be read */ + break; + case SOCK_RGBA: + value_node = nodeAddStaticNode(NULL, localtree, SH_NODE_RGB); + value_socket = ntree_shader_node_find_output(value_node, "Color"); + BLI_assert(value_socket != NULL); + src_rgba = group_socket->default_value; + dst_rgba = value_socket->default_value; + copy_v4_v4(dst_rgba->value, src_rgba->value); + break; + case SOCK_INT: + /* HACK: Support as float. */ + value_node = nodeAddStaticNode(NULL, localtree, SH_NODE_VALUE); + value_socket = ntree_shader_node_find_output(value_node, "Value"); + BLI_assert(value_socket != NULL); + src_int = group_socket->default_value; + dst_float = value_socket->default_value; + dst_float->value = (float)(src_int->value); + break; + case SOCK_FLOAT: + value_node = nodeAddStaticNode(NULL, localtree, SH_NODE_VALUE); + value_socket = ntree_shader_node_find_output(value_node, "Value"); + BLI_assert(value_socket != NULL); + src_float = group_socket->default_value; + dst_float = value_socket->default_value; + dst_float->value = src_float->value; + break; + default: + continue; + } + + nodeAddLink(localtree, value_node, value_socket, group_node, group_socket); + + link_added = true; + } + } + + if (link_added) { + ntreeUpdateTree(G.main, localtree); + } } /* Check whether shader has a displacement. @@ -532,25 +516,24 @@ static bool ntree_shader_has_displacement(bNodeTree *ntree, bNodeSocket **r_socket, bNodeLink **r_link) { - if (output_node == NULL) { - /* We can't have displacement without output node, apparently. */ - return false; - } - /* Make sure sockets links pointers are correct. */ - ntreeUpdateTree(G.main, ntree); - bNodeSocket *displacement = ntree_shader_node_find_input(output_node, - "Displacement"); - - if (displacement == NULL) { - /* Non-cycles node is used as an output. */ - return false; - } - if (displacement->link != NULL) { - *r_node = displacement->link->fromnode; - *r_socket = displacement->link->fromsock; - *r_link = displacement->link; - } - return displacement->link != NULL; + if (output_node == NULL) { + /* We can't have displacement without output node, apparently. */ + return false; + } + /* Make sure sockets links pointers are correct. */ + ntreeUpdateTree(G.main, ntree); + bNodeSocket *displacement = ntree_shader_node_find_input(output_node, "Displacement"); + + if (displacement == NULL) { + /* Non-cycles node is used as an output. */ + return false; + } + if (displacement->link != NULL) { + *r_node = displacement->link->fromnode; + *r_socket = displacement->link->fromsock; + *r_link = displacement->link; + } + return displacement->link != NULL; } static bool ntree_shader_relink_node_normal(bNodeTree *ntree, @@ -558,108 +541,100 @@ static bool ntree_shader_relink_node_normal(bNodeTree *ntree, bNode *node_from, bNodeSocket *socket_from) { - bNodeSocket *sock = ntree_shader_node_find_input(node, "Normal"); - /* TODO(sergey): Can we do something smarter here than just a name-based - * matching? - */ - if (sock == NULL) { - /* There's no Normal input, nothing to link. */ - return false; - } - if (sock->link != NULL) { - /* Something is linked to the normal input already. can't - * use other input for that. - */ - return false; - } - /* Create connection between specified node and the normal input. */ - nodeAddLink(ntree, node_from, socket_from, node, sock); - return true; + bNodeSocket *sock = ntree_shader_node_find_input(node, "Normal"); + /* TODO(sergey): Can we do something smarter here than just a name-based + * matching? + */ + if (sock == NULL) { + /* There's no Normal input, nothing to link. */ + return false; + } + if (sock->link != NULL) { + /* Something is linked to the normal input already. can't + * use other input for that. + */ + return false; + } + /* Create connection between specified node and the normal input. */ + nodeAddLink(ntree, node_from, socket_from, node, sock); + return true; } -static void ntree_shader_link_builtin_group_normal( - bNodeTree *ntree, - bNode *group_node, - bNode *node_from, - bNodeSocket *socket_from, - bNode *displacement_node, - bNodeSocket *displacement_socket) +static void ntree_shader_link_builtin_group_normal(bNodeTree *ntree, + bNode *group_node, + bNode *node_from, + bNodeSocket *socket_from, + bNode *displacement_node, + bNodeSocket *displacement_socket) { - bNodeTree *group_ntree = (bNodeTree *)group_node->id; - /* Create input socket to plug displacement connection to. */ - bNodeSocket *group_normal_socket = - ntreeAddSocketInterface(group_ntree, - SOCK_IN, - "NodeSocketVector", - "Normal"); - /* Need to update tree so all node instances nodes gets proper sockets. */ - bNode *group_input_node = ntreeFindType(group_ntree, NODE_GROUP_INPUT); - node_group_verify(ntree, group_node, &group_ntree->id); - if (group_input_node) - node_group_input_verify(group_ntree, group_input_node, &group_ntree->id); - ntreeUpdateTree(G.main, group_ntree); - /* Assumes sockets are always added at the end. */ - bNodeSocket *group_node_normal_socket = group_node->inputs.last; - if (displacement_node == group_node) { - /* If displacement is coming from this node group we need to perform - * some internal re-linking in order to avoid cycles. - */ - bNode *group_output_node = ntreeFindType(group_ntree, NODE_GROUP_OUTPUT); - if (group_output_node == NULL) { - return; - } - bNodeSocket *group_output_node_displacement_socket = - nodeFindSocket(group_output_node, - SOCK_IN, - displacement_socket->identifier); - bNodeLink *group_displacement_link = group_output_node_displacement_socket->link; - if (group_displacement_link == NULL) { - /* Displacement output is not connected to anything, can just stop - * right away. - */ - return; - } - /* This code is similar to ntree_shader_relink_displacement() */ - bNode *group_displacement_node = group_displacement_link->fromnode; - bNodeSocket *group_displacement_socket = group_displacement_link->fromsock; - /* Create and link bump node. - * Can't re-use bump node from parent tree because it'll cause cycle. - */ - bNode *bump_node = nodeAddStaticNode(NULL, group_ntree, SH_NODE_BUMP); - bNodeSocket *bump_input_socket = ntree_shader_node_find_input(bump_node, "Height"); - bNodeSocket *bump_output_socket = ntree_shader_node_find_output(bump_node, "Normal"); - BLI_assert(bump_input_socket != NULL); - BLI_assert(bump_output_socket != NULL); - nodeAddLink(group_ntree, - group_displacement_node, group_displacement_socket, - bump_node, bump_input_socket); - /* Relink normals inside of the instanced tree. */ - ntree_shader_link_builtin_normal(group_ntree, - bump_node, - bump_output_socket, - group_displacement_node, - group_displacement_socket); - ntreeUpdateTree(G.main, group_ntree); - } - else if (group_input_node) { - /* Connect group node normal input. */ - nodeAddLink(ntree, - node_from, socket_from, - group_node, group_node_normal_socket); - BLI_assert(group_input_node != NULL); - bNodeSocket *group_input_node_normal_socket = - nodeFindSocket(group_input_node, - SOCK_OUT, - group_normal_socket->identifier); - BLI_assert(group_input_node_normal_socket != NULL); - /* Relink normals inside of the instanced tree. */ - ntree_shader_link_builtin_normal(group_ntree, - group_input_node, - group_input_node_normal_socket, - displacement_node, - displacement_socket); - ntreeUpdateTree(G.main, group_ntree); - } + bNodeTree *group_ntree = (bNodeTree *)group_node->id; + /* Create input socket to plug displacement connection to. */ + bNodeSocket *group_normal_socket = ntreeAddSocketInterface( + group_ntree, SOCK_IN, "NodeSocketVector", "Normal"); + /* Need to update tree so all node instances nodes gets proper sockets. */ + bNode *group_input_node = ntreeFindType(group_ntree, NODE_GROUP_INPUT); + node_group_verify(ntree, group_node, &group_ntree->id); + if (group_input_node) + node_group_input_verify(group_ntree, group_input_node, &group_ntree->id); + ntreeUpdateTree(G.main, group_ntree); + /* Assumes sockets are always added at the end. */ + bNodeSocket *group_node_normal_socket = group_node->inputs.last; + if (displacement_node == group_node) { + /* If displacement is coming from this node group we need to perform + * some internal re-linking in order to avoid cycles. + */ + bNode *group_output_node = ntreeFindType(group_ntree, NODE_GROUP_OUTPUT); + if (group_output_node == NULL) { + return; + } + bNodeSocket *group_output_node_displacement_socket = nodeFindSocket( + group_output_node, SOCK_IN, displacement_socket->identifier); + bNodeLink *group_displacement_link = group_output_node_displacement_socket->link; + if (group_displacement_link == NULL) { + /* Displacement output is not connected to anything, can just stop + * right away. + */ + return; + } + /* This code is similar to ntree_shader_relink_displacement() */ + bNode *group_displacement_node = group_displacement_link->fromnode; + bNodeSocket *group_displacement_socket = group_displacement_link->fromsock; + /* Create and link bump node. + * Can't re-use bump node from parent tree because it'll cause cycle. + */ + bNode *bump_node = nodeAddStaticNode(NULL, group_ntree, SH_NODE_BUMP); + bNodeSocket *bump_input_socket = ntree_shader_node_find_input(bump_node, "Height"); + bNodeSocket *bump_output_socket = ntree_shader_node_find_output(bump_node, "Normal"); + BLI_assert(bump_input_socket != NULL); + BLI_assert(bump_output_socket != NULL); + nodeAddLink(group_ntree, + group_displacement_node, + group_displacement_socket, + bump_node, + bump_input_socket); + /* Relink normals inside of the instanced tree. */ + ntree_shader_link_builtin_normal(group_ntree, + bump_node, + bump_output_socket, + group_displacement_node, + group_displacement_socket); + ntreeUpdateTree(G.main, group_ntree); + } + else if (group_input_node) { + /* Connect group node normal input. */ + nodeAddLink(ntree, node_from, socket_from, group_node, group_node_normal_socket); + BLI_assert(group_input_node != NULL); + bNodeSocket *group_input_node_normal_socket = nodeFindSocket( + group_input_node, SOCK_OUT, group_normal_socket->identifier); + BLI_assert(group_input_node_normal_socket != NULL); + /* Relink normals inside of the instanced tree. */ + ntree_shader_link_builtin_normal(group_ntree, + group_input_node, + group_input_node_normal_socket, + displacement_node, + displacement_socket); + ntreeUpdateTree(G.main, group_ntree); + } } /* Use specified node and socket as an input for unconnected normal sockets. */ @@ -669,27 +644,23 @@ static void ntree_shader_link_builtin_normal(bNodeTree *ntree, bNode *displacement_node, bNodeSocket *displacement_socket) { - for (bNode *node = ntree->nodes.first; node != NULL; node = node->next) { - if (node == node_from) { - /* Don't connect node itself! */ - continue; - } - if ((ELEM(node->type, NODE_GROUP, NODE_CUSTOM_GROUP)) && node->id) { - /* Special re-linking for group nodes. */ - ntree_shader_link_builtin_group_normal(ntree, - node, - node_from, - socket_from, - displacement_node, - displacement_socket); - continue; - } - if (ELEM(node->type, NODE_GROUP_INPUT, NODE_GROUP_OUTPUT)) { - /* Group inputs and outputs needs nothing special. */ - continue; - } - ntree_shader_relink_node_normal(ntree, node, node_from, socket_from); - } + for (bNode *node = ntree->nodes.first; node != NULL; node = node->next) { + if (node == node_from) { + /* Don't connect node itself! */ + continue; + } + if ((ELEM(node->type, NODE_GROUP, NODE_CUSTOM_GROUP)) && node->id) { + /* Special re-linking for group nodes. */ + ntree_shader_link_builtin_group_normal( + ntree, node, node_from, socket_from, displacement_node, displacement_socket); + continue; + } + if (ELEM(node->type, NODE_GROUP_INPUT, NODE_GROUP_OUTPUT)) { + /* Group inputs and outputs needs nothing special. */ + continue; + } + ntree_shader_relink_node_normal(ntree, node, node_from, socket_from); + } } /* Re-link displacement output to unconnected normal sockets via bump node. @@ -697,107 +668,101 @@ static void ntree_shader_link_builtin_normal(bNodeTree *ntree, */ static void ntree_shader_relink_displacement(bNodeTree *ntree, bNode *output_node) { - bNode *displacement_node; - bNodeSocket *displacement_socket; - bNodeLink *displacement_link; - if (!ntree_shader_has_displacement(ntree, - output_node, - &displacement_node, - &displacement_socket, - &displacement_link)) - { - /* There is no displacement output connected, nothing to re-link. */ - return; - } - /* We have to disconnect displacement output socket, otherwise we'll have - * cycles in the Cycles material :) - */ - nodeRemLink(ntree, displacement_link); - - /* Convert displacement vector to bump height. */ - bNode *dot_node = nodeAddStaticNode(NULL, ntree, SH_NODE_VECT_MATH); - bNode *geo_node = nodeAddStaticNode(NULL, ntree, SH_NODE_NEW_GEOMETRY); - dot_node->custom1 = 3; /* dot product */ - - nodeAddLink(ntree, - displacement_node, displacement_socket, - dot_node, dot_node->inputs.first); - nodeAddLink(ntree, - geo_node, ntree_shader_node_find_output(geo_node, "Normal"), - dot_node, dot_node->inputs.last); - displacement_node = dot_node; - displacement_socket = ntree_shader_node_find_output(dot_node, "Value"); - - /* We can't connect displacement to normal directly, use bump node for that - * and hope that it gives good enough approximation. - */ - bNode *bump_node = nodeAddStaticNode(NULL, ntree, SH_NODE_BUMP); - bNodeSocket *bump_input_socket = ntree_shader_node_find_input(bump_node, "Height"); - bNodeSocket *bump_output_socket = ntree_shader_node_find_output(bump_node, "Normal"); - BLI_assert(bump_input_socket != NULL); - BLI_assert(bump_output_socket != NULL); - /* Connect bump node to where displacement output was originally - * connected to. - */ - nodeAddLink(ntree, - displacement_node, displacement_socket, - bump_node, bump_input_socket); - /* Connect all free-standing Normal inputs. */ - ntree_shader_link_builtin_normal(ntree, - bump_node, - bump_output_socket, - displacement_node, - displacement_socket); - /* TODO(sergey): Reconnect Geometry Info->Normal sockets to the new - * bump node. - */ - /* We modified the tree, it needs to be updated now. */ - ntreeUpdateTree(G.main, ntree); + bNode *displacement_node; + bNodeSocket *displacement_socket; + bNodeLink *displacement_link; + if (!ntree_shader_has_displacement( + ntree, output_node, &displacement_node, &displacement_socket, &displacement_link)) { + /* There is no displacement output connected, nothing to re-link. */ + return; + } + /* We have to disconnect displacement output socket, otherwise we'll have + * cycles in the Cycles material :) + */ + nodeRemLink(ntree, displacement_link); + + /* Convert displacement vector to bump height. */ + bNode *dot_node = nodeAddStaticNode(NULL, ntree, SH_NODE_VECT_MATH); + bNode *geo_node = nodeAddStaticNode(NULL, ntree, SH_NODE_NEW_GEOMETRY); + dot_node->custom1 = 3; /* dot product */ + + nodeAddLink(ntree, displacement_node, displacement_socket, dot_node, dot_node->inputs.first); + nodeAddLink(ntree, + geo_node, + ntree_shader_node_find_output(geo_node, "Normal"), + dot_node, + dot_node->inputs.last); + displacement_node = dot_node; + displacement_socket = ntree_shader_node_find_output(dot_node, "Value"); + + /* We can't connect displacement to normal directly, use bump node for that + * and hope that it gives good enough approximation. + */ + bNode *bump_node = nodeAddStaticNode(NULL, ntree, SH_NODE_BUMP); + bNodeSocket *bump_input_socket = ntree_shader_node_find_input(bump_node, "Height"); + bNodeSocket *bump_output_socket = ntree_shader_node_find_output(bump_node, "Normal"); + BLI_assert(bump_input_socket != NULL); + BLI_assert(bump_output_socket != NULL); + /* Connect bump node to where displacement output was originally + * connected to. + */ + nodeAddLink(ntree, displacement_node, displacement_socket, bump_node, bump_input_socket); + /* Connect all free-standing Normal inputs. */ + ntree_shader_link_builtin_normal( + ntree, bump_node, bump_output_socket, displacement_node, displacement_socket); + /* TODO(sergey): Reconnect Geometry Info->Normal sockets to the new + * bump node. + */ + /* We modified the tree, it needs to be updated now. */ + ntreeUpdateTree(G.main, ntree); } -static bool ntree_tag_bsdf_cb(bNode *fromnode, bNode *UNUSED(tonode), void *userdata, const bool UNUSED(reversed)) +static bool ntree_tag_bsdf_cb(bNode *fromnode, + bNode *UNUSED(tonode), + void *userdata, + const bool UNUSED(reversed)) { - /* Don't evaluate nodes more than once. */ - if (fromnode->tmp_flag) { - return true; - } - fromnode->tmp_flag = 1; - - switch (fromnode->type) { - case NODE_GROUP: - case NODE_CUSTOM_GROUP: - /* Recursive */ - if (fromnode->id != NULL) { - bNodeTree *ntree = (bNodeTree *)fromnode->id; - bNode *group_output = ntree_group_output_node(ntree); - ntree_shader_tag_nodes(ntree, group_output, (nTreeTags *)userdata); - } - break; - case SH_NODE_BSDF_ANISOTROPIC: - case SH_NODE_EEVEE_SPECULAR: - case SH_NODE_BSDF_GLOSSY: - case SH_NODE_BSDF_GLASS: - fromnode->ssr_id = ((nTreeTags *)userdata)->ssr_id; - ((nTreeTags *)userdata)->ssr_id += 1; - break; - case SH_NODE_SUBSURFACE_SCATTERING: - fromnode->sss_id = ((nTreeTags *)userdata)->sss_id; - ((nTreeTags *)userdata)->sss_id += 1; - break; - case SH_NODE_BSDF_PRINCIPLED: - fromnode->ssr_id = ((nTreeTags *)userdata)->ssr_id; - fromnode->sss_id = ((nTreeTags *)userdata)->sss_id; - ((nTreeTags *)userdata)->sss_id += 1; - ((nTreeTags *)userdata)->ssr_id += 1; - break; - default: - /* We could return false here but since we - * allow the use of Closure as RGBA, we can have - * Bsdf nodes linked to other Bsdf nodes. */ - break; - } - - return true; + /* Don't evaluate nodes more than once. */ + if (fromnode->tmp_flag) { + return true; + } + fromnode->tmp_flag = 1; + + switch (fromnode->type) { + case NODE_GROUP: + case NODE_CUSTOM_GROUP: + /* Recursive */ + if (fromnode->id != NULL) { + bNodeTree *ntree = (bNodeTree *)fromnode->id; + bNode *group_output = ntree_group_output_node(ntree); + ntree_shader_tag_nodes(ntree, group_output, (nTreeTags *)userdata); + } + break; + case SH_NODE_BSDF_ANISOTROPIC: + case SH_NODE_EEVEE_SPECULAR: + case SH_NODE_BSDF_GLOSSY: + case SH_NODE_BSDF_GLASS: + fromnode->ssr_id = ((nTreeTags *)userdata)->ssr_id; + ((nTreeTags *)userdata)->ssr_id += 1; + break; + case SH_NODE_SUBSURFACE_SCATTERING: + fromnode->sss_id = ((nTreeTags *)userdata)->sss_id; + ((nTreeTags *)userdata)->sss_id += 1; + break; + case SH_NODE_BSDF_PRINCIPLED: + fromnode->ssr_id = ((nTreeTags *)userdata)->ssr_id; + fromnode->sss_id = ((nTreeTags *)userdata)->sss_id; + ((nTreeTags *)userdata)->sss_id += 1; + ((nTreeTags *)userdata)->ssr_id += 1; + break; + default: + /* We could return false here but since we + * allow the use of Closure as RGBA, we can have + * Bsdf nodes linked to other Bsdf nodes. */ + break; + } + + return true; } /* EEVEE: Scan the ntree to set the Screen Space Reflection @@ -805,162 +770,168 @@ static bool ntree_tag_bsdf_cb(bNode *fromnode, bNode *UNUSED(tonode), void *user */ void ntree_shader_tag_nodes(bNodeTree *ntree, bNode *output_node, nTreeTags *tags) { - if (output_node == NULL) { - return; - } - /* Make sure sockets links pointers are correct. */ - ntreeUpdateTree(G.main, ntree); - - /* Reset visit flag. */ - for (bNode *node = ntree->nodes.first; node; node = node->next) { - node->tmp_flag = 0; - } - - nodeChainIter(ntree, output_node, ntree_tag_bsdf_cb, tags, true); + if (output_node == NULL) { + return; + } + /* Make sure sockets links pointers are correct. */ + ntreeUpdateTree(G.main, ntree); + + /* Reset visit flag. */ + for (bNode *node = ntree->nodes.first; node; node = node->next) { + node->tmp_flag = 0; + } + + nodeChainIter(ntree, output_node, ntree_tag_bsdf_cb, tags, true); } /* This one needs to work on a local tree. */ -void ntreeGPUMaterialNodes(bNodeTree *localtree, GPUMaterial *mat, bool *has_surface_output, bool *has_volume_output) +void ntreeGPUMaterialNodes(bNodeTree *localtree, + GPUMaterial *mat, + bool *has_surface_output, + bool *has_volume_output) { - bNodeTreeExec *exec; + bNodeTreeExec *exec; - /* Extract output nodes from inside nodegroups. */ - ntree_shader_output_node_from_group(localtree, SHD_OUTPUT_EEVEE); + /* Extract output nodes from inside nodegroups. */ + ntree_shader_output_node_from_group(localtree, SHD_OUTPUT_EEVEE); - bNode *output = ntreeShaderOutputNode(localtree, SHD_OUTPUT_EEVEE); + bNode *output = ntreeShaderOutputNode(localtree, SHD_OUTPUT_EEVEE); - ntree_shader_groups_expand_inputs(localtree); + ntree_shader_groups_expand_inputs(localtree); - /* Perform all needed modifications on the tree in order to support - * displacement/bump mapping. - */ - ntree_shader_relink_displacement(localtree, output); + /* Perform all needed modifications on the tree in order to support + * displacement/bump mapping. + */ + ntree_shader_relink_displacement(localtree, output); - /* TODO(fclem): consider moving this to the gpu shader tree evaluation. */ - nTreeTags tags = { - .ssr_id = 1.0, - .sss_id = 1.0, - }; - ntree_shader_tag_nodes(localtree, output, &tags); + /* TODO(fclem): consider moving this to the gpu shader tree evaluation. */ + nTreeTags tags = { + .ssr_id = 1.0, + .sss_id = 1.0, + }; + ntree_shader_tag_nodes(localtree, output, &tags); - exec = ntreeShaderBeginExecTree(localtree); - ntreeExecGPUNodes(exec, mat, output); - ntreeShaderEndExecTree(exec); + exec = ntreeShaderBeginExecTree(localtree); + ntreeExecGPUNodes(exec, mat, output); + ntreeShaderEndExecTree(exec); - /* EEVEE: Find which material domain was used (volume, surface ...). */ - *has_surface_output = false; - *has_volume_output = false; + /* EEVEE: Find which material domain was used (volume, surface ...). */ + *has_surface_output = false; + *has_volume_output = false; - if (output != NULL) { - bNodeSocket *surface_sock = ntree_shader_node_find_input(output, "Surface"); - bNodeSocket *volume_sock = ntree_shader_node_find_input(output, "Volume"); + if (output != NULL) { + bNodeSocket *surface_sock = ntree_shader_node_find_input(output, "Surface"); + bNodeSocket *volume_sock = ntree_shader_node_find_input(output, "Volume"); - if (surface_sock != NULL) { - *has_surface_output = (nodeCountSocketLinks(localtree, surface_sock) > 0); - } + if (surface_sock != NULL) { + *has_surface_output = (nodeCountSocketLinks(localtree, surface_sock) > 0); + } - if (volume_sock != NULL) { - *has_volume_output = (nodeCountSocketLinks(localtree, volume_sock) > 0); - } - } + if (volume_sock != NULL) { + *has_volume_output = (nodeCountSocketLinks(localtree, volume_sock) > 0); + } + } } -bNodeTreeExec *ntreeShaderBeginExecTree_internal(bNodeExecContext *context, bNodeTree *ntree, bNodeInstanceKey parent_key) +bNodeTreeExec *ntreeShaderBeginExecTree_internal(bNodeExecContext *context, + bNodeTree *ntree, + bNodeInstanceKey parent_key) { - bNodeTreeExec *exec; - bNode *node; + bNodeTreeExec *exec; + bNode *node; - /* ensures only a single output node is enabled */ - ntreeSetOutput(ntree); + /* ensures only a single output node is enabled */ + ntreeSetOutput(ntree); - /* common base initialization */ - exec = ntree_exec_begin(context, ntree, parent_key); + /* common base initialization */ + exec = ntree_exec_begin(context, ntree, parent_key); - /* allocate the thread stack listbase array */ - exec->threadstack = MEM_callocN(BLENDER_MAX_THREADS * sizeof(ListBase), "thread stack array"); + /* allocate the thread stack listbase array */ + exec->threadstack = MEM_callocN(BLENDER_MAX_THREADS * sizeof(ListBase), "thread stack array"); - for (node = exec->nodetree->nodes.first; node; node = node->next) - node->need_exec = 1; + for (node = exec->nodetree->nodes.first; node; node = node->next) + node->need_exec = 1; - return exec; + return exec; } bNodeTreeExec *ntreeShaderBeginExecTree(bNodeTree *ntree) { - bNodeExecContext context; - bNodeTreeExec *exec; + bNodeExecContext context; + bNodeTreeExec *exec; - /* XXX hack: prevent exec data from being generated twice. - * this should be handled by the renderer! - */ - if (ntree->execdata) - return ntree->execdata; + /* XXX hack: prevent exec data from being generated twice. + * this should be handled by the renderer! + */ + if (ntree->execdata) + return ntree->execdata; - context.previews = ntree->previews; + context.previews = ntree->previews; - exec = ntreeShaderBeginExecTree_internal(&context, ntree, NODE_INSTANCE_KEY_BASE); + exec = ntreeShaderBeginExecTree_internal(&context, ntree, NODE_INSTANCE_KEY_BASE); - /* XXX this should not be necessary, but is still used for cmp/sha/tex nodes, - * which only store the ntree pointer. Should be fixed at some point! - */ - ntree->execdata = exec; + /* XXX this should not be necessary, but is still used for cmp/sha/tex nodes, + * which only store the ntree pointer. Should be fixed at some point! + */ + ntree->execdata = exec; - return exec; + return exec; } void ntreeShaderEndExecTree_internal(bNodeTreeExec *exec) { - bNodeThreadStack *nts; - int a; - - if (exec->threadstack) { - for (a = 0; a < BLENDER_MAX_THREADS; a++) { - for (nts = exec->threadstack[a].first; nts; nts = nts->next) - if (nts->stack) MEM_freeN(nts->stack); - BLI_freelistN(&exec->threadstack[a]); - } - - MEM_freeN(exec->threadstack); - exec->threadstack = NULL; - } - - ntree_exec_end(exec); + bNodeThreadStack *nts; + int a; + + if (exec->threadstack) { + for (a = 0; a < BLENDER_MAX_THREADS; a++) { + for (nts = exec->threadstack[a].first; nts; nts = nts->next) + if (nts->stack) + MEM_freeN(nts->stack); + BLI_freelistN(&exec->threadstack[a]); + } + + MEM_freeN(exec->threadstack); + exec->threadstack = NULL; + } + + ntree_exec_end(exec); } void ntreeShaderEndExecTree(bNodeTreeExec *exec) { - if (exec) { - /* exec may get freed, so assign ntree */ - bNodeTree *ntree = exec->nodetree; - ntreeShaderEndExecTree_internal(exec); - - /* XXX clear nodetree backpointer to exec data, same problem as noted in ntreeBeginExecTree */ - ntree->execdata = NULL; - } + if (exec) { + /* exec may get freed, so assign ntree */ + bNodeTree *ntree = exec->nodetree; + ntreeShaderEndExecTree_internal(exec); + + /* XXX clear nodetree backpointer to exec data, same problem as noted in ntreeBeginExecTree */ + ntree->execdata = NULL; + } } /* TODO: left over from Blender Internal, could reuse for new texture nodes. */ bool ntreeShaderExecTree(bNodeTree *ntree, int thread) { - ShaderCallData scd; - bNodeThreadStack *nts = NULL; - bNodeTreeExec *exec = ntree->execdata; - int compat; - - /* ensure execdata is only initialized once */ - if (!exec) { - BLI_thread_lock(LOCK_NODES); - if (!ntree->execdata) - ntree->execdata = ntreeShaderBeginExecTree(ntree); - BLI_thread_unlock(LOCK_NODES); - - exec = ntree->execdata; - } - - nts = ntreeGetThreadStack(exec, thread); - compat = ntreeExecThreadNodes(exec, nts, &scd, thread); - ntreeReleaseThreadStack(nts); - - /* if compat is zero, it has been using non-compatible nodes */ - return compat; + ShaderCallData scd; + bNodeThreadStack *nts = NULL; + bNodeTreeExec *exec = ntree->execdata; + int compat; + + /* ensure execdata is only initialized once */ + if (!exec) { + BLI_thread_lock(LOCK_NODES); + if (!ntree->execdata) + ntree->execdata = ntreeShaderBeginExecTree(ntree); + BLI_thread_unlock(LOCK_NODES); + + exec = ntree->execdata; + } + + nts = ntreeGetThreadStack(exec, thread); + compat = ntreeExecThreadNodes(exec, nts, &scd, thread); + ntreeReleaseThreadStack(nts); + + /* if compat is zero, it has been using non-compatible nodes */ + return compat; } diff --git a/source/blender/nodes/shader/node_shader_util.c b/source/blender/nodes/shader/node_shader_util.c index 19bfd755928..a29962843af 100644 --- a/source/blender/nodes/shader/node_shader_util.c +++ b/source/blender/nodes/shader/node_shader_util.c @@ -21,246 +21,247 @@ * \ingroup nodes */ - #include "DNA_node_types.h" #include "node_shader_util.h" #include "node_exec.h" - bool sh_node_poll_default(bNodeType *UNUSED(ntype), bNodeTree *ntree) { - return STREQ(ntree->idname, "ShaderNodeTree"); + return STREQ(ntree->idname, "ShaderNodeTree"); } -void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag) +void sh_node_type_base( + struct bNodeType *ntype, int type, const char *name, short nclass, short flag) { - node_type_base(ntype, type, name, nclass, flag); + node_type_base(ntype, type, name, nclass, flag); - ntype->poll = sh_node_poll_default; - ntype->insert_link = node_insert_link_default; - ntype->update_internal_links = node_update_internal_links_default; + ntype->poll = sh_node_poll_default; + ntype->insert_link = node_insert_link_default; + ntype->update_internal_links = node_update_internal_links_default; } /* ****** */ void nodestack_get_vec(float *in, short type_in, bNodeStack *ns) { - const float *from = ns->vec; - - if (type_in == SOCK_FLOAT) { - if (ns->sockettype == SOCK_FLOAT) - *in = *from; - else - *in = (from[0] + from[1] + from[2]) / 3.0f; - } - else if (type_in == SOCK_VECTOR) { - if (ns->sockettype == SOCK_FLOAT) { - in[0] = from[0]; - in[1] = from[0]; - in[2] = from[0]; - } - else { - copy_v3_v3(in, from); - } - } - else { /* type_in==SOCK_RGBA */ - if (ns->sockettype == SOCK_RGBA) { - copy_v4_v4(in, from); - } - else if (ns->sockettype == SOCK_FLOAT) { - in[0] = from[0]; - in[1] = from[0]; - in[2] = from[0]; - in[3] = 1.0f; - } - else { - copy_v3_v3(in, from); - in[3] = 1.0f; - } - } + const float *from = ns->vec; + + if (type_in == SOCK_FLOAT) { + if (ns->sockettype == SOCK_FLOAT) + *in = *from; + else + *in = (from[0] + from[1] + from[2]) / 3.0f; + } + else if (type_in == SOCK_VECTOR) { + if (ns->sockettype == SOCK_FLOAT) { + in[0] = from[0]; + in[1] = from[0]; + in[2] = from[0]; + } + else { + copy_v3_v3(in, from); + } + } + else { /* type_in==SOCK_RGBA */ + if (ns->sockettype == SOCK_RGBA) { + copy_v4_v4(in, from); + } + else if (ns->sockettype == SOCK_FLOAT) { + in[0] = from[0]; + in[1] = from[0]; + in[2] = from[0]; + in[3] = 1.0f; + } + else { + copy_v3_v3(in, from); + in[3] = 1.0f; + } + } } - void node_gpu_stack_from_data(struct GPUNodeStack *gs, int type, bNodeStack *ns) { - memset(gs, 0, sizeof(*gs)); - - if (ns == NULL) { - /* node_get_stack() will generate NULL bNodeStack pointers for unknown/unsupported types of sockets... */ - zero_v4(gs->vec); - gs->link = NULL; - gs->type = GPU_NONE; - gs->hasinput = false; - gs->hasoutput = false; - gs->sockettype = type; - } - else { - nodestack_get_vec(gs->vec, type, ns); - gs->link = ns->data; - - if (type == SOCK_FLOAT) - gs->type = GPU_FLOAT; - else if (type == SOCK_INT) - gs->type = GPU_FLOAT; /* HACK: Support as float. */ - else if (type == SOCK_VECTOR) - gs->type = GPU_VEC3; - else if (type == SOCK_RGBA) - gs->type = GPU_VEC4; - else if (type == SOCK_SHADER) - gs->type = GPU_CLOSURE; - else - gs->type = GPU_NONE; - - gs->hasinput = ns->hasinput && ns->data; - /* XXX Commented out the ns->data check here, as it seems it's not always set, - * even though there *is* a valid connection/output... But that might need - * further investigation. - */ - gs->hasoutput = ns->hasoutput /*&& ns->data*/; - gs->sockettype = ns->sockettype; - } + memset(gs, 0, sizeof(*gs)); + + if (ns == NULL) { + /* node_get_stack() will generate NULL bNodeStack pointers for unknown/unsupported types of sockets... */ + zero_v4(gs->vec); + gs->link = NULL; + gs->type = GPU_NONE; + gs->hasinput = false; + gs->hasoutput = false; + gs->sockettype = type; + } + else { + nodestack_get_vec(gs->vec, type, ns); + gs->link = ns->data; + + if (type == SOCK_FLOAT) + gs->type = GPU_FLOAT; + else if (type == SOCK_INT) + gs->type = GPU_FLOAT; /* HACK: Support as float. */ + else if (type == SOCK_VECTOR) + gs->type = GPU_VEC3; + else if (type == SOCK_RGBA) + gs->type = GPU_VEC4; + else if (type == SOCK_SHADER) + gs->type = GPU_CLOSURE; + else + gs->type = GPU_NONE; + + gs->hasinput = ns->hasinput && ns->data; + /* XXX Commented out the ns->data check here, as it seems it's not always set, + * even though there *is* a valid connection/output... But that might need + * further investigation. + */ + gs->hasoutput = ns->hasoutput /*&& ns->data*/; + gs->sockettype = ns->sockettype; + } } void node_data_from_gpu_stack(bNodeStack *ns, GPUNodeStack *gs) { - copy_v4_v4(ns->vec, gs->vec); - ns->data = gs->link; - ns->sockettype = gs->sockettype; + copy_v4_v4(ns->vec, gs->vec); + ns->data = gs->link; + ns->sockettype = gs->sockettype; } static void gpu_stack_from_data_list(GPUNodeStack *gs, ListBase *sockets, bNodeStack **ns) { - bNodeSocket *sock; - int i; + bNodeSocket *sock; + int i; - for (sock = sockets->first, i = 0; sock; sock = sock->next, i++) - node_gpu_stack_from_data(&gs[i], sock->type, ns[i]); + for (sock = sockets->first, i = 0; sock; sock = sock->next, i++) + node_gpu_stack_from_data(&gs[i], sock->type, ns[i]); - gs[i].end = true; + gs[i].end = true; } static void data_from_gpu_stack_list(ListBase *sockets, bNodeStack **ns, GPUNodeStack *gs) { - bNodeSocket *sock; - int i; + bNodeSocket *sock; + int i; - for (sock = sockets->first, i = 0; sock; sock = sock->next, i++) - node_data_from_gpu_stack(ns[i], &gs[i]); + for (sock = sockets->first, i = 0; sock; sock = sock->next, i++) + node_data_from_gpu_stack(ns[i], &gs[i]); } bNode *nodeGetActiveTexture(bNodeTree *ntree) { - /* this is the node we texture paint and draw in textured draw */ - bNode *node, *tnode, *inactivenode = NULL, *activetexnode = NULL, *activegroup = NULL; - bool hasgroup = false; - - if (!ntree) - return NULL; - - for (node = ntree->nodes.first; node; node = node->next) { - if (node->flag & NODE_ACTIVE_TEXTURE) { - activetexnode = node; - /* if active we can return immediately */ - if (node->flag & NODE_ACTIVE) - return node; - } - else if (!inactivenode && node->typeinfo->nclass == NODE_CLASS_TEXTURE) - inactivenode = node; - else if (node->type == NODE_GROUP) { - if (node->flag & NODE_ACTIVE) - activegroup = node; - else - hasgroup = true; - } - } - - /* first, check active group for textures */ - if (activegroup) { - tnode = nodeGetActiveTexture((bNodeTree *)activegroup->id); - /* active node takes priority, so ignore any other possible nodes here */ - if (tnode) - return tnode; - } - - if (activetexnode) - return activetexnode; - - if (hasgroup) { - /* node active texture node in this tree, look inside groups */ - for (node = ntree->nodes.first; node; node = node->next) { - if (node->type == NODE_GROUP) { - tnode = nodeGetActiveTexture((bNodeTree *)node->id); - if (tnode && ((tnode->flag & NODE_ACTIVE_TEXTURE) || !inactivenode)) - return tnode; - } - } - } - - return inactivenode; + /* this is the node we texture paint and draw in textured draw */ + bNode *node, *tnode, *inactivenode = NULL, *activetexnode = NULL, *activegroup = NULL; + bool hasgroup = false; + + if (!ntree) + return NULL; + + for (node = ntree->nodes.first; node; node = node->next) { + if (node->flag & NODE_ACTIVE_TEXTURE) { + activetexnode = node; + /* if active we can return immediately */ + if (node->flag & NODE_ACTIVE) + return node; + } + else if (!inactivenode && node->typeinfo->nclass == NODE_CLASS_TEXTURE) + inactivenode = node; + else if (node->type == NODE_GROUP) { + if (node->flag & NODE_ACTIVE) + activegroup = node; + else + hasgroup = true; + } + } + + /* first, check active group for textures */ + if (activegroup) { + tnode = nodeGetActiveTexture((bNodeTree *)activegroup->id); + /* active node takes priority, so ignore any other possible nodes here */ + if (tnode) + return tnode; + } + + if (activetexnode) + return activetexnode; + + if (hasgroup) { + /* node active texture node in this tree, look inside groups */ + for (node = ntree->nodes.first; node; node = node->next) { + if (node->type == NODE_GROUP) { + tnode = nodeGetActiveTexture((bNodeTree *)node->id); + if (tnode && ((tnode->flag & NODE_ACTIVE_TEXTURE) || !inactivenode)) + return tnode; + } + } + } + + return inactivenode; } void ntreeExecGPUNodes(bNodeTreeExec *exec, GPUMaterial *mat, bNode *output_node) { - bNodeExec *nodeexec; - bNode *node; - int n; - bNodeStack *stack; - bNodeStack *nsin[MAX_SOCKET]; /* arbitrary... watch this */ - bNodeStack *nsout[MAX_SOCKET]; /* arbitrary... watch this */ - GPUNodeStack gpuin[MAX_SOCKET + 1], gpuout[MAX_SOCKET + 1]; - bool do_it; - - stack = exec->stack; - - for (n = 0, nodeexec = exec->nodeexec; n < exec->totnodes; ++n, ++nodeexec) { - node = nodeexec->node; - - do_it = false; - /* for groups, only execute outputs for edited group */ - if (node->typeinfo->nclass == NODE_CLASS_OUTPUT) { - if ((output_node != NULL) && (node == output_node)) - do_it = true; - } - else { - do_it = true; - } - - if (do_it) { - if (node->typeinfo->gpufunc) { - node_get_stack(node, stack, nsin, nsout); - gpu_stack_from_data_list(gpuin, &node->inputs, nsin); - gpu_stack_from_data_list(gpuout, &node->outputs, nsout); - if (node->typeinfo->gpufunc(mat, node, &nodeexec->data, gpuin, gpuout)) - data_from_gpu_stack_list(&node->outputs, nsout, gpuout); - } - } - } + bNodeExec *nodeexec; + bNode *node; + int n; + bNodeStack *stack; + bNodeStack *nsin[MAX_SOCKET]; /* arbitrary... watch this */ + bNodeStack *nsout[MAX_SOCKET]; /* arbitrary... watch this */ + GPUNodeStack gpuin[MAX_SOCKET + 1], gpuout[MAX_SOCKET + 1]; + bool do_it; + + stack = exec->stack; + + for (n = 0, nodeexec = exec->nodeexec; n < exec->totnodes; ++n, ++nodeexec) { + node = nodeexec->node; + + do_it = false; + /* for groups, only execute outputs for edited group */ + if (node->typeinfo->nclass == NODE_CLASS_OUTPUT) { + if ((output_node != NULL) && (node == output_node)) + do_it = true; + } + else { + do_it = true; + } + + if (do_it) { + if (node->typeinfo->gpufunc) { + node_get_stack(node, stack, nsin, nsout); + gpu_stack_from_data_list(gpuin, &node->inputs, nsin); + gpu_stack_from_data_list(gpuout, &node->outputs, nsout); + if (node->typeinfo->gpufunc(mat, node, &nodeexec->data, gpuin, gpuout)) + data_from_gpu_stack_list(&node->outputs, nsout, gpuout); + } + } + } } -void node_shader_gpu_tex_mapping(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *UNUSED(out)) +void node_shader_gpu_tex_mapping(GPUMaterial *mat, + bNode *node, + GPUNodeStack *in, + GPUNodeStack *UNUSED(out)) { - NodeTexBase *base = node->storage; - TexMapping *texmap = &base->tex_mapping; - float domin = (texmap->flag & TEXMAP_CLIP_MIN) != 0; - float domax = (texmap->flag & TEXMAP_CLIP_MAX) != 0; - - if (domin || domax || !(texmap->flag & TEXMAP_UNIT_MATRIX)) { - static float max[3] = { FLT_MAX, FLT_MAX, FLT_MAX}; - static float min[3] = {-FLT_MAX, -FLT_MAX, -FLT_MAX}; - GPUNodeLink *tmin, *tmax, *tmat0, *tmat1, *tmat2, *tmat3; - - tmin = GPU_uniform((domin) ? texmap->min : min); - tmax = GPU_uniform((domax) ? texmap->max : max); - tmat0 = GPU_uniform((float *)texmap->mat[0]); - tmat1 = GPU_uniform((float *)texmap->mat[1]); - tmat2 = GPU_uniform((float *)texmap->mat[2]); - tmat3 = GPU_uniform((float *)texmap->mat[3]); - - GPU_link(mat, "mapping", in[0].link, tmat0, tmat1, tmat2, tmat3, tmin, tmax, &in[0].link); - - if (texmap->type == TEXMAP_TYPE_NORMAL) - GPU_link(mat, "texco_norm", in[0].link, &in[0].link); - } + NodeTexBase *base = node->storage; + TexMapping *texmap = &base->tex_mapping; + float domin = (texmap->flag & TEXMAP_CLIP_MIN) != 0; + float domax = (texmap->flag & TEXMAP_CLIP_MAX) != 0; + + if (domin || domax || !(texmap->flag & TEXMAP_UNIT_MATRIX)) { + static float max[3] = {FLT_MAX, FLT_MAX, FLT_MAX}; + static float min[3] = {-FLT_MAX, -FLT_MAX, -FLT_MAX}; + GPUNodeLink *tmin, *tmax, *tmat0, *tmat1, *tmat2, *tmat3; + + tmin = GPU_uniform((domin) ? texmap->min : min); + tmax = GPU_uniform((domax) ? texmap->max : max); + tmat0 = GPU_uniform((float *)texmap->mat[0]); + tmat1 = GPU_uniform((float *)texmap->mat[1]); + tmat2 = GPU_uniform((float *)texmap->mat[2]); + tmat3 = GPU_uniform((float *)texmap->mat[3]); + + GPU_link(mat, "mapping", in[0].link, tmat0, tmat1, tmat2, tmat3, tmin, tmax, &in[0].link); + + if (texmap->type == TEXMAP_TYPE_NORMAL) + GPU_link(mat, "texco_norm", in[0].link, &in[0].link); + } } diff --git a/source/blender/nodes/shader/node_shader_util.h b/source/blender/nodes/shader/node_shader_util.h index e457f2f8b56..916cb81953e 100644 --- a/source/blender/nodes/shader/node_shader_util.h +++ b/source/blender/nodes/shader/node_shader_util.h @@ -21,7 +21,6 @@ * \ingroup nodes */ - #ifndef __NODE_SHADER_UTIL_H__ #define __NODE_SHADER_UTIL_H__ @@ -70,24 +69,28 @@ #include "GPU_material.h" #include "GPU_uniformbuffer.h" - bool sh_node_poll_default(struct bNodeType *ntype, struct bNodeTree *ntree); -void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag); - +void sh_node_type_base( + struct bNodeType *ntype, int type, const char *name, short nclass, short flag); /* ********* exec data struct, remains internal *********** */ typedef struct ShaderCallData { - /* Empty for now, may be reused if we convert shader to texture nodes. */ - int dummy; + /* Empty for now, may be reused if we convert shader to texture nodes. */ + int dummy; } ShaderCallData; void nodestack_get_vec(float *in, short type_in, bNodeStack *ns); void node_gpu_stack_from_data(struct GPUNodeStack *gs, int type, struct bNodeStack *ns); void node_data_from_gpu_stack(struct bNodeStack *ns, struct GPUNodeStack *gs); -void node_shader_gpu_tex_mapping(struct GPUMaterial *mat, struct bNode *node, struct GPUNodeStack *in, struct GPUNodeStack *out); - -void ntreeExecGPUNodes(struct bNodeTreeExec *exec, struct GPUMaterial *mat, struct bNode *output_node); +void node_shader_gpu_tex_mapping(struct GPUMaterial *mat, + struct bNode *node, + struct GPUNodeStack *in, + struct GPUNodeStack *out); + +void ntreeExecGPUNodes(struct bNodeTreeExec *exec, + struct GPUMaterial *mat, + struct bNode *output_node); #endif diff --git a/source/blender/nodes/shader/nodes/node_shader_add_shader.c b/source/blender/nodes/shader/nodes/node_shader_add_shader.c index 3eb5e3831f4..35709af16d0 100644 --- a/source/blender/nodes/shader/nodes/node_shader_add_shader.c +++ b/source/blender/nodes/shader/nodes/node_shader_add_shader.c @@ -22,31 +22,35 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_add_shader_in[] = { - { SOCK_SHADER, 1, N_("Shader")}, - { SOCK_SHADER, 1, N_("Shader")}, - { -1, 0, "" }, + {SOCK_SHADER, 1, N_("Shader")}, + {SOCK_SHADER, 1, N_("Shader")}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_add_shader_out[] = { - { SOCK_SHADER, 0, N_("Shader")}, - { -1, 0, "" }, + {SOCK_SHADER, 0, N_("Shader")}, + {-1, 0, ""}, }; -static int node_shader_gpu_add_shader(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_add_shader(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "node_add_shader", in, out); + return GPU_stack_link(mat, node, "node_add_shader", in, out); } /* node type definition */ void register_node_type_sh_add_shader(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_ADD_SHADER, "Add Shader", NODE_CLASS_SHADER, 0); - node_type_socket_templates(&ntype, sh_node_add_shader_in, sh_node_add_shader_out); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_add_shader); + sh_node_type_base(&ntype, SH_NODE_ADD_SHADER, "Add Shader", NODE_CLASS_SHADER, 0); + node_type_socket_templates(&ntype, sh_node_add_shader_in, sh_node_add_shader_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_add_shader); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.c b/source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.c index e38a97ae9b2..84dda89c47d 100644 --- a/source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.c +++ b/source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.c @@ -22,44 +22,58 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_ambient_occlusion_in[] = { - { SOCK_RGBA, 1, N_("Color"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Distance"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Distance"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + {SOCK_VECTOR, + 1, + N_("Normal"), + 0.0f, + 0.0f, + 0.0f, + 1.0f, + -1.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_ambient_occlusion_out[] = { - { SOCK_RGBA, 0, N_("Color"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("AO"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("AO"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; -static int node_shader_gpu_ambient_occlusion(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_ambient_occlusion(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - if (!in[2].link) - GPU_link(mat, "world_normals_get", &in[2].link); + if (!in[2].link) + GPU_link(mat, "world_normals_get", &in[2].link); - GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE); + GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE); - return GPU_stack_link(mat, node, "node_ambient_occlusion", in, out); + return GPU_stack_link(mat, node, "node_ambient_occlusion", in, out); } static void node_shader_init_ambient_occlusion(bNodeTree *UNUSED(ntree), bNode *node) { - node->custom1 = 16; /* samples */ - node->custom2 = 0; + node->custom1 = 16; /* samples */ + node->custom2 = 0; } /* node type definition */ void register_node_type_sh_ambient_occlusion(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_AMBIENT_OCCLUSION, "Ambient Occlusion", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, sh_node_ambient_occlusion_in, sh_node_ambient_occlusion_out); - node_type_init(&ntype, node_shader_init_ambient_occlusion); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_ambient_occlusion); + sh_node_type_base(&ntype, SH_NODE_AMBIENT_OCCLUSION, "Ambient Occlusion", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, sh_node_ambient_occlusion_in, sh_node_ambient_occlusion_out); + node_type_init(&ntype, node_shader_init_ambient_occlusion); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_ambient_occlusion); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_attribute.c b/source/blender/nodes/shader/nodes/node_shader_attribute.c index 6f79b4588bb..489bb8c3557 100644 --- a/source/blender/nodes/shader/nodes/node_shader_attribute.c +++ b/source/blender/nodes/shader/nodes/node_shader_attribute.c @@ -22,56 +22,65 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_attribute_out[] = { - { SOCK_RGBA, 0, N_("Color")}, - { SOCK_VECTOR, 0, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Fac"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX, PROP_FACTOR}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color")}, + {SOCK_VECTOR, 0, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Fac"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX, PROP_FACTOR}, + {-1, 0, ""}, }; static void node_shader_init_attribute(bNodeTree *UNUSED(ntree), bNode *node) { - NodeShaderAttribute *attr = MEM_callocN(sizeof(NodeShaderAttribute), "NodeShaderAttribute"); - node->storage = attr; + NodeShaderAttribute *attr = MEM_callocN(sizeof(NodeShaderAttribute), "NodeShaderAttribute"); + node->storage = attr; } -static int node_shader_gpu_attribute(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_attribute(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - NodeShaderAttribute *attr = node->storage; + NodeShaderAttribute *attr = node->storage; - /* FIXME : if an attribute layer (like vertex color) has one of theses name, it will not work as expected. */ - if (strcmp(attr->name, "density") == 0) { - return GPU_stack_link(mat, node, "node_attribute_volume_density", in, out, - GPU_builtin(GPU_VOLUME_DENSITY)); - } - else if (strcmp(attr->name, "color") == 0) { - return GPU_stack_link(mat, node, "node_attribute_volume_color", in, out, - GPU_builtin(GPU_VOLUME_DENSITY)); - } - else if (strcmp(attr->name, "flame") == 0) { - return GPU_stack_link(mat, node, "node_attribute_volume_flame", in, out, - GPU_builtin(GPU_VOLUME_FLAME)); - } - else if (strcmp(attr->name, "temperature") == 0) { - return GPU_stack_link(mat, node, "node_attribute_volume_temperature", in, out, - GPU_builtin(GPU_VOLUME_FLAME), - GPU_builtin(GPU_VOLUME_TEMPERATURE)); - } - else { - GPUNodeLink *cd_attr = GPU_attribute(CD_AUTO_FROM_NAME, attr->name); - return GPU_stack_link(mat, node, "node_attribute", in, out, cd_attr); - } + /* FIXME : if an attribute layer (like vertex color) has one of theses name, it will not work as expected. */ + if (strcmp(attr->name, "density") == 0) { + return GPU_stack_link( + mat, node, "node_attribute_volume_density", in, out, GPU_builtin(GPU_VOLUME_DENSITY)); + } + else if (strcmp(attr->name, "color") == 0) { + return GPU_stack_link( + mat, node, "node_attribute_volume_color", in, out, GPU_builtin(GPU_VOLUME_DENSITY)); + } + else if (strcmp(attr->name, "flame") == 0) { + return GPU_stack_link( + mat, node, "node_attribute_volume_flame", in, out, GPU_builtin(GPU_VOLUME_FLAME)); + } + else if (strcmp(attr->name, "temperature") == 0) { + return GPU_stack_link(mat, + node, + "node_attribute_volume_temperature", + in, + out, + GPU_builtin(GPU_VOLUME_FLAME), + GPU_builtin(GPU_VOLUME_TEMPERATURE)); + } + else { + GPUNodeLink *cd_attr = GPU_attribute(CD_AUTO_FROM_NAME, attr->name); + return GPU_stack_link(mat, node, "node_attribute", in, out, cd_attr); + } } /* node type definition */ void register_node_type_sh_attribute(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_ATTRIBUTE, "Attribute", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, NULL, sh_node_attribute_out); - node_type_init(&ntype, node_shader_init_attribute); - node_type_storage(&ntype, "NodeShaderAttribute", node_free_standard_storage, node_copy_standard_storage); - node_type_gpu(&ntype, node_shader_gpu_attribute); + sh_node_type_base(&ntype, SH_NODE_ATTRIBUTE, "Attribute", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, NULL, sh_node_attribute_out); + node_type_init(&ntype, node_shader_init_attribute); + node_type_storage( + &ntype, "NodeShaderAttribute", node_free_standard_storage, node_copy_standard_storage); + node_type_gpu(&ntype, node_shader_gpu_attribute); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_background.c b/source/blender/nodes/shader/nodes/node_shader_background.c index 8301a5476db..ddef020efa0 100644 --- a/source/blender/nodes/shader/nodes/node_shader_background.c +++ b/source/blender/nodes/shader/nodes/node_shader_background.c @@ -22,31 +22,35 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_background_in[] = { - { SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Strength"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000000.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Strength"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000000.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_background_out[] = { - { SOCK_SHADER, 0, N_("Background")}, - { -1, 0, "" }, + {SOCK_SHADER, 0, N_("Background")}, + {-1, 0, ""}, }; -static int node_shader_gpu_background(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_background(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "node_background", in, out); + return GPU_stack_link(mat, node, "node_background", in, out); } /* node type definition */ void register_node_type_sh_background(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_BACKGROUND, "Background", NODE_CLASS_SHADER, 0); - node_type_socket_templates(&ntype, sh_node_background_in, sh_node_background_out); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_background); + sh_node_type_base(&ntype, SH_NODE_BACKGROUND, "Background", NODE_CLASS_SHADER, 0); + node_type_socket_templates(&ntype, sh_node_background_in, sh_node_background_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_background); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_bevel.c b/source/blender/nodes/shader/nodes/node_shader_bevel.c index 7b89c7d6f98..7878ff7c50b 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bevel.c +++ b/source/blender/nodes/shader/nodes/node_shader_bevel.c @@ -22,40 +22,58 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_bevel_in[] = { - { SOCK_FLOAT, 1, N_("Radius"), 0.05f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Radius"), 0.05f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + {SOCK_VECTOR, + 1, + N_("Normal"), + 0.0f, + 0.0f, + 0.0f, + 1.0f, + -1.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_bevel_out[] = { - { SOCK_VECTOR, 0, N_("Normal"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_VECTOR, 0, N_("Normal"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; static void node_shader_init_bevel(bNodeTree *UNUSED(ntree), bNode *node) { - node->custom1 = 4; /* samples */ + node->custom1 = 4; /* samples */ } -static int gpu_shader_bevel(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_bevel(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - if (!in[1].link) { - GPU_link(mat, "direction_transform_m4v3", GPU_builtin(GPU_VIEW_NORMAL), GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &in[1].link); - } + if (!in[1].link) { + GPU_link(mat, + "direction_transform_m4v3", + GPU_builtin(GPU_VIEW_NORMAL), + GPU_builtin(GPU_INVERSE_VIEW_MATRIX), + &in[1].link); + } - return GPU_stack_link(mat, node, "node_bevel", in, out); + return GPU_stack_link(mat, node, "node_bevel", in, out); } /* node type definition */ void register_node_type_sh_bevel(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_BEVEL, "Bevel", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, sh_node_bevel_in, sh_node_bevel_out); - node_type_init(&ntype, node_shader_init_bevel); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, gpu_shader_bevel); + sh_node_type_base(&ntype, SH_NODE_BEVEL, "Bevel", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, sh_node_bevel_in, sh_node_bevel_out); + node_type_init(&ntype, node_shader_init_bevel); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, gpu_shader_bevel); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_blackbody.c b/source/blender/nodes/shader/nodes/node_shader_blackbody.c index 7e7dcffc8ee..35e0d1e74e7 100644 --- a/source/blender/nodes/shader/nodes/node_shader_blackbody.c +++ b/source/blender/nodes/shader/nodes/node_shader_blackbody.c @@ -21,39 +21,43 @@ /* **************** Blackbody ******************** */ static bNodeSocketTemplate sh_node_blackbody_in[] = { - { SOCK_FLOAT, 1, N_("Temperature"), 1500.0f, 0.0f, 0.0f, 0.0f, 800.0f, 12000.0f}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Temperature"), 1500.0f, 0.0f, 0.0f, 0.0f, 800.0f, 12000.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_blackbody_out[] = { - { SOCK_RGBA, 0, N_("Color")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color")}, + {-1, 0, ""}, }; -static int node_shader_gpu_blackbody(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_blackbody(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - const int size = CM_TABLE + 1; - float *data = MEM_mallocN(sizeof(float) * size * 4, "blackbody texture"); + const int size = CM_TABLE + 1; + float *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); - float layer; - GPUNodeLink *ramp_texture = GPU_color_band(mat, size, data, &layer); + float layer; + GPUNodeLink *ramp_texture = GPU_color_band(mat, size, data, &layer); - return GPU_stack_link(mat, node, "node_blackbody", in, out, ramp_texture, GPU_constant(&layer)); + return GPU_stack_link(mat, node, "node_blackbody", in, out, ramp_texture, GPU_constant(&layer)); } /* node type definition */ void register_node_type_sh_blackbody(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_BLACKBODY, "Blackbody", NODE_CLASS_CONVERTOR, 0); - node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); - node_type_socket_templates(&ntype, sh_node_blackbody_in, sh_node_blackbody_out); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_blackbody); + sh_node_type_base(&ntype, SH_NODE_BLACKBODY, "Blackbody", NODE_CLASS_CONVERTOR, 0); + node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); + node_type_socket_templates(&ntype, sh_node_blackbody_in, sh_node_blackbody_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_blackbody); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_brightness.c b/source/blender/nodes/shader/nodes/node_shader_brightness.c index 5fee57fe0bf..646284d458b 100644 --- a/source/blender/nodes/shader/nodes/node_shader_brightness.c +++ b/source/blender/nodes/shader/nodes/node_shader_brightness.c @@ -19,35 +19,38 @@ #include "node_shader_util.h" - /* **************** Brigh and contrsast ******************** */ static bNodeSocketTemplate sh_node_brightcontrast_in[] = { - { SOCK_RGBA, 1, N_("Color"), 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Bright"), 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("Contrast"), 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Bright"), 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("Contrast"), 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_brightcontrast_out[] = { - { SOCK_RGBA, 0, N_("Color")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color")}, + {-1, 0, ""}, }; -static int gpu_shader_brightcontrast(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_brightcontrast(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "brightness_contrast", in, out); + return GPU_stack_link(mat, node, "brightness_contrast", in, out); } void register_node_type_sh_brightcontrast(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_BRIGHTCONTRAST, "Bright/Contrast", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, sh_node_brightcontrast_in, sh_node_brightcontrast_out); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, gpu_shader_brightcontrast); + sh_node_type_base(&ntype, SH_NODE_BRIGHTCONTRAST, "Bright/Contrast", NODE_CLASS_OP_COLOR, 0); + node_type_socket_templates(&ntype, sh_node_brightcontrast_in, sh_node_brightcontrast_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, gpu_shader_brightcontrast); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.c index e0303b07e10..dc92af5ee48 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.c @@ -22,46 +22,70 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_bsdf_anisotropic_in[] = { - { SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Roughness"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("Anisotropy"), 0.5f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Rotation"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { SOCK_VECTOR, 1, N_("Tangent"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Roughness"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Anisotropy"), 0.5f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Rotation"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_VECTOR, + 1, + N_("Normal"), + 0.0f, + 0.0f, + 0.0f, + 1.0f, + -1.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {SOCK_VECTOR, + 1, + N_("Tangent"), + 0.0f, + 0.0f, + 0.0f, + 1.0f, + -1.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_bsdf_anisotropic_out[] = { - { SOCK_SHADER, 0, N_("BSDF")}, - { -1, 0, "" }, + {SOCK_SHADER, 0, N_("BSDF")}, + {-1, 0, ""}, }; static void node_shader_init_anisotropic(bNodeTree *UNUSED(ntree), bNode *node) { - node->custom1 = SHD_GLOSSY_GGX; + node->custom1 = SHD_GLOSSY_GGX; } -static int node_shader_gpu_bsdf_anisotropic(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_bsdf_anisotropic(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - if (!in[4].link) - GPU_link(mat, "world_normals_get", &in[4].link); + if (!in[4].link) + GPU_link(mat, "world_normals_get", &in[4].link); - GPU_material_flag_set(mat, GPU_MATFLAG_GLOSSY); + GPU_material_flag_set(mat, GPU_MATFLAG_GLOSSY); - return GPU_stack_link(mat, node, "node_bsdf_anisotropic", in, out); + return GPU_stack_link(mat, node, "node_bsdf_anisotropic", in, out); } /* node type definition */ void register_node_type_sh_bsdf_anisotropic(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_BSDF_ANISOTROPIC, "Anisotropic BSDF", NODE_CLASS_SHADER, 0); - node_type_socket_templates(&ntype, sh_node_bsdf_anisotropic_in, sh_node_bsdf_anisotropic_out); - node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); - node_type_init(&ntype, node_shader_init_anisotropic); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_bsdf_anisotropic); + sh_node_type_base(&ntype, SH_NODE_BSDF_ANISOTROPIC, "Anisotropic BSDF", NODE_CLASS_SHADER, 0); + node_type_socket_templates(&ntype, sh_node_bsdf_anisotropic_in, sh_node_bsdf_anisotropic_out); + node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); + node_type_init(&ntype, node_shader_init_anisotropic); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_bsdf_anisotropic); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.c index 15640eba6e9..5ed02a275f1 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.c @@ -22,38 +22,52 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_bsdf_diffuse_in[] = { - { SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Roughness"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Roughness"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_VECTOR, + 1, + N_("Normal"), + 0.0f, + 0.0f, + 0.0f, + 1.0f, + -1.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_bsdf_diffuse_out[] = { - { SOCK_SHADER, 0, N_("BSDF")}, - { -1, 0, "" }, + {SOCK_SHADER, 0, N_("BSDF")}, + {-1, 0, ""}, }; -static int node_shader_gpu_bsdf_diffuse(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_bsdf_diffuse(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - if (!in[2].link) - GPU_link(mat, "world_normals_get", &in[2].link); + if (!in[2].link) + GPU_link(mat, "world_normals_get", &in[2].link); - GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE); + GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE); - return GPU_stack_link(mat, node, "node_bsdf_diffuse", in, out); + return GPU_stack_link(mat, node, "node_bsdf_diffuse", in, out); } /* node type definition */ void register_node_type_sh_bsdf_diffuse(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_BSDF_DIFFUSE, "Diffuse BSDF", NODE_CLASS_SHADER, 0); - node_type_socket_templates(&ntype, sh_node_bsdf_diffuse_in, sh_node_bsdf_diffuse_out); - node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_bsdf_diffuse); + sh_node_type_base(&ntype, SH_NODE_BSDF_DIFFUSE, "Diffuse BSDF", NODE_CLASS_SHADER, 0); + node_type_socket_templates(&ntype, sh_node_bsdf_diffuse_in, sh_node_bsdf_diffuse_out); + node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_bsdf_diffuse); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_glass.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_glass.c index 20f000dc62b..682fddc1f9d 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_glass.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_glass.c @@ -22,44 +22,58 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_bsdf_glass_in[] = { - { SOCK_RGBA, 1, N_("Color"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Roughness"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("IOR"), 1.45f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Roughness"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("IOR"), 1.45f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + {SOCK_VECTOR, + 1, + N_("Normal"), + 0.0f, + 0.0f, + 0.0f, + 1.0f, + -1.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_bsdf_glass_out[] = { - { SOCK_SHADER, 0, N_("BSDF")}, - { -1, 0, "" }, + {SOCK_SHADER, 0, N_("BSDF")}, + {-1, 0, ""}, }; static void node_shader_init_glass(bNodeTree *UNUSED(ntree), bNode *node) { - node->custom1 = SHD_GLOSSY_BECKMANN; + node->custom1 = SHD_GLOSSY_BECKMANN; } -static int node_shader_gpu_bsdf_glass(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_bsdf_glass(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - if (!in[3].link) - GPU_link(mat, "world_normals_get", &in[3].link); + if (!in[3].link) + GPU_link(mat, "world_normals_get", &in[3].link); - GPU_material_flag_set(mat, GPU_MATFLAG_GLOSSY | GPU_MATFLAG_REFRACT); + GPU_material_flag_set(mat, GPU_MATFLAG_GLOSSY | GPU_MATFLAG_REFRACT); - return GPU_stack_link(mat, node, "node_bsdf_glass", in, out, GPU_constant(&node->ssr_id)); + return GPU_stack_link(mat, node, "node_bsdf_glass", in, out, GPU_constant(&node->ssr_id)); } /* node type definition */ void register_node_type_sh_bsdf_glass(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_BSDF_GLASS, "Glass BSDF", NODE_CLASS_SHADER, 0); - node_type_socket_templates(&ntype, sh_node_bsdf_glass_in, sh_node_bsdf_glass_out); - node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); - node_type_init(&ntype, node_shader_init_glass); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_bsdf_glass); + sh_node_type_base(&ntype, SH_NODE_BSDF_GLASS, "Glass BSDF", NODE_CLASS_SHADER, 0); + node_type_socket_templates(&ntype, sh_node_bsdf_glass_in, sh_node_bsdf_glass_out); + node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); + node_type_init(&ntype, node_shader_init_glass); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_bsdf_glass); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.c index 5c5824814a6..97c1afbbee2 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.c @@ -22,46 +22,60 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_bsdf_glossy_in[] = { - { SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Roughness"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Roughness"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_VECTOR, + 1, + N_("Normal"), + 0.0f, + 0.0f, + 0.0f, + 1.0f, + -1.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_bsdf_glossy_out[] = { - { SOCK_SHADER, 0, N_("BSDF")}, - { -1, 0, "" }, + {SOCK_SHADER, 0, N_("BSDF")}, + {-1, 0, ""}, }; static void node_shader_init_glossy(bNodeTree *UNUSED(ntree), bNode *node) { - node->custom1 = SHD_GLOSSY_GGX; + node->custom1 = SHD_GLOSSY_GGX; } -static int node_shader_gpu_bsdf_glossy(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_bsdf_glossy(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - if (!in[2].link) - GPU_link(mat, "world_normals_get", &in[2].link); + if (!in[2].link) + GPU_link(mat, "world_normals_get", &in[2].link); - if (node->custom1 == SHD_GLOSSY_SHARP) - GPU_link(mat, "set_value_zero", &in[1].link); + if (node->custom1 == SHD_GLOSSY_SHARP) + GPU_link(mat, "set_value_zero", &in[1].link); - GPU_material_flag_set(mat, GPU_MATFLAG_GLOSSY); + GPU_material_flag_set(mat, GPU_MATFLAG_GLOSSY); - return GPU_stack_link(mat, node, "node_bsdf_glossy", in, out, GPU_constant(&node->ssr_id)); + return GPU_stack_link(mat, node, "node_bsdf_glossy", in, out, GPU_constant(&node->ssr_id)); } /* node type definition */ void register_node_type_sh_bsdf_glossy(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_BSDF_GLOSSY, "Glossy BSDF", NODE_CLASS_SHADER, 0); - node_type_socket_templates(&ntype, sh_node_bsdf_glossy_in, sh_node_bsdf_glossy_out); - node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); - node_type_init(&ntype, node_shader_init_glossy); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_bsdf_glossy); + sh_node_type_base(&ntype, SH_NODE_BSDF_GLOSSY, "Glossy BSDF", NODE_CLASS_SHADER, 0); + node_type_socket_templates(&ntype, sh_node_bsdf_glossy_in, sh_node_bsdf_glossy_out); + node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); + node_type_init(&ntype, node_shader_init_glossy); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_bsdf_glossy); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_hair.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_hair.c index 6756ca61fb2..d62bbf28070 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_hair.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_hair.c @@ -22,35 +22,49 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_bsdf_hair_in[] = { - { SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Offset"), 0.0f, 0.0f, 0.0f, 0.0f, -M_PI_2, M_PI_2, PROP_ANGLE}, - { SOCK_FLOAT, 1, N_("RoughnessU"), 0.1f, 0.1f, 0.1f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("RoughnessV"), 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_VECTOR, 1, N_("Tangent"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Offset"), 0.0f, 0.0f, 0.0f, 0.0f, -M_PI_2, M_PI_2, PROP_ANGLE}, + {SOCK_FLOAT, 1, N_("RoughnessU"), 0.1f, 0.1f, 0.1f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("RoughnessV"), 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_VECTOR, + 1, + N_("Tangent"), + 0.0f, + 0.0f, + 0.0f, + 1.0f, + -1.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_bsdf_hair_out[] = { - { SOCK_SHADER, 0, N_("BSDF")}, - { -1, 0, "" }, + {SOCK_SHADER, 0, N_("BSDF")}, + {-1, 0, ""}, }; -static int node_shader_gpu_bsdf_hair(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_bsdf_hair(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "node_bsdf_hair", in, out); + return GPU_stack_link(mat, node, "node_bsdf_hair", in, out); } /* node type definition */ void register_node_type_sh_bsdf_hair(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_BSDF_HAIR, "Hair BSDF", NODE_CLASS_SHADER, 0); - node_type_socket_templates(&ntype, sh_node_bsdf_hair_in, sh_node_bsdf_hair_out); - node_type_size(&ntype, 150, 60, 200); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_bsdf_hair); + sh_node_type_base(&ntype, SH_NODE_BSDF_HAIR, "Hair BSDF", NODE_CLASS_SHADER, 0); + node_type_socket_templates(&ntype, sh_node_bsdf_hair_in, sh_node_bsdf_hair_out); + node_type_size(&ntype, 150, 60, 200); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_bsdf_hair); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_hair_principled.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_hair_principled.c index 0b953c34010..ce90933fcc4 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_hair_principled.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_hair_principled.c @@ -23,102 +23,113 @@ /* Color, melanin and absorption coefficient default to approximately same brownish hair. */ static bNodeSocketTemplate sh_node_bsdf_hair_principled_in[] = { - { SOCK_RGBA, 1, N_("Color"), 0.017513f, 0.005763f, 0.002059f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Melanin"), 0.8f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("Melanin Redness"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_RGBA, 1, N_("Tint"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 1, N_("Absorption Coefficient"), 0.245531f, 0.52f, 1.365f, 0.0f, 0.0f, 1000.0f}, - { SOCK_FLOAT, 1, N_("Roughness"), 0.3f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("Radial Roughness"), 0.3f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("Coat"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("IOR"), 1.55f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { SOCK_FLOAT, 1, N_("Offset"), 2.0f * ((float)M_PI) / 180.f, 0.0f, 0.0f, 0.0f, -M_PI_2, M_PI_2, PROP_ANGLE}, - { SOCK_FLOAT, 1, N_("Random Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("Random Roughness"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("Random"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 0.017513f, 0.005763f, 0.002059f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Melanin"), 0.8f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Melanin Redness"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_RGBA, 1, N_("Tint"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, + {SOCK_VECTOR, 1, N_("Absorption Coefficient"), 0.245531f, 0.52f, 1.365f, 0.0f, 0.0f, 1000.0f}, + {SOCK_FLOAT, 1, N_("Roughness"), 0.3f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Radial Roughness"), 0.3f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Coat"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("IOR"), 1.55f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + {SOCK_FLOAT, + 1, + N_("Offset"), + 2.0f * ((float)M_PI) / 180.f, + 0.0f, + 0.0f, + 0.0f, + -M_PI_2, + M_PI_2, + PROP_ANGLE}, + {SOCK_FLOAT, 1, N_("Random Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Random Roughness"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Random"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_bsdf_hair_principled_out[] = { - { SOCK_SHADER, 0, N_("BSDF")}, - { -1, 0, "" }, + {SOCK_SHADER, 0, N_("BSDF")}, + {-1, 0, ""}, }; /* Initialize the custom Parametrization property to Color. */ static void node_shader_init_hair_principled(bNodeTree *UNUSED(ntree), bNode *node) { - node->custom1 = SHD_PRINCIPLED_HAIR_REFLECTANCE; + node->custom1 = SHD_PRINCIPLED_HAIR_REFLECTANCE; } /* Triggers (in)visibility of some sockets when changing Parametrization. */ static void node_shader_update_hair_principled(bNodeTree *UNUSED(ntree), bNode *node) { - bNodeSocket *sock; - int parametrization = node->custom1; + bNodeSocket *sock; + int parametrization = node->custom1; - for (sock = node->inputs.first; sock; sock = sock->next) { - if (STREQ(sock->name, "Color")) { - if (parametrization == SHD_PRINCIPLED_HAIR_REFLECTANCE) { - sock->flag &= ~SOCK_UNAVAIL; - } - else { - sock->flag |= SOCK_UNAVAIL; - } - } - else if (STREQ(sock->name, "Melanin")) { - if (parametrization == SHD_PRINCIPLED_HAIR_PIGMENT_CONCENTRATION) { - sock->flag &= ~SOCK_UNAVAIL; - } - else { - sock->flag |= SOCK_UNAVAIL; - } - } - else if (STREQ(sock->name, "Melanin Redness")) { - if (parametrization == SHD_PRINCIPLED_HAIR_PIGMENT_CONCENTRATION) { - sock->flag &= ~SOCK_UNAVAIL; - } - else { - sock->flag |= SOCK_UNAVAIL; - } - } - else if (STREQ(sock->name, "Tint")) { - if (parametrization == SHD_PRINCIPLED_HAIR_PIGMENT_CONCENTRATION) { - sock->flag &= ~SOCK_UNAVAIL; - } - else { - sock->flag |= SOCK_UNAVAIL; - } - } - else if (STREQ(sock->name, "Absorption Coefficient")) { - if (parametrization == SHD_PRINCIPLED_HAIR_DIRECT_ABSORPTION) { - sock->flag &= ~SOCK_UNAVAIL; - } - else { - sock->flag |= SOCK_UNAVAIL; - } - } - else if (STREQ(sock->name, "Random Color")) { - if (parametrization == SHD_PRINCIPLED_HAIR_PIGMENT_CONCENTRATION) { - sock->flag &= ~SOCK_UNAVAIL; - } - else { - sock->flag |= SOCK_UNAVAIL; - } - } - } + for (sock = node->inputs.first; sock; sock = sock->next) { + if (STREQ(sock->name, "Color")) { + if (parametrization == SHD_PRINCIPLED_HAIR_REFLECTANCE) { + sock->flag &= ~SOCK_UNAVAIL; + } + else { + sock->flag |= SOCK_UNAVAIL; + } + } + else if (STREQ(sock->name, "Melanin")) { + if (parametrization == SHD_PRINCIPLED_HAIR_PIGMENT_CONCENTRATION) { + sock->flag &= ~SOCK_UNAVAIL; + } + else { + sock->flag |= SOCK_UNAVAIL; + } + } + else if (STREQ(sock->name, "Melanin Redness")) { + if (parametrization == SHD_PRINCIPLED_HAIR_PIGMENT_CONCENTRATION) { + sock->flag &= ~SOCK_UNAVAIL; + } + else { + sock->flag |= SOCK_UNAVAIL; + } + } + else if (STREQ(sock->name, "Tint")) { + if (parametrization == SHD_PRINCIPLED_HAIR_PIGMENT_CONCENTRATION) { + sock->flag &= ~SOCK_UNAVAIL; + } + else { + sock->flag |= SOCK_UNAVAIL; + } + } + else if (STREQ(sock->name, "Absorption Coefficient")) { + if (parametrization == SHD_PRINCIPLED_HAIR_DIRECT_ABSORPTION) { + sock->flag &= ~SOCK_UNAVAIL; + } + else { + sock->flag |= SOCK_UNAVAIL; + } + } + else if (STREQ(sock->name, "Random Color")) { + if (parametrization == SHD_PRINCIPLED_HAIR_PIGMENT_CONCENTRATION) { + sock->flag &= ~SOCK_UNAVAIL; + } + else { + sock->flag |= SOCK_UNAVAIL; + } + } + } } /* node type definition */ void register_node_type_sh_bsdf_hair_principled(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_BSDF_HAIR_PRINCIPLED, "Principled Hair BSDF", NODE_CLASS_SHADER, 0); - node_type_socket_templates(&ntype, sh_node_bsdf_hair_principled_in, sh_node_bsdf_hair_principled_out); - node_type_size_preset(&ntype, NODE_SIZE_LARGE); - node_type_init(&ntype, node_shader_init_hair_principled); - node_type_storage(&ntype, "", NULL, NULL); - node_type_update(&ntype, node_shader_update_hair_principled, NULL); + sh_node_type_base( + &ntype, SH_NODE_BSDF_HAIR_PRINCIPLED, "Principled Hair BSDF", NODE_CLASS_SHADER, 0); + node_type_socket_templates( + &ntype, sh_node_bsdf_hair_principled_in, sh_node_bsdf_hair_principled_out); + node_type_size_preset(&ntype, NODE_SIZE_LARGE); + node_type_init(&ntype, node_shader_init_hair_principled); + node_type_storage(&ntype, "", NULL, NULL); + node_type_update(&ntype, node_shader_update_hair_principled, NULL); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c index abc95161cd0..e0fda117648 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c @@ -22,155 +22,200 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_bsdf_principled_in[] = { - { SOCK_RGBA, 1, N_("Base Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Subsurface"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_VECTOR, 1, N_("Subsurface Radius"), 1.0f, 0.2f, 0.1f, 0.0f, 0.0f, 100.0f}, - { SOCK_RGBA, 1, N_("Subsurface Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Metallic"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("Specular"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("Specular Tint"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("Roughness"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("Anisotropic"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("Anisotropic Rotation"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("Sheen"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("Sheen Tint"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("Clearcoat"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("Clearcoat Roughness"), 0.03f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("IOR"), 1.45f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { SOCK_FLOAT, 1, N_("Transmission"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("Transmission Roughness"),0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { SOCK_VECTOR, 1, N_("Clearcoat Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { SOCK_VECTOR, 1, N_("Tangent"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Base Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Subsurface"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_VECTOR, 1, N_("Subsurface Radius"), 1.0f, 0.2f, 0.1f, 0.0f, 0.0f, 100.0f}, + {SOCK_RGBA, 1, N_("Subsurface Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Metallic"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Specular"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Specular Tint"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Roughness"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Anisotropic"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Anisotropic Rotation"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Sheen"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Sheen Tint"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Clearcoat"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Clearcoat Roughness"), 0.03f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("IOR"), 1.45f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + {SOCK_FLOAT, 1, N_("Transmission"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Transmission Roughness"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_VECTOR, + 1, + N_("Normal"), + 0.0f, + 0.0f, + 0.0f, + 1.0f, + -1.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {SOCK_VECTOR, + 1, + N_("Clearcoat Normal"), + 0.0f, + 0.0f, + 0.0f, + 1.0f, + -1.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {SOCK_VECTOR, + 1, + N_("Tangent"), + 0.0f, + 0.0f, + 0.0f, + 1.0f, + -1.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_bsdf_principled_out[] = { - { SOCK_SHADER, 0, N_("BSDF")}, - { -1, 0, "" }, + {SOCK_SHADER, 0, N_("BSDF")}, + {-1, 0, ""}, }; static void node_shader_init_principled(bNodeTree *UNUSED(ntree), bNode *node) { - node->custom1 = SHD_GLOSSY_GGX; - node->custom2 = SHD_SUBSURFACE_BURLEY; + node->custom1 = SHD_GLOSSY_GGX; + node->custom2 = SHD_SUBSURFACE_BURLEY; } #define socket_not_zero(sock) (in[sock].link || (clamp_f(in[sock].vec[0], 0.0f, 1.0f) > 1e-5f)) -#define socket_not_one(sock) (in[sock].link || (clamp_f(in[sock].vec[0], 0.0f, 1.0f) < 1.0f - 1e-5f)) - -static int node_shader_gpu_bsdf_principled(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +#define socket_not_one(sock) \ + (in[sock].link || (clamp_f(in[sock].vec[0], 0.0f, 1.0f) < 1.0f - 1e-5f)) + +static int node_shader_gpu_bsdf_principled(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - GPUNodeLink *sss_scale; - - /* Normals */ - if (!in[17].link) { - GPU_link(mat, "world_normals_get", &in[17].link); - } - - /* Clearcoat Normals */ - if (!in[18].link) { - GPU_link(mat, "world_normals_get", &in[18].link); - } - - /* Tangents */ - if (!in[19].link) { - GPUNodeLink *orco = GPU_attribute(CD_ORCO, ""); - GPU_link(mat, "tangent_orco_z", orco, &in[19].link); - GPU_link(mat, "node_tangent", - GPU_builtin(GPU_VIEW_NORMAL), in[19].link, GPU_builtin(GPU_OBJECT_MATRIX), GPU_builtin(GPU_INVERSE_VIEW_MATRIX), - &in[19].link); - } - - /* SSS Profile */ - if (node->sss_id == 1) { - static short profile = SHD_SUBSURFACE_BURLEY; - bNodeSocket *socket = BLI_findlink(&node->original->inputs, 2); - bNodeSocketValueRGBA *socket_data = socket->default_value; - /* For some reason it seems that the socket value is in ARGB format. */ - GPU_material_sss_profile_create(mat, &socket_data->value[1], &profile, NULL); - } - - if (in[2].link) { - sss_scale = in[2].link; - } - else { - GPU_link(mat, "set_rgb_one", &sss_scale); - } - - bool use_diffuse = socket_not_one(4) && socket_not_one(15); - bool use_subsurf = socket_not_zero(1) && use_diffuse; - bool use_refract = socket_not_one(4) && socket_not_zero(15); - bool use_clear = socket_not_zero(12); - - /* Due to the manual effort done per config, we only optimize the most common permutations. */ - char *node_name; - uint flag = 0; - if (!use_subsurf && use_diffuse && !use_refract && !use_clear) { - static char name[] = "node_bsdf_principled_dielectric"; - node_name = name; - flag = GPU_MATFLAG_DIFFUSE | GPU_MATFLAG_GLOSSY; - } - else if (!use_subsurf && !use_diffuse && !use_refract && !use_clear) { - static char name[] = "node_bsdf_principled_metallic"; - node_name = name; - flag = GPU_MATFLAG_GLOSSY; - } - else if (!use_subsurf && !use_diffuse && !use_refract && use_clear) { - static char name[] = "node_bsdf_principled_clearcoat"; - node_name = name; - flag = GPU_MATFLAG_GLOSSY; - } - else if (use_subsurf && use_diffuse && !use_refract && !use_clear) { - static char name[] = "node_bsdf_principled_subsurface"; - node_name = name; - flag = GPU_MATFLAG_DIFFUSE | GPU_MATFLAG_SSS | GPU_MATFLAG_GLOSSY; - } - else if (!use_subsurf && !use_diffuse && use_refract && !use_clear && !socket_not_zero(4)) { - static char name[] = "node_bsdf_principled_glass"; - node_name = name; - flag = GPU_MATFLAG_GLOSSY | GPU_MATFLAG_REFRACT; - } - else { - static char name[] = "node_bsdf_principled"; - node_name = name; - flag = GPU_MATFLAG_DIFFUSE | GPU_MATFLAG_GLOSSY | GPU_MATFLAG_SSS | GPU_MATFLAG_REFRACT; - } - - GPU_material_flag_set(mat, flag); - - return GPU_stack_link(mat, node, node_name, in, out, GPU_builtin(GPU_VIEW_POSITION), - GPU_constant(&node->ssr_id), GPU_constant(&node->sss_id), sss_scale); + GPUNodeLink *sss_scale; + + /* Normals */ + if (!in[17].link) { + GPU_link(mat, "world_normals_get", &in[17].link); + } + + /* Clearcoat Normals */ + if (!in[18].link) { + GPU_link(mat, "world_normals_get", &in[18].link); + } + + /* Tangents */ + if (!in[19].link) { + GPUNodeLink *orco = GPU_attribute(CD_ORCO, ""); + GPU_link(mat, "tangent_orco_z", orco, &in[19].link); + GPU_link(mat, + "node_tangent", + GPU_builtin(GPU_VIEW_NORMAL), + in[19].link, + GPU_builtin(GPU_OBJECT_MATRIX), + GPU_builtin(GPU_INVERSE_VIEW_MATRIX), + &in[19].link); + } + + /* SSS Profile */ + if (node->sss_id == 1) { + static short profile = SHD_SUBSURFACE_BURLEY; + bNodeSocket *socket = BLI_findlink(&node->original->inputs, 2); + bNodeSocketValueRGBA *socket_data = socket->default_value; + /* For some reason it seems that the socket value is in ARGB format. */ + GPU_material_sss_profile_create(mat, &socket_data->value[1], &profile, NULL); + } + + if (in[2].link) { + sss_scale = in[2].link; + } + else { + GPU_link(mat, "set_rgb_one", &sss_scale); + } + + bool use_diffuse = socket_not_one(4) && socket_not_one(15); + bool use_subsurf = socket_not_zero(1) && use_diffuse; + bool use_refract = socket_not_one(4) && socket_not_zero(15); + bool use_clear = socket_not_zero(12); + + /* Due to the manual effort done per config, we only optimize the most common permutations. */ + char *node_name; + uint flag = 0; + if (!use_subsurf && use_diffuse && !use_refract && !use_clear) { + static char name[] = "node_bsdf_principled_dielectric"; + node_name = name; + flag = GPU_MATFLAG_DIFFUSE | GPU_MATFLAG_GLOSSY; + } + else if (!use_subsurf && !use_diffuse && !use_refract && !use_clear) { + static char name[] = "node_bsdf_principled_metallic"; + node_name = name; + flag = GPU_MATFLAG_GLOSSY; + } + else if (!use_subsurf && !use_diffuse && !use_refract && use_clear) { + static char name[] = "node_bsdf_principled_clearcoat"; + node_name = name; + flag = GPU_MATFLAG_GLOSSY; + } + else if (use_subsurf && use_diffuse && !use_refract && !use_clear) { + static char name[] = "node_bsdf_principled_subsurface"; + node_name = name; + flag = GPU_MATFLAG_DIFFUSE | GPU_MATFLAG_SSS | GPU_MATFLAG_GLOSSY; + } + else if (!use_subsurf && !use_diffuse && use_refract && !use_clear && !socket_not_zero(4)) { + static char name[] = "node_bsdf_principled_glass"; + node_name = name; + flag = GPU_MATFLAG_GLOSSY | GPU_MATFLAG_REFRACT; + } + else { + static char name[] = "node_bsdf_principled"; + node_name = name; + flag = GPU_MATFLAG_DIFFUSE | GPU_MATFLAG_GLOSSY | GPU_MATFLAG_SSS | GPU_MATFLAG_REFRACT; + } + + GPU_material_flag_set(mat, flag); + + return GPU_stack_link(mat, + node, + node_name, + in, + out, + GPU_builtin(GPU_VIEW_POSITION), + GPU_constant(&node->ssr_id), + GPU_constant(&node->sss_id), + sss_scale); } static void node_shader_update_principled(bNodeTree *UNUSED(ntree), bNode *node) { - bNodeSocket *sock; - int distribution = node->custom1; - - for (sock = node->inputs.first; sock; sock = sock->next) { - if (STREQ(sock->name, "Transmission Roughness")) { - if (distribution == SHD_GLOSSY_GGX) - sock->flag &= ~SOCK_UNAVAIL; - else - sock->flag |= SOCK_UNAVAIL; - - } - } + bNodeSocket *sock; + int distribution = node->custom1; + + for (sock = node->inputs.first; sock; sock = sock->next) { + if (STREQ(sock->name, "Transmission Roughness")) { + if (distribution == SHD_GLOSSY_GGX) + sock->flag &= ~SOCK_UNAVAIL; + else + sock->flag |= SOCK_UNAVAIL; + } + } } /* node type definition */ void register_node_type_sh_bsdf_principled(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_BSDF_PRINCIPLED, "Principled BSDF", NODE_CLASS_SHADER, 0); - node_type_socket_templates(&ntype, sh_node_bsdf_principled_in, sh_node_bsdf_principled_out); - node_type_size_preset(&ntype, NODE_SIZE_LARGE); - node_type_init(&ntype, node_shader_init_principled); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_bsdf_principled); - node_type_update(&ntype, node_shader_update_principled, NULL); + sh_node_type_base(&ntype, SH_NODE_BSDF_PRINCIPLED, "Principled BSDF", NODE_CLASS_SHADER, 0); + node_type_socket_templates(&ntype, sh_node_bsdf_principled_in, sh_node_bsdf_principled_out); + node_type_size_preset(&ntype, NODE_SIZE_LARGE); + node_type_init(&ntype, node_shader_init_principled); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_bsdf_principled); + node_type_update(&ntype, node_shader_update_principled, NULL); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_refraction.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_refraction.c index db4451eea6b..2d740cab776 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_refraction.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_refraction.c @@ -22,47 +22,61 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_bsdf_refraction_in[] = { - { SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Roughness"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("IOR"), 1.45f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Roughness"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("IOR"), 1.45f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + {SOCK_VECTOR, + 1, + N_("Normal"), + 0.0f, + 0.0f, + 0.0f, + 1.0f, + -1.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_bsdf_refraction_out[] = { - { SOCK_SHADER, 0, N_("BSDF")}, - { -1, 0, "" }, + {SOCK_SHADER, 0, N_("BSDF")}, + {-1, 0, ""}, }; static void node_shader_init_refraction(bNodeTree *UNUSED(ntree), bNode *node) { - node->custom1 = SHD_GLOSSY_BECKMANN; + node->custom1 = SHD_GLOSSY_BECKMANN; } -static int node_shader_gpu_bsdf_refraction(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_bsdf_refraction(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - if (!in[3].link) - GPU_link(mat, "world_normals_get", &in[3].link); + if (!in[3].link) + GPU_link(mat, "world_normals_get", &in[3].link); - if (node->custom1 == SHD_GLOSSY_SHARP) - GPU_link(mat, "set_value_zero", &in[1].link); + if (node->custom1 == SHD_GLOSSY_SHARP) + GPU_link(mat, "set_value_zero", &in[1].link); - GPU_material_flag_set(mat, GPU_MATFLAG_REFRACT); + GPU_material_flag_set(mat, GPU_MATFLAG_REFRACT); - return GPU_stack_link(mat, node, "node_bsdf_refraction", in, out); + return GPU_stack_link(mat, node, "node_bsdf_refraction", in, out); } /* node type definition */ void register_node_type_sh_bsdf_refraction(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_BSDF_REFRACTION, "Refraction BSDF", NODE_CLASS_SHADER, 0); - node_type_socket_templates(&ntype, sh_node_bsdf_refraction_in, sh_node_bsdf_refraction_out); - node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); - node_type_init(&ntype, node_shader_init_refraction); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_bsdf_refraction); + sh_node_type_base(&ntype, SH_NODE_BSDF_REFRACTION, "Refraction BSDF", NODE_CLASS_SHADER, 0); + node_type_socket_templates(&ntype, sh_node_bsdf_refraction_in, sh_node_bsdf_refraction_out); + node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); + node_type_init(&ntype, node_shader_init_refraction); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_bsdf_refraction); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_toon.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_toon.c index de08f00b0b8..8ec80be748e 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_toon.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_toon.c @@ -22,39 +22,53 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_bsdf_toon_in[] = { - { SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Size"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("Smooth"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Size"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Smooth"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_VECTOR, + 1, + N_("Normal"), + 0.0f, + 0.0f, + 0.0f, + 1.0f, + -1.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_bsdf_toon_out[] = { - { SOCK_SHADER, 0, N_("BSDF")}, - { -1, 0, "" }, + {SOCK_SHADER, 0, N_("BSDF")}, + {-1, 0, ""}, }; -static int node_shader_gpu_bsdf_toon(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_bsdf_toon(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - if (!in[3].link) - GPU_link(mat, "world_normals_get", &in[3].link); + if (!in[3].link) + GPU_link(mat, "world_normals_get", &in[3].link); - GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE); + GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE); - return GPU_stack_link(mat, node, "node_bsdf_toon", in, out); + return GPU_stack_link(mat, node, "node_bsdf_toon", in, out); } /* node type definition */ void register_node_type_sh_bsdf_toon(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_BSDF_TOON, "Toon BSDF", NODE_CLASS_SHADER, 0); - node_type_socket_templates(&ntype, sh_node_bsdf_toon_in, sh_node_bsdf_toon_out); - node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_bsdf_toon); + sh_node_type_base(&ntype, SH_NODE_BSDF_TOON, "Toon BSDF", NODE_CLASS_SHADER, 0); + node_type_socket_templates(&ntype, sh_node_bsdf_toon_in, sh_node_bsdf_toon_out); + node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_bsdf_toon); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_translucent.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_translucent.c index 4dba71e80b4..6e2556d7446 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_translucent.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_translucent.c @@ -22,36 +22,50 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_bsdf_translucent_in[] = { - { SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_VECTOR, + 1, + N_("Normal"), + 0.0f, + 0.0f, + 0.0f, + 1.0f, + -1.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_bsdf_translucent_out[] = { - { SOCK_SHADER, 0, N_("BSDF")}, - { -1, 0, "" }, + {SOCK_SHADER, 0, N_("BSDF")}, + {-1, 0, ""}, }; -static int node_shader_gpu_bsdf_translucent(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_bsdf_translucent(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - if (!in[1].link) - GPU_link(mat, "world_normals_get", &in[1].link); + if (!in[1].link) + GPU_link(mat, "world_normals_get", &in[1].link); - GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE); + GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE); - return GPU_stack_link(mat, node, "node_bsdf_translucent", in, out); + return GPU_stack_link(mat, node, "node_bsdf_translucent", in, out); } /* node type definition */ void register_node_type_sh_bsdf_translucent(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_BSDF_TRANSLUCENT, "Translucent BSDF", NODE_CLASS_SHADER, 0); - node_type_socket_templates(&ntype, sh_node_bsdf_translucent_in, sh_node_bsdf_translucent_out); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_bsdf_translucent); + sh_node_type_base(&ntype, SH_NODE_BSDF_TRANSLUCENT, "Translucent BSDF", NODE_CLASS_SHADER, 0); + node_type_socket_templates(&ntype, sh_node_bsdf_translucent_in, sh_node_bsdf_translucent_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_bsdf_translucent); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_transparent.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_transparent.c index a8fbe3afbee..09a59e00873 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_transparent.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_transparent.c @@ -22,30 +22,34 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_bsdf_transparent_in[] = { - { SOCK_RGBA, 1, N_("Color"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_bsdf_transparent_out[] = { - { SOCK_SHADER, 0, N_("BSDF")}, - { -1, 0, "" }, + {SOCK_SHADER, 0, N_("BSDF")}, + {-1, 0, ""}, }; -static int node_shader_gpu_bsdf_transparent(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_bsdf_transparent(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "node_bsdf_transparent", in, out); + return GPU_stack_link(mat, node, "node_bsdf_transparent", in, out); } /* node type definition */ void register_node_type_sh_bsdf_transparent(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_BSDF_TRANSPARENT, "Transparent BSDF", NODE_CLASS_SHADER, 0); - node_type_socket_templates(&ntype, sh_node_bsdf_transparent_in, sh_node_bsdf_transparent_out); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_bsdf_transparent); + sh_node_type_base(&ntype, SH_NODE_BSDF_TRANSPARENT, "Transparent BSDF", NODE_CLASS_SHADER, 0); + node_type_socket_templates(&ntype, sh_node_bsdf_transparent_in, sh_node_bsdf_transparent_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_bsdf_transparent); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_velvet.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_velvet.c index 15aa58123a2..d4cb444cf08 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_velvet.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_velvet.c @@ -22,37 +22,51 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_bsdf_velvet_in[] = { - { SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Sigma"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Sigma"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_VECTOR, + 1, + N_("Normal"), + 0.0f, + 0.0f, + 0.0f, + 1.0f, + -1.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_bsdf_velvet_out[] = { - { SOCK_SHADER, 0, N_("BSDF")}, - { -1, 0, "" }, + {SOCK_SHADER, 0, N_("BSDF")}, + {-1, 0, ""}, }; -static int node_shader_gpu_bsdf_velvet(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_bsdf_velvet(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - if (!in[2].link) - GPU_link(mat, "world_normals_get", &in[2].link); + if (!in[2].link) + GPU_link(mat, "world_normals_get", &in[2].link); - GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE); + GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE); - return GPU_stack_link(mat, node, "node_bsdf_velvet", in, out); + return GPU_stack_link(mat, node, "node_bsdf_velvet", in, out); } /* node type definition */ void register_node_type_sh_bsdf_velvet(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_BSDF_VELVET, "Velvet BSDF", NODE_CLASS_SHADER, 0); - node_type_socket_templates(&ntype, sh_node_bsdf_velvet_in, sh_node_bsdf_velvet_out); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_bsdf_velvet); + sh_node_type_base(&ntype, SH_NODE_BSDF_VELVET, "Velvet BSDF", NODE_CLASS_SHADER, 0); + node_type_socket_templates(&ntype, sh_node_bsdf_velvet_in, sh_node_bsdf_velvet_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_bsdf_velvet); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_bump.c b/source/blender/nodes/shader/nodes/node_shader_bump.c index 8e6cfc5d4cc..d17edae35df 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bump.c +++ b/source/blender/nodes/shader/nodes/node_shader_bump.c @@ -25,38 +25,59 @@ /* **************** BUMP ******************** */ static bNodeSocketTemplate sh_node_bump_in[] = { - { SOCK_FLOAT, 1, N_("Strength"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("Distance"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { SOCK_FLOAT, 1, N_("Height"), 1.0f, 1.0f, 1.0f, 1.0f, -1000.0f, 1000.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { -1, 0, "" } -}; - -static bNodeSocketTemplate sh_node_bump_out[] = { - { SOCK_VECTOR, 0, "Normal"}, - { -1, 0, "" } -}; - -static int gpu_shader_bump(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) + {SOCK_FLOAT, 1, N_("Strength"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Distance"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + {SOCK_FLOAT, + 1, + N_("Height"), + 1.0f, + 1.0f, + 1.0f, + 1.0f, + -1000.0f, + 1000.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {SOCK_VECTOR, + 1, + N_("Normal"), + 0.0f, + 0.0f, + 0.0f, + 1.0f, + -1.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {-1, 0, ""}}; + +static bNodeSocketTemplate sh_node_bump_out[] = {{SOCK_VECTOR, 0, "Normal"}, {-1, 0, ""}}; + +static int gpu_shader_bump(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - if (!in[3].link) { - GPU_link(mat, "world_normals_get", &in[3].link); - } + if (!in[3].link) { + GPU_link(mat, "world_normals_get", &in[3].link); + } - float invert = (node->custom1) ? -1.0 : 1.0; + float invert = (node->custom1) ? -1.0 : 1.0; - return GPU_stack_link(mat, node, "node_bump", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_constant(&invert)); + return GPU_stack_link( + mat, node, "node_bump", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_constant(&invert)); } /* node type definition */ void register_node_type_sh_bump(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_BUMP, "Bump", NODE_CLASS_OP_VECTOR, 0); - node_type_socket_templates(&ntype, sh_node_bump_in, sh_node_bump_out); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, gpu_shader_bump); + sh_node_type_base(&ntype, SH_NODE_BUMP, "Bump", NODE_CLASS_OP_VECTOR, 0); + node_type_socket_templates(&ntype, sh_node_bump_in, sh_node_bump_out); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, gpu_shader_bump); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_camera.c b/source/blender/nodes/shader/nodes/node_shader_camera.c index 95e255dcf1d..a6fc08f812f 100644 --- a/source/blender/nodes/shader/nodes/node_shader_camera.c +++ b/source/blender/nodes/shader/nodes/node_shader_camera.c @@ -21,34 +21,37 @@ * \ingroup shdnodes */ - #include "node_shader_util.h" /* **************** CAMERA INFO ******************** */ static bNodeSocketTemplate sh_node_camera_out[] = { - { SOCK_VECTOR, 0, N_("View Vector")}, - { SOCK_FLOAT, 0, N_("View Z Depth")}, - { SOCK_FLOAT, 0, N_("View Distance")}, - { -1, 0, "" }, + {SOCK_VECTOR, 0, N_("View Vector")}, + {SOCK_FLOAT, 0, N_("View Z Depth")}, + {SOCK_FLOAT, 0, N_("View Distance")}, + {-1, 0, ""}, }; -static int gpu_shader_camera(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_camera(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - GPUNodeLink *viewvec; + GPUNodeLink *viewvec; - viewvec = GPU_builtin(GPU_VIEW_POSITION); - GPU_link(mat, "invert_z", viewvec, &viewvec); - return GPU_stack_link(mat, node, "camera", in, out, viewvec); + viewvec = GPU_builtin(GPU_VIEW_POSITION); + GPU_link(mat, "invert_z", viewvec, &viewvec); + return GPU_stack_link(mat, node, "camera", in, out, viewvec); } void register_node_type_sh_camera(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_CAMERA, "Camera Data", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, NULL, sh_node_camera_out); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, gpu_shader_camera); + sh_node_type_base(&ntype, SH_NODE_CAMERA, "Camera Data", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, NULL, sh_node_camera_out); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, gpu_shader_camera); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_common.c b/source/blender/nodes/shader/nodes/node_shader_common.c index b9c9093a065..3f95d31841e 100644 --- a/source/blender/nodes/shader/nodes/node_shader_common.c +++ b/source/blender/nodes/shader/nodes/node_shader_common.c @@ -22,7 +22,6 @@ * \ingroup shdnodes */ - #include "DNA_node_types.h" #include "BLI_utildefines.h" @@ -38,221 +37,227 @@ static void copy_stack(bNodeStack *to, bNodeStack *from) { - if (to != from) { - copy_v4_v4(to->vec, from->vec); - to->data = from->data; - to->datatype = from->datatype; - - /* tag as copy to prevent freeing */ - to->is_copy = 1; - } + if (to != from) { + copy_v4_v4(to->vec, from->vec); + to->data = from->data; + to->datatype = from->datatype; + + /* tag as copy to prevent freeing */ + to->is_copy = 1; + } } static void move_stack(bNodeStack *to, bNodeStack *from) { - if (to != from) { - copy_v4_v4(to->vec, from->vec); - to->data = from->data; - to->datatype = from->datatype; - to->is_copy = from->is_copy; - - from->data = NULL; - from->is_copy = 0; - } + if (to != from) { + copy_v4_v4(to->vec, from->vec); + to->data = from->data; + to->datatype = from->datatype; + to->is_copy = from->is_copy; + + from->data = NULL; + from->is_copy = 0; + } } /**** GROUP ****/ static void *group_initexec(bNodeExecContext *context, bNode *node, bNodeInstanceKey key) { - bNodeTree *ngroup = (bNodeTree *)node->id; - bNodeTreeExec *exec; + bNodeTree *ngroup = (bNodeTree *)node->id; + bNodeTreeExec *exec; - if (!ngroup) - return NULL; + if (!ngroup) + return NULL; - /* initialize the internal node tree execution */ - exec = ntreeShaderBeginExecTree_internal(context, ngroup, key); + /* initialize the internal node tree execution */ + exec = ntreeShaderBeginExecTree_internal(context, ngroup, key); - return exec; + return exec; } static void group_freeexec(void *nodedata) { - bNodeTreeExec *gexec = (bNodeTreeExec *)nodedata; + bNodeTreeExec *gexec = (bNodeTreeExec *)nodedata; - if (gexec) - ntreeShaderEndExecTree_internal(gexec); + if (gexec) + ntreeShaderEndExecTree_internal(gexec); } /* Copy inputs to the internal stack. */ static void group_copy_inputs(bNode *gnode, bNodeStack **in, bNodeStack *gstack) { - bNodeTree *ngroup = (bNodeTree *)gnode->id; - bNode *node; - bNodeSocket *sock; - bNodeStack *ns; - int a; - - for (node = ngroup->nodes.first; node; node = node->next) { - if (node->type == NODE_GROUP_INPUT) { - for (sock = node->outputs.first, a = 0; sock; sock = sock->next, ++a) { - ns = node_get_socket_stack(gstack, sock); - if (ns) - copy_stack(ns, in[a]); - } - } - } + bNodeTree *ngroup = (bNodeTree *)gnode->id; + bNode *node; + bNodeSocket *sock; + bNodeStack *ns; + int a; + + for (node = ngroup->nodes.first; node; node = node->next) { + if (node->type == NODE_GROUP_INPUT) { + for (sock = node->outputs.first, a = 0; sock; sock = sock->next, ++a) { + ns = node_get_socket_stack(gstack, sock); + if (ns) + copy_stack(ns, in[a]); + } + } + } } /* Copy internal results to the external outputs. */ static void group_move_outputs(bNode *gnode, bNodeStack **out, bNodeStack *gstack) { - bNodeTree *ngroup = (bNodeTree *)gnode->id; - bNode *node; - bNodeSocket *sock; - bNodeStack *ns; - int a; - - for (node = ngroup->nodes.first; node; node = node->next) { - if (node->type == NODE_GROUP_OUTPUT && (node->flag & NODE_DO_OUTPUT)) { - for (sock = node->inputs.first, a = 0; sock; sock = sock->next, ++a) { - ns = node_get_socket_stack(gstack, sock); - if (ns) - move_stack(out[a], ns); - } - break; /* only one active output node */ - } - } + bNodeTree *ngroup = (bNodeTree *)gnode->id; + bNode *node; + bNodeSocket *sock; + bNodeStack *ns; + int a; + + for (node = ngroup->nodes.first; node; node = node->next) { + if (node->type == NODE_GROUP_OUTPUT && (node->flag & NODE_DO_OUTPUT)) { + for (sock = node->inputs.first, a = 0; sock; sock = sock->next, ++a) { + ns = node_get_socket_stack(gstack, sock); + if (ns) + move_stack(out[a], ns); + } + break; /* only one active output node */ + } + } } -static void group_execute(void *data, int thread, struct bNode *node, bNodeExecData *execdata, struct bNodeStack **in, struct bNodeStack **out) +static void group_execute(void *data, + int thread, + struct bNode *node, + bNodeExecData *execdata, + struct bNodeStack **in, + struct bNodeStack **out) { - bNodeTreeExec *exec = execdata->data; - bNodeThreadStack *nts; + bNodeTreeExec *exec = execdata->data; + bNodeThreadStack *nts; - if (!exec) - return; + if (!exec) + return; - /* XXX same behavior as trunk: all nodes inside group are executed. - * it's stupid, but just makes it work. compo redesign will do this better. - */ - { - bNode *inode; - for (inode = exec->nodetree->nodes.first; inode; inode = inode->next) - inode->need_exec = 1; - } + /* XXX same behavior as trunk: all nodes inside group are executed. + * it's stupid, but just makes it work. compo redesign will do this better. + */ + { + bNode *inode; + for (inode = exec->nodetree->nodes.first; inode; inode = inode->next) + inode->need_exec = 1; + } - nts = ntreeGetThreadStack(exec, thread); + nts = ntreeGetThreadStack(exec, thread); - group_copy_inputs(node, in, nts->stack); - ntreeExecThreadNodes(exec, nts, data, thread); - group_move_outputs(node, out, nts->stack); + group_copy_inputs(node, in, nts->stack); + ntreeExecThreadNodes(exec, nts, data, thread); + group_move_outputs(node, out, nts->stack); - ntreeReleaseThreadStack(nts); + ntreeReleaseThreadStack(nts); } static void group_gpu_copy_inputs(bNode *gnode, GPUNodeStack *in, bNodeStack *gstack) { - bNodeTree *ngroup = (bNodeTree *)gnode->id; - bNode *node; - bNodeSocket *sock; - bNodeStack *ns; - int a; - - for (node = ngroup->nodes.first; node; node = node->next) { - if (node->type == NODE_GROUP_INPUT) { - for (sock = node->outputs.first, a = 0; sock; sock = sock->next, ++a) { - ns = node_get_socket_stack(gstack, sock); - if (ns) { - /* convert the external gpu stack back to internal node stack data */ - node_data_from_gpu_stack(ns, &in[a]); - } - } - } - } + bNodeTree *ngroup = (bNodeTree *)gnode->id; + bNode *node; + bNodeSocket *sock; + bNodeStack *ns; + int a; + + for (node = ngroup->nodes.first; node; node = node->next) { + if (node->type == NODE_GROUP_INPUT) { + for (sock = node->outputs.first, a = 0; sock; sock = sock->next, ++a) { + ns = node_get_socket_stack(gstack, sock); + if (ns) { + /* convert the external gpu stack back to internal node stack data */ + node_data_from_gpu_stack(ns, &in[a]); + } + } + } + } } /* Copy internal results to the external outputs. */ static void group_gpu_move_outputs(bNode *gnode, GPUNodeStack *out, bNodeStack *gstack) { - bNodeTree *ngroup = (bNodeTree *)gnode->id; - bNode *node; - bNodeSocket *sock; - bNodeStack *ns; - int a; - - for (node = ngroup->nodes.first; node; node = node->next) { - if (node->type == NODE_GROUP_OUTPUT && (node->flag & NODE_DO_OUTPUT)) { - for (sock = node->inputs.first, a = 0; sock; sock = sock->next, ++a) { - ns = node_get_socket_stack(gstack, sock); - if (ns) { - /* convert the node stack data result back to gpu stack */ - node_gpu_stack_from_data(&out[a], sock->type, ns); - } - } - break; /* only one active output node */ - } - } + bNodeTree *ngroup = (bNodeTree *)gnode->id; + bNode *node; + bNodeSocket *sock; + bNodeStack *ns; + int a; + + for (node = ngroup->nodes.first; node; node = node->next) { + if (node->type == NODE_GROUP_OUTPUT && (node->flag & NODE_DO_OUTPUT)) { + for (sock = node->inputs.first, a = 0; sock; sock = sock->next, ++a) { + ns = node_get_socket_stack(gstack, sock); + if (ns) { + /* convert the node stack data result back to gpu stack */ + node_gpu_stack_from_data(&out[a], sock->type, ns); + } + } + break; /* only one active output node */ + } + } } -static int gpu_group_execute(GPUMaterial *mat, bNode *node, bNodeExecData *execdata, GPUNodeStack *in, GPUNodeStack *out) +static int gpu_group_execute( + GPUMaterial *mat, bNode *node, bNodeExecData *execdata, GPUNodeStack *in, GPUNodeStack *out) { - bNodeTreeExec *exec = execdata->data; + bNodeTreeExec *exec = execdata->data; - if (!node->id) - return 0; + if (!node->id) + return 0; - group_gpu_copy_inputs(node, in, exec->stack); - ntreeExecGPUNodes(exec, mat, NULL); - group_gpu_move_outputs(node, out, exec->stack); + group_gpu_copy_inputs(node, in, exec->stack); + ntreeExecGPUNodes(exec, mat, NULL); + group_gpu_move_outputs(node, out, exec->stack); - return 1; + return 1; } void register_node_type_sh_group(void) { - static bNodeType ntype; - - /* NB: cannot use sh_node_type_base for node group, because it would map the node type - * to the shared NODE_GROUP integer type id. - */ - node_type_base_custom(&ntype, "ShaderNodeGroup", "Group", NODE_CLASS_GROUP, NODE_CONST_OUTPUT); - ntype.type = NODE_GROUP; - ntype.poll = sh_node_poll_default; - ntype.poll_instance = node_group_poll_instance; - ntype.insert_link = node_insert_link_default; - ntype.update_internal_links = node_update_internal_links_default; - ntype.ext.srna = RNA_struct_find("ShaderNodeGroup"); - BLI_assert(ntype.ext.srna != NULL); - RNA_struct_blender_type_set(ntype.ext.srna, &ntype); - - node_type_socket_templates(&ntype, NULL, NULL); - node_type_size(&ntype, 140, 60, 400); - node_type_label(&ntype, node_group_label); - node_type_update(&ntype, NULL, node_group_verify); - node_type_exec(&ntype, group_initexec, group_freeexec, group_execute); - node_type_gpu(&ntype, gpu_group_execute); - - nodeRegisterType(&ntype); + static bNodeType ntype; + + /* NB: cannot use sh_node_type_base for node group, because it would map the node type + * to the shared NODE_GROUP integer type id. + */ + node_type_base_custom(&ntype, "ShaderNodeGroup", "Group", NODE_CLASS_GROUP, NODE_CONST_OUTPUT); + ntype.type = NODE_GROUP; + ntype.poll = sh_node_poll_default; + ntype.poll_instance = node_group_poll_instance; + ntype.insert_link = node_insert_link_default; + ntype.update_internal_links = node_update_internal_links_default; + ntype.ext.srna = RNA_struct_find("ShaderNodeGroup"); + BLI_assert(ntype.ext.srna != NULL); + RNA_struct_blender_type_set(ntype.ext.srna, &ntype); + + node_type_socket_templates(&ntype, NULL, NULL); + node_type_size(&ntype, 140, 60, 400); + node_type_label(&ntype, node_group_label); + node_type_update(&ntype, NULL, node_group_verify); + node_type_exec(&ntype, group_initexec, group_freeexec, group_execute); + node_type_gpu(&ntype, gpu_group_execute); + + nodeRegisterType(&ntype); } void register_node_type_sh_custom_group(bNodeType *ntype) { - /* These methods can be overriden but need a default implementation otherwise. */ - if (ntype->poll == NULL) { - ntype->poll = sh_node_poll_default; - } - if (ntype->insert_link == NULL) { - ntype->insert_link = node_insert_link_default; - } - if (ntype->update_internal_links == NULL) { - ntype->update_internal_links = node_update_internal_links_default; - } - - node_type_exec(ntype, group_initexec, group_freeexec, group_execute); - node_type_gpu(ntype, gpu_group_execute); + /* These methods can be overriden but need a default implementation otherwise. */ + if (ntype->poll == NULL) { + ntype->poll = sh_node_poll_default; + } + if (ntype->insert_link == NULL) { + ntype->insert_link = node_insert_link_default; + } + if (ntype->update_internal_links == NULL) { + ntype->update_internal_links = node_update_internal_links_default; + } + + node_type_exec(ntype, group_initexec, group_freeexec, group_execute); + node_type_gpu(ntype, gpu_group_execute); } diff --git a/source/blender/nodes/shader/nodes/node_shader_curves.c b/source/blender/nodes/shader/nodes/node_shader_curves.c index 2b4c3581fc0..1b96dabac77 100644 --- a/source/blender/nodes/shader/nodes/node_shader_curves.c +++ b/source/blender/nodes/shader/nodes/node_shader_curves.c @@ -21,170 +21,193 @@ * \ingroup shdnodes */ - #include "node_shader_util.h" - /* **************** CURVE VEC ******************** */ static bNodeSocketTemplate sh_node_curve_vec_in[] = { - { SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_curve_vec_out[] = { - { SOCK_VECTOR, 0, N_("Vector")}, - { -1, 0, "" }, + {SOCK_VECTOR, 0, N_("Vector")}, + {-1, 0, ""}, }; -static void node_shader_exec_curve_vec(void *UNUSED(data), int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) +static void node_shader_exec_curve_vec(void *UNUSED(data), + int UNUSED(thread), + bNode *node, + bNodeExecData *UNUSED(execdata), + bNodeStack **in, + bNodeStack **out) { - float vec[3]; + float vec[3]; - /* stack order input: vec */ - /* stack order output: vec */ - nodestack_get_vec(vec, SOCK_VECTOR, in[1]); - curvemapping_evaluate3F(node->storage, out[0]->vec, vec); + /* stack order input: vec */ + /* stack order output: vec */ + nodestack_get_vec(vec, SOCK_VECTOR, in[1]); + curvemapping_evaluate3F(node->storage, out[0]->vec, vec); } static void node_shader_init_curve_vec(bNodeTree *UNUSED(ntree), bNode *node) { - node->storage = curvemapping_add(3, -1.0f, -1.0f, 1.0f, 1.0f); + node->storage = curvemapping_add(3, -1.0f, -1.0f, 1.0f, 1.0f); } -static int gpu_shader_curve_vec(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_curve_vec(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - float *array, layer; - int size; + float *array, layer; + int size; - curvemapping_table_RGBA(node->storage, &array, &size); - GPUNodeLink *tex = GPU_color_band(mat, size, array, &layer); + curvemapping_table_RGBA(node->storage, &array, &size); + GPUNodeLink *tex = GPU_color_band(mat, size, array, &layer); - return GPU_stack_link(mat, node, "curves_vec", in, out, tex, GPU_constant(&layer)); + return GPU_stack_link(mat, node, "curves_vec", in, out, tex, GPU_constant(&layer)); } void register_node_type_sh_curve_vec(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_CURVE_VEC, "Vector Curves", NODE_CLASS_OP_VECTOR, 0); - node_type_socket_templates(&ntype, sh_node_curve_vec_in, sh_node_curve_vec_out); - node_type_init(&ntype, node_shader_init_curve_vec); - node_type_size_preset(&ntype, NODE_SIZE_LARGE); - node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); - node_type_exec(&ntype, node_initexec_curves, NULL, node_shader_exec_curve_vec); - node_type_gpu(&ntype, gpu_shader_curve_vec); + sh_node_type_base(&ntype, SH_NODE_CURVE_VEC, "Vector Curves", NODE_CLASS_OP_VECTOR, 0); + node_type_socket_templates(&ntype, sh_node_curve_vec_in, sh_node_curve_vec_out); + node_type_init(&ntype, node_shader_init_curve_vec); + node_type_size_preset(&ntype, NODE_SIZE_LARGE); + node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); + node_type_exec(&ntype, node_initexec_curves, NULL, node_shader_exec_curve_vec); + node_type_gpu(&ntype, gpu_shader_curve_vec); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } - /* **************** CURVE RGB ******************** */ static bNodeSocketTemplate sh_node_curve_rgb_in[] = { - { SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_FACTOR}, - { SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_FACTOR}, + {SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_curve_rgb_out[] = { - { SOCK_RGBA, 0, N_("Color")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color")}, + {-1, 0, ""}, }; -static void node_shader_exec_curve_rgb(void *UNUSED(data), int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) +static void node_shader_exec_curve_rgb(void *UNUSED(data), + int UNUSED(thread), + bNode *node, + bNodeExecData *UNUSED(execdata), + bNodeStack **in, + bNodeStack **out) { - float vec[3]; - float fac; - - /* stack order input: vec */ - /* stack order output: vec */ - nodestack_get_vec(&fac, SOCK_FLOAT, in[0]); - nodestack_get_vec(vec, SOCK_VECTOR, in[1]); - curvemapping_evaluateRGBF(node->storage, out[0]->vec, vec); - if (fac != 1.0f) { - interp_v3_v3v3(out[0]->vec, vec, out[0]->vec, fac); - } + float vec[3]; + float fac; + + /* stack order input: vec */ + /* stack order output: vec */ + nodestack_get_vec(&fac, SOCK_FLOAT, in[0]); + nodestack_get_vec(vec, SOCK_VECTOR, in[1]); + curvemapping_evaluateRGBF(node->storage, out[0]->vec, vec); + if (fac != 1.0f) { + interp_v3_v3v3(out[0]->vec, vec, out[0]->vec, fac); + } } static void node_shader_init_curve_rgb(bNodeTree *UNUSED(ntree), bNode *node) { - node->storage = curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f); + node->storage = curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f); } -static int gpu_shader_curve_rgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_curve_rgb(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - float *array, layer; - int size; - bool use_opti = true; - - CurveMapping *cumap = node->storage; - - curvemapping_initialize(cumap); - curvemapping_table_RGBA(cumap, &array, &size); - GPUNodeLink *tex = GPU_color_band(mat, size, array, &layer); - - float ext_rgba[4][4]; - float range_rgba[4]; - - for (int a = 0; a < CM_TOT; ++a) { - const CurveMap *cm = &cumap->cm[a]; - ext_rgba[a][0] = cm->mintable; - ext_rgba[a][2] = cm->maxtable; - range_rgba[a] = 1.0f / max_ff(1e-8f, cm->maxtable - cm->mintable); - /* Compute extrapolation gradients. */ - if ((cm->flag & CUMA_EXTEND_EXTRAPOLATE) != 0) { - ext_rgba[a][1] = (cm->ext_in[0] != 0.0f) ? (cm->ext_in[1] / (cm->ext_in[0] * range_rgba[a])) : 1e8f; - ext_rgba[a][3] = (cm->ext_out[0] != 0.0f) ? (cm->ext_out[1] / (cm->ext_out[0] * range_rgba[a])) : 1e8f; - } - else { - ext_rgba[a][1] = 0.0f; - ext_rgba[a][3] = 0.0f; - } - - /* Check if rgb comps are just linear. */ - if (a < 3) { - if (range_rgba[a] != 1.0f || - ext_rgba[a][1] != 1.0f || - ext_rgba[a][2] != 1.0f || - cm->totpoint != 2 || - cm->curve[0].x != 0.0f || - cm->curve[0].y != 0.0f || - cm->curve[1].x != 1.0f || - cm->curve[1].y != 1.0f) - { - use_opti = false; - } - } - } - - if (use_opti) { - return GPU_stack_link(mat, node, "curves_rgb_opti", in, out, tex, - GPU_constant(&layer), - GPU_uniform(range_rgba), - GPU_uniform(ext_rgba[3])); - } - else { - return GPU_stack_link(mat, node, "curves_rgb", in, out, tex, - GPU_constant(&layer), - GPU_uniform(range_rgba), - GPU_uniform(ext_rgba[0]), - GPU_uniform(ext_rgba[1]), - GPU_uniform(ext_rgba[2]), - GPU_uniform(ext_rgba[3])); - } + float *array, layer; + int size; + bool use_opti = true; + + CurveMapping *cumap = node->storage; + + curvemapping_initialize(cumap); + curvemapping_table_RGBA(cumap, &array, &size); + GPUNodeLink *tex = GPU_color_band(mat, size, array, &layer); + + float ext_rgba[4][4]; + float range_rgba[4]; + + for (int a = 0; a < CM_TOT; ++a) { + const CurveMap *cm = &cumap->cm[a]; + ext_rgba[a][0] = cm->mintable; + ext_rgba[a][2] = cm->maxtable; + range_rgba[a] = 1.0f / max_ff(1e-8f, cm->maxtable - cm->mintable); + /* Compute extrapolation gradients. */ + if ((cm->flag & CUMA_EXTEND_EXTRAPOLATE) != 0) { + ext_rgba[a][1] = (cm->ext_in[0] != 0.0f) ? + (cm->ext_in[1] / (cm->ext_in[0] * range_rgba[a])) : + 1e8f; + ext_rgba[a][3] = (cm->ext_out[0] != 0.0f) ? + (cm->ext_out[1] / (cm->ext_out[0] * range_rgba[a])) : + 1e8f; + } + else { + ext_rgba[a][1] = 0.0f; + ext_rgba[a][3] = 0.0f; + } + + /* Check if rgb comps are just linear. */ + if (a < 3) { + if (range_rgba[a] != 1.0f || ext_rgba[a][1] != 1.0f || ext_rgba[a][2] != 1.0f || + cm->totpoint != 2 || cm->curve[0].x != 0.0f || cm->curve[0].y != 0.0f || + cm->curve[1].x != 1.0f || cm->curve[1].y != 1.0f) { + use_opti = false; + } + } + } + + if (use_opti) { + return GPU_stack_link(mat, + node, + "curves_rgb_opti", + in, + out, + tex, + GPU_constant(&layer), + GPU_uniform(range_rgba), + GPU_uniform(ext_rgba[3])); + } + else { + return GPU_stack_link(mat, + node, + "curves_rgb", + in, + out, + tex, + GPU_constant(&layer), + GPU_uniform(range_rgba), + GPU_uniform(ext_rgba[0]), + GPU_uniform(ext_rgba[1]), + GPU_uniform(ext_rgba[2]), + GPU_uniform(ext_rgba[3])); + } } void register_node_type_sh_curve_rgb(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_CURVE_RGB, "RGB Curves", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, sh_node_curve_rgb_in, sh_node_curve_rgb_out); - node_type_init(&ntype, node_shader_init_curve_rgb); - node_type_size_preset(&ntype, NODE_SIZE_LARGE); - node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); - node_type_exec(&ntype, node_initexec_curves, NULL, node_shader_exec_curve_rgb); - node_type_gpu(&ntype, gpu_shader_curve_rgb); + sh_node_type_base(&ntype, SH_NODE_CURVE_RGB, "RGB Curves", NODE_CLASS_OP_COLOR, 0); + node_type_socket_templates(&ntype, sh_node_curve_rgb_in, sh_node_curve_rgb_out); + node_type_init(&ntype, node_shader_init_curve_rgb); + node_type_size_preset(&ntype, NODE_SIZE_LARGE); + node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); + node_type_exec(&ntype, node_initexec_curves, NULL, node_shader_exec_curve_rgb); + node_type_gpu(&ntype, gpu_shader_curve_rgb); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_displacement.c b/source/blender/nodes/shader/nodes/node_shader_displacement.c index 3ab8e3215a8..5668e6c7329 100644 --- a/source/blender/nodes/shader/nodes/node_shader_displacement.c +++ b/source/blender/nodes/shader/nodes/node_shader_displacement.c @@ -22,54 +22,74 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_displacement_in[] = { - { SOCK_FLOAT, 1, N_("Height"), 0.00f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { SOCK_FLOAT, 1, N_("Midlevel"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { SOCK_FLOAT, 1, N_("Scale"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Height"), 0.00f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + {SOCK_FLOAT, 1, N_("Midlevel"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + {SOCK_FLOAT, 1, N_("Scale"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + {SOCK_VECTOR, + 1, + N_("Normal"), + 0.0f, + 0.0f, + 0.0f, + 1.0f, + -1.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_displacement_out[] = { - { SOCK_VECTOR, 0, N_("Displacement"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_VECTOR, 0, N_("Displacement"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; static void node_shader_init_displacement(bNodeTree *UNUSED(ntree), bNode *node) { - node->custom1 = SHD_SPACE_OBJECT; /* space */ + node->custom1 = SHD_SPACE_OBJECT; /* space */ - /* Set default value here for backwards compatibility. */ - for (bNodeSocket *sock = node->inputs.first; sock; sock = sock->next) { - if (STREQ(sock->name, "Midlevel")) { - ((bNodeSocketValueFloat *)sock->default_value)->value = 0.5f; - } - } + /* Set default value here for backwards compatibility. */ + for (bNodeSocket *sock = node->inputs.first; sock; sock = sock->next) { + if (STREQ(sock->name, "Midlevel")) { + ((bNodeSocketValueFloat *)sock->default_value)->value = 0.5f; + } + } } -static int gpu_shader_displacement(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_displacement(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - if (!in[3].link) { - GPU_link(mat, "direction_transform_m4v3", GPU_builtin(GPU_VIEW_NORMAL), GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &in[3].link); - } + if (!in[3].link) { + GPU_link(mat, + "direction_transform_m4v3", + GPU_builtin(GPU_VIEW_NORMAL), + GPU_builtin(GPU_INVERSE_VIEW_MATRIX), + &in[3].link); + } - if (node->custom1 == SHD_SPACE_OBJECT) { - return GPU_stack_link(mat, node, "node_displacement_object", in, out, GPU_builtin(GPU_OBJECT_MATRIX)); - } - else { - return GPU_stack_link(mat, node, "node_displacement_world", in, out, GPU_builtin(GPU_OBJECT_MATRIX)); - } + if (node->custom1 == SHD_SPACE_OBJECT) { + return GPU_stack_link( + mat, node, "node_displacement_object", in, out, GPU_builtin(GPU_OBJECT_MATRIX)); + } + else { + return GPU_stack_link( + mat, node, "node_displacement_world", in, out, GPU_builtin(GPU_OBJECT_MATRIX)); + } } /* node type definition */ void register_node_type_sh_displacement(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_DISPLACEMENT, "Displacement", NODE_CLASS_OP_VECTOR, 0); - node_type_socket_templates(&ntype, sh_node_displacement_in, sh_node_displacement_out); - node_type_storage(&ntype, "", NULL, NULL); - node_type_init(&ntype, node_shader_init_displacement); - node_type_gpu(&ntype, gpu_shader_displacement); + sh_node_type_base(&ntype, SH_NODE_DISPLACEMENT, "Displacement", NODE_CLASS_OP_VECTOR, 0); + node_type_socket_templates(&ntype, sh_node_displacement_in, sh_node_displacement_out); + node_type_storage(&ntype, "", NULL, NULL); + node_type_init(&ntype, node_shader_init_displacement); + node_type_gpu(&ntype, gpu_shader_displacement); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_eevee_specular.c b/source/blender/nodes/shader/nodes/node_shader_eevee_specular.c index eb5e3bc7b3c..ae6a4e7e9eb 100644 --- a/source/blender/nodes/shader/nodes/node_shader_eevee_specular.c +++ b/source/blender/nodes/shader/nodes/node_shader_eevee_specular.c @@ -22,59 +22,92 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_eevee_specular_in[] = { - { SOCK_RGBA, 1, N_("Base Color"), 0.8f, 0.8f, 0.8f, 1.0f}, - { SOCK_RGBA, 1, N_("Specular"), 0.03f, 0.03f, 0.03f, 1.0f}, - { SOCK_FLOAT, 1, N_("Roughness"), 0.2f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_RGBA, 1, N_("Emissive Color"), 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Transparency"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { SOCK_FLOAT, 1, N_("Clear Coat"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("Clear Coat Roughness"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_VECTOR, 1, N_("Clear Coat Normal"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { SOCK_FLOAT, 1, N_("Ambient Occlusion"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Base Color"), 0.8f, 0.8f, 0.8f, 1.0f}, + {SOCK_RGBA, 1, N_("Specular"), 0.03f, 0.03f, 0.03f, 1.0f}, + {SOCK_FLOAT, 1, N_("Roughness"), 0.2f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_RGBA, 1, N_("Emissive Color"), 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Transparency"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_VECTOR, + 1, + N_("Normal"), + 0.0f, + 0.0f, + 0.0f, + 1.0f, + -1.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {SOCK_FLOAT, 1, N_("Clear Coat"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Clear Coat Roughness"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_VECTOR, + 1, + N_("Clear Coat Normal"), + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {SOCK_FLOAT, + 1, + N_("Ambient Occlusion"), + 1.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_eevee_specular_out[] = { - { SOCK_SHADER, 0, N_("BSDF")}, - { -1, 0, "" }, + {SOCK_SHADER, 0, N_("BSDF")}, + {-1, 0, ""}, }; -static int node_shader_gpu_eevee_specular(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_eevee_specular(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - static float one = 1.0f; + static float one = 1.0f; - /* Normals */ - if (!in[5].link) { - GPU_link(mat, "world_normals_get", &in[5].link); - } + /* Normals */ + if (!in[5].link) { + GPU_link(mat, "world_normals_get", &in[5].link); + } - /* Clearcoat Normals */ - if (!in[8].link) { - GPU_link(mat, "world_normals_get", &in[8].link); - } + /* Clearcoat Normals */ + if (!in[8].link) { + GPU_link(mat, "world_normals_get", &in[8].link); + } - /* Occlusion */ - if (!in[9].link) { - GPU_link(mat, "set_value", GPU_constant(&one), &in[9].link); - } + /* Occlusion */ + if (!in[9].link) { + GPU_link(mat, "set_value", GPU_constant(&one), &in[9].link); + } - GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE | GPU_MATFLAG_GLOSSY); + GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE | GPU_MATFLAG_GLOSSY); - return GPU_stack_link(mat, node, "node_eevee_specular", in, out, GPU_constant(&node->ssr_id)); + return GPU_stack_link(mat, node, "node_eevee_specular", in, out, GPU_constant(&node->ssr_id)); } - /* node type definition */ void register_node_type_sh_eevee_specular(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_EEVEE_SPECULAR, "Specular", NODE_CLASS_SHADER, 0); - node_type_socket_templates(&ntype, sh_node_eevee_specular_in, sh_node_eevee_specular_out); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_eevee_specular); + sh_node_type_base(&ntype, SH_NODE_EEVEE_SPECULAR, "Specular", NODE_CLASS_SHADER, 0); + node_type_socket_templates(&ntype, sh_node_eevee_specular_in, sh_node_eevee_specular_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_eevee_specular); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_emission.c b/source/blender/nodes/shader/nodes/node_shader_emission.c index 5440ef5e0d0..b6901c1a8cc 100644 --- a/source/blender/nodes/shader/nodes/node_shader_emission.c +++ b/source/blender/nodes/shader/nodes/node_shader_emission.c @@ -22,31 +22,35 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_emission_in[] = { - { SOCK_RGBA, 1, N_("Color"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Strength"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000000.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Strength"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000000.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_emission_out[] = { - { SOCK_SHADER, 0, N_("Emission")}, - { -1, 0, "" }, + {SOCK_SHADER, 0, N_("Emission")}, + {-1, 0, ""}, }; -static int node_shader_gpu_emission(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_emission(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "node_emission", in, out, GPU_builtin(GPU_VIEW_NORMAL)); + return GPU_stack_link(mat, node, "node_emission", in, out, GPU_builtin(GPU_VIEW_NORMAL)); } /* node type definition */ void register_node_type_sh_emission(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_EMISSION, "Emission", NODE_CLASS_SHADER, 0); - node_type_socket_templates(&ntype, sh_node_emission_in, sh_node_emission_out); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_emission); + sh_node_type_base(&ntype, SH_NODE_EMISSION, "Emission", NODE_CLASS_SHADER, 0); + node_type_socket_templates(&ntype, sh_node_emission_in, sh_node_emission_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_emission); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_fresnel.c b/source/blender/nodes/shader/nodes/node_shader_fresnel.c index 681e361202e..f7ea7c48083 100644 --- a/source/blender/nodes/shader/nodes/node_shader_fresnel.c +++ b/source/blender/nodes/shader/nodes/node_shader_fresnel.c @@ -21,43 +21,63 @@ /* **************** Fresnel ******************** */ static bNodeSocketTemplate sh_node_fresnel_in[] = { - { SOCK_FLOAT, 1, N_("IOR"), 1.45f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("IOR"), 1.45f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + {SOCK_VECTOR, + 1, + N_("Normal"), + 0.0f, + 0.0f, + 0.0f, + 1.0f, + -1.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_fresnel_out[] = { - { SOCK_FLOAT, 0, N_("Fac"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("Fac"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {-1, 0, ""}, }; -static int node_shader_gpu_fresnel(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_fresnel(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - if (!in[1].link) { - in[1].link = GPU_builtin(GPU_VIEW_NORMAL); - } - else { - GPU_link(mat, "direction_transform_m4v3", in[1].link, GPU_builtin(GPU_VIEW_MATRIX), &in[1].link); - } - - return GPU_stack_link(mat, node, "node_fresnel", in, out, GPU_builtin(GPU_VIEW_POSITION)); + if (!in[1].link) { + in[1].link = GPU_builtin(GPU_VIEW_NORMAL); + } + else { + GPU_link( + mat, "direction_transform_m4v3", in[1].link, GPU_builtin(GPU_VIEW_MATRIX), &in[1].link); + } + + return GPU_stack_link(mat, node, "node_fresnel", in, out, GPU_builtin(GPU_VIEW_POSITION)); } -static void node_shader_exec_fresnel(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out)) +static void node_shader_exec_fresnel(void *UNUSED(data), + int UNUSED(thread), + bNode *UNUSED(node), + bNodeExecData *UNUSED(execdata), + bNodeStack **UNUSED(in), + bNodeStack **UNUSED(out)) { } /* node type definition */ void register_node_type_sh_fresnel(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_FRESNEL, "Fresnel", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, sh_node_fresnel_in, sh_node_fresnel_out); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_fresnel); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_fresnel); + sh_node_type_base(&ntype, SH_NODE_FRESNEL, "Fresnel", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, sh_node_fresnel_in, sh_node_fresnel_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_fresnel); + node_type_exec(&ntype, NULL, NULL, node_shader_exec_fresnel); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_gamma.c b/source/blender/nodes/shader/nodes/node_shader_gamma.c index 06b2ed272c8..41a1db311c8 100644 --- a/source/blender/nodes/shader/nodes/node_shader_gamma.c +++ b/source/blender/nodes/shader/nodes/node_shader_gamma.c @@ -22,43 +22,52 @@ /* **************** Gamma Tools ******************** */ static bNodeSocketTemplate sh_node_gamma_in[] = { - { SOCK_RGBA, 1, N_("Color"), 1.0f, 1.0f, 1.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Gamma"), 1.0f, 0.0f, 0.0f, 0.0f, 0.001f, 10.0f, PROP_UNSIGNED}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Gamma"), 1.0f, 0.0f, 0.0f, 0.0f, 0.001f, 10.0f, PROP_UNSIGNED}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_gamma_out[] = { - { SOCK_RGBA, 0, N_("Color")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color")}, + {-1, 0, ""}, }; -static void node_shader_exec_gamma(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) +static void node_shader_exec_gamma(void *UNUSED(data), + int UNUSED(thread), + bNode *UNUSED(node), + bNodeExecData *UNUSED(execdata), + bNodeStack **in, + bNodeStack **out) { - float col[3]; - float gamma; - nodestack_get_vec(col, SOCK_VECTOR, in[0]); - nodestack_get_vec(&gamma, SOCK_FLOAT, in[1]); + float col[3]; + float gamma; + nodestack_get_vec(col, SOCK_VECTOR, in[0]); + nodestack_get_vec(&gamma, SOCK_FLOAT, in[1]); - out[0]->vec[0] = col[0] > 0.0f ? powf(col[0], gamma) : col[0]; - out[0]->vec[1] = col[1] > 0.0f ? powf(col[1], gamma) : col[1]; - out[0]->vec[2] = col[2] > 0.0f ? powf(col[2], gamma) : col[2]; + out[0]->vec[0] = col[0] > 0.0f ? powf(col[0], gamma) : col[0]; + out[0]->vec[1] = col[1] > 0.0f ? powf(col[1], gamma) : col[1]; + out[0]->vec[2] = col[2] > 0.0f ? powf(col[2], gamma) : col[2]; } -static int node_shader_gpu_gamma(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_gamma(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "node_gamma", in, out); + return GPU_stack_link(mat, node, "node_gamma", in, out); } void register_node_type_sh_gamma(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_GAMMA, "Gamma", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, sh_node_gamma_in, sh_node_gamma_out); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_gamma); - node_type_gpu(&ntype, node_shader_gpu_gamma); + sh_node_type_base(&ntype, SH_NODE_GAMMA, "Gamma", NODE_CLASS_OP_COLOR, 0); + node_type_socket_templates(&ntype, sh_node_gamma_in, sh_node_gamma_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_exec(&ntype, NULL, NULL, node_shader_exec_gamma); + node_type_gpu(&ntype, node_shader_gpu_gamma); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_geometry.c b/source/blender/nodes/shader/nodes/node_shader_geometry.c index ec9b3a5443e..6f97efe9f73 100644 --- a/source/blender/nodes/shader/nodes/node_shader_geometry.c +++ b/source/blender/nodes/shader/nodes/node_shader_geometry.c @@ -22,40 +22,52 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_geometry_out[] = { - { SOCK_VECTOR, 0, N_("Position"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 0, N_("Normal"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 0, N_("Tangent"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 0, N_("True Normal"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 0, N_("Incoming"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 0, N_("Parametric"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Backfacing"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Pointiness"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_VECTOR, 0, N_("Position"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_VECTOR, 0, N_("Normal"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_VECTOR, 0, N_("Tangent"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_VECTOR, 0, N_("True Normal"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_VECTOR, 0, N_("Incoming"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_VECTOR, 0, N_("Parametric"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Backfacing"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Pointiness"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; -static int node_shader_gpu_geometry(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_geometry(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - /* HACK: Don't request GPU_BARYCENTRIC_TEXCO if not used because it will - * trigger the use of geometry shader (and the performance penalty it implies). */ - float val[2] = {0.0f, 0.0f}; - GPUNodeLink *bary_link = (!out[5].hasoutput) ? GPU_constant(val) : GPU_builtin(GPU_BARYCENTRIC_TEXCO); - - return GPU_stack_link(mat, node, "node_geometry", in, out, - GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL), - GPU_attribute(CD_ORCO, ""), GPU_builtin(GPU_OBJECT_MATRIX), - GPU_builtin(GPU_INVERSE_VIEW_MATRIX), bary_link); + /* HACK: Don't request GPU_BARYCENTRIC_TEXCO if not used because it will + * trigger the use of geometry shader (and the performance penalty it implies). */ + float val[2] = {0.0f, 0.0f}; + GPUNodeLink *bary_link = (!out[5].hasoutput) ? GPU_constant(val) : + GPU_builtin(GPU_BARYCENTRIC_TEXCO); + + return GPU_stack_link(mat, + node, + "node_geometry", + in, + out, + GPU_builtin(GPU_VIEW_POSITION), + GPU_builtin(GPU_VIEW_NORMAL), + GPU_attribute(CD_ORCO, ""), + GPU_builtin(GPU_OBJECT_MATRIX), + GPU_builtin(GPU_INVERSE_VIEW_MATRIX), + bary_link); } /* node type definition */ void register_node_type_sh_geometry(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_NEW_GEOMETRY, "Geometry", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, NULL, sh_node_geometry_out); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_geometry); + sh_node_type_base(&ntype, SH_NODE_NEW_GEOMETRY, "Geometry", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, NULL, sh_node_geometry_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_geometry); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_hair_info.c b/source/blender/nodes/shader/nodes/node_shader_hair_info.c index 2191f71a221..c92031f5505 100644 --- a/source/blender/nodes/shader/nodes/node_shader_hair_info.c +++ b/source/blender/nodes/shader/nodes/node_shader_hair_info.c @@ -20,30 +20,34 @@ #include "../node_shader_util.h" static bNodeSocketTemplate outputs[] = { - { SOCK_FLOAT, 0, N_("Is Strand"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Intercept"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Thickness"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 0, N_("Tangent Normal"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - /*{ SOCK_FLOAT, 0, N_("Fade"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},*/ - { SOCK_FLOAT, 0, N_("Random") }, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("Is Strand"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Intercept"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Thickness"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_VECTOR, 0, N_("Tangent Normal"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + /*{ SOCK_FLOAT, 0, N_("Fade"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},*/ + {SOCK_FLOAT, 0, N_("Random")}, + {-1, 0, ""}, }; -static int node_shader_gpu_hair_info(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_hair_info(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "node_hair_info", in, out); + return GPU_stack_link(mat, node, "node_hair_info", in, out); } /* node type definition */ void register_node_type_sh_hair_info(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_HAIR_INFO, "Hair Info", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, NULL, outputs); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_hair_info); + sh_node_type_base(&ntype, SH_NODE_HAIR_INFO, "Hair Info", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, NULL, outputs); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_hair_info); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_holdout.c b/source/blender/nodes/shader/nodes/node_shader_holdout.c index 57394414f4b..a4d1e77c736 100644 --- a/source/blender/nodes/shader/nodes/node_shader_holdout.c +++ b/source/blender/nodes/shader/nodes/node_shader_holdout.c @@ -22,24 +22,23 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_holdout_in[] = { - { -1, 0, "" }, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_holdout_out[] = { - { SOCK_SHADER, 0, N_("Holdout")}, - { -1, 0, "" }, + {SOCK_SHADER, 0, N_("Holdout")}, + {-1, 0, ""}, }; - /* node type definition */ void register_node_type_sh_holdout(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_HOLDOUT, "Holdout", NODE_CLASS_SHADER, 0); - node_type_socket_templates(&ntype, sh_node_holdout_in, sh_node_holdout_out); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); + sh_node_type_base(&ntype, SH_NODE_HOLDOUT, "Holdout", NODE_CLASS_SHADER, 0); + node_type_socket_templates(&ntype, sh_node_holdout_in, sh_node_holdout_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_hueSatVal.c b/source/blender/nodes/shader/nodes/node_shader_hueSatVal.c index 1d4b1289fd7..ea916d25ffd 100644 --- a/source/blender/nodes/shader/nodes/node_shader_hueSatVal.c +++ b/source/blender/nodes/shader/nodes/node_shader_hueSatVal.c @@ -21,72 +21,79 @@ * \ingroup shdnodes */ - #include "node_shader_util.h" - /* **************** Hue Saturation ******************** */ static bNodeSocketTemplate sh_node_hue_sat_in[] = { - { SOCK_FLOAT, 1, N_("Hue"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("Saturation"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("Value"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Hue"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("Saturation"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("Value"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_hue_sat_out[] = { - { SOCK_RGBA, 0, N_("Color")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color")}, + {-1, 0, ""}, }; /* note: it would be possible to use CMP version for both nodes */ -static void do_hue_sat_fac(bNode *UNUSED(node), float *out, float hue, float sat, float val, float in[4], float fac) +static void do_hue_sat_fac( + bNode *UNUSED(node), float *out, float hue, float sat, float val, float in[4], float fac) { - if (fac != 0.0f && (hue != 0.5f || sat != 1.0f || val != 1.0f)) { - float col[3], hsv[3], mfac = 1.0f - fac; + if (fac != 0.0f && (hue != 0.5f || sat != 1.0f || val != 1.0f)) { + float col[3], hsv[3], mfac = 1.0f - fac; - rgb_to_hsv(in[0], in[1], in[2], hsv, hsv + 1, hsv + 2); - hsv[0] = fmodf(hsv[0] + hue + 0.5f, 1.0f); - hsv[1] = clamp_f(hsv[1] * sat, 0.0f, 1.0f); - hsv[2] *= val; - hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col + 1, col + 2); + rgb_to_hsv(in[0], in[1], in[2], hsv, hsv + 1, hsv + 2); + hsv[0] = fmodf(hsv[0] + hue + 0.5f, 1.0f); + hsv[1] = clamp_f(hsv[1] * sat, 0.0f, 1.0f); + hsv[2] *= val; + hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col + 1, col + 2); - out[0] = mfac * in[0] + fac * col[0]; - out[1] = mfac * in[1] + fac * col[1]; - out[2] = mfac * in[2] + fac * col[2]; - } - else { - copy_v4_v4(out, in); - } + out[0] = mfac * in[0] + fac * col[0]; + out[1] = mfac * in[1] + fac * col[1]; + out[2] = mfac * in[2] + fac * col[2]; + } + else { + copy_v4_v4(out, in); + } } -static void node_shader_exec_hue_sat(void *UNUSED(data), int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) +static void node_shader_exec_hue_sat(void *UNUSED(data), + int UNUSED(thread), + bNode *node, + bNodeExecData *UNUSED(execdata), + bNodeStack **in, + bNodeStack **out) { - float hue, sat, val, fac; - float col[4]; - nodestack_get_vec(&hue, SOCK_FLOAT, in[0]); - nodestack_get_vec(&sat, SOCK_FLOAT, in[1]); - nodestack_get_vec(&val, SOCK_FLOAT, in[2]); - nodestack_get_vec(&fac, SOCK_FLOAT, in[3]); - nodestack_get_vec(col, SOCK_RGBA, in[4]); - do_hue_sat_fac(node, out[0]->vec, hue, sat, val, col, fac); + float hue, sat, val, fac; + float col[4]; + nodestack_get_vec(&hue, SOCK_FLOAT, in[0]); + nodestack_get_vec(&sat, SOCK_FLOAT, in[1]); + nodestack_get_vec(&val, SOCK_FLOAT, in[2]); + nodestack_get_vec(&fac, SOCK_FLOAT, in[3]); + nodestack_get_vec(col, SOCK_RGBA, in[4]); + do_hue_sat_fac(node, out[0]->vec, hue, sat, val, col, fac); } - -static int gpu_shader_hue_sat(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_hue_sat(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "hue_sat", in, out); + return GPU_stack_link(mat, node, "hue_sat", in, out); } void register_node_type_sh_hue_sat(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_HUE_SAT, "Hue Saturation Value", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, sh_node_hue_sat_in, sh_node_hue_sat_out); - node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_hue_sat); - node_type_gpu(&ntype, gpu_shader_hue_sat); + sh_node_type_base(&ntype, SH_NODE_HUE_SAT, "Hue Saturation Value", NODE_CLASS_OP_COLOR, 0); + node_type_socket_templates(&ntype, sh_node_hue_sat_in, sh_node_hue_sat_out); + node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); + node_type_exec(&ntype, NULL, NULL, node_shader_exec_hue_sat); + node_type_gpu(&ntype, gpu_shader_hue_sat); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_ies_light.c b/source/blender/nodes/shader/nodes/node_shader_ies_light.c index 566deee0c42..859dd947139 100644 --- a/source/blender/nodes/shader/nodes/node_shader_ies_light.c +++ b/source/blender/nodes/shader/nodes/node_shader_ies_light.c @@ -22,31 +22,32 @@ /* **************** IES Light ******************** */ static bNodeSocketTemplate sh_node_tex_ies_in[] = { - { SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { SOCK_FLOAT, 1, N_("Strength"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000000.0f, PROP_NONE}, - { -1, 0, "" }, + {SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + {SOCK_FLOAT, 1, N_("Strength"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000000.0f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_tex_ies_out[] = { - { SOCK_FLOAT, 0, N_("Fac")}, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("Fac")}, + {-1, 0, ""}, }; static void node_shader_init_tex_ies(bNodeTree *UNUSED(ntree), bNode *node) { - NodeShaderTexIES *tex = MEM_callocN(sizeof(NodeShaderTexIES), "NodeShaderIESLight"); - node->storage = tex; + NodeShaderTexIES *tex = MEM_callocN(sizeof(NodeShaderTexIES), "NodeShaderIESLight"); + node->storage = tex; } /* node type definition */ void register_node_type_sh_tex_ies(void) { - static bNodeType ntype; + 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); + 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); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_invert.c b/source/blender/nodes/shader/nodes/node_shader_invert.c index f3d22a5b89f..802d10def0a 100644 --- a/source/blender/nodes/shader/nodes/node_shader_invert.c +++ b/source/blender/nodes/shader/nodes/node_shader_invert.c @@ -21,55 +21,56 @@ * \ingroup shdnodes */ - #include "node_shader_util.h" - - /* **************** INVERT ******************** */ static bNodeSocketTemplate sh_node_invert_in[] = { - { SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; + {SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}}; -static bNodeSocketTemplate sh_node_invert_out[] = { - { SOCK_RGBA, 0, N_("Color")}, - { -1, 0, "" } -}; +static bNodeSocketTemplate sh_node_invert_out[] = {{SOCK_RGBA, 0, N_("Color")}, {-1, 0, ""}}; -static void node_shader_exec_invert(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **in, +static void node_shader_exec_invert(void *UNUSED(data), + int UNUSED(thread), + bNode *UNUSED(node), + bNodeExecData *UNUSED(execdata), + bNodeStack **in, bNodeStack **out) { - float col[3], icol[3], fac; + float col[3], icol[3], fac; - nodestack_get_vec(&fac, SOCK_FLOAT, in[0]); - nodestack_get_vec(col, SOCK_VECTOR, in[1]); + nodestack_get_vec(&fac, SOCK_FLOAT, in[0]); + nodestack_get_vec(col, SOCK_VECTOR, in[1]); - icol[0] = 1.0f - col[0]; - icol[1] = 1.0f - col[1]; - icol[2] = 1.0f - col[2]; + icol[0] = 1.0f - col[0]; + icol[1] = 1.0f - col[1]; + icol[2] = 1.0f - col[2]; - /* if fac, blend result against original input */ - if (fac < 1.0f) - interp_v3_v3v3(out[0]->vec, col, icol, fac); - else - copy_v3_v3(out[0]->vec, icol); + /* if fac, blend result against original input */ + if (fac < 1.0f) + interp_v3_v3v3(out[0]->vec, col, icol, fac); + else + copy_v3_v3(out[0]->vec, icol); } -static int gpu_shader_invert(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_invert(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "invert", in, out); + return GPU_stack_link(mat, node, "invert", in, out); } void register_node_type_sh_invert(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_INVERT, "Invert", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, sh_node_invert_in, sh_node_invert_out); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_invert); - node_type_gpu(&ntype, gpu_shader_invert); + sh_node_type_base(&ntype, SH_NODE_INVERT, "Invert", NODE_CLASS_OP_COLOR, 0); + node_type_socket_templates(&ntype, sh_node_invert_in, sh_node_invert_out); + node_type_exec(&ntype, NULL, NULL, node_shader_exec_invert); + node_type_gpu(&ntype, gpu_shader_invert); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_layer_weight.c b/source/blender/nodes/shader/nodes/node_shader_layer_weight.c index 1dd615bceac..20b9a67fa76 100644 --- a/source/blender/nodes/shader/nodes/node_shader_layer_weight.c +++ b/source/blender/nodes/shader/nodes/node_shader_layer_weight.c @@ -22,44 +22,64 @@ /* **************** Layer Weight ******************** */ static bNodeSocketTemplate sh_node_layer_weight_in[] = { - { SOCK_FLOAT, 1, N_("Blend"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Blend"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_VECTOR, + 1, + N_("Normal"), + 0.0f, + 0.0f, + 0.0f, + 1.0f, + -1.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_layer_weight_out[] = { - { SOCK_FLOAT, 0, N_("Fresnel"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Facing"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("Fresnel"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Facing"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; -static int node_shader_gpu_layer_weight(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_layer_weight(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - if (!in[1].link) { - in[1].link = GPU_builtin(GPU_VIEW_NORMAL); - } - else { - GPU_link(mat, "direction_transform_m4v3", in[1].link, GPU_builtin(GPU_VIEW_MATRIX), &in[1].link); - } + if (!in[1].link) { + in[1].link = GPU_builtin(GPU_VIEW_NORMAL); + } + else { + GPU_link( + mat, "direction_transform_m4v3", in[1].link, GPU_builtin(GPU_VIEW_MATRIX), &in[1].link); + } - return GPU_stack_link(mat, node, "node_layer_weight", in, out, GPU_builtin(GPU_VIEW_POSITION)); + return GPU_stack_link(mat, node, "node_layer_weight", in, out, GPU_builtin(GPU_VIEW_POSITION)); } -static void node_shader_exec_layer_weight(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out)) +static void node_shader_exec_layer_weight(void *UNUSED(data), + int UNUSED(thread), + bNode *UNUSED(node), + bNodeExecData *UNUSED(execdata), + bNodeStack **UNUSED(in), + bNodeStack **UNUSED(out)) { } /* node type definition */ void register_node_type_sh_layer_weight(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_LAYER_WEIGHT, "Layer Weight", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, sh_node_layer_weight_in, sh_node_layer_weight_out); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_layer_weight); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_layer_weight); + sh_node_type_base(&ntype, SH_NODE_LAYER_WEIGHT, "Layer Weight", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, sh_node_layer_weight_in, sh_node_layer_weight_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_layer_weight); + node_type_exec(&ntype, NULL, NULL, node_shader_exec_layer_weight); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_light_falloff.c b/source/blender/nodes/shader/nodes/node_shader_light_falloff.c index c3dd65305ab..95e8a511076 100644 --- a/source/blender/nodes/shader/nodes/node_shader_light_falloff.c +++ b/source/blender/nodes/shader/nodes/node_shader_light_falloff.c @@ -22,36 +22,40 @@ /* **************** INPUT ********************* */ static bNodeSocketTemplate sh_node_light_falloff_in[] = { - { SOCK_FLOAT, 1, N_("Strength"), 100.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000000.0f}, - { SOCK_FLOAT, 1, N_("Smooth"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Strength"), 100.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000000.0f}, + {SOCK_FLOAT, 1, N_("Smooth"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + {-1, 0, ""}, }; /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_light_falloff_out[] = { - { SOCK_FLOAT, 0, N_("Quadratic"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Linear"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Constant"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("Quadratic"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Linear"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Constant"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; -static int node_shader_gpu_light_falloff(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_light_falloff(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "node_light_falloff", in, out); + return GPU_stack_link(mat, node, "node_light_falloff", in, out); } /* node type definition */ void register_node_type_sh_light_falloff(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_LIGHT_FALLOFF, "Light Falloff", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, sh_node_light_falloff_in, sh_node_light_falloff_out); - node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_light_falloff); + sh_node_type_base(&ntype, SH_NODE_LIGHT_FALLOFF, "Light Falloff", NODE_CLASS_OP_COLOR, 0); + node_type_socket_templates(&ntype, sh_node_light_falloff_in, sh_node_light_falloff_out); + node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_light_falloff); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_light_path.c b/source/blender/nodes/shader/nodes/node_shader_light_path.c index 3584fb542dd..09289766fb6 100644 --- a/source/blender/nodes/shader/nodes/node_shader_light_path.c +++ b/source/blender/nodes/shader/nodes/node_shader_light_path.c @@ -22,37 +22,41 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_light_path_out[] = { - { SOCK_FLOAT, 0, N_("Is Camera Ray"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Is Shadow Ray"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Is Diffuse Ray"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Is Glossy Ray"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Is Singular Ray"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Is Reflection Ray"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Is Transmission Ray"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Ray Length"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Ray Depth"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Diffuse Depth"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Glossy Depth"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Transparent Depth"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Transmission Depth"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("Is Camera Ray"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Is Shadow Ray"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Is Diffuse Ray"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Is Glossy Ray"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Is Singular Ray"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Is Reflection Ray"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Is Transmission Ray"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Ray Length"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Ray Depth"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Diffuse Depth"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Glossy Depth"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Transparent Depth"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Transmission Depth"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; -static int node_shader_gpu_light_path(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_light_path(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "node_light_path", in, out); + return GPU_stack_link(mat, node, "node_light_path", in, out); } /* node type definition */ void register_node_type_sh_light_path(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_LIGHT_PATH, "Light Path", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, NULL, sh_node_light_path_out); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_light_path); + sh_node_type_base(&ntype, SH_NODE_LIGHT_PATH, "Light Path", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, NULL, sh_node_light_path_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_light_path); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_mapping.c b/source/blender/nodes/shader/nodes/node_shader_mapping.c index 265d4235c8d..5af0dd55083 100644 --- a/source/blender/nodes/shader/nodes/node_shader_mapping.c +++ b/source/blender/nodes/shader/nodes/node_shader_mapping.c @@ -25,91 +25,105 @@ /* **************** MAPPING ******************** */ static bNodeSocketTemplate sh_node_mapping_in[] = { - { SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE}, - { -1, 0, "" }, + {SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_mapping_out[] = { - { SOCK_VECTOR, 0, N_("Vector")}, - { -1, 0, "" }, + {SOCK_VECTOR, 0, N_("Vector")}, + {-1, 0, ""}, }; static void *node_shader_initexec_mapping(bNodeExecContext *UNUSED(context), bNode *node, bNodeInstanceKey UNUSED(key)) { - TexMapping *texmap = node->storage; - BKE_texture_mapping_init(texmap); - return NULL; + TexMapping *texmap = node->storage; + BKE_texture_mapping_init(texmap); + return NULL; } /* do the regular mapping options for blender textures */ -static void node_shader_exec_mapping(void *UNUSED(data), int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) +static void node_shader_exec_mapping(void *UNUSED(data), + int UNUSED(thread), + bNode *node, + bNodeExecData *UNUSED(execdata), + bNodeStack **in, + bNodeStack **out) { - TexMapping *texmap = node->storage; - float *vec = out[0]->vec; - - /* stack order input: vector */ - /* stack order output: vector */ - nodestack_get_vec(vec, SOCK_VECTOR, in[0]); - mul_m4_v3(texmap->mat, vec); - - if (texmap->flag & TEXMAP_CLIP_MIN) { - if (vec[0] < texmap->min[0]) vec[0] = texmap->min[0]; - if (vec[1] < texmap->min[1]) vec[1] = texmap->min[1]; - if (vec[2] < texmap->min[2]) vec[2] = texmap->min[2]; - } - if (texmap->flag & TEXMAP_CLIP_MAX) { - if (vec[0] > texmap->max[0]) vec[0] = texmap->max[0]; - if (vec[1] > texmap->max[1]) vec[1] = texmap->max[1]; - if (vec[2] > texmap->max[2]) vec[2] = texmap->max[2]; - } - - if (texmap->type == TEXMAP_TYPE_NORMAL) - normalize_v3(vec); + TexMapping *texmap = node->storage; + float *vec = out[0]->vec; + + /* stack order input: vector */ + /* stack order output: vector */ + nodestack_get_vec(vec, SOCK_VECTOR, in[0]); + mul_m4_v3(texmap->mat, vec); + + if (texmap->flag & TEXMAP_CLIP_MIN) { + if (vec[0] < texmap->min[0]) + vec[0] = texmap->min[0]; + if (vec[1] < texmap->min[1]) + vec[1] = texmap->min[1]; + if (vec[2] < texmap->min[2]) + vec[2] = texmap->min[2]; + } + if (texmap->flag & TEXMAP_CLIP_MAX) { + if (vec[0] > texmap->max[0]) + vec[0] = texmap->max[0]; + if (vec[1] > texmap->max[1]) + vec[1] = texmap->max[1]; + if (vec[2] > texmap->max[2]) + vec[2] = texmap->max[2]; + } + + if (texmap->type == TEXMAP_TYPE_NORMAL) + normalize_v3(vec); } - static void node_shader_init_mapping(bNodeTree *UNUSED(ntree), bNode *node) { - node->storage = BKE_texture_mapping_add(TEXMAP_TYPE_POINT); + node->storage = BKE_texture_mapping_add(TEXMAP_TYPE_POINT); } -static int gpu_shader_mapping(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_mapping(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - TexMapping *texmap = node->storage; - float domin = (texmap->flag & TEXMAP_CLIP_MIN) != 0; - float domax = (texmap->flag & TEXMAP_CLIP_MAX) != 0; - static float max[3] = { FLT_MAX, FLT_MAX, FLT_MAX}; - static float min[3] = {-FLT_MAX, -FLT_MAX, -FLT_MAX}; - GPUNodeLink *tmin, *tmax, *tmat0, *tmat1, *tmat2, *tmat3; - - tmin = GPU_uniform((domin) ? texmap->min : min); - tmax = GPU_uniform((domax) ? texmap->max : max); - tmat0 = GPU_uniform((float *)texmap->mat[0]); - tmat1 = GPU_uniform((float *)texmap->mat[1]); - tmat2 = GPU_uniform((float *)texmap->mat[2]); - tmat3 = GPU_uniform((float *)texmap->mat[3]); - - GPU_stack_link(mat, node, "mapping", in, out, tmat0, tmat1, tmat2, tmat3, tmin, tmax); - - if (texmap->type == TEXMAP_TYPE_NORMAL) - GPU_link(mat, "texco_norm", out[0].link, &out[0].link); - - return true; + TexMapping *texmap = node->storage; + float domin = (texmap->flag & TEXMAP_CLIP_MIN) != 0; + float domax = (texmap->flag & TEXMAP_CLIP_MAX) != 0; + static float max[3] = {FLT_MAX, FLT_MAX, FLT_MAX}; + static float min[3] = {-FLT_MAX, -FLT_MAX, -FLT_MAX}; + GPUNodeLink *tmin, *tmax, *tmat0, *tmat1, *tmat2, *tmat3; + + tmin = GPU_uniform((domin) ? texmap->min : min); + tmax = GPU_uniform((domax) ? texmap->max : max); + tmat0 = GPU_uniform((float *)texmap->mat[0]); + tmat1 = GPU_uniform((float *)texmap->mat[1]); + tmat2 = GPU_uniform((float *)texmap->mat[2]); + tmat3 = GPU_uniform((float *)texmap->mat[3]); + + GPU_stack_link(mat, node, "mapping", in, out, tmat0, tmat1, tmat2, tmat3, tmin, tmax); + + if (texmap->type == TEXMAP_TYPE_NORMAL) + GPU_link(mat, "texco_norm", out[0].link, &out[0].link); + + return true; } void register_node_type_sh_mapping(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_MAPPING, "Mapping", NODE_CLASS_OP_VECTOR, 0); - node_type_socket_templates(&ntype, sh_node_mapping_in, sh_node_mapping_out); - node_type_size(&ntype, 320, 160, 360); - node_type_init(&ntype, node_shader_init_mapping); - node_type_storage(&ntype, "TexMapping", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, node_shader_initexec_mapping, NULL, node_shader_exec_mapping); - node_type_gpu(&ntype, gpu_shader_mapping); + sh_node_type_base(&ntype, SH_NODE_MAPPING, "Mapping", NODE_CLASS_OP_VECTOR, 0); + node_type_socket_templates(&ntype, sh_node_mapping_in, sh_node_mapping_out); + node_type_size(&ntype, 320, 160, 360); + node_type_init(&ntype, node_shader_init_mapping); + node_type_storage(&ntype, "TexMapping", node_free_standard_storage, node_copy_standard_storage); + node_type_exec(&ntype, node_shader_initexec_mapping, NULL, node_shader_exec_mapping); + node_type_gpu(&ntype, gpu_shader_mapping); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_math.c b/source/blender/nodes/shader/nodes/node_shader_math.c index a0ecc0f16f1..6e104066a58 100644 --- a/source/blender/nodes/shader/nodes/node_shader_math.c +++ b/source/blender/nodes/shader/nodes/node_shader_math.c @@ -21,325 +21,318 @@ * \ingroup shdnodes */ - #include "node_shader_util.h" - /* **************** SCALAR MATH ******************** */ static bNodeSocketTemplate sh_node_math_in[] = { - { SOCK_FLOAT, 1, N_("Value"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("Value"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, - { -1, 0, "" } -}; + {SOCK_FLOAT, 1, N_("Value"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("Value"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, + {-1, 0, ""}}; -static bNodeSocketTemplate sh_node_math_out[] = { - { SOCK_FLOAT, 0, N_("Value")}, - { -1, 0, "" } -}; +static bNodeSocketTemplate sh_node_math_out[] = {{SOCK_FLOAT, 0, N_("Value")}, {-1, 0, ""}}; -static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) +static void node_shader_exec_math(void *UNUSED(data), + int UNUSED(thread), + bNode *node, + bNodeExecData *UNUSED(execdata), + bNodeStack **in, + bNodeStack **out) { - float a, b, r = 0.0f; + float a, b, r = 0.0f; - nodestack_get_vec(&a, SOCK_FLOAT, in[0]); - nodestack_get_vec(&b, SOCK_FLOAT, in[1]); + nodestack_get_vec(&a, SOCK_FLOAT, in[0]); + nodestack_get_vec(&b, SOCK_FLOAT, in[1]); - switch (node->custom1) { + switch (node->custom1) { - case NODE_MATH_ADD: - r = a + b; - break; - case NODE_MATH_SUB: - r = a - b; - break; - case NODE_MATH_MUL: - r = a * b; - break; - case NODE_MATH_DIVIDE: - { - if (b == 0) /* We don't want to divide by zero. */ - r = 0.0; - else - r = a / b; - break; - } - case NODE_MATH_SIN: - { - if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ - r = sinf(a); - else - r = sinf(b); - break; - } - case NODE_MATH_COS: - { - if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ - r = cosf(a); - else - r = cosf(b); - break; - } - case NODE_MATH_TAN: - { - if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ - r = tanf(a); - else - r = tanf(b); - break; - } - case NODE_MATH_ASIN: - { - if (in[0]->hasinput || !in[1]->hasinput) { /* This one only takes one input, so we've got to choose. */ - /* Can't do the impossible... */ - if (a <= 1 && a >= -1) - r = asinf(a); - else - r = 0.0; - } - else { - /* Can't do the impossible... */ - if (b <= 1 && b >= -1) - r = asinf(b); - else - r = 0.0; - } - break; - } - case NODE_MATH_ACOS: - { - if (in[0]->hasinput || !in[1]->hasinput) { /* This one only takes one input, so we've got to choose. */ - /* Can't do the impossible... */ - if (a <= 1 && a >= -1) - r = acosf(a); - else - r = 0.0; - } - else { - /* Can't do the impossible... */ - if (b <= 1 && b >= -1) - r = acosf(b); - else - r = 0.0; - } - break; - } - case NODE_MATH_ATAN: - { - if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ - r = atan(a); - else - r = atan(b); - break; - } - case NODE_MATH_POW: - { - /* Only raise negative numbers by full integers */ - if (a >= 0) { - r = pow(a, b); - } - else { - float y_mod_1 = fabsf(fmodf(b, 1.0f)); + case NODE_MATH_ADD: + r = a + b; + break; + case NODE_MATH_SUB: + r = a - b; + break; + case NODE_MATH_MUL: + r = a * b; + break; + case NODE_MATH_DIVIDE: { + if (b == 0) /* We don't want to divide by zero. */ + r = 0.0; + else + r = a / b; + break; + } + case NODE_MATH_SIN: { + if (in[0]->hasinput || + !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ + r = sinf(a); + else + r = sinf(b); + break; + } + case NODE_MATH_COS: { + if (in[0]->hasinput || + !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ + r = cosf(a); + else + r = cosf(b); + break; + } + case NODE_MATH_TAN: { + if (in[0]->hasinput || + !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ + r = tanf(a); + else + r = tanf(b); + break; + } + case NODE_MATH_ASIN: { + if (in[0]->hasinput || + !in[1]->hasinput) { /* This one only takes one input, so we've got to choose. */ + /* Can't do the impossible... */ + if (a <= 1 && a >= -1) + r = asinf(a); + else + r = 0.0; + } + else { + /* Can't do the impossible... */ + if (b <= 1 && b >= -1) + r = asinf(b); + else + r = 0.0; + } + break; + } + case NODE_MATH_ACOS: { + if (in[0]->hasinput || + !in[1]->hasinput) { /* This one only takes one input, so we've got to choose. */ + /* Can't do the impossible... */ + if (a <= 1 && a >= -1) + r = acosf(a); + else + r = 0.0; + } + else { + /* Can't do the impossible... */ + if (b <= 1 && b >= -1) + r = acosf(b); + else + r = 0.0; + } + break; + } + case NODE_MATH_ATAN: { + if (in[0]->hasinput || + !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ + r = atan(a); + else + r = atan(b); + break; + } + case NODE_MATH_POW: { + /* Only raise negative numbers by full integers */ + if (a >= 0) { + r = pow(a, b); + } + else { + float y_mod_1 = fabsf(fmodf(b, 1.0f)); - /* if input value is not nearly an integer, fall back to zero, nicer than straight rounding */ - if (y_mod_1 > 0.999f || y_mod_1 < 0.001f) { - r = powf(a, floorf(b + 0.5f)); - } - else { - r = 0.0f; - } - } + /* if input value is not nearly an integer, fall back to zero, nicer than straight rounding */ + if (y_mod_1 > 0.999f || y_mod_1 < 0.001f) { + r = powf(a, floorf(b + 0.5f)); + } + else { + r = 0.0f; + } + } - break; - } - case NODE_MATH_LOG: - { - /* Don't want any imaginary numbers... */ - if (a > 0 && b > 0) - r = log(a) / log(b); - else - r = 0.0; - break; - } - case NODE_MATH_MIN: - { - if (a < b) - r = a; - else - r = b; - break; - } - case NODE_MATH_MAX: - { - if (a > b) - r = a; - else - r = b; - break; - } - case NODE_MATH_ROUND: - { - if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ - r = (a < 0) ? (int)(a - 0.5f) : (int)(a + 0.5f); - else - r = (b < 0) ? (int)(b - 0.5f) : (int)(b + 0.5f); - break; - } - case NODE_MATH_LESS: - { - if (a < b) - r = 1.0f; - else - r = 0.0f; - break; - } - case NODE_MATH_GREATER: - { - if (a > b) - r = 1.0f; - else - r = 0.0f; - break; - } - case NODE_MATH_MOD: - { - if (b == 0.0f) - r = 0.0f; - else - r = fmod(a, b); - break; - } - case NODE_MATH_ABS: - { - r = fabsf(a); - break; - } - case NODE_MATH_ATAN2: - { - r = atan2(a, b); - break; - } - case NODE_MATH_FLOOR: - { - if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ - r = floorf(a); - else - r = floorf(b); - break; - } - case NODE_MATH_CEIL: - { - if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ - r = ceilf(a); - else - r = ceilf(b); - break; - } - case NODE_MATH_FRACT: - { - if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ - r = a - floorf(a); - else - r = b - floorf(b); - break; - } - case NODE_MATH_SQRT: - { - if (in[0]->hasinput || !in[1]->hasinput) { /* This one only takes one input, so we've got to choose. */ - if (a > 0) - r = sqrt(a); - else - r = 0.0; - } - else { - if (b > 0) - r = sqrt(b); - else - r = 0.0; - } - break; - } - } - if (node->custom2 & SHD_MATH_CLAMP) { - CLAMP(r, 0.0f, 1.0f); - } - out[0]->vec[0] = r; + break; + } + case NODE_MATH_LOG: { + /* Don't want any imaginary numbers... */ + if (a > 0 && b > 0) + r = log(a) / log(b); + else + r = 0.0; + break; + } + case NODE_MATH_MIN: { + if (a < b) + r = a; + else + r = b; + break; + } + case NODE_MATH_MAX: { + if (a > b) + r = a; + else + r = b; + break; + } + case NODE_MATH_ROUND: { + if (in[0]->hasinput || + !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ + r = (a < 0) ? (int)(a - 0.5f) : (int)(a + 0.5f); + else + r = (b < 0) ? (int)(b - 0.5f) : (int)(b + 0.5f); + break; + } + case NODE_MATH_LESS: { + if (a < b) + r = 1.0f; + else + r = 0.0f; + break; + } + case NODE_MATH_GREATER: { + if (a > b) + r = 1.0f; + else + r = 0.0f; + break; + } + case NODE_MATH_MOD: { + if (b == 0.0f) + r = 0.0f; + else + r = fmod(a, b); + break; + } + case NODE_MATH_ABS: { + r = fabsf(a); + break; + } + case NODE_MATH_ATAN2: { + r = atan2(a, b); + break; + } + case NODE_MATH_FLOOR: { + if (in[0]->hasinput || + !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ + r = floorf(a); + else + r = floorf(b); + break; + } + case NODE_MATH_CEIL: { + if (in[0]->hasinput || + !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ + r = ceilf(a); + else + r = ceilf(b); + break; + } + case NODE_MATH_FRACT: { + if (in[0]->hasinput || + !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ + r = a - floorf(a); + else + r = b - floorf(b); + break; + } + case NODE_MATH_SQRT: { + if (in[0]->hasinput || + !in[1]->hasinput) { /* This one only takes one input, so we've got to choose. */ + if (a > 0) + r = sqrt(a); + else + r = 0.0; + } + else { + if (b > 0) + r = sqrt(b); + else + r = 0.0; + } + break; + } + } + if (node->custom2 & SHD_MATH_CLAMP) { + CLAMP(r, 0.0f, 1.0f); + } + out[0]->vec[0] = r; } -static int gpu_shader_math(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_math(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - static const char *names[] = { - "math_add", "math_subtract", "math_multiply", - "math_divide", "math_sine", "math_cosine", "math_tangent", "math_asin", - "math_acos", "math_atan", "math_pow", "math_log", "math_min", "math_max", - "math_round", "math_less_than", "math_greater_than", "math_modulo", "math_abs", - "math_atan2", "math_floor", "math_ceil", "math_fract", "math_sqrt", - }; + static const char *names[] = { + "math_add", "math_subtract", "math_multiply", "math_divide", "math_sine", + "math_cosine", "math_tangent", "math_asin", "math_acos", "math_atan", + "math_pow", "math_log", "math_min", "math_max", "math_round", + "math_less_than", "math_greater_than", "math_modulo", "math_abs", "math_atan2", + "math_floor", "math_ceil", "math_fract", "math_sqrt", + }; - switch (node->custom1) { - case NODE_MATH_ADD: - case NODE_MATH_SUB: - case NODE_MATH_MUL: - case NODE_MATH_DIVIDE: - case NODE_MATH_POW: - case NODE_MATH_LOG: - case NODE_MATH_MIN: - case NODE_MATH_MAX: - case NODE_MATH_LESS: - case NODE_MATH_GREATER: - case NODE_MATH_MOD: - case NODE_MATH_ATAN2: - GPU_stack_link(mat, node, names[node->custom1], in, out); - break; - case NODE_MATH_SIN: - case NODE_MATH_COS: - case NODE_MATH_TAN: - case NODE_MATH_ASIN: - case NODE_MATH_ACOS: - case NODE_MATH_ATAN: - case NODE_MATH_ROUND: - case NODE_MATH_ABS: - case NODE_MATH_FLOOR: - case NODE_MATH_FRACT: - case NODE_MATH_CEIL: - case NODE_MATH_SQRT: - if (in[0].hasinput || !in[1].hasinput) { - /* use only first item and terminator */ - GPUNodeStack tmp_in[2]; - memcpy(&tmp_in[0], &in[0], sizeof(GPUNodeStack)); - memcpy(&tmp_in[1], &in[2], sizeof(GPUNodeStack)); - GPU_stack_link(mat, node, names[node->custom1], tmp_in, out); - } - else { - /* use only second item and terminator */ - GPUNodeStack tmp_in[2]; - memcpy(&tmp_in[0], &in[1], sizeof(GPUNodeStack)); - memcpy(&tmp_in[1], &in[2], sizeof(GPUNodeStack)); - GPU_stack_link(mat, node, names[node->custom1], tmp_in, out); - } - break; - default: - return 0; - } + switch (node->custom1) { + case NODE_MATH_ADD: + case NODE_MATH_SUB: + case NODE_MATH_MUL: + case NODE_MATH_DIVIDE: + case NODE_MATH_POW: + case NODE_MATH_LOG: + case NODE_MATH_MIN: + case NODE_MATH_MAX: + case NODE_MATH_LESS: + case NODE_MATH_GREATER: + case NODE_MATH_MOD: + case NODE_MATH_ATAN2: + GPU_stack_link(mat, node, names[node->custom1], in, out); + break; + case NODE_MATH_SIN: + case NODE_MATH_COS: + case NODE_MATH_TAN: + case NODE_MATH_ASIN: + case NODE_MATH_ACOS: + case NODE_MATH_ATAN: + case NODE_MATH_ROUND: + case NODE_MATH_ABS: + case NODE_MATH_FLOOR: + case NODE_MATH_FRACT: + case NODE_MATH_CEIL: + case NODE_MATH_SQRT: + if (in[0].hasinput || !in[1].hasinput) { + /* use only first item and terminator */ + GPUNodeStack tmp_in[2]; + memcpy(&tmp_in[0], &in[0], sizeof(GPUNodeStack)); + memcpy(&tmp_in[1], &in[2], sizeof(GPUNodeStack)); + GPU_stack_link(mat, node, names[node->custom1], tmp_in, out); + } + else { + /* use only second item and terminator */ + GPUNodeStack tmp_in[2]; + memcpy(&tmp_in[0], &in[1], sizeof(GPUNodeStack)); + memcpy(&tmp_in[1], &in[2], sizeof(GPUNodeStack)); + GPU_stack_link(mat, node, names[node->custom1], tmp_in, out); + } + break; + default: + return 0; + } - if (node->custom2 & SHD_MATH_CLAMP) { - float min[3] = {0.0f, 0.0f, 0.0f}; - float max[3] = {1.0f, 1.0f, 1.0f}; - GPU_link(mat, "clamp_val", out[0].link, GPU_constant(min), GPU_constant(max), &out[0].link); - } + if (node->custom2 & SHD_MATH_CLAMP) { + float min[3] = {0.0f, 0.0f, 0.0f}; + float max[3] = {1.0f, 1.0f, 1.0f}; + GPU_link(mat, "clamp_val", out[0].link, GPU_constant(min), GPU_constant(max), &out[0].link); + } - return 1; + return 1; } void register_node_type_sh_math(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_MATH, "Math", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, sh_node_math_in, sh_node_math_out); - node_type_label(&ntype, node_math_label); - node_type_storage(&ntype, "", NULL, NULL); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_math); - node_type_gpu(&ntype, gpu_shader_math); + sh_node_type_base(&ntype, SH_NODE_MATH, "Math", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, sh_node_math_in, sh_node_math_out); + node_type_label(&ntype, node_math_label); + node_type_storage(&ntype, "", NULL, NULL); + node_type_exec(&ntype, NULL, NULL, node_shader_exec_math); + node_type_gpu(&ntype, gpu_shader_math); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_mixRgb.c b/source/blender/nodes/shader/nodes/node_shader_mixRgb.c index 24432132a5b..872f4f9da9c 100644 --- a/source/blender/nodes/shader/nodes/node_shader_mixRgb.c +++ b/source/blender/nodes/shader/nodes/node_shader_mixRgb.c @@ -21,70 +21,91 @@ * \ingroup shdnodes */ - #include "node_shader_util.h" /* **************** MIX RGB ******************** */ static bNodeSocketTemplate sh_node_mix_rgb_in[] = { - { SOCK_FLOAT, 1, N_("Fac"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_RGBA, 1, N_("Color1"), 0.5f, 0.5f, 0.5f, 1.0f}, - { SOCK_RGBA, 1, N_("Color2"), 0.5f, 0.5f, 0.5f, 1.0f}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Fac"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_RGBA, 1, N_("Color1"), 0.5f, 0.5f, 0.5f, 1.0f}, + {SOCK_RGBA, 1, N_("Color2"), 0.5f, 0.5f, 0.5f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_mix_rgb_out[] = { - { SOCK_RGBA, 0, N_("Color")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color")}, + {-1, 0, ""}, }; -static void node_shader_exec_mix_rgb(void *UNUSED(data), int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) +static void node_shader_exec_mix_rgb(void *UNUSED(data), + int UNUSED(thread), + bNode *node, + bNodeExecData *UNUSED(execdata), + bNodeStack **in, + bNodeStack **out) { - /* stack order in: fac, col1, col2 */ - /* stack order out: col */ - float col[3]; - float fac; - float vec[3]; + /* stack order in: fac, col1, col2 */ + /* stack order out: col */ + float col[3]; + float fac; + float vec[3]; - nodestack_get_vec(&fac, SOCK_FLOAT, in[0]); - CLAMP(fac, 0.0f, 1.0f); + nodestack_get_vec(&fac, SOCK_FLOAT, in[0]); + CLAMP(fac, 0.0f, 1.0f); - nodestack_get_vec(col, SOCK_VECTOR, in[1]); - nodestack_get_vec(vec, SOCK_VECTOR, in[2]); + nodestack_get_vec(col, SOCK_VECTOR, in[1]); + nodestack_get_vec(vec, SOCK_VECTOR, in[2]); - ramp_blend(node->custom1, col, fac, vec); - if (node->custom2 & SHD_MIXRGB_CLAMP) { - CLAMP3(col, 0.0f, 1.0f); - } - copy_v3_v3(out[0]->vec, col); + ramp_blend(node->custom1, col, fac, vec); + if (node->custom2 & SHD_MIXRGB_CLAMP) { + CLAMP3(col, 0.0f, 1.0f); + } + copy_v3_v3(out[0]->vec, col); } -static int gpu_shader_mix_rgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_mix_rgb(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - static const char *names[] = { - "mix_blend", "mix_add", "mix_mult", "mix_sub", - "mix_screen", "mix_div", "mix_diff", "mix_dark", "mix_light", - "mix_overlay", "mix_dodge", "mix_burn", "mix_hue", "mix_sat", - "mix_val", "mix_color", "mix_soft", "mix_linear", - }; + static const char *names[] = { + "mix_blend", + "mix_add", + "mix_mult", + "mix_sub", + "mix_screen", + "mix_div", + "mix_diff", + "mix_dark", + "mix_light", + "mix_overlay", + "mix_dodge", + "mix_burn", + "mix_hue", + "mix_sat", + "mix_val", + "mix_color", + "mix_soft", + "mix_linear", + }; - int ret = GPU_stack_link(mat, node, names[node->custom1], in, out); - if (ret && node->custom2 & SHD_MIXRGB_CLAMP) { - float min[3] = {0.0f, 0.0f, 0.0f}; - float max[3] = {1.0f, 1.0f, 1.0f}; - GPU_link(mat, "clamp_vec3", out[0].link, GPU_constant(min), GPU_constant(max), &out[0].link); - } - return ret; + int ret = GPU_stack_link(mat, node, names[node->custom1], in, out); + if (ret && node->custom2 & SHD_MIXRGB_CLAMP) { + float min[3] = {0.0f, 0.0f, 0.0f}; + float max[3] = {1.0f, 1.0f, 1.0f}; + GPU_link(mat, "clamp_vec3", out[0].link, GPU_constant(min), GPU_constant(max), &out[0].link); + } + return ret; } - void register_node_type_sh_mix_rgb(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, sh_node_mix_rgb_in, sh_node_mix_rgb_out); - node_type_label(&ntype, node_blend_label); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_mix_rgb); - node_type_gpu(&ntype, gpu_shader_mix_rgb); + sh_node_type_base(&ntype, SH_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, 0); + node_type_socket_templates(&ntype, sh_node_mix_rgb_in, sh_node_mix_rgb_out); + node_type_label(&ntype, node_blend_label); + node_type_exec(&ntype, NULL, NULL, node_shader_exec_mix_rgb); + node_type_gpu(&ntype, gpu_shader_mix_rgb); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_mix_shader.c b/source/blender/nodes/shader/nodes/node_shader_mix_shader.c index 345680a5b76..31440f76c98 100644 --- a/source/blender/nodes/shader/nodes/node_shader_mix_shader.c +++ b/source/blender/nodes/shader/nodes/node_shader_mix_shader.c @@ -22,32 +22,36 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_mix_shader_in[] = { - { SOCK_FLOAT, 1, N_("Fac"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_SHADER, 1, N_("Shader")}, - { SOCK_SHADER, 1, N_("Shader")}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Fac"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_SHADER, 1, N_("Shader")}, + {SOCK_SHADER, 1, N_("Shader")}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_mix_shader_out[] = { - { SOCK_SHADER, 0, N_("Shader")}, - { -1, 0, "" }, + {SOCK_SHADER, 0, N_("Shader")}, + {-1, 0, ""}, }; -static int node_shader_gpu_mix_shader(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_mix_shader(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "node_mix_shader", in, out); + return GPU_stack_link(mat, node, "node_mix_shader", in, out); } /* node type definition */ void register_node_type_sh_mix_shader(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_MIX_SHADER, "Mix Shader", NODE_CLASS_SHADER, 0); - node_type_socket_templates(&ntype, sh_node_mix_shader_in, sh_node_mix_shader_out); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_mix_shader); + sh_node_type_base(&ntype, SH_NODE_MIX_SHADER, "Mix Shader", NODE_CLASS_SHADER, 0); + node_type_socket_templates(&ntype, sh_node_mix_shader_in, sh_node_mix_shader_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_mix_shader); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_normal.c b/source/blender/nodes/shader/nodes/node_shader_normal.c index 63cbabd4556..074cc3dd87f 100644 --- a/source/blender/nodes/shader/nodes/node_shader_normal.c +++ b/source/blender/nodes/shader/nodes/node_shader_normal.c @@ -21,49 +21,57 @@ * \ingroup shdnodes */ - #include "node_shader_util.h" /* **************** NORMAL ******************** */ static bNodeSocketTemplate sh_node_normal_in[] = { - { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_DIRECTION}, - { -1, 0, "" }, + {SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_DIRECTION}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_normal_out[] = { - { SOCK_VECTOR, 0, N_("Normal"), 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f, PROP_DIRECTION}, - { SOCK_FLOAT, 0, N_("Dot")}, - { -1, 0, "" }, + {SOCK_VECTOR, 0, N_("Normal"), 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f, PROP_DIRECTION}, + {SOCK_FLOAT, 0, N_("Dot")}, + {-1, 0, ""}, }; /* generates normal, does dot product */ -static void node_shader_exec_normal(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) +static void node_shader_exec_normal(void *UNUSED(data), + int UNUSED(thread), + bNode *UNUSED(node), + bNodeExecData *UNUSED(execdata), + bNodeStack **in, + bNodeStack **out) { - float vec[3]; + float vec[3]; - /* stack order input: normal */ - /* stack order output: normal, value */ + /* stack order input: normal */ + /* stack order output: normal, value */ - nodestack_get_vec(vec, SOCK_VECTOR, in[0]); + nodestack_get_vec(vec, SOCK_VECTOR, in[0]); - /* render normals point inside... the widget points outside */ - out[1]->vec[0] = -dot_v3v3(vec, out[0]->vec); + /* render normals point inside... the widget points outside */ + out[1]->vec[0] = -dot_v3v3(vec, out[0]->vec); } -static int gpu_shader_normal(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_normal(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - GPUNodeLink *vec = GPU_uniform(out[0].vec); - return GPU_stack_link(mat, node, "normal_new_shading", in, out, vec); + GPUNodeLink *vec = GPU_uniform(out[0].vec); + return GPU_stack_link(mat, node, "normal_new_shading", in, out, vec); } void register_node_type_sh_normal(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_NORMAL, "Normal", NODE_CLASS_OP_VECTOR, 0); - node_type_socket_templates(&ntype, sh_node_normal_in, sh_node_normal_out); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_normal); - node_type_gpu(&ntype, gpu_shader_normal); + sh_node_type_base(&ntype, SH_NODE_NORMAL, "Normal", NODE_CLASS_OP_VECTOR, 0); + node_type_socket_templates(&ntype, sh_node_normal_in, sh_node_normal_out); + node_type_exec(&ntype, NULL, NULL, node_shader_exec_normal); + node_type_gpu(&ntype, gpu_shader_normal); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_normal_map.c b/source/blender/nodes/shader/nodes/node_shader_normal_map.c index 7eb5d2b716c..fcc64707642 100644 --- a/source/blender/nodes/shader/nodes/node_shader_normal_map.c +++ b/source/blender/nodes/shader/nodes/node_shader_normal_map.c @@ -22,103 +22,131 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_normal_map_in[] = { - { SOCK_FLOAT, 1, N_("Strength"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 10.0f}, - { SOCK_RGBA, 1, N_("Color"), 0.5f, 0.5f, 1.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Strength"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 10.0f}, + {SOCK_RGBA, 1, N_("Color"), 0.5f, 0.5f, 1.0f, 1.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_normal_map_out[] = { - { SOCK_VECTOR, 0, N_("Normal"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_VECTOR, 0, N_("Normal"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; static void node_shader_init_normal_map(bNodeTree *UNUSED(ntree), bNode *node) { - NodeShaderNormalMap *attr = MEM_callocN(sizeof(NodeShaderNormalMap), "NodeShaderNormalMap"); - node->storage = attr; + NodeShaderNormalMap *attr = MEM_callocN(sizeof(NodeShaderNormalMap), "NodeShaderNormalMap"); + node->storage = attr; } -static void node_shader_exec_normal_map( - void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), - bNodeStack **UNUSED(in), bNodeStack **UNUSED(out)) +static void node_shader_exec_normal_map(void *UNUSED(data), + int UNUSED(thread), + bNode *UNUSED(node), + bNodeExecData *UNUSED(execdata), + bNodeStack **UNUSED(in), + bNodeStack **UNUSED(out)) { } -static int gpu_shader_normal_map(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_normal_map(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - NodeShaderNormalMap *nm = node->storage; - GPUNodeLink *negnorm; - GPUNodeLink *realnorm; - GPUNodeLink *strength; - - float d[4] = {0, 0, 0, 0}; - - if (in[0].link) - strength = in[0].link; - else if (node->original) { - bNodeSocket *socket = BLI_findlink(&node->original->inputs, 0); - bNodeSocketValueFloat *socket_data = socket->default_value; - strength = GPU_uniform(&socket_data->value); - } - else - strength = GPU_constant(in[0].vec); - - if (in[1].link) - realnorm = in[1].link; - else if (node->original) { - bNodeSocket *socket = BLI_findlink(&node->original->inputs, 1); - bNodeSocketValueRGBA *socket_data = socket->default_value; - realnorm = GPU_uniform(socket_data->value); - } - else - realnorm = GPU_constant(in[1].vec); - - negnorm = GPU_builtin(GPU_VIEW_NORMAL); - GPU_link(mat, "math_max", strength, GPU_constant(d), &strength); - - const char *color_to_normal_fnc_name = "color_to_normal_new_shading"; - if (nm->space == SHD_SPACE_BLENDER_OBJECT || nm->space == SHD_SPACE_BLENDER_WORLD) - color_to_normal_fnc_name = "color_to_blender_normal_new_shading"; - switch (nm->space) { - case SHD_SPACE_TANGENT: - GPU_link(mat, "color_to_normal_new_shading", realnorm, &realnorm); - GPU_link(mat, "node_normal_map", GPU_builtin(GPU_OBJECT_INFO), GPU_attribute(CD_TANGENT, nm->uv_map), negnorm, realnorm, &realnorm); - GPU_link(mat, "vec_math_mix", strength, realnorm, GPU_builtin(GPU_VIEW_NORMAL), &out[0].link); - /* for uniform scale this is sufficient to match Cycles */ - GPU_link(mat, "direction_transform_m4v3", out[0].link, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &out[0].link); - GPU_link(mat, "vect_normalize", out[0].link, &out[0].link); - return true; - case SHD_SPACE_OBJECT: - case SHD_SPACE_BLENDER_OBJECT: - GPU_link(mat, "direction_transform_m4v3", negnorm, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &negnorm); - GPU_link(mat, color_to_normal_fnc_name, realnorm, &realnorm); - GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_OBJECT_MATRIX), &realnorm); - break; - case SHD_SPACE_WORLD: - case SHD_SPACE_BLENDER_WORLD: - GPU_link(mat, "direction_transform_m4v3", negnorm, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &negnorm); - GPU_link(mat, color_to_normal_fnc_name, realnorm, &realnorm); - break; - } - - GPU_link(mat, "vec_math_mix", strength, realnorm, negnorm, &out[0].link); - GPU_link(mat, "vect_normalize", out[0].link, &out[0].link); - - return true; + NodeShaderNormalMap *nm = node->storage; + GPUNodeLink *negnorm; + GPUNodeLink *realnorm; + GPUNodeLink *strength; + + float d[4] = {0, 0, 0, 0}; + + if (in[0].link) + strength = in[0].link; + else if (node->original) { + bNodeSocket *socket = BLI_findlink(&node->original->inputs, 0); + bNodeSocketValueFloat *socket_data = socket->default_value; + strength = GPU_uniform(&socket_data->value); + } + else + strength = GPU_constant(in[0].vec); + + if (in[1].link) + realnorm = in[1].link; + else if (node->original) { + bNodeSocket *socket = BLI_findlink(&node->original->inputs, 1); + bNodeSocketValueRGBA *socket_data = socket->default_value; + realnorm = GPU_uniform(socket_data->value); + } + else + realnorm = GPU_constant(in[1].vec); + + negnorm = GPU_builtin(GPU_VIEW_NORMAL); + GPU_link(mat, "math_max", strength, GPU_constant(d), &strength); + + const char *color_to_normal_fnc_name = "color_to_normal_new_shading"; + if (nm->space == SHD_SPACE_BLENDER_OBJECT || nm->space == SHD_SPACE_BLENDER_WORLD) + color_to_normal_fnc_name = "color_to_blender_normal_new_shading"; + switch (nm->space) { + case SHD_SPACE_TANGENT: + GPU_link(mat, "color_to_normal_new_shading", realnorm, &realnorm); + GPU_link(mat, + "node_normal_map", + GPU_builtin(GPU_OBJECT_INFO), + GPU_attribute(CD_TANGENT, nm->uv_map), + negnorm, + realnorm, + &realnorm); + GPU_link( + mat, "vec_math_mix", strength, realnorm, GPU_builtin(GPU_VIEW_NORMAL), &out[0].link); + /* for uniform scale this is sufficient to match Cycles */ + GPU_link(mat, + "direction_transform_m4v3", + out[0].link, + GPU_builtin(GPU_INVERSE_VIEW_MATRIX), + &out[0].link); + GPU_link(mat, "vect_normalize", out[0].link, &out[0].link); + return true; + case SHD_SPACE_OBJECT: + case SHD_SPACE_BLENDER_OBJECT: + GPU_link(mat, + "direction_transform_m4v3", + negnorm, + GPU_builtin(GPU_INVERSE_VIEW_MATRIX), + &negnorm); + GPU_link(mat, color_to_normal_fnc_name, realnorm, &realnorm); + GPU_link( + mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_OBJECT_MATRIX), &realnorm); + break; + case SHD_SPACE_WORLD: + case SHD_SPACE_BLENDER_WORLD: + GPU_link(mat, + "direction_transform_m4v3", + negnorm, + GPU_builtin(GPU_INVERSE_VIEW_MATRIX), + &negnorm); + GPU_link(mat, color_to_normal_fnc_name, realnorm, &realnorm); + break; + } + + GPU_link(mat, "vec_math_mix", strength, realnorm, negnorm, &out[0].link); + GPU_link(mat, "vect_normalize", out[0].link, &out[0].link); + + return true; } /* node type definition */ void register_node_type_sh_normal_map(void) { - static bNodeType ntype; - - sh_node_type_base(&ntype, SH_NODE_NORMAL_MAP, "Normal Map", NODE_CLASS_OP_VECTOR, 0); - node_type_socket_templates(&ntype, sh_node_normal_map_in, sh_node_normal_map_out); - node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); - node_type_init(&ntype, node_shader_init_normal_map); - node_type_storage(&ntype, "NodeShaderNormalMap", node_free_standard_storage, node_copy_standard_storage); - node_type_gpu(&ntype, gpu_shader_normal_map); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_normal_map); - - nodeRegisterType(&ntype); + static bNodeType ntype; + + sh_node_type_base(&ntype, SH_NODE_NORMAL_MAP, "Normal Map", NODE_CLASS_OP_VECTOR, 0); + node_type_socket_templates(&ntype, sh_node_normal_map_in, sh_node_normal_map_out); + node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); + node_type_init(&ntype, node_shader_init_normal_map); + node_type_storage( + &ntype, "NodeShaderNormalMap", node_free_standard_storage, node_copy_standard_storage); + node_type_gpu(&ntype, gpu_shader_normal_map); + node_type_exec(&ntype, NULL, NULL, node_shader_exec_normal_map); + + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_object_info.c b/source/blender/nodes/shader/nodes/node_shader_object_info.c index fe3015e689f..5520f6f325f 100644 --- a/source/blender/nodes/shader/nodes/node_shader_object_info.c +++ b/source/blender/nodes/shader/nodes/node_shader_object_info.c @@ -22,33 +22,48 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_object_info_out[] = { - { SOCK_VECTOR, 0, N_("Location"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Object Index"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Material Index"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Random"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_VECTOR, 0, N_("Location"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Object Index"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Material Index"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Random"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; -static int node_shader_gpu_object_info(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_object_info(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "node_object_info", in, out, GPU_builtin(GPU_OBJECT_MATRIX), GPU_builtin(GPU_OBJECT_INFO)); + return GPU_stack_link(mat, + node, + "node_object_info", + in, + out, + GPU_builtin(GPU_OBJECT_MATRIX), + GPU_builtin(GPU_OBJECT_INFO)); } -static void node_shader_exec_object_info(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out)) +static void node_shader_exec_object_info(void *UNUSED(data), + int UNUSED(thread), + bNode *UNUSED(node), + bNodeExecData *UNUSED(execdata), + bNodeStack **UNUSED(in), + bNodeStack **UNUSED(out)) { } /* node type definition */ void register_node_type_sh_object_info(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_OBJECT_INFO, "Object Info", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, NULL, sh_node_object_info_out); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_object_info); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_object_info); + sh_node_type_base(&ntype, SH_NODE_OBJECT_INFO, "Object Info", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, NULL, sh_node_object_info_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_object_info); + node_type_exec(&ntype, NULL, NULL, node_shader_exec_object_info); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_output_light.c b/source/blender/nodes/shader/nodes/node_shader_output_light.c index e9afefe5ea1..8fc5123ce49 100644 --- a/source/blender/nodes/shader/nodes/node_shader_output_light.c +++ b/source/blender/nodes/shader/nodes/node_shader_output_light.c @@ -22,22 +22,22 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_output_light_in[] = { - { SOCK_SHADER, 1, N_("Surface"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_SHADER, 1, N_("Surface"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; /* node type definition */ void register_node_type_sh_output_light(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_OUTPUT_LIGHT, "Light Output", NODE_CLASS_OUTPUT, 0); - node_type_socket_templates(&ntype, sh_node_output_light_in, NULL); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); + sh_node_type_base(&ntype, SH_NODE_OUTPUT_LIGHT, "Light Output", NODE_CLASS_OUTPUT, 0); + node_type_socket_templates(&ntype, sh_node_output_light_in, NULL); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); - /* Do not allow muting output node. */ - node_type_internal_links(&ntype, NULL); + /* Do not allow muting output node. */ + node_type_internal_links(&ntype, NULL); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_output_linestyle.c b/source/blender/nodes/shader/nodes/node_shader_output_linestyle.c index e1c03c53679..bf6e562a92a 100644 --- a/source/blender/nodes/shader/nodes/node_shader_output_linestyle.c +++ b/source/blender/nodes/shader/nodes/node_shader_output_linestyle.c @@ -22,24 +22,24 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_output_linestyle_in[] = { - { SOCK_RGBA, 1, N_("Color"), 1.0f, 0.0f, 1.0f, 1.0f }, - { SOCK_FLOAT, 1, N_("Color Fac"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR }, - { SOCK_FLOAT, 1, N_("Alpha"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR }, - { SOCK_FLOAT, 1, N_("Alpha Fac"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR }, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 1.0f, 0.0f, 1.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Color Fac"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Alpha"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Alpha Fac"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {-1, 0, ""}, }; /* node type definition */ void register_node_type_sh_output_linestyle(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_OUTPUT_LINESTYLE, "Line Style Output", NODE_CLASS_OUTPUT, 0); - node_type_socket_templates(&ntype, sh_node_output_linestyle_in, NULL); - node_type_init(&ntype, NULL); + sh_node_type_base(&ntype, SH_NODE_OUTPUT_LINESTYLE, "Line Style Output", NODE_CLASS_OUTPUT, 0); + node_type_socket_templates(&ntype, sh_node_output_linestyle_in, NULL); + node_type_init(&ntype, NULL); - /* Do not allow muting output node. */ - node_type_internal_links(&ntype, NULL); + /* Do not allow muting output node. */ + node_type_internal_links(&ntype, NULL); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_output_material.c b/source/blender/nodes/shader/nodes/node_shader_output_material.c index 3f6cb0d8704..b813db00b2a 100644 --- a/source/blender/nodes/shader/nodes/node_shader_output_material.c +++ b/source/blender/nodes/shader/nodes/node_shader_output_material.c @@ -24,36 +24,49 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_output_material_in[] = { - { SOCK_SHADER, 1, N_("Surface")}, - { SOCK_SHADER, 1, N_("Volume")}, - { SOCK_VECTOR, 1, N_("Displacement"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { -1, 0, "" }, + {SOCK_SHADER, 1, N_("Surface")}, + {SOCK_SHADER, 1, N_("Volume")}, + {SOCK_VECTOR, + 1, + N_("Displacement"), + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {-1, 0, ""}, }; -static int node_shader_gpu_output_material(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_output_material(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - GPUNodeLink *outlink; + GPUNodeLink *outlink; - GPU_stack_link(mat, node, "node_output_material", in, out, &outlink); - GPU_material_output_link(mat, outlink); + GPU_stack_link(mat, node, "node_output_material", in, out, &outlink); + GPU_material_output_link(mat, outlink); - return true; + return true; } - /* node type definition */ void register_node_type_sh_output_material(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_OUTPUT_MATERIAL, "Material Output", NODE_CLASS_OUTPUT, 0); - node_type_socket_templates(&ntype, sh_node_output_material_in, NULL); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_output_material); + sh_node_type_base(&ntype, SH_NODE_OUTPUT_MATERIAL, "Material Output", NODE_CLASS_OUTPUT, 0); + node_type_socket_templates(&ntype, sh_node_output_material_in, NULL); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_output_material); - /* Do not allow muting output node. */ - node_type_internal_links(&ntype, NULL); + /* Do not allow muting output node. */ + node_type_internal_links(&ntype, NULL); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_output_world.c b/source/blender/nodes/shader/nodes/node_shader_output_world.c index 84f52860b5f..c54909308ac 100644 --- a/source/blender/nodes/shader/nodes/node_shader_output_world.c +++ b/source/blender/nodes/shader/nodes/node_shader_output_world.c @@ -22,34 +22,38 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_output_world_in[] = { - { SOCK_SHADER, 1, N_("Surface"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_SHADER, 1, N_("Volume"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_SHADER, 1, N_("Surface"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_SHADER, 1, N_("Volume"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; -static int node_shader_gpu_output_world(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_output_world(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - GPUNodeLink *outlink; + GPUNodeLink *outlink; - GPU_stack_link(mat, node, "node_output_world", in, out, &outlink); - GPU_material_output_link(mat, outlink); + GPU_stack_link(mat, node, "node_output_world", in, out, &outlink); + GPU_material_output_link(mat, outlink); - return true; + return true; } /* node type definition */ void register_node_type_sh_output_world(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_OUTPUT_WORLD, "World Output", NODE_CLASS_OUTPUT, 0); - node_type_socket_templates(&ntype, sh_node_output_world_in, NULL); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_output_world); + sh_node_type_base(&ntype, SH_NODE_OUTPUT_WORLD, "World Output", NODE_CLASS_OUTPUT, 0); + node_type_socket_templates(&ntype, sh_node_output_world_in, NULL); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_output_world); - /* Do not allow muting output node. */ - node_type_internal_links(&ntype, NULL); + /* Do not allow muting output node. */ + node_type_internal_links(&ntype, NULL); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_particle_info.c b/source/blender/nodes/shader/nodes/node_shader_particle_info.c index f14d46a7d1c..2b5c991161d 100644 --- a/source/blender/nodes/shader/nodes/node_shader_particle_info.c +++ b/source/blender/nodes/shader/nodes/node_shader_particle_info.c @@ -21,42 +21,55 @@ #include "RE_shader_ext.h" static bNodeSocketTemplate outputs[] = { - { SOCK_FLOAT, 0, "Index" }, - { SOCK_FLOAT, 0, "Random" }, - { SOCK_FLOAT, 0, "Age" }, - { SOCK_FLOAT, 0, "Lifetime" }, - { SOCK_VECTOR, 0, "Location" }, -#if 0 /* quaternion sockets not yet supported */ - { SOCK_QUATERNION, 0, "Rotation" }, + {SOCK_FLOAT, 0, "Index"}, + {SOCK_FLOAT, 0, "Random"}, + {SOCK_FLOAT, 0, "Age"}, + {SOCK_FLOAT, 0, "Lifetime"}, + {SOCK_VECTOR, 0, "Location"}, +#if 0 /* quaternion sockets not yet supported */ + { SOCK_QUATERNION, 0, "Rotation" }, #endif - { SOCK_FLOAT, 0, "Size" }, - { SOCK_VECTOR, 0, "Velocity" }, - { SOCK_VECTOR, 0, "Angular Velocity" }, - { -1, 0, "" }, + {SOCK_FLOAT, 0, "Size"}, + {SOCK_VECTOR, 0, "Velocity"}, + {SOCK_VECTOR, 0, "Angular Velocity"}, + {-1, 0, ""}, }; -static void node_shader_exec_particle_info(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out)) +static void node_shader_exec_particle_info(void *UNUSED(data), + int UNUSED(thread), + bNode *UNUSED(node), + bNodeExecData *UNUSED(execdata), + bNodeStack **UNUSED(in), + bNodeStack **UNUSED(out)) { } -static int gpu_shader_particle_info(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_particle_info(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "particle_info", in, out, - GPU_builtin(GPU_PARTICLE_SCALAR_PROPS), - GPU_builtin(GPU_PARTICLE_LOCATION), - GPU_builtin(GPU_PARTICLE_VELOCITY), - GPU_builtin(GPU_PARTICLE_ANG_VELOCITY)); + return GPU_stack_link(mat, + node, + "particle_info", + in, + out, + GPU_builtin(GPU_PARTICLE_SCALAR_PROPS), + GPU_builtin(GPU_PARTICLE_LOCATION), + GPU_builtin(GPU_PARTICLE_VELOCITY), + GPU_builtin(GPU_PARTICLE_ANG_VELOCITY)); } /* node type definition */ void register_node_type_sh_particle_info(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_PARTICLE_INFO, "Particle Info", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, NULL, outputs); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_particle_info); - node_type_gpu(&ntype, gpu_shader_particle_info); + sh_node_type_base(&ntype, SH_NODE_PARTICLE_INFO, "Particle Info", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, NULL, outputs); + node_type_exec(&ntype, NULL, NULL, node_shader_exec_particle_info); + node_type_gpu(&ntype, gpu_shader_particle_info); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_rgb.c b/source/blender/nodes/shader/nodes/node_shader_rgb.c index 6d53963cef7..a7ae2742a94 100644 --- a/source/blender/nodes/shader/nodes/node_shader_rgb.c +++ b/source/blender/nodes/shader/nodes/node_shader_rgb.c @@ -21,28 +21,31 @@ * \ingroup shdnodes */ - #include "node_shader_util.h" /* **************** RGB ******************** */ static bNodeSocketTemplate sh_node_rgb_out[] = { - { SOCK_RGBA, 0, N_("Color"), 0.5f, 0.5f, 0.5f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color"), 0.5f, 0.5f, 0.5f, 1.0f}, + {-1, 0, ""}, }; -static int gpu_shader_rgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_rgb(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - GPUNodeLink *link = GPU_uniformbuffer_link_out(mat, node, out, 0); - return GPU_stack_link(mat, node, "set_rgba", in, out, link); + GPUNodeLink *link = GPU_uniformbuffer_link_out(mat, node, out, 0); + return GPU_stack_link(mat, node, "set_rgba", in, out, link); } void register_node_type_sh_rgb(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_RGB, "RGB", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, NULL, sh_node_rgb_out); - node_type_gpu(&ntype, gpu_shader_rgb); + sh_node_type_base(&ntype, SH_NODE_RGB, "RGB", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, NULL, sh_node_rgb_out); + node_type_gpu(&ntype, gpu_shader_rgb); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_script.c b/source/blender/nodes/shader/nodes/node_shader_script.c index 79f140e0687..088272bbfb4 100644 --- a/source/blender/nodes/shader/nodes/node_shader_script.c +++ b/source/blender/nodes/shader/nodes/node_shader_script.c @@ -27,41 +27,41 @@ static void init(bNodeTree *UNUSED(ntree), bNode *node) { - NodeShaderScript *nss = MEM_callocN(sizeof(NodeShaderScript), "shader script node"); - node->storage = nss; + NodeShaderScript *nss = MEM_callocN(sizeof(NodeShaderScript), "shader script node"); + node->storage = nss; } static void node_free_script(bNode *node) { - NodeShaderScript *nss = node->storage; + NodeShaderScript *nss = node->storage; - if (nss) { - if (nss->bytecode) { - MEM_freeN(nss->bytecode); - } + if (nss) { + if (nss->bytecode) { + MEM_freeN(nss->bytecode); + } - MEM_freeN(nss); - } + MEM_freeN(nss); + } } static void node_copy_script(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, bNode *src_node) { - NodeShaderScript *src_nss = src_node->storage; - NodeShaderScript *dest_nss = MEM_dupallocN(src_nss); + NodeShaderScript *src_nss = src_node->storage; + NodeShaderScript *dest_nss = MEM_dupallocN(src_nss); - if (src_nss->bytecode) - dest_nss->bytecode = MEM_dupallocN(src_nss->bytecode); + if (src_nss->bytecode) + dest_nss->bytecode = MEM_dupallocN(src_nss->bytecode); - dest_node->storage = dest_nss; + dest_node->storage = dest_nss; } void register_node_type_sh_script(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_SCRIPT, "Script", NODE_CLASS_SCRIPT, 0); - node_type_init(&ntype, init); - node_type_storage(&ntype, "NodeShaderScript", node_free_script, node_copy_script); + sh_node_type_base(&ntype, SH_NODE_SCRIPT, "Script", NODE_CLASS_SCRIPT, 0); + node_type_init(&ntype, init); + node_type_storage(&ntype, "NodeShaderScript", node_free_script, node_copy_script); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c b/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c index f3d6311a764..fe9bbf3ddff 100644 --- a/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c +++ b/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c @@ -21,83 +21,98 @@ * \ingroup shdnodes */ - #include "node_shader_util.h" /* **************** SEPARATE HSV ******************** */ static bNodeSocketTemplate sh_node_sephsv_in[] = { - { SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_sephsv_out[] = { - { SOCK_FLOAT, 0, N_("H")}, - { SOCK_FLOAT, 0, N_("S")}, - { SOCK_FLOAT, 0, N_("V")}, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("H")}, + {SOCK_FLOAT, 0, N_("S")}, + {SOCK_FLOAT, 0, N_("V")}, + {-1, 0, ""}, }; -static void node_shader_exec_sephsv(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) +static void node_shader_exec_sephsv(void *UNUSED(data), + int UNUSED(thread), + bNode *UNUSED(node), + bNodeExecData *UNUSED(execdata), + bNodeStack **in, + bNodeStack **out) { - float col[3]; - nodestack_get_vec(col, SOCK_VECTOR, in[0]); + float col[3]; + nodestack_get_vec(col, SOCK_VECTOR, in[0]); - rgb_to_hsv(col[0], col[1], col[2], - &out[0]->vec[0], &out[1]->vec[0], &out[2]->vec[0]); + rgb_to_hsv(col[0], col[1], col[2], &out[0]->vec[0], &out[1]->vec[0], &out[2]->vec[0]); } -static int gpu_shader_sephsv(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_sephsv(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "separate_hsv", in, out); + return GPU_stack_link(mat, node, "separate_hsv", in, out); } void register_node_type_sh_sephsv(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_SEPHSV, "Separate HSV", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, sh_node_sephsv_in, sh_node_sephsv_out); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_sephsv); - node_type_gpu(&ntype, gpu_shader_sephsv); + sh_node_type_base(&ntype, SH_NODE_SEPHSV, "Separate HSV", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, sh_node_sephsv_in, sh_node_sephsv_out); + node_type_exec(&ntype, NULL, NULL, node_shader_exec_sephsv); + node_type_gpu(&ntype, gpu_shader_sephsv); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } - /* **************** COMBINE HSV ******************** */ static bNodeSocketTemplate sh_node_combhsv_in[] = { - { SOCK_FLOAT, 1, N_("H"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED}, - { SOCK_FLOAT, 1, N_("S"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED}, - { SOCK_FLOAT, 1, N_("V"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("H"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED}, + {SOCK_FLOAT, 1, N_("S"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED}, + {SOCK_FLOAT, 1, N_("V"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_combhsv_out[] = { - { SOCK_RGBA, 0, N_("Color")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color")}, + {-1, 0, ""}, }; -static void node_shader_exec_combhsv(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) +static void node_shader_exec_combhsv(void *UNUSED(data), + int UNUSED(thread), + bNode *UNUSED(node), + bNodeExecData *UNUSED(execdata), + bNodeStack **in, + bNodeStack **out) { - float h, s, v; - nodestack_get_vec(&h, SOCK_FLOAT, in[0]); - nodestack_get_vec(&s, SOCK_FLOAT, in[1]); - nodestack_get_vec(&v, SOCK_FLOAT, in[2]); + float h, s, v; + nodestack_get_vec(&h, SOCK_FLOAT, in[0]); + nodestack_get_vec(&s, SOCK_FLOAT, in[1]); + nodestack_get_vec(&v, SOCK_FLOAT, in[2]); - hsv_to_rgb(h, s, v, &out[0]->vec[0], &out[0]->vec[1], &out[0]->vec[2]); + hsv_to_rgb(h, s, v, &out[0]->vec[0], &out[0]->vec[1], &out[0]->vec[2]); } -static int gpu_shader_combhsv(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_combhsv(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "combine_hsv", in, out); + return GPU_stack_link(mat, node, "combine_hsv", in, out); } void register_node_type_sh_combhsv(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_COMBHSV, "Combine HSV", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, sh_node_combhsv_in, sh_node_combhsv_out); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_combhsv); - node_type_gpu(&ntype, gpu_shader_combhsv); + sh_node_type_base(&ntype, SH_NODE_COMBHSV, "Combine HSV", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, sh_node_combhsv_in, sh_node_combhsv_out); + node_type_exec(&ntype, NULL, NULL, node_shader_exec_combhsv); + node_type_gpu(&ntype, gpu_shader_combhsv); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.c b/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.c index 09f1cc2f973..55363525595 100644 --- a/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.c +++ b/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.c @@ -21,87 +21,102 @@ * \ingroup shdnodes */ - #include "node_shader_util.h" /* **************** SEPARATE RGBA ******************** */ static bNodeSocketTemplate sh_node_seprgb_in[] = { - { SOCK_RGBA, 1, N_("Image"), 0.8f, 0.8f, 0.8f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Image"), 0.8f, 0.8f, 0.8f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_seprgb_out[] = { - { SOCK_FLOAT, 0, N_("R")}, - { SOCK_FLOAT, 0, N_("G")}, - { SOCK_FLOAT, 0, N_("B")}, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("R")}, + {SOCK_FLOAT, 0, N_("G")}, + {SOCK_FLOAT, 0, N_("B")}, + {-1, 0, ""}, }; -static void node_shader_exec_seprgb(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) +static void node_shader_exec_seprgb(void *UNUSED(data), + int UNUSED(thread), + bNode *UNUSED(node), + bNodeExecData *UNUSED(execdata), + bNodeStack **in, + bNodeStack **out) { - float col[3]; - nodestack_get_vec(col, SOCK_VECTOR, in[0]); + float col[3]; + nodestack_get_vec(col, SOCK_VECTOR, in[0]); - out[0]->vec[0] = col[0]; - out[1]->vec[0] = col[1]; - out[2]->vec[0] = col[2]; + out[0]->vec[0] = col[0]; + out[1]->vec[0] = col[1]; + out[2]->vec[0] = col[2]; } -static int gpu_shader_seprgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_seprgb(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "separate_rgb", in, out); + return GPU_stack_link(mat, node, "separate_rgb", in, out); } void register_node_type_sh_seprgb(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_SEPRGB, "Separate RGB", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, sh_node_seprgb_in, sh_node_seprgb_out); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_seprgb); - node_type_gpu(&ntype, gpu_shader_seprgb); + sh_node_type_base(&ntype, SH_NODE_SEPRGB, "Separate RGB", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, sh_node_seprgb_in, sh_node_seprgb_out); + node_type_exec(&ntype, NULL, NULL, node_shader_exec_seprgb); + node_type_gpu(&ntype, gpu_shader_seprgb); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } - - /* **************** COMBINE RGB ******************** */ static bNodeSocketTemplate sh_node_combrgb_in[] = { - { SOCK_FLOAT, 1, N_("R"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED}, - { SOCK_FLOAT, 1, N_("G"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED}, - { SOCK_FLOAT, 1, N_("B"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("R"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED}, + {SOCK_FLOAT, 1, N_("G"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED}, + {SOCK_FLOAT, 1, N_("B"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_combrgb_out[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; -static void node_shader_exec_combrgb(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) +static void node_shader_exec_combrgb(void *UNUSED(data), + int UNUSED(thread), + bNode *UNUSED(node), + bNodeExecData *UNUSED(execdata), + bNodeStack **in, + bNodeStack **out) { - float r, g, b; - nodestack_get_vec(&r, SOCK_FLOAT, in[0]); - nodestack_get_vec(&g, SOCK_FLOAT, in[1]); - nodestack_get_vec(&b, SOCK_FLOAT, in[2]); - - out[0]->vec[0] = r; - out[0]->vec[1] = g; - out[0]->vec[2] = b; + float r, g, b; + nodestack_get_vec(&r, SOCK_FLOAT, in[0]); + nodestack_get_vec(&g, SOCK_FLOAT, in[1]); + nodestack_get_vec(&b, SOCK_FLOAT, in[2]); + + out[0]->vec[0] = r; + out[0]->vec[1] = g; + out[0]->vec[2] = b; } -static int gpu_shader_combrgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_combrgb(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "combine_rgb", in, out); + return GPU_stack_link(mat, node, "combine_rgb", in, out); } void register_node_type_sh_combrgb(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_COMBRGB, "Combine RGB", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, sh_node_combrgb_in, sh_node_combrgb_out); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_combrgb); - node_type_gpu(&ntype, gpu_shader_combrgb); + sh_node_type_base(&ntype, SH_NODE_COMBRGB, "Combine RGB", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, sh_node_combrgb_in, sh_node_combrgb_out); + node_type_exec(&ntype, NULL, NULL, node_shader_exec_combrgb); + node_type_gpu(&ntype, gpu_shader_combrgb); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.c b/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.c index c2c520c32ce..61685165f45 100644 --- a/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.c +++ b/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.c @@ -21,63 +21,68 @@ * \ingroup shdnodes */ - #include "node_shader_util.h" /* **************** SEPARATE XYZ ******************** */ static bNodeSocketTemplate sh_node_sepxyz_in[] = { - { SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f}, - { -1, 0, "" }, + {SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_sepxyz_out[] = { - { SOCK_FLOAT, 0, N_("X")}, - { SOCK_FLOAT, 0, N_("Y")}, - { SOCK_FLOAT, 0, N_("Z")}, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("X")}, + {SOCK_FLOAT, 0, N_("Y")}, + {SOCK_FLOAT, 0, N_("Z")}, + {-1, 0, ""}, }; -static int gpu_shader_sepxyz(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_sepxyz(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "separate_xyz", in, out); + return GPU_stack_link(mat, node, "separate_xyz", in, out); } void register_node_type_sh_sepxyz(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_SEPXYZ, "Separate XYZ", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, sh_node_sepxyz_in, sh_node_sepxyz_out); - node_type_gpu(&ntype, gpu_shader_sepxyz); + sh_node_type_base(&ntype, SH_NODE_SEPXYZ, "Separate XYZ", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, sh_node_sepxyz_in, sh_node_sepxyz_out); + node_type_gpu(&ntype, gpu_shader_sepxyz); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } - - /* **************** COMBINE XYZ ******************** */ static bNodeSocketTemplate sh_node_combxyz_in[] = { - { SOCK_FLOAT, 1, N_("X"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f}, - { SOCK_FLOAT, 1, N_("Y"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f}, - { SOCK_FLOAT, 1, N_("Z"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("X"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f}, + {SOCK_FLOAT, 1, N_("Y"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f}, + {SOCK_FLOAT, 1, N_("Z"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_combxyz_out[] = { - { SOCK_VECTOR, 0, N_("Vector")}, - { -1, 0, "" }, + {SOCK_VECTOR, 0, N_("Vector")}, + {-1, 0, ""}, }; -static int gpu_shader_combxyz(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_combxyz(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "combine_xyz", in, out); + return GPU_stack_link(mat, node, "combine_xyz", in, out); } void register_node_type_sh_combxyz(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_COMBXYZ, "Combine XYZ", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, sh_node_combxyz_in, sh_node_combxyz_out); - node_type_gpu(&ntype, gpu_shader_combxyz); + sh_node_type_base(&ntype, SH_NODE_COMBXYZ, "Combine XYZ", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, sh_node_combxyz_in, sh_node_combxyz_out); + node_type_gpu(&ntype, gpu_shader_combxyz); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_shaderToRgb.c b/source/blender/nodes/shader/nodes/node_shader_shaderToRgb.c index fbb1f97e121..583ec7edcc3 100644 --- a/source/blender/nodes/shader/nodes/node_shader_shaderToRgb.c +++ b/source/blender/nodes/shader/nodes/node_shader_shaderToRgb.c @@ -22,31 +22,35 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_shadertorgb_in[] = { - { SOCK_SHADER, 1, N_("Shader")}, - { -1, 0, "" }, + {SOCK_SHADER, 1, N_("Shader")}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_shadertorgb_out[] = { - { SOCK_RGBA, 0, N_("Color")}, - { SOCK_FLOAT, 0, N_("Alpha")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color")}, + {SOCK_FLOAT, 0, N_("Alpha")}, + {-1, 0, ""}, }; -static int node_shader_gpu_shadertorgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_shadertorgb(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "node_shader_to_rgba", in, out); + return GPU_stack_link(mat, node, "node_shader_to_rgba", in, out); } /* node type definition */ void register_node_type_sh_shadertorgb(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_SHADERTORGB, "Shader to RGB", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, sh_node_shadertorgb_in, sh_node_shadertorgb_out); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_shadertorgb); + sh_node_type_base(&ntype, SH_NODE_SHADERTORGB, "Shader to RGB", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, sh_node_shadertorgb_in, sh_node_shadertorgb_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_shadertorgb); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_squeeze.c b/source/blender/nodes/shader/nodes/node_shader_squeeze.c index 1ccfebac08f..f150c70bf8d 100644 --- a/source/blender/nodes/shader/nodes/node_shader_squeeze.c +++ b/source/blender/nodes/shader/nodes/node_shader_squeeze.c @@ -21,47 +21,51 @@ * \ingroup shdnodes */ - #include "node_shader_util.h" /* **************** VALUE SQUEEZE ******************** */ static bNodeSocketTemplate sh_node_squeeze_in[] = { - { SOCK_FLOAT, 1, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("Width"), 1.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("Center"), 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE}, - { -1, 0, "" } -}; + {SOCK_FLOAT, 1, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("Width"), 1.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("Center"), 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE}, + {-1, 0, ""}}; -static bNodeSocketTemplate sh_node_squeeze_out[] = { - { SOCK_FLOAT, 0, N_("Value")}, - { -1, 0, "" } -}; +static bNodeSocketTemplate sh_node_squeeze_out[] = {{SOCK_FLOAT, 0, N_("Value")}, {-1, 0, ""}}; -static void node_shader_exec_squeeze(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) +static void node_shader_exec_squeeze(void *UNUSED(data), + int UNUSED(thread), + bNode *UNUSED(node), + bNodeExecData *UNUSED(execdata), + bNodeStack **in, + bNodeStack **out) { - float vec[3]; + float vec[3]; - nodestack_get_vec(vec, SOCK_FLOAT, in[0]); - nodestack_get_vec(vec + 1, SOCK_FLOAT, in[1]); - nodestack_get_vec(vec + 2, SOCK_FLOAT, in[2]); + nodestack_get_vec(vec, SOCK_FLOAT, in[0]); + nodestack_get_vec(vec + 1, SOCK_FLOAT, in[1]); + nodestack_get_vec(vec + 2, SOCK_FLOAT, in[2]); - out[0]->vec[0] = 1.0f / (1.0f + powf(M_E, -((vec[0] - vec[2]) * vec[1]))); + out[0]->vec[0] = 1.0f / (1.0f + powf(M_E, -((vec[0] - vec[2]) * vec[1]))); } -static int gpu_shader_squeeze(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_squeeze(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "squeeze", in, out); + return GPU_stack_link(mat, node, "squeeze", in, out); } void register_node_type_sh_squeeze(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_SQUEEZE, "Squeeze Value", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, sh_node_squeeze_in, sh_node_squeeze_out); - node_type_storage(&ntype, "", NULL, NULL); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_squeeze); - node_type_gpu(&ntype, gpu_shader_squeeze); + sh_node_type_base(&ntype, SH_NODE_SQUEEZE, "Squeeze Value", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, sh_node_squeeze_in, sh_node_squeeze_out); + node_type_storage(&ntype, "", NULL, NULL); + node_type_exec(&ntype, NULL, NULL, node_shader_exec_squeeze); + node_type_gpu(&ntype, gpu_shader_squeeze); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.c b/source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.c index b414dd85eea..a6a2edd5352 100644 --- a/source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.c +++ b/source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.c @@ -22,74 +22,89 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_subsurface_scattering_in[] = { - { SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Scale"), 1.0, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { SOCK_VECTOR, 1, N_("Radius"), 1.0f, 0.2f, 0.1f, 0.0f, 0.0f, 100.0f}, - { SOCK_FLOAT, 1, N_("Sharpness"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_FLOAT, 1, N_("Texture Blur"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Scale"), 1.0, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + {SOCK_VECTOR, 1, N_("Radius"), 1.0f, 0.2f, 0.1f, 0.0f, 0.0f, 100.0f}, + {SOCK_FLOAT, 1, N_("Sharpness"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_FLOAT, 1, N_("Texture Blur"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_VECTOR, + 1, + N_("Normal"), + 0.0f, + 0.0f, + 0.0f, + 1.0f, + -1.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_subsurface_scattering_out[] = { - { SOCK_SHADER, 0, N_("BSSRDF")}, - { -1, 0, "" }, + {SOCK_SHADER, 0, N_("BSSRDF")}, + {-1, 0, ""}, }; static void node_shader_init_subsurface_scattering(bNodeTree *UNUSED(ntree), bNode *node) { - node->custom1 = SHD_SUBSURFACE_BURLEY; + node->custom1 = SHD_SUBSURFACE_BURLEY; } -static int node_shader_gpu_subsurface_scattering(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_subsurface_scattering(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - if (!in[5].link) - GPU_link(mat, "world_normals_get", &in[5].link); + if (!in[5].link) + GPU_link(mat, "world_normals_get", &in[5].link); - GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE | GPU_MATFLAG_SSS); + GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE | GPU_MATFLAG_SSS); - if (node->sss_id == 1) { - bNodeSocket *socket = BLI_findlink(&node->original->inputs, 2); - bNodeSocketValueRGBA *socket_data = socket->default_value; - bNodeSocket *socket_sharp = BLI_findlink(&node->original->inputs, 3); - bNodeSocketValueFloat *socket_data_sharp = socket_sharp->default_value; - /* For some reason it seems that the socket value is in ARGB format. */ - GPU_material_sss_profile_create(mat, &socket_data->value[1], - &node->original->custom1, - &socket_data_sharp->value); - } + if (node->sss_id == 1) { + bNodeSocket *socket = BLI_findlink(&node->original->inputs, 2); + bNodeSocketValueRGBA *socket_data = socket->default_value; + bNodeSocket *socket_sharp = BLI_findlink(&node->original->inputs, 3); + bNodeSocketValueFloat *socket_data_sharp = socket_sharp->default_value; + /* For some reason it seems that the socket value is in ARGB format. */ + GPU_material_sss_profile_create( + mat, &socket_data->value[1], &node->original->custom1, &socket_data_sharp->value); + } - return GPU_stack_link(mat, node, "node_subsurface_scattering", in, out, GPU_constant(&node->sss_id)); + return GPU_stack_link( + mat, node, "node_subsurface_scattering", in, out, GPU_constant(&node->sss_id)); } static void node_shader_update_subsurface_scattering(bNodeTree *UNUSED(ntree), bNode *node) { - bNodeSocket *sock; - int falloff = node->custom1; + bNodeSocket *sock; + int falloff = node->custom1; - for (sock = node->inputs.first; sock; sock = sock->next) { - if (STREQ(sock->name, "Sharpness")) { - if (falloff == SHD_SUBSURFACE_CUBIC) - sock->flag &= ~SOCK_UNAVAIL; - else - sock->flag |= SOCK_UNAVAIL; - - } - } + for (sock = node->inputs.first; sock; sock = sock->next) { + if (STREQ(sock->name, "Sharpness")) { + if (falloff == SHD_SUBSURFACE_CUBIC) + sock->flag &= ~SOCK_UNAVAIL; + else + sock->flag |= SOCK_UNAVAIL; + } + } } /* node type definition */ void register_node_type_sh_subsurface_scattering(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_SUBSURFACE_SCATTERING, "Subsurface Scattering", NODE_CLASS_SHADER, 0); - node_type_socket_templates(&ntype, sh_node_subsurface_scattering_in, sh_node_subsurface_scattering_out); - node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); - node_type_init(&ntype, node_shader_init_subsurface_scattering); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_subsurface_scattering); - node_type_update(&ntype, node_shader_update_subsurface_scattering, NULL); + sh_node_type_base( + &ntype, SH_NODE_SUBSURFACE_SCATTERING, "Subsurface Scattering", NODE_CLASS_SHADER, 0); + node_type_socket_templates( + &ntype, sh_node_subsurface_scattering_in, sh_node_subsurface_scattering_out); + node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); + node_type_init(&ntype, node_shader_init_subsurface_scattering); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_subsurface_scattering); + node_type_update(&ntype, node_shader_update_subsurface_scattering, NULL); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_tangent.c b/source/blender/nodes/shader/nodes/node_shader_tangent.c index bbb1f60a7e7..6af19503800 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tangent.c +++ b/source/blender/nodes/shader/nodes/node_shader_tangent.c @@ -22,51 +22,68 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_tangent_out[] = { - { SOCK_VECTOR, 0, N_("Tangent"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_VECTOR, 0, N_("Tangent"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; static void node_shader_init_tangent(bNodeTree *UNUSED(ntree), bNode *node) { - NodeShaderTangent *attr = MEM_callocN(sizeof(NodeShaderTangent), "NodeShaderTangent"); - attr->axis = SHD_TANGENT_AXIS_Z; - node->storage = attr; + NodeShaderTangent *attr = MEM_callocN(sizeof(NodeShaderTangent), "NodeShaderTangent"); + attr->axis = SHD_TANGENT_AXIS_Z; + node->storage = attr; } -static int node_shader_gpu_tangent(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_tangent(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - NodeShaderTangent *attr = node->storage; + NodeShaderTangent *attr = node->storage; - if (attr->direction_type == SHD_TANGENT_UVMAP) { - return GPU_stack_link(mat, node, "node_tangentmap", in, out, GPU_attribute(CD_TANGENT, ""), GPU_builtin(GPU_INVERSE_VIEW_MATRIX)); - } - else { - GPUNodeLink *orco = GPU_attribute(CD_ORCO, ""); + if (attr->direction_type == SHD_TANGENT_UVMAP) { + return GPU_stack_link(mat, + node, + "node_tangentmap", + in, + out, + GPU_attribute(CD_TANGENT, ""), + GPU_builtin(GPU_INVERSE_VIEW_MATRIX)); + } + else { + GPUNodeLink *orco = GPU_attribute(CD_ORCO, ""); - if (attr->axis == SHD_TANGENT_AXIS_X) - GPU_link(mat, "tangent_orco_x", orco, &orco); - else if (attr->axis == SHD_TANGENT_AXIS_Y) - GPU_link(mat, "tangent_orco_y", orco, &orco); - else - GPU_link(mat, "tangent_orco_z", orco, &orco); + if (attr->axis == SHD_TANGENT_AXIS_X) + GPU_link(mat, "tangent_orco_x", orco, &orco); + else if (attr->axis == SHD_TANGENT_AXIS_Y) + GPU_link(mat, "tangent_orco_y", orco, &orco); + else + GPU_link(mat, "tangent_orco_z", orco, &orco); - return GPU_stack_link( - mat, node, "node_tangent", in, out, GPU_builtin(GPU_VIEW_NORMAL), orco, - GPU_builtin(GPU_OBJECT_MATRIX), GPU_builtin(GPU_INVERSE_VIEW_MATRIX)); - } + return GPU_stack_link(mat, + node, + "node_tangent", + in, + out, + GPU_builtin(GPU_VIEW_NORMAL), + orco, + GPU_builtin(GPU_OBJECT_MATRIX), + GPU_builtin(GPU_INVERSE_VIEW_MATRIX)); + } } /* node type definition */ void register_node_type_sh_tangent(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_TANGENT, "Tangent", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, NULL, sh_node_tangent_out); - node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); - node_type_init(&ntype, node_shader_init_tangent); - node_type_gpu(&ntype, node_shader_gpu_tangent); - node_type_storage(&ntype, "NodeShaderTangent", node_free_standard_storage, node_copy_standard_storage); + sh_node_type_base(&ntype, SH_NODE_TANGENT, "Tangent", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, NULL, sh_node_tangent_out); + node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); + node_type_init(&ntype, node_shader_init_tangent); + node_type_gpu(&ntype, node_shader_gpu_tangent); + node_type_storage( + &ntype, "NodeShaderTangent", node_free_standard_storage, node_copy_standard_storage); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_brick.c b/source/blender/nodes/shader/nodes/node_shader_tex_brick.c index ffd81631a11..92ade999650 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_brick.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_brick.c @@ -22,73 +22,173 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_tex_brick_in[] = { - { SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE | SOCK_NO_INTERNAL_LINK}, - { SOCK_RGBA, 1, N_("Color1"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 1, N_("Color2"), 0.2f, 0.2f, 0.2f, 1.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 1, N_("Mortar"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - { SOCK_FLOAT, 1, N_("Scale"), 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - { SOCK_FLOAT, 1, N_("Mortar Size"), 0.02f, 0.0f, 0.0f, 0.0f, 0.0f, 0.125f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - { SOCK_FLOAT, 1, N_("Mortar Smooth"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - { SOCK_FLOAT, 1, N_("Bias"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - { SOCK_FLOAT, 1, N_("Brick Width"), 0.5f, 0.0f, 0.0f, 0.0f, 0.01f, 100.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - { SOCK_FLOAT, 1, N_("Row Height"), 0.25f, 0.0f, 0.0f, 0.0f, 0.01f, 100.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - { -1, 0, "" }, + {SOCK_VECTOR, + 1, + N_("Vector"), + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f, + PROP_NONE, + SOCK_HIDE_VALUE | SOCK_NO_INTERNAL_LINK}, + {SOCK_RGBA, 1, N_("Color1"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 1, N_("Color2"), 0.2f, 0.2f, 0.2f, 1.0f, 0.0f, 1.0f}, + {SOCK_RGBA, + 1, + N_("Mortar"), + 0.0f, + 0.0f, + 0.0f, + 1.0f, + 0.0f, + 1.0f, + PROP_NONE, + SOCK_NO_INTERNAL_LINK}, + {SOCK_FLOAT, + 1, + N_("Scale"), + 5.0f, + 0.0f, + 0.0f, + 0.0f, + -1000.0f, + 1000.0f, + PROP_NONE, + SOCK_NO_INTERNAL_LINK}, + {SOCK_FLOAT, + 1, + N_("Mortar Size"), + 0.02f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.125f, + PROP_NONE, + SOCK_NO_INTERNAL_LINK}, + {SOCK_FLOAT, + 1, + N_("Mortar Smooth"), + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f, + PROP_NONE, + SOCK_NO_INTERNAL_LINK}, + {SOCK_FLOAT, + 1, + N_("Bias"), + 0.0f, + 0.0f, + 0.0f, + 0.0f, + -1.0f, + 1.0f, + PROP_NONE, + SOCK_NO_INTERNAL_LINK}, + {SOCK_FLOAT, + 1, + N_("Brick Width"), + 0.5f, + 0.0f, + 0.0f, + 0.0f, + 0.01f, + 100.0f, + PROP_NONE, + SOCK_NO_INTERNAL_LINK}, + {SOCK_FLOAT, + 1, + N_("Row Height"), + 0.25f, + 0.0f, + 0.0f, + 0.0f, + 0.01f, + 100.0f, + PROP_NONE, + SOCK_NO_INTERNAL_LINK}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_tex_brick_out[] = { - { SOCK_RGBA, 0, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Fac"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR, SOCK_NO_INTERNAL_LINK}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, + 0, + N_("Fac"), + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f, + PROP_FACTOR, + SOCK_NO_INTERNAL_LINK}, + {-1, 0, ""}, }; static void node_shader_init_tex_brick(bNodeTree *UNUSED(ntree), bNode *node) { - NodeTexBrick *tex = MEM_callocN(sizeof(NodeTexBrick), "NodeTexBrick"); - BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT); - BKE_texture_colormapping_default(&tex->base.color_mapping); + NodeTexBrick *tex = MEM_callocN(sizeof(NodeTexBrick), "NodeTexBrick"); + BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT); + BKE_texture_colormapping_default(&tex->base.color_mapping); - tex->offset = 0.5f; - tex->squash = 1.0f; - tex->offset_freq = 2; - tex->squash_freq = 2; + tex->offset = 0.5f; + tex->squash = 1.0f; + tex->offset_freq = 2; + tex->squash_freq = 2; - node->storage = tex; + node->storage = tex; - for (bNodeSocket *sock = node->inputs.first; sock; sock = sock->next) { - if (STREQ(sock->name, "Mortar Smooth")) { - ((bNodeSocketValueFloat *)sock->default_value)->value = 0.1f; - } - } + for (bNodeSocket *sock = node->inputs.first; sock; sock = sock->next) { + if (STREQ(sock->name, "Mortar Smooth")) { + ((bNodeSocketValueFloat *)sock->default_value)->value = 0.1f; + } + } } -static int node_shader_gpu_tex_brick(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_tex_brick(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - if (!in[0].link) { - in[0].link = GPU_attribute(CD_ORCO, ""); - GPU_link(mat, "generated_texco", GPU_builtin(GPU_VIEW_POSITION), in[0].link, &in[0].link); - } + if (!in[0].link) { + in[0].link = GPU_attribute(CD_ORCO, ""); + GPU_link(mat, "generated_texco", GPU_builtin(GPU_VIEW_POSITION), in[0].link, &in[0].link); + } - node_shader_gpu_tex_mapping(mat, node, in, out); - NodeTexBrick *tex = (NodeTexBrick *)node->storage; - float offset_freq = tex->offset_freq; - float squash_freq = tex->squash_freq; - return GPU_stack_link(mat, node, "node_tex_brick", - in, out, - GPU_constant(&tex->offset), GPU_constant(&offset_freq), - GPU_constant(&tex->squash), GPU_constant(&squash_freq)); + node_shader_gpu_tex_mapping(mat, node, in, out); + NodeTexBrick *tex = (NodeTexBrick *)node->storage; + float offset_freq = tex->offset_freq; + float squash_freq = tex->squash_freq; + return GPU_stack_link(mat, + node, + "node_tex_brick", + in, + out, + GPU_constant(&tex->offset), + GPU_constant(&offset_freq), + GPU_constant(&tex->squash), + GPU_constant(&squash_freq)); } /* node type definition */ void register_node_type_sh_tex_brick(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_TEX_BRICK, "Brick Texture", NODE_CLASS_TEXTURE, 0); - node_type_socket_templates(&ntype, sh_node_tex_brick_in, sh_node_tex_brick_out); - node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); - node_type_init(&ntype, node_shader_init_tex_brick); - node_type_storage(&ntype, "NodeTexBrick", node_free_standard_storage, node_copy_standard_storage); - node_type_gpu(&ntype, node_shader_gpu_tex_brick); + sh_node_type_base(&ntype, SH_NODE_TEX_BRICK, "Brick Texture", NODE_CLASS_TEXTURE, 0); + node_type_socket_templates(&ntype, sh_node_tex_brick_in, sh_node_tex_brick_out); + node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); + node_type_init(&ntype, node_shader_init_tex_brick); + node_type_storage( + &ntype, "NodeTexBrick", node_free_standard_storage, node_copy_standard_storage); + node_type_gpu(&ntype, node_shader_gpu_tex_brick); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_checker.c b/source/blender/nodes/shader/nodes/node_shader_tex_checker.c index 80cf1cecae3..9dcb6057589 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_checker.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_checker.c @@ -22,50 +22,75 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_tex_checker_in[] = { - { SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { SOCK_RGBA, 1, N_("Color1"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 1, N_("Color2"), 0.2f, 0.2f, 0.2f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Scale"), 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - { -1, 0, "" }, + {SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + {SOCK_RGBA, 1, N_("Color1"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 1, N_("Color2"), 0.2f, 0.2f, 0.2f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, + 1, + N_("Scale"), + 5.0f, + 0.0f, + 0.0f, + 0.0f, + -1000.0f, + 1000.0f, + PROP_NONE, + SOCK_NO_INTERNAL_LINK}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_tex_checker_out[] = { - { SOCK_RGBA, 0, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 0, N_("Fac"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR, SOCK_NO_INTERNAL_LINK}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, + 0, + N_("Fac"), + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f, + PROP_FACTOR, + SOCK_NO_INTERNAL_LINK}, + {-1, 0, ""}, }; static void node_shader_init_tex_checker(bNodeTree *UNUSED(ntree), bNode *node) { - NodeTexChecker *tex = MEM_callocN(sizeof(NodeTexChecker), "NodeTexChecker"); - BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT); - BKE_texture_colormapping_default(&tex->base.color_mapping); + NodeTexChecker *tex = MEM_callocN(sizeof(NodeTexChecker), "NodeTexChecker"); + BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT); + BKE_texture_colormapping_default(&tex->base.color_mapping); - node->storage = tex; + node->storage = tex; } -static int node_shader_gpu_tex_checker(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_tex_checker(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - if (!in[0].link) { - in[0].link = GPU_attribute(CD_ORCO, ""); - GPU_link(mat, "generated_texco", GPU_builtin(GPU_VIEW_POSITION), in[0].link, &in[0].link); - } + if (!in[0].link) { + in[0].link = GPU_attribute(CD_ORCO, ""); + GPU_link(mat, "generated_texco", GPU_builtin(GPU_VIEW_POSITION), in[0].link, &in[0].link); + } - node_shader_gpu_tex_mapping(mat, node, in, out); + node_shader_gpu_tex_mapping(mat, node, in, out); - return GPU_stack_link(mat, node, "node_tex_checker", in, out); + return GPU_stack_link(mat, node, "node_tex_checker", in, out); } /* node type definition */ void register_node_type_sh_tex_checker(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_TEX_CHECKER, "Checker Texture", NODE_CLASS_TEXTURE, 0); - node_type_socket_templates(&ntype, sh_node_tex_checker_in, sh_node_tex_checker_out); - node_type_init(&ntype, node_shader_init_tex_checker); - node_type_storage(&ntype, "NodeTexChecker", node_free_standard_storage, node_copy_standard_storage); - node_type_gpu(&ntype, node_shader_gpu_tex_checker); + sh_node_type_base(&ntype, SH_NODE_TEX_CHECKER, "Checker Texture", NODE_CLASS_TEXTURE, 0); + node_type_socket_templates(&ntype, sh_node_tex_checker_in, sh_node_tex_checker_out); + node_type_init(&ntype, node_shader_init_tex_checker); + node_type_storage( + &ntype, "NodeTexChecker", node_free_standard_storage, node_copy_standard_storage); + node_type_gpu(&ntype, node_shader_gpu_tex_checker); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_coord.c b/source/blender/nodes/shader/nodes/node_shader_tex_coord.c index 5a7a81f57bd..fd62e8ce960 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_coord.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_coord.c @@ -24,47 +24,60 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_tex_coord_out[] = { - { SOCK_VECTOR, 0, N_("Generated"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 0, N_("Normal"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 0, N_("UV"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 0, N_("Object"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 0, N_("Camera"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 0, N_("Window"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 0, N_("Reflection"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_VECTOR, 0, N_("Generated"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_VECTOR, 0, N_("Normal"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_VECTOR, 0, N_("UV"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_VECTOR, 0, N_("Object"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_VECTOR, 0, N_("Camera"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_VECTOR, 0, N_("Window"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_VECTOR, 0, N_("Reflection"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; -static int node_shader_gpu_tex_coord(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_tex_coord(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - Object *ob = (Object *)node->id; + Object *ob = (Object *)node->id; - if (ob != NULL) { - invert_m4_m4(ob->imat, ob->obmat); - } + if (ob != NULL) { + invert_m4_m4(ob->imat, ob->obmat); + } - GPUNodeLink *inv_obmat = (ob != NULL) ? GPU_uniform(&ob->imat[0][0]) : GPU_builtin(GPU_INVERSE_OBJECT_MATRIX); + GPUNodeLink *inv_obmat = (ob != NULL) ? GPU_uniform(&ob->imat[0][0]) : + GPU_builtin(GPU_INVERSE_OBJECT_MATRIX); - GPUNodeLink *orco = GPU_attribute(CD_ORCO, ""); - GPUNodeLink *mtface = GPU_attribute(CD_MTFACE, ""); + GPUNodeLink *orco = GPU_attribute(CD_ORCO, ""); + GPUNodeLink *mtface = GPU_attribute(CD_MTFACE, ""); - GPU_link(mat, "generated_from_orco", orco, &orco); + GPU_link(mat, "generated_from_orco", orco, &orco); - return GPU_stack_link(mat, node, "node_tex_coord", in, out, - GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL), - GPU_builtin(GPU_INVERSE_VIEW_MATRIX), inv_obmat, - GPU_builtin(GPU_CAMERA_TEXCO_FACTORS), orco, mtface); + return GPU_stack_link(mat, + node, + "node_tex_coord", + in, + out, + GPU_builtin(GPU_VIEW_POSITION), + GPU_builtin(GPU_VIEW_NORMAL), + GPU_builtin(GPU_INVERSE_VIEW_MATRIX), + inv_obmat, + GPU_builtin(GPU_CAMERA_TEXCO_FACTORS), + orco, + mtface); } /* node type definition */ void register_node_type_sh_tex_coord(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_TEX_COORD, "Texture Coordinate", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, NULL, sh_node_tex_coord_out); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_tex_coord); + sh_node_type_base(&ntype, SH_NODE_TEX_COORD, "Texture Coordinate", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, NULL, sh_node_tex_coord_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_tex_coord); - nodeRegisterType(&ntype); + 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 index 3f6c1b92d8b..6e8516b9886 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_environment.c @@ -22,101 +22,134 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_tex_environment_in[] = { - { SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { -1, 0, "" }, + {SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_tex_environment_out[] = { - { SOCK_RGBA, 0, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - { -1, 0, "" }, + {SOCK_RGBA, + 0, + N_("Color"), + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f, + PROP_NONE, + SOCK_NO_INTERNAL_LINK}, + {-1, 0, ""}, }; 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->color_space = SHD_COLORSPACE_COLOR; - tex->projection = SHD_PROJ_EQUIRECTANGULAR; - tex->iuser.frames = 1; - tex->iuser.sfra = 1; - tex->iuser.ok = 1; - - node->storage = tex; + 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->color_space = SHD_COLORSPACE_COLOR; + tex->projection = SHD_PROJ_EQUIRECTANGULAR; + tex->iuser.frames = 1; + tex->iuser.sfra = 1; + tex->iuser.ok = 1; + + node->storage = tex; } -static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +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; - - int isdata = tex->color_space == SHD_COLORSPACE_NONE; - 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_tex_mapping(mat, node, in, out); - - /* Compute texture coordinate. */ - if (tex->projection == SHD_PROJ_EQUIRECTANGULAR) { - /* To fix pole issue we clamp the v coordinate. The clamp value depends on the filter size. */ - float clamp_size = (ELEM(tex->interpolation, SHD_INTERP_CUBIC, SHD_INTERP_SMART)) ? 1.5 : 0.5; - GPU_link(mat, "node_tex_environment_equirectangular", in[0].link, GPU_constant(&clamp_size), - GPU_image(ima, iuser, isdata), &in[0].link); - } - else { - GPU_link(mat, "node_tex_environment_mirror_ball", in[0].link, &in[0].link); - } - - /* Sample texture with correct interpolation. */ - switch (tex->interpolation) { - case SHD_INTERP_LINEAR: - /* Force the highest mipmap and don't do anisotropic filtering. - * This is to fix the artifact caused by derivatives discontinuity. */ - GPU_link(mat, "node_tex_image_linear_no_mip", in[0].link, GPU_image(ima, iuser, isdata), &out[0].link, &outalpha); - break; - case SHD_INTERP_CLOSEST: - GPU_link(mat, "node_tex_image_nearest", in[0].link, GPU_image(ima, iuser, isdata), &out[0].link, &outalpha); - break; - default: - GPU_link(mat, "node_tex_image_cubic", in[0].link, GPU_image(ima, iuser, isdata), &out[0].link, &outalpha); - break; - } - - ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL); - if (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 && - GPU_material_do_color_management(mat)) - { - GPU_link(mat, "srgb_to_linearrgb", out[0].link, &out[0].link); - } - BKE_image_release_ibuf(ima, ibuf, NULL); - - return true; + 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; + + int isdata = tex->color_space == SHD_COLORSPACE_NONE; + 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_tex_mapping(mat, node, in, out); + + /* Compute texture coordinate. */ + if (tex->projection == SHD_PROJ_EQUIRECTANGULAR) { + /* To fix pole issue we clamp the v coordinate. The clamp value depends on the filter size. */ + float clamp_size = (ELEM(tex->interpolation, SHD_INTERP_CUBIC, SHD_INTERP_SMART)) ? 1.5 : 0.5; + GPU_link(mat, + "node_tex_environment_equirectangular", + in[0].link, + GPU_constant(&clamp_size), + GPU_image(ima, iuser, isdata), + &in[0].link); + } + else { + GPU_link(mat, "node_tex_environment_mirror_ball", in[0].link, &in[0].link); + } + + /* Sample texture with correct interpolation. */ + switch (tex->interpolation) { + case SHD_INTERP_LINEAR: + /* Force the highest mipmap and don't do anisotropic filtering. + * This is to fix the artifact caused by derivatives discontinuity. */ + GPU_link(mat, + "node_tex_image_linear_no_mip", + in[0].link, + GPU_image(ima, iuser, isdata), + &out[0].link, + &outalpha); + break; + case SHD_INTERP_CLOSEST: + GPU_link(mat, + "node_tex_image_nearest", + in[0].link, + GPU_image(ima, iuser, isdata), + &out[0].link, + &outalpha); + break; + default: + GPU_link(mat, + "node_tex_image_cubic", + in[0].link, + GPU_image(ima, iuser, isdata), + &out[0].link, + &outalpha); + break; + } + + ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL); + if (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 && + GPU_material_do_color_management(mat)) { + GPU_link(mat, "srgb_to_linearrgb", out[0].link, &out[0].link); + } + BKE_image_release_ibuf(ima, ibuf, NULL); + + 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); - node_type_label(&ntype, node_image_label); - node_type_size_preset(&ntype, NODE_SIZE_LARGE); - - nodeRegisterType(&ntype); + 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); + node_type_label(&ntype, node_image_label); + node_type_size_preset(&ntype, NODE_SIZE_LARGE); + + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_gradient.c b/source/blender/nodes/shader/nodes/node_shader_tex_gradient.c index 5dd0b5bf37c..9271ba72a05 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_gradient.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_gradient.c @@ -22,50 +22,75 @@ /* **************** BLEND ******************** */ static bNodeSocketTemplate sh_node_tex_gradient_in[] = { - { SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { -1, 0, "" }, + {SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_tex_gradient_out[] = { - { SOCK_RGBA, 0, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - { SOCK_FLOAT, 0, N_("Fac"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR, SOCK_NO_INTERNAL_LINK}, - { -1, 0, "" }, + {SOCK_RGBA, + 0, + N_("Color"), + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f, + PROP_NONE, + SOCK_NO_INTERNAL_LINK}, + {SOCK_FLOAT, + 0, + N_("Fac"), + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f, + PROP_FACTOR, + SOCK_NO_INTERNAL_LINK}, + {-1, 0, ""}, }; static void node_shader_init_tex_gradient(bNodeTree *UNUSED(ntree), bNode *node) { - NodeTexGradient *tex = MEM_callocN(sizeof(NodeTexGradient), "NodeTexGradient"); - BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT); - BKE_texture_colormapping_default(&tex->base.color_mapping); - tex->gradient_type = SHD_BLEND_LINEAR; + NodeTexGradient *tex = MEM_callocN(sizeof(NodeTexGradient), "NodeTexGradient"); + BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT); + BKE_texture_colormapping_default(&tex->base.color_mapping); + tex->gradient_type = SHD_BLEND_LINEAR; - node->storage = tex; + node->storage = tex; } -static int node_shader_gpu_tex_gradient(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_tex_gradient(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - if (!in[0].link) { - in[0].link = GPU_attribute(CD_ORCO, ""); - GPU_link(mat, "generated_texco", GPU_builtin(GPU_VIEW_POSITION), in[0].link, &in[0].link); - } + if (!in[0].link) { + in[0].link = GPU_attribute(CD_ORCO, ""); + GPU_link(mat, "generated_texco", GPU_builtin(GPU_VIEW_POSITION), in[0].link, &in[0].link); + } - node_shader_gpu_tex_mapping(mat, node, in, out); + node_shader_gpu_tex_mapping(mat, node, in, out); - NodeTexGradient *tex = (NodeTexGradient *)node->storage; - float gradient_type = tex->gradient_type; - return GPU_stack_link(mat, node, "node_tex_gradient", in, out, GPU_constant(&gradient_type)); + NodeTexGradient *tex = (NodeTexGradient *)node->storage; + float gradient_type = tex->gradient_type; + return GPU_stack_link(mat, node, "node_tex_gradient", in, out, GPU_constant(&gradient_type)); } /* node type definition */ void register_node_type_sh_tex_gradient(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_TEX_GRADIENT, "Gradient Texture", NODE_CLASS_TEXTURE, 0); - node_type_socket_templates(&ntype, sh_node_tex_gradient_in, sh_node_tex_gradient_out); - node_type_init(&ntype, node_shader_init_tex_gradient); - node_type_storage(&ntype, "NodeTexGradient", node_free_standard_storage, node_copy_standard_storage); - node_type_gpu(&ntype, node_shader_gpu_tex_gradient); + sh_node_type_base(&ntype, SH_NODE_TEX_GRADIENT, "Gradient Texture", NODE_CLASS_TEXTURE, 0); + node_type_socket_templates(&ntype, sh_node_tex_gradient_in, sh_node_tex_gradient_out); + node_type_init(&ntype, node_shader_init_tex_gradient); + node_type_storage( + &ntype, "NodeTexGradient", node_free_standard_storage, node_copy_standard_storage); + node_type_gpu(&ntype, node_shader_gpu_tex_gradient); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_image.c b/source/blender/nodes/shader/nodes/node_shader_tex_image.c index 3491a28fa8f..55e8e6a0e8f 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_image.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_image.c @@ -22,178 +22,212 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_tex_image_in[] = { - { SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { -1, 0, "" }, + {SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_tex_image_out[] = { - { SOCK_RGBA, 0, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - { SOCK_FLOAT, 0, N_("Alpha"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - { -1, 0, "" }, + {SOCK_RGBA, + 0, + N_("Color"), + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f, + PROP_NONE, + SOCK_NO_INTERNAL_LINK}, + {SOCK_FLOAT, + 0, + N_("Alpha"), + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f, + PROP_NONE, + SOCK_NO_INTERNAL_LINK}, + {-1, 0, ""}, }; static void node_shader_init_tex_image(bNodeTree *UNUSED(ntree), bNode *node) { - NodeTexImage *tex = MEM_callocN(sizeof(NodeTexImage), "NodeTexImage"); - BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT); - BKE_texture_colormapping_default(&tex->base.color_mapping); - tex->color_space = SHD_COLORSPACE_COLOR; - tex->iuser.frames = 1; - tex->iuser.sfra = 1; - tex->iuser.ok = 1; - - node->storage = tex; + NodeTexImage *tex = MEM_callocN(sizeof(NodeTexImage), "NodeTexImage"); + BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT); + BKE_texture_colormapping_default(&tex->base.color_mapping); + tex->color_space = SHD_COLORSPACE_COLOR; + tex->iuser.frames = 1; + tex->iuser.sfra = 1; + tex->iuser.ok = 1; + + node->storage = tex; } -static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_tex_image(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - static const char *names[] = { - "node_tex_image_linear", - "node_tex_image_nearest", - "node_tex_image_cubic", - "node_tex_image_smart", - }; - static const char *names_box[] = { - "tex_box_sample_linear", - "tex_box_sample_nearest", - "tex_box_sample_cubic", - "tex_box_sample_smart", - }; - static const char *names_clip[] = { - "tex_clip_linear", - "tex_clip_nearest", - "tex_clip_cubic", - "tex_clip_smart", - }; - - Image *ima = (Image *)node->id; - NodeTexImage *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; - - const char *gpu_node_name = (tex->projection == SHD_PROJ_BOX) - ? names_box[tex->interpolation] - : names[tex->interpolation]; - bool do_color_correction = false; - bool do_texco_extend = (tex->extension != SHD_IMAGE_EXTENSION_REPEAT); - const bool do_texco_clip = (tex->extension == SHD_IMAGE_EXTENSION_CLIP); - - if (do_texco_extend && (tex->projection != SHD_PROJ_BOX) && - ELEM(tex->interpolation, SHD_INTERP_CUBIC, SHD_INTERP_SMART)) - { - gpu_node_name = "node_tex_image_cubic_extend"; - /* We do it inside the sampling function */ - do_texco_extend = false; - } - - GPUNodeLink *norm, *col1, *col2, *col3, *input_coords; - - int isdata = tex->color_space == SHD_COLORSPACE_NONE; - float blend = tex->projection_blend; - - if (!ima) - return GPU_stack_link(mat, node, "node_tex_image_empty", in, out); - - ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL); - if ((tex->color_space == SHD_COLORSPACE_COLOR) && - ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 && - GPU_material_do_color_management(mat)) - { - do_color_correction = true; - } - BKE_image_release_ibuf(ima, ibuf, NULL); - - if (!in[0].link) - in[0].link = GPU_attribute(CD_MTFACE, ""); - - node_shader_gpu_tex_mapping(mat, node, in, out); - - switch (tex->projection) { - case SHD_PROJ_FLAT: - if (do_texco_clip) { - GPU_link(mat, "set_rgb", in[0].link, &input_coords); - } - if (do_texco_extend) { - GPU_link(mat, "point_texco_clamp", in[0].link, GPU_image(ima, iuser, isdata), &in[0].link); - } - GPU_stack_link(mat, node, gpu_node_name, in, out, GPU_image(ima, iuser, isdata)); - break; - case SHD_PROJ_BOX: - GPU_link(mat, "mat3_mul", GPU_builtin(GPU_VIEW_NORMAL), - GPU_builtin(GPU_INVERSE_NORMAL_MATRIX), - &norm); - GPU_link(mat, gpu_node_name, in[0].link, - norm, - GPU_image(ima, iuser, isdata), - &col1, - &col2, - &col3); - if (do_color_correction) { - GPU_link(mat, "srgb_to_linearrgb", col1, &col1); - GPU_link(mat, "srgb_to_linearrgb", col2, &col2); - GPU_link(mat, "srgb_to_linearrgb", col3, &col3); - } - GPU_link(mat, "node_tex_image_box", in[0].link, - norm, - col1, col2, col3, - GPU_image(ima, iuser, isdata), - GPU_uniform(&blend), - &out[0].link, - &out[1].link); - break; - case SHD_PROJ_SPHERE: - GPU_link(mat, "point_texco_remap_square", in[0].link, &in[0].link); - GPU_link(mat, "point_map_to_sphere", in[0].link, &in[0].link); - if (do_texco_clip) { - GPU_link(mat, "set_rgb", in[0].link, &input_coords); - } - if (do_texco_extend) { - GPU_link(mat, "point_texco_clamp", in[0].link, GPU_image(ima, iuser, isdata), &in[0].link); - } - GPU_stack_link(mat, node, gpu_node_name, in, out, GPU_image(ima, iuser, isdata)); - break; - case SHD_PROJ_TUBE: - GPU_link(mat, "point_texco_remap_square", in[0].link, &in[0].link); - GPU_link(mat, "point_map_to_tube", in[0].link, &in[0].link); - if (do_texco_clip) { - GPU_link(mat, "set_rgb", in[0].link, &input_coords); - } - if (do_texco_extend) { - GPU_link(mat, "point_texco_clamp", in[0].link, GPU_image(ima, iuser, isdata), &in[0].link); - } - GPU_stack_link(mat, node, gpu_node_name, in, out, GPU_image(ima, iuser, isdata)); - break; - } - - if (do_texco_clip && (tex->projection != SHD_PROJ_BOX)) { - GPU_link(mat, names_clip[tex->interpolation], - input_coords, GPU_image(ima, iuser, isdata), out[0].link, - &out[0].link, &out[1].link); - } - - if (do_color_correction && (tex->projection != SHD_PROJ_BOX)) { - GPU_link(mat, "srgb_to_linearrgb", out[0].link, &out[0].link); - } - - return true; + static const char *names[] = { + "node_tex_image_linear", + "node_tex_image_nearest", + "node_tex_image_cubic", + "node_tex_image_smart", + }; + static const char *names_box[] = { + "tex_box_sample_linear", + "tex_box_sample_nearest", + "tex_box_sample_cubic", + "tex_box_sample_smart", + }; + static const char *names_clip[] = { + "tex_clip_linear", + "tex_clip_nearest", + "tex_clip_cubic", + "tex_clip_smart", + }; + + Image *ima = (Image *)node->id; + NodeTexImage *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; + + const char *gpu_node_name = (tex->projection == SHD_PROJ_BOX) ? names_box[tex->interpolation] : + names[tex->interpolation]; + bool do_color_correction = false; + bool do_texco_extend = (tex->extension != SHD_IMAGE_EXTENSION_REPEAT); + const bool do_texco_clip = (tex->extension == SHD_IMAGE_EXTENSION_CLIP); + + if (do_texco_extend && (tex->projection != SHD_PROJ_BOX) && + ELEM(tex->interpolation, SHD_INTERP_CUBIC, SHD_INTERP_SMART)) { + gpu_node_name = "node_tex_image_cubic_extend"; + /* We do it inside the sampling function */ + do_texco_extend = false; + } + + GPUNodeLink *norm, *col1, *col2, *col3, *input_coords; + + int isdata = tex->color_space == SHD_COLORSPACE_NONE; + float blend = tex->projection_blend; + + if (!ima) + return GPU_stack_link(mat, node, "node_tex_image_empty", in, out); + + ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL); + if ((tex->color_space == SHD_COLORSPACE_COLOR) && ibuf && + (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 && + GPU_material_do_color_management(mat)) { + do_color_correction = true; + } + BKE_image_release_ibuf(ima, ibuf, NULL); + + if (!in[0].link) + in[0].link = GPU_attribute(CD_MTFACE, ""); + + node_shader_gpu_tex_mapping(mat, node, in, out); + + switch (tex->projection) { + case SHD_PROJ_FLAT: + if (do_texco_clip) { + GPU_link(mat, "set_rgb", in[0].link, &input_coords); + } + if (do_texco_extend) { + GPU_link(mat, "point_texco_clamp", in[0].link, GPU_image(ima, iuser, isdata), &in[0].link); + } + GPU_stack_link(mat, node, gpu_node_name, in, out, GPU_image(ima, iuser, isdata)); + break; + case SHD_PROJ_BOX: + GPU_link(mat, + "mat3_mul", + GPU_builtin(GPU_VIEW_NORMAL), + GPU_builtin(GPU_INVERSE_NORMAL_MATRIX), + &norm); + GPU_link(mat, + gpu_node_name, + in[0].link, + norm, + GPU_image(ima, iuser, isdata), + &col1, + &col2, + &col3); + if (do_color_correction) { + GPU_link(mat, "srgb_to_linearrgb", col1, &col1); + GPU_link(mat, "srgb_to_linearrgb", col2, &col2); + GPU_link(mat, "srgb_to_linearrgb", col3, &col3); + } + GPU_link(mat, + "node_tex_image_box", + in[0].link, + norm, + col1, + col2, + col3, + GPU_image(ima, iuser, isdata), + GPU_uniform(&blend), + &out[0].link, + &out[1].link); + break; + case SHD_PROJ_SPHERE: + GPU_link(mat, "point_texco_remap_square", in[0].link, &in[0].link); + GPU_link(mat, "point_map_to_sphere", in[0].link, &in[0].link); + if (do_texco_clip) { + GPU_link(mat, "set_rgb", in[0].link, &input_coords); + } + if (do_texco_extend) { + GPU_link(mat, "point_texco_clamp", in[0].link, GPU_image(ima, iuser, isdata), &in[0].link); + } + GPU_stack_link(mat, node, gpu_node_name, in, out, GPU_image(ima, iuser, isdata)); + break; + case SHD_PROJ_TUBE: + GPU_link(mat, "point_texco_remap_square", in[0].link, &in[0].link); + GPU_link(mat, "point_map_to_tube", in[0].link, &in[0].link); + if (do_texco_clip) { + GPU_link(mat, "set_rgb", in[0].link, &input_coords); + } + if (do_texco_extend) { + GPU_link(mat, "point_texco_clamp", in[0].link, GPU_image(ima, iuser, isdata), &in[0].link); + } + GPU_stack_link(mat, node, gpu_node_name, in, out, GPU_image(ima, iuser, isdata)); + break; + } + + if (do_texco_clip && (tex->projection != SHD_PROJ_BOX)) { + GPU_link(mat, + names_clip[tex->interpolation], + input_coords, + GPU_image(ima, iuser, isdata), + out[0].link, + &out[0].link, + &out[1].link); + } + + if (do_color_correction && (tex->projection != SHD_PROJ_BOX)) { + GPU_link(mat, "srgb_to_linearrgb", out[0].link, &out[0].link); + } + + return true; } /* node type definition */ void register_node_type_sh_tex_image(void) { - static bNodeType ntype; - - sh_node_type_base(&ntype, SH_NODE_TEX_IMAGE, "Image Texture", NODE_CLASS_TEXTURE, 0); - node_type_socket_templates(&ntype, sh_node_tex_image_in, sh_node_tex_image_out); - node_type_init(&ntype, node_shader_init_tex_image); - node_type_storage(&ntype, "NodeTexImage", node_free_standard_storage, node_copy_standard_storage); - node_type_gpu(&ntype, node_shader_gpu_tex_image); - node_type_label(&ntype, node_image_label); - node_type_size_preset(&ntype, NODE_SIZE_LARGE); - - nodeRegisterType(&ntype); + static bNodeType ntype; + + sh_node_type_base(&ntype, SH_NODE_TEX_IMAGE, "Image Texture", NODE_CLASS_TEXTURE, 0); + node_type_socket_templates(&ntype, sh_node_tex_image_in, sh_node_tex_image_out); + node_type_init(&ntype, node_shader_init_tex_image); + node_type_storage( + &ntype, "NodeTexImage", node_free_standard_storage, node_copy_standard_storage); + node_type_gpu(&ntype, node_shader_gpu_tex_image); + node_type_label(&ntype, node_image_label); + node_type_size_preset(&ntype, NODE_SIZE_LARGE); + + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_magic.c b/source/blender/nodes/shader/nodes/node_shader_tex_magic.c index ba99e53735b..f5dc0435f27 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_magic.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_magic.c @@ -22,53 +22,78 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_tex_magic_in[] = { - { SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { SOCK_FLOAT, 1, N_("Scale"), 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, - { SOCK_FLOAT, 1, N_("Distortion"), 1.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, - { -1, 0, "" }, + {SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + {SOCK_FLOAT, 1, N_("Scale"), 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, + {SOCK_FLOAT, 1, N_("Distortion"), 1.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_tex_magic_out[] = { - { SOCK_RGBA, 0, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - { SOCK_FLOAT, 0, N_("Fac"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR, SOCK_NO_INTERNAL_LINK}, - { -1, 0, "" }, + {SOCK_RGBA, + 0, + N_("Color"), + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f, + PROP_NONE, + SOCK_NO_INTERNAL_LINK}, + {SOCK_FLOAT, + 0, + N_("Fac"), + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f, + PROP_FACTOR, + SOCK_NO_INTERNAL_LINK}, + {-1, 0, ""}, }; static void node_shader_init_tex_magic(bNodeTree *UNUSED(ntree), bNode *node) { - NodeTexMagic *tex = MEM_callocN(sizeof(NodeTexMagic), "NodeTexMagic"); - BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT); - BKE_texture_colormapping_default(&tex->base.color_mapping); - tex->depth = 2; + NodeTexMagic *tex = MEM_callocN(sizeof(NodeTexMagic), "NodeTexMagic"); + BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT); + BKE_texture_colormapping_default(&tex->base.color_mapping); + tex->depth = 2; - node->storage = tex; + node->storage = tex; } -static int node_shader_gpu_tex_magic(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_tex_magic(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - NodeTexMagic *tex = (NodeTexMagic *)node->storage; - float depth = tex->depth; + NodeTexMagic *tex = (NodeTexMagic *)node->storage; + float depth = tex->depth; - if (!in[0].link) { - in[0].link = GPU_attribute(CD_ORCO, ""); - GPU_link(mat, "generated_texco", GPU_builtin(GPU_VIEW_POSITION), in[0].link, &in[0].link); - } + if (!in[0].link) { + in[0].link = GPU_attribute(CD_ORCO, ""); + GPU_link(mat, "generated_texco", GPU_builtin(GPU_VIEW_POSITION), in[0].link, &in[0].link); + } - node_shader_gpu_tex_mapping(mat, node, in, out); + node_shader_gpu_tex_mapping(mat, node, in, out); - return GPU_stack_link(mat, node, "node_tex_magic", in, out, GPU_constant(&depth)); + return GPU_stack_link(mat, node, "node_tex_magic", in, out, GPU_constant(&depth)); } /* node type definition */ void register_node_type_sh_tex_magic(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_TEX_MAGIC, "Magic Texture", NODE_CLASS_TEXTURE, 0); - node_type_socket_templates(&ntype, sh_node_tex_magic_in, sh_node_tex_magic_out); - node_type_init(&ntype, node_shader_init_tex_magic); - node_type_storage(&ntype, "NodeTexMagic", node_free_standard_storage, node_copy_standard_storage); - node_type_gpu(&ntype, node_shader_gpu_tex_magic); + sh_node_type_base(&ntype, SH_NODE_TEX_MAGIC, "Magic Texture", NODE_CLASS_TEXTURE, 0); + node_type_socket_templates(&ntype, sh_node_tex_magic_in, sh_node_tex_magic_out); + node_type_init(&ntype, node_shader_init_tex_magic); + node_type_storage( + &ntype, "NodeTexMagic", node_free_standard_storage, node_copy_standard_storage); + node_type_gpu(&ntype, node_shader_gpu_tex_magic); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.c b/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.c index 0cfbd225a61..250a1da3c23 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.c @@ -22,58 +22,83 @@ /* **************** MUSGRAVE ******************** */ static bNodeSocketTemplate sh_node_tex_musgrave_in[] = { - { SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { SOCK_FLOAT, 1, N_("Scale"), 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, - { SOCK_FLOAT, 1, N_("Detail"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 16.0f}, - { SOCK_FLOAT, 1, N_("Dimension"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { SOCK_FLOAT, 1, N_("Lacunarity"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { SOCK_FLOAT, 1, N_("Offset"), 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, - { SOCK_FLOAT, 1, N_("Gain"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { -1, 0, "" }, + {SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + {SOCK_FLOAT, 1, N_("Scale"), 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, + {SOCK_FLOAT, 1, N_("Detail"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 16.0f}, + {SOCK_FLOAT, 1, N_("Dimension"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + {SOCK_FLOAT, 1, N_("Lacunarity"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + {SOCK_FLOAT, 1, N_("Offset"), 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, + {SOCK_FLOAT, 1, N_("Gain"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_tex_musgrave_out[] = { - { SOCK_RGBA, 0, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - { SOCK_FLOAT, 0, N_("Fac"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR, SOCK_NO_INTERNAL_LINK}, - { -1, 0, "" }, + {SOCK_RGBA, + 0, + N_("Color"), + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f, + PROP_NONE, + SOCK_NO_INTERNAL_LINK}, + {SOCK_FLOAT, + 0, + N_("Fac"), + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f, + PROP_FACTOR, + SOCK_NO_INTERNAL_LINK}, + {-1, 0, ""}, }; static void node_shader_init_tex_musgrave(bNodeTree *UNUSED(ntree), bNode *node) { - NodeTexMusgrave *tex = MEM_callocN(sizeof(NodeTexMusgrave), "NodeTexMusgrave"); - BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT); - BKE_texture_colormapping_default(&tex->base.color_mapping); - tex->musgrave_type = SHD_MUSGRAVE_FBM; + NodeTexMusgrave *tex = MEM_callocN(sizeof(NodeTexMusgrave), "NodeTexMusgrave"); + BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT); + BKE_texture_colormapping_default(&tex->base.color_mapping); + tex->musgrave_type = SHD_MUSGRAVE_FBM; - node->storage = tex; + node->storage = tex; } -static int node_shader_gpu_tex_musgrave(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_tex_musgrave(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - if (!in[0].link) { - in[0].link = GPU_attribute(CD_ORCO, ""); - GPU_link(mat, "generated_texco", GPU_builtin(GPU_VIEW_POSITION), in[0].link, &in[0].link); - } + if (!in[0].link) { + in[0].link = GPU_attribute(CD_ORCO, ""); + GPU_link(mat, "generated_texco", GPU_builtin(GPU_VIEW_POSITION), in[0].link, &in[0].link); + } - node_shader_gpu_tex_mapping(mat, node, in, out); + node_shader_gpu_tex_mapping(mat, node, in, out); - NodeTexMusgrave *tex = (NodeTexMusgrave *)node->storage; - float type = tex->musgrave_type; + NodeTexMusgrave *tex = (NodeTexMusgrave *)node->storage; + float type = tex->musgrave_type; - return GPU_stack_link(mat, node, "node_tex_musgrave", in, out, GPU_constant(&type)); + return GPU_stack_link(mat, node, "node_tex_musgrave", in, out, GPU_constant(&type)); } /* node type definition */ void register_node_type_sh_tex_musgrave(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_TEX_MUSGRAVE, "Musgrave Texture", NODE_CLASS_TEXTURE, 0); - node_type_socket_templates(&ntype, sh_node_tex_musgrave_in, sh_node_tex_musgrave_out); - node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); - node_type_init(&ntype, node_shader_init_tex_musgrave); - node_type_storage(&ntype, "NodeTexMusgrave", node_free_standard_storage, node_copy_standard_storage); - node_type_gpu(&ntype, node_shader_gpu_tex_musgrave); + sh_node_type_base(&ntype, SH_NODE_TEX_MUSGRAVE, "Musgrave Texture", NODE_CLASS_TEXTURE, 0); + node_type_socket_templates(&ntype, sh_node_tex_musgrave_in, sh_node_tex_musgrave_out); + node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); + node_type_init(&ntype, node_shader_init_tex_musgrave); + node_type_storage( + &ntype, "NodeTexMusgrave", node_free_standard_storage, node_copy_standard_storage); + node_type_gpu(&ntype, node_shader_gpu_tex_musgrave); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_noise.c b/source/blender/nodes/shader/nodes/node_shader_tex_noise.c index 65ab7e459c6..34c4b17f255 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_noise.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_noise.c @@ -22,50 +22,75 @@ /* **************** NOISE ******************** */ static bNodeSocketTemplate sh_node_tex_noise_in[] = { - { SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { SOCK_FLOAT, 1, N_("Scale"), 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, - { SOCK_FLOAT, 1, N_("Detail"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 16.0f}, - { SOCK_FLOAT, 1, N_("Distortion"), 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, - { -1, 0, "" }, + {SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + {SOCK_FLOAT, 1, N_("Scale"), 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, + {SOCK_FLOAT, 1, N_("Detail"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 16.0f}, + {SOCK_FLOAT, 1, N_("Distortion"), 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_tex_noise_out[] = { - { SOCK_RGBA, 0, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - { SOCK_FLOAT, 0, N_("Fac"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR, SOCK_NO_INTERNAL_LINK}, - { -1, 0, "" }, + {SOCK_RGBA, + 0, + N_("Color"), + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f, + PROP_NONE, + SOCK_NO_INTERNAL_LINK}, + {SOCK_FLOAT, + 0, + N_("Fac"), + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f, + PROP_FACTOR, + SOCK_NO_INTERNAL_LINK}, + {-1, 0, ""}, }; static void node_shader_init_tex_noise(bNodeTree *UNUSED(ntree), bNode *node) { - NodeTexNoise *tex = MEM_callocN(sizeof(NodeTexNoise), "NodeTexNoise"); - BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT); - BKE_texture_colormapping_default(&tex->base.color_mapping); + NodeTexNoise *tex = MEM_callocN(sizeof(NodeTexNoise), "NodeTexNoise"); + BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT); + BKE_texture_colormapping_default(&tex->base.color_mapping); - node->storage = tex; + node->storage = tex; } -static int node_shader_gpu_tex_noise(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_tex_noise(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - if (!in[0].link) { - in[0].link = GPU_attribute(CD_ORCO, ""); - GPU_link(mat, "generated_texco", GPU_builtin(GPU_VIEW_POSITION), in[0].link, &in[0].link); - } + if (!in[0].link) { + in[0].link = GPU_attribute(CD_ORCO, ""); + GPU_link(mat, "generated_texco", GPU_builtin(GPU_VIEW_POSITION), in[0].link, &in[0].link); + } - node_shader_gpu_tex_mapping(mat, node, in, out); + node_shader_gpu_tex_mapping(mat, node, in, out); - return GPU_stack_link(mat, node, "node_tex_noise", in, out); + return GPU_stack_link(mat, node, "node_tex_noise", in, out); } /* node type definition */ void register_node_type_sh_tex_noise(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_TEX_NOISE, "Noise Texture", NODE_CLASS_TEXTURE, 0); - node_type_socket_templates(&ntype, sh_node_tex_noise_in, sh_node_tex_noise_out); - node_type_init(&ntype, node_shader_init_tex_noise); - node_type_storage(&ntype, "NodeTexNoise", node_free_standard_storage, node_copy_standard_storage); - node_type_gpu(&ntype, node_shader_gpu_tex_noise); + sh_node_type_base(&ntype, SH_NODE_TEX_NOISE, "Noise Texture", NODE_CLASS_TEXTURE, 0); + node_type_socket_templates(&ntype, sh_node_tex_noise_in, sh_node_tex_noise_out); + node_type_init(&ntype, node_shader_init_tex_noise); + node_type_storage( + &ntype, "NodeTexNoise", node_free_standard_storage, node_copy_standard_storage); + node_type_gpu(&ntype, node_shader_gpu_tex_noise); - nodeRegisterType(&ntype); + nodeRegisterType(&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 index 56e98520e8b..561f39716b9 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.c @@ -19,72 +19,64 @@ #include "../node_shader_util.h" - #include "RE_render_ext.h" /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_tex_pointdensity_in[] = { - {SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - {-1, 0, ""}, + {SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_tex_pointdensity_out[] = { - {SOCK_RGBA, 0, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - {SOCK_FLOAT, 0, N_("Density"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f}, - {-1, 0, ""}, + {SOCK_RGBA, 0, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 0, N_("Density"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f}, + {-1, 0, ""}, }; -static void node_shader_init_tex_pointdensity(bNodeTree *UNUSED(ntree), - bNode *node) +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; + 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); + 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, 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)); + 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; + 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); + 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); + 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 index 1fa58396733..15db757a9a1 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_sky.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_sky.c @@ -22,51 +22,65 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_tex_sky_in[] = { - { SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { -1, 0, "" }, + {SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_tex_sky_out[] = { - { SOCK_RGBA, 0, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - { -1, 0, "" }, + {SOCK_RGBA, + 0, + N_("Color"), + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f, + PROP_NONE, + SOCK_NO_INTERNAL_LINK}, + {-1, 0, ""}, }; 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->sky_model = SHD_SKY_NEW; + 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->sky_model = SHD_SKY_NEW; - node->storage = tex; + node->storage = tex; } -static int node_shader_gpu_tex_sky(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_tex_sky(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - if (!in[0].link) - in[0].link = GPU_attribute(CD_ORCO, ""); + if (!in[0].link) + in[0].link = GPU_attribute(CD_ORCO, ""); - node_shader_gpu_tex_mapping(mat, node, in, out); + node_shader_gpu_tex_mapping(mat, node, in, out); - return GPU_stack_link(mat, node, "node_tex_sky", in, out); + return GPU_stack_link(mat, node, "node_tex_sky", in, out); } /* node type definition */ void register_node_type_sh_tex_sky(void) { - static bNodeType ntype; + 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); + 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); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c index bd3dc0d2c79..99668741f65 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c @@ -22,75 +22,107 @@ /* **************** VORONOI ******************** */ static bNodeSocketTemplate sh_node_tex_voronoi_in[] = { - { SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { SOCK_FLOAT, 1, N_("Scale"), 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, - { SOCK_FLOAT, 1, N_("Exponent"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 32.0f}, - { -1, 0, "" }, + {SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + {SOCK_FLOAT, 1, N_("Scale"), 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, + {SOCK_FLOAT, 1, N_("Exponent"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 32.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_tex_voronoi_out[] = { - { SOCK_RGBA, 0, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - { SOCK_FLOAT, 0, N_("Fac"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR, SOCK_NO_INTERNAL_LINK}, - { -1, 0, "" }, + {SOCK_RGBA, + 0, + N_("Color"), + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f, + PROP_NONE, + SOCK_NO_INTERNAL_LINK}, + {SOCK_FLOAT, + 0, + N_("Fac"), + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f, + PROP_FACTOR, + SOCK_NO_INTERNAL_LINK}, + {-1, 0, ""}, }; static void node_shader_init_tex_voronoi(bNodeTree *UNUSED(ntree), bNode *node) { - NodeTexVoronoi *tex = MEM_callocN(sizeof(NodeTexVoronoi), "NodeTexVoronoi"); - BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT); - BKE_texture_colormapping_default(&tex->base.color_mapping); - tex->coloring = SHD_VORONOI_INTENSITY; - tex->distance = SHD_VORONOI_DISTANCE; - tex->feature = SHD_VORONOI_F1; + NodeTexVoronoi *tex = MEM_callocN(sizeof(NodeTexVoronoi), "NodeTexVoronoi"); + BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT); + BKE_texture_colormapping_default(&tex->base.color_mapping); + tex->coloring = SHD_VORONOI_INTENSITY; + tex->distance = SHD_VORONOI_DISTANCE; + tex->feature = SHD_VORONOI_F1; - node->storage = tex; + node->storage = tex; } -static int node_shader_gpu_tex_voronoi(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_tex_voronoi(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - if (!in[0].link) { - in[0].link = GPU_attribute(CD_ORCO, ""); - GPU_link(mat, "generated_texco", GPU_builtin(GPU_VIEW_POSITION), in[0].link, &in[0].link); - } + if (!in[0].link) { + in[0].link = GPU_attribute(CD_ORCO, ""); + GPU_link(mat, "generated_texco", GPU_builtin(GPU_VIEW_POSITION), in[0].link, &in[0].link); + } - node_shader_gpu_tex_mapping(mat, node, in, out); + node_shader_gpu_tex_mapping(mat, node, in, out); - NodeTexVoronoi *tex = (NodeTexVoronoi *)node->storage; - float coloring = tex->coloring; - float metric = tex->distance; - float feature = tex->feature; + NodeTexVoronoi *tex = (NodeTexVoronoi *)node->storage; + float coloring = tex->coloring; + float metric = tex->distance; + float feature = tex->feature; - return GPU_stack_link(mat, node, "node_tex_voronoi", in, out, GPU_constant(&coloring), GPU_constant(&metric), GPU_constant(&feature)); + return GPU_stack_link(mat, + node, + "node_tex_voronoi", + in, + out, + GPU_constant(&coloring), + GPU_constant(&metric), + GPU_constant(&feature)); } static void node_shader_update_tex_voronoi(bNodeTree *UNUSED(ntree), bNode *node) { - NodeTexVoronoi *tex = (NodeTexVoronoi *)node->storage; - bNodeSocket *sock; + NodeTexVoronoi *tex = (NodeTexVoronoi *)node->storage; + bNodeSocket *sock; - for (sock = node->inputs.first; sock; sock = sock->next) { - if (STREQ(sock->name, "Exponent")) { - if (tex->distance == SHD_VORONOI_MINKOWSKI) { - sock->flag &= ~SOCK_UNAVAIL; - } - else { - sock->flag |= SOCK_UNAVAIL; - } - } - } + for (sock = node->inputs.first; sock; sock = sock->next) { + if (STREQ(sock->name, "Exponent")) { + if (tex->distance == SHD_VORONOI_MINKOWSKI) { + sock->flag &= ~SOCK_UNAVAIL; + } + else { + sock->flag |= SOCK_UNAVAIL; + } + } + } } /* node type definition */ void register_node_type_sh_tex_voronoi(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_TEX_VORONOI, "Voronoi Texture", NODE_CLASS_TEXTURE, 0); - node_type_socket_templates(&ntype, sh_node_tex_voronoi_in, sh_node_tex_voronoi_out); - node_type_init(&ntype, node_shader_init_tex_voronoi); - node_type_storage(&ntype, "NodeTexVoronoi", node_free_standard_storage, node_copy_standard_storage); - node_type_gpu(&ntype, node_shader_gpu_tex_voronoi); - node_type_update(&ntype, node_shader_update_tex_voronoi, NULL); + sh_node_type_base(&ntype, SH_NODE_TEX_VORONOI, "Voronoi Texture", NODE_CLASS_TEXTURE, 0); + node_type_socket_templates(&ntype, sh_node_tex_voronoi_in, sh_node_tex_voronoi_out); + node_type_init(&ntype, node_shader_init_tex_voronoi); + node_type_storage( + &ntype, "NodeTexVoronoi", node_free_standard_storage, node_copy_standard_storage); + node_type_gpu(&ntype, node_shader_gpu_tex_voronoi); + node_type_update(&ntype, node_shader_update_tex_voronoi, NULL); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_wave.c b/source/blender/nodes/shader/nodes/node_shader_tex_wave.c index 660fc0fdcae..65b78f2923d 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_wave.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_wave.c @@ -22,57 +22,82 @@ /* **************** WAVE ******************** */ static bNodeSocketTemplate sh_node_tex_wave_in[] = { - { SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { SOCK_FLOAT, 1, N_("Scale"), 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, - { SOCK_FLOAT, 1, N_("Distortion"), 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, - { SOCK_FLOAT, 1, N_("Detail"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 16.0f}, - { SOCK_FLOAT, 1, N_("Detail Scale"), 1.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, - { -1, 0, "" }, + {SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + {SOCK_FLOAT, 1, N_("Scale"), 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, + {SOCK_FLOAT, 1, N_("Distortion"), 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, + {SOCK_FLOAT, 1, N_("Detail"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 16.0f}, + {SOCK_FLOAT, 1, N_("Detail Scale"), 1.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_tex_wave_out[] = { - { SOCK_RGBA, 0, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - { SOCK_FLOAT, 0, N_("Fac"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR, SOCK_NO_INTERNAL_LINK}, - { -1, 0, "" }, + {SOCK_RGBA, + 0, + N_("Color"), + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f, + PROP_NONE, + SOCK_NO_INTERNAL_LINK}, + {SOCK_FLOAT, + 0, + N_("Fac"), + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1.0f, + PROP_FACTOR, + SOCK_NO_INTERNAL_LINK}, + {-1, 0, ""}, }; static void node_shader_init_tex_wave(bNodeTree *UNUSED(ntree), bNode *node) { - NodeTexWave *tex = MEM_callocN(sizeof(NodeTexWave), "NodeTexWave"); - BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT); - BKE_texture_colormapping_default(&tex->base.color_mapping); - tex->wave_type = SHD_WAVE_BANDS; + NodeTexWave *tex = MEM_callocN(sizeof(NodeTexWave), "NodeTexWave"); + BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT); + BKE_texture_colormapping_default(&tex->base.color_mapping); + tex->wave_type = SHD_WAVE_BANDS; - node->storage = tex; + node->storage = tex; } -static int node_shader_gpu_tex_wave(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_tex_wave(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - if (!in[0].link) { - in[0].link = GPU_attribute(CD_ORCO, ""); - GPU_link(mat, "generated_texco", GPU_builtin(GPU_VIEW_POSITION), in[0].link, &in[0].link); - } + if (!in[0].link) { + in[0].link = GPU_attribute(CD_ORCO, ""); + GPU_link(mat, "generated_texco", GPU_builtin(GPU_VIEW_POSITION), in[0].link, &in[0].link); + } - node_shader_gpu_tex_mapping(mat, node, in, out); + node_shader_gpu_tex_mapping(mat, node, in, out); - NodeTexWave *tex = (NodeTexWave *)node->storage; - float wave_type = tex->wave_type; - float wave_profile = tex->wave_profile; + NodeTexWave *tex = (NodeTexWave *)node->storage; + float wave_type = tex->wave_type; + float wave_profile = tex->wave_profile; - return GPU_stack_link(mat, node, "node_tex_wave", in, out, GPU_constant(&wave_type), GPU_constant(&wave_profile)); + return GPU_stack_link( + mat, node, "node_tex_wave", in, out, GPU_constant(&wave_type), GPU_constant(&wave_profile)); } /* node type definition */ void register_node_type_sh_tex_wave(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_TEX_WAVE, "Wave Texture", NODE_CLASS_TEXTURE, 0); - node_type_socket_templates(&ntype, sh_node_tex_wave_in, sh_node_tex_wave_out); - node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); - node_type_init(&ntype, node_shader_init_tex_wave); - node_type_storage(&ntype, "NodeTexWave", node_free_standard_storage, node_copy_standard_storage); - node_type_gpu(&ntype, node_shader_gpu_tex_wave); + sh_node_type_base(&ntype, SH_NODE_TEX_WAVE, "Wave Texture", NODE_CLASS_TEXTURE, 0); + node_type_socket_templates(&ntype, sh_node_tex_wave_in, sh_node_tex_wave_out); + node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); + node_type_init(&ntype, node_shader_init_tex_wave); + node_type_storage(&ntype, "NodeTexWave", node_free_standard_storage, node_copy_standard_storage); + node_type_gpu(&ntype, node_shader_gpu_tex_wave); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_uvAlongStroke.c b/source/blender/nodes/shader/nodes/node_shader_uvAlongStroke.c index 1f70b845fed..77bc133b638 100644 --- a/source/blender/nodes/shader/nodes/node_shader_uvAlongStroke.c +++ b/source/blender/nodes/shader/nodes/node_shader_uvAlongStroke.c @@ -22,18 +22,18 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_uvalongstroke_out[] = { - { SOCK_VECTOR, 0, N_("UV"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_VECTOR, 0, N_("UV"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; /* node type definition */ void register_node_type_sh_uvalongstroke(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_UVALONGSTROKE, "UV Along Stroke", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, NULL, sh_node_uvalongstroke_out); - node_type_init(&ntype, NULL); + sh_node_type_base(&ntype, SH_NODE_UVALONGSTROKE, "UV Along Stroke", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, NULL, sh_node_uvalongstroke_out); + node_type_init(&ntype, NULL); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_uvmap.c b/source/blender/nodes/shader/nodes/node_shader_uvmap.c index d2c2341414c..73fb022e476 100644 --- a/source/blender/nodes/shader/nodes/node_shader_uvmap.c +++ b/source/blender/nodes/shader/nodes/node_shader_uvmap.c @@ -24,35 +24,40 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_uvmap_out[] = { - { SOCK_VECTOR, 0, N_("UV"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_VECTOR, 0, N_("UV"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; static void node_shader_init_uvmap(bNodeTree *UNUSED(ntree), bNode *node) { - NodeShaderUVMap *attr = MEM_callocN(sizeof(NodeShaderUVMap), "NodeShaderUVMap"); - node->storage = attr; + NodeShaderUVMap *attr = MEM_callocN(sizeof(NodeShaderUVMap), "NodeShaderUVMap"); + node->storage = attr; } -static int node_shader_gpu_uvmap(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_uvmap(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - NodeShaderUVMap *attr = node->storage; - GPUNodeLink *mtface = GPU_attribute(CD_MTFACE, attr->uv_map); + NodeShaderUVMap *attr = node->storage; + GPUNodeLink *mtface = GPU_attribute(CD_MTFACE, attr->uv_map); - return GPU_stack_link(mat, node, "node_uvmap", in, out, mtface); + return GPU_stack_link(mat, node, "node_uvmap", in, out, mtface); } /* node type definition */ void register_node_type_sh_uvmap(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_UVMAP, "UV Map", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, NULL, sh_node_uvmap_out); - node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); - node_type_init(&ntype, node_shader_init_uvmap); - node_type_storage(&ntype, "NodeShaderUVMap", node_free_standard_storage, node_copy_standard_storage); - node_type_gpu(&ntype, node_shader_gpu_uvmap); + sh_node_type_base(&ntype, SH_NODE_UVMAP, "UV Map", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, NULL, sh_node_uvmap_out); + node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); + node_type_init(&ntype, node_shader_init_uvmap); + node_type_storage( + &ntype, "NodeShaderUVMap", node_free_standard_storage, node_copy_standard_storage); + node_type_gpu(&ntype, node_shader_gpu_uvmap); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_valToRgb.c b/source/blender/nodes/shader/nodes/node_shader_valToRgb.c index 51093cd67ad..6d2611626c2 100644 --- a/source/blender/nodes/shader/nodes/node_shader_valToRgb.c +++ b/source/blender/nodes/shader/nodes/node_shader_valToRgb.c @@ -21,127 +21,148 @@ * \ingroup shdnodes */ - #include "node_shader_util.h" #include "IMB_colormanagement.h" /* **************** VALTORGB ******************** */ static bNodeSocketTemplate sh_node_valtorgb_in[] = { - { SOCK_FLOAT, 1, N_("Fac"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Fac"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_valtorgb_out[] = { - { SOCK_RGBA, 0, N_("Color")}, - { SOCK_FLOAT, 0, N_("Alpha")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color")}, + {SOCK_FLOAT, 0, N_("Alpha")}, + {-1, 0, ""}, }; -static void node_shader_exec_valtorgb(void *UNUSED(data), int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) +static void node_shader_exec_valtorgb(void *UNUSED(data), + int UNUSED(thread), + bNode *node, + bNodeExecData *UNUSED(execdata), + bNodeStack **in, + bNodeStack **out) { - /* stack order in: fac */ - /* stack order out: col, alpha */ + /* stack order in: fac */ + /* stack order out: col, alpha */ - if (node->storage) { - float fac; - nodestack_get_vec(&fac, SOCK_FLOAT, in[0]); + if (node->storage) { + float fac; + nodestack_get_vec(&fac, SOCK_FLOAT, in[0]); - BKE_colorband_evaluate(node->storage, fac, out[0]->vec); - out[1]->vec[0] = out[0]->vec[3]; - } + BKE_colorband_evaluate(node->storage, fac, out[0]->vec); + out[1]->vec[0] = out[0]->vec[3]; + } } static void node_shader_init_valtorgb(bNodeTree *UNUSED(ntree), bNode *node) { - node->storage = BKE_colorband_add(true); + node->storage = BKE_colorband_add(true); } -static int gpu_shader_valtorgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_valtorgb(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - struct ColorBand *coba = node->storage; - float *array, layer; - int size; - - /* Common / easy case optimisation. */ - if ((coba->tot <= 2) && (coba->color_mode == COLBAND_BLEND_RGB)) { - float mul_bias[2]; - switch (coba->ipotype) { - case COLBAND_INTERP_LINEAR: - mul_bias[0] = 1.0f / (coba->data[1].pos - coba->data[0].pos); - mul_bias[1] = -mul_bias[0] * coba->data[0].pos; - return GPU_stack_link(mat, node, "valtorgb_opti_linear", in, out, GPU_uniform(mul_bias), - GPU_uniform(&coba->data[0].r), - GPU_uniform(&coba->data[1].r)); - case COLBAND_INTERP_CONSTANT: - mul_bias[1] = max_ff(coba->data[0].pos, coba->data[1].pos); - return GPU_stack_link(mat, node, "valtorgb_opti_constant", in, out, GPU_uniform(&mul_bias[1]), - GPU_uniform(&coba->data[0].r), - GPU_uniform(&coba->data[1].r)); - default: - break; - } - } - - BKE_colorband_evaluate_table_rgba(coba, &array, &size); - GPUNodeLink *tex = GPU_color_band(mat, size, array, &layer); - - if (coba->ipotype == COLBAND_INTERP_CONSTANT) { - return GPU_stack_link(mat, node, "valtorgb_nearest", in, out, tex, GPU_constant(&layer)); - } - else { - return GPU_stack_link(mat, node, "valtorgb", in, out, tex, GPU_constant(&layer)); - } + struct ColorBand *coba = node->storage; + float *array, layer; + int size; + + /* Common / easy case optimisation. */ + if ((coba->tot <= 2) && (coba->color_mode == COLBAND_BLEND_RGB)) { + float mul_bias[2]; + switch (coba->ipotype) { + case COLBAND_INTERP_LINEAR: + mul_bias[0] = 1.0f / (coba->data[1].pos - coba->data[0].pos); + mul_bias[1] = -mul_bias[0] * coba->data[0].pos; + return GPU_stack_link(mat, + node, + "valtorgb_opti_linear", + in, + out, + GPU_uniform(mul_bias), + GPU_uniform(&coba->data[0].r), + GPU_uniform(&coba->data[1].r)); + case COLBAND_INTERP_CONSTANT: + mul_bias[1] = max_ff(coba->data[0].pos, coba->data[1].pos); + return GPU_stack_link(mat, + node, + "valtorgb_opti_constant", + in, + out, + GPU_uniform(&mul_bias[1]), + GPU_uniform(&coba->data[0].r), + GPU_uniform(&coba->data[1].r)); + default: + break; + } + } + + BKE_colorband_evaluate_table_rgba(coba, &array, &size); + GPUNodeLink *tex = GPU_color_band(mat, size, array, &layer); + + if (coba->ipotype == COLBAND_INTERP_CONSTANT) { + return GPU_stack_link(mat, node, "valtorgb_nearest", in, out, tex, GPU_constant(&layer)); + } + else { + return GPU_stack_link(mat, node, "valtorgb", in, out, tex, GPU_constant(&layer)); + } } void register_node_type_sh_valtorgb(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, sh_node_valtorgb_in, sh_node_valtorgb_out); - node_type_init(&ntype, node_shader_init_valtorgb); - node_type_size_preset(&ntype, NODE_SIZE_LARGE); - node_type_storage(&ntype, "ColorBand", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_valtorgb); - node_type_gpu(&ntype, gpu_shader_valtorgb); + sh_node_type_base(&ntype, SH_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, sh_node_valtorgb_in, sh_node_valtorgb_out); + node_type_init(&ntype, node_shader_init_valtorgb); + node_type_size_preset(&ntype, NODE_SIZE_LARGE); + node_type_storage(&ntype, "ColorBand", node_free_standard_storage, node_copy_standard_storage); + node_type_exec(&ntype, NULL, NULL, node_shader_exec_valtorgb); + node_type_gpu(&ntype, gpu_shader_valtorgb); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } - /* **************** RGBTOBW ******************** */ static bNodeSocketTemplate sh_node_rgbtobw_in[] = { - { SOCK_RGBA, 1, N_("Color"), 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; + {SOCK_RGBA, 1, N_("Color"), 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f}, {-1, 0, ""}}; static bNodeSocketTemplate sh_node_rgbtobw_out[] = { - { SOCK_FLOAT, 0, N_("Val"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - - -static void node_shader_exec_rgbtobw(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) + {SOCK_FLOAT, 0, N_("Val"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, {-1, 0, ""}}; + +static void node_shader_exec_rgbtobw(void *UNUSED(data), + int UNUSED(thread), + bNode *UNUSED(node), + bNodeExecData *UNUSED(execdata), + bNodeStack **in, + bNodeStack **out) { - /* stack order out: bw */ - /* stack order in: col */ - float col[3]; - nodestack_get_vec(col, SOCK_VECTOR, in[0]); + /* stack order out: bw */ + /* stack order in: col */ + float col[3]; + nodestack_get_vec(col, SOCK_VECTOR, in[0]); - out[0]->vec[0] = IMB_colormanagement_get_luminance(col); + out[0]->vec[0] = IMB_colormanagement_get_luminance(col); } -static int gpu_shader_rgbtobw(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_rgbtobw(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "rgbtobw", in, out); + return GPU_stack_link(mat, node, "rgbtobw", in, out); } void register_node_type_sh_rgbtobw(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, sh_node_rgbtobw_in, sh_node_rgbtobw_out); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_rgbtobw); - node_type_gpu(&ntype, gpu_shader_rgbtobw); + sh_node_type_base(&ntype, SH_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, sh_node_rgbtobw_in, sh_node_rgbtobw_out); + node_type_exec(&ntype, NULL, NULL, node_shader_exec_rgbtobw); + node_type_gpu(&ntype, gpu_shader_rgbtobw); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_value.c b/source/blender/nodes/shader/nodes/node_shader_value.c index 6e3428bbdd1..6311dabb5b8 100644 --- a/source/blender/nodes/shader/nodes/node_shader_value.c +++ b/source/blender/nodes/shader/nodes/node_shader_value.c @@ -21,28 +21,31 @@ * \ingroup shdnodes */ - #include "node_shader_util.h" /* **************** VALUE ******************** */ static bNodeSocketTemplate sh_node_value_out[] = { - { SOCK_FLOAT, 0, N_("Value"), 0.5f, 0, 0, 0, -FLT_MAX, FLT_MAX, PROP_NONE}, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("Value"), 0.5f, 0, 0, 0, -FLT_MAX, FLT_MAX, PROP_NONE}, + {-1, 0, ""}, }; -static int gpu_shader_value(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_value(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - GPUNodeLink *link = GPU_uniformbuffer_link_out(mat, node, out, 0); - return GPU_stack_link(mat, node, "set_value", in, out, link); + GPUNodeLink *link = GPU_uniformbuffer_link_out(mat, node, out, 0); + return GPU_stack_link(mat, node, "set_value", in, out, link); } void register_node_type_sh_value(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_VALUE, "Value", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, NULL, sh_node_value_out); - node_type_gpu(&ntype, gpu_shader_value); + sh_node_type_base(&ntype, SH_NODE_VALUE, "Value", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, NULL, sh_node_value_out); + node_type_gpu(&ntype, gpu_shader_value); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_vectMath.c b/source/blender/nodes/shader/nodes/node_shader_vectMath.c index 5d6c1b6cd4f..c6b74e2a727 100644 --- a/source/blender/nodes/shader/nodes/node_shader_vectMath.c +++ b/source/blender/nodes/shader/nodes/node_shader_vectMath.c @@ -25,121 +25,131 @@ /* **************** VECTOR MATH ******************** */ static bNodeSocketTemplate sh_node_vect_math_in[] = { - { SOCK_VECTOR, 1, N_("Vector"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, - { SOCK_VECTOR, 1, N_("Vector"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, - { -1, 0, "" } -}; + {SOCK_VECTOR, 1, N_("Vector"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, + {SOCK_VECTOR, 1, N_("Vector"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, + {-1, 0, ""}}; static bNodeSocketTemplate sh_node_vect_math_out[] = { - { SOCK_VECTOR, 0, N_("Vector")}, - { SOCK_FLOAT, 0, N_("Value")}, - { -1, 0, "" } -}; - -static void node_shader_exec_vect_math(void *UNUSED(data), int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) + {SOCK_VECTOR, 0, N_("Vector")}, {SOCK_FLOAT, 0, N_("Value")}, {-1, 0, ""}}; + +static void node_shader_exec_vect_math(void *UNUSED(data), + int UNUSED(thread), + bNode *node, + bNodeExecData *UNUSED(execdata), + bNodeStack **in, + bNodeStack **out) { - float vec1[3], vec2[3]; - - nodestack_get_vec(vec1, SOCK_VECTOR, in[0]); - nodestack_get_vec(vec2, SOCK_VECTOR, in[1]); - - if (node->custom1 == 0) { /* Add */ - out[0]->vec[0] = vec1[0] + vec2[0]; - out[0]->vec[1] = vec1[1] + vec2[1]; - out[0]->vec[2] = vec1[2] + vec2[2]; - - out[1]->vec[0] = (fabsf(out[0]->vec[0]) + fabsf(out[0]->vec[1]) + fabsf(out[0]->vec[2])) / 3.0f; - } - else if (node->custom1 == 1) { /* Subtract */ - out[0]->vec[0] = vec1[0] - vec2[0]; - out[0]->vec[1] = vec1[1] - vec2[1]; - out[0]->vec[2] = vec1[2] - vec2[2]; - - out[1]->vec[0] = (fabsf(out[0]->vec[0]) + fabsf(out[0]->vec[1]) + fabsf(out[0]->vec[2])) / 3.0f; - } - else if (node->custom1 == 2) { /* Average */ - out[0]->vec[0] = vec1[0] + vec2[0]; - out[0]->vec[1] = vec1[1] + vec2[1]; - out[0]->vec[2] = vec1[2] + vec2[2]; - - out[1]->vec[0] = normalize_v3(out[0]->vec); - } - else if (node->custom1 == 3) { /* Dot product */ - out[1]->vec[0] = (vec1[0] * vec2[0]) + (vec1[1] * vec2[1]) + (vec1[2] * vec2[2]); - } - else if (node->custom1 == 4) { /* Cross product */ - out[0]->vec[0] = (vec1[1] * vec2[2]) - (vec1[2] * vec2[1]); - out[0]->vec[1] = (vec1[2] * vec2[0]) - (vec1[0] * vec2[2]); - out[0]->vec[2] = (vec1[0] * vec2[1]) - (vec1[1] * vec2[0]); - - out[1]->vec[0] = normalize_v3(out[0]->vec); - } - else if (node->custom1 == 5) { /* Normalize */ - if (in[0]->hasinput || !in[1]->hasinput) { /* This one only takes one input, so we've got to choose. */ - out[0]->vec[0] = vec1[0]; - out[0]->vec[1] = vec1[1]; - out[0]->vec[2] = vec1[2]; - } - else { - out[0]->vec[0] = vec2[0]; - out[0]->vec[1] = vec2[1]; - out[0]->vec[2] = vec2[2]; - } - - out[1]->vec[0] = normalize_v3(out[0]->vec); - } - + float vec1[3], vec2[3]; + + nodestack_get_vec(vec1, SOCK_VECTOR, in[0]); + nodestack_get_vec(vec2, SOCK_VECTOR, in[1]); + + if (node->custom1 == 0) { /* Add */ + out[0]->vec[0] = vec1[0] + vec2[0]; + out[0]->vec[1] = vec1[1] + vec2[1]; + out[0]->vec[2] = vec1[2] + vec2[2]; + + out[1]->vec[0] = (fabsf(out[0]->vec[0]) + fabsf(out[0]->vec[1]) + fabsf(out[0]->vec[2])) / + 3.0f; + } + else if (node->custom1 == 1) { /* Subtract */ + out[0]->vec[0] = vec1[0] - vec2[0]; + out[0]->vec[1] = vec1[1] - vec2[1]; + out[0]->vec[2] = vec1[2] - vec2[2]; + + out[1]->vec[0] = (fabsf(out[0]->vec[0]) + fabsf(out[0]->vec[1]) + fabsf(out[0]->vec[2])) / + 3.0f; + } + else if (node->custom1 == 2) { /* Average */ + out[0]->vec[0] = vec1[0] + vec2[0]; + out[0]->vec[1] = vec1[1] + vec2[1]; + out[0]->vec[2] = vec1[2] + vec2[2]; + + out[1]->vec[0] = normalize_v3(out[0]->vec); + } + else if (node->custom1 == 3) { /* Dot product */ + out[1]->vec[0] = (vec1[0] * vec2[0]) + (vec1[1] * vec2[1]) + (vec1[2] * vec2[2]); + } + else if (node->custom1 == 4) { /* Cross product */ + out[0]->vec[0] = (vec1[1] * vec2[2]) - (vec1[2] * vec2[1]); + out[0]->vec[1] = (vec1[2] * vec2[0]) - (vec1[0] * vec2[2]); + out[0]->vec[2] = (vec1[0] * vec2[1]) - (vec1[1] * vec2[0]); + + out[1]->vec[0] = normalize_v3(out[0]->vec); + } + else if (node->custom1 == 5) { /* Normalize */ + if (in[0]->hasinput || + !in[1]->hasinput) { /* This one only takes one input, so we've got to choose. */ + out[0]->vec[0] = vec1[0]; + out[0]->vec[1] = vec1[1]; + out[0]->vec[2] = vec1[2]; + } + else { + out[0]->vec[0] = vec2[0]; + out[0]->vec[1] = vec2[1]; + out[0]->vec[2] = vec2[2]; + } + + out[1]->vec[0] = normalize_v3(out[0]->vec); + } } -static int gpu_shader_vect_math(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_vect_math(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - static const char *names[] = { - "vec_math_add", "vec_math_sub", - "vec_math_average", "vec_math_dot", "vec_math_cross", - "vec_math_normalize", - }; - - switch (node->custom1) { - case 0: - case 1: - case 2: - case 3: - case 4: - GPU_stack_link(mat, node, names[node->custom1], in, out); - break; - case 5: - if (in[0].hasinput || !in[1].hasinput) { - /* use only first item and terminator */ - GPUNodeStack tmp_in[2]; - memcpy(&tmp_in[0], &in[0], sizeof(GPUNodeStack)); - memcpy(&tmp_in[1], &in[2], sizeof(GPUNodeStack)); - GPU_stack_link(mat, node, names[node->custom1], tmp_in, out); - } - else { - /* use only second item and terminator */ - GPUNodeStack tmp_in[2]; - memcpy(&tmp_in[0], &in[1], sizeof(GPUNodeStack)); - memcpy(&tmp_in[1], &in[2], sizeof(GPUNodeStack)); - GPU_stack_link(mat, node, names[node->custom1], tmp_in, out); - } - break; - default: - return false; - } - - return true; + static const char *names[] = { + "vec_math_add", + "vec_math_sub", + "vec_math_average", + "vec_math_dot", + "vec_math_cross", + "vec_math_normalize", + }; + + switch (node->custom1) { + case 0: + case 1: + case 2: + case 3: + case 4: + GPU_stack_link(mat, node, names[node->custom1], in, out); + break; + case 5: + if (in[0].hasinput || !in[1].hasinput) { + /* use only first item and terminator */ + GPUNodeStack tmp_in[2]; + memcpy(&tmp_in[0], &in[0], sizeof(GPUNodeStack)); + memcpy(&tmp_in[1], &in[2], sizeof(GPUNodeStack)); + GPU_stack_link(mat, node, names[node->custom1], tmp_in, out); + } + else { + /* use only second item and terminator */ + GPUNodeStack tmp_in[2]; + memcpy(&tmp_in[0], &in[1], sizeof(GPUNodeStack)); + memcpy(&tmp_in[1], &in[2], sizeof(GPUNodeStack)); + GPU_stack_link(mat, node, names[node->custom1], tmp_in, out); + } + break; + default: + return false; + } + + return true; } void register_node_type_sh_vect_math(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_VECT_MATH, "Vector Math", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, sh_node_vect_math_in, sh_node_vect_math_out); - node_type_label(&ntype, node_vect_math_label); - node_type_storage(&ntype, "", NULL, NULL); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_vect_math); - node_type_gpu(&ntype, gpu_shader_vect_math); + sh_node_type_base(&ntype, SH_NODE_VECT_MATH, "Vector Math", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, sh_node_vect_math_in, sh_node_vect_math_out); + node_type_label(&ntype, node_vect_math_label); + node_type_storage(&ntype, "", NULL, NULL); + node_type_exec(&ntype, NULL, NULL, node_shader_exec_vect_math); + node_type_gpu(&ntype, gpu_shader_vect_math); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_vectTransform.c b/source/blender/nodes/shader/nodes/node_shader_vectTransform.c index 66def025bff..19cc9f2ce55 100644 --- a/source/blender/nodes/shader/nodes/node_shader_vectTransform.c +++ b/source/blender/nodes/shader/nodes/node_shader_vectTransform.c @@ -25,114 +25,124 @@ /* **************** Vector Transform ******************** */ static bNodeSocketTemplate sh_node_vect_transform_in[] = { - { SOCK_VECTOR, 1, N_("Vector"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, - { -1, 0, "" } -}; + {SOCK_VECTOR, 1, N_("Vector"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, + {-1, 0, ""}}; -static bNodeSocketTemplate sh_node_vect_transform_out[] = { - { SOCK_VECTOR, 0, N_("Vector")}, - { -1, 0, "" } -}; +static bNodeSocketTemplate sh_node_vect_transform_out[] = {{SOCK_VECTOR, 0, N_("Vector")}, + {-1, 0, ""}}; static void node_shader_init_vect_transform(bNodeTree *UNUSED(ntree), bNode *node) { - NodeShaderVectTransform *vect = MEM_callocN(sizeof(NodeShaderVectTransform), "NodeShaderVectTransform"); + NodeShaderVectTransform *vect = MEM_callocN(sizeof(NodeShaderVectTransform), + "NodeShaderVectTransform"); - /* Convert World into Object Space per default */ - vect->convert_to = 1; + /* Convert World into Object Space per default */ + vect->convert_to = 1; - node->storage = vect; + node->storage = vect; } -static void node_shader_exec_vect_transform(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out)) +static void node_shader_exec_vect_transform(void *UNUSED(data), + int UNUSED(thread), + bNode *UNUSED(node), + bNodeExecData *UNUSED(execdata), + bNodeStack **UNUSED(in), + bNodeStack **UNUSED(out)) { } static GPUNodeLink *get_gpulink_matrix_from_to(short from, short to) { - switch (from) { - case SHD_VECT_TRANSFORM_SPACE_OBJECT: - switch (to) { - case SHD_VECT_TRANSFORM_SPACE_OBJECT: - return NULL; - case SHD_VECT_TRANSFORM_SPACE_WORLD: - return GPU_builtin(GPU_OBJECT_MATRIX); - case SHD_VECT_TRANSFORM_SPACE_CAMERA: - return GPU_builtin(GPU_LOC_TO_VIEW_MATRIX); - } - break; - case SHD_VECT_TRANSFORM_SPACE_WORLD: - switch (to) { - case SHD_VECT_TRANSFORM_SPACE_WORLD: - return NULL; - case SHD_VECT_TRANSFORM_SPACE_CAMERA: - return GPU_builtin(GPU_VIEW_MATRIX); - case SHD_VECT_TRANSFORM_SPACE_OBJECT: - return GPU_builtin(GPU_INVERSE_OBJECT_MATRIX); - } - break; - case SHD_VECT_TRANSFORM_SPACE_CAMERA: - switch (to) { - case SHD_VECT_TRANSFORM_SPACE_CAMERA: - return NULL; - case SHD_VECT_TRANSFORM_SPACE_WORLD: - return GPU_builtin(GPU_INVERSE_VIEW_MATRIX); - case SHD_VECT_TRANSFORM_SPACE_OBJECT: - return GPU_builtin(GPU_INVERSE_LOC_TO_VIEW_MATRIX); - } - break; - } - return NULL; + switch (from) { + case SHD_VECT_TRANSFORM_SPACE_OBJECT: + switch (to) { + case SHD_VECT_TRANSFORM_SPACE_OBJECT: + return NULL; + case SHD_VECT_TRANSFORM_SPACE_WORLD: + return GPU_builtin(GPU_OBJECT_MATRIX); + case SHD_VECT_TRANSFORM_SPACE_CAMERA: + return GPU_builtin(GPU_LOC_TO_VIEW_MATRIX); + } + break; + case SHD_VECT_TRANSFORM_SPACE_WORLD: + switch (to) { + case SHD_VECT_TRANSFORM_SPACE_WORLD: + return NULL; + case SHD_VECT_TRANSFORM_SPACE_CAMERA: + return GPU_builtin(GPU_VIEW_MATRIX); + case SHD_VECT_TRANSFORM_SPACE_OBJECT: + return GPU_builtin(GPU_INVERSE_OBJECT_MATRIX); + } + break; + case SHD_VECT_TRANSFORM_SPACE_CAMERA: + switch (to) { + case SHD_VECT_TRANSFORM_SPACE_CAMERA: + return NULL; + case SHD_VECT_TRANSFORM_SPACE_WORLD: + return GPU_builtin(GPU_INVERSE_VIEW_MATRIX); + case SHD_VECT_TRANSFORM_SPACE_OBJECT: + return GPU_builtin(GPU_INVERSE_LOC_TO_VIEW_MATRIX); + } + break; + } + return NULL; } -static int gpu_shader_vect_transform(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_vect_transform(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - struct GPUNodeLink *inputlink; - struct GPUNodeLink *fromto; - - const char *vtransform = "direction_transform_m4v3"; - const char *ptransform = "point_transform_m4v3"; - const char *func_name = 0; - - NodeShaderVectTransform *nodeprop = (NodeShaderVectTransform *)node->storage; - - if (in[0].hasinput) - inputlink = in[0].link; - else - inputlink = GPU_constant(in[0].vec); - - fromto = get_gpulink_matrix_from_to(nodeprop->convert_from, nodeprop->convert_to); - - func_name = (nodeprop->type == SHD_VECT_TRANSFORM_TYPE_POINT) ? ptransform : vtransform; - if (fromto) { - /* For cycles we have inverted Z */ - /* TODO: pass here the correct matrices */ - if (nodeprop->convert_from == SHD_VECT_TRANSFORM_SPACE_CAMERA && nodeprop->convert_to != SHD_VECT_TRANSFORM_SPACE_CAMERA) { - GPU_link(mat, "invert_z", inputlink, &inputlink); - } - GPU_link(mat, func_name, inputlink, fromto, &out[0].link); - if (nodeprop->convert_to == SHD_VECT_TRANSFORM_SPACE_CAMERA && nodeprop->convert_from != SHD_VECT_TRANSFORM_SPACE_CAMERA) { - GPU_link(mat, "invert_z", out[0].link, &out[0].link); - } - } - else - GPU_link(mat, "set_rgb", inputlink, &out[0].link); - - if (nodeprop->type == SHD_VECT_TRANSFORM_TYPE_NORMAL) - GPU_link(mat, "vect_normalize", out[0].link, &out[0].link); - - return true; + struct GPUNodeLink *inputlink; + struct GPUNodeLink *fromto; + + const char *vtransform = "direction_transform_m4v3"; + const char *ptransform = "point_transform_m4v3"; + const char *func_name = 0; + + NodeShaderVectTransform *nodeprop = (NodeShaderVectTransform *)node->storage; + + if (in[0].hasinput) + inputlink = in[0].link; + else + inputlink = GPU_constant(in[0].vec); + + fromto = get_gpulink_matrix_from_to(nodeprop->convert_from, nodeprop->convert_to); + + func_name = (nodeprop->type == SHD_VECT_TRANSFORM_TYPE_POINT) ? ptransform : vtransform; + if (fromto) { + /* For cycles we have inverted Z */ + /* TODO: pass here the correct matrices */ + if (nodeprop->convert_from == SHD_VECT_TRANSFORM_SPACE_CAMERA && + nodeprop->convert_to != SHD_VECT_TRANSFORM_SPACE_CAMERA) { + GPU_link(mat, "invert_z", inputlink, &inputlink); + } + GPU_link(mat, func_name, inputlink, fromto, &out[0].link); + if (nodeprop->convert_to == SHD_VECT_TRANSFORM_SPACE_CAMERA && + nodeprop->convert_from != SHD_VECT_TRANSFORM_SPACE_CAMERA) { + GPU_link(mat, "invert_z", out[0].link, &out[0].link); + } + } + else + GPU_link(mat, "set_rgb", inputlink, &out[0].link); + + if (nodeprop->type == SHD_VECT_TRANSFORM_TYPE_NORMAL) + GPU_link(mat, "vect_normalize", out[0].link, &out[0].link); + + return true; } void register_node_type_sh_vect_transform(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_VECT_TRANSFORM, "Vector Transform", NODE_CLASS_OP_VECTOR, 0); - node_type_init(&ntype, node_shader_init_vect_transform); - node_type_socket_templates(&ntype, sh_node_vect_transform_in, sh_node_vect_transform_out); - node_type_storage(&ntype, "NodeShaderVectTransform", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_vect_transform); - node_type_gpu(&ntype, gpu_shader_vect_transform); + sh_node_type_base(&ntype, SH_NODE_VECT_TRANSFORM, "Vector Transform", NODE_CLASS_OP_VECTOR, 0); + node_type_init(&ntype, node_shader_init_vect_transform); + node_type_socket_templates(&ntype, sh_node_vect_transform_in, sh_node_vect_transform_out); + node_type_storage( + &ntype, "NodeShaderVectTransform", node_free_standard_storage, node_copy_standard_storage); + node_type_exec(&ntype, NULL, NULL, node_shader_exec_vect_transform); + node_type_gpu(&ntype, gpu_shader_vect_transform); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_vector_displacement.c b/source/blender/nodes/shader/nodes/node_shader_vector_displacement.c index 83e6b078be7..cbc012040b0 100644 --- a/source/blender/nodes/shader/nodes/node_shader_vector_displacement.c +++ b/source/blender/nodes/shader/nodes/node_shader_vector_displacement.c @@ -22,53 +22,70 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_vector_displacement_in[] = { - { SOCK_RGBA, 1, N_("Vector"), 0.00f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f, PROP_NONE, SOCK_HIDE_VALUE}, - { SOCK_FLOAT, 1, N_("Midlevel"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { SOCK_FLOAT, 1, N_("Scale"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { -1, 0, "" }, + {SOCK_RGBA, + 1, + N_("Vector"), + 0.00f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 1000.0f, + PROP_NONE, + SOCK_HIDE_VALUE}, + {SOCK_FLOAT, 1, N_("Midlevel"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + {SOCK_FLOAT, 1, N_("Scale"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_vector_displacement_out[] = { - { SOCK_VECTOR, 0, N_("Displacement"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_VECTOR, 0, N_("Displacement"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; static void node_shader_init_vector_displacement(bNodeTree *UNUSED(ntree), bNode *node) { - node->custom1 = SHD_SPACE_TANGENT; /* space */ + node->custom1 = SHD_SPACE_TANGENT; /* space */ } -static int gpu_shader_vector_displacement(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_vector_displacement(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - if (node->custom1 == SHD_SPACE_TANGENT) { - return GPU_stack_link(mat, - node, - "node_vector_displacement_tangent", - in, - out, - GPU_attribute(CD_TANGENT, ""), - GPU_builtin(GPU_VIEW_NORMAL), - GPU_builtin(GPU_OBJECT_MATRIX), - GPU_builtin(GPU_VIEW_MATRIX)); - } - else if (node->custom1 == SHD_SPACE_OBJECT) { - return GPU_stack_link(mat, node, "node_vector_displacement_object", in, out, GPU_builtin(GPU_OBJECT_MATRIX)); - } - else { - return GPU_stack_link(mat, node, "node_vector_displacement_world", in, out); - } + if (node->custom1 == SHD_SPACE_TANGENT) { + return GPU_stack_link(mat, + node, + "node_vector_displacement_tangent", + in, + out, + GPU_attribute(CD_TANGENT, ""), + GPU_builtin(GPU_VIEW_NORMAL), + GPU_builtin(GPU_OBJECT_MATRIX), + GPU_builtin(GPU_VIEW_MATRIX)); + } + else if (node->custom1 == SHD_SPACE_OBJECT) { + return GPU_stack_link( + mat, node, "node_vector_displacement_object", in, out, GPU_builtin(GPU_OBJECT_MATRIX)); + } + else { + return GPU_stack_link(mat, node, "node_vector_displacement_world", in, out); + } } /* node type definition */ void register_node_type_sh_vector_displacement(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_VECTOR_DISPLACEMENT, "Vector Displacement", NODE_CLASS_OP_VECTOR, 0); - node_type_socket_templates(&ntype, sh_node_vector_displacement_in, sh_node_vector_displacement_out); - node_type_storage(&ntype, "", NULL, NULL); - node_type_init(&ntype, node_shader_init_vector_displacement); - node_type_gpu(&ntype, gpu_shader_vector_displacement); + sh_node_type_base( + &ntype, SH_NODE_VECTOR_DISPLACEMENT, "Vector Displacement", NODE_CLASS_OP_VECTOR, 0); + node_type_socket_templates( + &ntype, sh_node_vector_displacement_in, sh_node_vector_displacement_out); + node_type_storage(&ntype, "", NULL, NULL); + node_type_init(&ntype, node_shader_init_vector_displacement); + node_type_gpu(&ntype, gpu_shader_vector_displacement); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_volume_absorption.c b/source/blender/nodes/shader/nodes/node_shader_volume_absorption.c index 19dd9bdb5db..8f100cd494a 100644 --- a/source/blender/nodes/shader/nodes/node_shader_volume_absorption.c +++ b/source/blender/nodes/shader/nodes/node_shader_volume_absorption.c @@ -22,31 +22,35 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_volume_absorption_in[] = { - { SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Density"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Density"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_volume_absorption_out[] = { - { SOCK_SHADER, 0, N_("Volume")}, - { -1, 0, "" }, + {SOCK_SHADER, 0, N_("Volume")}, + {-1, 0, ""}, }; -static int node_shader_gpu_volume_absorption(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_volume_absorption(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "node_volume_absorption", in, out); + return GPU_stack_link(mat, node, "node_volume_absorption", in, out); } /* node type definition */ void register_node_type_sh_volume_absorption(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_VOLUME_ABSORPTION, "Volume Absorption", NODE_CLASS_SHADER, 0); - node_type_socket_templates(&ntype, sh_node_volume_absorption_in, sh_node_volume_absorption_out); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_volume_absorption); + sh_node_type_base(&ntype, SH_NODE_VOLUME_ABSORPTION, "Volume Absorption", NODE_CLASS_SHADER, 0); + node_type_socket_templates(&ntype, sh_node_volume_absorption_in, sh_node_volume_absorption_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_volume_absorption); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_volume_principled.c b/source/blender/nodes/shader/nodes/node_shader_volume_principled.c index f0ebd9f52be..82d8d30a602 100644 --- a/source/blender/nodes/shader/nodes/node_shader_volume_principled.c +++ b/source/blender/nodes/shader/nodes/node_shader_volume_principled.c @@ -22,134 +22,154 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_volume_principled_in[] = { - { SOCK_RGBA, 1, N_("Color"), 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f}, - { SOCK_STRING, 1, N_("Color Attribute"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Density"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { SOCK_STRING, 1, N_("Density Attribute"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Anisotropy"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_FACTOR}, - { SOCK_RGBA, 1, N_("Absorption Color"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Emission Strength"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1000.0f}, - { SOCK_RGBA, 1, N_("Emission Color"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Blackbody Intensity"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { SOCK_RGBA, 1, N_("Blackbody Tint"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Temperature"), 1000.0f, 0.0f, 0.0f, 0.0f, 0.0f, 6500.0f}, - { SOCK_STRING, 1, N_("Temperature Attribute"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f}, + {SOCK_STRING, 1, N_("Color Attribute"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Density"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + {SOCK_STRING, 1, N_("Density Attribute"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Anisotropy"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_FACTOR}, + {SOCK_RGBA, 1, N_("Absorption Color"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Emission Strength"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1000.0f}, + {SOCK_RGBA, 1, N_("Emission Color"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Blackbody Intensity"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {SOCK_RGBA, 1, N_("Blackbody Tint"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Temperature"), 1000.0f, 0.0f, 0.0f, 0.0f, 0.0f, 6500.0f}, + {SOCK_STRING, 1, N_("Temperature Attribute"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_volume_principled_out[] = { - { SOCK_SHADER, 0, N_("Volume")}, - { -1, 0, "" }, + {SOCK_SHADER, 0, N_("Volume")}, + {-1, 0, ""}, }; static void node_shader_init_volume_principled(bNodeTree *UNUSED(ntree), bNode *node) { - for (bNodeSocket *sock = node->inputs.first; sock; sock = sock->next) { - if (STREQ(sock->name, "Density Attribute")) { - strcpy(((bNodeSocketValueString *)sock->default_value)->value, "density"); - } - else if (STREQ(sock->name, "Temperature Attribute")) { - strcpy(((bNodeSocketValueString *)sock->default_value)->value, "temperature"); - } - } + for (bNodeSocket *sock = node->inputs.first; sock; sock = sock->next) { + if (STREQ(sock->name, "Density Attribute")) { + strcpy(((bNodeSocketValueString *)sock->default_value)->value, "density"); + } + else if (STREQ(sock->name, "Temperature Attribute")) { + strcpy(((bNodeSocketValueString *)sock->default_value)->value, "temperature"); + } + } } -static void node_shader_gpu_volume_attribute(GPUMaterial *mat, const char *name, GPUNodeLink **outcol, GPUNodeLink **outvec, GPUNodeLink **outf) +static void node_shader_gpu_volume_attribute(GPUMaterial *mat, + const char *name, + GPUNodeLink **outcol, + GPUNodeLink **outvec, + GPUNodeLink **outf) { - if (strcmp(name, "density") == 0) { - GPU_link(mat, "node_attribute_volume_density", - GPU_builtin(GPU_VOLUME_DENSITY), - outcol, outvec, outf); - } - else if (strcmp(name, "color") == 0) { - GPU_link(mat, "node_attribute_volume_color", - GPU_builtin(GPU_VOLUME_DENSITY), - outcol, outvec, outf); - } - else if (strcmp(name, "flame") == 0) { - GPU_link(mat, "node_attribute_volume_flame", - GPU_builtin(GPU_VOLUME_FLAME), - outcol, outvec, outf); - } - else if (strcmp(name, "temperature") == 0) { - GPU_link(mat, "node_attribute_volume_temperature", - GPU_builtin(GPU_VOLUME_FLAME), - GPU_builtin(GPU_VOLUME_TEMPERATURE), - outcol, outvec, outf); - } - else { - *outcol = *outvec = *outf = NULL; - } + if (strcmp(name, "density") == 0) { + GPU_link(mat, + "node_attribute_volume_density", + GPU_builtin(GPU_VOLUME_DENSITY), + outcol, + outvec, + outf); + } + else if (strcmp(name, "color") == 0) { + GPU_link( + mat, "node_attribute_volume_color", GPU_builtin(GPU_VOLUME_DENSITY), outcol, outvec, outf); + } + else if (strcmp(name, "flame") == 0) { + GPU_link( + mat, "node_attribute_volume_flame", GPU_builtin(GPU_VOLUME_FLAME), outcol, outvec, outf); + } + else if (strcmp(name, "temperature") == 0) { + GPU_link(mat, + "node_attribute_volume_temperature", + GPU_builtin(GPU_VOLUME_FLAME), + GPU_builtin(GPU_VOLUME_TEMPERATURE), + outcol, + outvec, + outf); + } + else { + *outcol = *outvec = *outf = NULL; + } } -static int node_shader_gpu_volume_principled(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_volume_principled(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - /* Test if blackbody intensity is enabled. */ - bool use_blackbody = (in[8].link || in[8].vec[0] != 0.0f); - - /* Get volume attributes. */ - GPUNodeLink *density = NULL, *color = NULL, *temperature = NULL; - - for (bNodeSocket *sock = node->inputs.first; sock; sock = sock->next) { - if (sock->typeinfo->type != SOCK_STRING) { - continue; - } - - bNodeSocketValueString *value = sock->default_value; - GPUNodeLink *outcol, *outvec, *outf; - - if (STREQ(sock->name, "Density Attribute")) { - node_shader_gpu_volume_attribute(mat, value->value, &outcol, &outvec, &density); - } - else if (STREQ(sock->name, "Color Attribute")) { - node_shader_gpu_volume_attribute(mat, value->value, &color, &outvec, &outf); - } - else if (use_blackbody && STREQ(sock->name, "Temperature Attribute")) { - node_shader_gpu_volume_attribute(mat, value->value, &outcol, &outvec, &temperature); - } - } - - /* Default values if attributes not found. */ - if (!density) { - static float one = 1.0f; - density = GPU_constant(&one); - } - if (!color) { - static float white[4] = {1.0f, 1.0f, 1.0f, 1.0f}; - color = GPU_constant(white); - } - if (!temperature) { - static float one = 1.0f; - temperature = GPU_constant(&one); - } - - /* Create blackbody spectrum. */ - const int size = CM_TABLE + 1; - float *data, layer; - if (use_blackbody) { - data = MEM_mallocN(sizeof(float) * size * 4, "blackbody texture"); - blackbody_temperature_to_rgb_table(data, size, 965.0f, 12000.0f); - } - else { - data = MEM_callocN(sizeof(float) * size * 4, "blackbody black"); - } - GPUNodeLink *spectrummap = GPU_color_band(mat, size, data, &layer); - - return GPU_stack_link(mat, node, "node_volume_principled", in, out, density, color, temperature, spectrummap, - GPU_constant(&layer)); + /* Test if blackbody intensity is enabled. */ + bool use_blackbody = (in[8].link || in[8].vec[0] != 0.0f); + + /* Get volume attributes. */ + GPUNodeLink *density = NULL, *color = NULL, *temperature = NULL; + + for (bNodeSocket *sock = node->inputs.first; sock; sock = sock->next) { + if (sock->typeinfo->type != SOCK_STRING) { + continue; + } + + bNodeSocketValueString *value = sock->default_value; + GPUNodeLink *outcol, *outvec, *outf; + + if (STREQ(sock->name, "Density Attribute")) { + node_shader_gpu_volume_attribute(mat, value->value, &outcol, &outvec, &density); + } + else if (STREQ(sock->name, "Color Attribute")) { + node_shader_gpu_volume_attribute(mat, value->value, &color, &outvec, &outf); + } + else if (use_blackbody && STREQ(sock->name, "Temperature Attribute")) { + node_shader_gpu_volume_attribute(mat, value->value, &outcol, &outvec, &temperature); + } + } + + /* Default values if attributes not found. */ + if (!density) { + static float one = 1.0f; + density = GPU_constant(&one); + } + if (!color) { + static float white[4] = {1.0f, 1.0f, 1.0f, 1.0f}; + color = GPU_constant(white); + } + if (!temperature) { + static float one = 1.0f; + temperature = GPU_constant(&one); + } + + /* Create blackbody spectrum. */ + const int size = CM_TABLE + 1; + float *data, layer; + if (use_blackbody) { + data = MEM_mallocN(sizeof(float) * size * 4, "blackbody texture"); + blackbody_temperature_to_rgb_table(data, size, 965.0f, 12000.0f); + } + else { + data = MEM_callocN(sizeof(float) * size * 4, "blackbody black"); + } + GPUNodeLink *spectrummap = GPU_color_band(mat, size, data, &layer); + + return GPU_stack_link(mat, + node, + "node_volume_principled", + in, + out, + density, + color, + temperature, + spectrummap, + GPU_constant(&layer)); } /* node type definition */ void register_node_type_sh_volume_principled(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_VOLUME_PRINCIPLED, "Principled Volume", NODE_CLASS_SHADER, 0); - 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_init(&ntype, node_shader_init_volume_principled); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_volume_principled); + sh_node_type_base(&ntype, SH_NODE_VOLUME_PRINCIPLED, "Principled Volume", NODE_CLASS_SHADER, 0); + 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_init(&ntype, node_shader_init_volume_principled); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_volume_principled); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_volume_scatter.c b/source/blender/nodes/shader/nodes/node_shader_volume_scatter.c index d99bc47e25f..52955119d92 100644 --- a/source/blender/nodes/shader/nodes/node_shader_volume_scatter.c +++ b/source/blender/nodes/shader/nodes/node_shader_volume_scatter.c @@ -22,32 +22,36 @@ /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_volume_scatter_in[] = { - { SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Density"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, - { SOCK_FLOAT, 1, N_("Anisotropy"),0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_FACTOR}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Density"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + {SOCK_FLOAT, 1, N_("Anisotropy"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_FACTOR}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_volume_scatter_out[] = { - { SOCK_SHADER, 0, N_("Volume")}, - { -1, 0, "" }, + {SOCK_SHADER, 0, N_("Volume")}, + {-1, 0, ""}, }; -static int node_shader_gpu_volume_scatter(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_volume_scatter(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - return GPU_stack_link(mat, node, "node_volume_scatter", in, out); + return GPU_stack_link(mat, node, "node_volume_scatter", in, out); } /* node type definition */ void register_node_type_sh_volume_scatter(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_VOLUME_SCATTER, "Volume Scatter", NODE_CLASS_SHADER, 0); - node_type_socket_templates(&ntype, sh_node_volume_scatter_in, sh_node_volume_scatter_out); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_volume_scatter); + sh_node_type_base(&ntype, SH_NODE_VOLUME_SCATTER, "Volume Scatter", NODE_CLASS_SHADER, 0); + node_type_socket_templates(&ntype, sh_node_volume_scatter_in, sh_node_volume_scatter_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_volume_scatter); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_wavelength.c b/source/blender/nodes/shader/nodes/node_shader_wavelength.c index 427d9f17a63..65719c6a4b4 100644 --- a/source/blender/nodes/shader/nodes/node_shader_wavelength.c +++ b/source/blender/nodes/shader/nodes/node_shader_wavelength.c @@ -21,25 +21,25 @@ /* **************** Wavelength ******************** */ static bNodeSocketTemplate sh_node_wavelength_in[] = { - { SOCK_FLOAT, 1, N_("Wavelength"), 500.0f, 0.0f, 0.0f, 0.0f, 380.0f, 780.0f}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Wavelength"), 500.0f, 0.0f, 0.0f, 0.0f, 380.0f, 780.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_wavelength_out[] = { - { SOCK_RGBA, 0, N_("Color")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color")}, + {-1, 0, ""}, }; /* node type definition */ void register_node_type_sh_wavelength(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_WAVELENGTH, "Wavelength", NODE_CLASS_CONVERTOR, 0); - node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); - node_type_socket_templates(&ntype, sh_node_wavelength_in, sh_node_wavelength_out); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); + sh_node_type_base(&ntype, SH_NODE_WAVELENGTH, "Wavelength", NODE_CLASS_CONVERTOR, 0); + node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); + node_type_socket_templates(&ntype, sh_node_wavelength_in, sh_node_wavelength_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_wireframe.c b/source/blender/nodes/shader/nodes/node_shader_wireframe.c index 2a902211ee4..fd9c52c564b 100644 --- a/source/blender/nodes/shader/nodes/node_shader_wireframe.c +++ b/source/blender/nodes/shader/nodes/node_shader_wireframe.c @@ -21,36 +21,47 @@ /* **************** Wireframe ******************** */ static bNodeSocketTemplate sh_node_wireframe_in[] = { - { SOCK_FLOAT, 1, N_("Size"), 0.01f, 0.0f, 0.0f, 0.0f, 0.0f, 100.0f}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Size"), 0.01f, 0.0f, 0.0f, 0.0f, 0.0f, 100.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate sh_node_wireframe_out[] = { - { SOCK_FLOAT, 0, N_("Fac"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("Fac"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {-1, 0, ""}, }; -static int node_shader_gpu_wireframe(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_wireframe(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) { - /* node->custom1 is use_pixel_size */ - if (node->custom1) { - return GPU_stack_link(mat, node, "node_wireframe_screenspace", in, out, GPU_builtin(GPU_BARYCENTRIC_TEXCO)); - } - else { - return GPU_stack_link(mat, node, "node_wireframe", in, out, GPU_builtin(GPU_BARYCENTRIC_TEXCO), GPU_builtin(GPU_BARYCENTRIC_DIST)); - } + /* node->custom1 is use_pixel_size */ + if (node->custom1) { + return GPU_stack_link( + mat, node, "node_wireframe_screenspace", in, out, GPU_builtin(GPU_BARYCENTRIC_TEXCO)); + } + else { + return GPU_stack_link(mat, + node, + "node_wireframe", + in, + out, + GPU_builtin(GPU_BARYCENTRIC_TEXCO), + GPU_builtin(GPU_BARYCENTRIC_DIST)); + } } /* node type definition */ void register_node_type_sh_wireframe(void) { - static bNodeType ntype; + static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_WIREFRAME, "Wireframe", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, sh_node_wireframe_in, sh_node_wireframe_out); - node_type_init(&ntype, NULL); - node_type_storage(&ntype, "", NULL, NULL); - node_type_gpu(&ntype, node_shader_gpu_wireframe); + sh_node_type_base(&ntype, SH_NODE_WIREFRAME, "Wireframe", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, sh_node_wireframe_in, sh_node_wireframe_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_wireframe); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/node_texture_tree.c b/source/blender/nodes/texture/node_texture_tree.c index 6aeaf8d0179..76b906f5f22 100644 --- a/source/blender/nodes/texture/node_texture_tree.c +++ b/source/blender/nodes/texture/node_texture_tree.c @@ -21,7 +21,6 @@ * \ingroup nodes */ - #include <string.h> #include "DNA_texture_types.h" @@ -51,57 +50,60 @@ #include "RE_shader_ext.h" -static void texture_get_from_context( - const bContext *C, bNodeTreeType *UNUSED(treetype), bNodeTree **r_ntree, ID **r_id, ID **r_from) +static void texture_get_from_context(const bContext *C, + bNodeTreeType *UNUSED(treetype), + bNodeTree **r_ntree, + ID **r_id, + ID **r_from) { - SpaceNode *snode = CTX_wm_space_node(C); - Scene *scene = CTX_data_scene(C); - ViewLayer *view_layer = CTX_data_view_layer(C); - Object *ob = OBACT(view_layer); - Tex *tx = NULL; - - if (snode->texfrom == SNODE_TEX_BRUSH) { - struct Brush *brush = NULL; - - if (ob && (ob->mode & OB_MODE_SCULPT)) - brush = BKE_paint_brush(&scene->toolsettings->sculpt->paint); - else - brush = BKE_paint_brush(&scene->toolsettings->imapaint.paint); - - if (brush) { - *r_from = (ID *)brush; - tx = give_current_brush_texture(brush); - if (tx) { - *r_id = &tx->id; - *r_ntree = tx->nodetree; - } - } - } - else if (snode->texfrom == SNODE_TEX_LINESTYLE) { - FreestyleLineStyle *linestyle = BKE_linestyle_active_from_view_layer(view_layer); - if (linestyle) { - *r_from = (ID *)linestyle; - tx = give_current_linestyle_texture(linestyle); - if (tx) { - *r_id = &tx->id; - *r_ntree = tx->nodetree; - } - } - } + SpaceNode *snode = CTX_wm_space_node(C); + Scene *scene = CTX_data_scene(C); + ViewLayer *view_layer = CTX_data_view_layer(C); + Object *ob = OBACT(view_layer); + Tex *tx = NULL; + + if (snode->texfrom == SNODE_TEX_BRUSH) { + struct Brush *brush = NULL; + + if (ob && (ob->mode & OB_MODE_SCULPT)) + brush = BKE_paint_brush(&scene->toolsettings->sculpt->paint); + else + brush = BKE_paint_brush(&scene->toolsettings->imapaint.paint); + + if (brush) { + *r_from = (ID *)brush; + tx = give_current_brush_texture(brush); + if (tx) { + *r_id = &tx->id; + *r_ntree = tx->nodetree; + } + } + } + else if (snode->texfrom == SNODE_TEX_LINESTYLE) { + FreestyleLineStyle *linestyle = BKE_linestyle_active_from_view_layer(view_layer); + if (linestyle) { + *r_from = (ID *)linestyle; + tx = give_current_linestyle_texture(linestyle); + if (tx) { + *r_id = &tx->id; + *r_ntree = tx->nodetree; + } + } + } } static void foreach_nodeclass(Scene *UNUSED(scene), void *calldata, bNodeClassCallback func) { - func(calldata, NODE_CLASS_INPUT, N_("Input")); - func(calldata, NODE_CLASS_OUTPUT, N_("Output")); - func(calldata, NODE_CLASS_OP_COLOR, N_("Color")); - func(calldata, NODE_CLASS_PATTERN, N_("Patterns")); - func(calldata, NODE_CLASS_TEXTURE, N_("Textures")); - func(calldata, NODE_CLASS_CONVERTOR, N_("Convertor")); - func(calldata, NODE_CLASS_DISTORT, N_("Distort")); - func(calldata, NODE_CLASS_GROUP, N_("Group")); - func(calldata, NODE_CLASS_INTERFACE, N_("Interface")); - func(calldata, NODE_CLASS_LAYOUT, N_("Layout")); + func(calldata, NODE_CLASS_INPUT, N_("Input")); + func(calldata, NODE_CLASS_OUTPUT, N_("Output")); + func(calldata, NODE_CLASS_OP_COLOR, N_("Color")); + func(calldata, NODE_CLASS_PATTERN, N_("Patterns")); + func(calldata, NODE_CLASS_TEXTURE, N_("Textures")); + func(calldata, NODE_CLASS_CONVERTOR, N_("Convertor")); + func(calldata, NODE_CLASS_DISTORT, N_("Distort")); + func(calldata, NODE_CLASS_GROUP, N_("Group")); + func(calldata, NODE_CLASS_INTERFACE, N_("Interface")); + func(calldata, NODE_CLASS_LAYOUT, N_("Layout")); } /* XXX muting disabled in previews because of threading issues with the main execution @@ -110,17 +112,17 @@ static void foreach_nodeclass(Scene *UNUSED(scene), void *calldata, bNodeClassCa #if 1 static void localize(bNodeTree *localtree, bNodeTree *UNUSED(ntree)) { - bNode *node, *node_next; + bNode *node, *node_next; - /* replace muted nodes and reroute nodes by internal links */ - for (node = localtree->nodes.first; node; node = node_next) { - node_next = node->next; + /* replace muted nodes and reroute nodes by internal links */ + for (node = localtree->nodes.first; node; node = node_next) { + node_next = node->next; - if (node->flag & NODE_MUTED || node->type == NODE_REROUTE) { - nodeInternalRelink(localtree, node); - ntreeFreeLocalNode(localtree, node); - } - } + if (node->flag & NODE_MUTED || node->type == NODE_REROUTE) { + nodeInternalRelink(localtree, node); + ntreeFreeLocalNode(localtree, node); + } + } } #else static void localize(bNodeTree *UNUSED(localtree), bNodeTree *UNUSED(ntree)) @@ -130,206 +132,212 @@ static void localize(bNodeTree *UNUSED(localtree), bNodeTree *UNUSED(ntree)) static void local_sync(bNodeTree *localtree, bNodeTree *ntree) { - BKE_node_preview_sync_tree(ntree, localtree); + BKE_node_preview_sync_tree(ntree, localtree); } static void local_merge(Main *UNUSED(bmain), bNodeTree *localtree, bNodeTree *ntree) { - BKE_node_preview_merge_tree(ntree, localtree, true); + BKE_node_preview_merge_tree(ntree, localtree, true); } static void update(bNodeTree *ntree) { - ntree_update_reroute_nodes(ntree); + ntree_update_reroute_nodes(ntree); - if (ntree->update & NTREE_UPDATE_NODES) { - /* clean up preview cache, in case nodes have been removed */ - BKE_node_preview_remove_unused(ntree); - } + if (ntree->update & NTREE_UPDATE_NODES) { + /* clean up preview cache, in case nodes have been removed */ + BKE_node_preview_remove_unused(ntree); + } } bNodeTreeType *ntreeType_Texture; void register_node_tree_type_tex(void) { - bNodeTreeType *tt = ntreeType_Texture = MEM_callocN(sizeof(bNodeTreeType), "texture node tree type"); + bNodeTreeType *tt = ntreeType_Texture = MEM_callocN(sizeof(bNodeTreeType), + "texture node tree type"); - tt->type = NTREE_TEXTURE; - strcpy(tt->idname, "TextureNodeTree"); - strcpy(tt->ui_name, N_("Texture Node Editor")); - tt->ui_icon = 0; /* defined in drawnode.c */ - strcpy(tt->ui_description, N_("Texture nodes")); + tt->type = NTREE_TEXTURE; + strcpy(tt->idname, "TextureNodeTree"); + strcpy(tt->ui_name, N_("Texture Node Editor")); + tt->ui_icon = 0; /* defined in drawnode.c */ + strcpy(tt->ui_description, N_("Texture nodes")); - tt->foreach_nodeclass = foreach_nodeclass; - tt->update = update; - tt->localize = localize; - tt->local_sync = local_sync; - tt->local_merge = local_merge; - tt->get_from_context = texture_get_from_context; + tt->foreach_nodeclass = foreach_nodeclass; + tt->update = update; + tt->localize = localize; + tt->local_sync = local_sync; + tt->local_merge = local_merge; + tt->get_from_context = texture_get_from_context; - tt->ext.srna = &RNA_TextureNodeTree; + tt->ext.srna = &RNA_TextureNodeTree; - ntreeTypeAdd(tt); + ntreeTypeAdd(tt); } int ntreeTexTagAnimated(bNodeTree *ntree) { - bNode *node; - - if (ntree == NULL) return 0; - - for (node = ntree->nodes.first; node; node = node->next) { - if (node->type == TEX_NODE_CURVE_TIME) { - nodeUpdate(ntree, node); - return 1; - } - else if (node->type == NODE_GROUP) { - if (ntreeTexTagAnimated((bNodeTree *)node->id) ) { - return 1; - } - } - } - - return 0; + bNode *node; + + if (ntree == NULL) + return 0; + + for (node = ntree->nodes.first; node; node = node->next) { + if (node->type == TEX_NODE_CURVE_TIME) { + nodeUpdate(ntree, node); + return 1; + } + else if (node->type == NODE_GROUP) { + if (ntreeTexTagAnimated((bNodeTree *)node->id)) { + return 1; + } + } + } + + return 0; } -bNodeTreeExec *ntreeTexBeginExecTree_internal(bNodeExecContext *context, bNodeTree *ntree, bNodeInstanceKey parent_key) +bNodeTreeExec *ntreeTexBeginExecTree_internal(bNodeExecContext *context, + bNodeTree *ntree, + bNodeInstanceKey parent_key) { - bNodeTreeExec *exec; - bNode *node; + bNodeTreeExec *exec; + bNode *node; - /* common base initialization */ - exec = ntree_exec_begin(context, ntree, parent_key); + /* common base initialization */ + exec = ntree_exec_begin(context, ntree, parent_key); - /* allocate the thread stack listbase array */ - exec->threadstack = MEM_callocN(BLENDER_MAX_THREADS * sizeof(ListBase), "thread stack array"); + /* allocate the thread stack listbase array */ + exec->threadstack = MEM_callocN(BLENDER_MAX_THREADS * sizeof(ListBase), "thread stack array"); - for (node = exec->nodetree->nodes.first; node; node = node->next) - node->need_exec = 1; + for (node = exec->nodetree->nodes.first; node; node = node->next) + node->need_exec = 1; - return exec; + return exec; } bNodeTreeExec *ntreeTexBeginExecTree(bNodeTree *ntree) { - bNodeExecContext context; - bNodeTreeExec *exec; + bNodeExecContext context; + bNodeTreeExec *exec; - /* XXX hack: prevent exec data from being generated twice. - * this should be handled by the renderer! - */ - if (ntree->execdata) - return ntree->execdata; + /* XXX hack: prevent exec data from being generated twice. + * this should be handled by the renderer! + */ + if (ntree->execdata) + return ntree->execdata; - context.previews = ntree->previews; + context.previews = ntree->previews; - exec = ntreeTexBeginExecTree_internal(&context, ntree, NODE_INSTANCE_KEY_BASE); + exec = ntreeTexBeginExecTree_internal(&context, ntree, NODE_INSTANCE_KEY_BASE); - /* XXX this should not be necessary, but is still used for cmp/sha/tex nodes, - * which only store the ntree pointer. Should be fixed at some point! - */ - ntree->execdata = exec; + /* XXX this should not be necessary, but is still used for cmp/sha/tex nodes, + * which only store the ntree pointer. Should be fixed at some point! + */ + ntree->execdata = exec; - return exec; + return exec; } /* free texture delegates */ static void tex_free_delegates(bNodeTreeExec *exec) { - bNodeThreadStack *nts; - bNodeStack *ns; - int th, a; - - for (th = 0; th < BLENDER_MAX_THREADS; th++) - for (nts = exec->threadstack[th].first; nts; nts = nts->next) - for (ns = nts->stack, a = 0; a < exec->stacksize; a++, ns++) - if (ns->data && !ns->is_copy) - MEM_freeN(ns->data); + bNodeThreadStack *nts; + bNodeStack *ns; + int th, a; + + for (th = 0; th < BLENDER_MAX_THREADS; th++) + for (nts = exec->threadstack[th].first; nts; nts = nts->next) + for (ns = nts->stack, a = 0; a < exec->stacksize; a++, ns++) + if (ns->data && !ns->is_copy) + MEM_freeN(ns->data); } void ntreeTexEndExecTree_internal(bNodeTreeExec *exec) { - bNodeThreadStack *nts; - int a; + bNodeThreadStack *nts; + int a; - if (exec->threadstack) { - tex_free_delegates(exec); + if (exec->threadstack) { + tex_free_delegates(exec); - for (a = 0; a < BLENDER_MAX_THREADS; a++) { - for (nts = exec->threadstack[a].first; nts; nts = nts->next) - if (nts->stack) MEM_freeN(nts->stack); - BLI_freelistN(&exec->threadstack[a]); - } + for (a = 0; a < BLENDER_MAX_THREADS; a++) { + for (nts = exec->threadstack[a].first; nts; nts = nts->next) + if (nts->stack) + MEM_freeN(nts->stack); + BLI_freelistN(&exec->threadstack[a]); + } - MEM_freeN(exec->threadstack); - exec->threadstack = NULL; - } + MEM_freeN(exec->threadstack); + exec->threadstack = NULL; + } - ntree_exec_end(exec); + ntree_exec_end(exec); } void ntreeTexEndExecTree(bNodeTreeExec *exec) { - if (exec) { - /* exec may get freed, so assign ntree */ - bNodeTree *ntree = exec->nodetree; - ntreeTexEndExecTree_internal(exec); - - /* XXX clear nodetree backpointer to exec data, same problem as noted in ntreeBeginExecTree */ - ntree->execdata = NULL; - } + if (exec) { + /* exec may get freed, so assign ntree */ + bNodeTree *ntree = exec->nodetree; + ntreeTexEndExecTree_internal(exec); + + /* XXX clear nodetree backpointer to exec data, same problem as noted in ntreeBeginExecTree */ + ntree->execdata = NULL; + } } -int ntreeTexExecTree( - bNodeTree *nodes, - TexResult *texres, - float co[3], - float dxt[3], float dyt[3], - int osatex, - const short thread, - Tex *UNUSED(tex), - short which_output, - int cfra, - int preview, - MTex *mtex) +int ntreeTexExecTree(bNodeTree *nodes, + TexResult *texres, + float co[3], + float dxt[3], + float dyt[3], + int osatex, + const short thread, + Tex *UNUSED(tex), + short which_output, + int cfra, + int preview, + MTex *mtex) { - TexCallData data; - float *nor = texres->nor; - int retval = TEX_INT; - bNodeThreadStack *nts = NULL; - bNodeTreeExec *exec = nodes->execdata; - - data.co = co; - data.dxt = dxt; - data.dyt = dyt; - data.osatex = osatex; - data.target = texres; - data.do_preview = preview; - data.do_manage = true; - data.thread = thread; - data.which_output = which_output; - data.cfra = cfra; - data.mtex = mtex; - - /* ensure execdata is only initialized once */ - if (!exec) { - BLI_thread_lock(LOCK_NODES); - if (!nodes->execdata) - ntreeTexBeginExecTree(nodes); - BLI_thread_unlock(LOCK_NODES); - - exec = nodes->execdata; - } - - nts = ntreeGetThreadStack(exec, thread); - ntreeExecThreadNodes(exec, nts, &data, thread); - ntreeReleaseThreadStack(nts); - - if (texres->nor) retval |= TEX_NOR; - retval |= TEX_RGB; - /* confusing stuff; the texture output node sets this to NULL to indicate no normal socket was set - * however, the texture code checks this for other reasons (namely, a normal is required for material) */ - texres->nor = nor; - - return retval; + TexCallData data; + float *nor = texres->nor; + int retval = TEX_INT; + bNodeThreadStack *nts = NULL; + bNodeTreeExec *exec = nodes->execdata; + + data.co = co; + data.dxt = dxt; + data.dyt = dyt; + data.osatex = osatex; + data.target = texres; + data.do_preview = preview; + data.do_manage = true; + data.thread = thread; + data.which_output = which_output; + data.cfra = cfra; + data.mtex = mtex; + + /* ensure execdata is only initialized once */ + if (!exec) { + BLI_thread_lock(LOCK_NODES); + if (!nodes->execdata) + ntreeTexBeginExecTree(nodes); + BLI_thread_unlock(LOCK_NODES); + + exec = nodes->execdata; + } + + nts = ntreeGetThreadStack(exec, thread); + ntreeExecThreadNodes(exec, nts, &data, thread); + ntreeReleaseThreadStack(nts); + + if (texres->nor) + retval |= TEX_NOR; + retval |= TEX_RGB; + /* confusing stuff; the texture output node sets this to NULL to indicate no normal socket was set + * however, the texture code checks this for other reasons (namely, a normal is required for material) */ + texres->nor = nor; + + return retval; } diff --git a/source/blender/nodes/texture/node_texture_util.c b/source/blender/nodes/texture/node_texture_util.c index cc4ecbfb1d9..ba65a692835 100644 --- a/source/blender/nodes/texture/node_texture_util.c +++ b/source/blender/nodes/texture/node_texture_util.c @@ -21,7 +21,6 @@ * \ingroup nodes */ - /* * HOW TEXTURE NODES WORK * @@ -41,142 +40,147 @@ #include <assert.h> #include "node_texture_util.h" - bool tex_node_poll_default(bNodeType *UNUSED(ntype), bNodeTree *ntree) { - return STREQ(ntree->idname, "TextureNodeTree"); + return STREQ(ntree->idname, "TextureNodeTree"); } -void tex_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag) +void tex_node_type_base( + struct bNodeType *ntype, int type, const char *name, short nclass, short flag) { - node_type_base(ntype, type, name, nclass, flag); + node_type_base(ntype, type, name, nclass, flag); - ntype->poll = tex_node_poll_default; - ntype->insert_link = node_insert_link_default; - ntype->update_internal_links = node_update_internal_links_default; + ntype->poll = tex_node_poll_default; + ntype->insert_link = node_insert_link_default; + ntype->update_internal_links = node_update_internal_links_default; } - static void tex_call_delegate(TexDelegate *dg, float *out, TexParams *params, short thread) { - if (dg->node->need_exec) { - dg->fn(out, params, dg->node, dg->in, thread); + if (dg->node->need_exec) { + dg->fn(out, params, dg->node, dg->in, thread); - if (dg->cdata->do_preview) - tex_do_preview(dg->preview, params->previewco, out, dg->cdata->do_manage); - } + if (dg->cdata->do_preview) + tex_do_preview(dg->preview, params->previewco, out, dg->cdata->do_manage); + } } static void tex_input(float *out, int sz, bNodeStack *in, TexParams *params, short thread) { - TexDelegate *dg = in->data; - if (dg) { - tex_call_delegate(dg, in->vec, params, thread); - - if (in->hasoutput && in->sockettype == SOCK_FLOAT) - in->vec[1] = in->vec[2] = in->vec[0]; - } - memcpy(out, in->vec, sz * sizeof(float)); + TexDelegate *dg = in->data; + if (dg) { + tex_call_delegate(dg, in->vec, params, thread); + + if (in->hasoutput && in->sockettype == SOCK_FLOAT) + in->vec[1] = in->vec[2] = in->vec[0]; + } + memcpy(out, in->vec, sz * sizeof(float)); } void tex_input_vec(float *out, bNodeStack *in, TexParams *params, short thread) { - tex_input(out, 3, in, params, thread); + tex_input(out, 3, in, params, thread); } void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread) { - tex_input(out, 4, in, params, thread); - - if (in->hasoutput && in->sockettype == SOCK_FLOAT) { - out[1] = out[2] = out[0]; - out[3] = 1; - } - - if (in->hasoutput && in->sockettype == SOCK_VECTOR) { - out[0] = out[0] * 0.5f + 0.5f; - out[1] = out[1] * 0.5f + 0.5f; - out[2] = out[2] * 0.5f + 0.5f; - out[3] = 1; - } + tex_input(out, 4, in, params, thread); + + if (in->hasoutput && in->sockettype == SOCK_FLOAT) { + out[1] = out[2] = out[0]; + out[3] = 1; + } + + if (in->hasoutput && in->sockettype == SOCK_VECTOR) { + out[0] = out[0] * 0.5f + 0.5f; + out[1] = out[1] * 0.5f + 0.5f; + out[2] = out[2] * 0.5f + 0.5f; + out[3] = 1; + } } float tex_input_value(bNodeStack *in, TexParams *params, short thread) { - float out[4]; - tex_input_vec(out, in, params, thread); - return out[0]; + float out[4]; + tex_input_vec(out, in, params, thread); + return out[0]; } void params_from_cdata(TexParams *out, TexCallData *in) { - out->co = in->co; - out->dxt = in->dxt; - out->dyt = in->dyt; - out->previewco = in->co; - out->osatex = in->osatex; - out->cfra = in->cfra; - out->mtex = in->mtex; + out->co = in->co; + out->dxt = in->dxt; + out->dyt = in->dyt; + out->previewco = in->co; + out->osatex = in->osatex; + out->cfra = in->cfra; + out->mtex = in->mtex; } -void tex_do_preview(bNodePreview *preview, const float coord[2], const float col[4], bool do_manage) +void tex_do_preview(bNodePreview *preview, + const float coord[2], + const float col[4], + bool do_manage) { - if (preview) { - int xs = ((coord[0] + 1.0f) * 0.5f) * preview->xsize; - int ys = ((coord[1] + 1.0f) * 0.5f) * preview->ysize; + if (preview) { + int xs = ((coord[0] + 1.0f) * 0.5f) * preview->xsize; + int ys = ((coord[1] + 1.0f) * 0.5f) * preview->ysize; - BKE_node_preview_set_pixel(preview, col, xs, ys, do_manage); - } + BKE_node_preview_set_pixel(preview, col, xs, ys, do_manage); + } } -void tex_output(bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *cdata) +void tex_output(bNode *node, + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack *out, + TexFn texfn, + TexCallData *cdata) { - TexDelegate *dg; - - if (node->flag & NODE_MUTED) { - /* do not add a delegate if the node is muted */ - return; - } - else { - if (!out->data) - /* Freed in tex_end_exec (node.c) */ - dg = out->data = MEM_mallocN(sizeof(TexDelegate), "tex delegate"); - else - dg = out->data; - } - - - dg->cdata = cdata; - dg->fn = texfn; - dg->node = node; - dg->preview = execdata->preview; - memcpy(dg->in, in, MAX_SOCKET * sizeof(bNodeStack *)); - dg->type = out->sockettype; + TexDelegate *dg; + + if (node->flag & NODE_MUTED) { + /* do not add a delegate if the node is muted */ + return; + } + else { + if (!out->data) + /* Freed in tex_end_exec (node.c) */ + dg = out->data = MEM_mallocN(sizeof(TexDelegate), "tex delegate"); + else + dg = out->data; + } + + dg->cdata = cdata; + dg->fn = texfn; + dg->node = node; + dg->preview = execdata->preview; + memcpy(dg->in, in, MAX_SOCKET * sizeof(bNodeStack *)); + dg->type = out->sockettype; } void ntreeTexCheckCyclics(struct bNodeTree *ntree) { - bNode *node; - for (node = ntree->nodes.first; node; node = node->next) { - - if (node->type == TEX_NODE_TEXTURE && node->id) { - /* custom2 stops the node from rendering */ - if (node->custom1) { - node->custom2 = 1; - node->custom1 = 0; - } - else { - Tex *tex = (Tex *)node->id; - - node->custom2 = 0; - - node->custom1 = 1; - if (tex->use_nodes && tex->nodetree) { - ntreeTexCheckCyclics(tex->nodetree); - } - node->custom1 = 0; - } - } - - } + bNode *node; + for (node = ntree->nodes.first; node; node = node->next) { + + if (node->type == TEX_NODE_TEXTURE && node->id) { + /* custom2 stops the node from rendering */ + if (node->custom1) { + node->custom2 = 1; + node->custom1 = 0; + } + else { + Tex *tex = (Tex *)node->id; + + node->custom2 = 0; + + node->custom1 = 1; + if (tex->use_nodes && tex->nodetree) { + ntreeTexCheckCyclics(tex->nodetree); + } + node->custom1 = 0; + } + } + } } diff --git a/source/blender/nodes/texture/node_texture_util.h b/source/blender/nodes/texture/node_texture_util.h index 111b747fa9c..f638bdb0eec 100644 --- a/source/blender/nodes/texture/node_texture_util.h +++ b/source/blender/nodes/texture/node_texture_util.h @@ -21,7 +21,6 @@ * \ingroup nodes */ - #ifndef __NODE_TEXTURE_UTIL_H__ #define __NODE_TEXTURE_UTIL_H__ @@ -66,54 +65,62 @@ #include "RE_shader_ext.h" typedef struct TexCallData { - TexResult *target; - /* all float[3] */ - float *co; - float *dxt, *dyt; - - int osatex; - bool do_preview; - bool do_manage; - short thread; - short which_output; - int cfra; - - MTex *mtex; + TexResult *target; + /* all float[3] */ + float *co; + float *dxt, *dyt; + + int osatex; + bool do_preview; + bool do_manage; + short thread; + short which_output; + int cfra; + + MTex *mtex; } TexCallData; typedef struct TexParams { - float *co; - float *dxt, *dyt; - const float *previewco; - int cfra; - int osatex; - - /* optional. we don't really want these here, but image - * textures need to do mapping & color correction */ - MTex *mtex; + float *co; + float *dxt, *dyt; + const float *previewco; + int cfra; + int osatex; + + /* optional. we don't really want these here, but image + * textures need to do mapping & color correction */ + MTex *mtex; } TexParams; -typedef void(*TexFn) (float *out, TexParams *params, bNode *node, bNodeStack **in, short thread); +typedef void (*TexFn)(float *out, TexParams *params, bNode *node, bNodeStack **in, short thread); typedef struct TexDelegate { - TexCallData *cdata; - TexFn fn; - bNode *node; - bNodePreview *preview; - bNodeStack *in[MAX_SOCKET]; - int type; + TexCallData *cdata; + TexFn fn; + bNode *node; + bNodePreview *preview; + bNodeStack *in[MAX_SOCKET]; + int type; } TexDelegate; - bool tex_node_poll_default(struct bNodeType *ntype, struct bNodeTree *ntree); -void tex_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag); +void tex_node_type_base( + struct bNodeType *ntype, int type, const char *name, short nclass, short flag); void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread); void tex_input_vec(float *out, bNodeStack *in, TexParams *params, short thread); float tex_input_value(bNodeStack *in, TexParams *params, short thread); -void tex_output(bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *data); -void tex_do_preview(bNodePreview *preview, const float coord[2], const float col[4], bool do_manage); +void tex_output(bNode *node, + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack *out, + TexFn texfn, + TexCallData *data); +void tex_do_preview(bNodePreview *preview, + const float coord[2], + const float col[4], + bool do_manage); void params_from_cdata(TexParams *out, TexCallData *in); diff --git a/source/blender/nodes/texture/nodes/node_texture_at.c b/source/blender/nodes/texture/nodes/node_texture_at.c index 82e545cfd8e..f645b04a161 100644 --- a/source/blender/nodes/texture/nodes/node_texture_at.c +++ b/source/blender/nodes/texture/nodes/node_texture_at.c @@ -21,43 +21,47 @@ * \ingroup texnodes */ - #include "node_texture_util.h" #include "NOD_texture.h" static bNodeSocketTemplate inputs[] = { - { SOCK_RGBA, 1, N_("Texture"), 0.0f, 0.0f, 0.0f, 1.0f }, - { SOCK_VECTOR, 1, N_("Coordinates"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_NONE }, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Texture"), 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_VECTOR, 1, N_("Coordinates"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate outputs[] = { - { SOCK_RGBA, 0, N_("Texture") }, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Texture")}, + {-1, 0, ""}, }; static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) { - TexParams np = *p; - float new_co[3]; - np.co = new_co; + TexParams np = *p; + float new_co[3]; + np.co = new_co; - tex_input_vec(new_co, in[1], p, thread); - tex_input_rgba(out, in[0], &np, thread); + tex_input_vec(new_co, in[1], p, thread); + tex_input_rgba(out, in[0], &np, thread); } -static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void exec(void *data, + int UNUSED(thread), + bNode *node, + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack **out) { - tex_output(node, execdata, in, out[0], &colorfn, data); + tex_output(node, execdata, in, out[0], &colorfn, data); } void register_node_type_tex_at(void) { - static bNodeType ntype; + static bNodeType ntype; - tex_node_type_base(&ntype, TEX_NODE_AT, "At", NODE_CLASS_DISTORT, 0); - node_type_socket_templates(&ntype, inputs, outputs); - node_type_size(&ntype, 140, 100, 320); - node_type_exec(&ntype, NULL, NULL, exec); + tex_node_type_base(&ntype, TEX_NODE_AT, "At", NODE_CLASS_DISTORT, 0); + node_type_socket_templates(&ntype, inputs, outputs); + node_type_size(&ntype, 140, 100, 320); + node_type_exec(&ntype, NULL, NULL, exec); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_bricks.c b/source/blender/nodes/texture/nodes/node_texture_bricks.c index 0f034de99ec..c500fa31d34 100644 --- a/source/blender/nodes/texture/nodes/node_texture_bricks.c +++ b/source/blender/nodes/texture/nodes/node_texture_bricks.c @@ -21,107 +21,109 @@ * \ingroup texnodes */ - #include "node_texture_util.h" #include "NOD_texture.h" #include <math.h> static bNodeSocketTemplate inputs[] = { - { SOCK_RGBA, 1, N_("Bricks 1"), 0.596f, 0.282f, 0.0f, 1.0f }, - { SOCK_RGBA, 1, N_("Bricks 2"), 0.632f, 0.504f, 0.05f, 1.0f }, - { SOCK_RGBA, 1, N_("Mortar"), 0.0f, 0.0f, 0.0f, 1.0f }, - { SOCK_FLOAT, 1, N_("Thickness"), 0.02f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_UNSIGNED }, - { SOCK_FLOAT, 1, N_("Bias"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_NONE }, - { SOCK_FLOAT, 1, N_("Brick Width"), 0.5f, 0.0f, 0.0f, 0.0f, 0.001f, 99.0f, PROP_UNSIGNED }, - { SOCK_FLOAT, 1, N_("Row Height"), 0.25f, 0.0f, 0.0f, 0.0f, 0.001f, 99.0f, PROP_UNSIGNED }, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Bricks 1"), 0.596f, 0.282f, 0.0f, 1.0f}, + {SOCK_RGBA, 1, N_("Bricks 2"), 0.632f, 0.504f, 0.05f, 1.0f}, + {SOCK_RGBA, 1, N_("Mortar"), 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Thickness"), 0.02f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_UNSIGNED}, + {SOCK_FLOAT, 1, N_("Bias"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("Brick Width"), 0.5f, 0.0f, 0.0f, 0.0f, 0.001f, 99.0f, PROP_UNSIGNED}, + {SOCK_FLOAT, 1, N_("Row Height"), 0.25f, 0.0f, 0.0f, 0.0f, 0.001f, 99.0f, PROP_UNSIGNED}, + {-1, 0, ""}, }; static bNodeSocketTemplate outputs[] = { - { SOCK_RGBA, 0, N_("Color")}, - { -1, 0, ""}, + {SOCK_RGBA, 0, N_("Color")}, + {-1, 0, ""}, }; static void init(bNodeTree *UNUSED(ntree), bNode *node) { - node->custom3 = 0.5; /* offset */ - node->custom4 = 1.0; /* squash */ + node->custom3 = 0.5; /* offset */ + node->custom4 = 1.0; /* squash */ } static float noise(int n) /* fast integer noise */ { - int nn; - n = (n >> 13) ^ n; - nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff; - return 0.5f * ((float)nn / 1073741824.0f); + int nn; + n = (n >> 13) ^ n; + nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff; + return 0.5f * ((float)nn / 1073741824.0f); } static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread) { - const float *co = p->co; - - float x = co[0]; - float y = co[1]; - - int bricknum, rownum; - float offset = 0; - float ins_x, ins_y; - float tint; - - float bricks1[4]; - float bricks2[4]; - float mortar[4]; - - float mortar_thickness = tex_input_value(in[3], p, thread); - float bias = tex_input_value(in[4], p, thread); - float brick_width = tex_input_value(in[5], p, thread); - float row_height = tex_input_value(in[6], p, thread); - - tex_input_rgba(bricks1, in[0], p, thread); - tex_input_rgba(bricks2, in[1], p, thread); - tex_input_rgba(mortar, in[2], p, thread); - - rownum = (int)floor(y / row_height); - - if (node->custom1 && node->custom2) { - brick_width *= ((int)(rownum) % node->custom2) ? 1.0f : node->custom4; /* squash */ - offset = ((int)(rownum) % node->custom1) ? 0 : (brick_width * node->custom3); /* offset */ - } - - bricknum = (int)floor((x + offset) / brick_width); - - ins_x = (x + offset) - brick_width * bricknum; - ins_y = y - row_height * rownum; - - tint = noise((rownum << 16) + (bricknum & 0xFFFF)) + bias; - CLAMP(tint, 0.0f, 1.0f); - - if (ins_x < mortar_thickness || ins_y < mortar_thickness || - ins_x > (brick_width - mortar_thickness) || - ins_y > (row_height - mortar_thickness)) - { - copy_v4_v4(out, mortar); - } - else { - copy_v4_v4(out, bricks1); - ramp_blend(MA_RAMP_BLEND, out, tint, bricks2); - } + const float *co = p->co; + + float x = co[0]; + float y = co[1]; + + int bricknum, rownum; + float offset = 0; + float ins_x, ins_y; + float tint; + + float bricks1[4]; + float bricks2[4]; + float mortar[4]; + + float mortar_thickness = tex_input_value(in[3], p, thread); + float bias = tex_input_value(in[4], p, thread); + float brick_width = tex_input_value(in[5], p, thread); + float row_height = tex_input_value(in[6], p, thread); + + tex_input_rgba(bricks1, in[0], p, thread); + tex_input_rgba(bricks2, in[1], p, thread); + tex_input_rgba(mortar, in[2], p, thread); + + rownum = (int)floor(y / row_height); + + if (node->custom1 && node->custom2) { + brick_width *= ((int)(rownum) % node->custom2) ? 1.0f : node->custom4; /* squash */ + offset = ((int)(rownum) % node->custom1) ? 0 : (brick_width * node->custom3); /* offset */ + } + + bricknum = (int)floor((x + offset) / brick_width); + + ins_x = (x + offset) - brick_width * bricknum; + ins_y = y - row_height * rownum; + + tint = noise((rownum << 16) + (bricknum & 0xFFFF)) + bias; + CLAMP(tint, 0.0f, 1.0f); + + if (ins_x < mortar_thickness || ins_y < mortar_thickness || + ins_x > (brick_width - mortar_thickness) || ins_y > (row_height - mortar_thickness)) { + copy_v4_v4(out, mortar); + } + else { + copy_v4_v4(out, bricks1); + ramp_blend(MA_RAMP_BLEND, out, tint, bricks2); + } } -static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void exec(void *data, + int UNUSED(thread), + bNode *node, + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack **out) { - tex_output(node, execdata, in, out[0], &colorfn, data); + tex_output(node, execdata, in, out[0], &colorfn, data); } void register_node_type_tex_bricks(void) { - static bNodeType ntype; + static bNodeType ntype; - tex_node_type_base(&ntype, TEX_NODE_BRICKS, "Bricks", NODE_CLASS_PATTERN, NODE_PREVIEW); - node_type_socket_templates(&ntype, inputs, outputs); - node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); - node_type_init(&ntype, init); - node_type_exec(&ntype, NULL, NULL, exec); + tex_node_type_base(&ntype, TEX_NODE_BRICKS, "Bricks", NODE_CLASS_PATTERN, NODE_PREVIEW); + node_type_socket_templates(&ntype, inputs, outputs); + node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); + node_type_init(&ntype, init); + node_type_exec(&ntype, NULL, NULL, exec); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_checker.c b/source/blender/nodes/texture/nodes/node_texture_checker.c index 8cc40b7d5b0..33fc1a2c1f3 100644 --- a/source/blender/nodes/texture/nodes/node_texture_checker.c +++ b/source/blender/nodes/texture/nodes/node_texture_checker.c @@ -21,54 +21,58 @@ * \ingroup texnodes */ - #include "node_texture_util.h" #include "NOD_texture.h" #include <math.h> static bNodeSocketTemplate inputs[] = { - { SOCK_RGBA, 1, N_("Color1"), 1.0f, 0.0f, 0.0f, 1.0f }, - { SOCK_RGBA, 1, N_("Color2"), 1.0f, 1.0f, 1.0f, 1.0f }, - { SOCK_FLOAT, 1, N_("Size"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 100.0f, PROP_UNSIGNED }, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color1"), 1.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_RGBA, 1, N_("Color2"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Size"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 100.0f, PROP_UNSIGNED}, + {-1, 0, ""}, }; static bNodeSocketTemplate outputs[] = { - { SOCK_RGBA, 0, N_("Color") }, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color")}, + {-1, 0, ""}, }; static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) { - float x = p->co[0]; - float y = p->co[1]; - float z = p->co[2]; - float sz = tex_input_value(in[2], p, thread); + float x = p->co[0]; + float y = p->co[1]; + float z = p->co[2]; + float sz = tex_input_value(in[2], p, thread); - /* 0.00001 because of unit sized stuff */ - int xi = (int)fabs(floor(0.00001f + x / sz)); - int yi = (int)fabs(floor(0.00001f + y / sz)); - int zi = (int)fabs(floor(0.00001f + z / sz)); + /* 0.00001 because of unit sized stuff */ + int xi = (int)fabs(floor(0.00001f + x / sz)); + int yi = (int)fabs(floor(0.00001f + y / sz)); + int zi = (int)fabs(floor(0.00001f + z / sz)); - if ( (xi % 2 == yi % 2) == (zi % 2) ) { - tex_input_rgba(out, in[0], p, thread); - } - else { - tex_input_rgba(out, in[1], p, thread); - } + if ((xi % 2 == yi % 2) == (zi % 2)) { + tex_input_rgba(out, in[0], p, thread); + } + else { + tex_input_rgba(out, in[1], p, thread); + } } -static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void exec(void *data, + int UNUSED(thread), + bNode *node, + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack **out) { - tex_output(node, execdata, in, out[0], &colorfn, data); + tex_output(node, execdata, in, out[0], &colorfn, data); } void register_node_type_tex_checker(void) { - static bNodeType ntype; + static bNodeType ntype; - tex_node_type_base(&ntype, TEX_NODE_CHECKER, "Checker", NODE_CLASS_PATTERN, NODE_PREVIEW); - node_type_socket_templates(&ntype, inputs, outputs); - node_type_exec(&ntype, NULL, NULL, exec); + tex_node_type_base(&ntype, TEX_NODE_CHECKER, "Checker", NODE_CLASS_PATTERN, NODE_PREVIEW); + node_type_socket_templates(&ntype, inputs, outputs); + node_type_exec(&ntype, NULL, NULL, exec); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_common.c b/source/blender/nodes/texture/nodes/node_texture_common.c index 3efc01d25d6..9f76c464c12 100644 --- a/source/blender/nodes/texture/nodes/node_texture_common.c +++ b/source/blender/nodes/texture/nodes/node_texture_common.c @@ -22,7 +22,6 @@ * \ingroup texnodes */ - #include "DNA_node_types.h" #include "BLI_utildefines.h" @@ -38,37 +37,37 @@ static void copy_stack(bNodeStack *to, bNodeStack *from) { - if (to != from) { - copy_v4_v4(to->vec, from->vec); - to->data = from->data; - to->datatype = from->datatype; - - /* tag as copy to prevent freeing */ - to->is_copy = 1; - } + if (to != from) { + copy_v4_v4(to->vec, from->vec); + to->data = from->data; + to->datatype = from->datatype; + + /* tag as copy to prevent freeing */ + to->is_copy = 1; + } } /**** GROUP ****/ static void *group_initexec(bNodeExecContext *context, bNode *node, bNodeInstanceKey key) { - bNodeTree *ngroup = (bNodeTree *)node->id; - void *exec; + bNodeTree *ngroup = (bNodeTree *)node->id; + void *exec; - if (!ngroup) - return NULL; + if (!ngroup) + return NULL; - /* initialize the internal node tree execution */ - exec = ntreeTexBeginExecTree_internal(context, ngroup, key); + /* initialize the internal node tree execution */ + exec = ntreeTexBeginExecTree_internal(context, ngroup, key); - return exec; + return exec; } static void group_freeexec(void *nodedata) { - bNodeTreeExec *gexec = (bNodeTreeExec *)nodedata; + bNodeTreeExec *gexec = (bNodeTreeExec *)nodedata; - ntreeTexEndExecTree_internal(gexec); + ntreeTexEndExecTree_internal(gexec); } /* Copy inputs to the internal stack. @@ -76,99 +75,104 @@ static void group_freeexec(void *nodedata) */ static void group_copy_inputs(bNode *gnode, bNodeStack **in, bNodeStack *gstack) { - bNodeTree *ngroup = (bNodeTree *)gnode->id; - bNode *node; - bNodeSocket *sock; - bNodeStack *ns; - int a; - - for (node = ngroup->nodes.first; node; node = node->next) { - if (node->type == NODE_GROUP_INPUT) { - for (sock = node->outputs.first, a = 0; sock; sock = sock->next, ++a) { - if (in[a]) { /* shouldn't need to check this [#36694] */ - ns = node_get_socket_stack(gstack, sock); - if (ns) { - copy_stack(ns, in[a]); - } - } - } - } - } + bNodeTree *ngroup = (bNodeTree *)gnode->id; + bNode *node; + bNodeSocket *sock; + bNodeStack *ns; + int a; + + for (node = ngroup->nodes.first; node; node = node->next) { + if (node->type == NODE_GROUP_INPUT) { + for (sock = node->outputs.first, a = 0; sock; sock = sock->next, ++a) { + if (in[a]) { /* shouldn't need to check this [#36694] */ + ns = node_get_socket_stack(gstack, sock); + if (ns) { + copy_stack(ns, in[a]); + } + } + } + } + } } /* Copy internal results to the external outputs. */ static void group_copy_outputs(bNode *gnode, bNodeStack **out, bNodeStack *gstack) { - bNodeTree *ngroup = (bNodeTree *)gnode->id; - bNode *node; - bNodeSocket *sock; - bNodeStack *ns; - int a; - - for (node = ngroup->nodes.first; node; node = node->next) { - if (node->type == NODE_GROUP_OUTPUT && (node->flag & NODE_DO_OUTPUT)) { - for (sock = node->inputs.first, a = 0; sock; sock = sock->next, ++a) { - if (out[a]) { /* shouldn't need to check this [#36694] */ - ns = node_get_socket_stack(gstack, sock); - if (ns) { - copy_stack(out[a], ns); - } - } - } - break; /* only one active output node */ - } - } + bNodeTree *ngroup = (bNodeTree *)gnode->id; + bNode *node; + bNodeSocket *sock; + bNodeStack *ns; + int a; + + for (node = ngroup->nodes.first; node; node = node->next) { + if (node->type == NODE_GROUP_OUTPUT && (node->flag & NODE_DO_OUTPUT)) { + for (sock = node->inputs.first, a = 0; sock; sock = sock->next, ++a) { + if (out[a]) { /* shouldn't need to check this [#36694] */ + ns = node_get_socket_stack(gstack, sock); + if (ns) { + copy_stack(out[a], ns); + } + } + } + break; /* only one active output node */ + } + } } -static void group_execute(void *data, int thread, struct bNode *node, bNodeExecData *execdata, struct bNodeStack **in, struct bNodeStack **out) +static void group_execute(void *data, + int thread, + struct bNode *node, + bNodeExecData *execdata, + struct bNodeStack **in, + struct bNodeStack **out) { - bNodeTreeExec *exec = execdata->data; - bNodeThreadStack *nts; + bNodeTreeExec *exec = execdata->data; + bNodeThreadStack *nts; - if (!exec) - return; + if (!exec) + return; - /* XXX same behavior as trunk: all nodes inside group are executed. - * it's stupid, but just makes it work. compo redesign will do this better. - */ - { - bNode *inode; - for (inode = exec->nodetree->nodes.first; inode; inode = inode->next) - inode->need_exec = 1; - } + /* XXX same behavior as trunk: all nodes inside group are executed. + * it's stupid, but just makes it work. compo redesign will do this better. + */ + { + bNode *inode; + for (inode = exec->nodetree->nodes.first; inode; inode = inode->next) + inode->need_exec = 1; + } - nts = ntreeGetThreadStack(exec, thread); + nts = ntreeGetThreadStack(exec, thread); - group_copy_inputs(node, in, nts->stack); - ntreeExecThreadNodes(exec, nts, data, thread); - group_copy_outputs(node, out, nts->stack); + group_copy_inputs(node, in, nts->stack); + ntreeExecThreadNodes(exec, nts, data, thread); + group_copy_outputs(node, out, nts->stack); - ntreeReleaseThreadStack(nts); + ntreeReleaseThreadStack(nts); } void register_node_type_tex_group(void) { - static bNodeType ntype; - - /* NB: cannot use sh_node_type_base for node group, because it would map the node type - * to the shared NODE_GROUP integer type id. - */ - node_type_base_custom(&ntype, "TextureNodeGroup", "Group", NODE_CLASS_GROUP, NODE_CONST_OUTPUT); - ntype.type = NODE_GROUP; - ntype.poll = tex_node_poll_default; - ntype.poll_instance = node_group_poll_instance; - ntype.insert_link = node_insert_link_default; - ntype.update_internal_links = node_update_internal_links_default; - ntype.ext.srna = RNA_struct_find("TextureNodeGroup"); - BLI_assert(ntype.ext.srna != NULL); - RNA_struct_blender_type_set(ntype.ext.srna, &ntype); - - node_type_socket_templates(&ntype, NULL, NULL); - node_type_size(&ntype, 140, 60, 400); - node_type_label(&ntype, node_group_label); - node_type_update(&ntype, NULL, node_group_verify); - node_type_exec(&ntype, group_initexec, group_freeexec, group_execute); - - nodeRegisterType(&ntype); + static bNodeType ntype; + + /* NB: cannot use sh_node_type_base for node group, because it would map the node type + * to the shared NODE_GROUP integer type id. + */ + node_type_base_custom(&ntype, "TextureNodeGroup", "Group", NODE_CLASS_GROUP, NODE_CONST_OUTPUT); + ntype.type = NODE_GROUP; + ntype.poll = tex_node_poll_default; + ntype.poll_instance = node_group_poll_instance; + ntype.insert_link = node_insert_link_default; + ntype.update_internal_links = node_update_internal_links_default; + ntype.ext.srna = RNA_struct_find("TextureNodeGroup"); + BLI_assert(ntype.ext.srna != NULL); + RNA_struct_blender_type_set(ntype.ext.srna, &ntype); + + node_type_socket_templates(&ntype, NULL, NULL); + node_type_size(&ntype, 140, 60, 400); + node_type_label(&ntype, node_group_label); + node_type_update(&ntype, NULL, node_group_verify); + node_type_exec(&ntype, group_initexec, group_freeexec, group_execute); + + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_compose.c b/source/blender/nodes/texture/nodes/node_texture_compose.c index 767e4aee03e..ae266451671 100644 --- a/source/blender/nodes/texture/nodes/node_texture_compose.c +++ b/source/blender/nodes/texture/nodes/node_texture_compose.c @@ -21,41 +21,45 @@ * \ingroup texnodes */ - #include "node_texture_util.h" #include "NOD_texture.h" static bNodeSocketTemplate inputs[] = { - { SOCK_FLOAT, 1, N_("Red"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_UNSIGNED }, - { SOCK_FLOAT, 1, N_("Green"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_UNSIGNED }, - { SOCK_FLOAT, 1, N_("Blue"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_UNSIGNED }, - { SOCK_FLOAT, 1, N_("Alpha"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_UNSIGNED }, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Red"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_UNSIGNED}, + {SOCK_FLOAT, 1, N_("Green"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_UNSIGNED}, + {SOCK_FLOAT, 1, N_("Blue"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_UNSIGNED}, + {SOCK_FLOAT, 1, N_("Alpha"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_UNSIGNED}, + {-1, 0, ""}, }; static bNodeSocketTemplate outputs[] = { - { SOCK_RGBA, 0, N_("Color") }, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color")}, + {-1, 0, ""}, }; static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) { - int i; - for (i = 0; i < 4; i++) - out[i] = tex_input_value(in[i], p, thread); + int i; + for (i = 0; i < 4; i++) + out[i] = tex_input_value(in[i], p, thread); } -static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void exec(void *data, + int UNUSED(thread), + bNode *node, + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack **out) { - tex_output(node, execdata, in, out[0], &colorfn, data); + tex_output(node, execdata, in, out[0], &colorfn, data); } void register_node_type_tex_compose(void) { - static bNodeType ntype; + static bNodeType ntype; - tex_node_type_base(&ntype, TEX_NODE_COMPOSE, "Combine RGBA", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, inputs, outputs); - node_type_exec(&ntype, NULL, NULL, exec); + tex_node_type_base(&ntype, TEX_NODE_COMPOSE, "Combine RGBA", NODE_CLASS_OP_COLOR, 0); + node_type_socket_templates(&ntype, inputs, outputs); + node_type_exec(&ntype, NULL, NULL, exec); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_coord.c b/source/blender/nodes/texture/nodes/node_texture_coord.c index 8859e27cd6c..30911eae1a3 100644 --- a/source/blender/nodes/texture/nodes/node_texture_coord.c +++ b/source/blender/nodes/texture/nodes/node_texture_coord.c @@ -21,33 +21,38 @@ * \ingroup texnodes */ - #include "node_texture_util.h" #include "NOD_texture.h" static bNodeSocketTemplate outputs[] = { - { SOCK_VECTOR, 0, N_("Coordinates") }, - { -1, 0, "" }, + {SOCK_VECTOR, 0, N_("Coordinates")}, + {-1, 0, ""}, }; -static void vectorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **UNUSED(in), short UNUSED(thread)) +static void vectorfn( + float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **UNUSED(in), short UNUSED(thread)) { - copy_v3_v3(out, p->co); + copy_v3_v3(out, p->co); } -static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void exec(void *data, + int UNUSED(thread), + bNode *node, + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack **out) { - tex_output(node, execdata, in, out[0], &vectorfn, data); + tex_output(node, execdata, in, out[0], &vectorfn, data); } void register_node_type_tex_coord(void) { - static bNodeType ntype; + static bNodeType ntype; - tex_node_type_base(&ntype, TEX_NODE_COORD, "Coordinates", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, NULL, outputs); - node_type_storage(&ntype, "", NULL, NULL); - node_type_exec(&ntype, NULL, NULL, exec); + tex_node_type_base(&ntype, TEX_NODE_COORD, "Coordinates", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, NULL, outputs); + node_type_storage(&ntype, "", NULL, NULL); + node_type_exec(&ntype, NULL, NULL, exec); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_curves.c b/source/blender/nodes/texture/nodes/node_texture_curves.c index d0d387f3fa6..a57e2d8f35f 100644 --- a/source/blender/nodes/texture/nodes/node_texture_curves.c +++ b/source/blender/nodes/texture/nodes/node_texture_curves.c @@ -21,98 +21,104 @@ * \ingroup texnodes */ - #include "node_texture_util.h" #include "NOD_texture.h" /* **************** CURVE Time ******************** */ /* custom1 = sfra, custom2 = efra */ -static bNodeSocketTemplate time_outputs[] = { - { SOCK_FLOAT, 0, N_("Value") }, - { -1, 0, "" } -}; +static bNodeSocketTemplate time_outputs[] = {{SOCK_FLOAT, 0, N_("Value")}, {-1, 0, ""}}; -static void time_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **UNUSED(in), short UNUSED(thread)) +static void time_colorfn( + float *out, TexParams *p, bNode *node, bNodeStack **UNUSED(in), short UNUSED(thread)) { - /* stack order output: fac */ - float fac = 0.0f; + /* stack order output: fac */ + float fac = 0.0f; - if (node->custom1 < node->custom2) - fac = (p->cfra - node->custom1) / (float)(node->custom2 - node->custom1); + if (node->custom1 < node->custom2) + fac = (p->cfra - node->custom1) / (float)(node->custom2 - node->custom1); - curvemapping_initialize(node->storage); - fac = curvemapping_evaluateF(node->storage, 0, fac); - out[0] = CLAMPIS(fac, 0.0f, 1.0f); + curvemapping_initialize(node->storage); + fac = curvemapping_evaluateF(node->storage, 0, fac); + out[0] = CLAMPIS(fac, 0.0f, 1.0f); } -static void time_exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void time_exec(void *data, + int UNUSED(thread), + bNode *node, + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack **out) { - tex_output(node, execdata, in, out[0], &time_colorfn, data); + tex_output(node, execdata, in, out[0], &time_colorfn, data); } - static void time_init(bNodeTree *UNUSED(ntree), bNode *node) { - node->custom1 = 1; - node->custom2 = 250; - node->storage = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + node->custom1 = 1; + node->custom2 = 250; + node->storage = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); } void register_node_type_tex_curve_time(void) { - static bNodeType ntype; + static bNodeType ntype; - tex_node_type_base(&ntype, TEX_NODE_CURVE_TIME, "Time", NODE_CLASS_INPUT, 0); - node_type_socket_templates(&ntype, NULL, time_outputs); - node_type_size_preset(&ntype, NODE_SIZE_LARGE); - node_type_init(&ntype, time_init); - node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); - node_type_exec(&ntype, node_initexec_curves, NULL, time_exec); + tex_node_type_base(&ntype, TEX_NODE_CURVE_TIME, "Time", NODE_CLASS_INPUT, 0); + node_type_socket_templates(&ntype, NULL, time_outputs); + node_type_size_preset(&ntype, NODE_SIZE_LARGE); + node_type_init(&ntype, time_init); + node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); + node_type_exec(&ntype, node_initexec_curves, NULL, time_exec); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } /* **************** CURVE RGB ******************** */ static bNodeSocketTemplate rgb_inputs[] = { - { SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate rgb_outputs[] = { - { SOCK_RGBA, 0, N_("Color")}, - { -1, 0, ""}, + {SOCK_RGBA, 0, N_("Color")}, + {-1, 0, ""}, }; static void rgb_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread) { - float cin[4]; - tex_input_rgba(cin, in[0], p, thread); + float cin[4]; + tex_input_rgba(cin, in[0], p, thread); - curvemapping_evaluateRGBF(node->storage, out, cin); - out[3] = cin[3]; + curvemapping_evaluateRGBF(node->storage, out, cin); + out[3] = cin[3]; } -static void rgb_exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void rgb_exec(void *data, + int UNUSED(thread), + bNode *node, + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack **out) { - tex_output(node, execdata, in, out[0], &rgb_colorfn, data); + tex_output(node, execdata, in, out[0], &rgb_colorfn, data); } static void rgb_init(bNodeTree *UNUSED(ntree), bNode *node) { - node->storage = curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f); + node->storage = curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f); } void register_node_type_tex_curve_rgb(void) { - static bNodeType ntype; + static bNodeType ntype; - tex_node_type_base(&ntype, TEX_NODE_CURVE_RGB, "RGB Curves", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, rgb_inputs, rgb_outputs); - node_type_size_preset(&ntype, NODE_SIZE_LARGE); - node_type_init(&ntype, rgb_init); - node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); - node_type_exec(&ntype, node_initexec_curves, NULL, rgb_exec); + tex_node_type_base(&ntype, TEX_NODE_CURVE_RGB, "RGB Curves", NODE_CLASS_OP_COLOR, 0); + node_type_socket_templates(&ntype, rgb_inputs, rgb_outputs); + node_type_size_preset(&ntype, NODE_SIZE_LARGE); + node_type_init(&ntype, rgb_init); + node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); + node_type_exec(&ntype, node_initexec_curves, NULL, rgb_exec); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_decompose.c b/source/blender/nodes/texture/nodes/node_texture_decompose.c index e531eb6c816..999b2c30448 100644 --- a/source/blender/nodes/texture/nodes/node_texture_decompose.c +++ b/source/blender/nodes/texture/nodes/node_texture_decompose.c @@ -21,62 +21,66 @@ * \ingroup texnodes */ - #include "node_texture_util.h" #include "NOD_texture.h" #include <math.h> static bNodeSocketTemplate inputs[] = { - { SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f }, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate outputs[] = { - { SOCK_FLOAT, 0, N_("Red") }, - { SOCK_FLOAT, 0, N_("Green") }, - { SOCK_FLOAT, 0, N_("Blue") }, - { SOCK_FLOAT, 0, N_("Alpha") }, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("Red")}, + {SOCK_FLOAT, 0, N_("Green")}, + {SOCK_FLOAT, 0, N_("Blue")}, + {SOCK_FLOAT, 0, N_("Alpha")}, + {-1, 0, ""}, }; static void valuefn_r(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) { - tex_input_rgba(out, in[0], p, thread); - *out = out[0]; + tex_input_rgba(out, in[0], p, thread); + *out = out[0]; } static void valuefn_g(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) { - tex_input_rgba(out, in[0], p, thread); - *out = out[1]; + tex_input_rgba(out, in[0], p, thread); + *out = out[1]; } static void valuefn_b(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) { - tex_input_rgba(out, in[0], p, thread); - *out = out[2]; + tex_input_rgba(out, in[0], p, thread); + *out = out[2]; } static void valuefn_a(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) { - tex_input_rgba(out, in[0], p, thread); - *out = out[3]; + tex_input_rgba(out, in[0], p, thread); + *out = out[3]; } -static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void exec(void *data, + int UNUSED(thread), + bNode *node, + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack **out) { - tex_output(node, execdata, in, out[0], &valuefn_r, data); - tex_output(node, execdata, in, out[1], &valuefn_g, data); - tex_output(node, execdata, in, out[2], &valuefn_b, data); - tex_output(node, execdata, in, out[3], &valuefn_a, data); + tex_output(node, execdata, in, out[0], &valuefn_r, data); + tex_output(node, execdata, in, out[1], &valuefn_g, data); + tex_output(node, execdata, in, out[2], &valuefn_b, data); + tex_output(node, execdata, in, out[3], &valuefn_a, data); } void register_node_type_tex_decompose(void) { - static bNodeType ntype; + static bNodeType ntype; - tex_node_type_base(&ntype, TEX_NODE_DECOMPOSE, "Separate RGBA", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, inputs, outputs); - node_type_exec(&ntype, NULL, NULL, exec); + tex_node_type_base(&ntype, TEX_NODE_DECOMPOSE, "Separate RGBA", NODE_CLASS_OP_COLOR, 0); + node_type_socket_templates(&ntype, inputs, outputs); + node_type_exec(&ntype, NULL, NULL, exec); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_distance.c b/source/blender/nodes/texture/nodes/node_texture_distance.c index fed8fe6b866..e7df8b3073a 100644 --- a/source/blender/nodes/texture/nodes/node_texture_distance.c +++ b/source/blender/nodes/texture/nodes/node_texture_distance.c @@ -21,46 +21,50 @@ * \ingroup texnodes */ - #include <math.h> #include "BLI_math.h" #include "node_texture_util.h" #include "NOD_texture.h" static bNodeSocketTemplate inputs[] = { - { SOCK_VECTOR, 1, N_("Coordinate 1"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_NONE }, - { SOCK_VECTOR, 1, N_("Coordinate 2"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_NONE }, - { -1, 0, "" }, + {SOCK_VECTOR, 1, N_("Coordinate 1"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_NONE}, + {SOCK_VECTOR, 1, N_("Coordinate 2"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate outputs[] = { - { SOCK_FLOAT, 0, N_("Value") }, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("Value")}, + {-1, 0, ""}, }; static void valuefn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) { - float co1[3], co2[3]; + float co1[3], co2[3]; - tex_input_vec(co1, in[0], p, thread); - tex_input_vec(co2, in[1], p, thread); + tex_input_vec(co1, in[0], p, thread); + tex_input_vec(co2, in[1], p, thread); - *out = len_v3v3(co2, co1); + *out = len_v3v3(co2, co1); } -static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void exec(void *data, + int UNUSED(thread), + bNode *node, + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack **out) { - tex_output(node, execdata, in, out[0], &valuefn, data); + tex_output(node, execdata, in, out[0], &valuefn, data); } void register_node_type_tex_distance(void) { - static bNodeType ntype; + static bNodeType ntype; - tex_node_type_base(&ntype, TEX_NODE_DISTANCE, "Distance", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, inputs, outputs); - node_type_storage(&ntype, "", NULL, NULL); - node_type_exec(&ntype, NULL, NULL, exec); + tex_node_type_base(&ntype, TEX_NODE_DISTANCE, "Distance", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, inputs, outputs); + node_type_storage(&ntype, "", NULL, NULL); + node_type_exec(&ntype, NULL, NULL, exec); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_hueSatVal.c b/source/blender/nodes/texture/nodes/node_texture_hueSatVal.c index 8e4959bdf06..c4105083945 100644 --- a/source/blender/nodes/texture/nodes/node_texture_hueSatVal.c +++ b/source/blender/nodes/texture/nodes/node_texture_hueSatVal.c @@ -21,77 +21,90 @@ * \ingroup texnodes */ - #include "node_texture_util.h" #include "NOD_texture.h" - static bNodeSocketTemplate inputs[] = { - { SOCK_FLOAT, 1, N_("Hue"), 0.0f, 0.0f, 0.0f, 0.0f, -0.5f, 0.5f, PROP_NONE }, - { SOCK_FLOAT, 1, N_("Saturation"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, PROP_NONE }, - { SOCK_FLOAT, 1, N_("Value"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, PROP_NONE }, - { SOCK_FLOAT, 1, N_("Factor"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE }, - { SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f }, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Hue"), 0.0f, 0.0f, 0.0f, 0.0f, -0.5f, 0.5f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("Saturation"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("Value"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("Factor"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, + {SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate outputs[] = { - { SOCK_RGBA, 0, N_("Color") }, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color")}, + {-1, 0, ""}, }; -static void do_hue_sat_fac(bNode *UNUSED(node), float *out, float hue, float sat, float val, float *in, float fac) +static void do_hue_sat_fac( + bNode *UNUSED(node), float *out, float hue, float sat, float val, float *in, float fac) { - if (fac != 0 && (hue != 0.5f || sat != 1 || val != 1)) { - float col[3], hsv[3], mfac = 1.0f - fac; - - rgb_to_hsv(in[0], in[1], in[2], hsv, hsv + 1, hsv + 2); - hsv[0] += (hue - 0.5f); - if (hsv[0] > 1.0f) hsv[0] -= 1.0f; else if (hsv[0] < 0.0f) hsv[0] += 1.0f; - hsv[1] *= sat; - if (hsv[1] > 1.0f) hsv[1] = 1.0f; else if (hsv[1] < 0.0f) hsv[1] = 0.0f; - hsv[2] *= val; - if (hsv[2] > 1.0f) hsv[2] = 1.0f; else if (hsv[2] < 0.0f) hsv[2] = 0.0f; - hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col + 1, col + 2); - - out[0] = mfac * in[0] + fac * col[0]; - out[1] = mfac * in[1] + fac * col[1]; - out[2] = mfac * in[2] + fac * col[2]; - } - else { - copy_v4_v4(out, in); - } + if (fac != 0 && (hue != 0.5f || sat != 1 || val != 1)) { + float col[3], hsv[3], mfac = 1.0f - fac; + + rgb_to_hsv(in[0], in[1], in[2], hsv, hsv + 1, hsv + 2); + hsv[0] += (hue - 0.5f); + if (hsv[0] > 1.0f) + hsv[0] -= 1.0f; + else if (hsv[0] < 0.0f) + hsv[0] += 1.0f; + hsv[1] *= sat; + if (hsv[1] > 1.0f) + hsv[1] = 1.0f; + else if (hsv[1] < 0.0f) + hsv[1] = 0.0f; + hsv[2] *= val; + if (hsv[2] > 1.0f) + hsv[2] = 1.0f; + else if (hsv[2] < 0.0f) + hsv[2] = 0.0f; + hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col + 1, col + 2); + + out[0] = mfac * in[0] + fac * col[0]; + out[1] = mfac * in[1] + fac * col[1]; + out[2] = mfac * in[2] + fac * col[2]; + } + else { + copy_v4_v4(out, in); + } } static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread) { - float hue = tex_input_value(in[0], p, thread); - float sat = tex_input_value(in[1], p, thread); - float val = tex_input_value(in[2], p, thread); - float fac = tex_input_value(in[3], p, thread); + float hue = tex_input_value(in[0], p, thread); + float sat = tex_input_value(in[1], p, thread); + float val = tex_input_value(in[2], p, thread); + float fac = tex_input_value(in[3], p, thread); - float col[4]; - tex_input_rgba(col, in[4], p, thread); + float col[4]; + tex_input_rgba(col, in[4], p, thread); - hue += 0.5f; /* [-0.5, 0.5] -> [0, 1] */ + hue += 0.5f; /* [-0.5, 0.5] -> [0, 1] */ - do_hue_sat_fac(node, out, hue, sat, val, col, fac); + do_hue_sat_fac(node, out, hue, sat, val, col, fac); - out[3] = col[3]; + out[3] = col[3]; } -static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void exec(void *data, + int UNUSED(thread), + bNode *node, + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack **out) { - tex_output(node, execdata, in, out[0], &colorfn, data); + tex_output(node, execdata, in, out[0], &colorfn, data); } void register_node_type_tex_hue_sat(void) { - static bNodeType ntype; + static bNodeType ntype; - tex_node_type_base(&ntype, TEX_NODE_HUE_SAT, "Hue Saturation Value", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, inputs, outputs); - node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); - node_type_exec(&ntype, NULL, NULL, exec); + tex_node_type_base(&ntype, TEX_NODE_HUE_SAT, "Hue Saturation Value", NODE_CLASS_OP_COLOR, 0); + node_type_socket_templates(&ntype, inputs, outputs); + node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); + node_type_exec(&ntype, NULL, NULL, exec); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_image.c b/source/blender/nodes/texture/nodes/node_texture_image.c index 1975a9df306..5c7b7a56d3a 100644 --- a/source/blender/nodes/texture/nodes/node_texture_image.c +++ b/source/blender/nodes/texture/nodes/node_texture_image.c @@ -21,84 +21,94 @@ * \ingroup texnodes */ - #include "node_texture_util.h" #include "NOD_texture.h" static bNodeSocketTemplate outputs[] = { - { SOCK_RGBA, 0, N_("Image")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Image")}, + {-1, 0, ""}, }; -static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **UNUSED(in), short UNUSED(thread)) +static void colorfn( + float *out, TexParams *p, bNode *node, bNodeStack **UNUSED(in), short UNUSED(thread)) { - float x = p->co[0]; - float y = p->co[1]; - Image *ima = (Image *)node->id; - ImageUser *iuser = (ImageUser *)node->storage; - - if (ima) { - ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL); - if (ibuf) { - float xsize, ysize; - float xoff, yoff; - int px, py; - - const float *result; - - xsize = ibuf->x / 2; - ysize = ibuf->y / 2; - xoff = yoff = -1; - - px = (int)( (x - xoff) * xsize); - py = (int)( (y - yoff) * ysize); - - if ( (!xsize) || (!ysize) ) return; - - if (!ibuf->rect_float) { - BLI_thread_lock(LOCK_IMAGE); - if (!ibuf->rect_float) - IMB_float_from_rect(ibuf); - BLI_thread_unlock(LOCK_IMAGE); - } - - while (px < 0) px += ibuf->x; - while (py < 0) py += ibuf->y; - while (px >= ibuf->x) px -= ibuf->x; - while (py >= ibuf->y) py -= ibuf->y; - - result = ibuf->rect_float + py * ibuf->x * 4 + px * 4; - copy_v4_v4(out, result); - - BKE_image_release_ibuf(ima, ibuf, NULL); - } - } + float x = p->co[0]; + float y = p->co[1]; + Image *ima = (Image *)node->id; + ImageUser *iuser = (ImageUser *)node->storage; + + if (ima) { + ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL); + if (ibuf) { + float xsize, ysize; + float xoff, yoff; + int px, py; + + const float *result; + + xsize = ibuf->x / 2; + ysize = ibuf->y / 2; + xoff = yoff = -1; + + px = (int)((x - xoff) * xsize); + py = (int)((y - yoff) * ysize); + + if ((!xsize) || (!ysize)) + return; + + if (!ibuf->rect_float) { + BLI_thread_lock(LOCK_IMAGE); + if (!ibuf->rect_float) + IMB_float_from_rect(ibuf); + BLI_thread_unlock(LOCK_IMAGE); + } + + while (px < 0) + px += ibuf->x; + while (py < 0) + py += ibuf->y; + while (px >= ibuf->x) + px -= ibuf->x; + while (py >= ibuf->y) + py -= ibuf->y; + + result = ibuf->rect_float + py * ibuf->x * 4 + px * 4; + copy_v4_v4(out, result); + + BKE_image_release_ibuf(ima, ibuf, NULL); + } + } } -static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void exec(void *data, + int UNUSED(thread), + bNode *node, + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack **out) { - tex_output(node, execdata, in, out[0], &colorfn, data); + tex_output(node, execdata, in, out[0], &colorfn, data); } static void init(bNodeTree *UNUSED(ntree), bNode *node) { - ImageUser *iuser = MEM_callocN(sizeof(ImageUser), "node image user"); - node->storage = iuser; - iuser->sfra = 1; - iuser->ok = 1; - iuser->flag |= IMA_ANIM_ALWAYS; + ImageUser *iuser = MEM_callocN(sizeof(ImageUser), "node image user"); + node->storage = iuser; + iuser->sfra = 1; + iuser->ok = 1; + iuser->flag |= IMA_ANIM_ALWAYS; } void register_node_type_tex_image(void) { - static bNodeType ntype; + static bNodeType ntype; - tex_node_type_base(&ntype, TEX_NODE_IMAGE, "Image", NODE_CLASS_INPUT, NODE_PREVIEW); - node_type_socket_templates(&ntype, NULL, outputs); - node_type_init(&ntype, init); - node_type_storage(&ntype, "ImageUser", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, NULL, NULL, exec); - node_type_label(&ntype, node_image_label); + tex_node_type_base(&ntype, TEX_NODE_IMAGE, "Image", NODE_CLASS_INPUT, NODE_PREVIEW); + node_type_socket_templates(&ntype, NULL, outputs); + node_type_init(&ntype, init); + node_type_storage(&ntype, "ImageUser", node_free_standard_storage, node_copy_standard_storage); + node_type_exec(&ntype, NULL, NULL, exec); + node_type_label(&ntype, node_image_label); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_invert.c b/source/blender/nodes/texture/nodes/node_texture_invert.c index 60cc135a8d4..7bc335849bc 100644 --- a/source/blender/nodes/texture/nodes/node_texture_invert.c +++ b/source/blender/nodes/texture/nodes/node_texture_invert.c @@ -21,47 +21,51 @@ * \ingroup texnodes */ - #include "node_texture_util.h" #include "NOD_texture.h" /* **************** INVERT ******************** */ static bNodeSocketTemplate inputs[] = { - { SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate outputs[] = { - { SOCK_RGBA, 0, N_("Color")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color")}, + {-1, 0, ""}, }; static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) { - float col[4]; + float col[4]; - tex_input_rgba(col, in[0], p, thread); + tex_input_rgba(col, in[0], p, thread); - col[0] = 1.0f - col[0]; - col[1] = 1.0f - col[1]; - col[2] = 1.0f - col[2]; + col[0] = 1.0f - col[0]; + col[1] = 1.0f - col[1]; + col[2] = 1.0f - col[2]; - copy_v3_v3(out, col); - out[3] = col[3]; + copy_v3_v3(out, col); + out[3] = col[3]; } -static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void exec(void *data, + int UNUSED(thread), + bNode *node, + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack **out) { - tex_output(node, execdata, in, out[0], &colorfn, data); + tex_output(node, execdata, in, out[0], &colorfn, data); } void register_node_type_tex_invert(void) { - static bNodeType ntype; + static bNodeType ntype; - tex_node_type_base(&ntype, TEX_NODE_INVERT, "Invert", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, inputs, outputs); - node_type_exec(&ntype, NULL, NULL, exec); + tex_node_type_base(&ntype, TEX_NODE_INVERT, "Invert", NODE_CLASS_OP_COLOR, 0); + node_type_socket_templates(&ntype, inputs, outputs); + node_type_exec(&ntype, NULL, NULL, exec); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_math.c b/source/blender/nodes/texture/nodes/node_texture_math.c index 45205b6eac0..8b934be3698 100644 --- a/source/blender/nodes/texture/nodes/node_texture_math.c +++ b/source/blender/nodes/texture/nodes/node_texture_math.c @@ -21,225 +21,206 @@ * \ingroup texnodes */ - #include "node_texture_util.h" #include "NOD_texture.h" - /* **************** SCALAR MATH ******************** */ static bNodeSocketTemplate inputs[] = { - { SOCK_FLOAT, 1, N_("Value"), 0.5f, 0.5f, 0.5f, 1.0f, -100.0f, 100.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("Value"), 0.5f, 0.5f, 0.5f, 1.0f, -100.0f, 100.0f, PROP_NONE}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Value"), 0.5f, 0.5f, 0.5f, 1.0f, -100.0f, 100.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("Value"), 0.5f, 0.5f, 0.5f, 1.0f, -100.0f, 100.0f, PROP_NONE}, + {-1, 0, ""}, }; static bNodeSocketTemplate outputs[] = { - { SOCK_FLOAT, 0, N_("Value")}, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("Value")}, + {-1, 0, ""}, }; static void valuefn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread) { - float in0 = tex_input_value(in[0], p, thread); - float in1 = tex_input_value(in[1], p, thread); - - switch (node->custom1) { - - case NODE_MATH_ADD: - *out = in0 + in1; - break; - case NODE_MATH_SUB: - *out = in0 - in1; - break; - case NODE_MATH_MUL: - *out = in0 * in1; - break; - case NODE_MATH_DIVIDE: - { - if (in1 == 0) /* We don't want to divide by zero. */ - *out = 0.0; - else - *out = in0 / in1; - break; - } - case NODE_MATH_SIN: - { - *out = sinf(in0); - break; - } - case NODE_MATH_COS: - { - *out = cosf(in0); - break; - } - case NODE_MATH_TAN: - { - *out = tanf(in0); - break; - } - case NODE_MATH_ASIN: - { - /* Can't do the impossible... */ - if (in0 <= 1 && in0 >= -1) - *out = asinf(in0); - else - *out = 0.0; - break; - } - case NODE_MATH_ACOS: - { - /* Can't do the impossible... */ - if (in0 <= 1 && in0 >= -1) - *out = acosf(in0); - else - *out = 0.0; - break; - } - case NODE_MATH_ATAN: - { - *out = atan(in0); - break; - } - case NODE_MATH_POW: - { - /* Only raise negative numbers by full integers */ - if (in0 >= 0) { - out[0] = pow(in0, in1); - } - else { - float y_mod_1 = fmod(in1, 1); - if (y_mod_1 > 0.999f || y_mod_1 < 0.001f) { - *out = pow(in0, floor(in1 + 0.5f)); - } - else { - *out = 0.0; - } - } - break; - } - case NODE_MATH_LOG: - { - /* Don't want any imaginary numbers... */ - if (in0 > 0 && in1 > 0) - *out = log(in0) / log(in1); - else - *out = 0.0; - break; - } - case NODE_MATH_MIN: - { - if (in0 < in1) - *out = in0; - else - *out = in1; - break; - } - case NODE_MATH_MAX: - { - if (in0 > in1) - *out = in0; - else - *out = in1; - break; - } - case NODE_MATH_ROUND: - { - *out = (in0 < 0) ? (int)(in0 - 0.5f) : (int)(in0 + 0.5f); - break; - } - - case NODE_MATH_LESS: - { - if (in0 < in1) - *out = 1.0f; - else - *out = 0.0f; - break; - } - - case NODE_MATH_GREATER: - { - if (in0 > in1) - *out = 1.0f; - else - *out = 0.0f; - break; - } - - case NODE_MATH_MOD: - { - if (in1 == 0.0f) - *out = 0.0f; - else - *out = fmod(in0, in1); - break; - } - - case NODE_MATH_ABS: - { - *out = fabsf(in0); - break; - } - - case NODE_MATH_ATAN2: - { - *out = atan2(in0, in1); - break; - } - - case NODE_MATH_FLOOR: - { - *out = floorf(in0); - break; - } - - case NODE_MATH_CEIL: - { - *out = ceilf(in0); - break; - } - - case NODE_MATH_FRACT: - { - *out = in0 - floorf(in0); - break; - } - - case NODE_MATH_SQRT: - { - if (in0 > 0.0f) - *out = sqrtf(in0); - else - *out = 0.0f; - break; - } - - default: - { - BLI_assert(0); - break; - } - } - - if (node->custom2 & SHD_MATH_CLAMP) { - CLAMP(*out, 0.0f, 1.0f); - } + float in0 = tex_input_value(in[0], p, thread); + float in1 = tex_input_value(in[1], p, thread); + + switch (node->custom1) { + + case NODE_MATH_ADD: + *out = in0 + in1; + break; + case NODE_MATH_SUB: + *out = in0 - in1; + break; + case NODE_MATH_MUL: + *out = in0 * in1; + break; + case NODE_MATH_DIVIDE: { + if (in1 == 0) /* We don't want to divide by zero. */ + *out = 0.0; + else + *out = in0 / in1; + break; + } + case NODE_MATH_SIN: { + *out = sinf(in0); + break; + } + case NODE_MATH_COS: { + *out = cosf(in0); + break; + } + case NODE_MATH_TAN: { + *out = tanf(in0); + break; + } + case NODE_MATH_ASIN: { + /* Can't do the impossible... */ + if (in0 <= 1 && in0 >= -1) + *out = asinf(in0); + else + *out = 0.0; + break; + } + case NODE_MATH_ACOS: { + /* Can't do the impossible... */ + if (in0 <= 1 && in0 >= -1) + *out = acosf(in0); + else + *out = 0.0; + break; + } + case NODE_MATH_ATAN: { + *out = atan(in0); + break; + } + case NODE_MATH_POW: { + /* Only raise negative numbers by full integers */ + if (in0 >= 0) { + out[0] = pow(in0, in1); + } + else { + float y_mod_1 = fmod(in1, 1); + if (y_mod_1 > 0.999f || y_mod_1 < 0.001f) { + *out = pow(in0, floor(in1 + 0.5f)); + } + else { + *out = 0.0; + } + } + break; + } + case NODE_MATH_LOG: { + /* Don't want any imaginary numbers... */ + if (in0 > 0 && in1 > 0) + *out = log(in0) / log(in1); + else + *out = 0.0; + break; + } + case NODE_MATH_MIN: { + if (in0 < in1) + *out = in0; + else + *out = in1; + break; + } + case NODE_MATH_MAX: { + if (in0 > in1) + *out = in0; + else + *out = in1; + break; + } + case NODE_MATH_ROUND: { + *out = (in0 < 0) ? (int)(in0 - 0.5f) : (int)(in0 + 0.5f); + break; + } + + case NODE_MATH_LESS: { + if (in0 < in1) + *out = 1.0f; + else + *out = 0.0f; + break; + } + + case NODE_MATH_GREATER: { + if (in0 > in1) + *out = 1.0f; + else + *out = 0.0f; + break; + } + + case NODE_MATH_MOD: { + if (in1 == 0.0f) + *out = 0.0f; + else + *out = fmod(in0, in1); + break; + } + + case NODE_MATH_ABS: { + *out = fabsf(in0); + break; + } + + case NODE_MATH_ATAN2: { + *out = atan2(in0, in1); + break; + } + + case NODE_MATH_FLOOR: { + *out = floorf(in0); + break; + } + + case NODE_MATH_CEIL: { + *out = ceilf(in0); + break; + } + + case NODE_MATH_FRACT: { + *out = in0 - floorf(in0); + break; + } + + case NODE_MATH_SQRT: { + if (in0 > 0.0f) + *out = sqrtf(in0); + else + *out = 0.0f; + break; + } + + default: { + BLI_assert(0); + break; + } + } + + if (node->custom2 & SHD_MATH_CLAMP) { + CLAMP(*out, 0.0f, 1.0f); + } } -static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void exec(void *data, + int UNUSED(thread), + bNode *node, + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack **out) { - tex_output(node, execdata, in, out[0], &valuefn, data); + tex_output(node, execdata, in, out[0], &valuefn, data); } void register_node_type_tex_math(void) { - static bNodeType ntype; + static bNodeType ntype; - tex_node_type_base(&ntype, TEX_NODE_MATH, "Math", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, inputs, outputs); - node_type_label(&ntype, node_math_label); - node_type_storage(&ntype, "", NULL, NULL); - node_type_exec(&ntype, NULL, NULL, exec); + tex_node_type_base(&ntype, TEX_NODE_MATH, "Math", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, inputs, outputs); + node_type_label(&ntype, node_math_label); + node_type_storage(&ntype, "", NULL, NULL); + node_type_exec(&ntype, NULL, NULL, exec); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_mixRgb.c b/source/blender/nodes/texture/nodes/node_texture_mixRgb.c index 047e427f478..667b1317ea4 100644 --- a/source/blender/nodes/texture/nodes/node_texture_mixRgb.c +++ b/source/blender/nodes/texture/nodes/node_texture_mixRgb.c @@ -21,53 +21,57 @@ * \ingroup texnodes */ - #include "node_texture_util.h" #include "NOD_texture.h" /* **************** MIX RGB ******************** */ static bNodeSocketTemplate inputs[] = { - { SOCK_FLOAT, 1, N_("Factor"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE }, - { SOCK_RGBA, 1, N_("Color1"), 0.5f, 0.5f, 0.5f, 1.0f }, - { SOCK_RGBA, 1, N_("Color2"), 0.5f, 0.5f, 0.5f, 1.0f }, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Factor"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, + {SOCK_RGBA, 1, N_("Color1"), 0.5f, 0.5f, 0.5f, 1.0f}, + {SOCK_RGBA, 1, N_("Color2"), 0.5f, 0.5f, 0.5f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate outputs[] = { - { SOCK_RGBA, 0, N_("Color") }, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color")}, + {-1, 0, ""}, }; static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread) { - float fac = tex_input_value(in[0], p, thread); - float col1[4], col2[4]; + float fac = tex_input_value(in[0], p, thread); + float col1[4], col2[4]; - tex_input_rgba(col1, in[1], p, thread); - tex_input_rgba(col2, in[2], p, thread); + tex_input_rgba(col1, in[1], p, thread); + tex_input_rgba(col2, in[2], p, thread); - /* use alpha */ - if (node->custom2 & 1) - fac *= col2[3]; + /* use alpha */ + if (node->custom2 & 1) + fac *= col2[3]; - CLAMP(fac, 0.0f, 1.0f); + CLAMP(fac, 0.0f, 1.0f); - copy_v4_v4(out, col1); - ramp_blend(node->custom1, out, fac, col2); + copy_v4_v4(out, col1); + ramp_blend(node->custom1, out, fac, col2); } -static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void exec(void *data, + int UNUSED(thread), + bNode *node, + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack **out) { - tex_output(node, execdata, in, out[0], &colorfn, data); + tex_output(node, execdata, in, out[0], &colorfn, data); } void register_node_type_tex_mix_rgb(void) { - static bNodeType ntype; + static bNodeType ntype; - tex_node_type_base(&ntype, TEX_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, 0); - node_type_socket_templates(&ntype, inputs, outputs); - node_type_label(&ntype, node_blend_label); - node_type_exec(&ntype, NULL, NULL, exec); + tex_node_type_base(&ntype, TEX_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, 0); + node_type_socket_templates(&ntype, inputs, outputs); + node_type_label(&ntype, node_blend_label); + node_type_exec(&ntype, NULL, NULL, exec); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_output.c b/source/blender/nodes/texture/nodes/node_texture_output.c index ff9226479c9..e44bea3ecac 100644 --- a/source/blender/nodes/texture/nodes/node_texture_output.c +++ b/source/blender/nodes/texture/nodes/node_texture_output.c @@ -21,147 +21,150 @@ * \ingroup texnodes */ - #include "node_texture_util.h" #include "NOD_texture.h" /* **************** COMPOSITE ******************** */ static bNodeSocketTemplate inputs[] = { - { SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, PROP_DIRECTION}, - { -1, 0, ""}, + {SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, PROP_DIRECTION}, + {-1, 0, ""}, }; /* applies to render pipeline */ -static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **UNUSED(out)) +static void exec(void *data, + int UNUSED(thread), + bNode *node, + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack **UNUSED(out)) { - TexCallData *cdata = (TexCallData *)data; - TexResult *target = cdata->target; - - if (cdata->do_preview) { - TexParams params; - params_from_cdata(¶ms, cdata); - - if (in[1] && in[1]->hasinput && !in[0]->hasinput) - tex_input_rgba(&target->tr, in[1], ¶ms, cdata->thread); - else - tex_input_rgba(&target->tr, in[0], ¶ms, cdata->thread); - tex_do_preview(execdata->preview, params.co, &target->tr, cdata->do_manage); - } - else { - /* 0 means don't care, so just use first */ - if (cdata->which_output == node->custom1 || (cdata->which_output == 0 && node->custom1 == 1)) { - TexParams params; - params_from_cdata(¶ms, cdata); - - tex_input_rgba(&target->tr, in[0], ¶ms, cdata->thread); - - target->tin = (target->tr + target->tg + target->tb) / 3.0f; - target->talpha = true; - - if (target->nor) { - if (in[1] && in[1]->hasinput) - tex_input_vec(target->nor, in[1], ¶ms, cdata->thread); - else - target->nor = NULL; - } - } - } + TexCallData *cdata = (TexCallData *)data; + TexResult *target = cdata->target; + + if (cdata->do_preview) { + TexParams params; + params_from_cdata(¶ms, cdata); + + if (in[1] && in[1]->hasinput && !in[0]->hasinput) + tex_input_rgba(&target->tr, in[1], ¶ms, cdata->thread); + else + tex_input_rgba(&target->tr, in[0], ¶ms, cdata->thread); + tex_do_preview(execdata->preview, params.co, &target->tr, cdata->do_manage); + } + else { + /* 0 means don't care, so just use first */ + if (cdata->which_output == node->custom1 || (cdata->which_output == 0 && node->custom1 == 1)) { + TexParams params; + params_from_cdata(¶ms, cdata); + + tex_input_rgba(&target->tr, in[0], ¶ms, cdata->thread); + + target->tin = (target->tr + target->tg + target->tb) / 3.0f; + target->talpha = true; + + if (target->nor) { + if (in[1] && in[1]->hasinput) + tex_input_vec(target->nor, in[1], ¶ms, cdata->thread); + else + target->nor = NULL; + } + } + } } static void unique_name(bNode *node) { - TexNodeOutput *tno = (TexNodeOutput *)node->storage; - char new_name[sizeof(tno->name)]; - int new_len = 0; - int suffix; - bNode *i; - const char *name = tno->name; - - new_name[0] = '\0'; - i = node; - while (i->prev) i = i->prev; - for (; i; i = i->next) { - if (i == node || - i->type != TEX_NODE_OUTPUT || - !STREQ(name, ((TexNodeOutput *)(i->storage))->name)) - { - continue; - } - - if (new_name[0] == '\0') { - int len = strlen(name); - if (len >= 4 && sscanf(name + len - 4, ".%03d", &suffix) == 1) { - new_len = len; - } - else { - suffix = 0; - new_len = len + 4; - if (new_len > (sizeof(tno->name) - 1)) - new_len = (sizeof(tno->name) - 1); - } - - BLI_strncpy(new_name, name, sizeof(tno->name)); - name = new_name; - } - sprintf(new_name + new_len - 4, ".%03d", ++suffix); - } - - if (new_name[0] != '\0') { - BLI_strncpy(tno->name, new_name, sizeof(tno->name)); - } + TexNodeOutput *tno = (TexNodeOutput *)node->storage; + char new_name[sizeof(tno->name)]; + int new_len = 0; + int suffix; + bNode *i; + const char *name = tno->name; + + new_name[0] = '\0'; + i = node; + while (i->prev) + i = i->prev; + for (; i; i = i->next) { + if (i == node || i->type != TEX_NODE_OUTPUT || + !STREQ(name, ((TexNodeOutput *)(i->storage))->name)) { + continue; + } + + if (new_name[0] == '\0') { + int len = strlen(name); + if (len >= 4 && sscanf(name + len - 4, ".%03d", &suffix) == 1) { + new_len = len; + } + else { + suffix = 0; + new_len = len + 4; + if (new_len > (sizeof(tno->name) - 1)) + new_len = (sizeof(tno->name) - 1); + } + + BLI_strncpy(new_name, name, sizeof(tno->name)); + name = new_name; + } + sprintf(new_name + new_len - 4, ".%03d", ++suffix); + } + + if (new_name[0] != '\0') { + BLI_strncpy(tno->name, new_name, sizeof(tno->name)); + } } static void assign_index(struct bNode *node) { - bNode *tnode; - int index = 1; + bNode *tnode; + int index = 1; - tnode = node; - while (tnode->prev) - tnode = tnode->prev; + tnode = node; + while (tnode->prev) + tnode = tnode->prev; check_index: - for (; tnode; tnode = tnode->next) - if (tnode->type == TEX_NODE_OUTPUT && tnode != node) - if (tnode->custom1 == index) { - index++; - goto check_index; - } - - node->custom1 = index; + for (; tnode; tnode = tnode->next) + if (tnode->type == TEX_NODE_OUTPUT && tnode != node) + if (tnode->custom1 == index) { + index++; + goto check_index; + } + + node->custom1 = index; } static void init(bNodeTree *UNUSED(ntree), bNode *node) { - TexNodeOutput *tno = MEM_callocN(sizeof(TexNodeOutput), "TEX_output"); - node->storage = tno; + TexNodeOutput *tno = MEM_callocN(sizeof(TexNodeOutput), "TEX_output"); + node->storage = tno; - strcpy(tno->name, "Default"); - unique_name(node); - assign_index(node); + strcpy(tno->name, "Default"); + unique_name(node); + assign_index(node); } static void copy(bNodeTree *dest_ntree, bNode *dest_node, bNode *src_node) { - node_copy_standard_storage(dest_ntree, dest_node, src_node); - unique_name(dest_node); - assign_index(dest_node); + node_copy_standard_storage(dest_ntree, dest_node, src_node); + unique_name(dest_node); + assign_index(dest_node); } void register_node_type_tex_output(void) { - static bNodeType ntype; + static bNodeType ntype; - tex_node_type_base(&ntype, TEX_NODE_OUTPUT, "Output", NODE_CLASS_OUTPUT, NODE_PREVIEW); - node_type_socket_templates(&ntype, inputs, NULL); - node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); - node_type_init(&ntype, init); - node_type_storage(&ntype, "TexNodeOutput", node_free_standard_storage, copy); - node_type_exec(&ntype, NULL, NULL, exec); + tex_node_type_base(&ntype, TEX_NODE_OUTPUT, "Output", NODE_CLASS_OUTPUT, NODE_PREVIEW); + node_type_socket_templates(&ntype, inputs, NULL); + node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); + node_type_init(&ntype, init); + node_type_storage(&ntype, "TexNodeOutput", node_free_standard_storage, copy); + node_type_exec(&ntype, NULL, NULL, exec); - /* Do not allow muting output. */ - node_type_internal_links(&ntype, NULL); + /* Do not allow muting output. */ + node_type_internal_links(&ntype, NULL); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_proc.c b/source/blender/nodes/texture/nodes/node_texture_proc.c index 34be50aaeec..8024ccdc631 100644 --- a/source/blender/nodes/texture/nodes/node_texture_proc.c +++ b/source/blender/nodes/texture/nodes/node_texture_proc.c @@ -21,7 +21,6 @@ * \ingroup texnodes */ - #include "node_texture_util.h" #include "NOD_texture.h" @@ -31,287 +30,278 @@ * In this file: wrappers to use procedural textures as nodes */ - static bNodeSocketTemplate outputs_both[] = { - { SOCK_RGBA, 0, N_("Color"), 1.0f, 0.0f, 0.0f, 1.0f }, - { SOCK_VECTOR, 0, N_("Normal"), 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, PROP_DIRECTION }, - { -1, 0, "" } -}; -static bNodeSocketTemplate outputs_color_only[] = { - { SOCK_RGBA, 0, N_("Color") }, - { -1, 0, "" } -}; + {SOCK_RGBA, 0, N_("Color"), 1.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_VECTOR, 0, N_("Normal"), 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, PROP_DIRECTION}, + {-1, 0, ""}}; +static bNodeSocketTemplate outputs_color_only[] = {{SOCK_RGBA, 0, N_("Color")}, {-1, 0, ""}}; /* Inputs common to all, #defined because nodes will need their own inputs too */ #define I 2 /* count */ #define COMMON_INPUTS \ - { SOCK_RGBA, 1, "Color 1", 0.0f, 0.0f, 0.0f, 1.0f }, \ - { SOCK_RGBA, 1, "Color 2", 1.0f, 1.0f, 1.0f, 1.0f } + {SOCK_RGBA, 1, "Color 1", 0.0f, 0.0f, 0.0f, 1.0f}, \ + { \ + SOCK_RGBA, 1, "Color 2", 1.0f, 1.0f, 1.0f, 1.0f \ + } /* Calls multitex and copies the result to the outputs. Called by xxx_exec, which handles inputs. */ -static void do_proc(float *result, TexParams *p, const float col1[4], const float col2[4], char is_normal, Tex *tex, const short thread) +static void do_proc(float *result, + TexParams *p, + const float col1[4], + const float col2[4], + char is_normal, + Tex *tex, + const short thread) { - TexResult texres; - int textype; - - if (is_normal) { - texres.nor = result; - } - else - texres.nor = NULL; - - textype = multitex_nodes(tex, p->co, p->dxt, p->dyt, p->osatex, - &texres, thread, 0, p->mtex, NULL); - - if (is_normal) - return; - - if (textype & TEX_RGB) { - copy_v4_v4(result, &texres.tr); - } - else { - copy_v4_v4(result, col1); - ramp_blend(MA_RAMP_BLEND, result, texres.tin, col2); - } + TexResult texres; + int textype; + + if (is_normal) { + texres.nor = result; + } + else + texres.nor = NULL; + + textype = multitex_nodes( + tex, p->co, p->dxt, p->dyt, p->osatex, &texres, thread, 0, p->mtex, NULL); + + if (is_normal) + return; + + if (textype & TEX_RGB) { + copy_v4_v4(result, &texres.tr); + } + else { + copy_v4_v4(result, col1); + ramp_blend(MA_RAMP_BLEND, result, texres.tin, col2); + } } -typedef void (*MapFn) (Tex *tex, bNodeStack **in, TexParams *p, const short thread); +typedef void (*MapFn)(Tex *tex, bNodeStack **in, TexParams *p, const short thread); -static void texfn( - float *result, - TexParams *p, - bNode *node, - bNodeStack **in, - char is_normal, - MapFn map_inputs, - short thread) +static void texfn(float *result, + TexParams *p, + bNode *node, + bNodeStack **in, + char is_normal, + MapFn map_inputs, + short thread) { - Tex tex = *((Tex *)(node->storage)); - float col1[4], col2[4]; - tex_input_rgba(col1, in[0], p, thread); - tex_input_rgba(col2, in[1], p, thread); + Tex tex = *((Tex *)(node->storage)); + float col1[4], col2[4]; + tex_input_rgba(col1, in[0], p, thread); + tex_input_rgba(col2, in[1], p, thread); - map_inputs(&tex, in, p, thread); + map_inputs(&tex, in, p, thread); - do_proc(result, p, col1, col2, is_normal, &tex, thread); + do_proc(result, p, col1, col2, is_normal, &tex, thread); } static int count_outputs(bNode *node) { - bNodeSocket *sock; - int num = 0; - for (sock = node->outputs.first; sock; sock = sock->next) { - num++; - } - return num; + bNodeSocket *sock; + int num = 0; + for (sock = node->outputs.first; sock; sock = sock->next) { + num++; + } + return num; } /* Boilerplate generators */ #define ProcNoInputs(name) \ - static void name##_map_inputs(Tex *UNUSED(tex), bNodeStack **UNUSED(in), TexParams *UNUSED(p), short UNUSED(thread)) \ - {} + static void name##_map_inputs( \ + Tex *UNUSED(tex), bNodeStack **UNUSED(in), TexParams *UNUSED(p), short UNUSED(thread)) \ + { \ + } #define ProcDef(name) \ - static void name##_colorfn(float *result, TexParams *p, bNode *node, bNodeStack **in, short thread) \ - { \ - texfn(result, p, node, in, 0, &name##_map_inputs, thread); \ - } \ - static void name##_normalfn(float *result, TexParams *p, bNode *node, bNodeStack **in, short thread) \ - { \ - texfn(result, p, node, in, 1, &name##_map_inputs, thread); \ - } \ - static void name##_exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) \ - { \ - int outs = count_outputs(node); \ - if (outs >= 1) tex_output(node, execdata, in, out[0], &name##_colorfn, data); \ - if (outs >= 2) tex_output(node, execdata, in, out[1], &name##_normalfn, data); \ - } - + static void name##_colorfn( \ + float *result, TexParams *p, bNode *node, bNodeStack **in, short thread) \ + { \ + texfn(result, p, node, in, 0, &name##_map_inputs, thread); \ + } \ + static void name##_normalfn( \ + float *result, TexParams *p, bNode *node, bNodeStack **in, short thread) \ + { \ + texfn(result, p, node, in, 1, &name##_map_inputs, thread); \ + } \ + static void name##_exec(void *data, \ + int UNUSED(thread), \ + bNode *node, \ + bNodeExecData *execdata, \ + bNodeStack **in, \ + bNodeStack **out) \ + { \ + int outs = count_outputs(node); \ + if (outs >= 1) \ + tex_output(node, execdata, in, out[0], &name##_colorfn, data); \ + if (outs >= 2) \ + tex_output(node, execdata, in, out[1], &name##_normalfn, data); \ + } /* --- VORONOI -- */ static bNodeSocketTemplate voronoi_inputs[] = { - COMMON_INPUTS, - { SOCK_FLOAT, 1, N_("W1"), 1.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE }, - { SOCK_FLOAT, 1, N_("W2"), 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE }, - { SOCK_FLOAT, 1, N_("W3"), 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE }, - { SOCK_FLOAT, 1, N_("W4"), 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE }, + COMMON_INPUTS, + {SOCK_FLOAT, 1, N_("W1"), 1.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("W2"), 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("W3"), 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("W4"), 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("iScale"), 1.0f, 0.0f, 0.0f, 0.0f, 0.01f, 10.0f, PROP_UNSIGNED }, - { SOCK_FLOAT, 1, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 4.0f, PROP_UNSIGNED }, + {SOCK_FLOAT, 1, N_("iScale"), 1.0f, 0.0f, 0.0f, 0.0f, 0.01f, 10.0f, PROP_UNSIGNED}, + {SOCK_FLOAT, 1, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 4.0f, PROP_UNSIGNED}, - { -1, 0, "" } -}; + {-1, 0, ""}}; static void voronoi_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread) { - tex->vn_w1 = tex_input_value(in[I + 0], p, thread); - tex->vn_w2 = tex_input_value(in[I + 1], p, thread); - tex->vn_w3 = tex_input_value(in[I + 2], p, thread); - tex->vn_w4 = tex_input_value(in[I + 3], p, thread); + tex->vn_w1 = tex_input_value(in[I + 0], p, thread); + tex->vn_w2 = tex_input_value(in[I + 1], p, thread); + tex->vn_w3 = tex_input_value(in[I + 2], p, thread); + tex->vn_w4 = tex_input_value(in[I + 3], p, thread); - tex->ns_outscale = tex_input_value(in[I + 4], p, thread); - tex->noisesize = tex_input_value(in[I + 5], p, thread); + tex->ns_outscale = tex_input_value(in[I + 4], p, thread); + tex->noisesize = tex_input_value(in[I + 5], p, thread); } ProcDef(voronoi) -/* --- BLEND -- */ -static bNodeSocketTemplate blend_inputs[] = { - COMMON_INPUTS, - { -1, 0, "" } -}; -ProcNoInputs(blend) -ProcDef(blend) - -/* -- MAGIC -- */ -static bNodeSocketTemplate magic_inputs[] = { - COMMON_INPUTS, - { SOCK_FLOAT, 1, N_("Turbulence"), 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f, PROP_UNSIGNED }, - { -1, 0, "" } -}; + /* --- BLEND -- */ + static bNodeSocketTemplate blend_inputs[] = {COMMON_INPUTS, {-1, 0, ""}}; +ProcNoInputs(blend) ProcDef(blend) + + /* -- MAGIC -- */ + static bNodeSocketTemplate magic_inputs[] = { + COMMON_INPUTS, + {SOCK_FLOAT, 1, N_("Turbulence"), 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f, PROP_UNSIGNED}, + {-1, 0, ""}}; static void magic_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread) { - tex->turbul = tex_input_value(in[I + 0], p, thread); + tex->turbul = tex_input_value(in[I + 0], p, thread); } ProcDef(magic) -/* --- MARBLE --- */ -static bNodeSocketTemplate marble_inputs[] = { - COMMON_INPUTS, - { SOCK_FLOAT, 1, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED }, - { SOCK_FLOAT, 1, N_("Turbulence"), 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f, PROP_UNSIGNED }, - { -1, 0, "" } -}; + /* --- MARBLE --- */ + static bNodeSocketTemplate marble_inputs[] = { + COMMON_INPUTS, + {SOCK_FLOAT, 1, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED}, + {SOCK_FLOAT, 1, N_("Turbulence"), 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f, PROP_UNSIGNED}, + {-1, 0, ""}}; static void marble_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread) { - tex->noisesize = tex_input_value(in[I + 0], p, thread); - tex->turbul = tex_input_value(in[I + 1], p, thread); + tex->noisesize = tex_input_value(in[I + 0], p, thread); + tex->turbul = tex_input_value(in[I + 1], p, thread); } ProcDef(marble) -/* --- CLOUDS --- */ -static bNodeSocketTemplate clouds_inputs[] = { - COMMON_INPUTS, - { SOCK_FLOAT, 1, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED }, - { -1, 0, "" } -}; + /* --- CLOUDS --- */ + static bNodeSocketTemplate clouds_inputs[] = { + COMMON_INPUTS, + {SOCK_FLOAT, 1, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED}, + {-1, 0, ""}}; static void clouds_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread) { - tex->noisesize = tex_input_value(in[I + 0], p, thread); + tex->noisesize = tex_input_value(in[I + 0], p, thread); } ProcDef(clouds) -/* --- DISTORTED NOISE --- */ -static bNodeSocketTemplate distnoise_inputs[] = { - COMMON_INPUTS, - { SOCK_FLOAT, 1, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED }, - { SOCK_FLOAT, 1, N_("Distortion"), 1.00f, 0.0f, 0.0f, 0.0f, 0.0000f, 10.0f, PROP_UNSIGNED }, - { -1, 0, "" } -}; + /* --- DISTORTED NOISE --- */ + static bNodeSocketTemplate distnoise_inputs[] = { + COMMON_INPUTS, + {SOCK_FLOAT, 1, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED}, + {SOCK_FLOAT, 1, N_("Distortion"), 1.00f, 0.0f, 0.0f, 0.0f, 0.0000f, 10.0f, PROP_UNSIGNED}, + {-1, 0, ""}}; static void distnoise_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread) { - tex->noisesize = tex_input_value(in[I + 0], p, thread); - tex->dist_amount = tex_input_value(in[I + 1], p, thread); + tex->noisesize = tex_input_value(in[I + 0], p, thread); + tex->dist_amount = tex_input_value(in[I + 1], p, thread); } ProcDef(distnoise) -/* --- WOOD --- */ -static bNodeSocketTemplate wood_inputs[] = { - COMMON_INPUTS, - { SOCK_FLOAT, 1, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED }, - { SOCK_FLOAT, 1, N_("Turbulence"), 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f, PROP_UNSIGNED }, - { -1, 0, "" } -}; + /* --- WOOD --- */ + static bNodeSocketTemplate wood_inputs[] = { + COMMON_INPUTS, + {SOCK_FLOAT, 1, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED}, + {SOCK_FLOAT, 1, N_("Turbulence"), 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f, PROP_UNSIGNED}, + {-1, 0, ""}}; static void wood_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread) { - tex->noisesize = tex_input_value(in[I + 0], p, thread); - tex->turbul = tex_input_value(in[I + 1], p, thread); + tex->noisesize = tex_input_value(in[I + 0], p, thread); + tex->turbul = tex_input_value(in[I + 1], p, thread); } ProcDef(wood) -/* --- MUSGRAVE --- */ -static bNodeSocketTemplate musgrave_inputs[] = { - COMMON_INPUTS, - { SOCK_FLOAT, 1, N_("H"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED }, - { SOCK_FLOAT, 1, N_("Lacunarity"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 6.0f, PROP_UNSIGNED }, - { SOCK_FLOAT, 1, N_("Octaves"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 8.0f, PROP_UNSIGNED }, - - { SOCK_FLOAT, 1, N_("iScale"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 10.0f, PROP_UNSIGNED }, - { SOCK_FLOAT, 1, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED }, - { -1, 0, "" } -}; + /* --- MUSGRAVE --- */ + static bNodeSocketTemplate musgrave_inputs[] = { + COMMON_INPUTS, + {SOCK_FLOAT, 1, N_("H"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED}, + {SOCK_FLOAT, 1, N_("Lacunarity"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 6.0f, PROP_UNSIGNED}, + {SOCK_FLOAT, 1, N_("Octaves"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 8.0f, PROP_UNSIGNED}, + + {SOCK_FLOAT, 1, N_("iScale"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 10.0f, PROP_UNSIGNED}, + {SOCK_FLOAT, 1, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED}, + {-1, 0, ""}}; static void musgrave_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread) { - tex->mg_H = tex_input_value(in[I + 0], p, thread); - tex->mg_lacunarity = tex_input_value(in[I + 1], p, thread); - tex->mg_octaves = tex_input_value(in[I + 2], p, thread); - tex->ns_outscale = tex_input_value(in[I + 3], p, thread); - tex->noisesize = tex_input_value(in[I + 4], p, thread); + tex->mg_H = tex_input_value(in[I + 0], p, thread); + tex->mg_lacunarity = tex_input_value(in[I + 1], p, thread); + tex->mg_octaves = tex_input_value(in[I + 2], p, thread); + tex->ns_outscale = tex_input_value(in[I + 3], p, thread); + tex->noisesize = tex_input_value(in[I + 4], p, thread); } ProcDef(musgrave) -/* --- NOISE --- */ -static bNodeSocketTemplate noise_inputs[] = { - COMMON_INPUTS, - { -1, 0, "" } -}; -ProcNoInputs(noise) -ProcDef(noise) - -/* --- STUCCI --- */ -static bNodeSocketTemplate stucci_inputs[] = { - COMMON_INPUTS, - { SOCK_FLOAT, 1, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED }, - { SOCK_FLOAT, 1, N_("Turbulence"), 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f, PROP_UNSIGNED }, - { -1, 0, "" } -}; + /* --- NOISE --- */ + static bNodeSocketTemplate noise_inputs[] = {COMMON_INPUTS, {-1, 0, ""}}; +ProcNoInputs(noise) ProcDef(noise) + + /* --- STUCCI --- */ + static bNodeSocketTemplate stucci_inputs[] = { + COMMON_INPUTS, + {SOCK_FLOAT, 1, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED}, + {SOCK_FLOAT, 1, N_("Turbulence"), 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f, PROP_UNSIGNED}, + {-1, 0, ""}}; static void stucci_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread) { - tex->noisesize = tex_input_value(in[I + 0], p, thread); - tex->turbul = tex_input_value(in[I + 1], p, thread); + tex->noisesize = tex_input_value(in[I + 0], p, thread); + tex->turbul = tex_input_value(in[I + 1], p, thread); } ProcDef(stucci) -/* --- */ + /* --- */ -static void init(bNodeTree *UNUSED(ntree), bNode *node) + static void init(bNodeTree *UNUSED(ntree), bNode *node) { - Tex *tex = MEM_callocN(sizeof(Tex), "Tex"); - node->storage = tex; + Tex *tex = MEM_callocN(sizeof(Tex), "Tex"); + node->storage = tex; - BKE_texture_default(tex); - tex->type = node->type - TEX_NODE_PROC; - - if (tex->type == TEX_WOOD) - tex->stype = TEX_BANDNOISE; + BKE_texture_default(tex); + tex->type = node->type - TEX_NODE_PROC; + if (tex->type == TEX_WOOD) + tex->stype = TEX_BANDNOISE; } /* Node type definitions */ #define TexDef(TEXTYPE, outputs, name, Name) \ -void register_node_type_tex_proc_##name(void) \ -{ \ - static bNodeType ntype; \ - \ - tex_node_type_base(&ntype, TEX_NODE_PROC+TEXTYPE, Name, NODE_CLASS_TEXTURE, NODE_PREVIEW); \ - node_type_socket_templates(&ntype, name##_inputs, outputs); \ - node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); \ - node_type_init(&ntype, init); \ - node_type_storage(&ntype, "Tex", node_free_standard_storage, node_copy_standard_storage); \ - node_type_exec(&ntype, NULL, NULL, name##_exec); \ - \ - nodeRegisterType(&ntype); \ -} + void register_node_type_tex_proc_##name(void) \ + { \ + static bNodeType ntype; \ +\ + tex_node_type_base(&ntype, TEX_NODE_PROC + TEXTYPE, Name, NODE_CLASS_TEXTURE, NODE_PREVIEW); \ + node_type_socket_templates(&ntype, name##_inputs, outputs); \ + node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); \ + node_type_init(&ntype, init); \ + node_type_storage(&ntype, "Tex", node_free_standard_storage, node_copy_standard_storage); \ + node_type_exec(&ntype, NULL, NULL, name##_exec); \ +\ + nodeRegisterType(&ntype); \ + } #define C outputs_color_only #define CV outputs_both -TexDef(TEX_VORONOI, CV, voronoi, "Voronoi" ) -TexDef(TEX_BLEND, C, blend, "Blend" ) -TexDef(TEX_MAGIC, C, magic, "Magic" ) -TexDef(TEX_MARBLE, CV, marble, "Marble" ) -TexDef(TEX_CLOUDS, CV, clouds, "Clouds" ) -TexDef(TEX_WOOD, CV, wood, "Wood" ) -TexDef(TEX_MUSGRAVE, CV, musgrave, "Musgrave" ) -TexDef(TEX_NOISE, C, noise, "Noise" ) -TexDef(TEX_STUCCI, CV, stucci, "Stucci" ) -TexDef(TEX_DISTNOISE, CV, distnoise, "Distorted Noise" ) +TexDef(TEX_VORONOI, CV, voronoi, "Voronoi") TexDef(TEX_BLEND, C, blend, "Blend") + TexDef(TEX_MAGIC, C, magic, "Magic") TexDef(TEX_MARBLE, CV, marble, "Marble") + TexDef(TEX_CLOUDS, CV, clouds, "Clouds") TexDef(TEX_WOOD, CV, wood, "Wood") + TexDef(TEX_MUSGRAVE, CV, musgrave, "Musgrave") TexDef(TEX_NOISE, C, noise, "Noise") + TexDef(TEX_STUCCI, CV, stucci, "Stucci") + TexDef(TEX_DISTNOISE, CV, distnoise, "Distorted Noise") diff --git a/source/blender/nodes/texture/nodes/node_texture_rotate.c b/source/blender/nodes/texture/nodes/node_texture_rotate.c index b8dfc9cb608..a7f348076ac 100644 --- a/source/blender/nodes/texture/nodes/node_texture_rotate.c +++ b/source/blender/nodes/texture/nodes/node_texture_rotate.c @@ -21,79 +21,83 @@ * \ingroup texnodes */ - #include <math.h> #include "node_texture_util.h" #include "NOD_texture.h" static bNodeSocketTemplate inputs[] = { - { SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Turns"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_NONE }, - { SOCK_VECTOR, 1, N_("Axis"), 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f, PROP_DIRECTION }, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_FLOAT, 1, N_("Turns"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_NONE}, + {SOCK_VECTOR, 1, N_("Axis"), 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f, PROP_DIRECTION}, + {-1, 0, ""}, }; static bNodeSocketTemplate outputs[] = { - { SOCK_RGBA, 0, N_("Color")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color")}, + {-1, 0, ""}, }; static void rotate(float new_co[3], float a, float ax[3], const float co[3]) { - float para[3]; - float perp[3]; - float cp[3]; + float para[3]; + float perp[3]; + float cp[3]; - float cos_a = cosf(a * (float)(2 * M_PI)); - float sin_a = sinf(a * (float)(2 * M_PI)); + float cos_a = cosf(a * (float)(2 * M_PI)); + float sin_a = sinf(a * (float)(2 * M_PI)); - // x' = xcosa + n(n.x)(1-cosa) + (x*n)sina + // x' = xcosa + n(n.x)(1-cosa) + (x*n)sina - mul_v3_v3fl(perp, co, cos_a); - mul_v3_v3fl(para, ax, dot_v3v3(co, ax) * (1 - cos_a)); + mul_v3_v3fl(perp, co, cos_a); + mul_v3_v3fl(para, ax, dot_v3v3(co, ax) * (1 - cos_a)); - cross_v3_v3v3(cp, ax, co); - mul_v3_fl(cp, sin_a); + cross_v3_v3v3(cp, ax, co); + mul_v3_fl(cp, sin_a); - new_co[0] = para[0] + perp[0] + cp[0]; - new_co[1] = para[1] + perp[1] + cp[1]; - new_co[2] = para[2] + perp[2] + cp[2]; + new_co[0] = para[0] + perp[0] + cp[0]; + new_co[1] = para[1] + perp[1] + cp[1]; + new_co[2] = para[2] + perp[2] + cp[2]; } static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) { - float new_co[3], new_dxt[3], new_dyt[3], a, ax[3]; - - a = tex_input_value(in[1], p, thread); - tex_input_vec(ax, in[2], p, thread); - - rotate(new_co, a, ax, p->co); - if (p->osatex) { - rotate(new_dxt, a, ax, p->dxt); - rotate(new_dyt, a, ax, p->dyt); - } - - { - TexParams np = *p; - np.co = new_co; - np.dxt = new_dxt; - np.dyt = new_dyt; - tex_input_rgba(out, in[0], &np, thread); - } + float new_co[3], new_dxt[3], new_dyt[3], a, ax[3]; + + a = tex_input_value(in[1], p, thread); + tex_input_vec(ax, in[2], p, thread); + + rotate(new_co, a, ax, p->co); + if (p->osatex) { + rotate(new_dxt, a, ax, p->dxt); + rotate(new_dyt, a, ax, p->dyt); + } + + { + TexParams np = *p; + np.co = new_co; + np.dxt = new_dxt; + np.dyt = new_dyt; + tex_input_rgba(out, in[0], &np, thread); + } } -static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void exec(void *data, + int UNUSED(thread), + bNode *node, + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack **out) { - tex_output(node, execdata, in, out[0], &colorfn, data); + tex_output(node, execdata, in, out[0], &colorfn, data); } void register_node_type_tex_rotate(void) { - static bNodeType ntype; + static bNodeType ntype; - tex_node_type_base(&ntype, TEX_NODE_ROTATE, "Rotate", NODE_CLASS_DISTORT, 0); - node_type_socket_templates(&ntype, inputs, outputs); - node_type_exec(&ntype, NULL, NULL, exec); + tex_node_type_base(&ntype, TEX_NODE_ROTATE, "Rotate", NODE_CLASS_DISTORT, 0); + node_type_socket_templates(&ntype, inputs, outputs); + node_type_exec(&ntype, NULL, NULL, exec); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_scale.c b/source/blender/nodes/texture/nodes/node_texture_scale.c index e7e255ed7ef..61e81c1ed02 100644 --- a/source/blender/nodes/texture/nodes/node_texture_scale.c +++ b/source/blender/nodes/texture/nodes/node_texture_scale.c @@ -21,52 +21,56 @@ * \ingroup texnodes */ - #include <math.h> #include "node_texture_util.h" static bNodeSocketTemplate inputs[] = { - { SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f }, - { SOCK_VECTOR, 1, N_("Scale"), 1.0f, 1.0f, 1.0f, 0.0f, -10.0f, 10.0f, PROP_XYZ }, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_VECTOR, 1, N_("Scale"), 1.0f, 1.0f, 1.0f, 0.0f, -10.0f, 10.0f, PROP_XYZ}, + {-1, 0, ""}, }; static bNodeSocketTemplate outputs[] = { - { SOCK_RGBA, 0, N_("Color")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color")}, + {-1, 0, ""}, }; static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) { - float scale[3], new_co[3], new_dxt[3], new_dyt[3]; - TexParams np = *p; + float scale[3], new_co[3], new_dxt[3], new_dyt[3]; + TexParams np = *p; - np.co = new_co; - np.dxt = new_dxt; - np.dyt = new_dyt; + np.co = new_co; + np.dxt = new_dxt; + np.dyt = new_dyt; - tex_input_vec(scale, in[1], p, thread); + tex_input_vec(scale, in[1], p, thread); - mul_v3_v3v3(new_co, p->co, scale); - if (p->osatex) { - mul_v3_v3v3(new_dxt, p->dxt, scale); - mul_v3_v3v3(new_dyt, p->dyt, scale); - } + mul_v3_v3v3(new_co, p->co, scale); + if (p->osatex) { + mul_v3_v3v3(new_dxt, p->dxt, scale); + mul_v3_v3v3(new_dyt, p->dyt, scale); + } - tex_input_rgba(out, in[0], &np, thread); + tex_input_rgba(out, in[0], &np, thread); } -static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void exec(void *data, + int UNUSED(thread), + bNode *node, + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack **out) { - tex_output(node, execdata, in, out[0], &colorfn, data); + tex_output(node, execdata, in, out[0], &colorfn, data); } void register_node_type_tex_scale(void) { - static bNodeType ntype; + static bNodeType ntype; - tex_node_type_base(&ntype, TEX_NODE_SCALE, "Scale", NODE_CLASS_DISTORT, 0); - node_type_socket_templates(&ntype, inputs, outputs); - node_type_exec(&ntype, NULL, NULL, exec); + tex_node_type_base(&ntype, TEX_NODE_SCALE, "Scale", NODE_CLASS_DISTORT, 0); + node_type_socket_templates(&ntype, inputs, outputs); + node_type_exec(&ntype, NULL, NULL, exec); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_texture.c b/source/blender/nodes/texture/nodes/node_texture_texture.c index 791e0fab1fb..342807d3142 100644 --- a/source/blender/nodes/texture/nodes/node_texture_texture.c +++ b/source/blender/nodes/texture/nodes/node_texture_texture.c @@ -21,79 +21,82 @@ * \ingroup texnodes */ - #include "node_texture_util.h" #include "NOD_texture.h" #include "RE_shader_ext.h" static bNodeSocketTemplate inputs[] = { - { SOCK_RGBA, 1, N_("Color1"), 1.0f, 1.0f, 1.0f, 1.0f }, - { SOCK_RGBA, 1, N_("Color2"), 0.0f, 0.0f, 0.0f, 1.0f }, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color1"), 1.0f, 1.0f, 1.0f, 1.0f}, + {SOCK_RGBA, 1, N_("Color2"), 0.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate outputs[] = { - { SOCK_RGBA, 0, N_("Color") }, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color")}, + {-1, 0, ""}, }; static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread) { - Tex *nodetex = (Tex *)node->id; - static float red[] = {1, 0, 0, 1}; - static float white[] = {1, 1, 1, 1}; - float co[3], dxt[3], dyt[3]; - - copy_v3_v3(co, p->co); - if (p->osatex) { - copy_v3_v3(dxt, p->dxt); - copy_v3_v3(dyt, p->dyt); - } - else { - zero_v3(dxt); - zero_v3(dyt); - } - - if (node->custom2 || node->need_exec == 0) { - /* this node refers to its own texture tree! */ - copy_v4_v4(out, (fabsf(co[0] - co[1]) < 0.01f) ? white : red); - } - else if (nodetex) { - TexResult texres; - int textype; - float nor[] = {0, 0, 0}; - float col1[4], col2[4]; - - tex_input_rgba(col1, in[0], p, thread); - tex_input_rgba(col2, in[1], p, thread); - - texres.nor = nor; - textype = multitex_nodes(nodetex, co, dxt, dyt, p->osatex, - &texres, thread, 0, p->mtex, NULL); - - if (textype & TEX_RGB) { - copy_v4_v4(out, &texres.tr); - } - else { - copy_v4_v4(out, col1); - ramp_blend(MA_RAMP_BLEND, out, texres.tin, col2); - } - } + Tex *nodetex = (Tex *)node->id; + static float red[] = {1, 0, 0, 1}; + static float white[] = {1, 1, 1, 1}; + float co[3], dxt[3], dyt[3]; + + copy_v3_v3(co, p->co); + if (p->osatex) { + copy_v3_v3(dxt, p->dxt); + copy_v3_v3(dyt, p->dyt); + } + else { + zero_v3(dxt); + zero_v3(dyt); + } + + if (node->custom2 || node->need_exec == 0) { + /* this node refers to its own texture tree! */ + copy_v4_v4(out, (fabsf(co[0] - co[1]) < 0.01f) ? white : red); + } + else if (nodetex) { + TexResult texres; + int textype; + float nor[] = {0, 0, 0}; + float col1[4], col2[4]; + + tex_input_rgba(col1, in[0], p, thread); + tex_input_rgba(col2, in[1], p, thread); + + texres.nor = nor; + textype = multitex_nodes(nodetex, co, dxt, dyt, p->osatex, &texres, thread, 0, p->mtex, NULL); + + if (textype & TEX_RGB) { + copy_v4_v4(out, &texres.tr); + } + else { + copy_v4_v4(out, col1); + ramp_blend(MA_RAMP_BLEND, out, texres.tin, col2); + } + } } -static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void exec(void *data, + int UNUSED(thread), + bNode *node, + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack **out) { - tex_output(node, execdata, in, out[0], &colorfn, data); + tex_output(node, execdata, in, out[0], &colorfn, data); } void register_node_type_tex_texture(void) { - static bNodeType ntype; + static bNodeType ntype; - tex_node_type_base(&ntype, TEX_NODE_TEXTURE, "Texture", NODE_CLASS_INPUT, NODE_PREVIEW); - node_type_socket_templates(&ntype, inputs, outputs); - node_type_exec(&ntype, NULL, NULL, exec); + tex_node_type_base(&ntype, TEX_NODE_TEXTURE, "Texture", NODE_CLASS_INPUT, NODE_PREVIEW); + node_type_socket_templates(&ntype, inputs, outputs); + node_type_exec(&ntype, NULL, NULL, exec); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_translate.c b/source/blender/nodes/texture/nodes/node_texture_translate.c index d4fc045a383..c53077d792b 100644 --- a/source/blender/nodes/texture/nodes/node_texture_translate.c +++ b/source/blender/nodes/texture/nodes/node_texture_translate.c @@ -21,48 +21,52 @@ * \ingroup texnodes */ - #include <math.h> #include "node_texture_util.h" #include "NOD_texture.h" static bNodeSocketTemplate inputs[] = { - { SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_VECTOR, 1, N_("Offset"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f, PROP_TRANSLATION }, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f}, + {SOCK_VECTOR, 1, N_("Offset"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f, PROP_TRANSLATION}, + {-1, 0, ""}, }; static bNodeSocketTemplate outputs[] = { - { SOCK_RGBA, 0, N_("Color")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color")}, + {-1, 0, ""}, }; static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) { - float offset[3], new_co[3]; - TexParams np = *p; - np.co = new_co; + float offset[3], new_co[3]; + TexParams np = *p; + np.co = new_co; - tex_input_vec(offset, in[1], p, thread); + tex_input_vec(offset, in[1], p, thread); - new_co[0] = p->co[0] + offset[0]; - new_co[1] = p->co[1] + offset[1]; - new_co[2] = p->co[2] + offset[2]; + new_co[0] = p->co[0] + offset[0]; + new_co[1] = p->co[1] + offset[1]; + new_co[2] = p->co[2] + offset[2]; - tex_input_rgba(out, in[0], &np, thread); + tex_input_rgba(out, in[0], &np, thread); } -static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void exec(void *data, + int UNUSED(thread), + bNode *node, + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack **out) { - tex_output(node, execdata, in, out[0], &colorfn, data); + tex_output(node, execdata, in, out[0], &colorfn, data); } void register_node_type_tex_translate(void) { - static bNodeType ntype; + static bNodeType ntype; - tex_node_type_base(&ntype, TEX_NODE_TRANSLATE, "Translate", NODE_CLASS_DISTORT, 0); - node_type_socket_templates(&ntype, inputs, outputs); - node_type_exec(&ntype, NULL, NULL, exec); + tex_node_type_base(&ntype, TEX_NODE_TRANSLATE, "Translate", NODE_CLASS_DISTORT, 0); + node_type_socket_templates(&ntype, inputs, outputs); + node_type_exec(&ntype, NULL, NULL, exec); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_valToNor.c b/source/blender/nodes/texture/nodes/node_texture_valToNor.c index ea09b9e28ae..1a341b3129c 100644 --- a/source/blender/nodes/texture/nodes/node_texture_valToNor.c +++ b/source/blender/nodes/texture/nodes/node_texture_valToNor.c @@ -21,64 +21,68 @@ * \ingroup texnodes */ - #include "node_texture_util.h" #include "NOD_texture.h" static bNodeSocketTemplate inputs[] = { - { SOCK_FLOAT, 1, N_("Val"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE }, - { SOCK_FLOAT, 1, N_("Nabla"), 0.025f, 0.0f, 0.0f, 0.0f, 0.001f, 0.1f, PROP_UNSIGNED }, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Val"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, + {SOCK_FLOAT, 1, N_("Nabla"), 0.025f, 0.0f, 0.0f, 0.0f, 0.001f, 0.1f, PROP_UNSIGNED}, + {-1, 0, ""}, }; static bNodeSocketTemplate outputs[] = { - { SOCK_VECTOR, 0, N_("Normal") }, - { -1, 0, "" }, + {SOCK_VECTOR, 0, N_("Normal")}, + {-1, 0, ""}, }; static void normalfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) { - float new_co[3]; - const float *co = p->co; + float new_co[3]; + const float *co = p->co; - float nabla = tex_input_value(in[1], p, thread); - float val; - float nor[3]; + float nabla = tex_input_value(in[1], p, thread); + float val; + float nor[3]; - TexParams np = *p; - np.co = new_co; + TexParams np = *p; + np.co = new_co; - val = tex_input_value(in[0], p, thread); + val = tex_input_value(in[0], p, thread); - new_co[0] = co[0] + nabla; - new_co[1] = co[1]; - new_co[2] = co[2]; - nor[0] = tex_input_value(in[0], &np, thread); + new_co[0] = co[0] + nabla; + new_co[1] = co[1]; + new_co[2] = co[2]; + nor[0] = tex_input_value(in[0], &np, thread); - new_co[0] = co[0]; - new_co[1] = co[1] + nabla; - nor[1] = tex_input_value(in[0], &np, thread); + new_co[0] = co[0]; + new_co[1] = co[1] + nabla; + nor[1] = tex_input_value(in[0], &np, thread); - new_co[1] = co[1]; - new_co[2] = co[2] + nabla; - nor[2] = tex_input_value(in[0], &np, thread); + new_co[1] = co[1]; + new_co[2] = co[2] + nabla; + nor[2] = tex_input_value(in[0], &np, thread); - out[0] = val - nor[0]; - out[1] = val - nor[1]; - out[2] = val - nor[2]; + out[0] = val - nor[0]; + out[1] = val - nor[1]; + out[2] = val - nor[2]; } -static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void exec(void *data, + int UNUSED(thread), + bNode *node, + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack **out) { - tex_output(node, execdata, in, out[0], &normalfn, data); + tex_output(node, execdata, in, out[0], &normalfn, data); } void register_node_type_tex_valtonor(void) { - static bNodeType ntype; + static bNodeType ntype; - tex_node_type_base(&ntype, TEX_NODE_VALTONOR, "Value to Normal", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, inputs, outputs); - node_type_exec(&ntype, NULL, NULL, exec); + tex_node_type_base(&ntype, TEX_NODE_VALTONOR, "Value to Normal", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, inputs, outputs); + node_type_exec(&ntype, NULL, NULL, exec); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_valToRgb.c b/source/blender/nodes/texture/nodes/node_texture_valToRgb.c index 9db1caf6a85..8c315faaf8a 100644 --- a/source/blender/nodes/texture/nodes/node_texture_valToRgb.c +++ b/source/blender/nodes/texture/nodes/node_texture_valToRgb.c @@ -21,84 +21,93 @@ * \ingroup texnodes */ - #include "node_texture_util.h" #include "NOD_texture.h" #include "IMB_colormanagement.h" /* **************** VALTORGB ******************** */ static bNodeSocketTemplate valtorgb_in[] = { - { SOCK_FLOAT, 1, N_("Fac"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - { -1, 0, "" }, + {SOCK_FLOAT, 1, N_("Fac"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + {-1, 0, ""}, }; static bNodeSocketTemplate valtorgb_out[] = { - { SOCK_RGBA, 0, N_("Color")}, - { -1, 0, "" }, + {SOCK_RGBA, 0, N_("Color")}, + {-1, 0, ""}, }; static void valtorgb_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread) { - if (node->storage) { - float fac = tex_input_value(in[0], p, thread); + if (node->storage) { + float fac = tex_input_value(in[0], p, thread); - BKE_colorband_evaluate(node->storage, fac, out); - } + BKE_colorband_evaluate(node->storage, fac, out); + } } -static void valtorgb_exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void valtorgb_exec(void *data, + int UNUSED(thread), + bNode *node, + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack **out) { - tex_output(node, execdata, in, out[0], &valtorgb_colorfn, data); + tex_output(node, execdata, in, out[0], &valtorgb_colorfn, data); } static void valtorgb_init(bNodeTree *UNUSED(ntree), bNode *node) { - node->storage = BKE_colorband_add(true); + node->storage = BKE_colorband_add(true); } void register_node_type_tex_valtorgb(void) { - static bNodeType ntype; + static bNodeType ntype; - tex_node_type_base(&ntype, TEX_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, valtorgb_in, valtorgb_out); - node_type_size_preset(&ntype, NODE_SIZE_LARGE); - node_type_init(&ntype, valtorgb_init); - node_type_storage(&ntype, "ColorBand", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, NULL, NULL, valtorgb_exec); + tex_node_type_base(&ntype, TEX_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, valtorgb_in, valtorgb_out); + node_type_size_preset(&ntype, NODE_SIZE_LARGE); + node_type_init(&ntype, valtorgb_init); + node_type_storage(&ntype, "ColorBand", node_free_standard_storage, node_copy_standard_storage); + node_type_exec(&ntype, NULL, NULL, valtorgb_exec); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } /* **************** RGBTOBW ******************** */ static bNodeSocketTemplate rgbtobw_in[] = { - { SOCK_RGBA, 1, N_("Color"), 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate rgbtobw_out[] = { - { SOCK_FLOAT, 0, N_("Val"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" }, + {SOCK_FLOAT, 0, N_("Val"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; - -static void rgbtobw_valuefn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) +static void rgbtobw_valuefn( + float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) { - float cin[4]; - tex_input_rgba(cin, in[0], p, thread); - *out = IMB_colormanagement_get_luminance(cin); + float cin[4]; + tex_input_rgba(cin, in[0], p, thread); + *out = IMB_colormanagement_get_luminance(cin); } -static void rgbtobw_exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void rgbtobw_exec(void *data, + int UNUSED(thread), + bNode *node, + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack **out) { - tex_output(node, execdata, in, out[0], &rgbtobw_valuefn, data); + tex_output(node, execdata, in, out[0], &rgbtobw_valuefn, data); } void register_node_type_tex_rgbtobw(void) { - static bNodeType ntype; + static bNodeType ntype; - tex_node_type_base(&ntype, TEX_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTOR, 0); - node_type_socket_templates(&ntype, rgbtobw_in, rgbtobw_out); - node_type_exec(&ntype, NULL, NULL, rgbtobw_exec); + tex_node_type_base(&ntype, TEX_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, rgbtobw_in, rgbtobw_out); + node_type_exec(&ntype, NULL, NULL, rgbtobw_exec); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_viewer.c b/source/blender/nodes/texture/nodes/node_texture_viewer.c index f6adc256103..b0c119e975f 100644 --- a/source/blender/nodes/texture/nodes/node_texture_viewer.c +++ b/source/blender/nodes/texture/nodes/node_texture_viewer.c @@ -21,43 +21,47 @@ * \ingroup texnodes */ - #include "node_texture_util.h" #include "NOD_texture.h" #include <math.h> static bNodeSocketTemplate inputs[] = { - { SOCK_RGBA, 1, N_("Color"), 1.0f, 0.0f, 0.0f, 1.0f }, - { -1, 0, "" }, + {SOCK_RGBA, 1, N_("Color"), 1.0f, 0.0f, 0.0f, 1.0f}, + {-1, 0, ""}, }; static bNodeSocketTemplate outputs[] = { - { -1, 0, "" }, + {-1, 0, ""}, }; -static void exec(void *data, int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *execdata, bNodeStack **in, bNodeStack **UNUSED(out)) +static void exec(void *data, + int UNUSED(thread), + bNode *UNUSED(node), + bNodeExecData *execdata, + bNodeStack **in, + bNodeStack **UNUSED(out)) { - TexCallData *cdata = (TexCallData *)data; + TexCallData *cdata = (TexCallData *)data; - if (cdata->do_preview) { - TexParams params; - float col[4]; - params_from_cdata(¶ms, cdata); + if (cdata->do_preview) { + TexParams params; + float col[4]; + params_from_cdata(¶ms, cdata); - tex_input_rgba(col, in[0], ¶ms, cdata->thread); - tex_do_preview(execdata->preview, params.previewco, col, cdata->do_manage); - } + tex_input_rgba(col, in[0], ¶ms, cdata->thread); + tex_do_preview(execdata->preview, params.previewco, col, cdata->do_manage); + } } void register_node_type_tex_viewer(void) { - static bNodeType ntype; + static bNodeType ntype; - tex_node_type_base(&ntype, TEX_NODE_VIEWER, "Viewer", NODE_CLASS_OUTPUT, NODE_PREVIEW); - node_type_socket_templates(&ntype, inputs, outputs); - node_type_exec(&ntype, NULL, NULL, exec); + tex_node_type_base(&ntype, TEX_NODE_VIEWER, "Viewer", NODE_CLASS_OUTPUT, NODE_PREVIEW); + node_type_socket_templates(&ntype, inputs, outputs); + node_type_exec(&ntype, NULL, NULL, exec); - /* Do not allow muting viewer node. */ - node_type_internal_links(&ntype, NULL); + /* Do not allow muting viewer node. */ + node_type_internal_links(&ntype, NULL); - nodeRegisterType(&ntype); + nodeRegisterType(&ntype); } |