Search Unity

Question Branching-free in shader

Discussion in 'Shaders' started by thang_unity516, Jan 10, 2024.

  1. thang_unity516

    thang_unity516

    Joined:
    Oct 29, 2021
    Posts:
    43
    As I know, some specific cases of branching will made the shader run slower depending on GPU. Assuming that I want to run a shader on various GPUs (especially mobile), does turning the branching to a calculation is a good solution for it (Reference: https://theorangeduck.com/page/avoiding-shader-conditionals)? After I read this article, I feel that this way kind of magical to me: does the function like max, abs, sign,... don't turn into an if below?

    Thanks for your help
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,422
  3. thang_unity516

    thang_unity516

    Joined:
    Oct 29, 2021
    Posts:
    43
    Last edited: Jan 10, 2024