This shader can be used either as a standalone material to view the curve of some functions you know the equation or its main nodes can be imported into a shader you are working on to check the value of some variables.
It is intended to be used primarly as a tool, not as an in-game shader. Although the code shouldn't be resource consuming, I didn't really check the performances.
Features and notes
- Displays up to 3 function curves
- User-defined graphic range on X and Y axis
- Supports animated curves
- Can be used in any material or material function
There is room for improvements:
- The graduations values are only in the range [-2,2] and are part of the grid texture.
- The grid comes from a texture. It could be procedural (see this post in the blog of Oliver M-H for more)
- Currently the shader supports only linear map functions. In his post Oliver M-H also presents a method to draw parametric functions.
Download the package and unzip the content (be careful not to create a folder with the name of the archive) directly at the root of the Content directory of an UE4 project.
Then launch the UE4 project. You should find the WkFunctionDrawer data in the following folder:
- Standalone material: Open the material M_WkFunctionDrawer, add the equation of the functions into the green Comment node and plug them as in the examples.
- Viewer of variables in a material or a function material: In the shader you are working on right click to call the functions lister dialog box and instantiate the function MF_WkFunctionDrawer. Then plug the output X of this node into the branch of the shader you are interested in and the output of this branch into one of the 3 functions input. Now to display the graph connect the output of the Lerp node in the Emissive plug of the material.
One of the first thing you may notice when playing with the function drawer is the look of the sine and cosine. Indeed, as I did with some surprise, you will discover that these functions are periodic on a [-1,1] range instead of [-Pi,Pi].
Why is that? Mystery. The sine documentation says nothing about this strange range, it says input should be in radians.
There is a "linear sine" though: https://docs.unrealengine.com/latest/INT/Engine/Rendering/Materials/Functions/Reference/Math/index.html#linearsine
WkFunctionDrawer now comes with a set of sample functions such as a modified modulo or several periodic signals. It is easy to experiment with them and, as they proved to be quite useful, to encapsulate them in material functions for an easy reuse.
All these functions are in the material located here:
Open the material M_WkFunctionDrawer provided as an example to see how nodes and material functions are related toghether.
Among the material functions used in WkfunctionDrawer this one is interesting because it can also be used as a standalone texture to draw a segment or a line based on 2 points.
MF_WkDrawLineBetween2Coords is just a repack of a function written by RynaB, from Epic, in the following thread: UE4 Forum - Drawing a line between 2 coordinates
It is quite useful and you can download it as is here: MF_WkDrawLineBetween2Coords.zip
- : Oliver M-H blog - [UE4 Material] Graphing Functions - http://oliverm-h.blogspot.de/2014/12/ue4-material-graphing-functions.html
- : UE4 Forum - Drawing a line between 2 coordinates - Sample code from RyanB (Epic) - https://forums.unrealengine.com/showthread.php?69170-Material-draw-a-line-between-two-coordinates
- : Sample Examples project, freely available on the MarketPlace - Math_Hall map
While improving WkFunctionDrawer I discovered that both the draw function and the draw line function already existed !
MF_WkDrawLineBetween2Coords is provided by default in UE4 under the name DrawLine-2D (undocumented) and MF_WkFunctionDrawer is available in the Sample Examples project, in the map called Math_Hall.
In spite of that working on those functions was very instructive for me and I find my implementation quite flexible.
- V2.1 (18/11/2015): UE 4.10
- Moved the script folder from WkLibrary\WkFunctionDrawer to WkLibrary\WkMaterials\WkFunctionDrawer
- Added several examples of useful periodic functions
- V2.0 (18/10/2015): UE 4.9
- Created a function MF_WkFunctionDrawer that encapsulate MF_WkFunctionDrawerControls
MF_WkFunctionDrawerDisplay in order to have only 1 node to copy and paste in the user functions
- Removed some If nodes in the code for shorter compilation time
- V1.0 (10/09/2015): UE 4.9
- basic version