If you prefer code to diagrammatic blocks, you're in luck. You can write your own HLSL code to deploy to the GPU for the shading of some vertices in your project. We can construct Custom nodes that simply contain math code working on named variables to perform some generic computation. In this recipe, we'll write a custom math function to work with.
You need a material shader, and a general mathematical function to implement. As an example, we'll write a Custom node that returns the square of all inputs.
In order to create a custom material expression, simply right-click anywhere on the canvas, and select Custom.
With your new Custom block selected, go to the Details panel on the left side of your Material Editor window (choose Window | Details if your Details panel is not displayed).
Under Description, name your Custom block. For example,
Square3
, because we plan to square three float inputs and return afloat3
.Click the + icon as many...