不废话,直接上代码,在cocos2d-x 3.3rc0中使用,通过.
cocos2d-X在Sprite上使用shader
auto sprite = Sprite::create("test2.png");sprite->setposition(origin.x + visibleSize.wIDth/2,origin.y + visibleSize.height /2 );auto shader_program = GLProgram::createWithfilenames("shadow.vsh","shadow.fsh");shader_program->use();shader_program->setUniformsForBuiltins();sprite->setGLProgram(shader_program);this->addChild(sprite);
shadow.vsh
attribute vec4 a_position;attribute vec2 a_texCoord;varying vec2 v_texCoord;voID main(){gl_position = CC_PMatrix * a_position;v_texCoord = a_texCoord;}
shadow.fsh
varying vec2 v_texCoord;vec4 composite(vec4 over,vec4 under){return over + (1.0 - over.a)*under;}voID main(){vec2 shadowOffset = vec2(0.03,0.03);vec4 texturecolor = texture2D(CC_Texture0,v_texCoord + shadowOffset);float shadowMask = texture2D(CC_Texture0,v_texCoord ).a;const float shadowOpacity = 0.5;vec4 shadowcolor = vec4(0,shadowMask *shadowOpacity);gl_Fragcolor = composite(texturecolor,shadowcolor);}总结
以上是内存溢出为你收集整理的cocos2d-x用shader来实现阴影全部内容,希望文章能够帮你解决cocos2d-x用shader来实现阴影所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)