Features

The graph WkFunctionDrawer provides a context in which you will be able to add math functions or custom function graphs in order to viusalize and tweak them.

  • Displays up to 3 function curves
  • User-defined graphic range on X and Y axis
  • Changes on the functions are visible in real-time in the 2D-Viewer

There is room for improvements:

  • The graduations values are only in the range [-2,2] and are part of the grid texture

WkFunctionDrawer is intended to be used primarly as a tool, not directly as a node into a material. Although the code shouldn't be resource consuming thanks to the Pixel Processor node, I didn't really check the performances.

 

Visualizing function curves

Open the package WkFunctionDrawer.sbs in Substance Designer then open the graph named WkFunctionDrawer.

In the frame titled Duplicate and edit me copy the node on the right and paste it a bit further (keep the connection to the bitmap). This will allow you to work with your own data and keep a template clean.

Right-clic on this new node, choose View Output in 2D-View to visualize its content while modifiing it and clic on the Edit button in the Parameters panel to edit the Pixel Processor function.

 

  • WkFunctionDrawer_Overview

 

Content of the Pixel Processor:

  • WkFunctionDrawer_InPixelProcessor

 

To display a function curve: In the Pixel Processor function put the nodes or the functions you would like to see in one of the 3 main frames and plug them to the Null nodes respectively on the left side (the "X" value) and on the right side (the "f(X)" value) of the frame. According to the frame used it will draw a red, green of blue curve of the resulting function.

To hide a curve: Connect the node at the top right of the suitable frame to the Null node on the right.

 

To change the display range of the functions: Edit the values of the nodes in the frame named Set range here, on the left part of the graph.

 

Implementation notes

You may notice that the thickness of the curves depends on their slope: the higher the slope the less the curve is visible.

 

WkFunctionDrawer CurveThickness

 

This is because the Pixel Processor allows only to draw at the evaluated texel, not on its neighbourgs, so the ordinate f(X) is only evaluated for the absice X of the texel.

Getting a curve with a constant thickness would require to compute f(X + dX), where dX is a small value, or to use the derivative of the function f, which is rarely obvious. In both cases the graph would have been far more complex to use as a tool.