How to use a material function with a channel-packed texture?

I’m probably missing something really obvious here, but how can you use a channel packed texture with a material function that has a texture input?

It seems like it’s only possible to have a texture input for a material function be Texture2D, so you can’t take a TextureSample node and plug the red channel into it, for example.

But if I use a Texture Object, which does plug into the input of a material function, then I cannot extract a single channel from it, as far as I can tell.

This basically makes it impossible to use material functions and channel packed textures in the same material, which seems wrong.

Use the “ComponentMask” Node to filter a single channel

You can’t use ComponentMask on a TextureObject. And you can’t use the output of a ComponentMask (used on a Texture Sampler) as an input for a material function with a texture input.

You need to connect your TextureObject output into the Tex input of a TextureSample node.

I don’t understand how that helps…?

Let me explain it a different way:

  1. I have a channel-packed texture with different greyscale textures in each RGB channel.
  2. 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.
  3. 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).

It is something conceptual actually.

This is what I have told:
[SPOILER]


[/SPOILER]

that material function does the same thing:

[SPOILER]

[/SPOILER]

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.

It would also help more, if we could understand what you want to do with that single channel you want from the packaged texture.

Ah, OK.

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).

As I said, you can easily use the packed texture and put a ComponentMask AFTER the Function. Nothing that hard about it.

1 Like

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.

that’s not what I’m trying to do. I’m trying to pass a particular channel of a texture into a material function.

Make a copy of your material function and modify the function after the Texture Sample (pic1).

The function in a material (pic2).

Hope that helps.

1 Like

Not possible. Simple as that. You need to sample the whole texture to grab a single channel from it.

the best way is to copy-modify the material function so that it uses the channel that you need

some of the Epic functions do it in a way similar to what zombiethatatehimself shows, but adding a dot product simply to select a channel means making your material more complex just for convenience

Realised the post is rather old however…

This is what I was trying to wrap my head around - Quixel bridge offer up ORD images that cover Occlusion, roughness and displacement in one texture, the blue channel being displacement - I’m trying to utilise just that blue channel so I can feed it in to the parallax function but it only accepts Parameter texture objects. I’m trying to give the team flexibility in future so they can use both, no idea what I can use to ‘convert’ it to somthing it can read.

I also get why wanting to ‘rasterise’ one of the channels would be contrary to what the engine is trying to achieve and would be a performance hit however I’m producing static path tracer renders so not really an issue.