cocos2d-x 模型用上shader的方法。仅备份

前端之家收集整理的这篇文章主要介绍了cocos2d-x 模型用上shader的方法。仅备份前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
    auto floor = PhysicsSprite3D::create("Sprite3DTest/Box.c3t",&rbDes);
    //floor->setTexture("Sprite3DTest/plane.png");
	auto glprogram = GLProgram::createWithFilenames("Sprite3DTest/test.vs.txt","Sprite3DTest/test.fs.txt");
	auto glprogramstate = GLProgramState::create(glprogram);
	//floor->setGLProgramState(glprogramstate);
	Texture2D* mix_tex = Director::getInstance()->getTextureCache()->addImage("Sprite3DTest/mix.png");
	glprogramstate->setUniformTexture("mix",mix_tex);


	Texture2D* tex1 = Director::getInstance()->getTextureCache()->addImage("Sprite3DTest/GrassGround.png");
	glprogramstate->setUniformTexture("tex1",tex1);


	Texture2D* tex2 = Director::getInstance()->getTextureCache()->addImage("Sprite3DTest/Ground02.png");
	glprogramstate->setUniformTexture("tex2",tex2);


	auto material = Material::createWithGLStateProgram(glprogramstate);
	floor->setMaterial(material);


、、、、fs

varying vec2 TextureCoordOut;
uniform sampler2D mix;
uniform sampler2D tex1;
uniform sampler2D tex2;


void main()
{
vec4 clr_tex1=texture2D(tex1,TextureCoordOut);
vec4 clr_tex2=texture2D(tex2,TextureCoordOut);

vec4 clr_mix=texture2D(mix,TextureCoordOut);
gl_FragColor =clr_tex1*clr_mix.r + clr_tex2*clr_mix.g;

}



、、、、、vs

attribute vec4 a_position; attribute vec2 a_texCoord; varying vec2 TextureCoordOut; void main(void) { gl_Position = CC_MVPMatrix * a_position; TextureCoordOut = a_texCoord; }

猜你在找的Cocos2d-x相关文章