Announcement

Collapse
No announcement yet.

"If" node versus "custom" one with "a>b" and similar operations

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    "If" node versus "custom" one with "a>b" and similar operations

    Hi guys

    Does "if" node really cost a bit more performance rather that "custom" node with a code:
    return (a>b);

    I read that article http://www.froyok.fr/blog/2017-03-st...ng-the-if-node

    But as we also know, "custom" node itself are can be a bit more expensive, even with a dead simple code like add, divide, etc.

    #2
    Does "if" node really cost a bit more performance rather that "custom" node with a code:
    return (a>b);
    No.

    But as we also know, "custom" node itself are can be a bit more expensive, even with a dead simple code like add, divide, etc.
    No on this one too.

    Froyok's article is a bit misleading, namely the part where IF material expression is compared against custom node.
    It will be translated to different code, depending if equals pin is connected or not. If it is, expression will be translated to a heavier code, that does comparison with threshold in mind.
    Last edited by Deathrey; 12-13-2019, 05:26 AM.

    Comment


      #3
      Originally posted by Deathrey View Post
      No on this one too.
      This is straigth from documantation:
      Using the custom node prevents constant folding and may use significantly more instructions than an equivalent version done with built in nodes! Constant folding is an optimization that UE4 employs under the hood to reduce shader instruction count when necessary. For example, an expression chain of Time >Sin >Mul by parameter > Add to something can and will be collapsed by UE4 into a single instruction, the final add. This is possible because all of the inputs of that expression (Time, parameter) are constant for the whole draw call, they do not change per-pixel. UE4 cannot collapse anything in a custom node, which can produce less efficient shaders than an equivalent version made out of existing nodes. As a result, it is best to only use the custom node when it gives you access to functionality not possible with the existing nodes.

      https://docs.unrealengine.com/en-US/...tom/index.html

      Comment


        #4
        Originally posted by Alexander.L View Post
        This is straigth from documantation:
        Using the custom node prevents constant folding and may use significantly more instructions than an equivalent version done with built in nodes! Constant folding is an optimization that UE4 employs under the hood to reduce shader instruction count when necessary. For example, an expression chain of Time >Sin >Mul by parameter > Add to something can and will be collapsed by UE4 into a single instruction, the final add. This is possible because all of the inputs of that expression (Time, parameter) are constant for the whole draw call, they do not change per-pixel. UE4 cannot collapse anything in a custom node, which can produce less efficient shaders than an equivalent version made out of existing nodes. As a result, it is best to only use the custom node when it gives you access to functionality not possible with the existing nodes.

        https://docs.unrealengine.com/en-US/...tom/index.html
        That would still be no. Custom node does not prevent constant folding. Documentation is worded a bit off and is interpreted in a wrong way.
        Unreal's material translator has a system, that evaluates the graph and if any parts of the graph are uniform(thus, being the same for all shader executions), replaces it with a value, that is calculated on CPU.
        Custom material expression will never evaluate to a uniform material expression, and likewise, anything done within it won't and this is the part documentation refers to. Shader compiler constant folding though will not be affected by custom node.

        Guess what? You can move out all uniform operations with shader parameters out of custom node and keep them in the graph. So custom node being slower is myths and legends, provided, that you understand which parts of your graph are uniform.

        Besides, the example from documentation page, namely Time->Sine->Mul by scalar is also wrong, as it will be not be evaluated as uniform.
        Last edited by Deathrey; 12-13-2019, 11:12 PM.

        Comment

        Working...
        X