39 const char *socket_id,
46 switch (property_type) {
76 CLOG_WARN(&
LOG,
"Cannot load image file: '%s'", path.c_str());
79 CLOG_INFO(&
LOG,
"Loaded image from: '%s'", path.c_str());
99 auto end_pos = std::remove(image_path.begin(), image_path.end(),
'"');
100 image_path.erase(end_pos, image_path.end());
103 std::string tex_path{tex_map.
mtl_dir_path + image_path};
105 if (
image !=
nullptr) {
110 if (
image !=
nullptr) {
114 std::string no_underscore_path{image_path};
115 std::replace(no_underscore_path.begin(), no_underscore_path.end(),
'_',
' ');
116 if (!
ELEM(no_underscore_path, image_path, tex_path)) {
118 if (
image !=
nullptr) {
124 if (base_path != tex_path) {
126 if (
image !=
nullptr) {
152 node->location[0] =
x;
153 node->location[1] =
y;
159 const char *from_node_id,
161 const char *to_node_id)
172 bool do_highlight =
false;
173 bool do_tranparency =
false;
174 bool do_reflection =
false;
175 bool do_glass =
false;
189 do_reflection =
true;
195 do_reflection =
true;
196 do_tranparency =
true;
201 do_reflection =
true;
206 do_reflection =
true;
207 do_tranparency =
true;
212 do_reflection =
true;
213 do_tranparency =
true;
218 do_reflection =
true;
224 do_reflection =
false;
225 do_tranparency =
true;
230 "Material illum value '%d' is not supported by the Principled BSDF shader.",
239 if (specular < 0.0f) {
240 specular = do_highlight ? 1.0f : 0.0f;
245 roughness = do_highlight ? 0.0f : 1.0f;
248 float clamped_ns = std::max(0.0f, std::min(1000.0f, mtl_mat.
spec_exponent));
249 roughness = 1.0f -
sqrt(clamped_ns / 1000.0f);
256 if (metallic < 0.0f) {
264 float ior = mtl_mat.
ior;
266 if (do_tranparency) {
273 float alpha = mtl_mat.
alpha;
274 if (do_tranparency && alpha < 0) {
287 if (base_color.x >= 0 && base_color.y >= 0 && base_color.z >= 0) {
290 mat->r = base_color.x;
291 mat->g = base_color.y;
292 mat->b = base_color.z;
300 if (emission_color.x >= 0 && emission_color.y >= 0 && emission_color.z >= 0) {
301 float emission_strength = fmax(emission_color.x, fmax(emission_color.y, emission_color.z));
302 if (emission_strength > 1.0f) {
306 SOCK_RGBA,
"Emission Color", {emission_color / emission_strength, 3}, bsdf);
317 mat->roughness = roughness;
319 mat->metallic = metallic;
327 if (do_tranparency || (alpha >= 0.0f && alpha < 1.0f)) {
332 if (mtl_mat.
sheen >= 0) {
342 if (mtl_mat.
aniso >= 0) {
353 if (transmission >= 0) {
374 if (
image ==
nullptr) {
384 bNode *normal_map =
nullptr;
399 link_sockets(ntree, mapping,
"Vector", image_node,
"Vector");
403 link_sockets(ntree, image_node,
"Color", normal_map,
"Color");
404 link_sockets(ntree, normal_map,
"Normal", bsdf,
"Normal");
#define SH_NODE_TEX_IMAGE
#define SH_NODE_BSDF_PRINCIPLED
#define SH_NODE_TEX_COORD
#define SH_NODE_NORMAL_MAP
#define SH_NODE_OUTPUT_MATERIAL
#define CLOG_WARN(clg_ref,...)
#define CLOG_INFO(clg_ref,...)
constexpr const T * data() const
constexpr int64_t size() const
bNode * node_add_static_node(const bContext *C, bNodeTree &ntree, int type)
bNodeLink & node_add_link(bNodeTree &ntree, bNode &fromnode, bNodeSocket &fromsock, bNode &tonode, bNodeSocket &tosock)
bNodeSocket * node_find_socket(bNode &node, eNodeSocketInOut in_out, UString identifier)
void node_set_active(bNodeTree &ntree, bNode &node)
const char * tex_map_type_to_socket_id[]
const float node_locy_step
const float node_locx_normalmap
static void add_image_textures(Main *bmain, bNodeTree *ntree, bNode *bsdf, Material *mat, const MTLMaterial &mtl_mat, bool relative_paths)
const float node_locx_image
static bNode * add_node(bNodeTree *ntree, int type, float x, float y)
const float node_locx_mapping
const float node_locx_bsdf
static void set_bsdf_socket_values(bNode *bsdf, Material *mat, const MTLMaterial &mtl_mat)
static Image * create_placeholder_image(Main *bmain, const std::string &path)
bNodeTree * create_mtl_node_tree(Main *bmain, const MTLMaterial &mtl_mat, Material *mat, bool relative_paths)
const float node_locx_texcoord
static void set_property_of_socket(eNodeSocketDatatype property_type, const char *socket_id, Span< float > value, bNode *r_node)
const float node_locx_output
const float node_locy_top
static void link_sockets(bNodeTree *ntree, bNode *from_node, const char *from_node_id, bNode *to_node, const char *to_node_id)
static Image * load_image_at_path(Main *bmain, const std::string &path, bool relative_paths)
static Image * load_texture_image(Main *bmain, const MTLTexMap &tex_map, bool relative_paths)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE void copy_v3_v3(float r[3], const float a[3])
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
Image * BKE_image_load_exists(Main *bmain, const char *filepath, bool check_open=true, bool *r_exists=nullptr)
bool void BLI_path_rel(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1)
int BLI_path_normalize(char *path) ATTR_NONNULL(1)
MINLINE void copy_v4_v4(float r[4], const float a[4])
VecBase< float, 3 > float3
const MTLTexMap & tex_map_of_type(MTLTexMapType key) const
MTLTexMap texture_maps[int(MTLTexMapType::Count)]