x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Writing custom HLSL shaders?

I've been looking into rendering realtime fractals in unreal engine for VR.

Obviously this would be quite expensive, so doing a bit of digging I've found that people have been able to write custom shaders in unity to render signed distance functions.

Video: https://www.youtube.com/watch?v=68MLIvqXd7w Process: https://nshelton.github.io/vr/fractals/2017/12/30/RTA.html

Another Article about rendering SDF's: http://iquilezles.org/www/articles/distfunctions/distfunctions.htm

I'm new to HLSL and learning slowly, however all tutorials and information are abstract to my use case, and I can't seem to find any good guides on writing custom shaders for Ue4

Product Version: UE 4.19
Tags:
more ▼

asked May 05 '18 at 05:30 AM in Rendering

avatar image

Sahhar
38 2 5 12

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Before you start doing any custom HLSL code in UE4, make sure you really need to do that. Materials are shaders, the way it works is whole graph is converted to HLSL (you can even see whats graph generating, there option in Window menu), because of that there no performance hit because of using Materials as if you do same calculations with will be as much as expensive as it would be in HLSL directly in fact UE4 will try to optimize it more. So if you can try to port calculations you trying to get in UE4 using material nodes, i myself had successful attempts doing so. Remember that you can do material functions, as lot of HLSL code can extensively use functions. Only downside of using materials, is that you are limited to nodes available, some things are not controllable and there lack of looping support, then indeed using HLSL coding might be better solution.

Now there 2 ways to use HLSL direcly in UE4, most simplest one and less invasive is custom code node in material:

https://docs.unrealengine.com/en-us/Engine/Rendering/Materials/ExpressionReference/Custom

It works like a function, which you input arguments via input pins and return value becomes output pin. You still limited on what UE4 provides for and do to material, but you may use some things not avable in nodes and you can do loops.

2nd is writing custom HLSL shader using usf files, issue is they are not very well documented (because Epic expect you to use materials for most things) and usually requires C++ coding:

https://docs.unrealengine.com/en-us/Programming/Rendering/ShaderDevelopment https://www.unrealengine.com/en-US/blog/how-to-add-global-shaders-to-ue4

If you google usf you might find a lot more stuff.

One of biggest challage of making custom HLSL code using usf files is that you placing code in to already complex shader system that drives all effects in UE4 and you code need to follow the conventions established by it so you don't have any conflicts with it.

Unity indeed deals with it a lot better, but on other hand they use more direct HLSL because doing material system that UE4 have is quite a feat.

more ▼

answered May 06 '18 at 08:19 PM

avatar image

Shadowriver
37.1k 935 172 1116

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question