20 : mContext(
C),
material(ma), effect(nullptr), key_image_map(&key_image_map)
22 bNodeTree *new_ntree = prepare_material_nodetree();
27 add_link(shader_node, 0, output_node, 0);
32 COLLADAFW::EffectCommon *ef,
35 : mContext(
C),
material(ma), effect(ef), uid_image_map(&uid_image_map)
37 prepare_material_nodetree();
40 std::map<std::string, bNode *> nmap;
50 add_link(ntree, nmap[
"emission"], 0, nmap[
"add"], 0);
51 add_link(ntree, nmap[
"main"], 0, nmap[
"add"], 1);
52 add_link(ntree, nmap[
"add"], 0, nmap[
"mix"], 1);
53 add_link(ntree, nmap[
"transparent"], 0, nmap[
"mix"], 2);
55 add_link(ntree, nmap[
"mix"], 0, nmap[
"out"], 0);
57 make_group(
C, ntree, nmap);
61 add_link(shader_node, 0, output_node, 0);
65 void MaterialNode::setShaderType()
73 if (
shader == COLLADAFW::EffectCommon::SHADER_BLINN) {
74 ma->spec_shader = MA_SPEC_BLINN;
75 ma->spec = ef->getShininess().getFloatValue();
78 else if (
shader == COLLADAFW::EffectCommon::SHADER_PHONG) {
79 ma->spec_shader = MA_SPEC_PHONG;
80 ma->har = ef->getShininess().getFloatValue();
83 else if (
shader == COLLADAFW::EffectCommon::SHADER_LAMBERT) {
84 ma->diff_shader = MA_DIFF_LAMBERT;
88 ma->diff_shader = MA_DIFF_LAMBERT;
89 fprintf(stderr,
"Current shader type is not supported, default to lambert.\n");
95 bNodeTree *MaterialNode::prepare_material_nodetree()
113 bNode *MaterialNode::add_node(
int node_type,
int locx,
int locy, std::string
label)
117 if (
label.length() > 0) {
128 void MaterialNode::add_link(
bNode *from_node,
int from_index,
bNode *to_node,
int to_index)
133 nodeAddLink(ntree, from_node, from_socket, to_node, to_socket);
138 float reflectivity = val.getFloatValue();
139 if (reflectivity >= 0) {
160 float ior = val.getFloatValue();
163 "IOR of negative value is not allowed for materials (using Blender default value "
173 COLLADAFW::ColorOrTexture &cot,
174 COLLADAFW::FloatOrParam &val)
180 if (effect ==
nullptr) {
184 if (cot.isColor() || !cot.isValid()) {
187 float transparent_alpha;
190 transparent_alpha =
col.getAlpha();
194 transparent_alpha = 1;
197 float transparency_alpha = val.getFloatValue();
198 if (transparency_alpha < 0) {
200 transparency_alpha = 1;
203 float alpha = transparent_alpha * transparency_alpha;
204 if (mode == COLLADAFW::EffectCommon::RGB_ZERO) {
212 else if (cot.isTexture()) {
213 int locy = -300 * (node_map.size() - 2);
214 add_texture_node(cot, -300, locy,
"Alpha");
220 int locy = -300 * (node_map.size() - 2);
226 fcol[0] = material->
r =
col.getRed();
227 fcol[1] = material->
g =
col.getGreen();
228 fcol[2] = material->
b =
col.getBlue();
229 fcol[3] = material->
a =
col.getAlpha();
231 else if (cot.isTexture()) {
232 bNode *texture_node = add_texture_node(cot, -300, locy,
"Base Color");
233 if (texture_node !=
nullptr) {
234 add_link(texture_node, 0, shader_node, 0);
247 if (in_socket ==
nullptr) {
252 if (link ==
nullptr) {
273 fcol[0] =
col.getRed();
274 fcol[1] =
col.getGreen();
275 fcol[2] =
col.getBlue();
282 int locy = -300 * (node_map.size() - 2);
290 else if (cot.isTexture()) {
291 add_texture_node(cot, -300, locy,
"Ambient");
298 int locy = -300 * (node_map.size() - 2);
306 else if (cot.isTexture()) {
307 add_texture_node(cot, -300, locy,
"Reflective");
314 int locy = -300 * (node_map.size() - 2);
320 fcol[0] =
col.getRed();
321 fcol[1] =
col.getGreen();
322 fcol[2] =
col.getBlue();
323 fcol[3] =
col.getAlpha();
326 else if (cot.isTexture()) {
327 bNode *texture_node = add_texture_node(cot, -300, locy,
"Emission");
328 if (texture_node !=
nullptr) {
329 add_link(texture_node, 0, shader_node, 0);
341 if (effect ==
nullptr) {
345 int locy = -300 * (node_map.size() - 2);
348 float alpha = effect->getTransparency().getFloatValue();
358 else if (cot.isTexture()) {
359 add_texture_node(cot, -300, locy,
"Alpha");
366 int locy = -300 * (node_map.size() - 2);
374 else if (cot.isTexture()) {
375 add_texture_node(cot, -300, locy,
"Specular");
380 bNode *MaterialNode::add_texture_node(COLLADAFW::ColorOrTexture &cot,
385 if (effect ==
nullptr) {
393 COLLADAFW::SamplerPointerArray &samp_array = effect->getSamplerPointerArray();
394 COLLADAFW::Sampler *sampler = samp_array[ctex.getSamplerId()];
396 const COLLADAFW::UniqueId &ima_uid = sampler->getSourceImage();
398 if (image_map.find(ima_uid) == image_map.end()) {
399 fprintf(stderr,
"Couldn't find an image by UID.\n");
403 Image *ima = image_map[ima_uid];
405 texture_node->
id = &ima->
id;
struct Main * CTX_data_main(const bContext *C)
#define SH_NODE_MIX_SHADER
struct bNode * ntreeFindType(const struct bNodeTree *ntree, int type)
#define SH_NODE_BSDF_PRINCIPLED
void ntreeUpdateTree(struct Main *main, struct bNodeTree *ntree)
struct bNodeLink * nodeAddLink(struct bNodeTree *ntree, struct bNode *fromnode, struct bNodeSocket *fromsock, struct bNode *tonode, struct bNodeSocket *tosock)
struct bNodeSocket * nodeFindSocket(const struct bNode *node, eNodeSocketInOut in_out, const char *identifier)
struct bNodeTree * ntreeAddTree(struct Main *bmain, const char *name, const char *idname)
struct bNode * nodeAddStaticNode(const struct bContext *C, struct bNodeTree *ntree, int type)
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
static bNodeSocket * set_color(bNode *node, COLLADAFW::Color col)
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer SH_NODE_ADD_SHADER
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Texture
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction SH_NODE_BSDF_TRANSPARENT
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Color
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume SH_NODE_TEX_IMAGE
Group RGB to Bright Vector Camera Vector Combine SH_NODE_OUTPUT_MATERIAL
void set_reflectivity(COLLADAFW::FloatOrParam &val)
void set_shininess(COLLADAFW::FloatOrParam &val)
void set_specular(COLLADAFW::ColorOrTexture &cot)
void update_material_nodetree()
void set_ior(COLLADAFW::FloatOrParam &val)
void set_reflective(COLLADAFW::ColorOrTexture &cot)
void set_emission(COLLADAFW::ColorOrTexture &cot)
Image * get_diffuse_image()
MaterialNode(bContext *C, COLLADAFW::EffectCommon *ef, Material *ma, UidImageMap &uid_image_map)
void set_opacity(COLLADAFW::ColorOrTexture &cot)
void set_alpha(COLLADAFW::EffectCommon::OpaqueMode mode, COLLADAFW::ColorOrTexture &cot, COLLADAFW::FloatOrParam &val)
void set_diffuse(COLLADAFW::ColorOrTexture &cot)
void set_ambient(COLLADAFW::ColorOrTexture &cot)
std::map< std::string, Image * > KeyImageMap
std::map< COLLADAFW::UniqueId, Image * > UidImageMap
static CCL_NAMESPACE_BEGIN const double alpha
void KERNEL_FUNCTION_FULL_NAME() shader(KernelGlobals *kg, uint4 *input, float4 *output, int type, int filter, int i, int offset, int sample)
static const pxr::TfToken roughness("roughness", pxr::TfToken::Immortal)
struct bNodeTree * nodetree