GLSL Problem: Multiple shaders in one program

前端 未结 4 741
醉话见心
醉话见心 2020-12-29 09:30

I must have misunderstood something with shaders:

I thought that as you can attach multiple shaders to one program, you\'d be able to simply attach more than one fra

4条回答
  •  难免孤独
    2020-12-29 09:58

    You can have a set of entry points pre-defined. Suppose you have a limited number of effects (diffuse, specular, environment, etc). None of them is applied at most once, so you just need to create a managing shader like that one:

    void apply_diffuse();
    void apply_specular();
    void apply_environment();
    
    void main(){ ...
         apply_diffuse();
         apply_specular();
         apply_environment();
    ...}
    

    Then, when it's time to link the shader program you attach the corresponding implementations as separate GLSL objects. Some implementations may be dummies if you don't want the effect. This approach doesn't require source text parsing and has next to no performance penalty.

提交回复
热议问题