cocos creator 的shader

Posted daihanlong

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cocos creator 的shader相关的知识,希望对你有一定的参考价值。

sprite vert

uniform mat4 viewProj;

#ifdef use2DPos
attribute vec2 a_position;
#else
attribute vec3 a_position;
#endif

attribute lowp vec4 a_color;

#ifdef useModel
uniform mat4 model;
#endif

#ifdef useTexture
attribute mediump vec2 a_uv0;
varying mediump vec2 uv0;
#endif


#ifndef useColor
varying lowp vec4 v_fragmentColor;
#endif
void main ()
{
    mat4 mvp;
    #ifdef useModel
        mvp = viewProj * model;
    #else       
        mvp = viewProj;
    #endif

    #ifdef use2DPos
        vec4 pos = mvp * vec4(a_position, 0, 1);
    #else
        vec4 pos = mvp * vec4(a_position, 1);
    #endif

    #ifndef useColor
         v_fragmentColor = a_color;
    #endif

    #ifdef useTexture
        uv0 = a_uv0;
    #endif

     gl_Position = pos;
}   

sprite frag

#ifdef useTexture
uniform sampler2D texture;
varying mediump vec2 uv0;
#endif

#ifdef alphaTest
uniform lowp float alphaThreshold;
#endif


#ifdef useColor
uniform lowp vec4 color;
#else
varying lowp vec4 v_fragmentColor;
#endif

void main () {

    #ifdef useColor
        vec4 o = color;
    #else
        vec4 o = v_fragmentColor;
    #endif

    #ifdef useTexture 
        o *= texture2D(texture, uv0);
    #endif

    #ifdef alphaTest
        if (o.a <= alphaThreshold)
            discard;
    #endif

    gl_FragColor = o;
}   

以上是关于cocos creator 的shader的主要内容,如果未能解决你的问题,请参考以下文章

cocos creator 2.1版本Material材质系统解析

shader 动画之旗子/水纹波浪 !Cocos Creator !

cocos2dx creator canvas 怎么使用shader

使用 mesh 实现多边形裁剪图片!Cocos Creator!

Cocos Creator插件——Many Widgets助你快速开发

Cocos Creator插件——Many Widgets助你快速开发