Code

From Shader Forge Wiki
Jump to: navigation, search

The code node allows you to input raw shader code into your graph. This can be extremely useful for functions which are not easy to implement with a graph based interface, or that use instructions and constructs not present in shader forge (DDX/DDY instructions, for loops, etc).


Note that the code node is new as of beta 0.28, and has a few bugs to be aware of:

- When you paste code into the window, it will add the letter to the end of the paste, and you'll have to manually delete it before the node will function - Likewise, cut and copy will replace your code with the key pressed (c or x). - The node will give you no error messages if the code in it does not compile. You will simply see the broken (pink) shader. Therefor, it's useful to develop this code in another environment before use. - Code nodes do not work with node previews. This is because Shader Forge computes it's node previews via C# code instead of the actual shader code. For previews, all code nodes output a value of 1.


Some snippets of code are provided below. To use them, simply copy and paste the code into the code node. Note that after you press control-v, the editor will place a v at the end of the code which will have to be removed; this bug will hopefully be fixed soon.

If the node takes inputs, you will need to add them and set their types correctly.

Procedural Noise

RGB to HSV to RGB Color Space conversion