mirror of https://github.com/axmolengine/axmol.git
replace custom shaders by material files
add Sprite3DVertexColorTest
This commit is contained in:
parent
d17c04cf0e
commit
cc6e2077f4
|
@ -61,6 +61,7 @@ Sprite3DTests::Sprite3DTests()
|
||||||
ADD_TEST_CASE(Sprite3DClippingTest);
|
ADD_TEST_CASE(Sprite3DClippingTest);
|
||||||
ADD_TEST_CASE(Sprite3DTestMeshLight);
|
ADD_TEST_CASE(Sprite3DTestMeshLight);
|
||||||
ADD_TEST_CASE(Animate3DCallbackTest);
|
ADD_TEST_CASE(Animate3DCallbackTest);
|
||||||
|
ADD_TEST_CASE(Sprite3DVertexColorTest);
|
||||||
};
|
};
|
||||||
|
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
|
@ -231,38 +232,9 @@ Sprite3DUVAnimationTest::Sprite3DUVAnimationTest()
|
||||||
|
|
||||||
//create cylinder
|
//create cylinder
|
||||||
auto cylinder = Sprite3D::create("Sprite3DTest/cylinder.c3b");
|
auto cylinder = Sprite3D::create("Sprite3DTest/cylinder.c3b");
|
||||||
|
auto mat = Material::createWithFilename("Sprite3DTest/UVAnimation.material");
|
||||||
//create and set our custom shader
|
_state = mat->getTechniqueByIndex(0)->getPassByIndex(0)->getGLProgramState();
|
||||||
auto shader =GLProgram::createWithFilenames("Sprite3DTest/cylinder.vert","Sprite3DTest/cylinder.frag");
|
cylinder->setMaterial(mat);
|
||||||
_state = GLProgramState::create(shader);
|
|
||||||
cylinder->setGLProgramState(_state);
|
|
||||||
|
|
||||||
_state->setUniformFloat("offset",_cylinder_texture_offset);
|
|
||||||
_state->setUniformFloat("duration",_shining_duraion);
|
|
||||||
//pass mesh's attribute to shader
|
|
||||||
long offset = 0;
|
|
||||||
auto attributeCount = cylinder->getMesh()->getMeshVertexAttribCount();
|
|
||||||
for (auto i = 0; i < attributeCount; i++) {
|
|
||||||
auto meshattribute = cylinder->getMesh()->getMeshVertexAttribute(i);
|
|
||||||
_state->setVertexAttribPointer(s_attributeNames[meshattribute.vertexAttrib],
|
|
||||||
meshattribute.size,
|
|
||||||
meshattribute.type,
|
|
||||||
GL_FALSE,
|
|
||||||
cylinder->getMesh()->getVertexSizeInBytes(),
|
|
||||||
(GLvoid*)offset);
|
|
||||||
offset += meshattribute.attribSizeBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
//create the second texture for cylinder
|
|
||||||
auto shining_texture = Director::getInstance()->getTextureCache()->addImage("Sprite3DTest/caustics.png");
|
|
||||||
Texture2D::TexParams tRepeatParams;//set texture parameters
|
|
||||||
tRepeatParams.magFilter = GL_NEAREST;
|
|
||||||
tRepeatParams.minFilter = GL_NEAREST;
|
|
||||||
tRepeatParams.wrapS = GL_REPEAT;
|
|
||||||
tRepeatParams.wrapT = GL_REPEAT;
|
|
||||||
shining_texture->setTexParameters(tRepeatParams);
|
|
||||||
//pass the texture sampler to our custom shader
|
|
||||||
_state->setUniformTexture("caustics",shining_texture);
|
|
||||||
|
|
||||||
|
|
||||||
this->addChild(cylinder);
|
this->addChild(cylinder);
|
||||||
|
@ -275,31 +247,6 @@ Sprite3DUVAnimationTest::Sprite3DUVAnimationTest()
|
||||||
|
|
||||||
//the callback function update cylinder's texcoord
|
//the callback function update cylinder's texcoord
|
||||||
schedule(schedule_selector(Sprite3DUVAnimationTest::cylinderUpdate));
|
schedule(schedule_selector(Sprite3DUVAnimationTest::cylinderUpdate));
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
|
||||||
_backToForegroundListener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND,
|
|
||||||
[this](EventCustom*)
|
|
||||||
{
|
|
||||||
auto glProgram = _state->getGLProgram();
|
|
||||||
glProgram->reset();
|
|
||||||
glProgram->initWithFilenames("Sprite3DTest/cylinder.vert", "Sprite3DTest/cylinder.frag");
|
|
||||||
glProgram->link();
|
|
||||||
glProgram->updateUniforms();
|
|
||||||
auto shining_texture = Director::getInstance()->getTextureCache()->addImage("Sprite3DTest/caustics.png");
|
|
||||||
Texture2D::TexParams tRepeatParams;//set texture parameters
|
|
||||||
tRepeatParams.magFilter = GL_NEAREST;
|
|
||||||
tRepeatParams.minFilter = GL_NEAREST;
|
|
||||||
tRepeatParams.wrapS = GL_REPEAT;
|
|
||||||
tRepeatParams.wrapT = GL_REPEAT;
|
|
||||||
shining_texture->setTexParameters(tRepeatParams);
|
|
||||||
//pass the texture sampler to our custom shader
|
|
||||||
_state->setUniformTexture("caustics",shining_texture);
|
|
||||||
_state->setUniformFloat("offset",_cylinder_texture_offset);
|
|
||||||
_state->setUniformFloat("duration",_shining_duraion);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_backToForegroundListener, -1);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite3DUVAnimationTest::~Sprite3DUVAnimationTest()
|
Sprite3DUVAnimationTest::~Sprite3DUVAnimationTest()
|
||||||
|
@ -368,35 +315,11 @@ Sprite3DFakeShadowTest::Sprite3DFakeShadowTest()
|
||||||
_plane = Sprite3D::create("Sprite3DTest/plane.c3t");
|
_plane = Sprite3D::create("Sprite3DTest/plane.c3t");
|
||||||
_plane->setRotation3D(Vec3(90,0,0));
|
_plane->setRotation3D(Vec3(90,0,0));
|
||||||
|
|
||||||
// use custom shader
|
auto mat = Material::createWithFilename("Sprite3DTest/FakeShadow.material");
|
||||||
auto shader =GLProgram::createWithFilenames("Sprite3DTest/simple_shadow.vert","Sprite3DTest/simple_shadow.frag");
|
_state = mat->getTechniqueByIndex(0)->getPassByIndex(0)->getGLProgramState();
|
||||||
_state = GLProgramState::create(shader);
|
_plane->setMaterial(mat);
|
||||||
_plane->setGLProgramState(_state);
|
|
||||||
|
|
||||||
//pass mesh's attribute to shader
|
|
||||||
long offset = 0;
|
|
||||||
auto attributeCount = _plane->getMesh()->getMeshVertexAttribCount();
|
|
||||||
for (auto i = 0; i < attributeCount; i++) {
|
|
||||||
auto meshattribute = _plane->getMesh()->getMeshVertexAttribute(i);
|
|
||||||
_state->setVertexAttribPointer(s_attributeNames[meshattribute.vertexAttrib],
|
|
||||||
meshattribute.size,
|
|
||||||
meshattribute.type,
|
|
||||||
GL_FALSE,
|
|
||||||
_plane->getMesh()->getVertexSizeInBytes(),
|
|
||||||
(GLvoid*)offset);
|
|
||||||
offset += meshattribute.attribSizeBytes;
|
|
||||||
}
|
|
||||||
_state->setUniformMat4("u_model_matrix",_plane->getNodeToWorldTransform());
|
_state->setUniformMat4("u_model_matrix",_plane->getNodeToWorldTransform());
|
||||||
|
|
||||||
//create shadow texture
|
|
||||||
auto shadowTexture = Director::getInstance()->getTextureCache()->addImage("Sprite3DTest/shadowCircle.png");
|
|
||||||
Texture2D::TexParams tRepeatParams;//set texture parameters
|
|
||||||
tRepeatParams.magFilter = GL_LINEAR;
|
|
||||||
tRepeatParams.minFilter = GL_LINEAR;
|
|
||||||
tRepeatParams.wrapS = GL_CLAMP_TO_EDGE;
|
|
||||||
tRepeatParams.wrapT = GL_CLAMP_TO_EDGE;
|
|
||||||
shadowTexture->setTexParameters(tRepeatParams);
|
|
||||||
_state->setUniformTexture("u_shadowTexture",shadowTexture);
|
|
||||||
layer->addChild(_plane);
|
layer->addChild(_plane);
|
||||||
|
|
||||||
//create the orc
|
//create the orc
|
||||||
|
@ -405,38 +328,12 @@ Sprite3DFakeShadowTest::Sprite3DFakeShadowTest()
|
||||||
_orc->setRotation3D(Vec3(0,180,0));
|
_orc->setRotation3D(Vec3(0,180,0));
|
||||||
_orc->setPosition3D(Vec3(0,0,10));
|
_orc->setPosition3D(Vec3(0,0,10));
|
||||||
_targetPos = _orc->getPosition3D();
|
_targetPos = _orc->getPosition3D();
|
||||||
_plane->getGLProgramState()->setUniformVec3("u_target_pos",_orc->getPosition3D());
|
_state->setUniformVec3("u_target_pos", _orc->getPosition3D());
|
||||||
layer->addChild(_orc);
|
layer->addChild(_orc);
|
||||||
layer->addChild(_camera);
|
layer->addChild(_camera);
|
||||||
layer->setCameraMask(2);
|
layer->setCameraMask(2);
|
||||||
|
|
||||||
schedule(CC_SCHEDULE_SELECTOR(Sprite3DFakeShadowTest::updateCamera), 0.0f);
|
schedule(CC_SCHEDULE_SELECTOR(Sprite3DFakeShadowTest::updateCamera), 0.0f);
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
|
||||||
_backToForegroundListener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND,
|
|
||||||
[this](EventCustom*)
|
|
||||||
{
|
|
||||||
auto glProgram = _state->getGLProgram();
|
|
||||||
glProgram->reset();
|
|
||||||
glProgram->initWithFilenames("Sprite3DTest/simple_shadow.vert","Sprite3DTest/simple_shadow.frag");
|
|
||||||
glProgram->link();
|
|
||||||
glProgram->updateUniforms();
|
|
||||||
|
|
||||||
_state->setUniformMat4("u_model_matrix",_plane->getNodeToWorldTransform());
|
|
||||||
|
|
||||||
//create shadow texture
|
|
||||||
auto shadowTexture = Director::getInstance()->getTextureCache()->addImage("Sprite3DTest/shadowCircle.png");
|
|
||||||
Texture2D::TexParams tRepeatParams;//set texture parameters
|
|
||||||
tRepeatParams.magFilter = GL_LINEAR;
|
|
||||||
tRepeatParams.minFilter = GL_LINEAR;
|
|
||||||
tRepeatParams.wrapS = GL_CLAMP_TO_EDGE;
|
|
||||||
tRepeatParams.wrapT = GL_CLAMP_TO_EDGE;
|
|
||||||
shadowTexture->setTexParameters(tRepeatParams);
|
|
||||||
_state->setUniformTexture("u_shadowTexture",shadowTexture);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_backToForegroundListener, -1);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite3DFakeShadowTest::~Sprite3DFakeShadowTest()
|
Sprite3DFakeShadowTest::~Sprite3DFakeShadowTest()
|
||||||
|
@ -520,7 +417,7 @@ void Sprite3DFakeShadowTest::move3D(float elapsedTime)
|
||||||
offset.x=offset.x;
|
offset.x=offset.x;
|
||||||
offset.z=offset.z;
|
offset.z=offset.z;
|
||||||
//pass the newest orc position
|
//pass the newest orc position
|
||||||
_plane->getGLProgramState()->setUniformVec3("u_target_pos",_orc->getPosition3D());
|
_state->setUniformVec3("u_target_pos",_orc->getPosition3D());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite3DFakeShadowTest::updateState(float elapsedTime)
|
void Sprite3DFakeShadowTest::updateState(float elapsedTime)
|
||||||
|
@ -616,44 +513,17 @@ Sprite3DBasicToonShaderTest::Sprite3DBasicToonShaderTest()
|
||||||
_camera->setCameraFlag(CameraFlag::USER1);
|
_camera->setCameraFlag(CameraFlag::USER1);
|
||||||
// create a teapot
|
// create a teapot
|
||||||
auto teapot = Sprite3D::create("Sprite3DTest/teapot.c3b");
|
auto teapot = Sprite3D::create("Sprite3DTest/teapot.c3b");
|
||||||
//create and set our custom shader
|
auto mat = Material::createWithFilename("Sprite3DTest/BasicToon.material");
|
||||||
auto shader =GLProgram::createWithFilenames("Sprite3DTest/toon.vert","Sprite3DTest/toon.frag");
|
_state = mat->getTechniqueByIndex(0)->getPassByIndex(0)->getGLProgramState();
|
||||||
_state = GLProgramState::create(shader);
|
teapot->setMaterial(mat);
|
||||||
teapot->setGLProgramState(_state);
|
|
||||||
teapot->setPosition3D(Vec3(0,-5,-20));
|
teapot->setPosition3D(Vec3(0,-5,-20));
|
||||||
teapot->setRotation3D(Vec3(-90,180,0));
|
teapot->setRotation3D(Vec3(-90,180,0));
|
||||||
auto rotate_action = RotateBy::create(1.5,Vec3(0,30,0));
|
auto rotate_action = RotateBy::create(1.5,Vec3(0,30,0));
|
||||||
teapot->runAction(RepeatForever::create(rotate_action));
|
teapot->runAction(RepeatForever::create(rotate_action));
|
||||||
//pass mesh's attribute to shader
|
|
||||||
long offset = 0;
|
|
||||||
auto attributeCount = teapot->getMesh()->getMeshVertexAttribCount();
|
|
||||||
for (auto i = 0; i < attributeCount; i++) {
|
|
||||||
auto meshattribute = teapot->getMesh()->getMeshVertexAttribute(i);
|
|
||||||
_state->setVertexAttribPointer(s_attributeNames[meshattribute.vertexAttrib],
|
|
||||||
meshattribute.size,
|
|
||||||
meshattribute.type,
|
|
||||||
GL_FALSE,
|
|
||||||
teapot->getMesh()->getVertexSizeInBytes(),
|
|
||||||
(GLvoid*)offset);
|
|
||||||
offset += meshattribute.attribSizeBytes;
|
|
||||||
}
|
|
||||||
addChild(teapot);
|
addChild(teapot);
|
||||||
addChild(_camera);
|
addChild(_camera);
|
||||||
setCameraMask(2);
|
setCameraMask(2);
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
|
||||||
_backToForegroundListener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND,
|
|
||||||
[this](EventCustom*)
|
|
||||||
{
|
|
||||||
auto glProgram = _state->getGLProgram();
|
|
||||||
glProgram->reset();
|
|
||||||
glProgram->initWithFilenames("Sprite3DTest/toon.vert","Sprite3DTest/toon.frag");
|
|
||||||
glProgram->link();
|
|
||||||
glProgram->updateUniforms();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_backToForegroundListener, -1);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite3DBasicToonShaderTest::~Sprite3DBasicToonShaderTest()
|
Sprite3DBasicToonShaderTest::~Sprite3DBasicToonShaderTest()
|
||||||
|
@ -2433,10 +2303,6 @@ void Sprite3DCubeMapTest::addNewSpriteWithCoords(Vec2 p)
|
||||||
_teapot = Sprite3D::create("Sprite3DTest/teapot.c3b");
|
_teapot = Sprite3D::create("Sprite3DTest/teapot.c3b");
|
||||||
_teapot->retain();
|
_teapot->retain();
|
||||||
|
|
||||||
//create and set our custom shader
|
|
||||||
auto shader = GLProgram::createWithFilenames("Sprite3DTest/cube_map.vert", "Sprite3DTest/cube_map.frag");
|
|
||||||
auto state = GLProgramState::create(shader);
|
|
||||||
|
|
||||||
// create the second texture for cylinder
|
// create the second texture for cylinder
|
||||||
_textureCube = TextureCube::create("Sprite3DTest/skybox/left.jpg", "Sprite3DTest/skybox/right.jpg",
|
_textureCube = TextureCube::create("Sprite3DTest/skybox/left.jpg", "Sprite3DTest/skybox/right.jpg",
|
||||||
"Sprite3DTest/skybox/top.jpg", "Sprite3DTest/skybox/bottom.jpg",
|
"Sprite3DTest/skybox/top.jpg", "Sprite3DTest/skybox/bottom.jpg",
|
||||||
|
@ -2452,31 +2318,18 @@ void Sprite3DCubeMapTest::addNewSpriteWithCoords(Vec2 p)
|
||||||
tRepeatParams.wrapT = GL_CLAMP_TO_EDGE;
|
tRepeatParams.wrapT = GL_CLAMP_TO_EDGE;
|
||||||
_textureCube->setTexParameters(tRepeatParams);
|
_textureCube->setTexParameters(tRepeatParams);
|
||||||
|
|
||||||
|
auto mat = Material::createWithFilename("Sprite3DTest/CubeMap.material");
|
||||||
|
auto state = mat->getTechniqueByIndex(0)->getPassByIndex(0)->getGLProgramState();
|
||||||
|
_teapot->setMaterial(mat);
|
||||||
// pass the texture sampler to our custom shader
|
// pass the texture sampler to our custom shader
|
||||||
state->setUniformTexture("u_cubeTex", _textureCube);
|
state->setUniformTexture("u_cubeTex", _textureCube);
|
||||||
|
|
||||||
_teapot->setGLProgramState(state);
|
|
||||||
_teapot->setPosition3D(Vec3(0, -5, 0));
|
_teapot->setPosition3D(Vec3(0, -5, 0));
|
||||||
_teapot->setRotation3D(Vec3(-90, 180, 0));
|
_teapot->setRotation3D(Vec3(-90, 180, 0));
|
||||||
|
|
||||||
auto rotate_action = RotateBy::create(1.5, Vec3(0, 30, 0));
|
auto rotate_action = RotateBy::create(1.5, Vec3(0, 30, 0));
|
||||||
_teapot->runAction(RepeatForever::create(rotate_action));
|
_teapot->runAction(RepeatForever::create(rotate_action));
|
||||||
|
|
||||||
//pass mesh's attribute to shader
|
|
||||||
long offset = 0;
|
|
||||||
auto attributeCount = _teapot->getMesh()->getMeshVertexAttribCount();
|
|
||||||
for (auto i = 0; i < attributeCount; i++)
|
|
||||||
{
|
|
||||||
auto meshattribute = _teapot->getMesh()->getMeshVertexAttribute(i);
|
|
||||||
state->setVertexAttribPointer(s_attributeNames[meshattribute.vertexAttrib],
|
|
||||||
meshattribute.size,
|
|
||||||
meshattribute.type,
|
|
||||||
GL_FALSE,
|
|
||||||
_teapot->getMesh()->getVertexSizeInBytes(),
|
|
||||||
(GLvoid*)offset);
|
|
||||||
|
|
||||||
offset += meshattribute.attribSizeBytes;
|
|
||||||
}
|
|
||||||
addChild(_teapot);
|
addChild(_teapot);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -2490,33 +2343,6 @@ void Sprite3DCubeMapTest::addNewSpriteWithCoords(Vec2 p)
|
||||||
|
|
||||||
addChild(_camera);
|
addChild(_camera);
|
||||||
setCameraMask(2);
|
setCameraMask(2);
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
|
||||||
_backToForegroundListener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND,
|
|
||||||
[this](EventCustom*)
|
|
||||||
{
|
|
||||||
auto state = _teapot->getGLProgramState();
|
|
||||||
auto glProgram = state->getGLProgram();
|
|
||||||
glProgram->reset();
|
|
||||||
glProgram->initWithFilenames("Sprite3DTest/cube_map.vert", "Sprite3DTest/cube_map.frag");
|
|
||||||
glProgram->link();
|
|
||||||
glProgram->updateUniforms();
|
|
||||||
|
|
||||||
_textureCube->reloadTexture();
|
|
||||||
|
|
||||||
Texture2D::TexParams tRepeatParams;
|
|
||||||
tRepeatParams.magFilter = GL_NEAREST;
|
|
||||||
tRepeatParams.minFilter = GL_NEAREST;
|
|
||||||
tRepeatParams.wrapS = GL_CLAMP_TO_EDGE;
|
|
||||||
tRepeatParams.wrapT = GL_CLAMP_TO_EDGE;
|
|
||||||
_textureCube->setTexParameters(tRepeatParams);
|
|
||||||
state->setUniformTexture("u_cubeTex", _textureCube);
|
|
||||||
|
|
||||||
_skyBox->reload();
|
|
||||||
_skyBox->setTexture(_textureCube);
|
|
||||||
});
|
|
||||||
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_backToForegroundListener, 1);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite3DCubeMapTest::onTouchesMoved(const std::vector<Touch*>& touches, cocos2d::Event *event)
|
void Sprite3DCubeMapTest::onTouchesMoved(const std::vector<Touch*>& touches, cocos2d::Event *event)
|
||||||
|
@ -2668,6 +2494,7 @@ Animate3DCallbackTest::Animate3DCallbackTest()
|
||||||
node->setPosition3D(Vec3(mat.m[12] + 100, mat.m[13], mat.m[14]));
|
node->setPosition3D(Vec3(mat.m[12] + 100, mat.m[13], mat.m[14]));
|
||||||
((PUParticleSystem3D*)node)->startParticleSystem();
|
((PUParticleSystem3D*)node)->startParticleSystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
cocos2d::log("frame %d", info->frame);
|
cocos2d::log("frame %d", info->frame);
|
||||||
});
|
});
|
||||||
|
@ -2720,3 +2547,35 @@ std::string Sprite3DTestMeshLight::subtitle() const
|
||||||
{
|
{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Sprite3DVertexColorTest::Sprite3DVertexColorTest()
|
||||||
|
{
|
||||||
|
auto s = Director::getInstance()->getWinSize();
|
||||||
|
|
||||||
|
auto sprite = Sprite3D::create("Sprite3DTest/box_VertexCol.c3t");
|
||||||
|
sprite->setPosition(Vec2(0, 0));
|
||||||
|
sprite->setScale(1.0f);
|
||||||
|
sprite->setCameraMask(2);
|
||||||
|
auto mat = Material::createWithFilename("Sprite3DTest/VertexColor.material");
|
||||||
|
sprite->setMaterial(mat);
|
||||||
|
sprite->runAction(RepeatForever::create(RotateBy::create(1.0f, Vec3(10.0f, 50.0f, 10.0f))));
|
||||||
|
|
||||||
|
this->addChild(sprite);
|
||||||
|
|
||||||
|
//setup camera
|
||||||
|
auto camera = Camera::createPerspective(40, s.width / s.height, 0.01f, 1000.f);
|
||||||
|
camera->setCameraFlag(CameraFlag::USER1);
|
||||||
|
camera->setPosition3D(Vec3(0.0f, 0.0f, 10.f));
|
||||||
|
camera->lookAt(Vec3(0.f, 0.f, 0.f));
|
||||||
|
addChild(camera);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Sprite3DVertexColorTest::title() const
|
||||||
|
{
|
||||||
|
return "Testing Vertex Color";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Sprite3DVertexColorTest::subtitle() const
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
|
@ -592,4 +592,16 @@ protected:
|
||||||
cocos2d::Sprite3D* _sprite;
|
cocos2d::Sprite3D* _sprite;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Sprite3DVertexColorTest : public Sprite3DTestDemo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CREATE_FUNC(Sprite3DVertexColorTest);
|
||||||
|
Sprite3DVertexColorTest();
|
||||||
|
virtual std::string title() const override;
|
||||||
|
virtual std::string subtitle() const override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
cocos2d::Sprite3D* _sprite;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
// A "Material" file can contain one or more materials
|
||||||
|
material BasicToon
|
||||||
|
{
|
||||||
|
technique normal
|
||||||
|
{
|
||||||
|
pass 0
|
||||||
|
{
|
||||||
|
shader
|
||||||
|
{
|
||||||
|
vertexShader = Sprite3DTest/toon.vert
|
||||||
|
fragmentShader = Sprite3DTest/toon.frag
|
||||||
|
|
||||||
|
sampler u_sampler0
|
||||||
|
{
|
||||||
|
path = Sprite3DTest/teapot.png
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
// A "Material" file can contain one or more materials
|
||||||
|
material CubeMap
|
||||||
|
{
|
||||||
|
technique normal
|
||||||
|
{
|
||||||
|
pass 0
|
||||||
|
{
|
||||||
|
shader
|
||||||
|
{
|
||||||
|
vertexShader = Sprite3DTest/cube_map.vert
|
||||||
|
fragmentShader = Sprite3DTest/cube_map.frag
|
||||||
|
// sampler:
|
||||||
|
// responsible for setting the texture and its parameters
|
||||||
|
// the Id of the sampler is the uniform name
|
||||||
|
sampler u_cubeTex
|
||||||
|
{
|
||||||
|
path = Sprite3DTest/skybox/left.jpg
|
||||||
|
wrapS = GL_CLAMP_TO_EDGE
|
||||||
|
wrapT = GL_CLAMP_TO_EDGE
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
// A "Material" file can contain one or more materials
|
||||||
|
material FakeShadow
|
||||||
|
{
|
||||||
|
technique normal
|
||||||
|
{
|
||||||
|
pass 0
|
||||||
|
{
|
||||||
|
shader
|
||||||
|
{
|
||||||
|
vertexShader = Sprite3DTest/simple_shadow.vert
|
||||||
|
fragmentShader = Sprite3DTest/simple_shadow.frag
|
||||||
|
// sampler:
|
||||||
|
// responsible for setting the texture and its parameters
|
||||||
|
// the Id of the sampler is the uniform name
|
||||||
|
sampler u_sampler0
|
||||||
|
{
|
||||||
|
path = Sprite3DTest/plane.png
|
||||||
|
wrapS = REPEAT
|
||||||
|
wrapT = REPEAT
|
||||||
|
}
|
||||||
|
|
||||||
|
sampler u_sampler1
|
||||||
|
{
|
||||||
|
path = Sprite3DTest/shadowCircle.png
|
||||||
|
wrapS = CLAMP_TO_EDGE
|
||||||
|
wrapT = CLAMP_TO_EDGE
|
||||||
|
minFilter = LINEAR
|
||||||
|
magFilter = LINEAR
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
// A "Material" file can contain one or more materials
|
||||||
|
material UVAnimation
|
||||||
|
{
|
||||||
|
technique normal
|
||||||
|
{
|
||||||
|
pass 0
|
||||||
|
{
|
||||||
|
shader
|
||||||
|
{
|
||||||
|
vertexShader = Sprite3DTest/cylinder.vert
|
||||||
|
fragmentShader = Sprite3DTest/cylinder.frag
|
||||||
|
// sampler:
|
||||||
|
// responsible for setting the texture and its parameters
|
||||||
|
// the Id of the sampler is the uniform name
|
||||||
|
sampler u_sampler0
|
||||||
|
{
|
||||||
|
path = Sprite3DTest/dragon.png
|
||||||
|
wrapS = REPEAT
|
||||||
|
wrapT = REPEAT
|
||||||
|
}
|
||||||
|
|
||||||
|
sampler u_sampler1
|
||||||
|
{
|
||||||
|
path = Sprite3DTest/caustics.png
|
||||||
|
wrapS = REPEAT
|
||||||
|
wrapT = REPEAT
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
#ifdef GL_ES
|
||||||
|
precision lowp float;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
varying vec4 v_fragmentColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_FragColor = v_fragmentColor;
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
// A "Material" file can contain one or more materials
|
||||||
|
material VertexColor
|
||||||
|
{
|
||||||
|
technique normal
|
||||||
|
{
|
||||||
|
pass 0
|
||||||
|
{
|
||||||
|
renderState
|
||||||
|
{
|
||||||
|
depthTest = true
|
||||||
|
depthWrite = true
|
||||||
|
}
|
||||||
|
shader
|
||||||
|
{
|
||||||
|
vertexShader = Sprite3DTest/VertexColor.vert
|
||||||
|
fragmentShader = Sprite3DTest/VertexColor.frag
|
||||||
|
// sampler:
|
||||||
|
// responsible for setting the texture and its parameters
|
||||||
|
// the Id of the sampler is the uniform name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
attribute vec4 a_position;
|
||||||
|
attribute vec4 a_color;
|
||||||
|
|
||||||
|
#ifdef GL_ES
|
||||||
|
varying lowp vec4 v_fragmentColor;
|
||||||
|
#else
|
||||||
|
varying vec4 v_fragmentColor;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = CC_MVPMatrix * a_position;
|
||||||
|
v_fragmentColor = a_color;
|
||||||
|
}
|
|
@ -0,0 +1,93 @@
|
||||||
|
{
|
||||||
|
"version": "0.7",
|
||||||
|
"id": "",
|
||||||
|
"meshes": [
|
||||||
|
{
|
||||||
|
"attributes": [{
|
||||||
|
"size": 3,
|
||||||
|
"type": "GL_FLOAT",
|
||||||
|
"attribute": "VERTEX_ATTRIB_POSITION"
|
||||||
|
}, {
|
||||||
|
"size": 3,
|
||||||
|
"type": "GL_FLOAT",
|
||||||
|
"attribute": "VERTEX_ATTRIB_NORMAL"
|
||||||
|
}, {
|
||||||
|
"size": 4,
|
||||||
|
"type": "GL_FLOAT",
|
||||||
|
"attribute": "VERTEX_ATTRIB_COLOR"
|
||||||
|
}],
|
||||||
|
"vertices": [
|
||||||
|
0.500000, -0.500000, -0.500000, 0.000000, 0.000000, -1.000000, 1.000000, 0.000016, 0.000016, 1.000000,
|
||||||
|
-0.500000, -0.500000, -0.500000, 0.000000, 0.000000, -1.000000, 0.000000, 0.000000, 0.000000, 1.000000,
|
||||||
|
0.500000, 0.500000, -0.500000, 0.000000, 0.000000, -1.000000, 1.000000, 0.000054, 1.000000, 1.000000,
|
||||||
|
-0.500000, 0.500000, -0.500000, 0.000000, 0.000000, -1.000000, 0.000047, 0.000047, 1.000000, 1.000000,
|
||||||
|
0.500000, 0.500000, 0.500000, 0.000000, 0.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
|
||||||
|
-0.500000, 0.500000, 0.500000, 0.000000, 0.000000, 1.000000, 0.000207, 1.000000, 1.000000, 1.000000,
|
||||||
|
-0.500000, -0.500000, 0.500000, 0.000000, 0.000000, 1.000000, 0.000001, 1.000000, 0.000001, 1.000000,
|
||||||
|
0.500000, -0.500000, 0.500000, 0.000000, 0.000000, 1.000000, 1.000000, 1.000000, 0.000064, 1.000000,
|
||||||
|
0.500000, -0.500000, 0.500000, 0.000000, -1.000000, 0.000000, 1.000000, 1.000000, 0.000064, 1.000000,
|
||||||
|
-0.500000, -0.500000, 0.500000, 0.000000, -1.000000, 0.000000, 0.000001, 1.000000, 0.000001, 1.000000,
|
||||||
|
-0.500000, -0.500000, -0.500000, 0.000000, -1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000,
|
||||||
|
0.500000, -0.500000, -0.500000, 0.000000, -1.000000, 0.000000, 1.000000, 0.000016, 0.000016, 1.000000,
|
||||||
|
0.500000, 0.500000, 0.500000, 1.000000, 0.000000, 0.000000, 1.000000, 1.000000, 1.000000, 1.000000,
|
||||||
|
0.500000, -0.500000, 0.500000, 1.000000, 0.000000, 0.000000, 1.000000, 1.000000, 0.000064, 1.000000,
|
||||||
|
0.500000, -0.500000, -0.500000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000016, 0.000016, 1.000000,
|
||||||
|
0.500000, 0.500000, -0.500000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000054, 1.000000, 1.000000,
|
||||||
|
-0.500000, 0.500000, 0.500000, 0.000000, 1.000000, 0.000000, 0.000207, 1.000000, 1.000000, 1.000000,
|
||||||
|
0.500000, 0.500000, 0.500000, 0.000000, 1.000000, 0.000000, 1.000000, 1.000000, 1.000000, 1.000000,
|
||||||
|
0.500000, 0.500000, -0.500000, 0.000000, 1.000000, 0.000000, 1.000000, 0.000054, 1.000000, 1.000000,
|
||||||
|
-0.500000, 0.500000, -0.500000, 0.000000, 1.000000, 0.000000, 0.000047, 0.000047, 1.000000, 1.000000,
|
||||||
|
-0.500000, -0.500000, 0.500000, -1.000000, 0.000000, 0.000000, 0.000001, 1.000000, 0.000001, 1.000000,
|
||||||
|
-0.500000, 0.500000, 0.500000, -1.000000, 0.000000, 0.000000, 0.000207, 1.000000, 1.000000, 1.000000,
|
||||||
|
-0.500000, 0.500000, -0.500000, -1.000000, 0.000000, 0.000000, 0.000047, 0.000047, 1.000000, 1.000000,
|
||||||
|
-0.500000, -0.500000, -0.500000, -1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000
|
||||||
|
],
|
||||||
|
"parts": [
|
||||||
|
{
|
||||||
|
"id": "shape1_part1",
|
||||||
|
"type": "TRIANGLES",
|
||||||
|
"indices": [
|
||||||
|
0, 1, 2, 1, 3, 2, 4, 5, 6, 4, 6, 7,
|
||||||
|
8, 9, 10, 8, 10, 11, 12, 13, 14, 12, 14, 15,
|
||||||
|
16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23
|
||||||
|
],
|
||||||
|
"aabb": [-0.500000, -0.500000, -0.500000, 0.500000, 0.500000, 0.500000]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"materials": [
|
||||||
|
{
|
||||||
|
"id": "01 - Default",
|
||||||
|
"ambient": [ 0.588235, 0.588235, 0.588235],
|
||||||
|
"diffuse": [ 0.588235, 0.588235, 0.588235],
|
||||||
|
"emissive": [ 0.000000, 0.000000, 0.000000],
|
||||||
|
"opacity": 1.000000,
|
||||||
|
"specular": [ 0.900000, 0.900000, 0.900000],
|
||||||
|
"shininess": 2.000000,
|
||||||
|
"textures": [
|
||||||
|
{
|
||||||
|
"id": "Map #1",
|
||||||
|
"filename": "win",
|
||||||
|
"type": "DIFFUSE",
|
||||||
|
"wrapModeU": "REPEAT",
|
||||||
|
"wrapModeV": "REPEAT"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"id": "Box001",
|
||||||
|
"skeleton": false,
|
||||||
|
"transform": [ 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, -1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000],
|
||||||
|
"parts": [
|
||||||
|
{
|
||||||
|
"meshpartid": "shape1_part1",
|
||||||
|
"materialid": "01 - Default"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"animations": []
|
||||||
|
}
|
|
@ -7,10 +7,11 @@ varying vec2 v_texture_coord;
|
||||||
uniform vec4 u_color;
|
uniform vec4 u_color;
|
||||||
uniform float offset;
|
uniform float offset;
|
||||||
uniform float duration;
|
uniform float duration;
|
||||||
uniform sampler2D caustics;
|
uniform sampler2D u_sampler0;
|
||||||
|
uniform sampler2D u_sampler1;
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
vec4 color = duration*vec4(0,0.8,0.4,1.0);
|
vec4 color = duration*vec4(0,0.8,0.4,1.0);
|
||||||
//blend two texture
|
//blend two texture
|
||||||
gl_FragColor = u_color*texture2D(CC_Texture0, vec2(v_texture_coord.x- 2.0 * offset,v_texture_coord.y)) * vec4(0.3,0.3,0.3,1)+texture2D(caustics,vec2(v_texture_coord.x-offset,v_texture_coord.y)).r*color;
|
gl_FragColor = u_color*texture2D(u_sampler0, vec2(v_texture_coord.x- 2.0 * offset,v_texture_coord.y)) * vec4(0.3,0.3,0.3,1)+texture2D(u_sampler1,vec2(v_texture_coord.x-offset,v_texture_coord.y)).r*color;
|
||||||
}
|
}
|
|
@ -5,7 +5,8 @@ varying mediump vec4 v_position;
|
||||||
varying vec2 v_texture_coord;
|
varying vec2 v_texture_coord;
|
||||||
varying vec4 v_position;
|
varying vec4 v_position;
|
||||||
#endif
|
#endif
|
||||||
uniform sampler2D u_shadowTexture;
|
uniform sampler2D u_sampler0;
|
||||||
|
uniform sampler2D u_sampler1;
|
||||||
uniform vec3 u_target_pos;
|
uniform vec3 u_target_pos;
|
||||||
uniform vec4 u_color;
|
uniform vec4 u_color;
|
||||||
void main(void)
|
void main(void)
|
||||||
|
@ -18,5 +19,5 @@ void main(void)
|
||||||
coord.x = dot(v_position.xyz - u_target_pos, UVector) + 0.5;
|
coord.x = dot(v_position.xyz - u_target_pos, UVector) + 0.5;
|
||||||
coord.y = dot(v_position.xyz - u_target_pos, VVector) + 0.5;
|
coord.y = dot(v_position.xyz - u_target_pos, VVector) + 0.5;
|
||||||
|
|
||||||
gl_FragColor = u_color*texture2D(CC_Texture0,v_texture_coord)*texture2D(u_shadowTexture,coord);
|
gl_FragColor = u_color*texture2D(u_sampler0,v_texture_coord)*texture2D(u_sampler1,coord);
|
||||||
}
|
}
|
|
@ -4,6 +4,7 @@ varying mediump vec2 v_texture_coord;
|
||||||
varying vec2 v_texture_coord;
|
varying vec2 v_texture_coord;
|
||||||
#endif
|
#endif
|
||||||
uniform vec4 u_color;
|
uniform vec4 u_color;
|
||||||
|
uniform sampler2D u_sampler0;
|
||||||
varying vec3 v_normal;
|
varying vec3 v_normal;
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
|
@ -12,7 +13,7 @@ void main(void)
|
||||||
vec3 light_color = vec3(1,1,1);
|
vec3 light_color = vec3(1,1,1);
|
||||||
vec3 normal = normalize(v_normal);
|
vec3 normal = normalize(v_normal);
|
||||||
float diffuse_factor = dot(normal,-light_direction);
|
float diffuse_factor = dot(normal,-light_direction);
|
||||||
vec4 diffuse_color = texture2D(CC_Texture0,v_texture_coord);
|
vec4 diffuse_color = texture2D(u_sampler0,v_texture_coord);
|
||||||
|
|
||||||
if (diffuse_factor > 0.95) diffuse_factor=1.0;
|
if (diffuse_factor > 0.95) diffuse_factor=1.0;
|
||||||
else if (diffuse_factor > 0.75) diffuse_factor = 0.8;
|
else if (diffuse_factor > 0.75) diffuse_factor = 0.8;
|
||||||
|
|
Loading…
Reference in New Issue