码迷,mamicode.com
首页 > 其他好文 > 详细

cocos creator 的shader

时间:2019-02-28 00:43:14      阅读:655      评论:0      收藏:0      [点我收藏+]

标签:ntc   oat   ec2   osi   texture   xtu   code   div   ref   

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

标签:ntc   oat   ec2   osi   texture   xtu   code   div   ref   

原文地址:https://www.cnblogs.com/daihanlong/p/10447773.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!