# 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?

**URL:** <https://forums.unrealengine.com/t/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/485092>\
**Category:** Asset Creation\
**Tags:** unreal-engine, blur, hlsl, shader, question\
**Created:** [June 19, 2021, 11:57am UTC](https://forums.unrealengine.com/t/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/485092 "2021-06-19T11:57:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sayooj\_js](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/sayooj_js/32/88714_2.png) [@sayooj\_js](https://forums.unrealengine.com/u/sayooj_js)\
**Post date:** [June 19, 2021, 11:57am UTC](https://forums.unrealengine.com/t/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/485092/1 "2021-06-19T11:57:30Z")

</div>

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

 ![341843-gaus-textureobject.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/3/4/234d7e7f12292f14315f7f735307ba279b8cfd9c.jpeg)

With TextureSample

 ![341842-gaus-sample.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/c/7/5c788eb4590917793d1f2920f5d256e8b34be368.jpeg)

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:

> **[Custom Expressions](https://docs.unrealengine.com/4.26/en-US/RenderingAndGraphics/Materials/ExpressionReference/Custom/)**
>
> Expressions that allow the use of custom, plain shader code.

---

<div class="post-metadata">

**Author:** ![Deathrey](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Deathrey](https://forums.unrealengine.com/u/Deathrey)\
**Post date:** [June 19, 2021, 4:24pm UTC](https://forums.unrealengine.com/t/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/485092/2 "2021-06-19T16:24:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sayooj\_js](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/sayooj_js/32/88714_2.png) [@sayooj\_js](https://forums.unrealengine.com/u/sayooj_js)\
**Post date:** [June 26, 2021, 6:43am UTC](https://forums.unrealengine.com/t/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/485092/3 "2021-06-26T06:43:43Z")

</div>

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.

 ![342444-mat-func.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/e/2/5e21052845829d8a5f1d230bf6c16d930c984183.jpeg)

In UE 4.25

 ![342445-mat2.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/8/4/08424a43b9b8f59af1c6b3ba06d4f1eafdd995ee.jpeg)

---

<div class="post-metadata">

**Author:** ![rit](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@rit](https://forums.unrealengine.com/u/rit)\
**Post date:** [November 23, 2024, 1:52pm UTC](https://forums.unrealengine.com/t/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/485092/4 "2024-11-23T13:52:09Z")

</div>

> [@sayooj\_js](#):
>
> omponent mask later the custom node w

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! 🙂
