diff --git a/cocos/3d/CCSprite3D.cpp b/cocos/3d/CCSprite3D.cpp index e8890cc0c0..48992ac6e3 100644 --- a/cocos/3d/CCSprite3D.cpp +++ b/cocos/3d/CCSprite3D.cpp @@ -979,7 +979,10 @@ static GLProgramState* getGLProgramStateForAttribs(MeshVertexData* meshVertexDat } else { - shader = GLProgram::SHADER_3D_POSITION; + if (hasNormal && usesLight) + shader = GLProgram::SHADER_3D_POSITION_NORMAL; + else + shader = GLProgram::SHADER_3D_POSITION; } CCASSERT(shader, "Couldn't find shader for sprite"); diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp index 5aecd29462..6613cb3819 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp @@ -57,6 +57,7 @@ Sprite3DTests::Sprite3DTests() ADD_TEST_CASE(NodeAnimationTest); ADD_TEST_CASE(Issue9767); ADD_TEST_CASE(Sprite3DClippingTest); + ADD_TEST_CASE(Sprite3DTestMeshLight); }; //------------------------------------------------------------------ @@ -2616,3 +2617,35 @@ std::string Sprite3DClippingTest::subtitle() const { return ""; } + +Sprite3DTestMeshLight::Sprite3DTestMeshLight() +{ + auto s = Director::getInstance()->getWinSize(); + + auto _sprite = Sprite3D::create("Sprite3DTest/mesh_model.c3b"); + _sprite->setPosition(Vec2(0, 0)); + _sprite->setScale(0.05f); + _sprite->setCameraMask(2); + + PointLight * light = PointLight::create(Vec3(0, 0, 400), Color3B(255, 255, 255), 1000.0f); + + //setup camera + auto camera = Camera::createPerspective(40, s.width / s.height, 0.01f, 1000.f); + camera->setCameraFlag(CameraFlag::USER1); + camera->setPosition3D(Vec3(0.f, 30.f, 100.f)); + camera->lookAt(Vec3(0.f, 0.f, 0.f)); + addChild(camera); + + addChild(_sprite); + addChild(light); +} + +std::string Sprite3DTestMeshLight::title() const +{ + return "3D mesh with light without texture"; +} + +std::string Sprite3DTestMeshLight::subtitle() const +{ + return ""; +} \ No newline at end of file diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h index 17079ce4a2..eaf8695e34 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h @@ -567,4 +567,16 @@ public: virtual std::string subtitle() const override; }; +class Sprite3DTestMeshLight : public Sprite3DTestDemo +{ +public: + CREATE_FUNC(Sprite3DTestMeshLight); + Sprite3DTestMeshLight(); + 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/mesh_model.c3b b/tests/cpp-tests/Resources/Sprite3DTest/mesh_model.c3b new file mode 100644 index 0000000000..50f51efac0 Binary files /dev/null and b/tests/cpp-tests/Resources/Sprite3DTest/mesh_model.c3b differ