Declaring constants instead of literals in vertex shader. Standard practice, or needless rigor?

前端 未结 2 579
谎友^
谎友^ 2021-01-13 06:45

In a vertex shader, there is of course a limited amount of uniform storage allowed, and it is my understanding that different systems may i

2条回答
  •  礼貌的吻别
    2021-01-13 07:11

    From the OpenGL® ES 2.0 Programming Guide

    As far as literal values are concerned, the OpenGL ES 2.0 shading language spec states that no constant propagation is assumed. This means that multiple instances of the same literal value(s) will be counted multiple times. Instead of using literal values, appropriate const variables should be declared. This avoids having the same literal value count multiple times, which might cause the vertex shader to fail to compile if vertex uniform storage requirements exceed what the implementation supports.

    I could not find anything related to this in the actual spec. Also there is no information specific to the iOS.

    Also you can check a GLSL Optimizer tool written to tackle this issue (and lots of others).

提交回复
热议问题