I have a channel-packed texture with different greyscale textures in each RGB channel.
I have a material function which has a texture input. As far as I can tell, you can only have a Texture2D (ie. TextureObject) as an input for a material function, you cannot have a TextureSample.
I want to feed just the red channel from my texture into this material function.
In the material with the texture and the material function I could either:
(a) Have the texture as a TextureObject, which I can connect to the material function, but cannot use a ComponentMask to only get the red channel - the whole texture and all its channels are passed into the material function.
(b) Have the texture as a TextureSample where I can either use a ComponentMask or just drag straight off the red channel to get the part of the texture I want, but I cannot connect this to a material function. It says ‘Float is not compatible with Texture2D’.
What I need is to be able to convert one channel of a texture into a Texture2D. It seems crazy you can’t do this. But maybe I’m misunderstanding what you’re suggesting?
No you can’t do the way you want, because after the channel it is not a Texture (texture object stands for the whole texture) anymore but a sampled portion of the texture at specific UV position (so not the whole texture).
What you can do if you want to isolate the texture stored in that channel is to draw a material selecting the red channel (or any other) and use the material in a blueprint callind DrawMaterialToRenderTarget and use the render target right-clicking on it and choosing Save As to create a copy of the texture now stored into the render target.
Basically what I want to be able to do is just use a material function on any arbitrary channel of a texture. I am texture packing greyscale mask textures, and wanting to do stuff with them. And I might want to use the material function with the R, G, B or A channel, it depends. If it was always consistently just the red channel, then I could easily make the material function extract just the red channel in a way similar to what you’re suggesting.
I think the only option really is to just copy-paste the contents of the material function into whichever materials I want to use it in.
You are right, usually if you are going to use a ready to use material function accepting a T2D you will need to rewrite it in order to be able to have the functionality and apply it to a packaged texture. Note that the compression used for each channel is different, so there are few possibilities on what you can put on each channel. Usual packaged texture place Roughness in the red channel, Metallic or Height in the green channel, AO in the blue channel and sometimes Height on the Alpha channel, therefore the packaged texture receive the names: RMAH (packaged in 4 channel) or RHAO (packaged in 3 channel).
The very point in confusion people starting on UE does when dealing with textures is because the way the nodes are used. For them TextureObject and TextureSample seems the same (you can select a texture asset at both), while they are not. The TextureObject Node is just an alias for the texture itself (the whole asset thing) while the TextureSample node actually is a processing node, which takes the inputs texture and uv and then sample the texture at that uv coord in the outputs RBG, R, G, B and alpha. I would rename the name from TextureSample to TextureSampler to clarify it a little more.
If one needs to use packaged textures with the built-in functions in Unreal which takes T2D as input, the best thing to do is to recreate those functions and inside use the channel where the target portion of the texture is to be handled in order to make it work ok.