Referencing material functions from inside a custom expression

So far I have had to ‘inline’ the function into the custom node as hlsl code to get this to work. The reason is that the final hlsl code will simply call your function with the ‘inputs’ as simple variables that have already been processed. So there is no interface to tell the ‘input variables’ to re-evaluate from a different position (it would need to understand expression inputs for this to work I think).

Martin Mittring did something for volumetric decals to allow you to specify external input for raytracing. I am not sure what he did there but I have been meaning to find out.

FWIW, if you are having trouble converting material nodes to hlsl code, you can always build a small separate material and hook it up to emissive and then open up the preview HLSL code window and find/copy the area under emissive. In that way sometimes you can get some compiler optimizations as well.