[Bf-cycles] Any sample on creating basic materials from scratch?

Brecht Van Lommel brechtvanlommel at pandora.be
Thu Feb 22 16:37:51 CET 2018


You need to provide tangent vectors (ATTR_STD_UV_TANGENT). Cycles does not
compute them automatically. Usually these are exported from the 3D host app.

At some point we might support computing them inside Cycles, though there's
no a single standard so usually it's best to get them from the host app or
file to be exactly compatible.

On Thu, Feb 22, 2018 at 2:30 PM, F Escobar <materialesescobar at hotmail.es>
wrote:

> Oh I think I'll never end with this :S
>
> Now it looks that I'm having a problem with the normal maps, if I apply
> them my mesh renders black, obviously I've created a NormalMapNode that is
> connected in the between the texture and the Bsdf, I think that it could be
> related to the mesh tangents since if I apply the normalmap in other space
> that is not Tangent mode it renders wrong but it renders, in tangent mode
> it renders totally black.
>
> Any tip on this?
> ------------------------------
> *De:* Mohamed Sakr <3dsakr at gmail.com>
> *Enviado:* miércoles, 21 de febrero de 2018 17:51
> *Para:* F Escobar
> *Asunto:* Re: [Bf-cycles] Any sample on creating basic materials from
> scratch?
>
> ah, I thought you did this already :) (it is done in Cycles standalone
> already at the end).
>
> On Wed, Feb 21, 2018 at 4:41 PM, F Escobar <materialesescobar at hotmail.es>
> wrote:
>
> Oh!
> shader->tag_update(scene);
> was the solution it was properly set all this time but not updated!!!
> ------------------------------
> *De:* Bf-cycles <bf-cycles-bounces at blender.org> en nombre de F Escobar <
> materialesescobar at hotmail.es>
> *Enviado:* miércoles, 21 de febrero de 2018 15:23
> *Para:* Mohamed Sakr; Discussion list to assist Cycles render engine
> developers
>
> *Asunto:* Re: [Bf-cycles] Any sample on creating basic materials from
> scratch?
>
> Unfortunatly your first implementation is almost identical to my own
> method (now I tried without giving a name as you did) but it didn't work.
>
> Thank you anyway.
> ------------------------------
> *De:* Bf-cycles <bf-cycles-bounces at blender.org> en nombre de Mohamed Sakr
> <3dsakr at gmail.com>
> *Enviado:* miércoles, 21 de febrero de 2018 14:43
> *Para:* Discussion list to assist Cycles render engine developers
> *Asunto:* Re: [Bf-cycles] Any sample on creating basic materials from
> scratch?
>
> here is how it is done:
> Attribute *attr_UV = attributes.add(ATTR_STD_UV);
> UVMapNode* uvmap = new UVMapNode();
> uvmap->attribute = ustring("");
>
> this is per corner not per face or per vertex.
> here is how I modify them in custom attributes: (per vertex for example):
> Attribute * attr_UV = attributes.add(ustring("your uv custom name"),
> TypeDesc::TypeVector, ATTR_ELEMENT_VERTEX);
> UVMapNode* uvmap = new UVMapNode();
> uvmap->attribute = ustring(" your uv custom name ");
>
> in that case you do it per vertex, so your iteration must be on (points)
> not on (faces * 3)
>
>
> On Wed, Feb 21, 2018 at 3:36 PM, Mohamed Sakr <3dsakr at gmail.com> wrote:
>
> sorry my previous reply is wrong, what you do is already correct for the
> iteration, got confused here.
>
>
> On Wed, Feb 21, 2018 at 3:18 PM, Mohamed Sakr <3dsakr at gmail.com> wrote:
>
> for (int f = 0; f < facecount; f++)
> {
> for (int i = 0; i < 3; i++) //al faces are tris
> {
> attr_data_uv[uv*3 + i].x = 1.0;
> attr_data_uv[uv*3 + i].y = float(f) / 20.0f;
> attr_data_uv[uv*3 + i].z = 0.0;
>
> //correct
> uv++;
> }
> uv++; // <<<<<wrong , should be inside the inner loop of i
> }
>
> On Wed, Feb 21, 2018 at 1:12 PM, F Escobar <materialesescobar at hotmail.es>
> wrote:
>
> I didn't manage to make this working yet
>
> * UVs are per face corner by default, verify that you are doing that or
> switch to ATTR_ELEMENT_VERTEX.
> I'm creating it per face, probably in the future I'll move to ATTR_ELEMENT_VERTEX
> but it is easier to keep in the simplified method for now.
>
> * Adding some random value like 0.12345 to all UV coordinates to see if
> they are having an effect at all.
> Unfortunatly I had no luck with this.
>
> * Create just an UVMapNode and output that directly, to see if the UV
> coordinates are getting loaded.
> ccl::UVMapNode *uvnode = new ccl::UVMapNode();
> uvnode->attribute = ccl::ustring("UVMap");
> graph->add(uvnode);
> graph->connect(uvnode->output("UV"), bsdf->input("Color"));
>
> I tried that but it is always black (I assume that it means 0 0 ), notice
> that if I connect a texture to bsdf->input("Color") it is rendered in a
> plain color (uvs are wrong) but the color is given by the texture so the
> shader looks ok.
>
>
>
> The mesh was created like this:
>
> ccl::Attribute *attr_uv = mesh->attributes.add(ccl::ATTR_STD_UV,
> ccl::ustring("UVMap"));
> ccl::float3 *attr_data_uv = attr_uv->data_float3();
> for (int f = 0; f < facecount; f++)
> {
> for (int i = 0; i < 3; i++) //al faces are tris
> {
> attr_data_uv[uv*3 + i].x = 1.0;
> attr_data_uv[uv*3 + i].y = float(f) / 20.0f;
> attr_data_uv[uv*3 + i].z = 0.0;
> }
> uv++;
> }
>
> I'm not sure if I missed any step.
>
> Thank you in advance
> ------------------------------
> *De:* brechtvanlommel at gmail.com <brechtvanlommel at gmail.com> en nombre de
> Brecht Van Lommel <brechtvanlommel at pandora.be>
> *Enviado:* martes, 13 de febrero de 2018 15:05
> *Para:* F Escobar
> *Cc:* Discussion list to assist Cycles render engine developers
> *Asunto:* Re: [Bf-cycles] Any sample on creating basic materials from
> scratch?
>
> The checker texture will not use UV coordinates by default, you'd need to
> link in a UVMapNode node for that. For the image texture node it should
> work though.
>
> It's not clear to me what is wrong. A few things you could try:
> * UVs are per face corner by default, verify that you are doing that or
> switch to ATTR_ELEMENT_VERTEX.
> * Adding some random value like 0.12345 to all UV coordinates to see if
> they are having an effect at all.
> * Create just an UVMapNode and output that directly, to see if the UV
> coordinates are getting loaded.
>
>
> On Tue, Feb 13, 2018 at 2:25 PM, F Escobar <materialesescobar at hotmail.es>
> wrote:
>
> Thank you it worked like a charm!
>
> I'm driving nuts with other issue now
>
> I've created my UVs with
>
> ccl::Attribute *attr_uv = mesh->attributes.add(ccl::ATTR_STD_UV,
> ccl::ustring("UV"));
> ccl::float3 *attr_data_uv = attr_uv->data_float3();
>
> Filled attr_data_uv and so, but I cannot see the checker only one plain
> color, same issue if I use a ImageTextureNode even if I set Tex->projection
> = ccl::NodeImageProjection::NODE_IMAGE_PROJ_BOX;
>
> Any tip on this?
> ------------------------------
> *De:* Bf-cycles <bf-cycles-bounces at blender.org> en nombre de Brecht Van
> Lommel <brechtvanlommel at pandora.be>
> *Enviado:* jueves, 8 de febrero de 2018 15:34
> *Para:* Discussion list to assist Cycles render engine developers
> *Asunto:* Re: [Bf-cycles] Any sample on creating basic materials from
> scratch?
>
> Hi,
>
> We don't have any example code for this specifically. It's easiest to
> create node with the corresponding class directly.
>
> CheckerTextureNode *checker = new CheckerTextureNode();
> checker->color1 = make_float3(1.0f, 0.0f, 0.0f);
> checker->color2 = make_float3(0.0f, 0.0f, 1.0f);
> checker->scale = 1.0f;
> graph->add(checker);
> shader->set_graph(graph);
>
> If you want to use the generic API, don't create your own SocketType,
> look it up in the node.
>
> const SocketType *color1 = snode->find_input(ustring("color1"));
> snode->set(*color1, make_float3(1.0f, 0.0f, 0.0f));
>
> Regards,
> Brecht.
>
>
> On Thu, Feb 8, 2018 at 2:13 PM, F Escobar <materialesescobar at hotmail.es>
> wrote:
>
> I tried with this:
>
>
>
> ccl::Shader *shader = new ccl::Shader();
>
> if (scene != NULL)
> scene->shaders.push_back(shader);
>
> shader->name=ccl::ustring(material->mName);
> ccl::ShaderGraph *graph = new ccl::ShaderGraph();
>
> const ccl::NodeType *node_type = ccl::NodeType::find(ccl::ustri
> ng("checker_texture"));
> if (!node_type) {
> fprintf(stderr, "Unknown shader node \n");
> }
> else if (node_type->type != ccl::NodeType::SHADER) {
> fprintf(stderr, "Node type \"%s\" is not a shader node.\n",
> node_type->name.c_str());
> }
>
> ccl::ShaderNode* snode = (ccl::ShaderNode*)node_type->create(node_type);
>
> ccl::SocketType color1;
> color1.type = ccl::SocketType::COLOR;
> color1.name = ccl::ustring("color1");
> snode->set(color1, ccl::make_float3(1.0f, 0.0f, 0.0f));
>
> ccl::SocketType color2;
> color2.type = ccl::SocketType::COLOR;
> color2.name = ccl::ustring("color2");
> snode->set(color2, ccl::make_float3(0.0f, 0.0f, 1.0f));
>
> ccl::SocketType scale;
> scale.type = ccl::SocketType::FLOAT;
> scale.name = ccl::ustring("scale");
> snode->set(scale, 1.0f);
>
> graph->add(snode);
> shader->set_graph(graph);
>
>
> But I had crashes creating color2 probably I'm doing it wrongly, is there
> any sample on this?
>
>
> Thank you in advance.
>
> _______________________________________________
> Bf-cycles mailing list
> Bf-cycles at blender.org
> https://lists.blender.org/mailman/listinfo/bf-cycles
>
>
>
>
> _______________________________________________
> Bf-cycles mailing list
> Bf-cycles at blender.org
> https://lists.blender.org/mailman/listinfo/bf-cycles
>
>
>
>
>
>
> _______________________________________________
> Bf-cycles mailing list
> Bf-cycles at blender.org
> https://lists.blender.org/mailman/listinfo/bf-cycles
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.blender.org/pipermail/bf-cycles/attachments/20180222/3ce3b1c8/attachment.html>


More information about the Bf-cycles mailing list