Книга: The Cycles Encyclopedia 1.4
Назад: Chapter 8: Converter Nodes (N)
Дальше: Chapter 10: Group (G)

Chapter 9: Script (R)

Script (S)

Node_Script.jpg

This category only contains one node, since the script itself is so versatile that all your options will be included in the script you provide anyways.

The language that script nodes understand in Cycles is called OSL, which stands for Open Shading Language. As of now, to get this node to actually do anything, you first have to switch to CPU rendering and then enable the Open Shading Language checkbox, both in the in the properties panel.

It is probably easier to write or copy/paste your script inside the Blender Text Editor, but if you have to deal with changing versions or share your shader and similar cases, you can also use external script files, the file extension does not matter, but as a habit you might want to use .osl.

Once you have created your script, you can use this node to compile it which will then specify the required in- and the possible outputs.

If eventual changes do not get updated, use the refresh button.

To get a demonstration of how to use the script node, here is the code for an OSL shader that will create an add node with two factor inputs. Copy and paste it into Blender's text editor to use it with the “internal” option of the script node or save it as a text file with the ending .osl to use it with the “external” option:

#include "stdosl.h"

shader node_addvanced(

float Fac1 = 0.5,

closure color Closure1 = 0,

float Fac2 = 0.5,

closure color Closure2 = 0,

output closure color Closure = 0)

{

Closure = Fac1*Closure1 + Fac2*Closure2;

}

Script_add_shader.jpg

If you add a new text in the text editor, paste this text and name it e.g. MyShader, you can select it in a script node.

The script will be compiled automatically and the node will receive the inputs and outputs that are defined in the script and can be used in any Cycles node tree as long as Open Shading Language and CPU rendering are activated.


Назад: Chapter 8: Converter Nodes (N)
Дальше: Chapter 10: Group (G)