diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:17:24 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:21:24 +0300 |
commit | e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch) | |
tree | 8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/collada/Materials.cpp | |
parent | b3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff) |
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.
For details on usage and instructions for migrating branches
without conflicts, see:
https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/collada/Materials.cpp')
-rw-r--r-- | source/blender/collada/Materials.cpp | 450 |
1 files changed, 224 insertions, 226 deletions
diff --git a/source/blender/collada/Materials.cpp b/source/blender/collada/Materials.cpp index d6ed0e2859a..4313e634b23 100644 --- a/source/blender/collada/Materials.cpp +++ b/source/blender/collada/Materials.cpp @@ -16,306 +16,304 @@ #include "Materials.h" -MaterialNode::MaterialNode(bContext *C, Material *ma, KeyImageMap &key_image_map) : - mContext(C), - material(ma), - effect(nullptr), - key_image_map(&key_image_map) +MaterialNode::MaterialNode(bContext *C, Material *ma, KeyImageMap &key_image_map) + : mContext(C), material(ma), effect(nullptr), key_image_map(&key_image_map) { - ntree = prepare_material_nodetree(); - setShaderType(); + ntree = prepare_material_nodetree(); + setShaderType(); } -MaterialNode::MaterialNode(bContext *C, COLLADAFW::EffectCommon *ef, Material *ma, UidImageMap &uid_image_map) : - mContext(C), - material(ma), - effect(ef), - uid_image_map(&uid_image_map) +MaterialNode::MaterialNode(bContext *C, + COLLADAFW::EffectCommon *ef, + Material *ma, + UidImageMap &uid_image_map) + : mContext(C), material(ma), effect(ef), uid_image_map(&uid_image_map) { - ntree = prepare_material_nodetree(); - setShaderType(); + ntree = prepare_material_nodetree(); + setShaderType(); - std::map<std::string, bNode *> nmap; + std::map<std::string, bNode *> nmap; #if 0 - nmap["main"] = add_node(C, ntree, SH_NODE_BSDF_PRINCIPLED, -300, 300); - nmap["emission"] = add_node(C, ntree, SH_NODE_EMISSION, -300, 500, "emission"); - nmap["add"] = add_node(C, ntree, SH_NODE_ADD_SHADER, 100, 400); - nmap["transparent"] = add_node(C, ntree, SH_NODE_BSDF_TRANSPARENT, 100, 200); - nmap["mix"] = add_node(C, ntree, SH_NODE_MIX_SHADER, 400, 300, "transparency"); - nmap["out"] = add_node(C, ntree, SH_NODE_OUTPUT_MATERIAL, 600, 300); - nmap["out"]->flag &= ~NODE_SELECT; - - add_link(ntree, nmap["emission"], 0, nmap["add"], 0); - add_link(ntree, nmap["main"], 0, nmap["add"], 1); - add_link(ntree, nmap["add"], 0, nmap["mix"], 1); - add_link(ntree, nmap["transparent"], 0, nmap["mix"], 2); - - add_link(ntree, nmap["mix"], 0, nmap["out"], 0); - // experimental, probably not used. - make_group(C, ntree, nmap); + nmap["main"] = add_node(C, ntree, SH_NODE_BSDF_PRINCIPLED, -300, 300); + nmap["emission"] = add_node(C, ntree, SH_NODE_EMISSION, -300, 500, "emission"); + nmap["add"] = add_node(C, ntree, SH_NODE_ADD_SHADER, 100, 400); + nmap["transparent"] = add_node(C, ntree, SH_NODE_BSDF_TRANSPARENT, 100, 200); + nmap["mix"] = add_node(C, ntree, SH_NODE_MIX_SHADER, 400, 300, "transparency"); + nmap["out"] = add_node(C, ntree, SH_NODE_OUTPUT_MATERIAL, 600, 300); + nmap["out"]->flag &= ~NODE_SELECT; + + add_link(ntree, nmap["emission"], 0, nmap["add"], 0); + add_link(ntree, nmap["main"], 0, nmap["add"], 1); + add_link(ntree, nmap["add"], 0, nmap["mix"], 1); + add_link(ntree, nmap["transparent"], 0, nmap["mix"], 2); + + add_link(ntree, nmap["mix"], 0, nmap["out"], 0); + // experimental, probably not used. + make_group(C, ntree, nmap); #else - shader_node = add_node(SH_NODE_BSDF_PRINCIPLED, 0, 300, ""); - output_node = add_node(SH_NODE_OUTPUT_MATERIAL, 300, 300, ""); - add_link(shader_node, 0, output_node, 0); + shader_node = add_node(SH_NODE_BSDF_PRINCIPLED, 0, 300, ""); + output_node = add_node(SH_NODE_OUTPUT_MATERIAL, 300, 300, ""); + add_link(shader_node, 0, output_node, 0); #endif } void MaterialNode::setShaderType() { #if 0 - COLLADAFW::EffectCommon::ShaderType shader = ef->getShaderType(); - // Currently we only support PBR based shaders - // TODO: simulate the effects with PBR - - // blinn - if (shader == COLLADAFW::EffectCommon::SHADER_BLINN) { - ma->spec_shader = MA_SPEC_BLINN; - ma->spec = ef->getShininess().getFloatValue(); - } - // phong - else if (shader == COLLADAFW::EffectCommon::SHADER_PHONG) { - ma->spec_shader = MA_SPEC_PHONG; - ma->har = ef->getShininess().getFloatValue(); - } - // lambert - else if (shader == COLLADAFW::EffectCommon::SHADER_LAMBERT) { - ma->diff_shader = MA_DIFF_LAMBERT; - } - // default - lambert - else { - ma->diff_shader = MA_DIFF_LAMBERT; - fprintf(stderr, "Current shader type is not supported, default to lambert.\n"); - } + COLLADAFW::EffectCommon::ShaderType shader = ef->getShaderType(); + // Currently we only support PBR based shaders + // TODO: simulate the effects with PBR + + // blinn + if (shader == COLLADAFW::EffectCommon::SHADER_BLINN) { + ma->spec_shader = MA_SPEC_BLINN; + ma->spec = ef->getShininess().getFloatValue(); + } + // phong + else if (shader == COLLADAFW::EffectCommon::SHADER_PHONG) { + ma->spec_shader = MA_SPEC_PHONG; + ma->har = ef->getShininess().getFloatValue(); + } + // lambert + else if (shader == COLLADAFW::EffectCommon::SHADER_LAMBERT) { + ma->diff_shader = MA_DIFF_LAMBERT; + } + // default - lambert + else { + ma->diff_shader = MA_DIFF_LAMBERT; + fprintf(stderr, "Current shader type is not supported, default to lambert.\n"); + } #endif } bNodeTree *MaterialNode::prepare_material_nodetree() { - if (material->nodetree == NULL) { - material->nodetree = ntreeAddTree(NULL, "Shader Nodetree", "ShaderNodeTree"); - material->use_nodes = true; - } - return material->nodetree; + if (material->nodetree == NULL) { + material->nodetree = ntreeAddTree(NULL, "Shader Nodetree", "ShaderNodeTree"); + material->use_nodes = true; + } + return material->nodetree; } bNode *MaterialNode::add_node(int node_type, int locx, int locy, std::string label) { - bNode *node = nodeAddStaticNode(mContext, ntree, node_type); - if (node) { - if (label.length() > 0) { - strcpy(node->label, label.c_str()); - } - node->locx = locx; - node->locy = locy; - node->flag |= NODE_SELECT; - } - node_map[label] = node; - return node; + bNode *node = nodeAddStaticNode(mContext, ntree, node_type); + if (node) { + if (label.length() > 0) { + strcpy(node->label, label.c_str()); + } + node->locx = locx; + node->locy = locy; + node->flag |= NODE_SELECT; + } + node_map[label] = node; + return node; } void MaterialNode::add_link(bNode *from_node, int from_index, bNode *to_node, int to_index) { - bNodeSocket *from_socket = (bNodeSocket *)BLI_findlink(&from_node->outputs, from_index); - bNodeSocket *to_socket = (bNodeSocket *)BLI_findlink(&to_node->inputs, to_index); + bNodeSocket *from_socket = (bNodeSocket *)BLI_findlink(&from_node->outputs, from_index); + bNodeSocket *to_socket = (bNodeSocket *)BLI_findlink(&to_node->inputs, to_index); - nodeAddLink(ntree, from_node, from_socket, to_node, to_socket); + nodeAddLink(ntree, from_node, from_socket, to_node, to_socket); } void MaterialNode::set_reflectivity(float val) { - material->metallic = val; - bNodeSocket *socket = (bNodeSocket *)BLI_findlink(&shader_node->inputs, BC_PBR_METALLIC); - *(float *)socket->default_value = val; + material->metallic = val; + bNodeSocket *socket = (bNodeSocket *)BLI_findlink(&shader_node->inputs, BC_PBR_METALLIC); + *(float *)socket->default_value = val; } void MaterialNode::set_ior(float val) { - bNodeSocket *socket = (bNodeSocket *)BLI_findlink(&shader_node->inputs, BC_PBR_IOR); - *(float *)socket->default_value = val; + bNodeSocket *socket = (bNodeSocket *)BLI_findlink(&shader_node->inputs, BC_PBR_IOR); + *(float *)socket->default_value = val; } void MaterialNode::set_diffuse(COLLADAFW::ColorOrTexture &cot, std::string label) { - int locy = -300 * (node_map.size()-2); - if (cot.isColor()) { - COLLADAFW::Color col = cot.getColor(); - bNodeSocket *socket = (bNodeSocket *)BLI_findlink(&shader_node->inputs, BC_PBR_DIFFUSE); - float *fcol = (float *)socket->default_value; - - fcol[0] = material->r = col.getRed(); - fcol[1] = material->g = col.getGreen(); - fcol[2] = material->b = col.getBlue(); - fcol[3] = material->a = col.getAlpha(); - } - else if (cot.isTexture()) { - bNode *texture_node = add_texture_node(cot, -300, locy, label); - if (texture_node != NULL) { - add_link(texture_node, 0, shader_node, 0); - } - } + int locy = -300 * (node_map.size() - 2); + if (cot.isColor()) { + COLLADAFW::Color col = cot.getColor(); + bNodeSocket *socket = (bNodeSocket *)BLI_findlink(&shader_node->inputs, BC_PBR_DIFFUSE); + float *fcol = (float *)socket->default_value; + + fcol[0] = material->r = col.getRed(); + fcol[1] = material->g = col.getGreen(); + fcol[2] = material->b = col.getBlue(); + fcol[3] = material->a = col.getAlpha(); + } + else if (cot.isTexture()) { + bNode *texture_node = add_texture_node(cot, -300, locy, label); + if (texture_node != NULL) { + add_link(texture_node, 0, shader_node, 0); + } + } } Image *MaterialNode::get_diffuse_image() { - bNode *shader = ntreeFindType(ntree, SH_NODE_BSDF_PRINCIPLED); - if (shader == nullptr) { - return nullptr; - } - - bNodeSocket *in_socket = (bNodeSocket *)BLI_findlink(&shader->inputs, BC_PBR_DIFFUSE); - if (in_socket == nullptr) { - return nullptr; - } - - bNodeLink *link = in_socket->link; - if (link == nullptr) { - return nullptr; - } - - bNode *texture = link->fromnode; - if (texture == nullptr) { - return nullptr; - } - - if (texture->type != SH_NODE_TEX_IMAGE) { - return nullptr; - } - - Image *image = (Image *)texture->id; - return image; - + bNode *shader = ntreeFindType(ntree, SH_NODE_BSDF_PRINCIPLED); + if (shader == nullptr) { + return nullptr; + } + + bNodeSocket *in_socket = (bNodeSocket *)BLI_findlink(&shader->inputs, BC_PBR_DIFFUSE); + if (in_socket == nullptr) { + return nullptr; + } + + bNodeLink *link = in_socket->link; + if (link == nullptr) { + return nullptr; + } + + bNode *texture = link->fromnode; + if (texture == nullptr) { + return nullptr; + } + + if (texture->type != SH_NODE_TEX_IMAGE) { + return nullptr; + } + + Image *image = (Image *)texture->id; + return image; } static bNodeSocket *set_color(bNode *node, COLLADAFW::Color col) { - bNodeSocket *socket = (bNodeSocket *)BLI_findlink(&node->outputs, 0); - float *fcol = (float *)socket->default_value; - fcol[0] = col.getRed(); - fcol[1] = col.getGreen(); - fcol[2] = col.getBlue(); + bNodeSocket *socket = (bNodeSocket *)BLI_findlink(&node->outputs, 0); + float *fcol = (float *)socket->default_value; + fcol[0] = col.getRed(); + fcol[1] = col.getGreen(); + fcol[2] = col.getBlue(); - return socket; + return socket; } void MaterialNode::set_ambient(COLLADAFW::ColorOrTexture &cot, std::string label) { - int locy = -300 * (node_map.size() - 2); - if (cot.isColor()) { - COLLADAFW::Color col = cot.getColor(); - bNode *node = add_node(SH_NODE_RGB, -300, locy, label); - set_color(node, col); - // TODO: Connect node - } - // texture - else if (cot.isTexture()) { - add_texture_node(cot, -300, locy, label); - // TODO: Connect node - } + int locy = -300 * (node_map.size() - 2); + if (cot.isColor()) { + COLLADAFW::Color col = cot.getColor(); + bNode *node = add_node(SH_NODE_RGB, -300, locy, label); + set_color(node, col); + // TODO: Connect node + } + // texture + else if (cot.isTexture()) { + add_texture_node(cot, -300, locy, label); + // TODO: Connect node + } } void MaterialNode::set_reflective(COLLADAFW::ColorOrTexture &cot, std::string label) { - int locy = -300 * (node_map.size() - 2); - if (cot.isColor()) { - COLLADAFW::Color col = cot.getColor(); - bNode *node = add_node(SH_NODE_RGB, -300, locy, label); - set_color(node, col); - // TODO: Connect node - } - // texture - else if (cot.isTexture()) { - add_texture_node(cot, -300, locy, label); - // TODO: Connect node - } + int locy = -300 * (node_map.size() - 2); + if (cot.isColor()) { + COLLADAFW::Color col = cot.getColor(); + bNode *node = add_node(SH_NODE_RGB, -300, locy, label); + set_color(node, col); + // TODO: Connect node + } + // texture + else if (cot.isTexture()) { + add_texture_node(cot, -300, locy, label); + // TODO: Connect node + } } void MaterialNode::set_emission(COLLADAFW::ColorOrTexture &cot, std::string label) { - int locy = -300 * (node_map.size() - 2); - if (cot.isColor()) { - COLLADAFW::Color col = cot.getColor(); - bNode *node = add_node(SH_NODE_RGB, -300, locy, label); - set_color(node, col); - // TODO: Connect node - } - // texture - else if (cot.isTexture()) { - add_texture_node(cot, -300, locy, label); - // TODO: Connect node - } + int locy = -300 * (node_map.size() - 2); + if (cot.isColor()) { + COLLADAFW::Color col = cot.getColor(); + bNode *node = add_node(SH_NODE_RGB, -300, locy, label); + set_color(node, col); + // TODO: Connect node + } + // texture + else if (cot.isTexture()) { + add_texture_node(cot, -300, locy, label); + // TODO: Connect node + } } void MaterialNode::set_opacity(COLLADAFW::ColorOrTexture &cot, std::string label) { - if (effect == nullptr) { - return; - } - - int locy = -300 * (node_map.size() - 2); - if (cot.isColor()) { - COLLADAFW::Color col = effect->getTransparent().getColor(); - float alpha = effect->getTransparency().getFloatValue(); - - if (col.isValid()) { - alpha *= col.getAlpha(); // Assuming A_ONE opaque mode - } - if (col.isValid() || alpha < 1.0) { - // not sure what to do here - } - - bNode *node = add_node(SH_NODE_RGB, -300, locy, label); - set_color(node, col); - // TODO: Connect node - } - // texture - else if (cot.isTexture()) { - add_texture_node(cot, -300, locy, label); - // TODO: Connect node - } + if (effect == nullptr) { + return; + } + + int locy = -300 * (node_map.size() - 2); + if (cot.isColor()) { + COLLADAFW::Color col = effect->getTransparent().getColor(); + float alpha = effect->getTransparency().getFloatValue(); + + if (col.isValid()) { + alpha *= col.getAlpha(); // Assuming A_ONE opaque mode + } + if (col.isValid() || alpha < 1.0) { + // not sure what to do here + } + + bNode *node = add_node(SH_NODE_RGB, -300, locy, label); + set_color(node, col); + // TODO: Connect node + } + // texture + else if (cot.isTexture()) { + add_texture_node(cot, -300, locy, label); + // TODO: Connect node + } } void MaterialNode::set_specular(COLLADAFW::ColorOrTexture &cot, std::string label) { - int locy = -300 * (node_map.size() - 2); - if (cot.isColor()) { - COLLADAFW::Color col = cot.getColor(); - material->specr = col.getRed(); - material->specg = col.getGreen(); - material->specb = col.getBlue(); - - bNode *node = add_node(SH_NODE_RGB, -300, locy, label); - set_color(node, col); - // TODO: Connect node - } - // texture - else if (cot.isTexture()) { - add_texture_node(cot, -300, locy, label); - // TODO: Connect node - } + int locy = -300 * (node_map.size() - 2); + if (cot.isColor()) { + COLLADAFW::Color col = cot.getColor(); + material->specr = col.getRed(); + material->specg = col.getGreen(); + material->specb = col.getBlue(); + + bNode *node = add_node(SH_NODE_RGB, -300, locy, label); + set_color(node, col); + // TODO: Connect node + } + // texture + else if (cot.isTexture()) { + add_texture_node(cot, -300, locy, label); + // TODO: Connect node + } } -bNode *MaterialNode::add_texture_node(COLLADAFW::ColorOrTexture &cot, int locx, int locy, std::string label) +bNode *MaterialNode::add_texture_node(COLLADAFW::ColorOrTexture &cot, + int locx, + int locy, + std::string label) { - if (effect == nullptr) { - return nullptr; - } - - UidImageMap &image_map = *uid_image_map; + if (effect == nullptr) { + return nullptr; + } - COLLADAFW::Texture ctex = cot.getTexture(); + UidImageMap &image_map = *uid_image_map; - COLLADAFW::SamplerPointerArray& samp_array = effect->getSamplerPointerArray(); - COLLADAFW::Sampler *sampler = samp_array[ctex.getSamplerId()]; + COLLADAFW::Texture ctex = cot.getTexture(); - const COLLADAFW::UniqueId& ima_uid = sampler->getSourceImage(); + COLLADAFW::SamplerPointerArray &samp_array = effect->getSamplerPointerArray(); + COLLADAFW::Sampler *sampler = samp_array[ctex.getSamplerId()]; - if (image_map.find(ima_uid) == image_map.end()) { - fprintf(stderr, "Couldn't find an image by UID.\n"); - return NULL; - } + const COLLADAFW::UniqueId &ima_uid = sampler->getSourceImage(); - Image *ima = image_map[ima_uid]; - bNode *texture_node = add_node(SH_NODE_TEX_IMAGE, locx, locy, label); - texture_node->id = &ima->id; - return texture_node; + if (image_map.find(ima_uid) == image_map.end()) { + fprintf(stderr, "Couldn't find an image by UID.\n"); + return NULL; + } + Image *ima = image_map[ima_uid]; + bNode *texture_node = add_node(SH_NODE_TEX_IMAGE, locx, locy, label); + texture_node->id = &ima->id; + return texture_node; } |