34 const char *socket_id,
40 BLI_assert(socket && socket->type == property_type);
41 switch (property_type) {
71 fprintf(stderr,
"Cannot load image file: '%s'\n", path.c_str());
74 fprintf(stderr,
"Loaded image from: '%s'\n", path.c_str());
83 const float color[4] = {0, 0, 0, 1};
95 STRNCPY(image->filepath, path.c_str());
102 Image *image =
nullptr;
106 auto end_pos = std::remove(image_path.begin(), image_path.end(),
'"');
107 image_path.erase(end_pos, image_path.end());
110 std::string tex_path{tex_map.
mtl_dir_path + image_path};
112 if (image !=
nullptr) {
117 if (image !=
nullptr) {
121 std::string no_underscore_path{image_path};
122 std::replace(no_underscore_path.begin(), no_underscore_path.end(),
'_',
' ');
123 if (!
ELEM(no_underscore_path, image_path, tex_path)) {
125 if (image !=
nullptr) {
131 if (base_path != tex_path) {
133 if (image !=
nullptr) {
166 const char *from_node_id,
168 const char *to_node_id)
179 bool do_highlight =
false;
180 bool do_tranparency =
false;
181 bool do_reflection =
false;
182 bool do_glass =
false;
196 do_reflection =
true;
202 do_reflection =
true;
203 do_tranparency =
true;
208 do_reflection =
true;
213 do_reflection =
true;
214 do_tranparency =
true;
219 do_reflection =
true;
220 do_tranparency =
true;
225 do_reflection =
true;
231 do_reflection =
false;
232 do_tranparency =
true;
236 std::cerr <<
"Warning! illum value = " << illum
237 <<
"is not supported by the Principled-BSDF shader." << std::endl;
245 if (specular < 0.0f) {
246 specular = do_highlight ? 1.0f : 0.0f;
251 roughness = do_highlight ? 0.0f : 1.0f;
254 float clamped_ns = std::max(0.0f, std::min(1000.0f, mtl_mat.
spec_exponent));
255 roughness = 1.0f -
sqrt(clamped_ns / 1000.0f);
262 if (metallic < 0.0f) {
270 float ior = mtl_mat.
ior;
272 if (do_tranparency) {
279 float alpha = mtl_mat.
alpha;
280 if (do_tranparency && alpha < 0) {
293 if (base_color.x >= 0 && base_color.y >= 0 && base_color.z >= 0) {
296 mat->
r = base_color.x;
297 mat->
g = base_color.y;
298 mat->
b = base_color.z;
302 if (emission_color.x >= 0 && emission_color.y >= 0 && emission_color.z >= 0) {
320 if (do_tranparency || (alpha >= 0.0f && alpha < 1.0f)) {
325 if (mtl_mat.
sheen >= 0) {
335 if (mtl_mat.
aniso >= 0) {
346 if (transmission >= 0) {
361 if (!value.is_valid()) {
367 if (image ==
nullptr) {
373 image_node->
id = &image->id;
377 bNode *normal_map =
nullptr;
385 if (value.translation !=
float3(0, 0, 0) || value.scale !=
float3(1, 1, 1)) {
392 link_sockets(ntree, mapping,
"Vector", image_node,
"Vector");
396 link_sockets(ntree, image_node,
"Color", normal_map,
"Color");
397 link_sockets(ntree, normal_map,
"Normal", bsdf,
"Normal");
Image * BKE_image_load_exists(Main *bmain, const char *filepath, bool *r_exists=nullptr)
Image * BKE_image_add_generated(Main *bmain, unsigned int width, unsigned int height, const char *name, int depth, int floatbuf, short gen_type, const float color[4], bool stereo3d, bool is_data, bool tiled)
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
#define SH_NODE_TEX_IMAGE
#define SH_NODE_TEX_COORD
#define SH_NODE_NORMAL_MAP
#define SH_NODE_OUTPUT_MATERIAL
MINLINE void copy_v4_v4(float r[4], const float a[4])
MINLINE void copy_v3_v3(float r[3], const float a[3])
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
bool void BLI_path_rel(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1)
#define STRNCPY(dst, src)
struct blender::bke::bNodeTreeType * ntreeType_Shader
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a producing a negative Combine Generate a color from its and blue Hue Saturation Apply a color transformation in the HSV color model Specular Similar to the Principled BSDF node but uses the specular workflow instead of metallic
input_tx image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, "preview_img") .compute_source("compositor_compute_preview.glsl") .do_static_compilation(true)
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
void node_set_active(bNodeTree *ntree, bNode *node)
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)
bNodeTree * node_tree_add_tree_embedded(Main *bmain, ID *owner_id, const char *name, const char *idname)
bNodeSocket * node_find_socket(bNode *node, eNodeSocketInOut in_out, StringRef identifier)
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)
const MTLTexMap & tex_map_of_type(MTLTexMapType key) const
MTLTexMap texture_maps[int(MTLTexMapType::Count)]