# HLSL(.fx) to UE4 Material - porting advice?

**URL:** <https://forums.unrealengine.com/t/hlsl-fx-to-ue4-material-porting-advice/288042>\
**Category:** Rendering\
**Tags:** unreal-engine, hlsl, shader, question\
**Created:** [July 12, 2014, 3:26pm UTC](https://forums.unrealengine.com/t/hlsl-fx-to-ue4-material-porting-advice/288042 "2014-07-12T15:26:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_4071fa6e1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4071fa6e1](https://forums.unrealengine.com/u/anonymous_user_4071fa6e1)\
**Post date:** [July 12, 2014, 3:26pm UTC](https://forums.unrealengine.com/t/hlsl-fx-to-ue4-material-porting-advice/288042/1 "2014-07-12T15:26:17Z")

</div>

I have a great many HLSL.fx shaders that I have written collected and purchased over the last 5 years.  
I would like to make use of them as much as possible, but there doesn’t seem to be any porting advice as yet.

So far, I am aware that use of Custom Expressions are discouraged for performance and portability reasons.  
I am also aware that multi-pass shaders are not an option, which is ok as most of my shaders are single-pass.  
As such, I am wondering how I can reuse some of my 3rd party shaders within UE4.

For example,  
Consider this NVidia Perlin Noise shader:  
[[http://http.developer.nvidia.com/GPUGems2/gpugems2\_chapter26.html](http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter26.html)]  
…and imagine you already have it working (in some other graphics engine) as a compilable .fx file.

How would one go about porting that PerlinNoise.fx code to UE4 for use as a material effect?

**(a) Use UE4 material nodes & functions to replicate the .fx code?  
(b) Use Custom Expressions? (come with caveats!)  
(c) Use FVertexFactory? (no idea if they are appropriate let alone how to use them!)  
(d) Custom Plugin? (if possible, a basic tutorial example would be helpful)  
(e) USF shader approach?**

I am not looking for a ‘perlin noise shader’. I am purely interested in the possible workflow for  
[PixelShader.fx] → [Unreal Engine 4 material] so the generic process can be adapted for any shader.

---

<div class="post-metadata">

**Author:** ![HypnoticShark](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HypnoticShark](https://forums.unrealengine.com/u/HypnoticShark)\
**Post date:** [July 13, 2014, 10:02am UTC](https://forums.unrealengine.com/t/hlsl-fx-to-ue4-material-porting-advice/288042/2 "2014-07-13T10:02:38Z")

</div>

In most cases it would be (a). If you are finding it impossible to achieve it with (a), an example would be a multi pass pixel shader then you might have to write your own usf shader file.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4071fa6e1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4071fa6e1](https://forums.unrealengine.com/u/anonymous_user_4071fa6e1)\
**Post date:** [July 13, 2014, 5:20pm UTC](https://forums.unrealengine.com/t/hlsl-fx-to-ue4-material-porting-advice/288042/3 "2014-07-13T17:20:26Z")

</div>

Thanks.  
Do you know if usf shaders come with the same caveats as custom (hlsl) expressions?

---

<div class="post-metadata">

**Author:** ![Ehamloptiran\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ehamloptiran\_1](https://forums.unrealengine.com/u/Ehamloptiran_1)\
**Post date:** [July 14, 2014, 4:34am UTC](https://forums.unrealengine.com/t/hlsl-fx-to-ue4-material-porting-advice/288042/4 "2014-07-14T04:34:21Z")

</div>

No they dont, USF are the native shader formats for UE4. Everything shader based are in USF’s. ie the Material template is a USF (Which is just HLSL)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4071fa6e1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4071fa6e1](https://forums.unrealengine.com/u/anonymous_user_4071fa6e1)\
**Post date:** [July 14, 2014, 7:15am UTC](https://forums.unrealengine.com/t/hlsl-fx-to-ue4-material-porting-advice/288042/5 "2014-07-14T07:15:55Z")

</div>

Excellent. That’s good to know!

Time to start hunting down USF documents.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4071fa6e1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4071fa6e1](https://forums.unrealengine.com/u/anonymous_user_4071fa6e1)\
**Post date:** [July 17, 2014, 12:51pm UTC](https://forums.unrealengine.com/t/hlsl-fx-to-ue4-material-porting-advice/288042/7 "2014-07-17T12:51:11Z")

</div>

_“Then use a Custom expression to call your function”_

That sounds like an interesting idea, but I am again concerned about the Custom expression caveats:

> **[Custom Material Expressions](https://docs.unrealengine.com/5.2/en-US/custom-material-expressions-in-unreal-engine/)**
>
> Material expressions that allow the use of custom, plain shader code.

Also, can I assume there is no documentation on the MaterialTemplate.usf that can help me with this scenario?  
(or am I the only madman attempting it?!)

---

<div class="post-metadata">

**Author:** ![PowerDesign](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PowerDesign](https://forums.unrealengine.com/u/PowerDesign)\
**Post date:** [September 21, 2016, 5:44am UTC](https://forums.unrealengine.com/t/hlsl-fx-to-ue4-material-porting-advice/288042/8 "2016-09-21T05:44:07Z")

</div>

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...
