Blender V4.3
material.cc File Reference
#include <cmath>
#include <cstddef>
#include <cstring>
#include <optional>
#include "CLG_log.h"
#include "MEM_guardedalloc.h"
#include "DNA_ID.h"
#include "DNA_anim_types.h"
#include "DNA_collection_types.h"
#include "DNA_curve_types.h"
#include "DNA_curves_types.h"
#include "DNA_customdata_types.h"
#include "DNA_defaults.h"
#include "DNA_gpencil_legacy_types.h"
#include "DNA_grease_pencil_types.h"
#include "DNA_material_types.h"
#include "DNA_meta_types.h"
#include "DNA_node_types.h"
#include "DNA_object_types.h"
#include "DNA_particle_types.h"
#include "DNA_pointcloud_types.h"
#include "DNA_scene_types.h"
#include "DNA_volume_types.h"
#include "BLI_array_utils.h"
#include "BLI_listbase.h"
#include "BLI_math_color.h"
#include "BLI_math_vector.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "BLT_translation.hh"
#include "BKE_anim_data.hh"
#include "BKE_attribute.hh"
#include "BKE_brush.hh"
#include "BKE_curve.hh"
#include "BKE_displist.h"
#include "BKE_editmesh.hh"
#include "BKE_gpencil_legacy.h"
#include "BKE_grease_pencil.hh"
#include "BKE_icons.h"
#include "BKE_idtype.hh"
#include "BKE_image.hh"
#include "BKE_lib_id.hh"
#include "BKE_lib_query.hh"
#include "BKE_main.hh"
#include "BKE_material.h"
#include "BKE_mesh.hh"
#include "BKE_node.hh"
#include "BKE_node_runtime.hh"
#include "BKE_object.hh"
#include "BKE_object_types.hh"
#include "BKE_preview_image.hh"
#include "BKE_scene.hh"
#include "BKE_vfont.hh"
#include "DEG_depsgraph.hh"
#include "DEG_depsgraph_build.hh"
#include "DEG_depsgraph_query.hh"
#include "GPU_material.hh"
#include "NOD_shader.h"
#include "BLO_read_write.hh"

Go to the source code of this file.

Classes

struct  FillTexPaintSlotsData
 
struct  FindTexPaintNodeData
 

Macros

#define DNA_DEPRECATED_ALLOW
 

Typedefs

using ForEachTexNodeCallback = bool (*)(bNode *node, void *userdata)
 

Enumerations

enum  ePaintSlotFilter { PAINT_SLOT_IMAGE = 1 << 0 , PAINT_SLOT_COLOR_ATTRIBUTE = 1 << 1 }
 

Functions

static void material_init_data (ID *id)
 
static void material_copy_data (Main *bmain, std::optional< Library * > owner_library, ID *id_dst, const ID *id_src, const int flag)
 
static void material_free_data (ID *id)
 
static void material_foreach_id (ID *id, LibraryForeachIDData *data)
 
static void material_blend_write (BlendWriter *writer, ID *id, const void *id_address)
 
static void material_blend_read_data (BlendDataReader *reader, ID *id)
 
void BKE_gpencil_material_attr_init (Material *ma)
 
static void nodetree_mark_previews_dirty_reccursive (bNodeTree *tree)
 
void BKE_material_make_node_previews_dirty (Material *ma)
 
MaterialBKE_material_add (Main *bmain, const char *name)
 
MaterialBKE_gpencil_material_add (Main *bmain, const char *name)
 
Material *** BKE_object_material_array_p (Object *ob)
 
short * BKE_object_material_len_p (Object *ob)
 
Material *** BKE_id_material_array_p (ID *id)
 
short * BKE_id_material_len_p (ID *id)
 
static void material_data_index_remove_id (ID *id, short index)
 
bool BKE_object_material_slot_used (Object *object, short actcol)
 
static void material_data_index_clear_id (ID *id)
 
void BKE_id_materials_copy (Main *bmain, ID *id_src, ID *id_dst)
 
void BKE_id_material_resize (Main *bmain, ID *id, short totcol, bool do_id_user)
 
void BKE_id_material_append (Main *bmain, ID *id, Material *ma)
 
MaterialBKE_id_material_pop (Main *bmain, ID *id, int index_i)
 
void BKE_id_material_clear (Main *bmain, ID *id)
 
Material ** BKE_object_material_get_p (Object *ob, short act)
 
MaterialBKE_object_material_get (Object *ob, short act)
 
static const IDget_evaluated_object_data_with_materials (Object *ob)
 
MaterialBKE_object_material_get_eval (Object *ob, short act)
 
int BKE_object_material_count_eval (const Object *ob)
 
void BKE_id_material_eval_assign (ID *id, int slot, Material *material)
 
void BKE_id_material_eval_ensure_default_slot (ID *id)
 
int BKE_object_material_index_get (Object *ob, const Material *ma)
 
int BKE_object_material_index_get_with_hint (Object *ob, const Material *ma, const int hint_index)
 
int BKE_object_material_ensure (Main *bmain, Object *ob, Material *material)
 
MaterialBKE_gpencil_material (Object *ob, short act)
 
MaterialGPencilStyleBKE_gpencil_material_settings (Object *ob, short act)
 
void BKE_object_material_resize (Main *bmain, Object *ob, const short totcol, bool do_id_user)
 
void BKE_object_materials_test (Main *bmain, Object *ob, ID *id)
 
void BKE_objects_materials_test_all (Main *bmain, ID *id)
 
void BKE_id_material_assign (Main *bmain, ID *id, Material *ma, short act)
 
static void object_material_assign (Main *bmain, Object *ob, Material *ma, short act, int assign_type, bool do_test_all)
 
void BKE_object_material_assign (Main *bmain, Object *ob, Material *ma, short act, int assign_type)
 
void BKE_object_material_assign_single_obdata (Main *bmain, Object *ob, Material *ma, short act)
 
void BKE_object_material_remap (Object *ob, const uint *remap)
 
void BKE_object_material_remap_calc (Object *ob_dst, Object *ob_src, short *remap_src_to_dst)
 
void BKE_object_material_from_eval_data (Main *bmain, Object *ob_orig, const ID *data_eval)
 
void BKE_object_material_array_assign (Main *bmain, Object *ob, Material ***matar, int totcol, const bool to_object_only)
 
short BKE_object_material_slot_find_index (Object *ob, Material *ma)
 
bool BKE_object_material_slot_add (Main *bmain, Object *ob)
 
bool BKE_object_material_slot_remove (Main *bmain, Object *ob)
 
static bNodenodetree_uv_node_recursive (bNode *node)
 
static bool ntree_foreach_texnode_recursive (bNodeTree *nodetree, ForEachTexNodeCallback callback, void *userdata, ePaintSlotFilter slot_filter)
 
static bool count_texture_nodes_cb (bNode *, void *userdata)
 
static int count_texture_nodes_recursive (bNodeTree *nodetree, ePaintSlotFilter slot_filter)
 
static bool fill_texpaint_slots_cb (bNode *node, void *userdata)
 
static void fill_texpaint_slots_recursive (bNodeTree *nodetree, bNode *active_node, const Object *ob, Material *ma, int slot_len, ePaintSlotFilter slot_filter)
 
static ePaintSlotFilter material_paint_slot_filter (const Object *ob)
 
void BKE_texpaint_slot_refresh_cache (Scene *scene, Material *ma, const Object *ob)
 
void BKE_texpaint_slots_refresh_object (Scene *scene, Object *ob)
 
static bool texpaint_slot_node_find_cb (bNode *node, void *userdata)
 
bNodeBKE_texpaint_slot_material_find_node (Material *ma, short texpaint_slot)
 
void ramp_blend (int type, float r_col[3], const float fac, const float col[3])
 
void BKE_material_eval (Depsgraph *depsgraph, Material *material)
 
static void material_default_gpencil_init (Material *ma)
 
static void material_default_surface_init (Material *ma)
 
static void material_default_volume_init (Material *ma)
 
static void material_default_holdout_init (Material *ma)
 
MaterialBKE_material_default_empty ()
 
MaterialBKE_material_default_holdout ()
 
MaterialBKE_material_default_surface ()
 
MaterialBKE_material_default_volume ()
 
MaterialBKE_material_default_gpencil ()
 
void BKE_material_defaults_free_gpu ()
 
void BKE_materials_init ()
 
void BKE_materials_exit ()
 

Variables

static CLG_LogRef LOG = {"bke.material"}
 
IDTypeInfo IDType_ID_MA
 
static Material default_material_empty
 
static Material default_material_holdout
 
static Material default_material_surface
 
static Material default_material_volume
 
static Material default_material_gpencil
 
static Materialdefault_materials []
 

Macro Definition Documentation

◆ DNA_DEPRECATED_ALLOW

#define DNA_DEPRECATED_ALLOW

Definition at line 19 of file blenkernel/intern/material.cc.

Typedef Documentation

◆ ForEachTexNodeCallback

using ForEachTexNodeCallback = bool (*)(bNode *node, void *userdata)

Definition at line 1452 of file blenkernel/intern/material.cc.

Enumeration Type Documentation

◆ ePaintSlotFilter

Bitwise filter for updating paint slots.

Enumerator
PAINT_SLOT_IMAGE 
PAINT_SLOT_COLOR_ATTRIBUTE 

Definition at line 1446 of file blenkernel/intern/material.cc.

Function Documentation

◆ BKE_gpencil_material()

◆ BKE_gpencil_material_add()

Material * BKE_gpencil_material_add ( Main * bmain,
const char * name )

◆ BKE_gpencil_material_attr_init()

◆ BKE_gpencil_material_settings()

◆ BKE_id_material_append()

◆ BKE_id_material_array_p()

◆ BKE_id_material_assign()

void BKE_id_material_assign ( Main * bmain,
ID * id,
Material * ma,
short act )

◆ BKE_id_material_clear()

◆ BKE_id_material_eval_assign()

◆ BKE_id_material_eval_ensure_default_slot()

◆ BKE_id_material_len_p()

◆ BKE_id_material_pop()

◆ BKE_id_material_resize()

◆ BKE_id_materials_copy()

◆ BKE_material_add()

◆ BKE_material_default_empty()

Material * BKE_material_default_empty ( void )

◆ BKE_material_default_gpencil()

◆ BKE_material_default_holdout()

Material * BKE_material_default_holdout ( void )

Definition at line 2080 of file blenkernel/intern/material.cc.

References default_material_holdout.

◆ BKE_material_default_surface()

◆ BKE_material_default_volume()

◆ BKE_material_defaults_free_gpu()

void BKE_material_defaults_free_gpu ( void )

Definition at line 2100 of file blenkernel/intern/material.cc.

◆ BKE_material_eval()

void BKE_material_eval ( Depsgraph * depsgraph,
Material * material )

◆ BKE_material_make_node_previews_dirty()

void BKE_material_make_node_previews_dirty ( Material * ma)

◆ BKE_materials_exit()

void BKE_materials_exit ( void )

Definition at line 2124 of file blenkernel/intern/material.cc.

References default_materials, and material_free_data().

Referenced by WM_exit_ex().

◆ BKE_materials_init()

◆ BKE_object_material_array_assign()

◆ BKE_object_material_array_p()

◆ BKE_object_material_assign()

◆ BKE_object_material_assign_single_obdata()

void BKE_object_material_assign_single_obdata ( struct Main * bmain,
struct Object * ob,
struct Material * ma,
short act )

Similar to BKE_object_material_assign with BKE_MAT_ASSIGN_OBDATA type, but does not scan whole Main for other usages of the same obdata. Only use in cases where you know that the object's obdata is only used by this one object.

Definition at line 1147 of file blenkernel/intern/material.cc.

References BKE_MAT_ASSIGN_OBDATA, and object_material_assign().

Referenced by blender::io::alembic::utils::assign_materials(), and utils::assign_materials().

◆ BKE_object_material_count_eval()

◆ BKE_object_material_ensure()

◆ BKE_object_material_from_eval_data()

void BKE_object_material_from_eval_data ( Main * bmain,
Object * ob_orig,
const ID * data_eval )

◆ BKE_object_material_get()

Material * BKE_object_material_get ( Object * ob,
short act )

Definition at line 725 of file blenkernel/intern/material.cc.

References BKE_object_material_get_p(), Material::gp_style, OB_GREASE_PENCIL, and Object::type.

Referenced by InstanceWriter::add_material_bindings(), animdata_filter_ds_materials(), blender::io::usd::USDCurvesWriter::assign_materials(), blender::ed::greasepencil::bake_grease_pencil_animation_exec(), blender::ed::object::bake_object_check(), bc_has_animations(), BKE_gpencil_material(), BKE_gpencil_material_find_index_by_name_prefix(), BKE_gpencil_material_settings(), BKE_grease_pencil_object_material_ensure_by_name(), BKE_grease_pencil_object_material_ensure_from_active_input_material(), BKE_grease_pencil_object_material_ensure_from_brush(), BKE_grease_pencil_object_material_from_brush_get(), BKE_grease_pencil_object_material_index_get_by_name(), BKE_object_material_index_get(), BKE_object_material_index_get_with_hint(), BKE_object_material_remap_calc(), BKE_texpaint_slots_refresh_object(), buttons_context_path_material(), GeometryExporter::create_mesh_primitive_list(), blender::ed::greasepencil::image_render::draw_grease_pencil_strokes(), blender::ed::object::drop_named_material_tooltip(), ED_mesh_join_objects_exec(), ED_object_assign_active_image(), ED_object_get_active_image(), ED_object_texture_paint_mode_enter_ex(), ED_paint_proj_mesh_data_check(), AnimationExporter::export_curve_animation(), blender::ui::greasepencil::eyedropper_add_material(), eyedropper_cryptomatte_sample_view3d_fl(), blender::bke::paint::canvas::get_active_slot(), blender::ed::sculpt_paint::canvas::get_active_slot(), BCAnimationCurve::get_animation_name(), blender::ed::greasepencil::get_boundary_bounds(), blender::ed::space_node::get_context_path_node_shader(), get_default_texture_layer_name_for_object(), blender::ed::greasepencil::get_editable_material_indices(), blender::ed::greasepencil::get_fill_material_indices(), blender::modifier::greasepencil::get_grease_pencil_material_passes(), blender::ed::greasepencil::get_hidden_material_indices(), get_or_create_current_material(), blender::ed::greasepencil::get_visible_boundary_strokes(), blender::io::grease_pencil::get_visible_strokes(), blender::ed::sculpt_paint::grease_pencil_fill_invoke(), blender::ed::greasepencil::grease_pencil_material_copy_to_object_exec(), blender::ed::greasepencil::grease_pencil_material_hide_exec(), blender::ed::greasepencil::grease_pencil_material_lock_all_exec(), blender::ed::greasepencil::grease_pencil_material_lock_unselected_exec(), blender::ed::greasepencil::grease_pencil_material_lock_unused_exec(), blender::ed::greasepencil::grease_pencil_material_unlock_all_exec(), imapaint_pick_uv(), blender::io::obj::OBJImportTest::import_and_check(), CryptomatteSession::init(), Freestyle::BlenderFileLoader::insertShapeNode(), join_mesh_single(), lineart_load_tri_task(), blender::ed::object::make_links_data_exec(), blender::ed::greasepencil::material_enum_itemf(), material_slot_assign_exec(), material_slot_de_select(), blender::modify_fill_color(), blender::modify_fill_color(), blender::modify_stroke_color(), blender::modify_stroke_color(), blender::ed::object::object_grease_pencil_add_exec(), blender::ed::object::object_select_all_by_material(), blender::ed::object::object_select_linked_exec(), ForEachMaterialFunctor< Functor >::operator()(), paint_sample_color(), proj_paint_state_mesh_eval_init(), psys_cache_paths(), psys_get_particle_on_path(), psys_thread_context_init(), shader_get_from_context(), blender::ed::object::single_mat_users(), texture_paint_add_texture_paint_slot_invoke(), AnimationImporter::translate_Animations(), and versioning_eevee_shadow_settings().

◆ BKE_object_material_get_eval()

Material * BKE_object_material_get_eval ( struct Object * ob,
short act )

◆ BKE_object_material_get_p()

Material ** BKE_object_material_get_p ( Object * ob,
short act )

◆ BKE_object_material_index_get()

◆ BKE_object_material_index_get_with_hint()

int BKE_object_material_index_get_with_hint ( Object * ob,
const Material * ma,
int hint_index )

A version of BKE_object_material_index_get that takes an index to test first.

Parameters
hint_indexWhen this index is in a valid range, test it first. Useful when an active-index is preferred but may not match the material.

Definition at line 855 of file blenkernel/intern/material.cc.

References BKE_object_material_get(), BKE_object_material_index_get(), and BKE_object_material_len_p().

Referenced by material_slot_de_select().

◆ BKE_object_material_len_p()

◆ BKE_object_material_remap()

◆ BKE_object_material_remap_calc()

void BKE_object_material_remap_calc ( struct Object * ob_dst,
struct Object * ob_src,
short * remap_src_to_dst )

Calculate a material remapping from ob_src to ob_dst.

Parameters
remap_src_to_dstAn array the size of ob_src->totcol where index values are filled in which map to ob_dst materials.

Definition at line 1182 of file blenkernel/intern/material.cc.

References BKE_object_material_get(), BLI_ghash_free(), BLI_ghash_lookup_p(), BLI_ghash_ptr_new_ex(), BLI_ghash_reinsert(), POINTER_AS_INT, POINTER_FROM_INT, and Object::totcol.

Referenced by BMD_mesh_intersection().

◆ BKE_object_material_resize()

◆ BKE_object_material_slot_add()

◆ BKE_object_material_slot_find_index()

short BKE_object_material_slot_find_index ( Object * ob,
Material * ma )

◆ BKE_object_material_slot_remove()

◆ BKE_object_material_slot_used()

◆ BKE_object_materials_test()

◆ BKE_objects_materials_test_all()

◆ BKE_texpaint_slot_material_find_node()

◆ BKE_texpaint_slot_refresh_cache()

◆ BKE_texpaint_slots_refresh_object()

◆ count_texture_nodes_cb()

static bool count_texture_nodes_cb ( bNode * ,
void * userdata )
static

Definition at line 1484 of file blenkernel/intern/material.cc.

Referenced by count_texture_nodes_recursive().

◆ count_texture_nodes_recursive()

static int count_texture_nodes_recursive ( bNodeTree * nodetree,
ePaintSlotFilter slot_filter )
static

◆ fill_texpaint_slots_cb()

◆ fill_texpaint_slots_recursive()

static void fill_texpaint_slots_recursive ( bNodeTree * nodetree,
bNode * active_node,
const Object * ob,
Material * ma,
int slot_len,
ePaintSlotFilter slot_filter )
static

◆ get_evaluated_object_data_with_materials()

static const ID * get_evaluated_object_data_with_materials ( Object * ob)
static

◆ material_blend_read_data()

static void material_blend_read_data ( BlendDataReader * reader,
ID * id )
static

◆ material_blend_write()

◆ material_copy_data()

◆ material_data_index_clear_id()

static void material_data_index_clear_id ( ID * id)
static

◆ material_data_index_remove_id()

◆ material_default_gpencil_init()

static void material_default_gpencil_init ( Material * ma)
static

◆ material_default_holdout_init()

◆ material_default_surface_init()

◆ material_default_volume_init()

◆ material_foreach_id()

◆ material_free_data()

◆ material_init_data()

static void material_init_data ( ID * id)
static

◆ material_paint_slot_filter()

static ePaintSlotFilter material_paint_slot_filter ( const Object * ob)
static

Check which type of paint slots should be filled for the given object.

Definition at line 1576 of file blenkernel/intern/material.cc.

References Object::mode, OB_MODE_SCULPT, PAINT_SLOT_COLOR_ATTRIBUTE, and PAINT_SLOT_IMAGE.

Referenced by BKE_texpaint_slot_refresh_cache().

◆ nodetree_mark_previews_dirty_reccursive()

static void nodetree_mark_previews_dirty_reccursive ( bNodeTree * tree)
static

◆ nodetree_uv_node_recursive()

static bNode * nodetree_uv_node_recursive ( bNode * node)
static

◆ ntree_foreach_texnode_recursive()

◆ object_material_assign()

◆ ramp_blend()

◆ texpaint_slot_node_find_cb()

Variable Documentation

◆ default_material_empty

Material default_material_empty
static

Definition at line 1976 of file blenkernel/intern/material.cc.

Referenced by BKE_material_default_empty().

◆ default_material_gpencil

Material default_material_gpencil
static

◆ default_material_holdout

Material default_material_holdout
static

◆ default_material_surface

Material default_material_surface
static

◆ default_material_volume

Material default_material_volume
static

◆ default_materials

Material* default_materials[]
static
Initial value:
nullptr}
static Material default_material_gpencil
static Material default_material_surface
static Material default_material_empty
static Material default_material_holdout
static Material default_material_volume

Definition at line 1982 of file blenkernel/intern/material.cc.

Referenced by BKE_material_defaults_free_gpu(), BKE_materials_exit(), and BKE_materials_init().

◆ IDType_ID_MA

IDTypeInfo IDType_ID_MA
Initial value:
= {
sizeof(Material),
"Material",
N_("materials"),
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
}
@ IDTYPE_FLAGS_APPEND_IS_REUSABLE
Definition BKE_idtype.hh:39
#define BLT_I18NCONTEXT_ID_MATERIAL
#define FILTER_ID_MA
Definition DNA_ID.h:1175
#define FILTER_ID_GR
Definition DNA_ID.h:1170
#define FILTER_ID_TE
Definition DNA_ID.h:1187
@ INDEX_ID_MA
Definition DNA_ID.h:1280
@ ID_MA
struct Material Material
static void material_copy_data(Main *bmain, std::optional< Library * > owner_library, ID *id_dst, const ID *id_src, const int flag)
static void material_foreach_id(ID *id, LibraryForeachIDData *data)
static void material_blend_write(BlendWriter *writer, ID *id, const void *id_address)
static void material_free_data(ID *id)
static void material_blend_read_data(BlendDataReader *reader, ID *id)
static void material_init_data(ID *id)
#define N_(msgid)

Definition at line 240 of file blenkernel/intern/material.cc.

◆ LOG

CLG_LogRef LOG = {"bke.material"}
static

Definition at line 82 of file blenkernel/intern/material.cc.

Referenced by BKE_object_material_slot_remove().