How do i get Alpha from Texture object that I have passed into custom blur function? Or is it possible to use TextureSample instead Object?

I am relatively new in HLSL, I am trying to implement blur for my new dynamic shadow material project. I can input Texture Object, but not TextureSample, and getting an error, Is there is any other function for TextureSample? If not how do I get alpha from Texture Object? I am totally confused.

Error with TextureSample: error X3004: undeclared identifier 'TexSampler’

With Texture Object

With TextureSample

Source:

float3 blur = Texture2DSample(Tex, TexSampler, UV);

for (int i = 0; i < r; i++)
{

blur += Texture2DSample(Tex, TexSampler, UV + float2(i * dist, 0));

blur += Texture2DSample(Tex, TexSampler, UV - float2(i * dist, 0));

}

for (int j = 0; j < r; j++)
{

blur += Texture2DSample(Tex, TexSampler, UV + float2(0, j * dist));

blur += Texture2DSample(Tex, TexSampler, UV - float2(0, j * dist));

}

blur /= 2*(2*r)+1;

return blur;

Source reference:

Nope, can’t do that. Result of a texture sample is some kind of value per pixel. Texture object is just reference to a texture.

Solved! We can separate alpha from the custom node, indeed we cannot use the component mask with texture object on account it taking texture reference rather than per pixel value. There are two ways we can separate alpha either by using an alpha variable to pass the information into it (it would require UE 4.26.0 or newer versions on account of new functionality introduced for additional outputs) or use a component mask later the custom node without declaring a variable for alpha. I would suggest using the component mask as the result isn’t more expensive rather than using a variable in the script.

In UE 5.

In UE 4.25

2 Likes

Thank you so much for posting your solution!

I’ve been struggling with outputting alpha for texture blur for quite a while - I couldn’t have thought about simply changing the color input and output from float3 to float4 and masked it will solve the issue!

Thank you! :slight_smile: