I have heard many times that if statements in shaders slow down the gpu massively. But I also heard that texture samples are very expensive.

Which one is more endurable? Which one is less impactful?

I am asking, because I need to decide on if I should multiply a value by 0, or put an if statement.

  • FeyterM
    link
    fedilink
    arrow-up
    11
    ·
    edit-2
    1 month ago

    I think there is no obvious way of telling this, because it depends on how you if statement will be constructed and in the end what machine code will be generated from your code.

    So best thing would probably be implement both and measure the results. I would argue that’s how performance optimisations work. Don’t trust on what a forum post tells you.

    However chances are high that both will have similar performance in a range that doesn’t matter for your use case… Without knowing your use case :)