Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Stockner <lukas.stockner@freenet.de>2022-10-30 00:41:21 +0300
committerLukas Stockner <lukas.stockner@freenet.de>2022-10-30 01:14:59 +0300
commitbc37e8d8399eef686b71341aa90eced9bc117786 (patch)
tree92e4af388150209df9bc44e2cba6f2f303aa7baf /source/blender/nodes
parent552abb838c76d44a0d7d1226b59a1ab381e88386 (diff)
parentd1d2f002c7caaf4ab457ec27bbc44666d7aac624 (diff)
Merge remote-tracking branch 'origin/master' into principled-v2
Diffstat (limited to 'source/blender/nodes')
-rw-r--r--source/blender/nodes/CMakeLists.txt25
-rw-r--r--source/blender/nodes/NOD_derived_node_tree.hh172
-rw-r--r--source/blender/nodes/NOD_geometry.h34
-rw-r--r--source/blender/nodes/NOD_geometry_exec.hh209
-rw-r--r--source/blender/nodes/NOD_geometry_nodes_eval_log.hh411
-rw-r--r--source/blender/nodes/NOD_geometry_nodes_lazy_function.hh181
-rw-r--r--source/blender/nodes/NOD_geometry_nodes_log.hh339
-rw-r--r--source/blender/nodes/NOD_multi_function.hh26
-rw-r--r--source/blender/nodes/NOD_node_declaration.hh76
-rw-r--r--source/blender/nodes/NOD_node_tree_ref.hh760
-rw-r--r--source/blender/nodes/NOD_shader.h1
-rw-r--r--source/blender/nodes/NOD_static_types.h277
-rw-r--r--source/blender/nodes/composite/CMakeLists.txt12
-rw-r--r--source/blender/nodes/composite/node_composite_tree.cc20
-rw-r--r--source/blender/nodes/composite/node_composite_util.cc6
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_alpha_over.cc72
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_antialiasing.cc24
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_bilateralblur.cc79
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_blur.cc423
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_bokehblur.cc180
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_bokehimage.cc70
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_boxmask.cc103
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_brightness.cc51
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_channel_matte.cc102
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_chroma_matte.cc67
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_color_matte.cc66
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_color_spill.cc116
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_colorbalance.cc81
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_colorcorrection.cc89
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_composite.cc131
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_convert_color_space.cc24
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_cornerpin.cc21
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_crop.cc172
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc64
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_curves.cc253
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_defocus.cc22
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_denoise.cc24
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_despeckle.cc76
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_diff_matte.cc58
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_dilate.cc490
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_directionalblur.cc144
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_displace.cc20
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_distance_matte.cc78
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_double_edge_mask.cc22
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_ellipsemask.cc103
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_exposure.cc31
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_filter.cc132
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_flip.cc66
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_gamma.cc32
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_glare.cc24
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_hue_sat_val.cc49
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_huecorrect.cc67
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_id_mask.cc22
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_image.cc292
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_inpaint.cc22
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_invert.cc59
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_keying.cc26
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_keyingscreen.cc20
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_lensdist.cc208
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_levels.cc165
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_luma_matte.cc59
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_map_range.cc69
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_map_uv.cc22
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_map_value.cc62
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_mask.cc24
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_math.cc67
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_mixrgb.cc125
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_movieclip.cc190
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_moviedistortion.cc24
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_normal.cc42
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_normalize.cc65
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_output_file.cc25
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_pixelate.cc52
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_planetrackdeform.cc21
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_posterize.cc35
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_premulkey.cc41
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_rgb.cc30
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_rotate.cc58
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_scale.cc168
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_scene_time.cc36
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_sepcomb_color.cc130
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_sepcomb_hsva.cc83
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_sepcomb_rgba.cc83
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_sepcomb_xyz.cc63
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_sepcomb_ycca.cc136
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_sepcomb_yuva.cc82
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_setalpha.cc46
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_split_viewer.cc75
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_stabilize2d.cc20
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_sunbeams.cc24
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_switch.cc30
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_switchview.cc26
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_texture.cc21
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_tonemap.cc270
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_trackpos.cc22
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_transform.cc79
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_translate.cc76
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_val_to_rgb.cc150
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_value.cc26
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_vec_blur.cc24
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_viewer.cc135
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_zcombine.cc23
-rw-r--r--source/blender/nodes/function/node_function_util.cc2
-rw-r--r--source/blender/nodes/function/node_function_util.hh2
-rw-r--r--source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc6
-rw-r--r--source/blender/nodes/function/nodes/node_fn_boolean_math.cc6
-rw-r--r--source/blender/nodes/function/nodes/node_fn_combine_color.cc8
-rw-r--r--source/blender/nodes/function/nodes/node_fn_compare.cc8
-rw-r--r--source/blender/nodes/function/nodes/node_fn_float_to_int.cc14
-rw-r--r--source/blender/nodes/function/nodes/node_fn_input_bool.cc6
-rw-r--r--source/blender/nodes/function/nodes/node_fn_input_color.cc6
-rw-r--r--source/blender/nodes/function/nodes/node_fn_input_int.cc6
-rw-r--r--source/blender/nodes/function/nodes/node_fn_input_special_characters.cc2
-rw-r--r--source/blender/nodes/function/nodes/node_fn_input_string.cc10
-rw-r--r--source/blender/nodes/function/nodes/node_fn_input_vector.cc6
-rw-r--r--source/blender/nodes/function/nodes/node_fn_random_value.cc6
-rw-r--r--source/blender/nodes/function/nodes/node_fn_rotate_euler.cc4
-rw-r--r--source/blender/nodes/function/nodes/node_fn_separate_color.cc12
-rw-r--r--source/blender/nodes/geometry/CMakeLists.txt38
-rw-r--r--source/blender/nodes/geometry/node_geometry_exec.cc1
-rw-r--r--source/blender/nodes/geometry/node_geometry_tree.cc19
-rw-r--r--source/blender/nodes/geometry/node_geometry_util.cc6
-rw-r--r--source/blender/nodes/geometry/node_geometry_util.hh34
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc66
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc45
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_attribute_domain_size.cc6
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_attribute_statistic.cc18
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_boolean.cc13
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_collection_info.cc26
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_convex_hull.cc20
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_endpoint_selection.cc35
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc14
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc11
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_handle_type_selection.cc28
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_primitive_arc.cc10
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_primitive_bezier_segment.cc4
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc12
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc6
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadrilateral.cc11
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_primitive_spiral.cc6
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc47
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_reverse.cc12
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc10
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_set_handle_type.cc41
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc68
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_spline_type.cc9
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_subdivide.cc7
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc399
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_topology_curve_of_point.cc121
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_topology_points_of_curve.cc182
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc492
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc87
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc438
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_distribute_points_in_volume.cc288
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc132
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_dual_mesh.cc237
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc180
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_edge_paths_to_curves.cc110
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_edge_paths_to_selection.cc139
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_edge_split.cc23
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc283
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_field_at_index.cc150
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_flip_faces.cc28
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_geometry_to_instance.cc14
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_image_texture.cc60
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_input_curve_handles.cc25
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_input_instance_rotation.cc27
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_input_instance_scale.cc27
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_input_material.cc4
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_angle.cc92
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_neighbors.cc35
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_vertices.cc109
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_area.cc39
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_is_planar.cc54
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_neighbors.cc80
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_input_mesh_island.cc67
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_input_mesh_vertex_neighbors.cc72
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_input_named_attribute.cc14
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_input_scene_time.cc2
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_input_shortest_edge_paths.cc246
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_input_spline_length.cc25
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_input_tangent.cc27
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_instance_on_points.cc63
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_instances_to_points.cc16
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_interpolate_domain.cc (renamed from source/blender/nodes/geometry/nodes/node_geo_field_on_domain.cc)70
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc46
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_material_selection.cc44
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_merge_by_distance.cc46
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_face_set_boundaries.cc94
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc14
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc59
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cylinder.cc6
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_grid.cc10
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc2
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc15
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc163
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_to_curve.cc7
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_to_points.cc52
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_to_volume.cc21
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_topology_corners_of_face.cc189
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_topology_corners_of_vertex.cc209
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_topology_edges_of_corner.cc136
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_topology_edges_of_vertex.cc211
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_topology_face_of_corner.cc121
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_topology_offset_corner_in_face.cc113
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_topology_vertex_of_corner.cc79
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_object_info.cc16
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_offset_point_in_curve.cc169
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_points.cc14
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_points_to_vertices.cc25
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc15
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_proximity.cc11
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_raycast.cc26
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_realize_instances.cc2
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_remove_attribute.cc2
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_rotate_instances.cc19
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_sample_index.cc337
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_sample_nearest.cc342
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_sample_nearest_surface.cc278
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_sample_uv_surface.cc294
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_scale_elements.cc172
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_scale_instances.cc18
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_self_object.cc29
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_separate_geometry.cc6
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc47
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_set_curve_normal.cc73
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_set_curve_radius.cc23
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc24
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_set_id.cc4
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_set_material.cc13
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_set_material_index.cc20
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_set_point_radius.cc20
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_set_position.cc11
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_set_shade_smooth.cc29
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_set_spline_cyclic.cc24
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_set_spline_resolution.cc28
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc77
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_string_join.cc5
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_string_to_curves.cc42
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc26
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_switch.cc10
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc826
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_transform.cc97
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_translate_instances.cc20
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_triangulate.cc19
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_uv_pack_islands.cc51
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_uv_unwrap.cc58
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_viewer.cc20
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_volume_cube.cc30
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_volume_to_mesh.cc17
-rw-r--r--source/blender/nodes/intern/derived_node_tree.cc139
-rw-r--r--source/blender/nodes/intern/geometry_nodes_eval_log.cc520
-rw-r--r--source/blender/nodes/intern/geometry_nodes_lazy_function.cc1442
-rw-r--r--source/blender/nodes/intern/geometry_nodes_log.cc587
-rw-r--r--source/blender/nodes/intern/node_common.cc34
-rw-r--r--source/blender/nodes/intern/node_declaration.cc27
-rw-r--r--source/blender/nodes/intern/node_geometry_exec.cc71
-rw-r--r--source/blender/nodes/intern/node_multi_function.cc26
-rw-r--r--source/blender/nodes/intern/node_socket.cc26
-rw-r--r--source/blender/nodes/intern/node_socket_declarations.cc2
-rw-r--r--source/blender/nodes/intern/node_tree_ref.cc678
-rw-r--r--source/blender/nodes/intern/node_util.cc (renamed from source/blender/nodes/intern/node_util.c)18
-rw-r--r--source/blender/nodes/intern/socket_search_link.cc63
-rw-r--r--source/blender/nodes/shader/CMakeLists.txt27
-rw-r--r--source/blender/nodes/shader/node_shader_tree.cc56
-rw-r--r--source/blender/nodes/shader/node_shader_util.cc8
-rw-r--r--source/blender/nodes/shader/node_shader_util.hh2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_add_shader.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.cc8
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_attribute.cc37
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_background.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bevel.cc6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_blackbody.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_brightness.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.cc6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bsdf_glass.cc4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.cc4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bsdf_hair.cc4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bsdf_hair_principled.cc10
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc27
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bsdf_refraction.cc4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bsdf_toon.cc4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bsdf_translucent.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bsdf_transparent.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bsdf_velvet.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bump.cc4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_camera.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_clamp.cc6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_color_ramp.cc8
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_curves.cc39
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_displacement.cc4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_eevee_specular.cc4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_emission.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_fresnel.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_gamma.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_geometry.cc7
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_hair_info.cc6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_holdout.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_hueSatVal.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_ies_light.cc4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_invert.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_layer_weight.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_light_falloff.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_light_path.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_map_range.cc6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_mapping.cc4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_math.cc9
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_mix.cc469
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_mix_rgb.cc37
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_mix_shader.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_normal.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_normal_map.cc4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_object_info.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_output_aov.cc6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_output_light.cc6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_output_linestyle.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_output_material.cc6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_output_world.cc6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_particle_info.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_point_info.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_rgb.cc9
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_rgb_to_bw.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_script.cc8
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_sepcomb_color.cc10
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_sepcomb_hsv.cc10
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_sepcomb_rgb.cc14
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_sepcomb_xyz.cc6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_shader_to_rgb.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_squeeze.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.cc6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tangent.cc4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_brick.cc21
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_checker.cc17
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_coord.cc12
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_environment.cc10
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc14
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_image.cc6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_magic.cc12
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_musgrave.cc14
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_noise.cc10
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.cc8
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_sky.cc64
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc18
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_wave.cc12
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_white_noise.cc17
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_uv_along_stroke.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_uvmap.cc4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_value.cc9
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_vector_displacement.cc4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_vector_math.cc6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_vector_rotate.cc6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_vector_transform.cc8
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_vertex_color.cc11
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_volume_absorption.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_volume_info.cc8
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_volume_principled.cc4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_volume_scatter.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_wavelength.cc2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_wireframe.cc4
-rw-r--r--source/blender/nodes/texture/CMakeLists.txt18
-rw-r--r--source/blender/nodes/texture/node_texture_tree.c7
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_compose.c3
363 files changed, 17353 insertions, 7616 deletions
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index 386e5fe14c9..2398aefc67a 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -29,7 +29,6 @@ set(INC
../makesrna
../render
../windowmanager
- ../../../intern/glew-mx
../../../intern/guardedalloc
# dna_type_offsets.h
@@ -41,7 +40,8 @@ set(INC
set(SRC
intern/derived_node_tree.cc
- intern/geometry_nodes_eval_log.cc
+ intern/geometry_nodes_lazy_function.cc
+ intern/geometry_nodes_log.cc
intern/math_functions.cc
intern/node_common.cc
intern/node_declaration.cc
@@ -50,8 +50,7 @@ set(SRC
intern/node_multi_function.cc
intern/node_socket.cc
intern/node_socket_declarations.cc
- intern/node_tree_ref.cc
- intern/node_util.c
+ intern/node_util.cc
intern/socket_search_link.cc
NOD_common.h
@@ -60,11 +59,11 @@ set(SRC
NOD_function.h
NOD_geometry.h
NOD_geometry_exec.hh
- NOD_geometry_nodes_eval_log.hh
+ NOD_geometry_nodes_lazy_function.hh
+ NOD_geometry_nodes_log.hh
NOD_math_functions.hh
NOD_multi_function.hh
NOD_node_declaration.hh
- NOD_node_tree_ref.hh
NOD_shader.h
NOD_socket.h
NOD_socket_declarations.hh
@@ -104,20 +103,6 @@ if(WITH_BULLET)
add_definitions(-DWITH_BULLET)
endif()
-if(WITH_PYTHON)
- list(APPEND INC
- ../python
- )
- list(APPEND INC_SYS
- ${PYTHON_INCLUDE_DIRS}
- )
- list(APPEND LIB
- ${PYTHON_LINKFLAGS}
- ${PYTHON_LIBRARIES}
- )
- add_definitions(-DWITH_PYTHON)
-endif()
-
if(WITH_TBB)
list(APPEND INC_SYS
${TBB_INCLUDE_DIRS}
diff --git a/source/blender/nodes/NOD_derived_node_tree.hh b/source/blender/nodes/NOD_derived_node_tree.hh
index b0799d90dcd..b3775e729da 100644
--- a/source/blender/nodes/NOD_derived_node_tree.hh
+++ b/source/blender/nodes/NOD_derived_node_tree.hh
@@ -5,16 +5,17 @@
/** \file
* \ingroup nodes
*
- * DerivedNodeTree builds on top of NodeTreeRef and makes working with (nested) node groups more
- * convenient and safe. It does so by pairing nodes and sockets with a context. The context
- * contains information about the current "instance" of the node or socket. A node might be
- * "instanced" multiple times when it is in a node group that is used multiple times.
+ * DerivedNodeTree makes working with (nested) node groups more convenient and safe. It does so by
+ * pairing nodes and sockets with a context. The context contains information about the current
+ * "instance" of the node or socket. A node might be "instanced" multiple times when it is in a
+ * node group that is used multiple times.
*/
#include "BLI_function_ref.hh"
+#include "BLI_linear_allocator.hh"
#include "BLI_vector_set.hh"
-#include "NOD_node_tree_ref.hh"
+#include "BKE_node_runtime.hh"
namespace blender::nodes {
@@ -40,20 +41,20 @@ class DTreeContext {
DTreeContext *parent_context_;
/* Null when this context is for the root node group. Otherwise it points to the group node in
* the parent node group that contains this context. */
- const NodeRef *parent_node_;
+ const bNode *parent_node_;
/* The current node tree. */
- const NodeTreeRef *tree_;
+ const bNodeTree *btree_;
/* All the children contexts of this context. */
- Map<const NodeRef *, DTreeContext *> children_;
+ Map<const bNode *, DTreeContext *> children_;
DerivedNodeTree *derived_tree_;
friend DerivedNodeTree;
public:
- const NodeTreeRef &tree() const;
+ const bNodeTree &btree() const;
const DTreeContext *parent_context() const;
- const NodeRef *parent_node() const;
- const DTreeContext *child_context(const NodeRef &node) const;
+ const bNode *parent_node() const;
+ const DTreeContext *child_context(const bNode &node) const;
const DerivedNodeTree &derived_tree() const;
bool is_root() const;
};
@@ -65,15 +66,16 @@ class DTreeContext {
class DNode {
private:
const DTreeContext *context_ = nullptr;
- const NodeRef *node_ref_ = nullptr;
+ const bNode *bnode_ = nullptr;
public:
DNode() = default;
- DNode(const DTreeContext *context, const NodeRef *node);
+ DNode(const DTreeContext *context, const bNode *node);
const DTreeContext *context() const;
- const NodeRef *node_ref() const;
- const NodeRef *operator->() const;
+ const bNode *bnode() const;
+ const bNode *operator->() const;
+ const bNode &operator*() const;
friend bool operator==(const DNode &a, const DNode &b);
friend bool operator!=(const DNode &a, const DNode &b);
@@ -98,17 +100,18 @@ class DNode {
class DSocket {
protected:
const DTreeContext *context_ = nullptr;
- const SocketRef *socket_ref_ = nullptr;
+ const bNodeSocket *bsocket_ = nullptr;
public:
DSocket() = default;
- DSocket(const DTreeContext *context, const SocketRef *socket);
+ DSocket(const DTreeContext *context, const bNodeSocket *socket);
DSocket(const DInputSocket &input_socket);
DSocket(const DOutputSocket &output_socket);
const DTreeContext *context() const;
- const SocketRef *socket_ref() const;
- const SocketRef *operator->() const;
+ const bNodeSocket *bsocket() const;
+ const bNodeSocket *operator->() const;
+ const bNodeSocket &operator*() const;
friend bool operator==(const DSocket &a, const DSocket &b);
friend bool operator!=(const DSocket &a, const DSocket &b);
@@ -123,12 +126,9 @@ class DSocket {
class DInputSocket : public DSocket {
public:
DInputSocket() = default;
- DInputSocket(const DTreeContext *context, const InputSocketRef *socket);
+ DInputSocket(const DTreeContext *context, const bNodeSocket *socket);
explicit DInputSocket(const DSocket &base_socket);
- const InputSocketRef *socket_ref() const;
- const InputSocketRef *operator->() const;
-
DOutputSocket get_corresponding_group_node_output() const;
Vector<DOutputSocket, 4> get_corresponding_group_input_sockets() const;
@@ -144,12 +144,9 @@ class DInputSocket : public DSocket {
class DOutputSocket : public DSocket {
public:
DOutputSocket() = default;
- DOutputSocket(const DTreeContext *context, const OutputSocketRef *socket);
+ DOutputSocket(const DTreeContext *context, const bNodeSocket *socket);
explicit DOutputSocket(const DSocket &base_socket);
- const OutputSocketRef *socket_ref() const;
- const OutputSocketRef *operator->() const;
-
DInputSocket get_corresponding_group_node_input() const;
DInputSocket get_active_corresponding_group_output_socket() const;
@@ -177,7 +174,7 @@ class DerivedNodeTree {
private:
LinearAllocator<> allocator_;
DTreeContext *root_context_;
- VectorSet<const NodeTreeRef *> used_node_tree_refs_;
+ VectorSet<const bNodeTree *> used_btrees_;
public:
/**
@@ -186,11 +183,11 @@ class DerivedNodeTree {
* has to make sure that the node tree refs added to #node_tree_refs live at least as long as the
* derived node tree.
*/
- DerivedNodeTree(bNodeTree &btree, NodeTreeRefMap &node_tree_refs);
+ DerivedNodeTree(const bNodeTree &btree);
~DerivedNodeTree();
const DTreeContext &root_context() const;
- Span<const NodeTreeRef *> used_node_tree_refs() const;
+ Span<const bNodeTree *> used_btrees() const;
/**
* \return True when there is a link cycle. Unavailable sockets are ignored.
@@ -205,9 +202,8 @@ class DerivedNodeTree {
private:
DTreeContext &construct_context_recursively(DTreeContext *parent_context,
- const NodeRef *parent_node,
- bNodeTree &btree,
- NodeTreeRefMap &node_tree_refs);
+ const bNode *parent_node,
+ const bNodeTree &btree);
void destruct_context_recursively(DTreeContext *context);
void foreach_node_in_context_recursive(const DTreeContext &context,
@@ -215,7 +211,6 @@ class DerivedNodeTree {
};
namespace derived_node_tree_types {
-using namespace node_tree_ref_types;
using nodes::DerivedNodeTree;
using nodes::DInputSocket;
using nodes::DNode;
@@ -228,9 +223,9 @@ using nodes::DTreeContext;
/** \name #DTreeContext Inline Methods
* \{ */
-inline const NodeTreeRef &DTreeContext::tree() const
+inline const bNodeTree &DTreeContext::btree() const
{
- return *tree_;
+ return *btree_;
}
inline const DTreeContext *DTreeContext::parent_context() const
@@ -238,12 +233,12 @@ inline const DTreeContext *DTreeContext::parent_context() const
return parent_context_;
}
-inline const NodeRef *DTreeContext::parent_node() const
+inline const bNode *DTreeContext::parent_node() const
{
return parent_node_;
}
-inline const DTreeContext *DTreeContext::child_context(const NodeRef &node) const
+inline const DTreeContext *DTreeContext::child_context(const bNode &node) const
{
return children_.lookup_default(&node, nullptr);
}
@@ -264,10 +259,10 @@ inline bool DTreeContext::is_root() const
/** \name #DNode Inline Methods
* \{ */
-inline DNode::DNode(const DTreeContext *context, const NodeRef *node_ref)
- : context_(context), node_ref_(node_ref)
+inline DNode::DNode(const DTreeContext *context, const bNode *bnode)
+ : context_(context), bnode_(bnode)
{
- BLI_assert(node_ref == nullptr || &node_ref->tree() == &context->tree());
+ BLI_assert(bnode == nullptr || bnode->runtime->owner_tree == &context->btree());
}
inline const DTreeContext *DNode::context() const
@@ -275,14 +270,14 @@ inline const DTreeContext *DNode::context() const
return context_;
}
-inline const NodeRef *DNode::node_ref() const
+inline const bNode *DNode::bnode() const
{
- return node_ref_;
+ return bnode_;
}
inline bool operator==(const DNode &a, const DNode &b)
{
- return a.context_ == b.context_ && a.node_ref_ == b.node_ref_;
+ return a.context_ == b.context_ && a.bnode_ == b.bnode_;
}
inline bool operator!=(const DNode &a, const DNode &b)
@@ -292,37 +287,43 @@ inline bool operator!=(const DNode &a, const DNode &b)
inline DNode::operator bool() const
{
- return node_ref_ != nullptr;
+ return bnode_ != nullptr;
+}
+
+inline const bNode *DNode::operator->() const
+{
+ return bnode_;
}
-inline const NodeRef *DNode::operator->() const
+inline const bNode &DNode::operator*() const
{
- return node_ref_;
+ BLI_assert(bnode_ != nullptr);
+ return *bnode_;
}
inline uint64_t DNode::hash() const
{
- return get_default_hash_2(context_, node_ref_);
+ return get_default_hash_2(context_, bnode_);
}
inline DInputSocket DNode::input(int index) const
{
- return {context_, &node_ref_->input(index)};
+ return {context_, &bnode_->input_socket(index)};
}
inline DOutputSocket DNode::output(int index) const
{
- return {context_, &node_ref_->output(index)};
+ return {context_, &bnode_->output_socket(index)};
}
inline DInputSocket DNode::input_by_identifier(StringRef identifier) const
{
- return {context_, &node_ref_->input_by_identifier(identifier)};
+ return {context_, &bnode_->input_by_identifier(identifier)};
}
inline DOutputSocket DNode::output_by_identifier(StringRef identifier) const
{
- return {context_, &node_ref_->output_by_identifier(identifier)};
+ return {context_, &bnode_->output_by_identifier(identifier)};
}
/** \} */
@@ -331,19 +332,20 @@ inline DOutputSocket DNode::output_by_identifier(StringRef identifier) const
/** \name #DSocket Inline Methods
* \{ */
-inline DSocket::DSocket(const DTreeContext *context, const SocketRef *socket_ref)
- : context_(context), socket_ref_(socket_ref)
+inline DSocket::DSocket(const DTreeContext *context, const bNodeSocket *bsocket)
+ : context_(context), bsocket_(bsocket)
{
- BLI_assert(socket_ref == nullptr || &socket_ref->tree() == &context->tree());
+ BLI_assert(bsocket == nullptr ||
+ bsocket->runtime->owner_node->runtime->owner_tree == &context->btree());
}
inline DSocket::DSocket(const DInputSocket &input_socket)
- : DSocket(input_socket.context_, input_socket.socket_ref_)
+ : DSocket(input_socket.context_, input_socket.bsocket_)
{
}
inline DSocket::DSocket(const DOutputSocket &output_socket)
- : DSocket(output_socket.context_, output_socket.socket_ref_)
+ : DSocket(output_socket.context_, output_socket.bsocket_)
{
}
@@ -352,14 +354,14 @@ inline const DTreeContext *DSocket::context() const
return context_;
}
-inline const SocketRef *DSocket::socket_ref() const
+inline const bNodeSocket *DSocket::bsocket() const
{
- return socket_ref_;
+ return bsocket_;
}
inline bool operator==(const DSocket &a, const DSocket &b)
{
- return a.context_ == b.context_ && a.socket_ref_ == b.socket_ref_;
+ return a.context_ == b.context_ && a.bsocket_ == b.bsocket_;
}
inline bool operator!=(const DSocket &a, const DSocket &b)
@@ -369,23 +371,29 @@ inline bool operator!=(const DSocket &a, const DSocket &b)
inline DSocket::operator bool() const
{
- return socket_ref_ != nullptr;
+ return bsocket_ != nullptr;
}
-inline const SocketRef *DSocket::operator->() const
+inline const bNodeSocket *DSocket::operator->() const
{
- return socket_ref_;
+ return bsocket_;
+}
+
+inline const bNodeSocket &DSocket::operator*() const
+{
+ BLI_assert(bsocket_ != nullptr);
+ return *bsocket_;
}
inline uint64_t DSocket::hash() const
{
- return get_default_hash_2(context_, socket_ref_);
+ return get_default_hash_2(context_, bsocket_);
}
inline DNode DSocket::node() const
{
- BLI_assert(socket_ref_ != nullptr);
- return {context_, &socket_ref_->node()};
+ BLI_assert(bsocket_ != nullptr);
+ return {context_, bsocket_->runtime->owner_node};
}
/** \} */
@@ -394,8 +402,8 @@ inline DNode DSocket::node() const
/** \name #DInputSocket Inline Methods
* \{ */
-inline DInputSocket::DInputSocket(const DTreeContext *context, const InputSocketRef *socket_ref)
- : DSocket(context, socket_ref)
+inline DInputSocket::DInputSocket(const DTreeContext *context, const bNodeSocket *bsocket)
+ : DSocket(context, bsocket)
{
}
@@ -404,24 +412,14 @@ inline DInputSocket::DInputSocket(const DSocket &base_socket) : DSocket(base_soc
BLI_assert(base_socket->is_input());
}
-inline const InputSocketRef *DInputSocket::socket_ref() const
-{
- return (const InputSocketRef *)socket_ref_;
-}
-
-inline const InputSocketRef *DInputSocket::operator->() const
-{
- return (const InputSocketRef *)socket_ref_;
-}
-
/** \} */
/* -------------------------------------------------------------------- */
/** \name #DOutputSocket Inline Methods
* \{ */
-inline DOutputSocket::DOutputSocket(const DTreeContext *context, const OutputSocketRef *socket_ref)
- : DSocket(context, socket_ref)
+inline DOutputSocket::DOutputSocket(const DTreeContext *context, const bNodeSocket *bsocket)
+ : DSocket(context, bsocket)
{
}
@@ -430,16 +428,6 @@ inline DOutputSocket::DOutputSocket(const DSocket &base_socket) : DSocket(base_s
BLI_assert(base_socket->is_output());
}
-inline const OutputSocketRef *DOutputSocket::socket_ref() const
-{
- return (const OutputSocketRef *)socket_ref_;
-}
-
-inline const OutputSocketRef *DOutputSocket::operator->() const
-{
- return (const OutputSocketRef *)socket_ref_;
-}
-
/** \} */
/* -------------------------------------------------------------------- */
@@ -451,9 +439,9 @@ inline const DTreeContext &DerivedNodeTree::root_context() const
return *root_context_;
}
-inline Span<const NodeTreeRef *> DerivedNodeTree::used_node_tree_refs() const
+inline Span<const bNodeTree *> DerivedNodeTree::used_btrees() const
{
- return used_node_tree_refs_;
+ return used_btrees_;
}
/** \} */
diff --git a/source/blender/nodes/NOD_geometry.h b/source/blender/nodes/NOD_geometry.h
index 86c276fbd6f..3b886bd55c6 100644
--- a/source/blender/nodes/NOD_geometry.h
+++ b/source/blender/nodes/NOD_geometry.h
@@ -46,20 +46,23 @@ void register_node_type_geo_curve_spline_type(void);
void register_node_type_geo_curve_subdivide(void);
void register_node_type_geo_curve_to_mesh(void);
void register_node_type_geo_curve_to_points(void);
+void register_node_type_geo_curve_topology_curve_of_point(void);
+void register_node_type_geo_curve_topology_points_of_curve(void);
void register_node_type_geo_curve_trim(void);
void register_node_type_geo_deform_curves_on_surface(void);
void register_node_type_geo_delete_geometry(void);
-void register_node_type_geo_duplicate_elements(void);
+void register_node_type_geo_distribute_points_in_volume(void);
void register_node_type_geo_distribute_points_on_faces(void);
void register_node_type_geo_dual_mesh(void);
+void register_node_type_geo_duplicate_elements(void);
+void register_node_type_geo_edge_paths_to_curves(void);
+void register_node_type_geo_edge_paths_to_selection(void);
void register_node_type_geo_edge_split(void);
void register_node_type_geo_extrude_mesh(void);
void register_node_type_geo_field_at_index(void);
-void register_node_type_geo_field_on_domain(void);
void register_node_type_geo_flip_faces(void);
void register_node_type_geo_geometry_to_instance(void);
void register_node_type_geo_image_texture(void);
-void register_node_type_geo_input_named_attribute(void);
void register_node_type_geo_input_curve_handles(void);
void register_node_type_geo_input_curve_tilt(void);
void register_node_type_geo_input_id(void);
@@ -76,22 +79,26 @@ void register_node_type_geo_input_mesh_face_is_planar(void);
void register_node_type_geo_input_mesh_face_neighbors(void);
void register_node_type_geo_input_mesh_island(void);
void register_node_type_geo_input_mesh_vertex_neighbors(void);
+void register_node_type_geo_input_named_attribute(void);
void register_node_type_geo_input_normal(void);
void register_node_type_geo_input_position(void);
void register_node_type_geo_input_radius(void);
void register_node_type_geo_input_scene_time(void);
void register_node_type_geo_input_shade_smooth(void);
+void register_node_type_geo_input_shortest_edge_paths(void);
void register_node_type_geo_input_spline_cyclic(void);
void register_node_type_geo_input_spline_length(void);
void register_node_type_geo_input_spline_resolution(void);
void register_node_type_geo_input_tangent(void);
void register_node_type_geo_instance_on_points(void);
void register_node_type_geo_instances_to_points(void);
+void register_node_type_geo_interpolate_domain(void);
void register_node_type_geo_is_viewport(void);
void register_node_type_geo_join_geometry(void);
void register_node_type_geo_material_replace(void);
void register_node_type_geo_material_selection(void);
void register_node_type_geo_merge_by_distance(void);
+void register_node_type_geo_mesh_face_set_boundaries(void);
void register_node_type_geo_mesh_primitive_circle(void);
void register_node_type_geo_mesh_primitive_cone(void);
void register_node_type_geo_mesh_primitive_cube(void);
@@ -104,21 +111,35 @@ void register_node_type_geo_mesh_subdivide(void);
void register_node_type_geo_mesh_to_curve(void);
void register_node_type_geo_mesh_to_points(void);
void register_node_type_geo_mesh_to_volume(void);
+void register_node_type_geo_mesh_topology_corners_of_face(void);
+void register_node_type_geo_mesh_topology_corners_of_vertex(void);
+void register_node_type_geo_mesh_topology_edges_of_corner(void);
+void register_node_type_geo_mesh_topology_edges_of_vertex(void);
+void register_node_type_geo_mesh_topology_face_of_corner(void);
+void register_node_type_geo_mesh_topology_offset_corner_in_face(void);
+void register_node_type_geo_mesh_topology_vertex_of_corner(void);
void register_node_type_geo_object_info(void);
-void register_node_type_geo_points(void);
+void register_node_type_geo_offset_point_in_curve(void);
void register_node_type_geo_points_to_vertices(void);
void register_node_type_geo_points_to_volume(void);
+void register_node_type_geo_points(void);
void register_node_type_geo_proximity(void);
void register_node_type_geo_raycast(void);
void register_node_type_geo_realize_instances(void);
void register_node_type_geo_remove_attribute(void);
void register_node_type_geo_rotate_instances(void);
+void register_node_type_geo_sample_index(void);
+void register_node_type_geo_sample_nearest_surface(void);
+void register_node_type_geo_sample_nearest(void);
+void register_node_type_geo_sample_uv_surface(void);
void register_node_type_geo_scale_elements(void);
void register_node_type_geo_scale_instances(void);
void register_node_type_geo_select_by_handle_type(void);
void register_node_type_geo_separate_components(void);
void register_node_type_geo_separate_geometry(void);
+void register_node_type_geo_self_object(void);
void register_node_type_geo_set_curve_handles(void);
+void register_node_type_geo_set_curve_normal(void);
void register_node_type_geo_set_curve_radius(void);
void register_node_type_geo_set_curve_tilt(void);
void register_node_type_geo_set_id(void);
@@ -134,15 +155,14 @@ void register_node_type_geo_string_join(void);
void register_node_type_geo_string_to_curves(void);
void register_node_type_geo_subdivision_surface(void);
void register_node_type_geo_switch(void);
-void register_node_type_geo_transfer_attribute(void);
void register_node_type_geo_transform(void);
void register_node_type_geo_translate_instances(void);
void register_node_type_geo_triangulate(void);
+void register_node_type_geo_uv_pack_islands(void);
+void register_node_type_geo_uv_unwrap(void);
void register_node_type_geo_viewer(void);
void register_node_type_geo_volume_cube(void);
void register_node_type_geo_volume_to_mesh(void);
-void register_node_type_geo_uv_pack_islands(void);
-void register_node_type_geo_uv_unwrap(void);
#ifdef __cplusplus
}
diff --git a/source/blender/nodes/NOD_geometry_exec.hh b/source/blender/nodes/NOD_geometry_exec.hh
index c5bc42b059d..73e82f741ab 100644
--- a/source/blender/nodes/NOD_geometry_exec.hh
+++ b/source/blender/nodes/NOD_geometry_exec.hh
@@ -3,6 +3,7 @@
#pragma once
#include "FN_field.hh"
+#include "FN_lazy_function.hh"
#include "FN_multi_function_builder.hh"
#include "BKE_geometry_fields.hh"
@@ -11,9 +12,8 @@
#include "DNA_node_types.h"
#include "NOD_derived_node_tree.hh"
-#include "NOD_geometry_nodes_eval_log.hh"
+#include "NOD_geometry_nodes_lazy_function.hh"
-struct Depsgraph;
struct ModifierData;
namespace blender::nodes {
@@ -28,8 +28,6 @@ using bke::AttributeReader;
using bke::AttributeWriter;
using bke::GAttributeReader;
using bke::GAttributeWriter;
-using bke::GeometryComponentFieldContext;
-using bke::GeometryFieldInput;
using bke::GSpanAttributeWriter;
using bke::MutableAttributeAccessor;
using bke::SpanAttributeWriter;
@@ -42,75 +40,18 @@ using fn::FieldInput;
using fn::FieldOperation;
using fn::GField;
using fn::ValueOrField;
-using geometry_nodes_eval_log::eNamedAttrUsage;
-using geometry_nodes_eval_log::NodeWarningType;
-
-/**
- * This class exists to separate the memory management details of the geometry nodes evaluator
- * from the node execution functions and related utilities.
- */
-class GeoNodeExecParamsProvider {
- public:
- DNode dnode;
- const Object *self_object = nullptr;
- const ModifierData *modifier = nullptr;
- Depsgraph *depsgraph = nullptr;
- geometry_nodes_eval_log::GeoLogger *logger = nullptr;
-
- /**
- * Returns true when the node is allowed to get/extract the input value. The identifier is
- * expected to be valid. This may return false if the input value has been consumed already.
- */
- virtual bool can_get_input(StringRef identifier) const = 0;
-
- /**
- * Returns true when the node is allowed to set the output value. The identifier is expected to
- * be valid. This may return false if the output value has been set already.
- */
- virtual bool can_set_output(StringRef identifier) const = 0;
-
- /**
- * Take ownership of an input value. The caller is responsible for destructing the value. It does
- * not have to be freed, because the memory is managed by the geometry nodes evaluator.
- */
- virtual GMutablePointer extract_input(StringRef identifier) = 0;
-
- /**
- * Similar to #extract_input, but has to be used for multi-input sockets.
- */
- virtual Vector<GMutablePointer> extract_multi_input(StringRef identifier) = 0;
-
- /**
- * Get the input value for the identifier without taking ownership of it.
- */
- virtual GPointer get_input(StringRef identifier) const = 0;
-
- /**
- * Prepare a memory buffer for an output value of the node. The returned memory has to be
- * initialized by the caller. The identifier and type are expected to be correct.
- */
- virtual GMutablePointer alloc_output_value(const CPPType &type) = 0;
-
- /**
- * The value has been allocated with #alloc_output_value.
- */
- virtual void set_output(StringRef identifier, GMutablePointer value) = 0;
-
- /* A description for these methods is provided in GeoNodeExecParams. */
- virtual void set_input_unused(StringRef identifier) = 0;
- virtual bool output_is_required(StringRef identifier) const = 0;
- virtual bool lazy_require_input(StringRef identifier) = 0;
- virtual bool lazy_output_is_required(StringRef identifier) const = 0;
-
- virtual void set_default_remaining_outputs() = 0;
-};
+using geo_eval_log::NamedAttributeUsage;
+using geo_eval_log::NodeWarningType;
class GeoNodeExecParams {
private:
- GeoNodeExecParamsProvider *provider_;
+ const bNode &node_;
+ lf::Params &params_;
+ const lf::Context &lf_context_;
public:
- GeoNodeExecParams(GeoNodeExecParamsProvider &provider) : provider_(&provider)
+ GeoNodeExecParams(const bNode &node, lf::Params &params, const lf::Context &lf_context)
+ : node_(node), params_(params), lf_context_(lf_context)
{
}
@@ -121,20 +62,6 @@ class GeoNodeExecParams {
/**
* Get the input value for the input socket with the given identifier.
*
- * The node calling becomes responsible for destructing the value before it is done
- * executing. This method can only be called once for each identifier.
- */
- GMutablePointer extract_input(StringRef identifier)
- {
-#ifdef DEBUG
- this->check_input_access(identifier);
-#endif
- return provider_->extract_input(identifier);
- }
-
- /**
- * Get the input value for the input socket with the given identifier.
- *
* This method can only be called once for each identifier.
*/
template<typename T> T extract_input(StringRef identifier)
@@ -153,8 +80,8 @@ class GeoNodeExecParams {
#ifdef DEBUG
this->check_input_access(identifier, &CPPType::get<T>());
#endif
- GMutablePointer gvalue = this->extract_input(identifier);
- T value = gvalue.relocate_out<T>();
+ const int index = this->get_input_index(identifier);
+ T value = params_.extract_input<T>(index);
if constexpr (std::is_same_v<T, GeometrySet>) {
this->check_input_geometry_set(identifier, value);
}
@@ -166,27 +93,6 @@ class GeoNodeExecParams {
void check_output_geometry_set(const GeometrySet &geometry_set) const;
/**
- * Get input as vector for multi input socket with the given identifier.
- *
- * This method can only be called once for each identifier.
- */
- template<typename T> Vector<T> extract_multi_input(StringRef identifier)
- {
- Vector<GMutablePointer> gvalues = provider_->extract_multi_input(identifier);
- Vector<T> values;
- for (GMutablePointer gvalue : gvalues) {
- if constexpr (is_field_base_type_v<T>) {
- const ValueOrField<T> value_or_field = gvalue.relocate_out<ValueOrField<T>>();
- values.append(value_or_field.as_value());
- }
- else {
- values.append(gvalue.relocate_out<T>());
- }
- }
- return values;
- }
-
- /**
* Get the input value for the input socket with the given identifier.
*/
template<typename T> T get_input(StringRef identifier) const
@@ -204,9 +110,8 @@ class GeoNodeExecParams {
#ifdef DEBUG
this->check_input_access(identifier, &CPPType::get<T>());
#endif
- GPointer gvalue = provider_->get_input(identifier);
- BLI_assert(gvalue.is_type<T>());
- const T &value = *(const T *)gvalue.get();
+ const int index = this->get_input_index(identifier);
+ const T &value = params_.get_input<T>(index);
if constexpr (std::is_same_v<T, GeometrySet>) {
this->check_input_geometry_set(identifier, value);
}
@@ -228,17 +133,28 @@ class GeoNodeExecParams {
this->set_output(identifier, ValueOrField<BaseType>(std::forward<T>(value)));
}
else {
- const CPPType &type = CPPType::get<StoredT>();
#ifdef DEBUG
+ const CPPType &type = CPPType::get<StoredT>();
this->check_output_access(identifier, type);
#endif
if constexpr (std::is_same_v<StoredT, GeometrySet>) {
this->check_output_geometry_set(value);
}
- GMutablePointer gvalue = provider_->alloc_output_value(type);
- new (gvalue.get()) StoredT(std::forward<T>(value));
- provider_->set_output(identifier, gvalue);
+ const int index = this->get_output_index(identifier);
+ params_.set_output(index, std::forward<T>(value));
+ }
+ }
+
+ geo_eval_log::GeoTreeLogger *get_local_tree_logger() const
+ {
+ GeoNodesLFUserData *user_data = this->user_data();
+ BLI_assert(user_data != nullptr);
+ const ComputeContext *compute_context = user_data->compute_context;
+ BLI_assert(compute_context != nullptr);
+ if (user_data->modifier_data->eval_log == nullptr) {
+ return nullptr;
}
+ return &user_data->modifier_data->eval_log->get_local_tree_logger(*compute_context);
}
/**
@@ -246,7 +162,8 @@ class GeoNodeExecParams {
*/
void set_input_unused(StringRef identifier)
{
- provider_->set_input_unused(identifier);
+ const int index = this->get_input_index(identifier);
+ params_.set_input_unused(index);
}
/**
@@ -256,7 +173,8 @@ class GeoNodeExecParams {
*/
bool output_is_required(StringRef identifier) const
{
- return provider_->output_is_required(identifier);
+ const int index = this->get_output_index(identifier);
+ return params_.get_output_usage(index) != lf::ValueUsage::Unused;
}
/**
@@ -267,7 +185,8 @@ class GeoNodeExecParams {
*/
bool lazy_require_input(StringRef identifier)
{
- return provider_->lazy_require_input(identifier);
+ const int index = this->get_input_index(identifier);
+ return params_.try_get_input_data_ptr_or_request(index) == nullptr;
}
/**
@@ -277,7 +196,8 @@ class GeoNodeExecParams {
*/
bool lazy_output_is_required(StringRef identifier)
{
- return provider_->lazy_output_is_required(identifier);
+ const int index = this->get_output_index(identifier);
+ return params_.get_output_usage(index) == lf::ValueUsage::Used;
}
/**
@@ -285,30 +205,45 @@ class GeoNodeExecParams {
*/
const bNode &node() const
{
- return *provider_->dnode->bnode();
+ return node_;
}
const Object *self_object() const
{
- return provider_->self_object;
+ if (const auto *data = this->user_data()) {
+ if (data->modifier_data) {
+ return data->modifier_data->self_object;
+ }
+ }
+ return nullptr;
}
Depsgraph *depsgraph() const
{
- return provider_->depsgraph;
+ if (const auto *data = this->user_data()) {
+ if (data->modifier_data) {
+ return data->modifier_data->depsgraph;
+ }
+ }
+ return nullptr;
+ }
+
+ GeoNodesLFUserData *user_data() const
+ {
+ return dynamic_cast<GeoNodesLFUserData *>(lf_context_.user_data);
}
/**
* Add an error message displayed at the top of the node when displaying the node tree,
* and potentially elsewhere in Blender.
*/
- void error_message_add(const NodeWarningType type, std::string message) const;
+ void error_message_add(const NodeWarningType type, StringRef message) const;
std::string attribute_producer_name() const;
void set_default_remaining_outputs();
- void used_named_attribute(std::string attribute_name, eNamedAttrUsage usage);
+ void used_named_attribute(StringRef attribute_name, NamedAttributeUsage usage);
private:
/* Utilities for detecting common errors at when using this class. */
@@ -317,6 +252,38 @@ class GeoNodeExecParams {
/* Find the active socket with the input name (not the identifier). */
const bNodeSocket *find_available_socket(const StringRef name) const;
+
+ int get_input_index(const StringRef identifier) const
+ {
+ int counter = 0;
+ for (const bNodeSocket *socket : node_.input_sockets()) {
+ if (!socket->is_available()) {
+ continue;
+ }
+ if (socket->identifier == identifier) {
+ return counter;
+ }
+ counter++;
+ }
+ BLI_assert_unreachable();
+ return -1;
+ }
+
+ int get_output_index(const StringRef identifier) const
+ {
+ int counter = 0;
+ for (const bNodeSocket *socket : node_.output_sockets()) {
+ if (!socket->is_available()) {
+ continue;
+ }
+ if (socket->identifier == identifier) {
+ return counter;
+ }
+ counter++;
+ }
+ BLI_assert_unreachable();
+ return -1;
+ }
};
} // namespace blender::nodes
diff --git a/source/blender/nodes/NOD_geometry_nodes_eval_log.hh b/source/blender/nodes/NOD_geometry_nodes_eval_log.hh
deleted file mode 100644
index 46ba72d14d8..00000000000
--- a/source/blender/nodes/NOD_geometry_nodes_eval_log.hh
+++ /dev/null
@@ -1,411 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-
-#pragma once
-
-/**
- * Many geometry nodes related UI features need access to data produced during evaluation. Not only
- * is the final output required but also the intermediate results. Those features include
- * attribute search, node warnings, socket inspection and the viewer node.
- *
- * This file provides the framework for logging data during evaluation and accessing the data after
- * evaluation.
- *
- * During logging every thread gets its own local logger to avoid too much locking (logging
- * generally happens for every socket). After geometry nodes evaluation is done, the thread-local
- * logging information is combined and post-processed to make it easier for the UI to lookup.
- * necessary information.
- */
-
-#include "BLI_enumerable_thread_specific.hh"
-#include "BLI_function_ref.hh"
-#include "BLI_generic_pointer.hh"
-#include "BLI_linear_allocator.hh"
-#include "BLI_map.hh"
-
-#include "BKE_geometry_set.hh"
-
-#include "NOD_derived_node_tree.hh"
-
-#include "FN_field.hh"
-
-#include <chrono>
-
-struct SpaceNode;
-struct SpaceSpreadsheet;
-
-namespace blender::nodes::geometry_nodes_eval_log {
-
-/** Contains information about a value that has been computed during geometry nodes evaluation. */
-class ValueLog {
- public:
- virtual ~ValueLog() = default;
-};
-
-/** Contains an owned copy of a value of a generic type. */
-class GenericValueLog : public ValueLog {
- private:
- GMutablePointer data_;
-
- public:
- GenericValueLog(GMutablePointer data) : data_(data)
- {
- }
-
- ~GenericValueLog()
- {
- data_.destruct();
- }
-
- GPointer value() const
- {
- return data_;
- }
-};
-
-class GFieldValueLog : public ValueLog {
- private:
- fn::GField field_;
- const CPPType &type_;
- Vector<std::string> input_tooltips_;
-
- public:
- GFieldValueLog(fn::GField field, bool log_full_field);
-
- const fn::GField &field() const
- {
- return field_;
- }
-
- Span<std::string> input_tooltips() const
- {
- return input_tooltips_;
- }
-
- const CPPType &type() const
- {
- return type_;
- }
-};
-
-struct GeometryAttributeInfo {
- std::string name;
- /** Can be empty when #name does not actually exist on a geometry yet. */
- std::optional<eAttrDomain> domain;
- std::optional<eCustomDataType> data_type;
-};
-
-/** Contains information about a geometry set. In most cases this does not store the entire
- * geometry set as this would require too much memory. */
-class GeometryValueLog : public ValueLog {
- private:
- Vector<GeometryAttributeInfo> attributes_;
- Vector<GeometryComponentType> component_types_;
- std::unique_ptr<GeometrySet> full_geometry_;
-
- public:
- struct MeshInfo {
- int verts_num, edges_num, faces_num;
- };
- struct CurveInfo {
- int splines_num;
- };
- struct PointCloudInfo {
- int points_num;
- };
- struct InstancesInfo {
- int instances_num;
- };
- struct EditDataInfo {
- bool has_deformed_positions;
- bool has_deform_matrices;
- };
-
- std::optional<MeshInfo> mesh_info;
- std::optional<CurveInfo> curve_info;
- std::optional<PointCloudInfo> pointcloud_info;
- std::optional<InstancesInfo> instances_info;
- std::optional<EditDataInfo> edit_data_info;
-
- GeometryValueLog(const GeometrySet &geometry_set, bool log_full_geometry = false);
-
- Span<GeometryAttributeInfo> attributes() const
- {
- return attributes_;
- }
-
- Span<GeometryComponentType> component_types() const
- {
- return component_types_;
- }
-
- const GeometrySet *full_geometry() const
- {
- return full_geometry_.get();
- }
-};
-
-enum class NodeWarningType {
- Error,
- Warning,
- Info,
-};
-
-struct NodeWarning {
- NodeWarningType type;
- std::string message;
-};
-
-struct NodeWithWarning {
- DNode node;
- NodeWarning warning;
-};
-
-struct NodeWithExecutionTime {
- DNode node;
- std::chrono::microseconds exec_time;
-};
-
-struct NodeWithDebugMessage {
- DNode node;
- std::string message;
-};
-
-/** The same value can be referenced by multiple sockets when they are linked. */
-struct ValueOfSockets {
- Span<DSocket> sockets;
- destruct_ptr<ValueLog> value;
-};
-
-enum class eNamedAttrUsage {
- None = 0,
- Read = 1 << 0,
- Write = 1 << 1,
- Remove = 1 << 2,
-};
-ENUM_OPERATORS(eNamedAttrUsage, eNamedAttrUsage::Remove);
-
-struct UsedNamedAttribute {
- std::string name;
- eNamedAttrUsage usage;
-};
-
-struct NodeWithUsedNamedAttribute {
- DNode node;
- UsedNamedAttribute attribute;
-};
-
-class GeoLogger;
-class ModifierLog;
-
-/** Every thread has its own local logger to avoid having to communicate between threads during
- * evaluation. After evaluation the individual logs are combined. */
-class LocalGeoLogger {
- private:
- /* Back pointer to the owner of this local logger. */
- GeoLogger *main_logger_;
- /* Allocator for the many small allocations during logging. This is in a `unique_ptr` so that
- * ownership can be transferred later on. */
- std::unique_ptr<LinearAllocator<>> allocator_;
- Vector<ValueOfSockets> values_;
- Vector<NodeWithWarning> node_warnings_;
- Vector<NodeWithExecutionTime> node_exec_times_;
- Vector<NodeWithDebugMessage> node_debug_messages_;
- Vector<NodeWithUsedNamedAttribute> used_named_attributes_;
-
- friend ModifierLog;
-
- public:
- LocalGeoLogger(GeoLogger &main_logger) : main_logger_(&main_logger)
- {
- this->allocator_ = std::make_unique<LinearAllocator<>>();
- }
-
- void log_value_for_sockets(Span<DSocket> sockets, GPointer value);
- void log_multi_value_socket(DSocket socket, Span<GPointer> values);
- void log_node_warning(DNode node, NodeWarningType type, std::string message);
- void log_execution_time(DNode node, std::chrono::microseconds exec_time);
- void log_used_named_attribute(DNode node, std::string attribute_name, eNamedAttrUsage usage);
- /**
- * Log a message that will be displayed in the node editor next to the node.
- * This should only be used for debugging purposes and not to display information to users.
- */
- void log_debug_message(DNode node, std::string message);
-};
-
-/** The root logger class. */
-class GeoLogger {
- private:
- /**
- * Log the entire value for these sockets, because they may be inspected afterwards.
- * We don't log everything, because that would take up too much memory and cause significant
- * slowdowns.
- */
- Set<DSocket> log_full_sockets_;
- threading::EnumerableThreadSpecific<LocalGeoLogger> threadlocals_;
-
- /* These are only optional since they don't have a default constructor. */
- std::unique_ptr<GeometryValueLog> input_geometry_log_;
- std::unique_ptr<GeometryValueLog> output_geometry_log_;
-
- friend LocalGeoLogger;
- friend ModifierLog;
-
- public:
- GeoLogger(Set<DSocket> log_full_sockets)
- : log_full_sockets_(std::move(log_full_sockets)),
- threadlocals_([this]() { return LocalGeoLogger(*this); })
- {
- }
-
- void log_input_geometry(const GeometrySet &geometry)
- {
- input_geometry_log_ = std::make_unique<GeometryValueLog>(geometry);
- }
-
- void log_output_geometry(const GeometrySet &geometry)
- {
- output_geometry_log_ = std::make_unique<GeometryValueLog>(geometry);
- }
-
- LocalGeoLogger &local()
- {
- return threadlocals_.local();
- }
-
- auto begin()
- {
- return threadlocals_.begin();
- }
-
- auto end()
- {
- return threadlocals_.end();
- }
-};
-
-/** Contains information that has been logged for one specific socket. */
-class SocketLog {
- private:
- ValueLog *value_ = nullptr;
-
- friend ModifierLog;
-
- public:
- const ValueLog *value() const
- {
- return value_;
- }
-};
-
-/** Contains information that has been logged for one specific node. */
-class NodeLog {
- private:
- Vector<SocketLog> input_logs_;
- Vector<SocketLog> output_logs_;
- Vector<NodeWarning, 0> warnings_;
- Vector<std::string, 0> debug_messages_;
- Vector<UsedNamedAttribute, 0> used_named_attributes_;
- std::chrono::microseconds exec_time_;
-
- friend ModifierLog;
-
- public:
- const SocketLog *lookup_socket_log(eNodeSocketInOut in_out, int index) const;
- const SocketLog *lookup_socket_log(const bNode &node, const bNodeSocket &socket) const;
- void execution_time(std::chrono::microseconds exec_time);
-
- Span<SocketLog> input_logs() const
- {
- return input_logs_;
- }
-
- Span<SocketLog> output_logs() const
- {
- return output_logs_;
- }
-
- Span<NodeWarning> warnings() const
- {
- return warnings_;
- }
-
- Span<std::string> debug_messages() const
- {
- return debug_messages_;
- }
-
- Span<UsedNamedAttribute> used_named_attributes() const
- {
- return used_named_attributes_;
- }
-
- std::chrono::microseconds execution_time() const
- {
- return exec_time_;
- }
-
- Vector<const GeometryAttributeInfo *> lookup_available_attributes() const;
-};
-
-/** Contains information that has been logged for one specific tree. */
-class TreeLog {
- private:
- Map<std::string, destruct_ptr<NodeLog>> node_logs_;
- Map<std::string, destruct_ptr<TreeLog>> child_logs_;
-
- friend ModifierLog;
-
- public:
- const NodeLog *lookup_node_log(StringRef node_name) const;
- const NodeLog *lookup_node_log(const bNode &node) const;
- const TreeLog *lookup_child_log(StringRef node_name) const;
- void foreach_node_log(FunctionRef<void(const NodeLog &)> fn) const;
-};
-
-/** Contains information about an entire geometry nodes evaluation. */
-class ModifierLog {
- private:
- LinearAllocator<> allocator_;
- /* Allocators of the individual loggers. */
- Vector<std::unique_ptr<LinearAllocator<>>> logger_allocators_;
- destruct_ptr<TreeLog> root_tree_logs_;
- Vector<destruct_ptr<ValueLog>> logged_values_;
-
- std::unique_ptr<GeometryValueLog> input_geometry_log_;
- std::unique_ptr<GeometryValueLog> output_geometry_log_;
-
- public:
- ModifierLog(GeoLogger &logger);
-
- const TreeLog &root_tree() const
- {
- return *root_tree_logs_;
- }
-
- /* Utilities to find logged information for a specific context. */
- static const ModifierLog *find_root_by_node_editor_context(const SpaceNode &snode);
- static const TreeLog *find_tree_by_node_editor_context(const SpaceNode &snode);
- static const NodeLog *find_node_by_node_editor_context(const SpaceNode &snode,
- const bNode &node);
- static const NodeLog *find_node_by_node_editor_context(const SpaceNode &snode,
- const StringRef node_name);
- static const SocketLog *find_socket_by_node_editor_context(const SpaceNode &snode,
- const bNode &node,
- const bNodeSocket &socket);
- static const NodeLog *find_node_by_spreadsheet_editor_context(
- const SpaceSpreadsheet &sspreadsheet);
- void foreach_node_log(FunctionRef<void(const NodeLog &)> fn) const;
-
- const GeometryValueLog *input_geometry_log() const;
- const GeometryValueLog *output_geometry_log() const;
-
- private:
- using LogByTreeContext = Map<const DTreeContext *, TreeLog *>;
-
- TreeLog &lookup_or_add_tree_log(LogByTreeContext &log_by_tree_context,
- const DTreeContext &tree_context);
- NodeLog &lookup_or_add_node_log(LogByTreeContext &log_by_tree_context, DNode node);
- SocketLog &lookup_or_add_socket_log(LogByTreeContext &log_by_tree_context, DSocket socket);
-};
-
-} // namespace blender::nodes::geometry_nodes_eval_log
diff --git a/source/blender/nodes/NOD_geometry_nodes_lazy_function.hh b/source/blender/nodes/NOD_geometry_nodes_lazy_function.hh
new file mode 100644
index 00000000000..240a0115f68
--- /dev/null
+++ b/source/blender/nodes/NOD_geometry_nodes_lazy_function.hh
@@ -0,0 +1,181 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#pragma once
+
+/**
+ * For evaluation, geometry node groups are converted to a lazy-function graph. The generated graph
+ * is cached per node group, so it only has to be generated once after a change.
+ *
+ * Node groups are *not* inlined into the lazy-function graph. This could be added in the future as
+ * it might improve performance in some cases, but generally does not seem necessary. Inlining node
+ * groups also has disadvantages like making per-node-group caches less useful, resulting in more
+ * overhead.
+ *
+ * Instead, group nodes are just like all other nodes in the lazy-function graph. What makes them
+ * special is that they reference the lazy-function graph of the group they reference.
+ *
+ * During lazy-function graph generation, a mapping between the #bNodeTree and
+ * #lazy_function::Graph is build that can be used when evaluating the graph (e.g. for logging).
+ */
+
+#include "FN_lazy_function_graph.hh"
+#include "FN_lazy_function_graph_executor.hh"
+
+#include "NOD_geometry_nodes_log.hh"
+#include "NOD_multi_function.hh"
+
+#include "BLI_compute_context.hh"
+
+struct Object;
+struct Depsgraph;
+
+namespace blender::nodes {
+
+namespace lf = fn::lazy_function;
+using lf::LazyFunction;
+
+/**
+ * Data that is passed into geometry nodes evaluation from the modifier.
+ */
+struct GeoNodesModifierData {
+ /** Object that is currently evaluated. */
+ const Object *self_object = nullptr;
+ /** Depsgraph that is evaluating the modifier. */
+ Depsgraph *depsgraph = nullptr;
+ /** Optional logger. */
+ geo_eval_log::GeoModifierLog *eval_log = nullptr;
+ /**
+ * Some nodes should be executed even when their output is not used (e.g. active viewer nodes and
+ * the node groups they are contained in).
+ */
+ const MultiValueMap<ComputeContextHash, const lf::FunctionNode *> *side_effect_nodes;
+};
+
+/**
+ * Custom user data that is passed to every geometry nodes related lazy-function evaluation.
+ */
+struct GeoNodesLFUserData : public lf::UserData {
+ /**
+ * Data from the modifier that is being evaluated.
+ */
+ GeoNodesModifierData *modifier_data = nullptr;
+ /**
+ * Current compute context. This is different depending in the (nested) node group that is being
+ * evaluated.
+ */
+ const ComputeContext *compute_context = nullptr;
+};
+
+/**
+ * Contains the mapping between the #bNodeTree and the corresponding lazy-function graph.
+ * This is *not* a one-to-one mapping.
+ */
+struct GeometryNodeLazyFunctionGraphMapping {
+ /**
+ * Contains mapping of sockets for special nodes like group input and group output.
+ */
+ Map<const bNodeSocket *, lf::Socket *> dummy_socket_map;
+ /**
+ * The inputs sockets in the graph. Multiple group input nodes are combined into one in the
+ * lazy-function graph.
+ */
+ Vector<lf::OutputSocket *> group_input_sockets;
+ /**
+ * A mapping used for logging intermediate values.
+ */
+ MultiValueMap<const lf::Socket *, const bNodeSocket *> bsockets_by_lf_socket_map;
+ /**
+ * Mappings for some special node types. Generally, this mapping does not exist for all node
+ * types, so better have more specialized mappings for now.
+ */
+ Map<const bNode *, const lf::FunctionNode *> group_node_map;
+ Map<const bNode *, const lf::FunctionNode *> viewer_node_map;
+};
+
+/**
+ * Data that is cached for every #bNodeTree.
+ */
+struct GeometryNodesLazyFunctionGraphInfo {
+ /**
+ * Allocator used for many things contained in this struct.
+ */
+ LinearAllocator<> allocator;
+ /**
+ * Many nodes are implemented as multi-functions. So this contains a mapping from nodes to their
+ * corresponding multi-functions.
+ */
+ std::unique_ptr<NodeMultiFunctions> node_multi_functions;
+ /**
+ * Many lazy-functions are build for the lazy-function graph. Since the graph does not own them,
+ * we have to keep track of them separately.
+ */
+ Vector<std::unique_ptr<LazyFunction>> functions;
+ /**
+ * Many sockets have default values. Since those are not owned by the lazy-function graph, we
+ * have to keep track of them separately. This only owns the values, the memory is owned by the
+ * allocator above.
+ */
+ Vector<GMutablePointer> values_to_destruct;
+ /**
+ * The actual lazy-function graph.
+ */
+ lf::Graph graph;
+ /**
+ * Mappings between the lazy-function graph and the #bNodeTree.
+ */
+ GeometryNodeLazyFunctionGraphMapping mapping;
+ /**
+ * Approximate number of nodes in the graph if all sub-graphs were inlined.
+ * This can be used as a simple heuristic for the complexity of the node group.
+ */
+ int num_inline_nodes_approximate = 0;
+
+ GeometryNodesLazyFunctionGraphInfo();
+ ~GeometryNodesLazyFunctionGraphInfo();
+};
+
+/**
+ * Logs intermediate values from the lazy-function graph evaluation into #GeoModifierLog based on
+ * the mapping between the lazy-function graph and the corresponding #bNodeTree.
+ */
+class GeometryNodesLazyFunctionLogger : public fn::lazy_function::GraphExecutor::Logger {
+ private:
+ const GeometryNodesLazyFunctionGraphInfo &lf_graph_info_;
+
+ public:
+ GeometryNodesLazyFunctionLogger(const GeometryNodesLazyFunctionGraphInfo &lf_graph_info);
+ void log_socket_value(const fn::lazy_function::Socket &lf_socket,
+ GPointer value,
+ const fn::lazy_function::Context &context) const override;
+ void dump_when_outputs_are_missing(const lf::FunctionNode &node,
+ Span<const lf::OutputSocket *> missing_sockets,
+ const lf::Context &context) const override;
+ void dump_when_input_is_set_twice(const lf::InputSocket &target_socket,
+ const lf::OutputSocket &from_socket,
+ const lf::Context &context) const override;
+ void log_before_node_execute(const lf::FunctionNode &node,
+ const lf::Params &params,
+ const lf::Context &context) const override;
+};
+
+/**
+ * Tells the lazy-function graph evaluator which nodes have side effects based on the current
+ * context. For example, the same viewer node can have side effects in one context, but not in
+ * another (depending on e.g. which tree path is currently viewed in the node editor).
+ */
+class GeometryNodesLazyFunctionSideEffectProvider
+ : public fn::lazy_function::GraphExecutor::SideEffectProvider {
+ public:
+ Vector<const lf::FunctionNode *> get_nodes_with_side_effects(
+ const lf::Context &context) const override;
+};
+
+/**
+ * Main function that converts a #bNodeTree into a lazy-function graph. If the graph has been
+ * generated already, nothing is done. Under some circumstances a valid graph cannot be created. In
+ * those cases null is returned.
+ */
+const GeometryNodesLazyFunctionGraphInfo *ensure_geometry_nodes_lazy_function_graph(
+ const bNodeTree &btree);
+
+} // namespace blender::nodes
diff --git a/source/blender/nodes/NOD_geometry_nodes_log.hh b/source/blender/nodes/NOD_geometry_nodes_log.hh
new file mode 100644
index 00000000000..5a2203a76b7
--- /dev/null
+++ b/source/blender/nodes/NOD_geometry_nodes_log.hh
@@ -0,0 +1,339 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#pragma once
+
+/**
+ * Many geometry nodes related UI features need access to data produced during evaluation. Not only
+ * is the final output required but also the intermediate results. Those features include attribute
+ * search, node warnings, socket inspection and the viewer node.
+ *
+ * This file provides the system for logging data during evaluation and accessing the data after
+ * evaluation. Geometry nodes is executed by a modifier, therefore the "root" of logging is
+ * #GeoModifierLog which will contain all data generated in a modifier.
+ *
+ * The system makes a distinction between "loggers" and the "log":
+ * - Logger (#GeoTreeLogger): Is used during geometry nodes evaluation. Each thread logs data
+ * independently to avoid communication between threads. Logging should generally be fast.
+ * Generally, the logged data is just dumped into simple containers. Any processing of the data
+ * happens later if necessary. This is important for performance, because in practice, most of
+ * the logged data is never used again. So any processing of the data is likely to be a waste of
+ * resources.
+ * - Log (#GeoTreeLog, #GeoNodeLog): Those are used when accessing logged data in UI code. They
+ * contain and cache preprocessed data produced during logging. The log combines data from all
+ * thread-local loggers to provide simple access. Importantly, the (preprocessed) log is only
+ * created when it is actually used by UI code.
+ */
+
+#include <chrono>
+
+#include "BLI_compute_context.hh"
+#include "BLI_enumerable_thread_specific.hh"
+#include "BLI_generic_pointer.hh"
+#include "BLI_multi_value_map.hh"
+
+#include "BKE_attribute.h"
+#include "BKE_geometry_set.hh"
+#include "BKE_viewer_path.h"
+
+#include "FN_field.hh"
+
+#include "DNA_node_types.h"
+
+struct SpaceNode;
+struct SpaceSpreadsheet;
+struct NodesModifierData;
+
+namespace blender::nodes::geo_eval_log {
+
+using fn::GField;
+
+enum class NodeWarningType {
+ Error,
+ Warning,
+ Info,
+};
+
+struct NodeWarning {
+ NodeWarningType type;
+ std::string message;
+};
+
+enum class NamedAttributeUsage {
+ None = 0,
+ Read = 1 << 0,
+ Write = 1 << 1,
+ Remove = 1 << 2,
+};
+ENUM_OPERATORS(NamedAttributeUsage, NamedAttributeUsage::Remove);
+
+/**
+ * Values of different types are logged differently. This is necessary because some types are so
+ * simple that we can log them entirely (e.g. `int`), while we don't want to log all intermediate
+ * geometries in their entirety.
+ *
+ * #ValueLog is a base class for the different ways we log values.
+ */
+class ValueLog {
+ public:
+ virtual ~ValueLog() = default;
+};
+
+/**
+ * Simplest logger. It just stores a copy of the entire value. This is used for most simple types
+ * like `int`.
+ */
+class GenericValueLog : public ValueLog {
+ public:
+ /**
+ * This is owning the value, but not the memory.
+ */
+ GMutablePointer value;
+
+ GenericValueLog(const GMutablePointer value) : value(value)
+ {
+ }
+
+ ~GenericValueLog();
+};
+
+/**
+ * Fields are not logged entirely, because they might contain arbitrarily large data (e.g.
+ * geometries that are sampled). Instead, only the data needed for UI features is logged.
+ */
+class FieldInfoLog : public ValueLog {
+ public:
+ const CPPType &type;
+ Vector<std::string> input_tooltips;
+
+ FieldInfoLog(const GField &field);
+};
+
+struct GeometryAttributeInfo {
+ std::string name;
+ /** Can be empty when #name does not actually exist on a geometry yet. */
+ std::optional<eAttrDomain> domain;
+ std::optional<eCustomDataType> data_type;
+};
+
+/**
+ * Geometries are not logged entirely, because that would result in a lot of time and memory
+ * overhead. Instead, only the data needed for UI features is logged.
+ */
+class GeometryInfoLog : public ValueLog {
+ public:
+ Vector<GeometryAttributeInfo> attributes;
+ Vector<GeometryComponentType> component_types;
+
+ struct MeshInfo {
+ int verts_num, edges_num, faces_num;
+ };
+ struct CurveInfo {
+ int splines_num;
+ };
+ struct PointCloudInfo {
+ int points_num;
+ };
+ struct InstancesInfo {
+ int instances_num;
+ };
+ struct EditDataInfo {
+ bool has_deformed_positions;
+ bool has_deform_matrices;
+ };
+
+ std::optional<MeshInfo> mesh_info;
+ std::optional<CurveInfo> curve_info;
+ std::optional<PointCloudInfo> pointcloud_info;
+ std::optional<InstancesInfo> instances_info;
+ std::optional<EditDataInfo> edit_data_info;
+
+ GeometryInfoLog(const GeometrySet &geometry_set);
+};
+
+/**
+ * Data logged by a viewer node when it is executed. In this case, we do want to log the entire
+ * geometry.
+ */
+class ViewerNodeLog {
+ public:
+ GeometrySet geometry;
+};
+
+using Clock = std::chrono::steady_clock;
+using TimePoint = Clock::time_point;
+
+/**
+ * Logs all data for a specific geometry node tree in a specific context. When the same node group
+ * is used in multiple times each instantiation will have a separate logger.
+ */
+class GeoTreeLogger {
+ public:
+ std::optional<ComputeContextHash> parent_hash;
+ std::optional<std::string> group_node_name;
+ Vector<ComputeContextHash> children_hashes;
+
+ LinearAllocator<> *allocator = nullptr;
+
+ struct WarningWithNode {
+ StringRefNull node_name;
+ NodeWarning warning;
+ };
+ struct SocketValueLog {
+ StringRefNull node_name;
+ StringRefNull socket_identifier;
+ destruct_ptr<ValueLog> value;
+ };
+ struct NodeExecutionTime {
+ StringRefNull node_name;
+ TimePoint start;
+ TimePoint end;
+ };
+ struct ViewerNodeLogWithNode {
+ StringRefNull node_name;
+ destruct_ptr<ViewerNodeLog> viewer_log;
+ };
+ struct AttributeUsageWithNode {
+ StringRefNull node_name;
+ StringRefNull attribute_name;
+ NamedAttributeUsage usage;
+ };
+ struct DebugMessage {
+ StringRefNull node_name;
+ StringRefNull message;
+ };
+
+ Vector<WarningWithNode> node_warnings;
+ Vector<SocketValueLog> input_socket_values;
+ Vector<SocketValueLog> output_socket_values;
+ Vector<NodeExecutionTime> node_execution_times;
+ Vector<ViewerNodeLogWithNode, 0> viewer_node_logs;
+ Vector<AttributeUsageWithNode, 0> used_named_attributes;
+ Vector<DebugMessage, 0> debug_messages;
+
+ GeoTreeLogger();
+ ~GeoTreeLogger();
+
+ void log_value(const bNode &node, const bNodeSocket &socket, GPointer value);
+ void log_viewer_node(const bNode &viewer_node, GeometrySet geometry);
+};
+
+/**
+ * Contains data that has been logged for a specific node in a context. So when the node is in a
+ * node group that is used multiple times, there will be a different #GeoNodeLog for every
+ * instance.
+ *
+ * By default, not all of the info below is valid. A #GeoTreeLog::ensure_* method has to be called
+ * first.
+ */
+class GeoNodeLog {
+ public:
+ /** Warnings generated for that node. */
+ Vector<NodeWarning> warnings;
+ /**
+ * Time spend in that node. For node groups this is the sum of the run times of the nodes
+ * inside.
+ */
+ std::chrono::nanoseconds run_time{0};
+ /** Maps from socket identifiers to their values. */
+ Map<StringRefNull, ValueLog *> input_values_;
+ Map<StringRefNull, ValueLog *> output_values_;
+ /** Maps from attribute name to their usage flags. */
+ Map<StringRefNull, NamedAttributeUsage> used_named_attributes;
+ /** Messages that are used for debugging purposes during development. */
+ Vector<StringRefNull> debug_messages;
+
+ GeoNodeLog();
+ ~GeoNodeLog();
+};
+
+class GeoModifierLog;
+
+/**
+ * Contains data that has been logged for a specific node group in a context. If the same node
+ * group is used multiple times, there will be a different #GeoTreeLog for every instance.
+ *
+ * This contains lazily evaluated data. Call the corresponding `ensure_*` methods before accessing
+ * data.
+ */
+class GeoTreeLog {
+ private:
+ GeoModifierLog *modifier_log_;
+ Vector<GeoTreeLogger *> tree_loggers_;
+ VectorSet<ComputeContextHash> children_hashes_;
+ bool reduced_node_warnings_ = false;
+ bool reduced_node_run_times_ = false;
+ bool reduced_socket_values_ = false;
+ bool reduced_viewer_node_logs_ = false;
+ bool reduced_existing_attributes_ = false;
+ bool reduced_used_named_attributes_ = false;
+ bool reduced_debug_messages_ = false;
+
+ public:
+ Map<StringRefNull, GeoNodeLog> nodes;
+ Map<StringRefNull, ViewerNodeLog *, 0> viewer_node_logs;
+ Vector<NodeWarning> all_warnings;
+ std::chrono::nanoseconds run_time_sum{0};
+ Vector<const GeometryAttributeInfo *> existing_attributes;
+ Map<StringRefNull, NamedAttributeUsage> used_named_attributes;
+
+ GeoTreeLog(GeoModifierLog *modifier_log, Vector<GeoTreeLogger *> tree_loggers);
+ ~GeoTreeLog();
+
+ void ensure_node_warnings();
+ void ensure_node_run_time();
+ void ensure_socket_values();
+ void ensure_viewer_node_logs();
+ void ensure_existing_attributes();
+ void ensure_used_named_attributes();
+ void ensure_debug_messages();
+
+ ValueLog *find_socket_value_log(const bNodeSocket &query_socket);
+};
+
+/**
+ * There is one #GeoModifierLog for every modifier that evaluates geometry nodes. It contains all
+ * the loggers that are used during evaluation as well as the preprocessed logs that are used by UI
+ * code.
+ */
+class GeoModifierLog {
+ private:
+ /** Data that is stored for each thread. */
+ struct LocalData {
+ /** Each thread has its own allocator. */
+ LinearAllocator<> allocator;
+ /**
+ * Store a separate #GeoTreeLogger for each instance of the corresponding node group (e.g.
+ * when the same node group is used multiple times).
+ */
+ Map<ComputeContextHash, destruct_ptr<GeoTreeLogger>> tree_logger_by_context;
+ };
+
+ /** Container for all thread-local data. */
+ threading::EnumerableThreadSpecific<LocalData> data_per_thread_;
+ /**
+ * A #GeoTreeLog for every compute context. Those are created lazily when requested by UI code.
+ */
+ Map<ComputeContextHash, std::unique_ptr<GeoTreeLog>> tree_logs_;
+
+ public:
+ GeoModifierLog();
+ ~GeoModifierLog();
+
+ /**
+ * Get a thread-local logger for the current node tree.
+ */
+ GeoTreeLogger &get_local_tree_logger(const ComputeContext &compute_context);
+
+ /**
+ * Get a log a specific node tree instance.
+ */
+ GeoTreeLog &get_tree_log(const ComputeContextHash &compute_context_hash);
+
+ /**
+ * Utility accessor to logged data.
+ */
+ static GeoTreeLog *get_tree_log_for_node_editor(const SpaceNode &snode);
+ static const ViewerNodeLog *find_viewer_node_log_for_path(const ViewerPath &viewer_path);
+};
+
+} // namespace blender::nodes::geo_eval_log
diff --git a/source/blender/nodes/NOD_multi_function.hh b/source/blender/nodes/NOD_multi_function.hh
index b6d51578b1c..676bf03927e 100644
--- a/source/blender/nodes/NOD_multi_function.hh
+++ b/source/blender/nodes/NOD_multi_function.hh
@@ -6,8 +6,6 @@
#include "DNA_node_types.h"
-#include "NOD_derived_node_tree.hh"
-
namespace blender::nodes {
using namespace fn::multi_function_types;
@@ -19,15 +17,15 @@ class NodeMultiFunctions;
*/
class NodeMultiFunctionBuilder : NonCopyable, NonMovable {
private:
- bNode &node_;
- bNodeTree &tree_;
+ const bNode &node_;
+ const bNodeTree &tree_;
std::shared_ptr<MultiFunction> owned_built_fn_;
const MultiFunction *built_fn_ = nullptr;
friend NodeMultiFunctions;
public:
- NodeMultiFunctionBuilder(bNode &node, bNodeTree &tree);
+ NodeMultiFunctionBuilder(const bNode &node, const bNodeTree &tree);
/**
* Assign a multi-function for the current node. The input and output parameters of the function
@@ -42,8 +40,8 @@ class NodeMultiFunctionBuilder : NonCopyable, NonMovable {
*/
template<typename T, typename... Args> void construct_and_set_matching_fn(Args &&...args);
- bNode &node();
- bNodeTree &tree();
+ const bNode &node();
+ const bNodeTree &tree();
};
/**
@@ -60,26 +58,26 @@ class NodeMultiFunctions {
Map<const bNode *, Item> map_;
public:
- NodeMultiFunctions(const DerivedNodeTree &tree);
+ NodeMultiFunctions(const bNodeTree &tree);
- const Item &try_get(const DNode &node) const;
+ const Item &try_get(const bNode &node) const;
};
/* -------------------------------------------------------------------- */
/** \name #NodeMultiFunctionBuilder Inline Methods
* \{ */
-inline NodeMultiFunctionBuilder::NodeMultiFunctionBuilder(bNode &node, bNodeTree &tree)
+inline NodeMultiFunctionBuilder::NodeMultiFunctionBuilder(const bNode &node, const bNodeTree &tree)
: node_(node), tree_(tree)
{
}
-inline bNode &NodeMultiFunctionBuilder::node()
+inline const bNode &NodeMultiFunctionBuilder::node()
{
return node_;
}
-inline bNodeTree &NodeMultiFunctionBuilder::tree()
+inline const bNodeTree &NodeMultiFunctionBuilder::tree()
{
return tree_;
}
@@ -107,10 +105,10 @@ inline void NodeMultiFunctionBuilder::construct_and_set_matching_fn(Args &&...ar
/** \name #NodeMultiFunctions Inline Methods
* \{ */
-inline const NodeMultiFunctions::Item &NodeMultiFunctions::try_get(const DNode &node) const
+inline const NodeMultiFunctions::Item &NodeMultiFunctions::try_get(const bNode &node) const
{
static Item empty_item;
- const Item *item = map_.lookup_ptr(node->bnode());
+ const Item *item = map_.lookup_ptr(&node);
if (item == nullptr) {
return empty_item;
}
diff --git a/source/blender/nodes/NOD_node_declaration.hh b/source/blender/nodes/NOD_node_declaration.hh
index 4e78f6c1142..13f8af4ddf5 100644
--- a/source/blender/nodes/NOD_node_declaration.hh
+++ b/source/blender/nodes/NOD_node_declaration.hh
@@ -65,6 +65,8 @@ struct FieldInferencingInterface {
Vector<OutputFieldDependency> outputs;
};
+using ImplicitInputValueFn = std::function<void(const bNode &node, void *r_value)>;
+
/**
* Describes a single input or output socket. This is subclassed for different socket types.
*/
@@ -88,9 +90,25 @@ class SocketDeclaration {
InputSocketFieldType input_field_type_ = InputSocketFieldType::None;
OutputFieldDependency output_field_dependency_;
+ /** The priority of the input for determining the domain of the node. See
+ * realtime_compositor::InputDescriptor for more information. */
+ int compositor_domain_priority_ = 0;
+
+ /** This input shouldn't be realized on the operation domain of the node. See
+ * realtime_compositor::InputDescriptor for more information. */
+ bool compositor_skip_realization_ = false;
+
+ /** This input expects a single value and can't operate on non-single values. See
+ * realtime_compositor::InputDescriptor for more information. */
+ bool compositor_expects_single_value_ = false;
+
/** Utility method to make the socket available if there is a straightforward way to do so. */
std::function<void(bNode &)> make_available_fn_;
+ /** Some input sockets can have non-trivial values in the case when they are unlinked. This
+ * callback computes the default input of a values in geometry nodes when nothing is linked. */
+ std::unique_ptr<ImplicitInputValueFn> implicit_input_fn_;
+
friend NodeDeclarationBuilder;
template<typename SocketDecl> friend class SocketDeclarationBuilder;
@@ -124,6 +142,15 @@ class SocketDeclaration {
InputSocketFieldType input_field_type() const;
const OutputFieldDependency &output_field_dependency() const;
+ int compositor_domain_priority() const;
+ bool compositor_skip_realization() const;
+ bool compositor_expects_single_value() const;
+
+ const ImplicitInputValueFn *implicit_input_fn() const
+ {
+ return implicit_input_fn_.get();
+ }
+
protected:
void set_common_flags(bNodeSocket &socket) const;
bool matches_common_data(const bNodeSocket &socket) const;
@@ -209,10 +236,11 @@ class SocketDeclarationBuilder : public BaseSocketDeclarationBuilder {
}
/** The input supports a field and is a field by default when nothing is connected. */
- Self &implicit_field()
+ Self &implicit_field(ImplicitInputValueFn fn)
{
this->hide_value();
decl_->input_field_type_ = InputSocketFieldType::Implicit;
+ decl_->implicit_input_fn_ = std::make_unique<ImplicitInputValueFn>(std::move(fn));
return *(Self *)this;
}
@@ -238,6 +266,30 @@ class SocketDeclarationBuilder : public BaseSocketDeclarationBuilder {
return *(Self *)this;
}
+ /** The priority of the input for determining the domain of the node. See
+ * realtime_compositor::InputDescriptor for more information. */
+ Self &compositor_domain_priority(int priority)
+ {
+ decl_->compositor_domain_priority_ = priority;
+ return *(Self *)this;
+ }
+
+ /** This input shouldn't be realized on the operation domain of the node. See
+ * realtime_compositor::InputDescriptor for more information. */
+ Self &compositor_skip_realization(bool value = true)
+ {
+ decl_->compositor_skip_realization_ = value;
+ return *(Self *)this;
+ }
+
+ /** This input expects a single value and can't operate on non-single values. See
+ * realtime_compositor::InputDescriptor for more information. */
+ Self &compositor_expects_single_value(bool value = true)
+ {
+ decl_->compositor_expects_single_value_ = value;
+ return *(Self *)this;
+ }
+
/**
* Pass a function that sets properties on the node required to make the corresponding socket
* available, if it is not available on the default state of the node. The function is allowed to
@@ -308,6 +360,13 @@ class NodeDeclarationBuilder {
eNodeSocketInOut in_out);
};
+namespace implicit_field_inputs {
+void position(const bNode &node, void *r_value);
+void normal(const bNode &node, void *r_value);
+void index(const bNode &node, void *r_value);
+void id_or_index(const bNode &node, void *r_value);
+} // namespace implicit_field_inputs
+
/* -------------------------------------------------------------------- */
/** \name #OutputFieldDependency Inline Methods
* \{ */
@@ -428,6 +487,21 @@ inline const OutputFieldDependency &SocketDeclaration::output_field_dependency()
return output_field_dependency_;
}
+inline int SocketDeclaration::compositor_domain_priority() const
+{
+ return compositor_domain_priority_;
+}
+
+inline bool SocketDeclaration::compositor_skip_realization() const
+{
+ return compositor_skip_realization_;
+}
+
+inline bool SocketDeclaration::compositor_expects_single_value() const
+{
+ return compositor_expects_single_value_;
+}
+
inline void SocketDeclaration::make_available(bNode &node) const
{
if (make_available_fn_) {
diff --git a/source/blender/nodes/NOD_node_tree_ref.hh b/source/blender/nodes/NOD_node_tree_ref.hh
deleted file mode 100644
index 257aa5f4110..00000000000
--- a/source/blender/nodes/NOD_node_tree_ref.hh
+++ /dev/null
@@ -1,760 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-
-#pragma once
-
-/** \file
- * \ingroup nodes
- *
- * NodeTreeRef makes querying information about a bNodeTree more efficient. It is an immutable data
- * structure. It should not be used after anymore, after the underlying node tree changed.
- *
- * The following queries are supported efficiently:
- * - socket -> index of socket
- * - socket -> directly linked sockets
- * - socket -> directly linked links
- * - socket -> linked sockets when skipping reroutes
- * - socket -> node
- * - socket/node -> rna pointer
- * - node -> inputs/outputs
- * - node -> tree
- * - tree -> all nodes
- * - tree -> all (input/output) sockets
- * - idname -> nodes
- *
- * Every socket has an id. The id-space is shared between input and output sockets.
- * When storing data per socket, it is often better to use the id as index into an array, instead
- * of a hash table.
- *
- * Every node has an id as well. The same rule regarding hash tables applies.
- *
- * There is an utility to export this data structure as graph in dot format.
- */
-
-#include "BLI_array.hh"
-#include "BLI_function_ref.hh"
-#include "BLI_linear_allocator.hh"
-#include "BLI_map.hh"
-#include "BLI_multi_value_map.hh"
-#include "BLI_string_ref.hh"
-#include "BLI_timeit.hh"
-#include "BLI_utility_mixins.hh"
-#include "BLI_vector.hh"
-
-#include "BKE_node.h"
-#include "BKE_node_runtime.hh"
-
-#include "DNA_node_types.h"
-
-#include "RNA_access.h"
-
-namespace blender::nodes {
-
-class SocketRef;
-class InputSocketRef;
-class OutputSocketRef;
-class NodeRef;
-class NodeTreeRef;
-class LinkRef;
-class InternalLinkRef;
-
-using SocketIndexByIdentifierMap = Map<std::string, int>;
-
-class SocketRef : NonCopyable, NonMovable {
- protected:
- NodeRef *node_;
- bNodeSocket *bsocket_;
- bool is_input_;
- int id_;
- int index_;
- Vector<LinkRef *> directly_linked_links_;
-
- /* These sockets are linked directly, i.e. with a single link in between. */
- MutableSpan<const SocketRef *> directly_linked_sockets_;
- /* These sockets are linked when reroutes, muted links and muted nodes have been taken into
- * account. */
- MutableSpan<const SocketRef *> logically_linked_sockets_;
- /* These are the sockets that have been skipped when searching for logically linked sockets.
- * That includes for example the input and output socket of an intermediate reroute node. */
- MutableSpan<const SocketRef *> logically_linked_skipped_sockets_;
-
- friend NodeTreeRef;
-
- public:
- Span<const SocketRef *> logically_linked_sockets() const;
- Span<const SocketRef *> logically_linked_skipped_sockets() const;
- Span<const SocketRef *> directly_linked_sockets() const;
- Span<const LinkRef *> directly_linked_links() const;
-
- bool is_directly_linked() const;
- bool is_logically_linked() const;
-
- const NodeRef &node() const;
- const NodeTreeRef &tree() const;
-
- int id() const;
- int index() const;
-
- bool is_input() const;
- bool is_output() const;
-
- const SocketRef &as_base() const;
- const InputSocketRef &as_input() const;
- const OutputSocketRef &as_output() const;
-
- PointerRNA rna() const;
-
- StringRefNull idname() const;
- StringRefNull name() const;
- StringRefNull identifier() const;
- bNodeSocketType *typeinfo() const;
-
- bNodeSocket *bsocket() const;
- bNode *bnode() const;
- bNodeTree *btree() const;
-
- bool is_available() const;
- bool is_undefined() const;
-
- void *default_value() const;
- template<typename T> T *default_value() const;
-};
-
-class InputSocketRef final : public SocketRef {
- public:
- friend NodeTreeRef;
-
- Span<const OutputSocketRef *> logically_linked_sockets() const;
- Span<const OutputSocketRef *> directly_linked_sockets() const;
-
- bool is_multi_input_socket() const;
-
- private:
- void foreach_logical_origin(FunctionRef<void(const OutputSocketRef &)> origin_fn,
- FunctionRef<void(const SocketRef &)> skipped_fn,
- bool only_follow_first_input_link,
- Vector<const InputSocketRef *> &seen_sockets_stack) const;
-};
-
-class OutputSocketRef final : public SocketRef {
- public:
- friend NodeTreeRef;
-
- Span<const InputSocketRef *> logically_linked_sockets() const;
- Span<const InputSocketRef *> directly_linked_sockets() const;
-
- private:
- void foreach_logical_target(FunctionRef<void(const InputSocketRef &)> target_fn,
- FunctionRef<void(const SocketRef &)> skipped_fn,
- Vector<const OutputSocketRef *> &seen_sockets_stack) const;
-};
-
-class NodeRef : NonCopyable, NonMovable {
- private:
- NodeTreeRef *tree_;
- bNode *bnode_;
- int id_;
- Vector<InputSocketRef *> inputs_;
- Vector<OutputSocketRef *> outputs_;
- Vector<InternalLinkRef *> internal_links_;
- SocketIndexByIdentifierMap *input_index_by_identifier_;
- SocketIndexByIdentifierMap *output_index_by_identifier_;
-
- friend NodeTreeRef;
-
- public:
- const NodeTreeRef &tree() const;
-
- Span<const InputSocketRef *> inputs() const;
- Span<const OutputSocketRef *> outputs() const;
- Span<const InternalLinkRef *> internal_links() const;
- Span<const SocketRef *> sockets(eNodeSocketInOut in_out) const;
-
- const InputSocketRef &input(int index) const;
- const OutputSocketRef &output(int index) const;
-
- const InputSocketRef &input_by_identifier(StringRef identifier) const;
- const OutputSocketRef &output_by_identifier(StringRef identifier) const;
-
- bool any_input_is_directly_linked() const;
- bool any_output_is_directly_linked() const;
- bool any_socket_is_directly_linked(eNodeSocketInOut in_out) const;
-
- bNode *bnode() const;
- bNodeTree *btree() const;
-
- PointerRNA rna() const;
- StringRefNull idname() const;
- StringRefNull name() const;
- StringRefNull label() const;
- StringRefNull label_or_name() const;
- bNodeType *typeinfo() const;
- const NodeDeclaration *declaration() const;
-
- int id() const;
-
- bool is_reroute_node() const;
- bool is_group_node() const;
- bool is_group_input_node() const;
- bool is_group_output_node() const;
- bool is_muted() const;
- bool is_frame() const;
- bool is_undefined() const;
-
- void *storage() const;
- template<typename T> T *storage() const;
-};
-
-class LinkRef : NonCopyable, NonMovable {
- private:
- OutputSocketRef *from_;
- InputSocketRef *to_;
- bNodeLink *blink_;
-
- friend NodeTreeRef;
-
- public:
- const OutputSocketRef &from() const;
- const InputSocketRef &to() const;
-
- bNodeLink *blink() const;
-
- bool is_muted() const;
-};
-
-class InternalLinkRef : NonCopyable, NonMovable {
- private:
- InputSocketRef *from_;
- OutputSocketRef *to_;
- bNodeLink *blink_;
-
- friend NodeTreeRef;
-
- public:
- const InputSocketRef &from() const;
- const OutputSocketRef &to() const;
-
- bNodeLink *blink() const;
-};
-
-class NodeTreeRef : NonCopyable, NonMovable {
- private:
- LinearAllocator<> allocator_;
- bNodeTree *btree_;
- Vector<NodeRef *> nodes_by_id_;
- Vector<SocketRef *> sockets_by_id_;
- Vector<InputSocketRef *> input_sockets_;
- Vector<OutputSocketRef *> output_sockets_;
- Vector<LinkRef *> links_;
- MultiValueMap<const bNodeType *, NodeRef *> nodes_by_type_;
- Vector<std::unique_ptr<SocketIndexByIdentifierMap>> owned_identifier_maps_;
- const NodeRef *group_output_node_ = nullptr;
-
- public:
- NodeTreeRef(bNodeTree *btree);
- ~NodeTreeRef();
-
- Span<const NodeRef *> nodes() const;
- Span<const NodeRef *> nodes_by_type(StringRefNull idname) const;
- Span<const NodeRef *> nodes_by_type(const bNodeType *nodetype) const;
-
- Span<const SocketRef *> sockets() const;
- Span<const InputSocketRef *> input_sockets() const;
- Span<const OutputSocketRef *> output_sockets() const;
-
- Span<const LinkRef *> links() const;
-
- const NodeRef *find_node(const bNode &bnode) const;
-
- /**
- * This is the active group output node if there are multiple.
- */
- const NodeRef *group_output_node() const;
-
- /**
- * \return True when there is a link cycle. Unavailable sockets are ignored.
- */
- bool has_link_cycles() const;
- bool has_undefined_nodes_or_sockets() const;
-
- enum class ToposortDirection {
- LeftToRight,
- RightToLeft,
- };
-
- struct ToposortResult {
- Vector<const NodeRef *> sorted_nodes;
- /**
- * There can't be a correct topological sort of the nodes when there is a cycle. The nodes will
- * still be sorted to some degree. The caller has to decide whether it can handle non-perfect
- * sorts or not.
- */
- bool has_cycle = false;
- };
-
- /**
- * Sort nodes topologically from left to right or right to left.
- * In the future the result if this could be cached on #NodeTreeRef.
- */
- ToposortResult toposort(ToposortDirection direction) const;
-
- bNodeTree *btree() const;
- StringRefNull name() const;
-
- std::string to_dot() const;
-
- private:
- /* Utility functions used during construction. */
- InputSocketRef &find_input_socket(Map<bNode *, NodeRef *> &node_mapping,
- bNode *bnode,
- bNodeSocket *bsocket);
- OutputSocketRef &find_output_socket(Map<bNode *, NodeRef *> &node_mapping,
- bNode *bnode,
- bNodeSocket *bsocket);
-
- void create_linked_socket_caches();
- void create_socket_identifier_maps();
-};
-
-using NodeTreeRefMap = Map<bNodeTree *, std::unique_ptr<const NodeTreeRef>>;
-
-const NodeTreeRef &get_tree_ref_from_map(NodeTreeRefMap &node_tree_refs, bNodeTree &btree);
-
-namespace node_tree_ref_types {
-using nodes::InputSocketRef;
-using nodes::NodeRef;
-using nodes::NodeTreeRef;
-using nodes::NodeTreeRefMap;
-using nodes::OutputSocketRef;
-using nodes::SocketRef;
-} // namespace node_tree_ref_types
-
-/* -------------------------------------------------------------------- */
-/** \name #SocketRef Inline Methods
- * \{ */
-
-inline Span<const SocketRef *> SocketRef::logically_linked_sockets() const
-{
- return logically_linked_sockets_;
-}
-
-inline Span<const SocketRef *> SocketRef::logically_linked_skipped_sockets() const
-{
- return logically_linked_skipped_sockets_;
-}
-
-inline Span<const SocketRef *> SocketRef::directly_linked_sockets() const
-{
- return directly_linked_sockets_;
-}
-
-inline Span<const LinkRef *> SocketRef::directly_linked_links() const
-{
- return directly_linked_links_;
-}
-
-inline bool SocketRef::is_directly_linked() const
-{
- return directly_linked_sockets_.size() > 0;
-}
-
-inline bool SocketRef::is_logically_linked() const
-{
- return logically_linked_sockets_.size() > 0;
-}
-
-inline const NodeRef &SocketRef::node() const
-{
- return *node_;
-}
-
-inline const NodeTreeRef &SocketRef::tree() const
-{
- return node_->tree();
-}
-
-inline int SocketRef::id() const
-{
- return id_;
-}
-
-inline int SocketRef::index() const
-{
- return index_;
-}
-
-inline bool SocketRef::is_input() const
-{
- return is_input_;
-}
-
-inline bool SocketRef::is_output() const
-{
- return !is_input_;
-}
-
-inline const SocketRef &SocketRef::as_base() const
-{
- return *this;
-}
-
-inline const InputSocketRef &SocketRef::as_input() const
-{
- BLI_assert(this->is_input());
- return static_cast<const InputSocketRef &>(*this);
-}
-
-inline const OutputSocketRef &SocketRef::as_output() const
-{
- BLI_assert(this->is_output());
- return static_cast<const OutputSocketRef &>(*this);
-}
-
-inline StringRefNull SocketRef::idname() const
-{
- return bsocket_->idname;
-}
-
-inline StringRefNull SocketRef::name() const
-{
- return bsocket_->name;
-}
-
-inline StringRefNull SocketRef::identifier() const
-{
- return bsocket_->identifier;
-}
-
-inline bNodeSocketType *SocketRef::typeinfo() const
-{
- return bsocket_->typeinfo;
-}
-
-inline bNodeSocket *SocketRef::bsocket() const
-{
- return bsocket_;
-}
-
-inline bNode *SocketRef::bnode() const
-{
- return node_->bnode();
-}
-
-inline bNodeTree *SocketRef::btree() const
-{
- return node_->btree();
-}
-
-inline bool SocketRef::is_available() const
-{
- return (bsocket_->flag & SOCK_UNAVAIL) == 0;
-}
-
-inline bool SocketRef::is_undefined() const
-{
- return bsocket_->typeinfo == &NodeSocketTypeUndefined;
-}
-
-inline void *SocketRef::default_value() const
-{
- return bsocket_->default_value;
-}
-
-template<typename T> inline T *SocketRef::default_value() const
-{
- return (T *)bsocket_->default_value;
-}
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
-/** \name #InputSocketRef Inline Methods
- * \{ */
-
-inline Span<const OutputSocketRef *> InputSocketRef::logically_linked_sockets() const
-{
- return logically_linked_sockets_.as_span().cast<const OutputSocketRef *>();
-}
-
-inline Span<const OutputSocketRef *> InputSocketRef::directly_linked_sockets() const
-{
- return directly_linked_sockets_.cast<const OutputSocketRef *>();
-}
-
-inline bool InputSocketRef::is_multi_input_socket() const
-{
- return bsocket_->flag & SOCK_MULTI_INPUT;
-}
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
-/** \name #OutputSocketRef Inline Methods
- * \{ */
-
-inline Span<const InputSocketRef *> OutputSocketRef::logically_linked_sockets() const
-{
- return logically_linked_sockets_.as_span().cast<const InputSocketRef *>();
-}
-
-inline Span<const InputSocketRef *> OutputSocketRef::directly_linked_sockets() const
-{
- return directly_linked_sockets_.cast<const InputSocketRef *>();
-}
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
-/** \name #NodeRef Inline Methods
- * \{ */
-
-inline const NodeTreeRef &NodeRef::tree() const
-{
- return *tree_;
-}
-
-inline Span<const InputSocketRef *> NodeRef::inputs() const
-{
- return inputs_;
-}
-
-inline Span<const OutputSocketRef *> NodeRef::outputs() const
-{
- return outputs_;
-}
-
-inline Span<const SocketRef *> NodeRef::sockets(const eNodeSocketInOut in_out) const
-{
- return in_out == SOCK_IN ? inputs_.as_span().cast<const SocketRef *>() :
- outputs_.as_span().cast<const SocketRef *>();
-}
-
-inline Span<const InternalLinkRef *> NodeRef::internal_links() const
-{
- return internal_links_;
-}
-
-inline const InputSocketRef &NodeRef::input(int index) const
-{
- return *inputs_[index];
-}
-
-inline const OutputSocketRef &NodeRef::output(int index) const
-{
- return *outputs_[index];
-}
-
-inline const InputSocketRef &NodeRef::input_by_identifier(StringRef identifier) const
-{
- const int index = input_index_by_identifier_->lookup_as(identifier);
- return this->input(index);
-}
-
-inline const OutputSocketRef &NodeRef::output_by_identifier(StringRef identifier) const
-{
- const int index = output_index_by_identifier_->lookup_as(identifier);
- return this->output(index);
-}
-
-inline bNode *NodeRef::bnode() const
-{
- return bnode_;
-}
-
-inline bNodeTree *NodeRef::btree() const
-{
- return tree_->btree();
-}
-
-inline StringRefNull NodeRef::idname() const
-{
- return bnode_->idname;
-}
-
-inline StringRefNull NodeRef::name() const
-{
- return bnode_->name;
-}
-
-inline StringRefNull NodeRef::label() const
-{
- return bnode_->label;
-}
-
-inline StringRefNull NodeRef::label_or_name() const
-{
- const StringRefNull label = this->label();
- if (!label.is_empty()) {
- return label;
- }
- return this->name();
-}
-
-inline bNodeType *NodeRef::typeinfo() const
-{
- return bnode_->typeinfo;
-}
-
-/* Returns a pointer because not all nodes have declarations currently. */
-inline const NodeDeclaration *NodeRef::declaration() const
-{
- nodeDeclarationEnsure(this->tree().btree(), bnode_);
- return bnode_->runtime->declaration;
-}
-
-inline int NodeRef::id() const
-{
- return id_;
-}
-
-inline bool NodeRef::is_reroute_node() const
-{
- return bnode_->type == NODE_REROUTE;
-}
-
-inline bool NodeRef::is_group_node() const
-{
- return bnode_->type == NODE_GROUP || bnode_->type == NODE_CUSTOM_GROUP;
-}
-
-inline bool NodeRef::is_group_input_node() const
-{
- return bnode_->type == NODE_GROUP_INPUT;
-}
-
-inline bool NodeRef::is_group_output_node() const
-{
- return bnode_->type == NODE_GROUP_OUTPUT;
-}
-
-inline bool NodeRef::is_frame() const
-{
- return bnode_->type == NODE_FRAME;
-}
-
-inline bool NodeRef::is_undefined() const
-{
- return bnode_->typeinfo == &NodeTypeUndefined;
-}
-
-inline bool NodeRef::is_muted() const
-{
- return (bnode_->flag & NODE_MUTED) != 0;
-}
-
-inline void *NodeRef::storage() const
-{
- return bnode_->storage;
-}
-
-template<typename T> inline T *NodeRef::storage() const
-{
- return (T *)bnode_->storage;
-}
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
-/** \name #LinkRef Inline Methods
- * \{ */
-
-inline const OutputSocketRef &LinkRef::from() const
-{
- return *from_;
-}
-
-inline const InputSocketRef &LinkRef::to() const
-{
- return *to_;
-}
-
-inline bNodeLink *LinkRef::blink() const
-{
- return blink_;
-}
-
-inline bool LinkRef::is_muted() const
-{
- return blink_->flag & NODE_LINK_MUTED;
-}
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
-/** \name #InternalLinkRef Inline Methods
- * \{ */
-
-inline const InputSocketRef &InternalLinkRef::from() const
-{
- return *from_;
-}
-
-inline const OutputSocketRef &InternalLinkRef::to() const
-{
- return *to_;
-}
-
-inline bNodeLink *InternalLinkRef::blink() const
-{
- return blink_;
-}
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
-/** \name #NodeTreeRef Inline Methods
- * \{ */
-
-inline Span<const NodeRef *> NodeTreeRef::nodes() const
-{
- return nodes_by_id_;
-}
-
-inline Span<const NodeRef *> NodeTreeRef::nodes_by_type(StringRefNull idname) const
-{
- const bNodeType *nodetype = nodeTypeFind(idname.c_str());
- return this->nodes_by_type(nodetype);
-}
-
-inline Span<const NodeRef *> NodeTreeRef::nodes_by_type(const bNodeType *nodetype) const
-{
- return nodes_by_type_.lookup(nodetype);
-}
-
-inline Span<const SocketRef *> NodeTreeRef::sockets() const
-{
- return sockets_by_id_;
-}
-
-inline Span<const InputSocketRef *> NodeTreeRef::input_sockets() const
-{
- return input_sockets_;
-}
-
-inline Span<const OutputSocketRef *> NodeTreeRef::output_sockets() const
-{
- return output_sockets_;
-}
-
-inline Span<const LinkRef *> NodeTreeRef::links() const
-{
- return links_;
-}
-
-inline const NodeRef *NodeTreeRef::group_output_node() const
-{
- return group_output_node_;
-}
-
-inline bNodeTree *NodeTreeRef::btree() const
-{
- return btree_;
-}
-
-inline StringRefNull NodeTreeRef::name() const
-{
- return btree_->id.name + 2;
-}
-
-/** \} */
-
-} // namespace blender::nodes
diff --git a/source/blender/nodes/NOD_shader.h b/source/blender/nodes/NOD_shader.h
index 1d1310360b8..8fe77bffaad 100644
--- a/source/blender/nodes/NOD_shader.h
+++ b/source/blender/nodes/NOD_shader.h
@@ -26,6 +26,7 @@ void register_node_type_sh_camera(void);
void register_node_type_sh_value(void);
void register_node_type_sh_rgb(void);
void register_node_type_sh_mix_rgb(void);
+void register_node_type_sh_mix(void);
void register_node_type_sh_valtorgb(void);
void register_node_type_sh_rgbtobw(void);
void register_node_type_sh_shadertorgb(void);
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index d743c341885..9671f8148ec 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -25,7 +25,7 @@ DefNode(Node, NODE_REROUTE, 0, "REROUT
DefNode(ShaderNode, SH_NODE_RGB, 0, "RGB", RGB, "RGB", "A color picker")
DefNode(ShaderNode, SH_NODE_VALUE, 0, "VALUE", Value, "Value", "Used to Input numerical values to other nodes in the tree")
-DefNode(ShaderNode, SH_NODE_MIX_RGB, def_mix_rgb, "MIX_RGB", MixRGB, "MixRGB", "Mix two input colors")
+DefNode(ShaderNode, SH_NODE_MIX_RGB_LEGACY, def_mix_rgb, "MIX_RGB", MixRGB, "MixRGB", "Mix two input colors")
DefNode(ShaderNode, SH_NODE_VALTORGB, def_colorramp, "VALTORGB", ValToRGB, "ColorRamp", "Map values to colors with the use of a gradient")
DefNode(ShaderNode, SH_NODE_RGBTOBW, 0, "RGBTOBW", RGBToBW, "RGB to BW", "Convert a color's luminance to a grayscale value")
DefNode(ShaderNode, SH_NODE_SHADERTORGB, 0, "SHADERTORGB", ShaderToRGB, "Shader to RGB", "Convert rendering effect (such as light and shadow) to color. Typically used for non-photorealistic rendering, to apply additional effects on the output of BSDFs.\nNote: only supported for Eevee")
@@ -122,6 +122,7 @@ DefNode(ShaderNode, SH_NODE_OUTPUT_AOV, def_sh_output_aov, "OUT
DefNode(ShaderNode, SH_NODE_CURVE_FLOAT, def_float_curve, "CURVE_FLOAT", FloatCurve, "Float Curve", "Map an input float to a curve and outputs a float value")
DefNode(ShaderNode, SH_NODE_COMBINE_COLOR, def_sh_combsep_color, "COMBINE_COLOR", CombineColor, "Combine Color", "Create a color from individual components using multiple models")
DefNode(ShaderNode, SH_NODE_SEPARATE_COLOR, def_sh_combsep_color, "SEPARATE_COLOR", SeparateColor, "Separate Color", "Split a color into its individual components using multiple models")
+DefNode(ShaderNode, SH_NODE_MIX, def_sh_mix, "MIX", Mix, "Mix", "Mix values by a factor")
DefNode(CompositorNode, CMP_NODE_VIEWER, def_cmp_viewer, "VIEWER", Viewer, "Viewer", "" )
DefNode(CompositorNode, CMP_NODE_RGB, 0, "RGB", RGB, "RGB", "" )
@@ -261,7 +262,7 @@ DefNode(TextureNode, TEX_NODE_PROC+TEX_STUCCI, 0, "TEX_ST
DefNode(TextureNode, TEX_NODE_PROC+TEX_DISTNOISE, 0, "TEX_DISTNOISE", TexDistNoise, "Distorted Noise", "" )
DefNode(FunctionNode, FN_NODE_ALIGN_EULER_TO_VECTOR, def_fn_align_euler_to_vector, "ALIGN_EULER_TO_VECTOR", AlignEulerToVector, "Align Euler to Vector", "")
-DefNode(FunctionNode, FN_NODE_BOOLEAN_MATH, def_boolean_math, "BOOLEAN_MATH", BooleanMath, "Boolean Math", "")
+DefNode(FunctionNode, FN_NODE_BOOLEAN_MATH, def_boolean_math, "BOOLEAN_MATH", BooleanMath, "Boolean Math", "")
DefNode(FunctionNode, FN_NODE_COMBINE_COLOR, def_fn_combsep_color, "COMBINE_COLOR", CombineColor, "Combine Color", "")
DefNode(FunctionNode, FN_NODE_COMPARE, def_compare, "COMPARE", Compare, "Compare", "")
DefNode(FunctionNode, FN_NODE_FLOAT_TO_INT, def_float_to_int, "FLOAT_TO_INT", FloatToInt, "Float to Integer", "")
@@ -279,132 +280,152 @@ DefNode(FunctionNode, FN_NODE_SLICE_STRING, 0, "SLICE_STRING", SliceString, "Sli
DefNode(FunctionNode, FN_NODE_STRING_LENGTH, 0, "STRING_LENGTH", StringLength, "String Length", "")
DefNode(FunctionNode, FN_NODE_VALUE_TO_STRING, 0, "VALUE_TO_STRING", ValueToString, "Value to String", "")
-DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_DOMAIN_SIZE, def_geo_attribute_domain_size, "ATTRIBUTE_DOMAIN_SIZE", AttributeDomainSize, "Domain Size", "")
-DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_STATISTIC, def_geo_attribute_statistic, "ATTRIBUTE_STATISTIC", AttributeStatistic, "Attribute Statistic", "")
-DefNode(GeometryNode, GEO_NODE_BOUNDING_BOX, 0, "BOUNDING_BOX", BoundBox, "Bounding Box", "")
-DefNode(GeometryNode, GEO_NODE_CAPTURE_ATTRIBUTE, def_geo_attribute_capture, "CAPTURE_ATTRIBUTE", CaptureAttribute, "Capture Attribute", "")
-DefNode(GeometryNode, GEO_NODE_COLLECTION_INFO, def_geo_collection_info, "COLLECTION_INFO", CollectionInfo, "Collection Info", "")
-DefNode(GeometryNode, GEO_NODE_CONVEX_HULL, 0, "CONVEX_HULL", ConvexHull, "Convex Hull", "")
-DefNode(GeometryNode, GEO_NODE_CURVE_ENDPOINT_SELECTION, 0, "CURVE_ENDPOINT_SELECTION", CurveEndpointSelection, "Endpoint Selection", "")
-DefNode(GeometryNode, GEO_NODE_CURVE_HANDLE_TYPE_SELECTION, def_geo_curve_handle_type_selection, "CURVE_HANDLE_TYPE_SELECTION", CurveHandleTypeSelection, "Handle Type Selection", "")
-DefNode(GeometryNode, GEO_NODE_CURVE_LENGTH, 0, "CURVE_LENGTH", CurveLength, "Curve Length", "")
-DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_ARC, def_geo_curve_primitive_arc, "CURVE_PRIMITIVE_ARC", CurveArc, "Arc", "")
-DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_BEZIER_SEGMENT, def_geo_curve_primitive_bezier_segment, "CURVE_PRIMITIVE_BEZIER_SEGMENT", CurvePrimitiveBezierSegment, "Bezier Segment", "")
-DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_CIRCLE, def_geo_curve_primitive_circle, "CURVE_PRIMITIVE_CIRCLE", CurvePrimitiveCircle, "Curve Circle", "")
-DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_LINE, def_geo_curve_primitive_line, "CURVE_PRIMITIVE_LINE", CurvePrimitiveLine, "Curve Line", "")
-DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_QUADRATIC_BEZIER, 0, "CURVE_PRIMITIVE_QUADRATIC_BEZIER", CurveQuadraticBezier, "Quadratic Bezier", "")
-DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_QUADRILATERAL, def_geo_curve_primitive_quadrilateral, "CURVE_PRIMITIVE_QUADRILATERAL", CurvePrimitiveQuadrilateral, "Quadrilateral", "")
-DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_SPIRAL, 0, "CURVE_PRIMITIVE_SPIRAL", CurveSpiral, "Curve Spiral", "")
-DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_STAR, 0, "CURVE_PRIMITIVE_STAR", CurveStar, "Star", "")
-DefNode(GeometryNode, GEO_NODE_CURVE_SET_HANDLE_TYPE, def_geo_curve_set_handle_type, "CURVE_SET_HANDLES", CurveSetHandles, "Set Handle Type", "")
-DefNode(GeometryNode, GEO_NODE_CURVE_SPLINE_PARAMETER, 0, "SPLINE_PARAMETER", SplineParameter, "Spline Parameter", "")
-DefNode(GeometryNode, GEO_NODE_CURVE_SPLINE_TYPE, def_geo_curve_spline_type, "CURVE_SPLINE_TYPE", CurveSplineType, "Set Spline Type", "")
-DefNode(GeometryNode, GEO_NODE_CURVE_TO_MESH, 0, "CURVE_TO_MESH", CurveToMesh, "Curve to Mesh", "")
-DefNode(GeometryNode, GEO_NODE_CURVE_TO_POINTS, def_geo_curve_to_points, "CURVE_TO_POINTS", CurveToPoints, "Curve to Points", "")
-DefNode(GeometryNode, GEO_NODE_DEFORM_CURVES_ON_SURFACE, 0, "DEFORM_CURVES_ON_SURFACE", DeformCurvesOnSurface, "Deform Curves on Surface", "")
-DefNode(GeometryNode, GEO_NODE_DELETE_GEOMETRY, def_geo_delete_geometry, "DELETE_GEOMETRY", DeleteGeometry, "Delete Geometry", "")
-DefNode(GeometryNode, GEO_NODE_DUPLICATE_ELEMENTS, def_geo_duplicate_elements, "DUPLICATE_ELEMENTS", DuplicateElements, "Duplicate Elements", "")
-DefNode(GeometryNode, GEO_NODE_DISTRIBUTE_POINTS_ON_FACES, def_geo_distribute_points_on_faces, "DISTRIBUTE_POINTS_ON_FACES", DistributePointsOnFaces, "Distribute Points on Faces", "")
-DefNode(GeometryNode, GEO_NODE_ACCUMULATE_FIELD, def_geo_accumulate_field, "ACCUMULATE_FIELD", AccumulateField, "Accumulate Field", "")
-DefNode(GeometryNode, GEO_NODE_DUAL_MESH, 0, "DUAL_MESH", DualMesh, "Dual Mesh", "")
-DefNode(GeometryNode, GEO_NODE_EXTRUDE_MESH, def_geo_extrude_mesh, "EXTRUDE_MESH", ExtrudeMesh, "Extrude Mesh", "")
-DefNode(GeometryNode, GEO_NODE_FIELD_AT_INDEX, def_geo_field_at_index, "FIELD_AT_INDEX", FieldAtIndex, "Field at Index", "")
-DefNode(GeometryNode, GEO_NODE_FIELD_ON_DOMAIN, def_geo_field_on_domain, "FIELD_ON_DOMAIN", FieldOnDomain, "Field on Domain", "")
-DefNode(GeometryNode, GEO_NODE_FILL_CURVE, def_geo_curve_fill, "FILL_CURVE", FillCurve, "Fill Curve", "")
-DefNode(GeometryNode, GEO_NODE_FILLET_CURVE, def_geo_curve_fillet, "FILLET_CURVE", FilletCurve, "Fillet Curve", "")
-DefNode(GeometryNode, GEO_NODE_FLIP_FACES, 0, "FLIP_FACES", FlipFaces, "Flip Faces", "")
-DefNode(GeometryNode, GEO_NODE_GEOMETRY_TO_INSTANCE, 0, "GEOMETRY_TO_INSTANCE", GeometryToInstance, "Geometry to Instance", "")
-DefNode(GeometryNode, GEO_NODE_IMAGE_TEXTURE, def_geo_image_texture, "IMAGE_TEXTURE", ImageTexture, "Image Texture", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_NAMED_ATTRIBUTE, def_geo_input_named_attribute, "INPUT_ATTRIBUTE", InputNamedAttribute, "Named Attribute", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_CURVE_HANDLES, 0, "INPUT_CURVE_HANDLES", InputCurveHandlePositions, "Curve Handle Positions", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_CURVE_TILT, 0, "INPUT_CURVE_TILT", InputCurveTilt, "Curve Tilt", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_ID, 0, "INPUT_ID", InputID, "ID", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_INDEX, 0, "INDEX", InputIndex, "Index", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_INSTANCE_ROTATION, 0, "INPUT_INSTANCE_ROTATION", InputInstanceRotation, "Instance Rotation", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_INSTANCE_SCALE, 0, "INPUT_INSTANCE_SCALE", InputInstanceScale, "Instance Scale", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_MATERIAL_INDEX, 0, "INPUT_MATERIAL_INDEX", InputMaterialIndex, "Material Index", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_MATERIAL, def_geo_input_material, "INPUT_MATERIAL", InputMaterial, "Material", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_MESH_EDGE_ANGLE, 0, "MESH_EDGE_ANGLE", InputMeshEdgeAngle, "Edge Angle", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_MESH_EDGE_NEIGHBORS, 0, "MESH_EDGE_NEIGHBORS", InputMeshEdgeNeighbors, "Edge Neighbors", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_MESH_EDGE_VERTICES, 0, "MESH_EDGE_VERTICES", InputMeshEdgeVertices, "Edge Vertices", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_MESH_FACE_AREA, 0, "MESH_FACE_AREA", InputMeshFaceArea, "Face Area", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_MESH_FACE_IS_PLANAR, 0, "MESH_FACE_IS_PLANAR", InputMeshFaceIsPlanar, "Face is Planar", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_MESH_FACE_NEIGHBORS, 0, "MESH_FACE_NEIGHBORS", InputMeshFaceNeighbors, "Face Neighbors", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_MESH_ISLAND, 0, "MESH_ISLAND", InputMeshIsland, "Mesh Island", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_MESH_VERTEX_NEIGHBORS, 0, "MESH_VERTEX_NEIGHBORS", InputMeshVertexNeighbors, "Vertex Neighbors", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_NORMAL, 0, "INPUT_NORMAL", InputNormal, "Normal", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_POSITION, 0, "POSITION", InputPosition, "Position", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_RADIUS, 0, "INPUT_RADIUS", InputRadius, "Radius", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_SCENE_TIME, 0, "INPUT_SCENE_TIME", InputSceneTime, "Scene Time", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_SHADE_SMOOTH, 0, "INPUT_SHADE_SMOOTH", InputShadeSmooth, "Is Shade Smooth", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_SPLINE_CYCLIC, 0, "INPUT_SPLINE_CYCLIC", InputSplineCyclic, "Is Spline Cyclic", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_SPLINE_LENGTH, 0, "SPLINE_LENGTH", SplineLength, "Spline Length", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_SPLINE_RESOLUTION, 0, "INPUT_SPLINE_RESOLUTION", InputSplineResolution, "Spline Resolution", "")
-DefNode(GeometryNode, GEO_NODE_INPUT_TANGENT, 0, "INPUT_TANGENT", InputTangent, "Curve Tangent", "")
-DefNode(GeometryNode, GEO_NODE_INSTANCE_ON_POINTS, 0, "INSTANCE_ON_POINTS", InstanceOnPoints, "Instance on Points", "")
-DefNode(GeometryNode, GEO_NODE_INSTANCES_TO_POINTS, 0, "INSTANCES_TO_POINTS", InstancesToPoints, "Instances to Points", "")
-DefNode(GeometryNode, GEO_NODE_IS_VIEWPORT, 0, "IS_VIEWPORT", IsViewport, "Is Viewport", "")
-DefNode(GeometryNode, GEO_NODE_JOIN_GEOMETRY, 0, "JOIN_GEOMETRY", JoinGeometry, "Join Geometry", "")
-DefNode(GeometryNode, GEO_NODE_MATERIAL_SELECTION, 0, "MATERIAL_SELECTION", MaterialSelection, "Material Selection", "")
-DefNode(GeometryNode, GEO_NODE_MERGE_BY_DISTANCE, def_geo_merge_by_distance, "MERGE_BY_DISTANCE", MergeByDistance, "Merge by Distance", "")
-DefNode(GeometryNode, GEO_NODE_MESH_BOOLEAN, def_geo_boolean, "MESH_BOOLEAN", MeshBoolean, "Mesh Boolean", "")
-DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_CIRCLE, def_geo_mesh_circle, "MESH_PRIMITIVE_CIRCLE", MeshCircle, "Mesh Circle", "")
-DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_CONE, def_geo_mesh_cone, "MESH_PRIMITIVE_CONE", MeshCone, "Cone", "")
-DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_CUBE, 0, "MESH_PRIMITIVE_CUBE", MeshCube, "Cube", "")
-DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_CYLINDER, def_geo_mesh_cylinder, "MESH_PRIMITIVE_CYLINDER", MeshCylinder, "Cylinder", "")
-DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_GRID, 0, "MESH_PRIMITIVE_GRID", MeshGrid, "Grid", "")
-DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_ICO_SPHERE, 0, "MESH_PRIMITIVE_ICO_SPHERE", MeshIcoSphere, "Ico Sphere", "")
-DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_LINE, def_geo_mesh_line, "MESH_PRIMITIVE_LINE", MeshLine, "Mesh Line", "")
-DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_UV_SPHERE, 0, "MESH_PRIMITIVE_UV_SPHERE", MeshUVSphere, "UV Sphere", "")
-DefNode(GeometryNode, GEO_NODE_MESH_TO_CURVE, 0, "MESH_TO_CURVE", MeshToCurve, "Mesh to Curve", "")
-DefNode(GeometryNode, GEO_NODE_MESH_TO_POINTS, def_geo_mesh_to_points, "MESH_TO_POINTS", MeshToPoints, "Mesh to Points", "")
-DefNode(GeometryNode, GEO_NODE_MESH_TO_VOLUME, def_geo_mesh_to_volume, "MESH_TO_VOLUME", MeshToVolume, "Mesh to Volume", "")
-DefNode(GeometryNode, GEO_NODE_OBJECT_INFO, def_geo_object_info, "OBJECT_INFO", ObjectInfo, "Object Info", "")
-DefNode(GeometryNode, GEO_NODE_POINTS, 0, "POINTS", Points, "Points", "")
-DefNode(GeometryNode, GEO_NODE_POINTS_TO_VERTICES, 0, "POINTS_TO_VERTICES", PointsToVertices, "Points to Vertices", "")
-DefNode(GeometryNode, GEO_NODE_POINTS_TO_VOLUME, def_geo_points_to_volume, "POINTS_TO_VOLUME", PointsToVolume, "Points to Volume", "")
-DefNode(GeometryNode, GEO_NODE_PROXIMITY, def_geo_proximity, "PROXIMITY", Proximity, "Geometry Proximity", "")
-DefNode(GeometryNode, GEO_NODE_RAYCAST, def_geo_raycast, "RAYCAST", Raycast, "Raycast", "")
-DefNode(GeometryNode, GEO_NODE_REMOVE_ATTRIBUTE, 0, "REMOVE_ATTRIBUTE", RemoveAttribute, "Remove Named Attribute", "")
-DefNode(GeometryNode, GEO_NODE_REALIZE_INSTANCES, def_geo_realize_instances, "REALIZE_INSTANCES", RealizeInstances, "Realize Instances", "")
-DefNode(GeometryNode, GEO_NODE_REPLACE_MATERIAL, 0, "REPLACE_MATERIAL", ReplaceMaterial, "Replace Material", "")
-DefNode(GeometryNode, GEO_NODE_RESAMPLE_CURVE, def_geo_curve_resample, "RESAMPLE_CURVE", ResampleCurve, "Resample Curve", "")
-DefNode(GeometryNode, GEO_NODE_REVERSE_CURVE, 0, "REVERSE_CURVE", ReverseCurve, "Reverse Curve", "")
-DefNode(GeometryNode, GEO_NODE_ROTATE_INSTANCES, 0, "ROTATE_INSTANCES", RotateInstances, "Rotate Instances", "")
-DefNode(GeometryNode, GEO_NODE_SAMPLE_CURVE, def_geo_curve_sample, "SAMPLE_CURVE", SampleCurve, "Sample Curve", "")
-DefNode(GeometryNode, GEO_NODE_SCALE_ELEMENTS, def_geo_scale_elements, "SCALE_ELEMENTS", ScaleElements, "Scale Elements", "")
-DefNode(GeometryNode, GEO_NODE_SCALE_INSTANCES, 0, "SCALE_INSTANCES", ScaleInstances, "Scale Instances", "")
-DefNode(GeometryNode, GEO_NODE_SEPARATE_COMPONENTS, 0, "SEPARATE_COMPONENTS", SeparateComponents, "Separate Components", "")
-DefNode(GeometryNode, GEO_NODE_SEPARATE_GEOMETRY, def_geo_separate_geometry, "SEPARATE_GEOMETRY", SeparateGeometry, "Separate Geometry", "")
-DefNode(GeometryNode, GEO_NODE_SET_CURVE_HANDLES, def_geo_curve_set_handle_positions, "SET_CURVE_HANDLES", SetCurveHandlePositions, "Set Handle Positions", "")
-DefNode(GeometryNode, GEO_NODE_SET_CURVE_RADIUS, 0, "SET_CURVE_RADIUS", SetCurveRadius, "Set Curve Radius", "")
-DefNode(GeometryNode, GEO_NODE_SET_CURVE_TILT, 0, "SET_CURVE_TILT", SetCurveTilt, "Set Curve Tilt", "")
-DefNode(GeometryNode, GEO_NODE_SET_ID, 0, "SET_ID", SetID, "Set ID", "")
-DefNode(GeometryNode, GEO_NODE_SET_MATERIAL_INDEX, 0, "SET_MATERIAL_INDEX", SetMaterialIndex, "Set Material Index", "")
-DefNode(GeometryNode, GEO_NODE_SET_MATERIAL, 0, "SET_MATERIAL", SetMaterial, "Set Material", "")
-DefNode(GeometryNode, GEO_NODE_SET_POINT_RADIUS, 0, "SET_POINT_RADIUS", SetPointRadius, "Set Point Radius", "")
-DefNode(GeometryNode, GEO_NODE_SET_POSITION, 0, "SET_POSITION", SetPosition, "Set Position", "")
-DefNode(GeometryNode, GEO_NODE_SET_SHADE_SMOOTH, 0, "SET_SHADE_SMOOTH", SetShadeSmooth, "Set Shade Smooth", "")
-DefNode(GeometryNode, GEO_NODE_SET_SPLINE_CYCLIC, 0, "SET_SPLINE_CYCLIC", SetSplineCyclic, "Set Spline Cyclic", "")
-DefNode(GeometryNode, GEO_NODE_SET_SPLINE_RESOLUTION, 0, "SET_SPLINE_RESOLUTION", SetSplineResolution, "Set Spline Resolution", "")
-DefNode(GeometryNode, GEO_NODE_SPLIT_EDGES, 0, "SPLIT_EDGES", SplitEdges, "Split Edges", "")
-DefNode(GeometryNode, GEO_NODE_STORE_NAMED_ATTRIBUTE, def_geo_store_named_attribute, "STORE_NAMED_ATTRIBUTE", StoreNamedAttribute, "Store Named Attribute", "")
-DefNode(GeometryNode, GEO_NODE_STRING_JOIN, 0, "STRING_JOIN", StringJoin, "Join Strings", "")
-DefNode(GeometryNode, GEO_NODE_STRING_TO_CURVES, def_geo_string_to_curves, "STRING_TO_CURVES", StringToCurves, "String to Curves", "")
-DefNode(GeometryNode, GEO_NODE_SUBDIVIDE_CURVE, 0, "SUBDIVIDE_CURVE", SubdivideCurve, "Subdivide Curve", "")
-DefNode(GeometryNode, GEO_NODE_SUBDIVIDE_MESH, 0, "SUBDIVIDE_MESH", SubdivideMesh, "Subdivide Mesh", "")
-DefNode(GeometryNode, GEO_NODE_SUBDIVISION_SURFACE, def_geo_subdivision_surface, "SUBDIVISION_SURFACE", SubdivisionSurface, "Subdivision Surface", "")
-DefNode(GeometryNode, GEO_NODE_SWITCH, def_geo_switch, "SWITCH", Switch, "Switch", "")
-DefNode(GeometryNode, GEO_NODE_TRANSFER_ATTRIBUTE, def_geo_transfer_attribute, "ATTRIBUTE_TRANSFER", AttributeTransfer, "Transfer Attribute", "")
-DefNode(GeometryNode, GEO_NODE_TRANSFORM, 0, "TRANSFORM", Transform, "Transform", "")
-DefNode(GeometryNode, GEO_NODE_TRANSLATE_INSTANCES, 0, "TRANSLATE_INSTANCES", TranslateInstances, "Translate Instances", "")
-DefNode(GeometryNode, GEO_NODE_TRIANGULATE, def_geo_triangulate, "TRIANGULATE", Triangulate, "Triangulate", "")
-DefNode(GeometryNode, GEO_NODE_TRIM_CURVE, def_geo_curve_trim, "TRIM_CURVE", TrimCurve, "Trim Curve", "")
-DefNode(GeometryNode, GEO_NODE_VIEWER, def_geo_viewer, "VIEWER", Viewer, "Viewer", "")
-DefNode(GeometryNode, GEO_NODE_VOLUME_CUBE, 0, "VOLUME_CUBE", VolumeCube, "Volume Cube", "")
-DefNode(GeometryNode, GEO_NODE_VOLUME_TO_MESH, def_geo_volume_to_mesh, "VOLUME_TO_MESH", VolumeToMesh, "Volume to Mesh", "")
-DefNode(GeometryNode, GEO_NODE_UV_PACK_ISLANDS, 0, "UV_PACK_ISLANDS", UVPackIslands, "Pack UV Islands", "")
-DefNode(GeometryNode, GEO_NODE_UV_UNWRAP, def_geo_uv_unwrap, "UV_UNWRAP", UVUnwrap, "UV Unwrap", "")
+DefNode(GeometryNode, GEO_NODE_ACCUMULATE_FIELD, def_geo_accumulate_field, "ACCUMULATE_FIELD", AccumulateField, "Accumulate Field", "Add the values of an evaluated field together and output the running total for each element")
+DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_DOMAIN_SIZE, def_geo_attribute_domain_size, "ATTRIBUTE_DOMAIN_SIZE", AttributeDomainSize, "Domain Size", "Retrieve the number of elements in a geometry for each attribute domain")
+DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_STATISTIC, def_geo_attribute_statistic, "ATTRIBUTE_STATISTIC",AttributeStatistic, "Attribute Statistic","Calculate statistics about a data set from a field evaluated on a geometry")
+DefNode(GeometryNode, GEO_NODE_BOUNDING_BOX, 0, "BOUNDING_BOX", BoundBox, "Bounding Box", "Calculate the limits of a geometry's positions and generate a box mesh with those dimensions")
+DefNode(GeometryNode, GEO_NODE_CAPTURE_ATTRIBUTE, def_geo_attribute_capture,"CAPTURE_ATTRIBUTE", CaptureAttribute, "Capture Attribute", "Store the result of a field on a geometry and output the data as a node socket. Allows remembering or interpolating data as the geometry changes, such as positions before deformation")
+DefNode(GeometryNode, GEO_NODE_COLLECTION_INFO, def_geo_collection_info, "COLLECTION_INFO", CollectionInfo, "Collection Info", "Retrieve geometry from a collection")
+DefNode(GeometryNode, GEO_NODE_CONVEX_HULL, 0, "CONVEX_HULL", ConvexHull, "Convex Hull", "Create a mesh that encloses all points in the input geometry with the smallest number of points")
+DefNode(GeometryNode, GEO_NODE_CURVE_ENDPOINT_SELECTION, 0, "CURVE_ENDPOINT_SELECTION", CurveEndpointSelection, "Endpoint Selection", "Provide a selection for an arbitrary number of endpoints in each spline")
+DefNode(GeometryNode, GEO_NODE_CURVE_HANDLE_TYPE_SELECTION, def_geo_curve_handle_type_selection, "CURVE_HANDLE_TYPE_SELECTION", CurveHandleTypeSelection, "Handle Type Selection", "Provide a selection based on the handle types of Bézier control points")
+DefNode(GeometryNode, GEO_NODE_CURVE_LENGTH, 0, "CURVE_LENGTH", CurveLength, "Curve Length", "Retrieve the length of all splines added together")
+DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_ARC, def_geo_curve_primitive_arc, "CURVE_PRIMITIVE_ARC",CurveArc, "Arc", "Generate a poly spline arc")
+DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_BEZIER_SEGMENT, def_geo_curve_primitive_bezier_segment, "CURVE_PRIMITIVE_BEZIER_SEGMENT", CurvePrimitiveBezierSegment, "Bezier Segment", "Generate a 2D Bézier spline from the given control points and handles")
+DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_CIRCLE,def_geo_curve_primitive_circle, "CURVE_PRIMITIVE_CIRCLE", CurvePrimitiveCircle, "Curve Circle", "Generate a poly spline circle")
+DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_LINE, def_geo_curve_primitive_line, "CURVE_PRIMITIVE_LINE", CurvePrimitiveLine, "Curve Line", "Generate a poly spline line with two points")
+DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_QUADRATIC_BEZIER, 0, "CURVE_PRIMITIVE_QUADRATIC_BEZIER", CurveQuadraticBezier, "Quadratic Bezier", "Generate a poly spline in a parabola shape with control points positions")
+DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_QUADRILATERAL, def_geo_curve_primitive_quadrilateral, "CURVE_PRIMITIVE_QUADRILATERAL", CurvePrimitiveQuadrilateral, "Quadrilateral", "Generate a polygon with four points")
+DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_SPIRAL,0, "CURVE_PRIMITIVE_SPIRAL", CurveSpiral, "Curve Spiral", "Generate a poly spline in a spiral shape")
+DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_STAR, 0, "CURVE_PRIMITIVE_STAR", CurveStar, "Star", "Generate a poly spline in a star pattern by connecting alternating points of two circles")
+DefNode(GeometryNode, GEO_NODE_CURVE_SET_HANDLE_TYPE, def_geo_curve_set_handle_type, "CURVE_SET_HANDLES", CurveSetHandles, "Set Handle Type", "Set the handle type for the control points of a Bézier curve")
+DefNode(GeometryNode, GEO_NODE_CURVE_SPLINE_PARAMETER,0, "SPLINE_PARAMETER", SplineParameter, "Spline Parameter", "Retrieve how far along each spline a control point is")
+DefNode(GeometryNode, GEO_NODE_CURVE_SPLINE_TYPE, def_geo_curve_spline_type,"CURVE_SPLINE_TYPE", CurveSplineType, "Set Spline Type", "Change the type of curves")
+DefNode(GeometryNode, GEO_NODE_CURVE_TO_MESH, 0, "CURVE_TO_MESH", CurveToMesh, "Curve to Mesh", "Convert curves into a mesh, optionally with a custom profile shape defined by curves")
+DefNode(GeometryNode, GEO_NODE_CURVE_TO_POINTS, def_geo_curve_to_points, "CURVE_TO_POINTS", CurveToPoints, "Curve to Points", "Generate a point cloud by sampling positions along curves")
+DefNode(GeometryNode, GEO_NODE_CURVE_TOPOLOGY_CURVE_OF_POINT, 0, "CURVE_OF_POINT", CurveOfPoint, "Curve of Point", "Retrieve the curve a control point is part of")
+DefNode(GeometryNode, GEO_NODE_CURVE_TOPOLOGY_POINTS_OF_CURVE, 0, "POINTS_OF_CURVE", PointsOfCurve, "Points of Curve", "Retrieve a point index within a curve")
+DefNode(GeometryNode, GEO_NODE_DEFORM_CURVES_ON_SURFACE, 0, "DEFORM_CURVES_ON_SURFACE", DeformCurvesOnSurface, "Deform Curves on Surface", "Translate and rotate curves based on changes between the object's original and evaluated surface mesh")
+DefNode(GeometryNode, GEO_NODE_DELETE_GEOMETRY, def_geo_delete_geometry, "DELETE_GEOMETRY", DeleteGeometry, "Delete Geometry", "Remove selected elements of a geometry")
+DefNode(GeometryNode, GEO_NODE_DISTRIBUTE_POINTS_IN_VOLUME, def_geo_distribute_points_in_volume, "DISTRIBUTE_POINTS_IN_VOLUME", DistributePointsInVolume, "Distribute Points in Volume", "Generate points inside a volume")
+DefNode(GeometryNode, GEO_NODE_DISTRIBUTE_POINTS_ON_FACES, def_geo_distribute_points_on_faces, "DISTRIBUTE_POINTS_ON_FACES", DistributePointsOnFaces, "Distribute Points on Faces", "Generate points spread out on the surface of a mesh")
+DefNode(GeometryNode, GEO_NODE_DUAL_MESH, 0, "DUAL_MESH", DualMesh, "Dual Mesh", "Convert Faces into vertices and vertices into faces")
+DefNode(GeometryNode, GEO_NODE_DUPLICATE_ELEMENTS, def_geo_duplicate_elements, "DUPLICATE_ELEMENTS", DuplicateElements, "Duplicate Elements", "Generate an arbitrary number copies of each selected input element")
+DefNode(GeometryNode, GEO_NODE_EDGE_PATHS_TO_CURVES, 0, "EDGE_PATHS_TO_CURVES", EdgePathsToCurves, "Edge Paths to Curves", "")
+DefNode(GeometryNode, GEO_NODE_EDGE_PATHS_TO_SELECTION, 0, "EDGE_PATHS_TO_SELECTION", EdgePathsToSelection, "Edge Paths to Selection", "")
+DefNode(GeometryNode, GEO_NODE_EXTRUDE_MESH, def_geo_extrude_mesh, "EXTRUDE_MESH", ExtrudeMesh, "Extrude Mesh", "Generate new vertices, edges, or faces from selected elements and move them based on an offset while keeping them connected by their boundary")
+DefNode(GeometryNode, GEO_NODE_FIELD_AT_INDEX, def_geo_field_at_index, "FIELD_AT_INDEX", FieldAtIndex, "Field at Index", "Retrieve data of other elements in the context's geometry")
+DefNode(GeometryNode, GEO_NODE_FILL_CURVE, def_geo_curve_fill, "FILL_CURVE", FillCurve, "Fill Curve", "Generate a mesh on the XY plane with faces on the inside of input curves")
+DefNode(GeometryNode, GEO_NODE_FILLET_CURVE, def_geo_curve_fillet, "FILLET_CURVE", FilletCurve, "Fillet Curve", "Round corners by generating circular arcs on each control point")
+DefNode(GeometryNode, GEO_NODE_FLIP_FACES, 0, "FLIP_FACES", FlipFaces, "Flip Faces", "Reverse the order of the vertices and edges of selected faces, flipping their normal direction")
+DefNode(GeometryNode, GEO_NODE_GEOMETRY_TO_INSTANCE, 0, "GEOMETRY_TO_INSTANCE", GeometryToInstance, "Geometry to Instance", "Convert each input geometry into an instance, which can be much faster than the Join Geometry node when the inputs are large")
+DefNode(GeometryNode, GEO_NODE_IMAGE_TEXTURE, def_geo_image_texture, "IMAGE_TEXTURE", ImageTexture, "Image Texture", "Sample values from an image texture")
+DefNode(GeometryNode, GEO_NODE_INPUT_CURVE_HANDLES, 0, "INPUT_CURVE_HANDLES", InputCurveHandlePositions,"Curve Handle Positions", "Retrieve the position of each Bézier control point's handles")
+DefNode(GeometryNode, GEO_NODE_INPUT_CURVE_TILT, 0, "INPUT_CURVE_TILT", InputCurveTilt, "Curve Tilt", "Retrieve the angle at each control point used to twist the curve's normal around its tangent")
+DefNode(GeometryNode, GEO_NODE_INPUT_ID, 0, "INPUT_ID", InputID, "ID", "Retrieve a stable random identifier value from the \"id\" attribute on the point domain, or the index if the attribute does not exist")
+DefNode(GeometryNode, GEO_NODE_INPUT_INDEX, 0, "INDEX", InputIndex, "Index", "Retrieve an integer value indicating the position of each element in the list, starting at zero")
+DefNode(GeometryNode, GEO_NODE_INPUT_INSTANCE_ROTATION, 0, "INPUT_INSTANCE_ROTATION", InputInstanceRotation, "Instance Rotation", "Retrieve the rotation of each instance in the geometry")
+DefNode(GeometryNode, GEO_NODE_INPUT_INSTANCE_SCALE, 0, "INPUT_INSTANCE_SCALE", InputInstanceScale, "Instance Scale", "Retrieve the scale of each instance in the geometry")
+DefNode(GeometryNode, GEO_NODE_INPUT_MATERIAL_INDEX, 0, "INPUT_MATERIAL_INDEX", InputMaterialIndex, "Material Index", "Retrieve the index of the material used for each element in the geometry's list of materials")
+DefNode(GeometryNode, GEO_NODE_INPUT_MATERIAL, def_geo_input_material, "INPUT_MATERIAL", InputMaterial, "Material", "Output a single material")
+DefNode(GeometryNode, GEO_NODE_INPUT_MESH_EDGE_ANGLE, 0, "MESH_EDGE_ANGLE", InputMeshEdgeAngle, "Edge Angle", "Calculate the surface area of each face in a mesh")
+DefNode(GeometryNode, GEO_NODE_INPUT_MESH_EDGE_NEIGHBORS, 0, "MESH_EDGE_NEIGHBORS",InputMeshEdgeNeighbors, "Edge Neighbors", "Retrieve the number of faces that use each edge as one of their sides")
+DefNode(GeometryNode, GEO_NODE_INPUT_MESH_EDGE_VERTICES, 0, "MESH_EDGE_VERTICES", InputMeshEdgeVertices, "Edge Vertices", "Retrieve topology information relating to each edge of a mesh")
+DefNode(GeometryNode, GEO_NODE_INPUT_MESH_FACE_AREA, 0, "MESH_FACE_AREA", InputMeshFaceArea, "Face Area", "Calculate the surface area of a mesh's faces")
+DefNode(GeometryNode, GEO_NODE_INPUT_MESH_FACE_IS_PLANAR, 0, "MESH_FACE_IS_PLANAR",InputMeshFaceIsPlanar, "Is Face Planar", "Retrieve whether all triangles in a face are on the same plane, i.e. whether have the same normal")
+DefNode(GeometryNode, GEO_NODE_INPUT_MESH_FACE_NEIGHBORS, 0, "MESH_FACE_NEIGHBORS",InputMeshFaceNeighbors, "Face Neighbors", "Retrieve topology information relating to each face of a mesh")
+DefNode(GeometryNode, GEO_NODE_INPUT_MESH_ISLAND, 0, "MESH_ISLAND", InputMeshIsland, "Mesh Island", "Retrieve information about separate connected regions in a mesh")
+DefNode(GeometryNode, GEO_NODE_INPUT_MESH_VERTEX_NEIGHBORS, 0, "MESH_VERTEX_NEIGHBORS", InputMeshVertexNeighbors, "Vertex Neighbors", "Retrieve topology information relating to each vertex of a mesh")
+DefNode(GeometryNode, GEO_NODE_INPUT_NAMED_ATTRIBUTE, def_geo_input_named_attribute, "INPUT_ATTRIBUTE", InputNamedAttribute, "Named Attribute", "Retrieve the data of a specified attribute")
+DefNode(GeometryNode, GEO_NODE_INPUT_NORMAL, 0, "INPUT_NORMAL", InputNormal, "Normal", "Retrieve a unit length vector indicating the direction pointing away from the geometry at each element")
+DefNode(GeometryNode, GEO_NODE_INPUT_POSITION, 0, "POSITION", InputPosition, "Position", "Retrieve a vector indicating the location of each element")
+DefNode(GeometryNode, GEO_NODE_INPUT_RADIUS, 0, "INPUT_RADIUS", InputRadius, "Radius", "Retrieve the radius at each point on curve or point cloud geometry")
+DefNode(GeometryNode, GEO_NODE_INPUT_SCENE_TIME, 0, "INPUT_SCENE_TIME", InputSceneTime, "Scene Time", "Retrieve the current time in the scene's animation in units of seconds or frames")
+DefNode(GeometryNode, GEO_NODE_INPUT_SHADE_SMOOTH, 0, "INPUT_SHADE_SMOOTH", InputShadeSmooth, "Is Shade Smooth", "Retrieve whether each face is marked for smooth shading")
+DefNode(GeometryNode, GEO_NODE_INPUT_SHORTEST_EDGE_PATHS, 0, "SHORTEST_EDGE_PATHS", InputShortestEdgePaths, "Shortest Edge Paths", "")
+DefNode(GeometryNode, GEO_NODE_INPUT_SPLINE_CYCLIC, 0, "INPUT_SPLINE_CYCLIC",InputSplineCyclic, "Is Spline Cyclic", "Retrieve whether each spline endpoint connects to the beginning")
+DefNode(GeometryNode, GEO_NODE_INPUT_SPLINE_LENGTH, 0, "SPLINE_LENGTH", SplineLength, "Spline Length", "Retrieve the total length of each spline, as a distance or as a number of points")
+DefNode(GeometryNode, GEO_NODE_INPUT_SPLINE_RESOLUTION, 0, "INPUT_SPLINE_RESOLUTION", InputSplineResolution, "Spline Resolution", "Retrieve the number of evaluated points that will be generated for every control point on curves")
+DefNode(GeometryNode, GEO_NODE_INPUT_TANGENT, 0, "INPUT_TANGENT", InputTangent, "Curve Tangent", "Retrieve the direction of curves at each control point")
+DefNode(GeometryNode, GEO_NODE_INSTANCE_ON_POINTS, 0, "INSTANCE_ON_POINTS", InstanceOnPoints, "Instance on Points", "Generate a reference to geometry at each of the input points, without duplicating its underlying data")
+DefNode(GeometryNode, GEO_NODE_INSTANCES_TO_POINTS, 0, "INSTANCES_TO_POINTS",InstancesToPoints, "Instances to Points","Generate points at the origins of instances.\nNote: Nested instances are not affected by this node")
+DefNode(GeometryNode, GEO_NODE_INTERPOLATE_DOMAIN, def_geo_interpolate_domain, "FIELD_ON_DOMAIN", FieldOnDomain, "Interpolate Domain", "Retrieve values from a field on a different domain besides the domain from the context")
+DefNode(GeometryNode, GEO_NODE_IS_VIEWPORT, 0, "IS_VIEWPORT", IsViewport, "Is Viewport", "Retrieve whether the nodes are being evaluated for the viewport rather than the final render")
+DefNode(GeometryNode, GEO_NODE_JOIN_GEOMETRY, 0, "JOIN_GEOMETRY", JoinGeometry, "Join Geometry", "Merge separately generated geometries into a single one")
+DefNode(GeometryNode, GEO_NODE_MATERIAL_SELECTION, 0, "MATERIAL_SELECTION", MaterialSelection, "Material Selection", "Provide a selection of faces that use the specified material")
+DefNode(GeometryNode, GEO_NODE_MERGE_BY_DISTANCE, def_geo_merge_by_distance,"MERGE_BY_DISTANCE", MergeByDistance, "Merge by Distance", "Merge vertices or points within a given distance")
+DefNode(GeometryNode, GEO_NODE_MESH_BOOLEAN, def_geo_boolean, "MESH_BOOLEAN", MeshBoolean, "Mesh Boolean", "Cut, subtract, or join multiple mesh inputs")
+DefNode(GeometryNode, GEO_NODE_MESH_FACE_SET_BOUNDARIES, 0, "MESH_FACE_SET_BOUNDARIES", MeshFaceSetBoundaries, "Face Set Boundaries", "Find edges on the boundaries between face sets")
+DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_CIRCLE, def_geo_mesh_circle, "MESH_PRIMITIVE_CIRCLE", MeshCircle, "Mesh Circle", "Generate a circular ring of edges")
+DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_CONE, def_geo_mesh_cone, "MESH_PRIMITIVE_CONE",MeshCone, "Cone", "Generate a cone mesh")
+DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_CUBE, 0, "MESH_PRIMITIVE_CUBE",MeshCube, "Cube", "Generate a cuboid mesh with variable side lengths and subdivisions")
+DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_CYLINDER, def_geo_mesh_cylinder, "MESH_PRIMITIVE_CYLINDER", MeshCylinder, "Cylinder", "Generate a cylinder mesh")
+DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_GRID, 0, "MESH_PRIMITIVE_GRID",MeshGrid, "Grid", "Generate a planar mesh on the XY plane")
+DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_ICO_SPHERE, 0, "MESH_PRIMITIVE_ICO_SPHERE", MeshIcoSphere, "Ico Sphere", "Generate a spherical mesh that consists of equally sized triangles")
+DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_LINE, def_geo_mesh_line, "MESH_PRIMITIVE_LINE",MeshLine, "Mesh Line", "Generate vertices in a line and connect them with edges")
+DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_UV_SPHERE, 0, "MESH_PRIMITIVE_UV_SPHERE", MeshUVSphere, "UV Sphere", "Generate a spherical mesh with quads, except for triangles at the top and bottom")
+DefNode(GeometryNode, GEO_NODE_MESH_TO_CURVE, 0, "MESH_TO_CURVE", MeshToCurve, "Mesh to Curve", "Generate a curve from a mesh")
+DefNode(GeometryNode, GEO_NODE_MESH_TO_POINTS, def_geo_mesh_to_points, "MESH_TO_POINTS", MeshToPoints, "Mesh to Points", "Generate a point cloud from a mesh's vertices")
+DefNode(GeometryNode, GEO_NODE_MESH_TO_VOLUME, def_geo_mesh_to_volume, "MESH_TO_VOLUME", MeshToVolume, "Mesh to Volume", "Create a fog volume with the shape of the input mesh's surface")
+DefNode(GeometryNode, GEO_NODE_MESH_TOPOLOGY_CORNERS_OF_FACE, 0, "CORNERS_OF_FACE", CornersOfFace, "Corners of Face", "Retrieve corners that make up a face")
+DefNode(GeometryNode, GEO_NODE_MESH_TOPOLOGY_CORNERS_OF_VERTEX, 0, "CORNERS_OF_VERTEX", CornersOfVertex, "Corners of Vertex", "Retrieve face corners connected to vertices")
+DefNode(GeometryNode, GEO_NODE_MESH_TOPOLOGY_EDGES_OF_CORNER, 0, "EDGES_OF_CORNER", EdgesOfCorner, "Edges of Corner", "Retrieve the edges on both sides of a face corner")
+DefNode(GeometryNode, GEO_NODE_MESH_TOPOLOGY_EDGES_OF_VERTEX, 0, "EDGES_OF_VERTEX", EdgesOfVertex, "Edges of Vertex", "Retrieve the edges connected to each vertex")
+DefNode(GeometryNode, GEO_NODE_MESH_TOPOLOGY_FACE_OF_CORNER, 0, "FACE_OF_CORNER", FaceOfCorner, "Face of Corner", "Retrieve the face each face corner is part of")
+DefNode(GeometryNode, GEO_NODE_MESH_TOPOLOGY_OFFSET_CORNER_IN_FACE, 0, "OFFSET_CORNER_IN_FACE", OffsetCornerInFace, "Offset Corner in Face", "Retrieve corners in the same face as another")
+DefNode(GeometryNode, GEO_NODE_MESH_TOPOLOGY_VERTEX_OF_CORNER, 0, "VERTEX_OF_CORNER", VertexOfCorner, "Vertex of Corner", "Retrieve the vertex each face corner is attached to")
+DefNode(GeometryNode, GEO_NODE_OBJECT_INFO, def_geo_object_info, "OBJECT_INFO", ObjectInfo, "Object Info", "Retrieve information from an object")
+DefNode(GeometryNode, GEO_NODE_OFFSET_POINT_IN_CURVE, 0, "OFFSET_POINT_IN_CURVE", OffsetPointInCurve, "Offset Point in Curve", "Offset a control point index within its curve")
+DefNode(GeometryNode, GEO_NODE_POINTS_TO_VERTICES, 0, "POINTS_TO_VERTICES", PointsToVertices, "Points to Vertices", "Generate a mesh vertex for each point cloud point")
+DefNode(GeometryNode, GEO_NODE_POINTS_TO_VOLUME, def_geo_points_to_volume, "POINTS_TO_VOLUME", PointsToVolume, "Points to Volume", "Generate a fog volume sphere around every point")
+DefNode(GeometryNode, GEO_NODE_POINTS, 0, "POINTS", Points, "Points", "Generate a point cloud with positions and radii defined by fields")
+DefNode(GeometryNode, GEO_NODE_PROXIMITY, def_geo_proximity, "PROXIMITY", Proximity, "Geometry Proximity", "Compute the closest location on the target geometry")
+DefNode(GeometryNode, GEO_NODE_RAYCAST, def_geo_raycast, "RAYCAST", Raycast, "Raycast", "Cast rays from the context geometry onto a target geometry, and retrieve information from each hit point")
+DefNode(GeometryNode, GEO_NODE_REALIZE_INSTANCES, def_geo_realize_instances,"REALIZE_INSTANCES", RealizeInstances, "Realize Instances", "Change the direction of the curve by swapping each spline's start and end data")
+DefNode(GeometryNode, GEO_NODE_REMOVE_ATTRIBUTE, 0, "REMOVE_ATTRIBUTE", RemoveAttribute, "Remove Named Attribute", "Delete an attribute with a specified name from a geometry. Typically used to optimize performance")
+DefNode(GeometryNode, GEO_NODE_REPLACE_MATERIAL, 0, "REPLACE_MATERIAL", ReplaceMaterial, "Replace Material", "Swap one material with another")
+DefNode(GeometryNode, GEO_NODE_RESAMPLE_CURVE, def_geo_curve_resample, "RESAMPLE_CURVE", ResampleCurve, "Resample Curve", "Generate a poly spline for each input spline")
+DefNode(GeometryNode, GEO_NODE_REVERSE_CURVE, 0, "REVERSE_CURVE", ReverseCurve, "Reverse Curve", "Swap the start and end of splines")
+DefNode(GeometryNode, GEO_NODE_ROTATE_INSTANCES, 0, "ROTATE_INSTANCES", RotateInstances, "Rotate Instances", "Rotate geometry instances in local or global space")
+DefNode(GeometryNode, GEO_NODE_SAMPLE_CURVE, def_geo_curve_sample, "SAMPLE_CURVE", SampleCurve, "Sample Curve", "Retrieve data from a point on a curve at a certain distance from its start")
+DefNode(GeometryNode, GEO_NODE_SAMPLE_INDEX, def_geo_sample_index, "SAMPLE_INDEX", SampleIndex, "Sample Index", "Retrieve values from specific geometry elements")
+DefNode(GeometryNode, GEO_NODE_SAMPLE_NEAREST_SURFACE, def_geo_sample_nearest_surface, "SAMPLE_NEAREST_SURFACE", SampleNearestSurface, "Sample Nearest Surface", "Calculate the interpolated value of a mesh attribute on the closest point of its surface")
+DefNode(GeometryNode, GEO_NODE_SAMPLE_NEAREST, def_geo_sample_nearest, "SAMPLE_NEAREST", SampleNearest, "Sample Nearest", "Find the element of a geometry closest to a position")
+DefNode(GeometryNode, GEO_NODE_SAMPLE_UV_SURFACE, def_geo_sample_uv_surface, "SAMPLE_UV_SURFACE", SampleUVSurface, "Sample UV Surface", "Calculate the interpolated values of a mesh attribute at a UV coordinate")
+DefNode(GeometryNode, GEO_NODE_SCALE_ELEMENTS, def_geo_scale_elements, "SCALE_ELEMENTS", ScaleElements, "Scale Elements", "Scale groups of connected edges and faces")
+DefNode(GeometryNode, GEO_NODE_SCALE_INSTANCES, 0, "SCALE_INSTANCES", ScaleInstances, "Scale Instances", "Scale geometry instances in local or global space")
+DefNode(GeometryNode, GEO_NODE_SEPARATE_COMPONENTS, 0, "SEPARATE_COMPONENTS",SeparateComponents, "Separate Components","Split a geometry into a separate output for each type of data in the geometry")
+DefNode(GeometryNode, GEO_NODE_SEPARATE_GEOMETRY, def_geo_separate_geometry,"SEPARATE_GEOMETRY", SeparateGeometry, "Separate Geometry", "Split a geometry into two geometry outputs based on a selection")
+DefNode(GeometryNode, GEO_NODE_SELF_OBJECT, 0, "SELF_OBJECT", SelfObject, "Self Object", "Retrieve the object that contains the geometry nodes modifier currently being executed")
+DefNode(GeometryNode, GEO_NODE_SET_CURVE_HANDLES, def_geo_curve_set_handle_positions, "SET_CURVE_HANDLES", SetCurveHandlePositions, "Set Handle Positions", "Set the positions for the handles of Bézier curves")
+DefNode(GeometryNode, GEO_NODE_SET_CURVE_NORMAL, def_geo_set_curve_normal, "SET_CURVE_NORMAL", SetCurveNormal, "Set Curve Normal", "Set the evaluation mode for curve normals")
+DefNode(GeometryNode, GEO_NODE_SET_CURVE_RADIUS, 0, "SET_CURVE_RADIUS", SetCurveRadius, "Set Curve Radius", "Set the radius of the curve at each control point")
+DefNode(GeometryNode, GEO_NODE_SET_CURVE_TILT, 0, "SET_CURVE_TILT", SetCurveTilt, "Set Curve Tilt", "Set the tilt angle at each curve control point")
+DefNode(GeometryNode, GEO_NODE_SET_ID, 0, "SET_ID", SetID, "Set ID", "Set the id attribute on the input geometry, mainly used internally for randomizing")
+DefNode(GeometryNode, GEO_NODE_SET_MATERIAL_INDEX, 0, "SET_MATERIAL_INDEX", SetMaterialIndex, "Set Material Index", "Set the material index for each selected geometry element")
+DefNode(GeometryNode, GEO_NODE_SET_MATERIAL, 0, "SET_MATERIAL", SetMaterial, "Set Material", "Assign a material to geometry elements")
+DefNode(GeometryNode, GEO_NODE_SET_POINT_RADIUS, 0, "SET_POINT_RADIUS", SetPointRadius, "Set Point Radius", "Set the display size of point cloud points")
+DefNode(GeometryNode, GEO_NODE_SET_POSITION, 0, "SET_POSITION", SetPosition, "Set Position", "Set the location of each point")
+DefNode(GeometryNode, GEO_NODE_SET_SHADE_SMOOTH, 0, "SET_SHADE_SMOOTH", SetShadeSmooth, "Set Shade Smooth", "Control the smoothness of mesh normals around each face by changing the \"shade smooth\" attribute")
+DefNode(GeometryNode, GEO_NODE_SET_SPLINE_CYCLIC, 0, "SET_SPLINE_CYCLIC", SetSplineCyclic, "Set Spline Cyclic", "Control whether each spline loops back on itself by changing the \"cyclic\" attribute")
+DefNode(GeometryNode, GEO_NODE_SET_SPLINE_RESOLUTION, 0, "SET_SPLINE_RESOLUTION", SetSplineResolution, "Set Spline Resolution", "Control how many evaluated points should be generated on every curve segment")
+DefNode(GeometryNode, GEO_NODE_SPLIT_EDGES, 0, "SPLIT_EDGES", SplitEdges, "Split Edges", "Duplicate mesh edges and break connections with the surrounding faces")
+DefNode(GeometryNode, GEO_NODE_STORE_NAMED_ATTRIBUTE, def_geo_store_named_attribute, "STORE_NAMED_ATTRIBUTE", StoreNamedAttribute, "Store Named Attribute", "Store the result of a field on a geometry as an attribute with the specified name")
+DefNode(GeometryNode, GEO_NODE_STRING_JOIN, 0, "STRING_JOIN", StringJoin, "Join Strings", "Combine any number of input strings")
+DefNode(GeometryNode, GEO_NODE_STRING_TO_CURVES, def_geo_string_to_curves, "STRING_TO_CURVES", StringToCurves, "String to Curves", "Generate a paragraph of text with a specific font, using a curve instance to store each character")
+DefNode(GeometryNode, GEO_NODE_SUBDIVIDE_CURVE, 0, "SUBDIVIDE_CURVE", SubdivideCurve, "Subdivide Curve", "Dividing each curve segment into a specified number of pieces")
+DefNode(GeometryNode, GEO_NODE_SUBDIVIDE_MESH, 0, "SUBDIVIDE_MESH", SubdivideMesh, "Subdivide Mesh", "Divide mesh faces into smaller ones without changing the shape or volume, using linear interpolation to place the new vertices")
+DefNode(GeometryNode, GEO_NODE_SUBDIVISION_SURFACE, def_geo_subdivision_surface, "SUBDIVISION_SURFACE",SubdivisionSurface, "Subdivision Surface","Divide mesh faces to form a smooth surface, using the Catmull-Clark subdivision method")
+DefNode(GeometryNode, GEO_NODE_SWITCH, def_geo_switch, "SWITCH", Switch, "Switch", "Switch between two inputs")
+DefNode(GeometryNode, GEO_NODE_TRANSFORM, 0, "TRANSFORM", Transform, "Transform", "Translate, rotate or scale the geometry")
+DefNode(GeometryNode, GEO_NODE_TRANSLATE_INSTANCES, 0, "TRANSLATE_INSTANCES",TranslateInstances, "Translate Instances","Move top-level geometry instances in local or global space")
+DefNode(GeometryNode, GEO_NODE_TRIANGULATE, def_geo_triangulate, "TRIANGULATE", Triangulate, "Triangulate", "Convert all faces in a mesh to triangular faces")
+DefNode(GeometryNode, GEO_NODE_TRIM_CURVE, def_geo_curve_trim, "TRIM_CURVE", TrimCurve, "Trim Curve", "Shorten curves by removing portions at the start or end")
+DefNode(GeometryNode, GEO_NODE_UV_PACK_ISLANDS, 0, "UV_PACK_ISLANDS", UVPackIslands, "Pack UV Islands", "Scale islands of a UV map and move them so they fill the UV space as much as possible")
+DefNode(GeometryNode, GEO_NODE_UV_UNWRAP, def_geo_uv_unwrap, "UV_UNWRAP", UVUnwrap, "UV Unwrap", "Generate a UV map based on seam edges")
+DefNode(GeometryNode, GEO_NODE_VIEWER, def_geo_viewer, "VIEWER", Viewer, "Viewer", "Display the input data in the Spreadsheet Editor")
+DefNode(GeometryNode, GEO_NODE_VOLUME_CUBE, 0, "VOLUME_CUBE", VolumeCube, "Volume Cube", "Generate a dense volume with a field that controls the density at each grid voxel based on its position")
+DefNode(GeometryNode, GEO_NODE_VOLUME_TO_MESH, def_geo_volume_to_mesh, "VOLUME_TO_MESH", VolumeToMesh, "Volume to Mesh", "Generate a mesh on the \"surface\" of a volume")
/* undefine macros */
#undef DefNode
diff --git a/source/blender/nodes/composite/CMakeLists.txt b/source/blender/nodes/composite/CMakeLists.txt
index c0100d77889..4255a2dde21 100644
--- a/source/blender/nodes/composite/CMakeLists.txt
+++ b/source/blender/nodes/composite/CMakeLists.txt
@@ -10,11 +10,15 @@ set(INC
../../blenlib
../../blentranslation
../../depsgraph
+ ../../functions
+ ../../gpu
../../imbuf
../../makesdna
../../makesrna
../../render
../../windowmanager
+ ../../compositor/realtime_compositor
+ ../../compositor/realtime_compositor/algorithms
../../../../intern/guardedalloc
# dna_type_offsets.h
@@ -120,15 +124,19 @@ set(SRC
node_composite_util.hh
)
+set(LIB
+ bf_realtime_compositor
+)
+
if(WITH_IMAGE_OPENEXR)
add_definitions(-DWITH_OPENEXR)
endif()
-if(WITH_COMPOSITOR)
+if(WITH_COMPOSITOR_CPU)
list(APPEND INC
../../compositor
)
- add_definitions(-DWITH_COMPOSITOR)
+ add_definitions(-DWITH_COMPOSITOR_CPU)
endif()
if(WITH_OPENIMAGEDENOISE)
diff --git a/source/blender/nodes/composite/node_composite_tree.cc b/source/blender/nodes/composite/node_composite_tree.cc
index 32b5d98a556..37d4fe852be 100644
--- a/source/blender/nodes/composite/node_composite_tree.cc
+++ b/source/blender/nodes/composite/node_composite_tree.cc
@@ -32,15 +32,12 @@
#include "NOD_composite.h"
#include "node_composite_util.hh"
-#ifdef WITH_COMPOSITOR
+#ifdef WITH_COMPOSITOR_CPU
# 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 * /*treetype*/, bNodeTree **r_ntree, ID **r_id, ID **r_from)
{
Scene *scene = CTX_data_scene(C);
@@ -49,7 +46,7 @@ static void composite_get_from_context(const bContext *C,
*r_ntree = scene->nodetree;
}
-static void foreach_nodeclass(Scene *UNUSED(scene), void *calldata, bNodeClassCallback func)
+static void foreach_nodeclass(Scene * /*scene*/, void *calldata, bNodeClassCallback func)
{
func(calldata, NODE_CLASS_INPUT, N_("Input"));
func(calldata, NODE_CLASS_OUTPUT, N_("Output"));
@@ -64,7 +61,7 @@ static void foreach_nodeclass(Scene *UNUSED(scene), void *calldata, bNodeClassCa
func(calldata, NODE_CLASS_LAYOUT, N_("Layout"));
}
-static void free_node_cache(bNodeTree *UNUSED(ntree), bNode *node)
+static void free_node_cache(bNodeTree * /*ntree*/, bNode *node)
{
LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
if (sock->cache) {
@@ -158,7 +155,7 @@ static void update(bNodeTree *ntree)
ntree_update_reroute_nodes(ntree);
}
-static void composite_node_add_init(bNodeTree *UNUSED(bnodetree), bNode *bnode)
+static void composite_node_add_init(bNodeTree * /*bnodetree*/, bNode *bnode)
{
/* Composite node will only show previews for input classes
* by default, other will be hidden
@@ -168,7 +165,7 @@ static void composite_node_add_init(bNodeTree *UNUSED(bnodetree), bNode *bnode)
}
}
-static bool composite_node_tree_socket_type_valid(bNodeTreeType *UNUSED(ntreetype),
+static bool composite_node_tree_socket_type_valid(bNodeTreeType * /*ntreetype*/,
bNodeSocketType *socket_type)
{
return nodeIsStaticSocketType(socket_type) &&
@@ -183,6 +180,7 @@ void register_node_tree_type_cmp()
tt->type = NTREE_COMPOSIT;
strcpy(tt->idname, "CompositorNodeTree");
+ strcpy(tt->group_idname, "CompositorNodeGroup");
strcpy(tt->ui_name, N_("Compositor"));
tt->ui_icon = ICON_NODE_COMPOSITING;
strcpy(tt->ui_description, N_("Compositing nodes"));
@@ -209,7 +207,7 @@ void ntreeCompositExecTree(Scene *scene,
int do_preview,
const char *view_name)
{
-#ifdef WITH_COMPOSITOR
+#ifdef WITH_COMPOSITOR_CPU
COM_execute(rd, scene, ntree, rendering, view_name);
#else
UNUSED_VARS(scene, ntree, rd, rendering, view_name);
diff --git a/source/blender/nodes/composite/node_composite_util.cc b/source/blender/nodes/composite/node_composite_util.cc
index 575a32b1785..ae3352c0d1b 100644
--- a/source/blender/nodes/composite/node_composite_util.cc
+++ b/source/blender/nodes/composite/node_composite_util.cc
@@ -9,9 +9,7 @@
#include "node_composite_util.hh"
-bool cmp_node_poll_default(bNodeType *UNUSED(ntype),
- bNodeTree *ntree,
- const char **r_disabled_hint)
+bool cmp_node_poll_default(bNodeType * /*ntype*/, bNodeTree *ntree, const char **r_disabled_hint)
{
if (!STREQ(ntree->idname, "CompositorNodeTree")) {
*r_disabled_hint = TIP_("Not a compositor node tree");
@@ -20,7 +18,7 @@ bool cmp_node_poll_default(bNodeType *UNUSED(ntype),
return true;
}
-void cmp_node_update_default(bNodeTree *UNUSED(ntree), bNode *node)
+void cmp_node_update_default(bNodeTree * /*ntree*/, bNode *node)
{
LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
if (sock->cache) {
diff --git a/source/blender/nodes/composite/nodes/node_composite_alpha_over.cc b/source/blender/nodes/composite/nodes/node_composite_alpha_over.cc
index d392b810bc1..e2f4e80270e 100644
--- a/source/blender/nodes/composite/nodes/node_composite_alpha_over.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_alpha_over.cc
@@ -8,26 +8,41 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* **************** ALPHAOVER ******************** */
namespace blender::nodes::node_composite_alpha_over_cc {
+NODE_STORAGE_FUNCS(NodeTwoFloats)
+
static void cmp_node_alphaover_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Float>(N_("Fac")).default_value(1.0f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
- b.add_input<decl::Color>(N_("Image"), "Image_001").default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Float>(N_("Fac"))
+ .default_value(1.0f)
+ .min(0.0f)
+ .max(1.0f)
+ .subtype(PROP_FACTOR)
+ .compositor_domain_priority(2);
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
+ b.add_input<decl::Color>(N_("Image"), "Image_001")
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(1);
b.add_output<decl::Color>(N_("Image"));
}
-static void node_alphaover_init(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_alphaover_init(bNodeTree * /*ntree*/, bNode *node)
{
node->storage = MEM_cnew<NodeTwoFloats>(__func__);
}
-static void node_composit_buts_alphaover(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_alphaover(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col;
@@ -36,6 +51,52 @@ static void node_composit_buts_alphaover(uiLayout *layout, bContext *UNUSED(C),
uiItemR(col, ptr, "premul", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class AlphaOverShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ const float premultiply_factor = get_premultiply_factor();
+ if (premultiply_factor != 0.0f) {
+ GPU_stack_link(material,
+ &bnode(),
+ "node_composite_alpha_over_mixed",
+ inputs,
+ outputs,
+ GPU_uniform(&premultiply_factor));
+ return;
+ }
+
+ if (get_use_premultiply()) {
+ GPU_stack_link(material, &bnode(), "node_composite_alpha_over_key", inputs, outputs);
+ return;
+ }
+
+ GPU_stack_link(material, &bnode(), "node_composite_alpha_over_premultiply", inputs, outputs);
+ }
+
+ bool get_use_premultiply()
+ {
+ return bnode().custom1;
+ }
+
+ float get_premultiply_factor()
+ {
+ return node_storage(bnode()).x;
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new AlphaOverShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_alpha_over_cc
void register_node_type_cmp_alphaover()
@@ -50,6 +111,7 @@ void register_node_type_cmp_alphaover()
node_type_init(&ntype, file_ns::node_alphaover_init);
node_type_storage(
&ntype, "NodeTwoFloats", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_antialiasing.cc b/source/blender/nodes/composite/nodes/node_composite_antialiasing.cc
index f45b678fc50..25fefd33199 100644
--- a/source/blender/nodes/composite/nodes/node_composite_antialiasing.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_antialiasing.cc
@@ -8,6 +8,8 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** Anti-Aliasing (SMAA 1x) ******************** */
@@ -20,7 +22,7 @@ static void cmp_node_antialiasing_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_init_antialiasing(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_antialiasing(bNodeTree * /*ntree*/, bNode *node)
{
NodeAntiAliasingData *data = MEM_cnew<NodeAntiAliasingData>(__func__);
@@ -31,7 +33,7 @@ static void node_composit_init_antialiasing(bNodeTree *UNUSED(ntree), bNode *nod
node->storage = data;
}
-static void node_composit_buts_antialiasing(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_antialiasing(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col;
@@ -42,6 +44,23 @@ static void node_composit_buts_antialiasing(uiLayout *layout, bContext *UNUSED(C
uiItemR(col, ptr, "corner_rounding", 0, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class AntiAliasingOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_input("Image").pass_through(get_result("Image"));
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new AntiAliasingOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_antialiasing_cc
void register_node_type_cmp_antialiasing()
@@ -58,6 +77,7 @@ void register_node_type_cmp_antialiasing()
node_type_init(&ntype, file_ns::node_composit_init_antialiasing);
node_type_storage(
&ntype, "NodeAntiAliasingData", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_bilateralblur.cc b/source/blender/nodes/composite/nodes/node_composite_bilateralblur.cc
index ad4a1f701d6..af7581d845f 100644
--- a/source/blender/nodes/composite/nodes/node_composite_bilateralblur.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_bilateralblur.cc
@@ -5,23 +5,36 @@
* \ingroup cmpnodes
*/
+#include "BLI_math_base.hh"
+
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_shader.h"
+
+#include "COM_node_operation.hh"
+#include "COM_utilities.hh"
+
#include "node_composite_util.hh"
/* **************** BILATERALBLUR ******************** */
namespace blender::nodes::node_composite_bilateralblur_cc {
+NODE_STORAGE_FUNCS(NodeBilateralBlurData)
+
static void cmp_node_bilateralblur_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
- b.add_input<decl::Color>(N_("Determinator")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
+ b.add_input<decl::Color>(N_("Determinator"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(1);
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_init_bilateralblur(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_bilateralblur(bNodeTree * /*ntree*/, bNode *node)
{
NodeBilateralBlurData *nbbd = MEM_cnew<NodeBilateralBlurData>(__func__);
node->storage = nbbd;
@@ -30,9 +43,7 @@ static void node_composit_init_bilateralblur(bNodeTree *UNUSED(ntree), bNode *no
nbbd->sigma_space = 5.0;
}
-static void node_composit_buts_bilateralblur(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
+static void node_composit_buts_bilateralblur(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col;
@@ -42,6 +53,61 @@ static void node_composit_buts_bilateralblur(uiLayout *layout,
uiItemR(col, ptr, "sigma_space", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class BilateralBlurOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ const Result &input_image = get_input("Image");
+ /* Single value inputs can't be blurred and are returned as is. */
+ if (input_image.is_single_value()) {
+ get_input("Image").pass_through(get_result("Image"));
+ return;
+ }
+
+ GPUShader *shader = shader_manager().get("compositor_bilateral_blur");
+ GPU_shader_bind(shader);
+
+ GPU_shader_uniform_1i(shader, "radius", get_blur_radius());
+ GPU_shader_uniform_1f(shader, "threshold", get_threshold());
+
+ input_image.bind_as_texture(shader, "input_tx");
+
+ const Result &determinator_image = get_input("Determinator");
+ determinator_image.bind_as_texture(shader, "determinator_tx");
+
+ const Domain domain = compute_domain();
+ Result &output_image = get_result("Image");
+ output_image.allocate_texture(domain);
+ output_image.bind_as_image(shader, "output_img");
+
+ compute_dispatch_threads_at_least(shader, domain.size);
+
+ GPU_shader_unbind();
+ output_image.unbind_as_image();
+ input_image.unbind_as_texture();
+ determinator_image.unbind_as_texture();
+ }
+
+ int get_blur_radius()
+ {
+ return math::ceil(node_storage(bnode()).iter + node_storage(bnode()).sigma_space);
+ }
+
+ float get_threshold()
+ {
+ return node_storage(bnode()).sigma_color;
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new BilateralBlurOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_bilateralblur_cc
void register_node_type_cmp_bilateralblur()
@@ -56,6 +122,7 @@ void register_node_type_cmp_bilateralblur()
node_type_init(&ntype, file_ns::node_composit_init_bilateralblur);
node_type_storage(
&ntype, "NodeBilateralBlurData", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_blur.cc b/source/blender/nodes/composite/nodes/node_composite_blur.cc
index 7beffe15c8e..a9372bdcfb7 100644
--- a/source/blender/nodes/composite/nodes/node_composite_blur.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_blur.cc
@@ -5,17 +5,36 @@
* \ingroup cmpnodes
*/
+#include <cstdint>
+
+#include "BLI_array.hh"
+#include "BLI_assert.h"
+#include "BLI_index_range.hh"
+#include "BLI_math_base.hh"
+#include "BLI_math_vec_types.hh"
+#include "BLI_math_vector.hh"
+
#include "RNA_access.h"
#include "UI_interface.h"
#include "UI_resources.h"
+#include "RE_pipeline.h"
+
+#include "GPU_state.h"
+#include "GPU_texture.h"
+
+#include "COM_node_operation.hh"
+#include "COM_utilities.hh"
+
#include "node_composite_util.hh"
/* **************** BLUR ******************** */
namespace blender::nodes::node_composite_blur_cc {
+NODE_STORAGE_FUNCS(NodeBlurData)
+
static void cmp_node_blur_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
@@ -23,14 +42,14 @@ static void cmp_node_blur_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_init_blur(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_blur(bNodeTree * /*ntree*/, bNode *node)
{
NodeBlurData *data = MEM_cnew<NodeBlurData>(__func__);
data->filtertype = R_FILTER_GAUSS;
node->storage = data;
}
-static void node_composit_buts_blur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_blur(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col, *row;
@@ -71,6 +90,405 @@ static void node_composit_buts_blur(uiLayout *layout, bContext *UNUSED(C), Point
uiItemR(col, ptr, "use_extended_bounds", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+/* A helper class that computes and caches a 1D GPU texture containing the weights of the separable
+ * filter of the given type and radius. The filter is assumed to be symmetric, because the filter
+ * functions are all even functions. Consequently, only the positive half of the filter is computed
+ * and the shader takes that into consideration. */
+class SymmetricSeparableBlurWeights {
+ private:
+ float radius_ = 1.0f;
+ int type_ = R_FILTER_GAUSS;
+ GPUTexture *texture_ = nullptr;
+
+ public:
+ ~SymmetricSeparableBlurWeights()
+ {
+ if (texture_) {
+ GPU_texture_free(texture_);
+ }
+ }
+
+ /* Check if a texture containing the weights was already computed for the given filter type and
+ * radius. If such texture exists, do nothing, otherwise, free the already computed texture and
+ * recompute it with the given filter type and radius. */
+ void update(float radius, int type)
+ {
+ if (texture_ && type == type_ && radius == radius_) {
+ return;
+ }
+
+ if (texture_) {
+ GPU_texture_free(texture_);
+ }
+
+ /* The size of filter is double the radius plus 1, but since the filter is symmetric, we only
+ * compute half of it and no doubling happens. We add 1 to make sure the filter size is always
+ * odd and there is a center weight. */
+ const int size = math::ceil(radius) + 1;
+ Array<float> weights(size);
+
+ float sum = 0.0f;
+
+ /* First, compute the center weight. */
+ const float center_weight = RE_filter_value(type, 0.0f);
+ weights[0] = center_weight;
+ sum += center_weight;
+
+ /* Second, compute the other weights in the positive direction, making sure to add double the
+ * weight to the sum of weights because the filter is symmetric and we only loop over half of
+ * it. Skip the center weight already computed by dropping the front index. */
+ const float scale = radius > 0.0f ? 1.0f / radius : 0.0f;
+ for (const int i : weights.index_range().drop_front(1)) {
+ const float weight = RE_filter_value(type, i * scale);
+ weights[i] = weight;
+ sum += weight * 2.0f;
+ }
+
+ /* Finally, normalize the weights. */
+ for (const int i : weights.index_range()) {
+ weights[i] /= sum;
+ }
+
+ texture_ = GPU_texture_create_1d("Weights", size, 1, GPU_R16F, weights.data());
+
+ type_ = type;
+ radius_ = radius;
+ }
+
+ void bind_as_texture(GPUShader *shader, const char *texture_name)
+ {
+ const int texture_image_unit = GPU_shader_get_texture_binding(shader, texture_name);
+ GPU_texture_bind(texture_, texture_image_unit);
+ }
+
+ void unbind_as_texture()
+ {
+ GPU_texture_unbind(texture_);
+ }
+};
+
+/* A helper class that computes and caches a 2D GPU texture containing the weights of the filter of
+ * the given type and radius. The filter is assumed to be symmetric, because the filter functions
+ * are evaluated on the normalized distance to the center. Consequently, only the upper right
+ * quadrant are computed and the shader takes that into consideration. */
+class SymmetricBlurWeights {
+ private:
+ int type_ = R_FILTER_GAUSS;
+ float2 radius_ = float2(1.0f);
+ GPUTexture *texture_ = nullptr;
+
+ public:
+ ~SymmetricBlurWeights()
+ {
+ if (texture_) {
+ GPU_texture_free(texture_);
+ }
+ }
+
+ /* Check if a texture containing the weights was already computed for the given filter type and
+ * radius. If such texture exists, do nothing, otherwise, free the already computed texture and
+ * recompute it with the given filter type and radius. */
+ void update(float2 radius, int type)
+ {
+ if (texture_ && type == type_ && radius == radius_) {
+ return;
+ }
+
+ if (texture_) {
+ GPU_texture_free(texture_);
+ }
+
+ /* The full size of filter is double the radius plus 1, but since the filter is symmetric, we
+ * only compute a single quadrant of it and so no doubling happens. We add 1 to make sure the
+ * filter size is always odd and there is a center weight. */
+ const float2 scale = math::safe_divide(float2(1.0f), radius);
+ const int2 size = int2(math::ceil(radius)) + int2(1);
+ Array<float> weights(size.x * size.y);
+
+ float sum = 0.0f;
+
+ /* First, compute the center weight. */
+ const float center_weight = RE_filter_value(type, 0.0f);
+ weights[0] = center_weight;
+ sum += center_weight;
+
+ /* Then, compute the weights along the positive x axis, making sure to add double the weight to
+ * the sum of weights because the filter is symmetric and we only loop over the positive half
+ * of the x axis. Skip the center weight already computed by dropping the front index. */
+ for (const int x : IndexRange(size.x).drop_front(1)) {
+ const float weight = RE_filter_value(type, x * scale.x);
+ weights[x] = weight;
+ sum += weight * 2.0f;
+ }
+
+ /* Then, compute the weights along the positive y axis, making sure to add double the weight to
+ * the sum of weights because the filter is symmetric and we only loop over the positive half
+ * of the y axis. Skip the center weight already computed by dropping the front index. */
+ for (const int y : IndexRange(size.y).drop_front(1)) {
+ const float weight = RE_filter_value(type, y * scale.y);
+ weights[size.x * y] = weight;
+ sum += weight * 2.0f;
+ }
+
+ /* Then, compute the other weights in the upper right quadrant, making sure to add quadruple
+ * the weight to the sum of weights because the filter is symmetric and we only loop over one
+ * quadrant of it. Skip the weights along the y and x axis already computed by dropping the
+ * front index. */
+ for (const int y : IndexRange(size.y).drop_front(1)) {
+ for (const int x : IndexRange(size.x).drop_front(1)) {
+ const float weight = RE_filter_value(type, math::length(float2(x, y) * scale));
+ weights[size.x * y + x] = weight;
+ sum += weight * 4.0f;
+ }
+ }
+
+ /* Finally, normalize the weights. */
+ for (const int y : IndexRange(size.y)) {
+ for (const int x : IndexRange(size.x)) {
+ weights[size.x * y + x] /= sum;
+ }
+ }
+
+ texture_ = GPU_texture_create_2d("Weights", size.x, size.y, 1, GPU_R16F, weights.data());
+
+ type_ = type;
+ radius_ = radius;
+ }
+
+ void bind_as_texture(GPUShader *shader, const char *texture_name)
+ {
+ const int texture_image_unit = GPU_shader_get_texture_binding(shader, texture_name);
+ GPU_texture_bind(texture_, texture_image_unit);
+ }
+
+ void unbind_as_texture()
+ {
+ GPU_texture_unbind(texture_);
+ }
+};
+
+class BlurOperation : public NodeOperation {
+ private:
+ /* Cached symmetric blur weights. */
+ SymmetricBlurWeights blur_weights_;
+ /* Cached symmetric blur weights for the separable horizontal pass. */
+ SymmetricSeparableBlurWeights blur_horizontal_weights_;
+ /* Cached symmetric blur weights for the separable vertical pass. */
+ SymmetricSeparableBlurWeights blur_vertical_weights_;
+
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ if (is_identity()) {
+ get_input("Image").pass_through(get_result("Image"));
+ return;
+ }
+
+ if (use_separable_filter()) {
+ GPUTexture *horizontal_pass_result = execute_separable_blur_horizontal_pass();
+ execute_separable_blur_vertical_pass(horizontal_pass_result);
+ }
+ else {
+ execute_blur();
+ }
+ }
+
+ void execute_blur()
+ {
+ GPUShader *shader = shader_manager().get("compositor_symmetric_blur");
+ GPU_shader_bind(shader);
+
+ GPU_shader_uniform_1b(shader, "extend_bounds", get_extend_bounds());
+ GPU_shader_uniform_1b(shader, "gamma_correct", node_storage(bnode()).gamma);
+
+ const Result &input_image = get_input("Image");
+ input_image.bind_as_texture(shader, "input_tx");
+
+ blur_weights_.update(compute_blur_radius(), node_storage(bnode()).filtertype);
+ blur_weights_.bind_as_texture(shader, "weights_tx");
+
+ Domain domain = compute_domain();
+ if (get_extend_bounds()) {
+ /* Add a radius amount of pixels in both sides of the image, hence the multiply by 2. */
+ domain.size += int2(math::ceil(compute_blur_radius())) * 2;
+ }
+
+ Result &output_image = get_result("Image");
+ output_image.allocate_texture(domain);
+ output_image.bind_as_image(shader, "output_img");
+
+ compute_dispatch_threads_at_least(shader, domain.size);
+
+ GPU_shader_unbind();
+ output_image.unbind_as_image();
+ input_image.unbind_as_texture();
+ blur_weights_.unbind_as_texture();
+ }
+
+ GPUTexture *execute_separable_blur_horizontal_pass()
+ {
+ GPUShader *shader = shader_manager().get("compositor_symmetric_separable_blur");
+ GPU_shader_bind(shader);
+
+ GPU_shader_uniform_1b(shader, "extend_bounds", get_extend_bounds());
+ GPU_shader_uniform_1b(shader, "gamma_correct_input", node_storage(bnode()).gamma);
+ GPU_shader_uniform_1b(shader, "gamma_uncorrect_output", false);
+
+ const Result &input_image = get_input("Image");
+ input_image.bind_as_texture(shader, "input_tx");
+
+ blur_horizontal_weights_.update(compute_blur_radius().x, node_storage(bnode()).filtertype);
+ blur_horizontal_weights_.bind_as_texture(shader, "weights_tx");
+
+ Domain domain = compute_domain();
+ if (get_extend_bounds()) {
+ domain.size.x += int(math::ceil(compute_blur_radius().x)) * 2;
+ }
+
+ /* We allocate an output image of a transposed size, that is, with a height equivalent to the
+ * width of the input and vice versa. This is done as a performance optimization. The shader
+ * will blur the image horizontally and write it to the intermediate output transposed. Then
+ * the vertical pass will execute the same horizontal blur shader, but since its input is
+ * transposed, it will effectively do a vertical blur and write to the output transposed,
+ * effectively undoing the transposition in the horizontal pass. This is done to improve
+ * spatial cache locality in the shader and to avoid having two separate shaders for each blur
+ * pass. */
+ const int2 transposed_domain = int2(domain.size.y, domain.size.x);
+
+ GPUTexture *horizontal_pass_result = texture_pool().acquire_color(transposed_domain);
+ const int image_unit = GPU_shader_get_texture_binding(shader, "output_img");
+ GPU_texture_image_bind(horizontal_pass_result, image_unit);
+
+ compute_dispatch_threads_at_least(shader, domain.size);
+
+ GPU_shader_unbind();
+ input_image.unbind_as_texture();
+ blur_horizontal_weights_.unbind_as_texture();
+ GPU_texture_image_unbind(horizontal_pass_result);
+
+ return horizontal_pass_result;
+ }
+
+ void execute_separable_blur_vertical_pass(GPUTexture *horizontal_pass_result)
+ {
+ GPUShader *shader = shader_manager().get("compositor_symmetric_separable_blur");
+ GPU_shader_bind(shader);
+
+ GPU_shader_uniform_1b(shader, "extend_bounds", get_extend_bounds());
+ GPU_shader_uniform_1b(shader, "gamma_correct_input", false);
+ GPU_shader_uniform_1b(shader, "gamma_uncorrect_output", node_storage(bnode()).gamma);
+
+ GPU_memory_barrier(GPU_BARRIER_TEXTURE_FETCH);
+ const int texture_image_unit = GPU_shader_get_texture_binding(shader, "input_tx");
+ GPU_texture_bind(horizontal_pass_result, texture_image_unit);
+
+ blur_vertical_weights_.update(compute_blur_radius().y, node_storage(bnode()).filtertype);
+ blur_vertical_weights_.bind_as_texture(shader, "weights_tx");
+
+ Domain domain = compute_domain();
+ if (get_extend_bounds()) {
+ /* Add a radius amount of pixels in both sides of the image, hence the multiply by 2. */
+ domain.size += int2(math::ceil(compute_blur_radius())) * 2;
+ }
+
+ Result &output_image = get_result("Image");
+ output_image.allocate_texture(domain);
+ output_image.bind_as_image(shader, "output_img");
+
+ /* Notice that the domain is transposed, see the note on the horizontal pass method for more
+ * information on the reasoning behind this. */
+ compute_dispatch_threads_at_least(shader, int2(domain.size.y, domain.size.x));
+
+ GPU_shader_unbind();
+ output_image.unbind_as_image();
+ blur_vertical_weights_.unbind_as_texture();
+ GPU_texture_unbind(horizontal_pass_result);
+ }
+
+ float2 compute_blur_radius()
+ {
+ const float size = math::clamp(get_input("Size").get_float_value_default(1.0f), 0.0f, 1.0f);
+
+ if (!node_storage(bnode()).relative) {
+ return float2(node_storage(bnode()).sizex, node_storage(bnode()).sizey) * size;
+ }
+
+ int2 image_size = get_input("Image").domain().size;
+ switch (node_storage(bnode()).aspect) {
+ case CMP_NODE_BLUR_ASPECT_Y:
+ image_size.y = image_size.x;
+ break;
+ case CMP_NODE_BLUR_ASPECT_X:
+ image_size.x = image_size.y;
+ break;
+ default:
+ BLI_assert(node_storage(bnode()).aspect == CMP_NODE_BLUR_ASPECT_NONE);
+ break;
+ }
+
+ return float2(image_size) * get_size_factor() * size;
+ }
+
+ /* Returns true if the operation does nothing and the input can be passed through. */
+ bool is_identity()
+ {
+ const Result &input = get_input("Image");
+ /* Single value inputs can't be blurred and are returned as is. */
+ if (input.is_single_value()) {
+ return true;
+ }
+
+ /* Zero blur radius. The operation does nothing and the input can be passed through. */
+ if (compute_blur_radius() == float2(0.0)) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /* The blur node can operate with different filter types, evaluated on the normalized distance to
+ * the center of the filter. Some of those filters are separable and can be computed as such. If
+ * the bokeh member is disabled in the node, then the filter is always computed as separable even
+ * if it is not in fact separable, in which case, the used filter is a cheaper approximation to
+ * the actual filter. If the bokeh member is enabled, then the filter is computed as separable if
+ * it is in fact separable and as a normal 2D filter otherwise. */
+ bool use_separable_filter()
+ {
+ if (!node_storage(bnode()).bokeh) {
+ return true;
+ }
+
+ /* Both Box and Gaussian filters are separable. The rest is not. */
+ switch (node_storage(bnode()).filtertype) {
+ case R_FILTER_BOX:
+ case R_FILTER_GAUSS:
+ case R_FILTER_FAST_GAUSS:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ float2 get_size_factor()
+ {
+ return float2(node_storage(bnode()).percentx, node_storage(bnode()).percenty) / 100.0f;
+ }
+
+ bool get_extend_bounds()
+ {
+ return bnode().custom1 & CMP_NODEFLAG_BLUR_EXTEND_BOUNDS;
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new BlurOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_blur_cc
void register_node_type_cmp_blur()
@@ -86,6 +504,7 @@ void register_node_type_cmp_blur()
node_type_init(&ntype, file_ns::node_composit_init_blur);
node_type_storage(
&ntype, "NodeBlurData", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_bokehblur.cc b/source/blender/nodes/composite/nodes/node_composite_bokehblur.cc
index a936bafe671..a581d87a463 100644
--- a/source/blender/nodes/composite/nodes/node_composite_bokehblur.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_bokehblur.cc
@@ -5,9 +5,17 @@
* \ingroup cmpnodes
*/
+#include "BLI_math_base.hh"
+#include "BLI_math_vec_types.hh"
+
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_texture.h"
+
+#include "COM_node_operation.hh"
+#include "COM_utilities.hh"
+
#include "node_composite_util.hh"
/* **************** BLUR ******************** */
@@ -16,20 +24,32 @@ namespace blender::nodes::node_composite_bokehblur_cc {
static void cmp_node_bokehblur_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({0.8f, 0.8f, 0.8f, 1.0f});
- b.add_input<decl::Color>(N_("Bokeh")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
- b.add_input<decl::Float>(N_("Size")).default_value(1.0f).min(0.0f).max(10.0f);
- b.add_input<decl::Float>(N_("Bounding box")).default_value(1.0f).min(0.0f).max(1.0f);
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({0.8f, 0.8f, 0.8f, 1.0f})
+ .compositor_domain_priority(0);
+ b.add_input<decl::Color>(N_("Bokeh"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_skip_realization();
+ b.add_input<decl::Float>(N_("Size"))
+ .default_value(1.0f)
+ .min(0.0f)
+ .max(10.0f)
+ .compositor_domain_priority(1);
+ b.add_input<decl::Float>(N_("Bounding box"))
+ .default_value(1.0f)
+ .min(0.0f)
+ .max(1.0f)
+ .compositor_domain_priority(2);
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_init_bokehblur(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_bokehblur(bNodeTree * /*ntree*/, bNode *node)
{
node->custom3 = 4.0f;
node->custom4 = 16.0f;
}
-static void node_composit_buts_bokehblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_bokehblur(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "use_variable_size", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
// uiItemR(layout, ptr, "f_stop", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE); /* UNUSED */
@@ -37,6 +57,153 @@ static void node_composit_buts_bokehblur(uiLayout *layout, bContext *UNUSED(C),
uiItemR(layout, ptr, "use_extended_bounds", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class BokehBlurOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ if (is_identity()) {
+ get_input("Image").pass_through(get_result("Image"));
+ return;
+ }
+
+ if (get_input("Size").is_single_value() || !get_variable_size()) {
+ execute_constant_size();
+ }
+ else {
+ execute_variable_size();
+ }
+ }
+
+ void execute_constant_size()
+ {
+ GPUShader *shader = shader_manager().get("compositor_blur");
+ GPU_shader_bind(shader);
+
+ GPU_shader_uniform_1i(shader, "radius", int(compute_blur_radius()));
+ GPU_shader_uniform_1b(shader, "extend_bounds", get_extend_bounds());
+
+ const Result &input_image = get_input("Image");
+ input_image.bind_as_texture(shader, "input_tx");
+
+ const Result &input_weights = get_input("Bokeh");
+ input_weights.bind_as_texture(shader, "weights_tx");
+
+ const Result &input_mask = get_input("Bounding box");
+ input_mask.bind_as_texture(shader, "mask_tx");
+
+ Domain domain = compute_domain();
+ if (get_extend_bounds()) {
+ /* Add a radius amount of pixels in both sides of the image, hence the multiply by 2. */
+ domain.size += int2(int(compute_blur_radius()) * 2);
+ }
+
+ Result &output_image = get_result("Image");
+ output_image.allocate_texture(domain);
+ output_image.bind_as_image(shader, "output_img");
+
+ compute_dispatch_threads_at_least(shader, domain.size);
+
+ GPU_shader_unbind();
+ output_image.unbind_as_image();
+ input_image.unbind_as_texture();
+ input_weights.unbind_as_texture();
+ input_mask.unbind_as_texture();
+ }
+
+ void execute_variable_size()
+ {
+ GPUShader *shader = shader_manager().get("compositor_blur_variable_size");
+ GPU_shader_bind(shader);
+
+ GPU_shader_uniform_1f(shader, "base_size", compute_blur_radius());
+ GPU_shader_uniform_1i(shader, "search_radius", get_max_size());
+
+ const Result &input_image = get_input("Image");
+ input_image.bind_as_texture(shader, "input_tx");
+
+ const Result &input_weights = get_input("Bokeh");
+ input_weights.bind_as_texture(shader, "weights_tx");
+
+ const Result &input_size = get_input("Size");
+ input_size.bind_as_texture(shader, "size_tx");
+
+ const Result &input_mask = get_input("Bounding box");
+ input_mask.bind_as_texture(shader, "mask_tx");
+
+ const Domain domain = compute_domain();
+ Result &output_image = get_result("Image");
+ output_image.allocate_texture(domain);
+ output_image.bind_as_image(shader, "output_img");
+
+ compute_dispatch_threads_at_least(shader, domain.size);
+
+ GPU_shader_unbind();
+ output_image.unbind_as_image();
+ input_image.unbind_as_texture();
+ input_weights.unbind_as_texture();
+ input_size.unbind_as_texture();
+ input_mask.unbind_as_texture();
+ }
+
+ float compute_blur_radius()
+ {
+ const int2 image_size = get_input("Image").domain().size;
+ const int max_size = math::max(image_size.x, image_size.y);
+
+ /* The [0, 10] range of the size is arbitrary and is merely in place to avoid very long
+ * computations of the bokeh blur. */
+ const float size = math::clamp(get_input("Size").get_float_value_default(1.0f), 0.0f, 10.0f);
+
+ /* The 100 divisor is arbitrary and was chosen using visual judgment. */
+ return size * (max_size / 100.0f);
+ }
+
+ bool is_identity()
+ {
+ const Result &input = get_input("Image");
+ if (input.is_single_value()) {
+ return true;
+ }
+
+ if (compute_blur_radius() == 0.0f) {
+ return true;
+ }
+
+ /* This input is, in fact, a boolean mask. If it is zero, no blurring will take place.
+ * Otherwise, the blurring will take place ignoring the value of the input entirely. */
+ const Result &bounding_box = get_input("Bounding box");
+ if (bounding_box.is_single_value() && bounding_box.get_float_value() == 0.0) {
+ return true;
+ }
+
+ return false;
+ }
+
+ bool get_extend_bounds()
+ {
+ return bnode().custom1 & CMP_NODEFLAG_BLUR_EXTEND_BOUNDS;
+ }
+
+ bool get_variable_size()
+ {
+ return bnode().custom1 & CMP_NODEFLAG_BLUR_VARIABLE_SIZE;
+ }
+
+ int get_max_size()
+ {
+ return static_cast<int>(bnode().custom4);
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new BokehBlurOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_bokehblur_cc
void register_node_type_cmp_bokehblur()
@@ -49,6 +216,7 @@ void register_node_type_cmp_bokehblur()
ntype.declare = file_ns::cmp_node_bokehblur_declare;
ntype.draw_buttons = file_ns::node_composit_buts_bokehblur;
node_type_init(&ntype, file_ns::node_composit_init_bokehblur);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_bokehimage.cc b/source/blender/nodes/composite/nodes/node_composite_bokehimage.cc
index 8330c56736a..eb35b933d1b 100644
--- a/source/blender/nodes/composite/nodes/node_composite_bokehimage.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_bokehimage.cc
@@ -5,21 +5,31 @@
* \ingroup cmpnodes
*/
+#include "BLI_math_base.h"
+#include "BLI_math_vec_types.hh"
+
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_shader.h"
+
+#include "COM_node_operation.hh"
+#include "COM_utilities.hh"
+
#include "node_composite_util.hh"
/* **************** Bokeh image Tools ******************** */
namespace blender::nodes::node_composite_bokehimage_cc {
+NODE_STORAGE_FUNCS(NodeBokehImage)
+
static void cmp_node_bokehimage_declare(NodeDeclarationBuilder &b)
{
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_init_bokehimage(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_bokehimage(bNodeTree * /*ntree*/, bNode *node)
{
NodeBokehImage *data = MEM_cnew<NodeBokehImage>(__func__);
data->angle = 0.0f;
@@ -30,7 +40,7 @@ static void node_composit_init_bokehimage(bNodeTree *UNUSED(ntree), bNode *node)
node->storage = data;
}
-static void node_composit_buts_bokehimage(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_bokehimage(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "flaps", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
uiItemR(layout, ptr, "angle", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
@@ -45,6 +55,61 @@ static void node_composit_buts_bokehimage(uiLayout *layout, bContext *UNUSED(C),
uiItemR(layout, ptr, "shift", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class BokehImageOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ GPUShader *shader = shader_manager().get("compositor_bokeh_image");
+ GPU_shader_bind(shader);
+
+ GPU_shader_uniform_1f(shader, "exterior_angle", get_exterior_angle());
+ GPU_shader_uniform_1f(shader, "rotation", get_rotation());
+ GPU_shader_uniform_1f(shader, "roundness", node_storage(bnode()).rounding);
+ GPU_shader_uniform_1f(shader, "catadioptric", node_storage(bnode()).catadioptric);
+ GPU_shader_uniform_1f(shader, "lens_shift", node_storage(bnode()).lensshift);
+
+ Result &output = get_result("Image");
+ const Domain domain = compute_domain();
+ output.allocate_texture(domain);
+ output.bind_as_image(shader, "output_img");
+
+ compute_dispatch_threads_at_least(shader, domain.size);
+
+ output.unbind_as_image();
+ GPU_shader_unbind();
+ }
+
+ Domain compute_domain() override
+ {
+ return Domain(int2(512));
+ }
+
+ /* The exterior angle is the angle between each two consecutive vertices of the regular polygon
+ * from its center. */
+ float get_exterior_angle()
+ {
+ return (M_PI * 2.0f) / node_storage(bnode()).flaps;
+ }
+
+ float get_rotation()
+ {
+ /* Offset the rotation such that the second vertex of the regular polygon lies on the positive
+ * y axis, which is 90 degrees minus the angle that it makes with the positive x axis assuming
+ * the first vertex lies on the positive x axis. */
+ const float offset = M_PI_2 - get_exterior_angle();
+ return node_storage(bnode()).angle - offset;
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new BokehImageOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_bokehimage_cc
void register_node_type_cmp_bokehimage()
@@ -60,6 +125,7 @@ void register_node_type_cmp_bokehimage()
node_type_init(&ntype, file_ns::node_composit_init_bokehimage);
node_type_storage(
&ntype, "NodeBokehImage", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_boxmask.cc b/source/blender/nodes/composite/nodes/node_composite_boxmask.cc
index f39b69c63f2..668dc9d92de 100644
--- a/source/blender/nodes/composite/nodes/node_composite_boxmask.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_boxmask.cc
@@ -5,15 +5,26 @@
* \ingroup cmpnodes
*/
+#include <cmath>
+
+#include "BLI_math_vec_types.hh"
+
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_shader.h"
+
+#include "COM_node_operation.hh"
+#include "COM_utilities.hh"
+
#include "node_composite_util.hh"
/* **************** SCALAR MATH ******************** */
namespace blender::nodes::node_composite_boxmask_cc {
+NODE_STORAGE_FUNCS(NodeBoxMask)
+
static void cmp_node_boxmask_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Float>(N_("Mask")).default_value(0.0f).min(0.0f).max(1.0f);
@@ -21,7 +32,7 @@ static void cmp_node_boxmask_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("Mask"));
}
-static void node_composit_init_boxmask(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_boxmask(bNodeTree * /*ntree*/, bNode *node)
{
NodeBoxMask *data = MEM_cnew<NodeBoxMask>(__func__);
data->x = 0.5;
@@ -32,7 +43,7 @@ static void node_composit_init_boxmask(bNodeTree *UNUSED(ntree), bNode *node)
node->storage = data;
}
-static void node_composit_buts_boxmask(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_boxmask(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *row;
@@ -48,6 +59,93 @@ static void node_composit_buts_boxmask(uiLayout *layout, bContext *UNUSED(C), Po
uiItemR(layout, ptr, "mask_type", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class BoxMaskOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ GPUShader *shader = shader_manager().get(get_shader_name());
+ GPU_shader_bind(shader);
+
+ const Domain domain = compute_domain();
+
+ GPU_shader_uniform_2iv(shader, "domain_size", domain.size);
+
+ GPU_shader_uniform_2fv(shader, "location", get_location());
+ GPU_shader_uniform_2fv(shader, "size", get_size() / 2.0f);
+ GPU_shader_uniform_1f(shader, "cos_angle", std::cos(get_angle()));
+ GPU_shader_uniform_1f(shader, "sin_angle", std::sin(get_angle()));
+
+ const Result &input_mask = get_input("Mask");
+ input_mask.bind_as_texture(shader, "base_mask_tx");
+
+ const Result &value = get_input("Value");
+ value.bind_as_texture(shader, "mask_value_tx");
+
+ Result &output_mask = get_result("Mask");
+ output_mask.allocate_texture(domain);
+ output_mask.bind_as_image(shader, "output_mask_img");
+
+ compute_dispatch_threads_at_least(shader, domain.size);
+
+ input_mask.unbind_as_texture();
+ value.unbind_as_texture();
+ output_mask.unbind_as_image();
+ GPU_shader_unbind();
+ }
+
+ Domain compute_domain() override
+ {
+ if (get_input("Mask").is_single_value()) {
+ return Domain(context().get_output_size());
+ }
+ return get_input("Mask").domain();
+ }
+
+ CMPNodeMaskType get_mask_type()
+ {
+ return (CMPNodeMaskType)bnode().custom1;
+ }
+
+ const char *get_shader_name()
+ {
+ switch (get_mask_type()) {
+ default:
+ case CMP_NODE_MASKTYPE_ADD:
+ return "compositor_box_mask_add";
+ case CMP_NODE_MASKTYPE_SUBTRACT:
+ return "compositor_box_mask_subtract";
+ case CMP_NODE_MASKTYPE_MULTIPLY:
+ return "compositor_box_mask_multiply";
+ case CMP_NODE_MASKTYPE_NOT:
+ return "compositor_box_mask_not";
+ }
+ }
+
+ float2 get_location()
+ {
+ return float2(node_storage(bnode()).x, node_storage(bnode()).y);
+ }
+
+ float2 get_size()
+ {
+ return float2(node_storage(bnode()).width, node_storage(bnode()).height);
+ }
+
+ float get_angle()
+ {
+ return node_storage(bnode()).rotation;
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new BoxMaskOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_boxmask_cc
void register_node_type_cmp_boxmask()
@@ -61,6 +159,7 @@ void register_node_type_cmp_boxmask()
ntype.draw_buttons = file_ns::node_composit_buts_boxmask;
node_type_init(&ntype, file_ns::node_composit_init_boxmask);
node_type_storage(&ntype, "NodeBoxMask", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_brightness.cc b/source/blender/nodes/composite/nodes/node_composite_brightness.cc
index 65ed2885d9b..6b9fef75524 100644
--- a/source/blender/nodes/composite/nodes/node_composite_brightness.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_brightness.cc
@@ -8,6 +8,10 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* **************** Bright and Contrast ******************** */
@@ -16,24 +20,56 @@ namespace blender::nodes::node_composite_brightness_cc {
static void cmp_node_brightcontrast_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
- b.add_input<decl::Float>(N_("Bright")).min(-100.0f).max(100.0f);
- b.add_input<decl::Float>(N_("Contrast")).min(-100.0f).max(100.0f);
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
+ b.add_input<decl::Float>(N_("Bright")).min(-100.0f).max(100.0f).compositor_domain_priority(1);
+ b.add_input<decl::Float>(N_("Contrast")).min(-100.0f).max(100.0f).compositor_domain_priority(2);
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_init_brightcontrast(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_brightcontrast(bNodeTree * /*ntree*/, bNode *node)
{
node->custom1 = 1;
}
-static void node_composit_buts_brightcontrast(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
+static void node_composit_buts_brightcontrast(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "use_premultiply", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class BrightContrastShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ const float use_premultiply = get_use_premultiply();
+
+ GPU_stack_link(material,
+ &bnode(),
+ "node_composite_bright_contrast",
+ inputs,
+ outputs,
+ GPU_constant(&use_premultiply));
+ }
+
+ bool get_use_premultiply()
+ {
+ return bnode().custom1;
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new BrightContrastShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_brightness_cc
void register_node_type_cmp_brightcontrast()
@@ -46,6 +82,7 @@ void register_node_type_cmp_brightcontrast()
ntype.declare = file_ns::cmp_node_brightcontrast_declare;
ntype.draw_buttons = file_ns::node_composit_buts_brightcontrast;
node_type_init(&ntype, file_ns::node_composit_init_brightcontrast);
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_channel_matte.cc b/source/blender/nodes/composite/nodes/node_composite_channel_matte.cc
index 627f07fdfce..2fd2d6c8f71 100644
--- a/source/blender/nodes/composite/nodes/node_composite_channel_matte.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_channel_matte.cc
@@ -10,20 +10,28 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* ******************* Channel Matte Node ********************************* */
namespace blender::nodes::node_composite_channel_matte_cc {
+NODE_STORAGE_FUNCS(NodeChroma)
+
static void cmp_node_channel_matte_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
b.add_output<decl::Color>(N_("Image"));
b.add_output<decl::Float>(N_("Matte"));
}
-static void node_composit_init_channel_matte(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_channel_matte(bNodeTree * /*ntree*/, bNode *node)
{
NodeChroma *c = MEM_cnew<NodeChroma>(__func__);
node->storage = c;
@@ -38,9 +46,7 @@ static void node_composit_init_channel_matte(bNodeTree *UNUSED(ntree), bNode *no
node->custom2 = 2; /* Green Channel. */
}
-static void node_composit_buts_channel_matte(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
+static void node_composit_buts_channel_matte(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col, *row;
@@ -79,6 +85,91 @@ static void node_composit_buts_channel_matte(uiLayout *layout,
col, ptr, "limit_min", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class ChannelMatteShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ const float color_space = get_color_space();
+ const float matte_channel = get_matte_channel();
+ float limit_channels[2];
+ get_limit_channels(limit_channels);
+ const float max_limit = get_max_limit();
+ const float min_limit = get_min_limit();
+
+ GPU_stack_link(material,
+ &bnode(),
+ "node_composite_channel_matte",
+ inputs,
+ outputs,
+ GPU_constant(&color_space),
+ GPU_constant(&matte_channel),
+ GPU_constant(limit_channels),
+ GPU_uniform(&max_limit),
+ GPU_uniform(&min_limit));
+ }
+
+ /* 1 -> CMP_NODE_CHANNEL_MATTE_CS_RGB
+ * 2 -> CMP_NODE_CHANNEL_MATTE_CS_HSV
+ * 3 -> CMP_NODE_CHANNEL_MATTE_CS_YUV
+ * 4 -> CMP_NODE_CHANNEL_MATTE_CS_YCC */
+ int get_color_space()
+ {
+ return bnode().custom1;
+ }
+
+ /* Get the index of the channel used to generate the matte. */
+ int get_matte_channel()
+ {
+ return bnode().custom2 - 1;
+ }
+
+ /* Get the index of the channel used to compute the limit value. */
+ int get_limit_channel()
+ {
+ return node_storage(bnode()).channel - 1;
+ }
+
+ /* Get the indices of the channels used to compute the limit value. We always assume the limit
+ * algorithm is Max, if it is a single limit channel, store it in both limit channels, because
+ * the maximum of two identical values is the same value. */
+ void get_limit_channels(float limit_channels[2])
+ {
+ if (node_storage(bnode()).algorithm == CMP_NODE_CHANNEL_MATTE_LIMIT_ALGORITHM_MAX) {
+ /* If the algorithm is Max, store the indices of the other two channels other than the matte
+ * channel. */
+ limit_channels[0] = (get_matte_channel() + 1) % 3;
+ limit_channels[1] = (get_matte_channel() + 2) % 3;
+ }
+ else {
+ /* If the algorithm is Single, store the index of the limit channel in both channels. */
+ limit_channels[0] = get_limit_channel();
+ limit_channels[1] = get_limit_channel();
+ }
+ }
+
+ float get_max_limit()
+ {
+ return node_storage(bnode()).t1;
+ }
+
+ float get_min_limit()
+ {
+ return node_storage(bnode()).t2;
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new ChannelMatteShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_channel_matte_cc
void register_node_type_cmp_channel_matte()
@@ -93,6 +184,7 @@ void register_node_type_cmp_channel_matte()
ntype.flag |= NODE_PREVIEW;
node_type_init(&ntype, file_ns::node_composit_init_channel_matte);
node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_chroma_matte.cc b/source/blender/nodes/composite/nodes/node_composite_chroma_matte.cc
index 69319c6825d..e2ef96ea95e 100644
--- a/source/blender/nodes/composite/nodes/node_composite_chroma_matte.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_chroma_matte.cc
@@ -5,26 +5,38 @@
* \ingroup cmpnodes
*/
+#include <cmath>
+
#include "BLI_math_rotation.h"
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* ******************* Chroma Key ********************************************************** */
namespace blender::nodes::node_composite_chroma_matte_cc {
+NODE_STORAGE_FUNCS(NodeChroma)
+
static void cmp_node_chroma_matte_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
- b.add_input<decl::Color>(N_("Key Color")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
+ b.add_input<decl::Color>(N_("Key Color"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(1);
b.add_output<decl::Color>(N_("Image"));
b.add_output<decl::Float>(N_("Matte"));
}
-static void node_composit_init_chroma_matte(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_chroma_matte(bNodeTree * /*ntree*/, bNode *node)
{
NodeChroma *c = MEM_cnew<NodeChroma>(__func__);
node->storage = c;
@@ -35,7 +47,7 @@ static void node_composit_init_chroma_matte(bNodeTree *UNUSED(ntree), bNode *nod
c->fstrength = 1.0f;
}
-static void node_composit_buts_chroma_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_chroma_matte(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col;
@@ -51,6 +63,52 @@ static void node_composit_buts_chroma_matte(uiLayout *layout, bContext *UNUSED(C
// uiItemR(col, ptr, "shadow_adjust", UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class ChromaMatteShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ const float acceptance = get_acceptance();
+ const float cutoff = get_cutoff();
+ const float falloff = get_falloff();
+
+ GPU_stack_link(material,
+ &bnode(),
+ "node_composite_chroma_matte",
+ inputs,
+ outputs,
+ GPU_uniform(&acceptance),
+ GPU_uniform(&cutoff),
+ GPU_uniform(&falloff));
+ }
+
+ float get_acceptance()
+ {
+ return std::tan(node_storage(bnode()).t1) / 2.0f;
+ }
+
+ float get_cutoff()
+ {
+ return node_storage(bnode()).t2;
+ }
+
+ float get_falloff()
+ {
+ return node_storage(bnode()).fstrength;
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new ChromaMatteShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_chroma_matte_cc
void register_node_type_cmp_chroma_matte()
@@ -65,6 +123,7 @@ void register_node_type_cmp_chroma_matte()
ntype.flag |= NODE_PREVIEW;
node_type_init(&ntype, file_ns::node_composit_init_chroma_matte);
node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_color_matte.cc b/source/blender/nodes/composite/nodes/node_composite_color_matte.cc
index 474fb1b72f2..2a20a4d995f 100644
--- a/source/blender/nodes/composite/nodes/node_composite_color_matte.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_color_matte.cc
@@ -8,21 +8,31 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* ******************* Color Matte ********************************************************** */
namespace blender::nodes::node_composite_color_matte_cc {
+NODE_STORAGE_FUNCS(NodeChroma)
+
static void cmp_node_color_matte_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
- b.add_input<decl::Color>(N_("Key Color")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
+ b.add_input<decl::Color>(N_("Key Color"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(1);
b.add_output<decl::Color>(N_("Image"));
b.add_output<decl::Float>(N_("Matte"));
}
-static void node_composit_init_color_matte(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_color_matte(bNodeTree * /*ntree*/, bNode *node)
{
NodeChroma *c = MEM_cnew<NodeChroma>(__func__);
node->storage = c;
@@ -33,7 +43,7 @@ static void node_composit_init_color_matte(bNodeTree *UNUSED(ntree), bNode *node
c->fstrength = 1.0f;
}
-static void node_composit_buts_color_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_color_matte(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col;
@@ -50,6 +60,53 @@ static void node_composit_buts_color_matte(uiLayout *layout, bContext *UNUSED(C)
col, ptr, "color_value", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class ColorMatteShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ const float hue_epsilon = get_hue_epsilon();
+ const float saturation_epsilon = get_saturation_epsilon();
+ const float value_epsilon = get_value_epsilon();
+
+ GPU_stack_link(material,
+ &bnode(),
+ "node_composite_color_matte",
+ inputs,
+ outputs,
+ GPU_uniform(&hue_epsilon),
+ GPU_uniform(&saturation_epsilon),
+ GPU_uniform(&value_epsilon));
+ }
+
+ float get_hue_epsilon()
+ {
+ /* Divide by 2 because the hue wraps around. */
+ return node_storage(bnode()).t1 / 2.0f;
+ }
+
+ float get_saturation_epsilon()
+ {
+ return node_storage(bnode()).t2;
+ }
+
+ float get_value_epsilon()
+ {
+ return node_storage(bnode()).t3;
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new ColorMatteShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_color_matte_cc
void register_node_type_cmp_color_matte()
@@ -64,6 +121,7 @@ void register_node_type_cmp_color_matte()
ntype.flag |= NODE_PREVIEW;
node_type_init(&ntype, file_ns::node_composit_init_color_matte);
node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_color_spill.cc b/source/blender/nodes/composite/nodes/node_composite_color_spill.cc
index 9ad5dfbaeb2..ba829da83ed 100644
--- a/source/blender/nodes/composite/nodes/node_composite_color_spill.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_color_spill.cc
@@ -10,31 +10,44 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* ******************* Color Spill Suppression ********************************* */
namespace blender::nodes::node_composite_color_spill_cc {
+NODE_STORAGE_FUNCS(NodeColorspill)
+
static void cmp_node_color_spill_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
- b.add_input<decl::Float>(N_("Fac")).default_value(1.0f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
+ b.add_input<decl::Float>(N_("Fac"))
+ .default_value(1.0f)
+ .min(0.0f)
+ .max(1.0f)
+ .subtype(PROP_FACTOR)
+ .compositor_domain_priority(1);
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_init_color_spill(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_color_spill(bNodeTree * /*ntree*/, bNode *node)
{
NodeColorspill *ncs = MEM_cnew<NodeColorspill>(__func__);
node->storage = ncs;
+ node->custom2 = CMP_NODE_COLOR_SPILL_LIMIT_ALGORITHM_SINGLE;
node->custom1 = 2; /* green channel */
- node->custom2 = 0; /* simple limit algorithm */
ncs->limchan = 0; /* limit by red */
ncs->limscale = 1.0f; /* limit scaling factor */
ncs->unspill = 0; /* do not use unspill */
}
-static void node_composit_buts_color_spill(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_color_spill(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *row, *col;
@@ -80,6 +93,98 @@ static void node_composit_buts_color_spill(uiLayout *layout, bContext *UNUSED(C)
}
}
+using namespace blender::realtime_compositor;
+
+class ColorSpillShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ const float spill_channel = get_spill_channel();
+ float spill_scale[3];
+ get_spill_scale(spill_scale);
+ float limit_channels[2];
+ get_limit_channels(limit_channels);
+ const float limit_scale = get_limit_scale();
+
+ GPU_stack_link(material,
+ &bnode(),
+ "node_composite_color_spill",
+ inputs,
+ outputs,
+ GPU_constant(&spill_channel),
+ GPU_uniform(spill_scale),
+ GPU_constant(limit_channels),
+ GPU_uniform(&limit_scale));
+ }
+
+ /* Get the index of the channel used for spilling. */
+ int get_spill_channel()
+ {
+ return bnode().custom1 - 1;
+ }
+
+ CMPNodeColorSpillLimitAlgorithm get_limit_algorithm()
+ {
+ return (CMPNodeColorSpillLimitAlgorithm)bnode().custom2;
+ }
+
+ void get_spill_scale(float spill_scale[3])
+ {
+ const NodeColorspill &node_color_spill = node_storage(bnode());
+ if (node_color_spill.unspill) {
+ spill_scale[0] = node_color_spill.uspillr;
+ spill_scale[1] = node_color_spill.uspillg;
+ spill_scale[2] = node_color_spill.uspillb;
+ spill_scale[get_spill_channel()] *= -1.0f;
+ }
+ else {
+ spill_scale[0] = 0.0f;
+ spill_scale[1] = 0.0f;
+ spill_scale[2] = 0.0f;
+ spill_scale[get_spill_channel()] = -1.0f;
+ }
+ }
+
+ /* Get the index of the channel used for limiting. */
+ int get_limit_channel()
+ {
+ return node_storage(bnode()).limchan;
+ }
+
+ /* Get the indices of the channels used to compute the limit value. We always assume the limit
+ * algorithm is Average, if it is a single limit channel, store it in both limit channels,
+ * because the average of two identical values is the same value. */
+ void get_limit_channels(float limit_channels[2])
+ {
+ if (get_limit_algorithm() == CMP_NODE_COLOR_SPILL_LIMIT_ALGORITHM_AVERAGE) {
+ /* If the algorithm is Average, store the indices of the other two channels other than the
+ * spill channel. */
+ limit_channels[0] = (get_spill_channel() + 1) % 3;
+ limit_channels[1] = (get_spill_channel() + 2) % 3;
+ }
+ else {
+ /* If the algorithm is Single, store the index of the limit channel in both channels. */
+ limit_channels[0] = get_limit_channel();
+ limit_channels[1] = get_limit_channel();
+ }
+ }
+
+ float get_limit_scale()
+ {
+ return node_storage(bnode()).limscale;
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new ColorSpillShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_color_spill_cc
void register_node_type_cmp_color_spill()
@@ -94,6 +199,7 @@ void register_node_type_cmp_color_spill()
node_type_init(&ntype, file_ns::node_composit_init_color_spill);
node_type_storage(
&ntype, "NodeColorspill", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_colorbalance.cc b/source/blender/nodes/composite/nodes/node_composite_colorbalance.cc
index dd081c8fc12..3300896bfdf 100644
--- a/source/blender/nodes/composite/nodes/node_composite_colorbalance.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_colorbalance.cc
@@ -10,6 +10,10 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* ******************* Color Balance ********************************* */
@@ -19,7 +23,7 @@
* (sRGB conversion happens for LGG),
* but this keeps settings comparable. */
-void ntreeCompositColorBalanceSyncFromLGG(bNodeTree *UNUSED(ntree), bNode *node)
+void ntreeCompositColorBalanceSyncFromLGG(bNodeTree * /*ntree*/, bNode *node)
{
NodeColorBalance *n = (NodeColorBalance *)node->storage;
@@ -30,7 +34,7 @@ void ntreeCompositColorBalanceSyncFromLGG(bNodeTree *UNUSED(ntree), bNode *node)
}
}
-void ntreeCompositColorBalanceSyncFromCDL(bNodeTree *UNUSED(ntree), bNode *node)
+void ntreeCompositColorBalanceSyncFromCDL(bNodeTree * /*ntree*/, bNode *node)
{
NodeColorBalance *n = (NodeColorBalance *)node->storage;
@@ -44,14 +48,23 @@ void ntreeCompositColorBalanceSyncFromCDL(bNodeTree *UNUSED(ntree), bNode *node)
namespace blender::nodes::node_composite_colorbalance_cc {
+NODE_STORAGE_FUNCS(NodeColorBalance)
+
static void cmp_node_colorbalance_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Float>(N_("Fac")).default_value(1.0f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Float>(N_("Fac"))
+ .default_value(1.0f)
+ .min(0.0f)
+ .max(1.0f)
+ .subtype(PROP_FACTOR)
+ .compositor_domain_priority(1);
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_init_colorbalance(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_colorbalance(bNodeTree * /*ntree*/, bNode *node)
{
NodeColorBalance *n = MEM_cnew<NodeColorBalance>(__func__);
@@ -65,13 +78,13 @@ static void node_composit_init_colorbalance(bNodeTree *UNUSED(ntree), bNode *nod
node->storage = n;
}
-static void node_composit_buts_colorbalance(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_colorbalance(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *split, *col, *row;
uiItemR(layout, ptr, "correction_method", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
- if (RNA_enum_get(ptr, "correction_method") == 0) {
+ if (RNA_enum_get(ptr, "correction_method") == CMP_NODE_COLOR_BALANCE_LGG) {
split = uiLayoutSplit(layout, 0.0f, false);
col = uiLayoutColumn(split, false);
@@ -110,13 +123,11 @@ static void node_composit_buts_colorbalance(uiLayout *layout, bContext *UNUSED(C
}
}
-static void node_composit_buts_colorbalance_ex(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
+static void node_composit_buts_colorbalance_ex(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "correction_method", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
- if (RNA_enum_get(ptr, "correction_method") == 0) {
+ if (RNA_enum_get(ptr, "correction_method") == CMP_NODE_COLOR_BALANCE_LGG) {
uiTemplateColorPicker(layout, ptr, "lift", true, true, false, true);
uiItemR(layout, ptr, "lift", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
@@ -139,6 +150,53 @@ static void node_composit_buts_colorbalance_ex(uiLayout *layout,
}
}
+using namespace blender::realtime_compositor;
+
+class ColorBalanceShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ const NodeColorBalance &node_color_balance = node_storage(bnode());
+
+ if (get_color_balance_method() == CMP_NODE_COLOR_BALANCE_LGG) {
+ GPU_stack_link(material,
+ &bnode(),
+ "node_composite_color_balance_lgg",
+ inputs,
+ outputs,
+ GPU_uniform(node_color_balance.lift),
+ GPU_uniform(node_color_balance.gamma),
+ GPU_uniform(node_color_balance.gain));
+ return;
+ }
+
+ GPU_stack_link(material,
+ &bnode(),
+ "node_composite_color_balance_asc_cdl",
+ inputs,
+ outputs,
+ GPU_uniform(node_color_balance.offset),
+ GPU_uniform(node_color_balance.power),
+ GPU_uniform(node_color_balance.slope),
+ GPU_uniform(&node_color_balance.offset_basis));
+ }
+
+ CMPNodeColorBalanceMethod get_color_balance_method()
+ {
+ return (CMPNodeColorBalanceMethod)bnode().custom1;
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new ColorBalanceShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_colorbalance_cc
void register_node_type_cmp_colorbalance()
@@ -155,6 +213,7 @@ void register_node_type_cmp_colorbalance()
node_type_init(&ntype, file_ns::node_composit_init_colorbalance);
node_type_storage(
&ntype, "NodeColorBalance", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_colorcorrection.cc b/source/blender/nodes/composite/nodes/node_composite_colorcorrection.cc
index 39ecd277cec..c6051a42df6 100644
--- a/source/blender/nodes/composite/nodes/node_composite_colorcorrection.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_colorcorrection.cc
@@ -5,23 +5,37 @@
* \ingroup cmpnodes
*/
+#include "IMB_colormanagement.h"
+
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* ******************* Color Correction ********************************* */
namespace blender::nodes::node_composite_colorcorrection_cc {
+NODE_STORAGE_FUNCS(NodeColorCorrection)
+
static void cmp_node_colorcorrection_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
- b.add_input<decl::Float>(N_("Mask")).default_value(1.0f).min(0.0f).max(1.0f);
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
+ b.add_input<decl::Float>(N_("Mask"))
+ .default_value(1.0f)
+ .min(0.0f)
+ .max(1.0f)
+ .compositor_domain_priority(1);
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_init_colorcorrection(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_colorcorrection(bNodeTree * /*ntree*/, bNode *node)
{
NodeColorCorrection *n = MEM_cnew<NodeColorCorrection>(__func__);
n->startmidtones = 0.2f;
@@ -50,9 +64,7 @@ static void node_composit_init_colorcorrection(bNodeTree *UNUSED(ntree), bNode *
node->storage = n;
}
-static void node_composit_buts_colorcorrection(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
+static void node_composit_buts_colorcorrection(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *row;
@@ -141,7 +153,7 @@ static void node_composit_buts_colorcorrection(uiLayout *layout,
}
static void node_composit_buts_colorcorrection_ex(uiLayout *layout,
- bContext *UNUSED(C),
+ bContext * /*C*/,
PointerRNA *ptr)
{
uiLayout *row;
@@ -266,6 +278,68 @@ static void node_composit_buts_colorcorrection_ex(uiLayout *layout,
uiItemR(row, ptr, "midtones_end", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class ColorCorrectionShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ float enabled_channels[3];
+ get_enabled_channels(enabled_channels);
+ float luminance_coefficients[3];
+ IMB_colormanagement_get_luminance_coefficients(luminance_coefficients);
+
+ const NodeColorCorrection &node_color_correction = node_storage(bnode());
+
+ GPU_stack_link(material,
+ &bnode(),
+ "node_composite_color_correction",
+ inputs,
+ outputs,
+ GPU_constant(enabled_channels),
+ GPU_uniform(&node_color_correction.startmidtones),
+ GPU_uniform(&node_color_correction.endmidtones),
+ GPU_uniform(&node_color_correction.master.saturation),
+ GPU_uniform(&node_color_correction.master.contrast),
+ GPU_uniform(&node_color_correction.master.gamma),
+ GPU_uniform(&node_color_correction.master.gain),
+ GPU_uniform(&node_color_correction.master.lift),
+ GPU_uniform(&node_color_correction.shadows.saturation),
+ GPU_uniform(&node_color_correction.shadows.contrast),
+ GPU_uniform(&node_color_correction.shadows.gamma),
+ GPU_uniform(&node_color_correction.shadows.gain),
+ GPU_uniform(&node_color_correction.shadows.lift),
+ GPU_uniform(&node_color_correction.midtones.saturation),
+ GPU_uniform(&node_color_correction.midtones.contrast),
+ GPU_uniform(&node_color_correction.midtones.gamma),
+ GPU_uniform(&node_color_correction.midtones.gain),
+ GPU_uniform(&node_color_correction.midtones.lift),
+ GPU_uniform(&node_color_correction.highlights.saturation),
+ GPU_uniform(&node_color_correction.highlights.contrast),
+ GPU_uniform(&node_color_correction.highlights.gamma),
+ GPU_uniform(&node_color_correction.highlights.gain),
+ GPU_uniform(&node_color_correction.highlights.lift),
+ GPU_constant(luminance_coefficients));
+ }
+
+ void get_enabled_channels(float enabled_channels[3])
+ {
+ for (int i = 0; i < 3; i++) {
+ enabled_channels[i] = (bnode().custom1 & (1 << i)) ? 1.0f : 0.0f;
+ }
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new ColorCorrectionShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_colorcorrection_cc
void register_node_type_cmp_colorcorrection()
@@ -282,6 +356,7 @@ void register_node_type_cmp_colorcorrection()
node_type_init(&ntype, file_ns::node_composit_init_colorcorrection);
node_type_storage(
&ntype, "NodeColorCorrection", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_composite.cc b/source/blender/nodes/composite/nodes/node_composite_composite.cc
index d35ce7dc11a..24fe4e2d986 100644
--- a/source/blender/nodes/composite/nodes/node_composite_composite.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_composite.cc
@@ -5,9 +5,18 @@
* \ingroup cmpnodes
*/
+#include "BLI_math_vec_types.hh"
+
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_shader.h"
+#include "GPU_state.h"
+#include "GPU_texture.h"
+
+#include "COM_node_operation.hh"
+#include "COM_utilities.hh"
+
#include "node_composite_util.hh"
/* **************** COMPOSITE ******************** */
@@ -21,11 +30,130 @@ static void cmp_node_composite_declare(NodeDeclarationBuilder &b)
b.add_input<decl::Float>(N_("Z")).default_value(1.0f).min(0.0f).max(1.0f);
}
-static void node_composit_buts_composite(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_composite(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "use_alpha", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class CompositeOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ const Result &image = get_input("Image");
+ const Result &alpha = get_input("Alpha");
+
+ if (image.is_single_value() && alpha.is_single_value()) {
+ execute_clear();
+ }
+ else if (ignore_alpha()) {
+ execute_ignore_alpha();
+ }
+ else if (!node().input_by_identifier("Alpha")->is_logically_linked()) {
+ execute_copy();
+ }
+ else {
+ execute_set_alpha();
+ }
+ }
+
+ /* Executes when all inputs are single values, in which case, the output texture can just be
+ * cleared to the appropriate color. */
+ void execute_clear()
+ {
+ const Result &image = get_input("Image");
+ const Result &alpha = get_input("Alpha");
+
+ float4 color = image.get_color_value();
+ if (ignore_alpha()) {
+ color.w = 1.0f;
+ }
+ else if (node().input_by_identifier("Alpha")->is_logically_linked()) {
+ color.w = alpha.get_float_value();
+ }
+
+ GPU_texture_clear(context().get_output_texture(), GPU_DATA_FLOAT, color);
+ }
+
+ /* Executes when the alpha channel of the image is ignored. */
+ void execute_ignore_alpha()
+ {
+ GPUShader *shader = shader_manager().get("compositor_convert_color_to_opaque");
+ GPU_shader_bind(shader);
+
+ const Result &image = get_input("Image");
+ image.bind_as_texture(shader, "input_tx");
+
+ GPUTexture *output_texture = context().get_output_texture();
+ const int image_unit = GPU_shader_get_texture_binding(shader, "output_img");
+ GPU_texture_image_bind(output_texture, image_unit);
+
+ compute_dispatch_threads_at_least(shader, compute_domain().size);
+
+ image.unbind_as_texture();
+ GPU_texture_image_unbind(output_texture);
+ GPU_shader_unbind();
+ }
+
+ /* Executes when the image texture is written with no adjustments and can thus be copied directly
+ * to the output texture. */
+ void execute_copy()
+ {
+ const Result &image = get_input("Image");
+
+ /* Make sure any prior writes to the texture are reflected before copying it. */
+ GPU_memory_barrier(GPU_BARRIER_TEXTURE_UPDATE);
+
+ GPU_texture_copy(context().get_output_texture(), image.texture());
+ }
+
+ /* Executes when the alpha channel of the image is set as the value of the input alpha. */
+ void execute_set_alpha()
+ {
+ GPUShader *shader = shader_manager().get("compositor_set_alpha");
+ GPU_shader_bind(shader);
+
+ const Result &image = get_input("Image");
+ image.bind_as_texture(shader, "image_tx");
+
+ const Result &alpha = get_input("Alpha");
+ alpha.bind_as_texture(shader, "alpha_tx");
+
+ GPUTexture *output_texture = context().get_output_texture();
+ const int image_unit = GPU_shader_get_texture_binding(shader, "output_img");
+ GPU_texture_image_bind(output_texture, image_unit);
+
+ compute_dispatch_threads_at_least(shader, compute_domain().size);
+
+ image.unbind_as_texture();
+ alpha.unbind_as_texture();
+ GPU_texture_image_unbind(output_texture);
+ GPU_shader_unbind();
+ }
+
+ /* If true, the alpha channel of the image is set to 1, that is, it becomes opaque. If false, the
+ * alpha channel of the image is retained, but only if the alpha input is not linked. If the
+ * alpha input is linked, it the value of that input will be used as the alpha of the image. */
+ bool ignore_alpha()
+ {
+ return bnode().custom2 & CMP_NODE_OUTPUT_IGNORE_ALPHA;
+ }
+
+ /* The operation domain have the same dimensions of the output without any transformations. */
+ Domain compute_domain() override
+ {
+ return Domain(context().get_output_size());
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new CompositeOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_composite_cc
void register_node_type_cmp_composite()
@@ -37,6 +165,7 @@ void register_node_type_cmp_composite()
cmp_node_type_base(&ntype, CMP_NODE_COMPOSITE, "Composite", NODE_CLASS_OUTPUT);
ntype.declare = file_ns::cmp_node_composite_declare;
ntype.draw_buttons = file_ns::node_composit_buts_composite;
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
ntype.flag |= NODE_PREVIEW;
ntype.no_muting = true;
diff --git a/source/blender/nodes/composite/nodes/node_composite_convert_color_space.cc b/source/blender/nodes/composite/nodes/node_composite_convert_color_space.cc
index 303248c3852..3e521144b8d 100644
--- a/source/blender/nodes/composite/nodes/node_composite_convert_color_space.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_convert_color_space.cc
@@ -14,6 +14,8 @@
#include "IMB_colormanagement.h"
+#include "COM_node_operation.hh"
+
namespace blender::nodes::node_composite_convert_color_space_cc {
static void CMP_NODE_CONVERT_COLOR_SPACE_declare(NodeDeclarationBuilder &b)
@@ -22,7 +24,7 @@ static void CMP_NODE_CONVERT_COLOR_SPACE_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_init_convert_colorspace(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_convert_colorspace(bNodeTree * /*ntree*/, bNode *node)
{
NodeConvertColorSpace *ncs = static_cast<NodeConvertColorSpace *>(
MEM_callocN(sizeof(NodeConvertColorSpace), "node colorspace"));
@@ -40,13 +42,30 @@ static void node_composit_init_convert_colorspace(bNodeTree *UNUSED(ntree), bNod
}
static void node_composit_buts_convert_colorspace(uiLayout *layout,
- bContext *UNUSED(C),
+ bContext * /*C*/,
PointerRNA *ptr)
{
uiItemR(layout, ptr, "from_color_space", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
uiItemR(layout, ptr, "to_color_space", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class ConvertColorSpaceOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_input("Image").pass_through(get_result("Image"));
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new ConvertColorSpaceOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_convert_color_space_cc
void register_node_type_cmp_convert_color_space(void)
@@ -62,6 +81,7 @@ void register_node_type_cmp_convert_color_space(void)
node_type_init(&ntype, file_ns::node_composit_init_convert_colorspace);
node_type_storage(
&ntype, "NodeConvertColorSpace", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_cornerpin.cc b/source/blender/nodes/composite/nodes/node_composite_cornerpin.cc
index 07da0da0be1..9679701a7cf 100644
--- a/source/blender/nodes/composite/nodes/node_composite_cornerpin.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_cornerpin.cc
@@ -5,6 +5,8 @@
* \ingroup cmpnodes
*/
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
namespace blender::nodes::node_composite_cornerpin_cc {
@@ -32,6 +34,24 @@ static void cmp_node_cornerpin_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("Plane"));
}
+using namespace blender::realtime_compositor;
+
+class CornerPinOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_input("Image").pass_through(get_result("Image"));
+ get_result("Plane").allocate_invalid();
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new CornerPinOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_cornerpin_cc
void register_node_type_cmp_cornerpin()
@@ -42,6 +62,7 @@ void register_node_type_cmp_cornerpin()
cmp_node_type_base(&ntype, CMP_NODE_CORNERPIN, "Corner Pin", NODE_CLASS_DISTORT);
ntype.declare = file_ns::cmp_node_cornerpin_declare;
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_crop.cc b/source/blender/nodes/composite/nodes/node_composite_crop.cc
index 823e1052dd0..96a5443921b 100644
--- a/source/blender/nodes/composite/nodes/node_composite_crop.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_crop.cc
@@ -5,24 +5,39 @@
* \ingroup cmpnodes
*/
+#include "BLI_math_base.h"
+#include "BLI_math_vec_types.hh"
+
+#include "DNA_node_types.h"
+
#include "RNA_access.h"
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_shader.h"
+#include "GPU_texture.h"
+
+#include "COM_node_operation.hh"
+#include "COM_utilities.hh"
+
#include "node_composite_util.hh"
/* **************** Crop ******************** */
namespace blender::nodes::node_composite_crop_cc {
+NODE_STORAGE_FUNCS(NodeTwoXYs)
+
static void cmp_node_crop_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_init_crop(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_crop(bNodeTree * /*ntree*/, bNode *node)
{
NodeTwoXYs *nxy = MEM_cnew<NodeTwoXYs>(__func__);
node->storage = nxy;
@@ -32,7 +47,7 @@ static void node_composit_init_crop(bNodeTree *UNUSED(ntree), bNode *node)
nxy->y2 = 0;
}
-static void node_composit_buts_crop(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_crop(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col;
@@ -54,6 +69,156 @@ static void node_composit_buts_crop(uiLayout *layout, bContext *UNUSED(C), Point
}
}
+using namespace blender::realtime_compositor;
+
+class CropOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ /* The operation does nothing, so just pass the input through. */
+ if (is_identity()) {
+ get_input("Image").pass_through(get_result("Image"));
+ return;
+ }
+
+ if (get_is_image_crop()) {
+ execute_image_crop();
+ }
+ else {
+ execute_alpha_crop();
+ }
+ }
+
+ /* Crop by replacing areas outside of the cropping bounds with zero alpha. The output have the
+ * same domain as the input image. */
+ void execute_alpha_crop()
+ {
+ GPUShader *shader = shader_manager().get("compositor_alpha_crop");
+ GPU_shader_bind(shader);
+
+ int2 lower_bound, upper_bound;
+ compute_cropping_bounds(lower_bound, upper_bound);
+ GPU_shader_uniform_2iv(shader, "lower_bound", lower_bound);
+ GPU_shader_uniform_2iv(shader, "upper_bound", upper_bound);
+
+ const Result &input_image = get_input("Image");
+ input_image.bind_as_texture(shader, "input_tx");
+
+ const Domain domain = compute_domain();
+
+ Result &output_image = get_result("Image");
+ output_image.allocate_texture(domain);
+ output_image.bind_as_image(shader, "output_img");
+
+ compute_dispatch_threads_at_least(shader, domain.size);
+
+ input_image.unbind_as_texture();
+ output_image.unbind_as_image();
+ GPU_shader_unbind();
+ }
+
+ /* Crop the image into a new size that matches the cropping bounds. */
+ void execute_image_crop()
+ {
+ int2 lower_bound, upper_bound;
+ compute_cropping_bounds(lower_bound, upper_bound);
+
+ /* The image is cropped into nothing, so just return a single zero value. */
+ if (lower_bound.x == upper_bound.x || lower_bound.y == upper_bound.y) {
+ Result &result = get_result("Image");
+ result.allocate_invalid();
+ return;
+ }
+
+ GPUShader *shader = shader_manager().get("compositor_image_crop");
+ GPU_shader_bind(shader);
+
+ GPU_shader_uniform_2iv(shader, "lower_bound", lower_bound);
+
+ const Result &input_image = get_input("Image");
+ input_image.bind_as_texture(shader, "input_tx");
+
+ const int2 size = upper_bound - lower_bound;
+
+ Result &output_image = get_result("Image");
+ output_image.allocate_texture(Domain(size, compute_domain().transformation));
+ output_image.bind_as_image(shader, "output_img");
+
+ compute_dispatch_threads_at_least(shader, size);
+
+ input_image.unbind_as_texture();
+ output_image.unbind_as_image();
+ GPU_shader_unbind();
+ }
+
+ /* If true, the image should actually be cropped into a new size. Otherwise, if false, the region
+ * outside of the cropping bounds will be set to a zero alpha value. */
+ bool get_is_image_crop()
+ {
+ return bnode().custom1;
+ }
+
+ bool get_is_relative()
+ {
+ return bnode().custom2;
+ }
+
+ /* Returns true if the operation does nothing and the input can be passed through. */
+ bool is_identity()
+ {
+ const Result &input = get_input("Image");
+ /* Single value inputs can't be cropped and are returned as is. */
+ if (input.is_single_value()) {
+ return true;
+ }
+
+ int2 lower_bound, upper_bound;
+ compute_cropping_bounds(lower_bound, upper_bound);
+ const int2 input_size = input.domain().size;
+ /* The cropping bounds cover the whole image, so no cropping happens. */
+ if (lower_bound == int2(0) && upper_bound == input_size) {
+ return true;
+ }
+
+ return false;
+ }
+
+ void compute_cropping_bounds(int2 &lower_bound, int2 &upper_bound)
+ {
+ const NodeTwoXYs &node_two_xys = node_storage(bnode());
+ const int2 input_size = get_input("Image").domain().size;
+
+ if (get_is_relative()) {
+ /* The cropping bounds are relative to the image size. The factors are in the [0, 1] range,
+ * so it is guaranteed that they won't go over the input image size. */
+ lower_bound.x = input_size.x * node_two_xys.fac_x1;
+ lower_bound.y = input_size.y * node_two_xys.fac_y2;
+ upper_bound.x = input_size.x * node_two_xys.fac_x2;
+ upper_bound.y = input_size.y * node_two_xys.fac_y1;
+ }
+ else {
+ /* Make sure the bounds don't go over the input image size. */
+ lower_bound.x = min_ii(node_two_xys.x1, input_size.x);
+ lower_bound.y = min_ii(node_two_xys.y2, input_size.y);
+ upper_bound.x = min_ii(node_two_xys.x2, input_size.x);
+ upper_bound.y = min_ii(node_two_xys.y1, input_size.y);
+ }
+
+ /* Make sure upper bound is actually higher than the lower bound. */
+ lower_bound.x = min_ii(lower_bound.x, upper_bound.x);
+ lower_bound.y = min_ii(lower_bound.y, upper_bound.y);
+ upper_bound.x = max_ii(lower_bound.x, upper_bound.x);
+ upper_bound.y = max_ii(lower_bound.y, upper_bound.y);
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new CropOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_crop_cc
void register_node_type_cmp_crop()
@@ -67,6 +232,7 @@ void register_node_type_cmp_crop()
ntype.draw_buttons = file_ns::node_composit_buts_crop;
node_type_init(&ntype, file_ns::node_composit_init_crop);
node_type_storage(&ntype, "NodeTwoXYs", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc b/source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc
index 5462441660c..fa3b14ae015 100644
--- a/source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc
@@ -26,6 +26,8 @@
#include "RE_pipeline.h"
+#include "COM_node_operation.hh"
+
#include <optional>
/* -------------------------------------------------------------------- */
@@ -105,7 +107,6 @@ static blender::bke::cryptomatte::CryptomatteSessionPtr cryptomatte_init_from_no
return session;
}
-extern "C" {
static CryptomatteEntry *cryptomatte_find(const NodeCryptomatte &n, float encoded_hash)
{
LISTBASE_FOREACH (CryptomatteEntry *, entry, &n.entries) {
@@ -233,7 +234,7 @@ static bNodeSocketTemplate cmp_node_cryptomatte_out[] = {
{-1, ""},
};
-static void node_init_cryptomatte(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_init_cryptomatte(bNodeTree * /*ntree*/, bNode *node)
{
NodeCryptomatte *user = MEM_cnew<NodeCryptomatte>(__func__);
node->storage = user;
@@ -261,7 +262,7 @@ static void node_free_cryptomatte(bNode *node)
}
}
-static void node_copy_cryptomatte(bNodeTree *UNUSED(dest_ntree),
+static void node_copy_cryptomatte(bNodeTree * /*dst_ntree*/,
bNode *dest_node,
const bNode *src_node)
{
@@ -274,7 +275,7 @@ static void node_copy_cryptomatte(bNodeTree *UNUSED(dest_ntree),
dest_node->storage = dest_nc;
}
-static bool node_poll_cryptomatte(bNodeType *UNUSED(ntype),
+static bool node_poll_cryptomatte(bNodeType * /*ntype*/,
bNodeTree *ntree,
const char **r_disabled_hint)
{
@@ -299,6 +300,25 @@ static bool node_poll_cryptomatte(bNodeType *UNUSED(ntype),
return false;
}
+using namespace blender::realtime_compositor;
+
+class CryptoMatteOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_input("Image").pass_through(get_result("Image"));
+ get_result("Matte").allocate_invalid();
+ get_result("Pick").allocate_invalid();
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new CryptoMatteOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_cryptomatte_cc
void register_node_type_cmp_cryptomatte()
@@ -316,6 +336,8 @@ void register_node_type_cmp_cryptomatte()
ntype.poll = file_ns::node_poll_cryptomatte;
node_type_storage(
&ntype, "NodeCryptomatte", file_ns::node_free_cryptomatte, file_ns::node_copy_cryptomatte);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
+
nodeRegisterType(&ntype);
}
@@ -350,7 +372,7 @@ int ntreeCompositCryptomatteRemoveSocket(bNodeTree *ntree, bNode *node)
return 1;
}
-namespace blender::nodes::node_composite_cryptomatte_cc {
+namespace blender::nodes::node_composite_legacy_cryptomatte_cc {
static void node_init_cryptomatte_legacy(bNodeTree *ntree, bNode *node)
{
@@ -365,22 +387,44 @@ static void node_init_cryptomatte_legacy(bNodeTree *ntree, bNode *node)
ntreeCompositCryptomatteAddSocket(ntree, node);
}
-} // namespace blender::nodes::node_composite_cryptomatte_cc
+using namespace blender::realtime_compositor;
+
+class CryptoMatteOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_input("image").pass_through(get_result("Image"));
+ get_result("Matte").allocate_invalid();
+ get_result("Pick").allocate_invalid();
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new CryptoMatteOperation(context, node);
+}
+
+} // namespace blender::nodes::node_composite_legacy_cryptomatte_cc
void register_node_type_cmp_cryptomatte_legacy()
{
- namespace legacy_file_ns = blender::nodes::node_composite_cryptomatte_cc;
+ namespace legacy_file_ns = blender::nodes::node_composite_legacy_cryptomatte_cc;
namespace file_ns = blender::nodes::node_composite_cryptomatte_cc;
static bNodeType ntype;
- cmp_node_type_base(&ntype, CMP_NODE_CRYPTOMATTE_LEGACY, "Cryptomatte", NODE_CLASS_MATTE);
+ cmp_node_type_base(
+ &ntype, CMP_NODE_CRYPTOMATTE_LEGACY, "Cryptomatte (Legacy)", NODE_CLASS_MATTE);
node_type_socket_templates(&ntype, nullptr, file_ns::cmp_node_cryptomatte_out);
- node_type_init(&ntype, file_ns::node_init_cryptomatte_legacy);
+ node_type_init(&ntype, legacy_file_ns::node_init_cryptomatte_legacy);
node_type_storage(
&ntype, "NodeCryptomatte", file_ns::node_free_cryptomatte, file_ns::node_copy_cryptomatte);
+ ntype.gather_link_search_ops = nullptr;
+ ntype.get_compositor_operation = legacy_file_ns::get_compositor_operation;
+
nodeRegisterType(&ntype);
}
/** \} */
-}
diff --git a/source/blender/nodes/composite/nodes/node_composite_curves.cc b/source/blender/nodes/composite/nodes/node_composite_curves.cc
index 802664d7934..b631f75e879 100644
--- a/source/blender/nodes/composite/nodes/node_composite_curves.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_curves.cc
@@ -5,16 +5,23 @@
* \ingroup cmpnodes
*/
+#include "BLI_math_base.h"
+
#include "BKE_colortools.h"
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_material.h"
+
+#include "COM_node_operation.hh"
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* **************** CURVE Time ******************** */
-namespace blender::nodes::node_composite_curves_cc {
+namespace blender::nodes::node_composite_time_curves_cc {
static void cmp_node_time_declare(NodeDeclarationBuilder &b)
{
@@ -22,18 +29,71 @@ static void cmp_node_time_declare(NodeDeclarationBuilder &b)
}
/* custom1 = start_frame, custom2 = end_frame */
-static void node_composit_init_curves_time(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_curves_time(bNodeTree * /*ntree*/, bNode *node)
{
node->custom1 = 1;
node->custom2 = 250;
node->storage = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
}
-} // namespace blender::nodes::node_composite_curves_cc
+using namespace blender::realtime_compositor;
+
+class TimeCurveOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ Result &result = get_result("Fac");
+ result.allocate_single_value();
+
+ CurveMapping *curve_mapping = const_cast<CurveMapping *>(get_curve_mapping());
+ BKE_curvemapping_init(curve_mapping);
+ const float time = BKE_curvemapping_evaluateF(curve_mapping, 0, compute_normalized_time());
+ result.set_float_value(clamp_f(time, 0.0f, 1.0f));
+ }
+
+ const CurveMapping *get_curve_mapping()
+ {
+ return static_cast<const CurveMapping *>(bnode().storage);
+ }
+
+ int get_start_time()
+ {
+ return bnode().custom1;
+ }
+
+ int get_end_time()
+ {
+ return bnode().custom2;
+ }
+
+ float compute_normalized_time()
+ {
+ const int frame_number = context().get_frame_number();
+ if (frame_number < get_start_time()) {
+ return 0.0f;
+ }
+ if (frame_number > get_end_time()) {
+ return 1.0f;
+ }
+ if (get_start_time() == get_end_time()) {
+ return 0.0f;
+ }
+ return float(frame_number - get_start_time()) / float(get_end_time() - get_start_time());
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new TimeCurveOperation(context, node);
+}
+
+} // namespace blender::nodes::node_composite_time_curves_cc
void register_node_type_cmp_curve_time()
{
- namespace file_ns = blender::nodes::node_composite_curves_cc;
+ namespace file_ns = blender::nodes::node_composite_time_curves_cc;
static bNodeType ntype;
@@ -42,35 +102,92 @@ void register_node_type_cmp_curve_time()
node_type_size(&ntype, 200, 140, 320);
node_type_init(&ntype, file_ns::node_composit_init_curves_time);
node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
/* **************** CURVE VEC ******************** */
-namespace blender::nodes::node_composite_curves_cc {
+namespace blender::nodes::node_composite_vector_curves_cc {
static void cmp_node_curve_vec_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Vector>(N_("Vector")).default_value({0.0f, 0.0f, 0.0f}).min(-1.0f).max(1.0f);
+ b.add_input<decl::Vector>(N_("Vector"))
+ .default_value({0.0f, 0.0f, 0.0f})
+ .min(-1.0f)
+ .max(1.0f)
+ .compositor_domain_priority(0);
b.add_output<decl::Vector>(N_("Vector"));
}
-static void node_composit_init_curve_vec(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_curve_vec(bNodeTree * /*ntree*/, bNode *node)
{
node->storage = BKE_curvemapping_add(3, -1.0f, -1.0f, 1.0f, 1.0f);
}
-static void node_buts_curvevec(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_buts_curvevec(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiTemplateCurveMapping(layout, ptr, "mapping", 'v', false, false, false, false);
}
-} // namespace blender::nodes::node_composite_curves_cc
+using namespace blender::realtime_compositor;
+
+class VectorCurvesShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ CurveMapping *curve_mapping = const_cast<CurveMapping *>(get_curve_mapping());
+
+ BKE_curvemapping_init(curve_mapping);
+ float *band_values;
+ int band_size;
+ BKE_curvemapping_table_RGBA(curve_mapping, &band_values, &band_size);
+ float band_layer;
+ GPUNodeLink *band_texture = GPU_color_band(material, band_size, band_values, &band_layer);
+
+ float start_slopes[CM_TOT];
+ float end_slopes[CM_TOT];
+ BKE_curvemapping_compute_slopes(curve_mapping, start_slopes, end_slopes);
+ float range_minimums[CM_TOT];
+ BKE_curvemapping_get_range_minimums(curve_mapping, range_minimums);
+ float range_dividers[CM_TOT];
+ BKE_curvemapping_compute_range_dividers(curve_mapping, range_dividers);
+
+ GPU_stack_link(material,
+ &bnode(),
+ "curves_vector",
+ inputs,
+ outputs,
+ band_texture,
+ GPU_constant(&band_layer),
+ GPU_uniform(range_minimums),
+ GPU_uniform(range_dividers),
+ GPU_uniform(start_slopes),
+ GPU_uniform(end_slopes));
+ }
+
+ const CurveMapping *get_curve_mapping()
+ {
+ return static_cast<const CurveMapping *>(bnode().storage);
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new VectorCurvesShaderNode(node);
+}
+
+} // namespace blender::nodes::node_composite_vector_curves_cc
void register_node_type_cmp_curve_vec()
{
- namespace file_ns = blender::nodes::node_composite_curves_cc;
+ namespace file_ns = blender::nodes::node_composite_vector_curves_cc;
static bNodeType ntype;
@@ -80,34 +197,135 @@ void register_node_type_cmp_curve_vec()
node_type_size(&ntype, 200, 140, 320);
node_type_init(&ntype, file_ns::node_composit_init_curve_vec);
node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves);
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
/* **************** CURVE RGB ******************** */
-namespace blender::nodes::node_composite_curves_cc {
+namespace blender::nodes::node_composite_rgb_curves_cc {
static void cmp_node_rgbcurves_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Float>(N_("Fac")).default_value(1.0f).min(-1.0f).max(1.0f).subtype(
- PROP_FACTOR);
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Float>(N_("Fac"))
+ .default_value(1.0f)
+ .min(-1.0f)
+ .max(1.0f)
+ .subtype(PROP_FACTOR)
+ .compositor_domain_priority(1);
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
b.add_input<decl::Color>(N_("Black Level")).default_value({0.0f, 0.0f, 0.0f, 1.0f});
b.add_input<decl::Color>(N_("White Level")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_init_curve_rgb(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_curve_rgb(bNodeTree * /*ntree*/, bNode *node)
{
node->storage = BKE_curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);
}
-} // namespace blender::nodes::node_composite_curves_cc
+using namespace blender::realtime_compositor;
+
+class RGBCurvesShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ CurveMapping *curve_mapping = const_cast<CurveMapping *>(get_curve_mapping());
+
+ BKE_curvemapping_init(curve_mapping);
+ float *band_values;
+ int band_size;
+ BKE_curvemapping_table_RGBA(curve_mapping, &band_values, &band_size);
+ float band_layer;
+ GPUNodeLink *band_texture = GPU_color_band(material, band_size, band_values, &band_layer);
+
+ float start_slopes[CM_TOT];
+ float end_slopes[CM_TOT];
+ BKE_curvemapping_compute_slopes(curve_mapping, start_slopes, end_slopes);
+ float range_minimums[CM_TOT];
+ BKE_curvemapping_get_range_minimums(curve_mapping, range_minimums);
+ float range_dividers[CM_TOT];
+ BKE_curvemapping_compute_range_dividers(curve_mapping, range_dividers);
+
+ if (curve_mapping->tone == CURVE_TONE_FILMLIKE) {
+ GPU_stack_link(material,
+ &bnode(),
+ "curves_film_like",
+ inputs,
+ outputs,
+ band_texture,
+ GPU_constant(&band_layer),
+ GPU_uniform(&range_minimums[3]),
+ GPU_uniform(&range_dividers[3]),
+ GPU_uniform(&start_slopes[3]),
+ GPU_uniform(&end_slopes[3]));
+ return;
+ }
+
+ const float min = 0.0f;
+ const float max = 1.0f;
+ GPU_link(material,
+ "clamp_value",
+ get_input_link("Fac"),
+ GPU_constant(&min),
+ GPU_constant(&max),
+ &get_input("Fac").link);
+
+ /* If the RGB curves do nothing, use a function that skips RGB computations. */
+ if (BKE_curvemapping_is_map_identity(curve_mapping, 0) &&
+ BKE_curvemapping_is_map_identity(curve_mapping, 1) &&
+ BKE_curvemapping_is_map_identity(curve_mapping, 2)) {
+ GPU_stack_link(material,
+ &bnode(),
+ "curves_combined_only",
+ inputs,
+ outputs,
+ band_texture,
+ GPU_constant(&band_layer),
+ GPU_uniform(&range_minimums[3]),
+ GPU_uniform(&range_dividers[3]),
+ GPU_uniform(&start_slopes[3]),
+ GPU_uniform(&end_slopes[3]));
+ return;
+ }
+
+ GPU_stack_link(material,
+ &bnode(),
+ "curves_combined_rgb",
+ inputs,
+ outputs,
+ band_texture,
+ GPU_constant(&band_layer),
+ GPU_uniform(range_minimums),
+ GPU_uniform(range_dividers),
+ GPU_uniform(start_slopes),
+ GPU_uniform(end_slopes));
+ }
+
+ const CurveMapping *get_curve_mapping()
+ {
+ return static_cast<const CurveMapping *>(bnode().storage);
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new RGBCurvesShaderNode(node);
+}
+
+} // namespace blender::nodes::node_composite_rgb_curves_cc
void register_node_type_cmp_curve_rgb()
{
- namespace file_ns = blender::nodes::node_composite_curves_cc;
+ namespace file_ns = blender::nodes::node_composite_rgb_curves_cc;
static bNodeType ntype;
@@ -116,6 +334,7 @@ void register_node_type_cmp_curve_rgb()
node_type_size(&ntype, 200, 140, 320);
node_type_init(&ntype, file_ns::node_composit_init_curve_rgb);
node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves);
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_defocus.cc b/source/blender/nodes/composite/nodes/node_composite_defocus.cc
index 83dd397ff1f..197e02bebad 100644
--- a/source/blender/nodes/composite/nodes/node_composite_defocus.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_defocus.cc
@@ -12,6 +12,8 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* ************ Defocus Node ****************** */
@@ -25,7 +27,7 @@ static void cmp_node_defocus_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_init_defocus(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_defocus(bNodeTree * /*ntree*/, bNode *node)
{
/* defocus node */
NodeDefocus *nbd = MEM_cnew<NodeDefocus>(__func__);
@@ -81,6 +83,23 @@ static void node_composit_buts_defocus(uiLayout *layout, bContext *C, PointerRNA
uiItemR(sub, ptr, "z_scale", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class DefocusOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_input("Image").pass_through(get_result("Image"));
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new DefocusOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_defocus_cc
void register_node_type_cmp_defocus()
@@ -94,6 +113,7 @@ void register_node_type_cmp_defocus()
ntype.draw_buttons = file_ns::node_composit_buts_defocus;
node_type_init(&ntype, file_ns::node_composit_init_defocus);
node_type_storage(&ntype, "NodeDefocus", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_denoise.cc b/source/blender/nodes/composite/nodes/node_composite_denoise.cc
index 051a2580ef9..821b3c23a7b 100644
--- a/source/blender/nodes/composite/nodes/node_composite_denoise.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_denoise.cc
@@ -10,6 +10,8 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
namespace blender::nodes::node_composite_denoise_cc {
@@ -26,7 +28,7 @@ static void cmp_node_denoise_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_init_denonise(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_denonise(bNodeTree * /*ntree*/, bNode *node)
{
NodeDenoise *ndg = MEM_cnew<NodeDenoise>(__func__);
ndg->hdr = true;
@@ -34,7 +36,7 @@ static void node_composit_init_denonise(bNodeTree *UNUSED(ntree), bNode *node)
node->storage = ndg;
}
-static void node_composit_buts_denoise(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_denoise(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
#ifndef WITH_OPENIMAGEDENOISE
uiItemL(layout, IFACE_("Disabled, built without OpenImageDenoise"), ICON_ERROR);
@@ -52,6 +54,23 @@ static void node_composit_buts_denoise(uiLayout *layout, bContext *UNUSED(C), Po
uiItemR(layout, ptr, "use_hdr", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class DenoiseOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_input("Image").pass_through(get_result("Image"));
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new DenoiseOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_denoise_cc
void register_node_type_cmp_denoise()
@@ -65,6 +84,7 @@ void register_node_type_cmp_denoise()
ntype.draw_buttons = file_ns::node_composit_buts_denoise;
node_type_init(&ntype, file_ns::node_composit_init_denonise);
node_type_storage(&ntype, "NodeDenoise", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_despeckle.cc b/source/blender/nodes/composite/nodes/node_composite_despeckle.cc
index 66a18cfa369..1e15f9709fe 100644
--- a/source/blender/nodes/composite/nodes/node_composite_despeckle.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_despeckle.cc
@@ -8,6 +8,11 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_shader.h"
+
+#include "COM_node_operation.hh"
+#include "COM_utilities.hh"
+
#include "node_composite_util.hh"
/* **************** FILTER ******************** */
@@ -16,18 +21,25 @@ namespace blender::nodes::node_composite_despeckle_cc {
static void cmp_node_despeckle_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Float>(N_("Fac")).default_value(1.0f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Float>(N_("Fac"))
+ .default_value(1.0f)
+ .min(0.0f)
+ .max(1.0f)
+ .subtype(PROP_FACTOR)
+ .compositor_domain_priority(1);
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_init_despeckle(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_despeckle(bNodeTree * /*ntree*/, bNode *node)
{
node->custom3 = 0.5f;
node->custom4 = 0.5f;
}
-static void node_composit_buts_despeckle(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_despeckle(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col;
@@ -36,6 +48,61 @@ static void node_composit_buts_despeckle(uiLayout *layout, bContext *UNUSED(C),
uiItemR(col, ptr, "threshold_neighbor", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class DespeckleOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ const Result &input_image = get_input("Image");
+ /* Single value inputs can't be despeckled and are returned as is. */
+ if (input_image.is_single_value()) {
+ get_input("Image").pass_through(get_result("Image"));
+ return;
+ }
+
+ GPUShader *shader = shader_manager().get("compositor_despeckle");
+ GPU_shader_bind(shader);
+
+ GPU_shader_uniform_1f(shader, "threshold", get_threshold());
+ GPU_shader_uniform_1f(shader, "neighbor_threshold", get_neighbor_threshold());
+
+ input_image.bind_as_texture(shader, "input_tx");
+
+ const Result &factor_image = get_input("Fac");
+ factor_image.bind_as_texture(shader, "factor_tx");
+
+ const Domain domain = compute_domain();
+ Result &output_image = get_result("Image");
+ output_image.allocate_texture(domain);
+ output_image.bind_as_image(shader, "output_img");
+
+ compute_dispatch_threads_at_least(shader, domain.size);
+
+ GPU_shader_unbind();
+ output_image.unbind_as_image();
+ input_image.unbind_as_texture();
+ factor_image.unbind_as_texture();
+ }
+
+ float get_threshold()
+ {
+ return bnode().custom3;
+ }
+
+ float get_neighbor_threshold()
+ {
+ return bnode().custom4;
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new DespeckleOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_despeckle_cc
void register_node_type_cmp_despeckle()
@@ -49,6 +116,7 @@ void register_node_type_cmp_despeckle()
ntype.draw_buttons = file_ns::node_composit_buts_despeckle;
ntype.flag |= NODE_PREVIEW;
node_type_init(&ntype, file_ns::node_composit_init_despeckle);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_diff_matte.cc b/source/blender/nodes/composite/nodes/node_composite_diff_matte.cc
index b87bbe439db..cde537f7d4c 100644
--- a/source/blender/nodes/composite/nodes/node_composite_diff_matte.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_diff_matte.cc
@@ -8,21 +8,31 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* ******************* channel Difference Matte ********************************* */
namespace blender::nodes::node_composite_diff_matte_cc {
+NODE_STORAGE_FUNCS(NodeChroma)
+
static void cmp_node_diff_matte_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image 1")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
- b.add_input<decl::Color>(N_("Image 2")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Color>(N_("Image 1"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
+ b.add_input<decl::Color>(N_("Image 2"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(1);
b.add_output<decl::Color>(N_("Image"));
b.add_output<decl::Float>(N_("Matte"));
}
-static void node_composit_init_diff_matte(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_diff_matte(bNodeTree * /*ntree*/, bNode *node)
{
NodeChroma *c = MEM_cnew<NodeChroma>(__func__);
node->storage = c;
@@ -30,7 +40,7 @@ static void node_composit_init_diff_matte(bNodeTree *UNUSED(ntree), bNode *node)
c->t2 = 0.1f;
}
-static void node_composit_buts_diff_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_diff_matte(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col;
@@ -40,6 +50,45 @@ static void node_composit_buts_diff_matte(uiLayout *layout, bContext *UNUSED(C),
uiItemR(col, ptr, "falloff", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class DifferenceMatteShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ const float tolerance = get_tolerance();
+ const float falloff = get_falloff();
+
+ GPU_stack_link(material,
+ &bnode(),
+ "node_composite_difference_matte",
+ inputs,
+ outputs,
+ GPU_uniform(&tolerance),
+ GPU_uniform(&falloff));
+ }
+
+ float get_tolerance()
+ {
+ return node_storage(bnode()).t1;
+ }
+
+ float get_falloff()
+ {
+ return node_storage(bnode()).t2;
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new DifferenceMatteShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_diff_matte_cc
void register_node_type_cmp_diff_matte()
@@ -54,6 +103,7 @@ void register_node_type_cmp_diff_matte()
ntype.flag |= NODE_PREVIEW;
node_type_init(&ntype, file_ns::node_composit_init_diff_matte);
node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_dilate.cc b/source/blender/nodes/composite/nodes/node_composite_dilate.cc
index 9bdb9ae0837..d659c46721d 100644
--- a/source/blender/nodes/composite/nodes/node_composite_dilate.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_dilate.cc
@@ -5,44 +5,525 @@
* \ingroup cmpnodes
*/
+#include <cmath>
+
+#include "BLI_array.hh"
+#include "BLI_assert.h"
+#include "BLI_math_base.hh"
+
+#include "DNA_scene_types.h"
+
#include "RNA_access.h"
#include "UI_interface.h"
#include "UI_resources.h"
+#include "RE_pipeline.h"
+
+#include "GPU_shader.h"
+#include "GPU_state.h"
+#include "GPU_texture.h"
+
+#include "COM_node_operation.hh"
+#include "COM_utilities.hh"
+
#include "node_composite_util.hh"
/* **************** Dilate/Erode ******************** */
namespace blender::nodes::node_composite_dilate_cc {
+NODE_STORAGE_FUNCS(NodeDilateErode)
+
static void cmp_node_dilate_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Float>(N_("Mask")).default_value(0.0f).min(0.0f).max(1.0f);
b.add_output<decl::Float>(N_("Mask"));
}
-static void node_composit_init_dilateerode(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_dilateerode(bNodeTree * /*ntree*/, bNode *node)
{
NodeDilateErode *data = MEM_cnew<NodeDilateErode>(__func__);
data->falloff = PROP_SMOOTH;
node->storage = data;
}
-static void node_composit_buts_dilateerode(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_dilateerode(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "mode", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
uiItemR(layout, ptr, "distance", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
switch (RNA_enum_get(ptr, "mode")) {
- case CMP_NODE_DILATEERODE_DISTANCE_THRESH:
+ case CMP_NODE_DILATE_ERODE_DISTANCE_THRESHOLD:
uiItemR(layout, ptr, "edge", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
break;
- case CMP_NODE_DILATEERODE_DISTANCE_FEATHER:
+ case CMP_NODE_DILATE_ERODE_DISTANCE_FEATHER:
uiItemR(layout, ptr, "falloff", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
break;
}
}
+using namespace blender::realtime_compositor;
+
+/* Computes a falloff that is equal to 1 at an input of zero and decrease to zero at an input of 1,
+ * with the rate of decrease depending on the falloff type. */
+static float compute_distance_falloff(float x, int falloff_type)
+{
+ x = 1.0f - x;
+
+ switch (falloff_type) {
+ case PROP_SMOOTH:
+ return 3.0f * x * x - 2.0f * x * x * x;
+ case PROP_SPHERE:
+ return std::sqrt(2.0f * x - x * x);
+ case PROP_ROOT:
+ return std::sqrt(x);
+ case PROP_SHARP:
+ return x * x;
+ case PROP_INVSQUARE:
+ return x * (2.0f - x);
+ case PROP_LIN:
+ return x;
+ default:
+ BLI_assert_unreachable();
+ return x;
+ }
+}
+
+/* A helper class that computes and caches 1D GPU textures containing the weights of the separable
+ * Gaussian filter of the given radius as well as an inverse distance falloff of the given type and
+ * radius. The weights and falloffs are symmetric, because the Gaussian and falloff functions are
+ * all even functions. Consequently, only the positive half of the filter is computed and the
+ * shader takes that into consideration. */
+class SymmetricSeparableMorphologicalDistanceFeatherWeights {
+ private:
+ int radius_ = 1;
+ int falloff_type_ = PROP_SMOOTH;
+ GPUTexture *weights_texture_ = nullptr;
+ GPUTexture *distance_falloffs_texture_ = nullptr;
+
+ public:
+ ~SymmetricSeparableMorphologicalDistanceFeatherWeights()
+ {
+ if (weights_texture_) {
+ GPU_texture_free(weights_texture_);
+ }
+
+ if (distance_falloffs_texture_) {
+ GPU_texture_free(distance_falloffs_texture_);
+ }
+ }
+
+ /* Check if textures containing the weights and distance falloffs were already computed for the
+ * given distance falloff type and radius. If such textures exists, do nothing, otherwise, free
+ * the already computed textures and recompute it with the given distance falloff type and
+ * radius. */
+ void update(int radius, int falloff_type)
+ {
+ if (weights_texture_ && distance_falloffs_texture_ && falloff_type == falloff_type_ &&
+ radius == radius_) {
+ return;
+ }
+
+ radius_ = radius;
+ falloff_type_ = falloff_type;
+
+ compute_weights();
+ compute_distance_falloffs();
+ }
+
+ void compute_weights()
+ {
+ if (weights_texture_) {
+ GPU_texture_free(weights_texture_);
+ }
+
+ /* The size of filter is double the radius plus 1, but since the filter is symmetric, we only
+ * compute half of it and no doubling happens. We add 1 to make sure the filter size is always
+ * odd and there is a center weight. */
+ const int size = radius_ + 1;
+ Array<float> weights(size);
+
+ float sum = 0.0f;
+
+ /* First, compute the center weight. */
+ const float center_weight = RE_filter_value(R_FILTER_GAUSS, 0.0f);
+ weights[0] = center_weight;
+ sum += center_weight;
+
+ /* Second, compute the other weights in the positive direction, making sure to add double the
+ * weight to the sum of weights because the filter is symmetric and we only loop over half of
+ * it. Skip the center weight already computed by dropping the front index. */
+ const float scale = radius_ > 0.0f ? 1.0f / radius_ : 0.0f;
+ for (const int i : weights.index_range().drop_front(1)) {
+ const float weight = RE_filter_value(R_FILTER_GAUSS, i * scale);
+ weights[i] = weight;
+ sum += weight * 2.0f;
+ }
+
+ /* Finally, normalize the weights. */
+ for (const int i : weights.index_range()) {
+ weights[i] /= sum;
+ }
+
+ weights_texture_ = GPU_texture_create_1d("Weights", size, 1, GPU_R16F, weights.data());
+ }
+
+ void compute_distance_falloffs()
+ {
+ if (distance_falloffs_texture_) {
+ GPU_texture_free(distance_falloffs_texture_);
+ }
+
+ /* The size of the distance falloffs is double the radius plus 1, but since the falloffs are
+ * symmetric, we only compute half of them and no doubling happens. We add 1 to make sure the
+ * falloffs size is always odd and there is a center falloff. */
+ const int size = radius_ + 1;
+ Array<float> falloffs(size);
+
+ /* Compute the distance falloffs in the positive direction only, because the falloffs are
+ * symmetric. */
+ const float scale = radius_ > 0.0f ? 1.0f / radius_ : 0.0f;
+ for (const int i : falloffs.index_range()) {
+ falloffs[i] = compute_distance_falloff(i * scale, falloff_type_);
+ }
+
+ distance_falloffs_texture_ = GPU_texture_create_1d(
+ "Distance Factors", size, 1, GPU_R16F, falloffs.data());
+ }
+
+ void bind_weights_as_texture(GPUShader *shader, const char *texture_name)
+ {
+ const int texture_image_unit = GPU_shader_get_texture_binding(shader, texture_name);
+ GPU_texture_bind(weights_texture_, texture_image_unit);
+ }
+
+ void unbind_weights_as_texture()
+ {
+ GPU_texture_unbind(weights_texture_);
+ }
+
+ void bind_distance_falloffs_as_texture(GPUShader *shader, const char *texture_name)
+ {
+ const int texture_image_unit = GPU_shader_get_texture_binding(shader, texture_name);
+ GPU_texture_bind(distance_falloffs_texture_, texture_image_unit);
+ }
+
+ void unbind_distance_falloffs_as_texture()
+ {
+ GPU_texture_unbind(distance_falloffs_texture_);
+ }
+};
+
+class DilateErodeOperation : public NodeOperation {
+ private:
+ /* Cached symmetric blur weights and distance falloffs for the distance feature method. */
+ SymmetricSeparableMorphologicalDistanceFeatherWeights distance_feather_weights_;
+
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ if (is_identity()) {
+ get_input("Mask").pass_through(get_result("Mask"));
+ return;
+ }
+
+ switch (get_method()) {
+ case CMP_NODE_DILATE_ERODE_STEP:
+ execute_step();
+ return;
+ case CMP_NODE_DILATE_ERODE_DISTANCE:
+ execute_distance();
+ return;
+ case CMP_NODE_DILATE_ERODE_DISTANCE_THRESHOLD:
+ execute_distance_threshold();
+ return;
+ case CMP_NODE_DILATE_ERODE_DISTANCE_FEATHER:
+ execute_distance_feather();
+ return;
+ default:
+ BLI_assert_unreachable();
+ return;
+ }
+ }
+
+ /* ----------------------------
+ * Step Morphological Operator.
+ * ---------------------------- */
+
+ void execute_step()
+ {
+ GPUTexture *horizontal_pass_result = execute_step_horizontal_pass();
+ execute_step_vertical_pass(horizontal_pass_result);
+ }
+
+ GPUTexture *execute_step_horizontal_pass()
+ {
+ GPUShader *shader = shader_manager().get(get_morphological_step_shader_name());
+ GPU_shader_bind(shader);
+
+ /* Pass the absolute value of the distance. We have specialized shaders for each sign. */
+ GPU_shader_uniform_1i(shader, "radius", math::abs(get_distance()));
+
+ const Result &input_mask = get_input("Mask");
+ input_mask.bind_as_texture(shader, "input_tx");
+
+ /* We allocate an output image of a transposed size, that is, with a height equivalent to the
+ * width of the input and vice versa. This is done as a performance optimization. The shader
+ * will process the image horizontally and write it to the intermediate output transposed. Then
+ * the vertical pass will execute the same horizontal pass shader, but since its input is
+ * transposed, it will effectively do a vertical pass and write to the output transposed,
+ * effectively undoing the transposition in the horizontal pass. This is done to improve
+ * spatial cache locality in the shader and to avoid having two separate shaders for each of
+ * the passes. */
+ const Domain domain = compute_domain();
+ const int2 transposed_domain = int2(domain.size.y, domain.size.x);
+
+ GPUTexture *horizontal_pass_result = texture_pool().acquire_color(transposed_domain);
+ const int image_unit = GPU_shader_get_texture_binding(shader, "output_img");
+ GPU_texture_image_bind(horizontal_pass_result, image_unit);
+
+ compute_dispatch_threads_at_least(shader, domain.size);
+
+ GPU_shader_unbind();
+ input_mask.unbind_as_texture();
+ GPU_texture_image_unbind(horizontal_pass_result);
+
+ return horizontal_pass_result;
+ }
+
+ void execute_step_vertical_pass(GPUTexture *horizontal_pass_result)
+ {
+ GPUShader *shader = shader_manager().get(get_morphological_step_shader_name());
+ GPU_shader_bind(shader);
+
+ /* Pass the absolute value of the distance. We have specialized shaders for each sign. */
+ GPU_shader_uniform_1i(shader, "radius", math::abs(get_distance()));
+
+ GPU_memory_barrier(GPU_BARRIER_TEXTURE_FETCH);
+ const int texture_image_unit = GPU_shader_get_texture_binding(shader, "input_tx");
+ GPU_texture_bind(horizontal_pass_result, texture_image_unit);
+
+ const Domain domain = compute_domain();
+ Result &output_mask = get_result("Mask");
+ output_mask.allocate_texture(domain);
+ output_mask.bind_as_image(shader, "output_img");
+
+ /* Notice that the domain is transposed, see the note on the horizontal pass method for more
+ * information on the reasoning behind this. */
+ compute_dispatch_threads_at_least(shader, int2(domain.size.y, domain.size.x));
+
+ GPU_shader_unbind();
+ output_mask.unbind_as_image();
+ GPU_texture_unbind(horizontal_pass_result);
+ }
+
+ const char *get_morphological_step_shader_name()
+ {
+ if (get_distance() > 0) {
+ return "compositor_morphological_step_dilate";
+ }
+ return "compositor_morphological_step_erode";
+ }
+
+ /* --------------------------------
+ * Distance Morphological Operator.
+ * -------------------------------- */
+
+ void execute_distance()
+ {
+ GPUShader *shader = shader_manager().get(get_morphological_distance_shader_name());
+ GPU_shader_bind(shader);
+
+ /* Pass the absolute value of the distance. We have specialized shaders for each sign. */
+ GPU_shader_uniform_1i(shader, "radius", math::abs(get_distance()));
+
+ const Result &input_mask = get_input("Mask");
+ input_mask.bind_as_texture(shader, "input_tx");
+
+ const Domain domain = compute_domain();
+ Result &output_mask = get_result("Mask");
+ output_mask.allocate_texture(domain);
+ output_mask.bind_as_image(shader, "output_img");
+
+ compute_dispatch_threads_at_least(shader, domain.size);
+
+ GPU_shader_unbind();
+ output_mask.unbind_as_image();
+ input_mask.unbind_as_texture();
+ }
+
+ const char *get_morphological_distance_shader_name()
+ {
+ if (get_distance() > 0) {
+ return "compositor_morphological_distance_dilate";
+ }
+ return "compositor_morphological_distance_erode";
+ }
+
+ /* ------------------------------------------
+ * Distance Threshold Morphological Operator.
+ * ------------------------------------------ */
+
+ void execute_distance_threshold()
+ {
+ GPUShader *shader = shader_manager().get("compositor_morphological_distance_threshold");
+ GPU_shader_bind(shader);
+
+ GPU_shader_uniform_1f(shader, "inset", get_inset());
+ GPU_shader_uniform_1i(shader, "radius", get_morphological_distance_threshold_radius());
+ GPU_shader_uniform_1i(shader, "distance", get_distance());
+
+ const Result &input_mask = get_input("Mask");
+ input_mask.bind_as_texture(shader, "input_tx");
+
+ const Domain domain = compute_domain();
+ Result &output_mask = get_result("Mask");
+ output_mask.allocate_texture(domain);
+ output_mask.bind_as_image(shader, "output_img");
+
+ compute_dispatch_threads_at_least(shader, domain.size);
+
+ GPU_shader_unbind();
+ output_mask.unbind_as_image();
+ input_mask.unbind_as_texture();
+ }
+
+ /* See the discussion in the implementation for more information. */
+ int get_morphological_distance_threshold_radius()
+ {
+ return int(math::ceil(get_inset())) + math::abs(get_distance());
+ }
+
+ /* ----------------------------------------
+ * Distance Feather Morphological Operator.
+ * ---------------------------------------- */
+
+ void execute_distance_feather()
+ {
+ GPUTexture *horizontal_pass_result = execute_distance_feather_horizontal_pass();
+ execute_distance_feather_vertical_pass(horizontal_pass_result);
+ }
+
+ GPUTexture *execute_distance_feather_horizontal_pass()
+ {
+ GPUShader *shader = shader_manager().get(get_morphological_distance_feather_shader_name());
+ GPU_shader_bind(shader);
+
+ const Result &input_image = get_input("Mask");
+ input_image.bind_as_texture(shader, "input_tx");
+
+ distance_feather_weights_.update(math::abs(get_distance()), node_storage(bnode()).falloff);
+ distance_feather_weights_.bind_weights_as_texture(shader, "weights_tx");
+ distance_feather_weights_.bind_distance_falloffs_as_texture(shader, "falloffs_tx");
+
+ /* We allocate an output image of a transposed size, that is, with a height equivalent to the
+ * width of the input and vice versa. This is done as a performance optimization. The shader
+ * will process the image horizontally and write it to the intermediate output transposed. Then
+ * the vertical pass will execute the same horizontal pass shader, but since its input is
+ * transposed, it will effectively do a vertical pass and write to the output transposed,
+ * effectively undoing the transposition in the horizontal pass. This is done to improve
+ * spatial cache locality in the shader and to avoid having two separate shaders for each of
+ * the passes. */
+ const Domain domain = compute_domain();
+ const int2 transposed_domain = int2(domain.size.y, domain.size.x);
+
+ GPUTexture *horizontal_pass_result = texture_pool().acquire_color(transposed_domain);
+ const int image_unit = GPU_shader_get_texture_binding(shader, "output_img");
+ GPU_texture_image_bind(horizontal_pass_result, image_unit);
+
+ compute_dispatch_threads_at_least(shader, domain.size);
+
+ GPU_shader_unbind();
+ input_image.unbind_as_texture();
+ distance_feather_weights_.unbind_weights_as_texture();
+ distance_feather_weights_.unbind_distance_falloffs_as_texture();
+ GPU_texture_image_unbind(horizontal_pass_result);
+
+ return horizontal_pass_result;
+ }
+
+ void execute_distance_feather_vertical_pass(GPUTexture *horizontal_pass_result)
+ {
+ GPUShader *shader = shader_manager().get(get_morphological_distance_feather_shader_name());
+ GPU_shader_bind(shader);
+
+ GPU_memory_barrier(GPU_BARRIER_TEXTURE_FETCH);
+ const int texture_image_unit = GPU_shader_get_texture_binding(shader, "input_tx");
+ GPU_texture_bind(horizontal_pass_result, texture_image_unit);
+
+ distance_feather_weights_.update(math::abs(get_distance()), node_storage(bnode()).falloff);
+ distance_feather_weights_.bind_weights_as_texture(shader, "weights_tx");
+ distance_feather_weights_.bind_distance_falloffs_as_texture(shader, "falloffs_tx");
+
+ const Domain domain = compute_domain();
+ Result &output_image = get_result("Mask");
+ output_image.allocate_texture(domain);
+ output_image.bind_as_image(shader, "output_img");
+
+ /* Notice that the domain is transposed, see the note on the horizontal pass method for more
+ * information on the reasoning behind this. */
+ compute_dispatch_threads_at_least(shader, int2(domain.size.y, domain.size.x));
+
+ GPU_shader_unbind();
+ output_image.unbind_as_image();
+ distance_feather_weights_.unbind_weights_as_texture();
+ distance_feather_weights_.unbind_distance_falloffs_as_texture();
+ GPU_texture_unbind(horizontal_pass_result);
+ }
+
+ const char *get_morphological_distance_feather_shader_name()
+ {
+ if (get_distance() > 0) {
+ return "compositor_morphological_distance_feather_dilate";
+ }
+ return "compositor_morphological_distance_feather_erode";
+ }
+
+ /* ---------------
+ * Common Methods.
+ * --------------- */
+
+ bool is_identity()
+ {
+ const Result &input = get_input("Mask");
+ if (input.is_single_value()) {
+ return true;
+ }
+
+ if (get_method() == CMP_NODE_DILATE_ERODE_DISTANCE_THRESHOLD && get_inset() != 0.0f) {
+ return false;
+ }
+
+ if (get_distance() == 0) {
+ return true;
+ }
+
+ return false;
+ }
+
+ int get_distance()
+ {
+ return bnode().custom2;
+ }
+
+ float get_inset()
+ {
+ return bnode().custom3;
+ }
+
+ CMPNodeDilateErodeMethod get_method()
+ {
+ return (CMPNodeDilateErodeMethod)bnode().custom1;
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new DilateErodeOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_dilate_cc
void register_node_type_cmp_dilateerode()
@@ -57,6 +538,7 @@ void register_node_type_cmp_dilateerode()
node_type_init(&ntype, file_ns::node_composit_init_dilateerode);
node_type_storage(
&ntype, "NodeDilateErode", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_directionalblur.cc b/source/blender/nodes/composite/nodes/node_composite_directionalblur.cc
index 3d82ab04fc9..a5a253c2cca 100644
--- a/source/blender/nodes/composite/nodes/node_composite_directionalblur.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_directionalblur.cc
@@ -5,20 +5,34 @@
* \ingroup cmpnodes
*/
+#include "BLI_float3x3.hh"
+#include "BLI_math_base.hh"
+#include "BLI_math_vec_types.hh"
+#include "BLI_math_vector.hh"
+
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_shader.h"
+
+#include "COM_node_operation.hh"
+#include "COM_utilities.hh"
+
#include "node_composite_util.hh"
namespace blender::nodes::node_composite_directionalblur_cc {
+NODE_STORAGE_FUNCS(NodeDBlurData)
+
static void cmp_node_directional_blur_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_init_dblur(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_dblur(bNodeTree * /*ntree*/, bNode *node)
{
NodeDBlurData *ndbd = MEM_cnew<NodeDBlurData>(__func__);
node->storage = ndbd;
@@ -27,7 +41,7 @@ static void node_composit_init_dblur(bNodeTree *UNUSED(ntree), bNode *node)
ndbd->center_y = 0.5;
}
-static void node_composit_buts_dblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_dblur(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col;
@@ -51,6 +65,129 @@ static void node_composit_buts_dblur(uiLayout *layout, bContext *UNUSED(C), Poin
uiItemR(layout, ptr, "zoom", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class DirectionalBlurOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ if (is_identity()) {
+ get_input("Image").pass_through(get_result("Image"));
+ return;
+ }
+
+ GPUShader *shader = shader_manager().get("compositor_directional_blur");
+ GPU_shader_bind(shader);
+
+ /* The number of iterations does not cover the original image, that is, the image with no
+ * transformation. So add an extra iteration for the original image and put that into
+ * consideration in the shader. */
+ GPU_shader_uniform_1i(shader, "iterations", get_iterations() + 1);
+ GPU_shader_uniform_mat3_as_mat4(shader, "inverse_transformation", get_transformation().ptr());
+
+ const Result &input_image = get_input("Image");
+ input_image.bind_as_texture(shader, "input_tx");
+
+ GPU_texture_filter_mode(input_image.texture(), true);
+ GPU_texture_wrap_mode(input_image.texture(), false, false);
+
+ const Domain domain = compute_domain();
+ Result &output_image = get_result("Image");
+ output_image.allocate_texture(domain);
+ output_image.bind_as_image(shader, "output_img");
+
+ compute_dispatch_threads_at_least(shader, domain.size);
+
+ GPU_shader_unbind();
+ output_image.unbind_as_image();
+ input_image.unbind_as_texture();
+ }
+
+ /* Get the amount of translation that will be applied on each iteration. The translation is in
+ * the negative x direction rotated in the clock-wise direction, hence the negative sign for the
+ * rotation and translation vector. */
+ float2 get_translation()
+ {
+ const float diagonal_length = math::length(float2(get_input("Image").domain().size));
+ const float translation_amount = diagonal_length * node_storage(bnode()).distance;
+ const float3x3 rotation = float3x3::from_rotation(-node_storage(bnode()).angle);
+ return rotation * float2(-translation_amount / get_iterations(), 0.0f);
+ }
+
+ /* Get the amount of rotation that will be applied on each iteration. */
+ float get_rotation()
+ {
+ return node_storage(bnode()).spin / get_iterations();
+ }
+
+ /* Get the amount of scale that will be applied on each iteration. The scale is identity when the
+ * user supplies 0, so we add 1. */
+ float2 get_scale()
+ {
+ return float2(1.0f + node_storage(bnode()).zoom / get_iterations());
+ }
+
+ float2 get_origin()
+ {
+ const float2 center = float2(node_storage(bnode()).center_x, node_storage(bnode()).center_y);
+ return float2(get_input("Image").domain().size) * center;
+ }
+
+ float3x3 get_transformation()
+ {
+ /* Construct the transformation that will be applied on each iteration. */
+ const float3x3 transformation = float3x3::from_translation_rotation_scale(
+ get_translation(), get_rotation(), get_scale());
+ /* Change the origin of the transformation to the user-specified origin. */
+ const float3x3 origin_transformation = float3x3::from_origin_transformation(transformation,
+ get_origin());
+ /* The shader will transform the coordinates, not the image itself, so take the inverse. */
+ return origin_transformation.inverted();
+ }
+
+ /* The actual number of iterations is 2 to the power of the user supplied iterations. The power
+ * is implemented using a bit shift. But also make sure it doesn't exceed the upper limit which
+ * is the number of diagonal pixels. */
+ int get_iterations()
+ {
+ const int iterations = 2 << (node_storage(bnode()).iter - 1);
+ const int upper_limit = math::ceil(math::length(float2(get_input("Image").domain().size)));
+ return math::min(iterations, upper_limit);
+ }
+
+ /* Returns true if the operation does nothing and the input can be passed through. */
+ bool is_identity()
+ {
+ const Result &input = get_input("Image");
+ /* Single value inputs can't be blurred and are returned as is. */
+ if (input.is_single_value()) {
+ return true;
+ }
+
+ /* If any of the following options are non-zero, then the operation is not an identity. */
+ if (node_storage(bnode()).distance != 0.0f) {
+ return false;
+ }
+
+ if (node_storage(bnode()).spin != 0.0f) {
+ return false;
+ }
+
+ if (node_storage(bnode()).zoom != 0.0f) {
+ return false;
+ }
+
+ return true;
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new DirectionalBlurOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_directionalblur_cc
void register_node_type_cmp_dblur()
@@ -65,6 +202,7 @@ void register_node_type_cmp_dblur()
node_type_init(&ntype, file_ns::node_composit_init_dblur);
node_type_storage(
&ntype, "NodeDBlurData", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_displace.cc b/source/blender/nodes/composite/nodes/node_composite_displace.cc
index 0b0d42cbb08..1049f2fa4a9 100644
--- a/source/blender/nodes/composite/nodes/node_composite_displace.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_displace.cc
@@ -5,6 +5,8 @@
* \ingroup cmpnodes
*/
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** Displace ******************** */
@@ -24,6 +26,23 @@ static void cmp_node_displace_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Color>(N_("Image"));
}
+using namespace blender::realtime_compositor;
+
+class DisplaceOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_input("Image").pass_through(get_result("Image"));
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new DisplaceOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_displace_cc
void register_node_type_cmp_displace()
@@ -34,6 +53,7 @@ void register_node_type_cmp_displace()
cmp_node_type_base(&ntype, CMP_NODE_DISPLACE, "Displace", NODE_CLASS_DISTORT);
ntype.declare = file_ns::cmp_node_displace_declare;
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_distance_matte.cc b/source/blender/nodes/composite/nodes/node_composite_distance_matte.cc
index a8646d8498e..87b66810fe3 100644
--- a/source/blender/nodes/composite/nodes/node_composite_distance_matte.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_distance_matte.cc
@@ -8,32 +8,40 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* ******************* channel Distance Matte ********************************* */
namespace blender::nodes::node_composite_distance_matte_cc {
+NODE_STORAGE_FUNCS(NodeChroma)
+
static void cmp_node_distance_matte_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
- b.add_input<decl::Color>(N_("Key Color")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
+ b.add_input<decl::Color>(N_("Key Color"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(1);
b.add_output<decl::Color>(N_("Image"));
b.add_output<decl::Float>(N_("Matte"));
}
-static void node_composit_init_distance_matte(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_distance_matte(bNodeTree * /*ntree*/, bNode *node)
{
NodeChroma *c = MEM_cnew<NodeChroma>(__func__);
node->storage = c;
- c->channel = 1;
+ c->channel = CMP_NODE_DISTANCE_MATTE_COLOR_SPACE_RGBA;
c->t1 = 0.1f;
c->t2 = 0.1f;
}
-static void node_composit_buts_distance_matte(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
+static void node_composit_buts_distance_matte(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col, *row;
@@ -48,6 +56,61 @@ static void node_composit_buts_distance_matte(uiLayout *layout,
uiItemR(col, ptr, "falloff", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class DistanceMatteShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ const float tolerance = get_tolerance();
+ const float falloff = get_falloff();
+
+ if (get_color_space() == CMP_NODE_DISTANCE_MATTE_COLOR_SPACE_RGBA) {
+ GPU_stack_link(material,
+ &bnode(),
+ "node_composite_distance_matte_rgba",
+ inputs,
+ outputs,
+ GPU_uniform(&tolerance),
+ GPU_uniform(&falloff));
+ return;
+ }
+
+ GPU_stack_link(material,
+ &bnode(),
+ "node_composite_distance_matte_ycca",
+ inputs,
+ outputs,
+ GPU_uniform(&tolerance),
+ GPU_uniform(&falloff));
+ }
+
+ CMPNodeDistanceMatteColorSpace get_color_space()
+ {
+ return (CMPNodeDistanceMatteColorSpace)node_storage(bnode()).channel;
+ }
+
+ float get_tolerance()
+ {
+ return node_storage(bnode()).t1;
+ }
+
+ float get_falloff()
+ {
+ return node_storage(bnode()).t2;
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new DistanceMatteShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_distance_matte_cc
void register_node_type_cmp_distance_matte()
@@ -62,6 +125,7 @@ void register_node_type_cmp_distance_matte()
ntype.flag |= NODE_PREVIEW;
node_type_init(&ntype, file_ns::node_composit_init_distance_matte);
node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_double_edge_mask.cc b/source/blender/nodes/composite/nodes/node_composite_double_edge_mask.cc
index 9dc2b223618..553058cf545 100644
--- a/source/blender/nodes/composite/nodes/node_composite_double_edge_mask.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_double_edge_mask.cc
@@ -8,6 +8,8 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** Double Edge Mask ******************** */
@@ -22,7 +24,7 @@ static void cmp_node_double_edge_mask_declare(NodeDeclarationBuilder &b)
}
static void node_composit_buts_double_edge_mask(uiLayout *layout,
- bContext *UNUSED(C),
+ bContext * /*C*/,
PointerRNA *ptr)
{
uiLayout *col;
@@ -35,6 +37,23 @@ static void node_composit_buts_double_edge_mask(uiLayout *layout,
uiItemR(col, ptr, "edge_mode", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class DoubleEdgeMaskOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_input("Inner Mask").pass_through(get_result("Mask"));
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new DoubleEdgeMaskOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_double_edge_mask_cc
void register_node_type_cmp_doubleedgemask()
@@ -46,6 +65,7 @@ void register_node_type_cmp_doubleedgemask()
cmp_node_type_base(&ntype, CMP_NODE_DOUBLEEDGEMASK, "Double Edge Mask", NODE_CLASS_MATTE);
ntype.declare = file_ns::cmp_node_double_edge_mask_declare;
ntype.draw_buttons = file_ns::node_composit_buts_double_edge_mask;
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_ellipsemask.cc b/source/blender/nodes/composite/nodes/node_composite_ellipsemask.cc
index 4da6a0a442e..120b4d0d976 100644
--- a/source/blender/nodes/composite/nodes/node_composite_ellipsemask.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_ellipsemask.cc
@@ -5,15 +5,26 @@
* \ingroup cmpnodes
*/
+#include <cmath>
+
+#include "BLI_math_vec_types.hh"
+
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_shader.h"
+
+#include "COM_node_operation.hh"
+#include "COM_utilities.hh"
+
#include "node_composite_util.hh"
/* **************** SCALAR MATH ******************** */
namespace blender::nodes::node_composite_ellipsemask_cc {
+NODE_STORAGE_FUNCS(NodeEllipseMask)
+
static void cmp_node_ellipsemask_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Float>(N_("Mask")).default_value(0.0f).min(0.0f).max(1.0f);
@@ -21,7 +32,7 @@ static void cmp_node_ellipsemask_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("Mask"));
}
-static void node_composit_init_ellipsemask(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_ellipsemask(bNodeTree * /*ntree*/, bNode *node)
{
NodeEllipseMask *data = MEM_cnew<NodeEllipseMask>(__func__);
data->x = 0.5;
@@ -32,7 +43,7 @@ static void node_composit_init_ellipsemask(bNodeTree *UNUSED(ntree), bNode *node
node->storage = data;
}
-static void node_composit_buts_ellipsemask(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_ellipsemask(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *row;
row = uiLayoutRow(layout, true);
@@ -46,6 +57,93 @@ static void node_composit_buts_ellipsemask(uiLayout *layout, bContext *UNUSED(C)
uiItemR(layout, ptr, "mask_type", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class EllipseMaskOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ GPUShader *shader = shader_manager().get(get_shader_name());
+ GPU_shader_bind(shader);
+
+ const Domain domain = compute_domain();
+
+ GPU_shader_uniform_2iv(shader, "domain_size", domain.size);
+
+ GPU_shader_uniform_2fv(shader, "location", get_location());
+ GPU_shader_uniform_2fv(shader, "radius", get_size() / 2.0f);
+ GPU_shader_uniform_1f(shader, "cos_angle", std::cos(get_angle()));
+ GPU_shader_uniform_1f(shader, "sin_angle", std::sin(get_angle()));
+
+ const Result &input_mask = get_input("Mask");
+ input_mask.bind_as_texture(shader, "base_mask_tx");
+
+ const Result &value = get_input("Value");
+ value.bind_as_texture(shader, "mask_value_tx");
+
+ Result &output_mask = get_result("Mask");
+ output_mask.allocate_texture(domain);
+ output_mask.bind_as_image(shader, "output_mask_img");
+
+ compute_dispatch_threads_at_least(shader, domain.size);
+
+ input_mask.unbind_as_texture();
+ value.unbind_as_texture();
+ output_mask.unbind_as_image();
+ GPU_shader_unbind();
+ }
+
+ Domain compute_domain() override
+ {
+ if (get_input("Mask").is_single_value()) {
+ return Domain(context().get_output_size());
+ }
+ return get_input("Mask").domain();
+ }
+
+ CMPNodeMaskType get_mask_type()
+ {
+ return (CMPNodeMaskType)bnode().custom1;
+ }
+
+ const char *get_shader_name()
+ {
+ switch (get_mask_type()) {
+ default:
+ case CMP_NODE_MASKTYPE_ADD:
+ return "compositor_ellipse_mask_add";
+ case CMP_NODE_MASKTYPE_SUBTRACT:
+ return "compositor_ellipse_mask_subtract";
+ case CMP_NODE_MASKTYPE_MULTIPLY:
+ return "compositor_ellipse_mask_multiply";
+ case CMP_NODE_MASKTYPE_NOT:
+ return "compositor_ellipse_mask_not";
+ }
+ }
+
+ float2 get_location()
+ {
+ return float2(node_storage(bnode()).x, node_storage(bnode()).y);
+ }
+
+ float2 get_size()
+ {
+ return float2(node_storage(bnode()).width, node_storage(bnode()).height);
+ }
+
+ float get_angle()
+ {
+ return node_storage(bnode()).rotation;
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new EllipseMaskOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_ellipsemask_cc
void register_node_type_cmp_ellipsemask()
@@ -61,6 +159,7 @@ void register_node_type_cmp_ellipsemask()
node_type_init(&ntype, file_ns::node_composit_init_ellipsemask);
node_type_storage(
&ntype, "NodeEllipseMask", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_exposure.cc b/source/blender/nodes/composite/nodes/node_composite_exposure.cc
index 881cfc11058..19b93680ff6 100644
--- a/source/blender/nodes/composite/nodes/node_composite_exposure.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_exposure.cc
@@ -5,6 +5,10 @@
* \ingroup cmpnodes
*/
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* **************** Exposure ******************** */
@@ -13,11 +17,33 @@ namespace blender::nodes::node_composite_exposure_cc {
static void cmp_node_exposure_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
- b.add_input<decl::Float>(N_("Exposure")).min(-10.0f).max(10.0f);
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
+ b.add_input<decl::Float>(N_("Exposure")).min(-10.0f).max(10.0f).compositor_domain_priority(1);
b.add_output<decl::Color>(N_("Image"));
}
+using namespace blender::realtime_compositor;
+
+class ExposureShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ GPU_stack_link(material, &bnode(), "node_composite_exposure", inputs, outputs);
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new ExposureShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_exposure_cc
void register_node_type_cmp_exposure()
@@ -28,6 +54,7 @@ void register_node_type_cmp_exposure()
cmp_node_type_base(&ntype, CMP_NODE_EXPOSURE, "Exposure", NODE_CLASS_OP_COLOR);
ntype.declare = file_ns::cmp_node_exposure_declare;
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_filter.cc b/source/blender/nodes/composite/nodes/node_composite_filter.cc
index c343c21feb2..816d1009ffe 100644
--- a/source/blender/nodes/composite/nodes/node_composite_filter.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_filter.cc
@@ -5,9 +5,14 @@
* \ingroup cmpnodes
*/
+#include "BLI_float3x3.hh"
+
#include "UI_interface.h"
#include "UI_resources.h"
+#include "COM_node_operation.hh"
+#include "COM_utilities.hh"
+
#include "node_composite_util.hh"
/* **************** FILTER ******************** */
@@ -16,16 +21,136 @@ namespace blender::nodes::node_composite_filter_cc {
static void cmp_node_filter_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Float>(N_("Fac")).default_value(1.0f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Float>(N_("Fac"))
+ .default_value(1.0f)
+ .min(0.0f)
+ .max(1.0f)
+ .subtype(PROP_FACTOR)
+ .compositor_domain_priority(1);
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_buts_filter(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_filter(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "filter_type", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class FilterOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ GPUShader *shader = shader_manager().get(get_shader_name());
+ GPU_shader_bind(shader);
+
+ GPU_shader_uniform_mat3_as_mat4(shader, "kernel", get_filter_kernel().ptr());
+
+ const Result &input_image = get_input("Image");
+ input_image.bind_as_texture(shader, "input_tx");
+
+ const Result &factor = get_input("Fac");
+ factor.bind_as_texture(shader, "factor_tx");
+
+ const Domain domain = compute_domain();
+
+ Result &output_image = get_result("Image");
+ output_image.allocate_texture(domain);
+ output_image.bind_as_image(shader, "output_img");
+
+ compute_dispatch_threads_at_least(shader, domain.size);
+
+ input_image.unbind_as_texture();
+ factor.unbind_as_texture();
+ output_image.unbind_as_image();
+ GPU_shader_unbind();
+ }
+
+ CMPNodeFilterMethod get_filter_method()
+ {
+ return (CMPNodeFilterMethod)bnode().custom1;
+ }
+
+ float3x3 get_filter_kernel()
+ {
+ /* Initialize the kernels as arrays of rows with the top row first. Edge detection kernels
+ * return the kernel in the X direction, while the kernel in the Y direction will be computed
+ * inside the shader by transposing the kernel in the X direction. */
+ switch (get_filter_method()) {
+ case CMP_NODE_FILTER_SOFT: {
+ const float kernel[3][3] = {{1.0f / 16.0f, 2.0f / 16.0f, 1.0f / 16.0f},
+ {2.0f / 16.0f, 4.0f / 16.0f, 2.0f / 16.0f},
+ {1.0f / 16.0f, 2.0f / 16.0f, 1.0f / 16.0f}};
+ return float3x3(kernel);
+ }
+ case CMP_NODE_FILTER_SHARP_BOX: {
+ const float kernel[3][3] = {
+ {-1.0f, -1.0f, -1.0f}, {-1.0f, 9.0f, -1.0f}, {-1.0f, -1.0f, -1.0f}};
+ return float3x3(kernel);
+ }
+ case CMP_NODE_FILTER_LAPLACE: {
+ const float kernel[3][3] = {{-1.0f / 8.0f, -1.0f / 8.0f, -1.0f / 8.0f},
+ {-1.0f / 8.0f, 1.0f, -1.0f / 8.0f},
+ {-1.0f / 8.0f, -1.0f / 8.0f, -1.0f / 8.0f}};
+ return float3x3(kernel);
+ }
+ case CMP_NODE_FILTER_SOBEL: {
+ const float kernel[3][3] = {{1.0f, 0.0f, -1.0f}, {2.0f, 0.0f, -2.0f}, {1.0f, 0.0f, -1.0f}};
+ return float3x3(kernel);
+ }
+ case CMP_NODE_FILTER_PREWITT: {
+ const float kernel[3][3] = {{1.0f, 0.0f, -1.0f}, {1.0f, 0.0f, -1.0f}, {1.0f, 0.0f, -1.0f}};
+ return float3x3(kernel);
+ }
+ case CMP_NODE_FILTER_KIRSCH: {
+ const float kernel[3][3] = {
+ {5.0f, -3.0f, -2.0f}, {5.0f, -3.0f, -2.0f}, {5.0f, -3.0f, -2.0f}};
+ return float3x3(kernel);
+ }
+ case CMP_NODE_FILTER_SHADOW: {
+ const float kernel[3][3] = {{1.0f, 2.0f, 1.0f}, {0.0f, 1.0f, 0.0f}, {-1.0f, -2.0f, -1.0f}};
+ return float3x3(kernel);
+ }
+ case CMP_NODE_FILTER_SHARP_DIAMOND: {
+ const float kernel[3][3] = {
+ {0.0f, -1.0f, 0.0f}, {-1.0f, 5.0f, -1.0f}, {0.0f, -1.0f, 0.0f}};
+ return float3x3(kernel);
+ }
+ default: {
+ const float kernel[3][3] = {{0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 0.0f}};
+ return float3x3(kernel);
+ }
+ }
+ }
+
+ const char *get_shader_name()
+ {
+ switch (get_filter_method()) {
+ case CMP_NODE_FILTER_LAPLACE:
+ case CMP_NODE_FILTER_SOBEL:
+ case CMP_NODE_FILTER_PREWITT:
+ case CMP_NODE_FILTER_KIRSCH:
+ return "compositor_edge_filter";
+ case CMP_NODE_FILTER_SOFT:
+ case CMP_NODE_FILTER_SHARP_BOX:
+ case CMP_NODE_FILTER_SHADOW:
+ case CMP_NODE_FILTER_SHARP_DIAMOND:
+ default:
+ return "compositor_filter";
+ }
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new FilterOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_filter_cc
void register_node_type_cmp_filter()
@@ -39,6 +164,7 @@ void register_node_type_cmp_filter()
ntype.draw_buttons = file_ns::node_composit_buts_filter;
ntype.labelfunc = node_filter_label;
ntype.flag |= NODE_PREVIEW;
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_flip.cc b/source/blender/nodes/composite/nodes/node_composite_flip.cc
index 37b9a2d020d..07c96eb4d22 100644
--- a/source/blender/nodes/composite/nodes/node_composite_flip.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_flip.cc
@@ -5,9 +5,18 @@
* \ingroup cmpnodes
*/
+#include "BLI_assert.h"
+#include "BLI_utildefines.h"
+
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_shader.h"
+#include "GPU_texture.h"
+
+#include "COM_node_operation.hh"
+#include "COM_utilities.hh"
+
#include "node_composite_util.hh"
/* **************** Flip ******************** */
@@ -16,15 +25,67 @@ namespace blender::nodes::node_composite_flip_cc {
static void cmp_node_flip_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_buts_flip(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_flip(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "axis", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class FlipOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ Result &input = get_input("Image");
+ Result &result = get_result("Image");
+
+ /* Can't flip a single value, pass it through to the output. */
+ if (input.is_single_value()) {
+ input.pass_through(result);
+ return;
+ }
+
+ GPUShader *shader = shader_manager().get("compositor_flip");
+ GPU_shader_bind(shader);
+
+ GPU_shader_uniform_1b(
+ shader, "flip_x", ELEM(get_flip_mode(), CMP_NODE_FLIP_X, CMP_NODE_FLIP_X_Y));
+ GPU_shader_uniform_1b(
+ shader, "flip_y", ELEM(get_flip_mode(), CMP_NODE_FLIP_Y, CMP_NODE_FLIP_X_Y));
+
+ input.bind_as_texture(shader, "input_tx");
+
+ const Domain domain = compute_domain();
+
+ result.allocate_texture(domain);
+ result.bind_as_image(shader, "output_img");
+
+ compute_dispatch_threads_at_least(shader, domain.size);
+
+ input.unbind_as_texture();
+ result.unbind_as_image();
+ GPU_shader_unbind();
+ }
+
+ CMPNodeFlipMode get_flip_mode()
+ {
+ return (CMPNodeFlipMode)bnode().custom1;
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new FlipOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_flip_cc
void register_node_type_cmp_flip()
@@ -36,6 +97,7 @@ void register_node_type_cmp_flip()
cmp_node_type_base(&ntype, CMP_NODE_FLIP, "Flip", NODE_CLASS_DISTORT);
ntype.declare = file_ns::cmp_node_flip_declare;
ntype.draw_buttons = file_ns::node_composit_buts_flip;
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_gamma.cc b/source/blender/nodes/composite/nodes/node_composite_gamma.cc
index b4b8502e915..660d8068231 100644
--- a/source/blender/nodes/composite/nodes/node_composite_gamma.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_gamma.cc
@@ -5,6 +5,10 @@
* \ingroup cmpnodes
*/
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* **************** Gamma Tools ******************** */
@@ -13,15 +17,38 @@ namespace blender::nodes::node_composite_gamma_cc {
static void cmp_node_gamma_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
b.add_input<decl::Float>(N_("Gamma"))
.default_value(1.0f)
.min(0.001f)
.max(10.0f)
- .subtype(PROP_UNSIGNED);
+ .subtype(PROP_UNSIGNED)
+ .compositor_domain_priority(1);
b.add_output<decl::Color>(N_("Image"));
}
+using namespace blender::realtime_compositor;
+
+class GammaShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ GPU_stack_link(material, &bnode(), "node_composite_gamma", inputs, outputs);
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new GammaShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_gamma_cc
void register_node_type_cmp_gamma()
@@ -32,6 +59,7 @@ void register_node_type_cmp_gamma()
cmp_node_type_base(&ntype, CMP_NODE_GAMMA, "Gamma", NODE_CLASS_OP_COLOR);
ntype.declare = file_ns::cmp_node_gamma_declare;
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_glare.cc b/source/blender/nodes/composite/nodes/node_composite_glare.cc
index 7f21d30cfa6..60d149a32b9 100644
--- a/source/blender/nodes/composite/nodes/node_composite_glare.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_glare.cc
@@ -10,6 +10,8 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
namespace blender::nodes::node_composite_glare_cc {
@@ -20,7 +22,7 @@ static void cmp_node_glare_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_init_glare(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_glare(bNodeTree * /*ntree*/, bNode *node)
{
NodeGlare *ndg = MEM_cnew<NodeGlare>(__func__);
ndg->quality = 1;
@@ -37,7 +39,7 @@ static void node_composit_init_glare(bNodeTree *UNUSED(ntree), bNode *node)
node->storage = ndg;
}
-static void node_composit_buts_glare(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_glare(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "glare_type", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
uiItemR(layout, ptr, "quality", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
@@ -75,6 +77,23 @@ static void node_composit_buts_glare(uiLayout *layout, bContext *UNUSED(C), Poin
}
}
+using namespace blender::realtime_compositor;
+
+class GlareOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_input("Image").pass_through(get_result("Image"));
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new GlareOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_glare_cc
void register_node_type_cmp_glare()
@@ -88,6 +107,7 @@ void register_node_type_cmp_glare()
ntype.draw_buttons = file_ns::node_composit_buts_glare;
node_type_init(&ntype, file_ns::node_composit_init_glare);
node_type_storage(&ntype, "NodeGlare", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_hue_sat_val.cc b/source/blender/nodes/composite/nodes/node_composite_hue_sat_val.cc
index 08a048829df..091864a06f7 100644
--- a/source/blender/nodes/composite/nodes/node_composite_hue_sat_val.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_hue_sat_val.cc
@@ -5,6 +5,10 @@
* \ingroup cmpnodes
*/
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* **************** Hue Saturation ******************** */
@@ -13,22 +17,56 @@ namespace blender::nodes::node_composite_hue_sat_val_cc {
static void cmp_node_huesatval_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
- b.add_input<decl::Float>(N_("Hue")).default_value(0.5f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
+ b.add_input<decl::Float>(N_("Hue"))
+ .default_value(0.5f)
+ .min(0.0f)
+ .max(1.0f)
+ .subtype(PROP_FACTOR)
+ .compositor_domain_priority(1);
b.add_input<decl::Float>(N_("Saturation"))
.default_value(1.0f)
.min(0.0f)
.max(2.0f)
- .subtype(PROP_FACTOR);
+ .subtype(PROP_FACTOR)
+ .compositor_domain_priority(2);
b.add_input<decl::Float>(N_("Value"))
.default_value(1.0f)
.min(0.0f)
.max(2.0f)
- .subtype(PROP_FACTOR);
- b.add_input<decl::Float>(N_("Fac")).default_value(1.0f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
+ .subtype(PROP_FACTOR)
+ .compositor_domain_priority(3);
+ b.add_input<decl::Float>(N_("Fac"))
+ .default_value(1.0f)
+ .min(0.0f)
+ .max(1.0f)
+ .subtype(PROP_FACTOR)
+ .compositor_domain_priority(4);
b.add_output<decl::Color>(N_("Image"));
}
+using namespace blender::realtime_compositor;
+
+class HueSaturationValueShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ GPU_stack_link(material, &bnode(), "node_composite_hue_saturation_value", inputs, outputs);
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new HueSaturationValueShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_hue_sat_val_cc
void register_node_type_cmp_hue_sat()
@@ -39,6 +77,7 @@ void register_node_type_cmp_hue_sat()
cmp_node_type_base(&ntype, CMP_NODE_HUE_SAT, "Hue Saturation Value", NODE_CLASS_OP_COLOR);
ntype.declare = file_ns::cmp_node_huesatval_declare;
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_huecorrect.cc b/source/blender/nodes/composite/nodes/node_composite_huecorrect.cc
index d252d96f8c3..a365929138c 100644
--- a/source/blender/nodes/composite/nodes/node_composite_huecorrect.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_huecorrect.cc
@@ -5,6 +5,12 @@
* \ingroup cmpnodes
*/
+#include "BKE_colortools.h"
+
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
#include "BKE_colortools.h"
@@ -13,12 +19,19 @@ namespace blender::nodes::node_composite_huecorrect_cc {
static void cmp_node_huecorrect_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Float>(N_("Fac")).default_value(1.0f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Float>(N_("Fac"))
+ .default_value(1.0f)
+ .min(0.0f)
+ .max(1.0f)
+ .subtype(PROP_FACTOR)
+ .compositor_domain_priority(1);
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_init_huecorrect(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_huecorrect(bNodeTree * /*ntree*/, bNode *node)
{
node->storage = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
@@ -35,6 +48,53 @@ static void node_composit_init_huecorrect(bNodeTree *UNUSED(ntree), bNode *node)
cumapping->cur = 1;
}
+using namespace blender::realtime_compositor;
+
+class HueCorrectShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ CurveMapping *curve_mapping = const_cast<CurveMapping *>(get_curve_mapping());
+
+ BKE_curvemapping_init(curve_mapping);
+ float *band_values;
+ int band_size;
+ BKE_curvemapping_table_RGBA(curve_mapping, &band_values, &band_size);
+ float band_layer;
+ GPUNodeLink *band_texture = GPU_color_band(material, band_size, band_values, &band_layer);
+
+ float range_minimums[CM_TOT];
+ BKE_curvemapping_get_range_minimums(curve_mapping, range_minimums);
+ float range_dividers[CM_TOT];
+ BKE_curvemapping_compute_range_dividers(curve_mapping, range_dividers);
+
+ GPU_stack_link(material,
+ &bnode(),
+ "node_composite_hue_correct",
+ inputs,
+ outputs,
+ band_texture,
+ GPU_constant(&band_layer),
+ GPU_uniform(range_minimums),
+ GPU_uniform(range_dividers));
+ }
+
+ const CurveMapping *get_curve_mapping()
+ {
+ return static_cast<const CurveMapping *>(bnode().storage);
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new HueCorrectShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_huecorrect_cc
void register_node_type_cmp_huecorrect()
@@ -48,6 +108,7 @@ void register_node_type_cmp_huecorrect()
node_type_size(&ntype, 320, 140, 500);
node_type_init(&ntype, file_ns::node_composit_init_huecorrect);
node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves);
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_id_mask.cc b/source/blender/nodes/composite/nodes/node_composite_id_mask.cc
index 25ab9aa63fc..a71b3f132c0 100644
--- a/source/blender/nodes/composite/nodes/node_composite_id_mask.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_id_mask.cc
@@ -8,6 +8,8 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** ID Mask ******************** */
@@ -20,12 +22,29 @@ static void cmp_node_idmask_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("Alpha"));
}
-static void node_composit_buts_id_mask(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_id_mask(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "index", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
uiItemR(layout, ptr, "use_antialiasing", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class IDMaskOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_input("ID value").pass_through(get_result("Alpha"));
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new IDMaskOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_id_mask_cc
void register_node_type_cmp_idmask()
@@ -37,6 +56,7 @@ void register_node_type_cmp_idmask()
cmp_node_type_base(&ntype, CMP_NODE_ID_MASK, "ID Mask", NODE_CLASS_CONVERTER);
ntype.declare = file_ns::cmp_node_idmask_declare;
ntype.draw_buttons = file_ns::node_composit_buts_id_mask;
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_image.cc b/source/blender/nodes/composite/nodes/node_composite_image.cc
index d75aa575395..9efedf744ec 100644
--- a/source/blender/nodes/composite/nodes/node_composite_image.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_image.cc
@@ -8,6 +8,7 @@
#include "node_composite_util.hh"
#include "BLI_linklist.h"
+#include "BLI_math_vec_types.hh"
#include "BLI_utildefines.h"
#include "BKE_context.h"
@@ -17,6 +18,8 @@
#include "BKE_main.h"
#include "BKE_scene.h"
+#include "DEG_depsgraph_query.h"
+
#include "DNA_scene_types.h"
#include "RE_engine.h"
@@ -27,6 +30,12 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_shader.h"
+#include "GPU_texture.h"
+
+#include "COM_node_operation.hh"
+#include "COM_utilities.hh"
+
/* **************** IMAGE (and RenderResult, multilayer image) ******************** */
static bNodeSocketTemplate cmp_node_rlayers_out[] = {
@@ -71,7 +80,7 @@ static void cmp_node_image_add_pass_output(bNodeTree *ntree,
const char *passname,
int rres_index,
eNodeSocketDatatype type,
- int UNUSED(is_rlayers),
+ int /*is_rlayers*/,
LinkNodePair *available_sockets,
int *prev_index)
{
@@ -264,8 +273,8 @@ static void cmp_node_rlayer_create_outputs_cb(void *userdata,
Scene *scene,
ViewLayer *view_layer,
const char *name,
- int UNUSED(channels),
- const char *UNUSED(chanid),
+ int /*channels*/,
+ const char * /*chanid*/,
eNodeSocketDatatype type)
{
CreateOutputUserData &data = *(CreateOutputUserData *)userdata;
@@ -417,7 +426,7 @@ static void node_composit_free_image(bNode *node)
MEM_freeN(node->storage);
}
-static void node_composit_copy_image(bNodeTree *UNUSED(dest_ntree),
+static void node_composit_copy_image(bNodeTree * /*dst_ntree*/,
bNode *dest_node,
const bNode *src_node)
{
@@ -433,6 +442,215 @@ static void node_composit_copy_image(bNodeTree *UNUSED(dest_ntree),
}
}
+using namespace blender::realtime_compositor;
+
+class ImageOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ if (!is_valid()) {
+ allocate_invalid();
+ return;
+ }
+
+ update_image_frame_number();
+
+ for (const bNodeSocket *output : this->node()->output_sockets()) {
+ compute_output(output->identifier);
+ }
+ }
+
+ /* Returns true if the node results can be computed, otherwise, returns false. */
+ bool is_valid()
+ {
+ Image *image = get_image();
+ ImageUser *image_user = get_image_user();
+ if (!image || !image_user) {
+ return false;
+ }
+
+ if (BKE_image_is_multilayer(image)) {
+ if (!image->rr) {
+ return false;
+ }
+
+ RenderLayer *render_layer = get_render_layer();
+ if (!render_layer) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /* Allocate all needed outputs as invalid. This should be called when is_valid returns false. */
+ void allocate_invalid()
+ {
+ for (const bNodeSocket *output : this->node()->output_sockets()) {
+ if (!should_compute_output(output->identifier)) {
+ continue;
+ }
+
+ Result &result = get_result(output->identifier);
+ result.allocate_invalid();
+ }
+ }
+
+ /* Compute the effective frame number of the image if it was animated and invalidate the cached
+ * GPU texture if the computed frame number is different. */
+ void update_image_frame_number()
+ {
+ BKE_image_user_frame_calc(get_image(), get_image_user(), context().get_frame_number());
+ }
+
+ void compute_output(StringRef identifier)
+ {
+ if (!should_compute_output(identifier)) {
+ return;
+ }
+
+ ImageUser image_user = compute_image_user_for_output(identifier);
+ GPUTexture *image_texture = BKE_image_get_gpu_texture(get_image(), &image_user, nullptr);
+
+ const int2 size = int2(GPU_texture_width(image_texture), GPU_texture_height(image_texture));
+ Result &result = get_result(identifier);
+ result.allocate_texture(Domain(size));
+
+ GPUShader *shader = shader_manager().get(get_shader_name(identifier));
+ GPU_shader_bind(shader);
+
+ const int input_unit = GPU_shader_get_texture_binding(shader, "input_tx");
+ GPU_texture_bind(image_texture, input_unit);
+
+ result.bind_as_image(shader, "output_img");
+
+ compute_dispatch_threads_at_least(shader, size);
+
+ GPU_shader_unbind();
+ GPU_texture_unbind(image_texture);
+ result.unbind_as_image();
+ }
+
+ /* Get a copy of the image user that is appropriate to retrieve the image buffer for the output
+ * with the given identifier. This essentially sets the appropriate pass and view indices that
+ * corresponds to the output. */
+ ImageUser compute_image_user_for_output(StringRef identifier)
+ {
+ ImageUser image_user = *get_image_user();
+
+ /* Set the needed view. */
+ image_user.view = get_view_index();
+
+ /* Set the needed pass. */
+ if (BKE_image_is_multilayer(get_image())) {
+ image_user.pass = get_pass_index(get_pass_name(identifier));
+ BKE_image_multilayer_index(get_image()->rr, &image_user);
+ }
+ else {
+ BKE_image_multiview_index(get_image(), &image_user);
+ }
+
+ return image_user;
+ }
+
+ /* Get the shader that should be used to compute the output with the given identifier. The
+ * shaders just copy the retrieved image textures into the results except for the alpha output,
+ * which extracts the alpha and writes it to the result instead. Note that a call to a host
+ * texture copy doesn't work because results are stored in a different half float formats. */
+ const char *get_shader_name(StringRef identifier)
+ {
+ if (identifier == "Alpha") {
+ return "compositor_extract_alpha_from_color";
+ }
+ else if (get_result(identifier).type() == ResultType::Color) {
+ return "compositor_convert_color_to_half_color";
+ }
+ else {
+ return "compositor_convert_float_to_half_float";
+ }
+ }
+
+ Image *get_image()
+ {
+ return (Image *)bnode().id;
+ }
+
+ ImageUser *get_image_user()
+ {
+ return static_cast<ImageUser *>(bnode().storage);
+ }
+
+ /* Get the render layer selected in the node assuming the image is a multilayer image. */
+ RenderLayer *get_render_layer()
+ {
+ const ListBase *layers = &get_image()->rr->layers;
+ return static_cast<RenderLayer *>(BLI_findlink(layers, get_image_user()->layer));
+ }
+
+ /* Get the name of the pass corresponding to the output with the given identifier assuming the
+ * image is a multilayer image. */
+ const char *get_pass_name(StringRef identifier)
+ {
+ DOutputSocket output = node().output_by_identifier(identifier);
+ return static_cast<NodeImageLayer *>(output->storage)->pass_name;
+ }
+
+ /* Get the index of the pass with the given name in the selected render layer's passes list
+ * assuming the image is a multilayer image. */
+ int get_pass_index(const char *name)
+ {
+ return BLI_findstringindex(&get_render_layer()->passes, name, offsetof(RenderPass, name));
+ }
+
+ /* Get the index of the view selected in the node. If the image is not a multi-view image or only
+ * has a single view, then zero is returned. Otherwise, if the image is a multi-view image, the
+ * index of the selected view is returned. However, note that the value of the view member of the
+ * image user is not the actual index of the view. More specifically, the index 0 is reserved to
+ * denote the special mode of operation "All", which dynamically selects the view whose name
+ * matches the view currently being rendered. It follows that the views are then indexed starting
+ * from 1. So for non zero view values, the actual index of the view is the value of the view
+ * member of the image user minus 1. */
+ int get_view_index()
+ {
+ /* The image is not a multi-view image, so just return zero. */
+ if (!BKE_image_is_multiview(get_image())) {
+ return 0;
+ }
+
+ const ListBase *views = &get_image()->rr->views;
+ /* There is only one view and its index is 0. */
+ if (BLI_listbase_count_at_most(views, 2) < 2) {
+ return 0;
+ }
+
+ const int view = get_image_user()->view;
+ /* The view is not zero, which means it is manually specified and the actual index is then the
+ * view value minus 1. */
+ if (view != 0) {
+ return view - 1;
+ }
+
+ /* Otherwise, the view value is zero, denoting the special mode of operation "All", which finds
+ * the index of the view whose name matches the view currently being rendered. */
+ const char *view_name = context().get_view_name().data();
+ const int matched_view = BLI_findstringindex(views, view_name, offsetof(RenderView, name));
+
+ /* No view matches the view currently being rendered, so fallback to the first view. */
+ if (matched_view == -1) {
+ return 0;
+ }
+
+ return matched_view;
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new ImageOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_image_cc
void register_node_type_cmp_image()
@@ -446,6 +664,7 @@ void register_node_type_cmp_image()
node_type_storage(
&ntype, "ImageUser", file_ns::node_composit_free_image, file_ns::node_composit_copy_image);
node_type_update(&ntype, file_ns::cmp_node_image_update);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
ntype.labelfunc = node_image_label;
ntype.flag |= NODE_PREVIEW;
@@ -466,10 +685,10 @@ const char *node_cmp_rlayers_sock_to_pass(int sock_index)
}
const char *name = cmp_node_rlayers_out[sock_index].name;
/* Exception for alpha, which is derived from Combined. */
- return (STREQ(name, "Alpha")) ? RE_PASSNAME_COMBINED : name;
+ return STREQ(name, "Alpha") ? RE_PASSNAME_COMBINED : name;
}
-namespace blender::nodes::node_composite_image_cc {
+namespace blender::nodes::node_composite_render_layer_cc {
static void node_composit_init_rlayers(const bContext *C, PointerRNA *ptr)
{
@@ -491,7 +710,7 @@ static void node_composit_init_rlayers(const bContext *C, PointerRNA *ptr)
}
}
-static bool node_composit_poll_rlayers(bNodeType *UNUSED(ntype),
+static bool node_composit_poll_rlayers(bNodeType * /*ntype*/,
bNodeTree *ntree,
const char **r_disabled_hint)
{
@@ -530,7 +749,7 @@ static void node_composit_free_rlayers(bNode *node)
}
}
-static void node_composit_copy_rlayers(bNodeTree *UNUSED(dest_ntree),
+static void node_composit_copy_rlayers(bNodeTree * /*dst_ntree*/,
bNode *dest_node,
const bNode *src_node)
{
@@ -578,8 +797,7 @@ static void node_composit_buts_viewlayers(uiLayout *layout, bContext *C, Pointer
PropertyRNA *prop = RNA_struct_find_property(ptr, "layer");
const char *layer_name;
- if (!(RNA_property_enum_identifier(
- C, ptr, prop, RNA_property_enum_get(ptr, prop), &layer_name))) {
+ if (!RNA_property_enum_identifier(C, ptr, prop, RNA_property_enum_get(ptr, prop), &layer_name)) {
return;
}
@@ -595,11 +813,60 @@ static void node_composit_buts_viewlayers(uiLayout *layout, bContext *C, Pointer
RNA_string_set(&op_ptr, "scene", scene_name);
}
-} // namespace blender::nodes::node_composite_image_cc
+using namespace blender::realtime_compositor;
+
+class RenderLayerOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ const int view_layer = bnode().custom1;
+ GPUTexture *pass_texture = context().get_input_texture(view_layer, SCE_PASS_COMBINED);
+ const int2 size = int2(GPU_texture_width(pass_texture), GPU_texture_height(pass_texture));
+
+ /* Compute image output. */
+ Result &image_result = get_result("Image");
+ image_result.allocate_texture(Domain(size));
+ GPU_texture_copy(image_result.texture(), pass_texture);
+
+ /* Compute alpha output. */
+ Result &alpha_result = get_result("Alpha");
+ alpha_result.allocate_texture(Domain(size));
+
+ GPUShader *shader = shader_manager().get("compositor_extract_alpha_from_color");
+ GPU_shader_bind(shader);
+
+ const int input_unit = GPU_shader_get_texture_binding(shader, "input_tx");
+ GPU_texture_bind(pass_texture, input_unit);
+
+ alpha_result.bind_as_image(shader, "output_img");
+
+ compute_dispatch_threads_at_least(shader, size);
+
+ GPU_shader_unbind();
+ GPU_texture_unbind(pass_texture);
+ alpha_result.unbind_as_image();
+
+ /* Other output passes are not supported for now, so allocate them as invalid. */
+ for (const bNodeSocket *output : this->node()->output_sockets()) {
+ if (!STR_ELEM(output->identifier, "Image", "Alpha")) {
+ get_result(output->identifier).allocate_invalid();
+ }
+ }
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new RenderLayerOperation(context, node);
+}
+
+} // namespace blender::nodes::node_composite_render_layer_cc
void register_node_type_cmp_rlayers()
{
- namespace file_ns = blender::nodes::node_composite_image_cc;
+ namespace file_ns = blender::nodes::node_composite_render_layer_cc;
static bNodeType ntype;
@@ -608,6 +875,7 @@ void register_node_type_cmp_rlayers()
ntype.draw_buttons = file_ns::node_composit_buts_viewlayers;
ntype.initfunc_api = file_ns::node_composit_init_rlayers;
ntype.poll = file_ns::node_composit_poll_rlayers;
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
ntype.flag |= NODE_PREVIEW;
node_type_storage(
&ntype, nullptr, file_ns::node_composit_free_rlayers, file_ns::node_composit_copy_rlayers);
diff --git a/source/blender/nodes/composite/nodes/node_composite_inpaint.cc b/source/blender/nodes/composite/nodes/node_composite_inpaint.cc
index 2958d1b2869..c26021b16bd 100644
--- a/source/blender/nodes/composite/nodes/node_composite_inpaint.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_inpaint.cc
@@ -8,6 +8,8 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** Inpaint/ ******************** */
@@ -20,11 +22,28 @@ static void cmp_node_inpaint_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_buts_inpaint(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_inpaint(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "distance", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class InpaintOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_input("Image").pass_through(get_result("Image"));
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new InpaintOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_inpaint_cc
void register_node_type_cmp_inpaint()
@@ -36,6 +55,7 @@ void register_node_type_cmp_inpaint()
cmp_node_type_base(&ntype, CMP_NODE_INPAINT, "Inpaint", NODE_CLASS_OP_FILTER);
ntype.declare = file_ns::cmp_node_inpaint_declare;
ntype.draw_buttons = file_ns::node_composit_buts_inpaint;
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_invert.cc b/source/blender/nodes/composite/nodes/node_composite_invert.cc
index 6dff043537a..bbb2808c4ea 100644
--- a/source/blender/nodes/composite/nodes/node_composite_invert.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_invert.cc
@@ -8,6 +8,10 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* **************** INVERT ******************** */
@@ -16,17 +20,24 @@ namespace blender::nodes::node_composite_invert_cc {
static void cmp_node_invert_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Float>(N_("Fac")).default_value(1.0f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
- b.add_input<decl::Color>(N_("Color")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Float>(N_("Fac"))
+ .default_value(1.0f)
+ .min(0.0f)
+ .max(1.0f)
+ .subtype(PROP_FACTOR)
+ .compositor_domain_priority(1);
+ b.add_input<decl::Color>(N_("Color"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
b.add_output<decl::Color>(N_("Color"));
}
-static void node_composit_init_invert(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_invert(bNodeTree * /*ntree*/, bNode *node)
{
node->custom1 |= CMP_CHAN_RGB;
}
-static void node_composit_buts_invert(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_invert(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col;
@@ -35,6 +46,45 @@ static void node_composit_buts_invert(uiLayout *layout, bContext *UNUSED(C), Poi
uiItemR(col, ptr, "invert_alpha", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class InvertShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ const float do_rgb = get_do_rgb();
+ const float do_alpha = get_do_alpha();
+
+ GPU_stack_link(material,
+ &bnode(),
+ "node_composite_invert",
+ inputs,
+ outputs,
+ GPU_constant(&do_rgb),
+ GPU_constant(&do_alpha));
+ }
+
+ bool get_do_rgb()
+ {
+ return bnode().custom1 & CMP_CHAN_RGB;
+ }
+
+ bool get_do_alpha()
+ {
+ return bnode().custom1 & CMP_CHAN_A;
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new InvertShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_invert_cc
void register_node_type_cmp_invert()
@@ -47,6 +97,7 @@ void register_node_type_cmp_invert()
ntype.declare = file_ns::cmp_node_invert_declare;
ntype.draw_buttons = file_ns::node_composit_buts_invert;
node_type_init(&ntype, file_ns::node_composit_init_invert);
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_keying.cc b/source/blender/nodes/composite/nodes/node_composite_keying.cc
index fbfdf2ad3c6..4b61e06a232 100644
--- a/source/blender/nodes/composite/nodes/node_composite_keying.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_keying.cc
@@ -14,6 +14,8 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** Keying ******************** */
@@ -31,7 +33,7 @@ static void cmp_node_keying_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("Edges"));
}
-static void node_composit_init_keying(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_keying(bNodeTree * /*ntree*/, bNode *node)
{
NodeKeyingData *data = MEM_cnew<NodeKeyingData>(__func__);
@@ -45,7 +47,7 @@ static void node_composit_init_keying(bNodeTree *UNUSED(ntree), bNode *node)
node->storage = data;
}
-static void node_composit_buts_keying(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_keying(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
/* bNode *node = (bNode*)ptr->data; */ /* UNUSED */
@@ -63,6 +65,25 @@ static void node_composit_buts_keying(uiLayout *layout, bContext *UNUSED(C), Poi
uiItemR(layout, ptr, "blur_post", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class KeyingOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_input("Image").pass_through(get_result("Image"));
+ get_result("Matte").allocate_invalid();
+ get_result("Edges").allocate_invalid();
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new KeyingOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_keying_cc
void register_node_type_cmp_keying()
@@ -77,6 +98,7 @@ void register_node_type_cmp_keying()
node_type_init(&ntype, file_ns::node_composit_init_keying);
node_type_storage(
&ntype, "NodeKeyingData", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_keyingscreen.cc b/source/blender/nodes/composite/nodes/node_composite_keyingscreen.cc
index e835ee9e721..9eec705b6ca 100644
--- a/source/blender/nodes/composite/nodes/node_composite_keyingscreen.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_keyingscreen.cc
@@ -21,6 +21,8 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** Keying Screen ******************** */
@@ -78,6 +80,23 @@ static void node_composit_buts_keyingscreen(uiLayout *layout, bContext *C, Point
}
}
+using namespace blender::realtime_compositor;
+
+class KeyingScreenOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_result("Screen").allocate_invalid();
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new KeyingScreenOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_keyingscreen_cc
void register_node_type_cmp_keyingscreen()
@@ -92,6 +111,7 @@ void register_node_type_cmp_keyingscreen()
ntype.initfunc_api = file_ns::node_composit_init_keyingscreen;
node_type_storage(
&ntype, "NodeKeyingScreenData", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_lensdist.cc b/source/blender/nodes/composite/nodes/node_composite_lensdist.cc
index 593b7cc9b71..1cf482ff6ff 100644
--- a/source/blender/nodes/composite/nodes/node_composite_lensdist.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_lensdist.cc
@@ -5,31 +5,61 @@
* \ingroup cmpnodes
*/
+#include "BLI_math_base.h"
+#include "BLI_math_vec_types.hh"
+
#include "RNA_access.h"
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_shader.h"
+#include "GPU_texture.h"
+
+#include "COM_node_operation.hh"
+#include "COM_utilities.hh"
+
#include "node_composite_util.hh"
+/* Distortion can't be exactly -1.0 as it will cause infinite pincushion distortion. */
+#define MINIMUM_DISTORTION -0.999f
+/* Arbitrary scaling factor for the dispersion input in projector distortion mode. */
+#define PROJECTOR_DISPERSION_SCALE 5.0f
+/* Arbitrary scaling factor for the dispersion input in screen distortion mode. */
+#define SCREEN_DISPERSION_SCALE 4.0f
+/* Arbitrary scaling factor for the distortion input. */
+#define DISTORTION_SCALE 4.0f
+
namespace blender::nodes::node_composite_lensdist_cc {
+NODE_STORAGE_FUNCS(NodeLensDist)
+
static void cmp_node_lensdist_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
- b.add_input<decl::Float>(N_("Distort")).default_value(0.0f).min(-0.999f).max(1.0f);
- b.add_input<decl::Float>(N_("Dispersion")).default_value(0.0f).min(0.0f).max(1.0f);
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
+ b.add_input<decl::Float>(N_("Distort"))
+ .default_value(0.0f)
+ .min(MINIMUM_DISTORTION)
+ .max(1.0f)
+ .compositor_expects_single_value();
+ b.add_input<decl::Float>(N_("Dispersion"))
+ .default_value(0.0f)
+ .min(0.0f)
+ .max(1.0f)
+ .compositor_expects_single_value();
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_init_lensdist(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_lensdist(bNodeTree * /*ntree*/, bNode *node)
{
NodeLensDist *nld = MEM_cnew<NodeLensDist>(__func__);
nld->jit = nld->proj = nld->fit = 0;
node->storage = nld;
}
-static void node_composit_buts_lensdist(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_lensdist(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col;
@@ -42,6 +72,173 @@ static void node_composit_buts_lensdist(uiLayout *layout, bContext *UNUSED(C), P
uiItemR(col, ptr, "use_fit", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class LensDistortionOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ if (is_identity()) {
+ get_input("Image").pass_through(get_result("Image"));
+ return;
+ }
+
+ if (get_is_projector()) {
+ execute_projector_distortion();
+ }
+ else {
+ execute_screen_distortion();
+ }
+ }
+
+ void execute_projector_distortion()
+ {
+ GPUShader *shader = shader_manager().get("compositor_projector_lens_distortion");
+ GPU_shader_bind(shader);
+
+ const Result &input_image = get_input("Image");
+ input_image.bind_as_texture(shader, "input_tx");
+
+ GPU_texture_filter_mode(input_image.texture(), true);
+ GPU_texture_wrap_mode(input_image.texture(), false, false);
+
+ const Domain domain = compute_domain();
+
+ const float dispersion = (get_dispersion() * PROJECTOR_DISPERSION_SCALE) / domain.size.x;
+ GPU_shader_uniform_1f(shader, "dispersion", dispersion);
+
+ Result &output_image = get_result("Image");
+ output_image.allocate_texture(domain);
+ output_image.bind_as_image(shader, "output_img");
+
+ compute_dispatch_threads_at_least(shader, domain.size);
+
+ input_image.unbind_as_texture();
+ output_image.unbind_as_image();
+ GPU_shader_unbind();
+ }
+
+ void execute_screen_distortion()
+ {
+ GPUShader *shader = shader_manager().get(get_screen_distortion_shader());
+ GPU_shader_bind(shader);
+
+ const Result &input_image = get_input("Image");
+ input_image.bind_as_texture(shader, "input_tx");
+
+ GPU_texture_filter_mode(input_image.texture(), true);
+ GPU_texture_wrap_mode(input_image.texture(), false, false);
+
+ const Domain domain = compute_domain();
+
+ const float3 chromatic_distortion = compute_chromatic_distortion();
+ GPU_shader_uniform_3fv(shader, "chromatic_distortion", chromatic_distortion);
+
+ GPU_shader_uniform_1f(shader, "scale", compute_scale());
+
+ Result &output_image = get_result("Image");
+ output_image.allocate_texture(domain);
+ output_image.bind_as_image(shader, "output_img");
+
+ compute_dispatch_threads_at_least(shader, domain.size);
+
+ input_image.unbind_as_texture();
+ output_image.unbind_as_image();
+ GPU_shader_unbind();
+ }
+
+ const char *get_screen_distortion_shader()
+ {
+ if (get_is_jitter()) {
+ return "compositor_screen_lens_distortion_jitter";
+ }
+ return "compositor_screen_lens_distortion";
+ }
+
+ float get_distortion()
+ {
+ const Result &input = get_input("Distort");
+ return clamp_f(input.get_float_value_default(0.0f), MINIMUM_DISTORTION, 1.0f);
+ }
+
+ float get_dispersion()
+ {
+ const Result &input = get_input("Dispersion");
+ return clamp_f(input.get_float_value_default(0.0f), 0.0f, 1.0f);
+ }
+
+ /* Get the distortion amount for each channel. The green channel has a distortion amount that
+ * matches that specified in the node inputs, while the red and blue channels have higher and
+ * lower distortion amounts respectively based on the dispersion value. */
+ float3 compute_chromatic_distortion()
+ {
+ const float green_distortion = get_distortion();
+ const float dispersion = get_dispersion() / SCREEN_DISPERSION_SCALE;
+ const float red_distortion = clamp_f(green_distortion + dispersion, MINIMUM_DISTORTION, 1.0f);
+ const float blue_distortion = clamp_f(green_distortion - dispersion, MINIMUM_DISTORTION, 1.0f);
+ return float3(red_distortion, green_distortion, blue_distortion) * DISTORTION_SCALE;
+ }
+
+ /* The distortion model will distort the image in such a way that the result will no longer
+ * fit the domain of the original image, so we scale the image to account for that. If get_is_fit
+ * is false, then the scaling factor will be such that the furthest pixels horizontally and
+ * vertically are at the boundary of the image. Otherwise, if get_is_fit is true, the scaling
+ * factor will be such that the furthest pixels diagonally are at the corner of the image. */
+ float compute_scale()
+ {
+ const float3 distortion = compute_chromatic_distortion() / DISTORTION_SCALE;
+ const float maximum_distortion = max_fff(distortion[0], distortion[1], distortion[2]);
+
+ if (get_is_fit() && (maximum_distortion > 0.0f)) {
+ return 1.0f / (1.0f + 2.0f * maximum_distortion);
+ }
+ return 1.0f / (1.0f + maximum_distortion);
+ }
+
+ bool get_is_projector()
+ {
+ return node_storage(bnode()).proj;
+ }
+
+ bool get_is_jitter()
+ {
+ return node_storage(bnode()).jit;
+ }
+
+ bool get_is_fit()
+ {
+ return node_storage(bnode()).fit;
+ }
+
+ /* Returns true if the operation does nothing and the input can be passed through. */
+ bool is_identity()
+ {
+ /* The input is a single value and the operation does nothing. */
+ if (get_input("Image").is_single_value()) {
+ return true;
+ }
+
+ /* Projector have zero dispersion and does nothing. */
+ if (get_is_projector() && get_dispersion() == 0.0f) {
+ return true;
+ }
+
+ /* Both distortion and dispersion are zero and the operation does nothing. */
+ if (get_distortion() == 0.0f && get_dispersion() == 0.0f) {
+ return true;
+ }
+
+ return false;
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new LensDistortionOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_lensdist_cc
void register_node_type_cmp_lensdist()
@@ -56,6 +253,7 @@ void register_node_type_cmp_lensdist()
node_type_init(&ntype, file_ns::node_composit_init_lensdist);
node_type_storage(
&ntype, "NodeLensDist", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_levels.cc b/source/blender/nodes/composite/nodes/node_composite_levels.cc
index a30567672f0..4c901372b9f 100644
--- a/source/blender/nodes/composite/nodes/node_composite_levels.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_levels.cc
@@ -5,9 +5,20 @@
* \ingroup cmpnodes
*/
+#include <cmath>
+
+#include "BLI_assert.h"
+#include "BLI_math_vec_types.hh"
+#include "BLI_math_vector.hh"
+
#include "UI_interface.h"
#include "UI_resources.h"
+#include "IMB_colormanagement.h"
+
+#include "COM_algorithm_parallel_reduction.hh"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** LEVELS ******************** */
@@ -16,21 +27,168 @@ namespace blender::nodes::node_composite_levels_cc {
static void cmp_node_levels_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({0.0f, 0.0f, 0.0f, 1.0f});
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({0.0f, 0.0f, 0.0f, 1.0f})
+ .compositor_domain_priority(0);
b.add_output<decl::Float>(N_("Mean"));
b.add_output<decl::Float>(N_("Std Dev"));
}
-static void node_composit_init_view_levels(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_view_levels(bNodeTree * /*ntree*/, bNode *node)
{
node->custom1 = 1; /* All channels. */
}
-static void node_composit_buts_view_levels(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_view_levels(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "channel", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class LevelsOperation : public NodeOperation {
+ private:
+ constexpr static float luminance_coefficients_bt709_[3] = {0.2126f, 0.7152f, 0.0722f};
+
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ if (get_input("Image").is_single_value()) {
+ execute_single_value();
+ return;
+ }
+
+ const float mean = compute_mean();
+
+ Result &mean_result = get_result("Mean");
+ if (mean_result.should_compute()) {
+ mean_result.allocate_single_value();
+ mean_result.set_float_value(mean);
+ }
+
+ Result &standard_deviation_result = get_result("Std Dev");
+ if (standard_deviation_result.should_compute()) {
+ const float standard_deviation = compute_standard_deviation(mean);
+ standard_deviation_result.allocate_single_value();
+ standard_deviation_result.set_float_value(standard_deviation);
+ }
+ }
+
+ void execute_single_value()
+ {
+ Result &standard_deviation_result = get_result("Std Dev");
+ if (standard_deviation_result.should_compute()) {
+ standard_deviation_result.allocate_single_value();
+ standard_deviation_result.set_float_value(0.0f);
+ }
+
+ Result &mean_result = get_result("Mean");
+ if (!mean_result.should_compute()) {
+ return;
+ }
+
+ mean_result.allocate_single_value();
+ const float3 input = float3(get_input("Image").get_color_value());
+
+ switch (get_channel()) {
+ case CMP_NODE_LEVLES_RED:
+ mean_result.set_float_value(input.x);
+ break;
+ case CMP_NODE_LEVLES_GREEN:
+ mean_result.set_float_value(input.y);
+ break;
+ case CMP_NODE_LEVLES_BLUE:
+ mean_result.set_float_value(input.z);
+ break;
+ case CMP_NODE_LEVLES_LUMINANCE_BT709:
+ mean_result.set_float_value(math::dot(input, float3(luminance_coefficients_bt709_)));
+ break;
+ case CMP_NODE_LEVLES_LUMINANCE: {
+ float luminance_coefficients[3];
+ IMB_colormanagement_get_luminance_coefficients(luminance_coefficients);
+ mean_result.set_float_value(math::dot(input, float3(luminance_coefficients)));
+ break;
+ }
+ default:
+ BLI_assert_unreachable();
+ break;
+ }
+ }
+
+ float compute_mean()
+ {
+ const Result &input = get_input("Image");
+ return compute_sum() / (input.domain().size.x * input.domain().size.y);
+ }
+
+ float compute_sum()
+ {
+ const Result &input = get_input("Image");
+ switch (get_channel()) {
+ case CMP_NODE_LEVLES_RED:
+ return sum_red(context(), input.texture());
+ case CMP_NODE_LEVLES_GREEN:
+ return sum_green(context(), input.texture());
+ case CMP_NODE_LEVLES_BLUE:
+ return sum_blue(context(), input.texture());
+ case CMP_NODE_LEVLES_LUMINANCE_BT709:
+ return sum_luminance(context(), input.texture(), float3(luminance_coefficients_bt709_));
+ case CMP_NODE_LEVLES_LUMINANCE: {
+ float luminance_coefficients[3];
+ IMB_colormanagement_get_luminance_coefficients(luminance_coefficients);
+ return sum_luminance(context(), input.texture(), float3(luminance_coefficients));
+ }
+ default:
+ BLI_assert_unreachable();
+ return 0.0f;
+ }
+ }
+
+ float compute_standard_deviation(float mean)
+ {
+ const Result &input = get_input("Image");
+ const float sum = compute_sum_squared_difference(mean);
+ return std::sqrt(sum / (input.domain().size.x * input.domain().size.y));
+ }
+
+ float compute_sum_squared_difference(float subtrahend)
+ {
+ const Result &input = get_input("Image");
+ switch (get_channel()) {
+ case CMP_NODE_LEVLES_RED:
+ return sum_red_squared_difference(context(), input.texture(), subtrahend);
+ case CMP_NODE_LEVLES_GREEN:
+ return sum_green_squared_difference(context(), input.texture(), subtrahend);
+ case CMP_NODE_LEVLES_BLUE:
+ return sum_blue_squared_difference(context(), input.texture(), subtrahend);
+ case CMP_NODE_LEVLES_LUMINANCE_BT709:
+ return sum_luminance_squared_difference(
+ context(), input.texture(), float3(luminance_coefficients_bt709_), subtrahend);
+ case CMP_NODE_LEVLES_LUMINANCE: {
+ float luminance_coefficients[3];
+ IMB_colormanagement_get_luminance_coefficients(luminance_coefficients);
+ return sum_luminance_squared_difference(
+ context(), input.texture(), float3(luminance_coefficients), subtrahend);
+ }
+ default:
+ BLI_assert_unreachable();
+ return 0.0f;
+ }
+ }
+
+ CMPNodeLevelsChannel get_channel()
+ {
+ return static_cast<CMPNodeLevelsChannel>(bnode().custom1);
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new LevelsOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_levels_cc
void register_node_type_cmp_view_levels()
@@ -44,6 +202,7 @@ void register_node_type_cmp_view_levels()
ntype.draw_buttons = file_ns::node_composit_buts_view_levels;
ntype.flag |= NODE_PREVIEW;
node_type_init(&ntype, file_ns::node_composit_init_view_levels);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_luma_matte.cc b/source/blender/nodes/composite/nodes/node_composite_luma_matte.cc
index 94697a2aafd..8426efb0f1f 100644
--- a/source/blender/nodes/composite/nodes/node_composite_luma_matte.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_luma_matte.cc
@@ -5,23 +5,33 @@
* \ingroup cmpnodes
*/
+#include "IMB_colormanagement.h"
+
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* ******************* Luma Matte Node ********************************* */
namespace blender::nodes::node_composite_luma_matte_cc {
+NODE_STORAGE_FUNCS(NodeChroma)
+
static void cmp_node_luma_matte_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
b.add_output<decl::Color>(N_("Image"));
b.add_output<decl::Float>(N_("Matte"));
}
-static void node_composit_init_luma_matte(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_luma_matte(bNodeTree * /*ntree*/, bNode *node)
{
NodeChroma *c = MEM_cnew<NodeChroma>(__func__);
node->storage = c;
@@ -29,7 +39,7 @@ static void node_composit_init_luma_matte(bNodeTree *UNUSED(ntree), bNode *node)
c->t2 = 0.0f;
}
-static void node_composit_buts_luma_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_luma_matte(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col;
@@ -40,6 +50,48 @@ static void node_composit_buts_luma_matte(uiLayout *layout, bContext *UNUSED(C),
col, ptr, "limit_min", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class LuminanceMatteShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ const float high = get_high();
+ const float low = get_low();
+ float luminance_coefficients[3];
+ IMB_colormanagement_get_luminance_coefficients(luminance_coefficients);
+
+ GPU_stack_link(material,
+ &bnode(),
+ "node_composite_luminance_matte",
+ inputs,
+ outputs,
+ GPU_uniform(&high),
+ GPU_uniform(&low),
+ GPU_constant(luminance_coefficients));
+ }
+
+ float get_high()
+ {
+ return node_storage(bnode()).t1;
+ }
+
+ float get_low()
+ {
+ return node_storage(bnode()).t2;
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new LuminanceMatteShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_luma_matte_cc
void register_node_type_cmp_luma_matte()
@@ -54,6 +106,7 @@ void register_node_type_cmp_luma_matte()
ntype.flag |= NODE_PREVIEW;
node_type_init(&ntype, file_ns::node_composit_init_luma_matte);
node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_map_range.cc b/source/blender/nodes/composite/nodes/node_composite_map_range.cc
index e52c6d096b9..0dace651742 100644
--- a/source/blender/nodes/composite/nodes/node_composite_map_range.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_map_range.cc
@@ -8,6 +8,10 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* **************** Map Range ******************** */
@@ -16,15 +20,35 @@ namespace blender::nodes::node_composite_map_range_cc {
static void cmp_node_map_range_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Float>(N_("Value")).default_value(1.0f).min(0.0f).max(1.0f);
- b.add_input<decl::Float>(N_("From Min")).default_value(0.0f).min(-10000.0f).max(10000.0f);
- b.add_input<decl::Float>(N_("From Max")).default_value(1.0f).min(-10000.0f).max(10000.0f);
- b.add_input<decl::Float>(N_("To Min")).default_value(0.0f).min(-10000.0f).max(10000.0f);
- b.add_input<decl::Float>(N_("To Max")).default_value(1.0f).min(-10000.0f).max(10000.0f);
+ b.add_input<decl::Float>(N_("Value"))
+ .default_value(1.0f)
+ .min(0.0f)
+ .max(1.0f)
+ .compositor_domain_priority(0);
+ b.add_input<decl::Float>(N_("From Min"))
+ .default_value(0.0f)
+ .min(-10000.0f)
+ .max(10000.0f)
+ .compositor_domain_priority(1);
+ b.add_input<decl::Float>(N_("From Max"))
+ .default_value(1.0f)
+ .min(-10000.0f)
+ .max(10000.0f)
+ .compositor_domain_priority(2);
+ b.add_input<decl::Float>(N_("To Min"))
+ .default_value(0.0f)
+ .min(-10000.0f)
+ .max(10000.0f)
+ .compositor_domain_priority(3);
+ b.add_input<decl::Float>(N_("To Max"))
+ .default_value(1.0f)
+ .min(-10000.0f)
+ .max(10000.0f)
+ .compositor_domain_priority(4);
b.add_output<decl::Float>(N_("Value"));
}
-static void node_composit_buts_map_range(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_map_range(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col;
@@ -32,6 +56,38 @@ static void node_composit_buts_map_range(uiLayout *layout, bContext *UNUSED(C),
uiItemR(col, ptr, "use_clamp", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class MapRangeShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ const float should_clamp = get_should_clamp();
+
+ GPU_stack_link(material,
+ &bnode(),
+ "node_composite_map_range",
+ inputs,
+ outputs,
+ GPU_constant(&should_clamp));
+ }
+
+ bool get_should_clamp()
+ {
+ return bnode().custom1;
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new MapRangeShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_map_range_cc
void register_node_type_cmp_map_range()
@@ -43,6 +99,7 @@ void register_node_type_cmp_map_range()
cmp_node_type_base(&ntype, CMP_NODE_MAP_RANGE, "Map Range", NODE_CLASS_OP_VECTOR);
ntype.declare = file_ns::cmp_node_map_range_declare;
ntype.draw_buttons = file_ns::node_composit_buts_map_range;
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_map_uv.cc b/source/blender/nodes/composite/nodes/node_composite_map_uv.cc
index 31961f07ea4..86f85ed7031 100644
--- a/source/blender/nodes/composite/nodes/node_composite_map_uv.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_map_uv.cc
@@ -8,6 +8,8 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** Map UV ******************** */
@@ -21,11 +23,28 @@ static void cmp_node_map_uv_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_buts_map_uv(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_map_uv(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "alpha", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class MapUVOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_input("Image").pass_through(get_result("Image"));
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new MapUVOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_map_uv_cc
void register_node_type_cmp_mapuv()
@@ -37,6 +56,7 @@ void register_node_type_cmp_mapuv()
cmp_node_type_base(&ntype, CMP_NODE_MAP_UV, "Map UV", NODE_CLASS_DISTORT);
ntype.declare = file_ns::cmp_node_map_uv_declare;
ntype.draw_buttons = file_ns::node_composit_buts_map_uv;
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_map_value.cc b/source/blender/nodes/composite/nodes/node_composite_map_value.cc
index bb42628ed3d..eacc003378a 100644
--- a/source/blender/nodes/composite/nodes/node_composite_map_value.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_map_value.cc
@@ -12,24 +12,34 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* **************** MAP VALUE ******************** */
namespace blender::nodes::node_composite_map_value_cc {
+NODE_STORAGE_FUNCS(TexMapping)
+
static void cmp_node_map_value_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Float>(N_("Value")).default_value(1.0f).min(0.0f).max(1.0f);
+ b.add_input<decl::Float>(N_("Value"))
+ .default_value(1.0f)
+ .min(0.0f)
+ .max(1.0f)
+ .compositor_domain_priority(0);
b.add_output<decl::Float>(N_("Value"));
}
-static void node_composit_init_map_value(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_map_value(bNodeTree * /*ntree*/, bNode *node)
{
node->storage = BKE_texture_mapping_add(TEXMAP_TYPE_POINT);
}
-static void node_composit_buts_map_value(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_map_value(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *sub, *col;
@@ -50,6 +60,51 @@ static void node_composit_buts_map_value(uiLayout *layout, bContext *UNUSED(C),
uiItemR(sub, ptr, "max", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class MapValueShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ const TexMapping &texture_mapping = node_storage(bnode());
+
+ const float use_min = get_use_min();
+ const float use_max = get_use_max();
+
+ GPU_stack_link(material,
+ &bnode(),
+ "node_composite_map_value",
+ inputs,
+ outputs,
+ GPU_uniform(texture_mapping.loc),
+ GPU_uniform(texture_mapping.size),
+ GPU_constant(&use_min),
+ GPU_uniform(texture_mapping.min),
+ GPU_constant(&use_max),
+ GPU_uniform(texture_mapping.max));
+ }
+
+ bool get_use_min()
+ {
+ return node_storage(bnode()).flag & TEXMAP_CLIP_MIN;
+ }
+
+ bool get_use_max()
+ {
+ return node_storage(bnode()).flag & TEXMAP_CLIP_MAX;
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new MapValueShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_map_value_cc
void register_node_type_cmp_map_value()
@@ -63,6 +118,7 @@ void register_node_type_cmp_map_value()
ntype.draw_buttons = file_ns::node_composit_buts_map_value;
node_type_init(&ntype, file_ns::node_composit_init_map_value);
node_type_storage(&ntype, "TexMapping", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_mask.cc b/source/blender/nodes/composite/nodes/node_composite_mask.cc
index 5b8fac5d1c0..5dfcc9a9ecf 100644
--- a/source/blender/nodes/composite/nodes/node_composite_mask.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_mask.cc
@@ -10,6 +10,8 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** Mask ******************** */
@@ -21,7 +23,7 @@ static void cmp_node_mask_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("Mask"));
}
-static void node_composit_init_mask(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_mask(bNodeTree * /*ntree*/, bNode *node)
{
NodeMask *data = MEM_cnew<NodeMask>(__func__);
data->size_x = data->size_y = 256;
@@ -31,7 +33,7 @@ static void node_composit_init_mask(bNodeTree *UNUSED(ntree), bNode *node)
node->custom3 = 0.5f; /* shutter */
}
-static void node_mask_label(const bNodeTree *UNUSED(ntree),
+static void node_mask_label(const bNodeTree * /*ntree*/,
const bNode *node,
char *label,
int maxlen)
@@ -74,6 +76,23 @@ static void node_composit_buts_mask(uiLayout *layout, bContext *C, PointerRNA *p
}
}
+using namespace blender::realtime_compositor;
+
+class MaskOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_result("Mask").allocate_invalid();
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new MaskOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_mask_cc
void register_node_type_cmp_mask()
@@ -87,6 +106,7 @@ void register_node_type_cmp_mask()
ntype.draw_buttons = file_ns::node_composit_buts_mask;
node_type_init(&ntype, file_ns::node_composit_init_mask);
ntype.labelfunc = file_ns::node_mask_label;
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
node_type_storage(&ntype, "NodeMask", node_free_standard_storage, node_copy_standard_storage);
diff --git a/source/blender/nodes/composite/nodes/node_composite_math.cc b/source/blender/nodes/composite/nodes/node_composite_math.cc
index 7b2eadef2cb..4baf057913e 100644
--- a/source/blender/nodes/composite/nodes/node_composite_math.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_math.cc
@@ -5,6 +5,12 @@
* \ingroup cmpnodes
*/
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
+#include "NOD_math_functions.hh"
+
#include "node_composite_util.hh"
/* **************** SCALAR MATH ******************** */
@@ -13,18 +19,72 @@ namespace blender::nodes::node_composite_math_cc {
static void cmp_node_math_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Float>(N_("Value")).default_value(0.5f).min(-10000.0f).max(10000.0f);
+ b.add_input<decl::Float>(N_("Value"))
+ .default_value(0.5f)
+ .min(-10000.0f)
+ .max(10000.0f)
+ .compositor_domain_priority(0);
b.add_input<decl::Float>(N_("Value"), "Value_001")
.default_value(0.5f)
.min(-10000.0f)
- .max(10000.0f);
+ .max(10000.0f)
+ .compositor_domain_priority(1);
b.add_input<decl::Float>(N_("Value"), "Value_002")
.default_value(0.5f)
.min(-10000.0f)
- .max(10000.0f);
+ .max(10000.0f)
+ .compositor_domain_priority(2);
b.add_output<decl::Float>(N_("Value"));
}
+using namespace blender::realtime_compositor;
+
+class MathShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ GPU_stack_link(material, &bnode(), get_shader_function_name(), inputs, outputs);
+
+ if (!get_should_clamp()) {
+ return;
+ }
+
+ const float min = 0.0f;
+ const float max = 1.0f;
+ GPU_link(material,
+ "clamp_value",
+ get_output("Value").link,
+ GPU_constant(&min),
+ GPU_constant(&max),
+ &get_output("Value").link);
+ }
+
+ NodeMathOperation get_operation()
+ {
+ return (NodeMathOperation)bnode().custom1;
+ }
+
+ const char *get_shader_function_name()
+ {
+ return get_float_math_operation_info(get_operation())->shader_name.c_str();
+ }
+
+ bool get_should_clamp()
+ {
+ return bnode().custom2 & SHD_MATH_CLAMP;
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new MathShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_math_cc
void register_node_type_cmp_math()
@@ -37,6 +97,7 @@ void register_node_type_cmp_math()
ntype.declare = file_ns::cmp_node_math_declare;
ntype.labelfunc = node_math_label;
node_type_update(&ntype, node_math_update);
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_mixrgb.cc b/source/blender/nodes/composite/nodes/node_composite_mixrgb.cc
index fc11aa188b0..a1fbbfe7d40 100644
--- a/source/blender/nodes/composite/nodes/node_composite_mixrgb.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_mixrgb.cc
@@ -5,6 +5,14 @@
* \ingroup cmpnodes
*/
+#include "BLI_assert.h"
+
+#include "DNA_material_types.h"
+
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* **************** MIX RGB ******************** */
@@ -13,12 +21,122 @@ namespace blender::nodes::node_composite_mixrgb_cc {
static void cmp_node_mixrgb_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Float>(N_("Fac")).default_value(1.0f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
- b.add_input<decl::Color>(N_("Image"), "Image_001").default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Float>(N_("Fac"))
+ .default_value(1.0f)
+ .min(0.0f)
+ .max(1.0f)
+ .subtype(PROP_FACTOR)
+ .compositor_domain_priority(2);
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
+ b.add_input<decl::Color>(N_("Image"), "Image_001")
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(1);
b.add_output<decl::Color>(N_("Image"));
}
+using namespace blender::realtime_compositor;
+
+class MixRGBShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ if (get_use_alpha()) {
+ GPU_link(material,
+ "multiply_by_alpha",
+ get_input_link("Fac"),
+ get_input_link("Image_001"),
+ &get_input("Fac").link);
+ }
+
+ GPU_stack_link(material, &bnode(), get_shader_function_name(), inputs, outputs);
+
+ if (!get_should_clamp()) {
+ return;
+ }
+
+ const float min[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+ const float max[4] = {1.0f, 1.0f, 1.0f, 1.0f};
+ GPU_link(material,
+ "clamp_color",
+ get_output("Image").link,
+ GPU_constant(min),
+ GPU_constant(max),
+ &get_output("Image").link);
+ }
+
+ int get_mode()
+ {
+ return bnode().custom1;
+ }
+
+ const char *get_shader_function_name()
+ {
+ switch (get_mode()) {
+ case MA_RAMP_BLEND:
+ return "mix_blend";
+ case MA_RAMP_ADD:
+ return "mix_add";
+ case MA_RAMP_MULT:
+ return "mix_mult";
+ case MA_RAMP_SUB:
+ return "mix_sub";
+ case MA_RAMP_SCREEN:
+ return "mix_screen";
+ case MA_RAMP_DIV:
+ return "mix_div";
+ case MA_RAMP_DIFF:
+ return "mix_diff";
+ case MA_RAMP_DARK:
+ return "mix_dark";
+ case MA_RAMP_LIGHT:
+ return "mix_light";
+ case MA_RAMP_OVERLAY:
+ return "mix_overlay";
+ case MA_RAMP_DODGE:
+ return "mix_dodge";
+ case MA_RAMP_BURN:
+ return "mix_burn";
+ case MA_RAMP_HUE:
+ return "mix_hue";
+ case MA_RAMP_SAT:
+ return "mix_sat";
+ case MA_RAMP_VAL:
+ return "mix_val";
+ case MA_RAMP_COLOR:
+ return "mix_color";
+ case MA_RAMP_SOFT:
+ return "mix_soft";
+ case MA_RAMP_LINEAR:
+ return "mix_linear";
+ }
+
+ BLI_assert_unreachable();
+ return nullptr;
+ }
+
+ bool get_use_alpha()
+ {
+ return bnode().custom2 & SHD_MIXRGB_USE_ALPHA;
+ }
+
+ bool get_should_clamp()
+ {
+ return bnode().custom2 & SHD_MIXRGB_CLAMP;
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new MixRGBShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_mixrgb_cc
void register_node_type_cmp_mix_rgb()
@@ -31,6 +149,7 @@ void register_node_type_cmp_mix_rgb()
ntype.flag |= NODE_PREVIEW;
ntype.declare = file_ns::cmp_node_mixrgb_declare;
ntype.labelfunc = node_blend_label;
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_movieclip.cc b/source/blender/nodes/composite/nodes/node_composite_movieclip.cc
index a4d5f294fe0..b9d9620a214 100644
--- a/source/blender/nodes/composite/nodes/node_composite_movieclip.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_movieclip.cc
@@ -5,8 +5,13 @@
* \ingroup cmpnodes
*/
+#include "BLI_math_vec_types.hh"
+
#include "BKE_context.h"
#include "BKE_lib_id.h"
+#include "BKE_movieclip.h"
+#include "BKE_tracking.h"
+
#include "DNA_defaults.h"
#include "RNA_access.h"
@@ -14,6 +19,12 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_shader.h"
+#include "GPU_texture.h"
+
+#include "COM_node_operation.hh"
+#include "COM_utilities.hh"
+
#include "node_composite_util.hh"
namespace blender::nodes::node_composite_movieclip_cc {
@@ -79,6 +90,184 @@ static void node_composit_buts_movieclip_ex(uiLayout *layout, bContext *C, Point
uiTemplateColorspaceSettings(layout, &clipptr, "colorspace_settings");
}
+using namespace blender::realtime_compositor;
+
+class MovieClipOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ GPUTexture *movie_clip_texture = get_movie_clip_texture();
+
+ compute_image(movie_clip_texture);
+ compute_alpha(movie_clip_texture);
+ compute_stabilization_data(movie_clip_texture);
+
+ free_movie_clip_texture();
+ }
+
+ void compute_image(GPUTexture *movie_clip_texture)
+ {
+ if (!should_compute_output("Image")) {
+ return;
+ }
+
+ Result &result = get_result("Image");
+
+ /* The movie clip texture is invalid or missing, set an appropriate fallback value. */
+ if (!movie_clip_texture) {
+ result.allocate_invalid();
+ return;
+ }
+
+ const int2 size = int2(GPU_texture_width(movie_clip_texture),
+ GPU_texture_height(movie_clip_texture));
+ result.allocate_texture(Domain(size));
+
+ GPUShader *shader = shader_manager().get("compositor_convert_color_to_half_color");
+ GPU_shader_bind(shader);
+
+ const int input_unit = GPU_shader_get_texture_binding(shader, "input_tx");
+ GPU_texture_bind(movie_clip_texture, input_unit);
+
+ result.bind_as_image(shader, "output_img");
+
+ compute_dispatch_threads_at_least(shader, size);
+
+ GPU_shader_unbind();
+ GPU_texture_unbind(movie_clip_texture);
+ result.unbind_as_image();
+ }
+
+ void compute_alpha(GPUTexture *movie_clip_texture)
+ {
+ if (!should_compute_output("Alpha")) {
+ return;
+ }
+
+ Result &result = get_result("Alpha");
+
+ /* The movie clip texture is invalid or missing, set an appropriate fallback value. */
+ if (!movie_clip_texture) {
+ result.allocate_single_value();
+ result.set_float_value(1.0f);
+ return;
+ }
+
+ const int2 size = int2(GPU_texture_width(movie_clip_texture),
+ GPU_texture_height(movie_clip_texture));
+ result.allocate_texture(Domain(size));
+
+ GPUShader *shader = shader_manager().get("compositor_extract_alpha_from_color");
+ GPU_shader_bind(shader);
+
+ const int input_unit = GPU_shader_get_texture_binding(shader, "input_tx");
+ GPU_texture_bind(movie_clip_texture, input_unit);
+
+ result.bind_as_image(shader, "output_img");
+
+ compute_dispatch_threads_at_least(shader, size);
+
+ GPU_shader_unbind();
+ GPU_texture_unbind(movie_clip_texture);
+ result.unbind_as_image();
+ }
+
+ void compute_stabilization_data(GPUTexture *movie_clip_texture)
+ {
+ /* The movie clip texture is invalid or missing, set appropriate fallback values. */
+ if (!movie_clip_texture) {
+ if (should_compute_output("Offset X")) {
+ Result &result = get_result("Offset X");
+ result.allocate_single_value();
+ result.set_float_value(0.0f);
+ }
+ if (should_compute_output("Offset Y")) {
+ Result &result = get_result("Offset Y");
+ result.allocate_single_value();
+ result.set_float_value(0.0f);
+ }
+ if (should_compute_output("Scale")) {
+ Result &result = get_result("Scale");
+ result.allocate_single_value();
+ result.set_float_value(1.0f);
+ }
+ if (should_compute_output("Angle")) {
+ Result &result = get_result("Angle");
+ result.allocate_single_value();
+ result.set_float_value(0.0f);
+ }
+ return;
+ }
+
+ MovieClip *movie_clip = get_movie_clip();
+ const int frame_number = BKE_movieclip_remap_scene_to_clip_frame(movie_clip,
+ context().get_frame_number());
+ const int width = GPU_texture_width(movie_clip_texture);
+ const int height = GPU_texture_height(movie_clip_texture);
+
+ /* If the movie clip has no stabilization data, it will initialize the given values with
+ * fallback values regardless, so no need to handle that case. */
+ float2 offset;
+ float scale, angle;
+ BKE_tracking_stabilization_data_get(
+ movie_clip, frame_number, width, height, offset, &scale, &angle);
+
+ if (should_compute_output("Offset X")) {
+ Result &result = get_result("Offset X");
+ result.allocate_single_value();
+ result.set_float_value(offset.x);
+ }
+ if (should_compute_output("Offset Y")) {
+ Result &result = get_result("Offset Y");
+ result.allocate_single_value();
+ result.set_float_value(offset.y);
+ }
+ if (should_compute_output("Scale")) {
+ Result &result = get_result("Scale");
+ result.allocate_single_value();
+ result.set_float_value(scale);
+ }
+ if (should_compute_output("Angle")) {
+ Result &result = get_result("Angle");
+ result.allocate_single_value();
+ result.set_float_value(angle);
+ }
+ }
+
+ GPUTexture *get_movie_clip_texture()
+ {
+ MovieClip *movie_clip = get_movie_clip();
+ MovieClipUser *movie_clip_user = get_movie_clip_user();
+ BKE_movieclip_user_set_frame(movie_clip_user, context().get_frame_number());
+ return BKE_movieclip_get_gpu_texture(movie_clip, movie_clip_user);
+ }
+
+ void free_movie_clip_texture()
+ {
+ MovieClip *movie_clip = get_movie_clip();
+ if (movie_clip) {
+ BKE_movieclip_free_gputexture(movie_clip);
+ }
+ }
+
+ MovieClip *get_movie_clip()
+ {
+ return (MovieClip *)bnode().id;
+ }
+
+ MovieClipUser *get_movie_clip_user()
+ {
+ return static_cast<MovieClipUser *>(bnode().storage);
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new MovieClipOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_movieclip_cc
void register_node_type_cmp_movieclip()
@@ -91,6 +280,7 @@ void register_node_type_cmp_movieclip()
ntype.declare = file_ns::cmp_node_movieclip_declare;
ntype.draw_buttons = file_ns::node_composit_buts_movieclip;
ntype.draw_buttons_ex = file_ns::node_composit_buts_movieclip_ex;
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
ntype.initfunc_api = file_ns::init;
ntype.flag |= NODE_PREVIEW;
node_type_storage(
diff --git a/source/blender/nodes/composite/nodes/node_composite_moviedistortion.cc b/source/blender/nodes/composite/nodes/node_composite_moviedistortion.cc
index 4d52a767b8a..aad6eb3ce5e 100644
--- a/source/blender/nodes/composite/nodes/node_composite_moviedistortion.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_moviedistortion.cc
@@ -12,6 +12,8 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** Translate ******************** */
@@ -24,7 +26,7 @@ static void cmp_node_moviedistortion_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Color>(N_("Image"));
}
-static void label(const bNodeTree *UNUSED(ntree), const bNode *node, char *label, int maxlen)
+static void label(const bNodeTree * /*ntree*/, const bNode *node, char *label, int maxlen)
{
if (node->custom1 == 0) {
BLI_strncpy(label, IFACE_("Undistortion"), maxlen);
@@ -52,7 +54,7 @@ static void storage_free(bNode *node)
node->storage = nullptr;
}
-static void storage_copy(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
+static void storage_copy(bNodeTree * /*dst_ntree*/, bNode *dest_node, const bNode *src_node)
{
if (src_node->storage) {
dest_node->storage = BKE_tracking_distortion_copy((MovieDistortion *)src_node->storage);
@@ -81,6 +83,23 @@ static void node_composit_buts_moviedistortion(uiLayout *layout, bContext *C, Po
uiItemR(layout, ptr, "distortion_type", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class MovieDistortionOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_input("Image").pass_through(get_result("Image"));
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new MovieDistortionOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_moviedistortion_cc
void register_node_type_cmp_moviedistortion()
@@ -95,6 +114,7 @@ void register_node_type_cmp_moviedistortion()
ntype.labelfunc = file_ns::label;
ntype.initfunc_api = file_ns::init;
node_type_storage(&ntype, nullptr, file_ns::storage_free, file_ns::storage_copy);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_normal.cc b/source/blender/nodes/composite/nodes/node_composite_normal.cc
index b4dd0bbacd0..a1a6303e21b 100644
--- a/source/blender/nodes/composite/nodes/node_composite_normal.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_normal.cc
@@ -5,6 +5,10 @@
* \ingroup cmpnodes
*/
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* **************** NORMAL ******************** */
@@ -17,7 +21,8 @@ static void cmp_node_normal_declare(NodeDeclarationBuilder &b)
.default_value({0.0f, 0.0f, 1.0f})
.min(-1.0f)
.max(1.0f)
- .subtype(PROP_DIRECTION);
+ .subtype(PROP_DIRECTION)
+ .compositor_domain_priority(0);
b.add_output<decl::Vector>(N_("Normal"))
.default_value({0.0f, 0.0f, 1.0f})
.min(-1.0f)
@@ -26,6 +31,40 @@ static void cmp_node_normal_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("Dot"));
}
+using namespace blender::realtime_compositor;
+
+class NormalShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ GPU_stack_link(material,
+ &bnode(),
+ "node_composite_normal",
+ inputs,
+ outputs,
+ GPU_uniform(get_vector_value()));
+ }
+
+ /* The vector value is stored in the default value of the output socket. */
+ const float *get_vector_value()
+ {
+ return node()
+ .output_by_identifier("Normal")
+ ->default_value_typed<bNodeSocketValueVector>()
+ ->value;
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new NormalShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_normal_cc
void register_node_type_cmp_normal()
@@ -36,6 +75,7 @@ void register_node_type_cmp_normal()
cmp_node_type_base(&ntype, CMP_NODE_NORMAL, "Normal", NODE_CLASS_OP_VECTOR);
ntype.declare = file_ns::cmp_node_normal_declare;
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_normalize.cc b/source/blender/nodes/composite/nodes/node_composite_normalize.cc
index 49318279bdb..34fd63e5805 100644
--- a/source/blender/nodes/composite/nodes/node_composite_normalize.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_normalize.cc
@@ -5,6 +5,10 @@
* \ingroup cmpnodes
*/
+#include "COM_algorithm_parallel_reduction.hh"
+#include "COM_node_operation.hh"
+#include "COM_utilities.hh"
+
#include "node_composite_util.hh"
/* **************** NORMALIZE single channel, useful for Z buffer ******************** */
@@ -13,10 +17,68 @@ namespace blender::nodes::node_composite_normalize_cc {
static void cmp_node_normalize_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Float>(N_("Value")).default_value(1.0f).min(0.0f).max(1.0f);
+ b.add_input<decl::Float>(N_("Value"))
+ .default_value(1.0f)
+ .min(0.0f)
+ .max(1.0f)
+ .compositor_domain_priority(0);
b.add_output<decl::Float>(N_("Value"));
}
+using namespace blender::realtime_compositor;
+
+class NormalizeOperation : public NodeOperation {
+ private:
+ /* The normalize operation is specifically designed to normalize Z Depth information. But since Z
+ * Depth can contain near infinite values, normalization is limited to [-range_, range], meaning
+ * that values outside of that range will be ignored when computing the maximum and minimum for
+ * normalization and will eventually be 0 or 1 if they are less than or larger than the range
+ * respectively. */
+ constexpr static float range_ = 10000.0f;
+
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ Result &input_image = get_input("Value");
+ Result &output_image = get_result("Value");
+ if (input_image.is_single_value()) {
+ input_image.pass_through(output_image);
+ return;
+ }
+
+ const float maximum = maximum_float_in_range(
+ context(), input_image.texture(), -range_, range_);
+ const float minimum = minimum_float_in_range(
+ context(), input_image.texture(), -range_, range_);
+ const float scale = (maximum != minimum) ? (1.0f / (maximum - minimum)) : 0.0f;
+
+ GPUShader *shader = shader_manager().get("compositor_normalize");
+ GPU_shader_bind(shader);
+
+ GPU_shader_uniform_1f(shader, "minimum", minimum);
+ GPU_shader_uniform_1f(shader, "scale", scale);
+
+ input_image.bind_as_texture(shader, "input_tx");
+
+ const Domain domain = compute_domain();
+ output_image.allocate_texture(domain);
+ output_image.bind_as_image(shader, "output_img");
+
+ compute_dispatch_threads_at_least(shader, domain.size);
+
+ GPU_shader_unbind();
+ output_image.unbind_as_image();
+ input_image.unbind_as_texture();
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new NormalizeOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_normalize_cc
void register_node_type_cmp_normalize()
@@ -27,6 +89,7 @@ void register_node_type_cmp_normalize()
cmp_node_type_base(&ntype, CMP_NODE_NORMALIZE, "Normalize", NODE_CLASS_OP_VECTOR);
ntype.declare = file_ns::cmp_node_normalize_declare;
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_output_file.cc b/source/blender/nodes/composite/nodes/node_composite_output_file.cc
index 84235b085a4..f27dec91b1c 100644
--- a/source/blender/nodes/composite/nodes/node_composite_output_file.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_output_file.cc
@@ -24,6 +24,8 @@
#include "IMB_openexr.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** OUTPUT FILE ******************** */
@@ -229,9 +231,7 @@ static void free_output_file(bNode *node)
MEM_freeN(node->storage);
}
-static void copy_output_file(bNodeTree *UNUSED(dest_ntree),
- bNode *dest_node,
- const bNode *src_node)
+static void copy_output_file(bNodeTree * /*dst_ntree*/, bNode *dest_node, const bNode *src_node)
{
bNodeSocket *src_sock, *dest_sock;
@@ -280,7 +280,7 @@ static void update_output_file(bNodeTree *ntree, bNode *node)
}
}
-static void node_composit_buts_file_output(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_file_output(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
PointerRNA imfptr = RNA_pointer_get(ptr, "format");
const bool multilayer = RNA_enum_get(&imfptr, "file_format") == R_IMF_IMTYPE_MULTILAYER;
@@ -439,6 +439,22 @@ static void node_composit_buts_file_output_ex(uiLayout *layout, bContext *C, Poi
}
}
+using namespace blender::realtime_compositor;
+
+class OutputFileOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new OutputFileOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_output_file_cc
void register_node_type_cmp_output_file()
@@ -455,6 +471,7 @@ void register_node_type_cmp_output_file()
node_type_storage(
&ntype, "NodeImageMultiFile", file_ns::free_output_file, file_ns::copy_output_file);
node_type_update(&ntype, file_ns::update_output_file);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_pixelate.cc b/source/blender/nodes/composite/nodes/node_composite_pixelate.cc
index 529aa0f84de..c65bb7bb747 100644
--- a/source/blender/nodes/composite/nodes/node_composite_pixelate.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_pixelate.cc
@@ -5,6 +5,11 @@
* \ingroup cmpnodes
*/
+#include "BLI_math_vec_types.hh"
+#include "BLI_math_vector.hh"
+
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** Pixelate ******************** */
@@ -17,6 +22,52 @@ static void cmp_node_pixelate_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Color>(N_("Color"));
}
+using namespace blender::realtime_compositor;
+
+class PixelateOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ /* It might seems strange that the input is passed through without any processing, but note
+ * that the actual processing happens inside the domain realization input processor of the
+ * input. Indeed, the pixelate node merely realizes its input on a smaller-sized domain that
+ * matches its apparent size, that is, its size after the domain transformation. The pixelate
+ * node has no effect if the input is scaled-up. See the compute_domain method for more
+ * information. */
+ Result &result = get_result("Color");
+ get_input("Color").pass_through(result);
+
+ result.get_realization_options().interpolation = Interpolation::Nearest;
+ }
+
+ /* Compute a smaller-sized domain that matches the apparent size of the input while having a unit
+ * scale transformation, see the execute method for more information. */
+ Domain compute_domain() override
+ {
+ Domain domain = get_input("Color").domain();
+
+ /* Get the scaling component of the domain transformation, but make sure it doesn't exceed 1,
+ * because pixelation should only happen if the input is scaled down. */
+ const float2 scale = math::min(float2(1.0f), domain.transformation.scale_2d());
+
+ /* Multiply the size of the domain by its scale to match its apparent size, but make sure it is
+ * at least 1 pixel in both axis. */
+ domain.size = math::max(int2(float2(domain.size) * scale), int2(1));
+
+ /* Reset the scale of the transformation by transforming it with the inverse of the scale. */
+ domain.transformation *= float3x3::from_scale(math::safe_divide(float2(1.0f), scale));
+
+ return domain;
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new PixelateOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_pixelate_cc
void register_node_type_cmp_pixelate()
@@ -27,6 +78,7 @@ void register_node_type_cmp_pixelate()
cmp_node_type_base(&ntype, CMP_NODE_PIXELATE, "Pixelate", NODE_CLASS_OP_FILTER);
ntype.declare = file_ns::cmp_node_pixelate_declare;
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_planetrackdeform.cc b/source/blender/nodes/composite/nodes/node_composite_planetrackdeform.cc
index 6557478fc4b..68dc020a02e 100644
--- a/source/blender/nodes/composite/nodes/node_composite_planetrackdeform.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_planetrackdeform.cc
@@ -18,6 +18,8 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
namespace blender::nodes::node_composite_planetrackdeform_cc {
@@ -107,6 +109,24 @@ static void node_composit_buts_planetrackdeform(uiLayout *layout, bContext *C, P
}
}
+using namespace blender::realtime_compositor;
+
+class PlaneTrackDeformOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_input("Image").pass_through(get_result("Image"));
+ get_result("Plane").allocate_invalid();
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new PlaneTrackDeformOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_planetrackdeform_cc
void register_node_type_cmp_planetrackdeform()
@@ -121,6 +141,7 @@ void register_node_type_cmp_planetrackdeform()
ntype.initfunc_api = file_ns::init;
node_type_storage(
&ntype, "NodePlaneTrackDeformData", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_posterize.cc b/source/blender/nodes/composite/nodes/node_composite_posterize.cc
index c97035d55ea..1268219e7e2 100644
--- a/source/blender/nodes/composite/nodes/node_composite_posterize.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_posterize.cc
@@ -5,6 +5,10 @@
* \ingroup cmpnodes
*/
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* **************** Posterize ******************** */
@@ -13,11 +17,37 @@ namespace blender::nodes::node_composite_posterize_cc {
static void cmp_node_posterize_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
- b.add_input<decl::Float>(N_("Steps")).default_value(8.0f).min(2.0f).max(1024.0f);
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
+ b.add_input<decl::Float>(N_("Steps"))
+ .default_value(8.0f)
+ .min(2.0f)
+ .max(1024.0f)
+ .compositor_domain_priority(1);
b.add_output<decl::Color>(N_("Image"));
}
+using namespace blender::realtime_compositor;
+
+class PosterizeShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ GPU_stack_link(material, &bnode(), "node_composite_posterize", inputs, outputs);
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new PosterizeShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_posterize_cc
void register_node_type_cmp_posterize()
@@ -28,6 +58,7 @@ void register_node_type_cmp_posterize()
cmp_node_type_base(&ntype, CMP_NODE_POSTERIZE, "Posterize", NODE_CLASS_OP_COLOR);
ntype.declare = file_ns::cmp_node_posterize_declare;
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_premulkey.cc b/source/blender/nodes/composite/nodes/node_composite_premulkey.cc
index 000cc9df90a..85e37e12231 100644
--- a/source/blender/nodes/composite/nodes/node_composite_premulkey.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_premulkey.cc
@@ -8,6 +8,10 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* **************** Premul and Key Alpha Convert ******************** */
@@ -16,15 +20,47 @@ namespace blender::nodes::node_composite_premulkey_cc {
static void cmp_node_premulkey_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_buts_premulkey(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_premulkey(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "mapping", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class AlphaConvertShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ if (get_mode() == 0) {
+ GPU_stack_link(material, &bnode(), "color_alpha_premultiply", inputs, outputs);
+ return;
+ }
+
+ GPU_stack_link(material, &bnode(), "color_alpha_unpremultiply", inputs, outputs);
+ }
+
+ CMPNodeAlphaConvertMode get_mode()
+ {
+ return (CMPNodeAlphaConvertMode)bnode().custom1;
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new AlphaConvertShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_premulkey_cc
void register_node_type_cmp_premulkey()
@@ -36,6 +72,7 @@ void register_node_type_cmp_premulkey()
cmp_node_type_base(&ntype, CMP_NODE_PREMULKEY, "Alpha Convert", NODE_CLASS_CONVERTER);
ntype.declare = file_ns::cmp_node_premulkey_declare;
ntype.draw_buttons = file_ns::node_composit_buts_premulkey;
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_rgb.cc b/source/blender/nodes/composite/nodes/node_composite_rgb.cc
index 5bc4c67dd8e..f107961f301 100644
--- a/source/blender/nodes/composite/nodes/node_composite_rgb.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_rgb.cc
@@ -5,6 +5,12 @@
* \ingroup cmpnodes
*/
+#include "BLI_math_vec_types.hh"
+
+#include "DNA_node_types.h"
+
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** RGB ******************** */
@@ -16,6 +22,29 @@ static void cmp_node_rgb_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Color>(N_("RGBA")).default_value({0.5f, 0.5f, 0.5f, 1.0f});
}
+using namespace blender::realtime_compositor;
+
+class RGBOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ Result &result = get_result("RGBA");
+ result.allocate_single_value();
+
+ const bNodeSocket *socket = static_cast<const bNodeSocket *>(bnode().outputs.first);
+ float4 color = float4(static_cast<const bNodeSocketValueRGBA *>(socket->default_value)->value);
+
+ result.set_color_value(color);
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new RGBOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_rgb_cc
void register_node_type_cmp_rgb()
@@ -27,6 +56,7 @@ void register_node_type_cmp_rgb()
cmp_node_type_base(&ntype, CMP_NODE_RGB, "RGB", NODE_CLASS_INPUT);
ntype.declare = file_ns::cmp_node_rgb_declare;
node_type_size_preset(&ntype, NODE_SIZE_SMALL);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_rotate.cc b/source/blender/nodes/composite/nodes/node_composite_rotate.cc
index a083bc1837b..5f3df3abd35 100644
--- a/source/blender/nodes/composite/nodes/node_composite_rotate.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_rotate.cc
@@ -5,9 +5,14 @@
* \ingroup cmpnodes
*/
+#include "BLI_assert.h"
+#include "BLI_float3x3.hh"
+
#include "UI_interface.h"
#include "UI_resources.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** Rotate ******************** */
@@ -16,25 +21,69 @@ namespace blender::nodes::node_composite_rotate_cc {
static void cmp_node_rotate_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
b.add_input<decl::Float>(N_("Degr"))
.default_value(0.0f)
.min(-10000.0f)
.max(10000.0f)
- .subtype(PROP_ANGLE);
+ .subtype(PROP_ANGLE)
+ .compositor_expects_single_value();
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_init_rotate(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_rotate(bNodeTree * /*ntree*/, bNode *node)
{
node->custom1 = 1; /* Bilinear Filter. */
}
-static void node_composit_buts_rotate(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_rotate(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "filter_type", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class RotateOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ Result &input = get_input("Image");
+ Result &result = get_result("Image");
+ input.pass_through(result);
+
+ const float rotation = get_input("Degr").get_float_value_default(0.0f);
+
+ const float3x3 transformation = float3x3::from_rotation(rotation);
+
+ result.transform(transformation);
+ result.get_realization_options().interpolation = get_interpolation();
+ }
+
+ Interpolation get_interpolation()
+ {
+ switch (bnode().custom1) {
+ case 0:
+ return Interpolation::Nearest;
+ case 1:
+ return Interpolation::Bilinear;
+ case 2:
+ return Interpolation::Bicubic;
+ }
+
+ BLI_assert_unreachable();
+ return Interpolation::Nearest;
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new RotateOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_rotate_cc
void register_node_type_cmp_rotate()
@@ -47,6 +96,7 @@ void register_node_type_cmp_rotate()
ntype.declare = file_ns::cmp_node_rotate_declare;
ntype.draw_buttons = file_ns::node_composit_buts_rotate;
node_type_init(&ntype, file_ns::node_composit_init_rotate);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_scale.cc b/source/blender/nodes/composite/nodes/node_composite_scale.cc
index b2b42a3613c..c524d7b8da9 100644
--- a/source/blender/nodes/composite/nodes/node_composite_scale.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_scale.cc
@@ -5,11 +5,18 @@
* \ingroup cmpnodes
*/
+#include "BLI_assert.h"
+#include "BLI_float3x3.hh"
+#include "BLI_math_base.hh"
+#include "BLI_math_vec_types.hh"
+
#include "RNA_access.h"
#include "UI_interface.h"
#include "UI_resources.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** Scale ******************** */
@@ -18,16 +25,26 @@ namespace blender::nodes::node_composite_scale_cc {
static void cmp_node_scale_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
- b.add_input<decl::Float>(N_("X")).default_value(1.0f).min(0.0001f).max(CMP_SCALE_MAX);
- b.add_input<decl::Float>(N_("Y")).default_value(1.0f).min(0.0001f).max(CMP_SCALE_MAX);
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
+ b.add_input<decl::Float>(N_("X"))
+ .default_value(1.0f)
+ .min(0.0001f)
+ .max(CMP_SCALE_MAX)
+ .compositor_expects_single_value();
+ b.add_input<decl::Float>(N_("Y"))
+ .default_value(1.0f)
+ .min(0.0001f)
+ .max(CMP_SCALE_MAX)
+ .compositor_expects_single_value();
b.add_output<decl::Color>(N_("Image"));
}
static void node_composite_update_scale(bNodeTree *ntree, bNode *node)
{
bNodeSocket *sock;
- bool use_xy_scale = ELEM(node->custom1, CMP_SCALE_RELATIVE, CMP_SCALE_ABSOLUTE);
+ bool use_xy_scale = ELEM(node->custom1, CMP_NODE_SCALE_RELATIVE, CMP_NODE_SCALE_ABSOLUTE);
/* Only show X/Y scale factor inputs for modes using them! */
for (sock = (bNodeSocket *)node->inputs.first; sock; sock = sock->next) {
@@ -37,11 +54,11 @@ static void node_composite_update_scale(bNodeTree *ntree, bNode *node)
}
}
-static void node_composit_buts_scale(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_scale(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "space", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
- if (RNA_enum_get(ptr, "space") == CMP_SCALE_RENDERPERCENT) {
+ if (RNA_enum_get(ptr, "space") == CMP_NODE_SCALE_RENDER_SIZE) {
uiLayout *row;
uiItemR(layout,
ptr,
@@ -55,6 +72,144 @@ static void node_composit_buts_scale(uiLayout *layout, bContext *UNUSED(C), Poin
}
}
+using namespace blender::realtime_compositor;
+
+class ScaleOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ Result &input = get_input("Image");
+ Result &result = get_result("Image");
+ input.pass_through(result);
+
+ const float3x3 transformation = float3x3::from_translation_rotation_scale(
+ get_translation(), 0.0f, get_scale());
+
+ result.transform(transformation);
+ }
+
+ float2 get_scale()
+ {
+ switch (get_scale_method()) {
+ case CMP_NODE_SCALE_RELATIVE:
+ return get_scale_relative();
+ case CMP_NODE_SCALE_ABSOLUTE:
+ return get_scale_absolute();
+ case CMP_NODE_SCALE_RENDER_PERCENT:
+ return get_scale_render_percent();
+ case CMP_NODE_SCALE_RENDER_SIZE:
+ return get_scale_render_size();
+ default:
+ BLI_assert_unreachable();
+ return float2(1.0f);
+ }
+ }
+
+ /* Scale by the input factors. */
+ float2 get_scale_relative()
+ {
+ return float2(get_input("X").get_float_value_default(1.0f),
+ get_input("Y").get_float_value_default(1.0f));
+ }
+
+ /* Scale such that the new size matches the input absolute size. */
+ float2 get_scale_absolute()
+ {
+ const float2 input_size = float2(get_input("Image").domain().size);
+ const float2 absolute_size = float2(get_input("X").get_float_value_default(1.0f),
+ get_input("Y").get_float_value_default(1.0f));
+ return absolute_size / input_size;
+ }
+
+ /* Scale by the render resolution percentage. */
+ float2 get_scale_render_percent()
+ {
+ return float2(context().get_scene()->r.size / 100.0f);
+ }
+
+ float2 get_scale_render_size()
+ {
+ switch (get_scale_render_size_method()) {
+ case CMP_NODE_SCALE_RENDER_SIZE_STRETCH:
+ return get_scale_render_size_stretch();
+ case CMP_NODE_SCALE_RENDER_SIZE_FIT:
+ return get_scale_render_size_fit();
+ case CMP_NODE_SCALE_RENDER_SIZE_CROP:
+ return get_scale_render_size_crop();
+ default:
+ BLI_assert_unreachable();
+ return float2(1.0f);
+ }
+ }
+
+ /* Scale such that the new size matches the render size. Since the input is freely scaled, it is
+ * potentially stretched, hence the name. */
+ float2 get_scale_render_size_stretch()
+ {
+ const float2 input_size = float2(get_input("Image").domain().size);
+ const float2 render_size = float2(context().get_output_size());
+ return render_size / input_size;
+ }
+
+ /* Scale such that the dimension with the smaller scaling factor matches that of the render size
+ * while maintaining the input's aspect ratio. Since the other dimension is guaranteed not to
+ * exceed the render size region due to its larger scaling factor, the image is said to be fit
+ * inside that region, hence the name. */
+ float2 get_scale_render_size_fit()
+ {
+ const float2 input_size = float2(get_input("Image").domain().size);
+ const float2 render_size = float2(context().get_output_size());
+ const float2 scale = render_size / input_size;
+ return float2(math::min(scale.x, scale.y));
+ }
+
+ /* Scale such that the dimension with the larger scaling factor matches that of the render size
+ * while maintaining the input's aspect ratio. Since the other dimension is guaranteed to exceed
+ * the render size region due to its lower scaling factor, the image will be cropped inside that
+ * region, hence the name. */
+ float2 get_scale_render_size_crop()
+ {
+ const float2 input_size = float2(get_input("Image").domain().size);
+ const float2 render_size = float2(context().get_output_size());
+ const float2 scale = render_size / input_size;
+ return float2(math::max(scale.x, scale.y));
+ }
+
+ float2 get_translation()
+ {
+ /* Only the render size option supports offset translation. */
+ if (get_scale_method() != CMP_NODE_SCALE_RENDER_SIZE) {
+ return float2(0.0f);
+ }
+
+ /* Translate by the offset factor relative to the new size. */
+ const float2 input_size = float2(get_input("Image").domain().size);
+ return get_offset() * input_size * get_scale();
+ }
+
+ CMPNodeScaleMethod get_scale_method()
+ {
+ return (CMPNodeScaleMethod)bnode().custom1;
+ }
+
+ CMPNodeScaleRenderSizeMethod get_scale_render_size_method()
+ {
+ return (CMPNodeScaleRenderSizeMethod)bnode().custom2;
+ }
+
+ float2 get_offset()
+ {
+ return float2(bnode().custom3, bnode().custom4);
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new ScaleOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_scale_cc
void register_node_type_cmp_scale()
@@ -67,6 +222,7 @@ void register_node_type_cmp_scale()
ntype.declare = file_ns::cmp_node_scale_declare;
ntype.draw_buttons = file_ns::node_composit_buts_scale;
node_type_update(&ntype, file_ns::node_composite_update_scale);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_scene_time.cc b/source/blender/nodes/composite/nodes/node_composite_scene_time.cc
index 20bafb0d3d4..3a7e7dc78bd 100644
--- a/source/blender/nodes/composite/nodes/node_composite_scene_time.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_scene_time.cc
@@ -3,6 +3,8 @@
* \ingroup cmpnodes
*/
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
namespace blender::nodes {
@@ -13,6 +15,38 @@ static void cmp_node_scene_time_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("Frame"));
}
+using namespace blender::realtime_compositor;
+
+class SceneTimeOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ execute_seconds();
+ execute_frame();
+ }
+
+ void execute_seconds()
+ {
+ Result &result = get_result("Seconds");
+ result.allocate_single_value();
+ result.set_float_value(context().get_time());
+ }
+
+ void execute_frame()
+ {
+ Result &result = get_result("Frame");
+ result.allocate_single_value();
+ result.set_float_value(float(context().get_frame_number()));
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new SceneTimeOperation(context, node);
+}
+
} // namespace blender::nodes
void register_node_type_cmp_scene_time()
@@ -21,5 +55,7 @@ void register_node_type_cmp_scene_time()
cmp_node_type_base(&ntype, CMP_NODE_SCENE_TIME, "Scene Time", NODE_CLASS_INPUT);
ntype.declare = blender::nodes::cmp_node_scene_time_declare;
+ ntype.get_compositor_operation = blender::nodes::get_compositor_operation;
+
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_sepcomb_color.cc b/source/blender/nodes/composite/nodes/node_composite_sepcomb_color.cc
index b253656a628..d3f8530ae8b 100644
--- a/source/blender/nodes/composite/nodes/node_composite_sepcomb_color.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_sepcomb_color.cc
@@ -1,8 +1,14 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "BLI_assert.h"
+
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
-static void node_cmp_combsep_color_init(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_cmp_combsep_color_init(bNodeTree * /*ntree*/, bNode *node)
{
NodeCMPCombSepColor *data = MEM_cnew<NodeCMPCombSepColor>(__func__);
data->mode = CMP_NODE_COMBSEP_COLOR_RGB;
@@ -56,21 +62,71 @@ static void node_cmp_combsep_color_label(const ListBase *sockets, CMPNodeCombSep
namespace blender::nodes::node_composite_separate_color_cc {
+NODE_STORAGE_FUNCS(NodeCMPCombSepColor)
+
static void cmp_node_separate_color_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
b.add_output<decl::Float>(N_("Red"));
b.add_output<decl::Float>(N_("Green"));
b.add_output<decl::Float>(N_("Blue"));
b.add_output<decl::Float>(N_("Alpha"));
}
-static void cmp_node_separate_color_update(bNodeTree *UNUSED(ntree), bNode *node)
+static void cmp_node_separate_color_update(bNodeTree * /*ntree*/, bNode *node)
{
const NodeCMPCombSepColor *storage = (NodeCMPCombSepColor *)node->storage;
node_cmp_combsep_color_label(&node->outputs, (CMPNodeCombSepColorMode)storage->mode);
}
+using namespace blender::realtime_compositor;
+
+class SeparateColorShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ GPU_stack_link(material, &bnode(), get_shader_function_name(), inputs, outputs);
+ }
+
+ const char *get_shader_function_name()
+ {
+ switch (node_storage(bnode()).mode) {
+ case CMP_NODE_COMBSEP_COLOR_RGB:
+ return "node_composite_separate_rgba";
+ case CMP_NODE_COMBSEP_COLOR_HSV:
+ return "node_composite_separate_hsva";
+ case CMP_NODE_COMBSEP_COLOR_HSL:
+ return "node_composite_separate_hsla";
+ case CMP_NODE_COMBSEP_COLOR_YUV:
+ return "node_composite_separate_yuva_itu_709";
+ case CMP_NODE_COMBSEP_COLOR_YCC:
+ switch (node_storage(bnode()).ycc_mode) {
+ case BLI_YCC_ITU_BT601:
+ return "node_composite_separate_ycca_itu_601";
+ case BLI_YCC_ITU_BT709:
+ return "node_composite_separate_ycca_itu_709";
+ case BLI_YCC_JFIF_0_255:
+ return "node_composite_separate_ycca_jpeg";
+ }
+ }
+
+ BLI_assert_unreachable();
+ return nullptr;
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new SeparateColorShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_separate_color_cc
void register_node_type_cmp_separate_color()
@@ -85,6 +141,7 @@ void register_node_type_cmp_separate_color()
node_type_storage(
&ntype, "NodeCMPCombSepColor", node_free_standard_storage, node_copy_standard_storage);
node_type_update(&ntype, file_ns::cmp_node_separate_color_update);
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
@@ -93,33 +150,89 @@ void register_node_type_cmp_separate_color()
namespace blender::nodes::node_composite_combine_color_cc {
+NODE_STORAGE_FUNCS(NodeCMPCombSepColor)
+
static void cmp_node_combine_color_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Float>(N_("Red")).default_value(0.0f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
+ b.add_input<decl::Float>(N_("Red"))
+ .default_value(0.0f)
+ .min(0.0f)
+ .max(1.0f)
+ .subtype(PROP_FACTOR)
+ .compositor_domain_priority(0);
b.add_input<decl::Float>(N_("Green"))
.default_value(0.0f)
.min(0.0f)
.max(1.0f)
- .subtype(PROP_FACTOR);
+ .subtype(PROP_FACTOR)
+ .compositor_domain_priority(1);
b.add_input<decl::Float>(N_("Blue"))
.default_value(0.0f)
.min(0.0f)
.max(1.0f)
- .subtype(PROP_FACTOR);
+ .subtype(PROP_FACTOR)
+ .compositor_domain_priority(2);
b.add_input<decl::Float>(N_("Alpha"))
.default_value(1.0f)
.min(0.0f)
.max(1.0f)
- .subtype(PROP_FACTOR);
+ .subtype(PROP_FACTOR)
+ .compositor_domain_priority(3);
b.add_output<decl::Color>(N_("Image"));
}
-static void cmp_node_combine_color_update(bNodeTree *UNUSED(ntree), bNode *node)
+static void cmp_node_combine_color_update(bNodeTree * /*ntree*/, bNode *node)
{
const NodeCMPCombSepColor *storage = (NodeCMPCombSepColor *)node->storage;
node_cmp_combsep_color_label(&node->inputs, (CMPNodeCombSepColorMode)storage->mode);
}
+using namespace blender::realtime_compositor;
+
+class CombineColorShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ GPU_stack_link(material, &bnode(), get_shader_function_name(), inputs, outputs);
+ }
+
+ const char *get_shader_function_name()
+ {
+ switch (node_storage(bnode()).mode) {
+ case CMP_NODE_COMBSEP_COLOR_RGB:
+ return "node_composite_combine_rgba";
+ case CMP_NODE_COMBSEP_COLOR_HSV:
+ return "node_composite_combine_hsva";
+ case CMP_NODE_COMBSEP_COLOR_HSL:
+ return "node_composite_combine_hsla";
+ case CMP_NODE_COMBSEP_COLOR_YUV:
+ return "node_composite_combine_yuva_itu_709";
+ case CMP_NODE_COMBSEP_COLOR_YCC:
+ switch (node_storage(bnode()).ycc_mode) {
+ case BLI_YCC_ITU_BT601:
+ return "node_composite_combine_ycca_itu_601";
+ case BLI_YCC_ITU_BT709:
+ return "node_composite_combine_ycca_itu_709";
+ case BLI_YCC_JFIF_0_255:
+ return "node_composite_combine_ycca_jpeg";
+ }
+ }
+
+ BLI_assert_unreachable();
+ return nullptr;
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new CombineColorShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_combine_color_cc
void register_node_type_cmp_combine_color()
@@ -134,6 +247,7 @@ void register_node_type_cmp_combine_color()
node_type_storage(
&ntype, "NodeCMPCombSepColor", node_free_standard_storage, node_copy_standard_storage);
node_type_update(&ntype, file_ns::cmp_node_combine_color_update);
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_sepcomb_hsva.cc b/source/blender/nodes/composite/nodes/node_composite_sepcomb_hsva.cc
index a0d2485ea5a..3483285793a 100644
--- a/source/blender/nodes/composite/nodes/node_composite_sepcomb_hsva.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_sepcomb_hsva.cc
@@ -5,57 +5,114 @@
* \ingroup cmpnodes
*/
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* **************** SEPARATE HSVA ******************** */
-namespace blender::nodes::node_composite_sepcomb_hsva_cc {
+namespace blender::nodes::node_composite_separate_hsva_cc {
static void cmp_node_sephsva_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
b.add_output<decl::Float>(N_("H"));
b.add_output<decl::Float>(N_("S"));
b.add_output<decl::Float>(N_("V"));
b.add_output<decl::Float>(N_("A"));
}
-} // namespace blender::nodes::node_composite_sepcomb_hsva_cc
+using namespace blender::realtime_compositor;
+
+class SeparateHSVAShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ GPU_stack_link(material, &bnode(), "node_composite_separate_hsva", inputs, outputs);
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new SeparateHSVAShaderNode(node);
+}
+
+} // namespace blender::nodes::node_composite_separate_hsva_cc
void register_node_type_cmp_sephsva()
{
- namespace file_ns = blender::nodes::node_composite_sepcomb_hsva_cc;
+ namespace file_ns = blender::nodes::node_composite_separate_hsva_cc;
static bNodeType ntype;
- cmp_node_type_base(&ntype, CMP_NODE_SEPHSVA_LEGACY, "Separate HSVA", NODE_CLASS_CONVERTER);
+ cmp_node_type_base(
+ &ntype, CMP_NODE_SEPHSVA_LEGACY, "Separate HSVA (Legacy)", NODE_CLASS_CONVERTER);
ntype.declare = file_ns::cmp_node_sephsva_declare;
+ ntype.gather_link_search_ops = nullptr;
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
+
nodeRegisterType(&ntype);
}
/* **************** COMBINE HSVA ******************** */
-namespace blender::nodes::node_composite_sepcomb_hsva_cc {
+namespace blender::nodes::node_composite_combine_hsva_cc {
static void cmp_node_combhsva_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Float>(N_("H")).min(0.0f).max(1.0f);
- b.add_input<decl::Float>(N_("S")).min(0.0f).max(1.0f);
- b.add_input<decl::Float>(N_("V")).min(0.0f).max(1.0f);
- b.add_input<decl::Float>(N_("A")).default_value(1.0f).min(0.0f).max(1.0f);
+ b.add_input<decl::Float>(N_("H")).min(0.0f).max(1.0f).compositor_domain_priority(0);
+ b.add_input<decl::Float>(N_("S")).min(0.0f).max(1.0f).compositor_domain_priority(1);
+ b.add_input<decl::Float>(N_("V")).min(0.0f).max(1.0f).compositor_domain_priority(2);
+ b.add_input<decl::Float>(N_("A"))
+ .default_value(1.0f)
+ .min(0.0f)
+ .max(1.0f)
+ .compositor_domain_priority(3);
b.add_output<decl::Color>(N_("Image"));
}
-} // namespace blender::nodes::node_composite_sepcomb_hsva_cc
+using namespace blender::realtime_compositor;
+
+class CombineHSVAShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ GPU_stack_link(material, &bnode(), "node_composite_combine_hsva", inputs, outputs);
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new CombineHSVAShaderNode(node);
+}
+
+} // namespace blender::nodes::node_composite_combine_hsva_cc
void register_node_type_cmp_combhsva()
{
- namespace file_ns = blender::nodes::node_composite_sepcomb_hsva_cc;
+ namespace file_ns = blender::nodes::node_composite_combine_hsva_cc;
static bNodeType ntype;
- cmp_node_type_base(&ntype, CMP_NODE_COMBHSVA_LEGACY, "Combine HSVA", NODE_CLASS_CONVERTER);
+ cmp_node_type_base(
+ &ntype, CMP_NODE_COMBHSVA_LEGACY, "Combine HSVA (Legacy)", NODE_CLASS_CONVERTER);
ntype.declare = file_ns::cmp_node_combhsva_declare;
+ ntype.gather_link_search_ops = nullptr;
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_sepcomb_rgba.cc b/source/blender/nodes/composite/nodes/node_composite_sepcomb_rgba.cc
index ae46681b0f4..9308052454d 100644
--- a/source/blender/nodes/composite/nodes/node_composite_sepcomb_rgba.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_sepcomb_rgba.cc
@@ -5,57 +5,114 @@
* \ingroup cmpnodes
*/
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* **************** SEPARATE RGBA ******************** */
-namespace blender::nodes::node_composite_sepcomb_rgba_cc {
+
+namespace blender::nodes::node_composite_separate_rgba_cc {
static void cmp_node_seprgba_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
b.add_output<decl::Float>(N_("R"));
b.add_output<decl::Float>(N_("G"));
b.add_output<decl::Float>(N_("B"));
b.add_output<decl::Float>(N_("A"));
}
-} // namespace blender::nodes::node_composite_sepcomb_rgba_cc
+using namespace blender::realtime_compositor;
+
+class SeparateRGBAShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ GPU_stack_link(material, &bnode(), "node_composite_separate_rgba", inputs, outputs);
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new SeparateRGBAShaderNode(node);
+}
+
+} // namespace blender::nodes::node_composite_separate_rgba_cc
void register_node_type_cmp_seprgba()
{
- namespace file_ns = blender::nodes::node_composite_sepcomb_rgba_cc;
+ namespace file_ns = blender::nodes::node_composite_separate_rgba_cc;
static bNodeType ntype;
- cmp_node_type_base(&ntype, CMP_NODE_SEPRGBA_LEGACY, "Separate RGBA", NODE_CLASS_CONVERTER);
+ cmp_node_type_base(
+ &ntype, CMP_NODE_SEPRGBA_LEGACY, "Separate RGBA (Legacy)", NODE_CLASS_CONVERTER);
ntype.declare = file_ns::cmp_node_seprgba_declare;
+ ntype.gather_link_search_ops = nullptr;
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
/* **************** COMBINE RGBA ******************** */
-namespace blender::nodes::node_composite_sepcomb_rgba_cc {
+namespace blender::nodes::node_composite_combine_rgba_cc {
static void cmp_node_combrgba_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Float>(N_("R")).min(0.0f).max(1.0f);
- b.add_input<decl::Float>(N_("G")).min(0.0f).max(1.0f);
- b.add_input<decl::Float>(N_("B")).min(0.0f).max(1.0f);
- b.add_input<decl::Float>(N_("A")).default_value(1.0f).min(0.0f).max(1.0f);
+ b.add_input<decl::Float>(N_("R")).min(0.0f).max(1.0f).compositor_domain_priority(0);
+ b.add_input<decl::Float>(N_("G")).min(0.0f).max(1.0f).compositor_domain_priority(1);
+ b.add_input<decl::Float>(N_("B")).min(0.0f).max(1.0f).compositor_domain_priority(2);
+ b.add_input<decl::Float>(N_("A"))
+ .default_value(1.0f)
+ .min(0.0f)
+ .max(1.0f)
+ .compositor_domain_priority(3);
b.add_output<decl::Color>(N_("Image"));
}
-} // namespace blender::nodes::node_composite_sepcomb_rgba_cc
+using namespace blender::realtime_compositor;
+
+class CombineRGBAShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ GPU_stack_link(material, &bnode(), "node_composite_combine_rgba", inputs, outputs);
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new CombineRGBAShaderNode(node);
+}
+
+} // namespace blender::nodes::node_composite_combine_rgba_cc
void register_node_type_cmp_combrgba()
{
- namespace file_ns = blender::nodes::node_composite_sepcomb_rgba_cc;
+ namespace file_ns = blender::nodes::node_composite_combine_rgba_cc;
static bNodeType ntype;
- cmp_node_type_base(&ntype, CMP_NODE_COMBRGBA_LEGACY, "Combine RGBA", NODE_CLASS_CONVERTER);
+ cmp_node_type_base(
+ &ntype, CMP_NODE_COMBRGBA_LEGACY, "Combine RGBA (Legacy)", NODE_CLASS_CONVERTER);
ntype.declare = file_ns::cmp_node_combrgba_declare;
+ ntype.gather_link_search_ops = nullptr;
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_sepcomb_xyz.cc b/source/blender/nodes/composite/nodes/node_composite_sepcomb_xyz.cc
index 4979c376cab..e288e698808 100644
--- a/source/blender/nodes/composite/nodes/node_composite_sepcomb_xyz.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_sepcomb_xyz.cc
@@ -5,10 +5,15 @@
* \ingroup cmpnodes
*/
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* **************** SEPARATE XYZ ******************** */
-namespace blender::nodes {
+
+namespace blender::nodes::node_composite_separate_xyz_cc {
static void cmp_node_separate_xyz_declare(NodeDeclarationBuilder &b)
{
@@ -18,21 +23,44 @@ static void cmp_node_separate_xyz_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>("Z");
}
-} // namespace blender::nodes
+using namespace blender::realtime_compositor;
+
+class SeparateXYZShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ GPU_stack_link(material, &bnode(), "node_composite_separate_xyz", inputs, outputs);
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new SeparateXYZShaderNode(node);
+}
+
+} // namespace blender::nodes::node_composite_separate_xyz_cc
void register_node_type_cmp_separate_xyz()
{
+ namespace file_ns = blender::nodes::node_composite_separate_xyz_cc;
+
static bNodeType ntype;
cmp_node_type_base(&ntype, CMP_NODE_SEPARATE_XYZ, "Separate XYZ", NODE_CLASS_CONVERTER);
- ntype.declare = blender::nodes::cmp_node_separate_xyz_declare;
+ ntype.declare = file_ns::cmp_node_separate_xyz_declare;
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
/* **************** COMBINE XYZ ******************** */
-namespace blender::nodes {
+namespace blender::nodes::node_composite_combine_xyz_cc {
static void cmp_node_combine_xyz_declare(NodeDeclarationBuilder &b)
{
@@ -42,14 +70,37 @@ static void cmp_node_combine_xyz_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Vector>("Vector");
}
-} // namespace blender::nodes
+using namespace blender::realtime_compositor;
+
+class CombineXYZShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ GPU_stack_link(material, &bnode(), "node_composite_combine_xyz", inputs, outputs);
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new CombineXYZShaderNode(node);
+}
+
+} // namespace blender::nodes::node_composite_combine_xyz_cc
void register_node_type_cmp_combine_xyz()
{
+ namespace file_ns = blender::nodes::node_composite_combine_xyz_cc;
+
static bNodeType ntype;
cmp_node_type_base(&ntype, CMP_NODE_COMBINE_XYZ, "Combine XYZ", NODE_CLASS_CONVERTER);
- ntype.declare = blender::nodes::cmp_node_combine_xyz_declare;
+ ntype.declare = file_ns::cmp_node_combine_xyz_declare;
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_sepcomb_ycca.cc b/source/blender/nodes/composite/nodes/node_composite_sepcomb_ycca.cc
index a3c40b61e64..82fc37a18f6 100644
--- a/source/blender/nodes/composite/nodes/node_composite_sepcomb_ycca.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_sepcomb_ycca.cc
@@ -5,70 +5,176 @@
* \ingroup cmpnodes
*/
+#include "BLI_assert.h"
+
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* **************** SEPARATE YCCA ******************** */
-namespace blender::nodes::node_composite_sepcomb_ycca_cc {
+namespace blender::nodes::node_composite_separate_ycca_cc {
static void cmp_node_sepycca_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
b.add_output<decl::Float>(N_("Y"));
b.add_output<decl::Float>(N_("Cb"));
b.add_output<decl::Float>(N_("Cr"));
b.add_output<decl::Float>(N_("A"));
}
-static void node_composit_init_mode_sepycca(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_mode_sepycca(bNodeTree * /*ntree*/, bNode *node)
{
node->custom1 = 1; /* BLI_YCC_ITU_BT709 */
}
-} // namespace blender::nodes::node_composite_sepcomb_ycca_cc
+using namespace blender::realtime_compositor;
+
+class SeparateYCCAShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ GPU_stack_link(material, &bnode(), get_shader_function_name(), inputs, outputs);
+ }
+
+ int get_mode()
+ {
+ return bnode().custom1;
+ }
+
+ const char *get_shader_function_name()
+ {
+ switch (get_mode()) {
+ case BLI_YCC_ITU_BT601:
+ return "node_composite_separate_ycca_itu_601";
+ case BLI_YCC_ITU_BT709:
+ return "node_composite_separate_ycca_itu_709";
+ case BLI_YCC_JFIF_0_255:
+ return "node_composite_separate_ycca_jpeg";
+ }
+
+ BLI_assert_unreachable();
+ return nullptr;
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new SeparateYCCAShaderNode(node);
+}
+
+} // namespace blender::nodes::node_composite_separate_ycca_cc
void register_node_type_cmp_sepycca()
{
- namespace file_ns = blender::nodes::node_composite_sepcomb_ycca_cc;
+ namespace file_ns = blender::nodes::node_composite_separate_ycca_cc;
static bNodeType ntype;
- cmp_node_type_base(&ntype, CMP_NODE_SEPYCCA_LEGACY, "Separate YCbCrA", NODE_CLASS_CONVERTER);
+ cmp_node_type_base(
+ &ntype, CMP_NODE_SEPYCCA_LEGACY, "Separate YCbCrA (Legacy)", NODE_CLASS_CONVERTER);
ntype.declare = file_ns::cmp_node_sepycca_declare;
node_type_init(&ntype, file_ns::node_composit_init_mode_sepycca);
+ ntype.gather_link_search_ops = nullptr;
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
/* **************** COMBINE YCCA ******************** */
-namespace blender::nodes::node_composite_sepcomb_ycca_cc {
+namespace blender::nodes::node_composite_combine_ycca_cc {
static void cmp_node_combycca_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Float>(N_("Y")).min(0.0f).max(1.0f);
- b.add_input<decl::Float>(N_("Cb")).default_value(0.5f).min(0.0f).max(1.0f);
- b.add_input<decl::Float>(N_("Cr")).default_value(0.5f).min(0.0f).max(1.0f);
- b.add_input<decl::Float>(N_("A")).default_value(1.0f).min(0.0f).max(1.0f);
+ b.add_input<decl::Float>(N_("Y")).min(0.0f).max(1.0f).compositor_domain_priority(0);
+ b.add_input<decl::Float>(N_("Cb"))
+ .default_value(0.5f)
+ .min(0.0f)
+ .max(1.0f)
+ .compositor_domain_priority(1);
+ b.add_input<decl::Float>(N_("Cr"))
+ .default_value(0.5f)
+ .min(0.0f)
+ .max(1.0f)
+ .compositor_domain_priority(2);
+ b.add_input<decl::Float>(N_("A"))
+ .default_value(1.0f)
+ .min(0.0f)
+ .max(1.0f)
+ .compositor_domain_priority(3);
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_init_mode_combycca(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_mode_combycca(bNodeTree * /*ntree*/, bNode *node)
{
node->custom1 = 1; /* BLI_YCC_ITU_BT709 */
}
-} // namespace blender::nodes::node_composite_sepcomb_ycca_cc
+using namespace blender::realtime_compositor;
+
+class CombineYCCAShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ GPU_stack_link(material, &bnode(), get_shader_function_name(), inputs, outputs);
+ }
+
+ int get_mode()
+ {
+ return bnode().custom1;
+ }
+
+ const char *get_shader_function_name()
+ {
+ switch (get_mode()) {
+ case BLI_YCC_ITU_BT601:
+ return "node_composite_combine_ycca_itu_601";
+ case BLI_YCC_ITU_BT709:
+ return "node_composite_combine_ycca_itu_709";
+ case BLI_YCC_JFIF_0_255:
+ return "node_composite_combine_ycca_jpeg";
+ }
+
+ BLI_assert_unreachable();
+ return nullptr;
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new CombineYCCAShaderNode(node);
+}
+
+} // namespace blender::nodes::node_composite_combine_ycca_cc
void register_node_type_cmp_combycca()
{
- namespace file_ns = blender::nodes::node_composite_sepcomb_ycca_cc;
+ namespace file_ns = blender::nodes::node_composite_combine_ycca_cc;
static bNodeType ntype;
- cmp_node_type_base(&ntype, CMP_NODE_COMBYCCA_LEGACY, "Combine YCbCrA", NODE_CLASS_CONVERTER);
+ cmp_node_type_base(
+ &ntype, CMP_NODE_COMBYCCA_LEGACY, "Combine YCbCrA (Legacy)", NODE_CLASS_CONVERTER);
ntype.declare = file_ns::cmp_node_combycca_declare;
node_type_init(&ntype, file_ns::node_composit_init_mode_combycca);
+ ntype.gather_link_search_ops = nullptr;
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_sepcomb_yuva.cc b/source/blender/nodes/composite/nodes/node_composite_sepcomb_yuva.cc
index 7fdece5904d..b12e70ad9b8 100644
--- a/source/blender/nodes/composite/nodes/node_composite_sepcomb_yuva.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_sepcomb_yuva.cc
@@ -5,58 +5,114 @@
* \ingroup cmpnodes
*/
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* **************** SEPARATE YUVA ******************** */
-namespace blender::nodes::node_composite_sepcomb_yuva_cc {
+namespace blender::nodes::node_composite_separate_yuva_cc {
static void cmp_node_sepyuva_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
b.add_output<decl::Float>(N_("Y"));
b.add_output<decl::Float>(N_("U"));
b.add_output<decl::Float>(N_("V"));
b.add_output<decl::Float>(N_("A"));
}
-} // namespace blender::nodes::node_composite_sepcomb_yuva_cc
+using namespace blender::realtime_compositor;
+
+class SeparateYUVAShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ GPU_stack_link(material, &bnode(), "node_composite_separate_yuva_itu_709", inputs, outputs);
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new SeparateYUVAShaderNode(node);
+}
+
+} // namespace blender::nodes::node_composite_separate_yuva_cc
void register_node_type_cmp_sepyuva()
{
- namespace file_ns = blender::nodes::node_composite_sepcomb_yuva_cc;
+ namespace file_ns = blender::nodes::node_composite_separate_yuva_cc;
static bNodeType ntype;
- cmp_node_type_base(&ntype, CMP_NODE_SEPYUVA_LEGACY, "Separate YUVA", NODE_CLASS_CONVERTER);
+ cmp_node_type_base(
+ &ntype, CMP_NODE_SEPYUVA_LEGACY, "Separate YUVA (Legacy)", NODE_CLASS_CONVERTER);
ntype.declare = file_ns::cmp_node_sepyuva_declare;
+ ntype.gather_link_search_ops = nullptr;
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
/* **************** COMBINE YUVA ******************** */
-namespace blender::nodes::node_composite_sepcomb_yuva_cc {
+namespace blender::nodes::node_composite_combine_yuva_cc {
static void cmp_node_combyuva_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Float>(N_("Y")).min(0.0f).max(1.0f);
- b.add_input<decl::Float>(N_("U")).min(0.0f).max(1.0f);
- b.add_input<decl::Float>(N_("V")).min(0.0f).max(1.0f);
- b.add_input<decl::Float>(N_("A")).default_value(1.0f).min(0.0f).max(1.0f);
+ b.add_input<decl::Float>(N_("Y")).min(0.0f).max(1.0f).compositor_domain_priority(0);
+ b.add_input<decl::Float>(N_("U")).min(0.0f).max(1.0f).compositor_domain_priority(1);
+ b.add_input<decl::Float>(N_("V")).min(0.0f).max(1.0f).compositor_domain_priority(2);
+ b.add_input<decl::Float>(N_("A"))
+ .default_value(1.0f)
+ .min(0.0f)
+ .max(1.0f)
+ .compositor_domain_priority(3);
b.add_output<decl::Color>(N_("Image"));
}
-} // namespace blender::nodes::node_composite_sepcomb_yuva_cc
+using namespace blender::realtime_compositor;
+
+class CombineYUVAShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ GPU_stack_link(material, &bnode(), "node_composite_combine_yuva_itu_709", inputs, outputs);
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new CombineYUVAShaderNode(node);
+}
+
+} // namespace blender::nodes::node_composite_combine_yuva_cc
void register_node_type_cmp_combyuva()
{
- namespace file_ns = blender::nodes::node_composite_sepcomb_yuva_cc;
+ namespace file_ns = blender::nodes::node_composite_combine_yuva_cc;
static bNodeType ntype;
- cmp_node_type_base(&ntype, CMP_NODE_COMBYUVA_LEGACY, "Combine YUVA", NODE_CLASS_CONVERTER);
+ cmp_node_type_base(
+ &ntype, CMP_NODE_COMBYUVA_LEGACY, "Combine YUVA (Legacy)", NODE_CLASS_CONVERTER);
ntype.declare = file_ns::cmp_node_combyuva_declare;
+ ntype.gather_link_search_ops = nullptr;
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_setalpha.cc b/source/blender/nodes/composite/nodes/node_composite_setalpha.cc
index 8aeaafbbf67..725ae6e3fcb 100644
--- a/source/blender/nodes/composite/nodes/node_composite_setalpha.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_setalpha.cc
@@ -8,31 +8,68 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
/* **************** SET ALPHA ******************** */
namespace blender::nodes::node_composite_setalpha_cc {
+NODE_STORAGE_FUNCS(NodeSetAlpha)
+
static void cmp_node_setalpha_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
- b.add_input<decl::Float>(N_("Alpha")).default_value(1.0f).min(0.0f).max(1.0f);
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
+ b.add_input<decl::Float>(N_("Alpha"))
+ .default_value(1.0f)
+ .min(0.0f)
+ .max(1.0f)
+ .compositor_domain_priority(1);
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_init_setalpha(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_setalpha(bNodeTree * /*ntree*/, bNode *node)
{
NodeSetAlpha *settings = MEM_cnew<NodeSetAlpha>(__func__);
node->storage = settings;
settings->mode = CMP_NODE_SETALPHA_MODE_APPLY;
}
-static void node_composit_buts_set_alpha(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_set_alpha(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "mode", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class SetAlphaShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ if (node_storage(bnode()).mode == CMP_NODE_SETALPHA_MODE_APPLY) {
+ GPU_stack_link(material, &bnode(), "node_composite_set_alpha_apply", inputs, outputs);
+ return;
+ }
+
+ GPU_stack_link(material, &bnode(), "node_composite_set_alpha_replace", inputs, outputs);
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new SetAlphaShaderNode(node);
+}
+
} // namespace blender::nodes::node_composite_setalpha_cc
void register_node_type_cmp_setalpha()
@@ -47,6 +84,7 @@ void register_node_type_cmp_setalpha()
node_type_init(&ntype, file_ns::node_composit_init_setalpha);
node_type_storage(
&ntype, "NodeSetAlpha", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_split_viewer.cc b/source/blender/nodes/composite/nodes/node_composite_split_viewer.cc
index ab325c4559f..f25d33033a2 100644
--- a/source/blender/nodes/composite/nodes/node_composite_split_viewer.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_split_viewer.cc
@@ -11,6 +11,12 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_shader.h"
+#include "GPU_texture.h"
+
+#include "COM_node_operation.hh"
+#include "COM_utilities.hh"
+
#include "node_composite_util.hh"
/* **************** SPLIT VIEWER ******************** */
@@ -23,7 +29,7 @@ static void cmp_node_split_viewer_declare(NodeDeclarationBuilder &b)
b.add_input<decl::Color>(N_("Image"), "Image_001");
}
-static void node_composit_init_splitviewer(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_splitviewer(bNodeTree * /*ntree*/, bNode *node)
{
ImageUser *iuser = MEM_cnew<ImageUser>(__func__);
node->storage = iuser;
@@ -33,7 +39,7 @@ static void node_composit_init_splitviewer(bNodeTree *UNUSED(ntree), bNode *node
node->id = (ID *)BKE_image_ensure_viewer(G.main, IMA_TYPE_COMPOSITE, "Viewer Node");
}
-static void node_composit_buts_splitviewer(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_splitviewer(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *row, *col;
@@ -43,6 +49,70 @@ static void node_composit_buts_splitviewer(uiLayout *layout, bContext *UNUSED(C)
uiItemR(col, ptr, "factor", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class ViewerOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ GPUShader *shader = get_split_viewer_shader();
+ GPU_shader_bind(shader);
+
+ const int2 size = compute_domain().size;
+
+ GPU_shader_uniform_1f(shader, "split_ratio", get_split_ratio());
+ GPU_shader_uniform_2iv(shader, "view_size", size);
+
+ const Result &first_image = get_input("Image");
+ first_image.bind_as_texture(shader, "first_image_tx");
+ const Result &second_image = get_input("Image_001");
+ second_image.bind_as_texture(shader, "second_image_tx");
+
+ GPUTexture *output_texture = context().get_output_texture();
+ const int image_unit = GPU_shader_get_texture_binding(shader, "output_img");
+ GPU_texture_image_bind(output_texture, image_unit);
+
+ compute_dispatch_threads_at_least(shader, size);
+
+ first_image.unbind_as_texture();
+ second_image.unbind_as_texture();
+ GPU_texture_image_unbind(output_texture);
+ GPU_shader_unbind();
+ }
+
+ /* The operation domain have the same dimensions of the output without any transformations. */
+ Domain compute_domain() override
+ {
+ return Domain(context().get_output_size());
+ }
+
+ GPUShader *get_split_viewer_shader()
+ {
+ if (get_split_axis() == CMP_NODE_SPLIT_VIEWER_HORIZONTAL) {
+ return shader_manager().get("compositor_split_viewer_horizontal");
+ }
+
+ return shader_manager().get("compositor_split_viewer_vertical");
+ }
+
+ CMPNodeSplitViewerAxis get_split_axis()
+ {
+ return (CMPNodeSplitViewerAxis)bnode().custom2;
+ }
+
+ float get_split_ratio()
+ {
+ return bnode().custom1 / 100.0f;
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new ViewerOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_split_viewer_cc
void register_node_type_cmp_splitviewer()
@@ -57,6 +127,7 @@ void register_node_type_cmp_splitviewer()
ntype.flag |= NODE_PREVIEW;
node_type_init(&ntype, file_ns::node_composit_init_splitviewer);
node_type_storage(&ntype, "ImageUser", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
ntype.no_muting = true;
diff --git a/source/blender/nodes/composite/nodes/node_composite_stabilize2d.cc b/source/blender/nodes/composite/nodes/node_composite_stabilize2d.cc
index 63d00a0864b..75a96a05863 100644
--- a/source/blender/nodes/composite/nodes/node_composite_stabilize2d.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_stabilize2d.cc
@@ -11,6 +11,8 @@
#include "BKE_context.h"
#include "BKE_lib_id.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** Stabilize 2D ******************** */
@@ -58,6 +60,23 @@ static void node_composit_buts_stabilize2d(uiLayout *layout, bContext *C, Pointe
uiItemR(layout, ptr, "invert", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class Stabilize2DOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_input("Image").pass_through(get_result("Image"));
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new Stabilize2DOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_stabilize2d_cc
void register_node_type_cmp_stabilize2d()
@@ -70,6 +89,7 @@ void register_node_type_cmp_stabilize2d()
ntype.declare = file_ns::cmp_node_stabilize2d_declare;
ntype.draw_buttons = file_ns::node_composit_buts_stabilize2d;
ntype.initfunc_api = file_ns::init;
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_sunbeams.cc b/source/blender/nodes/composite/nodes/node_composite_sunbeams.cc
index 766f26745ef..d2ee9f567f2 100644
--- a/source/blender/nodes/composite/nodes/node_composite_sunbeams.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_sunbeams.cc
@@ -8,6 +8,8 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
namespace blender::nodes::node_composite_sunbeams_cc {
@@ -18,7 +20,7 @@ static void cmp_node_sunbeams_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Color>(N_("Image"));
}
-static void init(bNodeTree *UNUSED(ntree), bNode *node)
+static void init(bNodeTree * /*ntree*/, bNode *node)
{
NodeSunBeams *data = MEM_cnew<NodeSunBeams>(__func__);
@@ -27,7 +29,7 @@ static void init(bNodeTree *UNUSED(ntree), bNode *node)
node->storage = data;
}
-static void node_composit_buts_sunbeams(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_sunbeams(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "source", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_EXPAND, "", ICON_NONE);
uiItemR(layout,
@@ -38,6 +40,23 @@ static void node_composit_buts_sunbeams(uiLayout *layout, bContext *UNUSED(C), P
ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class SunBeamsOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_input("Image").pass_through(get_result("Image"));
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new SunBeamsOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_sunbeams_cc
void register_node_type_cmp_sunbeams()
@@ -52,6 +71,7 @@ void register_node_type_cmp_sunbeams()
node_type_init(&ntype, file_ns::init);
node_type_storage(
&ntype, "NodeSunBeams", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_switch.cc b/source/blender/nodes/composite/nodes/node_composite_switch.cc
index bda490572e9..c62ae652029 100644
--- a/source/blender/nodes/composite/nodes/node_composite_switch.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_switch.cc
@@ -8,6 +8,8 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** Switch ******************** */
@@ -21,11 +23,35 @@ static void cmp_node_switch_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_buts_switch(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_switch(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "check", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class SwitchOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ Result &input = get_input(get_condition() ? "On" : "Off");
+ Result &result = get_result("Image");
+ input.pass_through(result);
+ }
+
+ bool get_condition()
+ {
+ return bnode().custom1;
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new SwitchOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_switch_cc
void register_node_type_cmp_switch()
@@ -38,5 +64,7 @@ void register_node_type_cmp_switch()
ntype.declare = file_ns::cmp_node_switch_declare;
ntype.draw_buttons = file_ns::node_composit_buts_switch;
node_type_size_preset(&ntype, NODE_SIZE_SMALL);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
+
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_switchview.cc b/source/blender/nodes/composite/nodes/node_composite_switchview.cc
index 2cf3da03a05..9b21ecab335 100644
--- a/source/blender/nodes/composite/nodes/node_composite_switchview.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_switchview.cc
@@ -11,6 +11,8 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** SWITCH VIEW ******************** */
@@ -127,8 +129,8 @@ static void init_switch_view(const bContext *C, PointerRNA *ptr)
}
static void node_composit_buts_switch_view_ex(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *UNUSED(ptr))
+ bContext * /*C*/,
+ PointerRNA * /*ptr*/)
{
uiItemFullO(layout,
"NODE_OT_switch_view_update",
@@ -140,6 +142,25 @@ static void node_composit_buts_switch_view_ex(uiLayout *layout,
nullptr);
}
+using namespace blender::realtime_compositor;
+
+class SwitchViewOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ Result &input = get_input(context().get_view_name());
+ Result &result = get_result("Image");
+ input.pass_through(result);
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new SwitchViewOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_switchview_cc
void register_node_type_cmp_switch_view()
@@ -153,6 +174,7 @@ void register_node_type_cmp_switch_view()
ntype.draw_buttons_ex = file_ns::node_composit_buts_switch_view_ex;
ntype.initfunc_api = file_ns::init_switch_view;
node_type_update(&ntype, file_ns::cmp_node_switch_view_update);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_texture.cc b/source/blender/nodes/composite/nodes/node_composite_texture.cc
index 7571e97a2cd..5a628aae7a7 100644
--- a/source/blender/nodes/composite/nodes/node_composite_texture.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_texture.cc
@@ -5,6 +5,8 @@
* \ingroup cmpnodes
*/
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** TEXTURE ******************** */
@@ -23,6 +25,24 @@ static void cmp_node_texture_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Color>(N_("Color"));
}
+using namespace blender::realtime_compositor;
+
+class TextureOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_result("Value").allocate_invalid();
+ get_result("Color").allocate_invalid();
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new TextureOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_texture_cc
void register_node_type_cmp_texture()
@@ -34,6 +54,7 @@ void register_node_type_cmp_texture()
cmp_node_type_base(&ntype, CMP_NODE_TEXTURE, "Texture", NODE_CLASS_INPUT);
ntype.declare = file_ns::cmp_node_texture_declare;
ntype.flag |= NODE_PREVIEW;
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_tonemap.cc b/source/blender/nodes/composite/nodes/node_composite_tonemap.cc
index cdfe97b038d..d26a01bb3c9 100644
--- a/source/blender/nodes/composite/nodes/node_composite_tonemap.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_tonemap.cc
@@ -5,22 +5,39 @@
* \ingroup cmpnodes
*/
+#include <cmath>
+
+#include "BLI_assert.h"
+#include "BLI_math_base.hh"
+#include "BLI_math_vec_types.hh"
+#include "BLI_math_vector.hh"
+
#include "RNA_access.h"
#include "UI_interface.h"
#include "UI_resources.h"
+#include "IMB_colormanagement.h"
+
+#include "COM_algorithm_parallel_reduction.hh"
+#include "COM_node_operation.hh"
+#include "COM_utilities.hh"
+
#include "node_composite_util.hh"
namespace blender::nodes::node_composite_tonemap_cc {
+NODE_STORAGE_FUNCS(NodeTonemap)
+
static void cmp_node_tonemap_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_init_tonemap(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_tonemap(bNodeTree * /*ntree*/, bNode *node)
{
NodeTonemap *ntm = MEM_cnew<NodeTonemap>(__func__);
ntm->type = 1;
@@ -36,7 +53,7 @@ static void node_composit_init_tonemap(bNodeTree *UNUSED(ntree), bNode *node)
node->storage = ntm;
}
-static void node_composit_buts_tonemap(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_tonemap(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col;
@@ -58,6 +75,252 @@ static void node_composit_buts_tonemap(uiLayout *layout, bContext *UNUSED(C), Po
}
}
+using namespace blender::realtime_compositor;
+
+class ToneMapOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ Result &input_image = get_input("Image");
+ Result &output_image = get_result("Image");
+ if (input_image.is_single_value()) {
+ input_image.pass_through(output_image);
+ return;
+ }
+
+ switch (get_type()) {
+ case CMP_NODE_TONE_MAP_SIMPLE:
+ execute_simple();
+ return;
+ case CMP_NODE_TONE_MAP_PHOTORECEPTOR:
+ execute_photoreceptor();
+ return;
+ default:
+ BLI_assert_unreachable();
+ return;
+ }
+ }
+
+ /* Tone mapping based on equation (3) from Reinhard, Erik, et al. "Photographic tone reproduction
+ * for digital images." Proceedings of the 29th annual conference on Computer graphics and
+ * interactive techniques. 2002. */
+ void execute_simple()
+ {
+ const float luminance_scale = compute_luminance_scale();
+ const float luminance_scale_blend_factor = compute_luminance_scale_blend_factor();
+ const float gamma = node_storage(bnode()).gamma;
+ const float inverse_gamma = gamma != 0.0f ? 1.0f / gamma : 0.0f;
+
+ GPUShader *shader = shader_manager().get("compositor_tone_map_simple");
+ GPU_shader_bind(shader);
+
+ GPU_shader_uniform_1f(shader, "luminance_scale", luminance_scale);
+ GPU_shader_uniform_1f(shader, "luminance_scale_blend_factor", luminance_scale_blend_factor);
+ GPU_shader_uniform_1f(shader, "inverse_gamma", inverse_gamma);
+
+ const Result &input_image = get_input("Image");
+ input_image.bind_as_texture(shader, "input_tx");
+
+ const Domain domain = compute_domain();
+ Result &output_image = get_result("Image");
+ output_image.allocate_texture(domain);
+ output_image.bind_as_image(shader, "output_img");
+
+ compute_dispatch_threads_at_least(shader, domain.size);
+
+ GPU_shader_unbind();
+ output_image.unbind_as_image();
+ input_image.unbind_as_texture();
+ }
+
+ /* Computes the scaling factor in equation (2) from Reinhard's 2002 paper. */
+ float compute_luminance_scale()
+ {
+ const float geometric_mean = compute_geometric_mean_of_luminance();
+ return geometric_mean != 0.0 ? node_storage(bnode()).key / geometric_mean : 0.0f;
+ }
+
+ /* Computes equation (1) from Reinhard's 2002 paper. However, note that the equation in the paper
+ * is most likely wrong, and the intention is actually to compute the geometric mean through a
+ * logscale arithmetic mean, that is, the division should happen inside the exponential function,
+ * not outside of it. That's because the sum of the log luminance will be a very large negative
+ * number, whose exponential will almost always be zero, which is unexpected and useless. */
+ float compute_geometric_mean_of_luminance()
+ {
+ return std::exp(compute_average_log_luminance());
+ }
+
+ /* Equation (3) from Reinhard's 2002 paper blends between high luminance scaling for high
+ * luminance values and low luminance scaling for low luminance values. This is done by adding 1
+ * to the denominator, since for low luminance values, the denominator will be close to 1 and for
+ * high luminance values, the 1 in the denominator will be relatively insignificant. But the
+ * response of such function is not always ideal, so in this implementation, the 1 was exposed as
+ * a parameter to the user for more flexibility. */
+ float compute_luminance_scale_blend_factor()
+ {
+ return node_storage(bnode()).offset;
+ }
+
+ /* Tone mapping based on equation (1) and the trilinear interpolation between equations (6) and
+ * (7) from Reinhard, Erik, and Kate Devlin. "Dynamic range reduction inspired by photoreceptor
+ * physiology." IEEE transactions on visualization and computer graphics 11.1 (2005): 13-24. */
+ void execute_photoreceptor()
+ {
+ const float4 global_adaptation_level = compute_global_adaptation_level();
+ const float contrast = compute_contrast();
+ const float intensity = compute_intensity();
+ const float chromatic_adaptation = get_chromatic_adaptation();
+ const float light_adaptation = get_light_adaptation();
+
+ GPUShader *shader = shader_manager().get("compositor_tone_map_photoreceptor");
+ GPU_shader_bind(shader);
+
+ GPU_shader_uniform_4fv(shader, "global_adaptation_level", global_adaptation_level);
+ GPU_shader_uniform_1f(shader, "contrast", contrast);
+ GPU_shader_uniform_1f(shader, "intensity", intensity);
+ GPU_shader_uniform_1f(shader, "chromatic_adaptation", chromatic_adaptation);
+ GPU_shader_uniform_1f(shader, "light_adaptation", light_adaptation);
+
+ float luminance_coefficients[3];
+ IMB_colormanagement_get_luminance_coefficients(luminance_coefficients);
+ GPU_shader_uniform_3fv(shader, "luminance_coefficients", luminance_coefficients);
+
+ const Result &input_image = get_input("Image");
+ input_image.bind_as_texture(shader, "input_tx");
+
+ const Domain domain = compute_domain();
+ Result &output_image = get_result("Image");
+ output_image.allocate_texture(domain);
+ output_image.bind_as_image(shader, "output_img");
+
+ compute_dispatch_threads_at_least(shader, domain.size);
+
+ GPU_shader_unbind();
+ output_image.unbind_as_image();
+ input_image.unbind_as_texture();
+ }
+
+ /* Computes the global adaptation level from the trilinear interpolation equations constructed
+ * from equations (6) and (7) in Reinhard's 2005 paper. */
+ float4 compute_global_adaptation_level()
+ {
+ const float4 average_color = compute_average_color();
+ const float average_luminance = compute_average_luminance();
+ const float chromatic_adaptation = get_chromatic_adaptation();
+ return math::interpolate(float4(average_luminance), average_color, chromatic_adaptation);
+ }
+
+ float4 compute_average_color()
+ {
+ /* The average color will reduce to zero if chromatic adaptation is zero, so just return zero
+ * in this case to avoid needlessly computing the average. See the trilinear interpolation
+ * equations constructed from equations (6) and (7) in Reinhard's 2005 paper. */
+ if (get_chromatic_adaptation() == 0.0f) {
+ return float4(0.0f);
+ }
+
+ const Result &input = get_input("Image");
+ return sum_color(context(), input.texture()) / (input.domain().size.x * input.domain().size.y);
+ }
+
+ float compute_average_luminance()
+ {
+ /* The average luminance will reduce to zero if chromatic adaptation is one, so just return
+ * zero in this case to avoid needlessly computing the average. See the trilinear interpolation
+ * equations constructed from equations (6) and (7) in Reinhard's 2005 paper. */
+ if (get_chromatic_adaptation() == 1.0f) {
+ return 0.0f;
+ }
+
+ float luminance_coefficients[3];
+ IMB_colormanagement_get_luminance_coefficients(luminance_coefficients);
+ const Result &input = get_input("Image");
+ float sum = sum_luminance(context(), input.texture(), luminance_coefficients);
+ return sum / (input.domain().size.x * input.domain().size.y);
+ }
+
+ /* Computes equation (5) from Reinhard's 2005 paper. */
+ float compute_intensity()
+ {
+ return std::exp(-node_storage(bnode()).f);
+ }
+
+ /* If the contrast is not zero, return it, otherwise, a zero contrast denote automatic derivation
+ * of the contrast value based on equations (2) and (4) from Reinhard's 2005 paper. */
+ float compute_contrast()
+ {
+ if (node_storage(bnode()).m != 0.0f) {
+ return node_storage(bnode()).m;
+ }
+
+ const float log_maximum_luminance = compute_log_maximum_luminance();
+ const float log_minimum_luminance = compute_log_minimum_luminance();
+
+ /* This is merely to guard against zero division later. */
+ if (log_maximum_luminance == log_minimum_luminance) {
+ return 1.0f;
+ }
+
+ const float average_log_luminance = compute_average_log_luminance();
+ const float dynamic_range = log_maximum_luminance - log_minimum_luminance;
+ const float luminance_key = (log_maximum_luminance - average_log_luminance) / (dynamic_range);
+
+ return 0.3f + 0.7f * std::pow(luminance_key, 1.4f);
+ }
+
+ float compute_average_log_luminance()
+ {
+ const Result &input_image = get_input("Image");
+
+ float luminance_coefficients[3];
+ IMB_colormanagement_get_luminance_coefficients(luminance_coefficients);
+ const float sum_of_log_luminance = sum_log_luminance(
+ context(), input_image.texture(), luminance_coefficients);
+
+ return sum_of_log_luminance / (input_image.domain().size.x * input_image.domain().size.y);
+ }
+
+ float compute_log_maximum_luminance()
+ {
+ float luminance_coefficients[3];
+ IMB_colormanagement_get_luminance_coefficients(luminance_coefficients);
+ const float maximum = maximum_luminance(
+ context(), get_input("Image").texture(), luminance_coefficients);
+ return std::log(math::max(maximum, 1e-5f));
+ }
+
+ float compute_log_minimum_luminance()
+ {
+ float luminance_coefficients[3];
+ IMB_colormanagement_get_luminance_coefficients(luminance_coefficients);
+ const float minimum = minimum_luminance(
+ context(), get_input("Image").texture(), luminance_coefficients);
+ return std::log(math::max(minimum, 1e-5f));
+ }
+
+ float get_chromatic_adaptation()
+ {
+ return node_storage(bnode()).c;
+ }
+
+ float get_light_adaptation()
+ {
+ return node_storage(bnode()).a;
+ }
+
+ CMPNodeToneMapType get_type()
+ {
+ return static_cast<CMPNodeToneMapType>(node_storage(bnode()).type);
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new ToneMapOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_tonemap_cc
void register_node_type_cmp_tonemap()
@@ -71,6 +334,7 @@ void register_node_type_cmp_tonemap()
ntype.draw_buttons = file_ns::node_composit_buts_tonemap;
node_type_init(&ntype, file_ns::node_composit_init_tonemap);
node_type_storage(&ntype, "NodeTonemap", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_trackpos.cc b/source/blender/nodes/composite/nodes/node_composite_trackpos.cc
index 0e99ff59327..0e9bd800f44 100644
--- a/source/blender/nodes/composite/nodes/node_composite_trackpos.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_trackpos.cc
@@ -18,6 +18,8 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
namespace blender::nodes::node_composite_trackpos_cc {
@@ -102,6 +104,25 @@ static void node_composit_buts_trackpos(uiLayout *layout, bContext *C, PointerRN
}
}
+using namespace blender::realtime_compositor;
+
+class TrackPositionOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_result("X").allocate_invalid();
+ get_result("Y").allocate_invalid();
+ get_result("Speed").allocate_invalid();
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new TrackPositionOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_trackpos_cc
void register_node_type_cmp_trackpos()
@@ -116,6 +137,7 @@ void register_node_type_cmp_trackpos()
ntype.initfunc_api = file_ns::init;
node_type_storage(
&ntype, "NodeTrackPosData", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_transform.cc b/source/blender/nodes/composite/nodes/node_composite_transform.cc
index fe72f5e33ca..0eaa860b45f 100644
--- a/source/blender/nodes/composite/nodes/node_composite_transform.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_transform.cc
@@ -5,9 +5,15 @@
* \ingroup cmpnodes
*/
+#include "BLI_assert.h"
+#include "BLI_float3x3.hh"
+#include "BLI_math_vector.h"
+
#include "UI_interface.h"
#include "UI_resources.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** Transform ******************** */
@@ -16,23 +22,83 @@ namespace blender::nodes::node_composite_transform_cc {
static void cmp_node_transform_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({0.8f, 0.8f, 0.8f, 1.0f});
- b.add_input<decl::Float>(N_("X")).default_value(0.0f).min(-10000.0f).max(10000.0f);
- b.add_input<decl::Float>(N_("Y")).default_value(0.0f).min(-10000.0f).max(10000.0f);
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({0.8f, 0.8f, 0.8f, 1.0f})
+ .compositor_domain_priority(0);
+ b.add_input<decl::Float>(N_("X"))
+ .default_value(0.0f)
+ .min(-10000.0f)
+ .max(10000.0f)
+ .compositor_expects_single_value();
+ b.add_input<decl::Float>(N_("Y"))
+ .default_value(0.0f)
+ .min(-10000.0f)
+ .max(10000.0f)
+ .compositor_expects_single_value();
b.add_input<decl::Float>(N_("Angle"))
.default_value(0.0f)
.min(-10000.0f)
.max(10000.0f)
- .subtype(PROP_ANGLE);
- b.add_input<decl::Float>(N_("Scale")).default_value(1.0f).min(0.0001f).max(CMP_SCALE_MAX);
+ .subtype(PROP_ANGLE)
+ .compositor_expects_single_value();
+ b.add_input<decl::Float>(N_("Scale"))
+ .default_value(1.0f)
+ .min(0.0001f)
+ .max(CMP_SCALE_MAX)
+ .compositor_expects_single_value();
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_buts_transform(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_transform(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "filter_type", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class TransformOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ Result &input = get_input("Image");
+ Result &result = get_result("Image");
+ input.pass_through(result);
+
+ const float2 translation = float2(get_input("X").get_float_value_default(0.0f),
+ get_input("Y").get_float_value_default(0.0f));
+ const float rotation = get_input("Angle").get_float_value_default(0.0f);
+ const float2 scale = float2(get_input("Scale").get_float_value_default(1.0f));
+
+ const float3x3 transformation = float3x3::from_translation_rotation_scale(
+ translation, rotation, scale);
+
+ result.transform(transformation);
+ result.get_realization_options().interpolation = get_interpolation();
+ }
+
+ Interpolation get_interpolation()
+ {
+ switch (bnode().custom1) {
+ case 0:
+ return Interpolation::Nearest;
+ case 1:
+ return Interpolation::Bilinear;
+ case 2:
+ return Interpolation::Bicubic;
+ }
+
+ BLI_assert_unreachable();
+ return Interpolation::Nearest;
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new TransformOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_transform_cc
void register_node_type_cmp_transform()
@@ -44,6 +110,7 @@ void register_node_type_cmp_transform()
cmp_node_type_base(&ntype, CMP_NODE_TRANSFORM, "Transform", NODE_CLASS_DISTORT);
ntype.declare = file_ns::cmp_node_transform_declare;
ntype.draw_buttons = file_ns::node_composit_buts_transform;
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_translate.cc b/source/blender/nodes/composite/nodes/node_composite_translate.cc
index bbdc8ca4d31..c8f9f8ee666 100644
--- a/source/blender/nodes/composite/nodes/node_composite_translate.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_translate.cc
@@ -5,35 +5,100 @@
* \ingroup cmpnodes
*/
+#include "BLI_float3x3.hh"
+#include "BLI_math_vec_types.hh"
+
#include "UI_interface.h"
#include "UI_resources.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** Translate ******************** */
namespace blender::nodes::node_composite_translate_cc {
+NODE_STORAGE_FUNCS(NodeTranslateData)
+
static void cmp_node_translate_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
- b.add_input<decl::Float>(N_("X")).default_value(0.0f).min(-10000.0f).max(10000.0f);
- b.add_input<decl::Float>(N_("Y")).default_value(0.0f).min(-10000.0f).max(10000.0f);
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+ .compositor_domain_priority(0);
+ b.add_input<decl::Float>(N_("X"))
+ .default_value(0.0f)
+ .min(-10000.0f)
+ .max(10000.0f)
+ .compositor_expects_single_value();
+ b.add_input<decl::Float>(N_("Y"))
+ .default_value(0.0f)
+ .min(-10000.0f)
+ .max(10000.0f)
+ .compositor_expects_single_value();
b.add_output<decl::Color>(N_("Image"));
}
-static void node_composit_init_translate(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_translate(bNodeTree * /*ntree*/, bNode *node)
{
NodeTranslateData *data = MEM_cnew<NodeTranslateData>(__func__);
node->storage = data;
}
-static void node_composit_buts_translate(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_translate(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "use_relative", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
uiItemR(layout, ptr, "wrap_axis", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class TranslateOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ Result &input = get_input("Image");
+ Result &result = get_result("Image");
+ input.pass_through(result);
+
+ float x = get_input("X").get_float_value_default(0.0f);
+ float y = get_input("Y").get_float_value_default(0.0f);
+ if (get_use_relative()) {
+ x *= input.domain().size.x;
+ y *= input.domain().size.y;
+ }
+
+ const float2 translation = float2(x, y);
+ const float3x3 transformation = float3x3::from_translation(translation);
+
+ result.transform(transformation);
+ result.get_realization_options().repeat_x = get_repeat_x();
+ result.get_realization_options().repeat_y = get_repeat_y();
+ }
+
+ bool get_use_relative()
+ {
+ return node_storage(bnode()).relative;
+ }
+
+ bool get_repeat_x()
+ {
+ return ELEM(node_storage(bnode()).wrap_axis, CMP_NODE_WRAP_X, CMP_NODE_WRAP_XY);
+ }
+
+ bool get_repeat_y()
+ {
+ return ELEM(node_storage(bnode()).wrap_axis, CMP_NODE_WRAP_Y, CMP_NODE_WRAP_XY);
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new TranslateOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_translate_cc
void register_node_type_cmp_translate()
@@ -48,6 +113,7 @@ void register_node_type_cmp_translate()
node_type_init(&ntype, file_ns::node_composit_init_translate);
node_type_storage(
&ntype, "NodeTranslateData", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_val_to_rgb.cc b/source/blender/nodes/composite/nodes/node_composite_val_to_rgb.cc
index df669d5beda..2870b07f207 100644
--- a/source/blender/nodes/composite/nodes/node_composite_val_to_rgb.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_val_to_rgb.cc
@@ -5,31 +5,129 @@
* \ingroup cmpnodes
*/
+#include "BLI_assert.h"
+
+#include "IMB_colormanagement.h"
+
+#include "BKE_colorband.h"
+
+#include "GPU_material.h"
+
+#include "COM_shader_node.hh"
+
#include "node_composite_util.hh"
#include "BKE_colorband.h"
/* **************** VALTORGB ******************** */
-namespace blender::nodes::node_composite_val_to_rgb_cc {
+namespace blender::nodes::node_composite_color_ramp_cc {
static void cmp_node_valtorgb_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Float>(N_("Fac")).default_value(0.5f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
- b.add_output<decl::Color>(N_("Image"));
+ b.add_input<decl::Float>(N_("Fac"))
+ .default_value(0.5f)
+ .min(0.0f)
+ .max(1.0f)
+ .subtype(PROP_FACTOR)
+ .compositor_domain_priority(1);
+ b.add_output<decl::Color>(N_("Image")).compositor_domain_priority(0);
b.add_output<decl::Float>(N_("Alpha"));
}
-static void node_composit_init_valtorgb(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_valtorgb(bNodeTree * /*ntree*/, bNode *node)
{
node->storage = BKE_colorband_add(true);
}
-} // namespace blender::nodes::node_composite_val_to_rgb_cc
+using namespace blender::realtime_compositor;
+
+class ColorRampShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ struct ColorBand *color_band = get_color_band();
+
+ /* Common / easy case optimization. */
+ if ((color_band->tot <= 2) && (color_band->color_mode == COLBAND_BLEND_RGB)) {
+ float mul_bias[2];
+ switch (color_band->ipotype) {
+ case COLBAND_INTERP_LINEAR:
+ mul_bias[0] = 1.0f / (color_band->data[1].pos - color_band->data[0].pos);
+ mul_bias[1] = -mul_bias[0] * color_band->data[0].pos;
+ GPU_stack_link(material,
+ &bnode(),
+ "valtorgb_opti_linear",
+ inputs,
+ outputs,
+ GPU_uniform(mul_bias),
+ GPU_uniform(&color_band->data[0].r),
+ GPU_uniform(&color_band->data[1].r));
+ return;
+ case COLBAND_INTERP_CONSTANT:
+ mul_bias[1] = max_ff(color_band->data[0].pos, color_band->data[1].pos);
+ GPU_stack_link(material,
+ &bnode(),
+ "valtorgb_opti_constant",
+ inputs,
+ outputs,
+ GPU_uniform(&mul_bias[1]),
+ GPU_uniform(&color_band->data[0].r),
+ GPU_uniform(&color_band->data[1].r));
+ return;
+ case COLBAND_INTERP_EASE:
+ mul_bias[0] = 1.0f / (color_band->data[1].pos - color_band->data[0].pos);
+ mul_bias[1] = -mul_bias[0] * color_band->data[0].pos;
+ GPU_stack_link(material,
+ &bnode(),
+ "valtorgb_opti_ease",
+ inputs,
+ outputs,
+ GPU_uniform(mul_bias),
+ GPU_uniform(&color_band->data[0].r),
+ GPU_uniform(&color_band->data[1].r));
+ return;
+ default:
+ BLI_assert_unreachable();
+ return;
+ }
+ }
+
+ float *array, layer;
+ int size;
+ BKE_colorband_evaluate_table_rgba(color_band, &array, &size);
+ GPUNodeLink *tex = GPU_color_band(material, size, array, &layer);
+
+ if (color_band->ipotype == COLBAND_INTERP_CONSTANT) {
+ GPU_stack_link(
+ material, &bnode(), "valtorgb_nearest", inputs, outputs, tex, GPU_constant(&layer));
+ return;
+ }
+
+ GPU_stack_link(material, &bnode(), "valtorgb", inputs, outputs, tex, GPU_constant(&layer));
+ }
+
+ struct ColorBand *get_color_band()
+ {
+ return static_cast<struct ColorBand *>(bnode().storage);
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new ColorRampShaderNode(node);
+}
+
+} // namespace blender::nodes::node_composite_color_ramp_cc
void register_node_type_cmp_valtorgb()
{
- namespace file_ns = blender::nodes::node_composite_val_to_rgb_cc;
+ namespace file_ns = blender::nodes::node_composite_color_ramp_cc;
static bNodeType ntype;
@@ -38,31 +136,63 @@ void register_node_type_cmp_valtorgb()
node_type_size(&ntype, 240, 200, 320);
node_type_init(&ntype, file_ns::node_composit_init_valtorgb);
node_type_storage(&ntype, "ColorBand", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
/* **************** RGBTOBW ******************** */
-namespace blender::nodes::node_composite_val_to_rgb_cc {
+namespace blender::nodes::node_composite_rgb_to_bw_cc {
static void cmp_node_rgbtobw_declare(NodeDeclarationBuilder &b)
{
- b.add_input<decl::Color>(N_("Image")).default_value({0.8f, 0.8f, 0.8f, 1.0f});
+ b.add_input<decl::Color>(N_("Image"))
+ .default_value({0.8f, 0.8f, 0.8f, 1.0f})
+ .compositor_domain_priority(0);
b.add_output<decl::Float>(N_("Val"));
}
-} // namespace blender::nodes::node_composite_val_to_rgb_cc
+using namespace blender::realtime_compositor;
+
+class RGBToBWShaderNode : public ShaderNode {
+ public:
+ using ShaderNode::ShaderNode;
+
+ void compile(GPUMaterial *material) override
+ {
+ GPUNodeStack *inputs = get_inputs_array();
+ GPUNodeStack *outputs = get_outputs_array();
+
+ float luminance_coefficients[3];
+ IMB_colormanagement_get_luminance_coefficients(luminance_coefficients);
+
+ GPU_stack_link(material,
+ &bnode(),
+ "color_to_luminance",
+ inputs,
+ outputs,
+ GPU_constant(luminance_coefficients));
+ }
+};
+
+static ShaderNode *get_compositor_shader_node(DNode node)
+{
+ return new RGBToBWShaderNode(node);
+}
+
+} // namespace blender::nodes::node_composite_rgb_to_bw_cc
void register_node_type_cmp_rgbtobw()
{
- namespace file_ns = blender::nodes::node_composite_val_to_rgb_cc;
+ namespace file_ns = blender::nodes::node_composite_rgb_to_bw_cc;
static bNodeType ntype;
cmp_node_type_base(&ntype, CMP_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTER);
ntype.declare = file_ns::cmp_node_rgbtobw_declare;
node_type_size_preset(&ntype, NODE_SIZE_SMALL);
+ ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_value.cc b/source/blender/nodes/composite/nodes/node_composite_value.cc
index a3269d3d1c2..a96e1db14ad 100644
--- a/source/blender/nodes/composite/nodes/node_composite_value.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_value.cc
@@ -5,6 +5,8 @@
* \ingroup cmpnodes
*/
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** VALUE ******************** */
@@ -16,6 +18,29 @@ static void cmp_node_value_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("Value")).default_value(0.5f);
}
+using namespace blender::realtime_compositor;
+
+class ValueOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ Result &result = get_result("Value");
+ result.allocate_single_value();
+
+ const bNodeSocket *socket = static_cast<bNodeSocket *>(bnode().outputs.first);
+ float value = static_cast<bNodeSocketValueFloat *>(socket->default_value)->value;
+
+ result.set_float_value(value);
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new ValueOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_value_cc
void register_node_type_cmp_value()
@@ -27,6 +52,7 @@ void register_node_type_cmp_value()
cmp_node_type_base(&ntype, CMP_NODE_VALUE, "Value", NODE_CLASS_INPUT);
ntype.declare = file_ns::cmp_node_value_declare;
node_type_size_preset(&ntype, NODE_SIZE_SMALL);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_vec_blur.cc b/source/blender/nodes/composite/nodes/node_composite_vec_blur.cc
index 741f2e0e816..6d43647020f 100644
--- a/source/blender/nodes/composite/nodes/node_composite_vec_blur.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_vec_blur.cc
@@ -8,6 +8,8 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** VECTOR BLUR ******************** */
@@ -27,7 +29,7 @@ static void cmp_node_vec_blur_declare(NodeDeclarationBuilder &b)
}
/* custom1: iterations, custom2: max_speed (0 = no_limit). */
-static void node_composit_init_vecblur(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_vecblur(bNodeTree * /*ntree*/, bNode *node)
{
NodeBlurData *nbd = MEM_cnew<NodeBlurData>(__func__);
node->storage = nbd;
@@ -35,7 +37,7 @@ static void node_composit_init_vecblur(bNodeTree *UNUSED(ntree), bNode *node)
nbd->fac = 1.0f;
}
-static void node_composit_buts_vecblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_vecblur(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col;
@@ -51,6 +53,23 @@ static void node_composit_buts_vecblur(uiLayout *layout, bContext *UNUSED(C), Po
uiItemR(layout, ptr, "use_curved", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class VectorBlurOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_input("Image").pass_through(get_result("Image"));
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new VectorBlurOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_vec_blur_cc
void register_node_type_cmp_vecblur()
@@ -65,6 +84,7 @@ void register_node_type_cmp_vecblur()
node_type_init(&ntype, file_ns::node_composit_init_vecblur);
node_type_storage(
&ntype, "NodeBlurData", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_viewer.cc b/source/blender/nodes/composite/nodes/node_composite_viewer.cc
index 05f395183b5..c83674fa9c1 100644
--- a/source/blender/nodes/composite/nodes/node_composite_viewer.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_viewer.cc
@@ -5,6 +5,8 @@
* \ingroup cmpnodes
*/
+#include "BLI_math_vec_types.hh"
+
#include "BKE_global.h"
#include "BKE_image.h"
@@ -13,6 +15,13 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_shader.h"
+#include "GPU_state.h"
+#include "GPU_texture.h"
+
+#include "COM_node_operation.hh"
+#include "COM_utilities.hh"
+
#include "node_composite_util.hh"
/* **************** VIEWER ******************** */
@@ -26,7 +35,7 @@ static void cmp_node_viewer_declare(NodeDeclarationBuilder &b)
b.add_input<decl::Float>(N_("Z")).default_value(1.0f).min(0.0f).max(1.0f);
}
-static void node_composit_init_viewer(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_composit_init_viewer(bNodeTree * /*ntree*/, bNode *node)
{
ImageUser *iuser = MEM_cnew<ImageUser>(__func__);
node->storage = iuser;
@@ -37,12 +46,12 @@ static void node_composit_init_viewer(bNodeTree *UNUSED(ntree), bNode *node)
node->id = (ID *)BKE_image_ensure_viewer(G.main, IMA_TYPE_COMPOSITE, "Viewer Node");
}
-static void node_composit_buts_viewer(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_viewer(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "use_alpha", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
-static void node_composit_buts_viewer_ex(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_viewer_ex(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col;
@@ -55,6 +64,125 @@ static void node_composit_buts_viewer_ex(uiLayout *layout, bContext *UNUSED(C),
}
}
+using namespace blender::realtime_compositor;
+
+class ViewerOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ const Result &image = get_input("Image");
+ const Result &alpha = get_input("Alpha");
+
+ if (image.is_single_value() && alpha.is_single_value()) {
+ execute_clear();
+ }
+ else if (ignore_alpha()) {
+ execute_ignore_alpha();
+ }
+ else if (!node().input_by_identifier("Alpha")->is_logically_linked()) {
+ execute_copy();
+ }
+ else {
+ execute_set_alpha();
+ }
+ }
+
+ /* Executes when all inputs are single values, in which case, the output texture can just be
+ * cleared to the appropriate color. */
+ void execute_clear()
+ {
+ const Result &image = get_input("Image");
+ const Result &alpha = get_input("Alpha");
+
+ float4 color = image.get_color_value();
+ if (ignore_alpha()) {
+ color.w = 1.0f;
+ }
+ else if (node().input_by_identifier("Alpha")->is_logically_linked()) {
+ color.w = alpha.get_float_value();
+ }
+
+ GPU_texture_clear(context().get_output_texture(), GPU_DATA_FLOAT, color);
+ }
+
+ /* Executes when the alpha channel of the image is ignored. */
+ void execute_ignore_alpha()
+ {
+ GPUShader *shader = shader_manager().get("compositor_convert_color_to_opaque");
+ GPU_shader_bind(shader);
+
+ const Result &image = get_input("Image");
+ image.bind_as_texture(shader, "input_tx");
+
+ GPUTexture *output_texture = context().get_output_texture();
+ const int image_unit = GPU_shader_get_texture_binding(shader, "output_img");
+ GPU_texture_image_bind(output_texture, image_unit);
+
+ compute_dispatch_threads_at_least(shader, compute_domain().size);
+
+ image.unbind_as_texture();
+ GPU_texture_image_unbind(output_texture);
+ GPU_shader_unbind();
+ }
+
+ /* Executes when the image texture is written with no adjustments and can thus be copied directly
+ * to the output texture. */
+ void execute_copy()
+ {
+ const Result &image = get_input("Image");
+
+ /* Make sure any prior writes to the texture are reflected before copying it. */
+ GPU_memory_barrier(GPU_BARRIER_TEXTURE_UPDATE);
+
+ GPU_texture_copy(context().get_output_texture(), image.texture());
+ }
+
+ /* Executes when the alpha channel of the image is set as the value of the input alpha. */
+ void execute_set_alpha()
+ {
+ GPUShader *shader = shader_manager().get("compositor_set_alpha");
+ GPU_shader_bind(shader);
+
+ const Result &image = get_input("Image");
+ image.bind_as_texture(shader, "image_tx");
+
+ const Result &alpha = get_input("Alpha");
+ alpha.bind_as_texture(shader, "alpha_tx");
+
+ GPUTexture *output_texture = context().get_output_texture();
+ const int image_unit = GPU_shader_get_texture_binding(shader, "output_img");
+ GPU_texture_image_bind(output_texture, image_unit);
+
+ compute_dispatch_threads_at_least(shader, compute_domain().size);
+
+ image.unbind_as_texture();
+ alpha.unbind_as_texture();
+ GPU_texture_image_unbind(output_texture);
+ GPU_shader_unbind();
+ }
+
+ /* If true, the alpha channel of the image is set to 1, that is, it becomes opaque. If false, the
+ * alpha channel of the image is retained, but only if the alpha input is not linked. If the
+ * alpha input is linked, it the value of that input will be used as the alpha of the image. */
+ bool ignore_alpha()
+ {
+ return bnode().custom2 & CMP_NODE_OUTPUT_IGNORE_ALPHA;
+ }
+
+ /* The operation domain have the same dimensions of the output without any transformations. */
+ Domain compute_domain() override
+ {
+ return Domain(context().get_output_size());
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new ViewerOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_viewer_cc
void register_node_type_cmp_viewer()
@@ -70,6 +198,7 @@ void register_node_type_cmp_viewer()
ntype.flag |= NODE_PREVIEW;
node_type_init(&ntype, file_ns::node_composit_init_viewer);
node_type_storage(&ntype, "ImageUser", node_free_standard_storage, node_copy_standard_storage);
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
ntype.no_muting = true;
diff --git a/source/blender/nodes/composite/nodes/node_composite_zcombine.cc b/source/blender/nodes/composite/nodes/node_composite_zcombine.cc
index be90aeb7acc..c1d9442e9ad 100644
--- a/source/blender/nodes/composite/nodes/node_composite_zcombine.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_zcombine.cc
@@ -8,6 +8,8 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "COM_node_operation.hh"
+
#include "node_composite_util.hh"
/* **************** Z COMBINE ******************** */
@@ -24,7 +26,7 @@ static void cmp_node_zcombine_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("Z"));
}
-static void node_composit_buts_zcombine(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_composit_buts_zcombine(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col;
@@ -33,6 +35,24 @@ static void node_composit_buts_zcombine(uiLayout *layout, bContext *UNUSED(C), P
uiItemR(col, ptr, "use_antialias_z", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
+using namespace blender::realtime_compositor;
+
+class ZCombineOperation : public NodeOperation {
+ public:
+ using NodeOperation::NodeOperation;
+
+ void execute() override
+ {
+ get_input("Image").pass_through(get_result("Image"));
+ get_result("Z").allocate_invalid();
+ }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+ return new ZCombineOperation(context, node);
+}
+
} // namespace blender::nodes::node_composite_zcombine_cc
void register_node_type_cmp_zcombine()
@@ -44,6 +64,7 @@ void register_node_type_cmp_zcombine()
cmp_node_type_base(&ntype, CMP_NODE_ZCOMBINE, "Z Combine", NODE_CLASS_OP_COLOR);
ntype.declare = file_ns::cmp_node_zcombine_declare;
ntype.draw_buttons = file_ns::node_composit_buts_zcombine;
+ ntype.get_compositor_operation = file_ns::get_compositor_operation;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/function/node_function_util.cc b/source/blender/nodes/function/node_function_util.cc
index d956f91a91d..82459815b77 100644
--- a/source/blender/nodes/function/node_function_util.cc
+++ b/source/blender/nodes/function/node_function_util.cc
@@ -5,7 +5,7 @@
#include "NOD_socket_search_link.hh"
-static bool fn_node_poll_default(bNodeType *UNUSED(ntype),
+static bool fn_node_poll_default(bNodeType * /*ntype*/,
bNodeTree *ntree,
const char **r_disabled_hint)
{
diff --git a/source/blender/nodes/function/node_function_util.hh b/source/blender/nodes/function/node_function_util.hh
index fd0b6c31b1d..059b2f9bc17 100644
--- a/source/blender/nodes/function/node_function_util.hh
+++ b/source/blender/nodes/function/node_function_util.hh
@@ -23,4 +23,6 @@
#include "FN_multi_function_builder.hh"
+#include "RNA_access.h"
+
void fn_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass);
diff --git a/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc b/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc
index 7d08d57c503..9e21fc86871 100644
--- a/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc
+++ b/source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc
@@ -26,7 +26,7 @@ static void fn_node_align_euler_to_vector_declare(NodeDeclarationBuilder &b)
}
static void fn_node_align_euler_to_vector_layout(uiLayout *layout,
- bContext *UNUSED(C),
+ bContext * /*C*/,
PointerRNA *ptr)
{
uiItemR(layout, ptr, "axis", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
@@ -159,7 +159,7 @@ class MF_AlignEulerToVector : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
const VArray<float3> &input_rotations = params.readonly_single_input<float3>(0, "Rotation");
const VArray<float> &factors = params.readonly_single_input<float>(1, "Factor");
@@ -190,7 +190,7 @@ class MF_AlignEulerToVector : public fn::MultiFunction {
static void fn_node_align_euler_to_vector_build_multi_function(NodeMultiFunctionBuilder &builder)
{
- bNode &node = builder.node();
+ const bNode &node = builder.node();
builder.construct_and_set_matching_fn<MF_AlignEulerToVector>(node.custom1, node.custom2);
}
diff --git a/source/blender/nodes/function/nodes/node_fn_boolean_math.cc b/source/blender/nodes/function/nodes/node_fn_boolean_math.cc
index b6d7e6c9a5f..7fc7829186a 100644
--- a/source/blender/nodes/function/nodes/node_fn_boolean_math.cc
+++ b/source/blender/nodes/function/nodes/node_fn_boolean_math.cc
@@ -22,7 +22,7 @@ static void fn_node_boolean_math_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Bool>(N_("Boolean"));
}
-static void fn_node_boolean_math_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void fn_node_boolean_math_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
}
@@ -34,7 +34,7 @@ static void node_boolean_math_update(bNodeTree *ntree, bNode *node)
nodeSetSocketAvailability(ntree, sockB, !ELEM(node->custom1, NODE_BOOLEAN_MATH_NOT));
}
-static void node_boolean_math_label(const bNodeTree *UNUSED(ntree),
+static void node_boolean_math_label(const bNodeTree * /*tree*/,
const bNode *node,
char *label,
int maxlen)
@@ -68,7 +68,7 @@ static void node_gather_link_searches(GatherLinkSearchOpParams &params)
}
}
-static const fn::MultiFunction *get_multi_function(bNode &bnode)
+static const fn::MultiFunction *get_multi_function(const bNode &bnode)
{
static auto exec_preset = fn::CustomMF_presets::AllSpanOrSingle();
static fn::CustomMF_SI_SI_SO<bool, bool, bool> and_fn{
diff --git a/source/blender/nodes/function/nodes/node_fn_combine_color.cc b/source/blender/nodes/function/nodes/node_fn_combine_color.cc
index c5fd3ce38a1..fddf606dfc9 100644
--- a/source/blender/nodes/function/nodes/node_fn_combine_color.cc
+++ b/source/blender/nodes/function/nodes/node_fn_combine_color.cc
@@ -31,25 +31,25 @@ static void fn_node_combine_color_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Color>(N_("Color"));
};
-static void fn_node_combine_color_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void fn_node_combine_color_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
}
-static void fn_node_combine_color_update(bNodeTree *UNUSED(ntree), bNode *node)
+static void fn_node_combine_color_update(bNodeTree * /*tree*/, bNode *node)
{
const NodeCombSepColor &storage = node_storage(*node);
node_combsep_color_label(&node->inputs, (NodeCombSepColorMode)storage.mode);
}
-static void fn_node_combine_color_init(bNodeTree *UNUSED(tree), bNode *node)
+static void fn_node_combine_color_init(bNodeTree * /*tree*/, bNode *node)
{
NodeCombSepColor *data = MEM_cnew<NodeCombSepColor>(__func__);
data->mode = NODE_COMBSEP_COLOR_RGB;
node->storage = data;
}
-static const fn::MultiFunction *get_multi_function(bNode &bnode)
+static const fn::MultiFunction *get_multi_function(const bNode &bnode)
{
const NodeCombSepColor &storage = node_storage(bnode);
diff --git a/source/blender/nodes/function/nodes/node_fn_compare.cc b/source/blender/nodes/function/nodes/node_fn_compare.cc
index e3f13dc7d6b..4dd8d0c6ba4 100644
--- a/source/blender/nodes/function/nodes/node_fn_compare.cc
+++ b/source/blender/nodes/function/nodes/node_fn_compare.cc
@@ -44,7 +44,7 @@ static void fn_node_compare_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Bool>(N_("Result"));
}
-static void geo_node_compare_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void geo_node_compare_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
const NodeFunctionCompare &data = node_storage(*static_cast<const bNode *>(ptr->data));
uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE);
@@ -82,7 +82,7 @@ static void node_compare_update(bNodeTree *ntree, bNode *node)
data->data_type == SOCK_VECTOR);
}
-static void node_compare_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_compare_init(bNodeTree * /*tree*/, bNode *node)
{
NodeFunctionCompare *data = MEM_cnew<NodeFunctionCompare>(__func__);
data->operation = NODE_COMPARE_GREATER_THAN;
@@ -148,7 +148,7 @@ static void node_compare_gather_link_searches(GatherLinkSearchOpParams &params)
}
}
-static void node_compare_label(const bNodeTree *UNUSED(ntree),
+static void node_compare_label(const bNodeTree * /*tree*/,
const bNode *node,
char *label,
int maxlen)
@@ -167,7 +167,7 @@ static float component_average(float3 a)
return (a.x + a.y + a.z) / 3.0f;
}
-static const fn::MultiFunction *get_multi_function(bNode &node)
+static const fn::MultiFunction *get_multi_function(const bNode &node)
{
const NodeFunctionCompare *data = (NodeFunctionCompare *)node.storage;
diff --git a/source/blender/nodes/function/nodes/node_fn_float_to_int.cc b/source/blender/nodes/function/nodes/node_fn_float_to_int.cc
index 9c9d8620a7e..aa039309b3f 100644
--- a/source/blender/nodes/function/nodes/node_fn_float_to_int.cc
+++ b/source/blender/nodes/function/nodes/node_fn_float_to_int.cc
@@ -21,12 +21,12 @@ static void fn_node_float_to_int_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Int>(N_("Integer"));
}
-static void fn_node_float_to_int_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void fn_node_float_to_int_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "rounding_mode", 0, "", ICON_NONE);
}
-static void node_float_to_int_label(const bNodeTree *UNUSED(ntree),
+static void node_float_to_int_label(const bNodeTree * /*tree*/,
const bNode *node,
char *label,
int maxlen)
@@ -39,17 +39,17 @@ static void node_float_to_int_label(const bNodeTree *UNUSED(ntree),
BLI_strncpy(label, IFACE_(name), maxlen);
}
-static const fn::MultiFunction *get_multi_function(bNode &bnode)
+static const fn::MultiFunction *get_multi_function(const bNode &bnode)
{
static auto exec_preset = fn::CustomMF_presets::AllSpanOrSingle();
static fn::CustomMF_SI_SO<float, int> round_fn{
- "Round", [](float a) { return (int)round(a); }, exec_preset};
+ "Round", [](float a) { return int(round(a)); }, exec_preset};
static fn::CustomMF_SI_SO<float, int> floor_fn{
- "Floor", [](float a) { return (int)floor(a); }, exec_preset};
+ "Floor", [](float a) { return int(floor(a)); }, exec_preset};
static fn::CustomMF_SI_SO<float, int> ceil_fn{
- "Ceiling", [](float a) { return (int)ceil(a); }, exec_preset};
+ "Ceiling", [](float a) { return int(ceil(a)); }, exec_preset};
static fn::CustomMF_SI_SO<float, int> trunc_fn{
- "Truncate", [](float a) { return (int)trunc(a); }, exec_preset};
+ "Truncate", [](float a) { return int(trunc(a)); }, exec_preset};
switch (static_cast<FloatToIntRoundingMode>(bnode.custom1)) {
case FN_NODE_FLOAT_TO_INT_ROUND:
diff --git a/source/blender/nodes/function/nodes/node_fn_input_bool.cc b/source/blender/nodes/function/nodes/node_fn_input_bool.cc
index 5ced719627f..c68de06a91b 100644
--- a/source/blender/nodes/function/nodes/node_fn_input_bool.cc
+++ b/source/blender/nodes/function/nodes/node_fn_input_bool.cc
@@ -14,7 +14,7 @@ static void fn_node_input_bool_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Bool>(N_("Boolean"));
}
-static void fn_node_input_bool_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void fn_node_input_bool_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col = uiLayoutColumn(layout, true);
uiItemR(col, ptr, "boolean", UI_ITEM_R_EXPAND, IFACE_("Value"), ICON_NONE);
@@ -22,12 +22,12 @@ static void fn_node_input_bool_layout(uiLayout *layout, bContext *UNUSED(C), Poi
static void fn_node_input_bool_build_multi_function(NodeMultiFunctionBuilder &builder)
{
- bNode &bnode = builder.node();
+ const bNode &bnode = builder.node();
NodeInputBool *node_storage = static_cast<NodeInputBool *>(bnode.storage);
builder.construct_and_set_matching_fn<fn::CustomMF_Constant<bool>>(node_storage->boolean);
}
-static void fn_node_input_bool_init(bNodeTree *UNUSED(ntree), bNode *node)
+static void fn_node_input_bool_init(bNodeTree * /*tree*/, bNode *node)
{
NodeInputBool *data = MEM_cnew<NodeInputBool>(__func__);
node->storage = data;
diff --git a/source/blender/nodes/function/nodes/node_fn_input_color.cc b/source/blender/nodes/function/nodes/node_fn_input_color.cc
index 46787f7575d..9a66066189a 100644
--- a/source/blender/nodes/function/nodes/node_fn_input_color.cc
+++ b/source/blender/nodes/function/nodes/node_fn_input_color.cc
@@ -14,7 +14,7 @@ static void fn_node_input_color_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Color>(N_("Color"));
}
-static void fn_node_input_color_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void fn_node_input_color_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiTemplateColorPicker(layout, ptr, "color", true, false, false, true);
uiItemR(layout, ptr, "color", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
@@ -23,13 +23,13 @@ static void fn_node_input_color_layout(uiLayout *layout, bContext *UNUSED(C), Po
static void fn_node_input_color_build_multi_function(
blender::nodes::NodeMultiFunctionBuilder &builder)
{
- bNode &bnode = builder.node();
+ const bNode &bnode = builder.node();
NodeInputColor *node_storage = static_cast<NodeInputColor *>(bnode.storage);
blender::ColorGeometry4f color = (ColorGeometry4f)node_storage->color;
builder.construct_and_set_matching_fn<blender::fn::CustomMF_Constant<ColorGeometry4f>>(color);
}
-static void fn_node_input_color_init(bNodeTree *UNUSED(ntree), bNode *node)
+static void fn_node_input_color_init(bNodeTree * /*tree*/, bNode *node)
{
NodeInputColor *data = MEM_cnew<NodeInputColor>(__func__);
copy_v4_fl4(data->color, 0.5f, 0.5f, 0.5f, 1.0f);
diff --git a/source/blender/nodes/function/nodes/node_fn_input_int.cc b/source/blender/nodes/function/nodes/node_fn_input_int.cc
index 1e5dcd5ae7a..5285c242d88 100644
--- a/source/blender/nodes/function/nodes/node_fn_input_int.cc
+++ b/source/blender/nodes/function/nodes/node_fn_input_int.cc
@@ -14,7 +14,7 @@ static void fn_node_input_int_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Int>(N_("Integer"));
}
-static void fn_node_input_int_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void fn_node_input_int_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col = uiLayoutColumn(layout, true);
uiItemR(col, ptr, "integer", UI_ITEM_R_EXPAND, "", ICON_NONE);
@@ -22,12 +22,12 @@ static void fn_node_input_int_layout(uiLayout *layout, bContext *UNUSED(C), Poin
static void fn_node_input_int_build_multi_function(NodeMultiFunctionBuilder &builder)
{
- bNode &bnode = builder.node();
+ const bNode &bnode = builder.node();
NodeInputInt *node_storage = static_cast<NodeInputInt *>(bnode.storage);
builder.construct_and_set_matching_fn<fn::CustomMF_Constant<int>>(node_storage->integer);
}
-static void fn_node_input_int_init(bNodeTree *UNUSED(ntree), bNode *node)
+static void fn_node_input_int_init(bNodeTree * /*tree*/, bNode *node)
{
NodeInputInt *data = MEM_cnew<NodeInputInt>(__func__);
node->storage = data;
diff --git a/source/blender/nodes/function/nodes/node_fn_input_special_characters.cc b/source/blender/nodes/function/nodes/node_fn_input_special_characters.cc
index 88dc95aa026..b61bd6b5e22 100644
--- a/source/blender/nodes/function/nodes/node_fn_input_special_characters.cc
+++ b/source/blender/nodes/function/nodes/node_fn_input_special_characters.cc
@@ -26,7 +26,7 @@ class MF_SpecialCharacters : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
MutableSpan<std::string> lb = params.uninitialized_single_output<std::string>(0, "Line Break");
MutableSpan<std::string> tab = params.uninitialized_single_output<std::string>(1, "Tab");
diff --git a/source/blender/nodes/function/nodes/node_fn_input_string.cc b/source/blender/nodes/function/nodes/node_fn_input_string.cc
index 124a8572f78..a7172d9fcf9 100644
--- a/source/blender/nodes/function/nodes/node_fn_input_string.cc
+++ b/source/blender/nodes/function/nodes/node_fn_input_string.cc
@@ -13,20 +13,20 @@ static void fn_node_input_string_declare(NodeDeclarationBuilder &b)
b.add_output<decl::String>(N_("String"));
}
-static void fn_node_input_string_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void fn_node_input_string_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "string", 0, "", ICON_NONE);
}
static void fn_node_input_string_build_multi_function(NodeMultiFunctionBuilder &builder)
{
- bNode &bnode = builder.node();
+ const bNode &bnode = builder.node();
NodeInputString *node_storage = static_cast<NodeInputString *>(bnode.storage);
std::string string = std::string((node_storage->string) ? node_storage->string : "");
builder.construct_and_set_matching_fn<fn::CustomMF_Constant<std::string>>(std::move(string));
}
-static void fn_node_input_string_init(bNodeTree *UNUSED(ntree), bNode *node)
+static void fn_node_input_string_init(bNodeTree * /*tree*/, bNode *node)
{
node->storage = MEM_callocN(sizeof(NodeInputString), __func__);
}
@@ -43,9 +43,7 @@ static void fn_node_input_string_free(bNode *node)
MEM_freeN(storage);
}
-static void fn_node_string_copy(bNodeTree *UNUSED(dest_ntree),
- bNode *dest_node,
- const bNode *src_node)
+static void fn_node_string_copy(bNodeTree * /*dst_ntree*/, bNode *dest_node, const bNode *src_node)
{
NodeInputString *source_storage = (NodeInputString *)src_node->storage;
NodeInputString *destination_storage = (NodeInputString *)MEM_dupallocN(source_storage);
diff --git a/source/blender/nodes/function/nodes/node_fn_input_vector.cc b/source/blender/nodes/function/nodes/node_fn_input_vector.cc
index 898c19e92f0..49c8a6284e0 100644
--- a/source/blender/nodes/function/nodes/node_fn_input_vector.cc
+++ b/source/blender/nodes/function/nodes/node_fn_input_vector.cc
@@ -14,7 +14,7 @@ static void fn_node_input_vector_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Vector>(N_("Vector"));
}
-static void fn_node_input_vector_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void fn_node_input_vector_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col = uiLayoutColumn(layout, true);
uiItemR(col, ptr, "vector", UI_ITEM_R_EXPAND, "", ICON_NONE);
@@ -22,13 +22,13 @@ static void fn_node_input_vector_layout(uiLayout *layout, bContext *UNUSED(C), P
static void fn_node_input_vector_build_multi_function(NodeMultiFunctionBuilder &builder)
{
- bNode &bnode = builder.node();
+ const bNode &bnode = builder.node();
NodeInputVector *node_storage = static_cast<NodeInputVector *>(bnode.storage);
float3 vector(node_storage->vector);
builder.construct_and_set_matching_fn<fn::CustomMF_Constant<float3>>(vector);
}
-static void fn_node_input_vector_init(bNodeTree *UNUSED(ntree), bNode *node)
+static void fn_node_input_vector_init(bNodeTree * /*tree*/, bNode *node)
{
NodeInputVector *data = MEM_cnew<NodeInputVector>(__func__);
node->storage = data;
diff --git a/source/blender/nodes/function/nodes/node_fn_random_value.cc b/source/blender/nodes/function/nodes/node_fn_random_value.cc
index 360695299cb..9f842e81071 100644
--- a/source/blender/nodes/function/nodes/node_fn_random_value.cc
+++ b/source/blender/nodes/function/nodes/node_fn_random_value.cc
@@ -33,7 +33,7 @@ static void fn_node_random_value_declare(NodeDeclarationBuilder &b)
.subtype(PROP_FACTOR)
.supports_field()
.make_available([](bNode &node) { node_storage(node).data_type = CD_PROP_BOOL; });
- b.add_input<decl::Int>(N_("ID")).implicit_field();
+ b.add_input<decl::Int>(N_("ID")).implicit_field(implicit_field_inputs::id_or_index);
b.add_input<decl::Int>(N_("Seed")).default_value(0).min(-10000).max(10000).supports_field();
b.add_output<decl::Vector>(N_("Value")).dependent_field();
@@ -42,12 +42,12 @@ static void fn_node_random_value_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Bool>(N_("Value"), "Value_003").dependent_field();
}
-static void fn_node_random_value_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void fn_node_random_value_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE);
}
-static void fn_node_random_value_init(bNodeTree *UNUSED(tree), bNode *node)
+static void fn_node_random_value_init(bNodeTree * /*tree*/, bNode *node)
{
NodeRandomValue *data = MEM_cnew<NodeRandomValue>(__func__);
data->data_type = CD_PROP_FLOAT;
diff --git a/source/blender/nodes/function/nodes/node_fn_rotate_euler.cc b/source/blender/nodes/function/nodes/node_fn_rotate_euler.cc
index a4fc1a6bfd1..813d0a265f7 100644
--- a/source/blender/nodes/function/nodes/node_fn_rotate_euler.cc
+++ b/source/blender/nodes/function/nodes/node_fn_rotate_euler.cc
@@ -46,13 +46,13 @@ static void fn_node_rotate_euler_update(bNodeTree *ntree, bNode *node)
ntree, angle_socket, ELEM(node->custom1, FN_NODE_ROTATE_EULER_TYPE_AXIS_ANGLE));
}
-static void fn_node_rotate_euler_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void fn_node_rotate_euler_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "type", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
uiItemR(layout, ptr, "space", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
}
-static const fn::MultiFunction *get_multi_function(bNode &bnode)
+static const fn::MultiFunction *get_multi_function(const bNode &bnode)
{
static fn::CustomMF_SI_SI_SO<float3, float3, float3> obj_euler_rot{
"Rotate Euler by Euler/Object", [](const float3 &input, const float3 &rotation) {
diff --git a/source/blender/nodes/function/nodes/node_fn_separate_color.cc b/source/blender/nodes/function/nodes/node_fn_separate_color.cc
index 19613427835..19753f93b5c 100644
--- a/source/blender/nodes/function/nodes/node_fn_separate_color.cc
+++ b/source/blender/nodes/function/nodes/node_fn_separate_color.cc
@@ -19,18 +19,18 @@ static void fn_node_separate_color_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("Alpha"));
};
-static void fn_node_separate_color_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void fn_node_separate_color_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
}
-static void fn_node_separate_color_update(bNodeTree *UNUSED(ntree), bNode *node)
+static void fn_node_separate_color_update(bNodeTree * /*tree*/, bNode *node)
{
const NodeCombSepColor &storage = node_storage(*node);
node_combsep_color_label(&node->outputs, (NodeCombSepColorMode)storage.mode);
}
-static void fn_node_separate_color_init(bNodeTree *UNUSED(tree), bNode *node)
+static void fn_node_separate_color_init(bNodeTree * /*tree*/, bNode *node)
{
NodeCombSepColor *data = MEM_cnew<NodeCombSepColor>(__func__);
data->mode = NODE_COMBSEP_COLOR_RGB;
@@ -56,7 +56,7 @@ class SeparateRGBAFunction : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
const VArray<ColorGeometry4f> &colors = params.readonly_single_input<ColorGeometry4f>(0,
"Color");
@@ -117,7 +117,7 @@ class SeparateHSVAFunction : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
const VArray<ColorGeometry4f> &colors = params.readonly_single_input<ColorGeometry4f>(0,
"Color");
@@ -157,7 +157,7 @@ class SeparateHSLAFunction : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
const VArray<ColorGeometry4f> &colors = params.readonly_single_input<ColorGeometry4f>(0,
"Color");
diff --git a/source/blender/nodes/geometry/CMakeLists.txt b/source/blender/nodes/geometry/CMakeLists.txt
index d87f0312958..2b8de906a77 100644
--- a/source/blender/nodes/geometry/CMakeLists.txt
+++ b/source/blender/nodes/geometry/CMakeLists.txt
@@ -56,16 +56,20 @@ set(SRC
nodes/node_geo_curve_subdivide.cc
nodes/node_geo_curve_to_mesh.cc
nodes/node_geo_curve_to_points.cc
+ nodes/node_geo_curve_topology_curve_of_point.cc
+ nodes/node_geo_curve_topology_points_of_curve.cc
nodes/node_geo_curve_trim.cc
nodes/node_geo_deform_curves_on_surface.cc
nodes/node_geo_delete_geometry.cc
+ nodes/node_geo_distribute_points_in_volume.cc
nodes/node_geo_distribute_points_on_faces.cc
nodes/node_geo_dual_mesh.cc
nodes/node_geo_duplicate_elements.cc
+ nodes/node_geo_edge_paths_to_curves.cc
+ nodes/node_geo_edge_paths_to_selection.cc
nodes/node_geo_edge_split.cc
nodes/node_geo_extrude_mesh.cc
nodes/node_geo_field_at_index.cc
- nodes/node_geo_field_on_domain.cc
nodes/node_geo_flip_faces.cc
nodes/node_geo_geometry_to_instance.cc
nodes/node_geo_image_texture.cc
@@ -91,17 +95,20 @@ set(SRC
nodes/node_geo_input_radius.cc
nodes/node_geo_input_scene_time.cc
nodes/node_geo_input_shade_smooth.cc
+ nodes/node_geo_input_shortest_edge_paths.cc
nodes/node_geo_input_spline_cyclic.cc
nodes/node_geo_input_spline_length.cc
nodes/node_geo_input_spline_resolution.cc
nodes/node_geo_input_tangent.cc
nodes/node_geo_instance_on_points.cc
nodes/node_geo_instances_to_points.cc
+ nodes/node_geo_interpolate_domain.cc
nodes/node_geo_is_viewport.cc
nodes/node_geo_join_geometry.cc
nodes/node_geo_material_replace.cc
nodes/node_geo_material_selection.cc
nodes/node_geo_merge_by_distance.cc
+ nodes/node_geo_mesh_face_set_boundaries.cc
nodes/node_geo_mesh_primitive_circle.cc
nodes/node_geo_mesh_primitive_cone.cc
nodes/node_geo_mesh_primitive_cube.cc
@@ -114,7 +121,15 @@ set(SRC
nodes/node_geo_mesh_to_curve.cc
nodes/node_geo_mesh_to_points.cc
nodes/node_geo_mesh_to_volume.cc
+ nodes/node_geo_mesh_topology_corners_of_face.cc
+ nodes/node_geo_mesh_topology_corners_of_vertex.cc
+ nodes/node_geo_mesh_topology_edges_of_corner.cc
+ nodes/node_geo_mesh_topology_edges_of_vertex.cc
+ nodes/node_geo_mesh_topology_face_of_corner.cc
+ nodes/node_geo_mesh_topology_offset_corner_in_face.cc
+ nodes/node_geo_mesh_topology_vertex_of_corner.cc
nodes/node_geo_object_info.cc
+ nodes/node_geo_offset_point_in_curve.cc
nodes/node_geo_points.cc
nodes/node_geo_points_to_vertices.cc
nodes/node_geo_points_to_volume.cc
@@ -123,11 +138,17 @@ set(SRC
nodes/node_geo_realize_instances.cc
nodes/node_geo_remove_attribute.cc
nodes/node_geo_rotate_instances.cc
+ nodes/node_geo_sample_index.cc
+ nodes/node_geo_sample_nearest.cc
+ nodes/node_geo_sample_nearest_surface.cc
+ nodes/node_geo_sample_uv_surface.cc
nodes/node_geo_scale_elements.cc
nodes/node_geo_scale_instances.cc
+ nodes/node_geo_self_object.cc
nodes/node_geo_separate_components.cc
nodes/node_geo_separate_geometry.cc
nodes/node_geo_set_curve_handles.cc
+ nodes/node_geo_set_curve_normal.cc
nodes/node_geo_set_curve_radius.cc
nodes/node_geo_set_curve_tilt.cc
nodes/node_geo_set_id.cc
@@ -143,7 +164,6 @@ set(SRC
nodes/node_geo_string_to_curves.cc
nodes/node_geo_subdivision_surface.cc
nodes/node_geo_switch.cc
- nodes/node_geo_transfer_attribute.cc
nodes/node_geo_transform.cc
nodes/node_geo_translate_instances.cc
nodes/node_geo_triangulate.cc
@@ -184,20 +204,6 @@ if(WITH_BULLET)
add_definitions(-DWITH_BULLET)
endif()
-if(WITH_PYTHON)
- list(APPEND INC
- ../../python
- )
- list(APPEND INC_SYS
- ${PYTHON_INCLUDE_DIRS}
- )
- list(APPEND LIB
- ${PYTHON_LINKFLAGS}
- ${PYTHON_LIBRARIES}
- )
- add_definitions(-DWITH_PYTHON)
-endif()
-
if(WITH_TBB)
list(APPEND INC_SYS
${TBB_INCLUDE_DIRS}
diff --git a/source/blender/nodes/geometry/node_geometry_exec.cc b/source/blender/nodes/geometry/node_geometry_exec.cc
index 58ded7aadd2..ef4daf94bbe 100644
--- a/source/blender/nodes/geometry/node_geometry_exec.cc
+++ b/source/blender/nodes/geometry/node_geometry_exec.cc
@@ -4,3 +4,4 @@
#include "NOD_geometry_exec.hh"
BLI_CPP_TYPE_MAKE(GeometrySet, GeometrySet, CPPTypeFlags::Printable);
+BLI_CPP_TYPE_MAKE(GeometrySetVector, blender::Vector<GeometrySet>, CPPTypeFlags::None);
diff --git a/source/blender/nodes/geometry/node_geometry_tree.cc b/source/blender/nodes/geometry/node_geometry_tree.cc
index 38e914b9a9f..1339024b776 100644
--- a/source/blender/nodes/geometry/node_geometry_tree.cc
+++ b/source/blender/nodes/geometry/node_geometry_tree.cc
@@ -7,6 +7,7 @@
#include "NOD_geometry.h"
#include "BKE_context.h"
+#include "BKE_layer.h"
#include "BKE_node.h"
#include "BKE_object.h"
@@ -25,14 +26,13 @@
bNodeTreeType *ntreeType_Geometry;
-static void geometry_node_tree_get_from_context(const bContext *C,
- bNodeTreeType *UNUSED(treetype),
- bNodeTree **r_ntree,
- ID **r_id,
- ID **r_from)
+static void geometry_node_tree_get_from_context(
+ const bContext *C, bNodeTreeType * /*treetype*/, bNodeTree **r_ntree, ID **r_id, ID **r_from)
{
+ const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
- Object *ob = OBACT(view_layer);
+ BKE_view_layer_synced_ensure(scene, view_layer);
+ Object *ob = BKE_view_layer_active_object_get(view_layer);
if (ob == nullptr) {
return;
@@ -45,7 +45,7 @@ static void geometry_node_tree_get_from_context(const bContext *C,
}
if (md->type == eModifierType_Nodes) {
- NodesModifierData *nmd = (NodesModifierData *)md;
+ const NodesModifierData *nmd = reinterpret_cast<const NodesModifierData *>(md);
if (nmd->node_group != nullptr) {
*r_from = &ob->id;
*r_id = &ob->id;
@@ -62,7 +62,7 @@ static void geometry_node_tree_update(bNodeTree *ntree)
ntree_update_reroute_nodes(ntree);
}
-static void foreach_nodeclass(Scene *UNUSED(scene), void *calldata, bNodeClassCallback func)
+static void foreach_nodeclass(Scene * /*scene*/, void *calldata, bNodeClassCallback func)
{
func(calldata, NODE_CLASS_INPUT, N_("Input"));
func(calldata, NODE_CLASS_GEOMETRY, N_("Geometry"));
@@ -85,7 +85,7 @@ static bool geometry_node_tree_validate_link(eNodeSocketDatatype type_a,
return type_a == type_b;
}
-static bool geometry_node_tree_socket_type_valid(bNodeTreeType *UNUSED(ntreetype),
+static bool geometry_node_tree_socket_type_valid(bNodeTreeType * /*treetype*/,
bNodeSocketType *socket_type)
{
return nodeIsStaticSocketType(socket_type) && ELEM(socket_type->type,
@@ -109,6 +109,7 @@ void register_node_tree_type_geo()
MEM_callocN(sizeof(bNodeTreeType), "geometry node tree type"));
tt->type = NTREE_GEOMETRY;
strcpy(tt->idname, "GeometryNodeTree");
+ strcpy(tt->group_idname, "GeometryNodeGroup");
strcpy(tt->ui_name, N_("Geometry Node Editor"));
tt->ui_icon = ICON_GEOMETRY_NODES;
strcpy(tt->ui_description, N_("Geometry nodes"));
diff --git a/source/blender/nodes/geometry/node_geometry_util.cc b/source/blender/nodes/geometry/node_geometry_util.cc
index 8f673d2264e..8b962d39b3c 100644
--- a/source/blender/nodes/geometry/node_geometry_util.cc
+++ b/source/blender/nodes/geometry/node_geometry_util.cc
@@ -36,14 +36,12 @@ std::optional<eCustomDataType> node_data_type_to_custom_data_type(const eNodeSoc
std::optional<eCustomDataType> node_socket_to_custom_data_type(const bNodeSocket &socket)
{
- return node_data_type_to_custom_data_type(static_cast<eNodeSocketDatatype>(socket.type));
+ return node_data_type_to_custom_data_type(eNodeSocketDatatype(socket.type));
}
} // namespace blender::nodes
-bool geo_node_poll_default(bNodeType *UNUSED(ntype),
- bNodeTree *ntree,
- const char **r_disabled_hint)
+bool geo_node_poll_default(bNodeType * /*ntype*/, bNodeTree *ntree, const char **r_disabled_hint)
{
if (!STREQ(ntree->idname, "GeometryNodeTree")) {
*r_disabled_hint = TIP_("Not a geometry node tree");
diff --git a/source/blender/nodes/geometry/node_geometry_util.hh b/source/blender/nodes/geometry/node_geometry_util.hh
index efb7efaf1cc..adcf47f57fe 100644
--- a/source/blender/nodes/geometry/node_geometry_util.hh
+++ b/source/blender/nodes/geometry/node_geometry_util.hh
@@ -20,8 +20,12 @@
#include "NOD_socket_declarations.hh"
#include "NOD_socket_declarations_geometry.hh"
+#include "RNA_access.h"
+
#include "node_util.h"
+struct BVHTreeFromMesh;
+
void geo_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass);
bool geo_node_poll_default(struct bNodeType *ntype,
struct bNodeTree *ntree,
@@ -34,7 +38,8 @@ void transform_mesh(Mesh &mesh,
const float3 rotation,
const float3 scale);
-void transform_geometry_set(GeometrySet &geometry,
+void transform_geometry_set(GeoNodeExecParams &params,
+ GeometrySet &geometry,
const float4x4 &transform,
const Depsgraph &depsgraph);
@@ -75,7 +80,34 @@ void separate_geometry(GeometrySet &geometry_set,
const Field<bool> &selection_field,
bool &r_is_error);
+void get_closest_in_bvhtree(BVHTreeFromMesh &tree_data,
+ const VArray<float3> &positions,
+ const IndexMask mask,
+ const MutableSpan<int> r_indices,
+ const MutableSpan<float> r_distances_sq,
+ const MutableSpan<float3> r_positions);
+
+int apply_offset_in_cyclic_range(IndexRange range, int start_index, int offset);
+
std::optional<eCustomDataType> node_data_type_to_custom_data_type(eNodeSocketDatatype type);
std::optional<eCustomDataType> node_socket_to_custom_data_type(const bNodeSocket &socket);
+class FieldAtIndexInput final : public bke::GeometryFieldInput {
+ private:
+ Field<int> index_field_;
+ GField value_field_;
+ eAttrDomain value_field_domain_;
+
+ public:
+ FieldAtIndexInput(Field<int> index_field, GField value_field, eAttrDomain value_field_domain);
+
+ GVArray get_varray_for_context(const bke::GeometryFieldContext &context,
+ const IndexMask mask) const final;
+
+ std::optional<eAttrDomain> preferred_domain(const GeometryComponent & /*component*/) const final
+ {
+ return value_field_domain_;
+ }
+};
+
} // namespace blender::nodes
diff --git a/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc b/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc
index 58fbfb5a000..9af445090e9 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc
@@ -70,13 +70,13 @@ static void node_declare(NodeDeclarationBuilder &b)
.description(N_(total_out_description));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE);
uiItemR(layout, ptr, "domain", 0, "", ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeAccumulateField *data = MEM_cnew<NodeAccumulateField>(__func__);
data->data_type = CD_PROP_FLOAT;
@@ -87,13 +87,13 @@ static void node_init(bNodeTree *UNUSED(tree), bNode *node)
static void node_update(bNodeTree *ntree, bNode *node)
{
const NodeAccumulateField &storage = node_storage(*node);
- const eCustomDataType data_type = static_cast<eCustomDataType>(storage.data_type);
+ const eCustomDataType data_type = eCustomDataType(storage.data_type);
- bNodeSocket *sock_in_vector = (bNodeSocket *)node->inputs.first;
+ bNodeSocket *sock_in_vector = static_cast<bNodeSocket *>(node->inputs.first);
bNodeSocket *sock_in_float = sock_in_vector->next;
bNodeSocket *sock_in_int = sock_in_float->next;
- bNodeSocket *sock_out_vector = (bNodeSocket *)node->outputs.first;
+ bNodeSocket *sock_out_vector = static_cast<bNodeSocket *>(node->outputs.first);
bNodeSocket *sock_out_float = sock_out_vector->next;
bNodeSocket *sock_out_int = sock_out_float->next;
@@ -192,7 +192,7 @@ static void node_gather_link_searches(GatherLinkSearchOpParams &params)
}
}
-template<typename T> class AccumulateFieldInput final : public GeometryFieldInput {
+template<typename T> class AccumulateFieldInput final : public bke::GeometryFieldInput {
private:
Field<T> input_;
Field<int> group_index_;
@@ -204,7 +204,7 @@ template<typename T> class AccumulateFieldInput final : public GeometryFieldInpu
Field<T> input,
Field<int> group_index,
AccumulationMode accumulation_mode)
- : GeometryFieldInput(CPPType::get<T>(), "Accumulation"),
+ : bke::GeometryFieldInput(CPPType::get<T>(), "Accumulation"),
input_(input),
group_index_(group_index),
source_domain_(source_domain),
@@ -212,18 +212,18 @@ template<typename T> class AccumulateFieldInput final : public GeometryFieldInpu
{
}
- GVArray get_varray_for_context(const GeometryComponent &component,
- const eAttrDomain domain,
- IndexMask UNUSED(mask)) const final
+ GVArray get_varray_for_context(const bke::GeometryFieldContext &context,
+ const IndexMask /*mask*/) const final
{
- const GeometryComponentFieldContext field_context{component, source_domain_};
- const int domain_size = component.attribute_domain_size(field_context.domain());
+ const AttributeAccessor attributes = *context.attributes();
+ const int domain_size = attributes.domain_size(source_domain_);
if (domain_size == 0) {
return {};
}
- const AttributeAccessor attributes = *component.attributes();
- fn::FieldEvaluator evaluator{field_context, domain_size};
+ const bke::GeometryFieldContext source_context{
+ context.geometry(), context.type(), source_domain_};
+ fn::FieldEvaluator evaluator{source_context, domain_size};
evaluator.add(input_);
evaluator.add(group_index_);
evaluator.evaluate();
@@ -266,7 +266,7 @@ template<typename T> class AccumulateFieldInput final : public GeometryFieldInpu
}
return attributes.adapt_domain<T>(
- VArray<T>::ForContainer(std::move(accumulations_out)), source_domain_, domain);
+ VArray<T>::ForContainer(std::move(accumulations_out)), source_domain_, context.domain());
}
uint64_t hash() const override
@@ -285,9 +285,15 @@ template<typename T> class AccumulateFieldInput final : public GeometryFieldInpu
}
return false;
}
+
+ std::optional<eAttrDomain> preferred_domain(
+ const GeometryComponent & /*component*/) const override
+ {
+ return source_domain_;
+ }
};
-template<typename T> class TotalFieldInput final : public GeometryFieldInput {
+template<typename T> class TotalFieldInput final : public bke::GeometryFieldInput {
private:
Field<T> input_;
Field<int> group_index_;
@@ -295,25 +301,25 @@ template<typename T> class TotalFieldInput final : public GeometryFieldInput {
public:
TotalFieldInput(const eAttrDomain source_domain, Field<T> input, Field<int> group_index)
- : GeometryFieldInput(CPPType::get<T>(), "Total Value"),
+ : bke::GeometryFieldInput(CPPType::get<T>(), "Total Value"),
input_(input),
group_index_(group_index),
source_domain_(source_domain)
{
}
- GVArray get_varray_for_context(const GeometryComponent &component,
- const eAttrDomain domain,
- IndexMask UNUSED(mask)) const final
+ GVArray get_varray_for_context(const bke::GeometryFieldContext &context,
+ IndexMask /*mask*/) const final
{
- const GeometryComponentFieldContext field_context{component, source_domain_};
- const int domain_size = component.attribute_domain_size(field_context.domain());
+ const AttributeAccessor attributes = *context.attributes();
+ const int domain_size = attributes.domain_size(source_domain_);
if (domain_size == 0) {
return {};
}
- const AttributeAccessor attributes = *component.attributes();
- fn::FieldEvaluator evaluator{field_context, domain_size};
+ const bke::GeometryFieldContext source_context{
+ context.geometry(), context.type(), source_domain_};
+ fn::FieldEvaluator evaluator{source_context, domain_size};
evaluator.add(input_);
evaluator.add(group_index_);
evaluator.evaluate();
@@ -339,7 +345,7 @@ template<typename T> class TotalFieldInput final : public GeometryFieldInput {
}
return attributes.adapt_domain<T>(
- VArray<T>::ForContainer(std::move(accumulations_out)), source_domain_, domain);
+ VArray<T>::ForContainer(std::move(accumulations_out)), source_domain_, context.domain());
}
uint64_t hash() const override
@@ -355,6 +361,12 @@ template<typename T> class TotalFieldInput final : public GeometryFieldInput {
}
return false;
}
+
+ std::optional<eAttrDomain> preferred_domain(
+ const GeometryComponent & /*component*/) const override
+ {
+ return source_domain_;
+ }
};
template<typename T> std::string identifier_suffix()
@@ -373,8 +385,8 @@ template<typename T> std::string identifier_suffix()
static void node_geo_exec(GeoNodeExecParams params)
{
const NodeAccumulateField &storage = node_storage(params.node());
- const eCustomDataType data_type = static_cast<eCustomDataType>(storage.data_type);
- const eAttrDomain source_domain = static_cast<eAttrDomain>(storage.domain);
+ const eCustomDataType data_type = eCustomDataType(storage.data_type);
+ const eAttrDomain source_domain = eAttrDomain(storage.domain);
Field<int> group_index_field = params.extract_input<Field<int>>("Group Index");
attribute_math::convert_to_static_type(data_type, [&](auto dummy) {
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc
index 9f317075bb5..1aea129bd53 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc
@@ -30,7 +30,7 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Int>(N_("Attribute"), "Attribute_004").field_source();
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
@@ -38,7 +38,7 @@ static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
uiItemR(layout, ptr, "domain", 0, "", ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryAttributeCapture *data = MEM_cnew<NodeGeometryAttributeCapture>(__func__);
data->data_type = CD_PROP_FLOAT;
@@ -50,9 +50,9 @@ static void node_init(bNodeTree *UNUSED(tree), bNode *node)
static void node_update(bNodeTree *ntree, bNode *node)
{
const NodeGeometryAttributeCapture &storage = node_storage(*node);
- const eCustomDataType data_type = static_cast<eCustomDataType>(storage.data_type);
+ const eCustomDataType data_type = eCustomDataType(storage.data_type);
- bNodeSocket *socket_value_geometry = (bNodeSocket *)node->inputs.first;
+ bNodeSocket *socket_value_geometry = static_cast<bNodeSocket *>(node->inputs.first);
bNodeSocket *socket_value_vector = socket_value_geometry->next;
bNodeSocket *socket_value_float = socket_value_vector->next;
bNodeSocket *socket_value_color4f = socket_value_float->next;
@@ -65,7 +65,7 @@ static void node_update(bNodeTree *ntree, bNode *node)
nodeSetSocketAvailability(ntree, socket_value_boolean, data_type == CD_PROP_BOOL);
nodeSetSocketAvailability(ntree, socket_value_int32, data_type == CD_PROP_INT32);
- bNodeSocket *out_socket_value_geometry = (bNodeSocket *)node->outputs.first;
+ bNodeSocket *out_socket_value_geometry = static_cast<bNodeSocket *>(node->outputs.first);
bNodeSocket *out_socket_value_vector = out_socket_value_geometry->next;
bNodeSocket *out_socket_value_float = out_socket_value_vector->next;
bNodeSocket *out_socket_value_color4f = out_socket_value_float->next;
@@ -106,33 +106,6 @@ static void node_gather_link_searches(GatherLinkSearchOpParams &params)
}
}
-static void try_capture_field_on_geometry(GeometryComponent &component,
- const AttributeIDRef &attribute_id,
- const eAttrDomain domain,
- const GField &field)
-{
- const int domain_size = component.attribute_domain_size(domain);
- if (domain_size == 0) {
- return;
- }
- GeometryComponentFieldContext field_context{component, domain};
- MutableAttributeAccessor attributes = *component.attributes_for_write();
- const IndexMask mask{IndexMask(domain_size)};
-
- const eCustomDataType data_type = bke::cpp_type_to_custom_data_type(field.cpp_type());
- GAttributeWriter output_attribute = attributes.lookup_or_add_for_write(
- attribute_id, domain, data_type);
- if (!output_attribute) {
- return;
- }
-
- fn::FieldEvaluator evaluator{field_context, &mask};
- evaluator.add_with_destination(field, output_attribute.varray);
- evaluator.evaluate();
-
- output_attribute.finish();
-}
-
static StringRefNull identifier_suffix(eCustomDataType data_type)
{
switch (data_type) {
@@ -165,8 +138,8 @@ static void node_geo_exec(GeoNodeExecParams params)
}
const NodeGeometryAttributeCapture &storage = node_storage(params.node());
- const eCustomDataType data_type = static_cast<eCustomDataType>(storage.data_type);
- const eAttrDomain domain = static_cast<eAttrDomain>(storage.domain);
+ const eCustomDataType data_type = eCustomDataType(storage.data_type);
+ const eAttrDomain domain = eAttrDomain(storage.domain);
const std::string output_identifier = "Attribute" + identifier_suffix(data_type);
@@ -206,7 +179,7 @@ static void node_geo_exec(GeoNodeExecParams params)
if (geometry_set.has_instances()) {
GeometryComponent &component = geometry_set.get_component_for_write(
GEO_COMPONENT_TYPE_INSTANCES);
- try_capture_field_on_geometry(component, anonymous_id.get(), domain, field);
+ bke::try_capture_field_on_geometry(component, anonymous_id.get(), domain, field);
}
}
else {
@@ -217,7 +190,7 @@ static void node_geo_exec(GeoNodeExecParams params)
for (const GeometryComponentType type : types) {
if (geometry_set.has(type)) {
GeometryComponent &component = geometry_set.get_component_for_write(type);
- try_capture_field_on_geometry(component, anonymous_id.get(), domain, field);
+ bke::try_capture_field_on_geometry(component, anonymous_id.get(), domain, field);
}
}
});
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_domain_size.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_domain_size.cc
index f6ea6073459..af55ef3f7ed 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_domain_size.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_domain_size.cc
@@ -30,19 +30,19 @@ static void node_declare(NodeDeclarationBuilder &b)
});
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "component", 0, "", ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
node->custom1 = GEO_COMPONENT_TYPE_MESH;
}
static void node_update(bNodeTree *ntree, bNode *node)
{
- bNodeSocket *point_socket = (bNodeSocket *)node->outputs.first;
+ bNodeSocket *point_socket = static_cast<bNodeSocket *>(node->outputs.first);
bNodeSocket *edge_socket = point_socket->next;
bNodeSocket *face_socket = edge_socket->next;
bNodeSocket *face_corner_socket = face_socket->next;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_statistic.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_statistic.cc
index 34e28e50c81..3023c7bd751 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_statistic.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_statistic.cc
@@ -40,13 +40,13 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Vector>(N_("Variance"), "Variance_001");
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE);
uiItemR(layout, ptr, "domain", 0, "", ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
node->custom1 = CD_PROP_FLOAT;
node->custom2 = ATTR_DOMAIN_POINT;
@@ -54,12 +54,12 @@ static void node_init(bNodeTree *UNUSED(tree), bNode *node)
static void node_update(bNodeTree *ntree, bNode *node)
{
- bNodeSocket *socket_geo = (bNodeSocket *)node->inputs.first;
+ bNodeSocket *socket_geo = static_cast<bNodeSocket *>(node->inputs.first);
bNodeSocket *socket_selection = socket_geo->next;
bNodeSocket *socket_float_attr = socket_selection->next;
bNodeSocket *socket_float3_attr = socket_float_attr->next;
- bNodeSocket *socket_float_mean = (bNodeSocket *)node->outputs.first;
+ bNodeSocket *socket_float_mean = static_cast<bNodeSocket *>(node->outputs.first);
bNodeSocket *socket_float_median = socket_float_mean->next;
bNodeSocket *socket_float_sum = socket_float_median->next;
bNodeSocket *socket_float_min = socket_float_sum->next;
@@ -77,7 +77,7 @@ static void node_update(bNodeTree *ntree, bNode *node)
bNodeSocket *socket_vector_std = socket_vector_range->next;
bNodeSocket *socket_vector_variance = socket_vector_std->next;
- const eCustomDataType data_type = static_cast<eCustomDataType>(node->custom1);
+ const eCustomDataType data_type = eCustomDataType(node->custom1);
nodeSetSocketAvailability(ntree, socket_float_attr, data_type == CD_PROP_FLOAT);
nodeSetSocketAvailability(ntree, socket_float_mean, data_type == CD_PROP_FLOAT);
@@ -184,8 +184,8 @@ static void node_geo_exec(GeoNodeExecParams params)
{
GeometrySet geometry_set = params.get_input<GeometrySet>("Geometry");
const bNode &node = params.node();
- const eCustomDataType data_type = static_cast<eCustomDataType>(node.custom1);
- const eAttrDomain domain = static_cast<eAttrDomain>(node.custom2);
+ const eCustomDataType data_type = eCustomDataType(node.custom1);
+ const eAttrDomain domain = eAttrDomain(node.custom2);
Vector<const GeometryComponent *> components = geometry_set.get_components_for_read();
const Field<bool> selection_field = params.get_input<Field<bool>>("Selection");
@@ -200,7 +200,7 @@ static void node_geo_exec(GeoNodeExecParams params)
continue;
}
if (attributes->domain_supported(domain)) {
- GeometryComponentFieldContext field_context{*component, domain};
+ bke::GeometryFieldContext field_context{*component, domain};
const int domain_num = attributes->domain_size(domain);
fn::FieldEvaluator data_evaluator{field_context, domain_num};
@@ -282,7 +282,7 @@ static void node_geo_exec(GeoNodeExecParams params)
continue;
}
if (attributes->domain_supported(domain)) {
- GeometryComponentFieldContext field_context{*component, domain};
+ bke::GeometryFieldContext field_context{*component, domain};
const int domain_num = attributes->domain_size(domain);
fn::FieldEvaluator data_evaluator{field_context, domain_num};
diff --git a/source/blender/nodes/geometry/nodes/node_geo_boolean.cc b/source/blender/nodes/geometry/nodes/node_geo_boolean.cc
index 69938f3e447..094aab65653 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_boolean.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_boolean.cc
@@ -24,7 +24,7 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Bool>(N_("Intersecting Edges")).field_source();
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
}
@@ -37,7 +37,7 @@ static void node_update(bNodeTree *ntree, bNode *node)
{
GeometryNodeBooleanOperation operation = (GeometryNodeBooleanOperation)node->custom1;
- bNodeSocket *geometry_1_socket = (bNodeSocket *)node->inputs.first;
+ bNodeSocket *geometry_1_socket = static_cast<bNodeSocket *>(node->inputs.first);
bNodeSocket *geometry_2_socket = geometry_1_socket->next;
switch (operation) {
@@ -55,7 +55,7 @@ static void node_update(bNodeTree *ntree, bNode *node)
}
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
node->custom1 = GEO_NODE_BOOLEAN_DIFFERENCE;
}
@@ -93,7 +93,7 @@ static void node_geo_exec(GeoNodeExecParams params)
/* The instance transform matrices are owned by the instance group, so we have to
* keep all of them around for use during the boolean operation. */
Vector<bke::GeometryInstanceGroup> set_groups;
- Vector<GeometrySet> geometry_sets = params.extract_multi_input<GeometrySet>("Mesh 2");
+ Vector<GeometrySet> geometry_sets = params.extract_input<Vector<GeometrySet>>("Mesh 2");
for (const GeometrySet &geometry_set : geometry_sets) {
bke::geometry_set_gather_instances(geometry_set, set_groups);
}
@@ -148,13 +148,14 @@ static void node_geo_exec(GeoNodeExecParams params)
}
MEM_SAFE_FREE(result->mat);
- result->mat = (Material **)MEM_malloc_arrayN(materials.size(), sizeof(Material *), __func__);
+ result->mat = static_cast<Material **>(
+ MEM_malloc_arrayN(materials.size(), sizeof(Material *), __func__));
result->totcol = materials.size();
MutableSpan(result->mat, result->totcol).copy_from(materials);
/* Store intersecting edges in attribute. */
if (attribute_outputs.intersecting_edges_id) {
- MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*result);
+ MutableAttributeAccessor attributes = result->attributes_for_write();
SpanAttributeWriter<bool> selection = attributes.lookup_or_add_for_write_only_span<bool>(
attribute_outputs.intersecting_edges_id.get(), ATTR_DOMAIN_EDGE);
diff --git a/source/blender/nodes/geometry/nodes/node_geo_collection_info.cc b/source/blender/nodes/geometry/nodes/node_geo_collection_info.cc
index 54a061993a3..df677e1c399 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_collection_info.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_collection_info.cc
@@ -8,6 +8,7 @@
#include "UI_resources.h"
#include "BKE_collection.h"
+#include "BKE_instances.hh"
#include "node_geometry_util.hh"
@@ -30,12 +31,12 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Geometry"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "transform_space", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
}
-static void node_node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryCollectionInfo *data = MEM_cnew<NodeGeometryCollectionInfo>(__func__);
data->transform_space = GEO_NODE_TRANSFORM_SPACE_ORIGINAL;
@@ -57,8 +58,8 @@ static void node_geo_exec(GeoNodeExecParams params)
return;
}
const Object *self_object = params.self_object();
- const bool is_recursive = BKE_collection_has_object_recursive_instanced(collection,
- (Object *)self_object);
+ const bool is_recursive = BKE_collection_has_object_recursive_instanced(
+ collection, const_cast<Object *>(self_object));
if (is_recursive) {
params.error_message_add(NodeWarningType::Error, "Collection contains current object");
params.set_default_remaining_outputs();
@@ -69,8 +70,7 @@ static void node_geo_exec(GeoNodeExecParams params)
const bool use_relative_transform = (storage.transform_space ==
GEO_NODE_TRANSFORM_SPACE_RELATIVE);
- GeometrySet geometry_set_out;
- InstancesComponent &instances = geometry_set_out.get_component_for_write<InstancesComponent>();
+ std::unique_ptr<bke::Instances> instances = std::make_unique<bke::Instances>();
const bool separate_children = params.get_input<bool>("Separate Children");
if (separate_children) {
@@ -84,7 +84,7 @@ static void node_geo_exec(GeoNodeExecParams params)
children_objects.append(collection_object->ob);
}
- instances.reserve(children_collections.size() + children_objects.size());
+ instances->reserve(children_collections.size() + children_objects.size());
Vector<InstanceListEntry> entries;
entries.reserve(children_collections.size() + children_objects.size());
@@ -99,11 +99,11 @@ static void node_geo_exec(GeoNodeExecParams params)
sub_v3_v3(transform.values[3], collection->instance_offset);
}
}
- const int handle = instances.add_reference(*child_collection);
+ const int handle = instances->add_reference(*child_collection);
entries.append({handle, &(child_collection->id.name[2]), transform});
}
for (Object *child_object : children_objects) {
- const int handle = instances.add_reference(*child_object);
+ const int handle = instances->add_reference(*child_object);
float4x4 transform = float4x4::identity();
if (!reset_children) {
if (use_relative_transform) {
@@ -123,7 +123,7 @@ static void node_geo_exec(GeoNodeExecParams params)
return BLI_strcasecmp_natural(a.name, b.name) < 0;
});
for (const InstanceListEntry &entry : entries) {
- instances.add_instance(entry.handle, entry.transform);
+ instances->add_instance(entry.handle, entry.transform);
}
}
else {
@@ -133,11 +133,11 @@ static void node_geo_exec(GeoNodeExecParams params)
mul_m4_m4_pre(transform.values, self_object->imat);
}
- const int handle = instances.add_reference(*collection);
- instances.add_instance(handle, transform);
+ const int handle = instances->add_reference(*collection);
+ instances->add_instance(handle, transform);
}
- params.set_output("Geometry", geometry_set_out);
+ params.set_output("Geometry", GeometrySet::create_with_instances(instances.release()));
}
} // namespace blender::nodes::node_geo_collection_info_cc
diff --git a/source/blender/nodes/geometry/nodes/node_geo_convex_hull.cc b/source/blender/nodes/geometry/nodes/node_geo_convex_hull.cc
index 03892501c89..038309785fb 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_convex_hull.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_convex_hull.cc
@@ -46,6 +46,7 @@ static Mesh *hull_from_bullet(const Mesh *mesh, Span<float3> coords)
}
/* Copy vertices. */
+ MutableSpan<MVert> dst_verts = result->verts_for_write();
for (const int i : IndexRange(verts_num)) {
float co[3];
int original_index;
@@ -55,11 +56,11 @@ static Mesh *hull_from_bullet(const Mesh *mesh, Span<float3> coords)
# if 0 /* Disabled because it only works for meshes, not predictable enough. */
/* Copy custom data on vertices, like vertex groups etc. */
if (mesh && original_index < mesh->totvert) {
- CustomData_copy_data(&mesh->vdata, &result->vdata, (int)original_index, (int)i, 1);
+ CustomData_copy_data(&mesh->vdata, &result->vdata, int(original_index), int(i), 1);
}
# endif
/* Copy the position of the original point. */
- copy_v3_v3(result->mvert[i].co, co);
+ copy_v3_v3(dst_verts[i].co, co);
}
else {
BLI_assert_msg(0, "Unexpected new vertex in hull output");
@@ -73,15 +74,17 @@ static Mesh *hull_from_bullet(const Mesh *mesh, Span<float3> coords)
* to a loop and edges need to be created from that. */
Array<MLoop> mloop_src(loops_num);
uint edge_index = 0;
+ MutableSpan<MEdge> edges = result->edges_for_write();
+
for (const int i : IndexRange(loops_num)) {
int v_from;
int v_to;
plConvexHullGetLoop(hull, i, &v_from, &v_to);
- mloop_src[i].v = (uint)v_from;
+ mloop_src[i].v = uint(v_from);
/* Add edges for ascending order loops only. */
if (v_from < v_to) {
- MEdge &edge = result->medge[edge_index];
+ MEdge &edge = edges[edge_index];
edge.v1 = v_from;
edge.v2 = v_to;
edge.flag = ME_EDGEDRAW | ME_EDGERENDER;
@@ -95,7 +98,7 @@ static Mesh *hull_from_bullet(const Mesh *mesh, Span<float3> coords)
}
if (edges_num == 1) {
/* In this case there are no loops. */
- MEdge &edge = result->medge[0];
+ MEdge &edge = edges[0];
edge.v1 = 0;
edge.v2 = 1;
edge.flag |= ME_EDGEDRAW | ME_EDGERENDER | ME_LOOSEEDGE;
@@ -106,7 +109,10 @@ static Mesh *hull_from_bullet(const Mesh *mesh, Span<float3> coords)
/* Copy faces. */
Array<int> loops;
int j = 0;
- MLoop *loop = result->mloop;
+ MutableSpan<MPoly> polys = result->polys_for_write();
+ MutableSpan<MLoop> mesh_loops = result->loops_for_write();
+ MLoop *loop = mesh_loops.data();
+
for (const int i : IndexRange(faces_num)) {
const int len = plConvexHullGetFaceSize(hull, i);
@@ -116,7 +122,7 @@ static Mesh *hull_from_bullet(const Mesh *mesh, Span<float3> coords)
loops.reinitialize(len);
plConvexHullGetFaceLoops(hull, i, loops.data());
- MPoly &face = result->mpoly[i];
+ MPoly &face = polys[i];
face.loopstart = j;
face.totloop = len;
for (const int k : IndexRange(len)) {
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_endpoint_selection.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_endpoint_selection.cc
index db3f108aad5..4161ec7e7ad 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_endpoint_selection.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_endpoint_selection.cc
@@ -27,39 +27,31 @@ static void node_declare(NodeDeclarationBuilder &b)
N_("The selection from the start and end of the splines based on the input sizes"));
}
-class EndpointFieldInput final : public GeometryFieldInput {
+class EndpointFieldInput final : public bke::CurvesFieldInput {
Field<int> start_size_;
Field<int> end_size_;
public:
EndpointFieldInput(Field<int> start_size, Field<int> end_size)
- : GeometryFieldInput(CPPType::get<bool>(), "Endpoint Selection node"),
+ : bke::CurvesFieldInput(CPPType::get<bool>(), "Endpoint Selection node"),
start_size_(start_size),
end_size_(end_size)
{
category_ = Category::Generated;
}
- GVArray get_varray_for_context(const GeometryComponent &component,
+ GVArray get_varray_for_context(const bke::CurvesGeometry &curves,
const eAttrDomain domain,
- IndexMask UNUSED(mask)) const final
+ const IndexMask /*mask*/) const final
{
- if (component.type() != GEO_COMPONENT_TYPE_CURVE || domain != ATTR_DOMAIN_POINT) {
- return nullptr;
+ if (domain != ATTR_DOMAIN_POINT) {
+ return {};
}
-
- const CurveComponent &curve_component = static_cast<const CurveComponent &>(component);
- if (!curve_component.has_curves()) {
- return nullptr;
- }
-
- const Curves &curves_id = *curve_component.get_for_read();
- const bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id.geometry);
if (curves.points_num() == 0) {
- return nullptr;
+ return {};
}
- GeometryComponentFieldContext size_context{curve_component, ATTR_DOMAIN_CURVE};
+ bke::CurvesFieldContext size_context{curves, ATTR_DOMAIN_CURVE};
fn::FieldEvaluator evaluator{size_context, curves.curves_num()};
evaluator.add(start_size_);
evaluator.add(end_size_);
@@ -72,12 +64,12 @@ class EndpointFieldInput final : public GeometryFieldInput {
devirtualize_varray2(start_size, end_size, [&](const auto &start_size, const auto &end_size) {
threading::parallel_for(curves.curves_range(), 1024, [&](IndexRange curves_range) {
for (const int i : curves_range) {
- const IndexRange range = curves.points_for_curve(i);
+ const IndexRange points = curves.points_for_curve(i);
const int start = std::max(start_size[i], 0);
const int end = std::max(end_size[i], 0);
- selection_span.slice(range.take_front(start)).fill(true);
- selection_span.slice(range.take_back(end)).fill(true);
+ selection_span.slice(points.take_front(start)).fill(true);
+ selection_span.slice(points.take_back(end)).fill(true);
}
});
});
@@ -98,6 +90,11 @@ class EndpointFieldInput final : public GeometryFieldInput {
}
return false;
}
+
+ std::optional<eAttrDomain> preferred_domain(const CurvesGeometry & /*curves*/) const
+ {
+ return ATTR_DOMAIN_POINT;
+ }
};
static void node_geo_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc
index c9a8dba55b2..6eaa40bff03 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc
@@ -27,12 +27,12 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Mesh"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryCurveFill *data = MEM_cnew<NodeGeometryCurveFill>(__func__);
@@ -79,13 +79,13 @@ static Mesh *cdt_to_mesh(const meshintersect::CDT_result<double> &result)
}
Mesh *mesh = BKE_mesh_new_nomain(vert_len, edge_len, 0, loop_len, poly_len);
- MutableSpan<MVert> verts{mesh->mvert, mesh->totvert};
- MutableSpan<MEdge> edges{mesh->medge, mesh->totedge};
- MutableSpan<MLoop> loops{mesh->mloop, mesh->totloop};
- MutableSpan<MPoly> polys{mesh->mpoly, mesh->totpoly};
+ MutableSpan<MVert> verts = mesh->verts_for_write();
+ MutableSpan<MEdge> edges = mesh->edges_for_write();
+ MutableSpan<MPoly> polys = mesh->polys_for_write();
+ MutableSpan<MLoop> loops = mesh->loops_for_write();
for (const int i : IndexRange(result.vert.size())) {
- copy_v3_v3(verts[i].co, float3((float)result.vert[i].x, (float)result.vert[i].y, 0.0f));
+ copy_v3_v3(verts[i].co, float3(float(result.vert[i].x), float(result.vert[i].y), 0.0f));
}
for (const int i : IndexRange(result.edge.size())) {
edges[i].v1 = result.edge[i].first;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc
index ab1f8269c39..2b24b6cbf42 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc
@@ -32,12 +32,12 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Curve"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryCurveFillet *data = MEM_cnew<NodeGeometryCurveFillet>(__func__);
data->mode = GEO_NODE_CURVE_FILLET_BEZIER;
@@ -48,7 +48,7 @@ static void node_update(bNodeTree *ntree, bNode *node)
{
const NodeGeometryCurveFillet &storage = node_storage(*node);
const GeometryNodeCurveFilletMode mode = (GeometryNodeCurveFilletMode)storage.mode;
- bNodeSocket *poly_socket = ((bNodeSocket *)node->inputs.first)->next;
+ bNodeSocket *poly_socket = static_cast<bNodeSocket *>(node->inputs.first)->next;
nodeSetSocketAvailability(ntree, poly_socket, mode == GEO_NODE_CURVE_FILLET_POLY);
}
@@ -72,10 +72,9 @@ static void node_geo_exec(GeoNodeExecParams params)
return;
}
- const CurveComponent &component = *geometry_set.get_component_for_read<CurveComponent>();
- const Curves &curves_id = *component.get_for_read();
+ const Curves &curves_id = *geometry_set.get_curves_for_read();
const bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id.geometry);
- GeometryComponentFieldContext context{component, ATTR_DOMAIN_POINT};
+ bke::CurvesFieldContext context{curves, ATTR_DOMAIN_POINT};
fn::FieldEvaluator evaluator{context, curves.points_num()};
evaluator.add(radius_field);
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_handle_type_selection.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_handle_type_selection.cc
index 5ef20f03f28..252f66c308f 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_handle_type_selection.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_handle_type_selection.cc
@@ -16,13 +16,13 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Bool>(N_("Selection")).field_source();
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
uiItemR(layout, ptr, "handle_type", 0, "", ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryCurveSelectHandles *data = MEM_cnew<NodeGeometryCurveSelectHandles>(__func__);
@@ -70,41 +70,34 @@ static void select_by_handle_type(const bke::CurvesGeometry &curves,
}
}
-class HandleTypeFieldInput final : public GeometryFieldInput {
+class HandleTypeFieldInput final : public bke::CurvesFieldInput {
HandleType type_;
GeometryNodeCurveHandleMode mode_;
public:
HandleTypeFieldInput(HandleType type, GeometryNodeCurveHandleMode mode)
- : GeometryFieldInput(CPPType::get<bool>(), "Handle Type Selection node"),
+ : bke::CurvesFieldInput(CPPType::get<bool>(), "Handle Type Selection node"),
type_(type),
mode_(mode)
{
category_ = Category::Generated;
}
- GVArray get_varray_for_context(const GeometryComponent &component,
+ GVArray get_varray_for_context(const bke::CurvesGeometry &curves,
const eAttrDomain domain,
IndexMask mask) const final
{
- if (component.type() != GEO_COMPONENT_TYPE_CURVE || domain != ATTR_DOMAIN_POINT) {
+ if (domain != ATTR_DOMAIN_POINT) {
return {};
}
-
- const CurveComponent &curve_component = static_cast<const CurveComponent &>(component);
- const Curves *curves_id = curve_component.get_for_read();
- if (curves_id == nullptr) {
- return {};
- }
-
Array<bool> selection(mask.min_array_size());
- select_by_handle_type(bke::CurvesGeometry::wrap(curves_id->geometry), type_, mode_, selection);
+ select_by_handle_type(curves, type_, mode_, selection);
return VArray<bool>::ForContainer(std::move(selection));
}
uint64_t hash() const override
{
- return get_default_hash_2((int)mode_, (int)type_);
+ return get_default_hash_2(int(mode_), int(type_));
}
bool is_equal_to(const fn::FieldNode &other) const override
@@ -115,6 +108,11 @@ class HandleTypeFieldInput final : public GeometryFieldInput {
}
return false;
}
+
+ std::optional<eAttrDomain> preferred_domain(const CurvesGeometry & /*curves*/) const
+ {
+ return ATTR_DOMAIN_POINT;
+ }
};
static void node_geo_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_arc.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_arc.cc
index ba8c9a893c2..cc32c8f5efc 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_arc.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_arc.cc
@@ -88,12 +88,12 @@ static void node_declare(NodeDeclarationBuilder &b)
.make_available(enable_points);
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryCurvePrimitiveArc *data = MEM_cnew<NodeGeometryCurvePrimitiveArc>(__func__);
@@ -106,7 +106,7 @@ static void node_update(bNodeTree *ntree, bNode *node)
const NodeGeometryCurvePrimitiveArc &storage = node_storage(*node);
const GeometryNodeCurvePrimitiveArcMode mode = (GeometryNodeCurvePrimitiveArcMode)storage.mode;
- bNodeSocket *start_socket = ((bNodeSocket *)node->inputs.first)->next;
+ bNodeSocket *start_socket = static_cast<bNodeSocket *>(node->inputs.first)->next;
bNodeSocket *middle_socket = start_socket->next;
bNodeSocket *end_socket = middle_socket->next;
@@ -116,7 +116,7 @@ static void node_update(bNodeTree *ntree, bNode *node)
bNodeSocket *offset_angle_socket = sweep_angle_socket->next;
- bNodeSocket *center_out_socket = ((bNodeSocket *)node->outputs.first)->next;
+ bNodeSocket *center_out_socket = static_cast<bNodeSocket *>(node->outputs.first)->next;
bNodeSocket *normal_out_socket = center_out_socket->next;
bNodeSocket *radius_out_socket = normal_out_socket->next;
@@ -151,7 +151,7 @@ static bool colinear_f3_f3_f3(const float3 p1, const float3 p2, const float3 p3)
{
const float3 a = math::normalize(p2 - p1);
const float3 b = math::normalize(p3 - p1);
- return (ELEM(a, b, b * -1.0f));
+ return ELEM(a, b, b * -1.0f);
}
static Curves *create_arc_curve_from_points(const int resolution,
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_bezier_segment.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_bezier_segment.cc
index 875664c41fa..b407ac47dc9 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_bezier_segment.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_bezier_segment.cc
@@ -41,12 +41,12 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Curve"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryCurvePrimitiveBezierSegment *data =
MEM_cnew<NodeGeometryCurvePrimitiveBezierSegment>(__func__);
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc
index c33ba3e2a4c..35fdd6754cc 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc
@@ -56,12 +56,12 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Vector>(N_("Center")).make_available(endable_points);
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryCurvePrimitiveCircle *data = MEM_cnew<NodeGeometryCurvePrimitiveCircle>(__func__);
@@ -75,12 +75,12 @@ static void node_update(bNodeTree *ntree, bNode *node)
const GeometryNodeCurvePrimitiveCircleMode mode = (GeometryNodeCurvePrimitiveCircleMode)
storage.mode;
- bNodeSocket *start_socket = ((bNodeSocket *)node->inputs.first)->next;
+ bNodeSocket *start_socket = static_cast<bNodeSocket *>(node->inputs.first)->next;
bNodeSocket *middle_socket = start_socket->next;
bNodeSocket *end_socket = middle_socket->next;
bNodeSocket *radius_socket = end_socket->next;
- bNodeSocket *center_socket = ((bNodeSocket *)node->outputs.first)->next;
+ bNodeSocket *center_socket = static_cast<bNodeSocket *>(node->outputs.first)->next;
nodeSetSocketAvailability(
ntree, start_socket, mode == GEO_NODE_CURVE_PRIMITIVE_CIRCLE_TYPE_POINTS);
@@ -98,7 +98,7 @@ static bool colinear_f3_f3_f3(const float3 p1, const float3 p2, const float3 p3)
{
const float3 a = math::normalize(p2 - p1);
const float3 b = math::normalize(p3 - p1);
- return (ELEM(a, b, b * -1.0f));
+ return ELEM(a, b, b * -1.0f);
}
static Curves *create_point_circle_curve(
@@ -144,7 +144,7 @@ static Curves *create_point_circle_curve(
/* Get the radius from the center-point to p1. */
const float r = math::distance(p1, center);
- const float theta_step = ((2 * M_PI) / (float)resolution);
+ const float theta_step = ((2 * M_PI) / float(resolution));
for (const int i : IndexRange(resolution)) {
/* Formula for a circle around a point and 2 unit vectors perpendicular
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc
index 4cfa606d8eb..6b402a67450 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc
@@ -39,12 +39,12 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Curve"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryCurvePrimitiveLine *data = MEM_cnew<NodeGeometryCurvePrimitiveLine>(__func__);
@@ -57,7 +57,7 @@ static void node_update(bNodeTree *ntree, bNode *node)
const NodeGeometryCurvePrimitiveLine &storage = node_storage(*node);
const GeometryNodeCurvePrimitiveLineMode mode = (GeometryNodeCurvePrimitiveLineMode)storage.mode;
- bNodeSocket *p2_socket = ((bNodeSocket *)node->inputs.first)->next;
+ bNodeSocket *p2_socket = static_cast<bNodeSocket *>(node->inputs.first)->next;
bNodeSocket *direction_socket = p2_socket->next;
bNodeSocket *length_socket = direction_socket->next;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadrilateral.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadrilateral.cc
index fec4e31701f..44c2a078cb6 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadrilateral.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadrilateral.cc
@@ -68,12 +68,12 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Curve"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryCurvePrimitiveQuad *data = MEM_cnew<NodeGeometryCurvePrimitiveQuad>(__func__);
data->mode = GEO_NODE_CURVE_PRIMITIVE_QUAD_MODE_RECTANGLE;
@@ -83,10 +83,9 @@ static void node_init(bNodeTree *UNUSED(tree), bNode *node)
static void node_update(bNodeTree *ntree, bNode *node)
{
const NodeGeometryCurvePrimitiveQuad &storage = node_storage(*node);
- GeometryNodeCurvePrimitiveQuadMode mode = static_cast<GeometryNodeCurvePrimitiveQuadMode>(
- storage.mode);
+ GeometryNodeCurvePrimitiveQuadMode mode = GeometryNodeCurvePrimitiveQuadMode(storage.mode);
- bNodeSocket *width = ((bNodeSocket *)node->inputs.first);
+ bNodeSocket *width = static_cast<bNodeSocket *>(node->inputs.first);
bNodeSocket *height = width->next;
bNodeSocket *bottom = height->next;
bNodeSocket *top = bottom->next;
@@ -140,7 +139,7 @@ static void node_gather_link_searches(GatherLinkSearchOpParams &params)
search_link_ops_for_declarations(params, declaration.outputs());
}
else if (params.node_tree().typeinfo->validate_link(
- static_cast<eNodeSocketDatatype>(params.other_socket().type), SOCK_FLOAT)) {
+ eNodeSocketDatatype(params.other_socket().type), SOCK_FLOAT)) {
params.add_item(IFACE_("Width"),
SocketSearchOp{"Width", GEO_NODE_CURVE_PRIMITIVE_QUAD_MODE_RECTANGLE});
params.add_item(IFACE_("Height"),
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_spiral.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_spiral.cc
index 4aaf57d57cb..66284fe77db 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_spiral.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_spiral.cc
@@ -43,9 +43,9 @@ static Curves *create_spiral_curve(const float rotations,
const bool direction)
{
const int totalpoints = std::max(int(resolution * rotations), 1);
- const float delta_radius = (end_radius - start_radius) / (float)totalpoints;
- const float delta_height = height / (float)totalpoints;
- const float delta_theta = (M_PI * 2 * rotations) / (float)totalpoints *
+ const float delta_radius = (end_radius - start_radius) / float(totalpoints);
+ const float delta_height = height / float(totalpoints);
+ const float delta_theta = (M_PI * 2 * rotations) / float(totalpoints) *
(direction ? 1.0f : -1.0f);
Curves *curves_id = bke::curves_new_nomain_single(totalpoints + 1, CURVE_TYPE_POLY);
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc
index 37fc6823b9a..8b6a7064362 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc
@@ -26,12 +26,12 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Curve"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryCurveResample *data = MEM_cnew<NodeGeometryCurveResample>(__func__);
@@ -44,7 +44,7 @@ static void node_update(bNodeTree *ntree, bNode *node)
const NodeGeometryCurveResample &storage = node_storage(*node);
const GeometryNodeCurveResampleMode mode = (GeometryNodeCurveResampleMode)storage.mode;
- bNodeSocket *count_socket = ((bNodeSocket *)node->inputs.first)->next->next;
+ bNodeSocket *count_socket = static_cast<bNodeSocket *>(node->inputs.first)->next->next;
bNodeSocket *length_socket = count_socket->next;
nodeSetSocketAvailability(ntree, count_socket, mode == GEO_NODE_CURVE_RESAMPLE_COUNT);
@@ -66,12 +66,14 @@ static void node_geo_exec(GeoNodeExecParams params)
case GEO_NODE_CURVE_RESAMPLE_COUNT: {
Field<int> count = params.extract_input<Field<int>>("Count");
geometry_set.modify_geometry_sets([&](GeometrySet &geometry) {
- if (const CurveComponent *component = geometry.get_component_for_read<CurveComponent>()) {
- if (const Curves *src_curves = component->get_for_read()) {
- Curves *dst_curves = geometry::resample_to_count(*component, selection, count);
- bke::curves_copy_parameters(*src_curves, *dst_curves);
- geometry.replace_curves(dst_curves);
- }
+ if (const Curves *src_curves_id = geometry.get_curves_for_read()) {
+ const bke::CurvesGeometry &src_curves = bke::CurvesGeometry::wrap(
+ src_curves_id->geometry);
+ bke::CurvesGeometry dst_curves = geometry::resample_to_count(
+ src_curves, selection, count);
+ Curves *dst_curves_id = bke::curves_new_nomain(std::move(dst_curves));
+ bke::curves_copy_parameters(*src_curves_id, *dst_curves_id);
+ geometry.replace_curves(dst_curves_id);
}
});
break;
@@ -79,24 +81,27 @@ static void node_geo_exec(GeoNodeExecParams params)
case GEO_NODE_CURVE_RESAMPLE_LENGTH: {
Field<float> length = params.extract_input<Field<float>>("Length");
geometry_set.modify_geometry_sets([&](GeometrySet &geometry) {
- if (const CurveComponent *component = geometry.get_component_for_read<CurveComponent>()) {
- if (const Curves *src_curves = component->get_for_read()) {
- Curves *dst_curves = geometry::resample_to_length(*component, selection, length);
- bke::curves_copy_parameters(*src_curves, *dst_curves);
- geometry.replace_curves(dst_curves);
- }
+ if (const Curves *src_curves_id = geometry.get_curves_for_read()) {
+ const bke::CurvesGeometry &src_curves = bke::CurvesGeometry::wrap(
+ src_curves_id->geometry);
+ bke::CurvesGeometry dst_curves = geometry::resample_to_length(
+ src_curves, selection, length);
+ Curves *dst_curves_id = bke::curves_new_nomain(std::move(dst_curves));
+ bke::curves_copy_parameters(*src_curves_id, *dst_curves_id);
+ geometry.replace_curves(dst_curves_id);
}
});
break;
}
case GEO_NODE_CURVE_RESAMPLE_EVALUATED:
geometry_set.modify_geometry_sets([&](GeometrySet &geometry) {
- if (const CurveComponent *component = geometry.get_component_for_read<CurveComponent>()) {
- if (const Curves *src_curves = component->get_for_read()) {
- Curves *dst_curves = geometry::resample_to_evaluated(*component, selection);
- bke::curves_copy_parameters(*src_curves, *dst_curves);
- geometry.replace_curves(dst_curves);
- }
+ if (const Curves *src_curves_id = geometry.get_curves_for_read()) {
+ const bke::CurvesGeometry &src_curves = bke::CurvesGeometry::wrap(
+ src_curves_id->geometry);
+ bke::CurvesGeometry dst_curves = geometry::resample_to_evaluated(src_curves, selection);
+ Curves *dst_curves_id = bke::curves_new_nomain(std::move(dst_curves));
+ bke::curves_copy_parameters(*src_curves_id, *dst_curves_id);
+ geometry.replace_curves(dst_curves_id);
}
});
break;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_reverse.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_reverse.cc
index de29735bd2d..0169ead5bd2 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_reverse.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_reverse.cc
@@ -23,14 +23,12 @@ static void node_geo_exec(GeoNodeExecParams params)
if (!geometry_set.has_curves()) {
return;
}
+ const Curves &src_curves_id = *geometry_set.get_curves_for_read();
+ const bke::CurvesGeometry &src_curves = bke::CurvesGeometry::wrap(src_curves_id.geometry);
- Field<bool> selection_field = params.get_input<Field<bool>>("Selection");
- const CurveComponent &component = *geometry_set.get_component_for_read<CurveComponent>();
- GeometryComponentFieldContext field_context{component, ATTR_DOMAIN_CURVE};
- const int domain_size = component.attribute_domain_size(ATTR_DOMAIN_CURVE);
-
- fn::FieldEvaluator selection_evaluator{field_context, domain_size};
- selection_evaluator.add(selection_field);
+ bke::CurvesFieldContext field_context{src_curves, ATTR_DOMAIN_CURVE};
+ fn::FieldEvaluator selection_evaluator{field_context, src_curves.curves_num()};
+ selection_evaluator.add(params.get_input<Field<bool>>("Selection"));
selection_evaluator.evaluate();
const IndexMask selection = selection_evaluator.get_evaluated_as_mask(0);
if (selection.is_empty()) {
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc
index e80b600a740..27e111822bf 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc
@@ -35,12 +35,12 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Vector>(N_("Normal")).dependent_field();
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
}
-static void node_type_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_type_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryCurveSample *data = MEM_cnew<NodeGeometryCurveSample>(__func__);
data->mode = GEO_NODE_CURVE_SAMPLE_LENGTH;
@@ -52,7 +52,7 @@ static void node_update(bNodeTree *ntree, bNode *node)
const NodeGeometryCurveSample &storage = node_storage(*node);
const GeometryNodeCurveSampleMode mode = (GeometryNodeCurveSampleMode)storage.mode;
- bNodeSocket *factor = ((bNodeSocket *)node->inputs.first)->next;
+ bNodeSocket *factor = static_cast<bNodeSocket *>(node->inputs.first)->next;
bNodeSocket *length = factor->next;
nodeSetSocketAvailability(ntree, factor, mode == GEO_NODE_CURVE_SAMPLE_FACTOR);
@@ -134,7 +134,7 @@ class SampleFloatSegmentsFunction : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
const VArraySpan<float> lengths = params.readonly_single_input<float>(0, "Length");
MutableSpan<int> indices = params.uninitialized_single_output<int>(1, "Curve Index");
@@ -172,7 +172,7 @@ class SampleCurveFunction : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
MutableSpan<float3> sampled_positions = params.uninitialized_single_output_if_required<float3>(
2, "Position");
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_set_handle_type.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_set_handle_type.cc
index f7ba724c377..d37af6e5fe8 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_set_handle_type.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_set_handle_type.cc
@@ -20,13 +20,13 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Curve"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
uiItemR(layout, ptr, "handle_type", 0, "", ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryCurveSetHandles *data = MEM_cnew<NodeGeometryCurveSetHandles>(__func__);
@@ -51,15 +51,12 @@ static HandleType handle_type_from_input_type(GeometryNodeCurveHandleType type)
return BEZIER_HANDLE_AUTO;
}
-static void set_type_in_component(CurveComponent &component,
- const GeometryNodeCurveHandleMode mode,
- const HandleType new_handle_type,
- const Field<bool> &selection_field)
+static void set_handle_type(bke::CurvesGeometry &curves,
+ const GeometryNodeCurveHandleMode mode,
+ const HandleType new_handle_type,
+ const Field<bool> &selection_field)
{
- Curves &curves_id = *component.get_for_write();
- bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id.geometry);
-
- GeometryComponentFieldContext field_context{component, ATTR_DOMAIN_POINT};
+ bke::CurvesFieldContext field_context{curves, ATTR_DOMAIN_POINT};
fn::FieldEvaluator evaluator{field_context, curves.points_num()};
evaluator.set_selection(selection_field);
evaluator.evaluate();
@@ -93,21 +90,17 @@ static void node_geo_exec(GeoNodeExecParams params)
std::atomic<bool> has_bezier = false;
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
- if (!geometry_set.has_curves()) {
- return;
- }
- has_curves = true;
- const CurveComponent &component = *geometry_set.get_component_for_read<CurveComponent>();
- const AttributeAccessor attributes = *component.attributes();
- if (!attributes.contains("handle_type_left") || !attributes.contains("handle_type_right")) {
- return;
+ if (Curves *curves_id = geometry_set.get_curves_for_write()) {
+ bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry);
+ has_curves = true;
+ const AttributeAccessor attributes = curves.attributes();
+ if (!attributes.contains("handle_type_left") || !attributes.contains("handle_type_right")) {
+ return;
+ }
+ has_bezier = true;
+
+ set_handle_type(curves, mode, new_handle_type, selection_field);
}
- has_bezier = true;
-
- set_type_in_component(geometry_set.get_component_for_write<CurveComponent>(),
- mode,
- new_handle_type,
- selection_field);
});
if (has_curves && !has_bezier) {
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc
index b98541e3446..3dc89a9058e 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc
@@ -106,7 +106,7 @@ static Array<float> curve_length_point_domain(const bke::CurvesGeometry &curves)
}
static VArray<float> construct_curve_parameter_varray(const bke::CurvesGeometry &curves,
- const IndexMask UNUSED(mask),
+ const IndexMask /*mask*/,
const eAttrDomain domain)
{
VArray<bool> cyclic = curves.cyclic();
@@ -126,6 +126,10 @@ static VArray<float> construct_curve_parameter_varray(const bke::CurvesGeometry
value *= factor;
}
}
+ else if (curve_lengths.size() == 1) {
+ /* The curve is a single point. */
+ curve_lengths[0] = 0.0f;
+ }
else {
/* It is arbitrary what to do in those rare cases when all the points are
* in the same position. In this case we are just arbitrarily giving a valid
@@ -143,8 +147,8 @@ static VArray<float> construct_curve_parameter_varray(const bke::CurvesGeometry
Array<float> lengths = accumulated_lengths_curve_domain(curves);
const int last_index = curves.curves_num() - 1;
- const int total_length = lengths.last() + curves.evaluated_length_total_for_curve(
- last_index, cyclic[last_index]);
+ const float total_length = lengths.last() + curves.evaluated_length_total_for_curve(
+ last_index, cyclic[last_index]);
if (total_length > 0.0f) {
const float factor = 1.0f / total_length;
for (float &value : lengths) {
@@ -165,7 +169,7 @@ static VArray<float> construct_curve_parameter_varray(const bke::CurvesGeometry
}
static VArray<float> construct_curve_length_parameter_varray(const bke::CurvesGeometry &curves,
- const IndexMask UNUSED(mask),
+ const IndexMask /*mask*/,
const eAttrDomain domain)
{
curves.ensure_evaluated_lengths();
@@ -184,7 +188,7 @@ static VArray<float> construct_curve_length_parameter_varray(const bke::CurvesGe
}
static VArray<int> construct_index_on_spline_varray(const bke::CurvesGeometry &curves,
- const IndexMask UNUSED(mask),
+ const IndexMask /*mask*/,
const eAttrDomain domain)
{
if (domain == ATTR_DOMAIN_POINT) {
@@ -203,26 +207,18 @@ static VArray<int> construct_index_on_spline_varray(const bke::CurvesGeometry &c
return {};
}
-class CurveParameterFieldInput final : public GeometryFieldInput {
+class CurveParameterFieldInput final : public bke::CurvesFieldInput {
public:
- CurveParameterFieldInput() : GeometryFieldInput(CPPType::get<float>(), "Curve Parameter node")
+ CurveParameterFieldInput() : bke::CurvesFieldInput(CPPType::get<float>(), "Curve Parameter node")
{
category_ = Category::Generated;
}
- GVArray get_varray_for_context(const GeometryComponent &component,
+ GVArray get_varray_for_context(const bke::CurvesGeometry &curves,
const eAttrDomain domain,
IndexMask mask) const final
{
- if (component.type() == GEO_COMPONENT_TYPE_CURVE) {
- const CurveComponent &curve_component = static_cast<const CurveComponent &>(component);
- if (curve_component.has_curves()) {
- const Curves &curves_id = *curve_component.get_for_read();
- const bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id.geometry);
- return construct_curve_parameter_varray(curves, mask, domain);
- }
- }
- return {};
+ return construct_curve_parameter_varray(curves, mask, domain);
}
uint64_t hash() const override
@@ -237,26 +233,19 @@ class CurveParameterFieldInput final : public GeometryFieldInput {
}
};
-class CurveLengthParameterFieldInput final : public GeometryFieldInput {
+class CurveLengthParameterFieldInput final : public bke::CurvesFieldInput {
public:
- CurveLengthParameterFieldInput() : GeometryFieldInput(CPPType::get<float>(), "Curve Length node")
+ CurveLengthParameterFieldInput()
+ : bke::CurvesFieldInput(CPPType::get<float>(), "Curve Length node")
{
category_ = Category::Generated;
}
- GVArray get_varray_for_context(const GeometryComponent &component,
+ GVArray get_varray_for_context(const bke::CurvesGeometry &curves,
const eAttrDomain domain,
IndexMask mask) const final
{
- if (component.type() == GEO_COMPONENT_TYPE_CURVE) {
- const CurveComponent &curve_component = static_cast<const CurveComponent &>(component);
- if (curve_component.has_curves()) {
- const Curves &curves_id = *curve_component.get_for_read();
- const bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id.geometry);
- return construct_curve_length_parameter_varray(curves, mask, domain);
- }
- }
- return {};
+ return construct_curve_length_parameter_varray(curves, mask, domain);
}
uint64_t hash() const override
@@ -271,26 +260,18 @@ class CurveLengthParameterFieldInput final : public GeometryFieldInput {
}
};
-class IndexOnSplineFieldInput final : public GeometryFieldInput {
+class IndexOnSplineFieldInput final : public bke::CurvesFieldInput {
public:
- IndexOnSplineFieldInput() : GeometryFieldInput(CPPType::get<int>(), "Spline Index")
+ IndexOnSplineFieldInput() : bke::CurvesFieldInput(CPPType::get<int>(), "Spline Index")
{
category_ = Category::Generated;
}
- GVArray get_varray_for_context(const GeometryComponent &component,
+ GVArray get_varray_for_context(const bke::CurvesGeometry &curves,
const eAttrDomain domain,
IndexMask mask) const final
{
- if (component.type() == GEO_COMPONENT_TYPE_CURVE) {
- const CurveComponent &curve_component = static_cast<const CurveComponent &>(component);
- if (curve_component.has_curves()) {
- const Curves &curves_id = *curve_component.get_for_read();
- const bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id.geometry);
- return construct_index_on_spline_varray(curves, mask, domain);
- }
- }
- return {};
+ return construct_index_on_spline_varray(curves, mask, domain);
}
uint64_t hash() const override
@@ -303,6 +284,11 @@ class IndexOnSplineFieldInput final : public GeometryFieldInput {
{
return dynamic_cast<const IndexOnSplineFieldInput *>(&other) != nullptr;
}
+
+ std::optional<eAttrDomain> preferred_domain(const CurvesGeometry & /*curves*/) const
+ {
+ return ATTR_DOMAIN_POINT;
+ }
};
static void node_geo_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_spline_type.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_spline_type.cc
index a92479bc5f1..9ac6516ee7b 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_spline_type.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_spline_type.cc
@@ -20,12 +20,12 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Curve"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "spline_type", 0, "", ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryCurveSplineType *data = MEM_cnew<NodeGeometryCurveSplineType>(__func__);
@@ -45,14 +45,13 @@ static void node_geo_exec(GeoNodeExecParams params)
if (!geometry_set.has_curves()) {
return;
}
- const CurveComponent &src_component = *geometry_set.get_component_for_read<CurveComponent>();
- const Curves &src_curves_id = *src_component.get_for_read();
+ const Curves &src_curves_id = *geometry_set.get_curves_for_read();
const bke::CurvesGeometry &src_curves = bke::CurvesGeometry::wrap(src_curves_id.geometry);
if (src_curves.is_single_type(dst_type)) {
return;
}
- GeometryComponentFieldContext field_context{src_component, ATTR_DOMAIN_CURVE};
+ bke::CurvesFieldContext field_context{src_curves, ATTR_DOMAIN_CURVE};
fn::FieldEvaluator evaluator{field_context, src_curves.curves_num()};
evaluator.set_selection(selection_field);
evaluator.evaluate();
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_subdivide.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_subdivide.cc
index bd44adb35a2..5a1d2461c72 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_subdivide.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_subdivide.cc
@@ -29,16 +29,17 @@ static void node_geo_exec(GeoNodeExecParams params)
GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve");
Field<int> cuts_field = params.extract_input<Field<int>>("Cuts");
+ GeometryComponentEditData::remember_deformed_curve_positions_if_necessary(geometry_set);
+
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
if (!geometry_set.has_curves()) {
return;
}
- const CurveComponent &component = *geometry_set.get_component_for_read<CurveComponent>();
- const Curves &src_curves_id = *component.get_for_read();
+ const Curves &src_curves_id = *geometry_set.get_curves_for_read();
const bke::CurvesGeometry &src_curves = bke::CurvesGeometry::wrap(src_curves_id.geometry);
- GeometryComponentFieldContext field_context{component, ATTR_DOMAIN_POINT};
+ bke::CurvesFieldContext field_context{src_curves, ATTR_DOMAIN_POINT};
fn::FieldEvaluator evaluator{field_context, src_curves.points_num()};
evaluator.add(cuts_field);
evaluator.evaluate();
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc
index fd75855bddb..e9eaa00b02d 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc
@@ -4,8 +4,11 @@
#include "BLI_task.hh"
#include "BLI_timeit.hh"
+#include "DNA_pointcloud_types.h"
+
#include "BKE_pointcloud.h"
-#include "BKE_spline.hh"
+
+#include "GEO_resample_curves.hh"
#include "UI_interface.h"
#include "UI_resources.h"
@@ -37,12 +40,12 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Vector>(N_("Rotation")).field_source();
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryCurveToPoints *data = MEM_cnew<NodeGeometryCurveToPoints>(__func__);
@@ -55,16 +58,16 @@ static void node_update(bNodeTree *ntree, bNode *node)
const NodeGeometryCurveToPoints &storage = node_storage(*node);
const GeometryNodeCurveResampleMode mode = (GeometryNodeCurveResampleMode)storage.mode;
- bNodeSocket *count_socket = ((bNodeSocket *)node->inputs.first)->next;
+ bNodeSocket *count_socket = static_cast<bNodeSocket *>(node->inputs.first)->next;
bNodeSocket *length_socket = count_socket->next;
nodeSetSocketAvailability(ntree, count_socket, mode == GEO_NODE_CURVE_RESAMPLE_COUNT);
nodeSetSocketAvailability(ntree, length_socket, mode == GEO_NODE_CURVE_RESAMPLE_LENGTH);
}
-static void curve_create_default_rotation_attribute(Span<float3> tangents,
- Span<float3> normals,
- MutableSpan<float3> rotations)
+static void fill_rotation_attribute(const Span<float3> tangents,
+ const Span<float3> normals,
+ MutableSpan<float3> rotations)
{
threading::parallel_for(IndexRange(rotations.size()), 512, [&](IndexRange range) {
for (const int i : range) {
@@ -74,235 +77,30 @@ static void curve_create_default_rotation_attribute(Span<float3> tangents,
});
}
-static Array<int> calculate_spline_point_offsets(GeoNodeExecParams &params,
- const GeometryNodeCurveResampleMode mode,
- const CurveEval &curve,
- const Span<SplinePtr> splines)
-{
- const int size = curve.splines().size();
- switch (mode) {
- case GEO_NODE_CURVE_RESAMPLE_COUNT: {
- const int count = params.get_input<int>("Count");
- if (count < 1) {
- return {0};
- }
- Array<int> offsets(size + 1);
- int offset = 0;
- for (const int i : IndexRange(size)) {
- offsets[i] = offset;
- if (splines[i]->evaluated_points_num() > 0) {
- offset += count;
- }
- }
- offsets.last() = offset;
- return offsets;
- }
- case GEO_NODE_CURVE_RESAMPLE_LENGTH: {
- /* Don't allow asymptotic count increase for low resolution values. */
- const float resolution = std::max(params.get_input<float>("Length"), 0.0001f);
- Array<int> offsets(size + 1);
- int offset = 0;
- for (const int i : IndexRange(size)) {
- offsets[i] = offset;
- if (splines[i]->evaluated_points_num() > 0) {
- offset += splines[i]->length() / resolution + 1;
- }
- }
- offsets.last() = offset;
- return offsets;
- }
- case GEO_NODE_CURVE_RESAMPLE_EVALUATED: {
- return curve.evaluated_point_offsets();
- }
- }
- BLI_assert_unreachable();
- return {0};
-}
-
-/**
- * \note Relies on the fact that all attributes on point clouds are stored contiguously.
- */
-static GMutableSpan ensure_point_attribute(PointCloudComponent &points,
- const AttributeIDRef &attribute_id,
- const eCustomDataType data_type)
-{
- return points.attributes_for_write()
- ->lookup_or_add_for_write(attribute_id, ATTR_DOMAIN_POINT, data_type)
- .varray.get_internal_span();
-}
-
-template<typename T>
-static MutableSpan<T> ensure_point_attribute(PointCloudComponent &points,
- const AttributeIDRef &attribute_id)
-{
- return points.attributes_for_write()
- ->lookup_or_add_for_write<T>(attribute_id, ATTR_DOMAIN_POINT)
- .varray.get_internal_span();
-}
-
-namespace {
-struct AnonymousAttributeIDs {
- StrongAnonymousAttributeID tangent_id;
- StrongAnonymousAttributeID normal_id;
- StrongAnonymousAttributeID rotation_id;
-};
-
-struct ResultAttributes {
- MutableSpan<float3> positions;
- MutableSpan<float> radii;
-
- Map<AttributeIDRef, GMutableSpan> point_attributes;
-
- MutableSpan<float3> tangents;
- MutableSpan<float3> normals;
- MutableSpan<float3> rotations;
-};
-} // namespace
-
-static ResultAttributes create_attributes_for_transfer(PointCloudComponent &points,
- const CurveEval &curve,
- const AnonymousAttributeIDs &attributes)
+static PointCloud *pointcloud_from_curves(bke::CurvesGeometry curves,
+ const AttributeIDRef &tangent_id,
+ const AttributeIDRef &normal_id,
+ const AttributeIDRef &rotation_id)
{
- ResultAttributes outputs;
-
- outputs.positions = ensure_point_attribute<float3>(points, "position");
- outputs.radii = ensure_point_attribute<float>(points, "radius");
-
- if (attributes.tangent_id) {
- outputs.tangents = ensure_point_attribute<float3>(points, attributes.tangent_id.get());
- }
- if (attributes.normal_id) {
- outputs.normals = ensure_point_attribute<float3>(points, attributes.normal_id.get());
- }
- if (attributes.rotation_id) {
- outputs.rotations = ensure_point_attribute<float3>(points, attributes.rotation_id.get());
+ PointCloud *pointcloud = BKE_pointcloud_new_nomain(0);
+ pointcloud->totpoint = curves.points_num();
+
+ if (rotation_id) {
+ MutableAttributeAccessor attributes = curves.attributes_for_write();
+ const VArraySpan<float3> tangents = attributes.lookup<float3>(tangent_id, ATTR_DOMAIN_POINT);
+ const VArraySpan<float3> normals = attributes.lookup<float3>(normal_id, ATTR_DOMAIN_POINT);
+ SpanAttributeWriter<float3> rotations = attributes.lookup_or_add_for_write_only_span<float3>(
+ rotation_id, ATTR_DOMAIN_POINT);
+ fill_rotation_attribute(tangents, normals, rotations.span);
+ rotations.finish();
}
- /* Because of the invariants of the curve component, we use the attributes of the first spline
- * as a representative for the attribute meta data all splines. Attributes from the spline domain
- * are handled separately. */
- curve.splines().first()->attributes.foreach_attribute(
- [&](const AttributeIDRef &id, const AttributeMetaData &meta_data) {
- if (id.should_be_kept()) {
- outputs.point_attributes.add_new(
- id, ensure_point_attribute(points, id, meta_data.data_type));
- }
- return true;
- },
- ATTR_DOMAIN_POINT);
-
- return outputs;
-}
-
-/**
- * TODO: For non-poly splines, this has double copies that could be avoided as part
- * of a general look at optimizing uses of #Spline::interpolate_to_evaluated.
- */
-static void copy_evaluated_point_attributes(const Span<SplinePtr> splines,
- const Span<int> offsets,
- ResultAttributes &data)
-{
- threading::parallel_for(splines.index_range(), 64, [&](IndexRange range) {
- for (const int i : range) {
- const Spline &spline = *splines[i];
- const int offset = offsets[i];
- const int size = offsets[i + 1] - offsets[i];
-
- data.positions.slice(offset, size).copy_from(spline.evaluated_positions());
- spline.interpolate_to_evaluated(spline.radii()).materialize(data.radii.slice(offset, size));
+ /* Move the curve point custom data to the pointcloud, to avoid any copying. */
+ CustomData_free(&pointcloud->pdata, pointcloud->totpoint);
+ pointcloud->pdata = curves.point_data;
+ CustomData_reset(&curves.point_data);
- for (const Map<AttributeIDRef, GMutableSpan>::Item item : data.point_attributes.items()) {
- const AttributeIDRef attribute_id = item.key;
- const GMutableSpan dst = item.value;
-
- BLI_assert(spline.attributes.get_for_read(attribute_id));
- GSpan spline_span = *spline.attributes.get_for_read(attribute_id);
-
- spline.interpolate_to_evaluated(spline_span).materialize(dst.slice(offset, size).data());
- }
-
- if (!data.tangents.is_empty()) {
- data.tangents.slice(offset, size).copy_from(spline.evaluated_tangents());
- }
- if (!data.normals.is_empty()) {
- data.normals.slice(offset, size).copy_from(spline.evaluated_normals());
- }
- }
- });
-}
-
-static void copy_uniform_sample_point_attributes(const Span<SplinePtr> splines,
- const Span<int> offsets,
- ResultAttributes &data)
-{
- threading::parallel_for(splines.index_range(), 64, [&](IndexRange range) {
- for (const int i : range) {
- const Spline &spline = *splines[i];
- const int offset = offsets[i];
- const int num = offsets[i + 1] - offsets[i];
- if (num == 0) {
- continue;
- }
-
- const Array<float> uniform_samples = spline.sample_uniform_index_factors(num);
-
- spline.sample_with_index_factors<float3>(
- spline.evaluated_positions(), uniform_samples, data.positions.slice(offset, num));
- spline.sample_with_index_factors<float>(spline.interpolate_to_evaluated(spline.radii()),
- uniform_samples,
- data.radii.slice(offset, num));
-
- for (const Map<AttributeIDRef, GMutableSpan>::Item item : data.point_attributes.items()) {
- const AttributeIDRef attribute_id = item.key;
- const GMutableSpan dst = item.value;
-
- BLI_assert(spline.attributes.get_for_read(attribute_id));
- GSpan spline_span = *spline.attributes.get_for_read(attribute_id);
-
- spline.sample_with_index_factors(
- spline.interpolate_to_evaluated(spline_span), uniform_samples, dst.slice(offset, num));
- }
-
- if (!data.tangents.is_empty()) {
- Span<float3> src_tangents = spline.evaluated_tangents();
- MutableSpan<float3> sampled_tangents = data.tangents.slice(offset, num);
- spline.sample_with_index_factors<float3>(src_tangents, uniform_samples, sampled_tangents);
- for (float3 &vector : sampled_tangents) {
- vector = math::normalize(vector);
- }
- }
-
- if (!data.normals.is_empty()) {
- Span<float3> src_normals = spline.evaluated_normals();
- MutableSpan<float3> sampled_normals = data.normals.slice(offset, num);
- spline.sample_with_index_factors<float3>(src_normals, uniform_samples, sampled_normals);
- for (float3 &vector : sampled_normals) {
- vector = math::normalize(vector);
- }
- }
- }
- });
-}
-
-static void copy_spline_domain_attributes(const CurveEval &curve,
- const Span<int> offsets,
- PointCloudComponent &points)
-{
- curve.attributes.foreach_attribute(
- [&](const AttributeIDRef &attribute_id, const AttributeMetaData &meta_data) {
- const GSpan curve_attribute = *curve.attributes.get_for_read(attribute_id);
- const CPPType &type = curve_attribute.type();
- const GMutableSpan dst = ensure_point_attribute(points, attribute_id, meta_data.data_type);
-
- for (const int i : curve.splines().index_range()) {
- const int offset = offsets[i];
- const int num = offsets[i + 1] - offsets[i];
- type.fill_assign_n(curve_attribute[i], dst[offset], num);
- }
-
- return true;
- },
- ATTR_DOMAIN_CURVE);
+ return pointcloud;
}
static void node_geo_exec(GeoNodeExecParams params)
@@ -311,73 +109,96 @@ static void node_geo_exec(GeoNodeExecParams params)
const GeometryNodeCurveResampleMode mode = (GeometryNodeCurveResampleMode)storage.mode;
GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve");
- AnonymousAttributeIDs attribute_outputs;
- attribute_outputs.tangent_id = StrongAnonymousAttributeID("Tangent");
- attribute_outputs.normal_id = StrongAnonymousAttributeID("Normal");
- attribute_outputs.rotation_id = StrongAnonymousAttributeID("Rotation");
-
GeometryComponentEditData::remember_deformed_curve_positions_if_necessary(geometry_set);
- geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
- if (!geometry_set.has_curves()) {
- geometry_set.remove_geometry_during_modify();
- return;
- }
- const std::unique_ptr<CurveEval> curve = curves_to_curve_eval(
- *geometry_set.get_curves_for_read());
- const Span<SplinePtr> splines = curve->splines();
- curve->assert_valid_point_attributes();
-
- const Array<int> offsets = calculate_spline_point_offsets(params, mode, *curve, splines);
- const int total_num = offsets.last();
- if (total_num == 0) {
- geometry_set.remove_geometry_during_modify();
- return;
- }
+ StrongAnonymousAttributeID tangent_anonymous_id;
+ StrongAnonymousAttributeID normal_anonymous_id;
+ StrongAnonymousAttributeID rotation_anonymous_id;
+ const bool rotation_required = params.output_is_required("Rotation");
+ if (params.output_is_required("Tangent") || rotation_required) {
+ tangent_anonymous_id = StrongAnonymousAttributeID("Tangent");
+ }
+ if (params.output_is_required("Normal") || rotation_required) {
+ normal_anonymous_id = StrongAnonymousAttributeID("Normal");
+ }
+ if (rotation_required) {
+ rotation_anonymous_id = StrongAnonymousAttributeID("Rotation");
+ }
- geometry_set.replace_pointcloud(BKE_pointcloud_new_nomain(total_num));
- PointCloudComponent &points = geometry_set.get_component_for_write<PointCloudComponent>();
- ResultAttributes point_attributes = create_attributes_for_transfer(
- points, *curve, attribute_outputs);
+ geometry::ResampleCurvesOutputAttributeIDs resample_attributes;
+ resample_attributes.tangent_id = tangent_anonymous_id.get();
+ resample_attributes.normal_id = normal_anonymous_id.get();
- switch (mode) {
- case GEO_NODE_CURVE_RESAMPLE_COUNT:
- case GEO_NODE_CURVE_RESAMPLE_LENGTH:
- copy_uniform_sample_point_attributes(splines, offsets, point_attributes);
- break;
- case GEO_NODE_CURVE_RESAMPLE_EVALUATED:
- copy_evaluated_point_attributes(splines, offsets, point_attributes);
- break;
+ switch (mode) {
+ case GEO_NODE_CURVE_RESAMPLE_COUNT: {
+ Field<int> count = params.extract_input<Field<int>>("Count");
+ geometry_set.modify_geometry_sets([&](GeometrySet &geometry) {
+ if (const Curves *src_curves_id = geometry.get_curves_for_read()) {
+ const bke::CurvesGeometry &src_curves = bke::CurvesGeometry::wrap(
+ src_curves_id->geometry);
+ bke::CurvesGeometry dst_curves = geometry::resample_to_count(
+ src_curves, fn::make_constant_field<bool>(true), count, resample_attributes);
+ PointCloud *pointcloud = pointcloud_from_curves(std::move(dst_curves),
+ resample_attributes.tangent_id,
+ resample_attributes.normal_id,
+ rotation_anonymous_id.get());
+ geometry.remove_geometry_during_modify();
+ geometry.replace_pointcloud(pointcloud);
+ }
+ });
+ break;
}
-
- copy_spline_domain_attributes(*curve, offsets, points);
-
- if (!point_attributes.rotations.is_empty()) {
- curve_create_default_rotation_attribute(
- point_attributes.tangents, point_attributes.normals, point_attributes.rotations);
+ case GEO_NODE_CURVE_RESAMPLE_LENGTH: {
+ Field<float> length = params.extract_input<Field<float>>("Length");
+ geometry_set.modify_geometry_sets([&](GeometrySet &geometry) {
+ if (const Curves *src_curves_id = geometry.get_curves_for_read()) {
+ const bke::CurvesGeometry &src_curves = bke::CurvesGeometry::wrap(
+ src_curves_id->geometry);
+ bke::CurvesGeometry dst_curves = geometry::resample_to_length(
+ src_curves, fn::make_constant_field<bool>(true), length, resample_attributes);
+ PointCloud *pointcloud = pointcloud_from_curves(std::move(dst_curves),
+ resample_attributes.tangent_id,
+ resample_attributes.normal_id,
+ rotation_anonymous_id.get());
+ geometry.remove_geometry_during_modify();
+ geometry.replace_pointcloud(pointcloud);
+ }
+ });
+ break;
}
-
- geometry_set.keep_only_during_modify({GEO_COMPONENT_TYPE_POINT_CLOUD});
- });
+ case GEO_NODE_CURVE_RESAMPLE_EVALUATED:
+ geometry_set.modify_geometry_sets([&](GeometrySet &geometry) {
+ if (const Curves *src_curves_id = geometry.get_curves_for_read()) {
+ const bke::CurvesGeometry &src_curves = bke::CurvesGeometry::wrap(
+ src_curves_id->geometry);
+ bke::CurvesGeometry dst_curves = geometry::resample_to_evaluated(
+ src_curves, fn::make_constant_field<bool>(true), resample_attributes);
+ PointCloud *pointcloud = pointcloud_from_curves(std::move(dst_curves),
+ resample_attributes.tangent_id,
+ resample_attributes.normal_id,
+ rotation_anonymous_id.get());
+ geometry.remove_geometry_during_modify();
+ geometry.replace_pointcloud(pointcloud);
+ }
+ });
+ break;
+ }
params.set_output("Points", std::move(geometry_set));
- if (attribute_outputs.tangent_id) {
- params.set_output(
- "Tangent",
- AnonymousAttributeFieldInput::Create<float3>(std::move(attribute_outputs.tangent_id),
- params.attribute_producer_name()));
+ if (tangent_anonymous_id) {
+ params.set_output("Tangent",
+ AnonymousAttributeFieldInput::Create<float3>(
+ std::move(tangent_anonymous_id), params.attribute_producer_name()));
}
- if (attribute_outputs.normal_id) {
- params.set_output(
- "Normal",
- AnonymousAttributeFieldInput::Create<float3>(std::move(attribute_outputs.normal_id),
- params.attribute_producer_name()));
+ if (normal_anonymous_id) {
+ params.set_output("Normal",
+ AnonymousAttributeFieldInput::Create<float3>(
+ std::move(normal_anonymous_id), params.attribute_producer_name()));
}
- if (attribute_outputs.rotation_id) {
- params.set_output(
- "Rotation",
- AnonymousAttributeFieldInput::Create<float3>(std::move(attribute_outputs.rotation_id),
- params.attribute_producer_name()));
+ if (rotation_anonymous_id) {
+ params.set_output("Rotation",
+ AnonymousAttributeFieldInput::Create<float3>(
+ std::move(rotation_anonymous_id), params.attribute_producer_name()));
}
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_topology_curve_of_point.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_topology_curve_of_point.cc
new file mode 100644
index 00000000000..4d60ab939ca
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_topology_curve_of_point.cc
@@ -0,0 +1,121 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "BKE_curves.hh"
+
+#include "node_geometry_util.hh"
+
+namespace blender::nodes::node_geo_curve_topology_curve_of_point_cc {
+
+static void node_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::Int>(N_("Point Index"))
+ .implicit_field(implicit_field_inputs::index)
+ .description(N_("The control point to retrieve data from"));
+ b.add_output<decl::Int>(N_("Curve Index"))
+ .dependent_field()
+ .description(N_("The curve the control point is part of"));
+ b.add_output<decl::Int>(N_("Index in Curve"))
+ .dependent_field()
+ .description(N_("How far along the control point is along its curve"));
+}
+
+class CurveOfPointInput final : public bke::CurvesFieldInput {
+ public:
+ CurveOfPointInput() : bke::CurvesFieldInput(CPPType::get<int>(), "Point Curve Index")
+ {
+ category_ = Category::Generated;
+ }
+
+ GVArray get_varray_for_context(const bke::CurvesGeometry &curves,
+ const eAttrDomain domain,
+ const IndexMask /*mask*/) const final
+ {
+ if (domain != ATTR_DOMAIN_POINT) {
+ return {};
+ }
+ return VArray<int>::ForContainer(curves.point_to_curve_map());
+ }
+
+ uint64_t hash() const override
+ {
+ return 413209687345908697;
+ }
+
+ bool is_equal_to(const fn::FieldNode &other) const override
+ {
+ if (dynamic_cast<const CurveOfPointInput *>(&other)) {
+ return true;
+ }
+ return false;
+ }
+};
+
+class PointIndexInCurveInput final : public bke::CurvesFieldInput {
+ public:
+ PointIndexInCurveInput() : bke::CurvesFieldInput(CPPType::get<int>(), "Point Index in Curve")
+ {
+ category_ = Category::Generated;
+ }
+
+ GVArray get_varray_for_context(const bke::CurvesGeometry &curves,
+ const eAttrDomain domain,
+ const IndexMask /*mask*/) const final
+ {
+ if (domain != ATTR_DOMAIN_POINT) {
+ return {};
+ }
+ const Span<int> offsets = curves.offsets();
+ Array<int> point_to_curve_map = curves.point_to_curve_map();
+ return VArray<int>::ForFunc(
+ curves.points_num(),
+ [offsets, point_to_curve_map = std::move(point_to_curve_map)](const int point_i) {
+ const int curve_i = point_to_curve_map[point_i];
+ return point_i - offsets[curve_i];
+ });
+ }
+
+ uint64_t hash() const final
+ {
+ return 9834765987345677;
+ }
+
+ bool is_equal_to(const fn::FieldNode &other) const final
+ {
+ if (dynamic_cast<const PointIndexInCurveInput *>(&other)) {
+ return true;
+ }
+ return false;
+ }
+};
+
+static void node_geo_exec(GeoNodeExecParams params)
+{
+ const Field<int> point_index = params.extract_input<Field<int>>("Point Index");
+ if (params.output_is_required("Curve Index")) {
+ params.set_output(
+ "Curve Index",
+ Field<int>(std::make_shared<FieldAtIndexInput>(
+ point_index, Field<int>(std::make_shared<CurveOfPointInput>()), ATTR_DOMAIN_POINT)));
+ }
+ if (params.output_is_required("Index in Curve")) {
+ params.set_output("Index in Curve",
+ Field<int>(std::make_shared<FieldAtIndexInput>(
+ point_index,
+ Field<int>(std::make_shared<PointIndexInCurveInput>()),
+ ATTR_DOMAIN_POINT)));
+ }
+}
+
+} // namespace blender::nodes::node_geo_curve_topology_curve_of_point_cc
+
+void register_node_type_geo_curve_topology_curve_of_point()
+{
+ namespace file_ns = blender::nodes::node_geo_curve_topology_curve_of_point_cc;
+
+ static bNodeType ntype;
+ geo_node_type_base(
+ &ntype, GEO_NODE_CURVE_TOPOLOGY_CURVE_OF_POINT, "Curve of Point", NODE_CLASS_INPUT);
+ ntype.geometry_node_execute = file_ns::node_geo_exec;
+ ntype.declare = file_ns::node_declare;
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_topology_points_of_curve.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_topology_points_of_curve.cc
new file mode 100644
index 00000000000..9f3d3c2caf3
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_topology_points_of_curve.cc
@@ -0,0 +1,182 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "BKE_curves.hh"
+
+#include "BLI_task.hh"
+
+#include "node_geometry_util.hh"
+
+namespace blender::nodes::node_geo_curve_topology_points_of_curve_cc {
+
+static void node_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::Int>(N_("Curve Index"))
+ .implicit_field(implicit_field_inputs::index)
+ .description(N_("The curve to retrieve data from. Defaults to the curve from the context"));
+ b.add_input<decl::Float>(N_("Weights"))
+ .supports_field()
+ .hide_value()
+ .description(N_("Values used to sort the curve's points. Uses indices by default"));
+ b.add_input<decl::Int>(N_("Sort Index"))
+ .min(0)
+ .supports_field()
+ .description(N_("Which of the sorted points to output"));
+ b.add_output<decl::Int>(N_("Point Index"))
+ .dependent_field()
+ .description(N_("A point of the curve, chosen by the sort index"));
+ b.add_output<decl::Int>(N_("Total"))
+ .dependent_field()
+ .description(N_("The number of points in the curve"));
+}
+
+class PointsOfCurveInput final : public bke::CurvesFieldInput {
+ const Field<int> curve_index_;
+ const Field<int> sort_index_;
+ const Field<float> sort_weight_;
+
+ public:
+ PointsOfCurveInput(Field<int> curve_index, Field<int> sort_index, Field<float> sort_weight)
+ : bke::CurvesFieldInput(CPPType::get<int>(), "Point of Curve"),
+ curve_index_(std::move(curve_index)),
+ sort_index_(std::move(sort_index)),
+ sort_weight_(std::move(sort_weight))
+ {
+ category_ = Category::Generated;
+ }
+
+ GVArray get_varray_for_context(const bke::CurvesGeometry &curves,
+ const eAttrDomain domain,
+ const IndexMask mask) const final
+ {
+ const bke::CurvesFieldContext context{curves, domain};
+ fn::FieldEvaluator evaluator{context, &mask};
+ evaluator.add(curve_index_);
+ evaluator.add(sort_index_);
+ evaluator.evaluate();
+ const VArray<int> curve_indices = evaluator.get_evaluated<int>(0);
+ const VArray<int> indices_in_sort = evaluator.get_evaluated<int>(1);
+
+ const bke::CurvesFieldContext point_context{curves, ATTR_DOMAIN_POINT};
+ fn::FieldEvaluator point_evaluator{point_context, curves.points_num()};
+ point_evaluator.add(sort_weight_);
+ point_evaluator.evaluate();
+ const VArray<float> all_sort_weights = point_evaluator.get_evaluated<float>(0);
+
+ Array<int> point_of_curve(mask.min_array_size());
+ threading::parallel_for(mask.index_range(), 256, [&](const IndexRange range) {
+ /* Reuse arrays to avoid allocation. */
+ Array<float> sort_weights;
+ Array<int> sort_indices;
+
+ for (const int selection_i : mask.slice(range)) {
+ const int curve_i = curve_indices[selection_i];
+ const int index_in_sort = indices_in_sort[selection_i];
+ if (!curves.curves_range().contains(curve_i)) {
+ point_of_curve[selection_i] = 0;
+ continue;
+ }
+
+ const IndexRange points = curves.points_for_curve(curve_i);
+
+ /* Retrieve the weights for each point. */
+ sort_weights.reinitialize(points.size());
+ all_sort_weights.materialize_compressed(IndexMask(points), sort_weights.as_mutable_span());
+
+ /* Sort a separate array of compressed indices corresponding to the compressed weights.
+ * This allows using `materialize_compressed` to avoid virtual function call overhead
+ * when accessing values in the sort weights. However, it means a separate array of
+ * indices within the compressed array is necessary for sorting. */
+ sort_indices.reinitialize(points.size());
+ std::iota(sort_indices.begin(), sort_indices.end(), 0);
+ std::stable_sort(sort_indices.begin(), sort_indices.end(), [&](int a, int b) {
+ return sort_weights[a] < sort_weights[b];
+ });
+
+ const int index_in_sort_wrapped = mod_i(index_in_sort, points.size());
+ point_of_curve[selection_i] = points[sort_indices[index_in_sort_wrapped]];
+ }
+ });
+
+ return VArray<int>::ForContainer(std::move(point_of_curve));
+ }
+
+ uint64_t hash() const override
+ {
+ return 26978695677882;
+ }
+
+ bool is_equal_to(const fn::FieldNode &other) const override
+ {
+ if (const auto *typed = dynamic_cast<const PointsOfCurveInput *>(&other)) {
+ return typed->curve_index_ == curve_index_ && typed->sort_index_ == sort_index_ &&
+ typed->sort_weight_ == sort_weight_;
+ }
+ return false;
+ }
+};
+
+class CurvePointCountInput final : public bke::CurvesFieldInput {
+ public:
+ CurvePointCountInput() : bke::CurvesFieldInput(CPPType::get<int>(), "Curve Point Count")
+ {
+ category_ = Category::Generated;
+ }
+
+ GVArray get_varray_for_context(const bke::CurvesGeometry &curves,
+ const eAttrDomain domain,
+ const IndexMask /*mask*/) const final
+ {
+ if (domain != ATTR_DOMAIN_CURVE) {
+ return {};
+ }
+ return VArray<int>::ForFunc(curves.curves_num(), [&, curves](const int64_t curve_i) {
+ return curves.points_num_for_curve(curve_i);
+ });
+ }
+
+ uint64_t hash() const final
+ {
+ return 903847569873762;
+ }
+
+ bool is_equal_to(const fn::FieldNode &other) const final
+ {
+ if (dynamic_cast<const CurvePointCountInput *>(&other)) {
+ return true;
+ }
+ return false;
+ }
+};
+
+static void node_geo_exec(GeoNodeExecParams params)
+{
+ const Field<int> curve_index = params.extract_input<Field<int>>("Curve Index");
+ if (params.output_is_required("Total")) {
+ params.set_output("Total",
+ Field<int>(std::make_shared<FieldAtIndexInput>(
+ curve_index,
+ Field<int>(std::make_shared<CurvePointCountInput>()),
+ ATTR_DOMAIN_CURVE)));
+ }
+ if (params.output_is_required("Point Index")) {
+ params.set_output("Point Index",
+ Field<int>(std::make_shared<PointsOfCurveInput>(
+ curve_index,
+ params.extract_input<Field<int>>("Sort Index"),
+ params.extract_input<Field<float>>("Weights"))));
+ }
+}
+
+} // namespace blender::nodes::node_geo_curve_topology_points_of_curve_cc
+
+void register_node_type_geo_curve_topology_points_of_curve()
+{
+ namespace file_ns = blender::nodes::node_geo_curve_topology_points_of_curve_cc;
+
+ static bNodeType ntype;
+ geo_node_type_base(
+ &ntype, GEO_NODE_CURVE_TOPOLOGY_POINTS_OF_CURVE, "Points of Curve", NODE_CLASS_INPUT);
+ ntype.geometry_node_execute = file_ns::node_geo_exec;
+ ntype.declare = file_ns::node_declare;
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc
index 0932de237a9..15c89d78276 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc
@@ -1,7 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
#include "BKE_curves.hh"
-#include "BKE_spline.hh"
#include "BLI_task.hh"
#include "UI_interface.h"
@@ -9,12 +8,12 @@
#include "NOD_socket_search_link.hh"
+#include "GEO_trim_curves.hh"
+
#include "node_geometry_util.hh"
namespace blender::nodes::node_geo_curve_trim_cc {
-using blender::attribute_math::mix2;
-
NODE_STORAGE_FUNCS(NodeGeometryCurveTrim)
static void node_declare(NodeDeclarationBuilder &b)
@@ -47,12 +46,12 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Curve"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryCurveTrim *data = MEM_cnew<NodeGeometryCurveTrim>(__func__);
@@ -65,7 +64,7 @@ static void node_update(bNodeTree *ntree, bNode *node)
const NodeGeometryCurveTrim &storage = node_storage(*node);
const GeometryNodeCurveSampleMode mode = (GeometryNodeCurveSampleMode)storage.mode;
- bNodeSocket *start_fac = ((bNodeSocket *)node->inputs.first)->next;
+ bNodeSocket *start_fac = static_cast<bNodeSocket *>(node->inputs.first)->next;
bNodeSocket *end_fac = start_fac->next;
bNodeSocket *start_len = end_fac->next;
bNodeSocket *end_len = start_len->next;
@@ -96,8 +95,8 @@ static void node_gather_link_searches(GatherLinkSearchOpParams &params)
search_link_ops_for_declarations(params, declaration.inputs().take_front(1));
if (params.in_out() == SOCK_IN) {
- if (params.node_tree().typeinfo->validate_link(
- static_cast<eNodeSocketDatatype>(params.other_socket().type), SOCK_FLOAT)) {
+ if (params.node_tree().typeinfo->validate_link(eNodeSocketDatatype(params.other_socket().type),
+ SOCK_FLOAT)) {
params.add_item(IFACE_("Start (Factor)"),
SocketSearchOp{"Start", GEO_NODE_CURVE_SAMPLE_FACTOR});
params.add_item(IFACE_("End (Factor)"), SocketSearchOp{"End", GEO_NODE_CURVE_SAMPLE_FACTOR});
@@ -108,394 +107,6 @@ static void node_gather_link_searches(GatherLinkSearchOpParams &params)
}
}
-struct TrimLocation {
- /* Control point index at the start side of the trim location. */
- int left_index;
- /* Control point index at the end of the trim location's segment. */
- int right_index;
- /* The factor between the left and right indices. */
- float factor;
-};
-
-template<typename T>
-static void shift_slice_to_start(MutableSpan<T> data, const int start_index, const int num)
-{
- BLI_assert(start_index + num - 1 <= data.size());
- memmove(data.data(), &data[start_index], sizeof(T) * num);
-}
-
-/* Shift slice to start of span and modifies start and end data. */
-template<typename T>
-static void linear_trim_data(const TrimLocation &start,
- const TrimLocation &end,
- MutableSpan<T> data)
-{
- const int num = end.right_index - start.left_index + 1;
-
- if (start.left_index > 0) {
- shift_slice_to_start<T>(data, start.left_index, num);
- }
-
- const T start_data = mix2<T>(start.factor, data.first(), data[1]);
- const T end_data = mix2<T>(end.factor, data[num - 2], data[num - 1]);
-
- data.first() = start_data;
- data[num - 1] = end_data;
-}
-
-/**
- * Identical operation as #linear_trim_data, but copy data to a new #MutableSpan rather than
- * modifying the original data.
- */
-template<typename T>
-static void linear_trim_to_output_data(const TrimLocation &start,
- const TrimLocation &end,
- Span<T> src,
- MutableSpan<T> dst)
-{
- const int num = end.right_index - start.left_index + 1;
-
- const T start_data = mix2<T>(start.factor, src[start.left_index], src[start.right_index]);
- const T end_data = mix2<T>(end.factor, src[end.left_index], src[end.right_index]);
-
- dst.copy_from(src.slice(start.left_index, num));
- dst.first() = start_data;
- dst.last() = end_data;
-}
-
-/* Look up the control points to the left and right of factor, and get the factor between them. */
-static TrimLocation lookup_control_point_position(const Spline::LookupResult &lookup,
- const BezierSpline &spline)
-{
- Span<int> offsets = spline.control_point_offsets();
-
- const int *offset = std::lower_bound(offsets.begin(), offsets.end(), lookup.evaluated_index);
- const int index = offset - offsets.begin();
-
- const int left = offsets[index] > lookup.evaluated_index ? index - 1 : index;
- const int right = left == (spline.size() - 1) ? 0 : left + 1;
-
- const float offset_in_segment = lookup.evaluated_index + lookup.factor - offsets[left];
- const int segment_eval_num = offsets[left + 1] - offsets[left];
- const float factor = std::clamp(offset_in_segment / segment_eval_num, 0.0f, 1.0f);
-
- return {left, right, factor};
-}
-
-static void trim_poly_spline(Spline &spline,
- const Spline::LookupResult &start_lookup,
- const Spline::LookupResult &end_lookup)
-{
- /* Poly splines have a 1 to 1 mapping between control points and evaluated points. */
- const TrimLocation start = {
- start_lookup.evaluated_index, start_lookup.next_evaluated_index, start_lookup.factor};
- const TrimLocation end = {
- end_lookup.evaluated_index, end_lookup.next_evaluated_index, end_lookup.factor};
-
- const int num = end.right_index - start.left_index + 1;
-
- linear_trim_data<float3>(start, end, spline.positions());
- linear_trim_data<float>(start, end, spline.radii());
- linear_trim_data<float>(start, end, spline.tilts());
-
- spline.attributes.foreach_attribute(
- [&](const AttributeIDRef &attribute_id, const AttributeMetaData &UNUSED(meta_data)) {
- std::optional<GMutableSpan> src = spline.attributes.get_for_write(attribute_id);
- BLI_assert(src);
- attribute_math::convert_to_static_type(src->type(), [&](auto dummy) {
- using T = decltype(dummy);
- linear_trim_data<T>(start, end, src->typed<T>());
- });
- return true;
- },
- ATTR_DOMAIN_POINT);
-
- spline.resize(num);
-}
-
-/**
- * Trim NURB splines by converting to a poly spline.
- */
-static PolySpline trim_nurbs_spline(const Spline &spline,
- const Spline::LookupResult &start_lookup,
- const Spline::LookupResult &end_lookup)
-{
- /* Since this outputs a poly spline, the evaluated indices are the control point indices. */
- const TrimLocation start = {
- start_lookup.evaluated_index, start_lookup.next_evaluated_index, start_lookup.factor};
- const TrimLocation end = {
- end_lookup.evaluated_index, end_lookup.next_evaluated_index, end_lookup.factor};
-
- const int num = end.right_index - start.left_index + 1;
-
- /* Create poly spline and copy trimmed data to it. */
- PolySpline new_spline;
- new_spline.resize(num);
-
- /* Copy generic attribute data. */
- spline.attributes.foreach_attribute(
- [&](const AttributeIDRef &attribute_id, const AttributeMetaData &meta_data) {
- std::optional<GSpan> src = spline.attributes.get_for_read(attribute_id);
- BLI_assert(src);
- if (!new_spline.attributes.create(attribute_id, meta_data.data_type)) {
- BLI_assert_unreachable();
- return false;
- }
- std::optional<GMutableSpan> dst = new_spline.attributes.get_for_write(attribute_id);
- BLI_assert(dst);
-
- attribute_math::convert_to_static_type(src->type(), [&](auto dummy) {
- using T = decltype(dummy);
- VArray<T> eval_data = spline.interpolate_to_evaluated<T>(src->typed<T>());
- linear_trim_to_output_data<T>(
- start, end, eval_data.get_internal_span(), dst->typed<T>());
- });
- return true;
- },
- ATTR_DOMAIN_POINT);
-
- linear_trim_to_output_data<float3>(
- start, end, spline.evaluated_positions(), new_spline.positions());
-
- VArray<float> evaluated_radii = spline.interpolate_to_evaluated(spline.radii());
- linear_trim_to_output_data<float>(
- start, end, evaluated_radii.get_internal_span(), new_spline.radii());
-
- VArray<float> evaluated_tilts = spline.interpolate_to_evaluated(spline.tilts());
- linear_trim_to_output_data<float>(
- start, end, evaluated_tilts.get_internal_span(), new_spline.tilts());
-
- return new_spline;
-}
-
-/**
- * Trim Bezier splines by adjusting the first and last handles
- * and control points to maintain the original shape.
- */
-static void trim_bezier_spline(Spline &spline,
- const Spline::LookupResult &start_lookup,
- const Spline::LookupResult &end_lookup)
-{
- BezierSpline &bezier_spline = static_cast<BezierSpline &>(spline);
-
- const TrimLocation start = lookup_control_point_position(start_lookup, bezier_spline);
- TrimLocation end = lookup_control_point_position(end_lookup, bezier_spline);
-
- const Span<int> control_offsets = bezier_spline.control_point_offsets();
-
- /* The number of control points in the resulting spline. */
- const int num = end.right_index - start.left_index + 1;
-
- /* Trim the spline attributes. Done before end.factor recalculation as it needs
- * the original end.factor value. */
- linear_trim_data<float>(start, end, bezier_spline.radii());
- linear_trim_data<float>(start, end, bezier_spline.tilts());
- spline.attributes.foreach_attribute(
- [&](const AttributeIDRef &attribute_id, const AttributeMetaData &UNUSED(meta_data)) {
- std::optional<GMutableSpan> src = spline.attributes.get_for_write(attribute_id);
- BLI_assert(src);
- attribute_math::convert_to_static_type(src->type(), [&](auto dummy) {
- using T = decltype(dummy);
- linear_trim_data<T>(start, end, src->typed<T>());
- });
- return true;
- },
- ATTR_DOMAIN_POINT);
-
- /* Recalculate end.factor if the `num` is two, because the adjustment in the
- * position of the control point of the spline to the left of the new end point will change the
- * factor between them. */
- if (num == 2) {
- if (start_lookup.factor == 1.0f) {
- end.factor = 0.0f;
- }
- else {
- end.factor = (end_lookup.evaluated_index + end_lookup.factor -
- (start_lookup.evaluated_index + start_lookup.factor)) /
- (control_offsets[end.right_index] -
- (start_lookup.evaluated_index + start_lookup.factor));
- end.factor = std::clamp(end.factor, 0.0f, 1.0f);
- }
- }
-
- BezierSpline::InsertResult start_point = bezier_spline.calculate_segment_insertion(
- start.left_index, start.right_index, start.factor);
-
- /* Update the start control point parameters so they are used calculating the new end point. */
- bezier_spline.positions()[start.left_index] = start_point.position;
- bezier_spline.handle_positions_right()[start.left_index] = start_point.right_handle;
- bezier_spline.handle_positions_left()[start.right_index] = start_point.handle_next;
-
- const BezierSpline::InsertResult end_point = bezier_spline.calculate_segment_insertion(
- end.left_index, end.right_index, end.factor);
-
- /* If `num` is two, then the start point right handle needs to change to reflect the end point
- * previous handle update. */
- if (num == 2) {
- start_point.right_handle = end_point.handle_prev;
- }
-
- /* Shift control point position data to start at beginning of array. */
- if (start.left_index > 0) {
- shift_slice_to_start(bezier_spline.positions(), start.left_index, num);
- shift_slice_to_start(bezier_spline.handle_positions_left(), start.left_index, num);
- shift_slice_to_start(bezier_spline.handle_positions_right(), start.left_index, num);
- }
-
- bezier_spline.positions().first() = start_point.position;
- bezier_spline.positions()[num - 1] = end_point.position;
-
- bezier_spline.handle_positions_left().first() = start_point.left_handle;
- bezier_spline.handle_positions_left()[num - 1] = end_point.left_handle;
-
- bezier_spline.handle_positions_right().first() = start_point.right_handle;
- bezier_spline.handle_positions_right()[num - 1] = end_point.right_handle;
-
- /* If there is at least one control point between the endpoints, update the control
- * point handle to the right of the start point and to the left of the end point. */
- if (num > 2) {
- bezier_spline.handle_positions_left()[start.right_index - start.left_index] =
- start_point.handle_next;
- bezier_spline.handle_positions_right()[end.left_index - start.left_index] =
- end_point.handle_prev;
- }
-
- bezier_spline.resize(num);
-}
-
-static void trim_spline(SplinePtr &spline,
- const Spline::LookupResult start,
- const Spline::LookupResult end)
-{
- switch (spline->type()) {
- case CURVE_TYPE_BEZIER:
- trim_bezier_spline(*spline, start, end);
- break;
- case CURVE_TYPE_POLY:
- trim_poly_spline(*spline, start, end);
- break;
- case CURVE_TYPE_NURBS:
- spline = std::make_unique<PolySpline>(trim_nurbs_spline(*spline, start, end));
- break;
- case CURVE_TYPE_CATMULL_ROM:
- BLI_assert_unreachable();
- spline = {};
- }
- spline->mark_cache_invalid();
-}
-
-template<typename T>
-static void to_single_point_data(const TrimLocation &trim, MutableSpan<T> data)
-{
- data.first() = mix2<T>(trim.factor, data[trim.left_index], data[trim.right_index]);
-}
-template<typename T>
-static void to_single_point_data(const TrimLocation &trim, Span<T> src, MutableSpan<T> dst)
-{
- dst.first() = mix2<T>(trim.factor, src[trim.left_index], src[trim.right_index]);
-}
-
-static void to_single_point_bezier(Spline &spline, const Spline::LookupResult &lookup)
-{
- BezierSpline &bezier = static_cast<BezierSpline &>(spline);
-
- const TrimLocation trim = lookup_control_point_position(lookup, bezier);
-
- const BezierSpline::InsertResult new_point = bezier.calculate_segment_insertion(
- trim.left_index, trim.right_index, trim.factor);
- bezier.positions().first() = new_point.position;
- bezier.handle_types_left().first() = BEZIER_HANDLE_FREE;
- bezier.handle_types_right().first() = BEZIER_HANDLE_FREE;
- bezier.handle_positions_left().first() = new_point.left_handle;
- bezier.handle_positions_right().first() = new_point.right_handle;
-
- to_single_point_data<float>(trim, bezier.radii());
- to_single_point_data<float>(trim, bezier.tilts());
- spline.attributes.foreach_attribute(
- [&](const AttributeIDRef &attribute_id, const AttributeMetaData &UNUSED(meta_data)) {
- std::optional<GMutableSpan> data = spline.attributes.get_for_write(attribute_id);
- attribute_math::convert_to_static_type(data->type(), [&](auto dummy) {
- using T = decltype(dummy);
- to_single_point_data<T>(trim, data->typed<T>());
- });
- return true;
- },
- ATTR_DOMAIN_POINT);
- spline.resize(1);
-}
-
-static void to_single_point_poly(Spline &spline, const Spline::LookupResult &lookup)
-{
- const TrimLocation trim{lookup.evaluated_index, lookup.next_evaluated_index, lookup.factor};
-
- to_single_point_data<float3>(trim, spline.positions());
- to_single_point_data<float>(trim, spline.radii());
- to_single_point_data<float>(trim, spline.tilts());
- spline.attributes.foreach_attribute(
- [&](const AttributeIDRef &attribute_id, const AttributeMetaData &UNUSED(meta_data)) {
- std::optional<GMutableSpan> data = spline.attributes.get_for_write(attribute_id);
- attribute_math::convert_to_static_type(data->type(), [&](auto dummy) {
- using T = decltype(dummy);
- to_single_point_data<T>(trim, data->typed<T>());
- });
- return true;
- },
- ATTR_DOMAIN_POINT);
- spline.resize(1);
-}
-
-static PolySpline to_single_point_nurbs(const Spline &spline, const Spline::LookupResult &lookup)
-{
- /* Since this outputs a poly spline, the evaluated indices are the control point indices. */
- const TrimLocation trim{lookup.evaluated_index, lookup.next_evaluated_index, lookup.factor};
-
- /* Create poly spline and copy trimmed data to it. */
- PolySpline new_spline;
- new_spline.resize(1);
-
- spline.attributes.foreach_attribute(
- [&](const AttributeIDRef &attribute_id, const AttributeMetaData &meta_data) {
- new_spline.attributes.create(attribute_id, meta_data.data_type);
- std::optional<GSpan> src = spline.attributes.get_for_read(attribute_id);
- std::optional<GMutableSpan> dst = new_spline.attributes.get_for_write(attribute_id);
- attribute_math::convert_to_static_type(src->type(), [&](auto dummy) {
- using T = decltype(dummy);
- VArray<T> eval_data = spline.interpolate_to_evaluated<T>(src->typed<T>());
- to_single_point_data<T>(trim, eval_data.get_internal_span(), dst->typed<T>());
- });
- return true;
- },
- ATTR_DOMAIN_POINT);
-
- to_single_point_data<float3>(trim, spline.evaluated_positions(), new_spline.positions());
-
- VArray<float> evaluated_radii = spline.interpolate_to_evaluated(spline.radii());
- to_single_point_data<float>(trim, evaluated_radii.get_internal_span(), new_spline.radii());
-
- VArray<float> evaluated_tilts = spline.interpolate_to_evaluated(spline.tilts());
- to_single_point_data<float>(trim, evaluated_tilts.get_internal_span(), new_spline.tilts());
-
- return new_spline;
-}
-
-static void to_single_point_spline(SplinePtr &spline, const Spline::LookupResult &lookup)
-{
- switch (spline->type()) {
- case CURVE_TYPE_BEZIER:
- to_single_point_bezier(*spline, lookup);
- break;
- case CURVE_TYPE_POLY:
- to_single_point_poly(*spline, lookup);
- break;
- case CURVE_TYPE_NURBS:
- spline = std::make_unique<PolySpline>(to_single_point_nurbs(*spline, lookup));
- break;
- case CURVE_TYPE_CATMULL_ROM:
- BLI_assert_unreachable();
- spline = {};
- }
-}
-
static void geometry_set_curve_trim(GeometrySet &geometry_set,
const GeometryNodeCurveSampleMode mode,
Field<float> &start_field,
@@ -504,71 +115,50 @@ static void geometry_set_curve_trim(GeometrySet &geometry_set,
if (!geometry_set.has_curves()) {
return;
}
+ const Curves &src_curves_id = *geometry_set.get_curves_for_read();
+ const bke::CurvesGeometry &src_curves = bke::CurvesGeometry::wrap(src_curves_id.geometry);
+ if (src_curves.curves_num() == 0) {
+ return;
+ }
- CurveComponent &component = geometry_set.get_component_for_write<CurveComponent>();
- GeometryComponentFieldContext field_context{component, ATTR_DOMAIN_CURVE};
- const int domain_size = component.attribute_domain_size(ATTR_DOMAIN_CURVE);
-
- fn::FieldEvaluator evaluator{field_context, domain_size};
+ bke::CurvesFieldContext field_context{src_curves, ATTR_DOMAIN_CURVE};
+ fn::FieldEvaluator evaluator{field_context, src_curves.curves_num()};
evaluator.add(start_field);
evaluator.add(end_field);
evaluator.evaluate();
const VArray<float> starts = evaluator.get_evaluated<float>(0);
const VArray<float> ends = evaluator.get_evaluated<float>(1);
- const Curves &src_curves_id = *geometry_set.get_curves_for_read();
- std::unique_ptr<CurveEval> curve = curves_to_curve_eval(src_curves_id);
- MutableSpan<SplinePtr> splines = curve->splines();
-
- threading::parallel_for(splines.index_range(), 128, [&](IndexRange range) {
- for (const int i : range) {
- SplinePtr &spline = splines[i];
-
- /* Currently trimming cyclic splines is not supported. It could be in the future though. */
- if (spline->is_cyclic()) {
- continue;
- }
-
- if (spline->evaluated_edges_num() == 0) {
- continue;
- }
-
- const float length = spline->length();
- if (length == 0.0f) {
- continue;
- }
-
- const float start = starts[i];
- const float end = ends[i];
-
- /* When the start and end samples are reversed, instead of implicitly reversing the spline
- * or switching the parameters, create a single point spline with the end sample point. */
- if (end <= start) {
- if (mode == GEO_NODE_CURVE_SAMPLE_LENGTH) {
- to_single_point_spline(spline,
- spline->lookup_evaluated_length(std::clamp(start, 0.0f, length)));
- }
- else {
- to_single_point_spline(spline,
- spline->lookup_evaluated_factor(std::clamp(start, 0.0f, 1.0f)));
- }
- continue;
- }
-
- if (mode == GEO_NODE_CURVE_SAMPLE_LENGTH) {
- trim_spline(spline,
- spline->lookup_evaluated_length(std::clamp(start, 0.0f, length)),
- spline->lookup_evaluated_length(std::clamp(end, 0.0f, length)));
- }
- else {
- trim_spline(spline,
- spline->lookup_evaluated_factor(std::clamp(start, 0.0f, 1.0f)),
- spline->lookup_evaluated_factor(std::clamp(end, 0.0f, 1.0f)));
- }
+ const VArray<bool> cyclic = src_curves.cyclic();
+
+ /* If node length input is on form [0, 1] instead of [0, length]*/
+ const bool normalized_length_lookup = mode == GEO_NODE_CURVE_SAMPLE_FACTOR;
+
+ /* Stack start + end field. */
+ Vector<float> length_factors(src_curves.curves_num() * 2);
+ Vector<int64_t> lookup_indices(src_curves.curves_num() * 2);
+ threading::parallel_for(src_curves.curves_range(), 512, [&](IndexRange curve_range) {
+ for (const int64_t curve_i : curve_range) {
+ const bool negative_trim = !cyclic[curve_i] && starts[curve_i] > ends[curve_i];
+ length_factors[curve_i] = starts[curve_i];
+ length_factors[curve_i + src_curves.curves_num()] = negative_trim ? starts[curve_i] :
+ ends[curve_i];
+ lookup_indices[curve_i] = curve_i;
+ lookup_indices[curve_i + src_curves.curves_num()] = curve_i;
}
});
- Curves *dst_curves_id = curve_eval_to_curves(*curve);
+ /* Create curve trim lookup table. */
+ Array<bke::curves::CurvePoint, 12> point_lookups = geometry::lookup_curve_points(
+ src_curves, length_factors, lookup_indices, normalized_length_lookup);
+
+ bke::CurvesGeometry dst_curves = geometry::trim_curves(
+ src_curves,
+ src_curves.curves_range().as_span(),
+ point_lookups.as_span().slice(0, src_curves.curves_num()),
+ point_lookups.as_span().slice(src_curves.curves_num(), src_curves.curves_num()));
+
+ Curves *dst_curves_id = bke::curves_new_nomain(std::move(dst_curves));
bke::curves_copy_parameters(src_curves_id, *dst_curves_id);
geometry_set.replace_curves(dst_curves_id);
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc b/source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc
index 8b653296e12..0932624bdc3 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc
@@ -60,11 +60,18 @@ static void deform_curves(const CurvesGeometry &curves,
Array<ReverseUVSampler::Result> surface_samples_old(curves_num);
Array<ReverseUVSampler::Result> surface_samples_new(curves_num);
threading::parallel_invoke(
+ 1024 < curves_num,
[&]() { reverse_uv_sampler_old.sample_many(curve_attachment_uvs, surface_samples_old); },
[&]() { reverse_uv_sampler_new.sample_many(curve_attachment_uvs, surface_samples_new); });
const float4x4 curves_to_surface = surface_to_curves.inverted();
+ const Span<MVert> surface_verts_old = surface_mesh_old.verts();
+ const Span<MLoop> surface_loops_old = surface_mesh_old.loops();
+
+ const Span<MVert> surface_verts_new = surface_mesh_new.verts();
+ const Span<MLoop> surface_loops_new = surface_mesh_new.loops();
+
threading::parallel_for(curves.curves_range(), 256, [&](const IndexRange range) {
for (const int curve_i : range) {
const ReverseUVSampler::Result &surface_sample_old = surface_samples_old[curve_i];
@@ -91,13 +98,13 @@ static void deform_curves(const CurvesGeometry &curves,
const int corner_1_new = looptri_new.tri[1];
const int corner_2_new = looptri_new.tri[2];
- const int vert_0_old = surface_mesh_old.mloop[corner_0_old].v;
- const int vert_1_old = surface_mesh_old.mloop[corner_1_old].v;
- const int vert_2_old = surface_mesh_old.mloop[corner_2_old].v;
+ const int vert_0_old = surface_loops_old[corner_0_old].v;
+ const int vert_1_old = surface_loops_old[corner_1_old].v;
+ const int vert_2_old = surface_loops_old[corner_2_old].v;
- const int vert_0_new = surface_mesh_new.mloop[corner_0_new].v;
- const int vert_1_new = surface_mesh_new.mloop[corner_1_new].v;
- const int vert_2_new = surface_mesh_new.mloop[corner_2_new].v;
+ const int vert_0_new = surface_loops_new[corner_0_new].v;
+ const int vert_1_new = surface_loops_new[corner_1_new].v;
+ const int vert_2_new = surface_loops_new[corner_2_new].v;
const float3 &normal_0_old = corner_normals_old[corner_0_old];
const float3 &normal_1_old = corner_normals_old[corner_1_old];
@@ -111,14 +118,14 @@ static void deform_curves(const CurvesGeometry &curves,
const float3 normal_new = math::normalize(
mix3(bary_weights_new, normal_0_new, normal_1_new, normal_2_new));
- const float3 &pos_0_old = surface_mesh_old.mvert[vert_0_old].co;
- const float3 &pos_1_old = surface_mesh_old.mvert[vert_1_old].co;
- const float3 &pos_2_old = surface_mesh_old.mvert[vert_2_old].co;
+ const float3 &pos_0_old = surface_verts_old[vert_0_old].co;
+ const float3 &pos_1_old = surface_verts_old[vert_1_old].co;
+ const float3 &pos_2_old = surface_verts_old[vert_2_old].co;
const float3 pos_old = mix3(bary_weights_old, pos_0_old, pos_1_old, pos_2_old);
- const float3 &pos_0_new = surface_mesh_new.mvert[vert_0_new].co;
- const float3 &pos_1_new = surface_mesh_new.mvert[vert_1_new].co;
- const float3 &pos_2_new = surface_mesh_new.mvert[vert_2_new].co;
+ const float3 &pos_0_new = surface_verts_new[vert_0_new].co;
+ const float3 &pos_1_new = surface_verts_new[vert_1_new].co;
+ const float3 &pos_2_new = surface_verts_new[vert_2_new].co;
const float3 pos_new = mix3(bary_weights_new, pos_0_new, pos_1_new, pos_2_new);
/* The translation is just the difference between the old and new position on the surface. */
@@ -221,13 +228,13 @@ static void node_geo_exec(GeoNodeExecParams params)
const Object *self_ob_eval = params.self_object();
if (self_ob_eval == nullptr || self_ob_eval->type != OB_CURVES) {
pass_through_input();
+ params.error_message_add(NodeWarningType::Error, TIP_("Node only works for curves objects"));
return;
}
const Curves *self_curves_eval = static_cast<const Curves *>(self_ob_eval->data);
if (self_curves_eval->surface_uv_map == nullptr || self_curves_eval->surface_uv_map[0] == '\0') {
pass_through_input();
- const char *message = TIP_("Surface UV map not defined");
- params.error_message_add(NodeWarningType::Error, message);
+ params.error_message_add(NodeWarningType::Error, TIP_("Surface UV map not defined"));
return;
}
/* Take surface information from self-object. */
@@ -241,14 +248,14 @@ static void node_geo_exec(GeoNodeExecParams params)
}
if (surface_ob_eval == nullptr || surface_ob_eval->type != OB_MESH) {
pass_through_input();
- params.error_message_add(NodeWarningType::Error, "Curves not attached to a surface");
+ params.error_message_add(NodeWarningType::Error, TIP_("Curves not attached to a surface"));
return;
}
Object *surface_ob_orig = DEG_get_original_object(surface_ob_eval);
Mesh &surface_object_data = *static_cast<Mesh *>(surface_ob_orig->data);
if (BMEditMesh *em = surface_object_data.edit_mesh) {
- surface_mesh_orig = BKE_mesh_from_bmesh_for_eval_nomain(em->bm, NULL, &surface_object_data);
+ surface_mesh_orig = BKE_mesh_from_bmesh_for_eval_nomain(em->bm, nullptr, &surface_object_data);
free_suface_mesh_orig = true;
}
else {
@@ -257,21 +264,21 @@ static void node_geo_exec(GeoNodeExecParams params)
Mesh *surface_mesh_eval = BKE_modifier_get_evaluated_mesh_from_evaluated_object(surface_ob_eval);
if (surface_mesh_eval == nullptr) {
pass_through_input();
- params.error_message_add(NodeWarningType::Error, "Surface has no mesh");
+ params.error_message_add(NodeWarningType::Error, TIP_("Surface has no mesh"));
return;
}
BKE_mesh_wrapper_ensure_mdata(surface_mesh_eval);
- const AttributeAccessor mesh_attributes_eval = bke::mesh_attributes(*surface_mesh_eval);
- const AttributeAccessor mesh_attributes_orig = bke::mesh_attributes(*surface_mesh_orig);
+ const AttributeAccessor mesh_attributes_eval = surface_mesh_eval->attributes();
+ const AttributeAccessor mesh_attributes_orig = surface_mesh_orig->attributes();
Curves &curves_id = *curves_geometry.get_curves_for_write();
CurvesGeometry &curves = CurvesGeometry::wrap(curves_id.geometry);
if (!mesh_attributes_eval.contains(uv_map_name)) {
pass_through_input();
- char *message = BLI_sprintfN(TIP_("Evaluated surface missing UV map: %s"),
+ char *message = BLI_sprintfN(TIP_("Evaluated surface missing UV map: \"%s\""),
uv_map_name.c_str());
params.error_message_add(NodeWarningType::Error, message);
MEM_freeN(message);
@@ -279,7 +286,8 @@ static void node_geo_exec(GeoNodeExecParams params)
}
if (!mesh_attributes_orig.contains(uv_map_name)) {
pass_through_input();
- char *message = BLI_sprintfN(TIP_("Original surface missing UV map: %s"), uv_map_name.c_str());
+ char *message = BLI_sprintfN(TIP_("Original surface missing UV map: \"%s\""),
+ uv_map_name.c_str());
params.error_message_add(NodeWarningType::Error, message);
MEM_freeN(message);
return;
@@ -287,7 +295,7 @@ static void node_geo_exec(GeoNodeExecParams params)
if (!mesh_attributes_eval.contains(rest_position_name)) {
pass_through_input();
params.error_message_add(NodeWarningType::Error,
- TIP_("Evaluated surface missing attribute: rest_position"));
+ TIP_("Evaluated surface missing attribute: \"rest_position\""));
return;
}
if (curves.surface_uv_coords().is_empty() && curves.curves_num() > 0) {
@@ -304,10 +312,8 @@ static void node_geo_exec(GeoNodeExecParams params)
ATTR_DOMAIN_POINT);
const Span<float2> surface_uv_coords = curves.surface_uv_coords();
- const Span<MLoopTri> looptris_orig{BKE_mesh_runtime_looptri_ensure(surface_mesh_orig),
- BKE_mesh_runtime_looptri_len(surface_mesh_orig)};
- const Span<MLoopTri> looptris_eval{BKE_mesh_runtime_looptri_ensure(surface_mesh_eval),
- BKE_mesh_runtime_looptri_len(surface_mesh_eval)};
+ const Span<MLoopTri> looptris_orig = surface_mesh_orig->looptris();
+ const Span<MLoopTri> looptris_eval = surface_mesh_eval->looptris();
const ReverseUVSampler reverse_uv_sampler_orig{uv_map_orig, looptris_orig};
const ReverseUVSampler reverse_uv_sampler_eval{uv_map_eval, looptris_eval};
@@ -373,19 +379,22 @@ static void node_geo_exec(GeoNodeExecParams params)
invalid_uv_count);
/* Then also deform edit curve information for use in sculpt mode. */
const CurvesGeometry &curves_orig = CurvesGeometry::wrap(edit_hints->curves_id_orig.geometry);
- deform_curves(curves_orig,
- *surface_mesh_orig,
- *surface_mesh_eval,
- surface_uv_coords,
- reverse_uv_sampler_orig,
- reverse_uv_sampler_eval,
- corner_normals_orig,
- corner_normals_eval,
- rest_positions,
- transforms.surface_to_curves,
- edit_hint_positions,
- edit_hint_rotations,
- invalid_uv_count);
+ const Span<float2> surface_uv_coords_orig = curves_orig.surface_uv_coords();
+ if (!surface_uv_coords_orig.is_empty()) {
+ deform_curves(curves_orig,
+ *surface_mesh_orig,
+ *surface_mesh_eval,
+ surface_uv_coords_orig,
+ reverse_uv_sampler_orig,
+ reverse_uv_sampler_eval,
+ corner_normals_orig,
+ corner_normals_eval,
+ rest_positions,
+ transforms.surface_to_curves,
+ edit_hint_positions,
+ edit_hint_rotations,
+ invalid_uv_count);
+ }
}
curves.tag_positions_changed();
diff --git a/source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc b/source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc
index b74b4e45199..3e48a9fd923 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc
@@ -4,13 +4,16 @@
#include "UI_resources.h"
#include "BLI_array.hh"
+#include "BLI_array_utils.hh"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
+#include "DNA_pointcloud_types.h"
#include "BKE_attribute_math.hh"
#include "BKE_curves.hh"
#include "BKE_customdata.h"
+#include "BKE_instances.hh"
#include "BKE_mesh.h"
#include "BKE_pointcloud.h"
@@ -21,15 +24,9 @@ namespace blender::nodes::node_geo_delete_geometry_cc {
using blender::bke::CustomDataAttributes;
template<typename T>
-static void copy_data_based_on_mask(Span<T> data, MutableSpan<T> r_data, IndexMask mask)
-{
- for (const int i_out : mask.index_range()) {
- r_data[i_out] = data[mask[i_out]];
- }
-}
-
-template<typename T>
-static void copy_data_based_on_map(Span<T> src, MutableSpan<T> dst, Span<int> index_map)
+static void copy_data_based_on_map(const Span<T> src,
+ const Span<int> index_map,
+ MutableSpan<T> dst)
{
for (const int i_src : index_map.index_range()) {
const int i_dst = index_map[i_src];
@@ -53,26 +50,17 @@ static void copy_attributes(const Map<AttributeIDRef, AttributeKind> &attributes
if (!attribute) {
continue;
}
-
/* Only copy if it is on a domain we want. */
if (!domains.contains(attribute.domain)) {
continue;
}
const eCustomDataType data_type = bke::cpp_type_to_custom_data_type(attribute.varray.type());
-
GSpanAttributeWriter result_attribute = dst_attributes.lookup_or_add_for_write_only_span(
attribute_id, attribute.domain, data_type);
-
if (!result_attribute) {
continue;
}
-
- attribute_math::convert_to_static_type(data_type, [&](auto dummy) {
- using T = decltype(dummy);
- VArraySpan<T> span{attribute.varray.typed<T>()};
- MutableSpan<T> out_span = result_attribute.span.typed<T>();
- out_span.copy_from(span);
- });
+ attribute.varray.materialize(result_attribute.span.data());
result_attribute.finish();
}
}
@@ -93,26 +81,19 @@ static void copy_attributes_based_on_mask(const Map<AttributeIDRef, AttributeKin
if (!attribute) {
continue;
}
-
/* Only copy if it is on a domain we want. */
if (domain != attribute.domain) {
continue;
}
const eCustomDataType data_type = bke::cpp_type_to_custom_data_type(attribute.varray.type());
-
GSpanAttributeWriter result_attribute = dst_attributes.lookup_or_add_for_write_only_span(
attribute_id, attribute.domain, data_type);
-
if (!result_attribute) {
continue;
}
- attribute_math::convert_to_static_type(data_type, [&](auto dummy) {
- using T = decltype(dummy);
- VArraySpan<T> span{attribute.varray.typed<T>()};
- MutableSpan<T> out_span = result_attribute.span.typed<T>();
- copy_data_based_on_mask(span, out_span, mask);
- });
+ array_utils::gather(attribute.varray, mask, result_attribute.span);
+
result_attribute.finish();
}
}
@@ -129,16 +110,13 @@ static void copy_attributes_based_on_map(const Map<AttributeIDRef, AttributeKind
if (!attribute) {
continue;
}
-
/* Only copy if it is on a domain we want. */
if (domain != attribute.domain) {
continue;
}
const eCustomDataType data_type = bke::cpp_type_to_custom_data_type(attribute.varray.type());
-
GSpanAttributeWriter result_attribute = dst_attributes.lookup_or_add_for_write_only_span(
attribute_id, attribute.domain, data_type);
-
if (!result_attribute) {
continue;
}
@@ -147,7 +125,7 @@ static void copy_attributes_based_on_map(const Map<AttributeIDRef, AttributeKind
using T = decltype(dummy);
VArraySpan<T> span{attribute.varray.typed<T>()};
MutableSpan<T> out_span = result_attribute.span.typed<T>();
- copy_data_based_on_map(span, out_span, index_map);
+ copy_data_based_on_map(span, index_map, out_span);
});
result_attribute.finish();
}
@@ -160,10 +138,11 @@ static void copy_face_corner_attributes(const Map<AttributeIDRef, AttributeKind>
const Span<int> selected_poly_indices,
const Mesh &mesh_in)
{
+ const Span<MPoly> polys = mesh_in.polys();
Vector<int64_t> indices;
indices.reserve(selected_loops_num);
for (const int src_poly_index : selected_poly_indices) {
- const MPoly &src_poly = mesh_in.mpoly[src_poly_index];
+ const MPoly &src_poly = polys[src_poly_index];
const int src_loop_start = src_poly.loopstart;
const int tot_loop = src_poly.totloop;
for (const int i : IndexRange(tot_loop)) {
@@ -174,39 +153,35 @@ static void copy_face_corner_attributes(const Map<AttributeIDRef, AttributeKind>
attributes, src_attributes, dst_attributes, ATTR_DOMAIN_CORNER, IndexMask(indices));
}
-static void copy_masked_vertices_to_new_mesh(const Mesh &src_mesh,
- Mesh &dst_mesh,
- Span<int> vertex_map)
+static void copy_masked_verts_to_new_mesh(const Mesh &src_mesh,
+ Mesh &dst_mesh,
+ Span<int> vertex_map)
{
BLI_assert(src_mesh.totvert == vertex_map.size());
+ const Span<MVert> src_verts = src_mesh.verts();
+ MutableSpan<MVert> dst_verts = dst_mesh.verts_for_write();
+
for (const int i_src : vertex_map.index_range()) {
const int i_dst = vertex_map[i_src];
if (i_dst == -1) {
continue;
}
-
- const MVert &v_src = src_mesh.mvert[i_src];
- MVert &v_dst = dst_mesh.mvert[i_dst];
-
- v_dst = v_src;
+ dst_verts[i_dst] = src_verts[i_src];
}
}
static void copy_masked_edges_to_new_mesh(const Mesh &src_mesh, Mesh &dst_mesh, Span<int> edge_map)
{
BLI_assert(src_mesh.totedge == edge_map.size());
+ const Span<MEdge> src_edges = src_mesh.edges();
+ MutableSpan<MEdge> dst_edges = dst_mesh.edges_for_write();
+
for (const int i_src : IndexRange(src_mesh.totedge)) {
const int i_dst = edge_map[i_src];
if (ELEM(i_dst, -1, -2)) {
continue;
}
-
- const MEdge &e_src = src_mesh.medge[i_src];
- MEdge &e_dst = dst_mesh.medge[i_dst];
-
- e_dst = e_src;
- e_dst.v1 = e_src.v1;
- e_dst.v2 = e_src.v2;
+ dst_edges[i_dst] = src_edges[i_src];
}
}
@@ -217,14 +192,16 @@ static void copy_masked_edges_to_new_mesh(const Mesh &src_mesh,
{
BLI_assert(src_mesh.totvert == vertex_map.size());
BLI_assert(src_mesh.totedge == edge_map.size());
+ const Span<MEdge> src_edges = src_mesh.edges();
+ MutableSpan<MEdge> dst_edges = dst_mesh.edges_for_write();
+
for (const int i_src : IndexRange(src_mesh.totedge)) {
const int i_dst = edge_map[i_src];
if (i_dst == -1) {
continue;
}
-
- const MEdge &e_src = src_mesh.medge[i_src];
- MEdge &e_dst = dst_mesh.medge[i_dst];
+ const MEdge &e_src = src_edges[i_src];
+ MEdge &e_dst = dst_edges[i_dst];
e_dst = e_src;
e_dst.v1 = vertex_map[e_src.v1];
@@ -239,16 +216,21 @@ static void copy_masked_polys_to_new_mesh(const Mesh &src_mesh,
Span<int> masked_poly_indices,
Span<int> new_loop_starts)
{
+ const Span<MPoly> src_polys = src_mesh.polys();
+ const Span<MLoop> src_loops = src_mesh.loops();
+ MutableSpan<MPoly> dst_polys = dst_mesh.polys_for_write();
+ MutableSpan<MLoop> dst_loops = dst_mesh.loops_for_write();
+
for (const int i_dst : masked_poly_indices.index_range()) {
const int i_src = masked_poly_indices[i_dst];
- const MPoly &mp_src = src_mesh.mpoly[i_src];
- MPoly &mp_dst = dst_mesh.mpoly[i_dst];
+ const MPoly &mp_src = src_polys[i_src];
+ MPoly &mp_dst = dst_polys[i_dst];
const int i_ml_src = mp_src.loopstart;
const int i_ml_dst = new_loop_starts[i_dst];
- const MLoop *ml_src = src_mesh.mloop + i_ml_src;
- MLoop *ml_dst = dst_mesh.mloop + i_ml_dst;
+ const MLoop *ml_src = &src_loops[i_ml_src];
+ MLoop *ml_dst = &dst_loops[i_ml_dst];
mp_dst = mp_src;
mp_dst.loopstart = i_ml_dst;
@@ -265,16 +247,21 @@ static void copy_masked_polys_to_new_mesh(const Mesh &src_mesh,
Span<int> masked_poly_indices,
Span<int> new_loop_starts)
{
+ const Span<MPoly> src_polys = src_mesh.polys();
+ const Span<MLoop> src_loops = src_mesh.loops();
+ MutableSpan<MPoly> dst_polys = dst_mesh.polys_for_write();
+ MutableSpan<MLoop> dst_loops = dst_mesh.loops_for_write();
+
for (const int i_dst : masked_poly_indices.index_range()) {
const int i_src = masked_poly_indices[i_dst];
- const MPoly &mp_src = src_mesh.mpoly[i_src];
- MPoly &mp_dst = dst_mesh.mpoly[i_dst];
+ const MPoly &mp_src = src_polys[i_src];
+ MPoly &mp_dst = dst_polys[i_dst];
const int i_ml_src = mp_src.loopstart;
const int i_ml_dst = new_loop_starts[i_dst];
- const MLoop *ml_src = src_mesh.mloop + i_ml_src;
- MLoop *ml_dst = dst_mesh.mloop + i_ml_dst;
+ const MLoop *ml_src = &src_loops[i_ml_src];
+ MLoop *ml_dst = &dst_loops[i_ml_dst];
mp_dst = mp_src;
mp_dst.loopstart = i_ml_dst;
@@ -292,16 +279,21 @@ static void copy_masked_polys_to_new_mesh(const Mesh &src_mesh,
Span<int> masked_poly_indices,
Span<int> new_loop_starts)
{
+ const Span<MPoly> src_polys = src_mesh.polys();
+ const Span<MLoop> src_loops = src_mesh.loops();
+ MutableSpan<MPoly> dst_polys = dst_mesh.polys_for_write();
+ MutableSpan<MLoop> dst_loops = dst_mesh.loops_for_write();
+
for (const int i_dst : masked_poly_indices.index_range()) {
const int i_src = masked_poly_indices[i_dst];
- const MPoly &mp_src = src_mesh.mpoly[i_src];
- MPoly &mp_dst = dst_mesh.mpoly[i_dst];
+ const MPoly &mp_src = src_polys[i_src];
+ MPoly &mp_dst = dst_polys[i_dst];
const int i_ml_src = mp_src.loopstart;
const int i_ml_dst = new_loop_starts[i_dst];
- const MLoop *ml_src = src_mesh.mloop + i_ml_src;
- MLoop *ml_dst = dst_mesh.mloop + i_ml_dst;
+ const MLoop *ml_src = &src_loops[i_ml_src];
+ MLoop *ml_dst = &dst_loops[i_ml_dst];
mp_dst = mp_src;
mp_dst.loopstart = i_ml_dst;
@@ -316,18 +308,19 @@ static void delete_curves_selection(GeometrySet &geometry_set,
const Field<bool> &selection_field,
const eAttrDomain selection_domain)
{
- const CurveComponent &src_component = *geometry_set.get_component_for_read<CurveComponent>();
- GeometryComponentFieldContext field_context{src_component, selection_domain};
+ const Curves &src_curves_id = *geometry_set.get_curves_for_read();
+ const bke::CurvesGeometry &src_curves = bke::CurvesGeometry::wrap(src_curves_id.geometry);
- const int domain_num = src_component.attribute_domain_size(selection_domain);
- fn::FieldEvaluator evaluator{field_context, domain_num};
+ const int domain_size = src_curves.attributes().domain_size(selection_domain);
+ bke::CurvesFieldContext field_context{src_curves, selection_domain};
+ fn::FieldEvaluator evaluator{field_context, domain_size};
evaluator.set_selection(selection_field);
evaluator.evaluate();
const IndexMask selection = evaluator.get_evaluated_selection_as_mask();
if (selection.is_empty()) {
return;
}
- if (selection.size() == domain_num) {
+ if (selection.size() == domain_size) {
geometry_set.remove<CurveComponent>();
return;
}
@@ -347,11 +340,10 @@ static void delete_curves_selection(GeometrySet &geometry_set,
static void separate_point_cloud_selection(GeometrySet &geometry_set,
const Field<bool> &selection_field)
{
- const PointCloudComponent &src_points =
- *geometry_set.get_component_for_read<PointCloudComponent>();
- GeometryComponentFieldContext field_context{src_points, ATTR_DOMAIN_POINT};
+ const PointCloud &src_pointcloud = *geometry_set.get_pointcloud_for_read();
- fn::FieldEvaluator evaluator{field_context, src_points.attribute_domain_size(ATTR_DOMAIN_POINT)};
+ bke::PointCloudFieldContext field_context{src_pointcloud};
+ fn::FieldEvaluator evaluator{field_context, src_pointcloud.totpoint};
evaluator.set_selection(selection_field);
evaluator.evaluate();
const IndexMask selection = evaluator.get_evaluated_selection_as_mask();
@@ -367,8 +359,8 @@ static void separate_point_cloud_selection(GeometrySet &geometry_set,
{GEO_COMPONENT_TYPE_POINT_CLOUD}, GEO_COMPONENT_TYPE_POINT_CLOUD, false, attributes);
copy_attributes_based_on_mask(attributes,
- bke::pointcloud_attributes(*src_points.get_for_read()),
- bke::pointcloud_attributes_for_write(*pointcloud),
+ src_pointcloud.attributes(),
+ pointcloud->attributes_for_write(),
ATTR_DOMAIN_POINT,
selection);
geometry_set.replace_pointcloud(pointcloud);
@@ -377,8 +369,8 @@ static void separate_point_cloud_selection(GeometrySet &geometry_set,
static void delete_selected_instances(GeometrySet &geometry_set,
const Field<bool> &selection_field)
{
- InstancesComponent &instances = geometry_set.get_component_for_write<InstancesComponent>();
- GeometryComponentFieldContext field_context{instances, ATTR_DOMAIN_INSTANCE};
+ bke::Instances &instances = *geometry_set.get_instances_for_write();
+ bke::InstancesFieldContext field_context{instances};
fn::FieldEvaluator evaluator{field_context, instances.instances_num()};
evaluator.set_selection(selection_field);
@@ -389,12 +381,12 @@ static void delete_selected_instances(GeometrySet &geometry_set,
return;
}
- instances.remove_instances(selection);
+ instances.remove(selection);
}
-static void compute_selected_vertices_from_vertex_selection(const Span<bool> vertex_selection,
- MutableSpan<int> r_vertex_map,
- int *r_selected_vertices_num)
+static void compute_selected_verts_from_vertex_selection(const Span<bool> vertex_selection,
+ MutableSpan<int> r_vertex_map,
+ int *r_selected_verts_num)
{
BLI_assert(vertex_selection.size() == r_vertex_map.size());
@@ -409,7 +401,7 @@ static void compute_selected_vertices_from_vertex_selection(const Span<bool> ver
}
}
- *r_selected_vertices_num = selected_verts_num;
+ *r_selected_verts_num = selected_verts_num;
}
static void compute_selected_edges_from_vertex_selection(const Mesh &mesh,
@@ -418,10 +410,11 @@ static void compute_selected_edges_from_vertex_selection(const Mesh &mesh,
int *r_selected_edges_num)
{
BLI_assert(mesh.totedge == r_edge_map.size());
+ const Span<MEdge> edges = mesh.edges();
int selected_edges_num = 0;
for (const int i : IndexRange(mesh.totedge)) {
- const MEdge &edge = mesh.medge[i];
+ const MEdge &edge = edges[i];
/* Only add the edge if both vertices will be in the new mesh. */
if (vertex_selection[edge.v1] && vertex_selection[edge.v2]) {
@@ -436,25 +429,27 @@ static void compute_selected_edges_from_vertex_selection(const Mesh &mesh,
*r_selected_edges_num = selected_edges_num;
}
-static void compute_selected_polygons_from_vertex_selection(const Mesh &mesh,
- const Span<bool> vertex_selection,
- Vector<int> &r_selected_poly_indices,
- Vector<int> &r_loop_starts,
- int *r_selected_polys_num,
- int *r_selected_loops_num)
+static void compute_selected_polys_from_vertex_selection(const Mesh &mesh,
+ const Span<bool> vertex_selection,
+ Vector<int> &r_selected_poly_indices,
+ Vector<int> &r_loop_starts,
+ int *r_selected_polys_num,
+ int *r_selected_loops_num)
{
BLI_assert(mesh.totvert == vertex_selection.size());
+ const Span<MPoly> polys = mesh.polys();
+ const Span<MLoop> loops = mesh.loops();
r_selected_poly_indices.reserve(mesh.totpoly);
r_loop_starts.reserve(mesh.totloop);
int selected_loops_num = 0;
- for (const int i : IndexRange(mesh.totpoly)) {
- const MPoly &poly_src = mesh.mpoly[i];
+ for (const int i : polys.index_range()) {
+ const MPoly &poly_src = polys[i];
bool all_verts_in_selection = true;
- Span<MLoop> loops_src(&mesh.mloop[poly_src.loopstart], poly_src.totloop);
- for (const MLoop &loop : loops_src) {
+ const Span<MLoop> poly_loops = loops.slice(poly_src.loopstart, poly_src.totloop);
+ for (const MLoop &loop : poly_loops) {
if (!vertex_selection[loop.v]) {
all_verts_in_selection = false;
break;
@@ -476,20 +471,20 @@ static void compute_selected_polygons_from_vertex_selection(const Mesh &mesh,
* Checks for every edge if it is in `edge_selection`. If it is, then the two vertices of the
* edge are kept along with the edge.
*/
-static void compute_selected_vertices_and_edges_from_edge_selection(
- const Mesh &mesh,
- const Span<bool> edge_selection,
- MutableSpan<int> r_vertex_map,
- MutableSpan<int> r_edge_map,
- int *r_selected_vertices_num,
- int *r_selected_edges_num)
+static void compute_selected_verts_and_edges_from_edge_selection(const Mesh &mesh,
+ const Span<bool> edge_selection,
+ MutableSpan<int> r_vertex_map,
+ MutableSpan<int> r_edge_map,
+ int *r_selected_verts_num,
+ int *r_selected_edges_num)
{
BLI_assert(mesh.totedge == edge_selection.size());
+ const Span<MEdge> edges = mesh.edges();
int selected_edges_num = 0;
int selected_verts_num = 0;
for (const int i : IndexRange(mesh.totedge)) {
- const MEdge &edge = mesh.medge[i];
+ const MEdge &edge = edges[i];
if (edge_selection[i]) {
r_edge_map[i] = selected_edges_num;
selected_edges_num++;
@@ -507,7 +502,7 @@ static void compute_selected_vertices_and_edges_from_edge_selection(
}
}
- *r_selected_vertices_num = selected_verts_num;
+ *r_selected_verts_num = selected_verts_num;
*r_selected_edges_num = selected_edges_num;
}
@@ -539,23 +534,26 @@ static void compute_selected_edges_from_edge_selection(const Mesh &mesh,
* Checks for every polygon if all the edges are in `edge_selection`. If they are, then that
* polygon is kept.
*/
-static void compute_selected_polygons_from_edge_selection(const Mesh &mesh,
- const Span<bool> edge_selection,
- Vector<int> &r_selected_poly_indices,
- Vector<int> &r_loop_starts,
- int *r_selected_polys_num,
- int *r_selected_loops_num)
+static void compute_selected_polys_from_edge_selection(const Mesh &mesh,
+ const Span<bool> edge_selection,
+ Vector<int> &r_selected_poly_indices,
+ Vector<int> &r_loop_starts,
+ int *r_selected_polys_num,
+ int *r_selected_loops_num)
{
+ const Span<MPoly> polys = mesh.polys();
+ const Span<MLoop> loops = mesh.loops();
+
r_selected_poly_indices.reserve(mesh.totpoly);
r_loop_starts.reserve(mesh.totloop);
int selected_loops_num = 0;
- for (const int i : IndexRange(mesh.totpoly)) {
- const MPoly &poly_src = mesh.mpoly[i];
+ for (const int i : polys.index_range()) {
+ const MPoly &poly_src = polys[i];
bool all_edges_in_selection = true;
- Span<MLoop> loops_src(&mesh.mloop[poly_src.loopstart], poly_src.totloop);
- for (const MLoop &loop : loops_src) {
+ const Span<MLoop> poly_loops = loops.slice(poly_src.loopstart, poly_src.totloop);
+ for (const MLoop &loop : poly_loops) {
if (!edge_selection[loop.e]) {
all_edges_in_selection = false;
break;
@@ -590,12 +588,12 @@ static void compute_selected_mesh_data_from_vertex_selection_edge_face(
compute_selected_edges_from_vertex_selection(
mesh, vertex_selection, r_edge_map, r_selected_edges_num);
- compute_selected_polygons_from_vertex_selection(mesh,
- vertex_selection,
- r_selected_poly_indices,
- r_loop_starts,
- r_selected_polys_num,
- r_selected_loops_num);
+ compute_selected_polys_from_vertex_selection(mesh,
+ vertex_selection,
+ r_selected_poly_indices,
+ r_loop_starts,
+ r_selected_polys_num,
+ r_selected_loops_num);
}
/**
@@ -608,23 +606,23 @@ static void compute_selected_mesh_data_from_vertex_selection(const Mesh &mesh,
MutableSpan<int> r_edge_map,
Vector<int> &r_selected_poly_indices,
Vector<int> &r_loop_starts,
- int *r_selected_vertices_num,
+ int *r_selected_verts_num,
int *r_selected_edges_num,
int *r_selected_polys_num,
int *r_selected_loops_num)
{
- compute_selected_vertices_from_vertex_selection(
- vertex_selection, r_vertex_map, r_selected_vertices_num);
+ compute_selected_verts_from_vertex_selection(
+ vertex_selection, r_vertex_map, r_selected_verts_num);
compute_selected_edges_from_vertex_selection(
mesh, vertex_selection, r_edge_map, r_selected_edges_num);
- compute_selected_polygons_from_vertex_selection(mesh,
- vertex_selection,
- r_selected_poly_indices,
- r_loop_starts,
- r_selected_polys_num,
- r_selected_loops_num);
+ compute_selected_polys_from_vertex_selection(mesh,
+ vertex_selection,
+ r_selected_poly_indices,
+ r_loop_starts,
+ r_selected_polys_num,
+ r_selected_loops_num);
}
/**
@@ -643,17 +641,17 @@ static void compute_selected_mesh_data_from_edge_selection_edge_face(
{
compute_selected_edges_from_edge_selection(
mesh, edge_selection, r_edge_map, r_selected_edges_num);
- compute_selected_polygons_from_edge_selection(mesh,
- edge_selection,
- r_selected_poly_indices,
- r_loop_starts,
- r_selected_polys_num,
- r_selected_loops_num);
+ compute_selected_polys_from_edge_selection(mesh,
+ edge_selection,
+ r_selected_poly_indices,
+ r_loop_starts,
+ r_selected_polys_num,
+ r_selected_loops_num);
}
/**
* Checks for every edge if it is in `edge_selection`. If it is, the vertices belonging to
- * that edge are kept as well. The polygons are kept if all edges are in the selection.
+ * that edge are kept as well. The polys are kept if all edges are in the selection.
*/
static void compute_selected_mesh_data_from_edge_selection(const Mesh &mesh,
const Span<bool> edge_selection,
@@ -661,44 +659,41 @@ static void compute_selected_mesh_data_from_edge_selection(const Mesh &mesh,
MutableSpan<int> r_edge_map,
Vector<int> &r_selected_poly_indices,
Vector<int> &r_loop_starts,
- int *r_selected_vertices_num,
+ int *r_selected_verts_num,
int *r_selected_edges_num,
int *r_selected_polys_num,
int *r_selected_loops_num)
{
r_vertex_map.fill(-1);
- compute_selected_vertices_and_edges_from_edge_selection(mesh,
- edge_selection,
- r_vertex_map,
- r_edge_map,
- r_selected_vertices_num,
- r_selected_edges_num);
- compute_selected_polygons_from_edge_selection(mesh,
- edge_selection,
- r_selected_poly_indices,
- r_loop_starts,
- r_selected_polys_num,
- r_selected_loops_num);
+ compute_selected_verts_and_edges_from_edge_selection(
+ mesh, edge_selection, r_vertex_map, r_edge_map, r_selected_verts_num, r_selected_edges_num);
+ compute_selected_polys_from_edge_selection(mesh,
+ edge_selection,
+ r_selected_poly_indices,
+ r_loop_starts,
+ r_selected_polys_num,
+ r_selected_loops_num);
}
/**
* Checks for every polygon if it is in `poly_selection`.
*/
-static void compute_selected_polygons_from_poly_selection(const Mesh &mesh,
- const Span<bool> poly_selection,
- Vector<int> &r_selected_poly_indices,
- Vector<int> &r_loop_starts,
- int *r_selected_polys_num,
- int *r_selected_loops_num)
+static void compute_selected_polys_from_poly_selection(const Mesh &mesh,
+ const Span<bool> poly_selection,
+ Vector<int> &r_selected_poly_indices,
+ Vector<int> &r_loop_starts,
+ int *r_selected_polys_num,
+ int *r_selected_loops_num)
{
BLI_assert(mesh.totpoly == poly_selection.size());
+ const Span<MPoly> polys = mesh.polys();
r_selected_poly_indices.reserve(mesh.totpoly);
r_loop_starts.reserve(mesh.totloop);
int selected_loops_num = 0;
- for (const int i : IndexRange(mesh.totpoly)) {
- const MPoly &poly_src = mesh.mpoly[i];
+ for (const int i : polys.index_range()) {
+ const MPoly &poly_src = polys[i];
/* We keep this one. */
if (poly_selection[i]) {
r_selected_poly_indices.append_unchecked(i);
@@ -725,6 +720,9 @@ static void compute_selected_mesh_data_from_poly_selection_edge_face(
{
BLI_assert(mesh.totpoly == poly_selection.size());
BLI_assert(mesh.totedge == r_edge_map.size());
+ const Span<MPoly> polys = mesh.polys();
+ const Span<MLoop> loops = mesh.loops();
+
r_edge_map.fill(-1);
r_selected_poly_indices.reserve(mesh.totpoly);
@@ -732,8 +730,8 @@ static void compute_selected_mesh_data_from_poly_selection_edge_face(
int selected_loops_num = 0;
int selected_edges_num = 0;
- for (const int i : IndexRange(mesh.totpoly)) {
- const MPoly &poly_src = mesh.mpoly[i];
+ for (const int i : polys.index_range()) {
+ const MPoly &poly_src = polys[i];
/* We keep this one. */
if (poly_selection[i]) {
r_selected_poly_indices.append_unchecked(i);
@@ -741,8 +739,8 @@ static void compute_selected_mesh_data_from_poly_selection_edge_face(
selected_loops_num += poly_src.totloop;
/* Add the vertices and the edges. */
- Span<MLoop> loops_src(&mesh.mloop[poly_src.loopstart], poly_src.totloop);
- for (const MLoop &loop : loops_src) {
+ const Span<MLoop> poly_loops = loops.slice(poly_src.loopstart, poly_src.totloop);
+ for (const MLoop &loop : poly_loops) {
/* Check first if it has not yet been added. */
if (r_edge_map[loop.e] == -1) {
r_edge_map[loop.e] = selected_edges_num;
@@ -766,13 +764,16 @@ static void compute_selected_mesh_data_from_poly_selection(const Mesh &mesh,
MutableSpan<int> r_edge_map,
Vector<int> &r_selected_poly_indices,
Vector<int> &r_loop_starts,
- int *r_selected_vertices_num,
+ int *r_selected_verts_num,
int *r_selected_edges_num,
int *r_selected_polys_num,
int *r_selected_loops_num)
{
BLI_assert(mesh.totpoly == poly_selection.size());
BLI_assert(mesh.totedge == r_edge_map.size());
+ const Span<MPoly> polys = mesh.polys();
+ const Span<MLoop> loops = mesh.loops();
+
r_vertex_map.fill(-1);
r_edge_map.fill(-1);
@@ -782,8 +783,8 @@ static void compute_selected_mesh_data_from_poly_selection(const Mesh &mesh,
int selected_loops_num = 0;
int selected_verts_num = 0;
int selected_edges_num = 0;
- for (const int i : IndexRange(mesh.totpoly)) {
- const MPoly &poly_src = mesh.mpoly[i];
+ for (const int i : polys.index_range()) {
+ const MPoly &poly_src = polys[i];
/* We keep this one. */
if (poly_selection[i]) {
r_selected_poly_indices.append_unchecked(i);
@@ -791,8 +792,8 @@ static void compute_selected_mesh_data_from_poly_selection(const Mesh &mesh,
selected_loops_num += poly_src.totloop;
/* Add the vertices and the edges. */
- Span<MLoop> loops_src(&mesh.mloop[poly_src.loopstart], poly_src.totloop);
- for (const MLoop &loop : loops_src) {
+ const Span<MLoop> poly_loops = loops.slice(poly_src.loopstart, poly_src.totloop);
+ for (const MLoop &loop : poly_loops) {
/* Check first if it has not yet been added. */
if (r_vertex_map[loop.v] == -1) {
r_vertex_map[loop.v] = selected_verts_num;
@@ -805,7 +806,7 @@ static void compute_selected_mesh_data_from_poly_selection(const Mesh &mesh,
}
}
}
- *r_selected_vertices_num = selected_verts_num;
+ *r_selected_verts_num = selected_verts_num;
*r_selected_edges_num = selected_edges_num;
*r_selected_polys_num = r_selected_poly_indices.size();
*r_selected_loops_num = selected_loops_num;
@@ -890,30 +891,30 @@ static void do_mesh_separation(GeometrySet &geometry_set,
selected_polys_num);
/* Copy the selected parts of the mesh over to the new mesh. */
- copy_masked_vertices_to_new_mesh(mesh_in, *mesh_out, vertex_map);
+ copy_masked_verts_to_new_mesh(mesh_in, *mesh_out, vertex_map);
copy_masked_edges_to_new_mesh(mesh_in, *mesh_out, vertex_map, edge_map);
copy_masked_polys_to_new_mesh(
mesh_in, *mesh_out, vertex_map, edge_map, selected_poly_indices, new_loop_starts);
/* Copy attributes. */
copy_attributes_based_on_map(attributes,
- bke::mesh_attributes(mesh_in),
- bke::mesh_attributes_for_write(*mesh_out),
+ mesh_in.attributes(),
+ mesh_out->attributes_for_write(),
ATTR_DOMAIN_POINT,
vertex_map);
copy_attributes_based_on_map(attributes,
- bke::mesh_attributes(mesh_in),
- bke::mesh_attributes_for_write(*mesh_out),
+ mesh_in.attributes(),
+ mesh_out->attributes_for_write(),
ATTR_DOMAIN_EDGE,
edge_map);
copy_attributes_based_on_mask(attributes,
- bke::mesh_attributes(mesh_in),
- bke::mesh_attributes_for_write(*mesh_out),
+ mesh_in.attributes(),
+ mesh_out->attributes_for_write(),
ATTR_DOMAIN_FACE,
IndexMask(Vector<int64_t>(selected_poly_indices.as_span())));
copy_face_corner_attributes(attributes,
- bke::mesh_attributes(mesh_in),
- bke::mesh_attributes_for_write(*mesh_out),
+ mesh_in.attributes(),
+ mesh_out->attributes_for_write(),
selected_loops_num,
selected_poly_indices,
mesh_in);
@@ -967,29 +968,27 @@ static void do_mesh_separation(GeometrySet &geometry_set,
selected_polys_num);
/* Copy the selected parts of the mesh over to the new mesh. */
- memcpy(mesh_out->mvert, mesh_in.mvert, mesh_in.totvert * sizeof(MVert));
+ mesh_out->verts_for_write().copy_from(mesh_in.verts());
copy_masked_edges_to_new_mesh(mesh_in, *mesh_out, edge_map);
copy_masked_polys_to_new_mesh(
mesh_in, *mesh_out, edge_map, selected_poly_indices, new_loop_starts);
/* Copy attributes. */
- copy_attributes(attributes,
- bke::mesh_attributes(mesh_in),
- bke::mesh_attributes_for_write(*mesh_out),
- {ATTR_DOMAIN_POINT});
+ copy_attributes(
+ attributes, mesh_in.attributes(), mesh_out->attributes_for_write(), {ATTR_DOMAIN_POINT});
copy_attributes_based_on_map(attributes,
- bke::mesh_attributes(mesh_in),
- bke::mesh_attributes_for_write(*mesh_out),
+ mesh_in.attributes(),
+ mesh_out->attributes_for_write(),
ATTR_DOMAIN_EDGE,
edge_map);
copy_attributes_based_on_mask(attributes,
- bke::mesh_attributes(mesh_in),
- bke::mesh_attributes_for_write(*mesh_out),
+ mesh_in.attributes(),
+ mesh_out->attributes_for_write(),
ATTR_DOMAIN_FACE,
IndexMask(Vector<int64_t>(selected_poly_indices.as_span())));
copy_face_corner_attributes(attributes,
- bke::mesh_attributes(mesh_in),
- bke::mesh_attributes_for_write(*mesh_out),
+ mesh_in.attributes(),
+ mesh_out->attributes_for_write(),
selected_loops_num,
selected_poly_indices,
mesh_in);
@@ -999,28 +998,28 @@ static void do_mesh_separation(GeometrySet &geometry_set,
/* Fill all the maps based on the selection. */
switch (domain) {
case ATTR_DOMAIN_POINT:
- compute_selected_polygons_from_vertex_selection(mesh_in,
- selection,
- selected_poly_indices,
- new_loop_starts,
- &selected_polys_num,
- &selected_loops_num);
+ compute_selected_polys_from_vertex_selection(mesh_in,
+ selection,
+ selected_poly_indices,
+ new_loop_starts,
+ &selected_polys_num,
+ &selected_loops_num);
break;
case ATTR_DOMAIN_EDGE:
- compute_selected_polygons_from_edge_selection(mesh_in,
- selection,
- selected_poly_indices,
- new_loop_starts,
- &selected_polys_num,
- &selected_loops_num);
+ compute_selected_polys_from_edge_selection(mesh_in,
+ selection,
+ selected_poly_indices,
+ new_loop_starts,
+ &selected_polys_num,
+ &selected_loops_num);
break;
case ATTR_DOMAIN_FACE:
- compute_selected_polygons_from_poly_selection(mesh_in,
- selection,
- selected_poly_indices,
- new_loop_starts,
- &selected_polys_num,
- &selected_loops_num);
+ compute_selected_polys_from_poly_selection(mesh_in,
+ selection,
+ selected_poly_indices,
+ new_loop_starts,
+ &selected_polys_num,
+ &selected_loops_num);
break;
default:
BLI_assert_unreachable();
@@ -1030,23 +1029,23 @@ static void do_mesh_separation(GeometrySet &geometry_set,
&mesh_in, mesh_in.totvert, mesh_in.totedge, 0, selected_loops_num, selected_polys_num);
/* Copy the selected parts of the mesh over to the new mesh. */
- memcpy(mesh_out->mvert, mesh_in.mvert, mesh_in.totvert * sizeof(MVert));
- memcpy(mesh_out->medge, mesh_in.medge, mesh_in.totedge * sizeof(MEdge));
+ mesh_out->verts_for_write().copy_from(mesh_in.verts());
+ mesh_out->edges_for_write().copy_from(mesh_in.edges());
copy_masked_polys_to_new_mesh(mesh_in, *mesh_out, selected_poly_indices, new_loop_starts);
/* Copy attributes. */
copy_attributes(attributes,
- bke::mesh_attributes(mesh_in),
- bke::mesh_attributes_for_write(*mesh_out),
+ mesh_in.attributes(),
+ mesh_out->attributes_for_write(),
{ATTR_DOMAIN_POINT, ATTR_DOMAIN_EDGE});
copy_attributes_based_on_mask(attributes,
- bke::mesh_attributes(mesh_in),
- bke::mesh_attributes_for_write(*mesh_out),
+ mesh_in.attributes(),
+ mesh_out->attributes_for_write(),
ATTR_DOMAIN_FACE,
IndexMask(Vector<int64_t>(selected_poly_indices.as_span())));
copy_face_corner_attributes(attributes,
- bke::mesh_attributes(mesh_in),
- bke::mesh_attributes_for_write(*mesh_out),
+ mesh_in.attributes(),
+ mesh_out->attributes_for_write(),
selected_loops_num,
selected_poly_indices,
mesh_in);
@@ -1063,11 +1062,9 @@ static void separate_mesh_selection(GeometrySet &geometry_set,
const eAttrDomain selection_domain,
const GeometryNodeDeleteGeometryMode mode)
{
- const MeshComponent &src_component = *geometry_set.get_component_for_read<MeshComponent>();
- GeometryComponentFieldContext field_context{src_component, selection_domain};
-
- fn::FieldEvaluator evaluator{field_context,
- src_component.attribute_domain_size(selection_domain)};
+ const Mesh &src_mesh = *geometry_set.get_mesh_for_read();
+ bke::MeshFieldContext field_context{src_mesh, selection_domain};
+ fn::FieldEvaluator evaluator{field_context, src_mesh.attributes().domain_size(selection_domain)};
evaluator.add(selection_field);
evaluator.evaluate();
const VArray<bool> selection = evaluator.get_evaluated<bool>(0);
@@ -1078,8 +1075,7 @@ static void separate_mesh_selection(GeometrySet &geometry_set,
const VArraySpan<bool> selection_span{selection};
- do_mesh_separation(
- geometry_set, *src_component.get_for_read(), selection_span, selection_domain, mode);
+ do_mesh_separation(geometry_set, src_mesh, selection_span, selection_domain, mode);
}
} // namespace blender::nodes::node_geo_delete_geometry_cc
@@ -1140,11 +1136,11 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Geometry"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
const bNode *node = static_cast<bNode *>(ptr->data);
const NodeGeometryDeleteGeometry &storage = node_storage(*node);
- const eAttrDomain domain = static_cast<eAttrDomain>(storage.domain);
+ const eAttrDomain domain = eAttrDomain(storage.domain);
uiItemR(layout, ptr, "domain", 0, "", ICON_NONE);
/* Only show the mode when it is relevant. */
@@ -1153,7 +1149,7 @@ static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
}
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryDeleteGeometry *data = MEM_cnew<NodeGeometryDeleteGeometry>(__func__);
data->domain = ATTR_DOMAIN_POINT;
@@ -1173,7 +1169,7 @@ static void node_geo_exec(GeoNodeExecParams params)
params.extract_input<Field<bool>>("Selection"));
const NodeGeometryDeleteGeometry &storage = node_storage(params.node());
- const eAttrDomain domain = static_cast<eAttrDomain>(storage.domain);
+ const eAttrDomain domain = eAttrDomain(storage.domain);
const GeometryNodeDeleteGeometryMode mode = (GeometryNodeDeleteGeometryMode)storage.mode;
if (domain == ATTR_DOMAIN_INSTANCE) {
diff --git a/source/blender/nodes/geometry/nodes/node_geo_distribute_points_in_volume.cc b/source/blender/nodes/geometry/nodes/node_geo_distribute_points_in_volume.cc
new file mode 100644
index 00000000000..95173bd23a5
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_distribute_points_in_volume.cc
@@ -0,0 +1,288 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifdef WITH_OPENVDB
+# include <openvdb/openvdb.h>
+# include <openvdb/tools/Interpolation.h>
+# include <openvdb/tools/PointScatter.h>
+#endif
+
+#include "DNA_node_types.h"
+#include "DNA_pointcloud_types.h"
+
+#include "BKE_pointcloud.h"
+#include "BKE_volume.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "DEG_depsgraph_query.h"
+
+#include "node_geometry_util.hh"
+
+namespace blender::nodes {
+
+NODE_STORAGE_FUNCS(NodeGeometryDistributePointsInVolume)
+
+static void geo_node_distribute_points_in_volume_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::Geometry>(N_("Volume")).supported_type(GEO_COMPONENT_TYPE_VOLUME);
+ b.add_input<decl::Float>(N_("Density"))
+ .default_value(1.0f)
+ .min(0.0f)
+ .max(100000.0f)
+ .subtype(PROP_NONE)
+ .description(N_("Number of points to sample per unit volume"));
+ b.add_input<decl::Int>(N_("Seed"))
+ .min(-10000)
+ .max(10000)
+ .description(N_("Seed used by the random number generator to generate random points"));
+ b.add_input<decl::Vector>(N_("Spacing"))
+ .default_value({0.3, 0.3, 0.3})
+ .min(0.0001f)
+ .subtype(PROP_XYZ)
+ .description(N_("Spacing between grid points"));
+ b.add_input<decl::Float>(N_("Threshold"))
+ .default_value(0.1f)
+ .min(0.0f)
+ .max(FLT_MAX)
+ .description(N_("Minimum density of a volume cell to contain a grid point"));
+ b.add_output<decl::Geometry>(N_("Points"));
+}
+
+static void geo_node_distribute_points_in_volume_layout(uiLayout *layout,
+ bContext * /*C*/,
+ PointerRNA *ptr)
+{
+ uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
+}
+
+static void node_distribute_points_in_volume_init(bNodeTree * /*tree*/, bNode *node)
+{
+ NodeGeometryDistributePointsInVolume *data = MEM_cnew<NodeGeometryDistributePointsInVolume>(
+ __func__);
+ data->mode = GEO_NODE_DISTRIBUTE_POINTS_IN_VOLUME_DENSITY_RANDOM;
+ node->storage = data;
+}
+
+static void node_distribute_points_in_volume_update(bNodeTree *ntree, bNode *node)
+{
+ const NodeGeometryDistributePointsInVolume &storage = node_storage(*node);
+ GeometryNodeDistributePointsInVolumeMode mode = GeometryNodeDistributePointsInVolumeMode(
+ storage.mode);
+
+ bNodeSocket *sock_density = static_cast<bNodeSocket *>(node->inputs.first)->next;
+ bNodeSocket *sock_seed = sock_density->next;
+ bNodeSocket *sock_spacing = sock_seed->next;
+ bNodeSocket *sock_threshold = sock_spacing->next;
+
+ nodeSetSocketAvailability(
+ ntree, sock_density, mode == GEO_NODE_DISTRIBUTE_POINTS_IN_VOLUME_DENSITY_RANDOM);
+ nodeSetSocketAvailability(
+ ntree, sock_seed, mode == GEO_NODE_DISTRIBUTE_POINTS_IN_VOLUME_DENSITY_RANDOM);
+ nodeSetSocketAvailability(
+ ntree, sock_spacing, mode == GEO_NODE_DISTRIBUTE_POINTS_IN_VOLUME_DENSITY_GRID);
+ nodeSetSocketAvailability(
+ ntree, sock_threshold, mode == GEO_NODE_DISTRIBUTE_POINTS_IN_VOLUME_DENSITY_GRID);
+}
+
+#ifdef WITH_OPENVDB
+/* Implements the interface required by #openvdb::tools::NonUniformPointScatter. */
+class PositionsVDBWrapper {
+ private:
+ float3 offset_fix_;
+ Vector<float3> &vector_;
+
+ public:
+ PositionsVDBWrapper(Vector<float3> &vector, const float3 offset_fix)
+ : offset_fix_(offset_fix), vector_(vector)
+ {
+ }
+ PositionsVDBWrapper(const PositionsVDBWrapper &wrapper) = default;
+
+ void add(const openvdb::Vec3R &pos)
+ {
+ vector_.append(float3(float(pos[0]), float(pos[1]), float(pos[2])) + offset_fix_);
+ }
+};
+
+/* Use #std::mt19937 as a random number generator,
+ * it has a very long period and thus there should be no visible patterns in the generated points.
+ */
+using RNGType = std::mt19937;
+/* Non-uniform scatter allows the amount of points to be scaled with the volume's density. */
+using NonUniformPointScatterVDB =
+ openvdb::tools::NonUniformPointScatter<PositionsVDBWrapper, RNGType>;
+
+static void point_scatter_density_random(const openvdb::FloatGrid &grid,
+ const float density,
+ const int seed,
+ Vector<float3> &r_positions)
+{
+ /* Offset points by half a voxel so that grid points are aligned with world grid points. */
+ const float3 offset_fix = {0.5f * float(grid.voxelSize().x()),
+ 0.5f * float(grid.voxelSize().y()),
+ 0.5f * float(grid.voxelSize().z())};
+ /* Setup and call into OpenVDB's point scatter API. */
+ PositionsVDBWrapper vdb_position_wrapper = PositionsVDBWrapper(r_positions, offset_fix);
+ RNGType random_generator(seed);
+ NonUniformPointScatterVDB point_scatter(vdb_position_wrapper, density, random_generator);
+ point_scatter(grid);
+}
+
+static void point_scatter_density_grid(const openvdb::FloatGrid &grid,
+ const float3 spacing,
+ const float threshold,
+ Vector<float3> &r_positions)
+{
+ const openvdb::Vec3d half_voxel(0.5, 0.5, 0.5);
+ const openvdb::Vec3d voxel_spacing(double(spacing.x) / grid.voxelSize().x(),
+ double(spacing.y) / grid.voxelSize().y(),
+ double(spacing.z) / grid.voxelSize().z());
+
+ /* Abort if spacing is zero. */
+ const double min_spacing = std::min(voxel_spacing.x(),
+ std::min(voxel_spacing.y(), voxel_spacing.z()));
+ if (std::abs(min_spacing) < 0.0001) {
+ return;
+ }
+
+ /* Iterate through tiles and voxels on the grid. */
+ for (openvdb::FloatGrid::ValueOnCIter cell = grid.cbeginValueOn(); cell; ++cell) {
+ /* Check if the cell's value meets the minimum threshold. */
+ if (cell.getValue() < threshold) {
+ continue;
+ }
+ /* Compute the bounding box of each tile/voxel. */
+ const openvdb::CoordBBox bbox = cell.getBoundingBox();
+ const openvdb::Vec3d box_min = bbox.min().asVec3d() - half_voxel;
+ const openvdb::Vec3d box_max = bbox.max().asVec3d() + half_voxel;
+
+ /* Pick a starting point rounded up to the nearest possible point. */
+ double abs_spacing_x = std::abs(voxel_spacing.x());
+ double abs_spacing_y = std::abs(voxel_spacing.y());
+ double abs_spacing_z = std::abs(voxel_spacing.z());
+ const openvdb::Vec3d start(ceil(box_min.x() / abs_spacing_x) * abs_spacing_x,
+ ceil(box_min.y() / abs_spacing_y) * abs_spacing_y,
+ ceil(box_min.z() / abs_spacing_z) * abs_spacing_z);
+
+ /* Iterate through all possible points in box. */
+ for (double x = start.x(); x < box_max.x(); x += abs_spacing_x) {
+ for (double y = start.y(); y < box_max.y(); y += abs_spacing_y) {
+ for (double z = start.z(); z < box_max.z(); z += abs_spacing_z) {
+ /* Transform with grid matrix and add point. */
+ const openvdb::Vec3d idx_pos(x, y, z);
+ const openvdb::Vec3d local_pos = grid.indexToWorld(idx_pos + half_voxel);
+ r_positions.append({float(local_pos.x()), float(local_pos.y()), float(local_pos.z())});
+ }
+ }
+ }
+ }
+}
+
+#endif /* WITH_OPENVDB */
+
+static void geo_node_distribute_points_in_volume_exec(GeoNodeExecParams params)
+{
+#ifdef WITH_OPENVDB
+ GeometrySet geometry_set = params.extract_input<GeometrySet>("Volume");
+
+ const NodeGeometryDistributePointsInVolume &storage = node_storage(params.node());
+ const GeometryNodeDistributePointsInVolumeMode mode = GeometryNodeDistributePointsInVolumeMode(
+ storage.mode);
+
+ float density;
+ int seed;
+ float3 spacing{0, 0, 0};
+ float threshold;
+ if (mode == GEO_NODE_DISTRIBUTE_POINTS_IN_VOLUME_DENSITY_RANDOM) {
+ density = params.extract_input<float>("Density");
+ seed = params.extract_input<int>("Seed");
+ }
+ else if (mode == GEO_NODE_DISTRIBUTE_POINTS_IN_VOLUME_DENSITY_GRID) {
+ spacing = params.extract_input<float3>("Spacing");
+ threshold = params.extract_input<float>("Threshold");
+ }
+
+ geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
+ if (!geometry_set.has_volume()) {
+ geometry_set.keep_only({GEO_COMPONENT_TYPE_POINT_CLOUD, GEO_COMPONENT_TYPE_INSTANCES});
+ return;
+ }
+ const VolumeComponent *component = geometry_set.get_component_for_read<VolumeComponent>();
+ const Volume *volume = component->get_for_read();
+ BKE_volume_load(volume, DEG_get_bmain(params.depsgraph()));
+
+ Vector<float3> positions;
+
+ for (const int i : IndexRange(BKE_volume_num_grids(volume))) {
+ const VolumeGrid *volume_grid = BKE_volume_grid_get_for_read(volume, i);
+ if (volume_grid == nullptr) {
+ continue;
+ }
+
+ openvdb::GridBase::ConstPtr base_grid = BKE_volume_grid_openvdb_for_read(volume,
+ volume_grid);
+ if (!base_grid) {
+ continue;
+ }
+
+ if (!base_grid->isType<openvdb::FloatGrid>()) {
+ continue;
+ }
+
+ const openvdb::FloatGrid::ConstPtr grid = openvdb::gridConstPtrCast<openvdb::FloatGrid>(
+ base_grid);
+
+ if (mode == GEO_NODE_DISTRIBUTE_POINTS_IN_VOLUME_DENSITY_RANDOM) {
+ point_scatter_density_random(*grid, density, seed, positions);
+ }
+ else if (mode == GEO_NODE_DISTRIBUTE_POINTS_IN_VOLUME_DENSITY_GRID) {
+ point_scatter_density_grid(*grid, spacing, threshold, positions);
+ }
+ }
+
+ PointCloud *pointcloud = BKE_pointcloud_new_nomain(positions.size());
+ bke::MutableAttributeAccessor point_attributes = pointcloud->attributes_for_write();
+ bke::SpanAttributeWriter<float3> point_positions =
+ point_attributes.lookup_or_add_for_write_only_span<float3>("position", ATTR_DOMAIN_POINT);
+ bke::SpanAttributeWriter<float> point_radii =
+ point_attributes.lookup_or_add_for_write_only_span<float>("radius", ATTR_DOMAIN_POINT);
+
+ point_positions.span.copy_from(positions);
+ point_radii.span.fill(0.05f);
+ point_positions.finish();
+ point_radii.finish();
+
+ geometry_set.replace_pointcloud(pointcloud);
+ geometry_set.keep_only_during_modify({GEO_COMPONENT_TYPE_POINT_CLOUD});
+ });
+
+ params.set_output("Points", std::move(geometry_set));
+
+#else
+ params.set_default_remaining_outputs();
+ params.error_message_add(NodeWarningType::Error,
+ TIP_("Disabled, Blender was compiled without OpenVDB"));
+#endif
+}
+} // namespace blender::nodes
+
+void register_node_type_geo_distribute_points_in_volume()
+{
+ static bNodeType ntype;
+ geo_node_type_base(&ntype,
+ GEO_NODE_DISTRIBUTE_POINTS_IN_VOLUME,
+ "Distribute Points in Volume",
+ NODE_CLASS_GEOMETRY);
+ node_type_storage(&ntype,
+ "NodeGeometryDistributePointsInVolume",
+ node_free_standard_storage,
+ node_copy_standard_storage);
+ node_type_init(&ntype, blender::nodes::node_distribute_points_in_volume_init);
+ node_type_update(&ntype, blender::nodes::node_distribute_points_in_volume_update);
+ node_type_size(&ntype, 170, 100, 320);
+ ntype.declare = blender::nodes::geo_node_distribute_points_in_volume_declare;
+ ntype.geometry_node_execute = blender::nodes::geo_node_distribute_points_in_volume_exec;
+ ntype.draw_buttons = blender::nodes::geo_node_distribute_points_in_volume_layout;
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc b/source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc
index cfb9cbf7e24..c2cc70296ed 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc
@@ -62,15 +62,15 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Vector>(N_("Rotation")).subtype(PROP_EULER).field_source();
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "distribute_method", 0, "", ICON_NONE);
}
static void node_point_distribute_points_on_faces_update(bNodeTree *ntree, bNode *node)
{
- bNodeSocket *sock_distance_min = (bNodeSocket *)BLI_findlink(&node->inputs, 2);
- bNodeSocket *sock_density_max = (bNodeSocket *)sock_distance_min->next;
+ bNodeSocket *sock_distance_min = static_cast<bNodeSocket *>(BLI_findlink(&node->inputs, 2));
+ bNodeSocket *sock_density_max = static_cast<bNodeSocket *>(sock_distance_min->next);
bNodeSocket *sock_density = sock_density_max->next;
bNodeSocket *sock_density_factor = sock_density->next;
nodeSetSocketAvailability(ntree,
@@ -105,20 +105,21 @@ static void sample_mesh_surface(const Mesh &mesh,
Vector<float3> &r_bary_coords,
Vector<int> &r_looptri_indices)
{
- const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
- BKE_mesh_runtime_looptri_len(&mesh)};
+ const Span<MVert> verts = mesh.verts();
+ const Span<MLoop> loops = mesh.loops();
+ const Span<MLoopTri> looptris = mesh.looptris();
for (const int looptri_index : looptris.index_range()) {
const MLoopTri &looptri = looptris[looptri_index];
const int v0_loop = looptri.tri[0];
const int v1_loop = looptri.tri[1];
const int v2_loop = looptri.tri[2];
- const int v0_index = mesh.mloop[v0_loop].v;
- const int v1_index = mesh.mloop[v1_loop].v;
- const int v2_index = mesh.mloop[v2_loop].v;
- const float3 v0_pos = float3(mesh.mvert[v0_index].co);
- const float3 v1_pos = float3(mesh.mvert[v1_index].co);
- const float3 v2_pos = float3(mesh.mvert[v2_index].co);
+ const int v0_index = loops[v0_loop].v;
+ const int v1_index = loops[v1_loop].v;
+ const int v2_index = loops[v2_loop].v;
+ const float3 v0_pos = verts[v0_index].co;
+ const float3 v1_pos = verts[v1_index].co;
+ const float3 v2_pos = verts[v2_index].co;
float looptri_density_factor = 1.0f;
if (!density_factors.is_empty()) {
@@ -184,7 +185,7 @@ BLI_NOINLINE static void update_elimination_mask_for_close_points(
kdtree,
positions[i],
minimum_distance,
- [](void *user_data, int index, const float *UNUSED(co), float UNUSED(dist_sq)) {
+ [](void *user_data, int index, const float * /*co*/, float /*dist_sq*/) {
CallbackData &callback_data = *static_cast<CallbackData *>(user_data);
if (index != callback_data.index) {
callback_data.elimination_mask[index] = true;
@@ -202,8 +203,7 @@ BLI_NOINLINE static void update_elimination_mask_based_on_density_factors(
const Span<int> looptri_indices,
const MutableSpan<bool> elimination_mask)
{
- const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
- BKE_mesh_runtime_looptri_len(&mesh)};
+ const Span<MLoopTri> looptris = mesh.looptris();
for (const int i : bary_coords.index_range()) {
if (elimination_mask[i]) {
continue;
@@ -220,11 +220,11 @@ BLI_NOINLINE static void update_elimination_mask_based_on_density_factors(
const float v1_density_factor = std::max(0.0f, density_factors[v1_loop]);
const float v2_density_factor = std::max(0.0f, density_factors[v2_loop]);
- const float probablity = v0_density_factor * bary_coord.x + v1_density_factor * bary_coord.y +
- v2_density_factor * bary_coord.z;
+ const float probability = v0_density_factor * bary_coord.x + v1_density_factor * bary_coord.y +
+ v2_density_factor * bary_coord.z;
const float hash = noise::hash_float_to_float(bary_coord);
- if (hash > probablity) {
+ if (hash > probability) {
elimination_mask[i] = true;
}
}
@@ -283,15 +283,14 @@ BLI_NOINLINE static void interpolate_attribute(const Mesh &mesh,
}
BLI_NOINLINE static void propagate_existing_attributes(
- const MeshComponent &mesh_component,
+ const Mesh &mesh,
const Map<AttributeIDRef, AttributeKind> &attributes,
- GeometryComponent &point_component,
+ PointCloud &points,
const Span<float3> bary_coords,
const Span<int> looptri_indices)
{
- const Mesh &mesh = *mesh_component.get_for_read();
- const AttributeAccessor mesh_attributes = *mesh_component.attributes();
- MutableAttributeAccessor point_attributes = *point_component.attributes_for_write();
+ const AttributeAccessor mesh_attributes = mesh.attributes();
+ MutableAttributeAccessor point_attributes = points.attributes_for_write();
for (Map<AttributeIDRef, AttributeKind>::Item entry : attributes.items()) {
const AttributeIDRef attribute_id = entry.key;
@@ -326,44 +325,44 @@ struct AttributeOutputs {
};
} // namespace
-BLI_NOINLINE static void compute_attribute_outputs(const MeshComponent &mesh_component,
- PointCloudComponent &point_component,
+BLI_NOINLINE static void compute_attribute_outputs(const Mesh &mesh,
+ PointCloud &points,
const Span<float3> bary_coords,
const Span<int> looptri_indices,
const AttributeOutputs &attribute_outputs)
{
- MutableAttributeAccessor pointcloud_attributes = *point_component.attributes_for_write();
+ MutableAttributeAccessor point_attributes = points.attributes_for_write();
- SpanAttributeWriter<int> ids = pointcloud_attributes.lookup_or_add_for_write_only_span<int>(
+ SpanAttributeWriter<int> ids = point_attributes.lookup_or_add_for_write_only_span<int>(
"id", ATTR_DOMAIN_POINT);
SpanAttributeWriter<float3> normals;
SpanAttributeWriter<float3> rotations;
if (attribute_outputs.normal_id) {
- normals = pointcloud_attributes.lookup_or_add_for_write_only_span<float3>(
+ normals = point_attributes.lookup_or_add_for_write_only_span<float3>(
attribute_outputs.normal_id.get(), ATTR_DOMAIN_POINT);
}
if (attribute_outputs.rotation_id) {
- rotations = pointcloud_attributes.lookup_or_add_for_write_only_span<float3>(
+ rotations = point_attributes.lookup_or_add_for_write_only_span<float3>(
attribute_outputs.rotation_id.get(), ATTR_DOMAIN_POINT);
}
- const Mesh &mesh = *mesh_component.get_for_read();
- const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
- BKE_mesh_runtime_looptri_len(&mesh)};
+ const Span<MVert> verts = mesh.verts();
+ const Span<MLoop> loops = mesh.loops();
+ const Span<MLoopTri> looptris = mesh.looptris();
for (const int i : bary_coords.index_range()) {
const int looptri_index = looptri_indices[i];
const MLoopTri &looptri = looptris[looptri_index];
const float3 &bary_coord = bary_coords[i];
- const int v0_index = mesh.mloop[looptri.tri[0]].v;
- const int v1_index = mesh.mloop[looptri.tri[1]].v;
- const int v2_index = mesh.mloop[looptri.tri[2]].v;
- const float3 v0_pos = float3(mesh.mvert[v0_index].co);
- const float3 v1_pos = float3(mesh.mvert[v1_index].co);
- const float3 v2_pos = float3(mesh.mvert[v2_index].co);
+ const int v0_index = loops[looptri.tri[0]].v;
+ const int v1_index = loops[looptri.tri[1]].v;
+ const int v2_index = loops[looptri.tri[2]].v;
+ const float3 v0_pos = verts[v0_index].co;
+ const float3 v1_pos = verts[v1_index].co;
+ const float3 v2_pos = verts[v2_index].co;
ids.span[i] = noise::hash(noise::hash_float(bary_coord), looptri_index);
@@ -380,25 +379,19 @@ BLI_NOINLINE static void compute_attribute_outputs(const MeshComponent &mesh_com
}
ids.finish();
-
- if (normals) {
- normals.finish();
- }
- if (rotations) {
- rotations.finish();
- }
+ normals.finish();
+ rotations.finish();
}
-static Array<float> calc_full_density_factors_with_selection(const MeshComponent &component,
+static Array<float> calc_full_density_factors_with_selection(const Mesh &mesh,
const Field<float> &density_field,
const Field<bool> &selection_field)
{
- const eAttrDomain attribute_domain = ATTR_DOMAIN_CORNER;
- GeometryComponentFieldContext field_context{component, attribute_domain};
- const int domain_size = component.attribute_domain_size(attribute_domain);
-
+ const eAttrDomain domain = ATTR_DOMAIN_CORNER;
+ const int domain_size = mesh.attributes().domain_size(domain);
Array<float> densities(domain_size, 0.0f);
+ bke::MeshFieldContext field_context{mesh, domain};
fn::FieldEvaluator evaluator{field_context, domain_size};
evaluator.set_selection(selection_field);
evaluator.add_with_destination(density_field, densities.as_mutable_span());
@@ -406,7 +399,7 @@ static Array<float> calc_full_density_factors_with_selection(const MeshComponent
return densities;
}
-static void distribute_points_random(const MeshComponent &component,
+static void distribute_points_random(const Mesh &mesh,
const Field<float> &density_field,
const Field<bool> &selection_field,
const int seed,
@@ -415,12 +408,11 @@ static void distribute_points_random(const MeshComponent &component,
Vector<int> &looptri_indices)
{
const Array<float> densities = calc_full_density_factors_with_selection(
- component, density_field, selection_field);
- const Mesh &mesh = *component.get_for_read();
+ mesh, density_field, selection_field);
sample_mesh_surface(mesh, 1.0f, densities, seed, positions, bary_coords, looptri_indices);
}
-static void distribute_points_poisson_disk(const MeshComponent &mesh_component,
+static void distribute_points_poisson_disk(const Mesh &mesh,
const float minimum_distance,
const float max_density,
const Field<float> &density_factor_field,
@@ -430,14 +422,13 @@ static void distribute_points_poisson_disk(const MeshComponent &mesh_component,
Vector<float3> &bary_coords,
Vector<int> &looptri_indices)
{
- const Mesh &mesh = *mesh_component.get_for_read();
sample_mesh_surface(mesh, max_density, {}, seed, positions, bary_coords, looptri_indices);
Array<bool> elimination_mask(positions.size(), false);
update_elimination_mask_for_close_points(positions, minimum_distance, elimination_mask);
const Array<float> density_factors = calc_full_density_factors_with_selection(
- mesh_component, density_factor_field, selection_field);
+ mesh, density_factor_field, selection_field);
update_elimination_mask_based_on_density_factors(
mesh, density_factors, bary_coords, looptri_indices, elimination_mask.as_mutable_span());
@@ -457,7 +448,7 @@ static void point_distribution_calculate(GeometrySet &geometry_set,
return;
}
- const MeshComponent &mesh_component = *geometry_set.get_component_for_read<MeshComponent>();
+ const Mesh &mesh = *geometry_set.get_mesh_for_read();
Vector<float3> positions;
Vector<float3> bary_coords;
@@ -466,20 +457,15 @@ static void point_distribution_calculate(GeometrySet &geometry_set,
switch (method) {
case GEO_NODE_POINT_DISTRIBUTE_POINTS_ON_FACES_RANDOM: {
const Field<float> density_field = params.get_input<Field<float>>("Density");
- distribute_points_random(mesh_component,
- density_field,
- selection_field,
- seed,
- positions,
- bary_coords,
- looptri_indices);
+ distribute_points_random(
+ mesh, density_field, selection_field, seed, positions, bary_coords, looptri_indices);
break;
}
case GEO_NODE_POINT_DISTRIBUTE_POINTS_ON_FACES_POISSON: {
const float minimum_distance = params.get_input<float>("Distance Min");
const float density_max = params.get_input<float>("Density Max");
const Field<float> density_factors_field = params.get_input<Field<float>>("Density Factor");
- distribute_points_poisson_disk(mesh_component,
+ distribute_points_poisson_disk(mesh,
minimum_distance,
density_max,
density_factors_field,
@@ -497,8 +483,7 @@ static void point_distribution_calculate(GeometrySet &geometry_set,
}
PointCloud *pointcloud = BKE_pointcloud_new_nomain(positions.size());
- bke::MutableAttributeAccessor point_attributes = bke::pointcloud_attributes_for_write(
- *pointcloud);
+ bke::MutableAttributeAccessor point_attributes = pointcloud->attributes_for_write();
bke::SpanAttributeWriter<float3> point_positions =
point_attributes.lookup_or_add_for_write_only_span<float3>("position", ATTR_DOMAIN_POINT);
bke::SpanAttributeWriter<float> point_radii =
@@ -510,9 +495,6 @@ static void point_distribution_calculate(GeometrySet &geometry_set,
geometry_set.replace_pointcloud(pointcloud);
- PointCloudComponent &point_component =
- geometry_set.get_component_for_write<PointCloudComponent>();
-
Map<AttributeIDRef, AttributeKind> attributes;
geometry_set.gather_attributes_for_propagation(
{GEO_COMPONENT_TYPE_MESH}, GEO_COMPONENT_TYPE_POINT_CLOUD, false, attributes);
@@ -520,19 +502,17 @@ static void point_distribution_calculate(GeometrySet &geometry_set,
/* Position is set separately. */
attributes.remove("position");
- propagate_existing_attributes(
- mesh_component, attributes, point_component, bary_coords, looptri_indices);
+ propagate_existing_attributes(mesh, attributes, *pointcloud, bary_coords, looptri_indices);
- compute_attribute_outputs(
- mesh_component, point_component, bary_coords, looptri_indices, attribute_outputs);
+ compute_attribute_outputs(mesh, *pointcloud, bary_coords, looptri_indices, attribute_outputs);
}
static void node_geo_exec(GeoNodeExecParams params)
{
GeometrySet geometry_set = params.extract_input<GeometrySet>("Mesh");
- const GeometryNodeDistributePointsOnFacesMode method =
- static_cast<GeometryNodeDistributePointsOnFacesMode>(params.node().custom1);
+ const GeometryNodeDistributePointsOnFacesMode method = GeometryNodeDistributePointsOnFacesMode(
+ params.node().custom1);
const int seed = params.get_input<int>("Seed") * 5383843;
const Field<bool> selection_field = params.extract_input<Field<bool>>("Selection");
@@ -545,6 +525,8 @@ static void node_geo_exec(GeoNodeExecParams params)
attribute_outputs.rotation_id = StrongAnonymousAttributeID("Rotation");
}
+ lazy_threading::send_hint();
+
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
point_distribution_calculate(
geometry_set, selection_field, method, seed, attribute_outputs, params);
diff --git a/source/blender/nodes/geometry/nodes/node_geo_dual_mesh.cc b/source/blender/nodes/geometry/nodes/node_geo_dual_mesh.cc
index 76eeee95239..9b1c13bf563 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_dual_mesh.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_dual_mesh.cc
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "BLI_array_utils.hh"
#include "BLI_task.hh"
#include "DNA_mesh_types.h"
@@ -105,18 +106,6 @@ static void copy_data_based_on_pairs(Span<T> data,
}
}
-/* Copy using the map. */
-template<typename T>
-static void copy_data_based_on_new_to_old_map(Span<T> data,
- MutableSpan<T> r_data,
- const Span<int> new_to_old_map)
-{
- for (const int i : r_data.index_range()) {
- const int old_i = new_to_old_map[i];
- r_data[i] = data[old_i];
- }
-}
-
/**
* Transfers the attributes from the original mesh to the new mesh using the following logic:
* - If the attribute was on the face domain it is now on the point domain, and this is true
@@ -168,7 +157,6 @@ static void transfer_attributes(
src_attribute.varray.type());
GSpanAttributeWriter dst_attribute = dst_attributes.lookup_or_add_for_write_only_span(
attribute_id, out_domain, data_type);
-
if (!dst_attribute) {
continue;
}
@@ -177,20 +165,24 @@ static void transfer_attributes(
using T = decltype(dummy);
VArraySpan<T> span{src_attribute.varray.typed<T>()};
MutableSpan<T> dst_span = dst_attribute.span.typed<T>();
- if (src_attribute.domain == ATTR_DOMAIN_FACE) {
- dst_span.take_front(span.size()).copy_from(span);
- if (keep_boundaries) {
- copy_data_based_on_pairs(span, dst_span, boundary_vertex_to_relevant_face_map);
- }
- }
- else if (src_attribute.domain == ATTR_DOMAIN_POINT) {
- copy_data_based_on_vertex_types(span, dst_span, vertex_types, keep_boundaries);
- }
- else if (src_attribute.domain == ATTR_DOMAIN_EDGE) {
- copy_data_based_on_new_to_old_map(span, dst_span, new_to_old_edges_map);
- }
- else {
- copy_data_based_on_new_to_old_map(span, dst_span, new_to_old_face_corners_map);
+ switch (src_attribute.domain) {
+ case ATTR_DOMAIN_POINT:
+ copy_data_based_on_vertex_types(span, dst_span, vertex_types, keep_boundaries);
+ break;
+ case ATTR_DOMAIN_EDGE:
+ array_utils::gather(span, new_to_old_edges_map, dst_span);
+ break;
+ case ATTR_DOMAIN_FACE:
+ dst_span.take_front(span.size()).copy_from(span);
+ if (keep_boundaries) {
+ copy_data_based_on_pairs(span, dst_span, boundary_vertex_to_relevant_face_map);
+ }
+ break;
+ case ATTR_DOMAIN_CORNER:
+ array_utils::gather(span, new_to_old_face_corners_map, dst_span);
+ break;
+ default:
+ BLI_assert_unreachable();
}
});
dst_attribute.finish();
@@ -209,13 +201,18 @@ static void calc_boundaries(const Mesh &mesh,
{
BLI_assert(r_vertex_types.size() == mesh.totvert);
BLI_assert(r_edge_types.size() == mesh.totedge);
+ const Span<MEdge> edges = mesh.edges();
+ const Span<MPoly> polys = mesh.polys();
+ const Span<MLoop> loops = mesh.loops();
+
r_vertex_types.fill(VertexType::Loose);
r_edge_types.fill(EdgeType::Loose);
/* Add up the number of polys connected to each edge. */
for (const int i : IndexRange(mesh.totpoly)) {
- const MPoly &poly = mesh.mpoly[i];
- for (const MLoop &loop : Span<MLoop>(&mesh.mloop[poly.loopstart], poly.totloop)) {
+ const MPoly &poly = polys[i];
+ const Span<MLoop> poly_loops = loops.slice(poly.loopstart, poly.totloop);
+ for (const MLoop &loop : poly_loops) {
r_edge_types[loop.e] = get_edge_type_with_added_neighbor(r_edge_types[loop.e]);
}
}
@@ -226,7 +223,7 @@ static void calc_boundaries(const Mesh &mesh,
if (edge_type == EdgeType::Loose) {
continue;
}
- const MEdge &edge = mesh.medge[i];
+ const MEdge &edge = edges[i];
if (edge_type == EdgeType::Boundary) {
r_vertex_types[edge.v1] = get_vertex_type_with_added_neighbor(r_vertex_types[edge.v1]);
r_vertex_types[edge.v2] = get_vertex_type_with_added_neighbor(r_vertex_types[edge.v2]);
@@ -241,7 +238,7 @@ static void calc_boundaries(const Mesh &mesh,
for (const int i : IndexRange(mesh.totedge)) {
const EdgeType edge_type = r_edge_types[i];
if (edge_type == EdgeType::Normal) {
- const MEdge &edge = mesh.medge[i];
+ const MEdge &edge = edges[i];
if (r_vertex_types[edge.v1] == VertexType::Loose) {
r_vertex_types[edge.v1] = VertexType::Normal;
}
@@ -258,9 +255,12 @@ static void calc_boundaries(const Mesh &mesh,
static void create_vertex_poly_map(const Mesh &mesh,
MutableSpan<Vector<int>> r_vertex_poly_indices)
{
- for (const int i : IndexRange(mesh.totpoly)) {
- const MPoly &poly = mesh.mpoly[i];
- for (const MLoop &loop : Span<MLoop>(&mesh.mloop[poly.loopstart], poly.totloop)) {
+ const Span<MPoly> polys = mesh.polys();
+ const Span<MLoop> loops = mesh.loops();
+ for (const int i : polys.index_range()) {
+ const MPoly &poly = polys[i];
+ const Span<MLoop> poly_loops = loops.slice(poly.loopstart, poly.totloop);
+ for (const MLoop &loop : poly_loops) {
r_vertex_poly_indices[loop.v].append(i);
}
}
@@ -321,26 +321,28 @@ static void create_vertex_poly_map(const Mesh &mesh,
* - Finally if we are in the normal case we also need to add the last "shared edge" to close the
* loop.
*/
-static bool sort_vertex_polys(const Mesh &mesh,
+static bool sort_vertex_polys(const Span<MEdge> edges,
+ const Span<MPoly> polys,
+ const Span<MLoop> loops,
const int vertex_index,
const bool boundary_vertex,
const Span<EdgeType> edge_types,
- MutableSpan<int> connected_polygons,
+ MutableSpan<int> connected_polys,
MutableSpan<int> r_shared_edges,
MutableSpan<int> r_sorted_corners)
{
- if (connected_polygons.size() <= 2 && (!boundary_vertex || connected_polygons.size() == 0)) {
+ if (connected_polys.size() <= 2 && (!boundary_vertex || connected_polys.size() == 0)) {
return true;
}
/* For each polygon store the two corners whose edge contains the vertex. */
- Array<std::pair<int, int>> poly_vertex_corners(connected_polygons.size());
- for (const int i : connected_polygons.index_range()) {
- const MPoly &poly = mesh.mpoly[connected_polygons[i]];
+ Array<std::pair<int, int>> poly_vertex_corners(connected_polys.size());
+ for (const int i : connected_polys.index_range()) {
+ const MPoly &poly = polys[connected_polys[i]];
bool first_edge_done = false;
for (const int loop_index : IndexRange(poly.loopstart, poly.totloop)) {
- const MLoop &loop = mesh.mloop[loop_index];
- if (mesh.medge[loop.e].v1 == vertex_index || mesh.medge[loop.e].v2 == vertex_index) {
+ const MLoop &loop = loops[loop_index];
+ if (edges[loop.e].v1 == vertex_index || edges[loop.e].v2 == vertex_index) {
if (!first_edge_done) {
poly_vertex_corners[i].first = loop_index;
first_edge_done = true;
@@ -359,20 +361,20 @@ static bool sort_vertex_polys(const Mesh &mesh,
* the loop to determine the 'average' orientation. */
if (boundary_vertex) {
/* Our first polygon needs to be one which has a boundary edge. */
- for (const int i : connected_polygons.index_range()) {
- const MLoop &first_loop = mesh.mloop[poly_vertex_corners[i].first];
- const MLoop &second_loop = mesh.mloop[poly_vertex_corners[i].second];
+ for (const int i : connected_polys.index_range()) {
+ const MLoop &first_loop = loops[poly_vertex_corners[i].first];
+ const MLoop &second_loop = loops[poly_vertex_corners[i].second];
if (edge_types[first_loop.e] == EdgeType::Boundary && first_loop.v == vertex_index) {
shared_edge_i = second_loop.e;
r_sorted_corners[0] = poly_vertex_corners[i].first;
- std::swap(connected_polygons[i], connected_polygons[0]);
+ std::swap(connected_polys[i], connected_polys[0]);
std::swap(poly_vertex_corners[i], poly_vertex_corners[0]);
break;
}
if (edge_types[second_loop.e] == EdgeType::Boundary && second_loop.v == vertex_index) {
shared_edge_i = first_loop.e;
r_sorted_corners[0] = poly_vertex_corners[i].second;
- std::swap(connected_polygons[i], connected_polygons[0]);
+ std::swap(connected_polys[i], connected_polys[0]);
std::swap(poly_vertex_corners[i], poly_vertex_corners[0]);
break;
}
@@ -380,20 +382,20 @@ static bool sort_vertex_polys(const Mesh &mesh,
if (shared_edge_i == -1) {
/* The rotation is inconsistent between the two polygons on the boundary. Just choose one
* of the polygon's orientation. */
- for (const int i : connected_polygons.index_range()) {
- const MLoop &first_loop = mesh.mloop[poly_vertex_corners[i].first];
- const MLoop &second_loop = mesh.mloop[poly_vertex_corners[i].second];
+ for (const int i : connected_polys.index_range()) {
+ const MLoop &first_loop = loops[poly_vertex_corners[i].first];
+ const MLoop &second_loop = loops[poly_vertex_corners[i].second];
if (edge_types[first_loop.e] == EdgeType::Boundary) {
shared_edge_i = second_loop.e;
r_sorted_corners[0] = poly_vertex_corners[i].first;
- std::swap(connected_polygons[i], connected_polygons[0]);
+ std::swap(connected_polys[i], connected_polys[0]);
std::swap(poly_vertex_corners[i], poly_vertex_corners[0]);
break;
}
if (edge_types[second_loop.e] == EdgeType::Boundary) {
shared_edge_i = first_loop.e;
r_sorted_corners[0] = poly_vertex_corners[i].second;
- std::swap(connected_polygons[i], connected_polygons[0]);
+ std::swap(connected_polys[i], connected_polys[0]);
std::swap(poly_vertex_corners[i], poly_vertex_corners[0]);
break;
}
@@ -402,8 +404,8 @@ static bool sort_vertex_polys(const Mesh &mesh,
}
else {
/* Any polygon can be the first. Just need to check the orientation. */
- const MLoop &first_loop = mesh.mloop[poly_vertex_corners[0].first];
- const MLoop &second_loop = mesh.mloop[poly_vertex_corners[0].second];
+ const MLoop &first_loop = loops[poly_vertex_corners[0].first];
+ const MLoop &second_loop = loops[poly_vertex_corners[0].second];
if (first_loop.v == vertex_index) {
shared_edge_i = second_loop.e;
r_sorted_corners[0] = poly_vertex_corners[0].first;
@@ -415,14 +417,14 @@ static bool sort_vertex_polys(const Mesh &mesh,
}
BLI_assert(shared_edge_i != -1);
- for (const int i : IndexRange(connected_polygons.size() - 1)) {
+ for (const int i : IndexRange(connected_polys.size() - 1)) {
r_shared_edges[i] = shared_edge_i;
/* Look at the other polys to see if it has this shared edge. */
int j = i + 1;
- for (; j < connected_polygons.size(); ++j) {
- const MLoop &first_loop = mesh.mloop[poly_vertex_corners[j].first];
- const MLoop &second_loop = mesh.mloop[poly_vertex_corners[j].second];
+ for (; j < connected_polys.size(); ++j) {
+ const MLoop &first_loop = loops[poly_vertex_corners[j].first];
+ const MLoop &second_loop = loops[poly_vertex_corners[j].second];
if (first_loop.e == shared_edge_i) {
r_sorted_corners[i + 1] = poly_vertex_corners[j].first;
shared_edge_i = second_loop.e;
@@ -434,13 +436,13 @@ static bool sort_vertex_polys(const Mesh &mesh,
break;
}
}
- if (j == connected_polygons.size()) {
+ if (j == connected_polys.size()) {
/* The vertex is not manifold because the polygons around the vertex don't form a loop, and
* hence can't be sorted. */
return false;
}
- std::swap(connected_polygons[i + 1], connected_polygons[j]);
+ std::swap(connected_polys[i + 1], connected_polys[j]);
std::swap(poly_vertex_corners[i + 1], poly_vertex_corners[j]);
}
@@ -455,14 +457,16 @@ static bool sort_vertex_polys(const Mesh &mesh,
* Get the edge on the poly that contains the given vertex and is a boundary edge.
*/
static void boundary_edge_on_poly(const MPoly &poly,
- const Mesh &mesh,
+ const Span<MEdge> edges,
+ const Span<MLoop> loops,
const int vertex_index,
const Span<EdgeType> edge_types,
int &r_edge)
{
- for (const MLoop &loop : Span<MLoop>(&mesh.mloop[poly.loopstart], poly.totloop)) {
+ const Span<MLoop> poly_loops = loops.slice(poly.loopstart, poly.totloop);
+ for (const MLoop &loop : poly_loops) {
if (edge_types[loop.e] == EdgeType::Boundary) {
- const MEdge &edge = mesh.medge[loop.e];
+ const MEdge &edge = edges[loop.e];
if (edge.v1 == vertex_index || edge.v2 == vertex_index) {
r_edge = loop.e;
return;
@@ -476,7 +480,8 @@ static void boundary_edge_on_poly(const MPoly &poly,
* orientation of the poly is taken into account.
*/
static void boundary_edges_on_poly(const MPoly &poly,
- const Mesh &mesh,
+ const Span<MEdge> edges,
+ const Span<MLoop> loops,
const int vertex_index,
const Span<EdgeType> edge_types,
int &r_edge1,
@@ -486,9 +491,10 @@ static void boundary_edges_on_poly(const MPoly &poly,
/* This is set to true if the order in which we encounter the two edges is inconsistent with the
* orientation of the polygon. */
bool needs_swap = false;
- for (const MLoop &loop : Span<MLoop>(&mesh.mloop[poly.loopstart], poly.totloop)) {
+ const Span<MLoop> poly_loops = loops.slice(poly.loopstart, poly.totloop);
+ for (const MLoop &loop : poly_loops) {
if (edge_types[loop.e] == EdgeType::Boundary) {
- const MEdge &edge = mesh.medge[loop.e];
+ const MEdge &edge = edges[loop.e];
if (edge.v1 == vertex_index || edge.v2 == vertex_index) {
if (edge1_done) {
if (needs_swap) {
@@ -510,7 +516,7 @@ static void boundary_edges_on_poly(const MPoly &poly,
}
}
-static void add_edge(const Mesh &mesh,
+static void add_edge(const Span<MEdge> src_edges,
const int old_edge_i,
const int v1,
const int v2,
@@ -518,7 +524,7 @@ static void add_edge(const Mesh &mesh,
Vector<MEdge> &new_edges,
Vector<int> &loop_edges)
{
- MEdge new_edge = MEdge(mesh.medge[old_edge_i]);
+ MEdge new_edge = src_edges[old_edge_i];
new_edge.v1 = v1;
new_edge.v2 = v2;
const int new_edge_i = new_edges.size();
@@ -549,14 +555,17 @@ static bool vertex_needs_dissolving(const int vertex,
* edges in the input mesh which contain such a vertex are marked as 'done' to prevent duplicate
* edges being created. (See T94144)
*/
-static void dissolve_redundant_verts(const Mesh &mesh,
+static void dissolve_redundant_verts(const Span<MEdge> edges,
+ const Span<MPoly> polys,
+ const Span<MLoop> loops,
const Span<Vector<int>> vertex_poly_indices,
MutableSpan<VertexType> vertex_types,
MutableSpan<int> old_to_new_edges_map,
Vector<MEdge> &new_edges,
Vector<int> &new_to_old_edges_map)
{
- for (const int vert_i : IndexRange(mesh.totvert)) {
+ const int vertex_num = vertex_types.size();
+ for (const int vert_i : IndexRange(vertex_num)) {
if (vertex_poly_indices[vert_i].size() != 2 || vertex_types[vert_i] != VertexType::Normal) {
continue;
}
@@ -564,9 +573,10 @@ static void dissolve_redundant_verts(const Mesh &mesh,
const int second_poly_index = vertex_poly_indices[vert_i][1];
const int new_edge_index = new_edges.size();
bool edge_created = false;
- const MPoly &poly = mesh.mpoly[first_poly_index];
- for (const MLoop &loop : Span<MLoop>(&mesh.mloop[poly.loopstart], poly.totloop)) {
- const MEdge &edge = mesh.medge[loop.e];
+ const MPoly &poly = polys[first_poly_index];
+ const Span<MLoop> poly_loops = loops.slice(poly.loopstart, poly.totloop);
+ for (const MLoop &loop : poly_loops) {
+ const MEdge &edge = edges[loop.e];
const int v1 = edge.v1;
const int v2 = edge.v2;
bool mark_edge = false;
@@ -617,6 +627,10 @@ static void calc_dual_mesh(GeometrySet &geometry_set,
const bool keep_boundaries)
{
const Mesh &mesh_in = *in_component.get_for_read();
+ const Span<MVert> src_verts = mesh_in.verts();
+ const Span<MEdge> src_edges = mesh_in.edges();
+ const Span<MPoly> src_polys = mesh_in.polys();
+ const Span<MLoop> src_loops = mesh_in.loops();
Map<AttributeIDRef, AttributeKind> attributes;
geometry_set.gather_attributes_for_propagation(
@@ -644,14 +658,28 @@ static void calc_dual_mesh(GeometrySet &geometry_set,
bool vertex_ok = true;
if (vertex_types[i] == VertexType::Normal) {
Array<int> shared_edges(loop_indices.size());
- vertex_ok = sort_vertex_polys(
- mesh_in, i, false, edge_types, loop_indices, shared_edges, sorted_corners);
+ vertex_ok = sort_vertex_polys(src_edges,
+ src_polys,
+ src_loops,
+ i,
+ false,
+ edge_types,
+ loop_indices,
+ shared_edges,
+ sorted_corners);
vertex_shared_edges[i] = std::move(shared_edges);
}
else {
Array<int> shared_edges(loop_indices.size() - 1);
- vertex_ok = sort_vertex_polys(
- mesh_in, i, true, edge_types, loop_indices, shared_edges, sorted_corners);
+ vertex_ok = sort_vertex_polys(src_edges,
+ src_polys,
+ src_loops,
+ i,
+ true,
+ edge_types,
+ loop_indices,
+ shared_edges,
+ sorted_corners);
vertex_shared_edges[i] = std::move(shared_edges);
}
if (!vertex_ok) {
@@ -666,9 +694,9 @@ static void calc_dual_mesh(GeometrySet &geometry_set,
Vector<float3> vertex_positions(mesh_in.totpoly);
for (const int i : IndexRange(mesh_in.totpoly)) {
- const MPoly poly = mesh_in.mpoly[i];
+ const MPoly &poly = src_polys[i];
BKE_mesh_calc_poly_center(
- &poly, &mesh_in.mloop[poly.loopstart], mesh_in.mvert, vertex_positions[i]);
+ &poly, &src_loops[poly.loopstart], src_verts.data(), vertex_positions[i]);
}
Array<int> boundary_edge_midpoint_index;
@@ -679,8 +707,8 @@ static void calc_dual_mesh(GeometrySet &geometry_set,
for (const int i : IndexRange(mesh_in.totedge)) {
if (edge_types[i] == EdgeType::Boundary) {
float3 mid;
- const MEdge &edge = mesh_in.medge[i];
- mid_v3_v3v3(mid, mesh_in.mvert[edge.v1].co, mesh_in.mvert[edge.v2].co);
+ const MEdge &edge = src_edges[i];
+ mid_v3_v3v3(mid, src_verts[edge.v1].co, src_verts[edge.v2].co);
boundary_edge_midpoint_index[i] = vertex_positions.size();
vertex_positions.append(mid);
}
@@ -706,7 +734,9 @@ static void calc_dual_mesh(GeometrySet &geometry_set,
/* This is necessary to prevent duplicate edges from being created, but will likely not do
* anything for most meshes. */
- dissolve_redundant_verts(mesh_in,
+ dissolve_redundant_verts(src_edges,
+ src_polys,
+ src_loops,
vertex_poly_indices,
vertex_types,
old_to_new_edges_map,
@@ -734,7 +764,7 @@ static void calc_dual_mesh(GeometrySet &geometry_set,
const int old_edge_i = shared_edges[i];
if (old_to_new_edges_map[old_edge_i] == -1) {
/* This edge has not been created yet. */
- MEdge new_edge = MEdge(mesh_in.medge[old_edge_i]);
+ MEdge new_edge = src_edges[old_edge_i];
new_edge.v1 = loop_indices[i];
new_edge.v2 = loop_indices[(i + 1) % loop_indices.size()];
new_to_old_edges_map.append(old_edge_i);
@@ -776,7 +806,7 @@ static void calc_dual_mesh(GeometrySet &geometry_set,
const int old_edge_i = shared_edges[i];
if (old_to_new_edges_map[old_edge_i] == -1) {
/* This edge has not been created yet. */
- MEdge new_edge = MEdge(mesh_in.medge[old_edge_i]);
+ MEdge new_edge = src_edges[old_edge_i];
new_edge.v1 = loop_indices[i];
new_edge.v2 = loop_indices[i + 1];
new_to_old_edges_map.append(old_edge_i);
@@ -795,13 +825,15 @@ static void calc_dual_mesh(GeometrySet &geometry_set,
int edge2;
if (loop_indices.size() >= 2) {
/* The first boundary edge is at the end of the chain of polygons. */
- boundary_edge_on_poly(mesh_in.mpoly[loop_indices.last()], mesh_in, i, edge_types, edge1);
- boundary_edge_on_poly(mesh_in.mpoly[loop_indices.first()], mesh_in, i, edge_types, edge2);
+ boundary_edge_on_poly(
+ src_polys[loop_indices.last()], src_edges, src_loops, i, edge_types, edge1);
+ boundary_edge_on_poly(
+ src_polys[loop_indices.first()], src_edges, src_loops, i, edge_types, edge2);
}
else {
/* If there is only one polygon both edges are in that polygon. */
boundary_edges_on_poly(
- mesh_in.mpoly[loop_indices[0]], mesh_in, i, edge_types, edge1, edge2);
+ src_polys[loop_indices[0]], src_edges, src_loops, i, edge_types, edge1, edge2);
}
const int last_face_center = loop_indices.last();
@@ -809,7 +841,7 @@ static void calc_dual_mesh(GeometrySet &geometry_set,
new_to_old_face_corners_map.append(sorted_corners.last());
const int first_midpoint = loop_indices.last();
if (old_to_new_edges_map[edge1] == -1) {
- add_edge(mesh_in,
+ add_edge(src_edges,
edge1,
last_face_center,
first_midpoint,
@@ -827,9 +859,9 @@ static void calc_dual_mesh(GeometrySet &geometry_set,
new_to_old_face_corners_map.append(sorted_corners.first());
boundary_vertex_to_relevant_face_map.append(
std::pair(loop_indices.last(), last_face_center));
- vertex_positions.append(mesh_in.mvert[i].co);
+ vertex_positions.append(src_verts[i].co);
const int boundary_vertex = loop_indices.last();
- add_edge(mesh_in,
+ add_edge(src_edges,
edge1,
first_midpoint,
boundary_vertex,
@@ -840,7 +872,7 @@ static void calc_dual_mesh(GeometrySet &geometry_set,
loop_indices.append(boundary_edge_midpoint_index[edge2]);
new_to_old_face_corners_map.append(sorted_corners.first());
const int second_midpoint = loop_indices.last();
- add_edge(mesh_in,
+ add_edge(src_edges,
edge2,
boundary_vertex,
second_midpoint,
@@ -850,7 +882,7 @@ static void calc_dual_mesh(GeometrySet &geometry_set,
if (old_to_new_edges_map[edge2] == -1) {
const int first_face_center = loop_indices.first();
- add_edge(mesh_in,
+ add_edge(src_edges,
edge2,
second_midpoint,
first_face_center,
@@ -878,23 +910,28 @@ static void calc_dual_mesh(GeometrySet &geometry_set,
new_to_old_edges_map,
new_to_old_face_corners_map,
boundary_vertex_to_relevant_face_map,
- bke::mesh_attributes(mesh_in),
- bke::mesh_attributes_for_write(*mesh_out));
+ mesh_in.attributes(),
+ mesh_out->attributes_for_write());
+
+ MutableSpan<MVert> dst_verts = mesh_out->verts_for_write();
+ MutableSpan<MEdge> dst_edges = mesh_out->edges_for_write();
+ MutableSpan<MPoly> dst_polys = mesh_out->polys_for_write();
+ MutableSpan<MLoop> dst_loops = mesh_out->loops_for_write();
int loop_start = 0;
for (const int i : IndexRange(mesh_out->totpoly)) {
- mesh_out->mpoly[i].loopstart = loop_start;
- mesh_out->mpoly[i].totloop = loop_lengths[i];
+ dst_polys[i].loopstart = loop_start;
+ dst_polys[i].totloop = loop_lengths[i];
loop_start += loop_lengths[i];
}
for (const int i : IndexRange(mesh_out->totloop)) {
- mesh_out->mloop[i].v = loops[i];
- mesh_out->mloop[i].e = loop_edges[i];
+ dst_loops[i].v = loops[i];
+ dst_loops[i].e = loop_edges[i];
}
for (const int i : IndexRange(mesh_out->totvert)) {
- copy_v3_v3(mesh_out->mvert[i].co, vertex_positions[i]);
+ copy_v3_v3(dst_verts[i].co, vertex_positions[i]);
}
- memcpy(mesh_out->medge, new_edges.data(), sizeof(MEdge) * new_edges.size());
+ dst_edges.copy_from(new_edges);
geometry_set.replace_mesh(mesh_out);
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc b/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc
index c6b0fb4c068..486f900aca5 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "BLI_array_utils.hh"
#include "BLI_map.hh"
#include "BLI_noise.hh"
#include "BLI_span.hh"
@@ -11,6 +12,7 @@
#include "BKE_attribute_math.hh"
#include "BKE_curves.hh"
+#include "BKE_instances.hh"
#include "BKE_mesh.h"
#include "BKE_pointcloud.h"
@@ -40,14 +42,14 @@ static void node_declare(NodeDeclarationBuilder &b)
.description(N_("The indices of the duplicates for each element"));
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryDuplicateElements *data = MEM_cnew<NodeGeometryDuplicateElements>(__func__);
data->domain = ATTR_DOMAIN_POINT;
node->storage = data;
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "domain", 0, "", ICON_NONE);
}
@@ -104,16 +106,6 @@ static void threaded_slice_fill(Span<int> offsets,
});
}
-template<typename T>
-static void threaded_mapped_copy(const Span<int> mapping, const Span<T> src, MutableSpan<T> dst)
-{
- threading::parallel_for(mapping.index_range(), 512, [&](IndexRange range) {
- for (const int i : range) {
- dst[i] = src[mapping[i]];
- }
- });
-}
-
static void copy_hashed_ids(const Span<int> src, const int hash, MutableSpan<int> dst)
{
for (const int i : src.index_range()) {
@@ -334,11 +326,10 @@ static void duplicate_curves(GeometrySet &geometry_set,
geometry_set.keep_only_during_modify({GEO_COMPONENT_TYPE_CURVE});
GeometryComponentEditData::remember_deformed_curve_positions_if_necessary(geometry_set);
- const CurveComponent &src_component = *geometry_set.get_component_for_read<CurveComponent>();
- const Curves &curves_id = *src_component.get_for_read();
+ const Curves &curves_id = *geometry_set.get_curves_for_read();
const bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id.geometry);
- GeometryComponentFieldContext field_context{src_component, ATTR_DOMAIN_CURVE};
+ bke::CurvesFieldContext field_context{curves, ATTR_DOMAIN_CURVE};
FieldEvaluator evaluator{field_context, curves.curves_num()};
evaluator.add(count_field);
evaluator.set_selection(selection_field);
@@ -440,17 +431,17 @@ static void copy_face_attributes_without_id(GeometrySet &geometry_set,
MutableSpan<T> dst = dst_attribute.span.typed<T>();
switch (out_domain) {
- case ATTR_DOMAIN_FACE:
- threaded_slice_fill<T>(offsets, selection, src, dst);
+ case ATTR_DOMAIN_POINT:
+ array_utils::gather(src, vert_mapping, dst);
break;
case ATTR_DOMAIN_EDGE:
- threaded_mapped_copy<T>(edge_mapping, src, dst);
+ array_utils::gather(src, edge_mapping, dst);
break;
- case ATTR_DOMAIN_POINT:
- threaded_mapped_copy<T>(vert_mapping, src, dst);
+ case ATTR_DOMAIN_FACE:
+ threaded_slice_fill<T>(offsets, selection, src, dst);
break;
case ATTR_DOMAIN_CORNER:
- threaded_mapped_copy<T>(loop_mapping, src, dst);
+ array_utils::gather(src, loop_mapping, dst);
break;
default:
break;
@@ -487,7 +478,7 @@ static void copy_stable_id_faces(const Mesh &mesh,
VArraySpan<int> src{src_attribute.varray.typed<int>()};
MutableSpan<int> dst = dst_attribute.span.typed<int>();
- Span<MPoly> polys(mesh.mpoly, mesh.totpoly);
+ const Span<MPoly> polys = mesh.polys();
int loop_index = 0;
for (const int i_poly : selection.index_range()) {
const IndexRange range = range_for_offsets_index(poly_offsets, i_poly);
@@ -522,14 +513,13 @@ static void duplicate_faces(GeometrySet &geometry_set,
}
geometry_set.keep_only_during_modify({GEO_COMPONENT_TYPE_MESH});
- const MeshComponent &src_component = *geometry_set.get_component_for_read<MeshComponent>();
- const Mesh &mesh = *src_component.get_for_read();
- Span<MVert> verts(mesh.mvert, mesh.totvert);
- Span<MEdge> edges(mesh.medge, mesh.totedge);
- Span<MPoly> polys(mesh.mpoly, mesh.totpoly);
- Span<MLoop> loops(mesh.mloop, mesh.totloop);
+ const Mesh &mesh = *geometry_set.get_mesh_for_read();
+ const Span<MVert> verts = mesh.verts();
+ const Span<MEdge> edges = mesh.edges();
+ const Span<MPoly> polys = mesh.polys();
+ const Span<MLoop> loops = mesh.loops();
- GeometryComponentFieldContext field_context{src_component, ATTR_DOMAIN_FACE};
+ bke::MeshFieldContext field_context{mesh, ATTR_DOMAIN_FACE};
FieldEvaluator evaluator(field_context, polys.size());
evaluator.add(count_field);
evaluator.set_selection(selection_field);
@@ -549,10 +539,10 @@ static void duplicate_faces(GeometrySet &geometry_set,
offsets[selection.size()] = total_polys;
Mesh *new_mesh = BKE_mesh_new_nomain(total_loops, total_loops, 0, total_loops, total_polys);
- MutableSpan<MVert> new_verts(new_mesh->mvert, new_mesh->totvert);
- MutableSpan<MEdge> new_edges(new_mesh->medge, new_mesh->totedge);
- MutableSpan<MLoop> new_loops(new_mesh->mloop, new_mesh->totloop);
- MutableSpan<MPoly> new_poly(new_mesh->mpoly, new_mesh->totpoly);
+ MutableSpan<MVert> new_verts = new_mesh->verts_for_write();
+ MutableSpan<MEdge> new_edges = new_mesh->edges_for_write();
+ MutableSpan<MPoly> new_polys = new_mesh->polys_for_write();
+ MutableSpan<MLoop> new_loops = new_mesh->loops_for_write();
Array<int> vert_mapping(new_verts.size());
Array<int> edge_mapping(new_edges.size());
@@ -565,8 +555,8 @@ static void duplicate_faces(GeometrySet &geometry_set,
const MPoly &source = polys[selection[i_selection]];
for ([[maybe_unused]] const int i_duplicate : IndexRange(poly_range.size())) {
- new_poly[poly_index] = source;
- new_poly[poly_index].loopstart = loop_index;
+ new_polys[poly_index] = source;
+ new_polys[poly_index].loopstart = loop_index;
for (const int i_loops : IndexRange(source.totloop)) {
const MLoop &current_loop = loops[source.loopstart + i_loops];
loop_mapping[loop_index] = source.loopstart + i_loops;
@@ -579,7 +569,7 @@ static void duplicate_faces(GeometrySet &geometry_set,
new_edges[loop_index].v2 = loop_index + 1;
}
else {
- new_edges[loop_index].v2 = new_poly[poly_index].loopstart;
+ new_edges[loop_index].v2 = new_polys[poly_index].loopstart;
}
new_loops[loop_index].v = loop_index;
new_loops[loop_index].e = loop_index;
@@ -595,22 +585,15 @@ static void duplicate_faces(GeometrySet &geometry_set,
loop_mapping,
offsets,
selection,
- bke::mesh_attributes(mesh),
- bke::mesh_attributes_for_write(*new_mesh));
+ mesh.attributes(),
+ new_mesh->attributes_for_write());
- copy_stable_id_faces(mesh,
- selection,
- offsets,
- vert_mapping,
- bke::mesh_attributes(mesh),
- bke::mesh_attributes_for_write(*new_mesh));
+ copy_stable_id_faces(
+ mesh, selection, offsets, vert_mapping, mesh.attributes(), new_mesh->attributes_for_write());
if (attribute_outputs.duplicate_index) {
- create_duplicate_index_attribute(bke::mesh_attributes_for_write(*new_mesh),
- ATTR_DOMAIN_FACE,
- selection,
- attribute_outputs,
- offsets);
+ create_duplicate_index_attribute(
+ new_mesh->attributes_for_write(), ATTR_DOMAIN_FACE, selection, attribute_outputs, offsets);
}
geometry_set.replace_mesh(new_mesh);
@@ -661,7 +644,7 @@ static void copy_edge_attributes_without_id(GeometrySet &geometry_set,
threaded_slice_fill<T>(offsets, selection, src, dst);
break;
case ATTR_DOMAIN_POINT:
- threaded_mapped_copy<T>(point_mapping, src, dst);
+ array_utils::gather(src, point_mapping, dst);
break;
default:
break;
@@ -691,7 +674,7 @@ static void copy_stable_id_edges(const Mesh &mesh,
return;
}
- Span<MEdge> edges(mesh.medge, mesh.totedge);
+ const Span<MEdge> edges = mesh.edges();
VArraySpan<int> src{src_attribute.varray.typed<int>()};
MutableSpan<int> dst = dst_attribute.span.typed<int>();
@@ -724,12 +707,10 @@ static void duplicate_edges(GeometrySet &geometry_set,
geometry_set.remove_geometry_during_modify();
return;
};
- const MeshComponent &src_component = *geometry_set.get_component_for_read<MeshComponent>();
- const Mesh &mesh = *src_component.get_for_read();
- Span<MVert> verts(mesh.mvert, mesh.totvert);
- Span<MEdge> edges(mesh.medge, mesh.totedge);
+ const Mesh &mesh = *geometry_set.get_mesh_for_read();
+ const Span<MEdge> edges = mesh.edges();
- GeometryComponentFieldContext field_context{src_component, ATTR_DOMAIN_EDGE};
+ bke::MeshFieldContext field_context{mesh, ATTR_DOMAIN_EDGE};
FieldEvaluator evaluator{field_context, edges.size()};
evaluator.add(count_field);
evaluator.set_selection(selection_field);
@@ -740,8 +721,7 @@ static void duplicate_edges(GeometrySet &geometry_set,
Array<int> edge_offsets = accumulate_counts_to_offsets(selection, counts);
Mesh *new_mesh = BKE_mesh_new_nomain(edge_offsets.last() * 2, edge_offsets.last(), 0, 0, 0);
- MutableSpan<MVert> new_verts(new_mesh->mvert, new_mesh->totvert);
- MutableSpan<MEdge> new_edges(new_mesh->medge, new_mesh->totedge);
+ MutableSpan<MEdge> new_edges = new_mesh->edges_for_write();
Array<int> vert_orig_indices(edge_offsets.last() * 2);
threading::parallel_for(selection.index_range(), 1024, [&](IndexRange range) {
@@ -774,17 +754,14 @@ static void duplicate_edges(GeometrySet &geometry_set,
vert_orig_indices,
edge_offsets,
selection,
- bke::mesh_attributes(mesh),
- bke::mesh_attributes_for_write(*new_mesh));
+ mesh.attributes(),
+ new_mesh->attributes_for_write());
- copy_stable_id_edges(mesh,
- selection,
- edge_offsets,
- bke::mesh_attributes(mesh),
- bke::mesh_attributes_for_write(*new_mesh));
+ copy_stable_id_edges(
+ mesh, selection, edge_offsets, mesh.attributes(), new_mesh->attributes_for_write());
if (attribute_outputs.duplicate_index) {
- create_duplicate_index_attribute(bke::mesh_attributes_for_write(*new_mesh),
+ create_duplicate_index_attribute(new_mesh->attributes_for_write(),
ATTR_DOMAIN_EDGE,
selection,
attribute_outputs,
@@ -805,14 +782,13 @@ static void duplicate_points_curve(GeometrySet &geometry_set,
const Field<bool> &selection_field,
const IndexAttributes &attribute_outputs)
{
- const CurveComponent &src_component = *geometry_set.get_component_for_read<CurveComponent>();
- const Curves &src_curves_id = *src_component.get_for_read();
+ const Curves &src_curves_id = *geometry_set.get_curves_for_read();
const bke::CurvesGeometry &src_curves = bke::CurvesGeometry::wrap(src_curves_id.geometry);
if (src_curves.points_num() == 0) {
return;
}
- GeometryComponentFieldContext field_context{src_component, ATTR_DOMAIN_POINT};
+ bke::CurvesFieldContext field_context{src_curves, ATTR_DOMAIN_POINT};
FieldEvaluator evaluator{field_context, src_curves.points_num()};
evaluator.add(count_field);
evaluator.set_selection(selection_field);
@@ -845,7 +821,7 @@ static void duplicate_points_curve(GeometrySet &geometry_set,
for (const Map<AttributeIDRef, AttributeKind>::Item entry : attributes.items()) {
const AttributeIDRef attribute_id = entry.key;
- GAttributeReader src_attribute = src_component.attributes()->lookup(attribute_id);
+ GAttributeReader src_attribute = src_curves.attributes().lookup(attribute_id);
if (!src_attribute) {
continue;
}
@@ -909,11 +885,10 @@ static void duplicate_points_mesh(GeometrySet &geometry_set,
const Field<bool> &selection_field,
const IndexAttributes &attribute_outputs)
{
- const MeshComponent &src_component = *geometry_set.get_component_for_read<MeshComponent>();
const Mesh &mesh = *geometry_set.get_mesh_for_read();
- Span<MVert> src_verts(mesh.mvert, mesh.totvert);
+ const Span<MVert> src_verts = mesh.verts();
- GeometryComponentFieldContext field_context{src_component, ATTR_DOMAIN_POINT};
+ bke::MeshFieldContext field_context{mesh, ATTR_DOMAIN_POINT};
FieldEvaluator evaluator{field_context, src_verts.size()};
evaluator.add(count_field);
evaluator.set_selection(selection_field);
@@ -924,7 +899,7 @@ static void duplicate_points_mesh(GeometrySet &geometry_set,
Array<int> offsets = accumulate_counts_to_offsets(selection, counts);
Mesh *new_mesh = BKE_mesh_new_nomain(offsets.last(), 0, 0, 0, 0);
- MutableSpan<MVert> dst_verts(new_mesh->mvert, new_mesh->totvert);
+ MutableSpan<MVert> dst_verts = new_mesh->verts_for_write();
threaded_slice_fill(offsets.as_span(), selection, src_verts, dst_verts);
@@ -933,14 +908,13 @@ static void duplicate_points_mesh(GeometrySet &geometry_set,
ATTR_DOMAIN_POINT,
offsets,
selection,
- bke::mesh_attributes(mesh),
- bke::mesh_attributes_for_write(*new_mesh));
+ mesh.attributes(),
+ new_mesh->attributes_for_write());
- copy_stable_id_point(
- offsets, bke::mesh_attributes(mesh), bke::mesh_attributes_for_write(*new_mesh));
+ copy_stable_id_point(offsets, mesh.attributes(), new_mesh->attributes_for_write());
if (attribute_outputs.duplicate_index) {
- create_duplicate_index_attribute(bke::mesh_attributes_for_write(*new_mesh),
+ create_duplicate_index_attribute(new_mesh->attributes_for_write(),
ATTR_DOMAIN_POINT,
selection,
attribute_outputs,
@@ -961,12 +935,10 @@ static void duplicate_points_pointcloud(GeometrySet &geometry_set,
const Field<bool> &selection_field,
const IndexAttributes &attribute_outputs)
{
- const PointCloudComponent &src_points =
- *geometry_set.get_component_for_read<PointCloudComponent>();
- const int point_num = src_points.attribute_domain_size(ATTR_DOMAIN_POINT);
+ const PointCloud &src_points = *geometry_set.get_pointcloud_for_read();
- GeometryComponentFieldContext field_context{src_points, ATTR_DOMAIN_POINT};
- FieldEvaluator evaluator{field_context, point_num};
+ bke::PointCloudFieldContext field_context{src_points};
+ FieldEvaluator evaluator{field_context, src_points.totpoint};
evaluator.add(count_field);
evaluator.set_selection(selection_field);
evaluator.evaluate();
@@ -982,14 +954,13 @@ static void duplicate_points_pointcloud(GeometrySet &geometry_set,
ATTR_DOMAIN_POINT,
offsets,
selection,
- *src_points.attributes(),
- bke::pointcloud_attributes_for_write(*pointcloud));
+ src_points.attributes(),
+ pointcloud->attributes_for_write());
- copy_stable_id_point(
- offsets, *src_points.attributes(), bke::pointcloud_attributes_for_write(*pointcloud));
+ copy_stable_id_point(offsets, src_points.attributes(), pointcloud->attributes_for_write());
if (attribute_outputs.duplicate_index) {
- create_duplicate_index_attribute(bke::pointcloud_attributes_for_write(*pointcloud),
+ create_duplicate_index_attribute(pointcloud->attributes_for_write(),
ATTR_DOMAIN_POINT,
selection,
attribute_outputs,
@@ -1052,10 +1023,9 @@ static void duplicate_instances(GeometrySet &geometry_set,
return;
}
- const InstancesComponent &src_instances =
- *geometry_set.get_component_for_read<InstancesComponent>();
+ const bke::Instances &src_instances = *geometry_set.get_instances_for_read();
- GeometryComponentFieldContext field_context{src_instances, ATTR_DOMAIN_INSTANCE};
+ bke::InstancesFieldContext field_context{src_instances};
FieldEvaluator evaluator{field_context, src_instances.instances_num()};
evaluator.add(count_field);
evaluator.set_selection(selection_field);
@@ -1069,20 +1039,20 @@ static void duplicate_instances(GeometrySet &geometry_set,
return;
}
- GeometrySet dst_geometry;
- InstancesComponent &dst_instances = dst_geometry.get_component_for_write<InstancesComponent>();
- dst_instances.resize(offsets.last());
+ std::unique_ptr<bke::Instances> dst_instances = std::make_unique<bke::Instances>();
+
+ dst_instances->resize(offsets.last());
for (const int i_selection : selection.index_range()) {
const IndexRange range = range_for_offsets_index(offsets, i_selection);
if (range.size() == 0) {
continue;
}
- const int old_handle = src_instances.instance_reference_handles()[i_selection];
- const InstanceReference reference = src_instances.references()[old_handle];
- const int new_handle = dst_instances.add_reference(reference);
- const float4x4 transform = src_instances.instance_transforms()[i_selection];
- dst_instances.instance_transforms().slice(range).fill(transform);
- dst_instances.instance_reference_handles().slice(range).fill(new_handle);
+ const int old_handle = src_instances.reference_handles()[i_selection];
+ const bke::InstanceReference reference = src_instances.references()[old_handle];
+ const int new_handle = dst_instances->add_reference(reference);
+ const float4x4 transform = src_instances.transforms()[i_selection];
+ dst_instances->transforms().slice(range).fill(transform);
+ dst_instances->reference_handles().slice(range).fill(new_handle);
}
copy_attributes_without_id(geometry_set,
@@ -1090,18 +1060,18 @@ static void duplicate_instances(GeometrySet &geometry_set,
ATTR_DOMAIN_INSTANCE,
offsets,
selection,
- *src_instances.attributes(),
- *dst_instances.attributes_for_write());
+ src_instances.attributes(),
+ dst_instances->attributes_for_write());
if (attribute_outputs.duplicate_index) {
- create_duplicate_index_attribute(*dst_instances.attributes_for_write(),
+ create_duplicate_index_attribute(dst_instances->attributes_for_write(),
ATTR_DOMAIN_INSTANCE,
selection,
attribute_outputs,
offsets);
}
- geometry_set = std::move(dst_geometry);
+ geometry_set = GeometrySet::create_with_instances(dst_instances.release());
}
/** \} */
diff --git a/source/blender/nodes/geometry/nodes/node_geo_edge_paths_to_curves.cc b/source/blender/nodes/geometry/nodes/node_geo_edge_paths_to_curves.cc
new file mode 100644
index 00000000000..ba09acf0bf0
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_edge_paths_to_curves.cc
@@ -0,0 +1,110 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "BKE_curves.hh"
+
+#include "DNA_mesh_types.h"
+
+#include "GEO_mesh_to_curve.hh"
+
+#include "node_geometry_util.hh"
+
+namespace blender::nodes::node_geo_edge_paths_to_curves_cc {
+
+static void node_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::Geometry>(N_("Mesh")).supported_type(GEO_COMPONENT_TYPE_MESH);
+ b.add_input<decl::Bool>(N_("Start Vertices")).default_value(true).hide_value().supports_field();
+ b.add_input<decl::Int>(N_("Next Vertex Index")).default_value(-1).hide_value().supports_field();
+ b.add_output<decl::Geometry>(N_("Curves"));
+}
+
+static Curves *edge_paths_to_curves_convert(const Mesh &mesh,
+ const IndexMask start_verts_mask,
+ const Span<int> next_indices)
+{
+ Vector<int> vert_indices;
+ Vector<int> curve_offsets;
+ Array<bool> visited(mesh.totvert, false);
+ for (const int first_vert : start_verts_mask) {
+ const int second_vert = next_indices[first_vert];
+ if (first_vert == second_vert) {
+ continue;
+ }
+ if (second_vert < 0 || second_vert >= mesh.totvert) {
+ continue;
+ }
+
+ curve_offsets.append(vert_indices.size());
+
+ /* Iterate through path defined by #next_indices. */
+ int current_vert = first_vert;
+ while (!visited[current_vert]) {
+ visited[current_vert] = true;
+ vert_indices.append(current_vert);
+ const int next_vert = next_indices[current_vert];
+ if (next_vert < 0 || next_vert >= mesh.totvert) {
+ break;
+ }
+ current_vert = next_vert;
+ }
+
+ /* Reset visited status. */
+ const int points_in_curve_num = vert_indices.size() - curve_offsets.last();
+ for (const int vert_in_curve : vert_indices.as_span().take_back(points_in_curve_num)) {
+ visited[vert_in_curve] = false;
+ }
+ }
+
+ if (vert_indices.is_empty()) {
+ return nullptr;
+ }
+ Curves *curves_id = bke::curves_new_nomain(
+ geometry::create_curve_from_vert_indices(mesh, vert_indices, curve_offsets, IndexRange(0)));
+ return curves_id;
+}
+
+static void node_geo_exec(GeoNodeExecParams params)
+{
+ GeometrySet geometry_set = params.extract_input<GeometrySet>("Mesh");
+
+ geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
+ const Mesh *mesh = geometry_set.get_mesh_for_read();
+ if (mesh == nullptr) {
+ geometry_set.keep_only({GEO_COMPONENT_TYPE_INSTANCES});
+ return;
+ }
+
+ bke::MeshFieldContext context{*mesh, ATTR_DOMAIN_POINT};
+ fn::FieldEvaluator evaluator{context, mesh->totvert};
+ evaluator.add(params.get_input<Field<int>>("Next Vertex Index"));
+ evaluator.add(params.get_input<Field<bool>>("Start Vertices"));
+ evaluator.evaluate();
+ const VArraySpan<int> next_vert = evaluator.get_evaluated<int>(0);
+ IndexMask start_verts = evaluator.get_evaluated_as_mask(1);
+
+ if (start_verts.is_empty()) {
+ geometry_set.keep_only({GEO_COMPONENT_TYPE_INSTANCES});
+ return;
+ }
+
+ geometry_set.replace_curves(edge_paths_to_curves_convert(*mesh, start_verts, next_vert));
+ geometry_set.keep_only({GEO_COMPONENT_TYPE_CURVE, GEO_COMPONENT_TYPE_INSTANCES});
+ });
+
+ params.set_output("Curves", std::move(geometry_set));
+}
+
+} // namespace blender::nodes::node_geo_edge_paths_to_curves_cc
+
+void register_node_type_geo_edge_paths_to_curves()
+{
+ namespace file_ns = blender::nodes::node_geo_edge_paths_to_curves_cc;
+
+ static bNodeType ntype;
+
+ geo_node_type_base(
+ &ntype, GEO_NODE_EDGE_PATHS_TO_CURVES, "Edge Paths to Curves", NODE_CLASS_GEOMETRY);
+ ntype.declare = file_ns::node_declare;
+ ntype.geometry_node_execute = file_ns::node_geo_exec;
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_edge_paths_to_selection.cc b/source/blender/nodes/geometry/nodes/node_geo_edge_paths_to_selection.cc
new file mode 100644
index 00000000000..f0bd01a012b
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_edge_paths_to_selection.cc
@@ -0,0 +1,139 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "BKE_attribute_math.hh"
+#include "BKE_mesh.h"
+
+#include "BLI_map.hh"
+#include "BLI_set.hh"
+#include "BLI_task.hh"
+
+#include "node_geometry_util.hh"
+
+#include <set>
+
+namespace blender::nodes::node_geo_edge_paths_to_selection_cc {
+
+static void node_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::Bool>(N_("Start Vertices")).default_value(true).hide_value().supports_field();
+ b.add_input<decl::Int>(N_("Next Vertex Index")).default_value(-1).hide_value().supports_field();
+ b.add_output<decl::Bool>(N_("Selection")).field_source();
+}
+
+static void edge_paths_to_selection(const Mesh &src_mesh,
+ const IndexMask start_selection,
+ const Span<int> next_indices,
+ MutableSpan<bool> r_selection)
+{
+ const Span<MEdge> edges = src_mesh.edges();
+
+ Array<bool> selection(src_mesh.totvert, false);
+
+ for (const int start_vert : start_selection) {
+ selection[start_vert] = true;
+ }
+
+ for (const int start_i : start_selection) {
+ int iter = start_i;
+ while (iter != next_indices[iter] && !selection[next_indices[iter]]) {
+ if (next_indices[iter] < 0 || next_indices[iter] >= src_mesh.totvert) {
+ break;
+ }
+ selection[next_indices[iter]] = true;
+ iter = next_indices[iter];
+ }
+ }
+
+ for (const int i : edges.index_range()) {
+ const MEdge &edge = edges[i];
+ if ((selection[edge.v1] && selection[edge.v2]) &&
+ (edge.v1 == next_indices[edge.v2] || edge.v2 == next_indices[edge.v1])) {
+ r_selection[i] = true;
+ }
+ }
+}
+
+class PathToEdgeSelectionFieldInput final : public bke::MeshFieldInput {
+ private:
+ Field<bool> start_vertices_;
+ Field<int> next_vertex_;
+
+ public:
+ PathToEdgeSelectionFieldInput(Field<bool> start_verts, Field<int> next_vertex)
+ : bke::MeshFieldInput(CPPType::get<bool>(), "Edge Selection"),
+ start_vertices_(start_verts),
+ next_vertex_(next_vertex)
+ {
+ category_ = Category::Generated;
+ }
+
+ GVArray get_varray_for_context(const Mesh &mesh,
+ const eAttrDomain domain,
+ const IndexMask /*mask*/) const final
+ {
+ bke::MeshFieldContext context{mesh, ATTR_DOMAIN_POINT};
+ fn::FieldEvaluator evaluator{context, mesh.totvert};
+ evaluator.add(next_vertex_);
+ evaluator.add(start_vertices_);
+ evaluator.evaluate();
+ const VArraySpan<int> next_vert = evaluator.get_evaluated<int>(0);
+ const IndexMask start_verts = evaluator.get_evaluated_as_mask(1);
+
+ if (start_verts.is_empty()) {
+ return {};
+ }
+
+ Array<bool> selection(mesh.totedge, false);
+ MutableSpan<bool> selection_span = selection.as_mutable_span();
+
+ edge_paths_to_selection(mesh, start_verts, next_vert, selection_span);
+
+ return mesh.attributes().adapt_domain<bool>(
+ VArray<bool>::ForContainer(std::move(selection)), ATTR_DOMAIN_EDGE, domain);
+ }
+
+ uint64_t hash() const override
+ {
+ return get_default_hash_2(start_vertices_, next_vertex_);
+ }
+
+ bool is_equal_to(const fn::FieldNode &other) const override
+ {
+ if (const PathToEdgeSelectionFieldInput *other_field =
+ dynamic_cast<const PathToEdgeSelectionFieldInput *>(&other)) {
+ return other_field->start_vertices_ == start_vertices_ &&
+ other_field->next_vertex_ == next_vertex_;
+ }
+ return false;
+ }
+
+ std::optional<eAttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
+ {
+ return ATTR_DOMAIN_EDGE;
+ }
+};
+
+static void node_geo_exec(GeoNodeExecParams params)
+{
+ Field<bool> start_verts = params.extract_input<Field<bool>>("Start Vertices");
+ Field<int> next_vertex = params.extract_input<Field<int>>("Next Vertex Index");
+ Field<bool> selection_field{
+ std::make_shared<PathToEdgeSelectionFieldInput>(start_verts, next_vertex)};
+ params.set_output("Selection", std::move(selection_field));
+}
+
+} // namespace blender::nodes::node_geo_edge_paths_to_selection_cc
+
+void register_node_type_geo_edge_paths_to_selection()
+{
+ namespace file_ns = blender::nodes::node_geo_edge_paths_to_selection_cc;
+
+ static bNodeType ntype;
+
+ geo_node_type_base(
+ &ntype, GEO_NODE_EDGE_PATHS_TO_SELECTION, "Edge Paths to Selection", NODE_CLASS_INPUT);
+ ntype.declare = file_ns::node_declare;
+ node_type_size(&ntype, 150, 100, 300);
+ ntype.geometry_node_execute = file_ns::node_geo_exec;
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_edge_split.cc b/source/blender/nodes/geometry/nodes/node_geo_edge_split.cc
index 84acab47661..0b4d5bd53f3 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_edge_split.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_edge_split.cc
@@ -1,5 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "DNA_mesh_types.h"
+
#include "BKE_mesh.h"
#include "BKE_mesh_runtime.h"
@@ -51,19 +53,18 @@ static void node_geo_exec(GeoNodeExecParams params)
const Field<bool> selection_field = params.extract_input<Field<bool>>("Selection");
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
- if (!geometry_set.has_mesh()) {
- return;
- }
+ if (const Mesh *mesh = geometry_set.get_mesh_for_write()) {
- const MeshComponent &mesh_component = *geometry_set.get_component_for_read<MeshComponent>();
- GeometryComponentFieldContext field_context{mesh_component, ATTR_DOMAIN_EDGE};
- const int domain_size = mesh_component.attribute_domain_size(ATTR_DOMAIN_EDGE);
- fn::FieldEvaluator selection_evaluator{field_context, domain_size};
- selection_evaluator.add(selection_field);
- selection_evaluator.evaluate();
- const IndexMask selection = selection_evaluator.get_evaluated_as_mask(0);
+ bke::MeshFieldContext field_context{*mesh, ATTR_DOMAIN_EDGE};
+ fn::FieldEvaluator selection_evaluator{field_context, mesh->totedge};
+ selection_evaluator.add(selection_field);
+ selection_evaluator.evaluate();
+ const IndexMask selection = selection_evaluator.get_evaluated_as_mask(0);
- geometry_set.replace_mesh(mesh_edge_split(*mesh_component.get_for_read(), selection));
+ Mesh *result = mesh_edge_split(*mesh, selection);
+
+ geometry_set.replace_mesh(result);
+ }
});
params.set_output("Mesh", std::move(geometry_set));
diff --git a/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc b/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc
index acf85e74353..151ba3e59cc 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "BLI_array_utils.hh"
#include "BLI_disjoint_set.hh"
#include "BLI_task.hh"
#include "BLI_vector_set.hh"
@@ -24,7 +25,10 @@ static void node_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Geometry>("Mesh").supported_type(GEO_COMPONENT_TYPE_MESH);
b.add_input<decl::Bool>(N_("Selection")).default_value(true).supports_field().hide_value();
- b.add_input<decl::Vector>(N_("Offset")).subtype(PROP_TRANSLATION).implicit_field().hide_value();
+ b.add_input<decl::Vector>(N_("Offset"))
+ .subtype(PROP_TRANSLATION)
+ .implicit_field(implicit_field_inputs::normal)
+ .hide_value();
b.add_input<decl::Float>(N_("Offset Scale")).default_value(1.0f).supports_field();
b.add_input<decl::Bool>(N_("Individual")).default_value(true);
b.add_output<decl::Geometry>("Mesh");
@@ -32,14 +36,14 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Bool>(N_("Side")).field_source();
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryExtrudeMesh *data = MEM_cnew<NodeGeometryExtrudeMesh>(__func__);
data->mode = GEO_NODE_EXTRUDE_MESH_FACES;
@@ -49,9 +53,9 @@ static void node_init(bNodeTree *UNUSED(tree), bNode *node)
static void node_update(bNodeTree *ntree, bNode *node)
{
const NodeGeometryExtrudeMesh &storage = node_storage(*node);
- const GeometryNodeExtrudeMeshMode mode = static_cast<GeometryNodeExtrudeMeshMode>(storage.mode);
+ const GeometryNodeExtrudeMeshMode mode = GeometryNodeExtrudeMeshMode(storage.mode);
- bNodeSocket *individual_socket = (bNodeSocket *)node->inputs.last;
+ bNodeSocket *individual_socket = static_cast<bNodeSocket *>(node->inputs.last);
nodeSetSocketAvailability(ntree, individual_socket, mode == GEO_NODE_EXTRUDE_MESH_FACES);
}
@@ -61,15 +65,15 @@ struct AttributeOutputs {
StrongAnonymousAttributeID side_id;
};
-static void save_selection_as_attribute(MeshComponent &component,
+static void save_selection_as_attribute(Mesh &mesh,
const AnonymousAttributeID *id,
const eAttrDomain domain,
const IndexMask selection)
{
- BLI_assert(!component.attributes()->contains(id));
+ MutableAttributeAccessor attributes = mesh.attributes_for_write();
+ BLI_assert(!attributes.contains(id));
- SpanAttributeWriter<bool> attribute =
- component.attributes_for_write()->lookup_or_add_for_write_span<bool>(id, domain);
+ SpanAttributeWriter<bool> attribute = attributes.lookup_or_add_for_write_span<bool>(id, domain);
/* Rely on the new attribute being zeroed by default. */
BLI_assert(!attribute.span.as_span().contains(true));
@@ -83,31 +87,6 @@ static void save_selection_as_attribute(MeshComponent &component,
attribute.finish();
}
-static MutableSpan<MVert> mesh_verts(Mesh &mesh)
-{
- return {mesh.mvert, mesh.totvert};
-}
-static MutableSpan<MEdge> mesh_edges(Mesh &mesh)
-{
- return {mesh.medge, mesh.totedge};
-}
-static Span<MPoly> mesh_polys(const Mesh &mesh)
-{
- return {mesh.mpoly, mesh.totpoly};
-}
-static MutableSpan<MPoly> mesh_polys(Mesh &mesh)
-{
- return {mesh.mpoly, mesh.totpoly};
-}
-static Span<MLoop> mesh_loops(const Mesh &mesh)
-{
- return {mesh.mloop, mesh.totloop};
-}
-static MutableSpan<MLoop> mesh_loops(Mesh &mesh)
-{
- return {mesh.mloop, mesh.totloop};
-}
-
/**
* \note Some areas in this file rely on the new sections of attributes from #CustomData_realloc
* to be zeroed.
@@ -119,30 +98,25 @@ static void expand_mesh(Mesh &mesh,
const int loop_expand)
{
if (vert_expand != 0) {
- CustomData_duplicate_referenced_layers(&mesh.vdata, mesh.totvert);
+ const int old_verts_num = mesh.totvert;
mesh.totvert += vert_expand;
- CustomData_realloc(&mesh.vdata, mesh.totvert);
- }
- else {
- /* Even when the number of vertices is not changed, the mesh can still be deformed. */
- CustomData_duplicate_referenced_layer(&mesh.vdata, CD_MVERT, mesh.totvert);
+ CustomData_realloc(&mesh.vdata, old_verts_num, mesh.totvert);
}
if (edge_expand != 0) {
- CustomData_duplicate_referenced_layers(&mesh.edata, mesh.totedge);
+ const int old_edges_num = mesh.totedge;
mesh.totedge += edge_expand;
- CustomData_realloc(&mesh.edata, mesh.totedge);
+ CustomData_realloc(&mesh.edata, old_edges_num, mesh.totedge);
}
if (poly_expand != 0) {
- CustomData_duplicate_referenced_layers(&mesh.pdata, mesh.totpoly);
+ const int old_polys_num = mesh.totpoly;
mesh.totpoly += poly_expand;
- CustomData_realloc(&mesh.pdata, mesh.totpoly);
+ CustomData_realloc(&mesh.pdata, old_polys_num, mesh.totpoly);
}
if (loop_expand != 0) {
- CustomData_duplicate_referenced_layers(&mesh.ldata, mesh.totloop);
+ const int old_loops_num = mesh.totloop;
mesh.totloop += loop_expand;
- CustomData_realloc(&mesh.ldata, mesh.totloop);
+ CustomData_realloc(&mesh.ldata, old_loops_num, mesh.totloop);
}
- BKE_mesh_update_customdata_pointers(&mesh, false);
}
static CustomData &get_customdata(Mesh &mesh, const eAttrDomain domain)
@@ -162,9 +136,12 @@ static CustomData &get_customdata(Mesh &mesh, const eAttrDomain domain)
}
}
+/**
+ * \note The result may be an empty span.
+ */
static MutableSpan<int> get_orig_index_layer(Mesh &mesh, const eAttrDomain domain)
{
- const bke::AttributeAccessor attributes = bke::mesh_attributes(mesh);
+ const bke::AttributeAccessor attributes = mesh.attributes();
CustomData &custom_data = get_customdata(mesh, domain);
if (int *orig_indices = static_cast<int *>(CustomData_get_layer(&custom_data, CD_ORIGINDEX))) {
return {orig_indices, attributes.domain_size(domain)};
@@ -199,24 +176,6 @@ static MPoly new_poly(const int loopstart, const int totloop)
return poly;
}
-template<typename T> void copy_with_indices(MutableSpan<T> dst, Span<T> src, Span<int> indices)
-{
- BLI_assert(dst.size() == indices.size());
- for (const int i : dst.index_range()) {
- dst[i] = src[indices[i]];
- }
-}
-
-template<typename T> void copy_with_mask(MutableSpan<T> dst, Span<T> src, IndexMask mask)
-{
- BLI_assert(dst.size() == mask.size());
- threading::parallel_for(mask.index_range(), 512, [&](const IndexRange range) {
- for (const int i : range) {
- dst[i] = src[mask[i]];
- }
- });
-}
-
/**
* \param get_mix_indices_fn: Returns a Span of indices of the source points to mix for every
* result point.
@@ -225,7 +184,7 @@ template<typename T, typename GetMixIndicesFn>
void copy_with_mixing(MutableSpan<T> dst, Span<T> src, GetMixIndicesFn get_mix_indices_fn)
{
threading::parallel_for(dst.index_range(), 512, [&](const IndexRange range) {
- attribute_math::DefaultPropatationMixer<T> mixer{dst.slice(range)};
+ attribute_math::DefaultPropagationMixer<T> mixer{dst.slice(range)};
for (const int i_dst : IndexRange(range.size())) {
for (const int i_src : get_mix_indices_fn(range[i_dst])) {
mixer.mix_in(i_dst, src[i_src]);
@@ -247,16 +206,15 @@ static Array<Vector<int>> create_vert_to_edge_map(const int vert_size,
return vert_to_edge_map;
}
-static void extrude_mesh_vertices(MeshComponent &component,
+static void extrude_mesh_vertices(Mesh &mesh,
const Field<bool> &selection_field,
const Field<float3> &offset_field,
const AttributeOutputs &attribute_outputs)
{
- Mesh &mesh = *component.get_for_write();
const int orig_vert_size = mesh.totvert;
const int orig_edge_size = mesh.totedge;
- GeometryComponentFieldContext context{component, ATTR_DOMAIN_POINT};
+ bke::MeshFieldContext context{mesh, ATTR_DOMAIN_POINT};
FieldEvaluator evaluator{context, mesh.totvert};
evaluator.add(offset_field);
evaluator.set_selection(selection_field);
@@ -265,48 +223,49 @@ static void extrude_mesh_vertices(MeshComponent &component,
const VArray<float3> offsets = evaluator.get_evaluated<float3>(0);
/* This allows parallelizing attribute mixing for new edges. */
- Array<Vector<int>> vert_to_edge_map = create_vert_to_edge_map(orig_vert_size, mesh_edges(mesh));
+ Array<Vector<int>> vert_to_edge_map = create_vert_to_edge_map(orig_vert_size, mesh.edges());
expand_mesh(mesh, selection.size(), selection.size(), 0, 0);
const IndexRange new_vert_range{orig_vert_size, selection.size()};
const IndexRange new_edge_range{orig_edge_size, selection.size()};
- MutableSpan<MVert> new_verts = mesh_verts(mesh).slice(new_vert_range);
- MutableSpan<MEdge> new_edges = mesh_edges(mesh).slice(new_edge_range);
+ MutableSpan<MVert> new_verts = mesh.verts_for_write().slice(new_vert_range);
+ MutableSpan<MEdge> new_edges = mesh.edges_for_write().slice(new_edge_range);
for (const int i_selection : selection.index_range()) {
new_edges[i_selection] = new_loose_edge(selection[i_selection], new_vert_range[i_selection]);
}
- MutableAttributeAccessor attributes = *component.attributes_for_write();
+ MutableAttributeAccessor attributes = mesh.attributes_for_write();
attributes.for_all([&](const AttributeIDRef &id, const AttributeMetaData meta_data) {
if (!ELEM(meta_data.domain, ATTR_DOMAIN_POINT, ATTR_DOMAIN_EDGE)) {
return true;
}
+ if (meta_data.data_type == CD_PROP_STRING) {
+ return true;
+ }
GSpanAttributeWriter attribute = attributes.lookup_or_add_for_write_span(
id, meta_data.domain, meta_data.data_type);
- attribute_math::convert_to_static_type(meta_data.data_type, [&](auto dummy) {
- using T = decltype(dummy);
- MutableSpan<T> data = attribute.span.typed<T>();
- switch (attribute.domain) {
- case ATTR_DOMAIN_POINT: {
- /* New vertices copy the attribute values from their source vertex. */
- copy_with_mask(data.slice(new_vert_range), data.as_span(), selection);
- break;
- }
- case ATTR_DOMAIN_EDGE: {
+ switch (attribute.domain) {
+ case ATTR_DOMAIN_POINT:
+ /* New vertices copy the attribute values from their source vertex. */
+ array_utils::gather(attribute.span, selection, attribute.span.slice(new_vert_range));
+ break;
+ case ATTR_DOMAIN_EDGE:
+ attribute_math::convert_to_static_type(meta_data.data_type, [&](auto dummy) {
+ using T = decltype(dummy);
+ MutableSpan<T> data = attribute.span.typed<T>();
/* New edge values are mixed from of all the edges connected to the source vertex. */
copy_with_mixing(data.slice(new_edge_range), data.as_span(), [&](const int i) {
return vert_to_edge_map[selection[i]].as_span();
});
- break;
- }
- default:
- BLI_assert_unreachable();
- }
- });
+ });
+ break;
+ default:
+ BLI_assert_unreachable();
+ }
attribute.finish();
return true;
@@ -324,13 +283,16 @@ static void extrude_mesh_vertices(MeshComponent &component,
MutableSpan<int> vert_orig_indices = get_orig_index_layer(mesh, ATTR_DOMAIN_POINT);
vert_orig_indices.slice(new_vert_range).fill(ORIGINDEX_NONE);
+ MutableSpan<int> new_edge_orig_indices = get_orig_index_layer(mesh, ATTR_DOMAIN_EDGE);
+ new_edge_orig_indices.slice(new_edge_range).fill(ORIGINDEX_NONE);
+
if (attribute_outputs.top_id) {
save_selection_as_attribute(
- component, attribute_outputs.top_id.get(), ATTR_DOMAIN_POINT, new_vert_range);
+ mesh, attribute_outputs.top_id.get(), ATTR_DOMAIN_POINT, new_vert_range);
}
if (attribute_outputs.side_id) {
save_selection_as_attribute(
- component, attribute_outputs.side_id.get(), ATTR_DOMAIN_EDGE, new_edge_range);
+ mesh, attribute_outputs.side_id.get(), ATTR_DOMAIN_EDGE, new_edge_range);
}
BKE_mesh_runtime_clear_cache(&mesh);
@@ -338,8 +300,8 @@ static void extrude_mesh_vertices(MeshComponent &component,
static Array<Vector<int, 2>> mesh_calculate_polys_of_edge(const Mesh &mesh)
{
- Span<MPoly> polys = mesh_polys(mesh);
- Span<MLoop> loops = mesh_loops(mesh);
+ Span<MPoly> polys = mesh.polys();
+ Span<MLoop> loops = mesh.loops();
Array<Vector<int, 2>> polys_of_edge(mesh.totedge);
for (const int i_poly : polys.index_range()) {
@@ -397,29 +359,29 @@ template<typename T>
static VectorSet<int> vert_indices_from_edges(const Mesh &mesh, const Span<T> edge_indices)
{
static_assert(is_same_any_v<T, int, int64_t>);
+ const Span<MEdge> edges = mesh.edges();
VectorSet<int> vert_indices;
vert_indices.reserve(edge_indices.size());
for (const T i_edge : edge_indices) {
- const MEdge &edge = mesh.medge[i_edge];
+ const MEdge &edge = edges[i_edge];
vert_indices.add(edge.v1);
vert_indices.add(edge.v2);
}
return vert_indices;
}
-static void extrude_mesh_edges(MeshComponent &component,
+static void extrude_mesh_edges(Mesh &mesh,
const Field<bool> &selection_field,
const Field<float3> &offset_field,
const AttributeOutputs &attribute_outputs)
{
- Mesh &mesh = *component.get_for_write();
const int orig_vert_size = mesh.totvert;
- Span<MEdge> orig_edges = mesh_edges(mesh);
- Span<MPoly> orig_polys = mesh_polys(mesh);
+ Span<MEdge> orig_edges = mesh.edges();
+ Span<MPoly> orig_polys = mesh.polys();
const int orig_loop_size = mesh.totloop;
- GeometryComponentFieldContext edge_context{component, ATTR_DOMAIN_EDGE};
+ bke::MeshFieldContext edge_context{mesh, ATTR_DOMAIN_EDGE};
FieldEvaluator edge_evaluator{edge_context, mesh.totedge};
edge_evaluator.set_selection(selection_field);
edge_evaluator.add(offset_field);
@@ -437,7 +399,7 @@ static void extrude_mesh_edges(MeshComponent &component,
Array<float3> vert_offsets;
if (!edge_offsets.is_single()) {
vert_offsets.reinitialize(orig_vert_size);
- attribute_math::DefaultPropatationMixer<float3> mixer(vert_offsets);
+ attribute_math::DefaultPropagationMixer<float3> mixer(vert_offsets);
for (const int i_edge : edge_selection) {
const MEdge &edge = orig_edges[i_edge];
const float3 offset = edge_offsets[i_edge];
@@ -465,12 +427,12 @@ static void extrude_mesh_edges(MeshComponent &component,
new_poly_range.size(),
new_loop_range.size());
- MutableSpan<MVert> new_verts = mesh_verts(mesh).slice(new_vert_range);
- MutableSpan<MEdge> connect_edges = mesh_edges(mesh).slice(connect_edge_range);
- MutableSpan<MEdge> duplicate_edges = mesh_edges(mesh).slice(duplicate_edge_range);
- MutableSpan<MPoly> polys = mesh_polys(mesh);
+ MutableSpan<MEdge> edges = mesh.edges_for_write();
+ MutableSpan<MEdge> connect_edges = edges.slice(connect_edge_range);
+ MutableSpan<MEdge> duplicate_edges = edges.slice(duplicate_edge_range);
+ MutableSpan<MPoly> polys = mesh.polys_for_write();
MutableSpan<MPoly> new_polys = polys.slice(new_poly_range);
- MutableSpan<MLoop> loops = mesh_loops(mesh);
+ MutableSpan<MLoop> loops = mesh.loops_for_write();
MutableSpan<MLoop> new_loops = loops.slice(new_loop_range);
for (const int i : connect_edges.index_range()) {
@@ -478,7 +440,7 @@ static void extrude_mesh_edges(MeshComponent &component,
}
for (const int i : duplicate_edges.index_range()) {
- const MEdge &orig_edge = mesh.medge[edge_selection[i]];
+ const MEdge &orig_edge = edges[edge_selection[i]];
const int i_new_vert_1 = new_vert_indices.index_of(orig_edge.v1);
const int i_new_vert_2 = new_vert_indices.index_of(orig_edge.v2);
duplicate_edges[i] = new_edge(new_vert_range[i_new_vert_1], new_vert_range[i_new_vert_2]);
@@ -525,9 +487,12 @@ static void extrude_mesh_edges(MeshComponent &component,
const Array<Vector<int>> new_vert_to_duplicate_edge_map = create_vert_to_edge_map(
new_vert_range.size(), duplicate_edges, orig_vert_size);
- MutableAttributeAccessor attributes = *component.attributes_for_write();
+ MutableAttributeAccessor attributes = mesh.attributes_for_write();
attributes.for_all([&](const AttributeIDRef &id, const AttributeMetaData meta_data) {
+ if (meta_data.data_type == CD_PROP_STRING) {
+ return true;
+ }
GSpanAttributeWriter attribute = attributes.lookup_or_add_for_write_span(
id, meta_data.domain, meta_data.data_type);
if (!attribute) {
@@ -540,13 +505,14 @@ static void extrude_mesh_edges(MeshComponent &component,
switch (attribute.domain) {
case ATTR_DOMAIN_POINT: {
/* New vertices copy the attribute values from their source vertex. */
- copy_with_indices(data.slice(new_vert_range), data.as_span(), new_vert_indices);
+ array_utils::gather(
+ data.as_span(), new_vert_indices.as_span(), data.slice(new_vert_range));
break;
}
case ATTR_DOMAIN_EDGE: {
/* Edges parallel to original edges copy the edge attributes from the original edges. */
MutableSpan<T> duplicate_data = data.slice(duplicate_edge_range);
- copy_with_mask(duplicate_data, data.as_span(), edge_selection);
+ array_utils::gather(data.as_span(), edge_selection, duplicate_data);
/* Edges connected to original vertices mix values of selected connected edges. */
MutableSpan<T> connect_data = data.slice(connect_edge_range);
@@ -583,7 +549,7 @@ static void extrude_mesh_edges(MeshComponent &component,
/* Both corners on each vertical edge of the side polygon get the same value,
* so there are only two unique values to mix. */
Array<T> side_poly_corner_data(2);
- attribute_math::DefaultPropatationMixer<T> mixer{side_poly_corner_data};
+ attribute_math::DefaultPropagationMixer<T> mixer{side_poly_corner_data};
const MEdge &duplicate_edge = duplicate_edges[i_edge_selection];
const int new_vert_1 = duplicate_edge.v1;
@@ -633,6 +599,7 @@ static void extrude_mesh_edges(MeshComponent &component,
return true;
});
+ MutableSpan<MVert> new_verts = mesh.verts_for_write().slice(new_vert_range);
if (edge_offsets.is_single()) {
const float3 offset = edge_offsets.get_internal_single();
threading::parallel_for(new_verts.index_range(), 1024, [&](const IndexRange range) {
@@ -656,13 +623,16 @@ static void extrude_mesh_edges(MeshComponent &component,
edge_orig_indices.slice(connect_edge_range).fill(ORIGINDEX_NONE);
edge_orig_indices.slice(duplicate_edge_range).fill(ORIGINDEX_NONE);
+ MutableSpan<int> poly_orig_indices = get_orig_index_layer(mesh, ATTR_DOMAIN_FACE);
+ poly_orig_indices.slice(new_poly_range).fill(ORIGINDEX_NONE);
+
if (attribute_outputs.top_id) {
save_selection_as_attribute(
- component, attribute_outputs.top_id.get(), ATTR_DOMAIN_EDGE, duplicate_edge_range);
+ mesh, attribute_outputs.top_id.get(), ATTR_DOMAIN_EDGE, duplicate_edge_range);
}
if (attribute_outputs.side_id) {
save_selection_as_attribute(
- component, attribute_outputs.side_id.get(), ATTR_DOMAIN_FACE, new_poly_range);
+ mesh, attribute_outputs.side_id.get(), ATTR_DOMAIN_FACE, new_poly_range);
}
BKE_mesh_runtime_clear_cache(&mesh);
@@ -672,18 +642,17 @@ static void extrude_mesh_edges(MeshComponent &component,
* Edges connected to one selected face are on the boundary of a region and will be duplicated into
* a "side face". Edges inside a region will be duplicated to leave any original faces unchanged.
*/
-static void extrude_mesh_face_regions(MeshComponent &component,
+static void extrude_mesh_face_regions(Mesh &mesh,
const Field<bool> &selection_field,
const Field<float3> &offset_field,
const AttributeOutputs &attribute_outputs)
{
- Mesh &mesh = *component.get_for_write();
const int orig_vert_size = mesh.totvert;
- Span<MEdge> orig_edges = mesh_edges(mesh);
- Span<MPoly> orig_polys = mesh_polys(mesh);
- Span<MLoop> orig_loops = mesh_loops(mesh);
+ Span<MEdge> orig_edges = mesh.edges();
+ Span<MPoly> orig_polys = mesh.polys();
+ Span<MLoop> orig_loops = mesh.loops();
- GeometryComponentFieldContext poly_context{component, ATTR_DOMAIN_FACE};
+ bke::MeshFieldContext poly_context{mesh, ATTR_DOMAIN_FACE};
FieldEvaluator poly_evaluator{poly_context, mesh.totpoly};
poly_evaluator.set_selection(selection_field);
poly_evaluator.add(offset_field);
@@ -705,7 +674,7 @@ static void extrude_mesh_face_regions(MeshComponent &component,
Array<float3> vert_offsets;
if (!poly_offsets.is_single()) {
vert_offsets.reinitialize(orig_vert_size);
- attribute_math::DefaultPropatationMixer<float3> mixer(vert_offsets);
+ attribute_math::DefaultPropagationMixer<float3> mixer(vert_offsets);
for (const int i_poly : poly_selection) {
const MPoly &poly = orig_polys[i_poly];
const float3 offset = poly_offsets[i_poly];
@@ -784,7 +753,7 @@ static void extrude_mesh_face_regions(MeshComponent &component,
/* The vertices attached to duplicate inner edges also have to be duplicated. */
for (const int i_edge : new_inner_edge_indices) {
- const MEdge &edge = mesh.medge[i_edge];
+ const MEdge &edge = orig_edges[i_edge];
new_vert_indices.add(edge.v1);
new_vert_indices.add(edge.v2);
}
@@ -808,13 +777,13 @@ static void extrude_mesh_face_regions(MeshComponent &component,
side_poly_range.size(),
side_loop_range.size());
- MutableSpan<MEdge> edges = mesh_edges(mesh);
+ MutableSpan<MEdge> edges = mesh.edges_for_write();
MutableSpan<MEdge> connect_edges = edges.slice(connect_edge_range);
MutableSpan<MEdge> boundary_edges = edges.slice(boundary_edge_range);
MutableSpan<MEdge> new_inner_edges = edges.slice(new_inner_edge_range);
- MutableSpan<MPoly> polys = mesh_polys(mesh);
+ MutableSpan<MPoly> polys = mesh.polys_for_write();
MutableSpan<MPoly> new_polys = polys.slice(side_poly_range);
- MutableSpan<MLoop> loops = mesh_loops(mesh);
+ MutableSpan<MLoop> loops = mesh.loops_for_write();
MutableSpan<MLoop> new_loops = loops.slice(side_loop_range);
/* Initialize the edges that form the sides of the extrusion. */
@@ -905,9 +874,12 @@ static void extrude_mesh_face_regions(MeshComponent &component,
const Array<Vector<int>> new_vert_to_duplicate_edge_map = create_vert_to_edge_map(
new_vert_range.size(), boundary_edges, orig_vert_size);
- MutableAttributeAccessor attributes = *component.attributes_for_write();
+ MutableAttributeAccessor attributes = mesh.attributes_for_write();
attributes.for_all([&](const AttributeIDRef &id, const AttributeMetaData meta_data) {
+ if (meta_data.data_type == CD_PROP_STRING) {
+ return true;
+ }
GSpanAttributeWriter attribute = attributes.lookup_or_add_for_write_span(
id, meta_data.domain, meta_data.data_type);
if (!attribute) {
@@ -920,17 +892,18 @@ static void extrude_mesh_face_regions(MeshComponent &component,
switch (attribute.domain) {
case ATTR_DOMAIN_POINT: {
/* New vertices copy the attributes from their original vertices. */
- copy_with_indices(data.slice(new_vert_range), data.as_span(), new_vert_indices);
+ array_utils::gather(
+ data.as_span(), new_vert_indices.as_span(), data.slice(new_vert_range));
break;
}
case ATTR_DOMAIN_EDGE: {
/* Edges parallel to original edges copy the edge attributes from the original edges. */
MutableSpan<T> boundary_data = data.slice(boundary_edge_range);
- copy_with_indices(boundary_data, data.as_span(), boundary_edge_indices);
+ array_utils::gather(data.as_span(), boundary_edge_indices.as_span(), boundary_data);
/* Edges inside of face regions also just duplicate their source data. */
MutableSpan<T> new_inner_data = data.slice(new_inner_edge_range);
- copy_with_indices(new_inner_data, data.as_span(), new_inner_edge_indices);
+ array_utils::gather(data.as_span(), new_inner_edge_indices.as_span(), new_inner_data);
/* Edges connected to original vertices mix values of selected connected edges. */
MutableSpan<T> connect_data = data.slice(connect_edge_range);
@@ -942,8 +915,8 @@ static void extrude_mesh_face_regions(MeshComponent &component,
case ATTR_DOMAIN_FACE: {
/* New faces on the side of extrusions get the values from the corresponding selected
* face. */
- copy_with_indices(
- data.slice(side_poly_range), data.as_span(), edge_extruded_face_indices);
+ array_utils::gather(
+ data.as_span(), edge_extruded_face_indices.as_span(), data.slice(side_poly_range));
break;
}
case ATTR_DOMAIN_CORNER: {
@@ -1003,13 +976,14 @@ static void extrude_mesh_face_regions(MeshComponent &component,
/* Translate vertices based on the offset. If the vertex is used by a selected edge, it will
* have been duplicated and only the new vertex should use the offset. Otherwise the vertex might
* still need an offset, but it was reused on the inside of a region of extruded faces. */
+ MutableSpan<MVert> verts = mesh.verts_for_write();
if (poly_offsets.is_single()) {
const float3 offset = poly_offsets.get_internal_single();
threading::parallel_for(
IndexRange(all_selected_verts.size()), 1024, [&](const IndexRange range) {
for (const int i_orig : all_selected_verts.as_span().slice(range)) {
const int i_new = new_vert_indices.index_of_try(i_orig);
- MVert &vert = mesh_verts(mesh)[(i_new == -1) ? i_orig : new_vert_range[i_new]];
+ MVert &vert = verts[(i_new == -1) ? i_orig : new_vert_range[i_new]];
add_v3_v3(vert.co, offset);
}
});
@@ -1020,7 +994,7 @@ static void extrude_mesh_face_regions(MeshComponent &component,
for (const int i_orig : all_selected_verts.as_span().slice(range)) {
const int i_new = new_vert_indices.index_of_try(i_orig);
const float3 offset = vert_offsets[i_orig];
- MVert &vert = mesh_verts(mesh)[(i_new == -1) ? i_orig : new_vert_range[i_new]];
+ MVert &vert = verts[(i_new == -1) ? i_orig : new_vert_range[i_new]];
add_v3_v3(vert.co, offset);
}
});
@@ -1039,11 +1013,11 @@ static void extrude_mesh_face_regions(MeshComponent &component,
if (attribute_outputs.top_id) {
save_selection_as_attribute(
- component, attribute_outputs.top_id.get(), ATTR_DOMAIN_FACE, poly_selection);
+ mesh, attribute_outputs.top_id.get(), ATTR_DOMAIN_FACE, poly_selection);
}
if (attribute_outputs.side_id) {
save_selection_as_attribute(
- component, attribute_outputs.side_id.get(), ATTR_DOMAIN_FACE, side_poly_range);
+ mesh, attribute_outputs.side_id.get(), ATTR_DOMAIN_FACE, side_poly_range);
}
BKE_mesh_runtime_clear_cache(&mesh);
@@ -1057,21 +1031,20 @@ static IndexRange selected_corner_range(Span<int> offsets, const int index)
return IndexRange(offset, next_offset - offset);
}
-static void extrude_individual_mesh_faces(MeshComponent &component,
+static void extrude_individual_mesh_faces(Mesh &mesh,
const Field<bool> &selection_field,
const Field<float3> &offset_field,
const AttributeOutputs &attribute_outputs)
{
- Mesh &mesh = *component.get_for_write();
const int orig_vert_size = mesh.totvert;
const int orig_edge_size = mesh.totedge;
- Span<MPoly> orig_polys = mesh_polys(mesh);
- Span<MLoop> orig_loops = mesh_loops(mesh);
+ Span<MPoly> orig_polys = mesh.polys();
+ Span<MLoop> orig_loops = mesh.loops();
/* Use a mesh for the result of the evaluation because the mesh is reallocated before
* the vertices are moved, and the evaluated result might reference an attribute. */
Array<float3> poly_offset(orig_polys.size());
- GeometryComponentFieldContext poly_context{component, ATTR_DOMAIN_FACE};
+ bke::MeshFieldContext poly_context{mesh, ATTR_DOMAIN_FACE};
FieldEvaluator poly_evaluator{poly_context, mesh.totpoly};
poly_evaluator.set_selection(selection_field);
poly_evaluator.add_with_destination(offset_field, poly_offset.as_mutable_span());
@@ -1105,13 +1078,13 @@ static void extrude_individual_mesh_faces(MeshComponent &component,
side_poly_range.size(),
side_loop_range.size());
- MutableSpan<MVert> new_verts = mesh_verts(mesh).slice(new_vert_range);
- MutableSpan<MEdge> edges{mesh.medge, mesh.totedge};
+ MutableSpan<MVert> new_verts = mesh.verts_for_write().slice(new_vert_range);
+ MutableSpan<MEdge> edges = mesh.edges_for_write();
MutableSpan<MEdge> connect_edges = edges.slice(connect_edge_range);
MutableSpan<MEdge> duplicate_edges = edges.slice(duplicate_edge_range);
- MutableSpan<MPoly> polys{mesh.mpoly, mesh.totpoly};
+ MutableSpan<MPoly> polys = mesh.polys_for_write();
MutableSpan<MPoly> new_polys = polys.slice(side_poly_range);
- MutableSpan<MLoop> loops{mesh.mloop, mesh.totloop};
+ MutableSpan<MLoop> loops = mesh.loops_for_write();
/* For every selected polygon, build the faces that form the sides of the extrusion. Filling some
* of this data like the new edges or polygons could be easily split into separate loops, which
@@ -1159,9 +1132,12 @@ static void extrude_individual_mesh_faces(MeshComponent &component,
}
});
- MutableAttributeAccessor attributes = *component.attributes_for_write();
+ MutableAttributeAccessor attributes = mesh.attributes_for_write();
attributes.for_all([&](const AttributeIDRef &id, const AttributeMetaData meta_data) {
+ if (meta_data.data_type == CD_PROP_STRING) {
+ return true;
+ }
GSpanAttributeWriter attribute = attributes.lookup_or_add_for_write_span(
id, meta_data.domain, meta_data.data_type);
if (!attribute) {
@@ -1318,11 +1294,11 @@ static void extrude_individual_mesh_faces(MeshComponent &component,
if (attribute_outputs.top_id) {
save_selection_as_attribute(
- component, attribute_outputs.top_id.get(), ATTR_DOMAIN_FACE, poly_selection);
+ mesh, attribute_outputs.top_id.get(), ATTR_DOMAIN_FACE, poly_selection);
}
if (attribute_outputs.side_id) {
save_selection_as_attribute(
- component, attribute_outputs.side_id.get(), ATTR_DOMAIN_FACE, side_poly_range);
+ mesh, attribute_outputs.side_id.get(), ATTR_DOMAIN_FACE, side_poly_range);
}
BKE_mesh_runtime_clear_cache(&mesh);
@@ -1335,7 +1311,7 @@ static void node_geo_exec(GeoNodeExecParams params)
Field<float3> offset_field = params.extract_input<Field<float3>>("Offset");
Field<float> scale_field = params.extract_input<Field<float>>("Offset Scale");
const NodeGeometryExtrudeMesh &storage = node_storage(params.node());
- GeometryNodeExtrudeMeshMode mode = static_cast<GeometryNodeExtrudeMeshMode>(storage.mode);
+ GeometryNodeExtrudeMeshMode mode = GeometryNodeExtrudeMeshMode(storage.mode);
/* Create a combined field from the offset and the scale so the field evaluator
* can take care of the multiplication and to simplify each extrude function. */
@@ -1359,27 +1335,26 @@ static void node_geo_exec(GeoNodeExecParams params)
params.extract_input<bool>("Individual");
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
- if (geometry_set.has_mesh()) {
- MeshComponent &component = geometry_set.get_component_for_write<MeshComponent>();
+ if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
switch (mode) {
case GEO_NODE_EXTRUDE_MESH_VERTICES:
- extrude_mesh_vertices(component, selection, final_offset, attribute_outputs);
+ extrude_mesh_vertices(*mesh, selection, final_offset, attribute_outputs);
break;
case GEO_NODE_EXTRUDE_MESH_EDGES:
- extrude_mesh_edges(component, selection, final_offset, attribute_outputs);
+ extrude_mesh_edges(*mesh, selection, final_offset, attribute_outputs);
break;
case GEO_NODE_EXTRUDE_MESH_FACES: {
if (extrude_individual) {
- extrude_individual_mesh_faces(component, selection, final_offset, attribute_outputs);
+ extrude_individual_mesh_faces(*mesh, selection, final_offset, attribute_outputs);
}
else {
- extrude_mesh_face_regions(component, selection, final_offset, attribute_outputs);
+ extrude_mesh_face_regions(*mesh, selection, final_offset, attribute_outputs);
}
break;
}
}
- BLI_assert(BKE_mesh_is_valid(component.get_for_write()));
+ BLI_assert(BKE_mesh_is_valid(mesh));
}
});
diff --git a/source/blender/nodes/geometry/nodes/node_geo_field_at_index.cc b/source/blender/nodes/geometry/nodes/node_geo_field_at_index.cc
index 64861e529bc..fc1e2cb2503 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_field_at_index.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_field_at_index.cc
@@ -9,17 +9,76 @@
#include "BLI_task.hh"
+#include "NOD_socket_search_link.hh"
+
+namespace blender::nodes {
+
+FieldAtIndexInput::FieldAtIndexInput(Field<int> index_field,
+ GField value_field,
+ eAttrDomain value_field_domain)
+ : bke::GeometryFieldInput(value_field.cpp_type(), "Field at Index"),
+ index_field_(std::move(index_field)),
+ value_field_(std::move(value_field)),
+ value_field_domain_(value_field_domain)
+{
+}
+
+GVArray FieldAtIndexInput::get_varray_for_context(const bke::GeometryFieldContext &context,
+ const IndexMask mask) const
+{
+ const std::optional<AttributeAccessor> attributes = context.attributes();
+ if (!attributes) {
+ return {};
+ }
+
+ const bke::GeometryFieldContext value_field_context{
+ context.geometry(), context.type(), value_field_domain_};
+ FieldEvaluator value_evaluator{value_field_context,
+ attributes->domain_size(value_field_domain_)};
+ value_evaluator.add(value_field_);
+ value_evaluator.evaluate();
+ const GVArray &values = value_evaluator.get_evaluated(0);
+
+ FieldEvaluator index_evaluator{context, &mask};
+ index_evaluator.add(index_field_);
+ index_evaluator.evaluate();
+ const VArray<int> indices = index_evaluator.get_evaluated<int>(0);
+
+ GVArray output_array;
+ attribute_math::convert_to_static_type(*type_, [&](auto dummy) {
+ using T = decltype(dummy);
+ Array<T> dst_array(mask.min_array_size());
+ VArray<T> src_values = values.typed<T>();
+ threading::parallel_for(mask.index_range(), 1024, [&](const IndexRange range) {
+ for (const int i : mask.slice(range)) {
+ const int index = indices[i];
+ if (src_values.index_range().contains(index)) {
+ dst_array[i] = src_values[index];
+ }
+ else {
+ dst_array[i] = {};
+ }
+ }
+ });
+ output_array = VArray<T>::ForContainer(std::move(dst_array));
+ });
+
+ return output_array;
+}
+
+} // namespace blender::nodes
+
namespace blender::nodes::node_geo_field_at_index_cc {
static void node_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Int>(N_("Index")).min(0).supports_field();
- b.add_input<decl::Float>(N_("Value"), "Value_Float").supports_field();
- b.add_input<decl::Int>(N_("Value"), "Value_Int").supports_field();
- b.add_input<decl::Vector>(N_("Value"), "Value_Vector").supports_field();
- b.add_input<decl::Color>(N_("Value"), "Value_Color").supports_field();
- b.add_input<decl::Bool>(N_("Value"), "Value_Bool").supports_field();
+ b.add_input<decl::Float>(N_("Value"), "Value_Float").hide_value().supports_field();
+ b.add_input<decl::Int>(N_("Value"), "Value_Int").hide_value().supports_field();
+ b.add_input<decl::Vector>(N_("Value"), "Value_Vector").hide_value().supports_field();
+ b.add_input<decl::Color>(N_("Value"), "Value_Color").hide_value().supports_field();
+ b.add_input<decl::Bool>(N_("Value"), "Value_Bool").hide_value().supports_field();
b.add_output<decl::Float>(N_("Value"), "Value_Float").field_source();
b.add_output<decl::Int>(N_("Value"), "Value_Int").field_source();
@@ -28,13 +87,13 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Bool>(N_("Value"), "Value_Bool").field_source();
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE);
uiItemR(layout, ptr, "domain", 0, "", ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
node->custom1 = ATTR_DOMAIN_POINT;
node->custom2 = CD_PROP_FLOAT;
@@ -42,7 +101,7 @@ static void node_init(bNodeTree *UNUSED(tree), bNode *node)
static void node_update(bNodeTree *ntree, bNode *node)
{
- const eCustomDataType data_type = static_cast<eCustomDataType>(node->custom2);
+ const eCustomDataType data_type = eCustomDataType(node->custom2);
bNodeSocket *sock_index = static_cast<bNodeSocket *>(node->inputs.first);
bNodeSocket *sock_in_float = sock_index->next;
@@ -70,60 +129,22 @@ static void node_update(bNodeTree *ntree, bNode *node)
nodeSetSocketAvailability(ntree, sock_out_bool, data_type == CD_PROP_BOOL);
}
-class FieldAtIndex final : public GeometryFieldInput {
- private:
- Field<int> index_field_;
- GField value_field_;
- eAttrDomain value_field_domain_;
-
- public:
- FieldAtIndex(Field<int> index_field, GField value_field, eAttrDomain value_field_domain)
- : GeometryFieldInput(value_field.cpp_type(), "Field at Index"),
- index_field_(std::move(index_field)),
- value_field_(std::move(value_field)),
- value_field_domain_(value_field_domain)
- {
- }
-
- GVArray get_varray_for_context(const GeometryComponent &component,
- const eAttrDomain domain,
- IndexMask mask) const final
- {
- const GeometryComponentFieldContext value_field_context{component, value_field_domain_};
- FieldEvaluator value_evaluator{value_field_context,
- component.attribute_domain_size(value_field_domain_)};
- value_evaluator.add(value_field_);
- value_evaluator.evaluate();
- const GVArray &values = value_evaluator.get_evaluated(0);
-
- const GeometryComponentFieldContext index_field_context{component, domain};
- FieldEvaluator index_evaluator{index_field_context, &mask};
- index_evaluator.add(index_field_);
- index_evaluator.evaluate();
- const VArray<int> indices = index_evaluator.get_evaluated<int>(0);
-
- GVArray output_array;
- attribute_math::convert_to_static_type(*type_, [&](auto dummy) {
- using T = decltype(dummy);
- Array<T> dst_array(mask.min_array_size());
- VArray<T> src_values = values.typed<T>();
- threading::parallel_for(mask.index_range(), 1024, [&](const IndexRange range) {
- for (const int i : mask.slice(range)) {
- const int index = indices[i];
- if (index >= 0 && index < src_values.size()) {
- dst_array[i] = src_values[index];
- }
- else {
- dst_array[i] = {};
- }
- }
- });
- output_array = VArray<T>::ForContainer(std::move(dst_array));
+static void node_gather_link_searches(GatherLinkSearchOpParams &params)
+{
+ const NodeDeclaration &declaration = *params.node_type().fixed_declaration;
+ search_link_ops_for_declarations(params, declaration.inputs().take_front(1));
+
+ const bNodeType &node_type = params.node_type();
+ const std::optional<eCustomDataType> type = node_data_type_to_custom_data_type(
+ (eNodeSocketDatatype)params.other_socket().type);
+ if (type && *type != CD_PROP_STRING) {
+ params.add_item(IFACE_("Value"), [node_type, type](LinkSearchOpParams &params) {
+ bNode &node = params.add_node(node_type);
+ node.custom2 = *type;
+ params.update_and_connect_available_socket(node, "Value");
});
-
- return output_array;
}
-};
+}
static StringRefNull identifier_suffix(eCustomDataType data_type)
{
@@ -147,16 +168,16 @@ static StringRefNull identifier_suffix(eCustomDataType data_type)
static void node_geo_exec(GeoNodeExecParams params)
{
const bNode &node = params.node();
- const eAttrDomain domain = static_cast<eAttrDomain>(node.custom1);
- const eCustomDataType data_type = static_cast<eCustomDataType>(node.custom2);
+ const eAttrDomain domain = eAttrDomain(node.custom1);
+ const eCustomDataType data_type = eCustomDataType(node.custom2);
Field<int> index_field = params.extract_input<Field<int>>("Index");
attribute_math::convert_to_static_type(data_type, [&](auto dummy) {
using T = decltype(dummy);
static const std::string identifier = "Value_" + identifier_suffix(data_type);
Field<T> value_field = params.extract_input<Field<T>>(identifier);
- Field<T> output_field{
- std::make_shared<FieldAtIndex>(std::move(index_field), std::move(value_field), domain)};
+ Field<T> output_field{std::make_shared<FieldAtIndexInput>(
+ std::move(index_field), std::move(value_field), domain)};
params.set_output(identifier, std::move(output_field));
});
}
@@ -175,5 +196,6 @@ void register_node_type_geo_field_at_index()
ntype.draw_buttons = file_ns::node_layout;
ntype.initfunc = file_ns::node_init;
ntype.updatefunc = file_ns::node_update;
+ ntype.gather_link_search_ops = file_ns::node_gather_link_searches;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_flip_faces.cc b/source/blender/nodes/geometry/nodes/node_geo_flip_faces.cc
index 15b2822805a..95a0013a9e1 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_flip_faces.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_flip_faces.cc
@@ -19,24 +19,19 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Mesh"));
}
-static void mesh_flip_faces(MeshComponent &component, const Field<bool> &selection_field)
+static void mesh_flip_faces(Mesh &mesh, const Field<bool> &selection_field)
{
- GeometryComponentFieldContext field_context{component, ATTR_DOMAIN_FACE};
- const int domain_size = component.attribute_domain_size(ATTR_DOMAIN_FACE);
- if (domain_size == 0) {
+ if (mesh.totpoly == 0) {
return;
}
- fn::FieldEvaluator evaluator{field_context, domain_size};
+ bke::MeshFieldContext field_context{mesh, ATTR_DOMAIN_FACE};
+ fn::FieldEvaluator evaluator{field_context, mesh.totpoly};
evaluator.add(selection_field);
evaluator.evaluate();
const IndexMask selection = evaluator.get_evaluated_as_mask(0);
- Mesh *mesh = component.get_for_write();
-
- mesh->mloop = (MLoop *)CustomData_duplicate_referenced_layer(
- &mesh->ldata, CD_MLOOP, mesh->totloop);
- Span<MPoly> polys{mesh->mpoly, mesh->totpoly};
- MutableSpan<MLoop> loops{mesh->mloop, mesh->totloop};
+ const Span<MPoly> polys = mesh.polys();
+ MutableSpan<MLoop> loops = mesh.loops_for_write();
for (const int i : selection.index_range()) {
const MPoly &poly = polys[selection[i]];
@@ -49,9 +44,12 @@ static void mesh_flip_faces(MeshComponent &component, const Field<bool> &selecti
}
}
- MutableAttributeAccessor attributes = *component.attributes_for_write();
+ MutableAttributeAccessor attributes = mesh.attributes_for_write();
attributes.for_all(
[&](const bke::AttributeIDRef &attribute_id, const AttributeMetaData &meta_data) {
+ if (meta_data.data_type == CD_PROP_STRING) {
+ return true;
+ }
if (meta_data.domain == ATTR_DOMAIN_CORNER) {
GSpanAttributeWriter attribute = attributes.lookup_or_add_for_write_span(
attribute_id, ATTR_DOMAIN_CORNER, meta_data.data_type);
@@ -76,11 +74,9 @@ static void node_geo_exec(GeoNodeExecParams params)
const Field<bool> selection_field = params.extract_input<Field<bool>>("Selection");
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
- if (!geometry_set.has_mesh()) {
- return;
+ if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
+ mesh_flip_faces(*mesh, selection_field);
}
- MeshComponent &mesh_component = geometry_set.get_component_for_write<MeshComponent>();
- mesh_flip_faces(mesh_component, selection_field);
});
params.set_output("Mesh", std::move(geometry_set));
diff --git a/source/blender/nodes/geometry/nodes/node_geo_geometry_to_instance.cc b/source/blender/nodes/geometry/nodes/node_geo_geometry_to_instance.cc
index 1f84f8f288d..45808ff9996 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_geometry_to_instance.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_geometry_to_instance.cc
@@ -1,5 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "BKE_instances.hh"
+
#include "node_geometry_util.hh"
namespace blender::nodes::node_geo_geometry_to_instance_cc {
@@ -12,16 +14,14 @@ static void node_declare(NodeDeclarationBuilder &b)
static void node_geo_exec(GeoNodeExecParams params)
{
- Vector<GeometrySet> geometries = params.extract_multi_input<GeometrySet>("Geometry");
- GeometrySet instances_geometry;
- InstancesComponent &instances_component =
- instances_geometry.get_component_for_write<InstancesComponent>();
+ Vector<GeometrySet> geometries = params.extract_input<Vector<GeometrySet>>("Geometry");
+ std::unique_ptr<bke::Instances> instances = std::make_unique<bke::Instances>();
for (GeometrySet &geometry : geometries) {
geometry.ensure_owns_direct_data();
- const int handle = instances_component.add_reference(std::move(geometry));
- instances_component.add_instance(handle, float4x4::identity());
+ const int handle = instances->add_reference(std::move(geometry));
+ instances->add_instance(handle, float4x4::identity());
}
- params.set_output("Instances", std::move(instances_geometry));
+ params.set_output("Instances", GeometrySet::create_with_instances(instances.release()));
}
} // namespace blender::nodes::node_geo_geometry_to_instance_cc
diff --git a/source/blender/nodes/geometry/nodes/node_geo_image_texture.cc b/source/blender/nodes/geometry/nodes/node_geo_image_texture.cc
index 33802d00d2b..f39337d3fc3 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_image_texture.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_image_texture.cc
@@ -24,20 +24,20 @@ static void node_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Image>(N_("Image")).hide_label();
b.add_input<decl::Vector>(N_("Vector"))
- .implicit_field()
- .description(("Texture coordinates from 0 to 1"));
+ .implicit_field(implicit_field_inputs::position)
+ .description("Texture coordinates from 0 to 1");
b.add_input<decl::Int>(N_("Frame")).min(0).max(MAXFRAMEF);
b.add_output<decl::Color>(N_("Color")).no_muted_links().dependent_field();
b.add_output<decl::Float>(N_("Alpha")).no_muted_links().dependent_field();
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "interpolation", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
uiItemR(layout, ptr, "extension", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryImageTexture *tex = MEM_cnew<NodeGeometryImageTexture>(__func__);
node->storage = tex;
@@ -122,9 +122,9 @@ class ImageFieldsFunction : public fn::MultiFunction {
static float frac(const float x, int *ix)
{
- const int i = (int)x - ((x < 0.0f) ? 1 : 0);
+ const int i = int(x) - ((x < 0.0f) ? 1 : 0);
*ix = i;
- return x - (float)i;
+ return x - float(i);
}
static float4 image_cubic_texture_lookup(const ImBuf *ibuf,
@@ -135,8 +135,8 @@ class ImageFieldsFunction : public fn::MultiFunction {
const int width = ibuf->x;
const int height = ibuf->y;
int pix, piy, nix, niy;
- const float tx = frac(px * (float)width - 0.5f, &pix);
- const float ty = frac(py * (float)height - 0.5f, &piy);
+ const float tx = frac(px * float(width) - 0.5f, &pix);
+ const float ty = frac(py * float(height) - 0.5f, &piy);
int ppix, ppiy, nnix, nniy;
switch (extension) {
@@ -189,22 +189,22 @@ class ImageFieldsFunction : public fn::MultiFunction {
v[2] = ((-0.5f * ty + 0.5f) * ty + 0.5f) * ty + (1.0f / 6.0f);
v[3] = (1.0f / 6.0f) * ty * ty * ty;
- return (v[0] * (u[0] * (image_pixel_lookup(ibuf, xc[0], yc[0])) +
- u[1] * (image_pixel_lookup(ibuf, xc[1], yc[0])) +
- u[2] * (image_pixel_lookup(ibuf, xc[2], yc[0])) +
- u[3] * (image_pixel_lookup(ibuf, xc[3], yc[0])))) +
- (v[1] * (u[0] * (image_pixel_lookup(ibuf, xc[0], yc[1])) +
- u[1] * (image_pixel_lookup(ibuf, xc[1], yc[1])) +
- u[2] * (image_pixel_lookup(ibuf, xc[2], yc[1])) +
- u[3] * (image_pixel_lookup(ibuf, xc[3], yc[1])))) +
- (v[2] * (u[0] * (image_pixel_lookup(ibuf, xc[0], yc[2])) +
- u[1] * (image_pixel_lookup(ibuf, xc[1], yc[2])) +
- u[2] * (image_pixel_lookup(ibuf, xc[2], yc[2])) +
- u[3] * (image_pixel_lookup(ibuf, xc[3], yc[2])))) +
- (v[3] * (u[0] * (image_pixel_lookup(ibuf, xc[0], yc[3])) +
- u[1] * (image_pixel_lookup(ibuf, xc[1], yc[3])) +
- u[2] * (image_pixel_lookup(ibuf, xc[2], yc[3])) +
- u[3] * (image_pixel_lookup(ibuf, xc[3], yc[3]))));
+ return (v[0] * (u[0] * image_pixel_lookup(ibuf, xc[0], yc[0]) +
+ u[1] * image_pixel_lookup(ibuf, xc[1], yc[0]) +
+ u[2] * image_pixel_lookup(ibuf, xc[2], yc[0]) +
+ u[3] * image_pixel_lookup(ibuf, xc[3], yc[0]))) +
+ (v[1] * (u[0] * image_pixel_lookup(ibuf, xc[0], yc[1]) +
+ u[1] * image_pixel_lookup(ibuf, xc[1], yc[1]) +
+ u[2] * image_pixel_lookup(ibuf, xc[2], yc[1]) +
+ u[3] * image_pixel_lookup(ibuf, xc[3], yc[1]))) +
+ (v[2] * (u[0] * image_pixel_lookup(ibuf, xc[0], yc[2]) +
+ u[1] * image_pixel_lookup(ibuf, xc[1], yc[2]) +
+ u[2] * image_pixel_lookup(ibuf, xc[2], yc[2]) +
+ u[3] * image_pixel_lookup(ibuf, xc[3], yc[2]))) +
+ (v[3] * (u[0] * image_pixel_lookup(ibuf, xc[0], yc[3]) +
+ u[1] * image_pixel_lookup(ibuf, xc[1], yc[3]) +
+ u[2] * image_pixel_lookup(ibuf, xc[2], yc[3]) +
+ u[3] * image_pixel_lookup(ibuf, xc[3], yc[3])));
}
static float4 image_linear_texture_lookup(const ImBuf *ibuf,
@@ -215,8 +215,8 @@ class ImageFieldsFunction : public fn::MultiFunction {
const int width = ibuf->x;
const int height = ibuf->y;
int pix, piy, nix, niy;
- const float nfx = frac(px * (float)width - 0.5f, &pix);
- const float nfy = frac(py * (float)height - 0.5f, &piy);
+ const float nfx = frac(px * float(width) - 0.5f, &pix);
+ const float nfy = frac(py * float(height) - 0.5f, &piy);
switch (extension) {
case SHD_IMAGE_EXTENSION_CLIP: {
@@ -257,8 +257,8 @@ class ImageFieldsFunction : public fn::MultiFunction {
const int width = ibuf->x;
const int height = ibuf->y;
int ix, iy;
- const float tx = frac(px * (float)width, &ix);
- const float ty = frac(py * (float)height, &iy);
+ const float tx = frac(px * float(width), &ix);
+ const float ty = frac(py * float(height), &iy);
switch (extension) {
case SHD_IMAGE_EXTENSION_REPEAT: {
@@ -285,14 +285,14 @@ class ImageFieldsFunction : public fn::MultiFunction {
}
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
const VArray<float3> &vectors = params.readonly_single_input<float3>(0, "Vector");
MutableSpan<ColorGeometry4f> r_color = params.uninitialized_single_output<ColorGeometry4f>(
1, "Color");
MutableSpan<float> r_alpha = params.uninitialized_single_output_if_required<float>(2, "Alpha");
- MutableSpan<float4> color_data{(float4 *)r_color.data(), r_color.size()};
+ MutableSpan<float4> color_data{reinterpret_cast<float4 *>(r_color.data()), r_color.size()};
/* Sample image texture. */
switch (interpolation_) {
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_curve_handles.cc b/source/blender/nodes/geometry/nodes/node_geo_input_curve_handles.cc
index bc1b9e940a1..2979d0e4639 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_input_curve_handles.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_curve_handles.cc
@@ -1,5 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "BKE_curves.hh"
+
#include "node_geometry_util.hh"
namespace blender::nodes::node_geo_input_curve_handles_cc {
@@ -15,31 +17,27 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Vector>(N_("Right")).field_source();
}
-class HandlePositionFieldInput final : public GeometryFieldInput {
+class HandlePositionFieldInput final : public bke::CurvesFieldInput {
Field<bool> relative_;
bool left_;
public:
HandlePositionFieldInput(Field<bool> relative, bool left)
- : GeometryFieldInput(CPPType::get<float3>(), "Handle"), relative_(relative), left_(left)
+ : bke::CurvesFieldInput(CPPType::get<float3>(), "Handle"), relative_(relative), left_(left)
{
}
- GVArray get_varray_for_context(const GeometryComponent &component,
+ GVArray get_varray_for_context(const bke::CurvesGeometry &curves,
const eAttrDomain domain,
- IndexMask mask) const final
+ const IndexMask mask) const final
{
- if (component.type() != GEO_COMPONENT_TYPE_CURVE) {
- return {};
- }
-
- GeometryComponentFieldContext field_context{component, ATTR_DOMAIN_POINT};
+ bke::CurvesFieldContext field_context{curves, ATTR_DOMAIN_POINT};
fn::FieldEvaluator evaluator(field_context, &mask);
evaluator.add(relative_);
evaluator.evaluate();
const VArray<bool> relative = evaluator.get_evaluated<bool>(0);
- const AttributeAccessor attributes = *component.attributes();
+ const AttributeAccessor attributes = curves.attributes();
VArray<float3> positions = attributes.lookup_or_default<float3>(
"position", ATTR_DOMAIN_POINT, {0, 0, 0});
@@ -69,7 +67,7 @@ class HandlePositionFieldInput final : public GeometryFieldInput {
output[i] = handles[i];
}
}
- return component.attributes()->adapt_domain<float3>(
+ return attributes.adapt_domain<float3>(
VArray<float3>::ForContainer(std::move(output)), ATTR_DOMAIN_POINT, domain);
}
@@ -86,6 +84,11 @@ class HandlePositionFieldInput final : public GeometryFieldInput {
}
return false;
}
+
+ std::optional<eAttrDomain> preferred_domain(const CurvesGeometry & /*curves*/) const
+ {
+ return ATTR_DOMAIN_POINT;
+ }
};
static void node_geo_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_instance_rotation.cc b/source/blender/nodes/geometry/nodes/node_geo_input_instance_rotation.cc
index 4c7a148a797..f78815ebe74 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_input_instance_rotation.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_instance_rotation.cc
@@ -2,6 +2,8 @@
#include "node_geometry_util.hh"
+#include "BKE_instances.hh"
+
namespace blender::nodes::node_geo_input_instance_rotation_cc {
static void node_declare(NodeDeclarationBuilder &b)
@@ -9,28 +11,17 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Vector>(N_("Rotation")).field_source();
}
-class VectorFieldInput final : public GeometryFieldInput {
+class InstanceRotationFieldInput final : public bke::InstancesFieldInput {
public:
- VectorFieldInput() : GeometryFieldInput(CPPType::get<float3>(), "Rotation")
+ InstanceRotationFieldInput() : bke::InstancesFieldInput(CPPType::get<float3>(), "Rotation")
{
}
- GVArray get_varray_for_context(const GeometryComponent &component,
- const eAttrDomain UNUSED(domain),
- IndexMask UNUSED(mask)) const final
+ GVArray get_varray_for_context(const bke::Instances &instances, IndexMask /*mask*/) const final
{
- if (component.type() != GEO_COMPONENT_TYPE_INSTANCES) {
- return {};
- }
-
- const InstancesComponent &instance_component = static_cast<const InstancesComponent &>(
- component);
-
- auto rotation_fn = [&](const int i) -> float3 {
- return instance_component.instance_transforms()[i].to_euler();
- };
+ auto rotation_fn = [&](const int i) -> float3 { return instances.transforms()[i].to_euler(); };
- return VArray<float3>::ForFunc(instance_component.instances_num(), rotation_fn);
+ return VArray<float3>::ForFunc(instances.instances_num(), rotation_fn);
}
uint64_t hash() const override
@@ -40,13 +31,13 @@ class VectorFieldInput final : public GeometryFieldInput {
bool is_equal_to(const fn::FieldNode &other) const override
{
- return dynamic_cast<const VectorFieldInput *>(&other) != nullptr;
+ return dynamic_cast<const InstanceRotationFieldInput *>(&other) != nullptr;
}
};
static void node_geo_exec(GeoNodeExecParams params)
{
- Field<float3> rotation{std::make_shared<VectorFieldInput>()};
+ Field<float3> rotation{std::make_shared<InstanceRotationFieldInput>()};
params.set_output("Rotation", std::move(rotation));
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_instance_scale.cc b/source/blender/nodes/geometry/nodes/node_geo_input_instance_scale.cc
index b3a362fbf3e..12ac48f8f11 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_input_instance_scale.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_instance_scale.cc
@@ -2,6 +2,8 @@
#include "node_geometry_util.hh"
+#include "BKE_instances.hh"
+
namespace blender::nodes::node_geo_input_instance_scale_cc {
static void node_declare(NodeDeclarationBuilder &b)
@@ -9,28 +11,17 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Vector>(N_("Scale")).field_source();
}
-class VectorFieldInput final : public GeometryFieldInput {
+class InstanceScaleFieldInput final : public bke::InstancesFieldInput {
public:
- VectorFieldInput() : GeometryFieldInput(CPPType::get<float3>(), "Scale")
+ InstanceScaleFieldInput() : bke::InstancesFieldInput(CPPType::get<float3>(), "Scale")
{
}
- GVArray get_varray_for_context(const GeometryComponent &component,
- const eAttrDomain UNUSED(domain),
- IndexMask UNUSED(mask)) const final
+ GVArray get_varray_for_context(const bke::Instances &instances, IndexMask /*mask*/) const final
{
- if (component.type() != GEO_COMPONENT_TYPE_INSTANCES) {
- return {};
- }
-
- const InstancesComponent &instance_component = static_cast<const InstancesComponent &>(
- component);
-
- auto scale_fn = [&](const int i) -> float3 {
- return instance_component.instance_transforms()[i].scale();
- };
+ auto scale_fn = [&](const int i) -> float3 { return instances.transforms()[i].scale(); };
- return VArray<float3>::ForFunc(instance_component.instances_num(), scale_fn);
+ return VArray<float3>::ForFunc(instances.instances_num(), scale_fn);
}
uint64_t hash() const override
@@ -40,13 +31,13 @@ class VectorFieldInput final : public GeometryFieldInput {
bool is_equal_to(const fn::FieldNode &other) const override
{
- return dynamic_cast<const VectorFieldInput *>(&other) != nullptr;
+ return dynamic_cast<const InstanceScaleFieldInput *>(&other) != nullptr;
}
};
static void node_geo_exec(GeoNodeExecParams params)
{
- Field<float3> scale{std::make_shared<VectorFieldInput>()};
+ Field<float3> scale{std::make_shared<InstanceScaleFieldInput>()};
params.set_output("Scale", std::move(scale));
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_material.cc b/source/blender/nodes/geometry/nodes/node_geo_input_material.cc
index 19882c4966d..943193a0d82 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_input_material.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_material.cc
@@ -12,14 +12,14 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Material>(N_("Material"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "material", 0, "", ICON_NONE);
}
static void node_geo_exec(GeoNodeExecParams params)
{
- Material *material = (Material *)params.node().id;
+ Material *material = reinterpret_cast<Material *>(params.node().id);
params.set_output("Material", material);
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_angle.cc b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_angle.cc
index b009aaa5291..29730ab8dc4 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_angle.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_angle.cc
@@ -53,46 +53,36 @@ static Array<EdgeMapEntry> create_edge_map(const Span<MPoly> polys,
return edge_map;
}
-class AngleFieldInput final : public GeometryFieldInput {
+class AngleFieldInput final : public bke::MeshFieldInput {
public:
- AngleFieldInput() : GeometryFieldInput(CPPType::get<float>(), "Unsigned Angle Field")
+ AngleFieldInput() : bke::MeshFieldInput(CPPType::get<float>(), "Unsigned Angle Field")
{
category_ = Category::Generated;
}
- GVArray get_varray_for_context(const GeometryComponent &component,
+ GVArray get_varray_for_context(const Mesh &mesh,
const eAttrDomain domain,
- IndexMask UNUSED(mask)) const final
+ const IndexMask /*mask*/) const final
{
- if (component.type() != GEO_COMPONENT_TYPE_MESH) {
- return {};
- }
-
- const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
- const Mesh *mesh = mesh_component.get_for_read();
- if (mesh == nullptr) {
- return {};
- }
-
- Span<MPoly> polys{mesh->mpoly, mesh->totpoly};
- Span<MLoop> loops{mesh->mloop, mesh->totloop};
- Array<EdgeMapEntry> edge_map = create_edge_map(polys, loops, mesh->totedge);
+ const Span<MVert> verts = mesh.verts();
+ const Span<MPoly> polys = mesh.polys();
+ const Span<MLoop> loops = mesh.loops();
+ Array<EdgeMapEntry> edge_map = create_edge_map(polys, loops, mesh.totedge);
- auto angle_fn = [edge_map, polys, loops, mesh](const int i) -> float {
+ auto angle_fn = [edge_map = std::move(edge_map), verts, polys, loops](const int i) -> float {
if (edge_map[i].face_count != 2) {
return 0.0f;
}
const MPoly &mpoly_1 = polys[edge_map[i].face_index_1];
const MPoly &mpoly_2 = polys[edge_map[i].face_index_2];
float3 normal_1, normal_2;
- BKE_mesh_calc_poly_normal(&mpoly_1, &loops[mpoly_1.loopstart], mesh->mvert, normal_1);
- BKE_mesh_calc_poly_normal(&mpoly_2, &loops[mpoly_2.loopstart], mesh->mvert, normal_2);
+ BKE_mesh_calc_poly_normal(&mpoly_1, &loops[mpoly_1.loopstart], verts.data(), normal_1);
+ BKE_mesh_calc_poly_normal(&mpoly_2, &loops[mpoly_2.loopstart], verts.data(), normal_2);
return angle_normalized_v3v3(normal_1, normal_2);
};
- VArray<float> angles = VArray<float>::ForFunc(mesh->totedge, angle_fn);
- return component.attributes()->adapt_domain<float>(
- std::move(angles), ATTR_DOMAIN_EDGE, domain);
+ VArray<float> angles = VArray<float>::ForFunc(mesh.totedge, angle_fn);
+ return mesh.attributes().adapt_domain<float>(std::move(angles), ATTR_DOMAIN_EDGE, domain);
}
uint64_t hash() const override
@@ -105,34 +95,32 @@ class AngleFieldInput final : public GeometryFieldInput {
{
return dynamic_cast<const AngleFieldInput *>(&other) != nullptr;
}
+
+ std::optional<eAttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
+ {
+ return ATTR_DOMAIN_EDGE;
+ }
};
-class SignedAngleFieldInput final : public GeometryFieldInput {
+class SignedAngleFieldInput final : public bke::MeshFieldInput {
public:
- SignedAngleFieldInput() : GeometryFieldInput(CPPType::get<float>(), "Signed Angle Field")
+ SignedAngleFieldInput() : bke::MeshFieldInput(CPPType::get<float>(), "Signed Angle Field")
{
category_ = Category::Generated;
}
- GVArray get_varray_for_context(const GeometryComponent &component,
+ GVArray get_varray_for_context(const Mesh &mesh,
const eAttrDomain domain,
- IndexMask UNUSED(mask)) const final
+ const IndexMask /*mask*/) const final
{
- if (component.type() != GEO_COMPONENT_TYPE_MESH) {
- return {};
- }
-
- const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
- const Mesh *mesh = mesh_component.get_for_read();
- if (mesh == nullptr) {
- return {};
- }
-
- Span<MPoly> polys{mesh->mpoly, mesh->totpoly};
- Span<MLoop> loops{mesh->mloop, mesh->totloop};
- Array<EdgeMapEntry> edge_map = create_edge_map(polys, loops, mesh->totedge);
-
- auto angle_fn = [edge_map, polys, loops, mesh](const int i) -> float {
+ const Span<MVert> verts = mesh.verts();
+ const Span<MEdge> edges = mesh.edges();
+ const Span<MPoly> polys = mesh.polys();
+ const Span<MLoop> loops = mesh.loops();
+ Array<EdgeMapEntry> edge_map = create_edge_map(polys, loops, mesh.totedge);
+
+ auto angle_fn =
+ [edge_map = std::move(edge_map), verts, edges, polys, loops](const int i) -> float {
if (edge_map[i].face_count != 2) {
return 0.0f;
}
@@ -141,18 +129,18 @@ class SignedAngleFieldInput final : public GeometryFieldInput {
/* Find the normals of the 2 polys. */
float3 poly_1_normal, poly_2_normal;
- BKE_mesh_calc_poly_normal(&mpoly_1, &loops[mpoly_1.loopstart], mesh->mvert, poly_1_normal);
- BKE_mesh_calc_poly_normal(&mpoly_2, &loops[mpoly_2.loopstart], mesh->mvert, poly_2_normal);
+ BKE_mesh_calc_poly_normal(&mpoly_1, &loops[mpoly_1.loopstart], verts.data(), poly_1_normal);
+ BKE_mesh_calc_poly_normal(&mpoly_2, &loops[mpoly_2.loopstart], verts.data(), poly_2_normal);
/* Find the centerpoint of the axis edge */
- const float3 edge_centerpoint = (float3(mesh->mvert[mesh->medge[i].v1].co) +
- float3(mesh->mvert[mesh->medge[i].v2].co)) *
+ const float3 edge_centerpoint = (float3(verts[edges[i].v1].co) +
+ float3(verts[edges[i].v2].co)) *
0.5f;
/* Get the centerpoint of poly 2 and subtract the edge centerpoint to get a tangent
* normal for poly 2. */
float3 poly_center_2;
- BKE_mesh_calc_poly_center(&mpoly_2, &loops[mpoly_2.loopstart], mesh->mvert, poly_center_2);
+ BKE_mesh_calc_poly_center(&mpoly_2, &loops[mpoly_2.loopstart], verts.data(), poly_center_2);
const float3 poly_2_tangent = math::normalize(poly_center_2 - edge_centerpoint);
const float concavity = math::dot(poly_1_normal, poly_2_tangent);
@@ -165,9 +153,8 @@ class SignedAngleFieldInput final : public GeometryFieldInput {
return -angle;
};
- VArray<float> angles = VArray<float>::ForFunc(mesh->totedge, angle_fn);
- return component.attributes()->adapt_domain<float>(
- std::move(angles), ATTR_DOMAIN_EDGE, domain);
+ VArray<float> angles = VArray<float>::ForFunc(mesh.totedge, angle_fn);
+ return mesh.attributes().adapt_domain<float>(std::move(angles), ATTR_DOMAIN_EDGE, domain);
}
uint64_t hash() const override
@@ -180,6 +167,11 @@ class SignedAngleFieldInput final : public GeometryFieldInput {
{
return dynamic_cast<const SignedAngleFieldInput *>(&other) != nullptr;
}
+
+ std::optional<eAttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
+ {
+ return ATTR_DOMAIN_EDGE;
+ }
};
static void node_geo_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_neighbors.cc b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_neighbors.cc
index 50d6998bb27..97c950988e7 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_neighbors.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_neighbors.cc
@@ -16,34 +16,26 @@ static void node_declare(NodeDeclarationBuilder &b)
.description(N_("The number of faces that use each edge as one of their sides"));
}
-class EdgeNeighborCountFieldInput final : public GeometryFieldInput {
+class EdgeNeighborCountFieldInput final : public bke::MeshFieldInput {
public:
EdgeNeighborCountFieldInput()
- : GeometryFieldInput(CPPType::get<int>(), "Edge Neighbor Count Field")
+ : bke::MeshFieldInput(CPPType::get<int>(), "Edge Neighbor Count Field")
{
category_ = Category::Generated;
}
- GVArray get_varray_for_context(const GeometryComponent &component,
+ GVArray get_varray_for_context(const Mesh &mesh,
const eAttrDomain domain,
- IndexMask UNUSED(mask)) const final
+ const IndexMask /*mask*/) const final
{
- if (component.type() == GEO_COMPONENT_TYPE_MESH) {
- const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
- const Mesh *mesh = mesh_component.get_for_read();
- if (mesh == nullptr) {
- return {};
- }
-
- Array<int> face_count(mesh->totedge, 0);
- for (const int i : IndexRange(mesh->totloop)) {
- face_count[mesh->mloop[i].e]++;
- }
-
- return mesh_component.attributes()->adapt_domain<int>(
- VArray<int>::ForContainer(std::move(face_count)), ATTR_DOMAIN_EDGE, domain);
+ const Span<MLoop> loops = mesh.loops();
+ Array<int> face_count(mesh.totedge, 0);
+ for (const MLoop &loop : loops) {
+ face_count[loop.e]++;
}
- return {};
+
+ return mesh.attributes().adapt_domain<int>(
+ VArray<int>::ForContainer(std::move(face_count)), ATTR_DOMAIN_EDGE, domain);
}
uint64_t hash() const override
@@ -56,6 +48,11 @@ class EdgeNeighborCountFieldInput final : public GeometryFieldInput {
{
return dynamic_cast<const EdgeNeighborCountFieldInput *>(&other) != nullptr;
}
+
+ std::optional<eAttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
+ {
+ return ATTR_DOMAIN_EDGE;
+ }
};
static void node_geo_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_vertices.cc b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_vertices.cc
index 83e511f45c2..513ddd76055 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_vertices.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_vertices.cc
@@ -25,114 +25,102 @@ static void node_declare(NodeDeclarationBuilder &b)
.description(N_("The position of the second vertex in the edge"));
}
-enum VertexNumber { VERTEX_ONE, VERTEX_TWO };
+enum class VertNumber { V1, V2 };
-static VArray<int> construct_edge_vertices_gvarray(const MeshComponent &component,
- const VertexNumber vertex,
- const eAttrDomain domain)
+static VArray<int> construct_edge_verts_gvarray(const Mesh &mesh,
+ const VertNumber vertex,
+ const eAttrDomain domain)
{
- const Mesh *mesh = component.get_for_read();
- if (mesh == nullptr) {
- return {};
- }
+ const Span<MEdge> edges = mesh.edges();
if (domain == ATTR_DOMAIN_EDGE) {
- if (vertex == VERTEX_ONE) {
- return VArray<int>::ForFunc(mesh->totedge,
- [mesh](const int i) -> int { return mesh->medge[i].v1; });
+ if (vertex == VertNumber::V1) {
+ return VArray<int>::ForFunc(edges.size(),
+ [edges](const int i) -> int { return edges[i].v1; });
}
- return VArray<int>::ForFunc(mesh->totedge,
- [mesh](const int i) -> int { return mesh->medge[i].v2; });
+ return VArray<int>::ForFunc(edges.size(), [edges](const int i) -> int { return edges[i].v2; });
}
return {};
}
-class EdgeVerticesFieldInput final : public GeometryFieldInput {
+class EdgeVertsInput final : public bke::MeshFieldInput {
private:
- VertexNumber vertex_;
+ VertNumber vertex_;
public:
- EdgeVerticesFieldInput(VertexNumber vertex)
- : GeometryFieldInput(CPPType::get<int>(), "Edge Vertices Field"), vertex_(vertex)
+ EdgeVertsInput(VertNumber vertex)
+ : bke::MeshFieldInput(CPPType::get<int>(), "Edge Vertices Field"), vertex_(vertex)
{
category_ = Category::Generated;
}
- GVArray get_varray_for_context(const GeometryComponent &component,
+ GVArray get_varray_for_context(const Mesh &mesh,
const eAttrDomain domain,
- IndexMask UNUSED(mask)) const final
+ const IndexMask /*mask*/) const final
{
- if (component.type() == GEO_COMPONENT_TYPE_MESH) {
- const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
- return construct_edge_vertices_gvarray(mesh_component, vertex_, domain);
- }
- return {};
+ return construct_edge_verts_gvarray(mesh, vertex_, domain);
}
uint64_t hash() const override
{
- return vertex_ == VERTEX_ONE ? 23847562893465 : 92384598734567;
+ return vertex_ == VertNumber::V1 ? 23847562893465 : 92384598734567;
}
bool is_equal_to(const fn::FieldNode &other) const override
{
- if (const EdgeVerticesFieldInput *other_field = dynamic_cast<const EdgeVerticesFieldInput *>(
- &other)) {
+ if (const EdgeVertsInput *other_field = dynamic_cast<const EdgeVertsInput *>(&other)) {
return vertex_ == other_field->vertex_;
}
return false;
}
+
+ std::optional<eAttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
+ {
+ return ATTR_DOMAIN_EDGE;
+ }
};
-static VArray<float3> construct_edge_positions_gvarray(const MeshComponent &component,
- const VertexNumber vertex,
+static VArray<float3> construct_edge_positions_gvarray(const Mesh &mesh,
+ const VertNumber vertex,
const eAttrDomain domain)
{
- const Mesh *mesh = component.get_for_read();
- if (mesh == nullptr) {
- return {};
- }
+ const Span<MVert> verts = mesh.verts();
+ const Span<MEdge> edges = mesh.edges();
- if (vertex == VERTEX_ONE) {
- return component.attributes()->adapt_domain<float3>(
- VArray<float3>::ForFunc(
- mesh->totedge,
- [mesh](const int i) { return float3(mesh->mvert[mesh->medge[i].v1].co); }),
+ if (vertex == VertNumber::V1) {
+ return mesh.attributes().adapt_domain<float3>(
+ VArray<float3>::ForFunc(edges.size(),
+ [verts, edges](const int i) { return verts[edges[i].v1].co; }),
ATTR_DOMAIN_EDGE,
domain);
}
- return component.attributes()->adapt_domain<float3>(
- VArray<float3>::ForFunc(
- mesh->totedge,
- [mesh](const int i) { return float3(mesh->mvert[mesh->medge[i].v2].co); }),
+ return mesh.attributes().adapt_domain<float3>(
+ VArray<float3>::ForFunc(edges.size(),
+ [verts, edges](const int i) { return verts[edges[i].v2].co; }),
ATTR_DOMAIN_EDGE,
domain);
}
-class EdgePositionFieldInput final : public GeometryFieldInput {
+class EdgePositionFieldInput final : public bke::MeshFieldInput {
private:
- VertexNumber vertex_;
+ VertNumber vertex_;
public:
- EdgePositionFieldInput(VertexNumber vertex)
- : GeometryFieldInput(CPPType::get<float3>(), "Edge Position Field"), vertex_(vertex)
+ EdgePositionFieldInput(VertNumber vertex)
+ : bke::MeshFieldInput(CPPType::get<float3>(), "Edge Position Field"), vertex_(vertex)
{
category_ = Category::Generated;
}
- GVArray get_varray_for_context(const GeometryComponent &component,
+ GVArray get_varray_for_context(const Mesh &mesh,
const eAttrDomain domain,
- IndexMask UNUSED(mask)) const final
+ IndexMask /*mask*/) const final
{
- if (component.type() == GEO_COMPONENT_TYPE_MESH) {
- const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
- return construct_edge_positions_gvarray(mesh_component, vertex_, domain);
- }
- return {};
+ return construct_edge_positions_gvarray(mesh, vertex_, domain);
}
uint64_t hash() const override
{
- return vertex_ == VERTEX_ONE ? 987456978362 : 374587679866;
+ return vertex_ == VertNumber::V1 ? 987456978362 : 374587679866;
}
bool is_equal_to(const fn::FieldNode &other) const override
@@ -143,14 +131,19 @@ class EdgePositionFieldInput final : public GeometryFieldInput {
}
return false;
}
+
+ std::optional<eAttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
+ {
+ return ATTR_DOMAIN_EDGE;
+ }
};
static void node_geo_exec(GeoNodeExecParams params)
{
- Field<int> vertex_field_1{std::make_shared<EdgeVerticesFieldInput>(VERTEX_ONE)};
- Field<int> vertex_field_2{std::make_shared<EdgeVerticesFieldInput>(VERTEX_TWO)};
- Field<float3> position_field_1{std::make_shared<EdgePositionFieldInput>(VERTEX_ONE)};
- Field<float3> position_field_2{std::make_shared<EdgePositionFieldInput>(VERTEX_TWO)};
+ Field<int> vertex_field_1{std::make_shared<EdgeVertsInput>(VertNumber::V1)};
+ Field<int> vertex_field_2{std::make_shared<EdgeVertsInput>(VertNumber::V2)};
+ Field<float3> position_field_1{std::make_shared<EdgePositionFieldInput>(VertNumber::V1)};
+ Field<float3> position_field_2{std::make_shared<EdgePositionFieldInput>(VertNumber::V2)};
params.set_output("Vertex Index 1", std::move(vertex_field_1));
params.set_output("Vertex Index 2", std::move(vertex_field_2));
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_area.cc b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_area.cc
index 4d21bf9443a..aec1c27a4fc 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_area.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_area.cc
@@ -16,39 +16,33 @@ static void node_declare(NodeDeclarationBuilder &b)
.description(N_("The surface area of each of the mesh's faces"));
}
-static VArray<float> construct_face_area_gvarray(const MeshComponent &component,
- const eAttrDomain domain)
+static VArray<float> construct_face_area_varray(const Mesh &mesh, const eAttrDomain domain)
{
- const Mesh *mesh = component.get_for_read();
- if (mesh == nullptr) {
- return {};
- }
+ const Span<MVert> verts = mesh.verts();
+ const Span<MPoly> polys = mesh.polys();
+ const Span<MLoop> loops = mesh.loops();
- auto area_fn = [mesh](const int i) -> float {
- const MPoly *mp = &mesh->mpoly[i];
- return BKE_mesh_calc_poly_area(mp, &mesh->mloop[mp->loopstart], mesh->mvert);
+ auto area_fn = [verts, polys, loops](const int i) -> float {
+ const MPoly &poly = polys[i];
+ return BKE_mesh_calc_poly_area(&poly, &loops[poly.loopstart], verts.data());
};
- return component.attributes()->adapt_domain<float>(
- VArray<float>::ForFunc(mesh->totpoly, area_fn), ATTR_DOMAIN_FACE, domain);
+ return mesh.attributes().adapt_domain<float>(
+ VArray<float>::ForFunc(polys.size(), area_fn), ATTR_DOMAIN_FACE, domain);
}
-class FaceAreaFieldInput final : public GeometryFieldInput {
+class FaceAreaFieldInput final : public bke::MeshFieldInput {
public:
- FaceAreaFieldInput() : GeometryFieldInput(CPPType::get<float>(), "Face Area Field")
+ FaceAreaFieldInput() : bke::MeshFieldInput(CPPType::get<float>(), "Face Area Field")
{
category_ = Category::Generated;
}
- GVArray get_varray_for_context(const GeometryComponent &component,
+ GVArray get_varray_for_context(const Mesh &mesh,
const eAttrDomain domain,
- IndexMask UNUSED(mask)) const final
+ const IndexMask /*mask*/) const final
{
- if (component.type() == GEO_COMPONENT_TYPE_MESH) {
- const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
- return construct_face_area_gvarray(mesh_component, domain);
- }
- return {};
+ return construct_face_area_varray(mesh, domain);
}
uint64_t hash() const override
@@ -61,6 +55,11 @@ class FaceAreaFieldInput final : public GeometryFieldInput {
{
return dynamic_cast<const FaceAreaFieldInput *>(&other) != nullptr;
}
+
+ std::optional<eAttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
+ {
+ return ATTR_DOMAIN_FACE;
+ }
};
static void node_geo_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_is_planar.cc b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_is_planar.cc
index 6b04ff08d9e..7b084995fc3 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_is_planar.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_is_planar.cc
@@ -22,53 +22,46 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Bool>("Planar").field_source();
}
-class PlanarFieldInput final : public GeometryFieldInput {
+class PlanarFieldInput final : public bke::MeshFieldInput {
private:
Field<float> threshold_;
public:
PlanarFieldInput(Field<float> threshold)
- : GeometryFieldInput(CPPType::get<bool>(), "Planar"), threshold_(threshold)
+ : bke::MeshFieldInput(CPPType::get<bool>(), "Planar"), threshold_(threshold)
{
category_ = Category::Generated;
}
- GVArray get_varray_for_context(const GeometryComponent &component,
+ GVArray get_varray_for_context(const Mesh &mesh,
const eAttrDomain domain,
- [[maybe_unused]] IndexMask mask) const final
+ IndexMask /*mask*/) const final
{
- if (component.type() != GEO_COMPONENT_TYPE_MESH) {
- return {};
- }
-
- const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
- const Mesh *mesh = mesh_component.get_for_read();
- if (mesh == nullptr) {
- return {};
- }
-
- GeometryComponentFieldContext context{mesh_component, ATTR_DOMAIN_FACE};
- fn::FieldEvaluator evaluator{context, mesh->totpoly};
+ const Span<MVert> verts = mesh.verts();
+ const Span<MPoly> polys = mesh.polys();
+ const Span<MLoop> loops = mesh.loops();
+ const Span<float3> poly_normals{
+ reinterpret_cast<const float3 *>(BKE_mesh_poly_normals_ensure(&mesh)), mesh.totpoly};
+
+ bke::MeshFieldContext context{mesh, ATTR_DOMAIN_FACE};
+ fn::FieldEvaluator evaluator{context, polys.size()};
evaluator.add(threshold_);
evaluator.evaluate();
const VArray<float> thresholds = evaluator.get_evaluated<float>(0);
- Span<float3> poly_normals{(float3 *)BKE_mesh_poly_normals_ensure(mesh), mesh->totpoly};
-
- auto planar_fn = [mesh, thresholds, poly_normals](const int i_poly) -> bool {
- if (mesh->mpoly[i_poly].totloop <= 3) {
+ auto planar_fn = [verts, polys, loops, thresholds, poly_normals](const int i) -> bool {
+ const MPoly &poly = polys[i];
+ if (poly.totloop <= 3) {
return true;
}
- const int loopstart = mesh->mpoly[i_poly].loopstart;
- const int loops = mesh->mpoly[i_poly].totloop;
- Span<MLoop> poly_loops(&mesh->mloop[loopstart], loops);
- float3 reference_normal = poly_normals[i_poly];
+ const Span<MLoop> poly_loops = loops.slice(poly.loopstart, poly.totloop);
+ const float3 &reference_normal = poly_normals[i];
float min = FLT_MAX;
float max = -FLT_MAX;
for (const int i_loop : poly_loops.index_range()) {
- const float3 vert = mesh->mvert[poly_loops[i_loop].v].co;
+ const float3 vert = verts[poly_loops[i_loop].v].co;
float dot = math::dot(reference_normal, vert);
if (dot > max) {
max = dot;
@@ -77,11 +70,11 @@ class PlanarFieldInput final : public GeometryFieldInput {
min = dot;
}
}
- return max - min < thresholds[i_poly] / 2.0f;
+ return max - min < thresholds[i] / 2.0f;
};
- return component.attributes()->adapt_domain<bool>(
- VArray<bool>::ForFunc(mesh->totpoly, planar_fn), ATTR_DOMAIN_FACE, domain);
+ return mesh.attributes().adapt_domain<bool>(
+ VArray<bool>::ForFunc(polys.size(), planar_fn), ATTR_DOMAIN_FACE, domain);
}
uint64_t hash() const override
@@ -94,6 +87,11 @@ class PlanarFieldInput final : public GeometryFieldInput {
{
return dynamic_cast<const PlanarFieldInput *>(&other) != nullptr;
}
+
+ std::optional<eAttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
+ {
+ return ATTR_DOMAIN_FACE;
+ }
};
static void geo_node_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_neighbors.cc b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_neighbors.cc
index a225ce61b14..f1724ef4a41 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_neighbors.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_neighbors.cc
@@ -19,48 +19,41 @@ static void node_declare(NodeDeclarationBuilder &b)
.description(N_("Number of faces which share an edge with the face"));
}
-static VArray<int> construct_neighbor_count_gvarray(const MeshComponent &component,
- const eAttrDomain domain)
+static VArray<int> construct_neighbor_count_varray(const Mesh &mesh, const eAttrDomain domain)
{
- const Mesh *mesh = component.get_for_read();
- if (mesh == nullptr) {
- return {};
- }
+ const Span<MPoly> polys = mesh.polys();
+ const Span<MLoop> loops = mesh.loops();
- Array<int> edge_count(mesh->totedge, 0);
- for (const int i : IndexRange(mesh->totloop)) {
- edge_count[mesh->mloop[i].e]++;
+ Array<int> edge_count(mesh.totedge, 0);
+ for (const MLoop &loop : loops) {
+ edge_count[loop.e]++;
}
- Array<int> poly_count(mesh->totpoly, 0);
- for (const int poly_num : IndexRange(mesh->totpoly)) {
- MPoly &poly = mesh->mpoly[poly_num];
- for (const int loop_num : IndexRange(poly.loopstart, poly.totloop)) {
- poly_count[poly_num] += edge_count[mesh->mloop[loop_num].e] - 1;
+ Array<int> poly_count(polys.size(), 0);
+ for (const int poly_index : polys.index_range()) {
+ const MPoly &poly = polys[poly_index];
+ for (const MLoop &loop : loops.slice(poly.loopstart, poly.totloop)) {
+ poly_count[poly_index] += edge_count[loop.e] - 1;
}
}
- return component.attributes()->adapt_domain<int>(
+ return mesh.attributes().adapt_domain<int>(
VArray<int>::ForContainer(std::move(poly_count)), ATTR_DOMAIN_FACE, domain);
}
-class FaceNeighborCountFieldInput final : public GeometryFieldInput {
+class FaceNeighborCountFieldInput final : public bke::MeshFieldInput {
public:
FaceNeighborCountFieldInput()
- : GeometryFieldInput(CPPType::get<int>(), "Face Neighbor Count Field")
+ : bke::MeshFieldInput(CPPType::get<int>(), "Face Neighbor Count Field")
{
category_ = Category::Generated;
}
- GVArray get_varray_for_context(const GeometryComponent &component,
+ GVArray get_varray_for_context(const Mesh &mesh,
const eAttrDomain domain,
- IndexMask UNUSED(mask)) const final
+ const IndexMask /*mask*/) const final
{
- if (component.type() == GEO_COMPONENT_TYPE_MESH) {
- const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
- return construct_neighbor_count_gvarray(mesh_component, domain);
- }
- return {};
+ return construct_neighbor_count_varray(mesh, domain);
}
uint64_t hash() const override
@@ -73,39 +66,35 @@ class FaceNeighborCountFieldInput final : public GeometryFieldInput {
{
return dynamic_cast<const FaceNeighborCountFieldInput *>(&other) != nullptr;
}
-};
-static VArray<int> construct_vertex_count_gvarray(const MeshComponent &component,
- const eAttrDomain domain)
-{
- const Mesh *mesh = component.get_for_read();
- if (mesh == nullptr) {
- return {};
+ std::optional<eAttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
+ {
+ return ATTR_DOMAIN_FACE;
}
+};
- return component.attributes()->adapt_domain<int>(
- VArray<int>::ForFunc(mesh->totpoly,
- [mesh](const int i) -> float { return mesh->mpoly[i].totloop; }),
+static VArray<int> construct_vertex_count_varray(const Mesh &mesh, const eAttrDomain domain)
+{
+ const Span<MPoly> polys = mesh.polys();
+ return mesh.attributes().adapt_domain<int>(
+ VArray<int>::ForFunc(polys.size(),
+ [polys](const int i) -> float { return polys[i].totloop; }),
ATTR_DOMAIN_FACE,
domain);
}
-class FaceVertexCountFieldInput final : public GeometryFieldInput {
+class FaceVertexCountFieldInput final : public bke::MeshFieldInput {
public:
- FaceVertexCountFieldInput() : GeometryFieldInput(CPPType::get<int>(), "Vertex Count Field")
+ FaceVertexCountFieldInput() : bke::MeshFieldInput(CPPType::get<int>(), "Vertex Count Field")
{
category_ = Category::Generated;
}
- GVArray get_varray_for_context(const GeometryComponent &component,
+ GVArray get_varray_for_context(const Mesh &mesh,
const eAttrDomain domain,
- IndexMask UNUSED(mask)) const final
+ const IndexMask /*mask*/) const final
{
- if (component.type() == GEO_COMPONENT_TYPE_MESH) {
- const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
- return construct_vertex_count_gvarray(mesh_component, domain);
- }
- return {};
+ return construct_vertex_count_varray(mesh, domain);
}
uint64_t hash() const override
@@ -118,6 +107,11 @@ class FaceVertexCountFieldInput final : public GeometryFieldInput {
{
return dynamic_cast<const FaceVertexCountFieldInput *>(&other) != nullptr;
}
+
+ std::optional<eAttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
+ {
+ return ATTR_DOMAIN_FACE;
+ }
};
static void node_geo_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_island.cc b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_island.cc
index 2c7eef5665f..6b54828b042 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_island.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_island.cc
@@ -22,39 +22,32 @@ static void node_declare(NodeDeclarationBuilder &b)
.description(N_("The total number of mesh islands"));
}
-class IslandFieldInput final : public GeometryFieldInput {
+class IslandFieldInput final : public bke::MeshFieldInput {
public:
- IslandFieldInput() : GeometryFieldInput(CPPType::get<int>(), "Island Index")
+ IslandFieldInput() : bke::MeshFieldInput(CPPType::get<int>(), "Island Index")
{
category_ = Category::Generated;
}
- GVArray get_varray_for_context(const GeometryComponent &component,
+ GVArray get_varray_for_context(const Mesh &mesh,
const eAttrDomain domain,
- IndexMask UNUSED(mask)) const final
+ const IndexMask /*mask*/) const final
{
- if (component.type() != GEO_COMPONENT_TYPE_MESH) {
- return {};
- }
- const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
- const Mesh *mesh = mesh_component.get_for_read();
- if (mesh == nullptr) {
- return {};
- }
+ const Span<MEdge> edges = mesh.edges();
- DisjointSet islands(mesh->totvert);
- for (const int i : IndexRange(mesh->totedge)) {
- islands.join(mesh->medge[i].v1, mesh->medge[i].v2);
+ DisjointSet islands(mesh.totvert);
+ for (const int i : edges.index_range()) {
+ islands.join(edges[i].v1, edges[i].v2);
}
- Array<int> output(mesh->totvert);
+ Array<int> output(mesh.totvert);
VectorSet<int> ordered_roots;
- for (const int i : IndexRange(mesh->totvert)) {
+ for (const int i : IndexRange(mesh.totvert)) {
const int64_t root = islands.find_root(i);
output[i] = ordered_roots.index_of_or_add(root);
}
- return mesh_component.attributes()->adapt_domain<int>(
+ return mesh.attributes().adapt_domain<int>(
VArray<int>::ForContainer(std::move(output)), ATTR_DOMAIN_POINT, domain);
}
@@ -68,41 +61,38 @@ class IslandFieldInput final : public GeometryFieldInput {
{
return dynamic_cast<const IslandFieldInput *>(&other) != nullptr;
}
+
+ std::optional<eAttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
+ {
+ return ATTR_DOMAIN_POINT;
+ }
};
-class IslandCountFieldInput final : public GeometryFieldInput {
+class IslandCountFieldInput final : public bke::MeshFieldInput {
public:
- IslandCountFieldInput() : GeometryFieldInput(CPPType::get<int>(), "Island Count")
+ IslandCountFieldInput() : bke::MeshFieldInput(CPPType::get<int>(), "Island Count")
{
category_ = Category::Generated;
}
- GVArray get_varray_for_context(const GeometryComponent &component,
+ GVArray get_varray_for_context(const Mesh &mesh,
const eAttrDomain domain,
- IndexMask UNUSED(mask)) const final
+ const IndexMask /*mask*/) const final
{
- if (component.type() != GEO_COMPONENT_TYPE_MESH) {
- return {};
- }
- const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
- const Mesh *mesh = mesh_component.get_for_read();
- if (mesh == nullptr) {
- return {};
- }
+ const Span<MEdge> edges = mesh.edges();
- DisjointSet islands(mesh->totvert);
- for (const int i : IndexRange(mesh->totedge)) {
- islands.join(mesh->medge[i].v1, mesh->medge[i].v2);
+ DisjointSet islands(mesh.totvert);
+ for (const int i : edges.index_range()) {
+ islands.join(edges[i].v1, edges[i].v2);
}
Set<int> island_list;
- for (const int i_vert : IndexRange(mesh->totvert)) {
+ for (const int i_vert : IndexRange(mesh.totvert)) {
const int64_t root = islands.find_root(i_vert);
island_list.add(root);
}
- return VArray<int>::ForSingle(island_list.size(),
- mesh_component.attribute_domain_size(domain));
+ return VArray<int>::ForSingle(island_list.size(), mesh.attributes().domain_size(domain));
}
uint64_t hash() const override
@@ -115,6 +105,11 @@ class IslandCountFieldInput final : public GeometryFieldInput {
{
return dynamic_cast<const IslandCountFieldInput *>(&other) != nullptr;
}
+
+ std::optional<eAttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
+ {
+ return ATTR_DOMAIN_POINT;
+ }
};
static void node_geo_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_vertex_neighbors.cc b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_vertex_neighbors.cc
index 62b3f9d0e92..5b1b32c7b9c 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_vertex_neighbors.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_vertex_neighbors.cc
@@ -20,41 +20,32 @@ static void node_declare(NodeDeclarationBuilder &b)
.description(N_("Number of faces that contain the vertex"));
}
-static VArray<int> construct_vertex_count_gvarray(const MeshComponent &component,
- const eAttrDomain domain)
+static VArray<int> construct_vertex_count_gvarray(const Mesh &mesh, const eAttrDomain domain)
{
- const Mesh *mesh = component.get_for_read();
- if (mesh == nullptr) {
- return {};
- }
-
+ const Span<MEdge> edges = mesh.edges();
if (domain == ATTR_DOMAIN_POINT) {
- Array<int> vertices(mesh->totvert, 0);
- for (const int i : IndexRange(mesh->totedge)) {
- vertices[mesh->medge[i].v1]++;
- vertices[mesh->medge[i].v2]++;
+ Array<int> counts(mesh.totvert, 0);
+ for (const int i : edges.index_range()) {
+ counts[edges[i].v1]++;
+ counts[edges[i].v2]++;
}
- return VArray<int>::ForContainer(std::move(vertices));
+ return VArray<int>::ForContainer(std::move(counts));
}
return {};
}
-class VertexCountFieldInput final : public GeometryFieldInput {
+class VertexCountFieldInput final : public bke::MeshFieldInput {
public:
- VertexCountFieldInput() : GeometryFieldInput(CPPType::get<int>(), "Vertex Count Field")
+ VertexCountFieldInput() : bke::MeshFieldInput(CPPType::get<int>(), "Vertex Count Field")
{
category_ = Category::Generated;
}
- GVArray get_varray_for_context(const GeometryComponent &component,
+ GVArray get_varray_for_context(const Mesh &mesh,
const eAttrDomain domain,
- IndexMask UNUSED(mask)) const final
+ const IndexMask /*mask*/) const final
{
- if (component.type() == GEO_COMPONENT_TYPE_MESH) {
- const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
- return construct_vertex_count_gvarray(mesh_component, domain);
- }
- return {};
+ return construct_vertex_count_gvarray(mesh, domain);
}
uint64_t hash() const override
@@ -67,20 +58,20 @@ class VertexCountFieldInput final : public GeometryFieldInput {
{
return dynamic_cast<const VertexCountFieldInput *>(&other) != nullptr;
}
-};
-static VArray<int> construct_face_count_gvarray(const MeshComponent &component,
- const eAttrDomain domain)
-{
- const Mesh *mesh = component.get_for_read();
- if (mesh == nullptr) {
- return {};
+ std::optional<eAttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
+ {
+ return ATTR_DOMAIN_POINT;
}
+};
+static VArray<int> construct_face_count_gvarray(const Mesh &mesh, const eAttrDomain domain)
+{
+ const Span<MLoop> loops = mesh.loops();
if (domain == ATTR_DOMAIN_POINT) {
- Array<int> vertices(mesh->totvert, 0);
- for (const int i : IndexRange(mesh->totloop)) {
- int vertex = mesh->mloop[i].v;
+ Array<int> vertices(mesh.totvert, 0);
+ for (const int i : loops.index_range()) {
+ int vertex = loops[i].v;
vertices[vertex]++;
}
return VArray<int>::ForContainer(std::move(vertices));
@@ -88,22 +79,18 @@ static VArray<int> construct_face_count_gvarray(const MeshComponent &component,
return {};
}
-class VertexFaceCountFieldInput final : public GeometryFieldInput {
+class VertexFaceCountFieldInput final : public bke::MeshFieldInput {
public:
- VertexFaceCountFieldInput() : GeometryFieldInput(CPPType::get<int>(), "Vertex Face Count Field")
+ VertexFaceCountFieldInput() : bke::MeshFieldInput(CPPType::get<int>(), "Vertex Face Count Field")
{
category_ = Category::Generated;
}
- GVArray get_varray_for_context(const GeometryComponent &component,
+ GVArray get_varray_for_context(const Mesh &mesh,
const eAttrDomain domain,
- IndexMask UNUSED(mask)) const final
+ const IndexMask /*mask*/) const final
{
- if (component.type() == GEO_COMPONENT_TYPE_MESH) {
- const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
- return construct_face_count_gvarray(mesh_component, domain);
- }
- return {};
+ return construct_face_count_gvarray(mesh, domain);
}
uint64_t hash() const override
@@ -116,6 +103,11 @@ class VertexFaceCountFieldInput final : public GeometryFieldInput {
{
return dynamic_cast<const VertexFaceCountFieldInput *>(&other) != nullptr;
}
+
+ std::optional<eAttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
+ {
+ return ATTR_DOMAIN_POINT;
+ }
};
static void node_geo_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_named_attribute.cc b/source/blender/nodes/geometry/nodes/node_geo_input_named_attribute.cc
index 122c7b352c7..1063a022e9d 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_input_named_attribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_named_attribute.cc
@@ -22,12 +22,12 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Int>(N_("Attribute"), "Attribute_Int").field_source();
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryInputNamedAttribute *data = MEM_cnew<NodeGeometryInputNamedAttribute>(__func__);
data->data_type = CD_PROP_FLOAT;
@@ -37,9 +37,9 @@ static void node_init(bNodeTree *UNUSED(tree), bNode *node)
static void node_update(bNodeTree *ntree, bNode *node)
{
const NodeGeometryInputNamedAttribute &storage = node_storage(*node);
- const eCustomDataType data_type = static_cast<eCustomDataType>(storage.data_type);
+ const eCustomDataType data_type = eCustomDataType(storage.data_type);
- bNodeSocket *socket_vector = (bNodeSocket *)node->outputs.first;
+ bNodeSocket *socket_vector = static_cast<bNodeSocket *>(node->outputs.first);
bNodeSocket *socket_float = socket_vector->next;
bNodeSocket *socket_color4f = socket_float->next;
bNodeSocket *socket_boolean = socket_color4f->next;
@@ -59,7 +59,7 @@ static void node_gather_link_searches(GatherLinkSearchOpParams &params)
if (params.in_out() == SOCK_OUT) {
const std::optional<eCustomDataType> type = node_data_type_to_custom_data_type(
- static_cast<eNodeSocketDatatype>(params.other_socket().type));
+ eNodeSocketDatatype(params.other_socket().type));
if (type && *type != CD_PROP_STRING) {
/* The input and output sockets have the same name. */
params.add_item(IFACE_("Attribute"), [type](LinkSearchOpParams &params) {
@@ -74,7 +74,7 @@ static void node_gather_link_searches(GatherLinkSearchOpParams &params)
static void node_geo_exec(GeoNodeExecParams params)
{
const NodeGeometryInputNamedAttribute &storage = node_storage(params.node());
- const eCustomDataType data_type = static_cast<eCustomDataType>(storage.data_type);
+ const eCustomDataType data_type = eCustomDataType(storage.data_type);
const std::string name = params.extract_input<std::string>("Name");
@@ -88,7 +88,7 @@ static void node_geo_exec(GeoNodeExecParams params)
return;
}
- params.used_named_attribute(name, eNamedAttrUsage::Read);
+ params.used_named_attribute(name, NamedAttributeUsage::Read);
switch (data_type) {
case CD_PROP_FLOAT:
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_scene_time.cc b/source/blender/nodes/geometry/nodes/node_geo_input_scene_time.cc
index 0222ccbbd02..74d10c286a0 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_input_scene_time.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_scene_time.cc
@@ -18,7 +18,7 @@ static void node_exec(GeoNodeExecParams params)
{
const Scene *scene = DEG_get_input_scene(params.depsgraph());
const float scene_ctime = BKE_scene_ctime_get(scene);
- const double frame_rate = (((double)scene->r.frs_sec) / (double)scene->r.frs_sec_base);
+ const double frame_rate = (double(scene->r.frs_sec) / double(scene->r.frs_sec_base));
params.set_output("Seconds", float(scene_ctime / frame_rate));
params.set_output("Frame", scene_ctime);
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_shortest_edge_paths.cc b/source/blender/nodes/geometry/nodes/node_geo_input_shortest_edge_paths.cc
new file mode 100644
index 00000000000..00c92e30443
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_shortest_edge_paths.cc
@@ -0,0 +1,246 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include <queue>
+
+#include "BLI_map.hh"
+#include "BLI_math_vec_types.hh"
+#include "BLI_set.hh"
+#include "BLI_task.hh"
+
+#include "BKE_mesh.h"
+
+#include "node_geometry_util.hh"
+
+namespace blender::nodes::node_geo_input_shortest_edge_paths_cc {
+
+static void node_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::Bool>(N_("End Vertex")).default_value(false).hide_value().supports_field();
+ b.add_input<decl::Float>(N_("Edge Cost")).default_value(1.0f).hide_value().supports_field();
+ b.add_output<decl::Int>(N_("Next Vertex Index")).field_source();
+ b.add_output<decl::Float>(N_("Total Cost")).field_source();
+}
+
+typedef std::pair<float, int> VertPriority;
+
+struct EdgeVertMap {
+ Array<Vector<int>> edges_by_vertex_map;
+
+ EdgeVertMap(const Mesh &mesh)
+ {
+ const Span<MEdge> edges = mesh.edges();
+ edges_by_vertex_map.reinitialize(mesh.totvert);
+ for (const int edge_i : edges.index_range()) {
+ const MEdge &edge = edges[edge_i];
+ edges_by_vertex_map[edge.v1].append(edge_i);
+ edges_by_vertex_map[edge.v2].append(edge_i);
+ }
+ }
+};
+
+static void shortest_paths(const Mesh &mesh,
+ EdgeVertMap &maps,
+ const IndexMask end_selection,
+ const VArray<float> &input_cost,
+ MutableSpan<int> r_next_index,
+ MutableSpan<float> r_cost)
+{
+ const Span<MEdge> edges = mesh.edges();
+ Array<bool> visited(mesh.totvert, false);
+
+ std::priority_queue<VertPriority, std::vector<VertPriority>, std::greater<VertPriority>> queue;
+
+ for (const int start_vert_i : end_selection) {
+ r_cost[start_vert_i] = 0.0f;
+ queue.emplace(0.0f, start_vert_i);
+ }
+
+ while (!queue.empty()) {
+ const float cost_i = queue.top().first;
+ const int vert_i = queue.top().second;
+ queue.pop();
+ if (visited[vert_i]) {
+ continue;
+ }
+ visited[vert_i] = true;
+ const Span<int> incident_edge_indices = maps.edges_by_vertex_map[vert_i];
+ for (const int edge_i : incident_edge_indices) {
+ const MEdge &edge = edges[edge_i];
+ const int neighbor_vert_i = edge.v1 + edge.v2 - vert_i;
+ if (visited[neighbor_vert_i]) {
+ continue;
+ }
+ const float edge_cost = std::max(0.0f, input_cost[edge_i]);
+ const float new_neighbour_cost = cost_i + edge_cost;
+ if (new_neighbour_cost < r_cost[neighbor_vert_i]) {
+ r_cost[neighbor_vert_i] = new_neighbour_cost;
+ r_next_index[neighbor_vert_i] = vert_i;
+ queue.emplace(new_neighbour_cost, neighbor_vert_i);
+ }
+ }
+ }
+}
+
+class ShortestEdgePathsNextVertFieldInput final : public bke::MeshFieldInput {
+ private:
+ Field<bool> end_selection_;
+ Field<float> cost_;
+
+ public:
+ ShortestEdgePathsNextVertFieldInput(Field<bool> end_selection, Field<float> cost)
+ : bke::MeshFieldInput(CPPType::get<int>(), "Shortest Edge Paths Next Vertex Field"),
+ end_selection_(end_selection),
+ cost_(cost)
+ {
+ category_ = Category::Generated;
+ }
+
+ GVArray get_varray_for_context(const Mesh &mesh,
+ const eAttrDomain domain,
+ const IndexMask /*mask*/) const final
+ {
+ bke::MeshFieldContext edge_context{mesh, ATTR_DOMAIN_EDGE};
+ fn::FieldEvaluator edge_evaluator{edge_context, mesh.totedge};
+ edge_evaluator.add(cost_);
+ edge_evaluator.evaluate();
+ const VArray<float> input_cost = edge_evaluator.get_evaluated<float>(0);
+
+ bke::MeshFieldContext point_context{mesh, ATTR_DOMAIN_POINT};
+ fn::FieldEvaluator point_evaluator{point_context, mesh.totvert};
+ point_evaluator.add(end_selection_);
+ point_evaluator.evaluate();
+ const IndexMask end_selection = point_evaluator.get_evaluated_as_mask(0);
+
+ Array<int> next_index(mesh.totvert, -1);
+ Array<float> cost(mesh.totvert, FLT_MAX);
+
+ if (!end_selection.is_empty()) {
+ EdgeVertMap maps(mesh);
+ shortest_paths(mesh, maps, end_selection, input_cost, next_index, cost);
+ }
+ threading::parallel_for(next_index.index_range(), 1024, [&](const IndexRange range) {
+ for (const int i : range) {
+ if (next_index[i] == -1) {
+ next_index[i] = i;
+ }
+ }
+ });
+ return mesh.attributes().adapt_domain<int>(
+ VArray<int>::ForContainer(std::move(next_index)), ATTR_DOMAIN_POINT, domain);
+ }
+
+ uint64_t hash() const override
+ {
+ /* Some random constant hash. */
+ return 8466507837;
+ }
+
+ bool is_equal_to(const fn::FieldNode &other) const override
+ {
+ if (const ShortestEdgePathsNextVertFieldInput *other_field =
+ dynamic_cast<const ShortestEdgePathsNextVertFieldInput *>(&other)) {
+ return other_field->end_selection_ == end_selection_ && other_field->cost_ == cost_;
+ }
+ return false;
+ }
+
+ std::optional<eAttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
+ {
+ return ATTR_DOMAIN_POINT;
+ }
+};
+
+class ShortestEdgePathsCostFieldInput final : public bke::MeshFieldInput {
+ private:
+ Field<bool> end_selection_;
+ Field<float> cost_;
+
+ public:
+ ShortestEdgePathsCostFieldInput(Field<bool> end_selection, Field<float> cost)
+ : bke::MeshFieldInput(CPPType::get<float>(), "Shortest Edge Paths Cost Field"),
+ end_selection_(end_selection),
+ cost_(cost)
+ {
+ category_ = Category::Generated;
+ }
+
+ GVArray get_varray_for_context(const Mesh &mesh,
+ const eAttrDomain domain,
+ const IndexMask /*mask*/) const final
+ {
+ bke::MeshFieldContext edge_context{mesh, ATTR_DOMAIN_EDGE};
+ fn::FieldEvaluator edge_evaluator{edge_context, mesh.totedge};
+ edge_evaluator.add(cost_);
+ edge_evaluator.evaluate();
+ const VArray<float> input_cost = edge_evaluator.get_evaluated<float>(0);
+
+ bke::MeshFieldContext point_context{mesh, ATTR_DOMAIN_POINT};
+ fn::FieldEvaluator point_evaluator{point_context, mesh.totvert};
+ point_evaluator.add(end_selection_);
+ point_evaluator.evaluate();
+ const IndexMask end_selection = point_evaluator.get_evaluated_as_mask(0);
+
+ Array<int> next_index(mesh.totvert, -1);
+ Array<float> cost(mesh.totvert, FLT_MAX);
+
+ if (!end_selection.is_empty()) {
+ EdgeVertMap maps(mesh);
+ shortest_paths(mesh, maps, end_selection, input_cost, next_index, cost);
+ }
+ threading::parallel_for(cost.index_range(), 1024, [&](const IndexRange range) {
+ for (const int i : range) {
+ if (cost[i] == FLT_MAX) {
+ cost[i] = 0;
+ }
+ }
+ });
+ return mesh.attributes().adapt_domain<float>(
+ VArray<float>::ForContainer(std::move(cost)), ATTR_DOMAIN_POINT, domain);
+ }
+
+ uint64_t hash() const override
+ {
+ return get_default_hash_2(end_selection_, cost_);
+ }
+
+ bool is_equal_to(const fn::FieldNode &other) const override
+ {
+ if (const ShortestEdgePathsCostFieldInput *other_field =
+ dynamic_cast<const ShortestEdgePathsCostFieldInput *>(&other)) {
+ return other_field->end_selection_ == end_selection_ && other_field->cost_ == cost_;
+ }
+ return false;
+ }
+
+ std::optional<eAttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
+ {
+ return ATTR_DOMAIN_POINT;
+ }
+};
+
+static void node_geo_exec(GeoNodeExecParams params)
+{
+ Field<bool> end_selection = params.extract_input<Field<bool>>("End Vertex");
+ Field<float> cost = params.extract_input<Field<float>>("Edge Cost");
+
+ Field<int> next_vert_field{
+ std::make_shared<ShortestEdgePathsNextVertFieldInput>(end_selection, cost)};
+ Field<float> cost_field{std::make_shared<ShortestEdgePathsCostFieldInput>(end_selection, cost)};
+ params.set_output("Next Vertex Index", std::move(next_vert_field));
+ params.set_output("Total Cost", std::move(cost_field));
+}
+
+} // namespace blender::nodes::node_geo_input_shortest_edge_paths_cc
+
+void register_node_type_geo_input_shortest_edge_paths()
+{
+ namespace file_ns = blender::nodes::node_geo_input_shortest_edge_paths_cc;
+
+ static bNodeType ntype;
+
+ geo_node_type_base(
+ &ntype, GEO_NODE_INPUT_SHORTEST_EDGE_PATHS, "Shortest Edge Paths", NODE_CLASS_INPUT);
+ ntype.declare = file_ns::node_declare;
+ ntype.geometry_node_execute = file_ns::node_geo_exec;
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_spline_length.cc b/source/blender/nodes/geometry/nodes/node_geo_input_spline_length.cc
index 267ba44cc00..4bb4618588b 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_input_spline_length.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_spline_length.cc
@@ -16,15 +16,9 @@ static void node_declare(NodeDeclarationBuilder &b)
* Spline Count
*/
-static VArray<int> construct_curve_point_count_gvarray(const CurveComponent &component,
+static VArray<int> construct_curve_point_count_gvarray(const bke::CurvesGeometry &curves,
const eAttrDomain domain)
{
- if (!component.has_curves()) {
- return {};
- }
- const Curves &curves_id = *component.get_for_read();
- const bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id.geometry);
-
auto count_fn = [curves](int64_t i) { return curves.points_for_curve(i).size(); };
if (domain == ATTR_DOMAIN_CURVE) {
@@ -32,29 +26,24 @@ static VArray<int> construct_curve_point_count_gvarray(const CurveComponent &com
}
if (domain == ATTR_DOMAIN_POINT) {
VArray<int> count = VArray<int>::ForFunc(curves.curves_num(), count_fn);
- return component.attributes()->adapt_domain<int>(
- std::move(count), ATTR_DOMAIN_CURVE, ATTR_DOMAIN_POINT);
+ return curves.adapt_domain<int>(std::move(count), ATTR_DOMAIN_CURVE, ATTR_DOMAIN_POINT);
}
return {};
}
-class SplineCountFieldInput final : public GeometryFieldInput {
+class SplineCountFieldInput final : public bke::CurvesFieldInput {
public:
- SplineCountFieldInput() : GeometryFieldInput(CPPType::get<int>(), "Spline Point Count")
+ SplineCountFieldInput() : bke::CurvesFieldInput(CPPType::get<int>(), "Spline Point Count")
{
category_ = Category::Generated;
}
- GVArray get_varray_for_context(const GeometryComponent &component,
+ GVArray get_varray_for_context(const bke::CurvesGeometry &curves,
const eAttrDomain domain,
- IndexMask UNUSED(mask)) const final
+ const IndexMask /*mask*/) const final
{
- if (component.type() == GEO_COMPONENT_TYPE_CURVE) {
- const CurveComponent &curve_component = static_cast<const CurveComponent &>(component);
- return construct_curve_point_count_gvarray(curve_component, domain);
- }
- return {};
+ return construct_curve_point_count_gvarray(curves, domain);
}
uint64_t hash() const override
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_tangent.cc b/source/blender/nodes/geometry/nodes/node_geo_input_tangent.cc
index a2aab5464aa..7e7b0eb215f 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_input_tangent.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_tangent.cc
@@ -63,19 +63,12 @@ static Array<float3> curve_tangent_point_domain(const bke::CurvesGeometry &curve
return results;
}
-static VArray<float3> construct_curve_tangent_gvarray(const CurveComponent &component,
+static VArray<float3> construct_curve_tangent_gvarray(const bke::CurvesGeometry &curves,
const eAttrDomain domain)
{
- if (!component.has_curves()) {
- return {};
- }
-
- const Curves &curves_id = *component.get_for_read();
- const bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id.geometry);
-
const VArray<int8_t> types = curves.curve_types();
if (curves.is_single_type(CURVE_TYPE_POLY)) {
- return component.attributes()->adapt_domain<float3>(
+ return curves.adapt_domain<float3>(
VArray<float3>::ForSpan(curves.evaluated_tangents()), ATTR_DOMAIN_POINT, domain);
}
@@ -86,29 +79,25 @@ static VArray<float3> construct_curve_tangent_gvarray(const CurveComponent &comp
}
if (domain == ATTR_DOMAIN_CURVE) {
- return component.attributes()->adapt_domain<float3>(
+ return curves.adapt_domain<float3>(
VArray<float3>::ForContainer(std::move(tangents)), ATTR_DOMAIN_POINT, ATTR_DOMAIN_CURVE);
}
return nullptr;
}
-class TangentFieldInput final : public GeometryFieldInput {
+class TangentFieldInput final : public bke::CurvesFieldInput {
public:
- TangentFieldInput() : GeometryFieldInput(CPPType::get<float3>(), "Tangent node")
+ TangentFieldInput() : bke::CurvesFieldInput(CPPType::get<float3>(), "Tangent node")
{
category_ = Category::Generated;
}
- GVArray get_varray_for_context(const GeometryComponent &component,
+ GVArray get_varray_for_context(const bke::CurvesGeometry &curves,
const eAttrDomain domain,
- IndexMask UNUSED(mask)) const final
+ const IndexMask /*mask*/) const final
{
- if (component.type() == GEO_COMPONENT_TYPE_CURVE) {
- const CurveComponent &curve_component = static_cast<const CurveComponent &>(component);
- return construct_curve_tangent_gvarray(curve_component, domain);
- }
- return {};
+ return construct_curve_tangent_gvarray(curves, domain);
}
uint64_t hash() const override
diff --git a/source/blender/nodes/geometry/nodes/node_geo_instance_on_points.cc b/source/blender/nodes/geometry/nodes/node_geo_instance_on_points.cc
index 119d895fead..64546684186 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_instance_on_points.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_instance_on_points.cc
@@ -2,6 +2,7 @@
#include "DNA_collection_types.h"
+#include "BLI_array_utils.hh"
#include "BLI_hash.h"
#include "BLI_task.hh"
@@ -9,6 +10,7 @@
#include "UI_resources.h"
#include "BKE_attribute_math.hh"
+#include "BKE_instances.hh"
#include "node_geometry_util.hh"
@@ -25,7 +27,7 @@ static void node_declare(NodeDeclarationBuilder &b)
.description(N_("Choose instances from the \"Instance\" input at each point instead of "
"instancing the entire geometry"));
b.add_input<decl::Int>(N_("Instance Index"))
- .implicit_field()
+ .implicit_field(implicit_field_inputs::id_or_index)
.description(N_(
"Index of the instance that used for each point. This is only used when Pick Instances "
"is on. By default the point index is used"));
@@ -43,7 +45,7 @@ static void node_declare(NodeDeclarationBuilder &b)
}
static void add_instances_from_component(
- InstancesComponent &dst_component,
+ bke::Instances &dst_component,
const GeometryComponent &src_component,
const GeometrySet &instance,
const GeoNodeExecParams &params,
@@ -57,7 +59,7 @@ static void add_instances_from_component(
VArray<float3> rotations;
VArray<float3> scales;
- GeometryComponentFieldContext field_context{src_component, domain};
+ bke::GeometryFieldContext field_context{src_component, domain};
const Field<bool> selection_field = params.get_input<Field<bool>>("Selection");
fn::FieldEvaluator evaluator{field_context, domain_num};
evaluator.set_selection(selection_field);
@@ -70,6 +72,9 @@ static void add_instances_from_component(
evaluator.evaluate();
const IndexMask selection = evaluator.get_evaluated_selection_as_mask();
+ if (selection.is_empty()) {
+ return;
+ }
/* The initial size of the component might be non-zero when this function is called for multiple
* component types. */
@@ -77,25 +82,23 @@ static void add_instances_from_component(
const int select_len = selection.index_range().size();
dst_component.resize(start_len + select_len);
- MutableSpan<int> dst_handles = dst_component.instance_reference_handles().slice(start_len,
- select_len);
- MutableSpan<float4x4> dst_transforms = dst_component.instance_transforms().slice(start_len,
- select_len);
+ MutableSpan<int> dst_handles = dst_component.reference_handles().slice(start_len, select_len);
+ MutableSpan<float4x4> dst_transforms = dst_component.transforms().slice(start_len, select_len);
VArray<float3> positions = src_component.attributes()->lookup_or_default<float3>(
"position", domain, {0, 0, 0});
- const InstancesComponent *src_instances = instance.get_component_for_read<InstancesComponent>();
+ const bke::Instances *src_instances = instance.get_instances_for_read();
/* Maps handles from the source instances to handles on the new instance. */
Array<int> handle_mapping;
/* Only fill #handle_mapping when it may be used below. */
if (src_instances != nullptr &&
(!pick_instance.is_single() || pick_instance.get_internal_single())) {
- Span<InstanceReference> src_references = src_instances->references();
+ Span<bke::InstanceReference> src_references = src_instances->references();
handle_mapping.reinitialize(src_references.size());
for (const int src_instance_handle : src_references.index_range()) {
- const InstanceReference &reference = src_references[src_instance_handle];
+ const bke::InstanceReference &reference = src_references[src_instance_handle];
const int dst_instance_handle = dst_component.add_reference(reference);
handle_mapping[src_instance_handle] = dst_instance_handle;
}
@@ -103,7 +106,7 @@ static void add_instances_from_component(
const int full_instance_handle = dst_component.add_reference(instance);
/* Add this reference last, because it is the most likely one to be removed later on. */
- const int empty_reference_handle = dst_component.add_reference(InstanceReference());
+ const int empty_reference_handle = dst_component.add_reference(bke::InstanceReference());
threading::parallel_for(selection.index_range(), 1024, [&](IndexRange selection_range) {
for (const int range_i : selection_range) {
@@ -126,12 +129,11 @@ static void add_instances_from_component(
const int index = mod_i(original_index, std::max(src_instances_num, 1));
if (index < src_instances_num) {
/* Get the reference to the source instance. */
- const int src_handle = src_instances->instance_reference_handles()[index];
+ const int src_handle = src_instances->reference_handles()[index];
dst_handle = handle_mapping[src_handle];
/* Take transforms of the source instance into account. */
- mul_m4_m4_post(dst_transform.values,
- src_instances->instance_transforms()[index].values);
+ mul_m4_m4_post(dst_transform.values, src_instances->transforms()[index].values);
}
}
}
@@ -154,7 +156,7 @@ static void add_instances_from_component(
}
}
- bke::CustomDataAttributes &instance_attributes = dst_component.instance_attributes();
+ bke::CustomDataAttributes &instance_attributes = dst_component.custom_data_attributes();
for (const auto item : attributes_to_propagate.items()) {
const AttributeIDRef &attribute_id = item.key;
const AttributeKind attribute_kind = item.value;
@@ -171,18 +173,7 @@ static void add_instances_from_component(
dst_attribute_opt = instance_attributes.get_for_write(attribute_id);
}
BLI_assert(dst_attribute_opt);
- const GMutableSpan dst_attribute = dst_attribute_opt->slice(start_len, select_len);
- threading::parallel_for(selection.index_range(), 1024, [&](IndexRange selection_range) {
- attribute_math::convert_to_static_type(attribute_kind.data_type, [&](auto dummy) {
- using T = decltype(dummy);
- VArray<T> src = src_attribute.typed<T>();
- MutableSpan<T> dst = dst_attribute.typed<T>();
- for (const int range_i : selection_range) {
- const int i = selection[range_i];
- dst[range_i] = src[i];
- }
- });
- });
+ array_utils::gather(src_attribute, selection, dst_attribute_opt->slice(start_len, select_len));
}
}
@@ -193,7 +184,15 @@ static void node_geo_exec(GeoNodeExecParams params)
instance.ensure_owns_direct_data();
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
- InstancesComponent &instances = geometry_set.get_component_for_write<InstancesComponent>();
+ /* It's important not to invalidate the existing #InstancesComponent because it owns references
+ * to other geometry sets that are processed by this node. */
+ InstancesComponent &instances_component =
+ geometry_set.get_component_for_write<InstancesComponent>();
+ bke::Instances *dst_instances = instances_component.get_for_write();
+ if (dst_instances == nullptr) {
+ dst_instances = new bke::Instances();
+ instances_component.replace(dst_instances);
+ }
const Array<GeometryComponentType> types{
GEO_COMPONENT_TYPE_MESH, GEO_COMPONENT_TYPE_POINT_CLOUD, GEO_COMPONENT_TYPE_CURVE};
@@ -205,14 +204,13 @@ static void node_geo_exec(GeoNodeExecParams params)
for (const GeometryComponentType type : types) {
if (geometry_set.has(type)) {
- add_instances_from_component(instances,
+ add_instances_from_component(*dst_instances,
*geometry_set.get_component_for_read(type),
instance,
params,
attributes_to_propagate);
}
}
-
geometry_set.remove_geometry_during_modify();
});
@@ -220,8 +218,9 @@ static void node_geo_exec(GeoNodeExecParams params)
* process them needlessly.
* This should eventually be moved into the loop above, but currently this is quite tricky
* because it might remove references that the loop still wants to iterate over. */
- InstancesComponent &instances = geometry_set.get_component_for_write<InstancesComponent>();
- instances.remove_unused_references();
+ if (bke::Instances *instances = geometry_set.get_instances_for_write()) {
+ instances->remove_unused_references();
+ }
params.set_output("Instances", std::move(geometry_set));
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_instances_to_points.cc b/source/blender/nodes/geometry/nodes/node_geo_instances_to_points.cc
index 5e0789e557b..acd00d119ab 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_instances_to_points.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_instances_to_points.cc
@@ -3,6 +3,7 @@
#include "DNA_pointcloud_types.h"
#include "BKE_attribute_math.hh"
+#include "BKE_instances.hh"
#include "BKE_pointcloud.h"
#include "node_geometry_util.hh"
@@ -13,7 +14,7 @@ static void node_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Geometry>(N_("Instances")).only_instances();
b.add_input<decl::Bool>(N_("Selection")).default_value(true).hide_value().supports_field();
- b.add_input<decl::Vector>(N_("Position")).implicit_field();
+ b.add_input<decl::Vector>(N_("Position")).implicit_field(implicit_field_inputs::position);
b.add_input<decl::Float>(N_("Radius"))
.default_value(0.05f)
.min(0.0f)
@@ -27,12 +28,10 @@ static void convert_instances_to_points(GeometrySet &geometry_set,
Field<float> radius_field,
const Field<bool> selection_field)
{
- const InstancesComponent &instances = *geometry_set.get_component_for_read<InstancesComponent>();
+ const bke::Instances &instances = *geometry_set.get_instances_for_read();
- GeometryComponentFieldContext field_context{instances, ATTR_DOMAIN_INSTANCE};
- const int domain_size = instances.instances_num();
-
- fn::FieldEvaluator evaluator{field_context, domain_size};
+ const bke::InstancesFieldContext context{instances};
+ fn::FieldEvaluator evaluator{context, instances.instances_num()};
evaluator.set_selection(std::move(selection_field));
evaluator.add(std::move(position_field));
evaluator.add(std::move(radius_field));
@@ -47,8 +46,7 @@ static void convert_instances_to_points(GeometrySet &geometry_set,
PointCloud *pointcloud = BKE_pointcloud_new_nomain(selection.size());
geometry_set.replace_pointcloud(pointcloud);
- bke::MutableAttributeAccessor point_attributes = bke::pointcloud_attributes_for_write(
- *pointcloud);
+ bke::MutableAttributeAccessor point_attributes = pointcloud->attributes_for_write();
bke::SpanAttributeWriter<float3> point_positions =
point_attributes.lookup_or_add_for_write_only_span<float3>("position", ATTR_DOMAIN_POINT);
@@ -73,7 +71,7 @@ static void convert_instances_to_points(GeometrySet &geometry_set,
const AttributeIDRef &attribute_id = item.key;
const AttributeKind attribute_kind = item.value;
- const GVArray src = instances.attributes()->lookup_or_default(
+ const GVArray src = instances.attributes().lookup_or_default(
attribute_id, ATTR_DOMAIN_INSTANCE, attribute_kind.data_type);
BLI_assert(src);
GSpanAttributeWriter dst = point_attributes.lookup_or_add_for_write_only_span(
diff --git a/source/blender/nodes/geometry/nodes/node_geo_field_on_domain.cc b/source/blender/nodes/geometry/nodes/node_geo_interpolate_domain.cc
index 59e243db4a2..d4e18321665 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_field_on_domain.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_interpolate_domain.cc
@@ -9,7 +9,9 @@
#include "BLI_task.hh"
-namespace blender::nodes::node_geo_field_on_domain_cc {
+#include "NOD_socket_search_link.hh"
+
+namespace blender::nodes::node_geo_interpolate_domain_cc {
static void node_declare(NodeDeclarationBuilder &b)
{
@@ -26,13 +28,13 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Bool>(N_("Value"), "Value_Bool").field_source();
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE);
uiItemR(layout, ptr, "domain", 0, "", ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
node->custom1 = ATTR_DOMAIN_POINT;
node->custom2 = CD_PROP_FLOAT;
@@ -40,7 +42,7 @@ static void node_init(bNodeTree *UNUSED(tree), bNode *node)
static void node_update(bNodeTree *ntree, bNode *node)
{
- const eCustomDataType data_type = static_cast<eCustomDataType>(node->custom2);
+ const eCustomDataType data_type = eCustomDataType(node->custom2);
bNodeSocket *sock_in_float = static_cast<bNodeSocket *>(node->inputs.first);
bNodeSocket *sock_in_int = sock_in_float->next;
@@ -67,31 +69,53 @@ static void node_update(bNodeTree *ntree, bNode *node)
nodeSetSocketAvailability(ntree, sock_out_bool, data_type == CD_PROP_BOOL);
}
-class FieldOnDomain final : public GeometryFieldInput {
+static void node_gather_link_searches(GatherLinkSearchOpParams &params)
+{
+ const bNodeType &node_type = params.node_type();
+ const std::optional<eCustomDataType> type = node_data_type_to_custom_data_type(
+ (eNodeSocketDatatype)params.other_socket().type);
+ if (type && *type != CD_PROP_STRING) {
+ params.add_item(IFACE_("Value"), [node_type, type](LinkSearchOpParams &params) {
+ bNode &node = params.add_node(node_type);
+ node.custom2 = *type;
+ params.update_and_connect_available_socket(node, "Value");
+ });
+ }
+}
+
+class InterpolateDomain final : public bke::GeometryFieldInput {
private:
GField src_field_;
eAttrDomain src_domain_;
public:
- FieldOnDomain(GField field, eAttrDomain domain)
- : GeometryFieldInput(field.cpp_type(), "Field on Domain"),
+ InterpolateDomain(GField field, eAttrDomain domain)
+ : bke::GeometryFieldInput(field.cpp_type(), "Interpolate Domain"),
src_field_(std::move(field)),
src_domain_(domain)
{
}
- GVArray get_varray_for_context(const GeometryComponent &component,
- const eAttrDomain domain,
- IndexMask /* mask */) const final
+ GVArray get_varray_for_context(const bke::GeometryFieldContext &context,
+ IndexMask /*mask*/) const final
{
- const GeometryComponentFieldContext context{component, src_domain_};
- const int64_t src_domain_size = component.attribute_domain_size(src_domain_);
+ const bke::AttributeAccessor attributes = *context.attributes();
+
+ const bke::GeometryFieldContext other_domain_context{
+ context.geometry(), context.type(), src_domain_};
+ const int64_t src_domain_size = attributes.domain_size(src_domain_);
GArray values(src_field_.cpp_type(), src_domain_size);
- FieldEvaluator value_evaluator{context, src_domain_size};
+ FieldEvaluator value_evaluator{other_domain_context, src_domain_size};
value_evaluator.add_with_destination(src_field_, values.as_mutable_span());
value_evaluator.evaluate();
- return component.attributes()->adapt_domain(
- GVArray::ForGArray(std::move(values)), src_domain_, domain);
+ return attributes.adapt_domain(
+ GVArray::ForGArray(std::move(values)), src_domain_, context.domain());
+ }
+
+ std::optional<eAttrDomain> preferred_domain(
+ const GeometryComponent & /*component*/) const override
+ {
+ return src_domain_;
}
};
@@ -117,31 +141,33 @@ static StringRefNull identifier_suffix(eCustomDataType data_type)
static void node_geo_exec(GeoNodeExecParams params)
{
const bNode &node = params.node();
- const eAttrDomain domain = static_cast<eAttrDomain>(node.custom1);
- const eCustomDataType data_type = static_cast<eCustomDataType>(node.custom2);
+ const eAttrDomain domain = eAttrDomain(node.custom1);
+ const eCustomDataType data_type = eCustomDataType(node.custom2);
attribute_math::convert_to_static_type(data_type, [&](auto dummy) {
using T = decltype(dummy);
static const std::string identifier = "Value_" + identifier_suffix(data_type);
Field<T> src_field = params.extract_input<Field<T>>(identifier);
- Field<T> dst_field{std::make_shared<FieldOnDomain>(std::move(src_field), domain)};
+ Field<T> dst_field{std::make_shared<InterpolateDomain>(std::move(src_field), domain)};
params.set_output(identifier, std::move(dst_field));
});
}
-} // namespace blender::nodes::node_geo_field_on_domain_cc
+} // namespace blender::nodes::node_geo_interpolate_domain_cc
-void register_node_type_geo_field_on_domain()
+void register_node_type_geo_interpolate_domain()
{
- namespace file_ns = blender::nodes::node_geo_field_on_domain_cc;
+ namespace file_ns = blender::nodes::node_geo_interpolate_domain_cc;
static bNodeType ntype;
- geo_node_type_base(&ntype, GEO_NODE_FIELD_ON_DOMAIN, "Field on Domain", NODE_CLASS_CONVERTER);
+ geo_node_type_base(
+ &ntype, GEO_NODE_INTERPOLATE_DOMAIN, "Interpolate Domain", NODE_CLASS_CONVERTER);
ntype.geometry_node_execute = file_ns::node_geo_exec;
ntype.declare = file_ns::node_declare;
ntype.draw_buttons = file_ns::node_layout;
ntype.initfunc = file_ns::node_init;
ntype.updatefunc = file_ns::node_update;
+ ntype.gather_link_search_ops = file_ns::node_gather_link_searches;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc b/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc
index 083a505539a..ea2646a9786 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc
@@ -2,6 +2,8 @@
#include "GEO_realize_instances.hh"
+#include "BKE_instances.hh"
+
#include "node_geometry_util.hh"
namespace blender::nodes::node_geo_join_geometry_cc {
@@ -29,6 +31,9 @@ static Map<AttributeIDRef, AttributeMetaData> get_final_attribute_info(
if (attribute_id.is_named() && ignored_attributes.contains(attribute_id.name())) {
return true;
}
+ if (meta_data.data_type == CD_PROP_STRING) {
+ return true;
+ }
info.add_or_modify(
attribute_id,
[&](AttributeMetaData *meta_data_final) { *meta_data_final = meta_data; },
@@ -97,40 +102,44 @@ static void join_attributes(Span<const GeometryComponent *> src_components,
static void join_components(Span<const InstancesComponent *> src_components, GeometrySet &result)
{
- InstancesComponent &dst_component = result.get_component_for_write<InstancesComponent>();
+ std::unique_ptr<bke::Instances> dst_instances = std::make_unique<bke::Instances>();
int tot_instances = 0;
for (const InstancesComponent *src_component : src_components) {
- tot_instances += src_component->instances_num();
+ tot_instances += src_component->get_for_read()->instances_num();
}
- dst_component.reserve(tot_instances);
+ dst_instances->reserve(tot_instances);
for (const InstancesComponent *src_component : src_components) {
- Span<InstanceReference> src_references = src_component->references();
+ const bke::Instances &src_instances = *src_component->get_for_read();
+
+ Span<bke::InstanceReference> src_references = src_instances.references();
Array<int> handle_map(src_references.size());
for (const int src_handle : src_references.index_range()) {
- handle_map[src_handle] = dst_component.add_reference(src_references[src_handle]);
+ handle_map[src_handle] = dst_instances->add_reference(src_references[src_handle]);
}
- Span<float4x4> src_transforms = src_component->instance_transforms();
- Span<int> src_reference_handles = src_component->instance_reference_handles();
+ Span<float4x4> src_transforms = src_instances.transforms();
+ Span<int> src_reference_handles = src_instances.reference_handles();
for (const int i : src_transforms.index_range()) {
const int src_handle = src_reference_handles[i];
const int dst_handle = handle_map[src_handle];
const float4x4 &transform = src_transforms[i];
- dst_component.add_instance(dst_handle, transform);
+ dst_instances->add_instance(dst_handle, transform);
}
}
+
+ result.replace_instances(dst_instances.release());
+ InstancesComponent &dst_component = result.get_component_for_write<InstancesComponent>();
join_attributes(to_base_components(src_components), dst_component, {"position"});
}
-static void join_components(Span<const VolumeComponent *> src_components, GeometrySet &result)
+static void join_components(Span<const VolumeComponent *> /*src_components*/,
+ GeometrySet & /*result*/)
{
/* Not yet supported. Joining volume grids with the same name requires resampling of at least one
* of the grids. The cell size of the resulting volume has to be determined somehow. */
- VolumeComponent &dst_component = result.get_component_for_write<VolumeComponent>();
- UNUSED_VARS(src_components, dst_component);
}
template<typename Component>
@@ -152,32 +161,30 @@ static void join_component_type(Span<GeometrySet> src_geometry_sets, GeometrySet
return;
}
- GeometrySet instances_geometry_set;
- InstancesComponent &instances =
- instances_geometry_set.get_component_for_write<InstancesComponent>();
-
if constexpr (is_same_any_v<Component, InstancesComponent, VolumeComponent>) {
join_components(components, result);
}
else {
+ std::unique_ptr<bke::Instances> instances = std::make_unique<bke::Instances>();
for (const Component *component : components) {
GeometrySet tmp_geo;
tmp_geo.add(*component);
- const int handle = instances.add_reference(InstanceReference{tmp_geo});
- instances.add_instance(handle, float4x4::identity());
+ const int handle = instances->add_reference(bke::InstanceReference{tmp_geo});
+ instances->add_instance(handle, float4x4::identity());
}
geometry::RealizeInstancesOptions options;
options.keep_original_ids = true;
options.realize_instance_attributes = false;
- GeometrySet joined_components = geometry::realize_instances(instances_geometry_set, options);
+ GeometrySet joined_components = geometry::realize_instances(
+ GeometrySet::create_with_instances(instances.release()), options);
result.add(joined_components.get_component_for_write<Component>());
}
}
static void node_geo_exec(GeoNodeExecParams params)
{
- Vector<GeometrySet> geometry_sets = params.extract_multi_input<GeometrySet>("Geometry");
+ Vector<GeometrySet> geometry_sets = params.extract_input<Vector<GeometrySet>>("Geometry");
GeometrySet geometry_set_result;
join_component_type<MeshComponent>(geometry_sets, geometry_set_result);
@@ -185,6 +192,7 @@ static void node_geo_exec(GeoNodeExecParams params)
join_component_type<InstancesComponent>(geometry_sets, geometry_set_result);
join_component_type<VolumeComponent>(geometry_sets, geometry_set_result);
join_component_type<CurveComponent>(geometry_sets, geometry_set_result);
+ join_component_type<GeometryComponentEditData>(geometry_sets, geometry_set_result);
params.set_output("Geometry", std::move(geometry_set_result));
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_material_selection.cc b/source/blender/nodes/geometry/nodes/node_geo_material_selection.cc
index ca613ae009b..dfb4181926e 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_material_selection.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_material_selection.cc
@@ -23,46 +23,56 @@ static void node_declare(NodeDeclarationBuilder &b)
static void select_mesh_by_material(const Mesh &mesh,
const Material *material,
const IndexMask mask,
- const MutableSpan<bool> r_selection)
+ MutableSpan<bool> r_selection)
{
BLI_assert(mesh.totpoly >= r_selection.size());
- Vector<int> material_indices;
+ Vector<int> slots;
for (const int i : IndexRange(mesh.totcol)) {
if (mesh.mat[i] == material) {
- material_indices.append(i);
+ slots.append(i);
}
}
+ const AttributeAccessor attributes = mesh.attributes();
+ const VArray<int> material_indices = attributes.lookup_or_default<int>(
+ "material_index", ATTR_DOMAIN_FACE, 0);
+ if (material != nullptr && material_indices.is_single() &&
+ material_indices.get_internal_single() == 0) {
+ r_selection.fill_indices(mask, false);
+ return;
+ }
+
+ const VArraySpan<int> material_indices_span(material_indices);
+
threading::parallel_for(mask.index_range(), 1024, [&](IndexRange range) {
for (const int i : range) {
const int face_index = mask[i];
- r_selection[i] = material_indices.contains(mesh.mpoly[face_index].mat_nr);
+ r_selection[i] = slots.contains(material_indices_span[face_index]);
}
});
}
-class MaterialSelectionFieldInput final : public GeometryFieldInput {
+class MaterialSelectionFieldInput final : public bke::GeometryFieldInput {
Material *material_;
public:
MaterialSelectionFieldInput(Material *material)
- : GeometryFieldInput(CPPType::get<bool>(), "Material Selection node"), material_(material)
+ : bke::GeometryFieldInput(CPPType::get<bool>(), "Material Selection node"),
+ material_(material)
{
category_ = Category::Generated;
}
- GVArray get_varray_for_context(const GeometryComponent &component,
- const eAttrDomain domain,
- IndexMask mask) const final
+ GVArray get_varray_for_context(const bke::GeometryFieldContext &context,
+ const IndexMask mask) const final
{
- if (component.type() != GEO_COMPONENT_TYPE_MESH) {
+ if (context.type() != GEO_COMPONENT_TYPE_MESH) {
return {};
}
- const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
- const Mesh *mesh = mesh_component.get_for_read();
+ const Mesh *mesh = context.mesh();
if (mesh == nullptr) {
return {};
}
-
+ const eAttrDomain domain = context.domain();
if (domain == ATTR_DOMAIN_FACE) {
Array<bool> selection(mask.min_array_size());
select_mesh_by_material(*mesh, material_, mask, selection);
@@ -71,7 +81,7 @@ class MaterialSelectionFieldInput final : public GeometryFieldInput {
Array<bool> selection(mesh->totpoly);
select_mesh_by_material(*mesh, material_, IndexMask(mesh->totpoly), selection);
- return mesh_component.attributes()->adapt_domain<bool>(
+ return mesh->attributes().adapt_domain<bool>(
VArray<bool>::ForContainer(std::move(selection)), ATTR_DOMAIN_FACE, domain);
return nullptr;
@@ -90,6 +100,12 @@ class MaterialSelectionFieldInput final : public GeometryFieldInput {
}
return false;
}
+
+ std::optional<eAttrDomain> preferred_domain(
+ const GeometryComponent & /*component*/) const override
+ {
+ return ATTR_DOMAIN_FACE;
+ }
};
static void node_geo_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_merge_by_distance.cc b/source/blender/nodes/geometry/nodes/node_geo_merge_by_distance.cc
index a4fb79bef7a..ce8b078f195 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_merge_by_distance.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_merge_by_distance.cc
@@ -1,5 +1,8 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "DNA_mesh_types.h"
+#include "DNA_pointcloud_types.h"
+
#include "GEO_mesh_merge_by_distance.hh"
#include "GEO_point_merge_by_distance.hh"
@@ -21,27 +24,26 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Geometry"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryMergeByDistance *data = MEM_cnew<NodeGeometryMergeByDistance>(__func__);
data->mode = GEO_NODE_MERGE_BY_DISTANCE_MODE_ALL;
node->storage = data;
}
-static PointCloud *pointcloud_merge_by_distance(const PointCloudComponent &src_points,
+static PointCloud *pointcloud_merge_by_distance(const PointCloud &src_points,
const float merge_distance,
const Field<bool> &selection_field)
{
- const int src_num = src_points.attribute_domain_size(ATTR_DOMAIN_POINT);
- GeometryComponentFieldContext context{src_points, ATTR_DOMAIN_POINT};
- FieldEvaluator evaluator{context, src_num};
+ bke::PointCloudFieldContext context{src_points};
+ FieldEvaluator evaluator{context, src_points.totpoint};
evaluator.add(selection_field);
evaluator.evaluate();
@@ -50,31 +52,28 @@ static PointCloud *pointcloud_merge_by_distance(const PointCloudComponent &src_p
return nullptr;
}
- return geometry::point_merge_by_distance(*src_points.get_for_read(), merge_distance, selection);
+ return geometry::point_merge_by_distance(src_points, merge_distance, selection);
}
-static std::optional<Mesh *> mesh_merge_by_distance_connected(const MeshComponent &mesh_component,
+static std::optional<Mesh *> mesh_merge_by_distance_connected(const Mesh &mesh,
const float merge_distance,
const Field<bool> &selection_field)
{
- const int src_num = mesh_component.attribute_domain_size(ATTR_DOMAIN_POINT);
- Array<bool> selection(src_num);
- GeometryComponentFieldContext context{mesh_component, ATTR_DOMAIN_POINT};
- FieldEvaluator evaluator{context, src_num};
+ Array<bool> selection(mesh.totvert);
+ bke::MeshFieldContext context{mesh, ATTR_DOMAIN_POINT};
+ FieldEvaluator evaluator{context, mesh.totvert};
evaluator.add_with_destination(selection_field, selection.as_mutable_span());
evaluator.evaluate();
- const Mesh &mesh = *mesh_component.get_for_read();
return geometry::mesh_merge_by_distance_connected(mesh, selection, merge_distance, false);
}
-static std::optional<Mesh *> mesh_merge_by_distance_all(const MeshComponent &mesh_component,
+static std::optional<Mesh *> mesh_merge_by_distance_all(const Mesh &mesh,
const float merge_distance,
const Field<bool> &selection_field)
{
- const int src_num = mesh_component.attribute_domain_size(ATTR_DOMAIN_POINT);
- GeometryComponentFieldContext context{mesh_component, ATTR_DOMAIN_POINT};
- FieldEvaluator evaluator{context, src_num};
+ bke::MeshFieldContext context{mesh, ATTR_DOMAIN_POINT};
+ FieldEvaluator evaluator{context, mesh.totvert};
evaluator.add(selection_field);
evaluator.evaluate();
@@ -83,7 +82,6 @@ static std::optional<Mesh *> mesh_merge_by_distance_all(const MeshComponent &mes
return std::nullopt;
}
- const Mesh &mesh = *mesh_component.get_for_read();
return geometry::mesh_merge_by_distance_all(mesh, selection, merge_distance);
}
@@ -98,22 +96,20 @@ static void node_geo_exec(GeoNodeExecParams params)
const float merge_distance = params.extract_input<float>("Distance");
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
- if (geometry_set.has_pointcloud()) {
- PointCloud *result = pointcloud_merge_by_distance(
- *geometry_set.get_component_for_read<PointCloudComponent>(), merge_distance, selection);
+ if (const PointCloud *pointcloud = geometry_set.get_pointcloud_for_read()) {
+ PointCloud *result = pointcloud_merge_by_distance(*pointcloud, merge_distance, selection);
if (result) {
geometry_set.replace_pointcloud(result);
}
}
- if (geometry_set.has_mesh()) {
- const MeshComponent &component = *geometry_set.get_component_for_read<MeshComponent>();
+ if (const Mesh *mesh = geometry_set.get_mesh_for_read()) {
std::optional<Mesh *> result;
switch (mode) {
case GEO_NODE_MERGE_BY_DISTANCE_MODE_ALL:
- result = mesh_merge_by_distance_all(component, merge_distance, selection);
+ result = mesh_merge_by_distance_all(*mesh, merge_distance, selection);
break;
case GEO_NODE_MERGE_BY_DISTANCE_MODE_CONNECTED:
- result = mesh_merge_by_distance_connected(component, merge_distance, selection);
+ result = mesh_merge_by_distance_connected(*mesh, merge_distance, selection);
break;
default:
BLI_assert_unreachable();
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_face_set_boundaries.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_face_set_boundaries.cc
new file mode 100644
index 00000000000..1b9852cf7b9
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_face_set_boundaries.cc
@@ -0,0 +1,94 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+
+#include "BKE_mesh.h"
+
+#include "node_geometry_util.hh"
+
+namespace blender::nodes::node_geo_mesh_face_set_boundaries_cc {
+
+static void node_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::Int>(N_("Face Set"))
+ .default_value(0)
+ .hide_value()
+ .supports_field()
+ .description(N_("An identifier for the group of each face. All contiguous faces with the "
+ "same value are in the same region"));
+ b.add_output<decl::Bool>(N_("Boundary Edges"))
+ .field_source()
+ .description(N_("The edges that lie on the boundaries between the different face sets"));
+}
+
+class BoundaryFieldInput final : public bke::MeshFieldInput {
+ private:
+ const Field<int> face_set;
+
+ public:
+ BoundaryFieldInput(const Field<int> face_set)
+ : bke::MeshFieldInput(CPPType::get<bool>(), "Boundary Field"), face_set(face_set)
+ {
+ category_ = Category::Generated;
+ }
+
+ GVArray get_varray_for_context(const Mesh &mesh,
+ const eAttrDomain domain,
+ const IndexMask /*mask*/) const final
+ {
+ const bke::MeshFieldContext face_context{mesh, ATTR_DOMAIN_FACE};
+ FieldEvaluator face_evaluator{face_context, mesh.totpoly};
+ face_evaluator.add(face_set);
+ face_evaluator.evaluate();
+ const VArray<int> face_set = face_evaluator.get_evaluated<int>(0);
+
+ Array<bool> boundary(mesh.totedge, false);
+ Array<bool> edge_visited(mesh.totedge, false);
+ Array<int> edge_face_set(mesh.totedge, 0);
+ const Span<MPoly> polys = mesh.polys();
+ const Span<MLoop> loops = mesh.loops();
+ for (const int i : polys.index_range()) {
+ const MPoly &poly = polys[i];
+ for (const MLoop &loop : loops.slice(poly.loopstart, poly.totloop)) {
+ const int edge = loop.e;
+ if (edge_visited[edge]) {
+ if (edge_face_set[edge] != face_set[i]) {
+ /* This edge is connected to two faces on different face sets. */
+ boundary[edge] = true;
+ }
+ }
+ edge_visited[edge] = true;
+ edge_face_set[edge] = face_set[i];
+ }
+ }
+ return mesh.attributes().adapt_domain<bool>(
+ VArray<bool>::ForContainer(std::move(boundary)), ATTR_DOMAIN_EDGE, domain);
+ }
+
+ std::optional<eAttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
+ {
+ return ATTR_DOMAIN_EDGE;
+ }
+};
+
+static void node_geo_exec(GeoNodeExecParams params)
+{
+ const Field<int> face_set_field = params.extract_input<Field<int>>("Face Set");
+ Field<bool> face_set_boundaries{std::make_shared<BoundaryFieldInput>(face_set_field)};
+ params.set_output("Boundary Edges", std::move(face_set_boundaries));
+}
+
+} // namespace blender::nodes::node_geo_mesh_face_set_boundaries_cc
+
+void register_node_type_geo_mesh_face_set_boundaries()
+{
+ namespace file_ns = blender::nodes::node_geo_mesh_face_set_boundaries_cc;
+
+ static bNodeType ntype;
+ geo_node_type_base(
+ &ntype, GEO_NODE_MESH_FACE_SET_BOUNDARIES, "Face Set Boundaries", NODE_CLASS_INPUT);
+ ntype.declare = file_ns::node_declare;
+ ntype.geometry_node_execute = file_ns::node_geo_exec;
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc
index 9e85547315c..31a3e967905 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc
@@ -29,14 +29,14 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Mesh"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
uiItemR(layout, ptr, "fill_type", 0, nullptr, ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryMeshCircle *node_storage = MEM_cnew<NodeGeometryMeshCircle>(__func__);
@@ -109,13 +109,13 @@ static Mesh *create_circle_mesh(const float radius,
circle_corner_total(fill_type, verts_num),
circle_face_total(fill_type, verts_num));
BKE_id_material_eval_ensure_default_slot(&mesh->id);
- MutableSpan<MVert> verts{mesh->mvert, mesh->totvert};
- MutableSpan<MLoop> loops{mesh->mloop, mesh->totloop};
- MutableSpan<MEdge> edges{mesh->medge, mesh->totedge};
- MutableSpan<MPoly> polys{mesh->mpoly, mesh->totpoly};
+ MutableSpan<MVert> verts = mesh->verts_for_write();
+ MutableSpan<MEdge> edges = mesh->edges_for_write();
+ MutableSpan<MPoly> polys = mesh->polys_for_write();
+ MutableSpan<MLoop> loops = mesh->loops_for_write();
/* Assign vertex coordinates. */
- const float angle_delta = 2.0f * (M_PI / static_cast<float>(verts_num));
+ const float angle_delta = 2.0f * (M_PI / float(verts_num));
for (const int i : IndexRange(verts_num)) {
const float angle = i * angle_delta;
copy_v3_v3(verts[i].co, float3(std::cos(angle) * radius, std::sin(angle) * radius, 0.0f));
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc
index cb79ef93de9..4a9264b8464 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc
@@ -255,10 +255,10 @@ int ConeConfig::calculate_total_corners()
return corner_total;
}
-static void calculate_cone_vertices(const MutableSpan<MVert> &verts, const ConeConfig &config)
+static void calculate_cone_verts(const MutableSpan<MVert> &verts, const ConeConfig &config)
{
Array<float2> circle(config.circle_segments);
- const float angle_delta = 2.0f * (M_PI / static_cast<float>(config.circle_segments));
+ const float angle_delta = 2.0f * (M_PI / float(config.circle_segments));
float angle = 0.0f;
for (const int i : IndexRange(config.circle_segments)) {
circle[i].x = std::cos(angle);
@@ -275,8 +275,7 @@ static void calculate_cone_vertices(const MutableSpan<MVert> &verts, const ConeC
/* Top fill including the outer edge of the fill. */
if (!config.top_is_point) {
- const float top_fill_radius_delta = config.radius_top /
- static_cast<float>(config.fill_segments);
+ const float top_fill_radius_delta = config.radius_top / float(config.fill_segments);
for (const int i : IndexRange(config.fill_segments)) {
const float top_fill_radius = top_fill_radius_delta * (i + 1);
for (const int j : IndexRange(config.circle_segments)) {
@@ -289,8 +288,8 @@ static void calculate_cone_vertices(const MutableSpan<MVert> &verts, const ConeC
/* Rings along the side. */
const float side_radius_delta = (config.radius_bottom - config.radius_top) /
- static_cast<float>(config.side_segments);
- const float height_delta = 2.0f * config.height / static_cast<float>(config.side_segments);
+ float(config.side_segments);
+ const float height_delta = 2.0f * config.height / float(config.side_segments);
for (const int i : IndexRange(config.side_segments - 1)) {
const float ring_radius = config.radius_top + (side_radius_delta * (i + 1));
const float ring_height = config.height - (height_delta * (i + 1));
@@ -303,8 +302,7 @@ static void calculate_cone_vertices(const MutableSpan<MVert> &verts, const ConeC
/* Bottom fill including the outer edge of the fill. */
if (!config.bottom_is_point) {
- const float bottom_fill_radius_delta = config.radius_bottom /
- static_cast<float>(config.fill_segments);
+ const float bottom_fill_radius_delta = config.radius_bottom / float(config.fill_segments);
for (const int i : IndexRange(config.fill_segments)) {
const float bottom_fill_radius = config.radius_bottom - (i * bottom_fill_radius_delta);
for (const int j : IndexRange(config.circle_segments)) {
@@ -480,12 +478,12 @@ static void calculate_selection_outputs(Mesh *mesh,
const ConeConfig &config,
ConeAttributeOutputs &attribute_outputs)
{
- MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*mesh);
+ MutableAttributeAccessor attributes = mesh->attributes_for_write();
/* Populate "Top" selection output. */
if (attribute_outputs.top_id) {
const bool face = !config.top_is_point && config.fill_type != GEO_NODE_MESH_CIRCLE_FILL_NONE;
- SpanAttributeWriter<bool> selection = attributes.lookup_or_add_for_write_only_span<bool>(
+ SpanAttributeWriter<bool> selection = attributes.lookup_or_add_for_write_span<bool>(
attribute_outputs.top_id.get(), face ? ATTR_DOMAIN_FACE : ATTR_DOMAIN_POINT);
if (config.top_is_point) {
@@ -501,7 +499,7 @@ static void calculate_selection_outputs(Mesh *mesh,
if (attribute_outputs.bottom_id) {
const bool face = !config.bottom_is_point &&
config.fill_type != GEO_NODE_MESH_CIRCLE_FILL_NONE;
- SpanAttributeWriter<bool> selection = attributes.lookup_or_add_for_write_only_span<bool>(
+ SpanAttributeWriter<bool> selection = attributes.lookup_or_add_for_write_span<bool>(
attribute_outputs.bottom_id.get(), face ? ATTR_DOMAIN_FACE : ATTR_DOMAIN_POINT);
if (config.bottom_is_point) {
@@ -518,7 +516,7 @@ static void calculate_selection_outputs(Mesh *mesh,
/* Populate "Side" selection output. */
if (attribute_outputs.side_id) {
- SpanAttributeWriter<bool> selection = attributes.lookup_or_add_for_write_only_span<bool>(
+ SpanAttributeWriter<bool> selection = attributes.lookup_or_add_for_write_span<bool>(
attribute_outputs.side_id.get(), ATTR_DOMAIN_FACE);
selection.span.slice(config.side_faces_start, config.side_faces_len).fill(true);
@@ -536,7 +534,7 @@ static void calculate_selection_outputs(Mesh *mesh,
*/
static void calculate_cone_uvs(Mesh *mesh, const ConeConfig &config)
{
- MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*mesh);
+ MutableAttributeAccessor attributes = mesh->attributes_for_write();
SpanAttributeWriter<float2> uv_attribute = attributes.lookup_or_add_for_write_only_span<float2>(
"uv_map", ATTR_DOMAIN_CORNER);
@@ -544,7 +542,7 @@ static void calculate_cone_uvs(Mesh *mesh, const ConeConfig &config)
Array<float2> circle(config.circle_segments);
float angle = 0.0f;
- const float angle_delta = 2.0f * M_PI / static_cast<float>(config.circle_segments);
+ const float angle_delta = 2.0f * M_PI / float(config.circle_segments);
for (const int i : IndexRange(config.circle_segments)) {
circle[i].x = std::cos(angle) * 0.225f;
circle[i].y = std::sin(angle) * 0.225f;
@@ -556,9 +554,8 @@ static void calculate_cone_uvs(Mesh *mesh, const ConeConfig &config)
/* Left circle of the UV representing the top fill or top cone tip. */
if (config.top_is_point || config.fill_type != GEO_NODE_MESH_CIRCLE_FILL_NONE) {
const float2 center_left(0.25f, 0.25f);
- const float radius_factor_delta = 1.0f / (config.top_is_point ?
- static_cast<float>(config.side_segments) :
- static_cast<float>(config.fill_segments));
+ const float radius_factor_delta = 1.0f / (config.top_is_point ? float(config.side_segments) :
+ float(config.fill_segments));
const int left_circle_segment_count = config.top_is_point ? config.side_segments :
config.fill_segments;
@@ -595,8 +592,8 @@ static void calculate_cone_uvs(Mesh *mesh, const ConeConfig &config)
if (!config.top_is_point && !config.bottom_is_point) {
/* Mesh is a truncated cone or cylinder. The sides are unwrapped into a rectangle. */
const float bottom = (config.fill_type == GEO_NODE_MESH_CIRCLE_FILL_NONE) ? 0.0f : 0.5f;
- const float x_delta = 1.0f / static_cast<float>(config.circle_segments);
- const float y_delta = (1.0f - bottom) / static_cast<float>(config.side_segments);
+ const float x_delta = 1.0f / float(config.circle_segments);
+ const float y_delta = (1.0f - bottom) / float(config.side_segments);
for (const int i : IndexRange(config.side_segments)) {
for (const int j : IndexRange(config.circle_segments)) {
@@ -612,8 +609,8 @@ static void calculate_cone_uvs(Mesh *mesh, const ConeConfig &config)
if (config.bottom_is_point || config.fill_type != GEO_NODE_MESH_CIRCLE_FILL_NONE) {
const float2 center_right(0.75f, 0.25f);
const float radius_factor_delta = 1.0f / (config.bottom_is_point ?
- static_cast<float>(config.side_segments) :
- static_cast<float>(config.fill_segments));
+ float(config.side_segments) :
+ float(config.fill_segments));
const int right_circle_segment_count = config.bottom_is_point ? config.side_segments :
config.fill_segments;
@@ -657,7 +654,7 @@ static Mesh *create_vertex_mesh()
{
/* Returns a mesh with a single vertex at the origin. */
Mesh *mesh = BKE_mesh_new_nomain(1, 0, 0, 0, 0);
- copy_v3_fl3(mesh->mvert[0].co, 0.0f, 0.0f, 0.0f);
+ copy_v3_fl3(mesh->verts_for_write().first().co, 0.0f, 0.0f, 0.0f);
return mesh;
}
@@ -679,7 +676,7 @@ Mesh *create_cylinder_or_cone_mesh(const float radius_top,
if (config.height == 0.0f) {
return create_vertex_mesh();
}
- const float z_delta = -2.0f * config.height / static_cast<float>(config.side_segments);
+ const float z_delta = -2.0f * config.height / float(config.side_segments);
const float3 start(0.0f, 0.0f, config.height);
const float3 delta(0.0f, 0.0f, z_delta);
return create_line_mesh(start, delta, config.tot_verts);
@@ -689,12 +686,12 @@ Mesh *create_cylinder_or_cone_mesh(const float radius_top,
config.tot_verts, config.tot_edges, 0, config.tot_corners, config.tot_faces);
BKE_id_material_eval_ensure_default_slot(&mesh->id);
- MutableSpan<MVert> verts{mesh->mvert, mesh->totvert};
- MutableSpan<MLoop> loops{mesh->mloop, mesh->totloop};
- MutableSpan<MEdge> edges{mesh->medge, mesh->totedge};
- MutableSpan<MPoly> polys{mesh->mpoly, mesh->totpoly};
+ MutableSpan<MVert> verts = mesh->verts_for_write();
+ MutableSpan<MEdge> edges = mesh->edges_for_write();
+ MutableSpan<MPoly> polys = mesh->polys_for_write();
+ MutableSpan<MLoop> loops = mesh->loops_for_write();
- calculate_cone_vertices(verts, config);
+ calculate_cone_verts(verts, config);
calculate_cone_edges(edges, config);
calculate_cone_faces(loops, polys, config);
calculate_cone_uvs(mesh, config);
@@ -746,7 +743,7 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Bool>(N_("Side")).field_source();
}
-static void node_init(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryMeshCone *node_storage = MEM_cnew<NodeGeometryMeshCone>(__func__);
@@ -757,7 +754,7 @@ static void node_init(bNodeTree *UNUSED(ntree), bNode *node)
static void node_update(bNodeTree *ntree, bNode *node)
{
- bNodeSocket *vertices_socket = (bNodeSocket *)node->inputs.first;
+ bNodeSocket *vertices_socket = static_cast<bNodeSocket *>(node->inputs.first);
bNodeSocket *rings_socket = vertices_socket->next;
bNodeSocket *fill_subdiv_socket = rings_socket->next;
@@ -767,7 +764,7 @@ static void node_update(bNodeTree *ntree, bNode *node)
nodeSetSocketAvailability(ntree, fill_subdiv_socket, has_fill);
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cylinder.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cylinder.cc
index 301d46e586f..f192b385b1b 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cylinder.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cylinder.cc
@@ -48,14 +48,14 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Bool>(N_("Bottom")).field_source();
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
uiItemR(layout, ptr, "fill_type", 0, nullptr, ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryMeshCylinder *node_storage = MEM_cnew<NodeGeometryMeshCylinder>(__func__);
@@ -66,7 +66,7 @@ static void node_init(bNodeTree *UNUSED(ntree), bNode *node)
static void node_update(bNodeTree *ntree, bNode *node)
{
- bNodeSocket *vertices_socket = (bNodeSocket *)node->inputs.first;
+ bNodeSocket *vertices_socket = static_cast<bNodeSocket *>(node->inputs.first);
bNodeSocket *rings_socket = vertices_socket->next;
bNodeSocket *fill_subdiv_socket = rings_socket->next;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_grid.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_grid.cc
index 9baf0b3171e..6f0b8283b72 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_grid.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_grid.cc
@@ -18,7 +18,7 @@ namespace blender::nodes {
static void calculate_uvs(
Mesh *mesh, Span<MVert> verts, Span<MLoop> loops, const float size_x, const float size_y)
{
- MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*mesh);
+ MutableAttributeAccessor attributes = mesh->attributes_for_write();
SpanAttributeWriter<float2> uv_attribute = attributes.lookup_or_add_for_write_only_span<float2>(
"uv_map", ATTR_DOMAIN_CORNER);
@@ -49,10 +49,10 @@ Mesh *create_grid_mesh(const int verts_x,
0,
edges_x * edges_y * 4,
edges_x * edges_y);
- MutableSpan<MVert> verts{mesh->mvert, mesh->totvert};
- MutableSpan<MLoop> loops{mesh->mloop, mesh->totloop};
- MutableSpan<MEdge> edges{mesh->medge, mesh->totedge};
- MutableSpan<MPoly> polys{mesh->mpoly, mesh->totpoly};
+ MutableSpan<MVert> verts = mesh->verts_for_write();
+ MutableSpan<MEdge> edges = mesh->edges_for_write();
+ MutableSpan<MPoly> polys = mesh->polys_for_write();
+ MutableSpan<MLoop> loops = mesh->loops_for_write();
{
const float dx = edges_x == 0 ? 0.0f : size_x / edges_x;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc
index aa9a2e9013f..8287c6a6714 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc
@@ -47,7 +47,7 @@ static Mesh *create_ico_sphere_mesh(const int subdivisions, const float radius)
BMeshToMeshParams params{};
params.calc_object_remap = false;
- Mesh *mesh = (Mesh *)BKE_id_new_nomain(ID_ME, nullptr);
+ Mesh *mesh = reinterpret_cast<Mesh *>(BKE_id_new_nomain(ID_ME, nullptr));
BKE_id_material_eval_ensure_default_slot(&mesh->id);
BM_mesh_bm_to_me(nullptr, bm, mesh, &params);
BM_mesh_free(bm);
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc
index 2af86b4b1d2..7faa7e23274 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc
@@ -43,7 +43,7 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Mesh"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
@@ -53,7 +53,7 @@ static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
}
}
-static void node_init(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryMeshLine *node_storage = MEM_cnew<NodeGeometryMeshLine>(__func__);
@@ -65,7 +65,7 @@ static void node_init(bNodeTree *UNUSED(ntree), bNode *node)
static void node_update(bNodeTree *ntree, bNode *node)
{
- bNodeSocket *count_socket = (bNodeSocket *)node->inputs.first;
+ bNodeSocket *count_socket = static_cast<bNodeSocket *>(node->inputs.first);
bNodeSocket *resolution_socket = count_socket->next;
bNodeSocket *start_socket = resolution_socket->next;
bNodeSocket *end_and_offset_socket = start_socket->next;
@@ -97,7 +97,7 @@ static void node_gather_link_searches(GatherLinkSearchOpParams &params)
return;
}
else if (params.node_tree().typeinfo->validate_link(
- static_cast<eNodeSocketDatatype>(params.other_socket().type), SOCK_FLOAT)) {
+ eNodeSocketDatatype(params.other_socket().type), SOCK_FLOAT)) {
params.add_item(IFACE_("Count"), [](LinkSearchOpParams &params) {
bNode &node = params.add_node("GeometryNodeMeshLine");
node_storage(node).mode = GEO_NODE_MESH_LINE_MODE_OFFSET;
@@ -153,7 +153,7 @@ static void node_geo_exec(GeoNodeExecParams params)
mesh = create_line_mesh(start, float3(0), count);
}
else {
- const float3 delta = total_delta / (float)(count - 1);
+ const float3 delta = total_delta / float(count - 1);
mesh = create_line_mesh(start, delta, count);
}
}
@@ -179,10 +179,11 @@ Mesh *create_line_mesh(const float3 start, const float3 delta, const int count)
Mesh *mesh = BKE_mesh_new_nomain(count, count - 1, 0, 0, 0);
BKE_id_material_eval_ensure_default_slot(&mesh->id);
- MutableSpan<MVert> verts{mesh->mvert, mesh->totvert};
- MutableSpan<MEdge> edges{mesh->medge, mesh->totedge};
+ MutableSpan<MVert> verts = mesh->verts_for_write();
+ MutableSpan<MEdge> edges = mesh->edges_for_write();
threading::parallel_invoke(
+ 1024 < count,
[&]() {
threading::parallel_for(verts.index_range(), 4096, [&](IndexRange range) {
for (const int i : range) {
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc
index f78752387c6..4b43693f0f6 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc
@@ -1,5 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "BLI_task.hh"
+
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
@@ -61,15 +63,26 @@ static int sphere_face_total(const int segments, const int rings)
* Also calculate vertex normals here, since the calculation is trivial, and it allows avoiding the
* calculation later, if it's necessary. The vertex normals are just the normalized positions.
*/
-static void calculate_sphere_vertex_data(MutableSpan<MVert> verts,
- MutableSpan<float3> vert_normals,
- const float radius,
- const int segments,
- const int rings)
+BLI_NOINLINE static void calculate_sphere_vertex_data(MutableSpan<MVert> verts,
+ MutableSpan<float3> vert_normals,
+ const float radius,
+ const int segments,
+ const int rings)
{
const float delta_theta = M_PI / rings;
const float delta_phi = (2.0f * M_PI) / segments;
+ Array<float, 64> segment_cosines(segments + 1);
+ for (const int segment : IndexRange(1, segments)) {
+ const float phi = segment * delta_phi;
+ segment_cosines[segment] = std::cos(phi);
+ }
+ Array<float, 64> segment_sines(segments + 1);
+ for (const int segment : IndexRange(1, segments)) {
+ const float phi = segment * delta_phi;
+ segment_sines[segment] = std::sin(phi);
+ }
+
copy_v3_v3(verts[0].co, float3(0.0f, 0.0f, radius));
vert_normals.first() = float3(0.0f, 0.0f, 1.0f);
@@ -79,9 +92,8 @@ static void calculate_sphere_vertex_data(MutableSpan<MVert> verts,
const float sin_theta = std::sin(theta);
const float z = std::cos(theta);
for (const int segment : IndexRange(1, segments)) {
- const float phi = segment * delta_phi;
- const float x = sin_theta * std::cos(phi);
- const float y = sin_theta * std::sin(phi);
+ const float x = sin_theta * segment_cosines[segment];
+ const float y = sin_theta * segment_sines[segment];
copy_v3_v3(verts[vert_index].co, float3(x, y, z) * radius);
vert_normals[vert_index] = float3(x, y, z);
vert_index++;
@@ -92,9 +104,9 @@ static void calculate_sphere_vertex_data(MutableSpan<MVert> verts,
vert_normals.last() = float3(0.0f, 0.0f, -1.0f);
}
-static void calculate_sphere_edge_indices(MutableSpan<MEdge> edges,
- const int segments,
- const int rings)
+BLI_NOINLINE static void calculate_sphere_edge_indices(MutableSpan<MEdge> edges,
+ const int segments,
+ const int rings)
{
int edge_index = 0;
@@ -142,20 +154,46 @@ static void calculate_sphere_edge_indices(MutableSpan<MEdge> edges,
}
}
-static void calculate_sphere_faces(MutableSpan<MLoop> loops,
- MutableSpan<MPoly> polys,
- const int segments,
- const int rings)
+BLI_NOINLINE static void calculate_sphere_faces(MutableSpan<MPoly> polys, const int segments)
{
int loop_index = 0;
- int poly_index = 0;
/* Add the triangles connected to the top vertex. */
- const int first_vert_ring_index_start = 1;
- for (const int segment : IndexRange(segments)) {
- MPoly &poly = polys[poly_index++];
+ for (MPoly &poly : polys.take_front(segments)) {
+ poly.loopstart = loop_index;
+ poly.totloop = 3;
+ loop_index += 3;
+ }
+
+ /* Add the middle quads. */
+ for (MPoly &poly : polys.drop_front(segments).drop_back(segments)) {
+ poly.loopstart = loop_index;
+ poly.totloop = 4;
+ loop_index += 4;
+ }
+
+ /* Add the triangles connected to the bottom vertex. */
+ for (MPoly &poly : polys.take_back(segments)) {
poly.loopstart = loop_index;
poly.totloop = 3;
+ loop_index += 3;
+ }
+}
+
+BLI_NOINLINE static void calculate_sphere_corners(MutableSpan<MLoop> loops,
+ const int segments,
+ const int rings)
+{
+ int loop_index = 0;
+ auto segment_next_or_first = [&](const int segment) {
+ return segment == segments - 1 ? 0 : segment + 1;
+ };
+
+ /* Add the triangles connected to the top vertex. */
+ const int first_vert_ring_index_start = 1;
+ for (const int segment : IndexRange(segments)) {
+ const int segment_next = segment_next_or_first(segment);
+
MLoop &loop_a = loops[loop_index++];
loop_a.v = 0;
loop_a.e = segment;
@@ -163,8 +201,8 @@ static void calculate_sphere_faces(MutableSpan<MLoop> loops,
loop_b.v = first_vert_ring_index_start + segment;
loop_b.e = segments + segment;
MLoop &loop_c = loops[loop_index++];
- loop_c.v = first_vert_ring_index_start + (segment + 1) % segments;
- loop_c.e = (segment + 1) % segments;
+ loop_c.v = first_vert_ring_index_start + segment_next;
+ loop_c.e = segment_next;
}
int ring_vert_index_start = 1;
@@ -175,9 +213,7 @@ static void calculate_sphere_faces(MutableSpan<MLoop> loops,
const int ring_vertical_edge_index_start = ring_edge_index_start + segments;
for (const int segment : IndexRange(segments)) {
- MPoly &poly = polys[poly_index++];
- poly.loopstart = loop_index;
- poly.totloop = 4;
+ const int segment_next = segment_next_or_first(segment);
MLoop &loop_a = loops[loop_index++];
loop_a.v = ring_vert_index_start + segment;
@@ -186,10 +222,10 @@ static void calculate_sphere_faces(MutableSpan<MLoop> loops,
loop_b.v = next_ring_vert_index_start + segment;
loop_b.e = next_ring_edge_index_start + segment;
MLoop &loop_c = loops[loop_index++];
- loop_c.v = next_ring_vert_index_start + (segment + 1) % segments;
- loop_c.e = ring_vertical_edge_index_start + (segment + 1) % segments;
+ loop_c.v = next_ring_vert_index_start + segment_next;
+ loop_c.e = ring_vertical_edge_index_start + segment_next;
MLoop &loop_d = loops[loop_index++];
- loop_d.v = ring_vert_index_start + (segment + 1) % segments;
+ loop_d.v = ring_vert_index_start + segment_next;
loop_d.e = ring_edge_index_start + segment;
}
ring_vert_index_start += segments;
@@ -202,15 +238,13 @@ static void calculate_sphere_faces(MutableSpan<MLoop> loops,
const int last_vert_index = sphere_vert_total(segments, rings) - 1;
const int last_vert_ring_start = last_vert_index - segments;
for (const int segment : IndexRange(segments)) {
- MPoly &poly = polys[poly_index++];
- poly.loopstart = loop_index;
- poly.totloop = 3;
+ const int segment_next = segment_next_or_first(segment);
MLoop &loop_a = loops[loop_index++];
loop_a.v = last_vert_index;
- loop_a.e = bottom_edge_fan_start + (segment + 1) % segments;
+ loop_a.e = bottom_edge_fan_start + segment_next;
MLoop &loop_b = loops[loop_index++];
- loop_b.v = last_vert_ring_start + (segment + 1) % segments;
+ loop_b.v = last_vert_ring_start + segment_next;
loop_b.e = last_edge_ring_start + segment;
MLoop &loop_c = loops[loop_index++];
loop_c.v = last_vert_ring_start + segment;
@@ -218,9 +252,9 @@ static void calculate_sphere_faces(MutableSpan<MLoop> loops,
}
}
-static void calculate_sphere_uvs(Mesh *mesh, const float segments, const float rings)
+BLI_NOINLINE static void calculate_sphere_uvs(Mesh *mesh, const float segments, const float rings)
{
- MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*mesh);
+ MutableAttributeAccessor attributes = mesh->attributes_for_write();
SpanAttributeWriter<float2> uv_attribute = attributes.lookup_or_add_for_write_only_span<float2>(
"uv_map", ATTR_DOMAIN_CORNER);
@@ -229,29 +263,31 @@ static void calculate_sphere_uvs(Mesh *mesh, const float segments, const float r
int loop_index = 0;
const float dy = 1.0f / rings;
+ const float segments_inv = 1.0f / segments;
+
for (const int i_segment : IndexRange(segments)) {
- const float segment = static_cast<float>(i_segment);
- uvs[loop_index++] = float2((segment + 0.5f) / segments, 0.0f);
- uvs[loop_index++] = float2(segment / segments, dy);
- uvs[loop_index++] = float2((segment + 1.0f) / segments, dy);
+ const float segment = float(i_segment);
+ uvs[loop_index++] = float2((segment + 0.5f) * segments_inv, 0.0f);
+ uvs[loop_index++] = float2(segment * segments_inv, dy);
+ uvs[loop_index++] = float2((segment + 1.0f) * segments_inv, dy);
}
for (const int i_ring : IndexRange(1, rings - 2)) {
- const float ring = static_cast<float>(i_ring);
+ const float ring = float(i_ring);
for (const int i_segment : IndexRange(segments)) {
- const float segment = static_cast<float>(i_segment);
- uvs[loop_index++] = float2(segment / segments, ring / rings);
- uvs[loop_index++] = float2(segment / segments, (ring + 1.0f) / rings);
- uvs[loop_index++] = float2((segment + 1.0f) / segments, (ring + 1.0f) / rings);
- uvs[loop_index++] = float2((segment + 1.0f) / segments, ring / rings);
+ const float segment = float(i_segment);
+ uvs[loop_index++] = float2(segment * segments_inv, ring / rings);
+ uvs[loop_index++] = float2(segment * segments_inv, (ring + 1.0f) / rings);
+ uvs[loop_index++] = float2((segment + 1.0f) * segments_inv, (ring + 1.0f) / rings);
+ uvs[loop_index++] = float2((segment + 1.0f) * segments_inv, ring / rings);
}
}
for (const int i_segment : IndexRange(segments)) {
- const float segment = static_cast<float>(i_segment);
- uvs[loop_index++] = float2((segment + 0.5f) / segments, 1.0f);
- uvs[loop_index++] = float2((segment + 1.0f) / segments, 1.0f - dy);
- uvs[loop_index++] = float2(segment / segments, 1.0f - dy);
+ const float segment = float(i_segment);
+ uvs[loop_index++] = float2((segment + 0.5f) * segments_inv, 1.0f);
+ uvs[loop_index++] = float2((segment + 1.0f) * segments_inv, 1.0f - dy);
+ uvs[loop_index++] = float2(segment * segments_inv, 1.0f - dy);
}
uv_attribute.finish();
@@ -265,20 +301,23 @@ static Mesh *create_uv_sphere_mesh(const float radius, const int segments, const
sphere_corner_total(segments, rings),
sphere_face_total(segments, rings));
BKE_id_material_eval_ensure_default_slot(&mesh->id);
- MutableSpan<MVert> verts{mesh->mvert, mesh->totvert};
- MutableSpan<MLoop> loops{mesh->mloop, mesh->totloop};
- MutableSpan<MEdge> edges{mesh->medge, mesh->totedge};
- MutableSpan<MPoly> polys{mesh->mpoly, mesh->totpoly};
-
- MutableSpan vert_normals{(float3 *)BKE_mesh_vertex_normals_for_write(mesh), mesh->totvert};
- calculate_sphere_vertex_data(verts, vert_normals, radius, segments, rings);
- BKE_mesh_vertex_normals_clear_dirty(mesh);
-
- calculate_sphere_edge_indices(edges, segments, rings);
-
- calculate_sphere_faces(loops, polys, segments, rings);
-
- calculate_sphere_uvs(mesh, segments, rings);
+ MutableSpan<MVert> verts = mesh->verts_for_write();
+ MutableSpan<MEdge> edges = mesh->edges_for_write();
+ MutableSpan<MPoly> polys = mesh->polys_for_write();
+ MutableSpan<MLoop> loops = mesh->loops_for_write();
+
+ threading::parallel_invoke(
+ 1024 < segments * rings,
+ [&]() {
+ MutableSpan vert_normals{
+ reinterpret_cast<float3 *>(BKE_mesh_vertex_normals_for_write(mesh)), mesh->totvert};
+ calculate_sphere_vertex_data(verts, vert_normals, radius, segments, rings);
+ BKE_mesh_vertex_normals_clear_dirty(mesh);
+ },
+ [&]() { calculate_sphere_edge_indices(edges, segments, rings); },
+ [&]() { calculate_sphere_faces(polys, segments); },
+ [&]() { calculate_sphere_corners(loops, segments, rings); },
+ [&]() { calculate_sphere_uvs(mesh, segments, rings); });
return mesh;
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_to_curve.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_to_curve.cc
index 40169def51e..4d08fa40a29 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_to_curve.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_to_curve.cc
@@ -1,5 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "DNA_mesh_types.h"
+
#include "GEO_mesh_to_curve.hh"
#include "node_geometry_util.hh"
@@ -24,9 +26,8 @@ static void node_geo_exec(GeoNodeExecParams params)
return;
}
- const MeshComponent &component = *geometry_set.get_component_for_read<MeshComponent>();
- GeometryComponentFieldContext context{component, ATTR_DOMAIN_EDGE};
- fn::FieldEvaluator evaluator{context, component.attribute_domain_size(ATTR_DOMAIN_EDGE)};
+ bke::MeshFieldContext context{*mesh, ATTR_DOMAIN_EDGE};
+ fn::FieldEvaluator evaluator{context, mesh->totedge};
evaluator.add(params.get_input<Field<bool>>("Selection"));
evaluator.evaluate();
const IndexMask selection = evaluator.get_evaluated_as_mask(0);
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_to_points.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_to_points.cc
index d3d1312be6d..d97a0e72060 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_to_points.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_to_points.cc
@@ -1,7 +1,9 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "BLI_array_utils.hh"
#include "BLI_task.hh"
+#include "DNA_mesh_types.h"
#include "DNA_pointcloud_types.h"
#include "BKE_attribute_math.hh"
@@ -22,7 +24,7 @@ static void node_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Geometry>(N_("Mesh")).supported_type(GEO_COMPONENT_TYPE_MESH);
b.add_input<decl::Bool>(N_("Selection")).default_value(true).supports_field().hide_value();
- b.add_input<decl::Vector>(N_("Position")).implicit_field();
+ b.add_input<decl::Vector>(N_("Position")).implicit_field(implicit_field_inputs::position);
b.add_input<decl::Float>(N_("Radius"))
.default_value(0.05f)
.min(0.0f)
@@ -31,47 +33,36 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Points"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryMeshToPoints *data = MEM_cnew<NodeGeometryMeshToPoints>(__func__);
data->mode = GEO_NODE_MESH_TO_POINTS_VERTICES;
node->storage = data;
}
-static void materialize_compressed_to_uninitialized_threaded(const GVArray &src,
- const IndexMask mask,
- GMutableSpan dst)
-{
- BLI_assert(src.type() == dst.type());
- BLI_assert(mask.size() == dst.size());
- threading::parallel_for(mask.index_range(), 4096, [&](IndexRange range) {
- src.materialize_compressed_to_uninitialized(mask.slice(range), dst.slice(range).data());
- });
-}
-
static void geometry_set_mesh_to_points(GeometrySet &geometry_set,
Field<float3> &position_field,
Field<float> &radius_field,
Field<bool> &selection_field,
const eAttrDomain domain)
{
- const MeshComponent *mesh_component = geometry_set.get_component_for_read<MeshComponent>();
- if (mesh_component == nullptr) {
+ const Mesh *mesh = geometry_set.get_mesh_for_read();
+ if (mesh == nullptr) {
geometry_set.remove_geometry_during_modify();
return;
}
- GeometryComponentFieldContext field_context{*mesh_component, domain};
- const int domain_num = mesh_component->attribute_domain_size(domain);
- if (domain_num == 0) {
+ const int domain_size = mesh->attributes().domain_size(domain);
+ if (domain_size == 0) {
geometry_set.remove_geometry_during_modify();
return;
}
- fn::FieldEvaluator evaluator{field_context, domain_num};
+ bke::MeshFieldContext field_context{*mesh, domain};
+ fn::FieldEvaluator evaluator{field_context, domain_size};
evaluator.set_selection(selection_field);
/* Evaluating directly into the point cloud doesn't work because we are not using the full
* "min_array_size" array but compressing the selected elements into the final array with no
@@ -83,19 +74,16 @@ static void geometry_set_mesh_to_points(GeometrySet &geometry_set,
PointCloud *pointcloud = BKE_pointcloud_new_nomain(selection.size());
geometry_set.replace_pointcloud(pointcloud);
- MutableAttributeAccessor pointcloud_attributes = bke::pointcloud_attributes_for_write(
- *pointcloud);
+ MutableAttributeAccessor dst_attributes = pointcloud->attributes_for_write();
- GSpanAttributeWriter position = pointcloud_attributes.lookup_or_add_for_write_only_span(
+ GSpanAttributeWriter position = dst_attributes.lookup_or_add_for_write_only_span(
"position", ATTR_DOMAIN_POINT, CD_PROP_FLOAT3);
- materialize_compressed_to_uninitialized_threaded(
- evaluator.get_evaluated(0), selection, position.span);
+ array_utils::gather(evaluator.get_evaluated(0), selection, position.span);
position.finish();
- GSpanAttributeWriter radius = pointcloud_attributes.lookup_or_add_for_write_only_span(
+ GSpanAttributeWriter radius = dst_attributes.lookup_or_add_for_write_only_span(
"radius", ATTR_DOMAIN_POINT, CD_PROP_FLOAT);
- materialize_compressed_to_uninitialized_threaded(
- evaluator.get_evaluated(1), selection, radius.span);
+ array_utils::gather(evaluator.get_evaluated(1), selection, radius.span);
radius.finish();
Map<AttributeIDRef, AttributeKind> attributes;
@@ -103,14 +91,16 @@ static void geometry_set_mesh_to_points(GeometrySet &geometry_set,
{GEO_COMPONENT_TYPE_MESH}, GEO_COMPONENT_TYPE_POINT_CLOUD, false, attributes);
attributes.remove("position");
+ const AttributeAccessor src_attributes = mesh->attributes();
+
for (Map<AttributeIDRef, AttributeKind>::Item entry : attributes.items()) {
const AttributeIDRef attribute_id = entry.key;
const eCustomDataType data_type = entry.value.data_type;
- GVArray src = mesh_component->attributes()->lookup_or_default(attribute_id, domain, data_type);
- GSpanAttributeWriter dst = pointcloud_attributes.lookup_or_add_for_write_only_span(
+ GVArray src = src_attributes.lookup_or_default(attribute_id, domain, data_type);
+ GSpanAttributeWriter dst = dst_attributes.lookup_or_add_for_write_only_span(
attribute_id, ATTR_DOMAIN_POINT, data_type);
if (dst && src) {
- materialize_compressed_to_uninitialized_threaded(src, selection, dst.span);
+ array_utils::gather(src, selection, dst.span);
dst.finish();
}
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_to_volume.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_to_volume.cc
index 92814a8bc5e..8885903f828 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_to_volume.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_to_volume.cc
@@ -50,33 +50,31 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Volume"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
uiItemR(layout, ptr, "resolution_mode", 0, IFACE_("Resolution"), ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
- NodeGeometryMeshToVolume *data = (NodeGeometryMeshToVolume *)MEM_callocN(
- sizeof(NodeGeometryMeshToVolume), __func__);
+ NodeGeometryMeshToVolume *data = MEM_cnew<NodeGeometryMeshToVolume>(__func__);
data->resolution_mode = MESH_TO_VOLUME_RESOLUTION_MODE_VOXEL_AMOUNT;
node->storage = data;
}
static void node_update(bNodeTree *ntree, bNode *node)
{
- NodeGeometryMeshToVolume *data = (NodeGeometryMeshToVolume *)node->storage;
+ NodeGeometryMeshToVolume &data = node_storage(*node);
bNodeSocket *voxel_size_socket = nodeFindSocket(node, SOCK_IN, "Voxel Size");
bNodeSocket *voxel_amount_socket = nodeFindSocket(node, SOCK_IN, "Voxel Amount");
nodeSetSocketAvailability(ntree,
voxel_amount_socket,
- data->resolution_mode == MESH_TO_VOLUME_RESOLUTION_MODE_VOXEL_AMOUNT);
- nodeSetSocketAvailability(ntree,
- voxel_size_socket,
- data->resolution_mode == MESH_TO_VOLUME_RESOLUTION_MODE_VOXEL_SIZE);
+ data.resolution_mode == MESH_TO_VOLUME_RESOLUTION_MODE_VOXEL_AMOUNT);
+ nodeSetSocketAvailability(
+ ntree, voxel_size_socket, data.resolution_mode == MESH_TO_VOLUME_RESOLUTION_MODE_VOXEL_SIZE);
}
#ifdef WITH_OPENVDB
@@ -126,7 +124,7 @@ static Volume *create_volume_from_mesh(const Mesh &mesh, GeoNodeExecParams &para
exterior_band_width,
mesh_to_volume_space_transform);
- Volume *volume = (Volume *)BKE_id_new_nomain(ID_VO, nullptr);
+ Volume *volume = reinterpret_cast<Volume *>(BKE_id_new_nomain(ID_VO, nullptr));
BKE_volume_init_grids(volume);
/* Convert mesh to grid and add to volume. */
@@ -149,7 +147,6 @@ static void node_geo_exec(GeoNodeExecParams params)
{
#ifdef WITH_OPENVDB
GeometrySet geometry_set(params.extract_input<GeometrySet>("Mesh"));
-
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
if (geometry_set.has_mesh()) {
Volume *volume = create_volume_from_mesh(*geometry_set.get_mesh_for_read(), params);
@@ -159,9 +156,9 @@ static void node_geo_exec(GeoNodeExecParams params)
});
params.set_output("Volume", std::move(geometry_set));
#else
+ params.set_default_remaining_outputs();
params.error_message_add(NodeWarningType::Error,
TIP_("Disabled, Blender was compiled without OpenVDB"));
- params.set_default_remaining_outputs();
return;
#endif
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_corners_of_face.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_corners_of_face.cc
new file mode 100644
index 00000000000..94bca02640b
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_corners_of_face.cc
@@ -0,0 +1,189 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "BLI_task.hh"
+
+#include "BKE_mesh.h"
+
+#include "node_geometry_util.hh"
+
+namespace blender::nodes::node_geo_mesh_topology_corners_of_face_cc {
+
+static void node_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::Int>(N_("Face Index"))
+ .implicit_field(implicit_field_inputs::index)
+ .description(N_("The face to retrieve data from. Defaults to the face from the context"));
+ b.add_input<decl::Float>(N_("Weights"))
+ .supports_field()
+ .hide_value()
+ .description(N_("Values used to sort the face's corners. Uses indices by default"));
+ b.add_input<decl::Int>(N_("Sort Index"))
+ .min(0)
+ .supports_field()
+ .description(N_("Which of the sorted corners to output"));
+ b.add_output<decl::Int>(N_("Corner Index"))
+ .dependent_field()
+ .description(N_("A corner of the face, chosen by the sort index"));
+ b.add_output<decl::Int>(N_("Total"))
+ .dependent_field()
+ .description(N_("The number of corners in the face"));
+}
+
+class CornersOfFaceInput final : public bke::MeshFieldInput {
+ const Field<int> face_index_;
+ const Field<int> sort_index_;
+ const Field<float> sort_weight_;
+
+ public:
+ CornersOfFaceInput(Field<int> face_index, Field<int> sort_index, Field<float> sort_weight)
+ : bke::MeshFieldInput(CPPType::get<int>(), "Corner of Face"),
+ face_index_(std::move(face_index)),
+ sort_index_(std::move(sort_index)),
+ sort_weight_(std::move(sort_weight))
+ {
+ category_ = Category::Generated;
+ }
+
+ GVArray get_varray_for_context(const Mesh &mesh,
+ const eAttrDomain domain,
+ const IndexMask mask) const final
+ {
+ const Span<MPoly> polys = mesh.polys();
+
+ const bke::MeshFieldContext context{mesh, domain};
+ fn::FieldEvaluator evaluator{context, &mask};
+ evaluator.add(face_index_);
+ evaluator.add(sort_index_);
+ evaluator.evaluate();
+ const VArray<int> face_indices = evaluator.get_evaluated<int>(0);
+ const VArray<int> indices_in_sort = evaluator.get_evaluated<int>(1);
+
+ const bke::MeshFieldContext corner_context{mesh, ATTR_DOMAIN_CORNER};
+ fn::FieldEvaluator corner_evaluator{corner_context, mesh.totloop};
+ corner_evaluator.add(sort_weight_);
+ corner_evaluator.evaluate();
+ const VArray<float> all_sort_weights = corner_evaluator.get_evaluated<float>(0);
+
+ Array<int> corner_of_face(mask.min_array_size());
+ threading::parallel_for(mask.index_range(), 1024, [&](const IndexRange range) {
+ /* Reuse arrays to avoid allocation. */
+ Array<float> sort_weights;
+ Array<int> sort_indices;
+
+ for (const int selection_i : mask.slice(range)) {
+ const int poly_i = face_indices[selection_i];
+ const int index_in_sort = indices_in_sort[selection_i];
+ if (!polys.index_range().contains(poly_i)) {
+ corner_of_face[selection_i] = 0;
+ continue;
+ }
+
+ const MPoly &poly = polys[poly_i];
+ const IndexRange corners(poly.loopstart, poly.totloop);
+
+ /* Retrieve the weights for each corner. */
+ sort_weights.reinitialize(corners.size());
+ all_sort_weights.materialize_compressed(IndexMask(corners),
+ sort_weights.as_mutable_span());
+
+ /* Sort a separate array of compressed indices corresponding to the compressed weights.
+ * This allows using `materialize_compressed` to avoid virtual function call overhead
+ * when accessing values in the sort weights. However, it means a separate array of
+ * indices within the compressed array is necessary for sorting. */
+ sort_indices.reinitialize(corners.size());
+ std::iota(sort_indices.begin(), sort_indices.end(), 0);
+ std::stable_sort(sort_indices.begin(), sort_indices.end(), [&](int a, int b) {
+ return sort_weights[a] < sort_weights[b];
+ });
+
+ const int index_in_sort_wrapped = mod_i(index_in_sort, corners.size());
+ corner_of_face[selection_i] = corners[sort_indices[index_in_sort_wrapped]];
+ }
+ });
+
+ return VArray<int>::ForContainer(std::move(corner_of_face));
+ }
+
+ uint64_t hash() const final
+ {
+ return 6927982716657;
+ }
+
+ bool is_equal_to(const fn::FieldNode &other) const final
+ {
+ if (const auto *typed = dynamic_cast<const CornersOfFaceInput *>(&other)) {
+ return typed->face_index_ == face_index_ && typed->sort_index_ == sort_index_ &&
+ typed->sort_weight_ == sort_weight_;
+ }
+ return false;
+ }
+};
+
+static int get_poly_totloop(const MPoly &poly)
+{
+ return poly.totloop;
+}
+
+class CornersOfFaceCountInput final : public bke::MeshFieldInput {
+ public:
+ CornersOfFaceCountInput() : bke::MeshFieldInput(CPPType::get<int>(), "Face Corner Count")
+ {
+ category_ = Category::Generated;
+ }
+
+ GVArray get_varray_for_context(const Mesh &mesh,
+ const eAttrDomain domain,
+ const IndexMask /*mask*/) const final
+ {
+ if (domain != ATTR_DOMAIN_FACE) {
+ return {};
+ }
+ return VArray<int>::ForDerivedSpan<MPoly, get_poly_totloop>(mesh.polys());
+ }
+
+ uint64_t hash() const final
+ {
+ return 8345908765432698;
+ }
+
+ bool is_equal_to(const fn::FieldNode &other) const final
+ {
+ if (dynamic_cast<const CornersOfFaceCountInput *>(&other)) {
+ return true;
+ }
+ return false;
+ }
+};
+
+static void node_geo_exec(GeoNodeExecParams params)
+{
+ const Field<int> face_index = params.extract_input<Field<int>>("Face Index");
+ if (params.output_is_required("Total")) {
+ params.set_output("Total",
+ Field<int>(std::make_shared<FieldAtIndexInput>(
+ face_index,
+ Field<int>(std::make_shared<CornersOfFaceCountInput>()),
+ ATTR_DOMAIN_FACE)));
+ }
+ if (params.output_is_required("Corner Index")) {
+ params.set_output("Corner Index",
+ Field<int>(std::make_shared<CornersOfFaceInput>(
+ face_index,
+ params.extract_input<Field<int>>("Sort Index"),
+ params.extract_input<Field<float>>("Weights"))));
+ }
+}
+
+} // namespace blender::nodes::node_geo_mesh_topology_corners_of_face_cc
+
+void register_node_type_geo_mesh_topology_corners_of_face()
+{
+ namespace file_ns = blender::nodes::node_geo_mesh_topology_corners_of_face_cc;
+
+ static bNodeType ntype;
+ geo_node_type_base(
+ &ntype, GEO_NODE_MESH_TOPOLOGY_CORNERS_OF_FACE, "Corners of Face", NODE_CLASS_INPUT);
+ ntype.geometry_node_execute = file_ns::node_geo_exec;
+ ntype.declare = file_ns::node_declare;
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_corners_of_vertex.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_corners_of_vertex.cc
new file mode 100644
index 00000000000..036af2d3b93
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_corners_of_vertex.cc
@@ -0,0 +1,209 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "BKE_mesh.h"
+#include "BKE_mesh_mapping.h"
+
+#include "BLI_task.hh"
+
+#include "node_geometry_util.hh"
+
+namespace blender::nodes::node_geo_mesh_topology_corners_of_vertex_cc {
+
+static void node_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::Int>(N_("Vertex Index"))
+ .implicit_field(implicit_field_inputs::index)
+ .description(
+ N_("The vertex to retrieve data from. Defaults to the vertex from the context"));
+ b.add_input<decl::Float>(N_("Weights"))
+ .supports_field()
+ .hide_value()
+ .description(
+ N_("Values used to sort corners attached to the vertex. Uses indices by default"));
+ b.add_input<decl::Int>(N_("Sort Index"))
+ .min(0)
+ .supports_field()
+ .description(N_("Which of the sorted corners to output"));
+ b.add_output<decl::Int>(N_("Corner Index"))
+ .dependent_field()
+ .description(N_("A corner connected to the face, chosen by the sort index"));
+ b.add_output<decl::Int>(N_("Total"))
+ .dependent_field()
+ .description(N_("The number of faces or corners connected to each vertex"));
+}
+
+static void convert_span(const Span<int> src, MutableSpan<int64_t> dst)
+{
+ for (const int i : src.index_range()) {
+ dst[i] = src[i];
+ }
+}
+
+class CornersOfVertInput final : public bke::MeshFieldInput {
+ const Field<int> vert_index_;
+ const Field<int> sort_index_;
+ const Field<float> sort_weight_;
+
+ public:
+ CornersOfVertInput(Field<int> vert_index, Field<int> sort_index, Field<float> sort_weight)
+ : bke::MeshFieldInput(CPPType::get<int>(), "Corner of Vertex"),
+ vert_index_(std::move(vert_index)),
+ sort_index_(std::move(sort_index)),
+ sort_weight_(std::move(sort_weight))
+ {
+ category_ = Category::Generated;
+ }
+
+ GVArray get_varray_for_context(const Mesh &mesh,
+ const eAttrDomain domain,
+ const IndexMask mask) const final
+ {
+ const IndexRange vert_range(mesh.totvert);
+ const Span<MLoop> loops = mesh.loops();
+ Array<Vector<int>> vert_to_loop_map = bke::mesh_topology::build_vert_to_loop_map(loops,
+ mesh.totvert);
+
+ const bke::MeshFieldContext context{mesh, domain};
+ fn::FieldEvaluator evaluator{context, &mask};
+ evaluator.add(vert_index_);
+ evaluator.add(sort_index_);
+ evaluator.evaluate();
+ const VArray<int> vert_indices = evaluator.get_evaluated<int>(0);
+ const VArray<int> indices_in_sort = evaluator.get_evaluated<int>(1);
+
+ const bke::MeshFieldContext corner_context{mesh, ATTR_DOMAIN_CORNER};
+ fn::FieldEvaluator corner_evaluator{corner_context, loops.size()};
+ corner_evaluator.add(sort_weight_);
+ corner_evaluator.evaluate();
+ const VArray<float> all_sort_weights = corner_evaluator.get_evaluated<float>(0);
+
+ Array<int> corner_of_vertex(mask.min_array_size());
+ threading::parallel_for(mask.index_range(), 1024, [&](const IndexRange range) {
+ /* Reuse arrays to avoid allocation. */
+ Array<int64_t> corner_indices;
+ Array<float> sort_weights;
+ Array<int> sort_indices;
+
+ for (const int selection_i : mask.slice(range)) {
+ const int vert_i = vert_indices[selection_i];
+ const int index_in_sort = indices_in_sort[selection_i];
+ if (!vert_range.contains(vert_i)) {
+ corner_of_vertex[selection_i] = 0;
+ continue;
+ }
+
+ const Span<int> corners = vert_to_loop_map[vert_i];
+ if (corners.is_empty()) {
+ corner_of_vertex[selection_i] = 0;
+ continue;
+ }
+
+ /* Retrieve the connected edge indices as 64 bit integers for #materialize_compressed. */
+ corner_indices.reinitialize(corners.size());
+ convert_span(corners, corner_indices);
+
+ /* Retrieve a compressed array of weights for each edge. */
+ sort_weights.reinitialize(corners.size());
+ all_sort_weights.materialize_compressed(IndexMask(corner_indices),
+ sort_weights.as_mutable_span());
+
+ /* Sort a separate array of compressed indices corresponding to the compressed weights.
+ * This allows using `materialize_compressed` to avoid virtual function call overhead
+ * when accessing values in the sort weights. However, it means a separate array of
+ * indices within the compressed array is necessary for sorting. */
+ sort_indices.reinitialize(corners.size());
+ std::iota(sort_indices.begin(), sort_indices.end(), 0);
+ std::stable_sort(sort_indices.begin(), sort_indices.end(), [&](int a, int b) {
+ return sort_weights[a] < sort_weights[b];
+ });
+
+ const int index_in_sort_wrapped = mod_i(index_in_sort, corners.size());
+ corner_of_vertex[selection_i] = corner_indices[sort_indices[index_in_sort_wrapped]];
+ }
+ });
+
+ return VArray<int>::ForContainer(std::move(corner_of_vertex));
+ }
+
+ uint64_t hash() const final
+ {
+ return 3541871368173645;
+ }
+
+ bool is_equal_to(const fn::FieldNode &other) const final
+ {
+ if (const auto *typed = dynamic_cast<const CornersOfVertInput *>(&other)) {
+ return typed->vert_index_ == vert_index_ && typed->sort_index_ == sort_index_ &&
+ typed->sort_weight_ == sort_weight_;
+ }
+ return false;
+ }
+};
+
+class CornersOfVertCountInput final : public bke::MeshFieldInput {
+ public:
+ CornersOfVertCountInput() : bke::MeshFieldInput(CPPType::get<int>(), "Vertex Corner Count")
+ {
+ category_ = Category::Generated;
+ }
+
+ GVArray get_varray_for_context(const Mesh &mesh,
+ const eAttrDomain domain,
+ const IndexMask /*mask*/) const final
+ {
+ if (domain != ATTR_DOMAIN_POINT) {
+ return {};
+ }
+ const Span<MLoop> loops = mesh.loops();
+ Array<int> counts(mesh.totvert, 0);
+ for (const int i : loops.index_range()) {
+ counts[loops[i].v]++;
+ }
+ return VArray<int>::ForContainer(std::move(counts));
+ }
+
+ uint64_t hash() const final
+ {
+ return 253098745374645;
+ }
+
+ bool is_equal_to(const fn::FieldNode &other) const final
+ {
+ if (dynamic_cast<const CornersOfVertCountInput *>(&other)) {
+ return true;
+ }
+ return false;
+ }
+};
+
+static void node_geo_exec(GeoNodeExecParams params)
+{
+ const Field<int> vert_index = params.extract_input<Field<int>>("Vertex Index");
+ if (params.output_is_required("Total")) {
+ params.set_output("Total",
+ Field<int>(std::make_shared<FieldAtIndexInput>(
+ vert_index,
+ Field<int>(std::make_shared<CornersOfVertCountInput>()),
+ ATTR_DOMAIN_POINT)));
+ }
+ if (params.output_is_required("Corner Index")) {
+ params.set_output("Corner Index",
+ Field<int>(std::make_shared<CornersOfVertInput>(
+ vert_index,
+ params.extract_input<Field<int>>("Sort Index"),
+ params.extract_input<Field<float>>("Weights"))));
+ }
+}
+} // namespace blender::nodes::node_geo_mesh_topology_corners_of_vertex_cc
+
+void register_node_type_geo_mesh_topology_corners_of_vertex()
+{
+ namespace file_ns = blender::nodes::node_geo_mesh_topology_corners_of_vertex_cc;
+
+ static bNodeType ntype;
+ geo_node_type_base(
+ &ntype, GEO_NODE_MESH_TOPOLOGY_CORNERS_OF_VERTEX, "Corners of Vertex", NODE_CLASS_INPUT);
+ ntype.geometry_node_execute = file_ns::node_geo_exec;
+ ntype.declare = file_ns::node_declare;
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_edges_of_corner.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_edges_of_corner.cc
new file mode 100644
index 00000000000..84b560cb48a
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_edges_of_corner.cc
@@ -0,0 +1,136 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "BKE_mesh.h"
+#include "BKE_mesh_mapping.h"
+
+#include "BLI_task.hh"
+
+#include "node_geometry_util.hh"
+
+namespace blender::nodes::node_geo_mesh_topology_edges_of_corner_cc {
+
+static void node_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::Int>(N_("Corner Index"))
+ .implicit_field(implicit_field_inputs::index)
+ .description(
+ N_("The corner to retrieve data from. Defaults to the corner from the context"));
+ b.add_output<decl::Int>(N_("Next Edge Index"))
+ .dependent_field()
+ .description(
+ N_("The edge after the corner in the face, in the direction of increasing indices"));
+ b.add_output<decl::Int>(N_("Previous Edge Index"))
+ .dependent_field()
+ .description(
+ N_("The edge before the corner in the face, in the direction of decreasing indices"));
+}
+
+static int get_loop_edge(const MLoop &loop)
+{
+ return loop.e;
+}
+
+class CornerNextEdgeFieldInput final : public bke::MeshFieldInput {
+ public:
+ CornerNextEdgeFieldInput() : bke::MeshFieldInput(CPPType::get<int>(), "Corner Next Edge")
+ {
+ category_ = Category::Generated;
+ }
+
+ GVArray get_varray_for_context(const Mesh &mesh,
+ const eAttrDomain domain,
+ const IndexMask /*mask*/) const final
+ {
+ if (domain != ATTR_DOMAIN_CORNER) {
+ return {};
+ }
+ return VArray<int>::ForDerivedSpan<MLoop, get_loop_edge>(mesh.loops());
+ }
+
+ uint64_t hash() const final
+ {
+ return 1892753404495;
+ }
+
+ bool is_equal_to(const fn::FieldNode &other) const final
+ {
+ if (dynamic_cast<const CornerNextEdgeFieldInput *>(&other)) {
+ return true;
+ }
+ return false;
+ }
+};
+
+class CornerPreviousEdgeFieldInput final : public bke::MeshFieldInput {
+ public:
+ CornerPreviousEdgeFieldInput() : bke::MeshFieldInput(CPPType::get<int>(), "Corner Previous Edge")
+ {
+ category_ = Category::Generated;
+ }
+
+ GVArray get_varray_for_context(const Mesh &mesh,
+ const eAttrDomain domain,
+ const IndexMask /*mask*/) const final
+ {
+ if (domain != ATTR_DOMAIN_CORNER) {
+ return {};
+ }
+ const Span<MPoly> polys = mesh.polys();
+ const Span<MLoop> loops = mesh.loops();
+ Array<int> loop_to_poly_map = bke::mesh_topology::build_loop_to_poly_map(polys, mesh.totloop);
+ return VArray<int>::ForFunc(
+ mesh.totloop,
+ [polys, loops, loop_to_poly_map = std::move(loop_to_poly_map)](const int corner_i) {
+ const int poly_i = loop_to_poly_map[corner_i];
+ const MPoly &poly = polys[poly_i];
+ const int corner_i_prev = bke::mesh_topology::previous_poly_loop(poly, corner_i);
+ return loops[corner_i_prev].e;
+ });
+ }
+
+ uint64_t hash() const final
+ {
+ return 987298345762465;
+ }
+
+ bool is_equal_to(const fn::FieldNode &other) const final
+ {
+ if (dynamic_cast<const CornerPreviousEdgeFieldInput *>(&other)) {
+ return true;
+ }
+ return false;
+ }
+};
+
+static void node_geo_exec(GeoNodeExecParams params)
+{
+ const Field<int> corner_index = params.extract_input<Field<int>>("Corner Index");
+ if (params.output_is_required("Next Edge Index")) {
+ params.set_output("Next Edge Index",
+ Field<int>(std::make_shared<FieldAtIndexInput>(
+ corner_index,
+ Field<int>(std::make_shared<CornerNextEdgeFieldInput>()),
+ ATTR_DOMAIN_CORNER)));
+ }
+ if (params.output_is_required("Previous Edge Index")) {
+ params.set_output("Previous Edge Index",
+ Field<int>(std::make_shared<FieldAtIndexInput>(
+ corner_index,
+ Field<int>(std::make_shared<CornerPreviousEdgeFieldInput>()),
+ ATTR_DOMAIN_CORNER)));
+ }
+}
+
+} // namespace blender::nodes::node_geo_mesh_topology_edges_of_corner_cc
+
+void register_node_type_geo_mesh_topology_edges_of_corner()
+{
+ namespace file_ns = blender::nodes::node_geo_mesh_topology_edges_of_corner_cc;
+
+ static bNodeType ntype;
+ geo_node_type_base(
+ &ntype, GEO_NODE_MESH_TOPOLOGY_EDGES_OF_CORNER, "Edges of Corner", NODE_CLASS_INPUT);
+ ntype.geometry_node_execute = file_ns::node_geo_exec;
+ ntype.declare = file_ns::node_declare;
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_edges_of_vertex.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_edges_of_vertex.cc
new file mode 100644
index 00000000000..f0cc191e217
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_edges_of_vertex.cc
@@ -0,0 +1,211 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "BKE_mesh.h"
+#include "BKE_mesh_mapping.h"
+
+#include "BLI_task.hh"
+
+#include "node_geometry_util.hh"
+
+namespace blender::nodes::node_geo_mesh_topology_edges_of_vertex_cc {
+
+static void node_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::Int>(N_("Vertex Index"))
+ .implicit_field(implicit_field_inputs::index)
+ .description(
+ N_("The vertex to retrieve data from. Defaults to the vertex from the context"));
+ b.add_input<decl::Float>(N_("Weights"))
+ .supports_field()
+ .hide_value()
+ .description(
+ N_("Values used to sort the edges connected to the vertex. Uses indices by default"));
+ b.add_input<decl::Int>(N_("Sort Index"))
+ .min(0)
+ .supports_field()
+ .description(N_("Which of the sorted edges to output"));
+ b.add_output<decl::Int>(N_("Edge Index"))
+ .dependent_field()
+ .description(N_("An edge connected to the face, chosen by the sort index"));
+ b.add_output<decl::Int>(N_("Total"))
+ .dependent_field()
+ .description(N_("The number of edges connected to each vertex"));
+}
+
+static void convert_span(const Span<int> src, MutableSpan<int64_t> dst)
+{
+ for (const int i : src.index_range()) {
+ dst[i] = src[i];
+ }
+}
+
+class EdgesOfVertInput final : public bke::MeshFieldInput {
+ const Field<int> vert_index_;
+ const Field<int> sort_index_;
+ const Field<float> sort_weight_;
+
+ public:
+ EdgesOfVertInput(Field<int> vert_index, Field<int> sort_index, Field<float> sort_weight)
+ : bke::MeshFieldInput(CPPType::get<int>(), "Edge of Vertex"),
+ vert_index_(std::move(vert_index)),
+ sort_index_(std::move(sort_index)),
+ sort_weight_(std::move(sort_weight))
+ {
+ category_ = Category::Generated;
+ }
+
+ GVArray get_varray_for_context(const Mesh &mesh,
+ const eAttrDomain domain,
+ const IndexMask mask) const final
+ {
+ const IndexRange vert_range(mesh.totvert);
+ const Span<MEdge> edges = mesh.edges();
+ Array<Vector<int>> vert_to_edge_map = bke::mesh_topology::build_vert_to_edge_map(edges,
+ mesh.totvert);
+
+ const bke::MeshFieldContext context{mesh, domain};
+ fn::FieldEvaluator evaluator{context, &mask};
+ evaluator.add(vert_index_);
+ evaluator.add(sort_index_);
+ evaluator.evaluate();
+ const VArray<int> vert_indices = evaluator.get_evaluated<int>(0);
+ const VArray<int> indices_in_sort = evaluator.get_evaluated<int>(1);
+
+ const bke::MeshFieldContext edge_context{mesh, ATTR_DOMAIN_EDGE};
+ fn::FieldEvaluator edge_evaluator{edge_context, mesh.totedge};
+ edge_evaluator.add(sort_weight_);
+ edge_evaluator.evaluate();
+ const VArray<float> all_sort_weights = edge_evaluator.get_evaluated<float>(0);
+
+ Array<int> edge_of_vertex(mask.min_array_size());
+ threading::parallel_for(mask.index_range(), 1024, [&](const IndexRange range) {
+ /* Reuse arrays to avoid allocation. */
+ Array<int64_t> edge_indices;
+ Array<float> sort_weights;
+ Array<int> sort_indices;
+
+ for (const int selection_i : mask.slice(range)) {
+ const int vert_i = vert_indices[selection_i];
+ const int index_in_sort = indices_in_sort[selection_i];
+ if (!vert_range.contains(vert_i)) {
+ edge_of_vertex[selection_i] = 0;
+ continue;
+ }
+
+ const Span<int> edges = vert_to_edge_map[vert_i];
+ if (edges.is_empty()) {
+ edge_of_vertex[selection_i] = 0;
+ continue;
+ }
+
+ /* Retrieve the connected edge indices as 64 bit integers for #materialize_compressed. */
+ edge_indices.reinitialize(edges.size());
+ convert_span(edges, edge_indices);
+
+ /* Retrieve a compressed array of weights for each edge. */
+ sort_weights.reinitialize(edges.size());
+ all_sort_weights.materialize_compressed(IndexMask(edge_indices),
+ sort_weights.as_mutable_span());
+
+ /* Sort a separate array of compressed indices corresponding to the compressed weights.
+ * This allows using `materialize_compressed` to avoid virtual function call overhead
+ * when accessing values in the sort weights. However, it means a separate array of
+ * indices within the compressed array is necessary for sorting. */
+ sort_indices.reinitialize(edges.size());
+ std::iota(sort_indices.begin(), sort_indices.end(), 0);
+ std::stable_sort(sort_indices.begin(), sort_indices.end(), [&](int a, int b) {
+ return sort_weights[a] < sort_weights[b];
+ });
+
+ const int index_in_sort_wrapped = mod_i(index_in_sort, edges.size());
+ edge_of_vertex[selection_i] = edge_indices[sort_indices[index_in_sort_wrapped]];
+ }
+ });
+
+ return VArray<int>::ForContainer(std::move(edge_of_vertex));
+ }
+
+ uint64_t hash() const final
+ {
+ return 98762349875636;
+ }
+
+ bool is_equal_to(const fn::FieldNode &other) const final
+ {
+ if (const auto *typed = dynamic_cast<const EdgesOfVertInput *>(&other)) {
+ return typed->vert_index_ == vert_index_ && typed->sort_index_ == sort_index_ &&
+ typed->sort_weight_ == sort_weight_;
+ }
+ return false;
+ }
+};
+
+class EdgesOfVertCountInput final : public bke::MeshFieldInput {
+ public:
+ EdgesOfVertCountInput() : bke::MeshFieldInput(CPPType::get<int>(), "Corner Face Index")
+ {
+ category_ = Category::Generated;
+ }
+
+ GVArray get_varray_for_context(const Mesh &mesh,
+ const eAttrDomain domain,
+ const IndexMask /*mask*/) const final
+ {
+ if (domain != ATTR_DOMAIN_POINT) {
+ return {};
+ }
+ const Span<MEdge> edges = mesh.edges();
+ Array<int> counts(mesh.totvert, 0);
+ for (const int i : edges.index_range()) {
+ counts[edges[i].v1]++;
+ counts[edges[i].v2]++;
+ }
+ return VArray<int>::ForContainer(std::move(counts));
+ }
+
+ uint64_t hash() const final
+ {
+ return 436758278618374;
+ }
+
+ bool is_equal_to(const fn::FieldNode &other) const final
+ {
+ if (dynamic_cast<const EdgesOfVertCountInput *>(&other)) {
+ return true;
+ }
+ return false;
+ }
+};
+
+static void node_geo_exec(GeoNodeExecParams params)
+{
+ const Field<int> vert_index = params.extract_input<Field<int>>("Vertex Index");
+ if (params.output_is_required("Total")) {
+ params.set_output("Total",
+ Field<int>(std::make_shared<FieldAtIndexInput>(
+ vert_index,
+ Field<int>(std::make_shared<EdgesOfVertCountInput>()),
+ ATTR_DOMAIN_POINT)));
+ }
+ if (params.output_is_required("Edge Index")) {
+ params.set_output("Edge Index",
+ Field<int>(std::make_shared<EdgesOfVertInput>(
+ vert_index,
+ params.extract_input<Field<int>>("Sort Index"),
+ params.extract_input<Field<float>>("Weights"))));
+ }
+}
+
+} // namespace blender::nodes::node_geo_mesh_topology_edges_of_vertex_cc
+
+void register_node_type_geo_mesh_topology_edges_of_vertex()
+{
+ namespace file_ns = blender::nodes::node_geo_mesh_topology_edges_of_vertex_cc;
+
+ static bNodeType ntype;
+ geo_node_type_base(
+ &ntype, GEO_NODE_MESH_TOPOLOGY_EDGES_OF_VERTEX, "Edges of Vertex", NODE_CLASS_INPUT);
+ ntype.geometry_node_execute = file_ns::node_geo_exec;
+ ntype.declare = file_ns::node_declare;
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_face_of_corner.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_face_of_corner.cc
new file mode 100644
index 00000000000..d9f944ca11e
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_face_of_corner.cc
@@ -0,0 +1,121 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "BKE_mesh.h"
+#include "BKE_mesh_mapping.h"
+
+#include "node_geometry_util.hh"
+
+namespace blender::nodes::node_geo_mesh_topology_face_of_corner_cc {
+
+static void node_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::Int>(N_("Corner Index"))
+ .implicit_field(implicit_field_inputs::index)
+ .description(
+ N_("The corner to retrieve data from. Defaults to the corner from the context"));
+ b.add_output<decl::Int>(N_("Face Index"))
+ .dependent_field()
+ .description(N_("The index of the face the corner is a part of"));
+ b.add_output<decl::Int>(N_("Index in Face"))
+ .dependent_field()
+ .description(N_("The index of the corner starting from the first corner in the face"));
+}
+
+class CornerFaceIndexInput final : public bke::MeshFieldInput {
+ public:
+ CornerFaceIndexInput() : bke::MeshFieldInput(CPPType::get<int>(), "Corner Face Index")
+ {
+ category_ = Category::Generated;
+ }
+
+ GVArray get_varray_for_context(const Mesh &mesh,
+ const eAttrDomain domain,
+ const IndexMask /*mask*/) const final
+ {
+ if (domain != ATTR_DOMAIN_CORNER) {
+ return {};
+ }
+ return VArray<int>::ForContainer(
+ bke::mesh_topology::build_loop_to_poly_map(mesh.polys(), mesh.totloop));
+ }
+
+ uint64_t hash() const final
+ {
+ return 2348712958475728;
+ }
+
+ bool is_equal_to(const fn::FieldNode &other) const final
+ {
+ return dynamic_cast<const CornerFaceIndexInput *>(&other) != nullptr;
+ }
+};
+
+class CornerIndexInFaceInput final : public bke::MeshFieldInput {
+ public:
+ CornerIndexInFaceInput() : bke::MeshFieldInput(CPPType::get<int>(), "Corner Index In Face")
+ {
+ category_ = Category::Generated;
+ }
+
+ GVArray get_varray_for_context(const Mesh &mesh,
+ const eAttrDomain domain,
+ const IndexMask /*mask*/) const final
+ {
+ if (domain != ATTR_DOMAIN_CORNER) {
+ return {};
+ }
+ const Span<MPoly> polys = mesh.polys();
+ Array<int> loop_to_poly_map = bke::mesh_topology::build_loop_to_poly_map(polys, mesh.totloop);
+ return VArray<int>::ForFunc(
+ mesh.totloop, [polys, loop_to_poly_map = std::move(loop_to_poly_map)](const int corner_i) {
+ const int poly_i = loop_to_poly_map[corner_i];
+ return corner_i - polys[poly_i].loopstart;
+ });
+ }
+
+ uint64_t hash() const final
+ {
+ return 97837176448;
+ }
+
+ bool is_equal_to(const fn::FieldNode &other) const final
+ {
+ if (dynamic_cast<const CornerIndexInFaceInput *>(&other)) {
+ return true;
+ }
+ return false;
+ }
+};
+
+static void node_geo_exec(GeoNodeExecParams params)
+{
+ const Field<int> corner_index = params.extract_input<Field<int>>("Corner Index");
+ if (params.output_is_required("Face Index")) {
+ params.set_output("Face Index",
+ Field<int>(std::make_shared<FieldAtIndexInput>(
+ corner_index,
+ Field<int>(std::make_shared<CornerFaceIndexInput>()),
+ ATTR_DOMAIN_CORNER)));
+ }
+ if (params.output_is_required("Index in Face")) {
+ params.set_output("Index in Face",
+ Field<int>(std::make_shared<FieldAtIndexInput>(
+ corner_index,
+ Field<int>(std::make_shared<CornerIndexInFaceInput>()),
+ ATTR_DOMAIN_CORNER)));
+ }
+}
+
+} // namespace blender::nodes::node_geo_mesh_topology_face_of_corner_cc
+
+void register_node_type_geo_mesh_topology_face_of_corner()
+{
+ namespace file_ns = blender::nodes::node_geo_mesh_topology_face_of_corner_cc;
+
+ static bNodeType ntype;
+ geo_node_type_base(
+ &ntype, GEO_NODE_MESH_TOPOLOGY_FACE_OF_CORNER, "Face of Corner", NODE_CLASS_INPUT);
+ ntype.geometry_node_execute = file_ns::node_geo_exec;
+ ntype.declare = file_ns::node_declare;
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_offset_corner_in_face.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_offset_corner_in_face.cc
new file mode 100644
index 00000000000..2cb9ae82fa1
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_offset_corner_in_face.cc
@@ -0,0 +1,113 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "BKE_mesh.h"
+#include "BKE_mesh_mapping.h"
+
+#include "BLI_task.hh"
+
+#include "node_geometry_util.hh"
+
+namespace blender::nodes::node_geo_mesh_topology_offset_corner_in_face_cc {
+
+static void node_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::Int>(N_("Corner Index"))
+ .implicit_field(implicit_field_inputs::index)
+ .description(
+ N_("The corner to retrieve data from. Defaults to the corner from the context"));
+ b.add_input<decl::Int>(N_("Offset"))
+ .supports_field()
+ .description(N_("The number of corners to move around the face before finding the result, "
+ "circling around the start of the face if necessary"));
+ b.add_output<decl::Int>(N_("Corner Index"))
+ .dependent_field()
+ .description(N_("The index of the offset corner"));
+}
+
+class OffsetCornerInFaceFieldInput final : public bke::MeshFieldInput {
+ const Field<int> corner_index_;
+ const Field<int> offset_;
+
+ public:
+ OffsetCornerInFaceFieldInput(Field<int> corner_index, Field<int> offset)
+ : bke::MeshFieldInput(CPPType::get<int>(), "Offset Corner in Face"),
+ corner_index_(std::move(corner_index)),
+ offset_(std::move(offset))
+ {
+ category_ = Category::Generated;
+ }
+
+ GVArray get_varray_for_context(const Mesh &mesh,
+ const eAttrDomain domain,
+ const IndexMask mask) const final
+ {
+ const IndexRange corner_range(mesh.totloop);
+ const Span<MPoly> polys = mesh.polys();
+
+ const bke::MeshFieldContext context{mesh, domain};
+ fn::FieldEvaluator evaluator{context, &mask};
+ evaluator.add(corner_index_);
+ evaluator.add(offset_);
+ evaluator.evaluate();
+ const VArray<int> corner_indices = evaluator.get_evaluated<int>(0);
+ const VArray<int> offsets = evaluator.get_evaluated<int>(1);
+
+ Array<int> loop_to_poly_map = bke::mesh_topology::build_loop_to_poly_map(polys, mesh.totloop);
+
+ Array<int> offset_corners(mask.min_array_size());
+ threading::parallel_for(mask.index_range(), 2048, [&](const IndexRange range) {
+ for (const int selection_i : range) {
+ const int corner_i = corner_indices[selection_i];
+ const int offset = offsets[selection_i];
+ if (!corner_range.contains(corner_i)) {
+ offset_corners[selection_i] = 0;
+ continue;
+ }
+
+ const int poly_i = loop_to_poly_map[corner_i];
+ const IndexRange poly_range(polys[poly_i].loopstart, polys[poly_i].totloop);
+ offset_corners[selection_i] = apply_offset_in_cyclic_range(poly_range, corner_i, offset);
+ }
+ });
+
+ return VArray<int>::ForContainer(std::move(offset_corners));
+ }
+
+ uint64_t hash() const final
+ {
+ return get_default_hash(offset_);
+ }
+
+ bool is_equal_to(const fn::FieldNode &other) const final
+ {
+ if (const OffsetCornerInFaceFieldInput *other_field =
+ dynamic_cast<const OffsetCornerInFaceFieldInput *>(&other)) {
+ return other_field->corner_index_ == corner_index_ && other_field->offset_ == offset_;
+ }
+ return false;
+ }
+};
+
+static void node_geo_exec(GeoNodeExecParams params)
+{
+ params.set_output("Corner Index",
+ Field<int>(std::make_shared<OffsetCornerInFaceFieldInput>(
+ params.extract_input<Field<int>>("Corner Index"),
+ params.extract_input<Field<int>>("Offset"))));
+}
+
+} // namespace blender::nodes::node_geo_mesh_topology_offset_corner_in_face_cc
+
+void register_node_type_geo_mesh_topology_offset_corner_in_face()
+{
+ namespace file_ns = blender::nodes::node_geo_mesh_topology_offset_corner_in_face_cc;
+
+ static bNodeType ntype;
+ geo_node_type_base(&ntype,
+ GEO_NODE_MESH_TOPOLOGY_OFFSET_CORNER_IN_FACE,
+ "Offset Corner in Face",
+ NODE_CLASS_INPUT);
+ ntype.geometry_node_execute = file_ns::node_geo_exec;
+ ntype.declare = file_ns::node_declare;
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_vertex_of_corner.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_vertex_of_corner.cc
new file mode 100644
index 00000000000..f0163fa553a
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_vertex_of_corner.cc
@@ -0,0 +1,79 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "BKE_mesh.h"
+
+#include "BLI_task.hh"
+
+#include "node_geometry_util.hh"
+
+namespace blender::nodes::node_geo_mesh_topology_vertex_of_corner_cc {
+
+static void node_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::Int>(N_("Corner Index"))
+ .implicit_field(implicit_field_inputs::index)
+ .description(
+ N_("The corner to retrieve data from. Defaults to the corner from the context"));
+ b.add_output<decl::Int>(N_("Vertex Index"))
+ .dependent_field()
+ .description(N_("The vertex the corner is attached to"));
+}
+
+static int get_loop_vert(const MLoop &loop)
+{
+ return loop.v;
+}
+
+class CornerVertFieldInput final : public bke::MeshFieldInput {
+ public:
+ CornerVertFieldInput() : bke::MeshFieldInput(CPPType::get<int>(), "Corner Vertex")
+ {
+ category_ = Category::Generated;
+ }
+
+ GVArray get_varray_for_context(const Mesh &mesh,
+ const eAttrDomain domain,
+ const IndexMask /*mask*/) const final
+ {
+ if (domain != ATTR_DOMAIN_CORNER) {
+ return {};
+ }
+ return VArray<int>::ForDerivedSpan<MLoop, get_loop_vert>(mesh.loops());
+ }
+
+ uint64_t hash() const final
+ {
+ return 30495867093876;
+ }
+
+ bool is_equal_to(const fn::FieldNode &other) const final
+ {
+ if (dynamic_cast<const CornerVertFieldInput *>(&other)) {
+ return true;
+ }
+ return false;
+ }
+};
+
+static void node_geo_exec(GeoNodeExecParams params)
+{
+ params.set_output("Vertex Index",
+ Field<int>(std::make_shared<FieldAtIndexInput>(
+ params.extract_input<Field<int>>("Corner Index"),
+ Field<int>(std::make_shared<CornerVertFieldInput>()),
+ ATTR_DOMAIN_CORNER)));
+}
+
+} // namespace blender::nodes::node_geo_mesh_topology_vertex_of_corner_cc
+
+void register_node_type_geo_mesh_topology_vertex_of_corner()
+{
+ namespace file_ns = blender::nodes::node_geo_mesh_topology_vertex_of_corner_cc;
+
+ static bNodeType ntype;
+ geo_node_type_base(
+ &ntype, GEO_NODE_MESH_TOPOLOGY_VERTEX_OF_CORNER, "Vertex of Corner", NODE_CLASS_INPUT);
+ ntype.geometry_node_execute = file_ns::node_geo_exec;
+ ntype.declare = file_ns::node_declare;
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_object_info.cc b/source/blender/nodes/geometry/nodes/node_geo_object_info.cc
index 0b2159364f1..bf064c6fcbe 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_object_info.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_object_info.cc
@@ -3,6 +3,7 @@
#include "BLI_math_matrix.h"
#include "BKE_geometry_set_instances.hh"
+#include "BKE_instances.hh"
#include "UI_interface.h"
#include "UI_resources.h"
@@ -25,7 +26,7 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Geometry"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "transform_space", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
}
@@ -68,19 +69,20 @@ static void node_geo_exec(GeoNodeExecParams params)
GeometrySet geometry_set;
if (params.get_input<bool>("As Instance")) {
- InstancesComponent &instances = geometry_set.get_component_for_write<InstancesComponent>();
- const int handle = instances.add_reference(*object);
+ std::unique_ptr<bke::Instances> instances = std::make_unique<bke::Instances>();
+ const int handle = instances->add_reference(*object);
if (transform_space_relative) {
- instances.add_instance(handle, transform);
+ instances->add_instance(handle, transform);
}
else {
- instances.add_instance(handle, float4x4::identity());
+ instances->add_instance(handle, float4x4::identity());
}
+ geometry_set = GeometrySet::create_with_instances(instances.release());
}
else {
geometry_set = bke::object_get_evaluated_geometry_set(*object);
if (transform_space_relative) {
- transform_geometry_set(geometry_set, transform, *params.depsgraph());
+ transform_geometry_set(params, geometry_set, transform, *params.depsgraph());
}
}
@@ -88,7 +90,7 @@ static void node_geo_exec(GeoNodeExecParams params)
}
}
-static void node_node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryObjectInfo *data = MEM_cnew<NodeGeometryObjectInfo>(__func__);
data->transform_space = GEO_NODE_TRANSFORM_SPACE_ORIGINAL;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_offset_point_in_curve.cc b/source/blender/nodes/geometry/nodes/node_geo_offset_point_in_curve.cc
new file mode 100644
index 00000000000..d71e27e0385
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_offset_point_in_curve.cc
@@ -0,0 +1,169 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "BLI_task.hh"
+
+#include "BKE_curves.hh"
+
+#include "node_geometry_util.hh"
+
+namespace blender::nodes {
+
+int apply_offset_in_cyclic_range(const IndexRange range, const int start_index, const int offset)
+{
+ BLI_assert(range.contains(start_index));
+ const int start_in_range = start_index - range.first();
+ const int offset_in_range = start_in_range + offset;
+ const int mod_offset = offset_in_range % range.size();
+ if (mod_offset >= 0) {
+ return range[mod_offset];
+ }
+ return range.last(-(mod_offset + 1));
+}
+
+} // namespace blender::nodes
+
+namespace blender::nodes::node_geo_offset_point_in_curve_cc {
+
+static void node_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::Int>(N_("Point Index"))
+ .implicit_field(implicit_field_inputs::index)
+ .description(
+ N_("The index of the control point to evaluate. Defaults to the current index"));
+ b.add_input<decl::Int>(N_("Offset"))
+ .supports_field()
+ .description(N_("The number of control points along the curve to traverse"));
+ b.add_output<decl::Bool>(N_("Is Valid Offset"))
+ .dependent_field()
+ .description(N_("Outputs true if the evaluated control point plus the offset "
+ "is a valid index of the original curve"));
+ b.add_output<decl::Int>(N_("Point Index"))
+ .dependent_field()
+ .description(N_("The index of the control point plus the offset within the entire "
+ "curves data-block"));
+}
+
+class ControlPointNeighborFieldInput final : public bke::CurvesFieldInput {
+ private:
+ const Field<int> index_;
+ const Field<int> offset_;
+
+ public:
+ ControlPointNeighborFieldInput(Field<int> index, Field<int> offset)
+ : CurvesFieldInput(CPPType::get<int>(), "Offset Point in Curve"),
+ index_(std::move(index)),
+ offset_(std::move(offset))
+ {
+ category_ = Category::Generated;
+ }
+
+ GVArray get_varray_for_context(const bke::CurvesGeometry &curves,
+ const eAttrDomain domain,
+ const IndexMask mask) const final
+ {
+ const VArray<bool> cyclic = curves.cyclic();
+ const Array<int> parent_curves = curves.point_to_curve_map();
+
+ const bke::CurvesFieldContext context{curves, domain};
+ fn::FieldEvaluator evaluator{context, &mask};
+ evaluator.add(index_);
+ evaluator.add(offset_);
+ evaluator.evaluate();
+ const VArray<int> indices = evaluator.get_evaluated<int>(0);
+ const VArray<int> offsets = evaluator.get_evaluated<int>(1);
+
+ Array<int> output(mask.min_array_size());
+ for (const int i_selection : mask) {
+ const int i_point = std::clamp(indices[i_selection], 0, curves.points_num() - 1);
+ const int i_curve = parent_curves[i_point];
+ const IndexRange curve_points = curves.points_for_curve(i_curve);
+ const int offset_point = i_point + offsets[i_point];
+
+ if (cyclic[i_curve]) {
+ output[i_selection] = apply_offset_in_cyclic_range(
+ curve_points, i_point, offsets[i_selection]);
+ continue;
+ }
+ output[i_selection] = std::clamp(offset_point, 0, curves.points_num() - 1);
+ }
+
+ return VArray<int>::ForContainer(std::move(output));
+ }
+};
+
+class OffsetValidFieldInput final : public bke::CurvesFieldInput {
+ private:
+ const Field<int> index_;
+ const Field<int> offset_;
+
+ public:
+ OffsetValidFieldInput(Field<int> index, Field<int> offset)
+ : CurvesFieldInput(CPPType::get<bool>(), "Offset Valid"),
+ index_(std::move(index)),
+ offset_(std::move(offset))
+ {
+ category_ = Category::Generated;
+ }
+
+ GVArray get_varray_for_context(const bke::CurvesGeometry &curves,
+ const eAttrDomain domain,
+ const IndexMask mask) const final
+ {
+ const VArray<bool> cyclic = curves.cyclic();
+ const Array<int> parent_curves = curves.point_to_curve_map();
+
+ const bke::CurvesFieldContext context{curves, domain};
+ fn::FieldEvaluator evaluator{context, &mask};
+ evaluator.add(index_);
+ evaluator.add(offset_);
+ evaluator.evaluate();
+ const VArray<int> indices = evaluator.get_evaluated<int>(0);
+ const VArray<int> offsets = evaluator.get_evaluated<int>(1);
+
+ Array<bool> output(mask.min_array_size());
+ for (const int i_selection : mask) {
+ const int i_point = indices[i_selection];
+ if (!curves.points_range().contains(i_point)) {
+ output[i_selection] = false;
+ continue;
+ }
+
+ const int i_curve = parent_curves[i_point];
+ const IndexRange curve_points = curves.points_for_curve(i_curve);
+ if (cyclic[i_curve]) {
+ output[i_selection] = true;
+ continue;
+ }
+ output[i_selection] = curve_points.contains(i_point + offsets[i_selection]);
+ };
+ return VArray<bool>::ForContainer(std::move(output));
+ }
+};
+
+static void node_geo_exec(GeoNodeExecParams params)
+{
+ Field<int> index = params.extract_input<Field<int>>("Point Index");
+ Field<int> offset = params.extract_input<Field<int>>("Offset");
+
+ if (params.output_is_required("Point Index")) {
+ Field<int> curve_point_field{std::make_shared<ControlPointNeighborFieldInput>(index, offset)};
+ params.set_output("Point Index", std::move(curve_point_field));
+ }
+ if (params.output_is_required("Is Valid Offset")) {
+ Field<bool> valid_field{std::make_shared<OffsetValidFieldInput>(index, offset)};
+ params.set_output("Is Valid Offset", std::move(valid_field));
+ }
+}
+
+} // namespace blender::nodes::node_geo_offset_point_in_curve_cc
+
+void register_node_type_geo_offset_point_in_curve()
+{
+ namespace file_ns = blender::nodes::node_geo_offset_point_in_curve_cc;
+ static bNodeType ntype;
+ geo_node_type_base(
+ &ntype, GEO_NODE_OFFSET_POINT_IN_CURVE, "Offset Point in Curve", NODE_CLASS_INPUT);
+ ntype.geometry_node_execute = file_ns::node_geo_exec;
+ ntype.declare = file_ns::node_declare;
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_points.cc b/source/blender/nodes/geometry/nodes/node_geo_points.cc
index dd32e6714f4..dcbe176b384 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_points.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_points.cc
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
#include "BKE_pointcloud.h"
+#include "DNA_pointcloud_types.h"
#include "BLI_task.hh"
@@ -19,9 +20,10 @@ static void node_declare(NodeDeclarationBuilder &b)
.default_value(float3(0.0f))
.description(N_("The positions of the new points"));
b.add_input<decl::Float>(N_("Radius"))
+ .min(0.0f)
+ .default_value(0.1f)
.supports_field()
.subtype(PROP_DISTANCE)
- .default_value(float(0.1f))
.description(N_("The radii of the new points"));
b.add_output<decl::Geometry>(N_("Geometry"));
}
@@ -42,7 +44,7 @@ class PointsFieldContext : public FieldContext {
GVArray get_varray_for_input(const FieldInput &field_input,
const IndexMask mask,
- ResourceScope &UNUSED(scope)) const
+ ResourceScope & /*scope*/) const
{
const bke::IDAttributeFieldInput *id_field_input =
dynamic_cast<const bke::IDAttributeFieldInput *>(&field_input);
@@ -69,10 +71,8 @@ static void node_geo_exec(GeoNodeExecParams params)
Field<float3> position_field = params.extract_input<Field<float3>>("Position");
Field<float> radius_field = params.extract_input<Field<float>>("Radius");
- PointCloud *new_point_cloud = BKE_pointcloud_new_nomain(count);
- GeometrySet geometry_set = GeometrySet::create_with_pointcloud(new_point_cloud);
- PointCloudComponent &points = geometry_set.get_component_for_write<PointCloudComponent>();
- MutableAttributeAccessor attributes = *points.attributes_for_write();
+ PointCloud *points = BKE_pointcloud_new_nomain(count);
+ MutableAttributeAccessor attributes = points->attributes_for_write();
AttributeWriter<float3> output_position = attributes.lookup_or_add_for_write<float3>(
"position", ATTR_DOMAIN_POINT);
AttributeWriter<float> output_radii = attributes.lookup_or_add_for_write<float>(
@@ -86,7 +86,7 @@ static void node_geo_exec(GeoNodeExecParams params)
output_position.finish();
output_radii.finish();
- params.set_output("Geometry", std::move(geometry_set));
+ params.set_output("Geometry", GeometrySet::create_with_pointcloud(points));
}
} // namespace blender::nodes::node_geo_points_cc
diff --git a/source/blender/nodes/geometry/nodes/node_geo_points_to_vertices.cc b/source/blender/nodes/geometry/nodes/node_geo_points_to_vertices.cc
index ed7ef9b7c71..4ac3bf712f7 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_points_to_vertices.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_points_to_vertices.cc
@@ -2,6 +2,8 @@
#include "BLI_task.hh"
+#include "DNA_pointcloud_types.h"
+
#include "BKE_attribute_math.hh"
#include "BKE_mesh.h"
@@ -22,21 +24,18 @@ static void node_declare(NodeDeclarationBuilder &b)
static void geometry_set_points_to_vertices(GeometrySet &geometry_set,
Field<bool> &selection_field)
{
- const PointCloudComponent *point_component =
- geometry_set.get_component_for_read<PointCloudComponent>();
- if (point_component == nullptr) {
+ const PointCloud *points = geometry_set.get_pointcloud_for_read();
+ if (points == nullptr) {
geometry_set.remove_geometry_during_modify();
return;
}
-
- GeometryComponentFieldContext field_context{*point_component, ATTR_DOMAIN_POINT};
- const int domain_num = point_component->attribute_domain_size(ATTR_DOMAIN_POINT);
- if (domain_num == 0) {
+ if (points->totpoint == 0) {
geometry_set.remove_geometry_during_modify();
return;
}
- fn::FieldEvaluator selection_evaluator{field_context, domain_num};
+ bke::PointCloudFieldContext field_context{*points};
+ fn::FieldEvaluator selection_evaluator{field_context, points->totpoint};
selection_evaluator.add(selection_field);
selection_evaluator.evaluate();
const IndexMask selection = selection_evaluator.get_evaluated_as_mask(0);
@@ -47,16 +46,16 @@ static void geometry_set_points_to_vertices(GeometrySet &geometry_set,
Mesh *mesh = BKE_mesh_new_nomain(selection.size(), 0, 0, 0, 0);
geometry_set.replace_mesh(mesh);
- MeshComponent &mesh_component = geometry_set.get_component_for_write<MeshComponent>();
+
+ const AttributeAccessor src_attributes = points->attributes();
+ MutableAttributeAccessor dst_attributes = mesh->attributes_for_write();
for (Map<AttributeIDRef, AttributeKind>::Item entry : attributes.items()) {
const AttributeIDRef attribute_id = entry.key;
const eCustomDataType data_type = entry.value.data_type;
- GVArray src = point_component->attributes()->lookup_or_default(
+ GVArray src = src_attributes.lookup_or_default(attribute_id, ATTR_DOMAIN_POINT, data_type);
+ GSpanAttributeWriter dst = dst_attributes.lookup_or_add_for_write_only_span(
attribute_id, ATTR_DOMAIN_POINT, data_type);
- GSpanAttributeWriter dst =
- mesh_component.attributes_for_write()->lookup_or_add_for_write_only_span(
- attribute_id, ATTR_DOMAIN_POINT, data_type);
if (dst && src) {
src.materialize_compressed_to_uninitialized(selection, dst.span.data());
dst.finish();
diff --git a/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc b/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc
index 4a3048e5f4a..45f6820f2e5 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc
@@ -43,14 +43,14 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Volume"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
uiItemR(layout, ptr, "resolution_mode", 0, IFACE_("Resolution"), ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryPointsToVolume *data = MEM_cnew<NodeGeometryPointsToVolume>(__func__);
data->resolution_mode = GEO_NODE_POINTS_TO_VOLUME_RESOLUTION_MODE_AMOUNT;
@@ -83,7 +83,7 @@ struct ParticleList {
size_t size() const
{
- return (size_t)positions.size();
+ return size_t(positions.size());
}
void getPos(size_t n, openvdb::Vec3R &xyz) const
@@ -170,7 +170,7 @@ static void gather_point_data_from_component(GeoNodeExecParams &params,
"position", ATTR_DOMAIN_POINT, {0, 0, 0});
Field<float> radius_field = params.get_input<Field<float>>("Radius");
- GeometryComponentFieldContext field_context{component, ATTR_DOMAIN_POINT};
+ bke::GeometryFieldContext field_context{component, ATTR_DOMAIN_POINT};
const int domain_num = component.attribute_domain_size(ATTR_DOMAIN_POINT);
r_positions.resize(r_positions.size() + domain_num);
@@ -215,7 +215,7 @@ static void initialize_volume_component_from_points(GeoNodeExecParams &params,
return;
}
- Volume *volume = (Volume *)BKE_id_new_nomain(ID_VO, nullptr);
+ Volume *volume = reinterpret_cast<Volume *>(BKE_id_new_nomain(ID_VO, nullptr));
BKE_volume_init_grids(volume);
const float density = params.get_input<float>("Density");
@@ -231,17 +231,16 @@ static void initialize_volume_component_from_points(GeoNodeExecParams &params,
static void node_geo_exec(GeoNodeExecParams params)
{
- GeometrySet geometry_set = params.extract_input<GeometrySet>("Points");
-
#ifdef WITH_OPENVDB
+ GeometrySet geometry_set = params.extract_input<GeometrySet>("Points");
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
initialize_volume_component_from_points(params, geometry_set);
});
params.set_output("Volume", std::move(geometry_set));
#else
+ params.set_default_remaining_outputs();
params.error_message_add(NodeWarningType::Error,
TIP_("Disabled, Blender was compiled without OpenVDB"));
- params.set_default_remaining_outputs();
#endif
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_proximity.cc b/source/blender/nodes/geometry/nodes/node_geo_proximity.cc
index d5233ee35a4..21f4449baee 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_proximity.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_proximity.cc
@@ -22,17 +22,17 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_input<decl::Geometry>(N_("Target"))
.only_realized_data()
.supported_type({GEO_COMPONENT_TYPE_MESH, GEO_COMPONENT_TYPE_POINT_CLOUD});
- b.add_input<decl::Vector>(N_("Source Position")).implicit_field();
+ b.add_input<decl::Vector>(N_("Source Position")).implicit_field(implicit_field_inputs::position);
b.add_output<decl::Vector>(N_("Position")).dependent_field();
b.add_output<decl::Float>(N_("Distance")).dependent_field();
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "target_element", 0, "", ICON_NONE);
}
-static void geo_proximity_init(bNodeTree *UNUSED(ntree), bNode *node)
+static void geo_proximity_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryProximity *node_storage = MEM_cnew<NodeGeometryProximity>(__func__);
node_storage->target_element = GEO_NODE_PROX_TARGET_FACES;
@@ -151,7 +151,7 @@ class ProximityFunction : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
const VArray<float3> &src_positions = params.readonly_single_input<float3>(0,
"Source Position");
@@ -211,8 +211,7 @@ static void node_geo_exec(GeoNodeExecParams params)
Field<float3> position_field = params.extract_input<Field<float3>>("Source Position");
auto proximity_fn = std::make_unique<ProximityFunction>(
- std::move(geometry_set_target),
- static_cast<GeometryNodeProximityTargetType>(storage.target_element));
+ std::move(geometry_set_target), GeometryNodeProximityTargetType(storage.target_element));
auto proximity_op = std::make_shared<FieldOperation>(
FieldOperation(std::move(proximity_fn), {std::move(position_field)}));
diff --git a/source/blender/nodes/geometry/nodes/node_geo_raycast.cc b/source/blender/nodes/geometry/nodes/node_geo_raycast.cc
index f81748da587..d248bc539b1 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_raycast.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_raycast.cc
@@ -31,7 +31,7 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_input<decl::Bool>(N_("Attribute"), "Attribute_003").hide_value().supports_field();
b.add_input<decl::Int>(N_("Attribute"), "Attribute_004").hide_value().supports_field();
- b.add_input<decl::Vector>(N_("Source Position")).implicit_field();
+ b.add_input<decl::Vector>(N_("Source Position")).implicit_field(implicit_field_inputs::position);
b.add_input<decl::Vector>(N_("Ray Direction"))
.default_value({0.0f, 0.0f, -1.0f})
.supports_field();
@@ -53,13 +53,13 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Int>(N_("Attribute"), "Attribute_004").dependent_field({1, 2, 3, 4, 5, 6});
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE);
uiItemR(layout, ptr, "mapping", 0, "", ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryRaycast *data = MEM_cnew<NodeGeometryRaycast>(__func__);
data->mapping = GEO_NODE_RAYCAST_INTERPOLATED;
@@ -70,9 +70,9 @@ static void node_init(bNodeTree *UNUSED(tree), bNode *node)
static void node_update(bNodeTree *ntree, bNode *node)
{
const NodeGeometryRaycast &storage = node_storage(*node);
- const eCustomDataType data_type = static_cast<eCustomDataType>(storage.data_type);
+ const eCustomDataType data_type = eCustomDataType(storage.data_type);
- bNodeSocket *socket_vector = (bNodeSocket *)BLI_findlink(&node->inputs, 1);
+ bNodeSocket *socket_vector = static_cast<bNodeSocket *>(BLI_findlink(&node->inputs, 1));
bNodeSocket *socket_float = socket_vector->next;
bNodeSocket *socket_color4f = socket_float->next;
bNodeSocket *socket_boolean = socket_color4f->next;
@@ -84,7 +84,7 @@ static void node_update(bNodeTree *ntree, bNode *node)
nodeSetSocketAvailability(ntree, socket_boolean, data_type == CD_PROP_BOOL);
nodeSetSocketAvailability(ntree, socket_int32, data_type == CD_PROP_INT32);
- bNodeSocket *out_socket_vector = (bNodeSocket *)BLI_findlink(&node->outputs, 4);
+ bNodeSocket *out_socket_vector = static_cast<bNodeSocket *>(BLI_findlink(&node->outputs, 4));
bNodeSocket *out_socket_float = out_socket_vector->next;
bNodeSocket *out_socket_color4f = out_socket_float->next;
bNodeSocket *out_socket_boolean = out_socket_color4f->next;
@@ -208,7 +208,7 @@ class RaycastFunction : public fn::MultiFunction {
GeometryNodeRaycastMapMode mapping_;
/** The field for data evaluated on the target geometry. */
- std::optional<GeometryComponentFieldContext> target_context_;
+ std::optional<bke::MeshFieldContext> target_context_;
std::unique_ptr<FieldEvaluator> target_evaluator_;
const GVArray *target_data_ = nullptr;
@@ -245,7 +245,7 @@ class RaycastFunction : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
/* Hit positions are always necessary for retrieving the attribute from the target if that
* output is required, so always retrieve a span from the evaluator in that case (it's
@@ -310,9 +310,9 @@ class RaycastFunction : public fn::MultiFunction {
if (!src_field) {
return;
}
- const MeshComponent &mesh_component = *target_.get_component_for_read<MeshComponent>();
- target_context_.emplace(GeometryComponentFieldContext{mesh_component, domain_});
- const int domain_size = mesh_component.attribute_domain_size(domain_);
+ const Mesh &mesh = *target_.get_mesh_for_read();
+ target_context_.emplace(bke::MeshFieldContext{mesh, domain_});
+ const int domain_size = mesh.attributes().domain_size(domain_);
target_evaluator_ = std::make_unique<FieldEvaluator>(*target_context_, domain_size);
target_evaluator_->add(std::move(src_field));
target_evaluator_->evaluate();
@@ -386,8 +386,8 @@ static void node_geo_exec(GeoNodeExecParams params)
{
GeometrySet target = params.extract_input<GeometrySet>("Target Geometry");
const NodeGeometryRaycast &storage = node_storage(params.node());
- const GeometryNodeRaycastMapMode mapping = (GeometryNodeRaycastMapMode)storage.mapping;
- const eCustomDataType data_type = static_cast<eCustomDataType>(storage.data_type);
+ const GeometryNodeRaycastMapMode mapping = GeometryNodeRaycastMapMode(storage.mapping);
+ const eCustomDataType data_type = eCustomDataType(storage.data_type);
if (target.is_empty()) {
params.set_default_remaining_outputs();
diff --git a/source/blender/nodes/geometry/nodes/node_geo_realize_instances.cc b/source/blender/nodes/geometry/nodes/node_geo_realize_instances.cc
index 1c72d73d151..3ccc8afb0a7 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_realize_instances.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_realize_instances.cc
@@ -15,7 +15,7 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Geometry"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "legacy_behavior", 0, nullptr, ICON_NONE);
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_remove_attribute.cc b/source/blender/nodes/geometry/nodes/node_geo_remove_attribute.cc
index ee279ba58f9..1b398f63691 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_remove_attribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_remove_attribute.cc
@@ -55,7 +55,7 @@ static void node_geo_exec(GeoNodeExecParams params)
});
if (attribute_exists && !cannot_delete) {
- params.used_named_attribute(name, eNamedAttrUsage::Remove);
+ params.used_named_attribute(name, NamedAttributeUsage::Remove);
}
if (!attribute_exists) {
diff --git a/source/blender/nodes/geometry/nodes/node_geo_rotate_instances.cc b/source/blender/nodes/geometry/nodes/node_geo_rotate_instances.cc
index d414bb1fa1d..fac92a7500c 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_rotate_instances.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_rotate_instances.cc
@@ -2,6 +2,8 @@
#include "BLI_task.hh"
+#include "BKE_instances.hh"
+
#include "node_geometry_util.hh"
namespace blender::nodes::node_geo_rotate_instances_cc {
@@ -16,12 +18,10 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Instances"));
}
-static void rotate_instances(GeoNodeExecParams &params, InstancesComponent &instances_component)
+static void rotate_instances(GeoNodeExecParams &params, bke::Instances &instances)
{
- GeometryComponentFieldContext field_context{instances_component, ATTR_DOMAIN_INSTANCE};
- const int domain_num = instances_component.instances_num();
-
- fn::FieldEvaluator evaluator{field_context, domain_num};
+ const bke::InstancesFieldContext context{instances};
+ fn::FieldEvaluator evaluator{context, instances.instances_num()};
evaluator.set_selection(params.extract_input<Field<bool>>("Selection"));
evaluator.add(params.extract_input<Field<float3>>("Rotation"));
evaluator.add(params.extract_input<Field<float3>>("Pivot Point"));
@@ -33,14 +33,14 @@ static void rotate_instances(GeoNodeExecParams &params, InstancesComponent &inst
const VArray<float3> pivots = evaluator.get_evaluated<float3>(1);
const VArray<bool> local_spaces = evaluator.get_evaluated<bool>(2);
- MutableSpan<float4x4> instance_transforms = instances_component.instance_transforms();
+ MutableSpan<float4x4> transforms = instances.transforms();
threading::parallel_for(selection.index_range(), 512, [&](IndexRange range) {
for (const int i_selection : range) {
const int i = selection[i_selection];
const float3 pivot = pivots[i];
const float3 euler = rotations[i];
- float4x4 &instance_transform = instance_transforms[i];
+ float4x4 &instance_transform = transforms[i];
float4x4 rotation_matrix;
float3 used_pivot;
@@ -83,9 +83,8 @@ static void rotate_instances(GeoNodeExecParams &params, InstancesComponent &inst
static void node_geo_exec(GeoNodeExecParams params)
{
GeometrySet geometry_set = params.extract_input<GeometrySet>("Instances");
- if (geometry_set.has_instances()) {
- InstancesComponent &instances = geometry_set.get_component_for_write<InstancesComponent>();
- rotate_instances(params, instances);
+ if (bke::Instances *instances = geometry_set.get_instances_for_write()) {
+ rotate_instances(params, *instances);
}
params.set_output("Instances", std::move(geometry_set));
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_sample_index.cc b/source/blender/nodes/geometry/nodes/node_geo_sample_index.cc
new file mode 100644
index 00000000000..4d2db059798
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_sample_index.cc
@@ -0,0 +1,337 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "BLI_task.hh"
+
+#include "BKE_attribute_math.hh"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "NOD_socket_search_link.hh"
+
+#include "node_geometry_util.hh"
+
+namespace blender::nodes::node_geo_sample_index_cc {
+
+NODE_STORAGE_FUNCS(NodeGeometrySampleIndex);
+
+static void node_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::Geometry>(N_("Geometry"))
+ .supported_type({GEO_COMPONENT_TYPE_MESH,
+ GEO_COMPONENT_TYPE_POINT_CLOUD,
+ GEO_COMPONENT_TYPE_CURVE,
+ GEO_COMPONENT_TYPE_INSTANCES});
+
+ b.add_input<decl::Float>(N_("Value"), "Value_Float").hide_value().supports_field();
+ b.add_input<decl::Int>(N_("Value"), "Value_Int").hide_value().supports_field();
+ b.add_input<decl::Vector>(N_("Value"), "Value_Vector").hide_value().supports_field();
+ b.add_input<decl::Color>(N_("Value"), "Value_Color").hide_value().supports_field();
+ b.add_input<decl::Bool>(N_("Value"), "Value_Bool").hide_value().supports_field();
+ b.add_input<decl::Int>(N_("Index"))
+ .supports_field()
+ .description(N_("Which element to retrieve a value from on the geometry"));
+
+ b.add_output<decl::Float>(N_("Value"), "Value_Float").dependent_field({6});
+ b.add_output<decl::Int>(N_("Value"), "Value_Int").dependent_field({6});
+ b.add_output<decl::Vector>(N_("Value"), "Value_Vector").dependent_field({6});
+ b.add_output<decl::Color>(N_("Value"), "Value_Color").dependent_field({6});
+ b.add_output<decl::Bool>(N_("Value"), "Value_Bool").dependent_field({6});
+}
+
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
+{
+ uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE);
+ uiItemR(layout, ptr, "domain", 0, "", ICON_NONE);
+ uiItemR(layout, ptr, "clamp", 0, nullptr, ICON_NONE);
+}
+
+static void node_init(bNodeTree * /*tree*/, bNode *node)
+{
+ NodeGeometrySampleIndex *data = MEM_cnew<NodeGeometrySampleIndex>(__func__);
+ data->data_type = CD_PROP_FLOAT;
+ data->domain = ATTR_DOMAIN_POINT;
+ data->clamp = 0;
+ node->storage = data;
+}
+
+static void node_update(bNodeTree *ntree, bNode *node)
+{
+ const eCustomDataType data_type = eCustomDataType(node_storage(*node).data_type);
+
+ bNodeSocket *in_socket_geometry = static_cast<bNodeSocket *>(node->inputs.first);
+ bNodeSocket *in_socket_float = in_socket_geometry->next;
+ bNodeSocket *in_socket_int32 = in_socket_float->next;
+ bNodeSocket *in_socket_vector = in_socket_int32->next;
+ bNodeSocket *in_socket_color4f = in_socket_vector->next;
+ bNodeSocket *in_socket_bool = in_socket_color4f->next;
+
+ nodeSetSocketAvailability(ntree, in_socket_vector, data_type == CD_PROP_FLOAT3);
+ nodeSetSocketAvailability(ntree, in_socket_float, data_type == CD_PROP_FLOAT);
+ nodeSetSocketAvailability(ntree, in_socket_color4f, data_type == CD_PROP_COLOR);
+ nodeSetSocketAvailability(ntree, in_socket_bool, data_type == CD_PROP_BOOL);
+ nodeSetSocketAvailability(ntree, in_socket_int32, data_type == CD_PROP_INT32);
+
+ bNodeSocket *out_socket_float = static_cast<bNodeSocket *>(node->outputs.first);
+ bNodeSocket *out_socket_int32 = out_socket_float->next;
+ bNodeSocket *out_socket_vector = out_socket_int32->next;
+ bNodeSocket *out_socket_color4f = out_socket_vector->next;
+ bNodeSocket *out_socket_bool = out_socket_color4f->next;
+
+ nodeSetSocketAvailability(ntree, out_socket_vector, data_type == CD_PROP_FLOAT3);
+ nodeSetSocketAvailability(ntree, out_socket_float, data_type == CD_PROP_FLOAT);
+ nodeSetSocketAvailability(ntree, out_socket_color4f, data_type == CD_PROP_COLOR);
+ nodeSetSocketAvailability(ntree, out_socket_bool, data_type == CD_PROP_BOOL);
+ nodeSetSocketAvailability(ntree, out_socket_int32, data_type == CD_PROP_INT32);
+}
+
+static void node_gather_link_searches(GatherLinkSearchOpParams &params)
+{
+ const NodeDeclaration &declaration = *params.node_type().fixed_declaration;
+ search_link_ops_for_declarations(params, declaration.inputs().take_back(1));
+ search_link_ops_for_declarations(params, declaration.inputs().take_front(1));
+
+ const std::optional<eCustomDataType> type = node_data_type_to_custom_data_type(
+ (eNodeSocketDatatype)params.other_socket().type);
+ if (type && *type != CD_PROP_STRING) {
+ /* The input and output sockets have the same name. */
+ params.add_item(IFACE_("Value"), [type](LinkSearchOpParams &params) {
+ bNode &node = params.add_node("GeometryNodeSampleIndex");
+ node_storage(node).data_type = *type;
+ params.update_and_connect_available_socket(node, "Value");
+ });
+ }
+}
+
+static bool component_is_available(const GeometrySet &geometry,
+ const GeometryComponentType type,
+ const eAttrDomain domain)
+{
+ if (!geometry.has(type)) {
+ return false;
+ }
+ const GeometryComponent &component = *geometry.get_component_for_read(type);
+ if (component.is_empty()) {
+ return false;
+ }
+ return component.attribute_domain_size(domain) != 0;
+}
+
+static const GeometryComponent *find_source_component(const GeometrySet &geometry,
+ const eAttrDomain domain)
+{
+ /* Choose the other component based on a consistent order, rather than some more complicated
+ * heuristic. This is the same order visible in the spreadsheet and used in the ray-cast node. */
+ static const Array<GeometryComponentType> supported_types = {GEO_COMPONENT_TYPE_MESH,
+ GEO_COMPONENT_TYPE_POINT_CLOUD,
+ GEO_COMPONENT_TYPE_CURVE,
+ GEO_COMPONENT_TYPE_INSTANCES};
+ for (const GeometryComponentType src_type : supported_types) {
+ if (component_is_available(geometry, src_type, domain)) {
+ return geometry.get_component_for_read(src_type);
+ }
+ }
+
+ return nullptr;
+}
+
+template<typename T>
+void copy_with_indices(const VArray<T> &src,
+ const VArray<int> &indices,
+ const IndexMask mask,
+ MutableSpan<T> dst)
+{
+ const IndexRange src_range = src.index_range();
+ devirtualize_varray2(src, indices, [&](const auto src, const auto indices) {
+ threading::parallel_for(mask.index_range(), 4096, [&](IndexRange range) {
+ for (const int i : mask.slice(range)) {
+ const int index = indices[i];
+ if (src_range.contains(index)) {
+ dst[i] = src[index];
+ }
+ else {
+ dst[i] = {};
+ }
+ }
+ });
+ });
+}
+
+template<typename T>
+void copy_with_clamped_indices(const VArray<T> &src,
+ const VArray<int> &indices,
+ const IndexMask mask,
+ MutableSpan<T> dst)
+{
+ const int last_index = src.index_range().last();
+ devirtualize_varray2(src, indices, [&](const auto src, const auto indices) {
+ threading::parallel_for(mask.index_range(), 4096, [&](IndexRange range) {
+ for (const int i : mask.slice(range)) {
+ const int index = indices[i];
+ dst[i] = src[std::clamp(index, 0, last_index)];
+ }
+ });
+ });
+}
+
+/**
+ * The index-based transfer theoretically does not need realized data when there is only one
+ * instance geometry set in the source. A future optimization could be removing that limitation
+ * internally.
+ */
+class SampleIndexFunction : public fn::MultiFunction {
+ GeometrySet src_geometry_;
+ GField src_field_;
+ eAttrDomain domain_;
+ bool clamp_;
+
+ fn::MFSignature signature_;
+
+ std::optional<bke::GeometryFieldContext> geometry_context_;
+ std::unique_ptr<FieldEvaluator> evaluator_;
+ const GVArray *src_data_ = nullptr;
+
+ public:
+ SampleIndexFunction(GeometrySet geometry,
+ GField src_field,
+ const eAttrDomain domain,
+ const bool clamp)
+ : src_geometry_(std::move(geometry)),
+ src_field_(std::move(src_field)),
+ domain_(domain),
+ clamp_(clamp)
+ {
+ src_geometry_.ensure_owns_direct_data();
+
+ signature_ = this->create_signature();
+ this->set_signature(&signature_);
+
+ this->evaluate_field();
+ }
+
+ fn::MFSignature create_signature()
+ {
+ fn::MFSignatureBuilder signature{"Sample Index"};
+ signature.single_input<int>("Index");
+ signature.single_output("Value", src_field_.cpp_type());
+ return signature.build();
+ }
+
+ void evaluate_field()
+ {
+ const GeometryComponent *component = find_source_component(src_geometry_, domain_);
+ if (component == nullptr) {
+ return;
+ }
+ const int domain_num = component->attribute_domain_size(domain_);
+ geometry_context_.emplace(bke::GeometryFieldContext(*component, domain_));
+ evaluator_ = std::make_unique<FieldEvaluator>(*geometry_context_, domain_num);
+ evaluator_->add(src_field_);
+ evaluator_->evaluate();
+ src_data_ = &evaluator_->get_evaluated(0);
+ }
+
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
+ {
+ const VArray<int> &indices = params.readonly_single_input<int>(0, "Index");
+ GMutableSpan dst = params.uninitialized_single_output(1, "Value");
+
+ const CPPType &type = dst.type();
+ if (src_data_ == nullptr) {
+ type.value_initialize_indices(dst.data(), mask);
+ return;
+ }
+
+ attribute_math::convert_to_static_type(type, [&](auto dummy) {
+ using T = decltype(dummy);
+ if (clamp_) {
+ copy_with_clamped_indices(src_data_->typed<T>(), indices, mask, dst.typed<T>());
+ }
+ else {
+ copy_with_indices(src_data_->typed<T>(), indices, mask, dst.typed<T>());
+ }
+ });
+ }
+};
+
+static GField get_input_attribute_field(GeoNodeExecParams &params, const eCustomDataType data_type)
+{
+ switch (data_type) {
+ case CD_PROP_FLOAT:
+ return params.extract_input<Field<float>>("Value_Float");
+ case CD_PROP_FLOAT3:
+ return params.extract_input<Field<float3>>("Value_Vector");
+ case CD_PROP_COLOR:
+ return params.extract_input<Field<ColorGeometry4f>>("Value_Color");
+ case CD_PROP_BOOL:
+ return params.extract_input<Field<bool>>("Value_Bool");
+ case CD_PROP_INT32:
+ return params.extract_input<Field<int>>("Value_Int");
+ default:
+ BLI_assert_unreachable();
+ }
+ return {};
+}
+
+static void output_attribute_field(GeoNodeExecParams &params, GField field)
+{
+ switch (bke::cpp_type_to_custom_data_type(field.cpp_type())) {
+ case CD_PROP_FLOAT: {
+ params.set_output("Value_Float", Field<float>(field));
+ break;
+ }
+ case CD_PROP_FLOAT3: {
+ params.set_output("Value_Vector", Field<float3>(field));
+ break;
+ }
+ case CD_PROP_COLOR: {
+ params.set_output("Value_Color", Field<ColorGeometry4f>(field));
+ break;
+ }
+ case CD_PROP_BOOL: {
+ params.set_output("Value_Bool", Field<bool>(field));
+ break;
+ }
+ case CD_PROP_INT32: {
+ params.set_output("Value_Int", Field<int>(field));
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+static void node_geo_exec(GeoNodeExecParams params)
+{
+ GeometrySet geometry = params.extract_input<GeometrySet>("Geometry");
+ const NodeGeometrySampleIndex &storage = node_storage(params.node());
+ const eCustomDataType data_type = eCustomDataType(storage.data_type);
+ const eAttrDomain domain = eAttrDomain(storage.domain);
+
+ auto fn = std::make_shared<SampleIndexFunction>(std::move(geometry),
+ get_input_attribute_field(params, data_type),
+ domain,
+ bool(storage.clamp));
+ auto op = FieldOperation::Create(std::move(fn), {params.extract_input<Field<int>>("Index")});
+ output_attribute_field(params, GField(std::move(op)));
+}
+
+} // namespace blender::nodes::node_geo_sample_index_cc
+
+void register_node_type_geo_sample_index()
+{
+ namespace file_ns = blender::nodes::node_geo_sample_index_cc;
+
+ static bNodeType ntype;
+
+ geo_node_type_base(&ntype, GEO_NODE_SAMPLE_INDEX, "Sample Index", NODE_CLASS_GEOMETRY);
+ node_type_init(&ntype, file_ns::node_init);
+ node_type_update(&ntype, file_ns::node_update);
+ ntype.declare = file_ns::node_declare;
+ node_type_storage(
+ &ntype, "NodeGeometrySampleIndex", node_free_standard_storage, node_copy_standard_storage);
+ ntype.geometry_node_execute = file_ns::node_geo_exec;
+ ntype.draw_buttons = file_ns::node_layout;
+ ntype.gather_link_search_ops = file_ns::node_gather_link_searches;
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_sample_nearest.cc b/source/blender/nodes/geometry/nodes/node_geo_sample_nearest.cc
new file mode 100644
index 00000000000..8c5dad3a1c5
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_sample_nearest.cc
@@ -0,0 +1,342 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "DNA_pointcloud_types.h"
+
+#include "BKE_bvhutils.h"
+#include "BKE_mesh.h"
+#include "BKE_mesh_runtime.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "node_geometry_util.hh"
+
+namespace blender::nodes {
+
+void get_closest_in_bvhtree(BVHTreeFromMesh &tree_data,
+ const VArray<float3> &positions,
+ const IndexMask mask,
+ const MutableSpan<int> r_indices,
+ const MutableSpan<float> r_distances_sq,
+ const MutableSpan<float3> r_positions)
+{
+ BLI_assert(positions.size() >= r_indices.size());
+ BLI_assert(positions.size() >= r_distances_sq.size());
+ BLI_assert(positions.size() >= r_positions.size());
+
+ for (const int i : mask) {
+ BVHTreeNearest nearest;
+ nearest.dist_sq = FLT_MAX;
+ const float3 position = positions[i];
+ BLI_bvhtree_find_nearest(
+ tree_data.tree, position, &nearest, tree_data.nearest_callback, &tree_data);
+ if (!r_indices.is_empty()) {
+ r_indices[i] = nearest.index;
+ }
+ if (!r_distances_sq.is_empty()) {
+ r_distances_sq[i] = nearest.dist_sq;
+ }
+ if (!r_positions.is_empty()) {
+ r_positions[i] = nearest.co;
+ }
+ }
+}
+
+} // namespace blender::nodes
+
+namespace blender::nodes::node_geo_sample_nearest_cc {
+
+static void node_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::Geometry>(N_("Geometry"))
+ .supported_type({GEO_COMPONENT_TYPE_MESH, GEO_COMPONENT_TYPE_POINT_CLOUD});
+ b.add_input<decl::Vector>(N_("Sample Position")).implicit_field(implicit_field_inputs::position);
+ b.add_output<decl::Int>(N_("Index")).dependent_field({1});
+}
+
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
+{
+ uiItemR(layout, ptr, "domain", 0, "", ICON_NONE);
+}
+
+static void node_init(bNodeTree * /*tree*/, bNode *node)
+{
+ node->custom1 = CD_PROP_FLOAT;
+ node->custom2 = ATTR_DOMAIN_POINT;
+}
+
+static void get_closest_pointcloud_points(const PointCloud &pointcloud,
+ const VArray<float3> &positions,
+ const IndexMask mask,
+ const MutableSpan<int> r_indices,
+ const MutableSpan<float> r_distances_sq)
+{
+ BLI_assert(positions.size() >= r_indices.size());
+ BLI_assert(pointcloud.totpoint > 0);
+
+ BVHTreeFromPointCloud tree_data;
+ BKE_bvhtree_from_pointcloud_get(&tree_data, &pointcloud, 2);
+
+ for (const int i : mask) {
+ BVHTreeNearest nearest;
+ nearest.dist_sq = FLT_MAX;
+ const float3 position = positions[i];
+ BLI_bvhtree_find_nearest(
+ tree_data.tree, position, &nearest, tree_data.nearest_callback, &tree_data);
+ r_indices[i] = nearest.index;
+ if (!r_distances_sq.is_empty()) {
+ r_distances_sq[i] = nearest.dist_sq;
+ }
+ }
+
+ free_bvhtree_from_pointcloud(&tree_data);
+}
+
+static void get_closest_mesh_points(const Mesh &mesh,
+ const VArray<float3> &positions,
+ const IndexMask mask,
+ const MutableSpan<int> r_point_indices,
+ const MutableSpan<float> r_distances_sq,
+ const MutableSpan<float3> r_positions)
+{
+ BLI_assert(mesh.totvert > 0);
+ BVHTreeFromMesh tree_data;
+ BKE_bvhtree_from_mesh_get(&tree_data, &mesh, BVHTREE_FROM_VERTS, 2);
+ get_closest_in_bvhtree(tree_data, positions, mask, r_point_indices, r_distances_sq, r_positions);
+ free_bvhtree_from_mesh(&tree_data);
+}
+
+static void get_closest_mesh_edges(const Mesh &mesh,
+ const VArray<float3> &positions,
+ const IndexMask mask,
+ const MutableSpan<int> r_edge_indices,
+ const MutableSpan<float> r_distances_sq,
+ const MutableSpan<float3> r_positions)
+{
+ BLI_assert(mesh.totedge > 0);
+ BVHTreeFromMesh tree_data;
+ BKE_bvhtree_from_mesh_get(&tree_data, &mesh, BVHTREE_FROM_EDGES, 2);
+ get_closest_in_bvhtree(tree_data, positions, mask, r_edge_indices, r_distances_sq, r_positions);
+ free_bvhtree_from_mesh(&tree_data);
+}
+
+static void get_closest_mesh_looptris(const Mesh &mesh,
+ const VArray<float3> &positions,
+ const IndexMask mask,
+ const MutableSpan<int> r_looptri_indices,
+ const MutableSpan<float> r_distances_sq,
+ const MutableSpan<float3> r_positions)
+{
+ BLI_assert(mesh.totpoly > 0);
+ BVHTreeFromMesh tree_data;
+ BKE_bvhtree_from_mesh_get(&tree_data, &mesh, BVHTREE_FROM_LOOPTRI, 2);
+ get_closest_in_bvhtree(
+ tree_data, positions, mask, r_looptri_indices, r_distances_sq, r_positions);
+ free_bvhtree_from_mesh(&tree_data);
+}
+
+static void get_closest_mesh_polys(const Mesh &mesh,
+ const VArray<float3> &positions,
+ const IndexMask mask,
+ const MutableSpan<int> r_poly_indices,
+ const MutableSpan<float> r_distances_sq,
+ const MutableSpan<float3> r_positions)
+{
+ BLI_assert(mesh.totpoly > 0);
+
+ Array<int> looptri_indices(positions.size());
+ get_closest_mesh_looptris(mesh, positions, mask, looptri_indices, r_distances_sq, r_positions);
+
+ const Span<MLoopTri> looptris = mesh.looptris();
+
+ for (const int i : mask) {
+ const MLoopTri &looptri = looptris[looptri_indices[i]];
+ r_poly_indices[i] = looptri.poly;
+ }
+}
+
+/* The closest corner is defined to be the closest corner on the closest face. */
+static void get_closest_mesh_corners(const Mesh &mesh,
+ const VArray<float3> &positions,
+ const IndexMask mask,
+ const MutableSpan<int> r_corner_indices,
+ const MutableSpan<float> r_distances_sq,
+ const MutableSpan<float3> r_positions)
+{
+ const Span<MVert> verts = mesh.verts();
+ const Span<MPoly> polys = mesh.polys();
+ const Span<MLoop> loops = mesh.loops();
+
+ BLI_assert(mesh.totloop > 0);
+ Array<int> poly_indices(positions.size());
+ get_closest_mesh_polys(mesh, positions, mask, poly_indices, {}, {});
+
+ for (const int i : mask) {
+ const float3 position = positions[i];
+ const int poly_index = poly_indices[i];
+ const MPoly &poly = polys[poly_index];
+
+ /* Find the closest vertex in the polygon. */
+ float min_distance_sq = FLT_MAX;
+ const MVert *closest_mvert;
+ int closest_loop_index = 0;
+ for (const int loop_index : IndexRange(poly.loopstart, poly.totloop)) {
+ const MLoop &loop = loops[loop_index];
+ const int vertex_index = loop.v;
+ const MVert &mvert = verts[vertex_index];
+ const float distance_sq = math::distance_squared(position, float3(mvert.co));
+ if (distance_sq < min_distance_sq) {
+ min_distance_sq = distance_sq;
+ closest_loop_index = loop_index;
+ closest_mvert = &mvert;
+ }
+ }
+ if (!r_corner_indices.is_empty()) {
+ r_corner_indices[i] = closest_loop_index;
+ }
+ if (!r_positions.is_empty()) {
+ r_positions[i] = closest_mvert->co;
+ }
+ if (!r_distances_sq.is_empty()) {
+ r_distances_sq[i] = min_distance_sq;
+ }
+ }
+}
+
+static bool component_is_available(const GeometrySet &geometry,
+ const GeometryComponentType type,
+ const eAttrDomain domain)
+{
+ if (!geometry.has(type)) {
+ return false;
+ }
+ const GeometryComponent &component = *geometry.get_component_for_read(type);
+ if (component.is_empty()) {
+ return false;
+ }
+ return component.attribute_domain_size(domain) != 0;
+}
+
+static const GeometryComponent *find_source_component(const GeometrySet &geometry,
+ const eAttrDomain domain)
+{
+ /* Choose the other component based on a consistent order, rather than some more complicated
+ * heuristic. This is the same order visible in the spreadsheet and used in the ray-cast node. */
+ static const Array<GeometryComponentType> supported_types = {GEO_COMPONENT_TYPE_MESH,
+ GEO_COMPONENT_TYPE_POINT_CLOUD,
+ GEO_COMPONENT_TYPE_CURVE,
+ GEO_COMPONENT_TYPE_INSTANCES};
+ for (const GeometryComponentType src_type : supported_types) {
+ if (component_is_available(geometry, src_type, domain)) {
+ return geometry.get_component_for_read(src_type);
+ }
+ }
+
+ return nullptr;
+}
+
+class SampleNearestFunction : public fn::MultiFunction {
+ GeometrySet source_;
+ eAttrDomain domain_;
+
+ const GeometryComponent *src_component_;
+
+ fn::MFSignature signature_;
+
+ public:
+ SampleNearestFunction(GeometrySet geometry, eAttrDomain domain)
+ : source_(std::move(geometry)), domain_(domain)
+ {
+ source_.ensure_owns_direct_data();
+ signature_ = this->create_signature();
+ this->set_signature(&signature_);
+
+ this->src_component_ = find_source_component(source_, domain_);
+ }
+
+ fn::MFSignature create_signature()
+ {
+ blender::fn::MFSignatureBuilder signature{"Sample Nearest"};
+ signature.single_input<float3>("Position");
+ signature.single_output<int>("Index");
+ return signature.build();
+ }
+
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
+ {
+ const VArray<float3> &positions = params.readonly_single_input<float3>(0, "Position");
+ MutableSpan<int> indices = params.uninitialized_single_output<int>(1, "Index");
+ if (!src_component_) {
+ indices.fill_indices(mask, 0);
+ return;
+ }
+
+ switch (src_component_->type()) {
+ case GEO_COMPONENT_TYPE_MESH: {
+ const MeshComponent &component = *static_cast<const MeshComponent *>(src_component_);
+ const Mesh &mesh = *component.get_for_read();
+ Array<float> distances(mask.min_array_size());
+ switch (domain_) {
+ case ATTR_DOMAIN_POINT:
+ get_closest_mesh_points(mesh, positions, mask, indices, distances, {});
+ break;
+ case ATTR_DOMAIN_EDGE:
+ get_closest_mesh_edges(mesh, positions, mask, indices, distances, {});
+ break;
+ case ATTR_DOMAIN_FACE:
+ get_closest_mesh_polys(mesh, positions, mask, indices, distances, {});
+ break;
+ case ATTR_DOMAIN_CORNER:
+ get_closest_mesh_corners(mesh, positions, mask, indices, distances, {});
+ break;
+ default:
+ break;
+ }
+ break;
+ }
+ case GEO_COMPONENT_TYPE_POINT_CLOUD: {
+ const PointCloudComponent &component = *static_cast<const PointCloudComponent *>(
+ src_component_);
+ const PointCloud &points = *component.get_for_read();
+ Array<float> distances(mask.min_array_size());
+ get_closest_pointcloud_points(points, positions, mask, indices, distances);
+ break;
+ }
+ default:
+ break;
+ }
+ }
+};
+
+static void node_geo_exec(GeoNodeExecParams params)
+{
+ GeometrySet geometry = params.extract_input<GeometrySet>("Geometry");
+ const eAttrDomain domain = eAttrDomain(params.node().custom2);
+ if (geometry.has_curves() && !geometry.has_mesh() && !geometry.has_pointcloud()) {
+ params.error_message_add(NodeWarningType::Error,
+ TIP_("The source geometry must contain a mesh or a point cloud"));
+ params.set_default_remaining_outputs();
+ return;
+ }
+
+ Field<float3> positions = params.extract_input<Field<float3>>("Sample Position");
+ auto fn = std::make_shared<SampleNearestFunction>(std::move(geometry), domain);
+ auto op = FieldOperation::Create(std::move(fn), {std::move(positions)});
+ params.set_output<Field<int>>("Index", Field<int>(std::move(op)));
+}
+
+} // namespace blender::nodes::node_geo_sample_nearest_cc
+
+void register_node_type_geo_sample_nearest()
+{
+ namespace file_ns = blender::nodes::node_geo_sample_nearest_cc;
+
+ static bNodeType ntype;
+
+ geo_node_type_base(&ntype, GEO_NODE_SAMPLE_NEAREST, "Sample Nearest", NODE_CLASS_GEOMETRY);
+ node_type_init(&ntype, file_ns::node_init);
+ ntype.declare = file_ns::node_declare;
+ ntype.geometry_node_execute = file_ns::node_geo_exec;
+ ntype.draw_buttons = file_ns::node_layout;
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_sample_nearest_surface.cc b/source/blender/nodes/geometry/nodes/node_geo_sample_nearest_surface.cc
new file mode 100644
index 00000000000..95bf7199d63
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_sample_nearest_surface.cc
@@ -0,0 +1,278 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+
+#include "BKE_attribute_math.hh"
+#include "BKE_bvhutils.h"
+#include "BKE_mesh.h"
+#include "BKE_mesh_sample.hh"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "NOD_socket_search_link.hh"
+
+#include "node_geometry_util.hh"
+
+namespace blender::nodes::node_geo_sample_nearest_surface_cc {
+
+using namespace blender::bke::mesh_surface_sample;
+
+static void node_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::Geometry>(N_("Mesh")).supported_type(GEO_COMPONENT_TYPE_MESH);
+
+ b.add_input<decl::Float>(N_("Value"), "Value_Float").hide_value().supports_field();
+ b.add_input<decl::Int>(N_("Value"), "Value_Int").hide_value().supports_field();
+ b.add_input<decl::Vector>(N_("Value"), "Value_Vector").hide_value().supports_field();
+ b.add_input<decl::Color>(N_("Value"), "Value_Color").hide_value().supports_field();
+ b.add_input<decl::Bool>(N_("Value"), "Value_Bool").hide_value().supports_field();
+
+ b.add_input<decl::Vector>(N_("Sample Position")).implicit_field(implicit_field_inputs::position);
+
+ b.add_output<decl::Float>(N_("Value"), "Value_Float").dependent_field({6});
+ b.add_output<decl::Int>(N_("Value"), "Value_Int").dependent_field({6});
+ b.add_output<decl::Vector>(N_("Value"), "Value_Vector").dependent_field({6});
+ b.add_output<decl::Color>(N_("Value"), "Value_Color").dependent_field({6});
+ b.add_output<decl::Bool>(N_("Value"), "Value_Bool").dependent_field({6});
+}
+
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
+{
+ uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE);
+}
+
+static void node_init(bNodeTree * /*tree*/, bNode *node)
+{
+ node->custom1 = CD_PROP_FLOAT;
+}
+
+static void node_update(bNodeTree *ntree, bNode *node)
+{
+ const eCustomDataType data_type = eCustomDataType(node->custom1);
+
+ bNodeSocket *in_socket_mesh = static_cast<bNodeSocket *>(node->inputs.first);
+ bNodeSocket *in_socket_float = in_socket_mesh->next;
+ bNodeSocket *in_socket_int32 = in_socket_float->next;
+ bNodeSocket *in_socket_vector = in_socket_int32->next;
+ bNodeSocket *in_socket_color4f = in_socket_vector->next;
+ bNodeSocket *in_socket_bool = in_socket_color4f->next;
+
+ nodeSetSocketAvailability(ntree, in_socket_vector, data_type == CD_PROP_FLOAT3);
+ nodeSetSocketAvailability(ntree, in_socket_float, data_type == CD_PROP_FLOAT);
+ nodeSetSocketAvailability(ntree, in_socket_color4f, data_type == CD_PROP_COLOR);
+ nodeSetSocketAvailability(ntree, in_socket_bool, data_type == CD_PROP_BOOL);
+ nodeSetSocketAvailability(ntree, in_socket_int32, data_type == CD_PROP_INT32);
+
+ bNodeSocket *out_socket_float = static_cast<bNodeSocket *>(node->outputs.first);
+ bNodeSocket *out_socket_int32 = out_socket_float->next;
+ bNodeSocket *out_socket_vector = out_socket_int32->next;
+ bNodeSocket *out_socket_color4f = out_socket_vector->next;
+ bNodeSocket *out_socket_bool = out_socket_color4f->next;
+
+ nodeSetSocketAvailability(ntree, out_socket_vector, data_type == CD_PROP_FLOAT3);
+ nodeSetSocketAvailability(ntree, out_socket_float, data_type == CD_PROP_FLOAT);
+ nodeSetSocketAvailability(ntree, out_socket_color4f, data_type == CD_PROP_COLOR);
+ nodeSetSocketAvailability(ntree, out_socket_bool, data_type == CD_PROP_BOOL);
+ nodeSetSocketAvailability(ntree, out_socket_int32, data_type == CD_PROP_INT32);
+}
+
+static void node_gather_link_searches(GatherLinkSearchOpParams &params)
+{
+ const NodeDeclaration &declaration = *params.node_type().fixed_declaration;
+ search_link_ops_for_declarations(params, declaration.inputs().take_back(2));
+ search_link_ops_for_declarations(params, declaration.inputs().take_front(1));
+
+ const std::optional<eCustomDataType> type = node_data_type_to_custom_data_type(
+ (eNodeSocketDatatype)params.other_socket().type);
+ if (type && *type != CD_PROP_STRING) {
+ /* The input and output sockets have the same name. */
+ params.add_item(IFACE_("Value"), [type](LinkSearchOpParams &params) {
+ bNode &node = params.add_node("GeometryNodeSampleNearestSurface");
+ node.custom1 = *type;
+ params.update_and_connect_available_socket(node, "Value");
+ });
+ }
+}
+
+static void get_closest_mesh_looptris(const Mesh &mesh,
+ const VArray<float3> &positions,
+ const IndexMask mask,
+ const MutableSpan<int> r_looptri_indices,
+ const MutableSpan<float> r_distances_sq,
+ const MutableSpan<float3> r_positions)
+{
+ BLI_assert(mesh.totpoly > 0);
+ BVHTreeFromMesh tree_data;
+ BKE_bvhtree_from_mesh_get(&tree_data, &mesh, BVHTREE_FROM_LOOPTRI, 2);
+ get_closest_in_bvhtree(
+ tree_data, positions, mask, r_looptri_indices, r_distances_sq, r_positions);
+ free_bvhtree_from_mesh(&tree_data);
+}
+
+/**
+ * \note Multi-threading for this function is provided by the field evaluator. Since the #call
+ * function could be called many times, calculate the data from the source geometry once and store
+ * it for later.
+ */
+class SampleNearestSurfaceFunction : public fn::MultiFunction {
+ GeometrySet source_;
+ GField src_field_;
+
+ /**
+ * This function is meant to sample the surface of a mesh rather than take the value from
+ * individual elements, so use the most complex domain, ensuring no information is lost. In the
+ * future, it should be possible to use the most complex domain required by the field inputs, to
+ * simplify sampling and avoid domain conversions.
+ */
+ eAttrDomain domain_ = ATTR_DOMAIN_CORNER;
+
+ fn::MFSignature signature_;
+
+ std::optional<bke::MeshFieldContext> source_context_;
+ std::unique_ptr<FieldEvaluator> source_evaluator_;
+ const GVArray *source_data_;
+
+ public:
+ SampleNearestSurfaceFunction(GeometrySet geometry, GField src_field)
+ : source_(std::move(geometry)), src_field_(std::move(src_field))
+ {
+ source_.ensure_owns_direct_data();
+ signature_ = this->create_signature();
+ this->set_signature(&signature_);
+ this->evaluate_source_field();
+ }
+
+ fn::MFSignature create_signature()
+ {
+ blender::fn::MFSignatureBuilder signature{"Sample Nearest Surface"};
+ signature.single_input<float3>("Position");
+ signature.single_output("Value", src_field_.cpp_type());
+ return signature.build();
+ }
+
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
+ {
+ const VArray<float3> &positions = params.readonly_single_input<float3>(0, "Position");
+ GMutableSpan dst = params.uninitialized_single_output_if_required(1, "Value");
+
+ const MeshComponent &mesh_component = *source_.get_component_for_read<MeshComponent>();
+ BLI_assert(mesh_component.has_mesh());
+ const Mesh &mesh = *mesh_component.get_for_read();
+ BLI_assert(mesh.totpoly > 0);
+
+ /* Find closest points on the mesh surface. */
+ Array<int> looptri_indices(mask.min_array_size());
+ Array<float3> sampled_positions(mask.min_array_size());
+ get_closest_mesh_looptris(mesh, positions, mask, looptri_indices, {}, sampled_positions);
+
+ MeshAttributeInterpolator interp(&mesh, mask, sampled_positions, looptri_indices);
+ interp.sample_data(*source_data_, domain_, eAttributeMapMode::INTERPOLATED, dst);
+ }
+
+ private:
+ void evaluate_source_field()
+ {
+ const Mesh &mesh = *source_.get_mesh_for_read();
+ source_context_.emplace(bke::MeshFieldContext{mesh, domain_});
+ const int domain_size = mesh.attributes().domain_size(domain_);
+ source_evaluator_ = std::make_unique<FieldEvaluator>(*source_context_, domain_size);
+ source_evaluator_->add(src_field_);
+ source_evaluator_->evaluate();
+ source_data_ = &source_evaluator_->get_evaluated(0);
+ }
+};
+
+static GField get_input_attribute_field(GeoNodeExecParams &params, const eCustomDataType data_type)
+{
+ switch (data_type) {
+ case CD_PROP_FLOAT:
+ return params.extract_input<Field<float>>("Value_Float");
+ case CD_PROP_FLOAT3:
+ return params.extract_input<Field<float3>>("Value_Vector");
+ case CD_PROP_COLOR:
+ return params.extract_input<Field<ColorGeometry4f>>("Value_Color");
+ case CD_PROP_BOOL:
+ return params.extract_input<Field<bool>>("Value_Bool");
+ case CD_PROP_INT32:
+ return params.extract_input<Field<int>>("Value_Int");
+ default:
+ BLI_assert_unreachable();
+ }
+ return {};
+}
+
+static void output_attribute_field(GeoNodeExecParams &params, GField field)
+{
+ switch (bke::cpp_type_to_custom_data_type(field.cpp_type())) {
+ case CD_PROP_FLOAT: {
+ params.set_output("Value_Float", Field<float>(field));
+ break;
+ }
+ case CD_PROP_FLOAT3: {
+ params.set_output("Value_Vector", Field<float3>(field));
+ break;
+ }
+ case CD_PROP_COLOR: {
+ params.set_output("Value_Color", Field<ColorGeometry4f>(field));
+ break;
+ }
+ case CD_PROP_BOOL: {
+ params.set_output("Value_Bool", Field<bool>(field));
+ break;
+ }
+ case CD_PROP_INT32: {
+ params.set_output("Value_Int", Field<int>(field));
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+static void node_geo_exec(GeoNodeExecParams params)
+{
+ GeometrySet geometry = params.extract_input<GeometrySet>("Mesh");
+ const eCustomDataType data_type = eCustomDataType(params.node().custom1);
+ const Mesh *mesh = geometry.get_mesh_for_read();
+ if (mesh == nullptr) {
+ params.set_default_remaining_outputs();
+ return;
+ }
+ if (mesh->totvert == 0) {
+ params.set_default_remaining_outputs();
+ return;
+ }
+ if (mesh->totpoly == 0) {
+ params.error_message_add(NodeWarningType::Error, TIP_("The source mesh must have faces"));
+ params.set_default_remaining_outputs();
+ return;
+ }
+
+ Field<float3> positions = params.extract_input<Field<float3>>("Sample Position");
+ GField field = get_input_attribute_field(params, data_type);
+ auto fn = std::make_shared<SampleNearestSurfaceFunction>(std::move(geometry), std::move(field));
+ auto op = FieldOperation::Create(std::move(fn), {std::move(positions)});
+ output_attribute_field(params, GField(std::move(op)));
+}
+
+} // namespace blender::nodes::node_geo_sample_nearest_surface_cc
+
+void register_node_type_geo_sample_nearest_surface()
+{
+ namespace file_ns = blender::nodes::node_geo_sample_nearest_surface_cc;
+
+ static bNodeType ntype;
+
+ geo_node_type_base(
+ &ntype, GEO_NODE_SAMPLE_NEAREST_SURFACE, "Sample Nearest Surface", NODE_CLASS_GEOMETRY);
+ node_type_init(&ntype, file_ns::node_init);
+ node_type_update(&ntype, file_ns::node_update);
+ ntype.declare = file_ns::node_declare;
+ node_type_size_preset(&ntype, NODE_SIZE_MIDDLE);
+ ntype.geometry_node_execute = file_ns::node_geo_exec;
+ ntype.draw_buttons = file_ns::node_layout;
+ ntype.gather_link_search_ops = file_ns::node_gather_link_searches;
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_sample_uv_surface.cc b/source/blender/nodes/geometry/nodes/node_geo_sample_uv_surface.cc
new file mode 100644
index 00000000000..2e8446ba559
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_sample_uv_surface.cc
@@ -0,0 +1,294 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "BKE_attribute_math.hh"
+#include "BKE_mesh.h"
+#include "BKE_type_conversions.hh"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "GEO_reverse_uv_sampler.hh"
+
+#include "NOD_socket_search_link.hh"
+
+#include "node_geometry_util.hh"
+
+namespace blender::nodes::node_geo_sample_uv_surface_cc {
+
+using geometry::ReverseUVSampler;
+
+static void node_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::Geometry>(N_("Mesh")).supported_type(GEO_COMPONENT_TYPE_MESH);
+
+ b.add_input<decl::Float>(N_("Value"), "Value_Float").hide_value().supports_field();
+ b.add_input<decl::Int>(N_("Value"), "Value_Int").hide_value().supports_field();
+ b.add_input<decl::Vector>(N_("Value"), "Value_Vector").hide_value().supports_field();
+ b.add_input<decl::Color>(N_("Value"), "Value_Color").hide_value().supports_field();
+ b.add_input<decl::Bool>(N_("Value"), "Value_Bool").hide_value().supports_field();
+
+ b.add_input<decl::Vector>(N_("Source UV Map"))
+ .hide_value()
+ .supports_field()
+ .description(N_("The mesh UV map to sample. Should not have overlapping faces"));
+ b.add_input<decl::Vector>(N_("Sample UV"))
+ .supports_field()
+ .description(N_("The coordinates to sample within the UV map"));
+
+ b.add_output<decl::Float>(N_("Value"), "Value_Float").dependent_field({7});
+ b.add_output<decl::Int>(N_("Value"), "Value_Int").dependent_field({7});
+ b.add_output<decl::Vector>(N_("Value"), "Value_Vector").dependent_field({7});
+ b.add_output<decl::Color>(N_("Value"), "Value_Color").dependent_field({7});
+ b.add_output<decl::Bool>(N_("Value"), "Value_Bool").dependent_field({7});
+
+ b.add_output<decl::Bool>(N_("Is Valid"))
+ .dependent_field({7})
+ .description(N_("Whether the node could find a single face to sample at the UV coordinate"));
+}
+
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
+{
+ uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE);
+}
+
+static void node_init(bNodeTree * /*tree*/, bNode *node)
+{
+ node->custom1 = CD_PROP_FLOAT;
+}
+
+static void node_update(bNodeTree *ntree, bNode *node)
+{
+ const eCustomDataType data_type = eCustomDataType(node->custom1);
+
+ bNodeSocket *in_socket_mesh = static_cast<bNodeSocket *>(node->inputs.first);
+ bNodeSocket *in_socket_float = in_socket_mesh->next;
+ bNodeSocket *in_socket_int32 = in_socket_float->next;
+ bNodeSocket *in_socket_vector = in_socket_int32->next;
+ bNodeSocket *in_socket_color4f = in_socket_vector->next;
+ bNodeSocket *in_socket_bool = in_socket_color4f->next;
+
+ nodeSetSocketAvailability(ntree, in_socket_vector, data_type == CD_PROP_FLOAT3);
+ nodeSetSocketAvailability(ntree, in_socket_float, data_type == CD_PROP_FLOAT);
+ nodeSetSocketAvailability(ntree, in_socket_color4f, data_type == CD_PROP_COLOR);
+ nodeSetSocketAvailability(ntree, in_socket_bool, data_type == CD_PROP_BOOL);
+ nodeSetSocketAvailability(ntree, in_socket_int32, data_type == CD_PROP_INT32);
+
+ bNodeSocket *out_socket_float = static_cast<bNodeSocket *>(node->outputs.first);
+ bNodeSocket *out_socket_int32 = out_socket_float->next;
+ bNodeSocket *out_socket_vector = out_socket_int32->next;
+ bNodeSocket *out_socket_color4f = out_socket_vector->next;
+ bNodeSocket *out_socket_bool = out_socket_color4f->next;
+
+ nodeSetSocketAvailability(ntree, out_socket_vector, data_type == CD_PROP_FLOAT3);
+ nodeSetSocketAvailability(ntree, out_socket_float, data_type == CD_PROP_FLOAT);
+ nodeSetSocketAvailability(ntree, out_socket_color4f, data_type == CD_PROP_COLOR);
+ nodeSetSocketAvailability(ntree, out_socket_bool, data_type == CD_PROP_BOOL);
+ nodeSetSocketAvailability(ntree, out_socket_int32, data_type == CD_PROP_INT32);
+}
+
+static void node_gather_link_searches(GatherLinkSearchOpParams &params)
+{
+ const NodeDeclaration &declaration = *params.node_type().fixed_declaration;
+ search_link_ops_for_declarations(params, declaration.inputs().take_back(2));
+ search_link_ops_for_declarations(params, declaration.inputs().take_front(1));
+ search_link_ops_for_declarations(params, declaration.outputs().take_back(1));
+
+ const std::optional<eCustomDataType> type = node_data_type_to_custom_data_type(
+ eNodeSocketDatatype(params.other_socket().type));
+ if (type && *type != CD_PROP_STRING) {
+ /* The input and output sockets have the same name. */
+ params.add_item(IFACE_("Value"), [type](LinkSearchOpParams &params) {
+ bNode &node = params.add_node("GeometryNodeSampleUVSurface");
+ node.custom1 = *type;
+ params.update_and_connect_available_socket(node, "Value");
+ });
+ }
+}
+
+class SampleUVSurfaceFunction : public fn::MultiFunction {
+ GeometrySet source_;
+ Field<float2> src_uv_map_field_;
+ GField src_field_;
+
+ /**
+ * Use the most complex domain for now ensuring no information is lost. In the future, it should
+ * be possible to use the most complex domain required by the field inputs, to simplify sampling
+ * and avoid domain conversions.
+ */
+ eAttrDomain domain_ = ATTR_DOMAIN_CORNER;
+
+ fn::MFSignature signature_;
+
+ std::optional<bke::MeshFieldContext> source_context_;
+ std::unique_ptr<FieldEvaluator> source_evaluator_;
+ const GVArray *source_data_;
+ VArraySpan<float2> source_uv_map_;
+
+ std::optional<ReverseUVSampler> reverse_uv_sampler_;
+
+ public:
+ SampleUVSurfaceFunction(GeometrySet geometry, Field<float2> src_uv_map_field, GField src_field)
+ : source_(std::move(geometry)),
+ src_uv_map_field_(std::move(src_uv_map_field)),
+ src_field_(std::move(src_field))
+ {
+ source_.ensure_owns_direct_data();
+ signature_ = this->create_signature();
+ this->set_signature(&signature_);
+ this->evaluate_source();
+ }
+
+ fn::MFSignature create_signature()
+ {
+ blender::fn::MFSignatureBuilder signature{"Sample UV Surface"};
+ signature.single_input<float2>("Sample UV");
+ signature.single_output("Value", src_field_.cpp_type());
+ signature.single_output<bool>("Is Valid");
+ return signature.build();
+ }
+
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
+ {
+ const VArray<float2> &sample_uvs = params.readonly_single_input<float2>(0, "Sample UV");
+ GMutableSpan dst = params.uninitialized_single_output_if_required(1, "Value");
+ MutableSpan<bool> valid_dst = params.uninitialized_single_output_if_required<bool>(2,
+ "Is Valid");
+
+ const CPPType &type = src_field_.cpp_type();
+ attribute_math::convert_to_static_type(type, [&](auto dummy) {
+ using T = decltype(dummy);
+ const VArray<T> src_typed = source_data_->typed<T>();
+ MutableSpan<T> dst_typed = dst.typed<T>();
+ for (const int i : mask) {
+ const float2 sample_uv = sample_uvs[i];
+ const ReverseUVSampler::Result result = reverse_uv_sampler_->sample(sample_uv);
+ const bool valid = result.type == ReverseUVSampler::ResultType::Ok;
+ if (!dst_typed.is_empty()) {
+ if (valid) {
+ dst_typed[i] = attribute_math::mix3(result.bary_weights,
+ src_typed[result.looptri->tri[0]],
+ src_typed[result.looptri->tri[1]],
+ src_typed[result.looptri->tri[2]]);
+ }
+ else {
+ dst_typed[i] = {};
+ }
+ }
+ if (!valid_dst.is_empty()) {
+ valid_dst[i] = valid;
+ }
+ }
+ });
+ }
+
+ private:
+ void evaluate_source()
+ {
+ const Mesh &mesh = *source_.get_mesh_for_read();
+ source_context_.emplace(bke::MeshFieldContext{mesh, domain_});
+ const int domain_size = mesh.attributes().domain_size(domain_);
+ source_evaluator_ = std::make_unique<FieldEvaluator>(*source_context_, domain_size);
+ source_evaluator_->add(src_uv_map_field_);
+ source_evaluator_->add(src_field_);
+ source_evaluator_->evaluate();
+ source_uv_map_ = source_evaluator_->get_evaluated<float2>(0);
+ source_data_ = &source_evaluator_->get_evaluated(1);
+
+ reverse_uv_sampler_.emplace(source_uv_map_, mesh.looptris());
+ }
+};
+
+static GField get_input_attribute_field(GeoNodeExecParams &params, const eCustomDataType data_type)
+{
+ switch (data_type) {
+ case CD_PROP_FLOAT:
+ return params.extract_input<Field<float>>("Value_Float");
+ case CD_PROP_FLOAT3:
+ return params.extract_input<Field<float3>>("Value_Vector");
+ case CD_PROP_COLOR:
+ return params.extract_input<Field<ColorGeometry4f>>("Value_Color");
+ case CD_PROP_BOOL:
+ return params.extract_input<Field<bool>>("Value_Bool");
+ case CD_PROP_INT32:
+ return params.extract_input<Field<int>>("Value_Int");
+ default:
+ BLI_assert_unreachable();
+ }
+ return {};
+}
+
+static void output_attribute_field(GeoNodeExecParams &params, GField field)
+{
+ switch (bke::cpp_type_to_custom_data_type(field.cpp_type())) {
+ case CD_PROP_FLOAT: {
+ params.set_output("Value_Float", Field<float>(field));
+ break;
+ }
+ case CD_PROP_FLOAT3: {
+ params.set_output("Value_Vector", Field<float3>(field));
+ break;
+ }
+ case CD_PROP_COLOR: {
+ params.set_output("Value_Color", Field<ColorGeometry4f>(field));
+ break;
+ }
+ case CD_PROP_BOOL: {
+ params.set_output("Value_Bool", Field<bool>(field));
+ break;
+ }
+ case CD_PROP_INT32: {
+ params.set_output("Value_Int", Field<int>(field));
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+static void node_geo_exec(GeoNodeExecParams params)
+{
+ GeometrySet geometry = params.extract_input<GeometrySet>("Mesh");
+ const eCustomDataType data_type = eCustomDataType(params.node().custom1);
+ const Mesh *mesh = geometry.get_mesh_for_read();
+ if (mesh == nullptr) {
+ params.set_default_remaining_outputs();
+ return;
+ }
+ if (mesh->totpoly == 0 && mesh->totvert != 0) {
+ params.error_message_add(NodeWarningType::Error, TIP_("The source mesh must have faces"));
+ params.set_default_remaining_outputs();
+ return;
+ }
+
+ const CPPType &float2_type = CPPType::get<float2>();
+
+ const bke::DataTypeConversions &conversions = bke::get_implicit_type_conversions();
+ Field<float2> source_uv_map = conversions.try_convert(
+ params.extract_input<Field<float3>>("Source UV Map"), float2_type);
+ GField field = get_input_attribute_field(params, data_type);
+ Field<float2> sample_uvs = conversions.try_convert(
+ params.extract_input<Field<float3>>("Sample UV"), float2_type);
+ auto fn = std::make_shared<SampleUVSurfaceFunction>(
+ std::move(geometry), std::move(source_uv_map), std::move(field));
+ auto op = FieldOperation::Create(std::move(fn), {std::move(sample_uvs)});
+ output_attribute_field(params, GField(op, 0));
+ params.set_output("Is Valid", Field<bool>(op, 1));
+}
+
+} // namespace blender::nodes::node_geo_sample_uv_surface_cc
+
+void register_node_type_geo_sample_uv_surface()
+{
+ namespace file_ns = blender::nodes::node_geo_sample_uv_surface_cc;
+
+ static bNodeType ntype;
+
+ geo_node_type_base(&ntype, GEO_NODE_SAMPLE_UV_SURFACE, "Sample UV Surface", NODE_CLASS_GEOMETRY);
+ node_type_init(&ntype, file_ns::node_init);
+ node_type_update(&ntype, file_ns::node_update);
+ ntype.declare = file_ns::node_declare;
+ ntype.geometry_node_execute = file_ns::node_geo_exec;
+ ntype.draw_buttons = file_ns::node_layout;
+ ntype.gather_link_search_ops = file_ns::node_gather_link_searches;
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_scale_elements.cc b/source/blender/nodes/geometry/nodes/node_geo_scale_elements.cc
index d674f611c9f..5f1baa23511 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_scale_elements.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_scale_elements.cc
@@ -25,7 +25,7 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_input<decl::Float>(N_("Scale"), "Scale").default_value(1.0f).min(0.0f).supports_field();
b.add_input<decl::Vector>(N_("Center"))
.subtype(PROP_TRANSLATION)
- .implicit_field()
+ .implicit_field(implicit_field_inputs::position)
.description(N_("Origin of the scaling for each element. If multiple elements are "
"connected, their center is averaged"));
b.add_input<decl::Vector>(N_("Axis"))
@@ -36,13 +36,13 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Geometry"));
};
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "domain", 0, "", ICON_NONE);
uiItemR(layout, ptr, "scale_mode", 0, "", ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
node->custom1 = ATTR_DOMAIN_FACE;
node->custom2 = GEO_NODE_SCALE_ELEMENTS_UNIFORM;
@@ -56,8 +56,7 @@ static void node_update(bNodeTree *ntree, bNode *node)
bNodeSocket *center_socket = scale_float_socket->next;
bNodeSocket *axis_socket = center_socket->next;
- const GeometryNodeScaleElementsMode mode = static_cast<GeometryNodeScaleElementsMode>(
- node->custom2);
+ const GeometryNodeScaleElementsMode mode = GeometryNodeScaleElementsMode(node->custom2);
const bool use_single_axis = mode == GEO_NODE_SCALE_ELEMENTS_SINGLE_AXIS;
nodeSetSocketAvailability(ntree, axis_socket, use_single_axis);
@@ -147,14 +146,22 @@ static float4x4 create_single_axis_transform(const float3 &center,
return transform;
}
-using GetVertexIndicesFn =
- FunctionRef<void(const Mesh &mesh, int element_index, VectorSet<int> &r_vertex_indices)>;
+using GetVertexIndicesFn = FunctionRef<void(Span<MEdge> edges,
+ Span<MPoly> polys,
+ Span<MLoop> loops,
+ int element_index,
+ VectorSet<int> &r_vertex_indices)>;
static void scale_vertex_islands_uniformly(Mesh &mesh,
const Span<ElementIsland> islands,
const UniformScaleParams &params,
const GetVertexIndicesFn get_vertex_indices)
{
+ MutableSpan<MVert> verts = mesh.verts_for_write();
+ const Span<MEdge> edges = mesh.edges();
+ const Span<MPoly> polys = mesh.polys();
+ const Span<MLoop> loops = mesh.loops();
+
threading::parallel_for(islands.index_range(), 256, [&](const IndexRange range) {
for (const int island_index : range) {
const ElementIsland &island = islands[island_index];
@@ -164,7 +171,7 @@ static void scale_vertex_islands_uniformly(Mesh &mesh,
VectorSet<int> vertex_indices;
for (const int poly_index : island.element_indices) {
- get_vertex_indices(mesh, poly_index, vertex_indices);
+ get_vertex_indices(edges, polys, loops, poly_index, vertex_indices);
center += params.centers[poly_index];
scale += params.scales[poly_index];
}
@@ -175,7 +182,7 @@ static void scale_vertex_islands_uniformly(Mesh &mesh,
center *= f;
for (const int vert_index : vertex_indices) {
- MVert &vert = mesh.mvert[vert_index];
+ MVert &vert = verts[vert_index];
const float3 old_position = vert.co;
const float3 new_position = transform_with_uniform_scale(old_position, center, scale);
copy_v3_v3(vert.co, new_position);
@@ -191,6 +198,11 @@ static void scale_vertex_islands_on_axis(Mesh &mesh,
const AxisScaleParams &params,
const GetVertexIndicesFn get_vertex_indices)
{
+ MutableSpan<MVert> verts = mesh.verts_for_write();
+ const Span<MEdge> edges = mesh.edges();
+ const Span<MPoly> polys = mesh.polys();
+ const Span<MLoop> loops = mesh.loops();
+
threading::parallel_for(islands.index_range(), 256, [&](const IndexRange range) {
for (const int island_index : range) {
const ElementIsland &island = islands[island_index];
@@ -201,7 +213,7 @@ static void scale_vertex_islands_on_axis(Mesh &mesh,
VectorSet<int> vertex_indices;
for (const int poly_index : island.element_indices) {
- get_vertex_indices(mesh, poly_index, vertex_indices);
+ get_vertex_indices(edges, polys, loops, poly_index, vertex_indices);
center += params.centers[poly_index];
scale += params.scales[poly_index];
axis += params.axis_vectors[poly_index];
@@ -219,7 +231,7 @@ static void scale_vertex_islands_on_axis(Mesh &mesh,
const float4x4 transform = create_single_axis_transform(center, axis, scale);
for (const int vert_index : vertex_indices) {
- MVert &vert = mesh.mvert[vert_index];
+ MVert &vert = verts[vert_index];
const float3 old_position = vert.co;
const float3 new_position = transform * old_position;
copy_v3_v3(vert.co, new_position);
@@ -232,11 +244,14 @@ static void scale_vertex_islands_on_axis(Mesh &mesh,
static Vector<ElementIsland> prepare_face_islands(const Mesh &mesh, const IndexMask face_selection)
{
+ const Span<MPoly> polys = mesh.polys();
+ const Span<MLoop> loops = mesh.loops();
+
/* Use the disjoint set data structure to determine which vertices have to be scaled together. */
DisjointSet disjoint_set(mesh.totvert);
for (const int poly_index : face_selection) {
- const MPoly &poly = mesh.mpoly[poly_index];
- const Span<MLoop> poly_loops{mesh.mloop + poly.loopstart, poly.totloop};
+ const MPoly &poly = polys[poly_index];
+ const Span<MLoop> poly_loops = loops.slice(poly.loopstart, poly.totloop);
for (const int loop_index : IndexRange(poly.totloop - 1)) {
const int v1 = poly_loops[loop_index].v;
const int v2 = poly_loops[loop_index + 1].v;
@@ -252,8 +267,8 @@ static Vector<ElementIsland> prepare_face_islands(const Mesh &mesh, const IndexM
/* Gather all of the face indices in each island into separate vectors. */
for (const int poly_index : face_selection) {
- const MPoly &poly = mesh.mpoly[poly_index];
- const Span<MLoop> poly_loops{mesh.mloop + poly.loopstart, poly.totloop};
+ const MPoly &poly = polys[poly_index];
+ const Span<MLoop> poly_loops = loops.slice(poly.loopstart, poly.totloop);
const int island_id = disjoint_set.find_root(poly_loops[0].v);
const int island_index = island_ids.index_of_or_add(island_id);
if (island_index == islands.size()) {
@@ -266,10 +281,14 @@ static Vector<ElementIsland> prepare_face_islands(const Mesh &mesh, const IndexM
return islands;
}
-static void get_face_vertices(const Mesh &mesh, int face_index, VectorSet<int> &r_vertex_indices)
+static void get_face_verts(const Span<MEdge> /*edges*/,
+ const Span<MPoly> polys,
+ const Span<MLoop> loops,
+ int face_index,
+ VectorSet<int> &r_vertex_indices)
{
- const MPoly &poly = mesh.mpoly[face_index];
- const Span<MLoop> poly_loops{mesh.mloop + poly.loopstart, poly.totloop};
+ const MPoly &poly = polys[face_index];
+ const Span<MLoop> poly_loops = loops.slice(poly.loopstart, poly.totloop);
for (const MLoop &loop : poly_loops) {
r_vertex_indices.add(loop.v);
}
@@ -288,18 +307,14 @@ static AxisScaleParams evaluate_axis_scale_fields(FieldEvaluator &evaluator,
return out;
}
-static void scale_faces_on_axis(MeshComponent &mesh_component, const AxisScaleFields &fields)
+static void scale_faces_on_axis(Mesh &mesh, const AxisScaleFields &fields)
{
- Mesh &mesh = *mesh_component.get_for_write();
- mesh.mvert = static_cast<MVert *>(
- CustomData_duplicate_referenced_layer(&mesh.vdata, CD_MVERT, mesh.totvert));
-
- GeometryComponentFieldContext field_context{mesh_component, ATTR_DOMAIN_FACE};
+ bke::MeshFieldContext field_context{mesh, ATTR_DOMAIN_FACE};
FieldEvaluator evaluator{field_context, mesh.totpoly};
AxisScaleParams params = evaluate_axis_scale_fields(evaluator, fields);
Vector<ElementIsland> island = prepare_face_islands(mesh, params.selection);
- scale_vertex_islands_on_axis(mesh, island, params, get_face_vertices);
+ scale_vertex_islands_on_axis(mesh, island, params, get_face_verts);
}
static UniformScaleParams evaluate_uniform_scale_fields(FieldEvaluator &evaluator,
@@ -314,26 +329,24 @@ static UniformScaleParams evaluate_uniform_scale_fields(FieldEvaluator &evaluato
return out;
}
-static void scale_faces_uniformly(MeshComponent &mesh_component, const UniformScaleFields &fields)
+static void scale_faces_uniformly(Mesh &mesh, const UniformScaleFields &fields)
{
- Mesh &mesh = *mesh_component.get_for_write();
- mesh.mvert = static_cast<MVert *>(
- CustomData_duplicate_referenced_layer(&mesh.vdata, CD_MVERT, mesh.totvert));
-
- GeometryComponentFieldContext field_context{mesh_component, ATTR_DOMAIN_FACE};
+ bke::MeshFieldContext field_context{mesh, ATTR_DOMAIN_FACE};
FieldEvaluator evaluator{field_context, mesh.totpoly};
UniformScaleParams params = evaluate_uniform_scale_fields(evaluator, fields);
Vector<ElementIsland> island = prepare_face_islands(mesh, params.selection);
- scale_vertex_islands_uniformly(mesh, island, params, get_face_vertices);
+ scale_vertex_islands_uniformly(mesh, island, params, get_face_verts);
}
static Vector<ElementIsland> prepare_edge_islands(const Mesh &mesh, const IndexMask edge_selection)
{
+ const Span<MEdge> edges = mesh.edges();
+
/* Use the disjoint set data structure to determine which vertices have to be scaled together. */
DisjointSet disjoint_set(mesh.totvert);
for (const int edge_index : edge_selection) {
- const MEdge &edge = mesh.medge[edge_index];
+ const MEdge &edge = edges[edge_index];
disjoint_set.join(edge.v1, edge.v2);
}
@@ -344,7 +357,7 @@ static Vector<ElementIsland> prepare_edge_islands(const Mesh &mesh, const IndexM
/* Gather all of the edge indices in each island into separate vectors. */
for (const int edge_index : edge_selection) {
- const MEdge &edge = mesh.medge[edge_index];
+ const MEdge &edge = edges[edge_index];
const int island_id = disjoint_set.find_root(edge.v1);
const int island_index = island_ids.index_of_or_add(island_id);
if (island_index == islands.size()) {
@@ -357,47 +370,42 @@ static Vector<ElementIsland> prepare_edge_islands(const Mesh &mesh, const IndexM
return islands;
}
-static void get_edge_vertices(const Mesh &mesh, int edge_index, VectorSet<int> &r_vertex_indices)
+static void get_edge_verts(const Span<MEdge> edges,
+ const Span<MPoly> /*polys*/,
+ const Span<MLoop> /*loops*/,
+ int edge_index,
+ VectorSet<int> &r_vertex_indices)
{
- const MEdge &edge = mesh.medge[edge_index];
+ const MEdge &edge = edges[edge_index];
r_vertex_indices.add(edge.v1);
r_vertex_indices.add(edge.v2);
}
-static void scale_edges_uniformly(MeshComponent &mesh_component, const UniformScaleFields &fields)
+static void scale_edges_uniformly(Mesh &mesh, const UniformScaleFields &fields)
{
- Mesh &mesh = *mesh_component.get_for_write();
- mesh.mvert = static_cast<MVert *>(
- CustomData_duplicate_referenced_layer(&mesh.vdata, CD_MVERT, mesh.totvert));
-
- GeometryComponentFieldContext field_context{mesh_component, ATTR_DOMAIN_EDGE};
+ bke::MeshFieldContext field_context{mesh, ATTR_DOMAIN_EDGE};
FieldEvaluator evaluator{field_context, mesh.totedge};
UniformScaleParams params = evaluate_uniform_scale_fields(evaluator, fields);
Vector<ElementIsland> island = prepare_edge_islands(mesh, params.selection);
- scale_vertex_islands_uniformly(mesh, island, params, get_edge_vertices);
+ scale_vertex_islands_uniformly(mesh, island, params, get_edge_verts);
}
-static void scale_edges_on_axis(MeshComponent &mesh_component, const AxisScaleFields &fields)
+static void scale_edges_on_axis(Mesh &mesh, const AxisScaleFields &fields)
{
- Mesh &mesh = *mesh_component.get_for_write();
- mesh.mvert = static_cast<MVert *>(
- CustomData_duplicate_referenced_layer(&mesh.vdata, CD_MVERT, mesh.totvert));
-
- GeometryComponentFieldContext field_context{mesh_component, ATTR_DOMAIN_EDGE};
+ bke::MeshFieldContext field_context{mesh, ATTR_DOMAIN_EDGE};
FieldEvaluator evaluator{field_context, mesh.totedge};
AxisScaleParams params = evaluate_axis_scale_fields(evaluator, fields);
Vector<ElementIsland> island = prepare_edge_islands(mesh, params.selection);
- scale_vertex_islands_on_axis(mesh, island, params, get_edge_vertices);
+ scale_vertex_islands_on_axis(mesh, island, params, get_edge_verts);
}
static void node_geo_exec(GeoNodeExecParams params)
{
const bNode &node = params.node();
- const eAttrDomain domain = static_cast<eAttrDomain>(node.custom1);
- const GeometryNodeScaleElementsMode scale_mode = static_cast<GeometryNodeScaleElementsMode>(
- node.custom2);
+ const eAttrDomain domain = eAttrDomain(node.custom1);
+ const GeometryNodeScaleElementsMode scale_mode = GeometryNodeScaleElementsMode(node.custom2);
GeometrySet geometry = params.extract_input<GeometrySet>("Geometry");
@@ -410,42 +418,38 @@ static void node_geo_exec(GeoNodeExecParams params)
}
geometry.modify_geometry_sets([&](GeometrySet &geometry) {
- if (!geometry.has_mesh()) {
- return;
- }
- MeshComponent &mesh_component = geometry.get_component_for_write<MeshComponent>();
- switch (domain) {
- case ATTR_DOMAIN_FACE: {
- switch (scale_mode) {
- case GEO_NODE_SCALE_ELEMENTS_UNIFORM: {
- scale_faces_uniformly(mesh_component, {selection_field, scale_field, center_field});
- break;
- }
- case GEO_NODE_SCALE_ELEMENTS_SINGLE_AXIS: {
- scale_faces_on_axis(mesh_component,
- {selection_field, scale_field, center_field, axis_field});
- break;
+ if (Mesh *mesh = geometry.get_mesh_for_write()) {
+ switch (domain) {
+ case ATTR_DOMAIN_FACE: {
+ switch (scale_mode) {
+ case GEO_NODE_SCALE_ELEMENTS_UNIFORM: {
+ scale_faces_uniformly(*mesh, {selection_field, scale_field, center_field});
+ break;
+ }
+ case GEO_NODE_SCALE_ELEMENTS_SINGLE_AXIS: {
+ scale_faces_on_axis(*mesh, {selection_field, scale_field, center_field, axis_field});
+ break;
+ }
}
+ break;
}
- break;
- }
- case ATTR_DOMAIN_EDGE: {
- switch (scale_mode) {
- case GEO_NODE_SCALE_ELEMENTS_UNIFORM: {
- scale_edges_uniformly(mesh_component, {selection_field, scale_field, center_field});
- break;
- }
- case GEO_NODE_SCALE_ELEMENTS_SINGLE_AXIS: {
- scale_edges_on_axis(mesh_component,
- {selection_field, scale_field, center_field, axis_field});
- break;
+ case ATTR_DOMAIN_EDGE: {
+ switch (scale_mode) {
+ case GEO_NODE_SCALE_ELEMENTS_UNIFORM: {
+ scale_edges_uniformly(*mesh, {selection_field, scale_field, center_field});
+ break;
+ }
+ case GEO_NODE_SCALE_ELEMENTS_SINGLE_AXIS: {
+ scale_edges_on_axis(*mesh, {selection_field, scale_field, center_field, axis_field});
+ break;
+ }
}
+ break;
}
- break;
+ default:
+ BLI_assert_unreachable();
+ break;
}
- default:
- BLI_assert_unreachable();
- break;
}
});
diff --git a/source/blender/nodes/geometry/nodes/node_geo_scale_instances.cc b/source/blender/nodes/geometry/nodes/node_geo_scale_instances.cc
index 7156feb37d7..dacb130337f 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_scale_instances.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_scale_instances.cc
@@ -2,6 +2,8 @@
#include "BLI_task.hh"
+#include "BKE_instances.hh"
+
#include "node_geometry_util.hh"
namespace blender::nodes::node_geo_scale_instances_cc {
@@ -19,11 +21,10 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Instances"));
}
-static void scale_instances(GeoNodeExecParams &params, InstancesComponent &instances_component)
+static void scale_instances(GeoNodeExecParams &params, bke::Instances &instances)
{
- GeometryComponentFieldContext field_context{instances_component, ATTR_DOMAIN_INSTANCE};
-
- fn::FieldEvaluator evaluator{field_context, instances_component.instances_num()};
+ const bke::InstancesFieldContext context{instances};
+ fn::FieldEvaluator evaluator{context, instances.instances_num()};
evaluator.set_selection(params.extract_input<Field<bool>>("Selection"));
evaluator.add(params.extract_input<Field<float3>>("Scale"));
evaluator.add(params.extract_input<Field<float3>>("Center"));
@@ -35,13 +36,13 @@ static void scale_instances(GeoNodeExecParams &params, InstancesComponent &insta
const VArray<float3> pivots = evaluator.get_evaluated<float3>(1);
const VArray<bool> local_spaces = evaluator.get_evaluated<bool>(2);
- MutableSpan<float4x4> instance_transforms = instances_component.instance_transforms();
+ MutableSpan<float4x4> transforms = instances.transforms();
threading::parallel_for(selection.index_range(), 512, [&](IndexRange range) {
for (const int i_selection : range) {
const int i = selection[i_selection];
const float3 pivot = pivots[i];
- float4x4 &instance_transform = instance_transforms[i];
+ float4x4 &instance_transform = transforms[i];
if (local_spaces[i]) {
instance_transform *= float4x4::from_location(pivot);
@@ -62,9 +63,8 @@ static void scale_instances(GeoNodeExecParams &params, InstancesComponent &insta
static void node_geo_exec(GeoNodeExecParams params)
{
GeometrySet geometry_set = params.extract_input<GeometrySet>("Instances");
- if (geometry_set.has_instances()) {
- InstancesComponent &instances = geometry_set.get_component_for_write<InstancesComponent>();
- scale_instances(params, instances);
+ if (bke::Instances *instances = geometry_set.get_instances_for_write()) {
+ scale_instances(params, *instances);
}
params.set_output("Instances", std::move(geometry_set));
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_self_object.cc b/source/blender/nodes/geometry/nodes/node_geo_self_object.cc
new file mode 100644
index 00000000000..7b33afdb4a0
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_self_object.cc
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "node_geometry_util.hh"
+
+namespace blender::nodes::node_geo_self_object_cc {
+
+static void node_declare(NodeDeclarationBuilder &b)
+{
+ b.add_output<decl::Object>(N_("Self Object"));
+}
+
+static void node_geo_exec(GeoNodeExecParams params)
+{
+ params.set_output("Self Object", const_cast<Object *>(params.self_object()));
+}
+
+} // namespace blender::nodes::node_geo_self_object_cc
+
+void register_node_type_geo_self_object()
+{
+ namespace file_ns = blender::nodes::node_geo_self_object_cc;
+
+ static bNodeType ntype;
+
+ geo_node_type_base(&ntype, GEO_NODE_SELF_OBJECT, "Self Object", NODE_CLASS_INPUT);
+ ntype.geometry_node_execute = file_ns::node_geo_exec;
+ ntype.declare = file_ns::node_declare;
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_separate_geometry.cc b/source/blender/nodes/geometry/nodes/node_geo_separate_geometry.cc
index d785694f253..44d12466d9e 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_separate_geometry.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_separate_geometry.cc
@@ -23,12 +23,12 @@ static void node_declare(NodeDeclarationBuilder &b)
.description(N_("The parts of the geometry not in the selection"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "domain", 0, "", ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometrySeparateGeometry *data = MEM_cnew<NodeGeometrySeparateGeometry>(__func__);
data->domain = ATTR_DOMAIN_POINT;
@@ -43,7 +43,7 @@ static void node_geo_exec(GeoNodeExecParams params)
const Field<bool> selection_field = params.extract_input<Field<bool>>("Selection");
const NodeGeometrySeparateGeometry &storage = node_storage(params.node());
- const eAttrDomain domain = static_cast<eAttrDomain>(storage.domain);
+ const eAttrDomain domain = eAttrDomain(storage.domain);
auto separate_geometry_maybe_recursively = [&](GeometrySet &geometry_set,
const Field<bool> &selection) {
diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc b/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc
index fc3cb7006bb..c143203337a 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc
@@ -17,17 +17,21 @@ static void node_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Geometry>(N_("Curve")).supported_type(GEO_COMPONENT_TYPE_CURVE);
b.add_input<decl::Bool>(N_("Selection")).default_value(true).hide_value().supports_field();
- b.add_input<decl::Vector>(N_("Position")).implicit_field();
+ b.add_input<decl::Vector>(N_("Position")).implicit_field([](const bNode &node, void *r_value) {
+ const StringRef side = node_storage(node).mode == GEO_NODE_CURVE_HANDLE_LEFT ? "handle_left" :
+ "handle_right";
+ new (r_value) ValueOrField<float3>(bke::AttributeFieldInput::Create<float3>(side));
+ });
b.add_input<decl::Vector>(N_("Offset")).default_value(float3(0.0f, 0.0f, 0.0f)).supports_field();
b.add_output<decl::Geometry>(N_("Curve"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometrySetCurveHandlePositions *data = MEM_cnew<NodeGeometrySetCurveHandlePositions>(
__func__);
@@ -68,19 +72,18 @@ static void update_handle_types_for_movement(int8_t &type, int8_t &other)
}
}
-static void set_position_in_component(CurveComponent &component,
+static void set_position_in_component(bke::CurvesGeometry &curves,
const GeometryNodeCurveHandleMode mode,
const Field<bool> &selection_field,
const Field<float3> &position_field,
const Field<float3> &offset_field)
{
- GeometryComponentFieldContext field_context{component, ATTR_DOMAIN_POINT};
- const int domain_size = component.attribute_domain_size(ATTR_DOMAIN_POINT);
- if (domain_size == 0) {
+ if (curves.points_num() == 0) {
return;
}
- fn::FieldEvaluator evaluator{field_context, domain_size};
+ bke::CurvesFieldContext field_context{curves, ATTR_DOMAIN_POINT};
+ fn::FieldEvaluator evaluator{field_context, curves.points_num()};
evaluator.set_selection(selection_field);
evaluator.add(position_field);
evaluator.add(offset_field);
@@ -89,9 +92,6 @@ static void set_position_in_component(CurveComponent &component,
const VArray<float3> new_positions = evaluator.get_evaluated<float3>(0);
const VArray<float3> new_offsets = evaluator.get_evaluated<float3>(1);
- Curves &curves_id = *component.get_for_write();
- bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id.geometry);
-
Span<float3> positions = curves.positions();
const bool use_left = mode == GEO_NODE_CURVE_HANDLE_LEFT;
@@ -141,22 +141,17 @@ static void node_geo_exec(GeoNodeExecParams params)
std::atomic<bool> has_bezier = false;
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
- if (!geometry_set.has_curves()) {
- return;
- }
- has_curves = true;
- const CurveComponent &component = *geometry_set.get_component_for_read<CurveComponent>();
- const AttributeAccessor attributes = *component.attributes();
- if (!attributes.contains("handle_left") || !attributes.contains("handle_right")) {
- return;
- }
- has_bezier = true;
+ if (Curves *curves_id = geometry_set.get_curves_for_write()) {
+ bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry);
+ has_curves = true;
+ const AttributeAccessor attributes = curves.attributes();
+ if (!attributes.contains("handle_left") || !attributes.contains("handle_right")) {
+ return;
+ }
+ has_bezier = true;
- set_position_in_component(geometry_set.get_component_for_write<CurveComponent>(),
- mode,
- selection_field,
- position_field,
- offset_field);
+ set_position_in_component(curves, mode, selection_field, position_field, offset_field);
+ }
});
if (has_curves && !has_bezier) {
diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_curve_normal.cc b/source/blender/nodes/geometry/nodes/node_geo_set_curve_normal.cc
new file mode 100644
index 00000000000..e2169966f5a
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_set_curve_normal.cc
@@ -0,0 +1,73 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "BKE_curves.hh"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "node_geometry_util.hh"
+
+namespace blender::nodes::node_geo_set_curve_normal_cc {
+
+static void node_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::Geometry>(N_("Curve")).supported_type(GEO_COMPONENT_TYPE_CURVE);
+ b.add_input<decl::Bool>(N_("Selection")).default_value(true).hide_value().supports_field();
+ b.add_output<decl::Geometry>(N_("Curve"));
+}
+
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
+{
+ uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
+}
+
+static void node_init(bNodeTree * /*tree*/, bNode *node)
+{
+ node->custom1 = NORMAL_MODE_MINIMUM_TWIST;
+}
+
+static void set_normal_mode(bke::CurvesGeometry &curves,
+ const NormalMode mode,
+ const Field<bool> &selection_field)
+{
+ bke::CurvesFieldContext field_context{curves, ATTR_DOMAIN_CURVE};
+ fn::FieldEvaluator evaluator{field_context, curves.curves_num()};
+ evaluator.set_selection(selection_field);
+ evaluator.evaluate();
+ const IndexMask selection = evaluator.get_evaluated_selection_as_mask();
+ curves.normal_mode_for_write().fill_indices(selection, mode);
+ curves.tag_normals_changed();
+}
+
+static void node_geo_exec(GeoNodeExecParams params)
+{
+ const NormalMode mode = static_cast<NormalMode>(params.node().custom1);
+
+ GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve");
+ Field<bool> selection_field = params.extract_input<Field<bool>>("Selection");
+
+ geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
+ if (Curves *curves_id = geometry_set.get_curves_for_write()) {
+ bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry);
+ set_normal_mode(curves, mode, selection_field);
+ }
+ });
+
+ params.set_output("Curve", std::move(geometry_set));
+}
+
+} // namespace blender::nodes::node_geo_set_curve_normal_cc
+
+void register_node_type_geo_set_curve_normal()
+{
+ namespace file_ns = blender::nodes::node_geo_set_curve_normal_cc;
+
+ static bNodeType ntype;
+ geo_node_type_base(&ntype, GEO_NODE_SET_CURVE_NORMAL, "Set Curve Normal", NODE_CLASS_GEOMETRY);
+ ntype.declare = file_ns::node_declare;
+ ntype.geometry_node_execute = file_ns::node_geo_exec;
+ node_type_init(&ntype, file_ns::node_init);
+ ntype.draw_buttons = file_ns::node_layout;
+
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_curve_radius.cc b/source/blender/nodes/geometry/nodes/node_geo_set_curve_radius.cc
index e4fae95b5a5..0d361090068 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_set_curve_radius.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_set_curve_radius.cc
@@ -1,5 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "BKE_curves.hh"
+
#include "node_geometry_util.hh"
namespace blender::nodes::node_geo_set_curve_radius_cc {
@@ -16,21 +18,19 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Curve"));
}
-static void set_radius_in_component(GeometryComponent &component,
- const Field<bool> &selection_field,
- const Field<float> &radius_field)
+static void set_radius(bke::CurvesGeometry &curves,
+ const Field<bool> &selection_field,
+ const Field<float> &radius_field)
{
- const int domain_size = component.attribute_domain_size(ATTR_DOMAIN_POINT);
- if (domain_size == 0) {
+ if (curves.points_num() == 0) {
return;
}
- MutableAttributeAccessor attributes = *component.attributes_for_write();
- GeometryComponentFieldContext field_context{component, ATTR_DOMAIN_POINT};
-
+ MutableAttributeAccessor attributes = curves.attributes_for_write();
AttributeWriter<float> radii = attributes.lookup_or_add_for_write<float>("radius",
ATTR_DOMAIN_POINT);
- fn::FieldEvaluator evaluator{field_context, domain_size};
+ bke::CurvesFieldContext field_context{curves, ATTR_DOMAIN_POINT};
+ fn::FieldEvaluator evaluator{field_context, curves.points_num()};
evaluator.set_selection(selection_field);
evaluator.add_with_destination(radius_field, radii.varray);
evaluator.evaluate();
@@ -45,9 +45,8 @@ static void node_geo_exec(GeoNodeExecParams params)
Field<float> radii_field = params.extract_input<Field<float>>("Radius");
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
- if (geometry_set.has_curves()) {
- set_radius_in_component(
- geometry_set.get_component_for_write<CurveComponent>(), selection_field, radii_field);
+ if (Curves *curves_id = geometry_set.get_curves_for_write()) {
+ set_radius(bke::CurvesGeometry::wrap(curves_id->geometry), selection_field, radii_field);
}
});
diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc b/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc
index 2211ac62727..8c1fb883f46 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc
@@ -1,5 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "BKE_curves.hh"
+
#include "node_geometry_util.hh"
namespace blender::nodes::node_geo_set_curve_tilt_cc {
@@ -12,22 +14,19 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Curve"));
}
-static void set_tilt_in_component(GeometryComponent &component,
- const Field<bool> &selection_field,
- const Field<float> &tilt_field)
+static void set_tilt(bke::CurvesGeometry &curves,
+ const Field<bool> &selection_field,
+ const Field<float> &tilt_field)
{
- const int domain_size = component.attribute_domain_size(ATTR_DOMAIN_POINT);
- if (domain_size == 0) {
+ if (curves.points_num() == 0) {
return;
}
- MutableAttributeAccessor attributes = *component.attributes_for_write();
-
- GeometryComponentFieldContext field_context{component, ATTR_DOMAIN_POINT};
-
+ MutableAttributeAccessor attributes = curves.attributes_for_write();
AttributeWriter<float> tilts = attributes.lookup_or_add_for_write<float>("tilt",
ATTR_DOMAIN_POINT);
- fn::FieldEvaluator evaluator{field_context, domain_size};
+ bke::CurvesFieldContext field_context{curves, ATTR_DOMAIN_POINT};
+ fn::FieldEvaluator evaluator{field_context, curves.points_num()};
evaluator.set_selection(selection_field);
evaluator.add_with_destination(tilt_field, tilts.varray);
evaluator.evaluate();
@@ -42,9 +41,8 @@ static void node_geo_exec(GeoNodeExecParams params)
Field<float> tilt_field = params.extract_input<Field<float>>("Tilt");
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
- if (geometry_set.has_curves()) {
- set_tilt_in_component(
- geometry_set.get_component_for_write<CurveComponent>(), selection_field, tilt_field);
+ if (Curves *curves_id = geometry_set.get_curves_for_write()) {
+ set_tilt(bke::CurvesGeometry::wrap(curves_id->geometry), selection_field, tilt_field);
}
});
diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_id.cc b/source/blender/nodes/geometry/nodes/node_geo_set_id.cc
index fbb2ecbb799..e308371b1c2 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_set_id.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_set_id.cc
@@ -8,7 +8,7 @@ static void node_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Geometry>(N_("Geometry"));
b.add_input<decl::Bool>(N_("Selection")).default_value(true).hide_value().supports_field();
- b.add_input<decl::Int>(N_("ID")).implicit_field();
+ b.add_input<decl::Int>(N_("ID")).implicit_field(implicit_field_inputs::index);
b.add_output<decl::Geometry>(N_("Geometry"));
}
@@ -24,7 +24,7 @@ static void set_id_in_component(GeometryComponent &component,
return;
}
MutableAttributeAccessor attributes = *component.attributes_for_write();
- GeometryComponentFieldContext field_context{component, domain};
+ bke::GeometryFieldContext field_context{component, domain};
fn::FieldEvaluator evaluator{field_context, domain_size};
evaluator.set_selection(selection_field);
diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_material.cc b/source/blender/nodes/geometry/nodes/node_geo_set_material.cc
index 507c6e81b1f..8d00d82664b 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_set_material.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_set_material.cc
@@ -12,6 +12,7 @@
#include "DNA_volume_types.h"
#include "BKE_material.h"
+#include "BKE_mesh.h"
namespace blender::nodes::node_geo_set_material_cc {
@@ -49,11 +50,11 @@ static void assign_material_to_faces(Mesh &mesh, const IndexMask selection, Mate
BKE_id_material_eval_assign(&mesh.id, new_material_index + 1, material);
}
- mesh.mpoly = (MPoly *)CustomData_duplicate_referenced_layer(&mesh.pdata, CD_MPOLY, mesh.totpoly);
- for (const int i : selection) {
- MPoly &poly = mesh.mpoly[i];
- poly.mat_nr = new_material_index;
- }
+ MutableAttributeAccessor attributes = mesh.attributes_for_write();
+ SpanAttributeWriter<int> material_indices = attributes.lookup_or_add_for_write_span<int>(
+ "material_index", ATTR_DOMAIN_FACE);
+ material_indices.span.fill_indices(selection, new_material_index);
+ material_indices.finish();
}
static void node_geo_exec(GeoNodeExecParams params)
@@ -72,8 +73,8 @@ static void node_geo_exec(GeoNodeExecParams params)
if (geometry_set.has_mesh()) {
MeshComponent &mesh_component = geometry_set.get_component_for_write<MeshComponent>();
Mesh &mesh = *mesh_component.get_for_write();
- GeometryComponentFieldContext field_context{mesh_component, ATTR_DOMAIN_FACE};
+ bke::MeshFieldContext field_context{mesh, ATTR_DOMAIN_FACE};
fn::FieldEvaluator selection_evaluator{field_context, mesh.totpoly};
selection_evaluator.add(selection_field);
selection_evaluator.evaluate();
diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_material_index.cc b/source/blender/nodes/geometry/nodes/node_geo_set_material_index.cc
index 0dc89bb7ef4..bb9ac9b5d4c 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_set_material_index.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_set_material_index.cc
@@ -14,21 +14,23 @@ static void node_declare(NodeDeclarationBuilder &b)
static void set_material_index_in_component(GeometryComponent &component,
const Field<bool> &selection_field,
- const Field<int> &index_field)
+ const Field<int> &index_field,
+ const eAttrDomain domain)
{
- const int domain_size = component.attribute_domain_size(ATTR_DOMAIN_FACE);
+ const int domain_size = component.attribute_domain_size(domain);
if (domain_size == 0) {
return;
}
MutableAttributeAccessor attributes = *component.attributes_for_write();
- GeometryComponentFieldContext field_context{component, ATTR_DOMAIN_FACE};
+ bke::GeometryFieldContext field_context{component, domain};
- AttributeWriter<int> indices = attributes.lookup_or_add_for_write<int>("material_index",
- ATTR_DOMAIN_FACE);
+ const bke::AttributeValidator validator = attributes.lookup_validator("material_index");
+ AttributeWriter<int> indices = attributes.lookup_or_add_for_write<int>("material_index", domain);
fn::FieldEvaluator evaluator{field_context, domain_size};
evaluator.set_selection(selection_field);
- evaluator.add_with_destination(index_field, indices.varray);
+ evaluator.add_with_destination(validator.validate_field_if_necessary(index_field),
+ indices.varray);
evaluator.evaluate();
indices.finish();
}
@@ -41,8 +43,10 @@ static void node_geo_exec(GeoNodeExecParams params)
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
if (geometry_set.has_mesh()) {
- set_material_index_in_component(
- geometry_set.get_component_for_write<MeshComponent>(), selection_field, index_field);
+ set_material_index_in_component(geometry_set.get_component_for_write<MeshComponent>(),
+ selection_field,
+ index_field,
+ ATTR_DOMAIN_FACE);
}
});
params.set_output("Geometry", std::move(geometry_set));
diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_point_radius.cc b/source/blender/nodes/geometry/nodes/node_geo_set_point_radius.cc
index da7977a4fb4..28d07b31218 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_set_point_radius.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_set_point_radius.cc
@@ -1,5 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "DNA_pointcloud_types.h"
+
#include "node_geometry_util.hh"
namespace blender::nodes::node_geo_set_point_radius_cc {
@@ -16,21 +18,19 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Points"));
}
-static void set_radius_in_component(GeometryComponent &component,
+static void set_radius_in_component(PointCloud &pointcloud,
const Field<bool> &selection_field,
const Field<float> &radius_field)
{
- const int domain_size = component.attribute_domain_size(ATTR_DOMAIN_POINT);
- if (domain_size == 0) {
+ if (pointcloud.totpoint == 0) {
return;
}
- MutableAttributeAccessor attributes = *component.attributes_for_write();
- GeometryComponentFieldContext field_context{component, ATTR_DOMAIN_POINT};
-
+ MutableAttributeAccessor attributes = pointcloud.attributes_for_write();
AttributeWriter<float> radii = attributes.lookup_or_add_for_write<float>("radius",
ATTR_DOMAIN_POINT);
- fn::FieldEvaluator evaluator{field_context, domain_size};
+ bke::PointCloudFieldContext field_context{pointcloud};
+ fn::FieldEvaluator evaluator{field_context, pointcloud.totpoint};
evaluator.set_selection(selection_field);
evaluator.add_with_destination(radius_field, radii.varray);
evaluator.evaluate();
@@ -45,10 +45,8 @@ static void node_geo_exec(GeoNodeExecParams params)
Field<float> radii_field = params.extract_input<Field<float>>("Radius");
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
- if (geometry_set.has_pointcloud()) {
- set_radius_in_component(geometry_set.get_component_for_write<PointCloudComponent>(),
- selection_field,
- radii_field);
+ if (PointCloud *pointcloud = geometry_set.get_pointcloud_for_write()) {
+ set_radius_in_component(*pointcloud, selection_field, radii_field);
}
});
diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_position.cc b/source/blender/nodes/geometry/nodes/node_geo_set_position.cc
index 880252de4fa..e243fe3614c 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_set_position.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_set_position.cc
@@ -8,6 +8,7 @@
#include "DNA_meshdata_types.h"
#include "BKE_curves.hh"
+#include "BKE_mesh.h"
#include "node_geometry_util.hh"
@@ -17,7 +18,7 @@ static void node_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Geometry>(N_("Geometry"));
b.add_input<decl::Bool>(N_("Selection")).default_value(true).hide_value().supports_field();
- b.add_input<decl::Vector>(N_("Position")).implicit_field();
+ b.add_input<decl::Vector>(N_("Position")).implicit_field(implicit_field_inputs::position);
b.add_input<decl::Vector>(N_("Offset")).supports_field().subtype(PROP_TRANSLATION);
b.add_output<decl::Geometry>(N_("Geometry"));
}
@@ -35,14 +36,14 @@ static void set_computed_position_and_offset(GeometryComponent &component,
switch (component.type()) {
case GEO_COMPONENT_TYPE_MESH: {
Mesh *mesh = static_cast<MeshComponent &>(component).get_for_write();
- MutableSpan<MVert> mverts{mesh->mvert, mesh->totvert};
+ MutableSpan<MVert> verts = mesh->verts_for_write();
if (in_positions.is_same(positions.varray)) {
devirtualize_varray(in_offsets, [&](const auto in_offsets) {
threading::parallel_for(
selection.index_range(), grain_size, [&](const IndexRange range) {
for (const int i : selection.slice(range)) {
const float3 offset = in_offsets[i];
- add_v3_v3(mverts[i].co, offset);
+ add_v3_v3(verts[i].co, offset);
}
});
});
@@ -54,7 +55,7 @@ static void set_computed_position_and_offset(GeometryComponent &component,
selection.index_range(), grain_size, [&](const IndexRange range) {
for (const int i : selection.slice(range)) {
const float3 new_position = in_positions[i] + in_offsets[i];
- copy_v3_v3(mverts[i].co, new_position);
+ copy_v3_v3(verts[i].co, new_position);
}
});
});
@@ -136,7 +137,7 @@ static void set_position_in_component(GeometryComponent &component,
{
eAttrDomain domain = component.type() == GEO_COMPONENT_TYPE_INSTANCES ? ATTR_DOMAIN_INSTANCE :
ATTR_DOMAIN_POINT;
- GeometryComponentFieldContext field_context{component, domain};
+ bke::GeometryFieldContext field_context{component, domain};
const int domain_size = component.attribute_domain_size(domain);
if (domain_size == 0) {
return;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_shade_smooth.cc b/source/blender/nodes/geometry/nodes/node_geo_set_shade_smooth.cc
index e0cf0f98d58..0df51e49827 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_set_shade_smooth.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_set_shade_smooth.cc
@@ -1,5 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "DNA_mesh_types.h"
+
#include "node_geometry_util.hh"
namespace blender::nodes::node_geo_set_shade_smooth_cc {
@@ -12,27 +14,25 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Geometry"));
}
-static void set_smooth_in_component(GeometryComponent &component,
- const Field<bool> &selection_field,
- const Field<bool> &shade_field)
+static void set_smooth(Mesh &mesh,
+ const Field<bool> &selection_field,
+ const Field<bool> &shade_field)
{
- const int domain_size = component.attribute_domain_size(ATTR_DOMAIN_FACE);
- if (domain_size == 0) {
+ if (mesh.totpoly == 0) {
return;
}
- MutableAttributeAccessor attributes = *component.attributes_for_write();
-
- GeometryComponentFieldContext field_context{component, ATTR_DOMAIN_FACE};
- AttributeWriter<bool> shades = attributes.lookup_or_add_for_write<bool>("shade_smooth",
+ MutableAttributeAccessor attributes = mesh.attributes_for_write();
+ AttributeWriter<bool> smooth = attributes.lookup_or_add_for_write<bool>("shade_smooth",
ATTR_DOMAIN_FACE);
- fn::FieldEvaluator evaluator{field_context, domain_size};
+ bke::MeshFieldContext field_context{mesh, ATTR_DOMAIN_FACE};
+ fn::FieldEvaluator evaluator{field_context, mesh.totpoly};
evaluator.set_selection(selection_field);
- evaluator.add_with_destination(shade_field, shades.varray);
+ evaluator.add_with_destination(shade_field, smooth.varray);
evaluator.evaluate();
- shades.finish();
+ smooth.finish();
}
static void node_geo_exec(GeoNodeExecParams params)
@@ -42,9 +42,8 @@ static void node_geo_exec(GeoNodeExecParams params)
Field<bool> shade_field = params.extract_input<Field<bool>>("Shade Smooth");
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
- if (geometry_set.has_mesh()) {
- set_smooth_in_component(
- geometry_set.get_component_for_write<MeshComponent>(), selection_field, shade_field);
+ if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
+ set_smooth(*mesh, selection_field, shade_field);
}
});
params.set_output("Geometry", std::move(geometry_set));
diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_spline_cyclic.cc b/source/blender/nodes/geometry/nodes/node_geo_set_spline_cyclic.cc
index a35d8d66558..d8faa154477 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_set_spline_cyclic.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_set_spline_cyclic.cc
@@ -1,5 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "BKE_curves.hh"
+
#include "node_geometry_util.hh"
namespace blender::nodes::node_geo_set_spline_cyclic_cc {
@@ -12,22 +14,19 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Geometry"));
}
-static void set_cyclic_in_component(GeometryComponent &component,
- const Field<bool> &selection_field,
- const Field<bool> &cyclic_field)
+static void set_cyclic(bke::CurvesGeometry &curves,
+ const Field<bool> &selection_field,
+ const Field<bool> &cyclic_field)
{
- const int domain_size = component.attribute_domain_size(ATTR_DOMAIN_CURVE);
- if (domain_size == 0) {
+ if (curves.curves_num() == 0) {
return;
}
- MutableAttributeAccessor attributes = *component.attributes_for_write();
-
- GeometryComponentFieldContext field_context{component, ATTR_DOMAIN_CURVE};
-
+ MutableAttributeAccessor attributes = curves.attributes_for_write();
AttributeWriter<bool> cyclics = attributes.lookup_or_add_for_write<bool>("cyclic",
ATTR_DOMAIN_CURVE);
- fn::FieldEvaluator evaluator{field_context, domain_size};
+ bke::CurvesFieldContext field_context{curves, ATTR_DOMAIN_CURVE};
+ fn::FieldEvaluator evaluator{field_context, curves.curves_num()};
evaluator.set_selection(selection_field);
evaluator.add_with_destination(cyclic_field, cyclics.varray);
evaluator.evaluate();
@@ -42,9 +41,8 @@ static void node_geo_exec(GeoNodeExecParams params)
Field<bool> cyclic_field = params.extract_input<Field<bool>>("Cyclic");
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
- if (geometry_set.has_curves()) {
- set_cyclic_in_component(
- geometry_set.get_component_for_write<CurveComponent>(), selection_field, cyclic_field);
+ if (Curves *curves_id = geometry_set.get_curves_for_write()) {
+ set_cyclic(bke::CurvesGeometry::wrap(curves_id->geometry), selection_field, cyclic_field);
}
});
diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_spline_resolution.cc b/source/blender/nodes/geometry/nodes/node_geo_set_spline_resolution.cc
index fcebc1116d7..d46ceac92ba 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_set_spline_resolution.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_set_spline_resolution.cc
@@ -1,5 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "BKE_curves.hh"
+
#include "node_geometry_util.hh"
namespace blender::nodes::node_geo_set_spline_resolution_cc {
@@ -12,22 +14,19 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Geometry"));
}
-static void set_resolution_in_component(GeometryComponent &component,
- const Field<bool> &selection_field,
- const Field<int> &resolution_field)
+static void set_resolution(bke::CurvesGeometry &curves,
+ const Field<bool> &selection_field,
+ const Field<int> &resolution_field)
{
- const int domain_size = component.attribute_domain_size(ATTR_DOMAIN_CURVE);
- if (domain_size == 0) {
+ if (curves.curves_num() == 0) {
return;
}
- MutableAttributeAccessor attributes = *component.attributes_for_write();
-
- GeometryComponentFieldContext field_context{component, ATTR_DOMAIN_CURVE};
-
+ MutableAttributeAccessor attributes = curves.attributes_for_write();
AttributeWriter<int> resolutions = attributes.lookup_or_add_for_write<int>("resolution",
ATTR_DOMAIN_CURVE);
- fn::FieldEvaluator evaluator{field_context, domain_size};
+ bke::CurvesFieldContext field_context{curves, ATTR_DOMAIN_CURVE};
+ fn::FieldEvaluator evaluator{field_context, curves.curves_num()};
evaluator.set_selection(selection_field);
evaluator.add_with_destination(resolution_field, resolutions.varray);
evaluator.evaluate();
@@ -38,12 +37,13 @@ static void set_resolution_in_component(GeometryComponent &component,
static void node_geo_exec(GeoNodeExecParams params)
{
GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
- Field<bool> selection_field = params.extract_input<Field<bool>>("Selection");
- Field<int> resolution_field = params.extract_input<Field<int>>("Resolution");
+ Field<bool> selection = params.extract_input<Field<bool>>("Selection");
+ Field<int> resolution = params.extract_input<Field<int>>("Resolution");
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
- set_resolution_in_component(
- geometry_set.get_component_for_write<CurveComponent>(), selection_field, resolution_field);
+ if (Curves *curves_id = geometry_set.get_curves_for_write()) {
+ set_resolution(bke::CurvesGeometry::wrap(curves_id->geometry), selection, resolution);
+ }
});
params.set_output("Geometry", std::move(geometry_set));
diff --git a/source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc b/source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc
index dbd68f4c783..3c85fd459e1 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc
@@ -30,7 +30,7 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Geometry"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
@@ -38,7 +38,7 @@ static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
uiItemR(layout, ptr, "domain", 0, "", ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryStoreNamedAttribute *data = MEM_cnew<NodeGeometryStoreNamedAttribute>(__func__);
data->data_type = CD_PROP_FLOAT;
@@ -49,9 +49,9 @@ static void node_init(bNodeTree *UNUSED(tree), bNode *node)
static void node_update(bNodeTree *ntree, bNode *node)
{
const NodeGeometryStoreNamedAttribute &storage = node_storage(*node);
- const eCustomDataType data_type = static_cast<eCustomDataType>(storage.data_type);
+ const eCustomDataType data_type = eCustomDataType(storage.data_type);
- bNodeSocket *socket_geometry = (bNodeSocket *)node->inputs.first;
+ bNodeSocket *socket_geometry = static_cast<bNodeSocket *>(node->inputs.first);
bNodeSocket *socket_name = socket_geometry->next;
bNodeSocket *socket_vector = socket_name->next;
bNodeSocket *socket_float = socket_vector->next;
@@ -71,10 +71,11 @@ static void node_gather_link_searches(GatherLinkSearchOpParams &params)
{
const NodeDeclaration &declaration = *params.node_type().fixed_declaration;
search_link_ops_for_declarations(params, declaration.inputs().take_front(2));
+ search_link_ops_for_declarations(params, declaration.outputs().take_front(1));
- if (params.in_out() == SOCK_OUT) {
+ if (params.in_out() == SOCK_IN) {
const std::optional<eCustomDataType> type = node_data_type_to_custom_data_type(
- static_cast<eNodeSocketDatatype>(params.other_socket().type));
+ eNodeSocketDatatype(params.other_socket().type));
if (type && *type != CD_PROP_STRING) {
/* The input and output sockets have the same name. */
params.add_item(IFACE_("Value"), [type](LinkSearchOpParams &params) {
@@ -86,56 +87,6 @@ static void node_gather_link_searches(GatherLinkSearchOpParams &params)
}
}
-static void try_capture_field_on_geometry(GeometryComponent &component,
- const StringRef name,
- const eAttrDomain domain,
- const GField &field,
- std::atomic<bool> &r_failure)
-{
- MutableAttributeAccessor attributes = *component.attributes_for_write();
- const int domain_size = attributes.domain_size(domain);
- if (domain_size == 0) {
- return;
- }
-
- GeometryComponentFieldContext field_context{component, domain};
- const IndexMask mask{IndexMask(domain_size)};
-
- const CPPType &type = field.cpp_type();
- const eCustomDataType data_type = bke::cpp_type_to_custom_data_type(type);
-
- /* Could avoid allocating a new buffer if:
- * - We are writing to an attribute that exists already with the correct domain and type.
- * - The field does not depend on that attribute (we can't easily check for that yet). */
- void *buffer = MEM_mallocN(type.size() * domain_size, __func__);
-
- fn::FieldEvaluator evaluator{field_context, &mask};
- evaluator.add_with_destination(field, GMutableSpan{type, buffer, domain_size});
- evaluator.evaluate();
-
- if (GAttributeWriter attribute = attributes.lookup_for_write(name)) {
- if (attribute.domain == domain && attribute.varray.type() == type) {
- attribute.varray.set_all(buffer);
- attribute.finish();
- type.destruct_n(buffer, domain_size);
- MEM_freeN(buffer);
- return;
- }
- }
-
- if (attributes.remove(name)) {
- if (attributes.add(name, domain, data_type, bke::AttributeInitMove{buffer})) {
- return;
- }
- }
-
- /* If the name corresponds to a builtin attribute, removing the attribute might fail if
- * it's required, and adding the attribute might fail if the domain or type is incorrect. */
- type.destruct_n(buffer, domain_size);
- MEM_freeN(buffer);
- r_failure = true;
-}
-
static void node_geo_exec(GeoNodeExecParams params)
{
GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
@@ -151,11 +102,11 @@ static void node_geo_exec(GeoNodeExecParams params)
return;
}
- params.used_named_attribute(name, eNamedAttrUsage::Write);
+ params.used_named_attribute(name, NamedAttributeUsage::Write);
const NodeGeometryStoreNamedAttribute &storage = node_storage(params.node());
- const eCustomDataType data_type = static_cast<eCustomDataType>(storage.data_type);
- const eAttrDomain domain = static_cast<eAttrDomain>(storage.domain);
+ const eCustomDataType data_type = eCustomDataType(storage.data_type);
+ const eAttrDomain domain = eAttrDomain(storage.domain);
GField field;
switch (data_type) {
@@ -191,7 +142,9 @@ static void node_geo_exec(GeoNodeExecParams params)
if (geometry_set.has_instances()) {
GeometryComponent &component = geometry_set.get_component_for_write(
GEO_COMPONENT_TYPE_INSTANCES);
- try_capture_field_on_geometry(component, name, domain, field, failure);
+ if (!bke::try_capture_field_on_geometry(component, name, domain, field)) {
+ failure.store(true);
+ }
}
}
else {
@@ -200,7 +153,9 @@ static void node_geo_exec(GeoNodeExecParams params)
{GEO_COMPONENT_TYPE_MESH, GEO_COMPONENT_TYPE_POINT_CLOUD, GEO_COMPONENT_TYPE_CURVE}) {
if (geometry_set.has(type)) {
GeometryComponent &component = geometry_set.get_component_for_write(type);
- try_capture_field_on_geometry(component, name, domain, field, failure);
+ if (!bke::try_capture_field_on_geometry(component, name, domain, field)) {
+ failure.store(true);
+ }
}
}
});
diff --git a/source/blender/nodes/geometry/nodes/node_geo_string_join.cc b/source/blender/nodes/geometry/nodes/node_geo_string_join.cc
index bb33430a02f..09c01b8c627 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_string_join.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_string_join.cc
@@ -13,12 +13,13 @@ static void node_declare(NodeDeclarationBuilder &b)
static void node_geo_exec(GeoNodeExecParams params)
{
- Vector<std::string> strings = params.extract_multi_input<std::string>("Strings");
+ Vector<fn::ValueOrField<std::string>> strings =
+ params.extract_input<Vector<fn::ValueOrField<std::string>>>("Strings");
const std::string delim = params.extract_input<std::string>("Delimiter");
std::string output;
for (const int i : strings.index_range()) {
- output += strings[i];
+ output += strings[i].as_value();
if (i < (strings.size() - 1)) {
output += delim;
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_string_to_curves.cc b/source/blender/nodes/geometry/nodes/node_geo_string_to_curves.cc
index afd7db6604d..769a63f58cf 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_string_to_curves.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_string_to_curves.cc
@@ -6,6 +6,7 @@
#include "BKE_curve.h"
#include "BKE_curve_legacy_convert.hh"
#include "BKE_curves.hh"
+#include "BKE_instances.hh"
#include "BKE_vfont.h"
#include "BLI_hash.h"
@@ -76,7 +77,7 @@ static void node_layout(uiLayout *layout, struct bContext *C, PointerRNA *ptr)
uiItemR(layout, ptr, "pivot_mode", 0, IFACE_("Pivot Point"), ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryStringToCurves *data = MEM_cnew<NodeGeometryStringToCurves>(__func__);
@@ -85,7 +86,7 @@ static void node_init(bNodeTree *UNUSED(ntree), bNode *node)
data->align_y = GEO_NODE_STRING_TO_CURVES_ALIGN_Y_TOP_BASELINE;
data->pivot_mode = GEO_NODE_STRING_TO_CURVES_PIVOT_MODE_BOTTOM_LEFT;
node->storage = data;
- node->id = (ID *)BKE_vfont_builtin_get();
+ node->id = reinterpret_cast<ID *>(BKE_vfont_builtin_get());
}
static void node_update(bNodeTree *ntree, bNode *node)
@@ -93,11 +94,11 @@ static void node_update(bNodeTree *ntree, bNode *node)
const NodeGeometryStringToCurves &storage = node_storage(*node);
const GeometryNodeStringToCurvesOverflowMode overflow = (GeometryNodeStringToCurvesOverflowMode)
storage.overflow;
- bNodeSocket *socket_remainder = ((bNodeSocket *)node->outputs.first)->next;
+ bNodeSocket *socket_remainder = static_cast<bNodeSocket *>(node->outputs.first)->next;
nodeSetSocketAvailability(
ntree, socket_remainder, overflow == GEO_NODE_STRING_TO_CURVES_MODE_TRUNCATE);
- bNodeSocket *height_socket = (bNodeSocket *)node->inputs.last;
+ bNodeSocket *height_socket = static_cast<bNodeSocket *>(node->inputs.last);
nodeSetSocketAvailability(
ntree, height_socket, overflow != GEO_NODE_STRING_TO_CURVES_MODE_OVERFLOW);
}
@@ -203,7 +204,7 @@ static std::optional<TextLayout> get_text_layout(GeoNodeExecParams &params)
cu.linedist = line_spacing;
cu.vfont = vfont;
cu.overflow = overflow;
- cu.tb = (TextBox *)MEM_calloc_arrayN(MAXTEXTBOX, sizeof(TextBox), __func__);
+ cu.tb = static_cast<TextBox *>(MEM_calloc_arrayN(MAXTEXTBOX, sizeof(TextBox), __func__));
cu.tb->w = textbox_w;
cu.tb->h = textbox_h;
cu.totbox = 1;
@@ -213,8 +214,8 @@ static std::optional<TextLayout> get_text_layout(GeoNodeExecParams &params)
cu.len = len_bytes;
cu.pos = len_chars;
/* The reason for the additional character here is unknown, but reflects other code elsewhere. */
- cu.str = (char *)MEM_mallocN(len_bytes + sizeof(char32_t), __func__);
- cu.strinfo = (CharInfo *)MEM_callocN((len_chars + 1) * sizeof(CharInfo), __func__);
+ cu.str = static_cast<char *>(MEM_mallocN(len_bytes + sizeof(char32_t), __func__));
+ cu.strinfo = static_cast<CharInfo *>(MEM_callocN((len_chars + 1) * sizeof(CharInfo), __func__));
BLI_strncpy(cu.str, layout.text.c_str(), len_bytes + 1);
struct CharTrans *chartransdata = nullptr;
@@ -226,7 +227,7 @@ static std::optional<TextLayout> get_text_layout(GeoNodeExecParams &params)
nullptr, &cu, FO_DUPLI, nullptr, &r_text, &text_len, &text_free, &chartransdata);
if (text_free) {
- MEM_freeN((void *)r_text);
+ MEM_freeN(const_cast<char32_t *>(r_text));
}
Span<CharInfo> info{cu.strinfo, text_len};
@@ -270,9 +271,9 @@ static std::optional<TextLayout> get_text_layout(GeoNodeExecParams &params)
/* Returns a mapping of UTF-32 character code to instance handle. */
static Map<int, int> create_curve_instances(GeoNodeExecParams &params,
TextLayout &layout,
- InstancesComponent &instances)
+ bke::Instances &instances)
{
- VFont *vfont = (VFont *)params.node().id;
+ VFont *vfont = reinterpret_cast<VFont *>(params.node().id);
Map<int, int> handles;
bool pivot_required = params.output_is_required("Pivot Point");
@@ -315,13 +316,13 @@ static Map<int, int> create_curve_instances(GeoNodeExecParams &params,
return handles;
}
-static void add_instances_from_handles(InstancesComponent &instances,
+static void add_instances_from_handles(bke::Instances &instances,
const Map<int, int> &char_handles,
const TextLayout &layout)
{
instances.resize(layout.positions.size());
- MutableSpan<int> handles = instances.instance_reference_handles();
- MutableSpan<float4x4> transforms = instances.instance_transforms();
+ MutableSpan<int> handles = instances.reference_handles();
+ MutableSpan<float4x4> transforms = instances.transforms();
threading::parallel_for(IndexRange(layout.positions.size()), 256, [&](IndexRange range) {
for (const int i : range) {
@@ -333,9 +334,9 @@ static void add_instances_from_handles(InstancesComponent &instances,
static void create_attributes(GeoNodeExecParams &params,
const TextLayout &layout,
- InstancesComponent &instances)
+ bke::Instances &instances)
{
- MutableAttributeAccessor attributes = *instances.attributes_for_write();
+ MutableAttributeAccessor attributes = instances.attributes_for_write();
if (params.output_is_required("Line")) {
StrongAnonymousAttributeID line_id = StrongAnonymousAttributeID("Line");
@@ -385,13 +386,12 @@ static void node_geo_exec(GeoNodeExecParams params)
}
/* Create and add instances. */
- GeometrySet geometry_set_out;
- InstancesComponent &instances = geometry_set_out.get_component_for_write<InstancesComponent>();
- Map<int, int> char_handles = create_curve_instances(params, *layout, instances);
- add_instances_from_handles(instances, char_handles, *layout);
- create_attributes(params, *layout, instances);
+ std::unique_ptr<bke::Instances> instances = std::make_unique<bke::Instances>();
+ Map<int, int> char_handles = create_curve_instances(params, *layout, *instances);
+ add_instances_from_handles(*instances, char_handles, *layout);
+ create_attributes(params, *layout, *instances);
- params.set_output("Curve Instances", std::move(geometry_set_out));
+ params.set_output("Curve Instances", GeometrySet::create_with_instances(instances.release()));
}
} // namespace blender::nodes::node_geo_string_to_curves_cc
diff --git a/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc b/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc
index eda6a51d412..2e6ad02bfd5 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc
@@ -39,13 +39,13 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Mesh"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "uv_smooth", 0, "", ICON_NONE);
uiItemR(layout, ptr, "boundary_smooth", 0, "", ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometrySubdivisionSurface *data = MEM_cnew<NodeGeometrySubdivisionSurface>(__func__);
data->uv_smooth = SUBSURF_UV_SMOOTH_PRESERVE_BOUNDARIES;
@@ -73,7 +73,7 @@ static void write_vertex_creases(Mesh &mesh, const VArray<float> &crease_varray)
}
else {
crease = static_cast<float *>(
- CustomData_add_layer(&mesh.vdata, CD_CREASE, CD_DEFAULT, nullptr, mesh.totvert));
+ CustomData_add_layer(&mesh.vdata, CD_CREASE, CD_CONSTRUCT, nullptr, mesh.totvert));
}
materialize_and_clamp_creases(crease_varray, {crease, mesh.totvert});
}
@@ -119,21 +119,19 @@ static void node_geo_exec(GeoNodeExecParams params)
return;
}
- const MeshComponent &mesh_component = *geometry_set.get_component_for_read<MeshComponent>();
- const int verts_num = mesh_component.attribute_domain_size(ATTR_DOMAIN_POINT);
- const int edges_num = mesh_component.attribute_domain_size(ATTR_DOMAIN_EDGE);
- if (verts_num == 0 || edges_num == 0) {
+ const Mesh &mesh = *geometry_set.get_mesh_for_read();
+ if (mesh.totvert == 0 || mesh.totedge == 0) {
return;
}
- GeometryComponentFieldContext point_context{mesh_component, ATTR_DOMAIN_POINT};
- FieldEvaluator point_evaluator(point_context, verts_num);
+ bke::MeshFieldContext point_context{mesh, ATTR_DOMAIN_POINT};
+ FieldEvaluator point_evaluator(point_context, mesh.totvert);
point_evaluator.add(vertex_crease_field);
point_evaluator.evaluate();
const VArray<float> vertex_creases = point_evaluator.get_evaluated<float>(0);
- GeometryComponentFieldContext edge_context{mesh_component, ATTR_DOMAIN_EDGE};
- FieldEvaluator edge_evaluator(edge_context, edges_num);
+ bke::MeshFieldContext edge_context{mesh, ATTR_DOMAIN_EDGE};
+ FieldEvaluator edge_evaluator(edge_context, mesh.totedge);
edge_evaluator.add(edge_crease_field);
edge_evaluator.evaluate();
const VArray<float> edge_creases = edge_evaluator.get_evaluated<float>(0);
@@ -162,17 +160,15 @@ static void node_geo_exec(GeoNodeExecParams params)
subdiv_settings.fvar_linear_interpolation = BKE_subdiv_fvar_interpolation_from_uv_smooth(
uv_smooth);
- const Mesh &mesh_in = *geometry_set.get_mesh_for_read();
-
/* Apply subdivision to mesh. */
- Subdiv *subdiv = BKE_subdiv_update_from_mesh(nullptr, &subdiv_settings, &mesh_in);
+ Subdiv *subdiv = BKE_subdiv_update_from_mesh(nullptr, &subdiv_settings, &mesh);
/* In case of bad topology, skip to input mesh. */
if (subdiv == nullptr) {
return;
}
- Mesh *mesh_out = BKE_subdiv_to_mesh(subdiv, &mesh_settings, &mesh_in);
+ Mesh *mesh_out = BKE_subdiv_to_mesh(subdiv, &mesh_settings, &mesh);
geometry_set.replace_mesh(mesh_out);
diff --git a/source/blender/nodes/geometry/nodes/node_geo_switch.cc b/source/blender/nodes/geometry/nodes/node_geo_switch.cc
index ddc87e3dac4..36be68f1a22 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_switch.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_switch.cc
@@ -73,12 +73,12 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Image>(N_("Output"), "Output_011");
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "input_type", 0, "", ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeSwitch *data = MEM_cnew<NodeSwitch>(__func__);
data->input_type = SOCK_GEOMETRY;
@@ -89,8 +89,8 @@ static void node_update(bNodeTree *ntree, bNode *node)
{
const NodeSwitch &storage = node_storage(*node);
int index = 0;
- bNodeSocket *field_switch = (bNodeSocket *)node->inputs.first;
- bNodeSocket *non_field_switch = (bNodeSocket *)field_switch->next;
+ bNodeSocket *field_switch = static_cast<bNodeSocket *>(node->inputs.first);
+ bNodeSocket *non_field_switch = static_cast<bNodeSocket *>(field_switch->next);
const bool fields_type = ELEM(
storage.input_type, SOCK_FLOAT, SOCK_INT, SOCK_BOOLEAN, SOCK_VECTOR, SOCK_RGBA, SOCK_STRING);
@@ -222,7 +222,7 @@ template<typename T> void switch_no_fields(GeoNodeExecParams &params, const Stri
static void node_geo_exec(GeoNodeExecParams params)
{
const NodeSwitch &storage = node_storage(params.node());
- const eNodeSocketDatatype data_type = static_cast<eNodeSocketDatatype>(storage.input_type);
+ const eNodeSocketDatatype data_type = eNodeSocketDatatype(storage.input_type);
switch (data_type) {
diff --git a/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc b/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc
deleted file mode 100644
index cd75822f665..00000000000
--- a/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc
+++ /dev/null
@@ -1,826 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-
-#include "BLI_generic_array.hh"
-#include "BLI_kdopbvh.h"
-#include "BLI_task.hh"
-
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_pointcloud_types.h"
-
-#include "BKE_attribute_math.hh"
-#include "BKE_bvhutils.h"
-#include "BKE_mesh_runtime.h"
-#include "BKE_mesh_sample.hh"
-
-#include "UI_interface.h"
-#include "UI_resources.h"
-
-#include "NOD_socket_search_link.hh"
-
-#include "node_geometry_util.hh"
-
-namespace blender::nodes::node_geo_transfer_attribute_cc {
-
-using namespace blender::bke::mesh_surface_sample;
-
-NODE_STORAGE_FUNCS(NodeGeometryTransferAttribute)
-
-static void node_declare(NodeDeclarationBuilder &b)
-{
- b.add_input<decl::Geometry>(N_("Source"))
- .supported_type({GEO_COMPONENT_TYPE_MESH,
- GEO_COMPONENT_TYPE_POINT_CLOUD,
- GEO_COMPONENT_TYPE_CURVE,
- GEO_COMPONENT_TYPE_INSTANCES});
-
- b.add_input<decl::Vector>(N_("Attribute")).hide_value().supports_field();
- b.add_input<decl::Float>(N_("Attribute"), "Attribute_001").hide_value().supports_field();
- b.add_input<decl::Color>(N_("Attribute"), "Attribute_002").hide_value().supports_field();
- b.add_input<decl::Bool>(N_("Attribute"), "Attribute_003").hide_value().supports_field();
- b.add_input<decl::Int>(N_("Attribute"), "Attribute_004").hide_value().supports_field();
-
- b.add_input<decl::Vector>(N_("Source Position"))
- .implicit_field()
- .make_available([](bNode &node) {
- node_storage(node).mode = GEO_NODE_ATTRIBUTE_TRANSFER_NEAREST_FACE_INTERPOLATED;
- });
- b.add_input<decl::Int>(N_("Index")).implicit_field().make_available([](bNode &node) {
- node_storage(node).mode = GEO_NODE_ATTRIBUTE_TRANSFER_INDEX;
- });
-
- b.add_output<decl::Vector>(N_("Attribute")).dependent_field({6, 7});
- b.add_output<decl::Float>(N_("Attribute"), "Attribute_001").dependent_field({6, 7});
- b.add_output<decl::Color>(N_("Attribute"), "Attribute_002").dependent_field({6, 7});
- b.add_output<decl::Bool>(N_("Attribute"), "Attribute_003").dependent_field({6, 7});
- b.add_output<decl::Int>(N_("Attribute"), "Attribute_004").dependent_field({6, 7});
-}
-
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
-{
- const bNode &node = *static_cast<const bNode *>(ptr->data);
- const NodeGeometryTransferAttribute &storage = node_storage(node);
- const GeometryNodeAttributeTransferMode mapping = (GeometryNodeAttributeTransferMode)
- storage.mode;
-
- uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE);
- uiItemR(layout, ptr, "mapping", 0, "", ICON_NONE);
- if (mapping != GEO_NODE_ATTRIBUTE_TRANSFER_NEAREST_FACE_INTERPOLATED) {
- uiItemR(layout, ptr, "domain", 0, "", ICON_NONE);
- }
-}
-
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
-{
- NodeGeometryTransferAttribute *data = MEM_cnew<NodeGeometryTransferAttribute>(__func__);
- data->data_type = CD_PROP_FLOAT;
- data->mode = GEO_NODE_ATTRIBUTE_TRANSFER_NEAREST_FACE_INTERPOLATED;
- node->storage = data;
-}
-
-static void node_update(bNodeTree *ntree, bNode *node)
-{
- const NodeGeometryTransferAttribute &storage = node_storage(*node);
- const eCustomDataType data_type = static_cast<eCustomDataType>(storage.data_type);
- const GeometryNodeAttributeTransferMode mapping = (GeometryNodeAttributeTransferMode)
- storage.mode;
-
- bNodeSocket *socket_geometry = (bNodeSocket *)node->inputs.first;
- bNodeSocket *socket_vector = socket_geometry->next;
- bNodeSocket *socket_float = socket_vector->next;
- bNodeSocket *socket_color4f = socket_float->next;
- bNodeSocket *socket_boolean = socket_color4f->next;
- bNodeSocket *socket_int32 = socket_boolean->next;
-
- bNodeSocket *socket_positions = socket_int32->next;
- bNodeSocket *socket_indices = socket_positions->next;
-
- nodeSetSocketAvailability(ntree, socket_vector, data_type == CD_PROP_FLOAT3);
- nodeSetSocketAvailability(ntree, socket_float, data_type == CD_PROP_FLOAT);
- nodeSetSocketAvailability(ntree, socket_color4f, data_type == CD_PROP_COLOR);
- nodeSetSocketAvailability(ntree, socket_boolean, data_type == CD_PROP_BOOL);
- nodeSetSocketAvailability(ntree, socket_int32, data_type == CD_PROP_INT32);
-
- nodeSetSocketAvailability(ntree, socket_positions, mapping != GEO_NODE_ATTRIBUTE_TRANSFER_INDEX);
- nodeSetSocketAvailability(ntree, socket_indices, mapping == GEO_NODE_ATTRIBUTE_TRANSFER_INDEX);
-
- bNodeSocket *out_socket_vector = (bNodeSocket *)node->outputs.first;
- bNodeSocket *out_socket_float = out_socket_vector->next;
- bNodeSocket *out_socket_color4f = out_socket_float->next;
- bNodeSocket *out_socket_boolean = out_socket_color4f->next;
- bNodeSocket *out_socket_int32 = out_socket_boolean->next;
-
- nodeSetSocketAvailability(ntree, out_socket_vector, data_type == CD_PROP_FLOAT3);
- nodeSetSocketAvailability(ntree, out_socket_float, data_type == CD_PROP_FLOAT);
- nodeSetSocketAvailability(ntree, out_socket_color4f, data_type == CD_PROP_COLOR);
- nodeSetSocketAvailability(ntree, out_socket_boolean, data_type == CD_PROP_BOOL);
- nodeSetSocketAvailability(ntree, out_socket_int32, data_type == CD_PROP_INT32);
-}
-
-static void node_gather_link_searches(GatherLinkSearchOpParams &params)
-{
- const NodeDeclaration &declaration = *params.node_type().fixed_declaration;
- search_link_ops_for_declarations(params, declaration.inputs().take_back(2));
- search_link_ops_for_declarations(params, declaration.inputs().take_front(1));
-
- const std::optional<eCustomDataType> type = node_data_type_to_custom_data_type(
- (eNodeSocketDatatype)params.other_socket().type);
- if (type && *type != CD_PROP_STRING) {
- /* The input and output sockets have the same name. */
- params.add_item(IFACE_("Attribute"), [type](LinkSearchOpParams &params) {
- bNode &node = params.add_node("GeometryNodeAttributeTransfer");
- node_storage(node).data_type = *type;
- params.update_and_connect_available_socket(node, "Attribute");
- });
- }
-}
-
-static void get_closest_in_bvhtree(BVHTreeFromMesh &tree_data,
- const VArray<float3> &positions,
- const IndexMask mask,
- const MutableSpan<int> r_indices,
- const MutableSpan<float> r_distances_sq,
- const MutableSpan<float3> r_positions)
-{
- BLI_assert(positions.size() >= r_indices.size());
- BLI_assert(positions.size() >= r_distances_sq.size());
- BLI_assert(positions.size() >= r_positions.size());
-
- for (const int i : mask) {
- BVHTreeNearest nearest;
- nearest.dist_sq = FLT_MAX;
- const float3 position = positions[i];
- BLI_bvhtree_find_nearest(
- tree_data.tree, position, &nearest, tree_data.nearest_callback, &tree_data);
- if (!r_indices.is_empty()) {
- r_indices[i] = nearest.index;
- }
- if (!r_distances_sq.is_empty()) {
- r_distances_sq[i] = nearest.dist_sq;
- }
- if (!r_positions.is_empty()) {
- r_positions[i] = nearest.co;
- }
- }
-}
-
-static void get_closest_pointcloud_points(const PointCloud &pointcloud,
- const VArray<float3> &positions,
- const IndexMask mask,
- const MutableSpan<int> r_indices,
- const MutableSpan<float> r_distances_sq)
-{
- BLI_assert(positions.size() >= r_indices.size());
- BLI_assert(pointcloud.totpoint > 0);
-
- BVHTreeFromPointCloud tree_data;
- BKE_bvhtree_from_pointcloud_get(&tree_data, &pointcloud, 2);
-
- for (const int i : mask) {
- BVHTreeNearest nearest;
- nearest.dist_sq = FLT_MAX;
- const float3 position = positions[i];
- BLI_bvhtree_find_nearest(
- tree_data.tree, position, &nearest, tree_data.nearest_callback, &tree_data);
- r_indices[i] = nearest.index;
- if (!r_distances_sq.is_empty()) {
- r_distances_sq[i] = nearest.dist_sq;
- }
- }
-
- free_bvhtree_from_pointcloud(&tree_data);
-}
-
-static void get_closest_mesh_points(const Mesh &mesh,
- const VArray<float3> &positions,
- const IndexMask mask,
- const MutableSpan<int> r_point_indices,
- const MutableSpan<float> r_distances_sq,
- const MutableSpan<float3> r_positions)
-{
- BLI_assert(mesh.totvert > 0);
- BVHTreeFromMesh tree_data;
- BKE_bvhtree_from_mesh_get(&tree_data, &mesh, BVHTREE_FROM_VERTS, 2);
- get_closest_in_bvhtree(tree_data, positions, mask, r_point_indices, r_distances_sq, r_positions);
- free_bvhtree_from_mesh(&tree_data);
-}
-
-static void get_closest_mesh_edges(const Mesh &mesh,
- const VArray<float3> &positions,
- const IndexMask mask,
- const MutableSpan<int> r_edge_indices,
- const MutableSpan<float> r_distances_sq,
- const MutableSpan<float3> r_positions)
-{
- BLI_assert(mesh.totedge > 0);
- BVHTreeFromMesh tree_data;
- BKE_bvhtree_from_mesh_get(&tree_data, &mesh, BVHTREE_FROM_EDGES, 2);
- get_closest_in_bvhtree(tree_data, positions, mask, r_edge_indices, r_distances_sq, r_positions);
- free_bvhtree_from_mesh(&tree_data);
-}
-
-static void get_closest_mesh_looptris(const Mesh &mesh,
- const VArray<float3> &positions,
- const IndexMask mask,
- const MutableSpan<int> r_looptri_indices,
- const MutableSpan<float> r_distances_sq,
- const MutableSpan<float3> r_positions)
-{
- BLI_assert(mesh.totpoly > 0);
- BVHTreeFromMesh tree_data;
- BKE_bvhtree_from_mesh_get(&tree_data, &mesh, BVHTREE_FROM_LOOPTRI, 2);
- get_closest_in_bvhtree(
- tree_data, positions, mask, r_looptri_indices, r_distances_sq, r_positions);
- free_bvhtree_from_mesh(&tree_data);
-}
-
-static void get_closest_mesh_polygons(const Mesh &mesh,
- const VArray<float3> &positions,
- const IndexMask mask,
- const MutableSpan<int> r_poly_indices,
- const MutableSpan<float> r_distances_sq,
- const MutableSpan<float3> r_positions)
-{
- BLI_assert(mesh.totpoly > 0);
-
- Array<int> looptri_indices(positions.size());
- get_closest_mesh_looptris(mesh, positions, mask, looptri_indices, r_distances_sq, r_positions);
-
- const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
- BKE_mesh_runtime_looptri_len(&mesh)};
-
- for (const int i : mask) {
- const MLoopTri &looptri = looptris[looptri_indices[i]];
- r_poly_indices[i] = looptri.poly;
- }
-}
-
-/* The closest corner is defined to be the closest corner on the closest face. */
-static void get_closest_mesh_corners(const Mesh &mesh,
- const VArray<float3> &positions,
- const IndexMask mask,
- const MutableSpan<int> r_corner_indices,
- const MutableSpan<float> r_distances_sq,
- const MutableSpan<float3> r_positions)
-{
- BLI_assert(mesh.totloop > 0);
- Array<int> poly_indices(positions.size());
- get_closest_mesh_polygons(mesh, positions, mask, poly_indices, {}, {});
-
- for (const int i : mask) {
- const float3 position = positions[i];
- const int poly_index = poly_indices[i];
- const MPoly &poly = mesh.mpoly[poly_index];
-
- /* Find the closest vertex in the polygon. */
- float min_distance_sq = FLT_MAX;
- const MVert *closest_mvert;
- int closest_loop_index = 0;
- for (const int loop_index : IndexRange(poly.loopstart, poly.totloop)) {
- const MLoop &loop = mesh.mloop[loop_index];
- const int vertex_index = loop.v;
- const MVert &mvert = mesh.mvert[vertex_index];
- const float distance_sq = math::distance_squared(position, float3(mvert.co));
- if (distance_sq < min_distance_sq) {
- min_distance_sq = distance_sq;
- closest_loop_index = loop_index;
- closest_mvert = &mvert;
- }
- }
- if (!r_corner_indices.is_empty()) {
- r_corner_indices[i] = closest_loop_index;
- }
- if (!r_positions.is_empty()) {
- r_positions[i] = closest_mvert->co;
- }
- if (!r_distances_sq.is_empty()) {
- r_distances_sq[i] = min_distance_sq;
- }
- }
-}
-
-template<typename T>
-void copy_with_indices(const VArray<T> &src,
- const IndexMask mask,
- const Span<int> indices,
- const MutableSpan<T> dst)
-{
- if (src.is_empty()) {
- return;
- }
- for (const int i : mask) {
- dst[i] = src[indices[i]];
- }
-}
-
-template<typename T>
-void copy_with_indices_clamped(const VArray<T> &src,
- const IndexMask mask,
- const VArray<int> &indices,
- const MutableSpan<T> dst)
-{
- if (src.is_empty()) {
- return;
- }
- const int max_index = src.size() - 1;
- threading::parallel_for(mask.index_range(), 4096, [&](IndexRange range) {
- for (const int i : range) {
- const int index = mask[i];
- dst[index] = src[std::clamp(indices[index], 0, max_index)];
- }
- });
-}
-
-template<typename T>
-void copy_with_indices_and_comparison(const VArray<T> &src_1,
- const VArray<T> &src_2,
- const Span<float> distances_1,
- const Span<float> distances_2,
- const IndexMask mask,
- const Span<int> indices_1,
- const Span<int> indices_2,
- const MutableSpan<T> dst)
-{
- if (src_1.is_empty() || src_2.is_empty()) {
- return;
- }
- for (const int i : mask) {
- if (distances_1[i] < distances_2[i]) {
- dst[i] = src_1[indices_1[i]];
- }
- else {
- dst[i] = src_2[indices_2[i]];
- }
- }
-}
-
-static bool component_is_available(const GeometrySet &geometry,
- const GeometryComponentType type,
- const eAttrDomain domain)
-{
- if (!geometry.has(type)) {
- return false;
- }
- const GeometryComponent &component = *geometry.get_component_for_read(type);
- if (component.is_empty()) {
- return false;
- }
- return component.attribute_domain_size(domain) != 0;
-}
-
-/**
- * \note Multi-threading for this function is provided by the field evaluator. Since the #call
- * function could be called many times, calculate the data from the source geometry once and store
- * it for later.
- */
-class NearestInterpolatedTransferFunction : public fn::MultiFunction {
- GeometrySet source_;
- GField src_field_;
-
- /**
- * This function is meant to sample the surface of a mesh rather than take the value from
- * individual elements, so use the most complex domain, ensuring no information is lost. In the
- * future, it should be possible to use the most complex domain required by the field inputs, to
- * simplify sampling and avoid domain conversions.
- */
- eAttrDomain domain_ = ATTR_DOMAIN_CORNER;
-
- fn::MFSignature signature_;
-
- std::optional<GeometryComponentFieldContext> source_context_;
- std::unique_ptr<FieldEvaluator> source_evaluator_;
- const GVArray *source_data_;
-
- public:
- NearestInterpolatedTransferFunction(GeometrySet geometry, GField src_field)
- : source_(std::move(geometry)), src_field_(std::move(src_field))
- {
- source_.ensure_owns_direct_data();
- signature_ = this->create_signature();
- this->set_signature(&signature_);
- this->evaluate_source_field();
- }
-
- fn::MFSignature create_signature()
- {
- blender::fn::MFSignatureBuilder signature{"Attribute Transfer Nearest Interpolated"};
- signature.single_input<float3>("Position");
- signature.single_output("Attribute", src_field_.cpp_type());
- return signature.build();
- }
-
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
- {
- const VArray<float3> &positions = params.readonly_single_input<float3>(0, "Position");
- GMutableSpan dst = params.uninitialized_single_output_if_required(1, "Attribute");
-
- const MeshComponent &mesh_component = *source_.get_component_for_read<MeshComponent>();
- BLI_assert(mesh_component.has_mesh());
- const Mesh &mesh = *mesh_component.get_for_read();
- BLI_assert(mesh.totpoly > 0);
-
- /* Find closest points on the mesh surface. */
- Array<int> looptri_indices(mask.min_array_size());
- Array<float3> sampled_positions(mask.min_array_size());
- get_closest_mesh_looptris(mesh, positions, mask, looptri_indices, {}, sampled_positions);
-
- MeshAttributeInterpolator interp(&mesh, mask, sampled_positions, looptri_indices);
- interp.sample_data(*source_data_, domain_, eAttributeMapMode::INTERPOLATED, dst);
- }
-
- private:
- void evaluate_source_field()
- {
- const MeshComponent &mesh_component = *source_.get_component_for_read<MeshComponent>();
- source_context_.emplace(GeometryComponentFieldContext{mesh_component, domain_});
- const int domain_num = mesh_component.attribute_domain_size(domain_);
- source_evaluator_ = std::make_unique<FieldEvaluator>(*source_context_, domain_num);
- source_evaluator_->add(src_field_);
- source_evaluator_->evaluate();
- source_data_ = &source_evaluator_->get_evaluated(0);
- }
-};
-
-/**
- * \note Multi-threading for this function is provided by the field evaluator. Since the #call
- * function could be called many times, calculate the data from the source geometry once and store
- * it for later.
- */
-class NearestTransferFunction : public fn::MultiFunction {
- GeometrySet source_;
- GField src_field_;
- eAttrDomain domain_;
-
- fn::MFSignature signature_;
-
- bool use_mesh_;
- bool use_points_;
-
- /* Store data from the source as a virtual array, since we may only access a few indices. */
- std::optional<GeometryComponentFieldContext> mesh_context_;
- std::unique_ptr<FieldEvaluator> mesh_evaluator_;
- const GVArray *mesh_data_;
-
- std::optional<GeometryComponentFieldContext> point_context_;
- std::unique_ptr<FieldEvaluator> point_evaluator_;
- const GVArray *point_data_;
-
- public:
- NearestTransferFunction(GeometrySet geometry, GField src_field, eAttrDomain domain)
- : source_(std::move(geometry)), src_field_(std::move(src_field)), domain_(domain)
- {
- source_.ensure_owns_direct_data();
- signature_ = this->create_signature();
- this->set_signature(&signature_);
-
- this->use_mesh_ = component_is_available(source_, GEO_COMPONENT_TYPE_MESH, domain_);
- this->use_points_ = component_is_available(source_, GEO_COMPONENT_TYPE_POINT_CLOUD, domain_);
-
- this->evaluate_source_field();
- }
-
- fn::MFSignature create_signature()
- {
- blender::fn::MFSignatureBuilder signature{"Attribute Transfer Nearest"};
- signature.single_input<float3>("Position");
- signature.single_output("Attribute", src_field_.cpp_type());
- return signature.build();
- }
-
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
- {
- const VArray<float3> &positions = params.readonly_single_input<float3>(0, "Position");
- GMutableSpan dst = params.uninitialized_single_output_if_required(1, "Attribute");
-
- if (!use_mesh_ && !use_points_) {
- dst.type().value_initialize_indices(dst.data(), mask);
- return;
- }
-
- const Mesh *mesh = use_mesh_ ? source_.get_mesh_for_read() : nullptr;
- const PointCloud *pointcloud = use_points_ ? source_.get_pointcloud_for_read() : nullptr;
-
- const int tot_samples = mask.min_array_size();
-
- Array<int> point_indices;
- Array<float> point_distances;
-
- /* Depending on where what domain the source attribute lives, these indices are either vertex,
- * corner, edge or polygon indices. */
- Array<int> mesh_indices;
- Array<float> mesh_distances;
-
- /* If there is a point cloud, find the closest points. */
- if (use_points_) {
- point_indices.reinitialize(tot_samples);
- if (use_mesh_) {
- point_distances.reinitialize(tot_samples);
- }
- get_closest_pointcloud_points(*pointcloud, positions, mask, point_indices, point_distances);
- }
-
- /* If there is a mesh, find the closest mesh elements. */
- if (use_mesh_) {
- mesh_indices.reinitialize(tot_samples);
- if (use_points_) {
- mesh_distances.reinitialize(tot_samples);
- }
- switch (domain_) {
- case ATTR_DOMAIN_POINT: {
- get_closest_mesh_points(*mesh, positions, mask, mesh_indices, mesh_distances, {});
- break;
- }
- case ATTR_DOMAIN_EDGE: {
- get_closest_mesh_edges(*mesh, positions, mask, mesh_indices, mesh_distances, {});
- break;
- }
- case ATTR_DOMAIN_FACE: {
- get_closest_mesh_polygons(*mesh, positions, mask, mesh_indices, mesh_distances, {});
- break;
- }
- case ATTR_DOMAIN_CORNER: {
- get_closest_mesh_corners(*mesh, positions, mask, mesh_indices, mesh_distances, {});
- break;
- }
- default: {
- break;
- }
- }
- }
-
- attribute_math::convert_to_static_type(dst.type(), [&](auto dummy) {
- using T = decltype(dummy);
- if (use_mesh_ && use_points_) {
- VArray<T> src_mesh = mesh_data_->typed<T>();
- VArray<T> src_point = point_data_->typed<T>();
- copy_with_indices_and_comparison(src_mesh,
- src_point,
- mesh_distances,
- point_distances,
- mask,
- mesh_indices,
- point_indices,
- dst.typed<T>());
- }
- else if (use_points_) {
- VArray<T> src_point = point_data_->typed<T>();
- copy_with_indices(src_point, mask, point_indices, dst.typed<T>());
- }
- else if (use_mesh_) {
- VArray<T> src_mesh = mesh_data_->typed<T>();
- copy_with_indices(src_mesh, mask, mesh_indices, dst.typed<T>());
- }
- });
- }
-
- private:
- void evaluate_source_field()
- {
- if (use_mesh_) {
- const MeshComponent &mesh = *source_.get_component_for_read<MeshComponent>();
- const int domain_num = mesh.attribute_domain_size(domain_);
- mesh_context_.emplace(GeometryComponentFieldContext(mesh, domain_));
- mesh_evaluator_ = std::make_unique<FieldEvaluator>(*mesh_context_, domain_num);
- mesh_evaluator_->add(src_field_);
- mesh_evaluator_->evaluate();
- mesh_data_ = &mesh_evaluator_->get_evaluated(0);
- }
-
- if (use_points_) {
- const PointCloudComponent &points = *source_.get_component_for_read<PointCloudComponent>();
- const int domain_num = points.attribute_domain_size(domain_);
- point_context_.emplace(GeometryComponentFieldContext(points, domain_));
- point_evaluator_ = std::make_unique<FieldEvaluator>(*point_context_, domain_num);
- point_evaluator_->add(src_field_);
- point_evaluator_->evaluate();
- point_data_ = &point_evaluator_->get_evaluated(0);
- }
- }
-};
-
-static const GeometryComponent *find_source_component(const GeometrySet &geometry,
- const eAttrDomain domain)
-{
- /* Choose the other component based on a consistent order, rather than some more complicated
- * heuristic. This is the same order visible in the spreadsheet and used in the ray-cast node. */
- static const Array<GeometryComponentType> supported_types = {GEO_COMPONENT_TYPE_MESH,
- GEO_COMPONENT_TYPE_POINT_CLOUD,
- GEO_COMPONENT_TYPE_CURVE,
- GEO_COMPONENT_TYPE_INSTANCES};
- for (const GeometryComponentType src_type : supported_types) {
- if (component_is_available(geometry, src_type, domain)) {
- return geometry.get_component_for_read(src_type);
- }
- }
-
- return nullptr;
-}
-
-/**
- * The index-based transfer theoretically does not need realized data when there is only one
- * instance geometry set in the source. A future optimization could be removing that limitation
- * internally.
- */
-class IndexTransferFunction : public fn::MultiFunction {
- GeometrySet src_geometry_;
- GField src_field_;
- eAttrDomain domain_;
-
- fn::MFSignature signature_;
-
- std::optional<GeometryComponentFieldContext> geometry_context_;
- std::unique_ptr<FieldEvaluator> evaluator_;
- const GVArray *src_data_ = nullptr;
-
- public:
- IndexTransferFunction(GeometrySet geometry, GField src_field, const eAttrDomain domain)
- : src_geometry_(std::move(geometry)), src_field_(std::move(src_field)), domain_(domain)
- {
- src_geometry_.ensure_owns_direct_data();
-
- signature_ = this->create_signature();
- this->set_signature(&signature_);
-
- this->evaluate_field();
- }
-
- fn::MFSignature create_signature()
- {
- fn::MFSignatureBuilder signature{"Attribute Transfer Index"};
- signature.single_input<int>("Index");
- signature.single_output("Attribute", src_field_.cpp_type());
- return signature.build();
- }
-
- void evaluate_field()
- {
- const GeometryComponent *component = find_source_component(src_geometry_, domain_);
- if (component == nullptr) {
- return;
- }
- const int domain_num = component->attribute_domain_size(domain_);
- geometry_context_.emplace(GeometryComponentFieldContext(*component, domain_));
- evaluator_ = std::make_unique<FieldEvaluator>(*geometry_context_, domain_num);
- evaluator_->add(src_field_);
- evaluator_->evaluate();
- src_data_ = &evaluator_->get_evaluated(0);
- }
-
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
- {
- const VArray<int> &indices = params.readonly_single_input<int>(0, "Index");
- GMutableSpan dst = params.uninitialized_single_output(1, "Attribute");
-
- const CPPType &type = dst.type();
- if (src_data_ == nullptr) {
- type.value_initialize_indices(dst.data(), mask);
- return;
- }
-
- attribute_math::convert_to_static_type(type, [&](auto dummy) {
- using T = decltype(dummy);
- copy_with_indices_clamped(src_data_->typed<T>(), mask, indices, dst.typed<T>());
- });
- }
-};
-
-static GField get_input_attribute_field(GeoNodeExecParams &params, const eCustomDataType data_type)
-{
- switch (data_type) {
- case CD_PROP_FLOAT:
- return params.extract_input<Field<float>>("Attribute_001");
- case CD_PROP_FLOAT3:
- return params.extract_input<Field<float3>>("Attribute");
- case CD_PROP_COLOR:
- return params.extract_input<Field<ColorGeometry4f>>("Attribute_002");
- case CD_PROP_BOOL:
- return params.extract_input<Field<bool>>("Attribute_003");
- case CD_PROP_INT32:
- return params.extract_input<Field<int>>("Attribute_004");
- default:
- BLI_assert_unreachable();
- }
- return {};
-}
-
-static void output_attribute_field(GeoNodeExecParams &params, GField field)
-{
- switch (bke::cpp_type_to_custom_data_type(field.cpp_type())) {
- case CD_PROP_FLOAT: {
- params.set_output("Attribute_001", Field<float>(field));
- break;
- }
- case CD_PROP_FLOAT3: {
- params.set_output("Attribute", Field<float3>(field));
- break;
- }
- case CD_PROP_COLOR: {
- params.set_output("Attribute_002", Field<ColorGeometry4f>(field));
- break;
- }
- case CD_PROP_BOOL: {
- params.set_output("Attribute_003", Field<bool>(field));
- break;
- }
- case CD_PROP_INT32: {
- params.set_output("Attribute_004", Field<int>(field));
- break;
- }
- default:
- break;
- }
-}
-
-static void node_geo_exec(GeoNodeExecParams params)
-{
- GeometrySet geometry = params.extract_input<GeometrySet>("Source");
- const NodeGeometryTransferAttribute &storage = node_storage(params.node());
- const GeometryNodeAttributeTransferMode mapping = (GeometryNodeAttributeTransferMode)
- storage.mode;
- const eCustomDataType data_type = static_cast<eCustomDataType>(storage.data_type);
- const eAttrDomain domain = static_cast<eAttrDomain>(storage.domain);
-
- GField field = get_input_attribute_field(params, data_type);
-
- auto return_default = [&]() {
- attribute_math::convert_to_static_type(data_type, [&](auto dummy) {
- using T = decltype(dummy);
- output_attribute_field(params, fn::make_constant_field<T>(T()));
- });
- };
-
- GField output_field;
- switch (mapping) {
- case GEO_NODE_ATTRIBUTE_TRANSFER_NEAREST_FACE_INTERPOLATED: {
- const Mesh *mesh = geometry.get_mesh_for_read();
- if (mesh == nullptr) {
- if (!geometry.is_empty()) {
- params.error_message_add(NodeWarningType::Error,
- TIP_("The source geometry must contain a mesh"));
- }
- return return_default();
- }
- if (mesh->totpoly == 0) {
- /* Don't add a warning for empty meshes. */
- if (mesh->totvert != 0) {
- params.error_message_add(NodeWarningType::Error,
- TIP_("The source mesh must have faces"));
- }
- return return_default();
- }
- auto fn = std::make_unique<NearestInterpolatedTransferFunction>(std::move(geometry),
- std::move(field));
- auto op = std::make_shared<FieldOperation>(
- FieldOperation(std::move(fn), {params.extract_input<Field<float3>>("Source Position")}));
- output_field = GField(std::move(op));
- break;
- }
- case GEO_NODE_ATTRIBUTE_TRANSFER_NEAREST: {
- if (geometry.has_curves() && !geometry.has_mesh() && !geometry.has_pointcloud()) {
- params.error_message_add(NodeWarningType::Error,
- TIP_("The source geometry must contain a mesh or a point cloud"));
- return return_default();
- }
- auto fn = std::make_unique<NearestTransferFunction>(
- std::move(geometry), std::move(field), domain);
- auto op = std::make_shared<FieldOperation>(
- FieldOperation(std::move(fn), {params.extract_input<Field<float3>>("Source Position")}));
- output_field = GField(std::move(op));
- break;
- }
- case GEO_NODE_ATTRIBUTE_TRANSFER_INDEX: {
- Field<int> indices = params.extract_input<Field<int>>("Index");
- auto fn = std::make_unique<IndexTransferFunction>(
- std::move(geometry), std::move(field), domain);
- auto op = std::make_shared<FieldOperation>(
- FieldOperation(std::move(fn), {std::move(indices)}));
- output_field = GField(std::move(op));
- break;
- }
- }
-
- output_attribute_field(params, std::move(output_field));
-}
-
-} // namespace blender::nodes::node_geo_transfer_attribute_cc
-
-void register_node_type_geo_transfer_attribute()
-{
- namespace file_ns = blender::nodes::node_geo_transfer_attribute_cc;
-
- static bNodeType ntype;
-
- geo_node_type_base(
- &ntype, GEO_NODE_TRANSFER_ATTRIBUTE, "Transfer Attribute", NODE_CLASS_ATTRIBUTE);
- node_type_init(&ntype, file_ns::node_init);
- node_type_update(&ntype, file_ns::node_update);
- node_type_storage(&ntype,
- "NodeGeometryTransferAttribute",
- node_free_standard_storage,
- node_copy_standard_storage);
- ntype.declare = file_ns::node_declare;
- ntype.geometry_node_execute = file_ns::node_geo_exec;
- ntype.draw_buttons = file_ns::node_layout;
- ntype.gather_link_search_ops = file_ns::node_gather_link_searches;
- nodeRegisterType(&ntype);
-}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_transform.cc b/source/blender/nodes/geometry/nodes/node_geo_transform.cc
index 945d5fbdcac..3c8a3f3ca76 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_transform.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_transform.cc
@@ -11,6 +11,7 @@
#include "DNA_volume_types.h"
#include "BKE_curves.hh"
+#include "BKE_instances.hh"
#include "BKE_mesh.h"
#include "BKE_pointcloud.h"
#include "BKE_volume.h"
@@ -47,7 +48,7 @@ static void transform_mesh(Mesh &mesh, const float4x4 &transform)
static void translate_pointcloud(PointCloud &pointcloud, const float3 translation)
{
- MutableAttributeAccessor attributes = bke::pointcloud_attributes_for_write(pointcloud);
+ MutableAttributeAccessor attributes = pointcloud.attributes_for_write();
SpanAttributeWriter position = attributes.lookup_or_add_for_write_span<float3>(
"position", ATTR_DOMAIN_POINT);
for (const int i : position.span.index_range()) {
@@ -58,7 +59,7 @@ static void translate_pointcloud(PointCloud &pointcloud, const float3 translatio
static void transform_pointcloud(PointCloud &pointcloud, const float4x4 &transform)
{
- MutableAttributeAccessor attributes = bke::pointcloud_attributes_for_write(pointcloud);
+ MutableAttributeAccessor attributes = pointcloud.attributes_for_write();
SpanAttributeWriter position = attributes.lookup_or_add_for_write_span<float3>(
"position", ATTR_DOMAIN_POINT);
for (const int i : position.span.index_range()) {
@@ -67,60 +68,77 @@ static void transform_pointcloud(PointCloud &pointcloud, const float4x4 &transfo
position.finish();
}
-static void translate_instances(InstancesComponent &instances, const float3 translation)
+static void translate_instances(bke::Instances &instances, const float3 translation)
{
- MutableSpan<float4x4> transforms = instances.instance_transforms();
+ MutableSpan<float4x4> transforms = instances.transforms();
for (float4x4 &transform : transforms) {
add_v3_v3(transform.ptr()[3], translation);
}
}
-static void transform_instances(InstancesComponent &instances, const float4x4 &transform)
+static void transform_instances(bke::Instances &instances, const float4x4 &transform)
{
- MutableSpan<float4x4> instance_transforms = instances.instance_transforms();
- for (float4x4 &instance_transform : instance_transforms) {
+ MutableSpan<float4x4> transforms = instances.transforms();
+ for (float4x4 &instance_transform : transforms) {
instance_transform = transform * instance_transform;
}
}
-static void transform_volume(Volume &volume, const float4x4 &transform, const Depsgraph &depsgraph)
+static void transform_volume(GeoNodeExecParams &params,
+ Volume &volume,
+ const float4x4 &transform,
+ const Depsgraph &depsgraph)
{
#ifdef WITH_OPENVDB
- /* Scaling an axis to zero is not supported for volumes. */
- const float3 translation = transform.translation();
- const float3 rotation = transform.to_euler();
- const float3 scale = transform.scale();
- const float3 limited_scale = {
- (scale.x == 0.0f) ? FLT_EPSILON : scale.x,
- (scale.y == 0.0f) ? FLT_EPSILON : scale.y,
- (scale.z == 0.0f) ? FLT_EPSILON : scale.z,
- };
- const float4x4 scale_limited_transform = float4x4::from_loc_eul_scale(
- translation, rotation, limited_scale);
-
const Main *bmain = DEG_get_bmain(&depsgraph);
BKE_volume_load(&volume, bmain);
openvdb::Mat4s vdb_matrix;
- memcpy(vdb_matrix.asPointer(), &scale_limited_transform, sizeof(float[4][4]));
+ memcpy(vdb_matrix.asPointer(), &transform, sizeof(float[4][4]));
openvdb::Mat4d vdb_matrix_d{vdb_matrix};
+ bool found_too_small_scale = false;
const int grids_num = BKE_volume_num_grids(&volume);
for (const int i : IndexRange(grids_num)) {
VolumeGrid *volume_grid = BKE_volume_grid_get_for_write(&volume, i);
-
- openvdb::GridBase::Ptr grid = BKE_volume_grid_openvdb_for_write(&volume, volume_grid, false);
- openvdb::math::Transform &grid_transform = grid->transform();
- grid_transform.postMult(vdb_matrix_d);
+ float4x4 grid_matrix;
+ BKE_volume_grid_transform_matrix(volume_grid, grid_matrix.values);
+ mul_m4_m4_pre(grid_matrix.values, transform.values);
+ const float determinant = determinant_m4(grid_matrix.values);
+ if (!BKE_volume_grid_determinant_valid(determinant)) {
+ found_too_small_scale = true;
+ /* Clear the tree because it is too small. */
+ BKE_volume_grid_clear_tree(volume, *volume_grid);
+ if (determinant == 0) {
+ /* Reset rotation and scale. */
+ copy_v3_fl3(grid_matrix.values[0], 1, 0, 0);
+ copy_v3_fl3(grid_matrix.values[1], 0, 1, 0);
+ copy_v3_fl3(grid_matrix.values[2], 0, 0, 1);
+ }
+ else {
+ /* Keep rotation but reset scale. */
+ normalize_v3(grid_matrix.values[0]);
+ normalize_v3(grid_matrix.values[1]);
+ normalize_v3(grid_matrix.values[2]);
+ }
+ }
+ BKE_volume_grid_transform_matrix_set(volume_grid, grid_matrix.values);
+ }
+ if (found_too_small_scale) {
+ params.error_message_add(NodeWarningType::Warning,
+ TIP_("Volume scale is lower than permitted by OpenVDB"));
}
#else
- UNUSED_VARS(volume, transform, depsgraph);
+ UNUSED_VARS(params, volume, transform, depsgraph);
#endif
}
-static void translate_volume(Volume &volume, const float3 translation, const Depsgraph &depsgraph)
+static void translate_volume(GeoNodeExecParams &params,
+ Volume &volume,
+ const float3 translation,
+ const Depsgraph &depsgraph)
{
- transform_volume(volume, float4x4::from_location(translation), depsgraph);
+ transform_volume(params, volume, float4x4::from_location(translation), depsgraph);
}
static void transform_curve_edit_hints(bke::CurvesEditHints &edit_hints, const float4x4 &transform)
@@ -151,7 +169,8 @@ static void translate_curve_edit_hints(bke::CurvesEditHints &edit_hints, const f
}
}
-static void translate_geometry_set(GeometrySet &geometry,
+static void translate_geometry_set(GeoNodeExecParams &params,
+ GeometrySet &geometry,
const float3 translation,
const Depsgraph &depsgraph)
{
@@ -165,17 +184,18 @@ static void translate_geometry_set(GeometrySet &geometry,
translate_pointcloud(*pointcloud, translation);
}
if (Volume *volume = geometry.get_volume_for_write()) {
- translate_volume(*volume, translation, depsgraph);
+ translate_volume(params, *volume, translation, depsgraph);
}
- if (geometry.has_instances()) {
- translate_instances(geometry.get_component_for_write<InstancesComponent>(), translation);
+ if (bke::Instances *instances = geometry.get_instances_for_write()) {
+ translate_instances(*instances, translation);
}
if (bke::CurvesEditHints *curve_edit_hints = geometry.get_curve_edit_hints_for_write()) {
translate_curve_edit_hints(*curve_edit_hints, translation);
}
}
-void transform_geometry_set(GeometrySet &geometry,
+void transform_geometry_set(GeoNodeExecParams &params,
+ GeometrySet &geometry,
const float4x4 &transform,
const Depsgraph &depsgraph)
{
@@ -189,10 +209,10 @@ void transform_geometry_set(GeometrySet &geometry,
transform_pointcloud(*pointcloud, transform);
}
if (Volume *volume = geometry.get_volume_for_write()) {
- transform_volume(*volume, transform, depsgraph);
+ transform_volume(params, *volume, transform, depsgraph);
}
- if (geometry.has_instances()) {
- transform_instances(geometry.get_component_for_write<InstancesComponent>(), transform);
+ if (bke::Instances *instances = geometry.get_instances_for_write()) {
+ transform_instances(*instances, transform);
}
if (bke::CurvesEditHints *curve_edit_hints = geometry.get_curve_edit_hints_for_write()) {
transform_curve_edit_hints(*curve_edit_hints, transform);
@@ -230,10 +250,11 @@ static void node_geo_exec(GeoNodeExecParams params)
/* Use only translation if rotation and scale don't apply. */
if (use_translate(rotation, scale)) {
- translate_geometry_set(geometry_set, translation, *params.depsgraph());
+ translate_geometry_set(params, geometry_set, translation, *params.depsgraph());
}
else {
- transform_geometry_set(geometry_set,
+ transform_geometry_set(params,
+ geometry_set,
float4x4::from_loc_eul_scale(translation, rotation, scale),
*params.depsgraph());
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_translate_instances.cc b/source/blender/nodes/geometry/nodes/node_geo_translate_instances.cc
index ae538072e65..23052abddc4 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_translate_instances.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_translate_instances.cc
@@ -2,6 +2,8 @@
#include "BLI_task.hh"
+#include "BKE_instances.hh"
+
#include "node_geometry_util.hh"
namespace blender::nodes::node_geo_translate_instances_cc {
@@ -15,11 +17,10 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Instances"));
}
-static void translate_instances(GeoNodeExecParams &params, InstancesComponent &instances_component)
+static void translate_instances(GeoNodeExecParams &params, bke::Instances &instances)
{
- GeometryComponentFieldContext field_context{instances_component, ATTR_DOMAIN_INSTANCE};
-
- fn::FieldEvaluator evaluator{field_context, instances_component.instances_num()};
+ const bke::InstancesFieldContext context{instances};
+ fn::FieldEvaluator evaluator{context, instances.instances_num()};
evaluator.set_selection(params.extract_input<Field<bool>>("Selection"));
evaluator.add(params.extract_input<Field<float3>>("Translation"));
evaluator.add(params.extract_input<Field<bool>>("Local Space"));
@@ -29,16 +30,16 @@ static void translate_instances(GeoNodeExecParams &params, InstancesComponent &i
const VArray<float3> translations = evaluator.get_evaluated<float3>(0);
const VArray<bool> local_spaces = evaluator.get_evaluated<bool>(1);
- MutableSpan<float4x4> instance_transforms = instances_component.instance_transforms();
+ MutableSpan<float4x4> transforms = instances.transforms();
threading::parallel_for(selection.index_range(), 1024, [&](IndexRange range) {
for (const int i_selection : range) {
const int i = selection[i_selection];
if (local_spaces[i]) {
- instance_transforms[i] *= float4x4::from_location(translations[i]);
+ transforms[i] *= float4x4::from_location(translations[i]);
}
else {
- add_v3_v3(instance_transforms[i].values[3], translations[i]);
+ add_v3_v3(transforms[i].values[3], translations[i]);
}
}
});
@@ -47,9 +48,8 @@ static void translate_instances(GeoNodeExecParams &params, InstancesComponent &i
static void node_geo_exec(GeoNodeExecParams params)
{
GeometrySet geometry_set = params.extract_input<GeometrySet>("Instances");
- if (geometry_set.has_instances()) {
- InstancesComponent &instances = geometry_set.get_component_for_write<InstancesComponent>();
- translate_instances(params, instances);
+ if (bke::Instances *instances = geometry_set.get_instances_for_write()) {
+ translate_instances(params, *instances);
}
params.set_output("Instances", std::move(geometry_set));
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_triangulate.cc b/source/blender/nodes/geometry/nodes/node_geo_triangulate.cc
index 992470e8279..cedc1ef845b 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_triangulate.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_triangulate.cc
@@ -23,13 +23,13 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Mesh"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "quad_method", 0, "", ICON_NONE);
uiItemR(layout, ptr, "ngon_method", 0, "", ICON_NONE);
}
-static void geo_triangulate_init(bNodeTree *UNUSED(ntree), bNode *node)
+static void geo_triangulate_init(bNodeTree * /*tree*/, bNode *node)
{
node->custom1 = GEO_NODE_TRIANGULATE_QUAD_SHORTEDGE;
node->custom2 = GEO_NODE_TRIANGULATE_NGON_BEAUTY;
@@ -47,9 +47,6 @@ static Mesh *triangulate_mesh_selection(const Mesh &mesh,
BMeshFromMeshParams from_mesh_params{};
from_mesh_params.calc_face_normal = true;
from_mesh_params.calc_vert_normal = true;
- from_mesh_params.add_key_index = true;
- from_mesh_params.use_shapekey = true;
- from_mesh_params.active_shapekey = 1;
from_mesh_params.cd_mask_extra = cd_mask_extra;
BMesh *bm = BKE_mesh_to_bmesh_ex(&mesh, &create_params, &from_mesh_params);
@@ -71,21 +68,17 @@ static void node_geo_exec(GeoNodeExecParams params)
Field<bool> selection_field = params.extract_input<Field<bool>>("Selection");
const int min_vertices = std::max(params.extract_input<int>("Minimum Vertices"), 4);
- GeometryNodeTriangulateQuads quad_method = static_cast<GeometryNodeTriangulateQuads>(
- params.node().custom1);
- GeometryNodeTriangulateNGons ngon_method = static_cast<GeometryNodeTriangulateNGons>(
- params.node().custom2);
+ GeometryNodeTriangulateQuads quad_method = GeometryNodeTriangulateQuads(params.node().custom1);
+ GeometryNodeTriangulateNGons ngon_method = GeometryNodeTriangulateNGons(params.node().custom2);
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
if (!geometry_set.has_mesh()) {
return;
}
- GeometryComponent &component = geometry_set.get_component_for_write<MeshComponent>();
const Mesh &mesh_in = *geometry_set.get_mesh_for_read();
- const int domain_size = component.attribute_domain_size(ATTR_DOMAIN_FACE);
- GeometryComponentFieldContext context{component, ATTR_DOMAIN_FACE};
- FieldEvaluator evaluator{context, domain_size};
+ bke::MeshFieldContext context{mesh_in, ATTR_DOMAIN_FACE};
+ FieldEvaluator evaluator{context, mesh_in.totpoly};
evaluator.add(selection_field);
evaluator.evaluate();
const IndexMask selection = evaluator.get_evaluated_as_mask(0);
diff --git a/source/blender/nodes/geometry/nodes/node_geo_uv_pack_islands.cc b/source/blender/nodes/geometry/nodes/node_geo_uv_pack_islands.cc
index 17413e64f7d..c2d27cffa93 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_uv_pack_islands.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_uv_pack_islands.cc
@@ -5,6 +5,8 @@
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
+#include "BKE_mesh.h"
+
#include "node_geometry_util.hh"
namespace blender::nodes::node_geo_uv_pack_islands_cc {
@@ -28,21 +30,19 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Vector>(N_("UV")).field_source();
}
-static VArray<float3> construct_uv_gvarray(const MeshComponent &component,
+static VArray<float3> construct_uv_gvarray(const Mesh &mesh,
const Field<bool> selection_field,
const Field<float3> uv_field,
const bool rotate,
const float margin,
const eAttrDomain domain)
{
- const Mesh *mesh = component.get_for_read();
- if (mesh == nullptr) {
- return {};
- }
+ const Span<MVert> verts = mesh.verts();
+ const Span<MPoly> polys = mesh.polys();
+ const Span<MLoop> loops = mesh.loops();
- const int face_num = component.attribute_domain_size(ATTR_DOMAIN_FACE);
- GeometryComponentFieldContext face_context{component, ATTR_DOMAIN_FACE};
- FieldEvaluator face_evaluator{face_context, face_num};
+ bke::MeshFieldContext face_context{mesh, ATTR_DOMAIN_FACE};
+ FieldEvaluator face_evaluator{face_context, polys.size()};
face_evaluator.add(selection_field);
face_evaluator.evaluate();
const IndexMask selection = face_evaluator.get_evaluated_as_mask(0);
@@ -50,25 +50,24 @@ static VArray<float3> construct_uv_gvarray(const MeshComponent &component,
return {};
}
- const int corner_num = component.attribute_domain_size(ATTR_DOMAIN_CORNER);
- GeometryComponentFieldContext corner_context{component, ATTR_DOMAIN_CORNER};
- FieldEvaluator evaluator{corner_context, corner_num};
- Array<float3> uv(corner_num);
+ bke::MeshFieldContext corner_context{mesh, ATTR_DOMAIN_CORNER};
+ FieldEvaluator evaluator{corner_context, mesh.totloop};
+ Array<float3> uv(mesh.totloop);
evaluator.add_with_destination(uv_field, uv.as_mutable_span());
evaluator.evaluate();
ParamHandle *handle = GEO_uv_parametrizer_construct_begin();
for (const int mp_index : selection) {
- const MPoly &mp = mesh->mpoly[mp_index];
+ const MPoly &mp = polys[mp_index];
Array<ParamKey, 16> mp_vkeys(mp.totloop);
Array<bool, 16> mp_pin(mp.totloop);
Array<bool, 16> mp_select(mp.totloop);
Array<const float *, 16> mp_co(mp.totloop);
Array<float *, 16> mp_uv(mp.totloop);
for (const int i : IndexRange(mp.totloop)) {
- const MLoop &ml = mesh->mloop[mp.loopstart + i];
+ const MLoop &ml = loops[mp.loopstart + i];
mp_vkeys[i] = ml.v;
- mp_co[i] = mesh->mvert[ml.v].co;
+ mp_co[i] = verts[ml.v].co;
mp_uv[i] = uv[mp.loopstart + i];
mp_pin[i] = false;
mp_select[i] = false;
@@ -88,11 +87,11 @@ static VArray<float3> construct_uv_gvarray(const MeshComponent &component,
GEO_uv_parametrizer_flush(handle);
GEO_uv_parametrizer_delete(handle);
- return component.attributes()->adapt_domain<float3>(
+ return mesh.attributes().adapt_domain<float3>(
VArray<float3>::ForContainer(std::move(uv)), ATTR_DOMAIN_CORNER, domain);
}
-class PackIslandsFieldInput final : public GeometryFieldInput {
+class PackIslandsFieldInput final : public bke::MeshFieldInput {
private:
const Field<bool> selection_field;
const Field<float3> uv_field;
@@ -104,7 +103,7 @@ class PackIslandsFieldInput final : public GeometryFieldInput {
const Field<float3> uv_field,
const bool rotate,
const float margin)
- : GeometryFieldInput(CPPType::get<float3>(), "Pack UV Islands Field"),
+ : bke::MeshFieldInput(CPPType::get<float3>(), "Pack UV Islands Field"),
selection_field(selection_field),
uv_field(uv_field),
rotate(rotate),
@@ -113,16 +112,16 @@ class PackIslandsFieldInput final : public GeometryFieldInput {
category_ = Category::Generated;
}
- GVArray get_varray_for_context(const GeometryComponent &component,
+ GVArray get_varray_for_context(const Mesh &mesh,
const eAttrDomain domain,
- IndexMask UNUSED(mask)) const final
+ const IndexMask /*mask*/) const final
{
- if (component.type() == GEO_COMPONENT_TYPE_MESH) {
- const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
- return construct_uv_gvarray(
- mesh_component, selection_field, uv_field, rotate, margin, domain);
- }
- return {};
+ return construct_uv_gvarray(mesh, selection_field, uv_field, rotate, margin, domain);
+ }
+
+ std::optional<eAttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
+ {
+ return ATTR_DOMAIN_CORNER;
}
};
diff --git a/source/blender/nodes/geometry/nodes/node_geo_uv_unwrap.cc b/source/blender/nodes/geometry/nodes/node_geo_uv_unwrap.cc
index 03657f3e016..e45ce6b42b4 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_uv_unwrap.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_uv_unwrap.cc
@@ -5,6 +5,8 @@
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
+#include "BKE_mesh.h"
+
#include "UI_interface.h"
#include "UI_resources.h"
@@ -38,21 +40,21 @@ static void node_declare(NodeDeclarationBuilder &b)
N_("UV coordinates between 0 and 1 for each face corner in the selected faces"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
uiItemR(layout, ptr, "method", 0, "", ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryUVUnwrap *data = MEM_cnew<NodeGeometryUVUnwrap>(__func__);
data->method = GEO_NODE_UV_UNWRAP_METHOD_ANGLE_BASED;
node->storage = data;
}
-static VArray<float3> construct_uv_gvarray(const MeshComponent &component,
+static VArray<float3> construct_uv_gvarray(const Mesh &mesh,
const Field<bool> selection_field,
const Field<bool> seam_field,
const bool fill_holes,
@@ -60,14 +62,13 @@ static VArray<float3> construct_uv_gvarray(const MeshComponent &component,
const GeometryNodeUVUnwrapMethod method,
const eAttrDomain domain)
{
- const Mesh *mesh = component.get_for_read();
- if (mesh == nullptr) {
- return {};
- }
+ const Span<MVert> verts = mesh.verts();
+ const Span<MEdge> edges = mesh.edges();
+ const Span<MPoly> polys = mesh.polys();
+ const Span<MLoop> loops = mesh.loops();
- const int face_num = component.attribute_domain_size(ATTR_DOMAIN_FACE);
- GeometryComponentFieldContext face_context{component, ATTR_DOMAIN_FACE};
- FieldEvaluator face_evaluator{face_context, face_num};
+ bke::MeshFieldContext face_context{mesh, ATTR_DOMAIN_FACE};
+ FieldEvaluator face_evaluator{face_context, polys.size()};
face_evaluator.add(selection_field);
face_evaluator.evaluate();
const IndexMask selection = face_evaluator.get_evaluated_as_mask(0);
@@ -75,27 +76,26 @@ static VArray<float3> construct_uv_gvarray(const MeshComponent &component,
return {};
}
- const int edge_num = component.attribute_domain_size(ATTR_DOMAIN_EDGE);
- GeometryComponentFieldContext edge_context{component, ATTR_DOMAIN_EDGE};
- FieldEvaluator edge_evaluator{edge_context, edge_num};
+ bke::MeshFieldContext edge_context{mesh, ATTR_DOMAIN_EDGE};
+ FieldEvaluator edge_evaluator{edge_context, edges.size()};
edge_evaluator.add(seam_field);
edge_evaluator.evaluate();
const IndexMask seam = edge_evaluator.get_evaluated_as_mask(0);
- Array<float3> uv(mesh->totloop, float3(0));
+ Array<float3> uv(loops.size(), float3(0));
ParamHandle *handle = GEO_uv_parametrizer_construct_begin();
for (const int mp_index : selection) {
- const MPoly &mp = mesh->mpoly[mp_index];
+ const MPoly &mp = polys[mp_index];
Array<ParamKey, 16> mp_vkeys(mp.totloop);
Array<bool, 16> mp_pin(mp.totloop);
Array<bool, 16> mp_select(mp.totloop);
Array<const float *, 16> mp_co(mp.totloop);
Array<float *, 16> mp_uv(mp.totloop);
for (const int i : IndexRange(mp.totloop)) {
- const MLoop &ml = mesh->mloop[mp.loopstart + i];
+ const MLoop &ml = loops[mp.loopstart + i];
mp_vkeys[i] = ml.v;
- mp_co[i] = mesh->mvert[ml.v].co;
+ mp_co[i] = verts[ml.v].co;
mp_uv[i] = uv[mp.loopstart + i];
mp_pin[i] = false;
mp_select[i] = false;
@@ -110,7 +110,7 @@ static VArray<float3> construct_uv_gvarray(const MeshComponent &component,
mp_select.data());
}
for (const int i : seam) {
- const MEdge &edge = mesh->medge[i];
+ const MEdge &edge = edges[i];
ParamKey vkeys[2]{edge.v1, edge.v2};
GEO_uv_parametrizer_edge_set_seam(handle, vkeys);
}
@@ -126,11 +126,11 @@ static VArray<float3> construct_uv_gvarray(const MeshComponent &component,
GEO_uv_parametrizer_flush(handle);
GEO_uv_parametrizer_delete(handle);
- return component.attributes()->adapt_domain<float3>(
+ return mesh.attributes().adapt_domain<float3>(
VArray<float3>::ForContainer(std::move(uv)), ATTR_DOMAIN_CORNER, domain);
}
-class UnwrapFieldInput final : public GeometryFieldInput {
+class UnwrapFieldInput final : public bke::MeshFieldInput {
private:
const Field<bool> selection;
const Field<bool> seam;
@@ -144,7 +144,7 @@ class UnwrapFieldInput final : public GeometryFieldInput {
const bool fill_holes,
const float margin,
const GeometryNodeUVUnwrapMethod method)
- : GeometryFieldInput(CPPType::get<float3>(), "UV Unwrap Field"),
+ : bke::MeshFieldInput(CPPType::get<float3>(), "UV Unwrap Field"),
selection(selection),
seam(seam),
fill_holes(fill_holes),
@@ -154,16 +154,16 @@ class UnwrapFieldInput final : public GeometryFieldInput {
category_ = Category::Generated;
}
- GVArray get_varray_for_context(const GeometryComponent &component,
+ GVArray get_varray_for_context(const Mesh &mesh,
const eAttrDomain domain,
- IndexMask UNUSED(mask)) const final
+ const IndexMask /*mask*/) const final
{
- if (component.type() == GEO_COMPONENT_TYPE_MESH) {
- const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
- return construct_uv_gvarray(
- mesh_component, selection, seam, fill_holes, margin, method, domain);
- }
- return {};
+ return construct_uv_gvarray(mesh, selection, seam, fill_holes, margin, method, domain);
+ }
+
+ std::optional<eAttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
+ {
+ return ATTR_DOMAIN_CORNER;
}
};
diff --git a/source/blender/nodes/geometry/nodes/node_geo_viewer.cc b/source/blender/nodes/geometry/nodes/node_geo_viewer.cc
index 6979693e215..e9050f9e6a1 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_viewer.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_viewer.cc
@@ -6,7 +6,7 @@
#include "UI_resources.h"
#include "ED_node.h"
-#include "ED_spreadsheet.h"
+#include "ED_viewer_path.hh"
#include "NOD_socket_search_link.hh"
@@ -26,15 +26,21 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_input<decl::Bool>(N_("Value"), "Value_004").supports_field().hide_value();
}
-static void node_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryViewer *data = MEM_cnew<NodeGeometryViewer>(__func__);
data->data_type = CD_PROP_FLOAT;
+ data->domain = ATTR_DOMAIN_AUTO;
node->storage = data;
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
+{
+ uiItemR(layout, ptr, "domain", 0, "", ICON_NONE);
+}
+
+static void node_layout_ex(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE);
}
@@ -61,7 +67,7 @@ static eNodeSocketDatatype custom_data_type_to_socket_type(const eCustomDataType
static void node_update(bNodeTree *ntree, bNode *node)
{
const NodeGeometryViewer &storage = node_storage(*node);
- const eCustomDataType data_type = static_cast<eCustomDataType>(storage.data_type);
+ const eCustomDataType data_type = eCustomDataType(storage.data_type);
const eNodeSocketDatatype socket_type = custom_data_type_to_socket_type(data_type);
LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
@@ -79,7 +85,7 @@ static void node_gather_link_searches(GatherLinkSearchOpParams &params)
SpaceNode *snode = CTX_wm_space_node(&params.C);
Main *bmain = CTX_data_main(&params.C);
ED_node_set_active(bmain, snode, &params.node_tree, &viewer_node, nullptr);
- ED_spreadsheet_context_paths_set_geometry_node(bmain, snode, &viewer_node);
+ ed::viewer_path::activate_geometry_node(*bmain, *snode, viewer_node);
};
const std::optional<eCustomDataType> type = node_socket_to_custom_data_type(
@@ -132,7 +138,9 @@ void register_node_type_geo_viewer()
node_type_update(&ntype, file_ns::node_update);
node_type_init(&ntype, file_ns::node_init);
ntype.declare = file_ns::node_declare;
- ntype.draw_buttons_ex = file_ns::node_layout;
+ ntype.draw_buttons = file_ns::node_layout;
+ ntype.draw_buttons_ex = file_ns::node_layout_ex;
ntype.gather_link_search_ops = file_ns::node_gather_link_searches;
+ ntype.no_muting = true;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_volume_cube.cc b/source/blender/nodes/geometry/nodes/node_geo_volume_cube.cc
index d7e9e38ea0d..7d439309380 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_volume_cube.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_volume_cube.cc
@@ -75,13 +75,12 @@ class Grid3DFieldContext : public FieldContext {
int64_t points_num() const
{
- return static_cast<int64_t>(resolution_.x) * static_cast<int64_t>(resolution_.y) *
- static_cast<int64_t>(resolution_.z);
+ return int64_t(resolution_.x) * int64_t(resolution_.y) * int64_t(resolution_.z);
}
GVArray get_varray_for_input(const FieldInput &field_input,
- const IndexMask UNUSED(mask),
- ResourceScope &UNUSED(scope)) const
+ const IndexMask /*mask*/,
+ ResourceScope & /*scope*/) const
{
const bke::AttributeFieldInput *attribute_field_input =
dynamic_cast<const bke::AttributeFieldInput *>(&field_input);
@@ -113,9 +112,9 @@ class Grid3DFieldContext : public FieldContext {
}
};
-#ifdef WITH_OPENVDB
static void node_geo_exec(GeoNodeExecParams params)
{
+#ifdef WITH_OPENVDB
const float3 bounds_min = params.extract_input<float3>("Min");
const float3 bounds_max = params.extract_input<float3>("Max");
@@ -137,6 +136,14 @@ static void node_geo_exec(GeoNodeExecParams params)
return;
}
+ const double3 scale_fac = double3(bounds_max - bounds_min) / double3(resolution - 1);
+ if (!BKE_volume_grid_determinant_valid(scale_fac.x * scale_fac.y * scale_fac.z)) {
+ params.error_message_add(NodeWarningType::Warning,
+ TIP_("Volume scale is lower than permitted by OpenVDB"));
+ params.set_default_remaining_outputs();
+ return;
+ }
+
Field<float> input_field = params.extract_input<Field<float>>("Density");
/* Evaluate input field on a 3D grid. */
@@ -157,12 +164,11 @@ static void node_geo_exec(GeoNodeExecParams params)
openvdb::tools::copyFromDense(dense_grid, *grid, 0.0f);
grid->transform().preTranslate(openvdb::math::Vec3<float>(-0.5f));
- const float3 scale_fac = (bounds_max - bounds_min) / float3(resolution - 1);
- grid->transform().postScale(openvdb::math::Vec3<float>(scale_fac.x, scale_fac.y, scale_fac.z));
+ grid->transform().postScale(openvdb::math::Vec3<double>(scale_fac.x, scale_fac.y, scale_fac.z));
grid->transform().postTranslate(
openvdb::math::Vec3<float>(bounds_min.x, bounds_min.y, bounds_min.z));
- Volume *volume = (Volume *)BKE_id_new_nomain(ID_VO, nullptr);
+ Volume *volume = reinterpret_cast<Volume *>(BKE_id_new_nomain(ID_VO, nullptr));
BKE_volume_init_grids(volume);
BKE_volume_grid_add_vdb(*volume, "density", std::move(grid));
@@ -170,16 +176,12 @@ static void node_geo_exec(GeoNodeExecParams params)
GeometrySet r_geometry_set;
r_geometry_set.replace_volume(volume);
params.set_output("Volume", r_geometry_set);
-}
-
#else
-static void node_geo_exec(GeoNodeExecParams params)
-{
+ params.set_default_remaining_outputs();
params.error_message_add(NodeWarningType::Error,
TIP_("Disabled, Blender was compiled without OpenVDB"));
- params.set_default_remaining_outputs();
+#endif
}
-#endif /* WITH_OPENVDB */
} // namespace blender::nodes::node_geo_volume_cube_cc
diff --git a/source/blender/nodes/geometry/nodes/node_geo_volume_to_mesh.cc b/source/blender/nodes/geometry/nodes/node_geo_volume_to_mesh.cc
index 91429560ac8..88e7718ed3c 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_volume_to_mesh.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_volume_to_mesh.cc
@@ -48,14 +48,14 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Geometry>(N_("Mesh"));
}
-static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
uiItemR(layout, ptr, "resolution_mode", 0, IFACE_("Resolution"), ICON_NONE);
}
-static void node_init(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeGeometryVolumeToMesh *data = MEM_cnew<NodeGeometryVolumeToMesh>(__func__);
data->resolution_mode = VOLUME_TO_MESH_RESOLUTION_MODE_GRID;
@@ -123,9 +123,9 @@ static Mesh *create_mesh_from_volume_grids(Span<openvdb::GridBase::ConstPtr> gri
Mesh *mesh = BKE_mesh_new_nomain(vert_offset, 0, 0, loop_offset, poly_offset);
BKE_id_material_eval_ensure_default_slot(&mesh->id);
- MutableSpan<MVert> verts{mesh->mvert, mesh->totvert};
- MutableSpan<MLoop> loops{mesh->mloop, mesh->totloop};
- MutableSpan<MPoly> polys{mesh->mpoly, mesh->totpoly};
+ MutableSpan<MVert> verts = mesh->verts_for_write();
+ MutableSpan<MPoly> polys = mesh->polys_for_write();
+ MutableSpan<MLoop> loops = mesh->loops_for_write();
for (const int i : grids.index_range()) {
const bke::OpenVDBMeshData &data = mesh_data[i];
@@ -187,20 +187,19 @@ static Mesh *create_mesh_from_volume(GeometrySet &geometry_set, GeoNodeExecParam
static void node_geo_exec(GeoNodeExecParams params)
{
- GeometrySet geometry_set = params.extract_input<GeometrySet>("Volume");
-
#ifdef WITH_OPENVDB
+ GeometrySet geometry_set = params.extract_input<GeometrySet>("Volume");
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
Mesh *mesh = create_mesh_from_volume(geometry_set, params);
geometry_set.replace_mesh(mesh);
geometry_set.keep_only_during_modify({GEO_COMPONENT_TYPE_MESH});
});
+ params.set_output("Mesh", std::move(geometry_set));
#else
+ params.set_default_remaining_outputs();
params.error_message_add(NodeWarningType::Error,
TIP_("Disabled, Blender was compiled without OpenVDB"));
#endif
-
- params.set_output("Mesh", std::move(geometry_set));
}
} // namespace blender::nodes::node_geo_volume_to_mesh_cc
diff --git a/source/blender/nodes/intern/derived_node_tree.cc b/source/blender/nodes/intern/derived_node_tree.cc
index e589da09b16..2ea80008af8 100644
--- a/source/blender/nodes/intern/derived_node_tree.cc
+++ b/source/blender/nodes/intern/derived_node_tree.cc
@@ -2,38 +2,38 @@
#include "NOD_derived_node_tree.hh"
+#include "BKE_node.h"
+
#include "BLI_dot_export.hh"
namespace blender::nodes {
-DerivedNodeTree::DerivedNodeTree(bNodeTree &btree, NodeTreeRefMap &node_tree_refs)
+DerivedNodeTree::DerivedNodeTree(const bNodeTree &btree)
{
/* Construct all possible contexts immediately. This is significantly cheaper than inlining all
* node groups. If it still becomes a performance issue in the future, contexts could be
* constructed lazily when they are needed. */
- root_context_ = &this->construct_context_recursively(nullptr, nullptr, btree, node_tree_refs);
+ root_context_ = &this->construct_context_recursively(nullptr, nullptr, btree);
}
DTreeContext &DerivedNodeTree::construct_context_recursively(DTreeContext *parent_context,
- const NodeRef *parent_node,
- bNodeTree &btree,
- NodeTreeRefMap &node_tree_refs)
+ const bNode *parent_node,
+ const bNodeTree &btree)
{
+ btree.ensure_topology_cache();
DTreeContext &context = *allocator_.construct<DTreeContext>().release();
context.parent_context_ = parent_context;
context.parent_node_ = parent_node;
context.derived_tree_ = this;
- context.tree_ = &get_tree_ref_from_map(node_tree_refs, btree);
- used_node_tree_refs_.add(context.tree_);
+ context.btree_ = &btree;
+ used_btrees_.add(context.btree_);
- for (const NodeRef *node : context.tree_->nodes()) {
- if (node->is_group_node()) {
- bNode *bnode = node->bnode();
+ for (const bNode *bnode : context.btree_->all_nodes()) {
+ if (bnode->is_group()) {
bNodeTree *child_btree = reinterpret_cast<bNodeTree *>(bnode->id);
if (child_btree != nullptr) {
- DTreeContext &child = this->construct_context_recursively(
- &context, node, *child_btree, node_tree_refs);
- context.children_.add_new(node, &child);
+ DTreeContext &child = this->construct_context_recursively(&context, bnode, *child_btree);
+ context.children_.add_new(bnode, &child);
}
}
}
@@ -57,8 +57,8 @@ void DerivedNodeTree::destruct_context_recursively(DTreeContext *context)
bool DerivedNodeTree::has_link_cycles() const
{
- for (const NodeTreeRef *tree_ref : used_node_tree_refs_) {
- if (tree_ref->has_link_cycles()) {
+ for (const bNodeTree *btree : used_btrees_) {
+ if (btree->has_available_link_cycle()) {
return true;
}
}
@@ -67,8 +67,8 @@ bool DerivedNodeTree::has_link_cycles() const
bool DerivedNodeTree::has_undefined_nodes_or_sockets() const
{
- for (const NodeTreeRef *tree_ref : used_node_tree_refs_) {
- if (tree_ref->has_undefined_nodes_or_sockets()) {
+ for (const bNodeTree *btree : used_btrees_) {
+ if (btree->has_undefined_nodes_or_sockets()) {
return true;
}
}
@@ -83,8 +83,8 @@ void DerivedNodeTree::foreach_node(FunctionRef<void(DNode)> callback) const
void DerivedNodeTree::foreach_node_in_context_recursive(const DTreeContext &context,
FunctionRef<void(DNode)> callback) const
{
- for (const NodeRef *node_ref : context.tree_->nodes()) {
- callback(DNode(&context, node_ref));
+ for (const bNode *bnode : context.btree_->all_nodes()) {
+ callback(DNode(&context, bnode));
}
for (const DTreeContext *child_context : context.children_.values()) {
this->foreach_node_in_context_recursive(*child_context, callback);
@@ -94,32 +94,32 @@ void DerivedNodeTree::foreach_node_in_context_recursive(const DTreeContext &cont
DOutputSocket DInputSocket::get_corresponding_group_node_output() const
{
BLI_assert(*this);
- BLI_assert(socket_ref_->node().is_group_output_node());
- BLI_assert(socket_ref_->index() < socket_ref_->node().inputs().size() - 1);
+ BLI_assert(bsocket_->owner_node().is_group_output());
+ BLI_assert(bsocket_->index() < bsocket_->owner_node().input_sockets().size() - 1);
const DTreeContext *parent_context = context_->parent_context();
- const NodeRef *parent_node = context_->parent_node();
+ const bNode *parent_node = context_->parent_node();
BLI_assert(parent_context != nullptr);
BLI_assert(parent_node != nullptr);
- const int socket_index = socket_ref_->index();
- return {parent_context, &parent_node->output(socket_index)};
+ const int socket_index = bsocket_->index();
+ return {parent_context, &parent_node->output_socket(socket_index)};
}
Vector<DOutputSocket> DInputSocket::get_corresponding_group_input_sockets() const
{
BLI_assert(*this);
- BLI_assert(socket_ref_->node().is_group_node());
+ BLI_assert(bsocket_->owner_node().is_group());
- const DTreeContext *child_context = context_->child_context(socket_ref_->node());
+ const DTreeContext *child_context = context_->child_context(bsocket_->owner_node());
BLI_assert(child_context != nullptr);
- const NodeTreeRef &child_tree = child_context->tree();
- Span<const NodeRef *> group_input_nodes = child_tree.nodes_by_type("NodeGroupInput");
- const int socket_index = socket_ref_->index();
+ const bNodeTree &child_tree = child_context->btree();
+ Span<const bNode *> group_input_nodes = child_tree.nodes_by_type("NodeGroupInput");
+ const int socket_index = bsocket_->index();
Vector<DOutputSocket> sockets;
- for (const NodeRef *group_input_node : group_input_nodes) {
- sockets.append(DOutputSocket(child_context, &group_input_node->output(socket_index)));
+ for (const bNode *group_input_node : group_input_nodes) {
+ sockets.append(DOutputSocket(child_context, &group_input_node->output_socket(socket_index)));
}
return sockets;
}
@@ -127,36 +127,36 @@ Vector<DOutputSocket> DInputSocket::get_corresponding_group_input_sockets() cons
DInputSocket DOutputSocket::get_corresponding_group_node_input() const
{
BLI_assert(*this);
- BLI_assert(socket_ref_->node().is_group_input_node());
- BLI_assert(socket_ref_->index() < socket_ref_->node().outputs().size() - 1);
+ BLI_assert(bsocket_->owner_node().is_group_input());
+ BLI_assert(bsocket_->index() < bsocket_->owner_node().output_sockets().size() - 1);
const DTreeContext *parent_context = context_->parent_context();
- const NodeRef *parent_node = context_->parent_node();
+ const bNode *parent_node = context_->parent_node();
BLI_assert(parent_context != nullptr);
BLI_assert(parent_node != nullptr);
- const int socket_index = socket_ref_->index();
- return {parent_context, &parent_node->input(socket_index)};
+ const int socket_index = bsocket_->index();
+ return {parent_context, &parent_node->input_socket(socket_index)};
}
DInputSocket DOutputSocket::get_active_corresponding_group_output_socket() const
{
BLI_assert(*this);
- BLI_assert(socket_ref_->node().is_group_node());
+ BLI_assert(bsocket_->owner_node().is_group());
- const DTreeContext *child_context = context_->child_context(socket_ref_->node());
+ const DTreeContext *child_context = context_->child_context(bsocket_->owner_node());
if (child_context == nullptr) {
/* Can happen when the group node references a non-existent group (e.g. when the group is
* linked but the original file is not found). */
return {};
}
- const NodeTreeRef &child_tree = child_context->tree();
- Span<const NodeRef *> group_output_nodes = child_tree.nodes_by_type("NodeGroupOutput");
- const int socket_index = socket_ref_->index();
- for (const NodeRef *group_output_node : group_output_nodes) {
- if (group_output_node->bnode()->flag & NODE_DO_OUTPUT || group_output_nodes.size() == 1) {
- return {child_context, &group_output_node->input(socket_index)};
+ const bNodeTree &child_tree = child_context->btree();
+ Span<const bNode *> group_output_nodes = child_tree.nodes_by_type("NodeGroupOutput");
+ const int socket_index = bsocket_->index();
+ for (const bNode *group_output_node : group_output_nodes) {
+ if (group_output_node->flag & NODE_DO_OUTPUT || group_output_nodes.size() == 1) {
+ return {child_context, &group_output_node->input_socket(socket_index)};
}
}
return {};
@@ -165,11 +165,11 @@ DInputSocket DOutputSocket::get_active_corresponding_group_output_socket() const
void DInputSocket::foreach_origin_socket(FunctionRef<void(DSocket)> origin_fn) const
{
BLI_assert(*this);
- for (const OutputSocketRef *linked_socket : socket_ref_->as_input().logically_linked_sockets()) {
- const NodeRef &linked_node = linked_socket->node();
+ for (const bNodeSocket *linked_socket : bsocket_->logically_linked_sockets()) {
+ const bNode &linked_node = linked_socket->owner_node();
DOutputSocket linked_dsocket{context_, linked_socket};
- if (linked_node.is_group_input_node()) {
+ if (linked_node.is_group_input()) {
if (context_->is_root()) {
/* This is a group input in the root node group. */
origin_fn(linked_dsocket);
@@ -187,7 +187,7 @@ void DInputSocket::foreach_origin_socket(FunctionRef<void(DSocket)> origin_fn) c
}
}
}
- else if (linked_node.is_group_node()) {
+ else if (linked_node.is_group()) {
DInputSocket socket_in_group = linked_dsocket.get_active_corresponding_group_output_socket();
if (socket_in_group) {
if (socket_in_group->is_logically_linked()) {
@@ -217,16 +217,16 @@ void DOutputSocket::foreach_target_socket(ForeachTargetSocketFn target_fn) const
void DOutputSocket::foreach_target_socket(ForeachTargetSocketFn target_fn,
TargetSocketPathInfo &path_info) const
{
- for (const LinkRef *link : socket_ref_->as_output().directly_linked_links()) {
+ for (const bNodeLink *link : bsocket_->directly_linked_links()) {
if (link->is_muted()) {
continue;
}
- const DInputSocket &linked_socket{context_, &link->to()};
+ const DInputSocket &linked_socket{context_, link->tosock};
if (!linked_socket->is_available()) {
continue;
}
const DNode linked_node = linked_socket.node();
- if (linked_node->is_reroute_node()) {
+ if (linked_node->is_reroute()) {
const DInputSocket reroute_input = linked_socket;
const DOutputSocket reroute_output = linked_node.output(0);
path_info.sockets.append(reroute_input);
@@ -236,18 +236,18 @@ void DOutputSocket::foreach_target_socket(ForeachTargetSocketFn target_fn,
path_info.sockets.pop_last();
}
else if (linked_node->is_muted()) {
- for (const InternalLinkRef *internal_link : linked_node->internal_links()) {
- if (&internal_link->from() != linked_socket.socket_ref()) {
+ for (const bNodeLink *internal_link : linked_node->internal_links_span()) {
+ if (internal_link->fromsock != linked_socket.bsocket()) {
continue;
}
/* The internal link only forwards the first incoming link. */
- if (linked_socket->is_multi_input_socket()) {
+ if (linked_socket->is_multi_input()) {
if (linked_socket->directly_linked_links()[0] != link) {
continue;
}
}
const DInputSocket mute_input = linked_socket;
- const DOutputSocket mute_output{context_, &internal_link->to()};
+ const DOutputSocket mute_output{context_, internal_link->tosock};
path_info.sockets.append(mute_input);
path_info.sockets.append(mute_output);
mute_output.foreach_target_socket(target_fn, path_info);
@@ -255,8 +255,8 @@ void DOutputSocket::foreach_target_socket(ForeachTargetSocketFn target_fn,
path_info.sockets.pop_last();
}
}
- else if (linked_node->is_group_output_node()) {
- if (linked_node.node_ref() != context_->tree().group_output_node()) {
+ else if (linked_node->is_group_output()) {
+ if (linked_node.bnode() != context_->btree().group_output_node()) {
continue;
}
if (context_->is_root()) {
@@ -276,7 +276,7 @@ void DOutputSocket::foreach_target_socket(ForeachTargetSocketFn target_fn,
path_info.sockets.pop_last();
}
}
- else if (linked_node->is_group_node()) {
+ else if (linked_node->is_group()) {
/* Follow the links within the nested node group. */
path_info.sockets.append(linked_socket);
const Vector<DOutputSocket> sockets_in_group =
@@ -310,7 +310,8 @@ static dot::Cluster *get_dot_cluster_for_context(
}
dot::Cluster *parent_cluster = get_dot_cluster_for_context(
digraph, parent_context, dot_clusters);
- std::string cluster_name = context->tree().name() + " / " + context->parent_node()->name();
+ std::string cluster_name = StringRef(context->btree().id.name + 2) + " / " +
+ context->parent_node()->name;
dot::Cluster &cluster = digraph.new_cluster(cluster_name);
cluster.set_parent_cluster(parent_cluster);
return &cluster;
@@ -328,11 +329,11 @@ std::string DerivedNodeTree::to_dot() const
this->foreach_node([&](DNode node) {
/* Ignore nodes that should not show up in the final output. */
- if (node->is_muted() || node->is_group_node() || node->is_reroute_node() || node->is_frame()) {
+ if (node->is_muted() || node->is_group() || node->is_reroute() || node->is_frame()) {
return;
}
if (!node.context()->is_root()) {
- if (node->is_group_input_node() || node->is_group_output_node()) {
+ if (node->is_group_input() || node->is_group_output()) {
return;
}
}
@@ -345,22 +346,22 @@ std::string DerivedNodeTree::to_dot() const
Vector<std::string> input_names;
Vector<std::string> output_names;
- for (const InputSocketRef *socket : node->inputs()) {
+ for (const bNodeSocket *socket : node->input_sockets()) {
if (socket->is_available()) {
- input_names.append(socket->name());
+ input_names.append(socket->name);
}
}
- for (const OutputSocketRef *socket : node->outputs()) {
+ for (const bNodeSocket *socket : node->output_sockets()) {
if (socket->is_available()) {
- output_names.append(socket->name());
+ output_names.append(socket->name);
}
}
dot::NodeWithSocketsRef dot_node_with_sockets = dot::NodeWithSocketsRef(
- dot_node, node->name(), input_names, output_names);
+ dot_node, node->name, input_names, output_names);
int input_index = 0;
- for (const InputSocketRef *socket : node->inputs()) {
+ for (const bNodeSocket *socket : node->input_sockets()) {
if (socket->is_available()) {
dot_input_sockets.add_new(DInputSocket{node.context(), socket},
dot_node_with_sockets.input(input_index));
@@ -368,7 +369,7 @@ std::string DerivedNodeTree::to_dot() const
}
}
int output_index = 0;
- for (const OutputSocketRef *socket : node->outputs()) {
+ for (const bNodeSocket *socket : node->output_sockets()) {
if (socket->is_available()) {
dot_output_sockets.add_new(DOutputSocket{node.context(), socket},
dot_node_with_sockets.output(output_index));
@@ -392,7 +393,7 @@ std::string DerivedNodeTree::to_dot() const
}
}
dot::Node &dot_node = *dot_floating_inputs.lookup_or_add_cb(from_socket, [&]() {
- dot::Node &dot_node = digraph.new_node(from_socket->name());
+ dot::Node &dot_node = digraph.new_node(from_socket->name);
dot_node.set_background_color("white");
dot_node.set_shape(dot::Attr_shape::Ellipse);
dot_node.set_parent_cluster(
diff --git a/source/blender/nodes/intern/geometry_nodes_eval_log.cc b/source/blender/nodes/intern/geometry_nodes_eval_log.cc
deleted file mode 100644
index 55930dcb1ee..00000000000
--- a/source/blender/nodes/intern/geometry_nodes_eval_log.cc
+++ /dev/null
@@ -1,520 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-
-#include "NOD_geometry_nodes_eval_log.hh"
-
-#include "BKE_curves.hh"
-#include "BKE_geometry_set_instances.hh"
-
-#include "DNA_modifier_types.h"
-#include "DNA_space_types.h"
-
-#include "FN_field_cpp_type.hh"
-
-#include "BLT_translation.h"
-
-#include <chrono>
-
-namespace blender::nodes::geometry_nodes_eval_log {
-
-using fn::FieldCPPType;
-using fn::FieldInput;
-using fn::GField;
-using fn::ValueOrFieldCPPType;
-
-ModifierLog::ModifierLog(GeoLogger &logger)
- : input_geometry_log_(std::move(logger.input_geometry_log_)),
- output_geometry_log_(std::move(logger.output_geometry_log_))
-{
- root_tree_logs_ = allocator_.construct<TreeLog>();
-
- LogByTreeContext log_by_tree_context;
-
- /* Combine all the local loggers that have been used by separate threads. */
- for (LocalGeoLogger &local_logger : logger) {
- /* Take ownership of the allocator. */
- logger_allocators_.append(std::move(local_logger.allocator_));
-
- for (ValueOfSockets &value_of_sockets : local_logger.values_) {
- ValueLog *value_log = value_of_sockets.value.get();
-
- /* Take centralized ownership of the logged value. It might be referenced by multiple
- * sockets. */
- logged_values_.append(std::move(value_of_sockets.value));
-
- for (const DSocket &socket : value_of_sockets.sockets) {
- SocketLog &socket_log = this->lookup_or_add_socket_log(log_by_tree_context, socket);
- socket_log.value_ = value_log;
- }
- }
-
- for (NodeWithWarning &node_with_warning : local_logger.node_warnings_) {
- NodeLog &node_log = this->lookup_or_add_node_log(log_by_tree_context,
- node_with_warning.node);
- node_log.warnings_.append(node_with_warning.warning);
- }
-
- for (NodeWithExecutionTime &node_with_exec_time : local_logger.node_exec_times_) {
- NodeLog &node_log = this->lookup_or_add_node_log(log_by_tree_context,
- node_with_exec_time.node);
- node_log.exec_time_ = node_with_exec_time.exec_time;
- }
-
- for (NodeWithDebugMessage &debug_message : local_logger.node_debug_messages_) {
- NodeLog &node_log = this->lookup_or_add_node_log(log_by_tree_context, debug_message.node);
- node_log.debug_messages_.append(debug_message.message);
- }
-
- for (NodeWithUsedNamedAttribute &node_with_attribute_name :
- local_logger.used_named_attributes_) {
- NodeLog &node_log = this->lookup_or_add_node_log(log_by_tree_context,
- node_with_attribute_name.node);
- node_log.used_named_attributes_.append(std::move(node_with_attribute_name.attribute));
- }
- }
-}
-
-TreeLog &ModifierLog::lookup_or_add_tree_log(LogByTreeContext &log_by_tree_context,
- const DTreeContext &tree_context)
-{
- TreeLog *tree_log = log_by_tree_context.lookup_default(&tree_context, nullptr);
- if (tree_log != nullptr) {
- return *tree_log;
- }
-
- const DTreeContext *parent_context = tree_context.parent_context();
- if (parent_context == nullptr) {
- return *root_tree_logs_.get();
- }
- TreeLog &parent_log = this->lookup_or_add_tree_log(log_by_tree_context, *parent_context);
- destruct_ptr<TreeLog> owned_tree_log = allocator_.construct<TreeLog>();
- tree_log = owned_tree_log.get();
- log_by_tree_context.add_new(&tree_context, tree_log);
- parent_log.child_logs_.add_new(tree_context.parent_node()->name(), std::move(owned_tree_log));
- return *tree_log;
-}
-
-NodeLog &ModifierLog::lookup_or_add_node_log(LogByTreeContext &log_by_tree_context, DNode node)
-{
- TreeLog &tree_log = this->lookup_or_add_tree_log(log_by_tree_context, *node.context());
- NodeLog &node_log = *tree_log.node_logs_.lookup_or_add_cb(node->name(), [&]() {
- destruct_ptr<NodeLog> node_log = allocator_.construct<NodeLog>();
- node_log->input_logs_.resize(node->inputs().size());
- node_log->output_logs_.resize(node->outputs().size());
- return node_log;
- });
- return node_log;
-}
-
-SocketLog &ModifierLog::lookup_or_add_socket_log(LogByTreeContext &log_by_tree_context,
- DSocket socket)
-{
- NodeLog &node_log = this->lookup_or_add_node_log(log_by_tree_context, socket.node());
- MutableSpan<SocketLog> socket_logs = socket->is_input() ? node_log.input_logs_ :
- node_log.output_logs_;
- SocketLog &socket_log = socket_logs[socket->index()];
- return socket_log;
-}
-
-void ModifierLog::foreach_node_log(FunctionRef<void(const NodeLog &)> fn) const
-{
- if (root_tree_logs_) {
- root_tree_logs_->foreach_node_log(fn);
- }
-}
-
-const GeometryValueLog *ModifierLog::input_geometry_log() const
-{
- return input_geometry_log_.get();
-}
-const GeometryValueLog *ModifierLog::output_geometry_log() const
-{
- return output_geometry_log_.get();
-}
-
-const NodeLog *TreeLog::lookup_node_log(StringRef node_name) const
-{
- const destruct_ptr<NodeLog> *node_log = node_logs_.lookup_ptr_as(node_name);
- if (node_log == nullptr) {
- return nullptr;
- }
- return node_log->get();
-}
-
-const NodeLog *TreeLog::lookup_node_log(const bNode &node) const
-{
- return this->lookup_node_log(node.name);
-}
-
-const TreeLog *TreeLog::lookup_child_log(StringRef node_name) const
-{
- const destruct_ptr<TreeLog> *tree_log = child_logs_.lookup_ptr_as(node_name);
- if (tree_log == nullptr) {
- return nullptr;
- }
- return tree_log->get();
-}
-
-void TreeLog::foreach_node_log(FunctionRef<void(const NodeLog &)> fn) const
-{
- for (auto node_log : node_logs_.items()) {
- fn(*node_log.value);
- }
-
- for (auto child : child_logs_.items()) {
- child.value->foreach_node_log(fn);
- }
-}
-
-const SocketLog *NodeLog::lookup_socket_log(eNodeSocketInOut in_out, int index) const
-{
- BLI_assert(index >= 0);
- Span<SocketLog> socket_logs = (in_out == SOCK_IN) ? input_logs_ : output_logs_;
- if (index >= socket_logs.size()) {
- return nullptr;
- }
- return &socket_logs[index];
-}
-
-const SocketLog *NodeLog::lookup_socket_log(const bNode &node, const bNodeSocket &socket) const
-{
- ListBase sockets = socket.in_out == SOCK_IN ? node.inputs : node.outputs;
- int index = BLI_findindex(&sockets, &socket);
- return this->lookup_socket_log((eNodeSocketInOut)socket.in_out, index);
-}
-
-GFieldValueLog::GFieldValueLog(fn::GField field, bool log_full_field) : type_(field.cpp_type())
-{
- const std::shared_ptr<const fn::FieldInputs> &field_input_nodes = field.node().field_inputs();
-
- /* Put the deduplicated field inputs into a vector so that they can be sorted below. */
- Vector<std::reference_wrapper<const FieldInput>> field_inputs;
- if (field_input_nodes) {
- field_inputs.extend(field_input_nodes->deduplicated_nodes.begin(),
- field_input_nodes->deduplicated_nodes.end());
- }
-
- std::sort(
- field_inputs.begin(), field_inputs.end(), [](const FieldInput &a, const FieldInput &b) {
- const int index_a = (int)a.category();
- const int index_b = (int)b.category();
- if (index_a == index_b) {
- return a.socket_inspection_name().size() < b.socket_inspection_name().size();
- }
- return index_a < index_b;
- });
-
- for (const FieldInput &field_input : field_inputs) {
- input_tooltips_.append(field_input.socket_inspection_name());
- }
-
- if (log_full_field) {
- field_ = std::move(field);
- }
-}
-
-GeometryValueLog::GeometryValueLog(const GeometrySet &geometry_set, bool log_full_geometry)
-{
- static std::array all_component_types = {GEO_COMPONENT_TYPE_CURVE,
- GEO_COMPONENT_TYPE_INSTANCES,
- GEO_COMPONENT_TYPE_MESH,
- GEO_COMPONENT_TYPE_POINT_CLOUD,
- GEO_COMPONENT_TYPE_VOLUME};
-
- /* Keep track handled attribute names to make sure that we do not return the same name twice.
- * Currently #GeometrySet::attribute_foreach does not do that. Note that this will merge
- * attributes with the same name but different domains or data types on separate components. */
- Set<StringRef> names;
-
- geometry_set.attribute_foreach(
- all_component_types,
- true,
- [&](const bke::AttributeIDRef &attribute_id,
- const bke::AttributeMetaData &meta_data,
- const GeometryComponent &UNUSED(component)) {
- if (attribute_id.is_named() && names.add(attribute_id.name())) {
- this->attributes_.append({attribute_id.name(), meta_data.domain, meta_data.data_type});
- }
- });
-
- for (const GeometryComponent *component : geometry_set.get_components_for_read()) {
- component_types_.append(component->type());
- switch (component->type()) {
- case GEO_COMPONENT_TYPE_MESH: {
- const MeshComponent &mesh_component = *(const MeshComponent *)component;
- MeshInfo &info = this->mesh_info.emplace();
- info.verts_num = mesh_component.attribute_domain_size(ATTR_DOMAIN_POINT);
- info.edges_num = mesh_component.attribute_domain_size(ATTR_DOMAIN_EDGE);
- info.faces_num = mesh_component.attribute_domain_size(ATTR_DOMAIN_FACE);
- break;
- }
- case GEO_COMPONENT_TYPE_CURVE: {
- const CurveComponent &curve_component = *(const CurveComponent *)component;
- CurveInfo &info = this->curve_info.emplace();
- info.splines_num = curve_component.attribute_domain_size(ATTR_DOMAIN_CURVE);
- break;
- }
- case GEO_COMPONENT_TYPE_POINT_CLOUD: {
- const PointCloudComponent &pointcloud_component = *(const PointCloudComponent *)component;
- PointCloudInfo &info = this->pointcloud_info.emplace();
- info.points_num = pointcloud_component.attribute_domain_size(ATTR_DOMAIN_POINT);
- break;
- }
- case GEO_COMPONENT_TYPE_INSTANCES: {
- const InstancesComponent &instances_component = *(const InstancesComponent *)component;
- InstancesInfo &info = this->instances_info.emplace();
- info.instances_num = instances_component.instances_num();
- break;
- }
- case GEO_COMPONENT_TYPE_EDIT: {
- const GeometryComponentEditData &edit_component = *(
- const GeometryComponentEditData *)component;
- if (const bke::CurvesEditHints *curve_edit_hints =
- edit_component.curves_edit_hints_.get()) {
- EditDataInfo &info = this->edit_data_info.emplace();
- info.has_deform_matrices = curve_edit_hints->deform_mats.has_value();
- info.has_deformed_positions = curve_edit_hints->positions.has_value();
- }
- break;
- }
- case GEO_COMPONENT_TYPE_VOLUME: {
- break;
- }
- }
- }
- if (log_full_geometry) {
- full_geometry_ = std::make_unique<GeometrySet>(geometry_set);
- full_geometry_->ensure_owns_direct_data();
- }
-}
-
-Vector<const GeometryAttributeInfo *> NodeLog::lookup_available_attributes() const
-{
- Vector<const GeometryAttributeInfo *> attributes;
- Set<StringRef> names;
- for (const SocketLog &socket_log : input_logs_) {
- const ValueLog *value_log = socket_log.value();
- if (const GeometryValueLog *geo_value_log = dynamic_cast<const GeometryValueLog *>(
- value_log)) {
- for (const GeometryAttributeInfo &attribute : geo_value_log->attributes()) {
- if (names.add(attribute.name)) {
- attributes.append(&attribute);
- }
- }
- }
- }
- return attributes;
-}
-
-const ModifierLog *ModifierLog::find_root_by_node_editor_context(const SpaceNode &snode)
-{
- if (snode.id == nullptr) {
- return nullptr;
- }
- if (GS(snode.id->name) != ID_OB) {
- return nullptr;
- }
- Object *object = (Object *)snode.id;
- LISTBASE_FOREACH (ModifierData *, md, &object->modifiers) {
- if (md->type == eModifierType_Nodes) {
- NodesModifierData *nmd = (NodesModifierData *)md;
- if (nmd->node_group == snode.nodetree) {
- return (ModifierLog *)nmd->runtime_eval_log;
- }
- }
- }
- return nullptr;
-}
-
-const TreeLog *ModifierLog::find_tree_by_node_editor_context(const SpaceNode &snode)
-{
- const ModifierLog *eval_log = ModifierLog::find_root_by_node_editor_context(snode);
- if (eval_log == nullptr) {
- return nullptr;
- }
- Vector<bNodeTreePath *> tree_path_vec = snode.treepath;
- if (tree_path_vec.is_empty()) {
- return nullptr;
- }
- TreeLog *current = eval_log->root_tree_logs_.get();
- for (bNodeTreePath *path : tree_path_vec.as_span().drop_front(1)) {
- destruct_ptr<TreeLog> *tree_log = current->child_logs_.lookup_ptr_as(path->node_name);
- if (tree_log == nullptr) {
- return nullptr;
- }
- current = tree_log->get();
- }
- return current;
-}
-
-const NodeLog *ModifierLog::find_node_by_node_editor_context(const SpaceNode &snode,
- const bNode &node)
-{
- const TreeLog *tree_log = ModifierLog::find_tree_by_node_editor_context(snode);
- if (tree_log == nullptr) {
- return nullptr;
- }
- return tree_log->lookup_node_log(node);
-}
-
-const NodeLog *ModifierLog::find_node_by_node_editor_context(const SpaceNode &snode,
- const StringRef node_name)
-{
- const TreeLog *tree_log = ModifierLog::find_tree_by_node_editor_context(snode);
- if (tree_log == nullptr) {
- return nullptr;
- }
- return tree_log->lookup_node_log(node_name);
-}
-
-const SocketLog *ModifierLog::find_socket_by_node_editor_context(const SpaceNode &snode,
- const bNode &node,
- const bNodeSocket &socket)
-{
- const NodeLog *node_log = ModifierLog::find_node_by_node_editor_context(snode, node);
- if (node_log == nullptr) {
- return nullptr;
- }
- return node_log->lookup_socket_log(node, socket);
-}
-
-const NodeLog *ModifierLog::find_node_by_spreadsheet_editor_context(
- const SpaceSpreadsheet &sspreadsheet)
-{
- Vector<SpreadsheetContext *> context_path = sspreadsheet.context_path;
- if (context_path.size() <= 2) {
- return nullptr;
- }
- if (context_path[0]->type != SPREADSHEET_CONTEXT_OBJECT) {
- return nullptr;
- }
- if (context_path[1]->type != SPREADSHEET_CONTEXT_MODIFIER) {
- return nullptr;
- }
- for (SpreadsheetContext *context : context_path.as_span().drop_front(2)) {
- if (context->type != SPREADSHEET_CONTEXT_NODE) {
- return nullptr;
- }
- }
- Span<SpreadsheetContextNode *> node_contexts =
- context_path.as_span().drop_front(2).cast<SpreadsheetContextNode *>();
-
- Object *object = ((SpreadsheetContextObject *)context_path[0])->object;
- StringRefNull modifier_name = ((SpreadsheetContextModifier *)context_path[1])->modifier_name;
- if (object == nullptr) {
- return nullptr;
- }
-
- const ModifierLog *eval_log = nullptr;
- LISTBASE_FOREACH (ModifierData *, md, &object->modifiers) {
- if (md->type == eModifierType_Nodes) {
- if (md->name == modifier_name) {
- NodesModifierData *nmd = (NodesModifierData *)md;
- eval_log = (const ModifierLog *)nmd->runtime_eval_log;
- break;
- }
- }
- }
- if (eval_log == nullptr) {
- return nullptr;
- }
-
- const TreeLog *tree_log = &eval_log->root_tree();
- for (SpreadsheetContextNode *context : node_contexts.drop_back(1)) {
- tree_log = tree_log->lookup_child_log(context->node_name);
- if (tree_log == nullptr) {
- return nullptr;
- }
- }
- const NodeLog *node_log = tree_log->lookup_node_log(node_contexts.last()->node_name);
- return node_log;
-}
-
-void LocalGeoLogger::log_value_for_sockets(Span<DSocket> sockets, GPointer value)
-{
- const CPPType &type = *value.type();
- Span<DSocket> copied_sockets = allocator_->construct_array_copy(sockets);
- if (type.is<GeometrySet>()) {
- bool log_full_geometry = false;
- for (const DSocket &socket : sockets) {
- if (main_logger_->log_full_sockets_.contains(socket)) {
- log_full_geometry = true;
- break;
- }
- }
-
- const GeometrySet &geometry_set = *value.get<GeometrySet>();
- destruct_ptr<GeometryValueLog> value_log = allocator_->construct<GeometryValueLog>(
- geometry_set, log_full_geometry);
- values_.append({copied_sockets, std::move(value_log)});
- }
- else if (const ValueOrFieldCPPType *value_or_field_type =
- dynamic_cast<const ValueOrFieldCPPType *>(&type)) {
- const void *value_or_field = value.get();
- if (value_or_field_type->is_field(value_or_field)) {
- GField field = *value_or_field_type->get_field_ptr(value_or_field);
- bool log_full_field = false;
- if (!field.node().depends_on_input()) {
- /* Always log constant fields so that their value can be shown in socket inspection.
- * In the future we can also evaluate the field here and only store the value. */
- log_full_field = true;
- }
- if (!log_full_field) {
- for (const DSocket &socket : sockets) {
- if (main_logger_->log_full_sockets_.contains(socket)) {
- log_full_field = true;
- break;
- }
- }
- }
- destruct_ptr<GFieldValueLog> value_log = allocator_->construct<GFieldValueLog>(
- std::move(field), log_full_field);
- values_.append({copied_sockets, std::move(value_log)});
- }
- else {
- const CPPType &base_type = value_or_field_type->base_type();
- const void *value = value_or_field_type->get_value_ptr(value_or_field);
- void *buffer = allocator_->allocate(base_type.size(), base_type.alignment());
- base_type.copy_construct(value, buffer);
- destruct_ptr<GenericValueLog> value_log = allocator_->construct<GenericValueLog>(
- GMutablePointer{base_type, buffer});
- values_.append({copied_sockets, std::move(value_log)});
- }
- }
- else {
- void *buffer = allocator_->allocate(type.size(), type.alignment());
- type.copy_construct(value.get(), buffer);
- destruct_ptr<GenericValueLog> value_log = allocator_->construct<GenericValueLog>(
- GMutablePointer{type, buffer});
- values_.append({copied_sockets, std::move(value_log)});
- }
-}
-
-void LocalGeoLogger::log_multi_value_socket(DSocket socket, Span<GPointer> values)
-{
- /* Doesn't have to be logged currently. */
- UNUSED_VARS(socket, values);
-}
-
-void LocalGeoLogger::log_node_warning(DNode node, NodeWarningType type, std::string message)
-{
- node_warnings_.append({node, {type, std::move(message)}});
-}
-
-void LocalGeoLogger::log_execution_time(DNode node, std::chrono::microseconds exec_time)
-{
- node_exec_times_.append({node, exec_time});
-}
-
-void LocalGeoLogger::log_used_named_attribute(DNode node,
- std::string attribute_name,
- eNamedAttrUsage usage)
-{
- used_named_attributes_.append({node, {std::move(attribute_name), usage}});
-}
-
-void LocalGeoLogger::log_debug_message(DNode node, std::string message)
-{
- node_debug_messages_.append({node, std::move(message)});
-}
-
-} // namespace blender::nodes::geometry_nodes_eval_log
diff --git a/source/blender/nodes/intern/geometry_nodes_lazy_function.cc b/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
new file mode 100644
index 00000000000..197f0997160
--- /dev/null
+++ b/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
@@ -0,0 +1,1442 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/**
+ * This file mainly converts a #bNodeTree into a lazy-function graph. This generally works by
+ * creating a lazy-function for every node, which is then put into the lazy-function graph. Then
+ * the nodes in the new graph are linked based on links in the original #bNodeTree. Some additional
+ * nodes are inserted for things like type conversions and multi-input sockets.
+ *
+ * Currently, lazy-functions are even created for nodes that don't strictly require it, like
+ * reroutes or muted nodes. In the future we could avoid that at the cost of additional code
+ * complexity. So far, this does not seem to be a performance issue.
+ */
+
+#include "NOD_geometry_exec.hh"
+#include "NOD_geometry_nodes_lazy_function.hh"
+#include "NOD_multi_function.hh"
+#include "NOD_node_declaration.hh"
+
+#include "BLI_lazy_threading.hh"
+#include "BLI_map.hh"
+
+#include "DNA_ID.h"
+
+#include "BKE_compute_contexts.hh"
+#include "BKE_geometry_set.hh"
+#include "BKE_type_conversions.hh"
+
+#include "FN_field_cpp_type.hh"
+#include "FN_lazy_function_graph_executor.hh"
+
+#include "DEG_depsgraph_query.h"
+
+namespace blender::nodes {
+
+using fn::ValueOrField;
+using fn::ValueOrFieldCPPType;
+using namespace fn::multi_function_types;
+
+static const CPPType *get_socket_cpp_type(const bNodeSocketType &typeinfo)
+{
+ const CPPType *type = typeinfo.geometry_nodes_cpp_type;
+ if (type == nullptr) {
+ return nullptr;
+ }
+ BLI_assert(type->has_special_member_functions());
+ return type;
+}
+
+static const CPPType *get_socket_cpp_type(const bNodeSocket &socket)
+{
+ return get_socket_cpp_type(*socket.typeinfo);
+}
+
+static const CPPType *get_vector_type(const CPPType &type)
+{
+ /* This could be generalized in the future. For now we only support a small set of vectors. */
+ if (type.is<GeometrySet>()) {
+ return &CPPType::get<Vector<GeometrySet>>();
+ }
+ if (type.is<ValueOrField<std::string>>()) {
+ return &CPPType::get<Vector<ValueOrField<std::string>>>();
+ }
+ return nullptr;
+}
+
+/**
+ * Checks which sockets of the node are available and creates corresponding inputs/outputs on the
+ * lazy-function.
+ */
+static void lazy_function_interface_from_node(const bNode &node,
+ Vector<const bNodeSocket *> &r_used_inputs,
+ Vector<const bNodeSocket *> &r_used_outputs,
+ Vector<lf::Input> &r_inputs,
+ Vector<lf::Output> &r_outputs)
+{
+ const bool is_muted = node.is_muted();
+ const bool supports_laziness = node.typeinfo->geometry_node_execute_supports_laziness ||
+ node.is_group();
+ const lf::ValueUsage input_usage = supports_laziness ? lf::ValueUsage::Maybe :
+ lf::ValueUsage::Used;
+ for (const bNodeSocket *socket : node.input_sockets()) {
+ if (!socket->is_available()) {
+ continue;
+ }
+ const CPPType *type = get_socket_cpp_type(*socket);
+ if (type == nullptr) {
+ continue;
+ }
+ if (socket->is_multi_input() && !is_muted) {
+ type = get_vector_type(*type);
+ }
+ r_inputs.append({socket->identifier, *type, input_usage});
+ r_used_inputs.append(socket);
+ }
+ for (const bNodeSocket *socket : node.output_sockets()) {
+ if (!socket->is_available()) {
+ continue;
+ }
+ const CPPType *type = get_socket_cpp_type(*socket);
+ if (type == nullptr) {
+ continue;
+ }
+ r_outputs.append({socket->identifier, *type});
+ r_used_outputs.append(socket);
+ }
+}
+
+/**
+ * Used for most normal geometry nodes like Subdivision Surface and Set Position.
+ */
+class LazyFunctionForGeometryNode : public LazyFunction {
+ private:
+ const bNode &node_;
+
+ public:
+ LazyFunctionForGeometryNode(const bNode &node,
+ Vector<const bNodeSocket *> &r_used_inputs,
+ Vector<const bNodeSocket *> &r_used_outputs)
+ : node_(node)
+ {
+ BLI_assert(node.typeinfo->geometry_node_execute != nullptr);
+ debug_name_ = node.name;
+ lazy_function_interface_from_node(node, r_used_inputs, r_used_outputs, inputs_, outputs_);
+ }
+
+ void execute_impl(lf::Params &params, const lf::Context &context) const override
+ {
+ GeoNodesLFUserData *user_data = dynamic_cast<GeoNodesLFUserData *>(context.user_data);
+ BLI_assert(user_data != nullptr);
+
+ GeoNodeExecParams geo_params{node_, params, context};
+
+ geo_eval_log::TimePoint start_time = geo_eval_log::Clock::now();
+ node_.typeinfo->geometry_node_execute(geo_params);
+ geo_eval_log::TimePoint end_time = geo_eval_log::Clock::now();
+
+ if (geo_eval_log::GeoModifierLog *modifier_log = user_data->modifier_data->eval_log) {
+ geo_eval_log::GeoTreeLogger &tree_logger = modifier_log->get_local_tree_logger(
+ *user_data->compute_context);
+ tree_logger.node_execution_times.append(
+ {tree_logger.allocator->copy_string(node_.name), start_time, end_time});
+ }
+ }
+};
+
+/**
+ * Used to gather all inputs of a multi-input socket. A separate node is necessary because
+ * multi-inputs are not supported in lazy-function graphs.
+ */
+class LazyFunctionForMultiInput : public LazyFunction {
+ private:
+ const CPPType *base_type_;
+
+ public:
+ LazyFunctionForMultiInput(const bNodeSocket &socket)
+ {
+ debug_name_ = "Multi Input";
+ base_type_ = get_socket_cpp_type(socket);
+ BLI_assert(base_type_ != nullptr);
+ BLI_assert(socket.is_multi_input());
+ const bNodeTree &btree = socket.owner_tree();
+ for (const bNodeLink *link : socket.directly_linked_links()) {
+ if (!(link->is_muted() || nodeIsDanglingReroute(&btree, link->fromnode))) {
+ inputs_.append({"Input", *base_type_});
+ }
+ }
+ const CPPType *vector_type = get_vector_type(*base_type_);
+ BLI_assert(vector_type != nullptr);
+ outputs_.append({"Output", *vector_type});
+ }
+
+ void execute_impl(lf::Params &params, const lf::Context & /*context*/) const override
+ {
+ /* Currently we only have multi-inputs for geometry and string sockets. This could be
+ * generalized in the future. */
+ base_type_->to_static_type_tag<GeometrySet, ValueOrField<std::string>>([&](auto type_tag) {
+ using T = typename decltype(type_tag)::type;
+ if constexpr (std::is_void_v<T>) {
+ /* This type is not supported in this node for now. */
+ BLI_assert_unreachable();
+ }
+ else {
+ void *output_ptr = params.get_output_data_ptr(0);
+ Vector<T> &values = *new (output_ptr) Vector<T>();
+ for (const int i : inputs_.index_range()) {
+ values.append(params.extract_input<T>(i));
+ }
+ params.output_set(0);
+ }
+ });
+ }
+};
+
+/**
+ * Simple lazy-function that just forwards the input.
+ */
+class LazyFunctionForRerouteNode : public LazyFunction {
+ public:
+ LazyFunctionForRerouteNode(const CPPType &type)
+ {
+ debug_name_ = "Reroute";
+ inputs_.append({"Input", type});
+ outputs_.append({"Output", type});
+ }
+
+ void execute_impl(lf::Params &params, const lf::Context & /*context*/) const override
+ {
+ void *input_value = params.try_get_input_data_ptr(0);
+ void *output_value = params.get_output_data_ptr(0);
+ BLI_assert(input_value != nullptr);
+ BLI_assert(output_value != nullptr);
+ const CPPType &type = *inputs_[0].type;
+ type.move_construct(input_value, output_value);
+ params.output_set(0);
+ }
+};
+
+/**
+ * Lazy functions for nodes whose type cannot be found. An undefined function just outputs default
+ * values. It's useful to have so other parts of the conversion don't have to care about undefined
+ * nodes.
+ */
+class LazyFunctionForUndefinedNode : public LazyFunction {
+ public:
+ LazyFunctionForUndefinedNode(const bNode &node, Vector<const bNodeSocket *> &r_used_outputs)
+ {
+ debug_name_ = "Undefined";
+ Vector<const bNodeSocket *> dummy_used_inputs;
+ Vector<lf::Input> dummy_inputs;
+ lazy_function_interface_from_node(
+ node, dummy_used_inputs, r_used_outputs, dummy_inputs, outputs_);
+ }
+
+ void execute_impl(lf::Params &params, const lf::Context & /*context*/) const override
+ {
+ params.set_default_remaining_outputs();
+ }
+};
+
+/**
+ * Executes a multi-function. If all inputs are single values, the results will also be single
+ * values. If any input is a field, the outputs will also be fields.
+ */
+static void execute_multi_function_on_value_or_field(
+ const MultiFunction &fn,
+ const std::shared_ptr<MultiFunction> &owned_fn,
+ const Span<const ValueOrFieldCPPType *> input_types,
+ const Span<const ValueOrFieldCPPType *> output_types,
+ const Span<const void *> input_values,
+ const Span<void *> output_values)
+{
+ BLI_assert(fn.param_amount() == input_types.size() + output_types.size());
+ BLI_assert(input_types.size() == input_values.size());
+ BLI_assert(output_types.size() == output_values.size());
+
+ /* Check if any input is a field. */
+ bool any_input_is_field = false;
+ for (const int i : input_types.index_range()) {
+ const ValueOrFieldCPPType &type = *input_types[i];
+ const void *value_or_field = input_values[i];
+ if (type.is_field(value_or_field)) {
+ any_input_is_field = true;
+ break;
+ }
+ }
+
+ if (any_input_is_field) {
+ /* Convert all inputs into fields, so that they can be used as input in the new field. */
+ Vector<GField> input_fields;
+ for (const int i : input_types.index_range()) {
+ const ValueOrFieldCPPType &type = *input_types[i];
+ const void *value_or_field = input_values[i];
+ input_fields.append(type.as_field(value_or_field));
+ }
+
+ /* Construct the new field node. */
+ std::shared_ptr<fn::FieldOperation> operation;
+ if (owned_fn) {
+ operation = std::make_shared<fn::FieldOperation>(owned_fn, std::move(input_fields));
+ }
+ else {
+ operation = std::make_shared<fn::FieldOperation>(fn, std::move(input_fields));
+ }
+
+ /* Store the new fields in the output. */
+ for (const int i : output_types.index_range()) {
+ const ValueOrFieldCPPType &type = *output_types[i];
+ void *value_or_field = output_values[i];
+ type.construct_from_field(value_or_field, GField{operation, i});
+ }
+ }
+ else {
+ /* In this case, the multi-function is evaluated directly. */
+ MFParamsBuilder params{fn, 1};
+ MFContextBuilder context;
+
+ for (const int i : input_types.index_range()) {
+ const ValueOrFieldCPPType &type = *input_types[i];
+ const CPPType &base_type = type.base_type();
+ const void *value_or_field = input_values[i];
+ const void *value = type.get_value_ptr(value_or_field);
+ params.add_readonly_single_input(GVArray::ForSingleRef(base_type, 1, value));
+ }
+ for (const int i : output_types.index_range()) {
+ const ValueOrFieldCPPType &type = *output_types[i];
+ const CPPType &base_type = type.base_type();
+ void *value_or_field = output_values[i];
+ type.default_construct(value_or_field);
+ void *value = type.get_value_ptr(value_or_field);
+ base_type.destruct(value);
+ params.add_uninitialized_single_output(GMutableSpan{base_type, value, 1});
+ }
+ fn.call(IndexRange(1), params, context);
+ }
+}
+
+/**
+ * Behavior of muted nodes:
+ * - Some inputs are forwarded to outputs without changes.
+ * - Some inputs are converted to a different type which becomes the output.
+ * - Some outputs are value initialized because they don't have a corresponding input.
+ */
+class LazyFunctionForMutedNode : public LazyFunction {
+ private:
+ Array<int> input_by_output_index_;
+
+ public:
+ LazyFunctionForMutedNode(const bNode &node,
+ Vector<const bNodeSocket *> &r_used_inputs,
+ Vector<const bNodeSocket *> &r_used_outputs)
+ {
+ debug_name_ = "Muted";
+ lazy_function_interface_from_node(node, r_used_inputs, r_used_outputs, inputs_, outputs_);
+ for (lf::Input &fn_input : inputs_) {
+ fn_input.usage = lf::ValueUsage::Maybe;
+ }
+
+ for (lf::Input &fn_input : inputs_) {
+ fn_input.usage = lf::ValueUsage::Unused;
+ }
+
+ input_by_output_index_.reinitialize(outputs_.size());
+ input_by_output_index_.fill(-1);
+ for (const bNodeLink *internal_link : node.internal_links_span()) {
+ const int input_i = r_used_inputs.first_index_of_try(internal_link->fromsock);
+ const int output_i = r_used_outputs.first_index_of_try(internal_link->tosock);
+ if (ELEM(-1, input_i, output_i)) {
+ continue;
+ }
+ input_by_output_index_[output_i] = input_i;
+ inputs_[input_i].usage = lf::ValueUsage::Maybe;
+ }
+ }
+
+ void execute_impl(lf::Params &params, const lf::Context & /*context*/) const override
+ {
+ for (const int output_i : outputs_.index_range()) {
+ if (params.output_was_set(output_i)) {
+ continue;
+ }
+ const CPPType &output_type = *outputs_[output_i].type;
+ void *output_value = params.get_output_data_ptr(output_i);
+ const int input_i = input_by_output_index_[output_i];
+ if (input_i == -1) {
+ /* The output does not have a corresponding input. */
+ output_type.value_initialize(output_value);
+ params.output_set(output_i);
+ continue;
+ }
+ const void *input_value = params.try_get_input_data_ptr_or_request(input_i);
+ if (input_value == nullptr) {
+ continue;
+ }
+ const CPPType &input_type = *inputs_[input_i].type;
+ if (input_type == output_type) {
+ /* Forward the value as is. */
+ input_type.copy_construct(input_value, output_value);
+ params.output_set(output_i);
+ continue;
+ }
+ /* Perform a type conversion and then format the value. */
+ const bke::DataTypeConversions &conversions = bke::get_implicit_type_conversions();
+ const auto *from_field_type = dynamic_cast<const ValueOrFieldCPPType *>(&input_type);
+ const auto *to_field_type = dynamic_cast<const ValueOrFieldCPPType *>(&output_type);
+ if (from_field_type != nullptr && to_field_type != nullptr) {
+ const CPPType &from_base_type = from_field_type->base_type();
+ const CPPType &to_base_type = to_field_type->base_type();
+ if (conversions.is_convertible(from_base_type, to_base_type)) {
+ const MultiFunction &multi_fn = *conversions.get_conversion_multi_function(
+ MFDataType::ForSingle(from_base_type), MFDataType::ForSingle(to_base_type));
+ execute_multi_function_on_value_or_field(
+ multi_fn, {}, {from_field_type}, {to_field_type}, {input_value}, {output_value});
+ }
+ params.output_set(output_i);
+ continue;
+ }
+ /* Use a value initialization if the conversion does not work. */
+ output_type.value_initialize(output_value);
+ params.output_set(output_i);
+ }
+ }
+};
+
+/**
+ * Type conversions are generally implemented as multi-functions. This node checks if the input is
+ * a field or single value and outputs a field or single value respectively.
+ */
+class LazyFunctionForMultiFunctionConversion : public LazyFunction {
+ private:
+ const MultiFunction &fn_;
+ const ValueOrFieldCPPType &from_type_;
+ const ValueOrFieldCPPType &to_type_;
+ const Vector<const bNodeSocket *> target_sockets_;
+
+ public:
+ LazyFunctionForMultiFunctionConversion(const MultiFunction &fn,
+ const ValueOrFieldCPPType &from,
+ const ValueOrFieldCPPType &to,
+ Vector<const bNodeSocket *> &&target_sockets)
+ : fn_(fn), from_type_(from), to_type_(to), target_sockets_(std::move(target_sockets))
+ {
+ debug_name_ = "Convert";
+ inputs_.append({"From", from});
+ outputs_.append({"To", to});
+ }
+
+ void execute_impl(lf::Params &params, const lf::Context & /*context*/) const override
+ {
+ const void *from_value = params.try_get_input_data_ptr(0);
+ void *to_value = params.get_output_data_ptr(0);
+ BLI_assert(from_value != nullptr);
+ BLI_assert(to_value != nullptr);
+
+ execute_multi_function_on_value_or_field(
+ fn_, {}, {&from_type_}, {&to_type_}, {from_value}, {to_value});
+
+ params.output_set(0);
+ }
+};
+
+/**
+ * This lazy-function wraps nodes that are implemented as multi-function (mostly math nodes).
+ */
+class LazyFunctionForMultiFunctionNode : public LazyFunction {
+ private:
+ const NodeMultiFunctions::Item fn_item_;
+ Vector<const ValueOrFieldCPPType *> input_types_;
+ Vector<const ValueOrFieldCPPType *> output_types_;
+
+ public:
+ LazyFunctionForMultiFunctionNode(const bNode &node,
+ NodeMultiFunctions::Item fn_item,
+ Vector<const bNodeSocket *> &r_used_inputs,
+ Vector<const bNodeSocket *> &r_used_outputs)
+ : fn_item_(std::move(fn_item))
+ {
+ BLI_assert(fn_item_.fn != nullptr);
+ debug_name_ = node.name;
+ lazy_function_interface_from_node(node, r_used_inputs, r_used_outputs, inputs_, outputs_);
+ for (const lf::Input &fn_input : inputs_) {
+ input_types_.append(dynamic_cast<const ValueOrFieldCPPType *>(fn_input.type));
+ }
+ for (const lf::Output &fn_output : outputs_) {
+ output_types_.append(dynamic_cast<const ValueOrFieldCPPType *>(fn_output.type));
+ }
+ }
+
+ void execute_impl(lf::Params &params, const lf::Context & /*context*/) const override
+ {
+ Vector<const void *> input_values(inputs_.size());
+ Vector<void *> output_values(outputs_.size());
+ for (const int i : inputs_.index_range()) {
+ input_values[i] = params.try_get_input_data_ptr(i);
+ }
+ for (const int i : outputs_.index_range()) {
+ output_values[i] = params.get_output_data_ptr(i);
+ }
+ execute_multi_function_on_value_or_field(
+ *fn_item_.fn, fn_item_.owned_fn, input_types_, output_types_, input_values, output_values);
+ for (const int i : outputs_.index_range()) {
+ params.output_set(i);
+ }
+ }
+};
+
+/**
+ * Some sockets have non-trivial implicit inputs (e.g. the Position input of the Set Position
+ * node). Those are implemented as a separate node that outputs the value.
+ */
+class LazyFunctionForImplicitInput : public LazyFunction {
+ private:
+ /**
+ * The function that generates the implicit input. The passed in memory is uninitialized.
+ */
+ std::function<void(void *)> init_fn_;
+
+ public:
+ LazyFunctionForImplicitInput(const CPPType &type, std::function<void(void *)> init_fn)
+ : init_fn_(std::move(init_fn))
+ {
+ debug_name_ = "Input";
+ outputs_.append({"Output", type});
+ }
+
+ void execute_impl(lf::Params &params, const lf::Context & /*context*/) const override
+ {
+ void *value = params.get_output_data_ptr(0);
+ init_fn_(value);
+ params.output_set(0);
+ }
+};
+
+/**
+ * The viewer node does not have outputs. Instead it is executed because the executor knows that it
+ * has side effects. The side effect is that the inputs to the viewer are logged.
+ */
+class LazyFunctionForViewerNode : public LazyFunction {
+ private:
+ const bNode &bnode_;
+ /** The field is only logged when it is linked. */
+ bool use_field_input_ = true;
+
+ public:
+ LazyFunctionForViewerNode(const bNode &bnode, Vector<const bNodeSocket *> &r_used_inputs)
+ : bnode_(bnode)
+ {
+ debug_name_ = "Viewer";
+ Vector<const bNodeSocket *> dummy_used_outputs;
+ lazy_function_interface_from_node(bnode, r_used_inputs, dummy_used_outputs, inputs_, outputs_);
+ if (!r_used_inputs[1]->is_directly_linked()) {
+ use_field_input_ = false;
+ r_used_inputs.pop_last();
+ inputs_.pop_last();
+ }
+ }
+
+ void execute_impl(lf::Params &params, const lf::Context &context) const override
+ {
+ GeoNodesLFUserData *user_data = dynamic_cast<GeoNodesLFUserData *>(context.user_data);
+ BLI_assert(user_data != nullptr);
+ if (user_data->modifier_data == nullptr) {
+ return;
+ }
+ if (user_data->modifier_data->eval_log == nullptr) {
+ return;
+ }
+
+ GeometrySet geometry = params.extract_input<GeometrySet>(0);
+ const NodeGeometryViewer *storage = static_cast<NodeGeometryViewer *>(bnode_.storage);
+
+ if (use_field_input_) {
+ const void *value_or_field = params.try_get_input_data_ptr(1);
+ BLI_assert(value_or_field != nullptr);
+ const ValueOrFieldCPPType &value_or_field_type = static_cast<const ValueOrFieldCPPType &>(
+ *inputs_[1].type);
+ GField field = value_or_field_type.as_field(value_or_field);
+ const eAttrDomain domain = eAttrDomain(storage->domain);
+ const StringRefNull viewer_attribute_name = ".viewer";
+ if (domain == ATTR_DOMAIN_INSTANCE) {
+ if (geometry.has_instances()) {
+ GeometryComponent &component = geometry.get_component_for_write(
+ GEO_COMPONENT_TYPE_INSTANCES);
+ bke::try_capture_field_on_geometry(
+ component, viewer_attribute_name, ATTR_DOMAIN_INSTANCE, field);
+ }
+ }
+ else {
+ geometry.modify_geometry_sets([&](GeometrySet &geometry) {
+ for (const GeometryComponentType type : {GEO_COMPONENT_TYPE_MESH,
+ GEO_COMPONENT_TYPE_POINT_CLOUD,
+ GEO_COMPONENT_TYPE_CURVE}) {
+ if (geometry.has(type)) {
+ GeometryComponent &component = geometry.get_component_for_write(type);
+ eAttrDomain used_domain = domain;
+ if (used_domain == ATTR_DOMAIN_AUTO) {
+ if (const std::optional<eAttrDomain> detected_domain =
+ bke::try_detect_field_domain(component, field)) {
+ used_domain = *detected_domain;
+ }
+ else {
+ used_domain = type == GEO_COMPONENT_TYPE_MESH ? ATTR_DOMAIN_CORNER :
+ ATTR_DOMAIN_POINT;
+ }
+ }
+ bke::try_capture_field_on_geometry(
+ component, viewer_attribute_name, used_domain, field);
+ }
+ }
+ });
+ }
+ }
+
+ geo_eval_log::GeoTreeLogger &tree_logger =
+ user_data->modifier_data->eval_log->get_local_tree_logger(*user_data->compute_context);
+ tree_logger.log_viewer_node(bnode_, std::move(geometry));
+ }
+};
+
+/**
+ * This lazy-function wraps a group node. Internally it just executes the lazy-function graph of
+ * the referenced group.
+ */
+class LazyFunctionForGroupNode : public LazyFunction {
+ private:
+ const bNode &group_node_;
+ bool has_many_nodes_ = false;
+ bool use_fallback_outputs_ = false;
+ std::optional<GeometryNodesLazyFunctionLogger> lf_logger_;
+ std::optional<GeometryNodesLazyFunctionSideEffectProvider> lf_side_effect_provider_;
+ std::optional<lf::GraphExecutor> graph_executor_;
+
+ public:
+ LazyFunctionForGroupNode(const bNode &group_node,
+ const GeometryNodesLazyFunctionGraphInfo &lf_graph_info,
+ Vector<const bNodeSocket *> &r_used_inputs,
+ Vector<const bNodeSocket *> &r_used_outputs)
+ : group_node_(group_node)
+ {
+ debug_name_ = group_node.name;
+ lazy_function_interface_from_node(
+ group_node, r_used_inputs, r_used_outputs, inputs_, outputs_);
+
+ bNodeTree *group_btree = reinterpret_cast<bNodeTree *>(group_node_.id);
+ BLI_assert(group_btree != nullptr);
+
+ has_many_nodes_ = lf_graph_info.num_inline_nodes_approximate > 1000;
+
+ Vector<const lf::OutputSocket *> graph_inputs;
+ for (const lf::OutputSocket *socket : lf_graph_info.mapping.group_input_sockets) {
+ if (socket != nullptr) {
+ graph_inputs.append(socket);
+ }
+ }
+ Vector<const lf::InputSocket *> graph_outputs;
+ if (const bNode *group_output_bnode = group_btree->group_output_node()) {
+ for (const bNodeSocket *bsocket : group_output_bnode->input_sockets().drop_back(1)) {
+ const lf::Socket *socket = lf_graph_info.mapping.dummy_socket_map.lookup_default(bsocket,
+ nullptr);
+ if (socket != nullptr) {
+ graph_outputs.append(&socket->as_input());
+ }
+ }
+ }
+ else {
+ use_fallback_outputs_ = true;
+ }
+
+ lf_logger_.emplace(lf_graph_info);
+ lf_side_effect_provider_.emplace();
+ graph_executor_.emplace(lf_graph_info.graph,
+ std::move(graph_inputs),
+ std::move(graph_outputs),
+ &*lf_logger_,
+ &*lf_side_effect_provider_);
+ }
+
+ void execute_impl(lf::Params &params, const lf::Context &context) const override
+ {
+ GeoNodesLFUserData *user_data = dynamic_cast<GeoNodesLFUserData *>(context.user_data);
+ BLI_assert(user_data != nullptr);
+
+ if (has_many_nodes_) {
+ /* If the called node group has many nodes, it's likely that executing it takes a while even
+ * if every individual node is very small. */
+ lazy_threading::send_hint();
+ }
+ if (use_fallback_outputs_) {
+ /* The node group itself does not have an output node, so use default values as outputs.
+ * The group should still be executed in case it has side effects. */
+ params.set_default_remaining_outputs();
+ }
+
+ /* The compute context changes when entering a node group. */
+ bke::NodeGroupComputeContext compute_context{user_data->compute_context, group_node_.name};
+ GeoNodesLFUserData group_user_data = *user_data;
+ group_user_data.compute_context = &compute_context;
+
+ lf::Context group_context = context;
+ group_context.user_data = &group_user_data;
+
+ graph_executor_->execute(params, group_context);
+ }
+
+ void *init_storage(LinearAllocator<> &allocator) const override
+ {
+ return graph_executor_->init_storage(allocator);
+ }
+
+ void destruct_storage(void *storage) const override
+ {
+ graph_executor_->destruct_storage(storage);
+ }
+};
+
+static GMutablePointer get_socket_default_value(LinearAllocator<> &allocator,
+ const bNodeSocket &bsocket)
+{
+ const bNodeSocketType &typeinfo = *bsocket.typeinfo;
+ const CPPType *type = get_socket_cpp_type(typeinfo);
+ if (type == nullptr) {
+ return {};
+ }
+ void *buffer = allocator.allocate(type->size(), type->alignment());
+ typeinfo.get_geometry_nodes_cpp_value(bsocket, buffer);
+ return {type, buffer};
+}
+
+/**
+ * Utility class to build a lazy-function graph based on a geometry nodes tree.
+ * This is mainly a separate class because it makes it easier to have variables that can be
+ * accessed by many functions.
+ */
+struct GeometryNodesLazyFunctionGraphBuilder {
+ private:
+ const bNodeTree &btree_;
+ GeometryNodesLazyFunctionGraphInfo *lf_graph_info_;
+ lf::Graph *lf_graph_;
+ GeometryNodeLazyFunctionGraphMapping *mapping_;
+ MultiValueMap<const bNodeSocket *, lf::InputSocket *> input_socket_map_;
+ Map<const bNodeSocket *, lf::OutputSocket *> output_socket_map_;
+ Map<const bNodeSocket *, lf::Node *> multi_input_socket_nodes_;
+ const bke::DataTypeConversions *conversions_;
+
+ /**
+ * All group input nodes are combined into one dummy node in the lazy-function graph.
+ * If some input has an invalid type, it is ignored in the new graph. In this case null and -1 is
+ * used in the vectors below.
+ */
+ Vector<const CPPType *> group_input_types_;
+ Vector<int> group_input_indices_;
+ lf::DummyNode *group_input_lf_node_;
+
+ /**
+ * The output types or null if an output is invalid. Each group output node gets a separate
+ * corresponding dummy node in the new graph.
+ */
+ Vector<const CPPType *> group_output_types_;
+ Vector<int> group_output_indices_;
+
+ public:
+ GeometryNodesLazyFunctionGraphBuilder(const bNodeTree &btree,
+ GeometryNodesLazyFunctionGraphInfo &lf_graph_info)
+ : btree_(btree), lf_graph_info_(&lf_graph_info)
+ {
+ }
+
+ void build()
+ {
+ btree_.ensure_topology_cache();
+
+ lf_graph_ = &lf_graph_info_->graph;
+ mapping_ = &lf_graph_info_->mapping;
+ conversions_ = &bke::get_implicit_type_conversions();
+
+ this->prepare_node_multi_functions();
+ this->prepare_group_inputs();
+ this->prepare_group_outputs();
+ this->build_group_input_node();
+ this->handle_nodes();
+ this->handle_links();
+ this->add_default_inputs();
+
+ lf_graph_->update_node_indices();
+ lf_graph_info_->num_inline_nodes_approximate += lf_graph_->nodes().size();
+ }
+
+ private:
+ void prepare_node_multi_functions()
+ {
+ lf_graph_info_->node_multi_functions = std::make_unique<NodeMultiFunctions>(btree_);
+ }
+
+ void prepare_group_inputs()
+ {
+ LISTBASE_FOREACH (const bNodeSocket *, interface_bsocket, &btree_.inputs) {
+ const CPPType *type = get_socket_cpp_type(*interface_bsocket->typeinfo);
+ if (type != nullptr) {
+ const int index = group_input_types_.append_and_get_index(type);
+ group_input_indices_.append(index);
+ }
+ else {
+ group_input_indices_.append(-1);
+ }
+ }
+ }
+
+ void prepare_group_outputs()
+ {
+ LISTBASE_FOREACH (const bNodeSocket *, interface_bsocket, &btree_.outputs) {
+ const CPPType *type = get_socket_cpp_type(*interface_bsocket->typeinfo);
+ if (type != nullptr) {
+ const int index = group_output_types_.append_and_get_index(type);
+ group_output_indices_.append(index);
+ }
+ else {
+ group_output_indices_.append(-1);
+ }
+ }
+ }
+
+ void build_group_input_node()
+ {
+ /* Create a dummy node for the group inputs. */
+ group_input_lf_node_ = &lf_graph_->add_dummy({}, group_input_types_);
+ for (const int group_input_index : group_input_indices_) {
+ if (group_input_index == -1) {
+ mapping_->group_input_sockets.append(nullptr);
+ }
+ else {
+ mapping_->group_input_sockets.append(&group_input_lf_node_->output(group_input_index));
+ }
+ }
+ }
+
+ void handle_nodes()
+ {
+ /* Insert all nodes into the lazy function graph. */
+ for (const bNode *bnode : btree_.all_nodes()) {
+ const bNodeType *node_type = bnode->typeinfo;
+ if (node_type == nullptr) {
+ continue;
+ }
+ if (bnode->is_muted()) {
+ this->handle_muted_node(*bnode);
+ continue;
+ }
+ switch (node_type->type) {
+ case NODE_FRAME: {
+ /* Ignored. */
+ break;
+ }
+ case NODE_REROUTE: {
+ this->handle_reroute_node(*bnode);
+ break;
+ }
+ case NODE_GROUP_INPUT: {
+ this->handle_group_input_node(*bnode);
+ break;
+ }
+ case NODE_GROUP_OUTPUT: {
+ this->handle_group_output_node(*bnode);
+ break;
+ }
+ case NODE_CUSTOM_GROUP:
+ case NODE_GROUP: {
+ this->handle_group_node(*bnode);
+ break;
+ }
+ case GEO_NODE_VIEWER: {
+ this->handle_viewer_node(*bnode);
+ break;
+ }
+ default: {
+ if (node_type->geometry_node_execute) {
+ this->handle_geometry_node(*bnode);
+ break;
+ }
+ const NodeMultiFunctions::Item &fn_item = lf_graph_info_->node_multi_functions->try_get(
+ *bnode);
+ if (fn_item.fn != nullptr) {
+ this->handle_multi_function_node(*bnode, fn_item);
+ break;
+ }
+ if (node_type == &NodeTypeUndefined) {
+ this->handle_undefined_node(*bnode);
+ break;
+ }
+ /* Nodes that don't match any of the criteria above are just ignored. */
+ break;
+ }
+ }
+ }
+ }
+
+ void handle_muted_node(const bNode &bnode)
+ {
+ Vector<const bNodeSocket *> used_inputs;
+ Vector<const bNodeSocket *> used_outputs;
+ auto lazy_function = std::make_unique<LazyFunctionForMutedNode>(
+ bnode, used_inputs, used_outputs);
+ lf::Node &lf_node = lf_graph_->add_function(*lazy_function);
+ lf_graph_info_->functions.append(std::move(lazy_function));
+ for (const int i : used_inputs.index_range()) {
+ const bNodeSocket &bsocket = *used_inputs[i];
+ lf::InputSocket &lf_socket = lf_node.input(i);
+ input_socket_map_.add(&bsocket, &lf_socket);
+ mapping_->bsockets_by_lf_socket_map.add(&lf_socket, &bsocket);
+ }
+ for (const int i : used_outputs.index_range()) {
+ const bNodeSocket &bsocket = *used_outputs[i];
+ lf::OutputSocket &lf_socket = lf_node.output(i);
+ output_socket_map_.add_new(&bsocket, &lf_socket);
+ mapping_->bsockets_by_lf_socket_map.add(&lf_socket, &bsocket);
+ }
+ }
+
+ void handle_reroute_node(const bNode &bnode)
+ {
+ const bNodeSocket &input_bsocket = bnode.input_socket(0);
+ const bNodeSocket &output_bsocket = bnode.output_socket(0);
+ const CPPType *type = get_socket_cpp_type(input_bsocket);
+ if (type == nullptr) {
+ return;
+ }
+
+ auto lazy_function = std::make_unique<LazyFunctionForRerouteNode>(*type);
+ lf::Node &lf_node = lf_graph_->add_function(*lazy_function);
+ lf_graph_info_->functions.append(std::move(lazy_function));
+
+ lf::InputSocket &lf_input = lf_node.input(0);
+ lf::OutputSocket &lf_output = lf_node.output(0);
+ input_socket_map_.add(&input_bsocket, &lf_input);
+ output_socket_map_.add_new(&output_bsocket, &lf_output);
+ mapping_->bsockets_by_lf_socket_map.add(&lf_input, &input_bsocket);
+ mapping_->bsockets_by_lf_socket_map.add(&lf_output, &output_bsocket);
+ }
+
+ void handle_group_input_node(const bNode &bnode)
+ {
+ for (const int btree_index : group_input_indices_.index_range()) {
+ const int lf_index = group_input_indices_[btree_index];
+ if (lf_index == -1) {
+ continue;
+ }
+ const bNodeSocket &bsocket = bnode.output_socket(btree_index);
+ lf::OutputSocket &lf_socket = group_input_lf_node_->output(lf_index);
+ output_socket_map_.add_new(&bsocket, &lf_socket);
+ mapping_->dummy_socket_map.add_new(&bsocket, &lf_socket);
+ mapping_->bsockets_by_lf_socket_map.add(&lf_socket, &bsocket);
+ }
+ }
+
+ void handle_group_output_node(const bNode &bnode)
+ {
+ lf::DummyNode &group_output_lf_node = lf_graph_->add_dummy(group_output_types_, {});
+ for (const int btree_index : group_output_indices_.index_range()) {
+ const int lf_index = group_output_indices_[btree_index];
+ if (lf_index == -1) {
+ continue;
+ }
+ const bNodeSocket &bsocket = bnode.input_socket(btree_index);
+ lf::InputSocket &lf_socket = group_output_lf_node.input(lf_index);
+ input_socket_map_.add(&bsocket, &lf_socket);
+ mapping_->dummy_socket_map.add(&bsocket, &lf_socket);
+ mapping_->bsockets_by_lf_socket_map.add(&lf_socket, &bsocket);
+ }
+ }
+
+ void handle_group_node(const bNode &bnode)
+ {
+ const bNodeTree *group_btree = reinterpret_cast<bNodeTree *>(bnode.id);
+ if (group_btree == nullptr) {
+ return;
+ }
+ const GeometryNodesLazyFunctionGraphInfo *group_lf_graph_info =
+ ensure_geometry_nodes_lazy_function_graph(*group_btree);
+ if (group_lf_graph_info == nullptr) {
+ return;
+ }
+
+ Vector<const bNodeSocket *> used_inputs;
+ Vector<const bNodeSocket *> used_outputs;
+ auto lazy_function = std::make_unique<LazyFunctionForGroupNode>(
+ bnode, *group_lf_graph_info, used_inputs, used_outputs);
+ lf::FunctionNode &lf_node = lf_graph_->add_function(*lazy_function);
+ lf_graph_info_->functions.append(std::move(lazy_function));
+ for (const int i : used_inputs.index_range()) {
+ const bNodeSocket &bsocket = *used_inputs[i];
+ BLI_assert(!bsocket.is_multi_input());
+ lf::InputSocket &lf_socket = lf_node.input(i);
+ input_socket_map_.add(&bsocket, &lf_socket);
+ mapping_->bsockets_by_lf_socket_map.add(&lf_socket, &bsocket);
+ }
+ for (const int i : used_outputs.index_range()) {
+ const bNodeSocket &bsocket = *used_outputs[i];
+ lf::OutputSocket &lf_socket = lf_node.output(i);
+ output_socket_map_.add_new(&bsocket, &lf_socket);
+ mapping_->bsockets_by_lf_socket_map.add(&lf_socket, &bsocket);
+ }
+ mapping_->group_node_map.add(&bnode, &lf_node);
+ lf_graph_info_->num_inline_nodes_approximate +=
+ group_lf_graph_info->num_inline_nodes_approximate;
+ }
+
+ void handle_geometry_node(const bNode &bnode)
+ {
+ Vector<const bNodeSocket *> used_inputs;
+ Vector<const bNodeSocket *> used_outputs;
+ auto lazy_function = std::make_unique<LazyFunctionForGeometryNode>(
+ bnode, used_inputs, used_outputs);
+ lf::Node &lf_node = lf_graph_->add_function(*lazy_function);
+ lf_graph_info_->functions.append(std::move(lazy_function));
+
+ for (const int i : used_inputs.index_range()) {
+ const bNodeSocket &bsocket = *used_inputs[i];
+ lf::InputSocket &lf_socket = lf_node.input(i);
+
+ if (bsocket.is_multi_input()) {
+ auto multi_input_lazy_function = std::make_unique<LazyFunctionForMultiInput>(bsocket);
+ lf::Node &lf_multi_input_node = lf_graph_->add_function(*multi_input_lazy_function);
+ lf_graph_info_->functions.append(std::move(multi_input_lazy_function));
+ lf_graph_->add_link(lf_multi_input_node.output(0), lf_socket);
+ multi_input_socket_nodes_.add_new(&bsocket, &lf_multi_input_node);
+ for (lf::InputSocket *lf_multi_input_socket : lf_multi_input_node.inputs()) {
+ mapping_->bsockets_by_lf_socket_map.add(lf_multi_input_socket, &bsocket);
+ }
+ }
+ else {
+ input_socket_map_.add(&bsocket, &lf_socket);
+ mapping_->bsockets_by_lf_socket_map.add(&lf_socket, &bsocket);
+ }
+ }
+ for (const int i : used_outputs.index_range()) {
+ const bNodeSocket &bsocket = *used_outputs[i];
+ lf::OutputSocket &lf_socket = lf_node.output(i);
+ output_socket_map_.add_new(&bsocket, &lf_socket);
+ mapping_->bsockets_by_lf_socket_map.add(&lf_socket, &bsocket);
+ }
+ }
+
+ void handle_multi_function_node(const bNode &bnode, const NodeMultiFunctions::Item &fn_item)
+ {
+ Vector<const bNodeSocket *> used_inputs;
+ Vector<const bNodeSocket *> used_outputs;
+ auto lazy_function = std::make_unique<LazyFunctionForMultiFunctionNode>(
+ bnode, fn_item, used_inputs, used_outputs);
+ lf::Node &lf_node = lf_graph_->add_function(*lazy_function);
+ lf_graph_info_->functions.append(std::move(lazy_function));
+
+ for (const int i : used_inputs.index_range()) {
+ const bNodeSocket &bsocket = *used_inputs[i];
+ BLI_assert(!bsocket.is_multi_input());
+ lf::InputSocket &lf_socket = lf_node.input(i);
+ input_socket_map_.add(&bsocket, &lf_socket);
+ mapping_->bsockets_by_lf_socket_map.add(&lf_socket, &bsocket);
+ }
+ for (const int i : used_outputs.index_range()) {
+ const bNodeSocket &bsocket = *used_outputs[i];
+ lf::OutputSocket &lf_socket = lf_node.output(i);
+ output_socket_map_.add(&bsocket, &lf_socket);
+ mapping_->bsockets_by_lf_socket_map.add(&lf_socket, &bsocket);
+ }
+ }
+
+ void handle_viewer_node(const bNode &bnode)
+ {
+ Vector<const bNodeSocket *> used_inputs;
+ auto lazy_function = std::make_unique<LazyFunctionForViewerNode>(bnode, used_inputs);
+ lf::FunctionNode &lf_node = lf_graph_->add_function(*lazy_function);
+ lf_graph_info_->functions.append(std::move(lazy_function));
+
+ for (const int i : used_inputs.index_range()) {
+ const bNodeSocket &bsocket = *used_inputs[i];
+ lf::InputSocket &lf_socket = lf_node.input(i);
+ input_socket_map_.add(&bsocket, &lf_socket);
+ mapping_->bsockets_by_lf_socket_map.add(&lf_socket, &bsocket);
+ }
+
+ mapping_->viewer_node_map.add(&bnode, &lf_node);
+ }
+
+ void handle_undefined_node(const bNode &bnode)
+ {
+ Vector<const bNodeSocket *> used_outputs;
+ auto lazy_function = std::make_unique<LazyFunctionForUndefinedNode>(bnode, used_outputs);
+ lf::FunctionNode &lf_node = lf_graph_->add_function(*lazy_function);
+ lf_graph_info_->functions.append(std::move(lazy_function));
+
+ for (const int i : used_outputs.index_range()) {
+ const bNodeSocket &bsocket = *used_outputs[i];
+ lf::OutputSocket &lf_socket = lf_node.output(i);
+ output_socket_map_.add(&bsocket, &lf_socket);
+ mapping_->bsockets_by_lf_socket_map.add(&lf_socket, &bsocket);
+ }
+ }
+
+ void handle_links()
+ {
+ for (const auto item : output_socket_map_.items()) {
+ this->insert_links_from_socket(*item.key, *item.value);
+ }
+ }
+
+ void insert_links_from_socket(const bNodeSocket &from_bsocket, lf::OutputSocket &from_lf_socket)
+ {
+ if (nodeIsDanglingReroute(&btree_, &from_bsocket.owner_node())) {
+ return;
+ }
+
+ const Span<const bNodeLink *> links_from_bsocket = from_bsocket.directly_linked_links();
+
+ struct TypeWithLinks {
+ const CPPType *type;
+ Vector<const bNodeLink *> links;
+ };
+
+ /* Group available target sockets by type so that they can be handled together. */
+ Vector<TypeWithLinks> types_with_links;
+ for (const bNodeLink *link : links_from_bsocket) {
+ if (link->is_muted()) {
+ continue;
+ }
+ if (!link->is_available()) {
+ continue;
+ }
+ const bNodeSocket &to_bsocket = *link->tosock;
+ const CPPType *to_type = get_socket_cpp_type(to_bsocket);
+ if (to_type == nullptr) {
+ continue;
+ }
+ bool inserted = false;
+ for (TypeWithLinks &types_with_links : types_with_links) {
+ if (types_with_links.type == to_type) {
+ types_with_links.links.append(link);
+ inserted = true;
+ break;
+ }
+ }
+ if (inserted) {
+ continue;
+ }
+ types_with_links.append({to_type, {link}});
+ }
+
+ for (const TypeWithLinks &type_with_links : types_with_links) {
+ const CPPType &to_type = *type_with_links.type;
+ const Span<const bNodeLink *> links = type_with_links.links;
+
+ Vector<const bNodeSocket *> target_bsockets;
+ for (const bNodeLink *link : links) {
+ target_bsockets.append(link->tosock);
+ }
+
+ lf::OutputSocket *converted_from_lf_socket = this->insert_type_conversion_if_necessary(
+ from_lf_socket, to_type, std::move(target_bsockets));
+
+ auto make_input_link_or_set_default = [&](lf::InputSocket &to_lf_socket) {
+ if (converted_from_lf_socket == nullptr) {
+ const void *default_value = to_type.default_value();
+ to_lf_socket.set_default_value(default_value);
+ }
+ else {
+ lf_graph_->add_link(*converted_from_lf_socket, to_lf_socket);
+ }
+ };
+
+ for (const bNodeLink *link : links) {
+ const bNodeSocket &to_bsocket = *link->tosock;
+ if (to_bsocket.is_multi_input()) {
+ /* TODO: Cache this index on the link. */
+ int link_index = 0;
+ for (const bNodeLink *multi_input_link : to_bsocket.directly_linked_links()) {
+ if (multi_input_link == link) {
+ break;
+ }
+ if (!(multi_input_link->is_muted() ||
+ nodeIsDanglingReroute(&btree_, multi_input_link->fromnode))) {
+ link_index++;
+ }
+ }
+ if (to_bsocket.owner_node().is_muted()) {
+ if (link_index == 0) {
+ for (lf::InputSocket *to_lf_socket : input_socket_map_.lookup(&to_bsocket)) {
+ make_input_link_or_set_default(*to_lf_socket);
+ }
+ }
+ }
+ else {
+ lf::Node *multi_input_lf_node = multi_input_socket_nodes_.lookup_default(&to_bsocket,
+ nullptr);
+ if (multi_input_lf_node == nullptr) {
+ continue;
+ }
+ make_input_link_or_set_default(multi_input_lf_node->input(link_index));
+ }
+ }
+ else {
+ for (lf::InputSocket *to_lf_socket : input_socket_map_.lookup(&to_bsocket)) {
+ make_input_link_or_set_default(*to_lf_socket);
+ }
+ }
+ }
+ }
+ }
+
+ lf::OutputSocket *insert_type_conversion_if_necessary(
+ lf::OutputSocket &from_socket,
+ const CPPType &to_type,
+ Vector<const bNodeSocket *> &&target_sockets)
+ {
+ const CPPType &from_type = from_socket.type();
+ if (from_type == to_type) {
+ return &from_socket;
+ }
+ const auto *from_field_type = dynamic_cast<const ValueOrFieldCPPType *>(&from_type);
+ const auto *to_field_type = dynamic_cast<const ValueOrFieldCPPType *>(&to_type);
+ if (from_field_type != nullptr && to_field_type != nullptr) {
+ const CPPType &from_base_type = from_field_type->base_type();
+ const CPPType &to_base_type = to_field_type->base_type();
+ if (conversions_->is_convertible(from_base_type, to_base_type)) {
+ const MultiFunction &multi_fn = *conversions_->get_conversion_multi_function(
+ MFDataType::ForSingle(from_base_type), MFDataType::ForSingle(to_base_type));
+ auto fn = std::make_unique<LazyFunctionForMultiFunctionConversion>(
+ multi_fn, *from_field_type, *to_field_type, std::move(target_sockets));
+ lf::Node &conversion_node = lf_graph_->add_function(*fn);
+ lf_graph_info_->functions.append(std::move(fn));
+ lf_graph_->add_link(from_socket, conversion_node.input(0));
+ return &conversion_node.output(0);
+ }
+ }
+ return nullptr;
+ }
+
+ void add_default_inputs()
+ {
+ for (auto item : input_socket_map_.items()) {
+ const bNodeSocket &bsocket = *item.key;
+ const Span<lf::InputSocket *> lf_sockets = item.value;
+ for (lf::InputSocket *lf_socket : lf_sockets) {
+ if (lf_socket->origin() != nullptr) {
+ /* Is linked already. */
+ continue;
+ }
+ this->add_default_input(bsocket, *lf_socket);
+ }
+ }
+ }
+
+ void add_default_input(const bNodeSocket &input_bsocket, lf::InputSocket &input_lf_socket)
+ {
+ if (this->try_add_implicit_input(input_bsocket, input_lf_socket)) {
+ return;
+ }
+ GMutablePointer value = get_socket_default_value(lf_graph_info_->allocator, input_bsocket);
+ if (value.get() == nullptr) {
+ /* Not possible to add a default value. */
+ return;
+ }
+ input_lf_socket.set_default_value(value.get());
+ if (!value.type()->is_trivially_destructible()) {
+ lf_graph_info_->values_to_destruct.append(value);
+ }
+ }
+
+ bool try_add_implicit_input(const bNodeSocket &input_bsocket, lf::InputSocket &input_lf_socket)
+ {
+ const bNode &bnode = input_bsocket.owner_node();
+ const SocketDeclaration *socket_decl = input_bsocket.runtime->declaration;
+ if (socket_decl == nullptr) {
+ return false;
+ }
+ if (socket_decl->input_field_type() != InputSocketFieldType::Implicit) {
+ return false;
+ }
+ const ImplicitInputValueFn *implicit_input_fn = socket_decl->implicit_input_fn();
+ if (implicit_input_fn == nullptr) {
+ return false;
+ }
+ std::function<void(void *)> init_fn = [&bnode, implicit_input_fn](void *r_value) {
+ (*implicit_input_fn)(bnode, r_value);
+ };
+ const CPPType &type = input_lf_socket.type();
+ auto lazy_function = std::make_unique<LazyFunctionForImplicitInput>(type, std::move(init_fn));
+ lf::Node &lf_node = lf_graph_->add_function(*lazy_function);
+ lf_graph_info_->functions.append(std::move(lazy_function));
+ lf_graph_->add_link(lf_node.output(0), input_lf_socket);
+ return true;
+ }
+};
+
+const GeometryNodesLazyFunctionGraphInfo *ensure_geometry_nodes_lazy_function_graph(
+ const bNodeTree &btree)
+{
+ btree.ensure_topology_cache();
+ if (btree.has_available_link_cycle()) {
+ return nullptr;
+ }
+ if (const ID *id_orig = DEG_get_original_id(const_cast<ID *>(&btree.id))) {
+ if (id_orig->tag & LIB_TAG_MISSING) {
+ return nullptr;
+ }
+ }
+
+ std::unique_ptr<GeometryNodesLazyFunctionGraphInfo> &lf_graph_info_ptr =
+ btree.runtime->geometry_nodes_lazy_function_graph_info;
+
+ if (lf_graph_info_ptr) {
+ return lf_graph_info_ptr.get();
+ }
+ std::lock_guard lock{btree.runtime->geometry_nodes_lazy_function_graph_info_mutex};
+ if (lf_graph_info_ptr) {
+ return lf_graph_info_ptr.get();
+ }
+
+ auto lf_graph_info = std::make_unique<GeometryNodesLazyFunctionGraphInfo>();
+ GeometryNodesLazyFunctionGraphBuilder builder{btree, *lf_graph_info};
+ builder.build();
+
+ lf_graph_info_ptr = std::move(lf_graph_info);
+ return lf_graph_info_ptr.get();
+}
+
+GeometryNodesLazyFunctionLogger::GeometryNodesLazyFunctionLogger(
+ const GeometryNodesLazyFunctionGraphInfo &lf_graph_info)
+ : lf_graph_info_(lf_graph_info)
+{
+}
+
+void GeometryNodesLazyFunctionLogger::log_socket_value(
+ const fn::lazy_function::Socket &lf_socket,
+ const GPointer value,
+ const fn::lazy_function::Context &context) const
+{
+ const Span<const bNodeSocket *> bsockets =
+ lf_graph_info_.mapping.bsockets_by_lf_socket_map.lookup(&lf_socket);
+ if (bsockets.is_empty()) {
+ return;
+ }
+
+ GeoNodesLFUserData *user_data = dynamic_cast<GeoNodesLFUserData *>(context.user_data);
+ BLI_assert(user_data != nullptr);
+ if (user_data->modifier_data->eval_log == nullptr) {
+ return;
+ }
+ geo_eval_log::GeoTreeLogger &tree_logger =
+ user_data->modifier_data->eval_log->get_local_tree_logger(*user_data->compute_context);
+ for (const bNodeSocket *bsocket : bsockets) {
+ /* Avoid logging to some sockets when the same value will also be logged to a linked socket.
+ * This reduces the number of logged values without losing information. */
+ if (bsocket->is_input() && bsocket->is_directly_linked()) {
+ continue;
+ }
+ const bNode &bnode = bsocket->owner_node();
+ if (bnode.is_reroute()) {
+ continue;
+ }
+ tree_logger.log_value(bsocket->owner_node(), *bsocket, value);
+ }
+}
+
+static std::mutex dump_error_context_mutex;
+
+void GeometryNodesLazyFunctionLogger::dump_when_outputs_are_missing(
+ const lf::FunctionNode &node,
+ Span<const lf::OutputSocket *> missing_sockets,
+ const lf::Context &context) const
+{
+ std::lock_guard lock{dump_error_context_mutex};
+
+ GeoNodesLFUserData *user_data = dynamic_cast<GeoNodesLFUserData *>(context.user_data);
+ BLI_assert(user_data != nullptr);
+ user_data->compute_context->print_stack(std::cout, node.name());
+ std::cout << "Missing outputs:\n";
+ for (const lf::OutputSocket *socket : missing_sockets) {
+ std::cout << " " << socket->name() << "\n";
+ }
+}
+
+void GeometryNodesLazyFunctionLogger::dump_when_input_is_set_twice(
+ const lf::InputSocket &target_socket,
+ const lf::OutputSocket &from_socket,
+ const lf::Context &context) const
+{
+ std::lock_guard lock{dump_error_context_mutex};
+
+ std::stringstream ss;
+ ss << from_socket.node().name() << ":" << from_socket.name() << " -> "
+ << target_socket.node().name() << ":" << target_socket.name();
+
+ GeoNodesLFUserData *user_data = dynamic_cast<GeoNodesLFUserData *>(context.user_data);
+ BLI_assert(user_data != nullptr);
+ user_data->compute_context->print_stack(std::cout, ss.str());
+}
+
+Vector<const lf::FunctionNode *> GeometryNodesLazyFunctionSideEffectProvider::
+ get_nodes_with_side_effects(const lf::Context &context) const
+{
+ GeoNodesLFUserData *user_data = dynamic_cast<GeoNodesLFUserData *>(context.user_data);
+ BLI_assert(user_data != nullptr);
+ const ComputeContextHash &context_hash = user_data->compute_context->hash();
+ const GeoNodesModifierData &modifier_data = *user_data->modifier_data;
+ return modifier_data.side_effect_nodes->lookup(context_hash);
+}
+
+GeometryNodesLazyFunctionGraphInfo::GeometryNodesLazyFunctionGraphInfo() = default;
+GeometryNodesLazyFunctionGraphInfo::~GeometryNodesLazyFunctionGraphInfo()
+{
+ for (GMutablePointer &p : this->values_to_destruct) {
+ p.destruct();
+ }
+}
+
+[[maybe_unused]] static void add_thread_id_debug_message(
+ const GeometryNodesLazyFunctionGraphInfo &lf_graph_info,
+ const lf::FunctionNode &node,
+ const lf::Context &context)
+{
+ static std::atomic<int> thread_id_source = 0;
+ static thread_local const int thread_id = thread_id_source.fetch_add(1);
+ static thread_local const std::string thread_id_str = "Thread: " + std::to_string(thread_id);
+
+ GeoNodesLFUserData *user_data = dynamic_cast<GeoNodesLFUserData *>(context.user_data);
+ BLI_assert(user_data != nullptr);
+ if (user_data->modifier_data->eval_log == nullptr) {
+ return;
+ }
+ geo_eval_log::GeoTreeLogger &tree_logger =
+ user_data->modifier_data->eval_log->get_local_tree_logger(*user_data->compute_context);
+
+ /* Find corresponding node based on the socket mapping. */
+ auto check_sockets = [&](const Span<const lf::Socket *> lf_sockets) {
+ for (const lf::Socket *lf_socket : lf_sockets) {
+ const Span<const bNodeSocket *> bsockets =
+ lf_graph_info.mapping.bsockets_by_lf_socket_map.lookup(lf_socket);
+ if (!bsockets.is_empty()) {
+ const bNodeSocket &bsocket = *bsockets[0];
+ const bNode &bnode = bsocket.owner_node();
+ tree_logger.debug_messages.append(
+ {tree_logger.allocator->copy_string(bnode.name), thread_id_str});
+ return true;
+ }
+ }
+ return false;
+ };
+
+ if (check_sockets(node.inputs().cast<const lf::Socket *>())) {
+ return;
+ }
+ check_sockets(node.outputs().cast<const lf::Socket *>());
+}
+
+void GeometryNodesLazyFunctionLogger::log_before_node_execute(const lf::FunctionNode &node,
+ const lf::Params & /*params*/,
+ const lf::Context &context) const
+{
+ /* Enable this to see the threads that invoked a node. */
+ if constexpr (false) {
+ add_thread_id_debug_message(lf_graph_info_, node, context);
+ }
+}
+
+} // namespace blender::nodes
diff --git a/source/blender/nodes/intern/geometry_nodes_log.cc b/source/blender/nodes/intern/geometry_nodes_log.cc
new file mode 100644
index 00000000000..0f122307328
--- /dev/null
+++ b/source/blender/nodes/intern/geometry_nodes_log.cc
@@ -0,0 +1,587 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "NOD_geometry_nodes_lazy_function.hh"
+#include "NOD_geometry_nodes_log.hh"
+
+#include "BKE_compute_contexts.hh"
+#include "BKE_curves.hh"
+#include "BKE_node_runtime.hh"
+#include "BKE_viewer_path.h"
+
+#include "FN_field_cpp_type.hh"
+
+#include "DNA_modifier_types.h"
+#include "DNA_space_types.h"
+
+#include "ED_viewer_path.hh"
+
+namespace blender::nodes::geo_eval_log {
+
+using fn::FieldInput;
+using fn::FieldInputs;
+
+GenericValueLog::~GenericValueLog()
+{
+ this->value.destruct();
+}
+
+FieldInfoLog::FieldInfoLog(const GField &field) : type(field.cpp_type())
+{
+ const std::shared_ptr<const fn::FieldInputs> &field_input_nodes = field.node().field_inputs();
+
+ /* Put the deduplicated field inputs into a vector so that they can be sorted below. */
+ Vector<std::reference_wrapper<const FieldInput>> field_inputs;
+ if (field_input_nodes) {
+ field_inputs.extend(field_input_nodes->deduplicated_nodes.begin(),
+ field_input_nodes->deduplicated_nodes.end());
+ }
+
+ std::sort(
+ field_inputs.begin(), field_inputs.end(), [](const FieldInput &a, const FieldInput &b) {
+ const int index_a = int(a.category());
+ const int index_b = int(b.category());
+ if (index_a == index_b) {
+ return a.socket_inspection_name().size() < b.socket_inspection_name().size();
+ }
+ return index_a < index_b;
+ });
+
+ for (const FieldInput &field_input : field_inputs) {
+ this->input_tooltips.append(field_input.socket_inspection_name());
+ }
+}
+
+GeometryInfoLog::GeometryInfoLog(const GeometrySet &geometry_set)
+{
+ static std::array all_component_types = {GEO_COMPONENT_TYPE_CURVE,
+ GEO_COMPONENT_TYPE_INSTANCES,
+ GEO_COMPONENT_TYPE_MESH,
+ GEO_COMPONENT_TYPE_POINT_CLOUD,
+ GEO_COMPONENT_TYPE_VOLUME};
+
+ /* Keep track handled attribute names to make sure that we do not return the same name twice.
+ * Currently #GeometrySet::attribute_foreach does not do that. Note that this will merge
+ * attributes with the same name but different domains or data types on separate components. */
+ Set<StringRef> names;
+
+ geometry_set.attribute_foreach(
+ all_component_types,
+ true,
+ [&](const bke::AttributeIDRef &attribute_id,
+ const bke::AttributeMetaData &meta_data,
+ const GeometryComponent & /*component*/) {
+ if (attribute_id.is_named() && names.add(attribute_id.name())) {
+ this->attributes.append({attribute_id.name(), meta_data.domain, meta_data.data_type});
+ }
+ });
+
+ for (const GeometryComponent *component : geometry_set.get_components_for_read()) {
+ this->component_types.append(component->type());
+ switch (component->type()) {
+ case GEO_COMPONENT_TYPE_MESH: {
+ const MeshComponent &mesh_component = *(const MeshComponent *)component;
+ MeshInfo &info = this->mesh_info.emplace();
+ info.verts_num = mesh_component.attribute_domain_size(ATTR_DOMAIN_POINT);
+ info.edges_num = mesh_component.attribute_domain_size(ATTR_DOMAIN_EDGE);
+ info.faces_num = mesh_component.attribute_domain_size(ATTR_DOMAIN_FACE);
+ break;
+ }
+ case GEO_COMPONENT_TYPE_CURVE: {
+ const CurveComponent &curve_component = *(const CurveComponent *)component;
+ CurveInfo &info = this->curve_info.emplace();
+ info.splines_num = curve_component.attribute_domain_size(ATTR_DOMAIN_CURVE);
+ break;
+ }
+ case GEO_COMPONENT_TYPE_POINT_CLOUD: {
+ const PointCloudComponent &pointcloud_component = *(const PointCloudComponent *)component;
+ PointCloudInfo &info = this->pointcloud_info.emplace();
+ info.points_num = pointcloud_component.attribute_domain_size(ATTR_DOMAIN_POINT);
+ break;
+ }
+ case GEO_COMPONENT_TYPE_INSTANCES: {
+ const InstancesComponent &instances_component = *(const InstancesComponent *)component;
+ InstancesInfo &info = this->instances_info.emplace();
+ info.instances_num = instances_component.attribute_domain_size(ATTR_DOMAIN_INSTANCE);
+ break;
+ }
+ case GEO_COMPONENT_TYPE_EDIT: {
+ const GeometryComponentEditData &edit_component = *(
+ const GeometryComponentEditData *)component;
+ if (const bke::CurvesEditHints *curve_edit_hints =
+ edit_component.curves_edit_hints_.get()) {
+ EditDataInfo &info = this->edit_data_info.emplace();
+ info.has_deform_matrices = curve_edit_hints->deform_mats.has_value();
+ info.has_deformed_positions = curve_edit_hints->positions.has_value();
+ }
+ break;
+ }
+ case GEO_COMPONENT_TYPE_VOLUME: {
+ break;
+ }
+ }
+ }
+}
+
+/* Avoid generating these in every translation unit. */
+GeoModifierLog::GeoModifierLog() = default;
+GeoModifierLog::~GeoModifierLog() = default;
+
+GeoTreeLogger::GeoTreeLogger() = default;
+GeoTreeLogger::~GeoTreeLogger() = default;
+
+GeoNodeLog::GeoNodeLog() = default;
+GeoNodeLog::~GeoNodeLog() = default;
+
+GeoTreeLog::GeoTreeLog(GeoModifierLog *modifier_log, Vector<GeoTreeLogger *> tree_loggers)
+ : modifier_log_(modifier_log), tree_loggers_(std::move(tree_loggers))
+{
+ for (GeoTreeLogger *tree_logger : tree_loggers_) {
+ for (const ComputeContextHash &hash : tree_logger->children_hashes) {
+ children_hashes_.add(hash);
+ }
+ }
+}
+
+GeoTreeLog::~GeoTreeLog() = default;
+
+void GeoTreeLogger::log_value(const bNode &node, const bNodeSocket &socket, const GPointer value)
+{
+ const CPPType &type = *value.type();
+
+ auto store_logged_value = [&](destruct_ptr<ValueLog> value_log) {
+ auto &socket_values = socket.in_out == SOCK_IN ? this->input_socket_values :
+ this->output_socket_values;
+ socket_values.append({this->allocator->copy_string(node.name),
+ this->allocator->copy_string(socket.identifier),
+ std::move(value_log)});
+ };
+
+ auto log_generic_value = [&](const CPPType &type, const void *value) {
+ void *buffer = this->allocator->allocate(type.size(), type.alignment());
+ type.copy_construct(value, buffer);
+ store_logged_value(this->allocator->construct<GenericValueLog>(GMutablePointer{type, buffer}));
+ };
+
+ if (type.is<GeometrySet>()) {
+ const GeometrySet &geometry = *value.get<GeometrySet>();
+ store_logged_value(this->allocator->construct<GeometryInfoLog>(geometry));
+ }
+ else if (const auto *value_or_field_type = dynamic_cast<const fn::ValueOrFieldCPPType *>(
+ &type)) {
+ const void *value_or_field = value.get();
+ const CPPType &base_type = value_or_field_type->base_type();
+ if (value_or_field_type->is_field(value_or_field)) {
+ const GField *field = value_or_field_type->get_field_ptr(value_or_field);
+ if (field->node().depends_on_input()) {
+ store_logged_value(this->allocator->construct<FieldInfoLog>(*field));
+ }
+ else {
+ BUFFER_FOR_CPP_TYPE_VALUE(base_type, value);
+ fn::evaluate_constant_field(*field, value);
+ log_generic_value(base_type, value);
+ }
+ }
+ else {
+ const void *value = value_or_field_type->get_value_ptr(value_or_field);
+ log_generic_value(base_type, value);
+ }
+ }
+ else {
+ log_generic_value(type, value.get());
+ }
+}
+
+void GeoTreeLogger::log_viewer_node(const bNode &viewer_node, GeometrySet geometry)
+{
+ destruct_ptr<ViewerNodeLog> log = this->allocator->construct<ViewerNodeLog>();
+ log->geometry = std::move(geometry);
+ log->geometry.ensure_owns_direct_data();
+ this->viewer_node_logs.append({this->allocator->copy_string(viewer_node.name), std::move(log)});
+}
+
+void GeoTreeLog::ensure_node_warnings()
+{
+ if (reduced_node_warnings_) {
+ return;
+ }
+ for (GeoTreeLogger *tree_logger : tree_loggers_) {
+ for (const GeoTreeLogger::WarningWithNode &warnings : tree_logger->node_warnings) {
+ this->nodes.lookup_or_add_default(warnings.node_name).warnings.append(warnings.warning);
+ this->all_warnings.append(warnings.warning);
+ }
+ }
+ for (const ComputeContextHash &child_hash : children_hashes_) {
+ GeoTreeLog &child_log = modifier_log_->get_tree_log(child_hash);
+ child_log.ensure_node_warnings();
+ const std::optional<std::string> &group_node_name =
+ child_log.tree_loggers_[0]->group_node_name;
+ if (group_node_name.has_value()) {
+ this->nodes.lookup_or_add_default(*group_node_name).warnings.extend(child_log.all_warnings);
+ }
+ this->all_warnings.extend(child_log.all_warnings);
+ }
+ reduced_node_warnings_ = true;
+}
+
+void GeoTreeLog::ensure_node_run_time()
+{
+ if (reduced_node_run_times_) {
+ return;
+ }
+ for (GeoTreeLogger *tree_logger : tree_loggers_) {
+ for (const GeoTreeLogger::NodeExecutionTime &timings : tree_logger->node_execution_times) {
+ const std::chrono::nanoseconds duration = timings.end - timings.start;
+ this->nodes.lookup_or_add_default_as(timings.node_name).run_time += duration;
+ this->run_time_sum += duration;
+ }
+ }
+ for (const ComputeContextHash &child_hash : children_hashes_) {
+ GeoTreeLog &child_log = modifier_log_->get_tree_log(child_hash);
+ child_log.ensure_node_run_time();
+ const std::optional<std::string> &group_node_name =
+ child_log.tree_loggers_[0]->group_node_name;
+ if (group_node_name.has_value()) {
+ this->nodes.lookup_or_add_default(*group_node_name).run_time += child_log.run_time_sum;
+ }
+ this->run_time_sum += child_log.run_time_sum;
+ }
+ reduced_node_run_times_ = true;
+}
+
+void GeoTreeLog::ensure_socket_values()
+{
+ if (reduced_socket_values_) {
+ return;
+ }
+ for (GeoTreeLogger *tree_logger : tree_loggers_) {
+ for (const GeoTreeLogger::SocketValueLog &value_log_data : tree_logger->input_socket_values) {
+ this->nodes.lookup_or_add_as(value_log_data.node_name)
+ .input_values_.add(value_log_data.socket_identifier, value_log_data.value.get());
+ }
+ for (const GeoTreeLogger::SocketValueLog &value_log_data : tree_logger->output_socket_values) {
+ this->nodes.lookup_or_add_as(value_log_data.node_name)
+ .output_values_.add(value_log_data.socket_identifier, value_log_data.value.get());
+ }
+ }
+ reduced_socket_values_ = true;
+}
+
+void GeoTreeLog::ensure_viewer_node_logs()
+{
+ if (reduced_viewer_node_logs_) {
+ return;
+ }
+ for (GeoTreeLogger *tree_logger : tree_loggers_) {
+ for (const GeoTreeLogger::ViewerNodeLogWithNode &viewer_log : tree_logger->viewer_node_logs) {
+ this->viewer_node_logs.add(viewer_log.node_name, viewer_log.viewer_log.get());
+ }
+ }
+ reduced_viewer_node_logs_ = true;
+}
+
+void GeoTreeLog::ensure_existing_attributes()
+{
+ if (reduced_existing_attributes_) {
+ return;
+ }
+ this->ensure_socket_values();
+
+ Set<StringRef> names;
+
+ auto handle_value_log = [&](const ValueLog &value_log) {
+ const GeometryInfoLog *geo_log = dynamic_cast<const GeometryInfoLog *>(&value_log);
+ if (geo_log == nullptr) {
+ return;
+ }
+ for (const GeometryAttributeInfo &attribute : geo_log->attributes) {
+ if (names.add(attribute.name)) {
+ this->existing_attributes.append(&attribute);
+ }
+ }
+ };
+
+ for (const GeoNodeLog &node_log : this->nodes.values()) {
+ for (const ValueLog *value_log : node_log.input_values_.values()) {
+ handle_value_log(*value_log);
+ }
+ for (const ValueLog *value_log : node_log.output_values_.values()) {
+ handle_value_log(*value_log);
+ }
+ }
+ reduced_existing_attributes_ = true;
+}
+
+void GeoTreeLog::ensure_used_named_attributes()
+{
+ if (reduced_used_named_attributes_) {
+ return;
+ }
+
+ auto add_attribute = [&](const StringRefNull node_name,
+ const StringRefNull attribute_name,
+ const NamedAttributeUsage &usage) {
+ this->nodes.lookup_or_add_default(node_name).used_named_attributes.lookup_or_add(
+ attribute_name, usage) |= usage;
+ this->used_named_attributes.lookup_or_add_as(attribute_name, usage) |= usage;
+ };
+
+ for (GeoTreeLogger *tree_logger : tree_loggers_) {
+ for (const GeoTreeLogger::AttributeUsageWithNode &item : tree_logger->used_named_attributes) {
+ add_attribute(item.node_name, item.attribute_name, item.usage);
+ }
+ }
+ for (const ComputeContextHash &child_hash : children_hashes_) {
+ GeoTreeLog &child_log = modifier_log_->get_tree_log(child_hash);
+ child_log.ensure_used_named_attributes();
+ if (const std::optional<std::string> &group_node_name =
+ child_log.tree_loggers_[0]->group_node_name) {
+ for (const auto &item : child_log.used_named_attributes.items()) {
+ add_attribute(*group_node_name, item.key, item.value);
+ }
+ }
+ }
+ reduced_used_named_attributes_ = true;
+}
+
+void GeoTreeLog::ensure_debug_messages()
+{
+ if (reduced_debug_messages_) {
+ return;
+ }
+ for (GeoTreeLogger *tree_logger : tree_loggers_) {
+ for (const GeoTreeLogger::DebugMessage &debug_message : tree_logger->debug_messages) {
+ this->nodes.lookup_or_add_as(debug_message.node_name)
+ .debug_messages.append(debug_message.message);
+ }
+ }
+ reduced_debug_messages_ = true;
+}
+
+ValueLog *GeoTreeLog::find_socket_value_log(const bNodeSocket &query_socket)
+{
+ /**
+ * Geometry nodes does not log values for every socket. That would produce a lot of redundant
+ * data,because often many linked sockets have the same value. To find the logged value for a
+ * socket one might have to look at linked sockets as well.
+ */
+
+ BLI_assert(reduced_socket_values_);
+ if (query_socket.is_multi_input()) {
+ /* Not supported currently. */
+ return nullptr;
+ }
+
+ Set<const bNodeSocket *> added_sockets;
+ Stack<const bNodeSocket *> sockets_to_check;
+ sockets_to_check.push(&query_socket);
+ added_sockets.add(&query_socket);
+
+ while (!sockets_to_check.is_empty()) {
+ const bNodeSocket &socket = *sockets_to_check.pop();
+ const bNode &node = socket.owner_node();
+ if (GeoNodeLog *node_log = this->nodes.lookup_ptr(node.name)) {
+ ValueLog *value_log = socket.is_input() ?
+ node_log->input_values_.lookup_default(socket.identifier,
+ nullptr) :
+ node_log->output_values_.lookup_default(socket.identifier,
+ nullptr);
+ if (value_log != nullptr) {
+ return value_log;
+ }
+ }
+
+ if (socket.is_input()) {
+ const Span<const bNodeLink *> links = socket.directly_linked_links();
+ for (const bNodeLink *link : links) {
+ const bNodeSocket &from_socket = *link->fromsock;
+ if (added_sockets.add(&from_socket)) {
+ sockets_to_check.push(&from_socket);
+ }
+ }
+ }
+ else {
+ if (node.is_reroute()) {
+ const bNodeSocket &input_socket = node.input_socket(0);
+ if (added_sockets.add(&input_socket)) {
+ sockets_to_check.push(&input_socket);
+ }
+ const Span<const bNodeLink *> links = input_socket.directly_linked_links();
+ for (const bNodeLink *link : links) {
+ const bNodeSocket &from_socket = *link->fromsock;
+ if (added_sockets.add(&from_socket)) {
+ sockets_to_check.push(&from_socket);
+ }
+ }
+ }
+ else if (node.is_muted()) {
+ if (const bNodeSocket *input_socket = socket.internal_link_input()) {
+ if (added_sockets.add(input_socket)) {
+ sockets_to_check.push(input_socket);
+ }
+ const Span<const bNodeLink *> links = input_socket->directly_linked_links();
+ for (const bNodeLink *link : links) {
+ const bNodeSocket &from_socket = *link->fromsock;
+ if (added_sockets.add(&from_socket)) {
+ sockets_to_check.push(&from_socket);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return nullptr;
+}
+
+GeoTreeLogger &GeoModifierLog::get_local_tree_logger(const ComputeContext &compute_context)
+{
+ LocalData &local_data = data_per_thread_.local();
+ Map<ComputeContextHash, destruct_ptr<GeoTreeLogger>> &local_tree_loggers =
+ local_data.tree_logger_by_context;
+ destruct_ptr<GeoTreeLogger> &tree_logger_ptr = local_tree_loggers.lookup_or_add_default(
+ compute_context.hash());
+ if (tree_logger_ptr) {
+ return *tree_logger_ptr;
+ }
+ tree_logger_ptr = local_data.allocator.construct<GeoTreeLogger>();
+ GeoTreeLogger &tree_logger = *tree_logger_ptr;
+ tree_logger.allocator = &local_data.allocator;
+ const ComputeContext *parent_compute_context = compute_context.parent();
+ if (parent_compute_context != nullptr) {
+ tree_logger.parent_hash = parent_compute_context->hash();
+ GeoTreeLogger &parent_logger = this->get_local_tree_logger(*parent_compute_context);
+ parent_logger.children_hashes.append(compute_context.hash());
+ }
+ if (const bke::NodeGroupComputeContext *node_group_compute_context =
+ dynamic_cast<const bke::NodeGroupComputeContext *>(&compute_context)) {
+ tree_logger.group_node_name.emplace(node_group_compute_context->node_name());
+ }
+ return tree_logger;
+}
+
+GeoTreeLog &GeoModifierLog::get_tree_log(const ComputeContextHash &compute_context_hash)
+{
+ GeoTreeLog &reduced_tree_log = *tree_logs_.lookup_or_add_cb(compute_context_hash, [&]() {
+ Vector<GeoTreeLogger *> tree_logs;
+ for (LocalData &local_data : data_per_thread_) {
+ destruct_ptr<GeoTreeLogger> *tree_log = local_data.tree_logger_by_context.lookup_ptr(
+ compute_context_hash);
+ if (tree_log != nullptr) {
+ tree_logs.append(tree_log->get());
+ }
+ }
+ return std::make_unique<GeoTreeLog>(this, std::move(tree_logs));
+ });
+ return reduced_tree_log;
+}
+
+struct ObjectAndModifier {
+ const Object *object;
+ const NodesModifierData *nmd;
+};
+
+static std::optional<ObjectAndModifier> get_modifier_for_node_editor(const SpaceNode &snode)
+{
+ if (snode.id == nullptr) {
+ return std::nullopt;
+ }
+ if (GS(snode.id->name) != ID_OB) {
+ return std::nullopt;
+ }
+ const Object *object = reinterpret_cast<Object *>(snode.id);
+ const NodesModifierData *used_modifier = nullptr;
+ if (snode.flag & SNODE_PIN) {
+ LISTBASE_FOREACH (const ModifierData *, md, &object->modifiers) {
+ if (md->type == eModifierType_Nodes) {
+ const NodesModifierData *nmd = reinterpret_cast<const NodesModifierData *>(md);
+ /* Would be good to store the name of the pinned modifier in the node editor. */
+ if (nmd->node_group == snode.nodetree) {
+ used_modifier = nmd;
+ break;
+ }
+ }
+ }
+ }
+ else {
+ LISTBASE_FOREACH (const ModifierData *, md, &object->modifiers) {
+ if (md->type == eModifierType_Nodes) {
+ const NodesModifierData *nmd = reinterpret_cast<const NodesModifierData *>(md);
+ if (nmd->node_group == snode.nodetree) {
+ if (md->flag & eModifierFlag_Active) {
+ used_modifier = nmd;
+ break;
+ }
+ }
+ }
+ }
+ }
+ if (used_modifier == nullptr) {
+ return std::nullopt;
+ }
+ return ObjectAndModifier{object, used_modifier};
+}
+
+GeoTreeLog *GeoModifierLog::get_tree_log_for_node_editor(const SpaceNode &snode)
+{
+ std::optional<ObjectAndModifier> object_and_modifier = get_modifier_for_node_editor(snode);
+ if (!object_and_modifier) {
+ return nullptr;
+ }
+ GeoModifierLog *modifier_log = static_cast<GeoModifierLog *>(
+ object_and_modifier->nmd->runtime_eval_log);
+ if (modifier_log == nullptr) {
+ return nullptr;
+ }
+ Vector<const bNodeTreePath *> tree_path = snode.treepath;
+ if (tree_path.is_empty()) {
+ return nullptr;
+ }
+ ComputeContextBuilder compute_context_builder;
+ compute_context_builder.push<bke::ModifierComputeContext>(
+ object_and_modifier->nmd->modifier.name);
+ for (const bNodeTreePath *path_item : tree_path.as_span().drop_front(1)) {
+ compute_context_builder.push<bke::NodeGroupComputeContext>(path_item->node_name);
+ }
+ return &modifier_log->get_tree_log(compute_context_builder.hash());
+}
+
+const ViewerNodeLog *GeoModifierLog::find_viewer_node_log_for_path(const ViewerPath &viewer_path)
+{
+ const std::optional<ed::viewer_path::ViewerPathForGeometryNodesViewer> parsed_path =
+ ed::viewer_path::parse_geometry_nodes_viewer(viewer_path);
+ if (!parsed_path.has_value()) {
+ return nullptr;
+ }
+ const Object *object = parsed_path->object;
+ NodesModifierData *nmd = nullptr;
+ LISTBASE_FOREACH (ModifierData *, md, &object->modifiers) {
+ if (md->name == parsed_path->modifier_name) {
+ if (md->type == eModifierType_Nodes) {
+ nmd = reinterpret_cast<NodesModifierData *>(md);
+ }
+ }
+ }
+ if (nmd == nullptr) {
+ return nullptr;
+ }
+ if (nmd->runtime_eval_log == nullptr) {
+ return nullptr;
+ }
+ nodes::geo_eval_log::GeoModifierLog *modifier_log =
+ static_cast<nodes::geo_eval_log::GeoModifierLog *>(nmd->runtime_eval_log);
+
+ ComputeContextBuilder compute_context_builder;
+ compute_context_builder.push<bke::ModifierComputeContext>(parsed_path->modifier_name);
+ for (const StringRef group_node_name : parsed_path->group_node_names) {
+ compute_context_builder.push<bke::NodeGroupComputeContext>(group_node_name);
+ }
+ const ComputeContextHash context_hash = compute_context_builder.hash();
+ nodes::geo_eval_log::GeoTreeLog &tree_log = modifier_log->get_tree_log(context_hash);
+ tree_log.ensure_viewer_node_logs();
+
+ const ViewerNodeLog *viewer_log = tree_log.viewer_node_logs.lookup_default(
+ parsed_path->viewer_node_name, nullptr);
+ return viewer_log;
+}
+
+} // namespace blender::nodes::geo_eval_log
diff --git a/source/blender/nodes/intern/node_common.cc b/source/blender/nodes/intern/node_common.cc
index b7c5f9570e4..d7cc0b6065a 100644
--- a/source/blender/nodes/intern/node_common.cc
+++ b/source/blender/nodes/intern/node_common.cc
@@ -37,6 +37,7 @@ using blender::MultiValueMap;
using blender::Set;
using blender::Stack;
using blender::StringRef;
+using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name Node Group
@@ -62,7 +63,7 @@ bNodeSocket *node_group_find_output_socket(bNode *groupnode, const char *identif
return find_matching_socket(groupnode->outputs, identifier);
}
-void node_group_label(const bNodeTree *UNUSED(ntree), const bNode *node, char *label, int maxlen)
+void node_group_label(const bNodeTree * /*ntree*/, const bNode *node, char *label, int maxlen)
{
BLI_strncpy(label, (node->id) ? node->id->name + 2 : IFACE_("Missing Data-Block"), maxlen);
}
@@ -81,7 +82,9 @@ bool node_group_poll_instance(bNode *node, bNodeTree *nodetree, const char **dis
return false;
}
-bool nodeGroupPoll(bNodeTree *nodetree, bNodeTree *grouptree, const char **r_disabled_hint)
+bool nodeGroupPoll(const bNodeTree *nodetree,
+ const bNodeTree *grouptree,
+ const char **r_disabled_hint)
{
bool valid = true;
@@ -93,13 +96,16 @@ bool nodeGroupPoll(bNodeTree *nodetree, bNodeTree *grouptree, const char **r_dis
}
if (nodetree == grouptree) {
- *r_disabled_hint = TIP_("Nesting a node group inside of itself is not allowed");
+ if (r_disabled_hint) {
+ *r_disabled_hint = TIP_("Nesting a node group inside of itself is not allowed");
+ }
return false;
}
- LISTBASE_FOREACH (bNode *, node, &grouptree->nodes) {
+ LISTBASE_FOREACH (const bNode *, node, &grouptree->nodes) {
if (node->typeinfo->poll_instance &&
- !node->typeinfo->poll_instance(node, nodetree, r_disabled_hint)) {
+ !node->typeinfo->poll_instance(
+ const_cast<bNode *>(node), const_cast<bNodeTree *>(nodetree), r_disabled_hint)) {
valid = false;
break;
}
@@ -160,6 +166,7 @@ static void group_verify_socket_list(bNodeTree &node_tree,
const bool ensure_extend_socket_exists)
{
ListBase old_sockets = verify_lb;
+ Vector<bNodeSocket *> ordered_old_sockets = old_sockets;
BLI_listbase_clear(&verify_lb);
LISTBASE_FOREACH (const bNodeSocket *, interface_socket, &interface_sockets) {
@@ -193,6 +200,19 @@ static void group_verify_socket_list(bNodeTree &node_tree,
LISTBASE_FOREACH_MUTABLE (bNodeSocket *, unused_socket, &old_sockets) {
nodeRemoveSocket(&node_tree, &node, unused_socket);
}
+
+ {
+ /* Check if new sockets match the old sockets. */
+ int index;
+ LISTBASE_FOREACH_INDEX (bNodeSocket *, new_socket, &verify_lb, index) {
+ if (index < ordered_old_sockets.size()) {
+ if (ordered_old_sockets[index] != new_socket) {
+ BKE_ntree_update_tag_interface(&node_tree);
+ break;
+ }
+ }
+ }
+ }
}
void node_group_update(struct bNodeTree *ntree, struct bNode *node)
@@ -201,7 +221,7 @@ void node_group_update(struct bNodeTree *ntree, struct bNode *node)
if (node->id == nullptr) {
nodeRemoveAllSockets(ntree, node);
}
- else if ((ID_IS_LINKED(node->id) && (node->id->tag & LIB_TAG_MISSING))) {
+ else if (ID_IS_LINKED(node->id) && (node->id->tag & LIB_TAG_MISSING)) {
/* Missing data-block, leave sockets unchanged so that when it comes back
* the links remain valid. */
}
@@ -218,7 +238,7 @@ void node_group_update(struct bNodeTree *ntree, struct bNode *node)
/** \name Node Frame
* \{ */
-static void node_frame_init(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_frame_init(bNodeTree * /*ntree*/, bNode *node)
{
NodeFrame *data = MEM_cnew<NodeFrame>("frame node storage");
node->storage = data;
diff --git a/source/blender/nodes/intern/node_declaration.cc b/source/blender/nodes/intern/node_declaration.cc
index 2cd9c6000c0..f323d035668 100644
--- a/source/blender/nodes/intern/node_declaration.cc
+++ b/source/blender/nodes/intern/node_declaration.cc
@@ -2,6 +2,7 @@
#include "NOD_node_declaration.hh"
+#include "BKE_geometry_fields.hh"
#include "BKE_node.h"
namespace blender::nodes {
@@ -81,4 +82,30 @@ bool SocketDeclaration::matches_common_data(const bNodeSocket &socket) const
return true;
}
+namespace implicit_field_inputs {
+
+void position(const bNode & /*node*/, void *r_value)
+{
+ new (r_value) fn::ValueOrField<float3>(bke::AttributeFieldInput::Create<float3>("position"));
+}
+
+void normal(const bNode & /*node*/, void *r_value)
+{
+ new (r_value)
+ fn::ValueOrField<float3>(fn::Field<float3>(std::make_shared<bke::NormalFieldInput>()));
+}
+
+void index(const bNode & /*node*/, void *r_value)
+{
+ new (r_value) fn::ValueOrField<int>(fn::Field<int>(std::make_shared<fn::IndexFieldInput>()));
+}
+
+void id_or_index(const bNode & /*node*/, void *r_value)
+{
+ new (r_value)
+ fn::ValueOrField<int>(fn::Field<int>(std::make_shared<bke::IDAttributeFieldInput>()));
+}
+
+} // namespace implicit_field_inputs
+
} // namespace blender::nodes
diff --git a/source/blender/nodes/intern/node_geometry_exec.cc b/source/blender/nodes/intern/node_geometry_exec.cc
index c6ebc22c43c..1de92fa8409 100644
--- a/source/blender/nodes/intern/node_geometry_exec.cc
+++ b/source/blender/nodes/intern/node_geometry_exec.cc
@@ -11,34 +11,31 @@
#include "node_geometry_util.hh"
-using blender::nodes::geometry_nodes_eval_log::LocalGeoLogger;
-
namespace blender::nodes {
-void GeoNodeExecParams::error_message_add(const NodeWarningType type, std::string message) const
+void GeoNodeExecParams::error_message_add(const NodeWarningType type,
+ const StringRef message) const
{
- if (provider_->logger == nullptr) {
- return;
+ if (geo_eval_log::GeoTreeLogger *tree_logger = this->get_local_tree_logger()) {
+ tree_logger->node_warnings.append({tree_logger->allocator->copy_string(node_.name),
+ {type, tree_logger->allocator->copy_string(message)}});
}
- LocalGeoLogger &local_logger = provider_->logger->local();
- local_logger.log_node_warning(provider_->dnode, type, std::move(message));
}
-void GeoNodeExecParams::used_named_attribute(std::string attribute_name,
- const eNamedAttrUsage usage)
+void GeoNodeExecParams::used_named_attribute(const StringRef attribute_name,
+ const NamedAttributeUsage usage)
{
- if (provider_->logger == nullptr) {
- return;
+ if (geo_eval_log::GeoTreeLogger *tree_logger = this->get_local_tree_logger()) {
+ tree_logger->used_named_attributes.append({tree_logger->allocator->copy_string(node_.name),
+ tree_logger->allocator->copy_string(attribute_name),
+ usage});
}
- LocalGeoLogger &local_logger = provider_->logger->local();
- local_logger.log_used_named_attribute(provider_->dnode, std::move(attribute_name), usage);
}
void GeoNodeExecParams::check_input_geometry_set(StringRef identifier,
const GeometrySet &geometry_set) const
{
- const SocketDeclaration &decl =
- *provider_->dnode->input_by_identifier(identifier).bsocket()->runtime->declaration;
+ const SocketDeclaration &decl = *node_.input_by_identifier(identifier).runtime->declaration;
const decl::Geometry *geo_decl = dynamic_cast<const decl::Geometry *>(&decl);
if (geo_decl == nullptr) {
return;
@@ -118,9 +115,9 @@ void GeoNodeExecParams::check_output_geometry_set(const GeometrySet &geometry_se
const bNodeSocket *GeoNodeExecParams::find_available_socket(const StringRef name) const
{
- for (const InputSocketRef *socket : provider_->dnode->inputs()) {
- if (socket->is_available() && socket->name() == name) {
- return socket->bsocket();
+ for (const bNodeSocket *socket : node_.input_sockets()) {
+ if (socket->is_available() && socket->name == name) {
+ return socket;
}
}
@@ -129,21 +126,21 @@ const bNodeSocket *GeoNodeExecParams::find_available_socket(const StringRef name
std::string GeoNodeExecParams::attribute_producer_name() const
{
- return provider_->dnode->label_or_name() + TIP_(" node");
+ return node_.label_or_name() + TIP_(" node");
}
void GeoNodeExecParams::set_default_remaining_outputs()
{
- provider_->set_default_remaining_outputs();
+ params_.set_default_remaining_outputs();
}
void GeoNodeExecParams::check_input_access(StringRef identifier,
const CPPType *requested_type) const
{
- bNodeSocket *found_socket = nullptr;
- for (const InputSocketRef *socket : provider_->dnode->inputs()) {
- if (socket->identifier() == identifier) {
- found_socket = socket->bsocket();
+ const bNodeSocket *found_socket = nullptr;
+ for (const bNodeSocket *socket : node_.input_sockets()) {
+ if (socket->identifier == identifier) {
+ found_socket = socket;
break;
}
}
@@ -151,9 +148,9 @@ void GeoNodeExecParams::check_input_access(StringRef identifier,
if (found_socket == nullptr) {
std::cout << "Did not find an input socket with the identifier '" << identifier << "'.\n";
std::cout << "Possible identifiers are: ";
- for (const InputSocketRef *socket : provider_->dnode->inputs()) {
+ for (const bNodeSocket *socket : node_.input_sockets()) {
if (socket->is_available()) {
- std::cout << "'" << socket->identifier() << "', ";
+ std::cout << "'" << socket->identifier << "', ";
}
}
std::cout << "\n";
@@ -164,13 +161,7 @@ void GeoNodeExecParams::check_input_access(StringRef identifier,
<< "' is disabled.\n";
BLI_assert_unreachable();
}
- else if (!provider_->can_get_input(identifier)) {
- std::cout << "The identifier '" << identifier
- << "' is valid, but there is no value for it anymore.\n";
- std::cout << "Most likely it has been extracted before.\n";
- BLI_assert_unreachable();
- }
- else if (requested_type != nullptr) {
+ else if (requested_type != nullptr && (found_socket->flag & SOCK_MULTI_INPUT) == 0) {
const CPPType &expected_type = *found_socket->typeinfo->geometry_nodes_cpp_type;
if (*requested_type != expected_type) {
std::cout << "The requested type '" << requested_type->name() << "' is incorrect. Expected '"
@@ -182,10 +173,10 @@ void GeoNodeExecParams::check_input_access(StringRef identifier,
void GeoNodeExecParams::check_output_access(StringRef identifier, const CPPType &value_type) const
{
- bNodeSocket *found_socket = nullptr;
- for (const OutputSocketRef *socket : provider_->dnode->outputs()) {
- if (socket->identifier() == identifier) {
- found_socket = socket->bsocket();
+ const bNodeSocket *found_socket = nullptr;
+ for (const bNodeSocket *socket : node_.output_sockets()) {
+ if (socket->identifier == identifier) {
+ found_socket = socket;
break;
}
}
@@ -193,9 +184,9 @@ void GeoNodeExecParams::check_output_access(StringRef identifier, const CPPType
if (found_socket == nullptr) {
std::cout << "Did not find an output socket with the identifier '" << identifier << "'.\n";
std::cout << "Possible identifiers are: ";
- for (const OutputSocketRef *socket : provider_->dnode->outputs()) {
+ for (const bNodeSocket *socket : node_.output_sockets()) {
if (socket->is_available()) {
- std::cout << "'" << socket->identifier() << "', ";
+ std::cout << "'" << socket->identifier << "', ";
}
}
std::cout << "\n";
@@ -206,7 +197,7 @@ void GeoNodeExecParams::check_output_access(StringRef identifier, const CPPType
<< "' is disabled.\n";
BLI_assert_unreachable();
}
- else if (!provider_->can_set_output(identifier)) {
+ else if (params_.output_was_set(this->get_output_index(identifier))) {
std::cout << "The identifier '" << identifier << "' has been set already.\n";
BLI_assert_unreachable();
}
diff --git a/source/blender/nodes/intern/node_multi_function.cc b/source/blender/nodes/intern/node_multi_function.cc
index 13bfdfbfac1..d731fe8f877 100644
--- a/source/blender/nodes/intern/node_multi_function.cc
+++ b/source/blender/nodes/intern/node_multi_function.cc
@@ -2,22 +2,22 @@
#include "NOD_multi_function.hh"
+#include "BKE_node.h"
+#include "BKE_node_runtime.hh"
+
namespace blender::nodes {
-NodeMultiFunctions::NodeMultiFunctions(const DerivedNodeTree &tree)
+NodeMultiFunctions::NodeMultiFunctions(const bNodeTree &tree)
{
- for (const NodeTreeRef *tree_ref : tree.used_node_tree_refs()) {
- bNodeTree *btree = tree_ref->btree();
- for (const NodeRef *node : tree_ref->nodes()) {
- bNode *bnode = node->bnode();
- if (bnode->typeinfo->build_multi_function == nullptr) {
- continue;
- }
- NodeMultiFunctionBuilder builder{*bnode, *btree};
- bnode->typeinfo->build_multi_function(builder);
- if (builder.built_fn_ != nullptr) {
- map_.add_new(bnode, {builder.built_fn_, std::move(builder.owned_built_fn_)});
- }
+ tree.ensure_topology_cache();
+ for (const bNode *bnode : tree.all_nodes()) {
+ if (bnode->typeinfo->build_multi_function == nullptr) {
+ continue;
+ }
+ NodeMultiFunctionBuilder builder{*bnode, tree};
+ bnode->typeinfo->build_multi_function(builder);
+ if (builder.built_fn_ != nullptr) {
+ map_.add_new(bnode, {builder.built_fn_, std::move(builder.owned_built_fn_)});
}
}
}
diff --git a/source/blender/nodes/intern/node_socket.cc b/source/blender/nodes/intern/node_socket.cc
index 098f766589d..f2f4519625a 100644
--- a/source/blender/nodes/intern/node_socket.cc
+++ b/source/blender/nodes/intern/node_socket.cc
@@ -59,14 +59,14 @@ struct bNodeSocket *node_add_socket_from_template(struct bNodeTree *ntree,
}
case SOCK_INT: {
bNodeSocketValueInt *dval = (bNodeSocketValueInt *)sock->default_value;
- dval->value = (int)stemp->val1;
- dval->min = (int)stemp->min;
- dval->max = (int)stemp->max;
+ dval->value = int(stemp->val1);
+ dval->min = int(stemp->min);
+ dval->max = int(stemp->max);
break;
}
case SOCK_BOOLEAN: {
bNodeSocketValueBoolean *dval = (bNodeSocketValueBoolean *)sock->default_value;
- dval->value = (int)stemp->val1;
+ dval->value = int(stemp->val1);
break;
}
case SOCK_VECTOR: {
@@ -531,11 +531,11 @@ void node_socket_skip_reroutes(
}
}
-static void standard_node_socket_interface_init_socket(bNodeTree *UNUSED(ntree),
+static void standard_node_socket_interface_init_socket(bNodeTree * /*ntree*/,
const bNodeSocket *interface_socket,
- bNode *UNUSED(node),
+ bNode * /*node*/,
bNodeSocket *sock,
- const char *UNUSED(data_path))
+ const char * /*data_path*/)
{
/* initialize the type value */
sock->type = sock->typeinfo->type;
@@ -549,11 +549,11 @@ static void standard_node_socket_interface_init_socket(bNodeTree *UNUSED(ntree),
}
/* copies settings that are not changed for each socket instance */
-static void standard_node_socket_interface_verify_socket(bNodeTree *UNUSED(ntree),
+static void standard_node_socket_interface_verify_socket(bNodeTree * /*ntree*/,
const bNodeSocket *interface_socket,
- bNode *UNUSED(node),
+ bNode * /*node*/,
bNodeSocket *sock,
- const char *UNUSED(data_path))
+ const char * /*data_path*/)
{
/* sanity check */
if (sock->type != interface_socket->typeinfo->type) {
@@ -594,9 +594,9 @@ static void standard_node_socket_interface_verify_socket(bNodeTree *UNUSED(ntree
}
}
-static void standard_node_socket_interface_from_socket(bNodeTree *UNUSED(ntree),
+static void standard_node_socket_interface_from_socket(bNodeTree * /*ntree*/,
bNodeSocket *stemp,
- bNode *UNUSED(node),
+ bNode * /*node*/,
bNodeSocket *sock)
{
/* initialize settings */
@@ -801,7 +801,7 @@ static bNodeSocketType *make_socket_type_geometry()
{
bNodeSocketType *socktype = make_standard_socket_type(SOCK_GEOMETRY, PROP_NONE);
socktype->base_cpp_type = &blender::CPPType::get<GeometrySet>();
- socktype->get_base_cpp_value = [](const bNodeSocket &UNUSED(socket), void *r_value) {
+ socktype->get_base_cpp_value = [](const bNodeSocket & /*socket*/, void *r_value) {
new (r_value) GeometrySet();
};
socktype->geometry_nodes_cpp_type = socktype->base_cpp_type;
diff --git a/source/blender/nodes/intern/node_socket_declarations.cc b/source/blender/nodes/intern/node_socket_declarations.cc
index b9fb75f30c7..a7d281bcf52 100644
--- a/source/blender/nodes/intern/node_socket_declarations.cc
+++ b/source/blender/nodes/intern/node_socket_declarations.cc
@@ -50,7 +50,7 @@ static bool sockets_can_connect(const SocketDeclaration &socket_decl,
return true;
}
-static bool basic_types_can_connect(const SocketDeclaration &UNUSED(socket_decl),
+static bool basic_types_can_connect(const SocketDeclaration & /*socket_decl*/,
const bNodeSocket &other_socket)
{
return ELEM(other_socket.type, SOCK_FLOAT, SOCK_INT, SOCK_BOOLEAN, SOCK_VECTOR, SOCK_RGBA);
diff --git a/source/blender/nodes/intern/node_tree_ref.cc b/source/blender/nodes/intern/node_tree_ref.cc
deleted file mode 100644
index 64a8690a869..00000000000
--- a/source/blender/nodes/intern/node_tree_ref.cc
+++ /dev/null
@@ -1,678 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-
-#include <mutex>
-
-#include "NOD_node_tree_ref.hh"
-
-#include "BLI_dot_export.hh"
-#include "BLI_stack.hh"
-
-#include "RNA_prototypes.h"
-
-namespace blender::nodes {
-
-NodeTreeRef::NodeTreeRef(bNodeTree *btree) : btree_(btree)
-{
- Map<bNode *, NodeRef *> node_mapping;
-
- LISTBASE_FOREACH (bNode *, bnode, &btree->nodes) {
- NodeRef &node = *allocator_.construct<NodeRef>().release();
-
- node.tree_ = this;
- node.bnode_ = bnode;
- node.id_ = nodes_by_id_.append_and_get_index(&node);
-
- LISTBASE_FOREACH (bNodeSocket *, bsocket, &bnode->inputs) {
- InputSocketRef &socket = *allocator_.construct<InputSocketRef>().release();
- socket.node_ = &node;
- socket.index_ = node.inputs_.append_and_get_index(&socket);
- socket.is_input_ = true;
- socket.bsocket_ = bsocket;
- socket.id_ = sockets_by_id_.append_and_get_index(&socket);
- }
-
- LISTBASE_FOREACH (bNodeSocket *, bsocket, &bnode->outputs) {
- OutputSocketRef &socket = *allocator_.construct<OutputSocketRef>().release();
- socket.node_ = &node;
- socket.index_ = node.outputs_.append_and_get_index(&socket);
- socket.is_input_ = false;
- socket.bsocket_ = bsocket;
- socket.id_ = sockets_by_id_.append_and_get_index(&socket);
- }
-
- LISTBASE_FOREACH (bNodeLink *, blink, &bnode->internal_links) {
- InternalLinkRef &internal_link = *allocator_.construct<InternalLinkRef>().release();
- internal_link.blink_ = blink;
- for (InputSocketRef *socket_ref : node.inputs_) {
- if (socket_ref->bsocket_ == blink->fromsock) {
- internal_link.from_ = socket_ref;
- break;
- }
- }
- for (OutputSocketRef *socket_ref : node.outputs_) {
- if (socket_ref->bsocket_ == blink->tosock) {
- internal_link.to_ = socket_ref;
- break;
- }
- }
- BLI_assert(internal_link.from_ != nullptr);
- BLI_assert(internal_link.to_ != nullptr);
- node.internal_links_.append(&internal_link);
- }
-
- input_sockets_.extend(node.inputs_.as_span());
- output_sockets_.extend(node.outputs_.as_span());
-
- node_mapping.add_new(bnode, &node);
- }
-
- LISTBASE_FOREACH (bNodeLink *, blink, &btree->links) {
- OutputSocketRef &from_socket = this->find_output_socket(
- node_mapping, blink->fromnode, blink->fromsock);
- InputSocketRef &to_socket = this->find_input_socket(
- node_mapping, blink->tonode, blink->tosock);
-
- LinkRef &link = *allocator_.construct<LinkRef>().release();
- link.from_ = &from_socket;
- link.to_ = &to_socket;
- link.blink_ = blink;
-
- links_.append(&link);
-
- from_socket.directly_linked_links_.append(&link);
- to_socket.directly_linked_links_.append(&link);
- }
-
- for (InputSocketRef *input_socket : input_sockets_) {
- if (input_socket->is_multi_input_socket()) {
- std::sort(input_socket->directly_linked_links_.begin(),
- input_socket->directly_linked_links_.end(),
- [&](const LinkRef *a, const LinkRef *b) -> bool {
- int index_a = a->blink()->multi_input_socket_index;
- int index_b = b->blink()->multi_input_socket_index;
- return index_a > index_b;
- });
- }
- }
-
- this->create_socket_identifier_maps();
- this->create_linked_socket_caches();
-
- for (NodeRef *node : nodes_by_id_) {
- const bNodeType *nodetype = node->bnode_->typeinfo;
- nodes_by_type_.add(nodetype, node);
- }
-
- const Span<const NodeRef *> group_output_nodes = this->nodes_by_type("NodeGroupOutput");
- if (group_output_nodes.is_empty()) {
- group_output_node_ = nullptr;
- }
- else if (group_output_nodes.size() == 1) {
- group_output_node_ = group_output_nodes.first();
- }
- else {
- for (const NodeRef *group_output : group_output_nodes) {
- if (group_output->bnode_->flag & NODE_DO_OUTPUT) {
- group_output_node_ = group_output;
- break;
- }
- }
- }
-}
-
-NodeTreeRef::~NodeTreeRef()
-{
- /* The destructor has to be called manually, because these types are allocated in a linear
- * allocator. */
- for (NodeRef *node : nodes_by_id_) {
- node->~NodeRef();
- }
- for (InputSocketRef *socket : input_sockets_) {
- socket->~InputSocketRef();
- }
- for (OutputSocketRef *socket : output_sockets_) {
- socket->~OutputSocketRef();
- }
- for (LinkRef *link : links_) {
- link->~LinkRef();
- }
-}
-
-InputSocketRef &NodeTreeRef::find_input_socket(Map<bNode *, NodeRef *> &node_mapping,
- bNode *bnode,
- bNodeSocket *bsocket)
-{
- NodeRef *node = node_mapping.lookup(bnode);
- for (InputSocketRef *socket : node->inputs_) {
- if (socket->bsocket_ == bsocket) {
- return *socket;
- }
- }
- BLI_assert_unreachable();
- return *node->inputs_[0];
-}
-
-OutputSocketRef &NodeTreeRef::find_output_socket(Map<bNode *, NodeRef *> &node_mapping,
- bNode *bnode,
- bNodeSocket *bsocket)
-{
- NodeRef *node = node_mapping.lookup(bnode);
- for (OutputSocketRef *socket : node->outputs_) {
- if (socket->bsocket_ == bsocket) {
- return *socket;
- }
- }
- BLI_assert_unreachable();
- return *node->outputs_[0];
-}
-
-void NodeTreeRef::create_linked_socket_caches()
-{
- for (InputSocketRef *socket : input_sockets_) {
- /* Find directly linked socket based on incident links. */
- Vector<const SocketRef *> directly_linked_sockets;
- for (LinkRef *link : socket->directly_linked_links_) {
- directly_linked_sockets.append(link->from_);
- }
- socket->directly_linked_sockets_ = allocator_.construct_array_copy(
- directly_linked_sockets.as_span());
-
- /* Find logically linked sockets. */
- Vector<const SocketRef *> logically_linked_sockets;
- Vector<const SocketRef *> logically_linked_skipped_sockets;
- Vector<const InputSocketRef *> seen_sockets_stack;
- socket->foreach_logical_origin(
- [&](const OutputSocketRef &origin) { logically_linked_sockets.append(&origin); },
- [&](const SocketRef &socket) { logically_linked_skipped_sockets.append(&socket); },
- false,
- seen_sockets_stack);
- if (logically_linked_sockets == directly_linked_sockets) {
- socket->logically_linked_sockets_ = socket->directly_linked_sockets_;
- }
- else {
- socket->logically_linked_sockets_ = allocator_.construct_array_copy(
- logically_linked_sockets.as_span());
- }
- socket->logically_linked_skipped_sockets_ = allocator_.construct_array_copy(
- logically_linked_skipped_sockets.as_span());
- }
-
- for (OutputSocketRef *socket : output_sockets_) {
- /* Find directly linked socket based on incident links. */
- Vector<const SocketRef *> directly_linked_sockets;
- for (LinkRef *link : socket->directly_linked_links_) {
- directly_linked_sockets.append(link->to_);
- }
- socket->directly_linked_sockets_ = allocator_.construct_array_copy(
- directly_linked_sockets.as_span());
-
- /* Find logically linked sockets. */
- Vector<const SocketRef *> logically_linked_sockets;
- Vector<const SocketRef *> logically_linked_skipped_sockets;
- Vector<const OutputSocketRef *> handled_sockets;
- socket->foreach_logical_target(
- [&](const InputSocketRef &target) { logically_linked_sockets.append(&target); },
- [&](const SocketRef &socket) { logically_linked_skipped_sockets.append(&socket); },
- handled_sockets);
- if (logically_linked_sockets == directly_linked_sockets) {
- socket->logically_linked_sockets_ = socket->directly_linked_sockets_;
- }
- else {
- socket->logically_linked_sockets_ = allocator_.construct_array_copy(
- logically_linked_sockets.as_span());
- }
- socket->logically_linked_skipped_sockets_ = allocator_.construct_array_copy(
- logically_linked_skipped_sockets.as_span());
- }
-}
-
-void InputSocketRef::foreach_logical_origin(
- FunctionRef<void(const OutputSocketRef &)> origin_fn,
- FunctionRef<void(const SocketRef &)> skipped_fn,
- bool only_follow_first_input_link,
- Vector<const InputSocketRef *> &seen_sockets_stack) const
-{
- /* Protect against loops. */
- if (seen_sockets_stack.contains(this)) {
- return;
- }
- seen_sockets_stack.append(this);
-
- Span<const LinkRef *> links_to_check = this->directly_linked_links();
- if (only_follow_first_input_link) {
- links_to_check = links_to_check.take_front(1);
- }
- for (const LinkRef *link : links_to_check) {
- if (link->is_muted()) {
- continue;
- }
- const OutputSocketRef &origin = link->from();
- const NodeRef &origin_node = origin.node();
- if (!origin.is_available()) {
- /* Non available sockets are ignored. */
- }
- else if (origin_node.is_reroute_node()) {
- const InputSocketRef &reroute_input = origin_node.input(0);
- const OutputSocketRef &reroute_output = origin_node.output(0);
- skipped_fn.call_safe(reroute_input);
- skipped_fn.call_safe(reroute_output);
- reroute_input.foreach_logical_origin(origin_fn, skipped_fn, false, seen_sockets_stack);
- }
- else if (origin_node.is_muted()) {
- for (const InternalLinkRef *internal_link : origin_node.internal_links()) {
- if (&internal_link->to() == &origin) {
- const InputSocketRef &mute_input = internal_link->from();
- skipped_fn.call_safe(origin);
- skipped_fn.call_safe(mute_input);
- mute_input.foreach_logical_origin(origin_fn, skipped_fn, true, seen_sockets_stack);
- }
- }
- }
- else {
- origin_fn(origin);
- }
- }
-
- seen_sockets_stack.pop_last();
-}
-
-void OutputSocketRef::foreach_logical_target(
- FunctionRef<void(const InputSocketRef &)> target_fn,
- FunctionRef<void(const SocketRef &)> skipped_fn,
- Vector<const OutputSocketRef *> &seen_sockets_stack) const
-{
- /* Protect against loops. */
- if (seen_sockets_stack.contains(this)) {
- return;
- }
- seen_sockets_stack.append(this);
-
- for (const LinkRef *link : this->directly_linked_links()) {
- if (link->is_muted()) {
- continue;
- }
- const InputSocketRef &target = link->to();
- const NodeRef &target_node = target.node();
- if (!target.is_available()) {
- /* Non available sockets are ignored. */
- }
- else if (target_node.is_reroute_node()) {
- const OutputSocketRef &reroute_output = target_node.output(0);
- skipped_fn.call_safe(target);
- skipped_fn.call_safe(reroute_output);
- reroute_output.foreach_logical_target(target_fn, skipped_fn, seen_sockets_stack);
- }
- else if (target_node.is_muted()) {
- skipped_fn.call_safe(target);
- for (const InternalLinkRef *internal_link : target_node.internal_links()) {
- if (&internal_link->from() == &target) {
- /* The internal link only forwards the first incoming link. */
- if (target.is_multi_input_socket()) {
- if (target.directly_linked_links()[0] != link) {
- continue;
- }
- }
- const OutputSocketRef &mute_output = internal_link->to();
- skipped_fn.call_safe(target);
- skipped_fn.call_safe(mute_output);
- mute_output.foreach_logical_target(target_fn, skipped_fn, seen_sockets_stack);
- }
- }
- }
- else {
- target_fn(target);
- }
- }
-
- seen_sockets_stack.pop_last();
-}
-
-namespace {
-struct SocketByIdentifierMap {
- SocketIndexByIdentifierMap *map = nullptr;
- std::unique_ptr<SocketIndexByIdentifierMap> owned_map;
-};
-} // namespace
-
-static std::unique_ptr<SocketIndexByIdentifierMap> create_identifier_map(const ListBase &sockets)
-{
- std::unique_ptr<SocketIndexByIdentifierMap> map = std::make_unique<SocketIndexByIdentifierMap>();
- int index;
- LISTBASE_FOREACH_INDEX (bNodeSocket *, socket, &sockets, index) {
- map->add_new(socket->identifier, index);
- }
- return map;
-}
-
-/* This function is not threadsafe. */
-static SocketByIdentifierMap get_or_create_identifier_map(
- const bNode &node, const ListBase &sockets, const bNodeSocketTemplate *sockets_template)
-{
- SocketByIdentifierMap map;
- if (sockets_template == nullptr) {
- if (BLI_listbase_is_empty(&sockets)) {
- static SocketIndexByIdentifierMap empty_map;
- map.map = &empty_map;
- }
- else if (node.type == NODE_REROUTE) {
- if (&node.inputs == &sockets) {
- static SocketIndexByIdentifierMap reroute_input_map = [] {
- SocketIndexByIdentifierMap map;
- map.add_new("Input", 0);
- return map;
- }();
- map.map = &reroute_input_map;
- }
- else {
- static SocketIndexByIdentifierMap reroute_output_map = [] {
- SocketIndexByIdentifierMap map;
- map.add_new("Output", 0);
- return map;
- }();
- map.map = &reroute_output_map;
- }
- }
- else {
- /* The node has a dynamic amount of sockets. Therefore we need to create a new map. */
- map.owned_map = create_identifier_map(sockets);
- map.map = &*map.owned_map;
- }
- }
- else {
- /* Cache only one map for nodes that have the same sockets. */
- static Map<const bNodeSocketTemplate *, std::unique_ptr<SocketIndexByIdentifierMap>> maps;
- map.map = &*maps.lookup_or_add_cb(sockets_template,
- [&]() { return create_identifier_map(sockets); });
- }
- return map;
-}
-
-void NodeTreeRef::create_socket_identifier_maps()
-{
- /* `get_or_create_identifier_map` is not threadsafe, therefore we have to hold a lock here. */
- static std::mutex mutex;
- std::lock_guard lock{mutex};
-
- for (NodeRef *node : nodes_by_id_) {
- bNode &bnode = *node->bnode_;
- SocketByIdentifierMap inputs_map = get_or_create_identifier_map(
- bnode, bnode.inputs, bnode.typeinfo->inputs);
- SocketByIdentifierMap outputs_map = get_or_create_identifier_map(
- bnode, bnode.outputs, bnode.typeinfo->outputs);
- node->input_index_by_identifier_ = inputs_map.map;
- node->output_index_by_identifier_ = outputs_map.map;
- if (inputs_map.owned_map) {
- owned_identifier_maps_.append(std::move(inputs_map.owned_map));
- }
- if (outputs_map.owned_map) {
- owned_identifier_maps_.append(std::move(outputs_map.owned_map));
- }
- }
-}
-
-static bool has_link_cycles_recursive(const NodeRef &node,
- MutableSpan<bool> visited,
- MutableSpan<bool> is_in_stack)
-{
- const int node_id = node.id();
- if (is_in_stack[node_id]) {
- return true;
- }
- if (visited[node_id]) {
- return false;
- }
-
- visited[node_id] = true;
- is_in_stack[node_id] = true;
-
- for (const OutputSocketRef *from_socket : node.outputs()) {
- if (!from_socket->is_available()) {
- continue;
- }
- for (const InputSocketRef *to_socket : from_socket->directly_linked_sockets()) {
- if (!to_socket->is_available()) {
- continue;
- }
- const NodeRef &to_node = to_socket->node();
- if (has_link_cycles_recursive(to_node, visited, is_in_stack)) {
- return true;
- }
- }
- }
-
- is_in_stack[node_id] = false;
- return false;
-}
-
-bool NodeTreeRef::has_link_cycles() const
-{
- const int node_amount = nodes_by_id_.size();
- Array<bool> visited(node_amount, false);
- Array<bool> is_in_stack(node_amount, false);
-
- for (const NodeRef *node : nodes_by_id_) {
- if (has_link_cycles_recursive(*node, visited, is_in_stack)) {
- return true;
- }
- }
- return false;
-}
-
-bool NodeTreeRef::has_undefined_nodes_or_sockets() const
-{
- for (const NodeRef *node : nodes_by_id_) {
- if (node->is_undefined()) {
- return true;
- }
- }
- for (const SocketRef *socket : sockets_by_id_) {
- if (socket->is_undefined()) {
- return true;
- }
- }
- return false;
-}
-
-bool NodeRef::any_input_is_directly_linked() const
-{
- for (const SocketRef *socket : inputs_) {
- if (!socket->directly_linked_sockets().is_empty()) {
- return true;
- }
- }
- return false;
-}
-
-bool NodeRef::any_output_is_directly_linked() const
-{
- for (const SocketRef *socket : outputs_) {
- if (!socket->directly_linked_sockets().is_empty()) {
- return true;
- }
- }
- return false;
-}
-
-bool NodeRef::any_socket_is_directly_linked(eNodeSocketInOut in_out) const
-{
- if (in_out == SOCK_IN) {
- return this->any_input_is_directly_linked();
- }
- return this->any_output_is_directly_linked();
-}
-
-struct ToposortNodeState {
- bool is_done = false;
- bool is_in_stack = false;
-};
-
-static void toposort_from_start_node(const NodeTreeRef::ToposortDirection direction,
- const NodeRef &start_node,
- MutableSpan<ToposortNodeState> node_states,
- NodeTreeRef::ToposortResult &result)
-{
- struct Item {
- const NodeRef *node;
- /* Index of the next socket that is checked in the depth-first search. */
- int socket_index = 0;
- /* Link index in the next socket that is checked in the depth-first search. */
- int link_index = 0;
- };
-
- /* Do a depth-first search to sort nodes topologically. */
- Stack<Item, 64> nodes_to_check;
- nodes_to_check.push({&start_node});
- while (!nodes_to_check.is_empty()) {
- Item &item = nodes_to_check.peek();
- const NodeRef &node = *item.node;
- const Span<const SocketRef *> sockets = node.sockets(
- direction == NodeTreeRef::ToposortDirection::LeftToRight ? SOCK_IN : SOCK_OUT);
-
- while (true) {
- if (item.socket_index == sockets.size()) {
- /* All sockets have already been visited. */
- break;
- }
- const SocketRef &socket = *sockets[item.socket_index];
- const Span<const SocketRef *> linked_sockets = socket.directly_linked_sockets();
- if (item.link_index == linked_sockets.size()) {
- /* All links connected to this socket have already been visited. */
- item.socket_index++;
- item.link_index = 0;
- continue;
- }
- const SocketRef &linked_socket = *linked_sockets[item.link_index];
- const NodeRef &linked_node = linked_socket.node();
- ToposortNodeState &linked_node_state = node_states[linked_node.id()];
- if (linked_node_state.is_done) {
- /* The linked node has already been visited. */
- item.link_index++;
- continue;
- }
- if (linked_node_state.is_in_stack) {
- result.has_cycle = true;
- }
- else {
- nodes_to_check.push({&linked_node});
- linked_node_state.is_in_stack = true;
- }
- break;
- }
-
- /* If no other element has been pushed, the current node can be pushed to the sorted list. */
- if (&item == &nodes_to_check.peek()) {
- ToposortNodeState &node_state = node_states[node.id()];
- node_state.is_done = true;
- node_state.is_in_stack = false;
- result.sorted_nodes.append(&node);
- nodes_to_check.pop();
- }
- }
-}
-
-NodeTreeRef::ToposortResult NodeTreeRef::toposort(const ToposortDirection direction) const
-{
- ToposortResult result;
- result.sorted_nodes.reserve(nodes_by_id_.size());
-
- Array<ToposortNodeState> node_states(nodes_by_id_.size());
-
- for (const NodeRef *node : nodes_by_id_) {
- if (node_states[node->id()].is_done) {
- /* Ignore nodes that are done already. */
- continue;
- }
- if (node->any_socket_is_directly_linked(
- direction == ToposortDirection::LeftToRight ? SOCK_OUT : SOCK_IN)) {
- /* Ignore non-start nodes. */
- continue;
- }
-
- toposort_from_start_node(direction, *node, node_states, result);
- }
-
- /* Check if the loop above forgot some nodes because there is a cycle. */
- if (result.sorted_nodes.size() < nodes_by_id_.size()) {
- result.has_cycle = true;
- for (const NodeRef *node : nodes_by_id_) {
- if (node_states[node->id()].is_done) {
- /* Ignore nodes that are done already. */
- continue;
- }
- /* Start toposort at this node which is somewhere in the middle of a loop. */
- toposort_from_start_node(direction, *node, node_states, result);
- }
- }
-
- BLI_assert(result.sorted_nodes.size() == nodes_by_id_.size());
- return result;
-}
-
-const NodeRef *NodeTreeRef::find_node(const bNode &bnode) const
-{
- for (const NodeRef *node : this->nodes_by_type(bnode.typeinfo)) {
- if (node->bnode_ == &bnode) {
- return node;
- }
- }
- return nullptr;
-}
-
-std::string NodeTreeRef::to_dot() const
-{
- dot::DirectedGraph digraph;
- digraph.set_rankdir(dot::Attr_rankdir::LeftToRight);
-
- Map<const NodeRef *, dot::NodeWithSocketsRef> dot_nodes;
-
- for (const NodeRef *node : nodes_by_id_) {
- dot::Node &dot_node = digraph.new_node("");
- dot_node.set_background_color("white");
-
- Vector<std::string> input_names;
- Vector<std::string> output_names;
- for (const InputSocketRef *socket : node->inputs()) {
- input_names.append(socket->name());
- }
- for (const OutputSocketRef *socket : node->outputs()) {
- output_names.append(socket->name());
- }
-
- dot_nodes.add_new(node,
- dot::NodeWithSocketsRef(dot_node, node->name(), input_names, output_names));
- }
-
- for (const OutputSocketRef *from_socket : output_sockets_) {
- for (const InputSocketRef *to_socket : from_socket->directly_linked_sockets()) {
- dot::NodeWithSocketsRef &from_dot_node = dot_nodes.lookup(&from_socket->node());
- dot::NodeWithSocketsRef &to_dot_node = dot_nodes.lookup(&to_socket->node());
-
- digraph.new_edge(from_dot_node.output(from_socket->index()),
- to_dot_node.input(to_socket->index()));
- }
- }
-
- return digraph.to_dot_string();
-}
-
-const NodeTreeRef &get_tree_ref_from_map(NodeTreeRefMap &node_tree_refs, bNodeTree &btree)
-{
- return *node_tree_refs.lookup_or_add_cb(&btree,
- [&]() { return std::make_unique<NodeTreeRef>(&btree); });
-}
-
-PointerRNA NodeRef::rna() const
-{
- PointerRNA rna;
- RNA_pointer_create(&tree_->btree()->id, &RNA_Node, bnode_, &rna);
- return rna;
-}
-
-PointerRNA SocketRef::rna() const
-{
- PointerRNA rna;
- RNA_pointer_create(&this->tree().btree()->id, &RNA_NodeSocket, bsocket_, &rna);
- return rna;
-}
-
-} // namespace blender::nodes
diff --git a/source/blender/nodes/intern/node_util.c b/source/blender/nodes/intern/node_util.cc
index e8be093c606..17be20b4e4b 100644
--- a/source/blender/nodes/intern/node_util.c
+++ b/source/blender/nodes/intern/node_util.cc
@@ -37,7 +37,7 @@
void node_free_curves(bNode *node)
{
- BKE_curvemapping_free(node->storage);
+ BKE_curvemapping_free(static_cast<CurveMapping *>(node->storage));
}
void node_free_standard_storage(bNode *node)
@@ -49,7 +49,7 @@ void node_free_standard_storage(bNode *node)
void node_copy_curves(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
{
- dest_node->storage = BKE_curvemapping_copy(src_node->storage);
+ dest_node->storage = BKE_curvemapping_copy(static_cast<CurveMapping *>(src_node->storage));
}
void node_copy_standard_storage(bNodeTree *UNUSED(dest_ntree),
@@ -63,7 +63,7 @@ void *node_initexec_curves(bNodeExecContext *UNUSED(context),
bNode *node,
bNodeInstanceKey UNUSED(key))
{
- BKE_curvemapping_init(node->storage);
+ BKE_curvemapping_init(static_cast<CurveMapping *>(node->storage));
return NULL; /* unused return */
}
@@ -87,9 +87,9 @@ void node_sock_label_clear(bNodeSocket *sock)
void node_math_update(bNodeTree *ntree, bNode *node)
{
- bNodeSocket *sock1 = BLI_findlink(&node->inputs, 0);
- bNodeSocket *sock2 = BLI_findlink(&node->inputs, 1);
- bNodeSocket *sock3 = BLI_findlink(&node->inputs, 2);
+ bNodeSocket *sock1 = static_cast<bNodeSocket *>(BLI_findlink(&node->inputs, 0));
+ bNodeSocket *sock2 = static_cast<bNodeSocket *>(BLI_findlink(&node->inputs, 1));
+ bNodeSocket *sock3 = static_cast<bNodeSocket *>(BLI_findlink(&node->inputs, 2));
nodeSetSocketAvailability(ntree,
sock2,
!ELEM(node->custom1,
@@ -200,7 +200,7 @@ void node_math_label(const bNodeTree *UNUSED(ntree), const bNode *node, char *la
if (!enum_label) {
name = "Unknown";
}
- BLI_strncpy(label, IFACE_(name), maxlen);
+ BLI_strncpy(label, CTX_IFACE_(BLT_I18NCONTEXT_ID_NODETREE, name), maxlen);
}
void node_vector_math_label(const bNodeTree *UNUSED(ntree),
@@ -305,7 +305,9 @@ static bNodeSocket *node_find_linkable_socket(bNodeTree *ntree,
bNode *node,
bNodeSocket *to_socket)
{
- bNodeSocket *first = to_socket->in_out == SOCK_IN ? node->inputs.first : node->outputs.first;
+ bNodeSocket *first = to_socket->in_out == SOCK_IN ?
+ static_cast<bNodeSocket *>(node->inputs.first) :
+ static_cast<bNodeSocket *>((node->outputs.first));
/* Wrap around the list end. */
bNodeSocket *socket_iter = to_socket->next ? to_socket->next : first;
diff --git a/source/blender/nodes/intern/socket_search_link.cc b/source/blender/nodes/intern/socket_search_link.cc
index 0bd838ff002..b440952b503 100644
--- a/source/blender/nodes/intern/socket_search_link.cc
+++ b/source/blender/nodes/intern/socket_search_link.cc
@@ -125,64 +125,23 @@ void search_link_ops_for_declarations(GatherLinkSearchOpParams &params,
}
}
-static void search_link_ops_for_socket_templates(GatherLinkSearchOpParams &params,
- const bNodeSocketTemplate *templates,
- const eNodeSocketInOut in_out)
-{
- const bNodeType &node_type = params.node_type();
- const bNodeTreeType &node_tree_type = *params.node_tree().typeinfo;
-
- Set<StringRef> socket_names;
- for (const bNodeSocketTemplate *socket_template = templates; socket_template->type != -1;
- socket_template++) {
- eNodeSocketDatatype from = (eNodeSocketDatatype)socket_template->type;
- eNodeSocketDatatype to = (eNodeSocketDatatype)params.other_socket().type;
- if (in_out == SOCK_IN) {
- std::swap(from, to);
- }
- if (node_tree_type.validate_link && !node_tree_type.validate_link(from, to)) {
- continue;
- }
- if (!socket_names.add(socket_template->name)) {
- /* See comment in #search_link_ops_for_declarations. */
- continue;
- }
-
- params.add_item(
- socket_template->name, [socket_template, node_type, in_out](LinkSearchOpParams &params) {
- bNode &node = params.add_node(node_type);
- bNodeSocket *new_node_socket = bke::node_find_enabled_socket(
- node, in_out, socket_template->name);
- if (new_node_socket != nullptr) {
- /* Rely on the way #nodeAddLink switches in/out if necessary. */
- nodeAddLink(&params.node_tree, &params.node, &params.socket, &node, new_node_socket);
- }
- });
- }
-}
-
void search_link_ops_for_basic_node(GatherLinkSearchOpParams &params)
{
const bNodeType &node_type = params.node_type();
+ if (!node_type.declare) {
+ return;
+ }
- if (node_type.declare) {
- if (node_type.declaration_is_dynamic) {
- /* Dynamic declarations (whatever they end up being) aren't supported
- * by this function, but still avoid a crash in release builds. */
- BLI_assert_unreachable();
- return;
- }
+ if (node_type.declaration_is_dynamic) {
+ /* Dynamic declarations (whatever they end up being) aren't supported
+ * by this function, but still avoid a crash in release builds. */
+ BLI_assert_unreachable();
+ return;
+ }
- const NodeDeclaration &declaration = *node_type.fixed_declaration;
+ const NodeDeclaration &declaration = *node_type.fixed_declaration;
- search_link_ops_for_declarations(params, declaration.sockets(params.in_out()));
- }
- else if (node_type.inputs && params.in_out() == SOCK_IN) {
- search_link_ops_for_socket_templates(params, node_type.inputs, SOCK_IN);
- }
- else if (node_type.outputs && params.in_out() == SOCK_OUT) {
- search_link_ops_for_socket_templates(params, node_type.outputs, SOCK_OUT);
- }
+ search_link_ops_for_declarations(params, declaration.sockets(params.in_out()));
}
} // namespace blender::nodes
diff --git a/source/blender/nodes/shader/CMakeLists.txt b/source/blender/nodes/shader/CMakeLists.txt
index 3e90f185168..e6f90449843 100644
--- a/source/blender/nodes/shader/CMakeLists.txt
+++ b/source/blender/nodes/shader/CMakeLists.txt
@@ -67,6 +67,7 @@ set(SRC
nodes/node_shader_map_range.cc
nodes/node_shader_mapping.cc
nodes/node_shader_math.cc
+ nodes/node_shader_mix.cc
nodes/node_shader_mix_rgb.cc
nodes/node_shader_mix_shader.cc
nodes/node_shader_normal.cc
@@ -131,22 +132,24 @@ set(LIB
bf_nodes
)
-if(WITH_PYTHON)
- list(APPEND INC
- ../../python
- )
+if(WITH_FREESTYLE)
+ add_definitions(-DWITH_FREESTYLE)
+endif()
+
+if(WITH_TBB)
+ add_definitions(-DWITH_TBB)
+ if(WIN32)
+ # TBB includes Windows.h which will define min/max macros
+ # that will collide with the stl versions.
+ add_definitions(-DNOMINMAX)
+ endif()
list(APPEND INC_SYS
- ${PYTHON_INCLUDE_DIRS}
+ ${TBB_INCLUDE_DIRS}
)
+
list(APPEND LIB
- ${PYTHON_LINKFLAGS}
- ${PYTHON_LIBRARIES}
+ ${TBB_LIBRARIES}
)
- add_definitions(-DWITH_PYTHON)
-endif()
-
-if(WITH_FREESTYLE)
- add_definitions(-DWITH_FREESTYLE)
endif()
blender_add_lib(bf_nodes_shader "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/source/blender/nodes/shader/node_shader_tree.cc b/source/blender/nodes/shader/node_shader_tree.cc
index 43dbf5060bd..52edf68b3ff 100644
--- a/source/blender/nodes/shader/node_shader_tree.cc
+++ b/source/blender/nodes/shader/node_shader_tree.cc
@@ -26,6 +26,7 @@
#include "BLT_translation.h"
#include "BKE_context.h"
+#include "BKE_layer.h"
#include "BKE_lib_id.h"
#include "BKE_linestyle.h"
#include "BKE_node.h"
@@ -51,7 +52,7 @@
using blender::Array;
using blender::Vector;
-static bool shader_tree_poll(const bContext *C, bNodeTreeType *UNUSED(treetype))
+static bool shader_tree_poll(const bContext *C, bNodeTreeType * /*treetype*/)
{
Scene *scene = CTX_data_scene(C);
const char *engine_id = scene->r.engine;
@@ -62,16 +63,14 @@ static bool shader_tree_poll(const bContext *C, bNodeTreeType *UNUSED(treetype))
!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 * /*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);
+ BKE_view_layer_synced_ensure(scene, view_layer);
+ Object *ob = BKE_view_layer_active_object_get(view_layer);
if (snode->shaderfrom == SNODE_SHADER_OBJECT) {
if (ob) {
@@ -108,7 +107,7 @@ static void shader_get_from_context(const bContext *C,
}
}
-static void foreach_nodeclass(Scene *UNUSED(scene), void *calldata, bNodeClassCallback func)
+static void foreach_nodeclass(Scene * /*scene*/, void *calldata, bNodeClassCallback func)
{
func(calldata, NODE_CLASS_INPUT, N_("Input"));
func(calldata, NODE_CLASS_OUTPUT, N_("Output"));
@@ -123,7 +122,7 @@ static void foreach_nodeclass(Scene *UNUSED(scene), void *calldata, bNodeClassCa
func(calldata, NODE_CLASS_LAYOUT, N_("Layout"));
}
-static void localize(bNodeTree *localtree, bNodeTree *UNUSED(ntree))
+static void localize(bNodeTree *localtree, bNodeTree * /*ntree*/)
{
/* replace muted nodes and reroute nodes by internal links */
LISTBASE_FOREACH_MUTABLE (bNode *, node, &localtree->nodes) {
@@ -151,7 +150,7 @@ static bool shader_validate_link(eNodeSocketDatatype from, eNodeSocketDatatype t
return true;
}
-static bool shader_node_tree_socket_type_valid(bNodeTreeType *UNUSED(ntreetype),
+static bool shader_node_tree_socket_type_valid(bNodeTreeType * /*ntreetype*/,
bNodeSocketType *socket_type)
{
return nodeIsStaticSocketType(socket_type) &&
@@ -166,6 +165,7 @@ void register_node_tree_type_sh()
tt->type = NTREE_SHADER;
strcpy(tt->idname, "ShaderNodeTree");
+ strcpy(tt->group_idname, "ShaderNodeGroup");
strcpy(tt->ui_name, N_("Shader Editor"));
tt->ui_icon = ICON_NODE_MATERIAL;
strcpy(tt->ui_description, N_("Shader nodes"));
@@ -297,7 +297,7 @@ static bool ntree_shader_expand_socket_default(bNodeTree *localtree,
BLI_assert(value_socket != nullptr);
src_int = static_cast<bNodeSocketValueInt *>(socket->default_value);
dst_float = static_cast<bNodeSocketValueFloat *>(value_socket->default_value);
- dst_float->value = (float)(src_int->value);
+ dst_float->value = float(src_int->value);
break;
case SOCK_FLOAT:
value_node = nodeAddStaticNode(nullptr, localtree, SH_NODE_VALUE);
@@ -560,7 +560,7 @@ static bNode *ntree_shader_copy_branch(bNodeTree *ntree,
void (*callback)(bNode *node, int user_data),
int user_data)
{
- /* Init tmp flag. */
+ /* Initialize `tmp_flag`. */
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
node->tmp_flag = -1;
}
@@ -616,7 +616,7 @@ static bool ntree_shader_implicit_closure_cast(bNodeTree *ntree)
bool modified = false;
LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &ntree->links) {
if ((link->fromsock->type != SOCK_SHADER) && (link->tosock->type == SOCK_SHADER)) {
- bNode *emission_node = nodeAddStaticNode(NULL, ntree, SH_NODE_EMISSION);
+ bNode *emission_node = nodeAddStaticNode(nullptr, ntree, SH_NODE_EMISSION);
bNodeSocket *in_sock = ntree_shader_node_find_input(emission_node, "Color");
bNodeSocket *out_sock = ntree_shader_node_find_output(emission_node, "Emission");
nodeAddLink(ntree, link->fromnode, link->fromsock, emission_node, in_sock);
@@ -639,12 +639,12 @@ static bool ntree_shader_implicit_closure_cast(bNodeTree *ntree)
/* Socket already has a link to it. Add weights together. */
static void ntree_weight_tree_merge_weight(bNodeTree *ntree,
- bNode *UNUSED(fromnode),
+ bNode * /*fromnode*/,
bNodeSocket *fromsock,
bNode **tonode,
bNodeSocket **tosock)
{
- bNode *addnode = nodeAddStaticNode(NULL, ntree, SH_NODE_MATH);
+ bNode *addnode = nodeAddStaticNode(nullptr, ntree, SH_NODE_MATH);
addnode->custom1 = NODE_MATH_ADD;
addnode->tmp_flag = -2; /* Copy */
bNodeSocket *addsock_out = ntree_shader_node_output_get(addnode, 0);
@@ -682,19 +682,19 @@ static bool ntree_weight_tree_tag_nodes(bNode *fromnode, bNode *tonode, void *us
* with their respective weights. */
static void ntree_shader_weight_tree_invert(bNodeTree *ntree, bNode *output_node)
{
- bNodeLink *displace_link = NULL;
+ bNodeLink *displace_link = nullptr;
bNodeSocket *displace_output = ntree_shader_node_find_input(output_node, "Displacement");
if (displace_output && displace_output->link) {
/* Remove any displacement link to avoid tagging it later on. */
displace_link = displace_output->link;
- displace_output->link = NULL;
+ displace_output->link = nullptr;
}
- bNodeLink *thickness_link = NULL;
+ bNodeLink *thickness_link = nullptr;
bNodeSocket *thickness_output = ntree_shader_node_find_input(output_node, "Thickness");
if (thickness_output && thickness_output->link) {
/* Remove any thickness link to avoid tagging it later on. */
thickness_link = thickness_output->link;
- thickness_output->link = NULL;
+ thickness_output->link = nullptr;
}
/* Init tmp flag. */
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
@@ -716,7 +716,7 @@ static void ntree_shader_weight_tree_invert(bNodeTree *ntree, bNode *output_node
case SH_NODE_OUTPUT_WORLD:
case SH_NODE_OUTPUT_MATERIAL: {
/* Start the tree with full weight. */
- nodes_copy[id] = nodeAddStaticNode(NULL, ntree, SH_NODE_VALUE);
+ nodes_copy[id] = nodeAddStaticNode(nullptr, ntree, SH_NODE_VALUE);
nodes_copy[id]->tmp_flag = -2; /* Copy */
((bNodeSocketValueFloat *)ntree_shader_node_output_get(nodes_copy[id], 0)->default_value)
->value = 1.0f;
@@ -725,7 +725,7 @@ static void ntree_shader_weight_tree_invert(bNodeTree *ntree, bNode *output_node
case SH_NODE_ADD_SHADER: {
/* Simple passthrough node. Each original inputs will get the same weight. */
/* TODO(fclem): Better use some kind of reroute node? */
- nodes_copy[id] = nodeAddStaticNode(NULL, ntree, SH_NODE_MATH);
+ nodes_copy[id] = nodeAddStaticNode(nullptr, ntree, SH_NODE_MATH);
nodes_copy[id]->custom1 = NODE_MATH_ADD;
nodes_copy[id]->tmp_flag = -2; /* Copy */
((bNodeSocketValueFloat *)ntree_shader_node_input_get(nodes_copy[id], 0)->default_value)
@@ -738,17 +738,17 @@ static void ntree_shader_weight_tree_invert(bNodeTree *ntree, bNode *output_node
bNodeSocket *fromsock, *tosock;
int id_start = id;
/* output = (factor * input_weight) */
- nodes_copy[id] = nodeAddStaticNode(NULL, ntree, SH_NODE_MATH);
+ nodes_copy[id] = nodeAddStaticNode(nullptr, ntree, SH_NODE_MATH);
nodes_copy[id]->custom1 = NODE_MATH_MULTIPLY;
nodes_copy[id]->tmp_flag = -2; /* Copy */
id++;
/* output = ((1.0 - factor) * input_weight) <=> (input_weight - factor * input_weight) */
- nodes_copy[id] = nodeAddStaticNode(NULL, ntree, SH_NODE_MATH);
+ nodes_copy[id] = nodeAddStaticNode(nullptr, ntree, SH_NODE_MATH);
nodes_copy[id]->custom1 = NODE_MATH_SUBTRACT;
nodes_copy[id]->tmp_flag = -2; /* Copy */
id++;
/* Node sanitizes the input mix factor by clamping it. */
- nodes_copy[id] = nodeAddStaticNode(NULL, ntree, SH_NODE_MATH);
+ nodes_copy[id] = nodeAddStaticNode(nullptr, ntree, SH_NODE_MATH);
nodes_copy[id]->custom1 = NODE_MATH_ADD;
nodes_copy[id]->custom2 = SHD_MATH_CLAMP;
nodes_copy[id]->tmp_flag = -2; /* Copy */
@@ -764,7 +764,7 @@ static void ntree_shader_weight_tree_invert(bNodeTree *ntree, bNode *output_node
id++;
/* Reroute the weight input to the 3 processing nodes. Simplify linking later-on. */
/* TODO(fclem): Better use some kind of reroute node? */
- nodes_copy[id] = nodeAddStaticNode(NULL, ntree, SH_NODE_MATH);
+ nodes_copy[id] = nodeAddStaticNode(nullptr, ntree, SH_NODE_MATH);
nodes_copy[id]->custom1 = NODE_MATH_ADD;
nodes_copy[id]->tmp_flag = -2; /* Copy */
((bNodeSocketValueFloat *)ntree_shader_node_input_get(nodes_copy[id], 0)->default_value)
@@ -944,7 +944,7 @@ static bool closure_node_filter(const bNode *node)
}
}
-static bool shader_to_rgba_node_gather(bNode *UNUSED(fromnode), bNode *tonode, void *userdata)
+static bool shader_to_rgba_node_gather(bNode * /*fromnode*/, bNode *tonode, void *userdata)
{
Vector<bNode *> &shader_to_rgba_nodes = *(Vector<bNode *> *)userdata;
if (tonode->tmp_flag == -1 && tonode->type == SH_NODE_SHADERTORGB) {
@@ -984,7 +984,7 @@ static void ntree_shader_shader_to_rgba_branch(bNodeTree *ntree, bNode *output_n
}
}
-static bool ntree_branch_node_tag(bNode *fromnode, bNode *tonode, void *UNUSED(userdata))
+static bool ntree_branch_node_tag(bNode *fromnode, bNode *tonode, void * /*userdata*/)
{
fromnode->tmp_flag = 1;
tonode->tmp_flag = 1;
@@ -1039,7 +1039,7 @@ void ntreeGPUMaterialNodes(bNodeTree *localtree, GPUMaterial *mat)
/* Tree is valid if it contains no undefined implicit socket type cast. */
bool valid_tree = ntree_shader_implicit_closure_cast(localtree);
- if (valid_tree && output != NULL) {
+ if (valid_tree && output != nullptr) {
ntree_shader_pruned_unused(localtree, output);
ntree_shader_shader_to_rgba_branch(localtree, output);
ntree_shader_weight_tree_invert(localtree, output);
diff --git a/source/blender/nodes/shader/node_shader_util.cc b/source/blender/nodes/shader/node_shader_util.cc
index 059d7800fc5..929b11ded3e 100644
--- a/source/blender/nodes/shader/node_shader_util.cc
+++ b/source/blender/nodes/shader/node_shader_util.cc
@@ -13,7 +13,7 @@
#include "node_exec.h"
-bool sh_node_poll_default(bNodeType *UNUSED(ntype), bNodeTree *ntree, const char **r_disabled_hint)
+bool sh_node_poll_default(bNodeType * /*ntype*/, bNodeTree *ntree, const char **r_disabled_hint)
{
if (!STREQ(ntree->idname, "ShaderNodeTree")) {
*r_disabled_hint = TIP_("Not a shader node tree");
@@ -22,7 +22,7 @@ bool sh_node_poll_default(bNodeType *UNUSED(ntype), bNodeTree *ntree, const char
return true;
}
-static bool sh_fn_poll_default(bNodeType *UNUSED(ntype),
+static bool sh_fn_poll_default(bNodeType * /*ntype*/,
bNodeTree *ntree,
const char **r_disabled_hint)
{
@@ -284,7 +284,7 @@ void ntreeExecGPUNodes(bNodeTreeExec *exec, GPUMaterial *mat, bNode *output_node
}
}
-void node_shader_gpu_bump_tex_coord(GPUMaterial *mat, bNode *UNUSED(node), GPUNodeLink **link)
+void node_shader_gpu_bump_tex_coord(GPUMaterial *mat, bNode * /*node*/, GPUNodeLink **link)
{
GPU_link(mat, "differentiate_texco", *link, link);
}
@@ -300,7 +300,7 @@ void node_shader_gpu_default_tex_coord(GPUMaterial *mat, bNode *node, GPUNodeLin
void node_shader_gpu_tex_mapping(GPUMaterial *mat,
bNode *node,
GPUNodeStack *in,
- GPUNodeStack *UNUSED(out))
+ GPUNodeStack * /*out*/)
{
NodeTexBase *base = (NodeTexBase *)node->storage;
TexMapping *texmap = &base->tex_mapping;
diff --git a/source/blender/nodes/shader/node_shader_util.hh b/source/blender/nodes/shader/node_shader_util.hh
index d5f54d9cac9..38220634695 100644
--- a/source/blender/nodes/shader/node_shader_util.hh
+++ b/source/blender/nodes/shader/node_shader_util.hh
@@ -59,6 +59,8 @@
#include "RE_pipeline.h"
#include "RE_texture.h"
+#include "RNA_access.h"
+
bool sh_node_poll_default(struct bNodeType *ntype,
struct bNodeTree *ntree,
const char **r_disabled_hint);
diff --git a/source/blender/nodes/shader/nodes/node_shader_add_shader.cc b/source/blender/nodes/shader/nodes/node_shader_add_shader.cc
index 330bdc0ba61..f7b25225e30 100644
--- a/source/blender/nodes/shader/nodes/node_shader_add_shader.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_add_shader.cc
@@ -14,7 +14,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_add_shader(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.cc b/source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.cc
index 1e8df2e985d..5f30fe0dd30 100644
--- a/source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.cc
@@ -17,9 +17,7 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("AO"));
}
-static void node_shader_buts_ambient_occlusion(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
+static void node_shader_buts_ambient_occlusion(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "samples", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
uiItemR(layout, ptr, "inside", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
@@ -28,7 +26,7 @@ static void node_shader_buts_ambient_occlusion(uiLayout *layout,
static int node_shader_gpu_ambient_occlusion(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -50,7 +48,7 @@ static int node_shader_gpu_ambient_occlusion(GPUMaterial *mat,
GPU_constant(&f_samples));
}
-static void node_shader_init_ambient_occlusion(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_ambient_occlusion(bNodeTree * /*ntree*/, bNode *node)
{
node->custom1 = 16; /* samples */
node->custom2 = 0;
diff --git a/source/blender/nodes/shader/nodes/node_shader_attribute.cc b/source/blender/nodes/shader/nodes/node_shader_attribute.cc
index d01271c15d3..4694599f064 100644
--- a/source/blender/nodes/shader/nodes/node_shader_attribute.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_attribute.cc
@@ -16,13 +16,13 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("Alpha"));
}
-static void node_shader_buts_attribute(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_attribute(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "attribute_type", UI_ITEM_R_SPLIT_EMPTY_NAME, IFACE_("Type"), ICON_NONE);
uiItemR(layout, ptr, "attribute_name", UI_ITEM_R_SPLIT_EMPTY_NAME, IFACE_("Name"), ICON_NONE);
}
-static void node_shader_init_attribute(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_attribute(bNodeTree * /*ntree*/, bNode *node)
{
NodeShaderAttribute *attr = MEM_cnew<NodeShaderAttribute>("NodeShaderAttribute");
node->storage = attr;
@@ -30,34 +30,45 @@ static void node_shader_init_attribute(bNodeTree *UNUSED(ntree), bNode *node)
static int node_shader_gpu_attribute(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
NodeShaderAttribute *attr = static_cast<NodeShaderAttribute *>(node->storage);
bool is_varying = attr->type == SHD_ATTRIBUTE_GEOMETRY;
+ float attr_hash = 0.0f;
GPUNodeLink *cd_attr;
if (is_varying) {
cd_attr = GPU_attribute(mat, CD_AUTO_FROM_NAME, attr->name);
+
+ if (STREQ(attr->name, "color")) {
+ GPU_link(mat, "node_attribute_color", cd_attr, &cd_attr);
+ }
+ else if (STREQ(attr->name, "temperature")) {
+ GPU_link(mat, "node_attribute_temperature", cd_attr, &cd_attr);
+ }
}
- else {
- cd_attr = GPU_uniform_attribute(mat, attr->name, attr->type == SHD_ATTRIBUTE_INSTANCER);
+ else if (attr->type == SHD_ATTRIBUTE_VIEW_LAYER) {
+ cd_attr = GPU_layer_attribute(mat, attr->name);
}
+ else {
+ cd_attr = GPU_uniform_attribute(mat,
+ attr->name,
+ attr->type == SHD_ATTRIBUTE_INSTANCER,
+ reinterpret_cast<uint32_t *>(&attr_hash));
- if (STREQ(attr->name, "color")) {
- GPU_link(mat, "node_attribute_color", cd_attr, &cd_attr);
- }
- else if (STREQ(attr->name, "temperature")) {
- GPU_link(mat, "node_attribute_temperature", cd_attr, &cd_attr);
+ GPU_link(mat, "node_attribute_uniform", cd_attr, GPU_constant(&attr_hash), &cd_attr);
}
GPU_stack_link(mat, node, "node_attribute", in, out, cd_attr);
- int i;
- LISTBASE_FOREACH_INDEX (bNodeSocket *, sock, &node->outputs, i) {
- node_shader_gpu_bump_tex_coord(mat, node, &out[i].link);
+ if (is_varying) {
+ int i;
+ LISTBASE_FOREACH_INDEX (bNodeSocket *, sock, &node->outputs, i) {
+ node_shader_gpu_bump_tex_coord(mat, node, &out[i].link);
+ }
}
return 1;
diff --git a/source/blender/nodes/shader/nodes/node_shader_background.cc b/source/blender/nodes/shader/nodes/node_shader_background.cc
index ea5c1f541ea..1e41b66189a 100644
--- a/source/blender/nodes/shader/nodes/node_shader_background.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_background.cc
@@ -15,7 +15,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_background(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_bevel.cc b/source/blender/nodes/shader/nodes/node_shader_bevel.cc
index 4ae60af9974..14356a46125 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bevel.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_bevel.cc
@@ -15,19 +15,19 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Vector>(N_("Normal"));
}
-static void node_shader_buts_bevel(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_bevel(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "samples", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
-static void node_shader_init_bevel(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_bevel(bNodeTree * /*ntree*/, bNode *node)
{
node->custom1 = 4; /* samples */
}
static int gpu_shader_bevel(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_blackbody.cc b/source/blender/nodes/shader/nodes/node_shader_blackbody.cc
index 9f382e5a3bb..23e9a601045 100644
--- a/source/blender/nodes/shader/nodes/node_shader_blackbody.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_blackbody.cc
@@ -15,7 +15,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_blackbody(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_brightness.cc b/source/blender/nodes/shader/nodes/node_shader_brightness.cc
index a23783c6d46..09f0e21208c 100644
--- a/source/blender/nodes/shader/nodes/node_shader_brightness.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_brightness.cc
@@ -15,7 +15,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int gpu_shader_brightcontrast(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.cc b/source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.cc
index 761a833f377..2071b78fa64 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.cc
@@ -28,19 +28,19 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Shader>(N_("BSDF"));
}
-static void node_shader_buts_anisotropic(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_anisotropic(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "distribution", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
-static void node_shader_init_anisotropic(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_anisotropic(bNodeTree * /*ntree*/, bNode *node)
{
node->custom1 = SHD_GLOSSY_GGX;
}
static int node_shader_gpu_bsdf_anisotropic(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.cc b/source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.cc
index 5975e04450e..a4f0e04576f 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.cc
@@ -20,7 +20,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_bsdf_diffuse(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_glass.cc b/source/blender/nodes/shader/nodes/node_shader_bsdf_glass.cc
index 95869f13b7e..b3c047c3a47 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_glass.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_glass.cc
@@ -19,14 +19,14 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Shader>(N_("BSDF"));
}
-static void node_shader_init_glass(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_glass(bNodeTree * /*ntree*/, bNode *node)
{
node->custom1 = SHD_GLOSSY_BECKMANN;
}
static int node_shader_gpu_bsdf_glass(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.cc b/source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.cc
index 07062a9730e..7beecc0ecd4 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.cc
@@ -18,14 +18,14 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Shader>(N_("BSDF"));
}
-static void node_shader_init_glossy(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_glossy(bNodeTree * /*ntree*/, bNode *node)
{
node->custom1 = SHD_GLOSSY_GGX;
}
static int node_shader_gpu_bsdf_glossy(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_hair.cc b/source/blender/nodes/shader/nodes/node_shader_bsdf_hair.cc
index 1a1ba13e886..f8a17e146f4 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_hair.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_hair.cc
@@ -31,14 +31,14 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Shader>(N_("BSDF"));
}
-static void node_shader_buts_hair(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_hair(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "component", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
static int node_shader_gpu_bsdf_hair(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_hair_principled.cc b/source/blender/nodes/shader/nodes/node_shader_bsdf_hair_principled.cc
index a0579372a15..b1022a95783 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_hair_principled.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_hair_principled.cc
@@ -44,7 +44,7 @@ static void node_declare(NodeDeclarationBuilder &b)
.subtype(PROP_FACTOR);
b.add_input<decl::Float>(N_("IOR")).default_value(1.55f).min(0.0f).max(1000.0f);
b.add_input<decl::Float>(N_("Offset"))
- .default_value(2.0f * ((float)M_PI) / 180.0f)
+ .default_value(2.0f * float(M_PI) / 180.0f)
.min(-M_PI_2)
.max(M_PI_2)
.subtype(PROP_ANGLE);
@@ -63,15 +63,13 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Shader>(N_("BSDF"));
}
-static void node_shader_buts_principled_hair(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
+static void node_shader_buts_principled_hair(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "parametrization", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
/* Initialize the custom Parametrization property to Color. */
-static void node_shader_init_hair_principled(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_hair_principled(bNodeTree * /*ntree*/, bNode *node)
{
node->custom1 = SHD_PRINCIPLED_HAIR_REFLECTANCE;
}
@@ -110,7 +108,7 @@ static void node_shader_update_hair_principled(bNodeTree *ntree, bNode *node)
static int node_shader_gpu_hair_principled(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc
index 28cca42565a..468527c57a0 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc
@@ -125,13 +125,13 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Shader>(N_("BSDF"));
}
-static void node_shader_buts_principled(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_principled(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "distribution", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
uiItemR(layout, ptr, "subsurface_method", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
-static void node_shader_init_principled(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_principled(bNodeTree * /*ntree*/, bNode *node)
{
node->custom1 = SHD_PRINCIPLED_V2;
node->custom2 = SHD_SUBSURFACE_RANDOM_WALK;
@@ -143,7 +143,7 @@ static void node_shader_init_principled(bNodeTree *UNUSED(ntree), bNode *node)
static int node_shader_gpu_bsdf_principled(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -185,6 +185,27 @@ static int node_shader_gpu_bsdf_principled(GPUMaterial *mat,
if (use_transparency) {
flag |= GPU_MATFLAG_TRANSPARENT;
}
+ if (use_clear) {
+ flag |= GPU_MATFLAG_CLEARCOAT;
+ }
+
+ /* Ref. T98190: Defines are optimizations for old compilers.
+ * Might become unnecessary with EEVEE-Next. */
+ if (use_diffuse == false && use_refract == false && use_clear == true) {
+ flag |= GPU_MATFLAG_PRINCIPLED_CLEARCOAT;
+ }
+ else if (use_diffuse == false && use_refract == false && use_clear == false) {
+ flag |= GPU_MATFLAG_PRINCIPLED_METALLIC;
+ }
+ else if (use_diffuse == true && use_refract == false && use_clear == false) {
+ flag |= GPU_MATFLAG_PRINCIPLED_DIELECTRIC;
+ }
+ else if (use_diffuse == false && use_refract == true && use_clear == false) {
+ flag |= GPU_MATFLAG_PRINCIPLED_GLASS;
+ }
+ else {
+ flag |= GPU_MATFLAG_PRINCIPLED_ANY;
+ }
if (use_subsurf) {
bNodeSocket *socket = (bNodeSocket *)BLI_findlink(&node->original->inputs, 2);
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_refraction.cc b/source/blender/nodes/shader/nodes/node_shader_bsdf_refraction.cc
index e814eb223e5..a7111fd398f 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_refraction.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_refraction.cc
@@ -19,14 +19,14 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Shader>(N_("BSDF"));
}
-static void node_shader_init_refraction(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_refraction(bNodeTree * /*ntree*/, bNode *node)
{
node->custom1 = SHD_GLOSSY_BECKMANN;
}
static int node_shader_gpu_bsdf_refraction(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_toon.cc b/source/blender/nodes/shader/nodes/node_shader_bsdf_toon.cc
index c1c092e89c7..d0f70eb1c92 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_toon.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_toon.cc
@@ -26,14 +26,14 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Shader>(N_("BSDF"));
}
-static void node_shader_buts_toon(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_toon(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "component", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
static int node_shader_gpu_bsdf_toon(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_translucent.cc b/source/blender/nodes/shader/nodes/node_shader_bsdf_translucent.cc
index fd0dd9f93de..b8a2bf8043e 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_translucent.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_translucent.cc
@@ -15,7 +15,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_bsdf_translucent(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_transparent.cc b/source/blender/nodes/shader/nodes/node_shader_bsdf_transparent.cc
index 291b3fdb2be..8824c744fd3 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_transparent.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_transparent.cc
@@ -14,7 +14,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_bsdf_transparent(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_velvet.cc b/source/blender/nodes/shader/nodes/node_shader_bsdf_velvet.cc
index c86d70aecbf..c4aaf371e46 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_velvet.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_velvet.cc
@@ -20,7 +20,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_bsdf_velvet(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_bump.cc b/source/blender/nodes/shader/nodes/node_shader_bump.cc
index ad2c56d96b5..5447198107b 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bump.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_bump.cc
@@ -31,14 +31,14 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Vector>(N_("Normal"));
}
-static void node_shader_buts_bump(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_bump(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "invert", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, 0);
}
static int gpu_shader_bump(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_camera.cc b/source/blender/nodes/shader/nodes/node_shader_camera.cc
index 99c82582456..4d99d5ad17f 100644
--- a/source/blender/nodes/shader/nodes/node_shader_camera.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_camera.cc
@@ -18,7 +18,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int gpu_shader_camera(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_clamp.cc b/source/blender/nodes/shader/nodes/node_shader_clamp.cc
index c8785721dfb..7680c6f99c4 100644
--- a/source/blender/nodes/shader/nodes/node_shader_clamp.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_clamp.cc
@@ -21,19 +21,19 @@ static void sh_node_clamp_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("Result"));
}
-static void node_shader_buts_clamp(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_clamp(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "clamp_type", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
-static void node_shader_init_clamp(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_clamp(bNodeTree * /*ntree*/, bNode *node)
{
node->custom1 = NODE_CLAMP_MINMAX; /* clamp type */
}
static int gpu_shader_clamp(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_color_ramp.cc b/source/blender/nodes/shader/nodes/node_shader_color_ramp.cc
index 3723480ffa3..096884591ab 100644
--- a/source/blender/nodes/shader/nodes/node_shader_color_ramp.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_color_ramp.cc
@@ -21,14 +21,14 @@ static void sh_node_valtorgb_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("Alpha"));
}
-static void node_shader_init_valtorgb(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_valtorgb(bNodeTree * /*ntree*/, bNode *node)
{
node->storage = BKE_colorband_add(true);
}
static int gpu_shader_valtorgb(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -107,7 +107,7 @@ class ColorBandFunction : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
const VArray<float> &values = params.readonly_single_input<float>(0, "Value");
MutableSpan<ColorGeometry4f> colors = params.uninitialized_single_output<ColorGeometry4f>(
@@ -125,7 +125,7 @@ class ColorBandFunction : public fn::MultiFunction {
static void sh_node_valtorgb_build_multi_function(nodes::NodeMultiFunctionBuilder &builder)
{
- bNode &bnode = builder.node();
+ const bNode &bnode = builder.node();
const ColorBand *color_band = (const ColorBand *)bnode.storage;
builder.construct_and_set_matching_fn<ColorBandFunction>(*color_band);
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_curves.cc b/source/blender/nodes/shader/nodes/node_shader_curves.cc
index eb47059063d..c4dbc3ce6f1 100644
--- a/source/blender/nodes/shader/nodes/node_shader_curves.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_curves.cc
@@ -12,19 +12,24 @@ namespace blender::nodes::node_shader_curves_cc {
static void sh_node_curve_vec_declare(NodeDeclarationBuilder &b)
{
b.is_function_node();
- b.add_input<decl::Float>(N_("Fac")).min(0.0f).max(1.0f).default_value(1.0f).subtype(PROP_FACTOR);
+ b.add_input<decl::Float>(N_("Fac"))
+ .no_muted_links()
+ .min(0.0f)
+ .max(1.0f)
+ .default_value(1.0f)
+ .subtype(PROP_FACTOR);
b.add_input<decl::Vector>(N_("Vector")).min(-1.0f).max(1.0f);
b.add_output<decl::Vector>(N_("Vector"));
}
-static void node_shader_init_curve_vec(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_curve_vec(bNodeTree * /*ntree*/, bNode *node)
{
node->storage = BKE_curvemapping_add(3, -1.0f, -1.0f, 1.0f, 1.0f);
}
static int gpu_shader_curve_vec(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -78,7 +83,7 @@ class CurveVecFunction : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
const VArray<float> &fac = params.readonly_single_input<float>(0, "Fac");
const VArray<float3> &vec_in = params.readonly_single_input<float3>(1, "Vector");
@@ -95,7 +100,7 @@ class CurveVecFunction : public fn::MultiFunction {
static void sh_node_curve_vec_build_multi_function(NodeMultiFunctionBuilder &builder)
{
- bNode &bnode = builder.node();
+ const bNode &bnode = builder.node();
CurveMapping *cumap = (CurveMapping *)bnode.storage;
BKE_curvemapping_init(cumap);
builder.construct_and_set_matching_fn<CurveVecFunction>(*cumap);
@@ -127,19 +132,24 @@ namespace blender::nodes::node_shader_curves_cc {
static void sh_node_curve_rgb_declare(NodeDeclarationBuilder &b)
{
b.is_function_node();
- b.add_input<decl::Float>(N_("Fac")).min(0.0f).max(1.0f).default_value(1.0f).subtype(PROP_FACTOR);
+ b.add_input<decl::Float>(N_("Fac"))
+ .no_muted_links()
+ .min(0.0f)
+ .max(1.0f)
+ .default_value(1.0f)
+ .subtype(PROP_FACTOR);
b.add_input<decl::Color>(N_("Color")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
b.add_output<decl::Color>(N_("Color"));
}
-static void node_shader_init_curve_rgb(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_curve_rgb(bNodeTree * /*ntree*/, bNode *node)
{
node->storage = BKE_curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);
}
static int gpu_shader_curve_rgb(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -218,7 +228,7 @@ class CurveRGBFunction : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
const VArray<float> &fac = params.readonly_single_input<float>(0, "Fac");
const VArray<ColorGeometry4f> &col_in = params.readonly_single_input<ColorGeometry4f>(1,
@@ -237,7 +247,7 @@ class CurveRGBFunction : public fn::MultiFunction {
static void sh_node_curve_rgb_build_multi_function(NodeMultiFunctionBuilder &builder)
{
- bNode &bnode = builder.node();
+ const bNode &bnode = builder.node();
CurveMapping *cumap = (CurveMapping *)bnode.storage;
BKE_curvemapping_init(cumap);
builder.construct_and_set_matching_fn<CurveRGBFunction>(*cumap);
@@ -270,6 +280,7 @@ static void sh_node_curve_float_declare(NodeDeclarationBuilder &b)
{
b.is_function_node();
b.add_input<decl::Float>(N_("Factor"))
+ .no_muted_links()
.min(0.0f)
.max(1.0f)
.default_value(1.0f)
@@ -278,14 +289,14 @@ static void sh_node_curve_float_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("Value"));
}
-static void node_shader_init_curve_float(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_curve_float(bNodeTree * /*ntree*/, bNode *node)
{
node->storage = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
}
static int gpu_shader_curve_float(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -339,7 +350,7 @@ class CurveFloatFunction : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
const VArray<float> &fac = params.readonly_single_input<float>(0, "Factor");
const VArray<float> &val_in = params.readonly_single_input<float>(1, "Value");
@@ -356,7 +367,7 @@ class CurveFloatFunction : public fn::MultiFunction {
static void sh_node_curve_float_build_multi_function(NodeMultiFunctionBuilder &builder)
{
- bNode &bnode = builder.node();
+ const bNode &bnode = builder.node();
CurveMapping *cumap = (CurveMapping *)bnode.storage;
BKE_curvemapping_init(cumap);
builder.construct_and_set_matching_fn<CurveFloatFunction>(*cumap);
diff --git a/source/blender/nodes/shader/nodes/node_shader_displacement.cc b/source/blender/nodes/shader/nodes/node_shader_displacement.cc
index 6591396adda..fd5a6107447 100644
--- a/source/blender/nodes/shader/nodes/node_shader_displacement.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_displacement.cc
@@ -14,7 +14,7 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Vector>(N_("Displacement"));
}
-static void node_shader_init_displacement(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_displacement(bNodeTree * /*ntree*/, bNode *node)
{
node->custom1 = SHD_SPACE_OBJECT; /* space */
@@ -28,7 +28,7 @@ static void node_shader_init_displacement(bNodeTree *UNUSED(ntree), bNode *node)
static int gpu_shader_displacement(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_eevee_specular.cc b/source/blender/nodes/shader/nodes/node_shader_eevee_specular.cc
index d68b0c0c37c..5a058eec690 100644
--- a/source/blender/nodes/shader/nodes/node_shader_eevee_specular.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_eevee_specular.cc
@@ -41,7 +41,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_eevee_specular(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -64,7 +64,7 @@ static int node_shader_gpu_eevee_specular(GPUMaterial *mat,
GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE | GPU_MATFLAG_GLOSSY);
- float use_clear = (socket_not_zero(6)) ? 1.0f : 0.0f;
+ float use_clear = socket_not_zero(6) ? 1.0f : 0.0f;
return GPU_stack_link(mat, node, "node_eevee_specular", in, out, GPU_constant(&use_clear));
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_emission.cc b/source/blender/nodes/shader/nodes/node_shader_emission.cc
index be98f096ce5..69c6094e92e 100644
--- a/source/blender/nodes/shader/nodes/node_shader_emission.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_emission.cc
@@ -15,7 +15,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_emission(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_fresnel.cc b/source/blender/nodes/shader/nodes/node_shader_fresnel.cc
index 7b771d7dafd..abbfc5ad1d5 100644
--- a/source/blender/nodes/shader/nodes/node_shader_fresnel.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_fresnel.cc
@@ -14,7 +14,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_fresnel(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_gamma.cc b/source/blender/nodes/shader/nodes/node_shader_gamma.cc
index d1e07c8b363..80419ed732c 100644
--- a/source/blender/nodes/shader/nodes/node_shader_gamma.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_gamma.cc
@@ -18,7 +18,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_gamma(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_geometry.cc b/source/blender/nodes/shader/nodes/node_shader_geometry.cc
index 47df932f9d4..e27b5290513 100644
--- a/source/blender/nodes/shader/nodes/node_shader_geometry.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_geometry.cc
@@ -20,7 +20,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_geometry(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -29,10 +29,9 @@ static int node_shader_gpu_geometry(GPUMaterial *mat,
if (out[5].hasoutput) {
GPU_material_flag_set(mat, GPU_MATFLAG_BARYCENTRIC);
}
- /* Opti: don't request orco if not needed. */
+ /* Optimization: don't request orco if not needed. */
const float val[4] = {0.0f, 0.0f, 0.0f, 0.0f};
- GPUNodeLink *orco_link = (!out[2].hasoutput) ? GPU_constant(val) :
- GPU_attribute(mat, CD_ORCO, "");
+ GPUNodeLink *orco_link = out[2].hasoutput ? GPU_attribute(mat, CD_ORCO, "") : GPU_constant(val);
const bool success = GPU_stack_link(mat, node, "node_geometry", in, out, orco_link);
diff --git a/source/blender/nodes/shader/nodes/node_shader_hair_info.cc b/source/blender/nodes/shader/nodes/node_shader_hair_info.cc
index 11d23e47735..2ae87f7bc51 100644
--- a/source/blender/nodes/shader/nodes/node_shader_hair_info.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_hair_info.cc
@@ -17,14 +17,14 @@ static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_hair_info(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
/* Length: don't request length if not needed. */
static const float zero = 0;
- GPUNodeLink *length_link = (!out[2].hasoutput) ? GPU_constant(&zero) :
- GPU_attribute(mat, CD_HAIRLENGTH, "");
+ GPUNodeLink *length_link = out[2].hasoutput ? GPU_attribute(mat, CD_HAIRLENGTH, "") :
+ GPU_constant(&zero);
return GPU_stack_link(mat, node, "node_hair_info", in, out, length_link);
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_holdout.cc b/source/blender/nodes/shader/nodes/node_shader_holdout.cc
index 6a21fab28db..ee754a7afa8 100644
--- a/source/blender/nodes/shader/nodes/node_shader_holdout.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_holdout.cc
@@ -13,7 +13,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int gpu_shader_rgb(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_hueSatVal.cc b/source/blender/nodes/shader/nodes/node_shader_hueSatVal.cc
index a2220ebccc7..3e057d3d230 100644
--- a/source/blender/nodes/shader/nodes/node_shader_hueSatVal.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_hueSatVal.cc
@@ -21,7 +21,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int gpu_shader_hue_sat(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_ies_light.cc b/source/blender/nodes/shader/nodes/node_shader_ies_light.cc
index bc1d662a17a..65655ba2781 100644
--- a/source/blender/nodes/shader/nodes/node_shader_ies_light.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_ies_light.cc
@@ -15,7 +15,7 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("Fac"));
}
-static void node_shader_buts_ies(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_ies(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *row;
@@ -32,7 +32,7 @@ static void node_shader_buts_ies(uiLayout *layout, bContext *UNUSED(C), PointerR
}
}
-static void node_shader_init_tex_ies(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_tex_ies(bNodeTree * /*ntree*/, bNode *node)
{
NodeShaderTexIES *tex = MEM_cnew<NodeShaderTexIES>("NodeShaderIESLight");
node->storage = tex;
diff --git a/source/blender/nodes/shader/nodes/node_shader_invert.cc b/source/blender/nodes/shader/nodes/node_shader_invert.cc
index f87455b555d..adcb0508093 100644
--- a/source/blender/nodes/shader/nodes/node_shader_invert.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_invert.cc
@@ -18,7 +18,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int gpu_shader_invert(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_layer_weight.cc b/source/blender/nodes/shader/nodes/node_shader_layer_weight.cc
index 69825e472fb..5a56ee8bc75 100644
--- a/source/blender/nodes/shader/nodes/node_shader_layer_weight.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_layer_weight.cc
@@ -15,7 +15,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_layer_weight(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_light_falloff.cc b/source/blender/nodes/shader/nodes/node_shader_light_falloff.cc
index 599becb4400..1ee096c052f 100644
--- a/source/blender/nodes/shader/nodes/node_shader_light_falloff.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_light_falloff.cc
@@ -16,7 +16,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_light_falloff(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_light_path.cc b/source/blender/nodes/shader/nodes/node_shader_light_path.cc
index 1e4ecbd77b1..268a80af0ab 100644
--- a/source/blender/nodes/shader/nodes/node_shader_light_path.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_light_path.cc
@@ -24,7 +24,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_light_path(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_map_range.cc b/source/blender/nodes/shader/nodes/node_shader_map_range.cc
index 5fc69987c67..e0c1778f764 100644
--- a/source/blender/nodes/shader/nodes/node_shader_map_range.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_map_range.cc
@@ -39,7 +39,7 @@ static void sh_node_map_range_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Vector>(N_("Vector"));
}
-static void node_shader_buts_map_range(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_map_range(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "data_type", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
uiItemR(layout, ptr, "interpolation_type", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
@@ -94,7 +94,7 @@ static void node_shader_update_map_range(bNodeTree *ntree, bNode *node)
}
}
-static void node_shader_init_map_range(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_map_range(bNodeTree * /*ntree*/, bNode *node)
{
NodeMapRange *data = MEM_cnew<NodeMapRange>(__func__);
data->clamp = 1;
@@ -197,7 +197,7 @@ static const char *gpu_shader_get_name(int mode, bool use_vector)
static int gpu_shader_map_range(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_mapping.cc b/source/blender/nodes/shader/nodes/node_shader_mapping.cc
index 7824ee4861c..89cd5af045b 100644
--- a/source/blender/nodes/shader/nodes/node_shader_mapping.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_mapping.cc
@@ -36,7 +36,7 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Vector>(N_("Vector"));
}
-static void node_shader_buts_mapping(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_mapping(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "vector_type", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
@@ -58,7 +58,7 @@ static const char *gpu_shader_get_name(int mode)
static int gpu_shader_mapping(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_math.cc b/source/blender/nodes/shader/nodes/node_shader_math.cc
index 8a2b18d7d76..3f25da4652d 100644
--- a/source/blender/nodes/shader/nodes/node_shader_math.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_math.cc
@@ -61,8 +61,9 @@ static void sh_node_math_gather_link_searches(GatherLinkSearchOpParams &params)
ELEM(item->value, NODE_MATH_COMPARE, NODE_MATH_GREATER_THAN, NODE_MATH_LESS_THAN)) ?
-1 :
weight;
- params.add_item(
- IFACE_(item->name), SocketSearchOp{"Value", (NodeMathOperation)item->value}, gn_weight);
+ params.add_item(CTX_IFACE_(BLT_I18NCONTEXT_ID_NODETREE, item->name),
+ SocketSearchOp{"Value", (NodeMathOperation)item->value},
+ gn_weight);
}
}
}
@@ -81,7 +82,7 @@ static const char *gpu_shader_get_name(int mode)
static int gpu_shader_math(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -101,7 +102,7 @@ static int gpu_shader_math(GPUMaterial *mat,
return 0;
}
-static const fn::MultiFunction *get_base_multi_function(bNode &node)
+static const fn::MultiFunction *get_base_multi_function(const bNode &node)
{
const int mode = node.custom1;
const fn::MultiFunction *base_fn = nullptr;
diff --git a/source/blender/nodes/shader/nodes/node_shader_mix.cc b/source/blender/nodes/shader/nodes/node_shader_mix.cc
new file mode 100644
index 00000000000..878648105d1
--- /dev/null
+++ b/source/blender/nodes/shader/nodes/node_shader_mix.cc
@@ -0,0 +1,469 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2005 Blender Foundation. All rights reserved. */
+
+/** \file
+ * \ingroup shdnodes
+ */
+
+#include <algorithm>
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "node_shader_util.hh"
+
+#include "NOD_socket_search_link.hh"
+#include "RNA_enum_types.h"
+
+namespace blender::nodes::node_sh_mix_cc {
+
+NODE_STORAGE_FUNCS(NodeShaderMix)
+
+static void sh_node_mix_declare(NodeDeclarationBuilder &b)
+{
+ b.is_function_node();
+ b.add_input<decl::Float>(N_("Factor"), "Factor_Float")
+ .no_muted_links()
+ .default_value(0.5f)
+ .min(0.0f)
+ .max(1.0f)
+ .subtype(PROP_FACTOR);
+ b.add_input<decl::Vector>(N_("Factor"), "Factor_Vector")
+ .no_muted_links()
+ .default_value(float3(0.5f))
+ .subtype(PROP_FACTOR);
+
+ b.add_input<decl::Float>(N_("A"), "A_Float")
+ .min(-10000.0f)
+ .max(10000.0f)
+ .is_default_link_socket();
+ b.add_input<decl::Float>(N_("B"), "B_Float").min(-10000.0f).max(10000.0f);
+
+ b.add_input<decl::Vector>(N_("A"), "A_Vector").is_default_link_socket();
+ b.add_input<decl::Vector>(N_("B"), "B_Vector");
+
+ b.add_input<decl::Color>(N_("A"), "A_Color")
+ .default_value({0.5f, 0.5f, 0.5f, 1.0f})
+ .is_default_link_socket();
+ b.add_input<decl::Color>(N_("B"), "B_Color").default_value({0.5f, 0.5f, 0.5f, 1.0f});
+
+ b.add_output<decl::Float>(N_("Result"), "Result_Float");
+ b.add_output<decl::Vector>(N_("Result"), "Result_Vector");
+ b.add_output<decl::Color>(N_("Result"), "Result_Color");
+};
+
+static void sh_node_mix_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
+{
+ const NodeShaderMix &data = node_storage(*static_cast<const bNode *>(ptr->data));
+ uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE);
+ if (data.data_type == SOCK_VECTOR) {
+ uiItemR(layout, ptr, "factor_mode", 0, "", ICON_NONE);
+ }
+ if (data.data_type == SOCK_RGBA) {
+ uiItemR(layout, ptr, "blend_type", 0, "", ICON_NONE);
+ uiItemR(layout, ptr, "clamp_result", 0, nullptr, ICON_NONE);
+ uiItemR(layout, ptr, "clamp_factor", 0, nullptr, ICON_NONE);
+ }
+ else {
+ uiItemR(layout, ptr, "clamp_factor", 0, nullptr, ICON_NONE);
+ }
+}
+
+static void sh_node_mix_label(const bNodeTree * /*ntree*/,
+ const bNode *node,
+ char *label,
+ int maxlen)
+{
+ const NodeShaderMix &storage = node_storage(*node);
+ if (storage.data_type == SOCK_RGBA) {
+ const char *name;
+ bool enum_label = RNA_enum_name(rna_enum_ramp_blend_items, storage.blend_type, &name);
+ if (!enum_label) {
+ name = "Unknown";
+ }
+ BLI_strncpy(label, IFACE_(name), maxlen);
+ }
+}
+
+static int sh_node_mix_ui_class(const bNode *node)
+{
+ const NodeShaderMix &storage = node_storage(*node);
+ const eNodeSocketDatatype data_type = static_cast<eNodeSocketDatatype>(storage.data_type);
+
+ switch (data_type) {
+ case SOCK_VECTOR:
+ return NODE_CLASS_OP_VECTOR;
+ case SOCK_RGBA:
+ return NODE_CLASS_OP_COLOR;
+ default:
+ return NODE_CLASS_CONVERTER;
+ }
+}
+
+static void sh_node_mix_update(bNodeTree *ntree, bNode *node)
+{
+ const NodeShaderMix &storage = node_storage(*node);
+ const eNodeSocketDatatype data_type = static_cast<eNodeSocketDatatype>(storage.data_type);
+
+ LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
+ nodeSetSocketAvailability(ntree, socket, socket->type == data_type);
+ }
+
+ LISTBASE_FOREACH (bNodeSocket *, socket, &node->outputs) {
+ nodeSetSocketAvailability(ntree, socket, socket->type == data_type);
+ }
+
+ bool use_vector_factor = data_type == SOCK_VECTOR &&
+ storage.factor_mode != NODE_MIX_MODE_UNIFORM;
+
+ bNodeSocket *sock_factor = (bNodeSocket *)BLI_findlink(&node->inputs, 0);
+ nodeSetSocketAvailability(ntree, sock_factor, !use_vector_factor);
+
+ bNodeSocket *sock_factor_vec = (bNodeSocket *)BLI_findlink(&node->inputs, 1);
+ nodeSetSocketAvailability(ntree, sock_factor_vec, use_vector_factor);
+}
+
+class SocketSearchOp {
+ public:
+ std::string socket_name;
+ int type = MA_RAMP_BLEND;
+ void operator()(LinkSearchOpParams &params)
+ {
+ bNode &node = params.add_node("ShaderNodeMix");
+ node_storage(node).data_type = SOCK_RGBA;
+ node_storage(node).blend_type = type;
+ params.update_and_connect_available_socket(node, socket_name);
+ }
+};
+
+static void node_mix_gather_link_searches(GatherLinkSearchOpParams &params)
+{
+ const eNodeSocketDatatype sock_type = static_cast<eNodeSocketDatatype>(
+ params.other_socket().type);
+
+ if (ELEM(sock_type, SOCK_BOOLEAN, SOCK_FLOAT, SOCK_RGBA, SOCK_VECTOR, SOCK_INT)) {
+ const eNodeSocketDatatype type = ELEM(sock_type, SOCK_BOOLEAN, SOCK_INT) ? SOCK_FLOAT :
+ sock_type;
+
+ const int weight = ELEM(params.other_socket().type, SOCK_RGBA) ? 0 : -1;
+ const std::string socket_name = params.in_out() == SOCK_IN ? "A" : "Result";
+ for (const EnumPropertyItem *item = rna_enum_ramp_blend_items; item->identifier != nullptr;
+ item++) {
+ if (item->name != nullptr && item->identifier[0] != '\0') {
+ params.add_item(CTX_IFACE_(BLT_I18NCONTEXT_ID_NODETREE, item->name),
+ SocketSearchOp{socket_name, item->value},
+ weight);
+ }
+ }
+
+ if (params.in_out() == SOCK_OUT) {
+ params.add_item(IFACE_("Result"), [type](LinkSearchOpParams &params) {
+ bNode &node = params.add_node("ShaderNodeMix");
+ node_storage(node).data_type = type;
+ params.update_and_connect_available_socket(node, "Result");
+ });
+ }
+ else {
+ if (ELEM(sock_type, SOCK_VECTOR, SOCK_RGBA)) {
+ params.add_item(IFACE_("Factor (Non-Uniform)"), [](LinkSearchOpParams &params) {
+ bNode &node = params.add_node("ShaderNodeMix");
+ node_storage(node).data_type = SOCK_VECTOR;
+ node_storage(node).factor_mode = NODE_MIX_MODE_NON_UNIFORM;
+ params.update_and_connect_available_socket(node, "Factor");
+ });
+ }
+ params.add_item(IFACE_("Factor"), [type](LinkSearchOpParams &params) {
+ bNode &node = params.add_node("ShaderNodeMix");
+ node_storage(node).data_type = type;
+ params.update_and_connect_available_socket(node, "Factor");
+ });
+ params.add_item(IFACE_("A"), [type](LinkSearchOpParams &params) {
+ bNode &node = params.add_node("ShaderNodeMix");
+ node_storage(node).data_type = type;
+ params.update_and_connect_available_socket(node, "A");
+ });
+ params.add_item(IFACE_("B"), [type](LinkSearchOpParams &params) {
+ bNode &node = params.add_node("ShaderNodeMix");
+ node_storage(node).data_type = type;
+ params.update_and_connect_available_socket(node, "B");
+ });
+ }
+ }
+}
+
+static void node_mix_init(bNodeTree * /*tree*/, bNode *node)
+{
+ NodeShaderMix *data = MEM_cnew<NodeShaderMix>(__func__);
+ data->data_type = SOCK_FLOAT;
+ data->factor_mode = NODE_MIX_MODE_UNIFORM;
+ data->clamp_factor = 1;
+ data->clamp_result = 0;
+ data->blend_type = MA_RAMP_BLEND;
+ node->storage = data;
+}
+
+static const char *gpu_shader_get_name(eNodeSocketDatatype data_type,
+ const bool non_uniform,
+ const int blend_type)
+{
+ switch (data_type) {
+ case SOCK_FLOAT:
+ return "node_mix_float";
+ case SOCK_VECTOR:
+ return (non_uniform) ? "node_mix_vector_non_uniform" : "node_mix_vector";
+ case SOCK_RGBA:
+ switch (blend_type) {
+ case MA_RAMP_BLEND:
+ return "node_mix_blend";
+ case MA_RAMP_ADD:
+ return "node_mix_add";
+ case MA_RAMP_MULT:
+ return "node_mix_mult";
+ case MA_RAMP_SUB:
+ return "node_mix_sub";
+ case MA_RAMP_SCREEN:
+ return "node_mix_screen";
+ case MA_RAMP_DIV:
+ return "node_mix_div_fallback";
+ case MA_RAMP_DIFF:
+ return "node_mix_diff";
+ case MA_RAMP_DARK:
+ return "node_mix_dark";
+ case MA_RAMP_LIGHT:
+ return "node_mix_light";
+ case MA_RAMP_OVERLAY:
+ return "node_mix_overlay";
+ case MA_RAMP_DODGE:
+ return "node_mix_dodge";
+ case MA_RAMP_BURN:
+ return "node_mix_burn";
+ case MA_RAMP_HUE:
+ return "node_mix_hue";
+ case MA_RAMP_SAT:
+ return "node_mix_sat";
+ case MA_RAMP_VAL:
+ return "node_mix_val";
+ case MA_RAMP_COLOR:
+ return "node_mix_color";
+ case MA_RAMP_SOFT:
+ return "node_mix_soft";
+ case MA_RAMP_LINEAR:
+ return "node_mix_linear";
+ default:
+ BLI_assert_unreachable();
+ return nullptr;
+ }
+ default:
+ BLI_assert_unreachable();
+ return nullptr;
+ }
+}
+
+static int gpu_shader_mix(GPUMaterial *mat,
+ bNode *node,
+ bNodeExecData * /*execdata*/,
+ GPUNodeStack *in,
+ GPUNodeStack *out)
+{
+ const NodeShaderMix &storage = node_storage(*node);
+ const bool is_non_uniform = storage.factor_mode == NODE_MIX_MODE_NON_UNIFORM;
+ const bool is_color_mode = storage.data_type == SOCK_RGBA;
+ const bool is_vector_mode = storage.data_type == SOCK_VECTOR;
+ const int blend_type = storage.blend_type;
+ const char *name = gpu_shader_get_name(
+ (eNodeSocketDatatype)storage.data_type, is_non_uniform, blend_type);
+
+ if (name == nullptr) {
+ return 0;
+ }
+
+ if (storage.clamp_factor) {
+ if (is_non_uniform && is_vector_mode) {
+ const float min[3] = {0.0f, 0.0f, 0.0f};
+ const float max[3] = {1.0f, 1.0f, 1.0f};
+ const GPUNodeLink *factor_link = in[1].link ? in[1].link : GPU_uniform(in[1].vec);
+ GPU_link(mat,
+ "node_mix_clamp_vector",
+ factor_link,
+ GPU_constant(min),
+ GPU_constant(max),
+ &in[1].link);
+ }
+ else {
+ const float min = 0.0f;
+ const float max = 1.0f;
+ const GPUNodeLink *factor_link = in[0].link ? in[0].link : GPU_uniform(in[0].vec);
+ GPU_link(mat,
+ "node_mix_clamp_value",
+ factor_link,
+ GPU_constant(&min),
+ GPU_constant(&max),
+ &in[0].link);
+ }
+ }
+
+ int ret = GPU_stack_link(mat, node, name, in, out);
+
+ if (ret && is_color_mode && storage.clamp_result) {
+ const float min[3] = {0.0f, 0.0f, 0.0f};
+ const float max[3] = {1.0f, 1.0f, 1.0f};
+ GPU_link(mat,
+ "node_mix_clamp_vector",
+ out[2].link,
+ GPU_constant(min),
+ GPU_constant(max),
+ &out[2].link);
+ }
+ return ret;
+}
+
+class MixColorFunction : public fn::MultiFunction {
+ private:
+ const bool clamp_factor_;
+ const bool clamp_result_;
+ const int blend_type_;
+
+ public:
+ MixColorFunction(const bool clamp_factor, const bool clamp_result, const int blend_type)
+ : clamp_factor_(clamp_factor), clamp_result_(clamp_result), blend_type_(blend_type)
+ {
+ static fn::MFSignature signature = create_signature();
+ this->set_signature(&signature);
+ }
+
+ static fn::MFSignature create_signature()
+ {
+ fn::MFSignatureBuilder signature{"MixColor"};
+ signature.single_input<float>("Factor");
+ signature.single_input<ColorGeometry4f>("A");
+ signature.single_input<ColorGeometry4f>("B");
+ signature.single_output<ColorGeometry4f>("Result");
+ return signature.build();
+ }
+
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
+ {
+ const VArray<float> &fac = params.readonly_single_input<float>(0, "Factor");
+ const VArray<ColorGeometry4f> &col1 = params.readonly_single_input<ColorGeometry4f>(1, "A");
+ const VArray<ColorGeometry4f> &col2 = params.readonly_single_input<ColorGeometry4f>(2, "B");
+ MutableSpan<ColorGeometry4f> results = params.uninitialized_single_output<ColorGeometry4f>(
+ 3, "Result");
+
+ if (clamp_factor_) {
+ for (int64_t i : mask) {
+ results[i] = col1[i];
+ ramp_blend(blend_type_, results[i], std::clamp(fac[i], 0.0f, 1.0f), col2[i]);
+ }
+ }
+ else {
+ for (int64_t i : mask) {
+ results[i] = col1[i];
+ ramp_blend(blend_type_, results[i], fac[i], col2[i]);
+ }
+ }
+
+ if (clamp_result_) {
+ for (int64_t i : mask) {
+ clamp_v3(results[i], 0.0f, 1.0f);
+ }
+ }
+ }
+};
+
+static const fn::MultiFunction *get_multi_function(const bNode &node)
+{
+ const NodeShaderMix *data = (NodeShaderMix *)node.storage;
+ bool uniform_factor = data->factor_mode == NODE_MIX_MODE_UNIFORM;
+ const bool clamp_factor = data->clamp_factor;
+ switch (data->data_type) {
+ case SOCK_FLOAT: {
+ if (clamp_factor) {
+ static fn::CustomMF_SI_SI_SI_SO<float, float, float, float> fn{
+ "Clamp Mix Float", [](float t, const float a, const float b) {
+ return math::interpolate(a, b, std::clamp(t, 0.0f, 1.0f));
+ }};
+ return &fn;
+ }
+ else {
+ static fn::CustomMF_SI_SI_SI_SO<float, float, float, float> fn{
+ "Mix Float", [](const float t, const float a, const float b) {
+ return math::interpolate(a, b, t);
+ }};
+ return &fn;
+ }
+ }
+ case SOCK_VECTOR: {
+ if (clamp_factor) {
+ if (uniform_factor) {
+ static fn::CustomMF_SI_SI_SI_SO<float, float3, float3, float3> fn{
+ "Clamp Mix Vector", [](const float t, const float3 a, const float3 b) {
+ return math::interpolate(a, b, std::clamp(t, 0.0f, 1.0f));
+ }};
+ return &fn;
+ }
+ else {
+ static fn::CustomMF_SI_SI_SI_SO<float3, float3, float3, float3> fn{
+ "Clamp Mix Vector Non Uniform", [](float3 t, const float3 a, const float3 b) {
+ t = math::clamp(t, 0.0f, 1.0f);
+ return a * (float3(1.0f) - t) + b * t;
+ }};
+ return &fn;
+ }
+ }
+ else {
+ if (uniform_factor) {
+ static fn::CustomMF_SI_SI_SI_SO<float, float3, float3, float3> fn{
+ "Mix Vector", [](const float t, const float3 a, const float3 b) {
+ return math::interpolate(a, b, t);
+ }};
+ return &fn;
+ }
+ else {
+ static fn::CustomMF_SI_SI_SI_SO<float3, float3, float3, float3> fn{
+ "Mix Vector Non Uniform", [](const float3 t, const float3 a, const float3 b) {
+ return a * (float3(1.0f) - t) + b * t;
+ }};
+ return &fn;
+ }
+ }
+ }
+ }
+ BLI_assert_unreachable();
+ return nullptr;
+}
+
+static void sh_node_mix_build_multi_function(NodeMultiFunctionBuilder &builder)
+{
+ const NodeShaderMix &storage = node_storage(builder.node());
+
+ if (storage.data_type == SOCK_RGBA) {
+ builder.construct_and_set_matching_fn<MixColorFunction>(
+ storage.clamp_factor, storage.clamp_result, storage.blend_type);
+ }
+ else {
+ const fn::MultiFunction *fn = get_multi_function(builder.node());
+ builder.set_matching_fn(fn);
+ }
+}
+
+} // namespace blender::nodes::node_sh_mix_cc
+
+void register_node_type_sh_mix()
+{
+ namespace file_ns = blender::nodes::node_sh_mix_cc;
+
+ static bNodeType ntype;
+ sh_fn_node_type_base(&ntype, SH_NODE_MIX, "Mix", NODE_CLASS_CONVERTER);
+ ntype.declare = file_ns::sh_node_mix_declare;
+ ntype.ui_class = file_ns::sh_node_mix_ui_class;
+ node_type_gpu(&ntype, file_ns::gpu_shader_mix);
+ node_type_update(&ntype, file_ns::sh_node_mix_update);
+ node_type_init(&ntype, file_ns::node_mix_init);
+ node_type_storage(
+ &ntype, "NodeShaderMix", node_free_standard_storage, node_copy_standard_storage);
+ ntype.build_multi_function = file_ns::sh_node_mix_build_multi_function;
+ ntype.draw_buttons = file_ns::sh_node_mix_layout;
+ ntype.labelfunc = file_ns::sh_node_mix_label;
+ ntype.gather_link_search_ops = file_ns::node_mix_gather_link_searches;
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/shader/nodes/node_shader_mix_rgb.cc b/source/blender/nodes/shader/nodes/node_shader_mix_rgb.cc
index 12707623049..d1578b48c79 100644
--- a/source/blender/nodes/shader/nodes/node_shader_mix_rgb.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_mix_rgb.cc
@@ -32,7 +32,7 @@ static const char *gpu_shader_get_name(int mode)
case MA_RAMP_SCREEN:
return "mix_screen";
case MA_RAMP_DIV:
- return "mix_div";
+ return "mix_div_fallback";
case MA_RAMP_DIFF:
return "mix_diff";
case MA_RAMP_DARK:
@@ -64,24 +64,29 @@ static const char *gpu_shader_get_name(int mode)
static int gpu_shader_mix_rgb(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
const char *name = gpu_shader_get_name(node->custom1);
- if (name != nullptr) {
- int ret = GPU_stack_link(mat, node, name, in, out);
- if (ret && node->custom2 & SHD_MIXRGB_CLAMP) {
- const float min[3] = {0.0f, 0.0f, 0.0f};
- const float max[3] = {1.0f, 1.0f, 1.0f};
- GPU_link(
- mat, "clamp_color", out[0].link, GPU_constant(min), GPU_constant(max), &out[0].link);
- }
- return ret;
+ if (name == nullptr) {
+ return 0;
}
- return 0;
+ const float min = 0.0f;
+ const float max = 1.0f;
+ const GPUNodeLink *factor_link = in[0].link ? in[0].link : GPU_uniform(in[0].vec);
+ GPU_link(mat, "clamp_value", factor_link, GPU_constant(&min), GPU_constant(&max), &in[0].link);
+
+ int ret = GPU_stack_link(mat, node, name, in, out);
+
+ if (ret && node->custom2 & SHD_MIXRGB_CLAMP) {
+ const float min[3] = {0.0f, 0.0f, 0.0f};
+ const float max[3] = {1.0f, 1.0f, 1.0f};
+ GPU_link(mat, "clamp_color", out[0].link, GPU_constant(min), GPU_constant(max), &out[0].link);
+ }
+ return ret;
}
class MixRGBFunction : public fn::MultiFunction {
@@ -106,7 +111,7 @@ class MixRGBFunction : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
const VArray<float> &fac = params.readonly_single_input<float>(0, "Fac");
const VArray<ColorGeometry4f> &col1 = params.readonly_single_input<ColorGeometry4f>(1,
@@ -131,7 +136,7 @@ class MixRGBFunction : public fn::MultiFunction {
static void sh_node_mix_rgb_build_multi_function(NodeMultiFunctionBuilder &builder)
{
- bNode &node = builder.node();
+ const bNode &node = builder.node();
bool clamp = node.custom2 & SHD_MIXRGB_CLAMP;
int mix_type = node.custom1;
builder.construct_and_set_matching_fn<MixRGBFunction>(clamp, mix_type);
@@ -145,11 +150,11 @@ void register_node_type_sh_mix_rgb()
static bNodeType ntype;
- sh_fn_node_type_base(&ntype, SH_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR);
+ sh_fn_node_type_base(&ntype, SH_NODE_MIX_RGB_LEGACY, "Mix (Legacy)", NODE_CLASS_OP_COLOR);
ntype.declare = file_ns::sh_node_mix_rgb_declare;
ntype.labelfunc = node_blend_label;
node_type_gpu(&ntype, file_ns::gpu_shader_mix_rgb);
ntype.build_multi_function = file_ns::sh_node_mix_rgb_build_multi_function;
-
+ ntype.gather_link_search_ops = nullptr;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_mix_shader.cc b/source/blender/nodes/shader/nodes/node_shader_mix_shader.cc
index 7740bf9b92a..27e41406b48 100644
--- a/source/blender/nodes/shader/nodes/node_shader_mix_shader.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_mix_shader.cc
@@ -15,7 +15,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_mix_shader(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_normal.cc b/source/blender/nodes/shader/nodes/node_shader_normal.cc
index f6214dd9c89..49c075ac27e 100644
--- a/source/blender/nodes/shader/nodes/node_shader_normal.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_normal.cc
@@ -26,7 +26,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int gpu_shader_normal(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_normal_map.cc b/source/blender/nodes/shader/nodes/node_shader_normal_map.cc
index d51d8def945..99cb5f6f525 100644
--- a/source/blender/nodes/shader/nodes/node_shader_normal_map.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_normal_map.cc
@@ -34,7 +34,7 @@ static void node_shader_buts_normal_map(uiLayout *layout, bContext *C, PointerRN
}
}
-static void node_shader_init_normal_map(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_normal_map(bNodeTree * /*ntree*/, bNode *node)
{
NodeShaderNormalMap *attr = MEM_cnew<NodeShaderNormalMap>("NodeShaderNormalMap");
node->storage = attr;
@@ -42,7 +42,7 @@ static void node_shader_init_normal_map(bNodeTree *UNUSED(ntree), bNode *node)
static int gpu_shader_normal_map(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_object_info.cc b/source/blender/nodes/shader/nodes/node_shader_object_info.cc
index 8985ab6d0e9..210f855b9e0 100644
--- a/source/blender/nodes/shader/nodes/node_shader_object_info.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_object_info.cc
@@ -17,7 +17,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_object_info(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_output_aov.cc b/source/blender/nodes/shader/nodes/node_shader_output_aov.cc
index 78dabc5c1c2..cc95db9d333 100644
--- a/source/blender/nodes/shader/nodes/node_shader_output_aov.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_output_aov.cc
@@ -16,12 +16,12 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_input<decl::Float>(N_("Value")).default_value(0.0f).min(0.0f).max(1.0f);
}
-static void node_shader_buts_output_aov(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_output_aov(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "name", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
-static void node_shader_init_output_aov(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_output_aov(bNodeTree * /*ntree*/, bNode *node)
{
NodeShaderOutputAOV *aov = MEM_cnew<NodeShaderOutputAOV>("NodeShaderOutputAOV");
node->storage = aov;
@@ -29,7 +29,7 @@ static void node_shader_init_output_aov(bNodeTree *UNUSED(ntree), bNode *node)
static int node_shader_gpu_output_aov(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_output_light.cc b/source/blender/nodes/shader/nodes/node_shader_output_light.cc
index 3707806841e..6e4483dbbe9 100644
--- a/source/blender/nodes/shader/nodes/node_shader_output_light.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_output_light.cc
@@ -11,10 +11,10 @@ static void node_declare(NodeDeclarationBuilder &b)
}
static int node_shader_gpu_output_light(GPUMaterial *mat,
- bNode *UNUSED(node),
- bNodeExecData *UNUSED(execdata),
+ bNode * /*node*/,
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
- GPUNodeStack *UNUSED(out))
+ GPUNodeStack * /*out*/)
{
GPUNodeLink *outlink_surface;
/* Passthrough node in order to do the right socket conversions. */
diff --git a/source/blender/nodes/shader/nodes/node_shader_output_linestyle.cc b/source/blender/nodes/shader/nodes/node_shader_output_linestyle.cc
index b387aebf5e3..47909985374 100644
--- a/source/blender/nodes/shader/nodes/node_shader_output_linestyle.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_output_linestyle.cc
@@ -28,7 +28,7 @@ static void node_declare(NodeDeclarationBuilder &b)
.subtype(PROP_FACTOR);
}
-static void node_buts_output_linestyle(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_buts_output_linestyle(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *row, *col;
diff --git a/source/blender/nodes/shader/nodes/node_shader_output_material.cc b/source/blender/nodes/shader/nodes/node_shader_output_material.cc
index 133457c167f..857c5eb68df 100644
--- a/source/blender/nodes/shader/nodes/node_shader_output_material.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_output_material.cc
@@ -16,10 +16,10 @@ static void node_declare(NodeDeclarationBuilder &b)
}
static int node_shader_gpu_output_material(GPUMaterial *mat,
- bNode *UNUSED(node),
- bNodeExecData *UNUSED(execdata),
+ bNode * /*node*/,
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
- GPUNodeStack *UNUSED(out))
+ GPUNodeStack * /*out*/)
{
GPUNodeLink *outlink_surface, *outlink_volume, *outlink_displacement, *outlink_thickness;
/* Passthrough node in order to do the right socket conversions (important for displacement). */
diff --git a/source/blender/nodes/shader/nodes/node_shader_output_world.cc b/source/blender/nodes/shader/nodes/node_shader_output_world.cc
index b0cf4c80bc5..f450e667cd9 100644
--- a/source/blender/nodes/shader/nodes/node_shader_output_world.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_output_world.cc
@@ -12,10 +12,10 @@ static void node_declare(NodeDeclarationBuilder &b)
}
static int node_shader_gpu_output_world(GPUMaterial *mat,
- bNode *UNUSED(node),
- bNodeExecData *UNUSED(execdata),
+ bNode * /*node*/,
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
- GPUNodeStack *UNUSED(out))
+ GPUNodeStack * /*out*/)
{
GPUNodeLink *outlink_surface, *outlink_volume;
if (in[0].link) {
diff --git a/source/blender/nodes/shader/nodes/node_shader_particle_info.cc b/source/blender/nodes/shader/nodes/node_shader_particle_info.cc
index 71adbd5e5c4..76a91ab60aa 100644
--- a/source/blender/nodes/shader/nodes/node_shader_particle_info.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_particle_info.cc
@@ -24,7 +24,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int gpu_shader_particle_info(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_point_info.cc b/source/blender/nodes/shader/nodes/node_shader_point_info.cc
index 1cddf2acc8a..05b649490e4 100644
--- a/source/blender/nodes/shader/nodes/node_shader_point_info.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_point_info.cc
@@ -14,7 +14,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_point_info(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_rgb.cc b/source/blender/nodes/shader/nodes/node_shader_rgb.cc
index 38acfab322f..1adbbbc48bc 100644
--- a/source/blender/nodes/shader/nodes/node_shader_rgb.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_rgb.cc
@@ -16,12 +16,13 @@ static void node_declare(NodeDeclarationBuilder &b)
static int gpu_shader_rgb(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
- GPUNodeStack *in,
+ bNodeExecData * /*execdata*/,
+ GPUNodeStack * /*in*/,
GPUNodeStack *out)
{
- GPUNodeLink *link = GPU_uniformbuf_link_out(mat, node, out, 0);
- return GPU_stack_link(mat, node, "set_rgba", in, out, link);
+ const bNodeSocket *socket = static_cast<bNodeSocket *>(node->outputs.first);
+ float *value = static_cast<bNodeSocketValueRGBA *>(socket->default_value)->value;
+ return GPU_link(mat, "set_rgba", GPU_uniform(value), &out->link);
}
} // namespace blender::nodes::node_shader_rgb_cc
diff --git a/source/blender/nodes/shader/nodes/node_shader_rgb_to_bw.cc b/source/blender/nodes/shader/nodes/node_shader_rgb_to_bw.cc
index 7d738cdd719..1db3342733b 100644
--- a/source/blender/nodes/shader/nodes/node_shader_rgb_to_bw.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_rgb_to_bw.cc
@@ -19,7 +19,7 @@ static void sh_node_rgbtobw_declare(NodeDeclarationBuilder &b)
static int gpu_shader_rgbtobw(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_script.cc b/source/blender/nodes/shader/nodes/node_shader_script.cc
index 4d3d2af6aa6..8534ce129b4 100644
--- a/source/blender/nodes/shader/nodes/node_shader_script.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_script.cc
@@ -12,7 +12,7 @@
namespace blender::nodes::node_shader_script_cc {
-static void node_shader_buts_script(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_script(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *row;
@@ -44,7 +44,7 @@ static void node_shader_buts_script_ex(uiLayout *layout, bContext *C, PointerRNA
#endif
}
-static void init(bNodeTree *UNUSED(ntree), bNode *node)
+static void init(bNodeTree * /*ntree*/, bNode *node)
{
NodeShaderScript *nss = MEM_cnew<NodeShaderScript>("shader script node");
node->storage = nss;
@@ -63,9 +63,7 @@ static void node_free_script(bNode *node)
}
}
-static void node_copy_script(bNodeTree *UNUSED(dest_ntree),
- bNode *dest_node,
- const bNode *src_node)
+static void node_copy_script(bNodeTree * /*dst_ntree*/, bNode *dest_node, const bNode *src_node)
{
NodeShaderScript *src_nss = static_cast<NodeShaderScript *>(src_node->storage);
NodeShaderScript *dest_nss = static_cast<NodeShaderScript *>(MEM_dupallocN(src_nss));
diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcomb_color.cc b/source/blender/nodes/shader/nodes/node_shader_sepcomb_color.cc
index 8e378ebabce..77ce6f5e4e4 100644
--- a/source/blender/nodes/shader/nodes/node_shader_sepcomb_color.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_sepcomb_color.cc
@@ -10,7 +10,7 @@
#include "UI_interface.h"
#include "UI_resources.h"
-static void node_combsep_color_init(bNodeTree *UNUSED(tree), bNode *node)
+static void node_combsep_color_init(bNodeTree * /*tree*/, bNode *node)
{
NodeCombSepColor *data = MEM_cnew<NodeCombSepColor>(__func__);
data->mode = NODE_COMBSEP_COLOR_RGB;
@@ -31,7 +31,7 @@ static void sh_node_sepcolor_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("Blue"));
}
-static void node_sepcolor_update(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_sepcolor_update(bNodeTree * /*ntree*/, bNode *node)
{
const NodeCombSepColor &storage = node_storage(*node);
node_combsep_color_label(&node->outputs, (NodeCombSepColorMode)storage.mode);
@@ -53,7 +53,7 @@ static const char *gpu_shader_get_name(int mode)
static int gpu_shader_sepcolor(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -107,7 +107,7 @@ static void sh_node_combcolor_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Color>(N_("Color"));
}
-static void node_combcolor_update(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_combcolor_update(bNodeTree * /*ntree*/, bNode *node)
{
const NodeCombSepColor &storage = node_storage(*node);
node_combsep_color_label(&node->inputs, (NodeCombSepColorMode)storage.mode);
@@ -129,7 +129,7 @@ static const char *gpu_shader_get_name(int mode)
static int gpu_shader_combcolor(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcomb_hsv.cc b/source/blender/nodes/shader/nodes/node_shader_sepcomb_hsv.cc
index 6dfabe48292..b297ead1847 100644
--- a/source/blender/nodes/shader/nodes/node_shader_sepcomb_hsv.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_sepcomb_hsv.cc
@@ -21,7 +21,7 @@ static void node_declare_sephsv(NodeDeclarationBuilder &b)
static int gpu_shader_sephsv(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -36,9 +36,10 @@ void register_node_type_sh_sephsv()
static bNodeType ntype;
- sh_node_type_base(&ntype, SH_NODE_SEPHSV_LEGACY, "Separate HSV", NODE_CLASS_CONVERTER);
+ sh_node_type_base(&ntype, SH_NODE_SEPHSV_LEGACY, "Separate HSV (Legacy)", NODE_CLASS_CONVERTER);
ntype.declare = file_ns::node_declare_sephsv;
node_type_gpu(&ntype, file_ns::gpu_shader_sephsv);
+ ntype.gather_link_search_ops = nullptr;
nodeRegisterType(&ntype);
}
@@ -57,7 +58,7 @@ static void node_declare_combhsv(NodeDeclarationBuilder &b)
static int gpu_shader_combhsv(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -72,9 +73,10 @@ void register_node_type_sh_combhsv()
static bNodeType ntype;
- sh_node_type_base(&ntype, SH_NODE_COMBHSV_LEGACY, "Combine HSV", NODE_CLASS_CONVERTER);
+ sh_node_type_base(&ntype, SH_NODE_COMBHSV_LEGACY, "Combine HSV (Legacy)", NODE_CLASS_CONVERTER);
ntype.declare = file_ns::node_declare_combhsv;
node_type_gpu(&ntype, file_ns::gpu_shader_combhsv);
+ ntype.gather_link_search_ops = nullptr;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcomb_rgb.cc b/source/blender/nodes/shader/nodes/node_shader_sepcomb_rgb.cc
index 28b55047633..c298998cad5 100644
--- a/source/blender/nodes/shader/nodes/node_shader_sepcomb_rgb.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_sepcomb_rgb.cc
@@ -20,7 +20,7 @@ static void sh_node_seprgb_declare(NodeDeclarationBuilder &b)
static int gpu_shader_seprgb(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -45,7 +45,7 @@ class SeparateRGBFunction : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
const VArray<ColorGeometry4f> &colors = params.readonly_single_input<ColorGeometry4f>(0,
"Color");
@@ -76,10 +76,12 @@ void register_node_type_sh_seprgb()
static bNodeType ntype;
- sh_fn_node_type_base(&ntype, SH_NODE_SEPRGB_LEGACY, "Separate RGB", NODE_CLASS_CONVERTER);
+ sh_fn_node_type_base(
+ &ntype, SH_NODE_SEPRGB_LEGACY, "Separate RGB (Legacy)", NODE_CLASS_CONVERTER);
ntype.declare = file_ns::sh_node_seprgb_declare;
node_type_gpu(&ntype, file_ns::gpu_shader_seprgb);
ntype.build_multi_function = file_ns::sh_node_seprgb_build_multi_function;
+ ntype.gather_link_search_ops = nullptr;
nodeRegisterType(&ntype);
}
@@ -97,7 +99,7 @@ static void sh_node_combrgb_declare(NodeDeclarationBuilder &b)
static int gpu_shader_combrgb(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -119,10 +121,12 @@ void register_node_type_sh_combrgb()
static bNodeType ntype;
- sh_fn_node_type_base(&ntype, SH_NODE_COMBRGB_LEGACY, "Combine RGB", NODE_CLASS_CONVERTER);
+ sh_fn_node_type_base(
+ &ntype, SH_NODE_COMBRGB_LEGACY, "Combine RGB (Legacy)", NODE_CLASS_CONVERTER);
ntype.declare = file_ns::sh_node_combrgb_declare;
node_type_gpu(&ntype, file_ns::gpu_shader_combrgb);
ntype.build_multi_function = file_ns::sh_node_combrgb_build_multi_function;
+ ntype.gather_link_search_ops = nullptr;
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcomb_xyz.cc b/source/blender/nodes/shader/nodes/node_shader_sepcomb_xyz.cc
index d4413036555..8849824ec0b 100644
--- a/source/blender/nodes/shader/nodes/node_shader_sepcomb_xyz.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_sepcomb_xyz.cc
@@ -20,7 +20,7 @@ static void sh_node_sepxyz_declare(NodeDeclarationBuilder &b)
static int gpu_shader_sepxyz(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -45,7 +45,7 @@ class MF_SeparateXYZ : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
const VArray<float3> &vectors = params.readonly_single_input<float3>(0, "XYZ");
MutableSpan<float> xs = params.uninitialized_single_output_if_required<float>(1, "X");
@@ -116,7 +116,7 @@ static void sh_node_combxyz_declare(NodeDeclarationBuilder &b)
static int gpu_shader_combxyz(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_shader_to_rgb.cc b/source/blender/nodes/shader/nodes/node_shader_shader_to_rgb.cc
index 0404158a803..7345e374937 100644
--- a/source/blender/nodes/shader/nodes/node_shader_shader_to_rgb.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_shader_to_rgb.cc
@@ -14,7 +14,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_shadertorgb(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_squeeze.cc b/source/blender/nodes/shader/nodes/node_shader_squeeze.cc
index c22420d8d47..62e21088791 100644
--- a/source/blender/nodes/shader/nodes/node_shader_squeeze.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_squeeze.cc
@@ -19,7 +19,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int gpu_shader_squeeze(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.cc b/source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.cc
index e3ff4c28604..29d42b20a80 100644
--- a/source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.cc
@@ -29,12 +29,12 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Shader>(N_("BSSRDF"));
}
-static void node_shader_buts_subsurface(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_subsurface(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "falloff", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
-static void node_shader_init_subsurface_scattering(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_subsurface_scattering(bNodeTree * /*ntree*/, bNode *node)
{
node->custom1 = SHD_SUBSURFACE_RANDOM_WALK;
node->custom2 = true;
@@ -42,7 +42,7 @@ static void node_shader_init_subsurface_scattering(bNodeTree *UNUSED(ntree), bNo
static int node_shader_gpu_subsurface_scattering(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_tangent.cc b/source/blender/nodes/shader/nodes/node_shader_tangent.cc
index 8e27ebed21b..c2116c9c0ff 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tangent.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_tangent.cc
@@ -41,7 +41,7 @@ static void node_shader_buts_tangent(uiLayout *layout, bContext *C, PointerRNA *
}
}
-static void node_shader_init_tangent(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_tangent(bNodeTree * /*ntree*/, bNode *node)
{
NodeShaderTangent *attr = MEM_cnew<NodeShaderTangent>("NodeShaderTangent");
attr->axis = SHD_TANGENT_AXIS_Z;
@@ -50,7 +50,7 @@ static void node_shader_init_tangent(bNodeTree *UNUSED(ntree), bNode *node)
static int node_shader_gpu_tangent(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_brick.cc b/source/blender/nodes/shader/nodes/node_shader_tex_brick.cc
index cad9e1b33f2..f6bcedbd19e 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_brick.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_brick.cc
@@ -13,7 +13,10 @@ namespace blender::nodes::node_shader_tex_brick_cc {
static void sh_node_tex_brick_declare(NodeDeclarationBuilder &b)
{
b.is_function_node();
- b.add_input<decl::Vector>(N_("Vector")).min(-10000.0f).max(10000.0f).implicit_field();
+ b.add_input<decl::Vector>(N_("Vector"))
+ .min(-10000.0f)
+ .max(10000.0f)
+ .implicit_field(implicit_field_inputs::position);
b.add_input<decl::Color>(N_("Color1")).default_value({0.8f, 0.8f, 0.8f, 1.0f});
b.add_input<decl::Color>(N_("Color2")).default_value({0.2f, 0.2f, 0.2f, 1.0f});
b.add_input<decl::Color>(N_("Mortar")).default_value({0.0f, 0.0f, 0.0f, 1.0f}).no_muted_links();
@@ -43,7 +46,7 @@ static void sh_node_tex_brick_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("Fac"));
}
-static void node_shader_buts_tex_brick(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_tex_brick(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col;
@@ -63,7 +66,7 @@ static void node_shader_buts_tex_brick(uiLayout *layout, bContext *UNUSED(C), Po
col, ptr, "squash_frequency", UI_ITEM_R_SPLIT_EMPTY_NAME, IFACE_("Frequency"), ICON_NONE);
}
-static void node_shader_init_tex_brick(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_tex_brick(bNodeTree * /*ntree*/, bNode *node)
{
NodeTexBrick *tex = MEM_cnew<NodeTexBrick>(__func__);
BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT);
@@ -85,7 +88,7 @@ static void node_shader_init_tex_brick(bNodeTree *UNUSED(ntree), bNode *node)
static int node_shader_gpu_tex_brick(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -147,7 +150,7 @@ class BrickFunction : public fn::MultiFunction {
n = (n + 1013) & 0x7fffffff;
n = (n >> 13) ^ n;
const uint nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;
- return 0.5f * ((float)nn / 1073741824.0f);
+ return 0.5f * (float(nn) / 1073741824.0f);
}
static float smoothstepf(const float f)
@@ -169,14 +172,14 @@ class BrickFunction : public fn::MultiFunction {
{
float offset = 0.0f;
- const int rownum = (int)floorf(p.y / row_height);
+ const int rownum = int(floorf(p.y / row_height));
if (offset_frequency && squash_frequency) {
brick_width *= (rownum % squash_frequency) ? 1.0f : squash_amount;
offset = (rownum % offset_frequency) ? 0.0f : (brick_width * offset_amount);
}
- const int bricknum = (int)floorf((p.x + offset) / brick_width);
+ const int bricknum = int(floorf((p.x + offset) / brick_width));
const float x = (p.x + offset) - brick_width * bricknum;
const float y = p.y - row_height * rownum;
@@ -200,7 +203,7 @@ class BrickFunction : public fn::MultiFunction {
return float2(tint, mortar);
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
const VArray<float3> &vector = params.readonly_single_input<float3>(0, "Vector");
const VArray<ColorGeometry4f> &color1_values = params.readonly_single_input<ColorGeometry4f>(
@@ -261,7 +264,7 @@ class BrickFunction : public fn::MultiFunction {
static void sh_node_brick_build_multi_function(NodeMultiFunctionBuilder &builder)
{
- bNode &node = builder.node();
+ const bNode &node = builder.node();
NodeTexBrick *tex = (NodeTexBrick *)node.storage;
builder.construct_and_set_matching_fn<BrickFunction>(
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_checker.cc b/source/blender/nodes/shader/nodes/node_shader_tex_checker.cc
index b0e5639c893..c48f79698bb 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_checker.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_checker.cc
@@ -8,7 +8,10 @@ namespace blender::nodes::node_shader_tex_checker_cc {
static void sh_node_tex_checker_declare(NodeDeclarationBuilder &b)
{
b.is_function_node();
- b.add_input<decl::Vector>(N_("Vector")).min(-10000.0f).max(10000.0f).implicit_field();
+ b.add_input<decl::Vector>(N_("Vector"))
+ .min(-10000.0f)
+ .max(10000.0f)
+ .implicit_field(implicit_field_inputs::position);
b.add_input<decl::Color>(N_("Color1")).default_value({0.8f, 0.8f, 0.8f, 1.0f});
b.add_input<decl::Color>(N_("Color2")).default_value({0.2f, 0.2f, 0.2f, 1.0f});
b.add_input<decl::Float>(N_("Scale"))
@@ -20,7 +23,7 @@ static void sh_node_tex_checker_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("Fac"));
}
-static void node_shader_init_tex_checker(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_tex_checker(bNodeTree * /*ntree*/, bNode *node)
{
NodeTexChecker *tex = MEM_cnew<NodeTexChecker>(__func__);
BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT);
@@ -31,7 +34,7 @@ static void node_shader_init_tex_checker(bNodeTree *UNUSED(ntree), bNode *node)
static int node_shader_gpu_tex_checker(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -61,7 +64,7 @@ class NodeTexChecker : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
const VArray<float3> &vector = params.readonly_single_input<float3>(0, "Vector");
const VArray<ColorGeometry4f> &color1 = params.readonly_single_input<ColorGeometry4f>(
@@ -77,9 +80,9 @@ class NodeTexChecker : public fn::MultiFunction {
/* Avoid precision issues on unit coordinates. */
const float3 p = (vector[i] * scale[i] + 0.000001f) * 0.999999f;
- const int xi = abs((int)(floorf(p.x)));
- const int yi = abs((int)(floorf(p.y)));
- const int zi = abs((int)(floorf(p.z)));
+ const int xi = abs(int(floorf(p.x)));
+ const int yi = abs(int(floorf(p.y)));
+ const int zi = abs(int(floorf(p.z)));
r_fac[i] = ((xi % 2 == yi % 2) == (zi % 2)) ? 1.0f : 0.0f;
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_coord.cc b/source/blender/nodes/shader/nodes/node_shader_tex_coord.cc
index fb5971021fc..e2a40b79d53 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_coord.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_coord.cc
@@ -21,7 +21,7 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Vector>(N_("Reflection"));
}
-static void node_shader_buts_tex_coord(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_tex_coord(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "object", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, 0);
uiItemR(layout, ptr, "from_instancer", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, 0);
@@ -29,7 +29,7 @@ static void node_shader_buts_tex_coord(uiLayout *layout, bContext *UNUSED(C), Po
static int node_shader_gpu_tex_coord(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -38,12 +38,12 @@ static int node_shader_gpu_tex_coord(GPUMaterial *mat,
/* Use special matrix to let the shader branch to using the render object's matrix. */
float dummy_matrix[4][4];
dummy_matrix[3][3] = 0.0f;
- GPUNodeLink *inv_obmat = (ob != NULL) ? GPU_uniform(&ob->imat[0][0]) :
- GPU_uniform(&dummy_matrix[0][0]);
+ GPUNodeLink *inv_obmat = (ob != nullptr) ? GPU_uniform(&ob->imat[0][0]) :
+ GPU_uniform(&dummy_matrix[0][0]);
- /* Opti: don't request orco if not needed. */
+ /* Optimization: don't request orco if not needed. */
float4 zero(0.0f);
- GPUNodeLink *orco = (!out[0].hasoutput) ? GPU_constant(zero) : GPU_attribute(mat, CD_ORCO, "");
+ GPUNodeLink *orco = out[0].hasoutput ? GPU_attribute(mat, CD_ORCO, "") : GPU_constant(zero);
GPUNodeLink *mtface = GPU_attribute(mat, CD_AUTO_FROM_NAME, "");
GPU_stack_link(mat, node, "node_tex_coord", in, out, inv_obmat, orco, mtface);
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_environment.cc b/source/blender/nodes/shader/nodes/node_shader_tex_environment.cc
index df5fbac3ab5..a145bce3f6f 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_environment.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_environment.cc
@@ -11,7 +11,7 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Color>(N_("Color")).no_muted_links();
}
-static void node_shader_init_tex_environment(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_tex_environment(bNodeTree * /*ntree*/, bNode *node)
{
NodeTexEnvironment *tex = MEM_cnew<NodeTexEnvironment>("NodeTexEnvironment");
BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT);
@@ -24,7 +24,7 @@ static void node_shader_init_tex_environment(bNodeTree *UNUSED(ntree), bNode *no
static int node_shader_gpu_tex_environment(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -50,7 +50,11 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat,
return GPU_stack_link(mat, node, "node_tex_environment_empty", in, out);
}
- node_shader_gpu_default_tex_coord(mat, node, &in[0].link);
+ if (!in[0].link) {
+ GPU_link(mat, "node_tex_coord_position", &in[0].link);
+ node_shader_gpu_bump_tex_coord(mat, node, &in[0].link);
+ }
+
node_shader_gpu_tex_mapping(mat, node, in, out);
/* Compute texture coordinate. */
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc b/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc
index 8478cbd406b..75c469fe665 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc
@@ -11,17 +11,19 @@ namespace blender::nodes::node_shader_tex_gradient_cc {
static void sh_node_tex_gradient_declare(NodeDeclarationBuilder &b)
{
b.is_function_node();
- b.add_input<decl::Vector>(N_("Vector")).hide_value().implicit_field();
+ b.add_input<decl::Vector>(N_("Vector"))
+ .hide_value()
+ .implicit_field(implicit_field_inputs::position);
b.add_output<decl::Color>(N_("Color")).no_muted_links();
b.add_output<decl::Float>(N_("Fac")).no_muted_links();
}
-static void node_shader_buts_tex_gradient(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_tex_gradient(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "gradient_type", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
-static void node_shader_init_tex_gradient(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_tex_gradient(bNodeTree * /*ntree*/, bNode *node)
{
NodeTexGradient *tex = MEM_cnew<NodeTexGradient>(__func__);
BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT);
@@ -33,7 +35,7 @@ static void node_shader_init_tex_gradient(bNodeTree *UNUSED(ntree), bNode *node)
static int node_shader_gpu_tex_gradient(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -65,7 +67,7 @@ class GradientFunction : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
const VArray<float3> &vector = params.readonly_single_input<float3>(0, "Vector");
@@ -139,7 +141,7 @@ class GradientFunction : public fn::MultiFunction {
static void sh_node_gradient_tex_build_multi_function(NodeMultiFunctionBuilder &builder)
{
- bNode &node = builder.node();
+ const bNode &node = builder.node();
NodeTexGradient *tex = (NodeTexGradient *)node.storage;
builder.construct_and_set_matching_fn<GradientFunction>(tex->gradient_type);
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_image.cc b/source/blender/nodes/shader/nodes/node_shader_tex_image.cc
index c9588949761..80398871625 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_image.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_image.cc
@@ -8,12 +8,12 @@ namespace blender::nodes::node_shader_tex_image_cc {
static void sh_node_tex_image_declare(NodeDeclarationBuilder &b)
{
b.is_function_node();
- b.add_input<decl::Vector>(N_("Vector")).implicit_field();
+ b.add_input<decl::Vector>(N_("Vector")).implicit_field(implicit_field_inputs::position);
b.add_output<decl::Color>(N_("Color")).no_muted_links();
b.add_output<decl::Float>(N_("Alpha")).no_muted_links();
}
-static void node_shader_init_tex_image(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_tex_image(bNodeTree * /*ntree*/, bNode *node)
{
NodeTexImage *tex = MEM_cnew<NodeTexImage>(__func__);
BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT);
@@ -25,7 +25,7 @@ static void node_shader_init_tex_image(bNodeTree *UNUSED(ntree), bNode *node)
static int node_shader_gpu_tex_image(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_magic.cc b/source/blender/nodes/shader/nodes/node_shader_tex_magic.cc
index 95c4a8b8e46..b2ba0e52f02 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_magic.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_magic.cc
@@ -11,19 +11,19 @@ namespace blender::nodes::node_shader_tex_magic_cc {
static void sh_node_tex_magic_declare(NodeDeclarationBuilder &b)
{
b.is_function_node();
- b.add_input<decl::Vector>(N_("Vector")).implicit_field();
+ b.add_input<decl::Vector>(N_("Vector")).implicit_field(implicit_field_inputs::position);
b.add_input<decl::Float>(N_("Scale")).min(-1000.0f).max(1000.0f).default_value(5.0f);
b.add_input<decl::Float>(N_("Distortion")).min(-1000.0f).max(1000.0f).default_value(1.0f);
b.add_output<decl::Color>(N_("Color")).no_muted_links();
b.add_output<decl::Float>(N_("Fac")).no_muted_links();
}
-static void node_shader_buts_tex_magic(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_tex_magic(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "turbulence_depth", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
-static void node_shader_init_tex_magic(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_tex_magic(bNodeTree * /*ntree*/, bNode *node)
{
NodeTexMagic *tex = MEM_cnew<NodeTexMagic>(__func__);
BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT);
@@ -35,7 +35,7 @@ static void node_shader_init_tex_magic(bNodeTree *UNUSED(ntree), bNode *node)
static int node_shader_gpu_tex_magic(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -70,7 +70,7 @@ class MagicFunction : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
const VArray<float3> &vector = params.readonly_single_input<float3>(0, "Vector");
const VArray<float> &scale = params.readonly_single_input<float>(1, "Scale");
@@ -161,7 +161,7 @@ class MagicFunction : public fn::MultiFunction {
static void sh_node_magic_tex_build_multi_function(NodeMultiFunctionBuilder &builder)
{
- bNode &node = builder.node();
+ const bNode &node = builder.node();
NodeTexMagic *tex = (NodeTexMagic *)node.storage;
builder.construct_and_set_matching_fn<MagicFunction>(tex->depth);
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.cc b/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.cc
index c13ce3c3df3..9a7573fc870 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.cc
@@ -15,7 +15,9 @@ NODE_STORAGE_FUNCS(NodeTexMusgrave)
static void sh_node_tex_musgrave_declare(NodeDeclarationBuilder &b)
{
b.is_function_node();
- b.add_input<decl::Vector>(N_("Vector")).hide_value().implicit_field();
+ b.add_input<decl::Vector>(N_("Vector"))
+ .hide_value()
+ .implicit_field(implicit_field_inputs::position);
b.add_input<decl::Float>(N_("W")).min(-1000.0f).max(1000.0f).make_available([](bNode &node) {
/* Default to 1 instead of 4, because it is much faster. */
node_storage(node).dimensions = 1;
@@ -29,13 +31,13 @@ static void sh_node_tex_musgrave_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("Fac")).no_muted_links();
}
-static void node_shader_buts_tex_musgrave(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_tex_musgrave(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "musgrave_dimensions", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
uiItemR(layout, ptr, "musgrave_type", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
-static void node_shader_init_tex_musgrave(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_tex_musgrave(bNodeTree * /*ntree*/, bNode *node)
{
NodeTexMusgrave *tex = MEM_cnew<NodeTexMusgrave>(__func__);
BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT);
@@ -83,7 +85,7 @@ static const char *gpu_shader_name_get(const int type, const int dimensions)
static int node_shader_gpu_tex_musgrave(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -192,7 +194,7 @@ class MusgraveFunction : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
auto get_vector = [&](int param_index) -> VArray<float3> {
return params.readonly_single_input<float3>(param_index, "Vector");
@@ -516,7 +518,7 @@ class MusgraveFunction : public fn::MultiFunction {
static void sh_node_musgrave_build_multi_function(NodeMultiFunctionBuilder &builder)
{
- bNode &node = builder.node();
+ const bNode &node = builder.node();
NodeTexMusgrave *tex = (NodeTexMusgrave *)node.storage;
builder.construct_and_set_matching_fn<MusgraveFunction>(tex->dimensions, tex->musgrave_type);
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc b/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc
index 87fb1aeac29..684c122f7fe 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_noise.cc
@@ -15,7 +15,7 @@ NODE_STORAGE_FUNCS(NodeTexNoise)
static void sh_node_tex_noise_declare(NodeDeclarationBuilder &b)
{
b.is_function_node();
- b.add_input<decl::Vector>(N_("Vector")).implicit_field();
+ b.add_input<decl::Vector>(N_("Vector")).implicit_field(implicit_field_inputs::position);
b.add_input<decl::Float>(N_("W")).min(-1000.0f).max(1000.0f).make_available([](bNode &node) {
/* Default to 1 instead of 4, because it is much faster. */
node_storage(node).dimensions = 1;
@@ -32,12 +32,12 @@ static void sh_node_tex_noise_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Color>(N_("Color")).no_muted_links();
}
-static void node_shader_buts_tex_noise(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_tex_noise(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "noise_dimensions", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
-static void node_shader_init_tex_noise(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_tex_noise(bNodeTree * /*ntree*/, bNode *node)
{
NodeTexNoise *tex = MEM_cnew<NodeTexNoise>(__func__);
BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT);
@@ -59,7 +59,7 @@ static const char *gpu_shader_get_name(const int dimensions)
static int node_shader_gpu_tex_noise(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -120,7 +120,7 @@ class NoiseFunction : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
int param = ELEM(dimensions_, 2, 3, 4) + ELEM(dimensions_, 1, 4);
const VArray<float> &scale = params.readonly_single_input<float>(param++, "Scale");
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.cc b/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.cc
index fcd1d4973ff..0d10d5a5047 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.cc
@@ -17,9 +17,7 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("Density"));
}
-static void node_shader_buts_tex_pointdensity(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
+static void node_shader_buts_tex_pointdensity(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
bNode *node = (bNode *)ptr->data;
NodeShaderTexPointDensity *shader_point_density = (NodeShaderTexPointDensity *)node->storage;
@@ -63,7 +61,7 @@ static void node_shader_buts_tex_pointdensity(uiLayout *layout,
}
}
-static void node_shader_init_tex_pointdensity(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_tex_pointdensity(bNodeTree * /*ntree*/, bNode *node)
{
NodeShaderTexPointDensity *point_density = MEM_new<NodeShaderTexPointDensity>("new pd node");
point_density->resolution = 100;
@@ -83,7 +81,7 @@ static void node_shader_free_tex_pointdensity(bNode *node)
MEM_freeN(point_density);
}
-static void node_shader_copy_tex_pointdensity(bNodeTree *UNUSED(dest_ntree),
+static void node_shader_copy_tex_pointdensity(bNodeTree * /*dst_ntree*/,
bNode *dest_node,
const bNode *src_node)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_sky.cc b/source/blender/nodes/shader/nodes/node_shader_tex_sky.cc
index f5a4d087dbd..44df6b2b1a1 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_sky.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_sky.cc
@@ -4,6 +4,8 @@
#include "node_shader_util.hh"
#include "sky_model.h"
+#include "BLI_task.hh"
+
#include "BKE_context.h"
#include "BKE_scene.h"
@@ -36,7 +38,7 @@ static void node_shader_buts_tex_sky(uiLayout *layout, bContext *C, PointerRNA *
if (RNA_enum_get(ptr, "sky_type") == SHD_SKY_NISHITA) {
Scene *scene = CTX_data_scene(C);
if (BKE_scene_uses_blender_eevee(scene)) {
- uiItemL(layout, TIP_("Nishita not available in Eevee"), ICON_ERROR);
+ uiItemL(layout, TIP_("Sun disc not available in Eevee"), ICON_ERROR);
}
uiItemR(layout, ptr, "sun_disc", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, 0);
@@ -60,7 +62,7 @@ static void node_shader_buts_tex_sky(uiLayout *layout, bContext *C, PointerRNA *
}
}
-static void node_shader_init_tex_sky(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_tex_sky(bNodeTree * /*ntree*/, bNode *node)
{
NodeTexSky *tex = MEM_cnew<NodeTexSky>("NodeTexSky");
BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT);
@@ -144,7 +146,7 @@ static void sky_precompute_old(SkyModelPreetham *sunsky, const float sun_angles[
static int node_shader_gpu_tex_sky(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -179,7 +181,7 @@ static int node_shader_gpu_tex_sky(GPUMaterial *mat,
GPU_uniform(xyz_to_rgb.g),
GPU_uniform(xyz_to_rgb.b));
}
- if (tex->sky_model == 1) {
+ else if (tex->sky_model == 1) {
/* Hosek / Wilkie */
sun_angles[0] = fmin(M_PI_2, sun_angles[0]); /* clamp to horizon */
SKY_ArHosekSkyModelState *sky_state = SKY_arhosek_xyz_skymodelstate_alloc_init(
@@ -187,12 +189,12 @@ static int node_shader_gpu_tex_sky(GPUMaterial *mat,
/* Pass sky_state->configs[3][9] as 3*(vec4+vec4)+vec3 */
float config_x07[8], config_y07[8], config_z07[8], config_xyz8[3];
for (int i = 0; i < 8; ++i) {
- config_x07[i] = (float)sky_state->configs[0][i];
- config_y07[i] = (float)sky_state->configs[1][i];
- config_z07[i] = (float)sky_state->configs[2][i];
+ config_x07[i] = float(sky_state->configs[0][i]);
+ config_y07[i] = float(sky_state->configs[1][i]);
+ config_z07[i] = float(sky_state->configs[2][i]);
}
for (int i = 0; i < 3; ++i) {
- config_xyz8[i] = (float)sky_state->configs[i][8];
+ config_xyz8[i] = float(sky_state->configs[i][8]);
}
float radiance[3];
for (int i = 0; i < 3; i++) {
@@ -219,8 +221,52 @@ static int node_shader_gpu_tex_sky(GPUMaterial *mat,
GPU_uniform(xyz_to_rgb.g),
GPU_uniform(xyz_to_rgb.b));
}
+ else {
+ /* Nishita */
+
+ Array<float> pixels(4 * GPU_SKY_WIDTH * GPU_SKY_HEIGHT);
+
+ threading::parallel_for(IndexRange(GPU_SKY_HEIGHT), 2, [&](IndexRange range) {
+ SKY_nishita_skymodel_precompute_texture(pixels.data(),
+ 4,
+ range.first(),
+ range.one_after_last(),
+ GPU_SKY_WIDTH,
+ GPU_SKY_HEIGHT,
+ tex->sun_elevation,
+ tex->altitude,
+ tex->air_density,
+ tex->dust_density,
+ tex->ozone_density);
+ });
+
+ float sun_rotation = fmodf(tex->sun_rotation, 2.0f * M_PI);
+ if (sun_rotation < 0.0f) {
+ sun_rotation += 2.0f * M_PI;
+ }
+ sun_rotation = 2.0f * M_PI - sun_rotation;
+
+ XYZ_to_RGB xyz_to_rgb;
+ get_XYZ_to_RGB_for_gpu(&xyz_to_rgb);
- return GPU_stack_link(mat, node, "node_tex_sky_nishita", in, out);
+ eGPUSamplerState sampler = GPU_SAMPLER_REPEAT | GPU_SAMPLER_FILTER;
+ /* To fix pole issue we clamp the v coordinate. */
+ sampler &= ~GPU_SAMPLER_REPEAT_T;
+ float layer;
+ GPUNodeLink *sky_texture = GPU_image_sky(
+ mat, GPU_SKY_WIDTH, GPU_SKY_HEIGHT, pixels.data(), &layer, sampler);
+ return GPU_stack_link(mat,
+ node,
+ "node_tex_sky_nishita",
+ in,
+ out,
+ GPU_constant(&sun_rotation),
+ GPU_uniform(xyz_to_rgb.r),
+ GPU_uniform(xyz_to_rgb.g),
+ GPU_uniform(xyz_to_rgb.b),
+ sky_texture,
+ GPU_constant(&layer));
+ }
}
static void node_shader_update_sky(bNodeTree *ntree, bNode *node)
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc
index fc6a5ef72b6..0ef73f0c5ef 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc
@@ -15,7 +15,9 @@ NODE_STORAGE_FUNCS(NodeTexVoronoi)
static void sh_node_tex_voronoi_declare(NodeDeclarationBuilder &b)
{
b.is_function_node();
- b.add_input<decl::Vector>(N_("Vector")).hide_value().implicit_field();
+ b.add_input<decl::Vector>(N_("Vector"))
+ .hide_value()
+ .implicit_field(implicit_field_inputs::position);
b.add_input<decl::Float>(N_("W")).min(-1000.0f).max(1000.0f).make_available([](bNode &node) {
/* Default to 1 instead of 4, because it is much faster. */
node_storage(node).dimensions = 1;
@@ -49,7 +51,7 @@ static void sh_node_tex_voronoi_declare(NodeDeclarationBuilder &b)
});
}
-static void node_shader_buts_tex_voronoi(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_tex_voronoi(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "voronoi_dimensions", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
uiItemR(layout, ptr, "feature", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
@@ -60,7 +62,7 @@ static void node_shader_buts_tex_voronoi(uiLayout *layout, bContext *UNUSED(C),
}
}
-static void node_shader_init_tex_voronoi(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_tex_voronoi(bNodeTree * /*ntree*/, bNode *node)
{
NodeTexVoronoi *tex = MEM_cnew<NodeTexVoronoi>(__func__);
BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT);
@@ -119,7 +121,7 @@ static const char *gpu_shader_get_name(const int feature, const int dimensions)
static int node_shader_gpu_tex_voronoi(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -173,7 +175,7 @@ static void node_shader_update_tex_voronoi(bNodeTree *ntree, bNode *node)
outWSock,
storage.feature != SHD_VORONOI_DISTANCE_TO_EDGE &&
storage.feature != SHD_VORONOI_N_SPHERE_RADIUS &&
- (ELEM(storage.dimensions, 1, 4)));
+ ELEM(storage.dimensions, 1, 4));
nodeSetSocketAvailability(ntree, outRadiusSock, storage.feature == SHD_VORONOI_N_SPHERE_RADIUS);
}
@@ -234,7 +236,7 @@ class VoronoiMinowskiFunction : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
auto get_vector = [&](int param_index) -> VArray<float3> {
return params.readonly_single_input<float3>(param_index, "Vector");
@@ -670,7 +672,7 @@ class VoronoiMetricFunction : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
auto get_vector = [&](int param_index) -> VArray<float3> {
return params.readonly_single_input<float3>(param_index, "Vector");
@@ -1177,7 +1179,7 @@ class VoronoiEdgeFunction : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
auto get_vector = [&](int param_index) -> VArray<float3> {
return params.readonly_single_input<float3>(param_index, "Vector");
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_wave.cc b/source/blender/nodes/shader/nodes/node_shader_tex_wave.cc
index ad24224dc7f..91dbc149f78 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_wave.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_wave.cc
@@ -13,7 +13,7 @@ namespace blender::nodes::node_shader_tex_wave_cc {
static void sh_node_tex_wave_declare(NodeDeclarationBuilder &b)
{
b.is_function_node();
- b.add_input<decl::Vector>(N_("Vector")).implicit_field();
+ b.add_input<decl::Vector>(N_("Vector")).implicit_field(implicit_field_inputs::position);
b.add_input<decl::Float>(N_("Scale")).min(-1000.0f).max(1000.0f).default_value(5.0f);
b.add_input<decl::Float>(N_("Distortion")).min(-1000.0f).max(1000.0f).default_value(0.0f);
b.add_input<decl::Float>(N_("Detail")).min(0.0f).max(15.0f).default_value(2.0f);
@@ -28,7 +28,7 @@ static void sh_node_tex_wave_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("Fac")).no_muted_links();
}
-static void node_shader_buts_tex_wave(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_tex_wave(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "wave_type", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
int type = RNA_enum_get(ptr, "wave_type");
@@ -42,7 +42,7 @@ static void node_shader_buts_tex_wave(uiLayout *layout, bContext *UNUSED(C), Poi
uiItemR(layout, ptr, "wave_profile", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
-static void node_shader_init_tex_wave(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_tex_wave(bNodeTree * /*ntree*/, bNode *node)
{
NodeTexWave *tex = MEM_cnew<NodeTexWave>(__func__);
BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT);
@@ -56,7 +56,7 @@ static void node_shader_init_tex_wave(bNodeTree *UNUSED(ntree), bNode *node)
static int node_shader_gpu_tex_wave(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -113,7 +113,7 @@ class WaveFunction : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
const VArray<float3> &vector = params.readonly_single_input<float3>(0, "Vector");
const VArray<float> &scale = params.readonly_single_input<float>(1, "Scale");
@@ -206,7 +206,7 @@ class WaveFunction : public fn::MultiFunction {
static void sh_node_wave_tex_build_multi_function(NodeMultiFunctionBuilder &builder)
{
- bNode &node = builder.node();
+ const bNode &node = builder.node();
NodeTexWave *tex = (NodeTexWave *)node.storage;
builder.construct_and_set_matching_fn<WaveFunction>(
tex->wave_type, tex->bands_direction, tex->rings_direction, tex->wave_profile);
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_white_noise.cc b/source/blender/nodes/shader/nodes/node_shader_tex_white_noise.cc
index 6d4c491046b..9a026567682 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_white_noise.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_white_noise.cc
@@ -13,7 +13,10 @@ namespace blender::nodes::node_shader_tex_white_noise_cc {
static void sh_node_tex_white_noise_declare(NodeDeclarationBuilder &b)
{
b.is_function_node();
- b.add_input<decl::Vector>(N_("Vector")).min(-10000.0f).max(10000.0f).implicit_field();
+ b.add_input<decl::Vector>(N_("Vector"))
+ .min(-10000.0f)
+ .max(10000.0f)
+ .implicit_field(implicit_field_inputs::position);
b.add_input<decl::Float>(N_("W")).min(-10000.0f).max(10000.0f).make_available([](bNode &node) {
/* Default to 1 instead of 4, because it is faster. */
node.custom1 = 1;
@@ -22,12 +25,12 @@ static void sh_node_tex_white_noise_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Color>(N_("Color"));
}
-static void node_shader_buts_white_noise(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_white_noise(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "noise_dimensions", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
-static void node_shader_init_tex_white_noise(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_tex_white_noise(bNodeTree * /*ntree*/, bNode *node)
{
node->custom1 = 3;
}
@@ -43,7 +46,7 @@ static const char *gpu_shader_get_name(const int dimensions)
static int gpu_shader_tex_white_noise(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -94,7 +97,7 @@ class WhiteNoiseFunction : public fn::MultiFunction {
return signature.build();
}
- void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
+ void call(IndexMask mask, fn::MFParams params, fn::MFContext /*context*/) const override
{
int param = ELEM(dimensions_, 2, 3, 4) + ELEM(dimensions_, 1, 4);
@@ -176,8 +179,8 @@ class WhiteNoiseFunction : public fn::MultiFunction {
static void sh_node_noise_build_multi_function(NodeMultiFunctionBuilder &builder)
{
- bNode &node = builder.node();
- builder.construct_and_set_matching_fn<WhiteNoiseFunction>((int)node.custom1);
+ const bNode &node = builder.node();
+ builder.construct_and_set_matching_fn<WhiteNoiseFunction>(int(node.custom1));
}
} // namespace blender::nodes::node_shader_tex_white_noise_cc
diff --git a/source/blender/nodes/shader/nodes/node_shader_uv_along_stroke.cc b/source/blender/nodes/shader/nodes/node_shader_uv_along_stroke.cc
index fa98cb3aa27..6923d51ab51 100644
--- a/source/blender/nodes/shader/nodes/node_shader_uv_along_stroke.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_uv_along_stroke.cc
@@ -13,7 +13,7 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Vector>(N_("UV"));
}
-static void node_shader_buts_uvalongstroke(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_uvalongstroke(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "use_tips", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, 0);
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_uvmap.cc b/source/blender/nodes/shader/nodes/node_shader_uvmap.cc
index 53228f0a314..e9d2b32bfd7 100644
--- a/source/blender/nodes/shader/nodes/node_shader_uvmap.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_uvmap.cc
@@ -31,7 +31,7 @@ static void node_shader_buts_uvmap(uiLayout *layout, bContext *C, PointerRNA *pt
}
}
-static void node_shader_init_uvmap(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_uvmap(bNodeTree * /*ntree*/, bNode *node)
{
NodeShaderUVMap *attr = MEM_cnew<NodeShaderUVMap>("NodeShaderUVMap");
node->storage = attr;
@@ -39,7 +39,7 @@ static void node_shader_init_uvmap(bNodeTree *UNUSED(ntree), bNode *node)
static int node_shader_gpu_uvmap(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_value.cc b/source/blender/nodes/shader/nodes/node_shader_value.cc
index 362cdf58052..0cd1a1f05f8 100644
--- a/source/blender/nodes/shader/nodes/node_shader_value.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_value.cc
@@ -16,12 +16,13 @@ static void sh_node_value_declare(NodeDeclarationBuilder &b)
static int gpu_shader_value(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
- GPUNodeStack *in,
+ bNodeExecData * /*execdata*/,
+ GPUNodeStack * /*in*/,
GPUNodeStack *out)
{
- GPUNodeLink *link = GPU_uniformbuf_link_out(mat, node, out, 0);
- return GPU_stack_link(mat, node, "set_value", in, out, link);
+ const bNodeSocket *socket = static_cast<bNodeSocket *>(node->outputs.first);
+ float value = static_cast<bNodeSocketValueFloat *>(socket->default_value)->value;
+ return GPU_link(mat, "set_value", GPU_uniform(&value), &out->link);
}
static void sh_node_value_build_multi_function(NodeMultiFunctionBuilder &builder)
diff --git a/source/blender/nodes/shader/nodes/node_shader_vector_displacement.cc b/source/blender/nodes/shader/nodes/node_shader_vector_displacement.cc
index 9996e91177a..64484f83320 100644
--- a/source/blender/nodes/shader/nodes/node_shader_vector_displacement.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_vector_displacement.cc
@@ -13,14 +13,14 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Vector>(N_("Displacement"));
}
-static void node_shader_init_vector_displacement(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_vector_displacement(bNodeTree * /*ntree*/, bNode *node)
{
node->custom1 = SHD_SPACE_TANGENT; /* space */
}
static int gpu_shader_vector_displacement(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_vector_math.cc b/source/blender/nodes/shader/nodes/node_shader_vector_math.cc
index 21f5c44c640..42b84617996 100644
--- a/source/blender/nodes/shader/nodes/node_shader_vector_math.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_vector_math.cc
@@ -28,7 +28,7 @@ static void sh_node_vector_math_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("Value"));
}
-static void node_shader_buts_vect_math(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_vect_math(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "operation", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
@@ -141,7 +141,7 @@ static const char *gpu_shader_get_name(int mode)
static int gpu_shader_vector_math(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -225,7 +225,7 @@ static void node_shader_update_vector_math(bNodeTree *ntree, bNode *node)
}
}
-static const fn::MultiFunction *get_multi_function(bNode &node)
+static const fn::MultiFunction *get_multi_function(const bNode &node)
{
NodeVectorMathOperation operation = NodeVectorMathOperation(node.custom1);
diff --git a/source/blender/nodes/shader/nodes/node_shader_vector_rotate.cc b/source/blender/nodes/shader/nodes/node_shader_vector_rotate.cc
index b35f686e331..218ed0e54c9 100644
--- a/source/blender/nodes/shader/nodes/node_shader_vector_rotate.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_vector_rotate.cc
@@ -29,7 +29,7 @@ static void sh_node_vector_rotate_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Vector>(N_("Vector"));
}
-static void node_shader_buts_vector_rotate(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_vector_rotate(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "rotation_type", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
uiItemR(layout, ptr, "invert", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, 0);
@@ -55,7 +55,7 @@ static const char *gpu_shader_get_name(int mode)
static int gpu_shader_vector_rotate(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
@@ -96,7 +96,7 @@ static float3 sh_node_vector_rotate_euler(const float3 &vector,
return result + center;
}
-static const fn::MultiFunction *get_multi_function(bNode &node)
+static const fn::MultiFunction *get_multi_function(const bNode &node)
{
bool invert = node.custom2;
const int mode = node.custom1;
diff --git a/source/blender/nodes/shader/nodes/node_shader_vector_transform.cc b/source/blender/nodes/shader/nodes/node_shader_vector_transform.cc
index de588f9005f..9037c6208fb 100644
--- a/source/blender/nodes/shader/nodes/node_shader_vector_transform.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_vector_transform.cc
@@ -21,7 +21,7 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Vector>(N_("Vector"));
}
-static void node_shader_buts_vect_transform(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_vect_transform(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout,
ptr,
@@ -33,7 +33,7 @@ static void node_shader_buts_vect_transform(uiLayout *layout, bContext *UNUSED(C
uiItemR(layout, ptr, "convert_to", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
-static void node_shader_init_vect_transform(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_vect_transform(bNodeTree * /*ntree*/, bNode *node)
{
NodeShaderVectTransform *vect = MEM_cnew<NodeShaderVectTransform>("NodeShaderVectTransform");
@@ -83,12 +83,12 @@ static const char *get_gpufn_name_from_to(short from, short to, bool is_directio
}
break;
}
- return NULL;
+ return nullptr;
}
static int gpu_shader_vect_transform(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_vertex_color.cc b/source/blender/nodes/shader/nodes/node_shader_vertex_color.cc
index 830f02d8df1..6e2325bddf9 100644
--- a/source/blender/nodes/shader/nodes/node_shader_vertex_color.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_vertex_color.cc
@@ -29,7 +29,7 @@ static void node_shader_buts_vertex_color(uiLayout *layout, bContext *C, Pointer
}
}
-static void node_shader_init_vertex_color(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_vertex_color(bNodeTree * /*ntree*/, bNode *node)
{
NodeShaderVertexColor *vertexColor = MEM_cnew<NodeShaderVertexColor>("NodeShaderVertexColor");
node->storage = vertexColor;
@@ -37,14 +37,13 @@ static void node_shader_init_vertex_color(bNodeTree *UNUSED(ntree), bNode *node)
static int node_shader_gpu_vertex_color(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
NodeShaderVertexColor *vertexColor = (NodeShaderVertexColor *)node->storage;
- /* NOTE: using CD_AUTO_FROM_NAME instead of CD_MCOL or CD_PROP_COLOR for named attributes
- * as geometry nodes may overwrite data which will also change the eCustomDataType.
- * This will also make EEVEE and Cycles
+ /* NOTE: Using #CD_AUTO_FROM_NAME is necessary because there are multiple color attribute types,
+ * and the type may change during evaluation anyway. This will also make EEVEE and Cycles
* consistent. See T93179. */
GPUNodeLink *vertexColorLink;
@@ -53,7 +52,7 @@ static int node_shader_gpu_vertex_color(GPUMaterial *mat,
vertexColorLink = GPU_attribute(mat, CD_AUTO_FROM_NAME, vertexColor->layer_name);
}
else { /* Fall back on active render color attribute. */
- vertexColorLink = GPU_attribute(mat, CD_MCOL, vertexColor->layer_name);
+ vertexColorLink = GPU_attribute_default_color(mat);
}
return GPU_stack_link(mat, node, "node_vertex_color", in, out, vertexColorLink);
diff --git a/source/blender/nodes/shader/nodes/node_shader_volume_absorption.cc b/source/blender/nodes/shader/nodes/node_shader_volume_absorption.cc
index 930fa6e5fb9..d6a29f537ff 100644
--- a/source/blender/nodes/shader/nodes/node_shader_volume_absorption.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_volume_absorption.cc
@@ -15,7 +15,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_volume_absorption(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_volume_info.cc b/source/blender/nodes/shader/nodes/node_shader_volume_info.cc
index a202312f8d8..9f1feedc336 100644
--- a/source/blender/nodes/shader/nodes/node_shader_volume_info.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_volume_info.cc
@@ -14,9 +14,9 @@ static void node_declare(NodeDeclarationBuilder &b)
}
static int node_shader_gpu_volume_info(GPUMaterial *mat,
- bNode *UNUSED(node),
- bNodeExecData *UNUSED(execdata),
- GPUNodeStack *UNUSED(in),
+ bNode * /*node*/,
+ bNodeExecData * /*execdata*/,
+ GPUNodeStack * /*in*/,
GPUNodeStack *out)
{
if (out[0].hasoutput) {
@@ -25,9 +25,11 @@ static int node_shader_gpu_volume_info(GPUMaterial *mat,
}
if (out[1].hasoutput) {
out[1].link = GPU_attribute(mat, CD_AUTO_FROM_NAME, "density");
+ GPU_link(mat, "node_attribute_density", out[1].link, &out[1].link);
}
if (out[2].hasoutput) {
out[2].link = GPU_attribute(mat, CD_AUTO_FROM_NAME, "flame");
+ GPU_link(mat, "node_attribute_flame", out[2].link, &out[2].link);
}
if (out[3].hasoutput) {
out[3].link = GPU_attribute(mat, CD_AUTO_FROM_NAME, "temperature");
diff --git a/source/blender/nodes/shader/nodes/node_shader_volume_principled.cc b/source/blender/nodes/shader/nodes/node_shader_volume_principled.cc
index 4c4122a905f..2c5811045f0 100644
--- a/source/blender/nodes/shader/nodes/node_shader_volume_principled.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_volume_principled.cc
@@ -33,7 +33,7 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Shader>(N_("Volume"));
}
-static void node_shader_init_volume_principled(bNodeTree *UNUSED(ntree), bNode *node)
+static void node_shader_init_volume_principled(bNodeTree * /*ntree*/, bNode *node)
{
LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
if (STREQ(sock->name, "Density Attribute")) {
@@ -59,7 +59,7 @@ static void attribute_post_process(GPUMaterial *mat,
static int node_shader_gpu_volume_principled(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_volume_scatter.cc b/source/blender/nodes/shader/nodes/node_shader_volume_scatter.cc
index 0c6859ad1fb..1322a73ac37 100644
--- a/source/blender/nodes/shader/nodes/node_shader_volume_scatter.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_volume_scatter.cc
@@ -20,7 +20,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_volume_scatter(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_wavelength.cc b/source/blender/nodes/shader/nodes/node_shader_wavelength.cc
index 34fa639dd07..43bb4798e3f 100644
--- a/source/blender/nodes/shader/nodes/node_shader_wavelength.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_wavelength.cc
@@ -15,7 +15,7 @@ static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_wavelength(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/shader/nodes/node_shader_wireframe.cc b/source/blender/nodes/shader/nodes/node_shader_wireframe.cc
index 6a1acda3353..ddabebfeec2 100644
--- a/source/blender/nodes/shader/nodes/node_shader_wireframe.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_wireframe.cc
@@ -14,14 +14,14 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Float>(N_("Fac"));
}
-static void node_shader_buts_wireframe(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_shader_buts_wireframe(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "use_pixel_size", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, 0);
}
static int node_shader_gpu_wireframe(GPUMaterial *mat,
bNode *node,
- bNodeExecData *UNUSED(execdata),
+ bNodeExecData * /*execdata*/,
GPUNodeStack *in,
GPUNodeStack *out)
{
diff --git a/source/blender/nodes/texture/CMakeLists.txt b/source/blender/nodes/texture/CMakeLists.txt
index 5bed54ebfd7..2d704ac2228 100644
--- a/source/blender/nodes/texture/CMakeLists.txt
+++ b/source/blender/nodes/texture/CMakeLists.txt
@@ -2,7 +2,7 @@
set(INC
.
- ../
+ ..
../intern
../../editors/include
../../blenkernel
@@ -15,6 +15,7 @@ set(INC
../../render
../../windowmanager
../../../../intern/guardedalloc
+ ../../bmesh
# RNA_prototypes.h
${CMAKE_BINARY_DIR}/source/blender/makesrna
)
@@ -56,21 +57,6 @@ set(LIB
bf_nodes
)
-if(WITH_PYTHON)
- list(APPEND INC
- ../../python
- )
- list(APPEND INC_SYS
- ${PYTHON_INCLUDE_DIRS}
- )
- list(APPEND LIB
- ${PYTHON_LINKFLAGS}
- ${PYTHON_LIBRARIES}
- )
- add_definitions(-DWITH_PYTHON)
-endif()
-
-
blender_add_lib(bf_nodes_texture "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
# RNA_prototypes.h
diff --git a/source/blender/nodes/texture/node_texture_tree.c b/source/blender/nodes/texture/node_texture_tree.c
index 03dc61af9a2..81d0b0fbc84 100644
--- a/source/blender/nodes/texture/node_texture_tree.c
+++ b/source/blender/nodes/texture/node_texture_tree.c
@@ -18,6 +18,7 @@
#include "BLT_translation.h"
#include "BKE_context.h"
+#include "BKE_layer.h"
#include "BKE_linestyle.h"
#include "BKE_node.h"
#include "BKE_paint.h"
@@ -46,7 +47,8 @@ static void texture_get_from_context(const bContext *C,
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);
+ BKE_view_layer_synced_ensure(scene, view_layer);
+ Object *ob = BKE_view_layer_active_object_get(view_layer);
Tex *tx = NULL;
if (snode->texfrom == SNODE_TEX_BRUSH) {
@@ -140,6 +142,7 @@ void register_node_tree_type_tex(void)
tt->type = NTREE_TEXTURE;
strcpy(tt->idname, "TextureNodeTree");
+ strcpy(tt->group_idname, "TextureNodeGroup");
strcpy(tt->ui_name, N_("Texture Node Editor"));
tt->ui_icon = ICON_NODE_TEXTURE; /* Defined in `drawnode.c`. */
strcpy(tt->ui_description, N_("Texture nodes"));
@@ -248,7 +251,7 @@ bNodeTreeExec *ntreeTexBeginExecTree(bNodeTree *ntree)
exec = ntreeTexBeginExecTree_internal(&context, ntree, NODE_INSTANCE_KEY_BASE);
- /* XXX this should not be necessary, but is still used for cmp/sha/tex nodes,
+ /* XXX this should not be necessary, but is still used for compositor/shading/texture nodes,
* which only store the ntree pointer. Should be fixed at some point!
*/
ntree->execdata = exec;
diff --git a/source/blender/nodes/texture/nodes/node_texture_compose.c b/source/blender/nodes/texture/nodes/node_texture_compose.c
index ef14062c72d..e36bc248ed1 100644
--- a/source/blender/nodes/texture/nodes/node_texture_compose.c
+++ b/source/blender/nodes/texture/nodes/node_texture_compose.c
@@ -42,7 +42,8 @@ void register_node_type_tex_compose(void)
{
static bNodeType ntype;
- tex_node_type_base(&ntype, TEX_NODE_COMPOSE_LEGACY, "Combine RGBA", NODE_CLASS_OP_COLOR);
+ tex_node_type_base(
+ &ntype, TEX_NODE_COMPOSE_LEGACY, "Combine RGBA (Legacy)", NODE_CLASS_OP_COLOR);
node_type_socket_templates(&ntype, inputs, outputs);
node_type_exec(&ntype, NULL, NULL, exec);