Advertisement

You're blocking ads, which pay for BlenderNation. Read about other ways to support us.

The Shader Library - Python Scripting Tutorial

0

Darkfall writes:

In this video we will create a Shader Addon for the Node/Shader Editor.

This Add-on was created as a result from the tutorial and is not meant to be anything other than to demonstrate how it's possible but if you want to download the script you can find the link in our blog. If you guys like it, I could look at developing it further but keep in mind that there are probably better Add-ons like this already!.

Using the knowledge from the previous videos and utilizing the template scripts, we can quickly create a Main Panel and add some bl_info, (Remember without the bl_info we can not install our add-on from file).

In the previous videos, we have been using Operations that are readily available, though in this example there are no functions that will create the Shaders that we want. We have to create a custom Operator and then define (with python) what nodes we want to add to our Shader. We also need to then connect (or link as it's actually known) the nodes together.

I find it a good idea to add and arrange the nodes in a separate window as I write the code. It helps me keep track of what nodes I have added and it also lets me see how I need to link the nodes. Alternatively, I would suggest writing down the Nodes you want to use before hand.

If you find moving the Nodes around pain, this may help.

The '.location' parameter will move your node anywhere you want but knowing which set of numbers will move it, Horizontally or Vertically is a bit of trial and error at first.

(-200, -90) - The numbers on the left will move the node to the Left or Right. The numbers on the right will move the node Up or Down. So if we imagine that the center of the screen 0, if we want to move the Emission node to the Left we would type (-200,0). If we want the Node to move to the right we would type (200,0).

Using that logic, to move up would be (0,200), and down would be (0.-200)

For this Example, I start by creating a Diamond Shader. It doesn't matter what kind of Shader you want to create, the process is always the same.

Once we have finished writing our custom Operator, we need to make sure we register and unregister all classes and then add the button (on the Main Panel) to call the custom operator

Adding new Shaders becomes much easier since we can use the first Custom Operator as a template. We can copy and paste most of the code we have just written and then go through and change the appropriate details.

I decided to add a few Shaders that I thought were interesting and there are hundreds of different Shaders we could create.

I hope you guys find this video helpful and as always, thanks for Reading!.

About the Author

Avatar image for John Brook
John Brook

I make Youtube tutorials for blender Users. From CG and VFX to Animations, Shorts and Asset Creation. I upload tutorials once a week along with any assets we create for you to use in your own projects.

Leave A Reply

To add a profile picture to your message, register your email address with Gravatar.com. To protect your email address, create an account on BlenderNation and log in when posting a message.

Advertisement

×