What is the fastest way to pass values ​​to GLSL?

In GLSL shaders, I often want several functions to change the same value for various reasons (for example, a fragment shader that uses four functions to apply lighting, texture, mirrors and fog, say). I can think of at least three ways to bypass such values ​​for modification:

  • Use inout for each function.
  • Pass the value as an in parameter and use the return value (which has the obvious drawback that I can only use one value).
  • Use a global variable that modifies each function.

Should I expect any practical differences between these methods? Rather, faster than others? Are some more compatible than others? Are there any other differences? Or other methods, for that matter?

Or can I just choose the one I like best, stylistically?

+4
source share
1 answer

This optimization depends mainly on the underlying GLSL compiler. Profile your shader on different GPUs: AMD, nVidia, Intel and choose the best code.

0
source

All Articles