Search Unity

Question Can't connect Matrix output to the Branch inputs

Discussion in 'Shader Graph' started by andreyefimov2010, Sep 7, 2021.

  1. andreyefimov2010

    andreyefimov2010

    Joined:
    Oct 29, 2017
    Posts:
    44
    I can't connect a matrix to the branch input (although I can connect vectors normally):
    upload_2021-9-7_15-57-2.png

    Is this expected and is there a workaround for this?
     
  2. JJRivers

    JJRivers

    Joined:
    Oct 16, 2018
    Posts:
    137
    Not sure about the cause but workaround is to make a sign op your self like so:

    Use your predicate on the branch to output 0 or 1, pipe it to (Sign Node) and multiply the matrix with that, then if you want another matrix you oneminus the (Sign node) and multiply the other one with that.

    Depending on ShaderGraph version, the branch node itself is i believe a lerp and not a conditional branch to begin with and both sides get calculated regardless of which side you use finally. Trying to keep the branches early in the shader (meaning avoid connecting heavy chains of nodes to a branch only just before output to master etc) and their inputs simple tends to produce better performing shaders.
     
  3. andreyefimov2010

    andreyefimov2010

    Joined:
    Oct 29, 2017
    Posts:
    44
    Thanks for the workaround, it should work.
    But I'm just talking about the feature fullness of the Branch node: it allows you to connect any other type of data, like floats or vectors, but not a matrix, which is clearly an oversight to me.
    Also constructing a static matrix is not a heavy chain of nodes and should not have any impact on performance even if both of the matrices end up being built either way.
     
  4. andybak

    andybak

    Joined:
    Jan 14, 2017
    Posts:
    569
    This definitely strikes me as a bug or at least an oversight. Branch should surely accept any type.