zhishu520 / blog

一个关于游戏开发的博客(*^__^*)
3 stars 0 forks source link

cocos2dx shader 赏析 #8

Open zhishu520 opened 5 years ago

zhishu520 commented 5 years ago

GLProgram::SHADER_NAME_POSITION_GRAYSCALE

scalegray

// vert
attribute vec4 a_position;
attribute vec2 a_texCoord;
attribute vec4 a_color;

#ifdef GL_ES
varying lowp vec4 v_fragmentColor;
varying mediump vec2 v_texCoord;
#else
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
#endif

void main()
{
    gl_Position = CC_PMatrix * a_position;
    v_fragmentColor = a_color;
    v_texCoord = a_texCoord;
}

//frag
#ifdef GL_ES
precision mediump float;
#endif

varying vec4 v_fragmentColor;
varying vec2 v_texCoord;

void main(void)
{
    vec4 c = texture2D(CC_Texture0, v_texCoord);
    c = v_fragmentColor * c;
    gl_FragColor.xyz = vec3(0.2126*c.r + 0.7152*c.g + 0.0722*c.b);
    gl_FragColor.w = c.w;
}
zhishu520 commented 5 years ago

Shader 知识

变量类型 uniform attribute varying