Component Mask Parameters in Functions and Custom Nodes

I’m trying to use an iterative parallax system that allows users to specify the channel of a texture to use for an iterative parallax function. Unfortunately, a few issues have come up trying to do this. In order to specify a channel (and simplify rendering), a static component mask parameter needs to be implemented inside a material function. So users will plug in a texture object, and in a material instance specify which channel from that texture object they wish to use. There is no other way to simplify this type of rendering. Unfortunately, component mask parameters don’t seem to work inside functions. I tried using a mask function with custom nodes, this time the parameter is located outside the function, and it doesn’t seem to work with custom nodes either. So, between UE4 nodes and custom nodes, the component mask parameter doesn’t work with material nodes or custom nodes.

At the moment I have a hacky workaround that involves appending and multiplying the entire 4-channels of the texture by a user-specified 4-vector, then breaking that and adding the results together convert it to a 1-vector. But all of these instructions must be repeated every time another sample pass is added. So, I have 174 instructions for a shader that should only cost 159, an extra 15 wasted instructions, or 3 per sample, that don’t need to happen. And the displacement channel is the only one that requires a 4-vector channel instead of a simple mask.

Help me, please!