Featured post

new redirect for blender.org bpy docs.

http://www.blender.org/api/blender_python_api_current/ As of 10/11 november 2015 we can now link to the current api docs and not be worr...

October 01, 2012

Scripting Cycles Shaders - return of the time wasters.

I wanted a way to carry a shader inside a pyfile, to keep this self contained. This will be a pretty crazy example of how to script a shader from scratch. Writing a script that converts an existing shader node_tree ( material ) is possible and could be written with a cascading recursion into the node_tree.

As soon as the shader starts to get complicated it's probably best to use a .blend and append materials from it instead.

4 comments:

  1. interesting...I need something similar: I need to replace all nodes of one material with all nodes of another material via script, simply I am trying to replace all materials that I decide to replace with materials linked from another .blend file but having name of old material (eg replacing its data only not break any links to actual users of the material), but all I tried did not work. I was successful up to linking needed materials to my project but when I try simply copy/paste or assigning one material to another (like in a way of "thisMaterial = thatMaterial", or "thisMaterial = thatMaterial.paste()" etc.) I always end up in error... Then I thought that maybe simple replacing nodes would be much easier but I do not know how to via script and just now find this site which is the closest to what I am searching for. See I do not want to iterate thru all objects and when find some having my material assigned to it just replace it, rather I want to replace material on the upper level in materials itself (if something like that is possible at all?) so that the name of the old material would stay the same and just the data (its nodes) would change: is this even possible and if so how? btw: I am using Blender v2.70.5

    ReplyDelete
  2. Hi Kapela thanks for your question! I suspect you will get a more informed answer if you use that Last sentence as a Question on Blender.StackExchange.com -- there's a lot more people with experience of this kind on there. I could try, but don't have time.

    ReplyDelete
    Replies
    1. yea, thanx for replay...I am already registered there and I put my question there also ;)

      Delete
  3. I Like! I currently code shaders for Poser in a script tool called 'Matmatic' by Bagginsbill: his script essentially exposes Poser Pro 2014's nodes to Python so that you can create elaborate shaders for an entire figure.
    Fun. But very useful, since - as you said - it's all very self-contained and, even better, it's Python: what's not to like!
    So, what I see here is exactly what I was looking for: a way to script an entire node tree for, say, a discrete figure (skin and eyes and nails and.and.and) or architecture prop or whatever, having numerous material zones, and then just apply? No? This is the intended application, right?
    If I want to render a scene created in Poser in Cycles, the most tedious part of the process is the manual assigning of shaders to different mat zones. A script could do that so efficiently, so fast.

    ReplyDelete

Please use Blender.StackExchange.com for python scripting questions unrelated to this post.