8 : mContext(
C),
material(ma), effect(nullptr), key_image_map(&key_image_map)
10 bNodeTree *new_ntree = prepare_material_nodetree();
15 add_link(shader_node, 0, output_node, 0);
20 COLLADAFW::EffectCommon *ef,
23 : mContext(
C),
material(ma), effect(ef), uid_image_map(&uid_image_map)
25 prepare_material_nodetree();
28 std::map<std::string, bNode *> nmap;
38 add_link(ntree, nmap[
"emission"], 0, nmap[
"add"], 0);
39 add_link(ntree, nmap[
"main"], 0, nmap[
"add"], 1);
40 add_link(ntree, nmap[
"add"], 0, nmap[
"mix"], 1);
41 add_link(ntree, nmap[
"transparent"], 0, nmap[
"mix"], 2);
43 add_link(ntree, nmap[
"mix"], 0, nmap[
"out"], 0);
45 make_group(
C, ntree, nmap);
49 add_link(shader_node, 0, output_node, 0);
53 void MaterialNode::setShaderType()
61 if (shader == COLLADAFW::EffectCommon::SHADER_BLINN) {
62 ma->spec_shader = MA_SPEC_BLINN;
63 ma->spec = ef->getShininess().getFloatValue();
66 else if (shader == COLLADAFW::EffectCommon::SHADER_PHONG) {
67 ma->spec_shader = MA_SPEC_PHONG;
68 ma->har = ef->getShininess().getFloatValue();
71 else if (shader == COLLADAFW::EffectCommon::SHADER_LAMBERT) {
72 ma->diff_shader = MA_DIFF_LAMBERT;
76 ma->diff_shader = MA_DIFF_LAMBERT;
77 fprintf(stderr,
"Current shader type is not supported, default to lambert.\n");
82 bNodeTree *MaterialNode::prepare_material_nodetree()
100 bNode *MaterialNode::add_node(
int node_type,
int locx,
int locy, std::string
label)
104 if (
label.length() > 0) {
115 void MaterialNode::add_link(
bNode *from_node,
int from_index,
bNode *to_node,
int to_index)
120 nodeAddLink(ntree, from_node, from_socket, to_node, to_socket);
123 void MaterialNode::add_link(
bNode *from_node,
124 const char *from_label,
126 const char *to_label)
131 if (from_socket && to_socket) {
132 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);
222 if (cot.isTexture()) {
223 bNode *texture_node = add_texture_node(cot, -300, locy,
"Base Color");
224 if (texture_node !=
nullptr) {
225 add_link(texture_node, 0, shader_node, 0);
234 fcol[0] = material->
r =
col.getRed();
235 fcol[1] = material->
g =
col.getGreen();
236 fcol[2] = material->
b =
col.getBlue();
237 fcol[3] = material->
a =
col.getAlpha();
241 fcol[0] = material->
r = 0.0f;
242 fcol[1] = material->
g = 0.0f;
243 fcol[2] = material->
b = 0.0f;
244 fcol[3] = material->
a = 1.0f;
252 if (shader ==
nullptr) {
257 if (in_socket ==
nullptr) {
262 if (link ==
nullptr) {
267 if (texture ==
nullptr) {
283 fcol[0] =
col.getRed();
284 fcol[1] =
col.getGreen();
285 fcol[2] =
col.getBlue();
292 int locy = -300 * (node_map.size() - 2);
300 else if (cot.isTexture()) {
301 add_texture_node(cot, -300, locy,
"Ambient");
308 int locy = -300 * (node_map.size() - 2);
316 else if (cot.isTexture()) {
317 add_texture_node(cot, -300, locy,
"Reflective");
324 int locy = -300 * (node_map.size() - 2);
330 fcol[0] =
col.getRed();
331 fcol[1] =
col.getGreen();
332 fcol[2] =
col.getBlue();
333 fcol[3] =
col.getAlpha();
336 else if (cot.isTexture()) {
337 bNode *texture_node = add_texture_node(cot, -300, locy,
"Emission");
338 if (texture_node !=
nullptr) {
339 add_link(texture_node,
"Color", shader_node,
"Emission");
351 if (effect ==
nullptr) {
355 int locy = -300 * (node_map.size() - 2);
358 float alpha = effect->getTransparency().getFloatValue();
361 alpha *=
col.getAlpha();
368 else if (cot.isTexture()) {
369 add_texture_node(cot, -300, locy,
"Alpha");
376 bool has_specularity =
true;
377 int locy = -300 * (node_map.size() - 2);
381 if (
col.getRed() == 0 &&
col.getGreen() == 0 &&
col.getBlue() == 0) {
382 has_specularity =
false;
390 else if (cot.isTexture()) {
391 add_texture_node(cot, -300, locy,
"Specular");
396 has_specularity =
false;
399 if (!has_specularity) {
409 bNode *MaterialNode::add_texture_node(COLLADAFW::ColorOrTexture &cot,
414 if (effect ==
nullptr) {
422 COLLADAFW::SamplerPointerArray &samp_array = effect->getSamplerPointerArray();
423 COLLADAFW::Sampler *
sampler = samp_array[ctex.getSamplerId()];
425 const COLLADAFW::UniqueId &ima_uid =
sampler->getSourceImage();
427 if (image_map.find(ima_uid) == image_map.end()) {
428 fprintf(stderr,
"Couldn't find an image by UID.\n");
432 Image *ima = image_map[ima_uid];
434 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
#define SH_NODE_ADD_SHADER
#define SH_NODE_BSDF_TRANSPARENT
#define SH_NODE_OUTPUT_MATERIAL
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 BKE_ntree_update_main_tree(struct Main *bmain, struct bNodeTree *ntree, struct NodeTreeUpdateExtraParams *params)
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)
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between and object coordinate space Combine Create a color from its and value channels Color Retrieve a color or the default fallback if none is specified Separate Split a vector into its and Z components Generates normals with round corners and may slow down renders Vector Displace the surface along an arbitrary direction White Return a random value or color based on an input seed Float Map an input float to a curve and outputs a float value Separate Color
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Texture
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block SH_NODE_TEX_IMAGE
Group Output data from inside of a node group SH_NODE_RGB
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
depth_tx sampler(1, ImageType::FLOAT_2D, "combined_tx") .sampler(2
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img image(1, GPU_R32F, Qualifier::WRITE, ImageType::FLOAT_2D_ARRAY, "out_weight_img") .image(3
static const pxr::TfToken ior("ior", pxr::TfToken::Immortal)
static const pxr::TfToken roughness("roughness", pxr::TfToken::Immortal)
struct bNodeTree * nodetree