void DebugRenderer::RenderSceneDebugSprites(Camera* camera) { SpriteRenderer::Get()->Begin(SpriteSortMode::BackToFront); BoundingFrustum cameraFrustum(camera->GetView() * camera->GetProjection()); Vector2f lightSpriteSize(20.0f, 20.0f); const vector<AmbientLight*> ambientLights = SceneManager::Get()->GetAmbientLights(); for(auto it = begin(ambientLights); it != end(ambientLights); ++it) { AmbientLight* light = *it; if (cameraFrustum.Contains(light->GetCenter())) { Vector2f screenPos = light->GetCenter().Project(Matrix::Identity, camera->GetView(), camera->GetProjection(), camera->GetViewport()); F32 priority = Vector3f::Distance(camera->GetPosition(), light->GetCenter()) / 1000.0f; SpriteRenderer::Get()->Render(screenPos + lightSpriteSize, screenPos - lightSpriteSize, ResourceManager::Get()->LoadTextureResource("Icons\\ambient_light.png")->GetTexture(), priority); } } const vector<PointLight*> pointLights = SceneManager::Get()->GetPointLights(); for(auto it = begin(pointLights); it != end(pointLights); ++it) { PointLight* light = *it; if (cameraFrustum.Contains(light->GetCenter())) { Vector2f screenPos = light->GetCenter().Project(Matrix::Identity, camera->GetView(), camera->GetProjection(), camera->GetViewport()); F32 priority = Vector3f::Distance(camera->GetPosition(), light->GetCenter()) / 1000.0f; SpriteRenderer::Get()->Render(screenPos + lightSpriteSize, screenPos - lightSpriteSize, ResourceManager::Get()->LoadTextureResource("Icons\\point_light.png")->GetTexture(), priority); } } const vector<DirectionalLight*> directionalLight = SceneManager::Get()->GetDirectionalLights(); for(auto it = begin(directionalLight); it != end(directionalLight); ++it) { DirectionalLight* light = *it; if (cameraFrustum.Contains(light->GetCenter())) { Vector2f screenPos = light->GetCenter().Project(Matrix::Identity, camera->GetView(), camera->GetProjection(), camera->GetViewport()); F32 priority = Vector3f::Distance(camera->GetPosition(), light->GetCenter()) / 1000.0f; SpriteRenderer::Get()->Render(screenPos + lightSpriteSize, screenPos - lightSpriteSize, ResourceManager::Get()->LoadTextureResource("Icons\\directional_light.png")->GetTexture(), priority); } } const vector<SpotLight*> spotLights = SceneManager::Get()->GetSpotLights(); for(auto it = begin(spotLights); it != end(spotLights); ++it) { SpotLight* light = *it; if (cameraFrustum.Contains(light->GetCenter())) { Vector2f screenPos = light->GetCenter().Project(Matrix::Identity, camera->GetView(), camera->GetProjection(), camera->GetViewport()); F32 priority = Vector3f::Distance(camera->GetPosition(), light->GetCenter()) / 1000.0f; SpriteRenderer::Get()->Render(screenPos + lightSpriteSize, screenPos - lightSpriteSize, ResourceManager::Get()->LoadTextureResource("Icons\\spot_light.png")->GetTexture(), priority); } } SpriteRenderer::Get()->End(camera); }
void GameNode3DReader::setPropsWithFlatBuffers(cocos2d::Node *node, const flatbuffers::Table* node3DOptions) { auto options = (GameNode3DOption*)node3DOptions; std::string name = options->name()->c_str(); node->setName(name); _sceneBrushInstance = nullptr; bool skyBoxEnabled = options->skyBoxEnabled() != 0; if (skyBoxEnabled) { std::string leftFileData = options->leftFileData()->path()->c_str(); std::string rightFileData = options->rightFileData()->path()->c_str(); std::string upFileData = options->upFileData()->path()->c_str(); std::string downFileData = options->downFileData()->path()->c_str(); std::string forwardFileData = options->forwardFileData()->path()->c_str(); std::string backFileData = options->backFileData()->path()->c_str(); FileUtils *fileUtils = FileUtils::getInstance(); if (fileUtils->isFileExist(leftFileData) && fileUtils->isFileExist(rightFileData) && fileUtils->isFileExist(upFileData) && fileUtils->isFileExist(downFileData) && fileUtils->isFileExist(forwardFileData) && fileUtils->isFileExist(backFileData)) { _sceneBrushInstance = CameraBackgroundSkyBoxBrush::create(leftFileData, rightFileData, upFileData, downFileData, forwardFileData, backFileData); } } std::string customProperty = options->customProperty()->c_str(); ComExtensionData* extensionData = ComExtensionData::create(); extensionData->setCustomProperty(customProperty); if (node->getComponent(ComExtensionData::COMPONENT_NAME)) { node->removeComponent(ComExtensionData::COMPONENT_NAME); } node->addComponent(extensionData); bool useDefaultLight = options->useDefaultLight(); if (useDefaultLight) { AmbientLight* defaultLight = AmbientLight::create(Color3B::WHITE); defaultLight->setIntensity(0.5f); node->addChild(defaultLight); } }
void NormalMappingDelegate::onInit() { scene = new Scene(); this->move_forward=false; this->move_backward=false; this->move_left=false; this->move_right=false; this->move_up = false; this->move_down = false; scene->setRenderType (DEFERRED_SHADING); AmbientLight * ambient = scene->getAmbientLight (); ambient->setColor (QVector3D(1,1,1)); ambient->setIntensity (0.5); auto sprite = new Sprite(); sprite->setTexture (TexturePool::getInstance ()->createOrGetTexture ("./res/texture/mygame/fps/cross_hair.png")); sprite->setCamera (scene->guiCamera ()); sprite->setPos (QVector3D(1024/2-sprite->texture ()->width ()/2,768/2-sprite->texture ()->height ()/2,0)); scene->root ()->addChild (sprite); scene->setCamera (&camera); //set this scene as current scene scene->setAsCurrentScene(); scene->root ()->addChild (&camera); //create a box auto the_box = new Entity("./res/model/box/box.obj"); the_box->setShaderProgram (ShaderPool::getInstance ()->get ("deferred")); //set it's normal map the_box->getMesh (0)->getMaterial ()->setNormalMap (TexturePool::getInstance ()->createOrGetTexture ("./res/model/box/bricks_normal.jpg")); the_box->setCamera (&camera); scene->root ()->addChild (the_box); //this sample we don't use shadow the_box->setIsEnableShadow (false); the_box->onUpdate = [](Node* target){ target->setRotation (target->rotation ()+QVector3D(0,0.1,0)); }; //then add a Directional light auto directional_light = scene->getDirectionalLight (); directional_light->setIntensity (1); directional_light->setColor (QVector3D(1,1,1)); directional_light->setDirection (QVector3D(0,0,-1)); }
void LoadLight(TiXmlElement *element) { Light *light = NULL; // name const char* name = element->Attribute("name"); printf("Light ["); if ( name ) printf("%s",name); printf("]"); // type const char* type = element->Attribute("type"); if ( type ) { if ( COMPARE(type,"ambient") ) { printf(" - Ambient\n"); AmbientLight *l = new AmbientLight(); light = l; for ( TiXmlElement *child = element->FirstChildElement(); child!=NULL; child = child->NextSiblingElement() ) { if ( COMPARE( child->Value(), "intensity" ) ) { Color c(1,1,1); ReadColor( child, c ); l->SetIntensity(c); printf(" intensity %f %f %f\n",c.r,c.g,c.b); } } } else if ( COMPARE(type,"direct") ) { printf(" - Direct\n"); DirectLight *l = new DirectLight(); light = l; for ( TiXmlElement *child = element->FirstChildElement(); child!=NULL; child = child->NextSiblingElement() ) { if ( COMPARE( child->Value(), "intensity" ) ) { Color c(1,1,1); ReadColor( child, c ); l->SetIntensity(c); printf(" intensity %f %f %f\n",c.r,c.g,c.b); } else if ( COMPARE( child->Value(), "direction" ) ) { Point3 v(1,1,1); ReadVector( child, v ); l->SetDirection(v); printf(" direction %f %f %f\n",v.x,v.y,v.z); } } } else if ( COMPARE(type,"point") ) { printf(" - Point\n"); PointLight *l = new PointLight(); light = l; for ( TiXmlElement *child = element->FirstChildElement(); child!=NULL; child = child->NextSiblingElement() ) { if ( COMPARE( child->Value(), "intensity" ) ) { Color c(1,1,1); ReadColor( child, c ); l->SetIntensity(c); printf(" intensity %f %f %f\n",c.r,c.g,c.b); } else if ( COMPARE( child->Value(), "position" ) ) { Point3 v(0,0,0); ReadVector( child, v ); l->SetPosition(v); printf(" position %f %f %f\n",v.x,v.y,v.z); } } } else { printf(" - UNKNOWN\n"); } } if ( light ) { light->SetName(name); lights.push_back(light); } }
void NormalMappingDelegate::onInit() { scene = new Scene(); this->move_forward=false; this->move_backward=false; this->move_left=false; this->move_right=false; this->move_up = false; this->move_down = false; scene->setRenderType (DEFERRED_SHADING); AmbientLight * ambient = scene->getAmbientLight (); ambient->setColor (QVector3D(1,1,1)); ambient->setIntensity (0.5); auto sprite = new Sprite(); sprite->setTexture (TexturePool::getInstance ()->createOrGetTexture ("./res/texture/mygame/fps/cross_hair.png")); sprite->setCamera (scene->guiCamera ()); sprite->setPos (QVector3D(1024/2-sprite->texture ()->width ()/2,768/2-sprite->texture ()->height ()/2,0)); scene->root ()->addChild (sprite); scene->setCamera (&camera); //set this scene as current scene scene->setAsCurrentScene(); scene->root ()->addChild (&camera); //create a box auto the_head = new Entity("./res/model/scan_head/Infinite-Level_02.obj",Entity::LoadPolicy::LoadFromLoader); the_head->setShaderProgram (ShaderPool::getInstance ()->get ("deferred")); the_head->scale (30,30,30); //set it's normal map auto material = the_head->getMesh (0)->getMaterial (); material->setNormalMap (TexturePool::getInstance ()->createOrGetTexture ("./res/model/scan_head/Infinite-Level_02_Tangent_SmoothUV.jpg")); the_head->setCamera (&camera); //this sample we don't use shadow the_head->setIsEnableShadow (false); //bob auto the_bob2 = new Entity("./res/model/bob/boblampclean.md5mesh",Entity::LoadPolicy::LoadFromLoader); the_bob2->setShaderProgram (ShaderPool::getInstance ()->get ("deferred")); the_bob2->setCamera (&camera); the_bob2->setPos (QVector3D(-2,0,-10)); the_bob2->setRotation (QVector3D(-90,0,0)); scene->root ()->addChild (the_bob2); the_bob2->setIsEnableShadow (false); the_bob2->scale (0.05,0.05,0.05); the_bob2->getSkeleton ()->getEntityNodeRoot ()->findNode ("lamp")->addChild (the_head); //this sample we don't use shadow the_bob2->setIsEnableShadow (false); the_bob2->onRender = [](Entity * self, float dt){ self->playAnimate (0,self->animateTime ()+ 0.02); }; auto the_orc = new Entity("./res/model/orc/orc.FBX",Entity::LoadPolicy::LoadFromLoader); the_orc->setShaderProgram (ShaderPool::getInstance ()->get ("deferred")); the_orc->setCamera (&camera); the_orc->setRotation (QVector3D(0,180,0)); the_orc->setScalling (QVector3D(0.1,0.1,0.1)); the_orc->setPos (QVector3D(0,0,-10)); scene->root ()->addChild (the_orc); the_orc->onRender = [](Entity * self, float dt){ self->playAnimate (0,self->animateTime () + 0.02); }; auto the_orc_axe = new Entity("./res/model/orc/axe.FBX",Entity::LoadPolicy::LoadFromLoader); the_orc_axe->setShaderProgram (ShaderPool::getInstance ()->get ("deferred")); the_orc_axe->setCamera (&camera); the_orc->getSkeleton ()->getEntityNodeRoot ()->findNode ("Bip001 R Hand")->addChild (the_orc_axe); //then add a Directional light auto directional_light = scene->getDirectionalLight (); directional_light->setIntensity (1); directional_light->setColor (QVector3D(1,1,1)); directional_light->setDirection (QVector3D(0,0,-1)); }
void CSMDelegate::onInit() { scene = new Scene(); this->move_forward=false; this->move_backward=false; this->move_left=false; this->move_right=false; this->move_up = false; this->move_down = false; AmbientLight * ambient = scene->getAmbientLight (); ambient->setColor (QVector3D(1,1,1)); ambient->setIntensity (0.5); auto sprite = new Sprite(); sprite->setTexture (TexturePool::getInstance ()->createOrGetTexture ("./res/texture/mygame/fps/cross_hair.png")); sprite->setCamera (scene->guiCamera ()); sprite->setPos (QVector3D(1024/2-sprite->texture ()->width ()/2,768/2-sprite->texture ()->height ()/2,0)); scene->root ()->addChild (sprite); scene->setCamera (&camera); SkyBox * sky_box = new SkyBox("./res/texture/sky_box/right.jpg", "./res/texture/sky_box/left.jpg", "./res/texture/sky_box/top.jpg", "./res/texture/sky_box/bottom.jpg", "./res/texture/sky_box/front.jpg", "./res/texture/sky_box/back.jpg"); sky_box->setCamera(&camera); scene->setSkyBox(sky_box); //set this scene as current scene scene->setAsCurrentScene(); scene->root ()->addChild (&camera); camera.setPos (QVector3D(0,15,0)); camera.setRotation (QVector3D(-60,0,0)); Terrain a("./res/model/terrain/terrain.jpg"); auto terrain_model = new Entity(); terrain_model->setName ("terrain"); terrain_model->setCamera(&camera); terrain_model->setShaderProgram (ShaderPool::getInstance()->get ("deferred")); a.mesh ()->getMaterial ()->getDiffuse ()->texture= TexturePool::getInstance ()->createOrGetTexture ("./res/model/terrain/sand.jpg"); terrain_model->addMesh(a.mesh ()); terrain_model->scale (10,10,10); terrain_model->setPos (QVector3D(0,-1,0)); scene->root ()->addChild (terrain_model); for(int i = 0; i< 5; i++) { auto flight = new Entity("./res/model/spaceship/phoenix_ugv.md2"); flight->setCamera (&camera); flight->setShaderProgram (ShaderPool::getInstance()->get ("deferred")); flight->setScalling (QVector3D(0.05,0.05,0.05)); scene->root ()->addChild (flight); //flight->setIsEnableShadow (false); flight->setPos (QVector3D((rand()%5)*2,3,-2*i)); } /* auto spotLight = scene->createSpotLight (); spotLight->setIntensity (1); spotLight->setColor (QVector3D(0,1,1)); spotLight->setDirection (QVector3D(-1,-1,0)); spotLight->setPos (QVector3D(10,10,-4)); spotLight->setOutterAngle (35); spotLight->setAngle (20); spotLight->setRange (40); */ //then add a Directional light auto directional_light = scene->getDirectionalLight (); directional_light->setIntensity (0.5); directional_light->setColor (QVector3D(1,1,1)); directional_light->setDirection (QVector3D(-1,-1,0)); }