ios cocos2d 变色的着色器

这里贴一个着色器到这里,以备后面查看


GLchar * pszFragSource =

    "#ifdef GL_ES \n \

    precision mediump float; \n \

    #endif \n \

    uniform sampler2D u_texture; \n \

    varying vec2 v_texCoord; \n \

    varying vec4 v_fragmentColor; \n \

    void main(void) \n \

    { \n \

    // Convert to greyscale using NTSC weightings \n \

    vec4 color = texture2D( u_texture, v_texCoord ); \n \

    float grey = dot(texture2D(u_texture, v_texCoord).rgb, vec3(0.299, 0.587, 0.114)); \n \

    gl_FragColor = color; \n \

    }";


修改颜色只需要修改上面红色部分(值为想要颜色的rgb 值换算为0-1的值,eg:234.0/255)


[ [ CCGLProgram alloc ] initWithVertexShaderByteArray:ccPositionTextureColor_vert fragmentShaderByteArray:pszFragSource];




你可能感兴趣的:(cocos2d)