40 "array size mismatch");
47 const char *identifier,
59 switch (property_type) {
64 r_property[0] = socket_def_value->
value;
94 const char *dest_socket_id,
97 r_linked_sockets.
clear();
104 for (
const bNodeSocket *curr_socket : dest_inputs) {
105 if (
STREQ(curr_socket->identifier, dest_socket_id)) {
106 dest_socket = curr_socket;
112 r_linked_sockets.
resize(linked_sockets.
size());
113 r_linked_sockets = linked_sockets;
123 const bNode &parent_node = socket->owner_node();
124 if (parent_node.
typeinfo->type == node_type) {
140 Image *tex_image =
reinterpret_cast<Image *
>(tex_node->
id);
149 "Packed image found:'%s'. Unpack and place the image in the same "
150 "directory as the .MTL file.\n",
179 for (
const bNode *node : nodetree->nodes_by_type(
"ShaderNodeOutputMaterial")) {
180 const bNodeSocket &node_input_socket0 = node->input_socket(0);
181 for (
const bNodeSocket *out_sock : node_input_socket0.directly_linked_sockets()) {
182 const bNode &in_node = out_sock->owner_node();
183 if (in_node.
typeinfo->type == SH_NODE_BSDF_PRINCIPLED) {
198 float roughness = material->roughness;
203 float spec_exponent = (1.0f - roughness);
204 spec_exponent *= spec_exponent * 1000.0f;
206 float specular = material->spec;
211 float metallic = material->metallic;
216 float refraction_index = 1.0f;
221 float alpha = material->a;
225 const bool transparent = alpha != 1.0f;
227 float3 diffuse_col = {material->r, material->g, material->
b};
232 float3 emission_col{0.0f};
233 float emission_strength = 0.0f;
238 mul_v3_fl(emission_col, emission_strength);
242 float coat_roughness = -1.0f;
244 float aniso_rot = -1.0f;
245 float transmission = -1.0f;
261 if (specular == 0.0f) {
265 else if (metallic > 0.0f) {
276 else if (transparent) {
281 if (metallic != 0.0f) {
287 r_mtl_mat.
color = diffuse_col;
288 r_mtl_mat.
spec_color = {specular, specular, specular};
290 r_mtl_mat.
ior = refraction_index;
291 r_mtl_mat.
alpha = alpha;
298 r_mtl_mat.
aniso = aniso;
300 r_mtl_mat.
transmit_color = {transmission, transmission, transmission};
311 if (!material || !
node_tree || !bsdf_node) {
324 const bNode *normal_map_node{
nullptr};
338 float emission_strength = 0.0f;
340 SOCK_FLOAT, bsdf_node,
"Emission Strength", {&emission_strength, 1});
341 if (emission_strength == 0.0f) {
356 if (tex_image_filepath.empty()) {
364 if (normal_map_node) {
373 value.image_path = tex_image_filepath;
381 mtlmat.
name = std::string(material->id.name + 2);
382 std::replace(mtlmat.
name.begin(), mtlmat.
name.end(),
' ',
'_');
383 const bNodeTree *nodetree = material->nodetree;
384 if (nodetree !=
nullptr) {
385 nodetree->ensure_topology_cache();
bool BKE_image_has_filepath(const Image *ima)
bool BKE_image_has_packedfile(const Image *image)
#define SH_NODE_TEX_IMAGE
#define SH_NODE_NORMAL_MAP
#define BLI_STATIC_ASSERT(a, msg)
MINLINE void mul_v3_fl(float r[3], float f)
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
int BLI_path_sequence_decode(const char *path, char *head, size_t head_maxncpy, char *tail, size_t tail_maxncpy, unsigned short *r_digits_len)
void BLI_path_sequence_encode(char *path, size_t path_maxncpy, const char *head, const char *tail, unsigned short numlen, int pic)
#define STRNCPY(dst, src)
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
constexpr int64_t size() const
constexpr T * data() const
constexpr const T & first() const
constexpr int64_t size() const
void resize(const int64_t new_size)
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
bNodeSocket * node_find_socket(bNode *node, eNodeSocketInOut in_out, StringRef identifier)
const char * tex_map_type_to_socket_id[]
static const bNode * get_node_of_type(Span< const bNodeSocket * > sockets_list, const int node_type)
static std::string get_image_filepath(const bNode *tex_node)
static const bNode * find_bsdf_node(const bNodeTree *nodetree)
static void store_bsdf_properties(const bNode *bsdf_node, const Material *material, MTLMaterial &r_mtl_mat)
MTLMaterial mtlmaterial_for_material(const Material *material)
static void copy_property_from_node(const eNodeSocketDatatype property_type, const bNode *node, const char *identifier, MutableSpan< float > r_property)
static void store_image_textures(const bNode *bsdf_node, const bNodeTree *node_tree, const Material *material, MTLMaterial &r_mtl_mat)
static void linked_sockets_to_dest_id(const bNode *dest_node, const bNodeTree &node_tree, const char *dest_socket_id, Vector< const bNodeSocket * > &r_linked_sockets)
closure color sheen(normal N, float roughness) BUILTIN
bNodeTypeHandle * typeinfo
MTLTexMap texture_maps[int(MTLTexMapType::Count)]