Search code examples
openglopengl-esshader

Open GL Shaders "reused'


My Question is based on this answer GLSL reusable/shared functions, shared constants (OpenGL ES 2.0)?

If I can create a common Shader where is the limit ? Can I write in this common shader Uniform variables ? What is the max amount of common shaders that I can attach to on spezific one ? Increase this Performance ?

Is it recommend ? Anyone experience with this ?

EDIT: In my OpenGL Implementation I have some shaders that extends other shaders. Would it be possible without performance loss to get rid of the duplicate code ?

An example

ShaderC extends ShaderB extends ShaderA. Each of them is loading some uniform variables. Would it be good practice if I create a commonShaderB.glsl and a commonShaderA.glsl and attach them to the program from shaderC to avoid duplicate glsl code ?


Solution

  • Can I write in this common shader Uniform variables ?

    Yes.

    What is the max amount of common shaders that I can attach to on spezific one ?

    There is no limit on the number of shaders you can attach to a shader program. However, there are limits on the number of instructions, uniform variables, and attributes. It is unlikely that you hit any of these limits with a reasonably designed shader.

    Increase this Performance ?

    No.

    If I can create a Comon Shader where is the limit ? Is it recommend ? Anyone experience with this ?

    These questions are too broad or opinion-based and out of scope for StackOverflow. The functionality exists for a reason, so use it when appropriate.