From cc6e2077f48b073b68e59f8165e414a9192b02a3 Mon Sep 17 00:00:00 2001 From: songchengjiang Date: Wed, 2 Sep 2015 16:30:24 +0800 Subject: [PATCH] replace custom shaders by material files add Sprite3DVertexColorTest --- .../Classes/Sprite3DTest/Sprite3DTest.cpp | 239 ++++-------------- .../Classes/Sprite3DTest/Sprite3DTest.h | 12 + .../Resources/Sprite3DTest/BasicToon.material | 20 ++ .../Resources/Sprite3DTest/CubeMap.material | 25 ++ .../Sprite3DTest/FakeShadow.material | 33 +++ .../Sprite3DTest/UVAnimation.material | 31 +++ .../Resources/Sprite3DTest/VertexColor.frag | 10 + .../Sprite3DTest/VertexColor.material | 23 ++ .../Resources/Sprite3DTest/VertexColor.vert | 14 + .../Resources/Sprite3DTest/box_VertexCol.c3t | 93 +++++++ .../Resources/Sprite3DTest/cylinder.frag | 5 +- .../Resources/Sprite3DTest/simple_shadow.frag | 5 +- .../Resources/Sprite3DTest/toon.frag | 3 +- 13 files changed, 318 insertions(+), 195 deletions(-) create mode 100644 tests/cpp-tests/Resources/Sprite3DTest/BasicToon.material create mode 100644 tests/cpp-tests/Resources/Sprite3DTest/CubeMap.material create mode 100644 tests/cpp-tests/Resources/Sprite3DTest/FakeShadow.material create mode 100644 tests/cpp-tests/Resources/Sprite3DTest/UVAnimation.material create mode 100644 tests/cpp-tests/Resources/Sprite3DTest/VertexColor.frag create mode 100644 tests/cpp-tests/Resources/Sprite3DTest/VertexColor.material create mode 100644 tests/cpp-tests/Resources/Sprite3DTest/VertexColor.vert create mode 100644 tests/cpp-tests/Resources/Sprite3DTest/box_VertexCol.c3t diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp index 3996b8587c..82ab5734ed 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp @@ -61,6 +61,7 @@ Sprite3DTests::Sprite3DTests() ADD_TEST_CASE(Sprite3DClippingTest); ADD_TEST_CASE(Sprite3DTestMeshLight); ADD_TEST_CASE(Animate3DCallbackTest); + ADD_TEST_CASE(Sprite3DVertexColorTest); }; //------------------------------------------------------------------ @@ -231,38 +232,9 @@ Sprite3DUVAnimationTest::Sprite3DUVAnimationTest() //create cylinder auto cylinder = Sprite3D::create("Sprite3DTest/cylinder.c3b"); - - //create and set our custom shader - auto shader =GLProgram::createWithFilenames("Sprite3DTest/cylinder.vert","Sprite3DTest/cylinder.frag"); - _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); + auto mat = Material::createWithFilename("Sprite3DTest/UVAnimation.material"); + _state = mat->getTechniqueByIndex(0)->getPassByIndex(0)->getGLProgramState(); + cylinder->setMaterial(mat); this->addChild(cylinder); @@ -275,31 +247,6 @@ Sprite3DUVAnimationTest::Sprite3DUVAnimationTest() //the callback function update cylinder's texcoord 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() @@ -368,35 +315,11 @@ Sprite3DFakeShadowTest::Sprite3DFakeShadowTest() _plane = Sprite3D::create("Sprite3DTest/plane.c3t"); _plane->setRotation3D(Vec3(90,0,0)); - // use custom shader - auto shader =GLProgram::createWithFilenames("Sprite3DTest/simple_shadow.vert","Sprite3DTest/simple_shadow.frag"); - _state = GLProgramState::create(shader); - _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; - } + auto mat = Material::createWithFilename("Sprite3DTest/FakeShadow.material"); + _state = mat->getTechniqueByIndex(0)->getPassByIndex(0)->getGLProgramState(); + _plane->setMaterial(mat); _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); //create the orc @@ -405,38 +328,12 @@ Sprite3DFakeShadowTest::Sprite3DFakeShadowTest() _orc->setRotation3D(Vec3(0,180,0)); _orc->setPosition3D(Vec3(0,0,10)); _targetPos = _orc->getPosition3D(); - _plane->getGLProgramState()->setUniformVec3("u_target_pos",_orc->getPosition3D()); + _state->setUniformVec3("u_target_pos", _orc->getPosition3D()); layer->addChild(_orc); layer->addChild(_camera); layer->setCameraMask(2); 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() @@ -520,7 +417,7 @@ void Sprite3DFakeShadowTest::move3D(float elapsedTime) offset.x=offset.x; offset.z=offset.z; //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) @@ -616,44 +513,17 @@ Sprite3DBasicToonShaderTest::Sprite3DBasicToonShaderTest() _camera->setCameraFlag(CameraFlag::USER1); // create a teapot auto teapot = Sprite3D::create("Sprite3DTest/teapot.c3b"); - //create and set our custom shader - auto shader =GLProgram::createWithFilenames("Sprite3DTest/toon.vert","Sprite3DTest/toon.frag"); - _state = GLProgramState::create(shader); - teapot->setGLProgramState(_state); + auto mat = Material::createWithFilename("Sprite3DTest/BasicToon.material"); + _state = mat->getTechniqueByIndex(0)->getPassByIndex(0)->getGLProgramState(); + teapot->setMaterial(mat); + teapot->setPosition3D(Vec3(0,-5,-20)); teapot->setRotation3D(Vec3(-90,180,0)); auto rotate_action = RotateBy::create(1.5,Vec3(0,30,0)); 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(_camera); 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() @@ -2433,10 +2303,6 @@ void Sprite3DCubeMapTest::addNewSpriteWithCoords(Vec2 p) _teapot = Sprite3D::create("Sprite3DTest/teapot.c3b"); _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 _textureCube = TextureCube::create("Sprite3DTest/skybox/left.jpg", "Sprite3DTest/skybox/right.jpg", "Sprite3DTest/skybox/top.jpg", "Sprite3DTest/skybox/bottom.jpg", @@ -2452,31 +2318,18 @@ void Sprite3DCubeMapTest::addNewSpriteWithCoords(Vec2 p) tRepeatParams.wrapT = GL_CLAMP_TO_EDGE; _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 state->setUniformTexture("u_cubeTex", _textureCube); - _teapot->setGLProgramState(state); _teapot->setPosition3D(Vec3(0, -5, 0)); _teapot->setRotation3D(Vec3(-90, 180, 0)); auto rotate_action = RotateBy::create(1.5, Vec3(0, 30, 0)); _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); { @@ -2490,33 +2343,6 @@ void Sprite3DCubeMapTest::addNewSpriteWithCoords(Vec2 p) addChild(_camera); 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& touches, cocos2d::Event *event) @@ -2668,6 +2494,7 @@ Animate3DCallbackTest::Animate3DCallbackTest() node->setPosition3D(Vec3(mat.m[12] + 100, mat.m[13], mat.m[14])); ((PUParticleSystem3D*)node)->startParticleSystem(); } + cocos2d::log("frame %d", info->frame); }); @@ -2720,3 +2547,35 @@ std::string Sprite3DTestMeshLight::subtitle() const { 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 ""; +} diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h index 9a8cca3ef1..f5c0cffb58 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h @@ -592,4 +592,16 @@ protected: 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 diff --git a/tests/cpp-tests/Resources/Sprite3DTest/BasicToon.material b/tests/cpp-tests/Resources/Sprite3DTest/BasicToon.material new file mode 100644 index 0000000000..5613575f5a --- /dev/null +++ b/tests/cpp-tests/Resources/Sprite3DTest/BasicToon.material @@ -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 + } + } + } + } +} diff --git a/tests/cpp-tests/Resources/Sprite3DTest/CubeMap.material b/tests/cpp-tests/Resources/Sprite3DTest/CubeMap.material new file mode 100644 index 0000000000..6721945771 --- /dev/null +++ b/tests/cpp-tests/Resources/Sprite3DTest/CubeMap.material @@ -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 + } + + } + } + } +} diff --git a/tests/cpp-tests/Resources/Sprite3DTest/FakeShadow.material b/tests/cpp-tests/Resources/Sprite3DTest/FakeShadow.material new file mode 100644 index 0000000000..73e677a2cd --- /dev/null +++ b/tests/cpp-tests/Resources/Sprite3DTest/FakeShadow.material @@ -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 + } + } + } + } +} diff --git a/tests/cpp-tests/Resources/Sprite3DTest/UVAnimation.material b/tests/cpp-tests/Resources/Sprite3DTest/UVAnimation.material new file mode 100644 index 0000000000..a9a2a62184 --- /dev/null +++ b/tests/cpp-tests/Resources/Sprite3DTest/UVAnimation.material @@ -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 + } + } + } + } +} diff --git a/tests/cpp-tests/Resources/Sprite3DTest/VertexColor.frag b/tests/cpp-tests/Resources/Sprite3DTest/VertexColor.frag new file mode 100644 index 0000000000..eefb336b47 --- /dev/null +++ b/tests/cpp-tests/Resources/Sprite3DTest/VertexColor.frag @@ -0,0 +1,10 @@ +#ifdef GL_ES +precision lowp float; +#endif + +varying vec4 v_fragmentColor; + +void main() +{ + gl_FragColor = v_fragmentColor; +} \ No newline at end of file diff --git a/tests/cpp-tests/Resources/Sprite3DTest/VertexColor.material b/tests/cpp-tests/Resources/Sprite3DTest/VertexColor.material new file mode 100644 index 0000000000..655ceb5951 --- /dev/null +++ b/tests/cpp-tests/Resources/Sprite3DTest/VertexColor.material @@ -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 + } + } + } +} diff --git a/tests/cpp-tests/Resources/Sprite3DTest/VertexColor.vert b/tests/cpp-tests/Resources/Sprite3DTest/VertexColor.vert new file mode 100644 index 0000000000..0c6d4f6796 --- /dev/null +++ b/tests/cpp-tests/Resources/Sprite3DTest/VertexColor.vert @@ -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; +} \ No newline at end of file diff --git a/tests/cpp-tests/Resources/Sprite3DTest/box_VertexCol.c3t b/tests/cpp-tests/Resources/Sprite3DTest/box_VertexCol.c3t new file mode 100644 index 0000000000..1b7b66afce --- /dev/null +++ b/tests/cpp-tests/Resources/Sprite3DTest/box_VertexCol.c3t @@ -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": [] +} \ No newline at end of file diff --git a/tests/cpp-tests/Resources/Sprite3DTest/cylinder.frag b/tests/cpp-tests/Resources/Sprite3DTest/cylinder.frag index c971705dfd..e931b01277 100644 --- a/tests/cpp-tests/Resources/Sprite3DTest/cylinder.frag +++ b/tests/cpp-tests/Resources/Sprite3DTest/cylinder.frag @@ -7,10 +7,11 @@ varying vec2 v_texture_coord; uniform vec4 u_color; uniform float offset; uniform float duration; -uniform sampler2D caustics; +uniform sampler2D u_sampler0; +uniform sampler2D u_sampler1; void main(void) { vec4 color = duration*vec4(0,0.8,0.4,1.0); //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; } \ No newline at end of file diff --git a/tests/cpp-tests/Resources/Sprite3DTest/simple_shadow.frag b/tests/cpp-tests/Resources/Sprite3DTest/simple_shadow.frag index 917a8a73ab..f97d183f86 100644 --- a/tests/cpp-tests/Resources/Sprite3DTest/simple_shadow.frag +++ b/tests/cpp-tests/Resources/Sprite3DTest/simple_shadow.frag @@ -5,7 +5,8 @@ varying mediump vec4 v_position; varying vec2 v_texture_coord; varying vec4 v_position; #endif -uniform sampler2D u_shadowTexture; +uniform sampler2D u_sampler0; +uniform sampler2D u_sampler1; uniform vec3 u_target_pos; uniform vec4 u_color; void main(void) @@ -18,5 +19,5 @@ void main(void) coord.x = dot(v_position.xyz - u_target_pos, UVector) + 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); } \ No newline at end of file diff --git a/tests/cpp-tests/Resources/Sprite3DTest/toon.frag b/tests/cpp-tests/Resources/Sprite3DTest/toon.frag index aa412d1adf..0bd9be19e7 100644 --- a/tests/cpp-tests/Resources/Sprite3DTest/toon.frag +++ b/tests/cpp-tests/Resources/Sprite3DTest/toon.frag @@ -4,6 +4,7 @@ varying mediump vec2 v_texture_coord; varying vec2 v_texture_coord; #endif uniform vec4 u_color; +uniform sampler2D u_sampler0; varying vec3 v_normal; void main(void) { @@ -12,7 +13,7 @@ void main(void) vec3 light_color = vec3(1,1,1); vec3 normal = normalize(v_normal); 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; else if (diffuse_factor > 0.75) diffuse_factor = 0.8;