首页 > 代码库 > GLES & Shader Language 易错集锦

GLES & Shader Language 易错集锦

1. vertex shader 和 fragment shader 通过varying变量传递数据,

  如下代码在编译fragment shader时候会提示编译错误

vertex shader
Fragment shader
    varying vec4 v_color;                         \n    attribute vec3 v_Position;                    \n    attribute vec4 f_Color;                       \n    void main(void)                               \n    {                                             \n        gl_Position = vec4(v_Position, 1.0);      \n        v_color = f_Color;                        \n    }"
    varying vec4 v_color;                       \n    void main(void)                             \n    {                                           \n        gl_FragColor = v_color;                 \n    };

  在fragment shader中加入精度控制,就不会出现编译错误!任何一个精度控制都可以解决编译错误(不解!)

vertex shader
Fragment shader
    varying vec4 v_color;                         \n    attribute vec3 v_Position;                    \n    attribute vec4 f_Color;                       \n    void main(void)                               \n    {                                             \n        gl_Position = vec4(v_Position, 1.0);      \n        v_color = f_Color;                        \n    }"
    varying (lowp/mediump/highp) vec4 v_color;  \n    void main(void)                             \n    {                                           \n        gl_FragColor = v_color;                 \n    };

 

    http://blog.chinaunix.net/uid-12348673-id-3441087.html