void AtmosphericScatteringApp::OnCreate() { font_ = SyncLoadFont("gkai00mp.kfont"); this->LookAt(float3(0, 0, -4.0f), float3(0, 0, 0), float3(0, 1, 0)); this->Proj(0.01f, 500.0f); obj_controller_.AttachCamera(this->ActiveCamera()); obj_controller_.Scalers(0.003f, 0.003f); light_ctrl_camera_.ViewParams(float3(0, 0, 0), float3(1, 0, 0), float3(0, -1, 0)); light_controller_.AttachCamera(light_ctrl_camera_); light_controller_.Scalers(0.003f, 0.003f); RenderModelPtr model_planet = SyncLoadModel("geosphere.7z//geosphere.meshml", EAH_GPU_Read | EAH_Immutable, CreateModelFactory<RenderModel>(), CreateMeshFactory<PlanetMesh>()); planet_ = MakeSharedPtr<SceneObjectHelper>(model_planet->Subrenderable(0), SceneObjectHelper::SOA_Cullable); planet_->AddToSceneManager(); RenderModelPtr model_atmosphere = SyncLoadModel("geosphere.7z//geosphere.meshml", EAH_GPU_Read | EAH_Immutable, CreateModelFactory<RenderModel>(), CreateMeshFactory<AtmosphereMesh>()); atmosphere_ = MakeSharedPtr<SceneObjectHelper>(model_atmosphere->Subrenderable(0), SceneObjectHelper::SOA_Cullable); atmosphere_->AddToSceneManager(); UIManager::Instance().Load(ResLoader::Instance().Open("AtmosphericScattering.uiml")); dialog_param_ = UIManager::Instance().GetDialog("AtmosphericScattering"); id_atmosphere_top_ = dialog_param_->IDFromName("atmosphere_top"); id_density_ = dialog_param_->IDFromName("density"); id_beta_button_ = dialog_param_->IDFromName("beta_button"); id_absorb_button_ = dialog_param_->IDFromName("absorb_button"); dialog_param_->Control<UISlider>(id_atmosphere_top_)->OnValueChangedEvent().connect(KlayGE::bind(&AtmosphericScatteringApp::AtmosphereTopHandler, this, KlayGE::placeholders::_1)); this->AtmosphereTopHandler(*(dialog_param_->Control<UISlider>(id_atmosphere_top_))); dialog_param_->Control<UISlider>(id_density_)->OnValueChangedEvent().connect(KlayGE::bind(&AtmosphericScatteringApp::DensityHandler, this, KlayGE::placeholders::_1)); this->DensityHandler(*(dialog_param_->Control<UISlider>(id_density_))); dialog_param_->Control<UITexButton>(id_beta_button_)->OnClickedEvent().connect(KlayGE::bind(&AtmosphericScatteringApp::ChangeBetaHandler, this, KlayGE::placeholders::_1)); dialog_param_->Control<UITexButton>(id_absorb_button_)->OnClickedEvent().connect(KlayGE::bind(&AtmosphericScatteringApp::ChangeAbsorbHandler, this, KlayGE::placeholders::_1)); this->LoadBeta(Color(38.05f, 82.36f, 214.65f, 1)); this->LoadAbsorb(Color(0.75f, 0.85f, 1, 1)); sun_light_ = MakeSharedPtr<DirectionalLightSource>(); sun_light_->Attrib(0); sun_light_->Color(float3(1, 1, 1)); sun_light_->AddToSceneManager(); sun_light_src_ = MakeSharedPtr<SceneObjectLightSourceProxy>(sun_light_); checked_pointer_cast<SceneObjectLightSourceProxy>(sun_light_src_)->Scaling(0.1f, 0.1f, 0.1f); //sun_light_src_->AddToSceneManager(); InputEngine& inputEngine(Context::Instance().InputFactoryInstance().InputEngineInstance()); InputActionMap actionMap; actionMap.AddActions(actions, actions + sizeof(actions) / sizeof(actions[0])); action_handler_t input_handler = MakeSharedPtr<input_signal>(); input_handler->connect(KlayGE::bind(&AtmosphericScatteringApp::InputHandler, this, KlayGE::placeholders::_1, KlayGE::placeholders::_2)); inputEngine.ActionMap(actionMap, input_handler); }
void JudaTexViewer::OnCreate() { RenderFactory& rf = Context::Instance().RenderFactoryInstance(); font_ = SyncLoadFont("gkai00mp.kfont"); tile_pos_vb_ = rf.MakeVertexBuffer(BU_Dynamic, EAH_GPU_Read | EAH_CPU_Write, nullptr); tile_ = MakeSharedPtr<TileObject>(); tile_->AddToSceneManager(); checked_pointer_cast<TileObject>(tile_)->SetPosBuffer(tile_pos_vb_); grid_border_ = MakeSharedPtr<GridBorderObject>(); grid_border_->AddToSceneManager(); checked_pointer_cast<GridBorderObject>(grid_border_)->SetPosBuffer(tile_pos_vb_); this->OpenJudaTex("klayge_logo.jdt"); InputEngine& inputEngine(Context::Instance().InputFactoryInstance().InputEngineInstance()); InputActionMap actionMap; actionMap.AddActions(actions, actions + sizeof(actions) / sizeof(actions[0])); action_handler_t input_handler = MakeSharedPtr<input_signal>(); input_handler->connect(std::bind(&JudaTexViewer::InputHandler, this, std::placeholders::_1, std::placeholders::_2)); inputEngine.ActionMap(actionMap, input_handler); UIManager::Instance().Load(ResLoader::Instance().Open("JudaTexViewer.uiml")); dialog_ = UIManager::Instance().GetDialogs()[0]; id_open_ = dialog_->IDFromName("Open"); dialog_->Control<UIButton>(id_open_)->OnClickedEvent().connect(std::bind(&JudaTexViewer::OpenHandler, this, std::placeholders::_1)); }
void RasterizationOrderApp::OnCreate() { font_ = SyncLoadFont("gkai00mp.kfont"); render_quad_ = MakeSharedPtr<RenderQuad>(); RenderFactory& rf = Context::Instance().RenderFactoryInstance(); ras_order_fb_ = rf.MakeFrameBuffer(); copy_pp_ = SyncLoadPostProcess("Copy.ppml", "bilinear_copy"); InputEngine& inputEngine(Context::Instance().InputFactoryInstance().InputEngineInstance()); InputActionMap actionMap; actionMap.AddActions(actions, actions + std::size(actions)); action_handler_t input_handler = MakeSharedPtr<input_signal>(); input_handler->connect(std::bind(&RasterizationOrderApp::InputHandler, this, std::placeholders::_1, std::placeholders::_2)); inputEngine.ActionMap(actionMap, input_handler); UIManager::Instance().Load(ResLoader::Instance().Open("RasterizationOrder.uiml")); dialog_params_ = UIManager::Instance().GetDialog("Parameters"); id_color_map_ = dialog_params_->IDFromName("ColorMap"); id_capture_ = dialog_params_->IDFromName("Capture"); dialog_params_->Control<UICheckBox>(id_color_map_)->OnChangedEvent().connect( std::bind(&RasterizationOrderApp::ColorMapHandler, this, std::placeholders::_1)); this->ColorMapHandler(*dialog_params_->Control<UICheckBox>(id_color_map_)); dialog_params_->Control<UIButton>(id_capture_)->OnClickedEvent().connect( std::bind(&RasterizationOrderApp::CaptureHandler, this, std::placeholders::_1)); }
void JudaTexViewer::OnCreate() { font_ = SyncLoadFont("gkai00mp.kfont"); tile_ = MakeSharedPtr<TileObject>(); tile_->AddToSceneManager(); grid_border_ = MakeSharedPtr<GridBorderObject>(); grid_border_->AddToSceneManager(); this->OpenJudaTex("klayge_logo.jdt"); InputEngine& inputEngine(Context::Instance().InputFactoryInstance().InputEngineInstance()); InputActionMap actionMap; actionMap.AddActions(actions, actions + sizeof(actions) / sizeof(actions[0])); action_handler_t input_handler = MakeSharedPtr<input_signal>(); input_handler->connect(std::bind(&JudaTexViewer::InputHandler, this, std::placeholders::_1, std::placeholders::_2)); inputEngine.ActionMap(actionMap, input_handler); UIManager::Instance().Load(ResLoader::Instance().Open("JudaTexViewer.uiml")); dialog_ = UIManager::Instance().GetDialogs()[0]; id_open_ = dialog_->IDFromName("Open"); dialog_->Control<UIButton>(id_open_)->OnClickedEvent().connect(std::bind(&JudaTexViewer::OpenHandler, this, std::placeholders::_1)); }
void Refract::InitObjects() { font_ = SyncLoadFont("gkai00mp.kfont"); y_cube_map_ = SyncLoadTexture("uffizi_cross_y.dds", EAH_GPU_Read | EAH_Immutable); c_cube_map_ = SyncLoadTexture("uffizi_cross_c.dds", EAH_GPU_Read | EAH_Immutable); refractor_ = MakeSharedPtr<RefractorObject>(y_cube_map_, c_cube_map_); refractor_->AddToSceneManager(); sky_box_ = MakeSharedPtr<SceneObjectSkyBox>(0); checked_pointer_cast<SceneObjectSkyBox>(sky_box_)->CompressedCubeMap(y_cube_map_, c_cube_map_); sky_box_->AddToSceneManager(); RenderFactory& rf = Context::Instance().RenderFactoryInstance(); RenderEngine& re = rf.RenderEngineInstance(); this->LookAt(float3(0.36f, 0.11f, -0.39f), float3(0, 0.11f, 0)); this->Proj(0.05f, 100); fpcController_.AttachCamera(this->ActiveCamera()); fpcController_.Scalers(0.05f, 0.05f); InputEngine& inputEngine(Context::Instance().InputFactoryInstance().InputEngineInstance()); InputActionMap actionMap; actionMap.AddActions(actions, actions + sizeof(actions) / sizeof(actions[0])); action_handler_t input_handler = MakeSharedPtr<input_signal>(); input_handler->connect(KlayGE::bind(&Refract::InputHandler, this, KlayGE::placeholders::_1, KlayGE::placeholders::_2)); inputEngine.ActionMap(actionMap, input_handler); if (rf.RenderEngineInstance().DeviceCaps().texture_format_support(EF_D16)) { depth_texture_support_ = true; } else { depth_texture_support_ = false; } backface_buffer_ = rf.MakeFrameBuffer(); FrameBufferPtr const & screen_buffer = re.CurFrameBuffer(); backface_buffer_->GetViewport()->camera = screen_buffer->GetViewport()->camera; if (!depth_texture_support_) { backface_depth_buffer_ = rf.MakeFrameBuffer(); backface_depth_buffer_->GetViewport()->camera = screen_buffer->GetViewport()->camera; } UIManager::Instance().Load(ResLoader::Instance().Open("Refract.uiml")); }
void TessellationApp::OnCreate() { font_ = SyncLoadFont("gkai00mp.kfont"); polygon_ = MakeSharedPtr<TriangleObject>(); polygon_->ModelMatrix(MathLib::rotation_x(-0.5f)); polygon_->AddToSceneManager(); this->LookAt(float3(2, 0, -2), float3(0, 0, 0)); this->Proj(0.1f, 100); InputEngine& inputEngine(Context::Instance().InputFactoryInstance().InputEngineInstance()); InputActionMap actionMap; actionMap.AddActions(actions, actions + sizeof(actions) / sizeof(actions[0])); action_handler_t input_handler = MakeSharedPtr<input_signal>(); input_handler->connect(std::bind(&TessellationApp::InputHandler, this, std::placeholders::_1, std::placeholders::_2)); inputEngine.ActionMap(actionMap, input_handler); UIManager::Instance().Load(ResLoader::Instance().Open("Tessellation.uiml")); dialog_ = UIManager::Instance().GetDialogs()[0]; id_tess_enabled_ = dialog_->IDFromName("Tessellation"); id_edge0_static_ = dialog_->IDFromName("Edge0Static"); id_edge0_slider_ = dialog_->IDFromName("Edge0Slider"); id_edge1_static_ = dialog_->IDFromName("Edge1Static"); id_edge1_slider_ = dialog_->IDFromName("Edge1Slider"); id_edge2_static_ = dialog_->IDFromName("Edge2Static"); id_edge2_slider_ = dialog_->IDFromName("Edge2Slider"); id_inside_static_ = dialog_->IDFromName("InsideStatic"); id_inside_slider_ = dialog_->IDFromName("InsideSlider"); dialog_->Control<UICheckBox>(id_tess_enabled_)->OnChangedEvent().connect(std::bind(&TessellationApp::TessellationOnHandler, this, std::placeholders::_1)); this->TessellationOnHandler(*dialog_->Control<UICheckBox>(id_tess_enabled_)); dialog_->Control<UISlider>(id_edge0_slider_)->OnValueChangedEvent().connect(std::bind(&TessellationApp::Edge0ChangedHandler, this, std::placeholders::_1)); this->Edge0ChangedHandler(*dialog_->Control<UISlider>(id_edge0_slider_)); dialog_->Control<UISlider>(id_edge1_slider_)->OnValueChangedEvent().connect(std::bind(&TessellationApp::Edge1ChangedHandler, this, std::placeholders::_1)); this->Edge1ChangedHandler(*dialog_->Control<UISlider>(id_edge1_slider_)); dialog_->Control<UISlider>(id_edge2_slider_)->OnValueChangedEvent().connect(std::bind(&TessellationApp::Edge2ChangedHandler, this, std::placeholders::_1)); this->Edge2ChangedHandler(*dialog_->Control<UISlider>(id_edge2_slider_)); dialog_->Control<UISlider>(id_inside_slider_)->OnValueChangedEvent().connect(std::bind(&TessellationApp::InsideChangedHandler, this, std::placeholders::_1)); this->InsideChangedHandler(*dialog_->Control<UISlider>(id_inside_slider_)); RenderDeviceCaps const & caps = Context::Instance().RenderFactoryInstance().RenderEngineInstance().DeviceCaps(); if (!caps.ds_support) { dialog_->Control<UICheckBox>(id_tess_enabled_)->SetEnabled(false); } }
void SoundApp::OnCreate() { font_ = SyncLoadFont("gkai00mp.kfont"); this->LookAt(float3(-0.3f, 0.4f, -0.3f), float3(0, 0, 0)); this->Proj(0.01f, 100); InputEngine& inputEngine(Context::Instance().InputFactoryInstance().InputEngineInstance()); InputActionMap actionMap; actionMap.AddActions(actions, actions + std::size(actions)); action_handler_t input_handler = MakeSharedPtr<input_signal>(); input_handler->connect(std::bind(&SoundApp::InputHandler, this, std::placeholders::_1, std::placeholders::_2)); inputEngine.ActionMap(actionMap, input_handler); AudioDataSourceFactory& adsf = Context::Instance().AudioDataSourceFactoryInstance(); music_1_ = adsf.MakeAudioDataSource(); music_1_->Open(ResLoader::Instance().Open("Carl_Douglas_-_Kung_Fu_Fighting.ogg")); music_2_ = adsf.MakeAudioDataSource(); music_2_->Open(ResLoader::Instance().Open("Metallica_-_Enter_Sandman.ogg")); sound_ = adsf.MakeAudioDataSource(); sound_->Open(ResLoader::Instance().Open("Cash_register.ogg")); AudioFactory& af = Context::Instance().AudioFactoryInstance(); AudioEngine& ae = af.AudioEngineInstance(); ae.AddBuffer(1, af.MakeMusicBuffer(music_1_, 3)); ae.AddBuffer(2, af.MakeMusicBuffer(music_2_, 3)); ae.AddBuffer(3, af.MakeSoundBuffer(sound_)); UIManager::Instance().Load(ResLoader::Instance().Open("Sound.uiml")); dialog_ = UIManager::Instance().GetDialogs()[0]; id_music_1_ = dialog_->IDFromName("Music_1"); id_music_2_ = dialog_->IDFromName("Music_2"); id_sound_ = dialog_->IDFromName("Sound"); id_volume_static_ = dialog_->IDFromName("VolumeStatic"); id_volume_slider_ = dialog_->IDFromName("VolumeSlider"); dialog_->Control<UICheckBox>(id_music_1_)->OnChangedEvent().connect(std::bind(&SoundApp::Music1Handler, this, std::placeholders::_1)); this->Music1Handler(*dialog_->Control<UICheckBox>(id_music_1_)); dialog_->Control<UICheckBox>(id_music_2_)->OnChangedEvent().connect(std::bind(&SoundApp::Music2Handler, this, std::placeholders::_1)); this->Music2Handler(*dialog_->Control<UICheckBox>(id_music_2_)); dialog_->Control<UIButton>(id_sound_)->OnClickedEvent().connect(std::bind(&SoundApp::SoundHandler, this, std::placeholders::_1)); dialog_->Control<UISlider>(id_volume_slider_)->OnValueChangedEvent().connect(std::bind(&SoundApp::VolumeChangedHandler, this, std::placeholders::_1)); this->VolumeChangedHandler(*dialog_->Control<UISlider>(id_volume_slider_)); }
void Fractal::OnCreate() { font_ = SyncLoadFont("gkai00mp.kfont"); renderFractal_ = MakeSharedPtr<RenderFractal>(); InputEngine& inputEngine(Context::Instance().InputFactoryInstance().InputEngineInstance()); InputActionMap actionMap; actionMap.AddActions(actions, actions + sizeof(actions) / sizeof(actions[0])); action_handler_t input_handler = MakeSharedPtr<input_signal>(); input_handler->connect(std::bind(&Fractal::InputHandler, this, std::placeholders::_1, std::placeholders::_2)); inputEngine.ActionMap(actionMap, input_handler); UIManager::Instance().Load(ResLoader::Instance().Open("Fractal.uiml")); }
void DistanceMapping::OnCreate() { font_ = SyncLoadFont("gkai00mp.kfont"); polygon_ = MakeSharedPtr<PolygonObject>(); polygon_->ModelMatrix(MathLib::rotation_x(-0.5f)); polygon_->AddToSceneManager(); this->LookAt(float3(2, 0, -2), float3(0, 0, 0)); this->Proj(0.1f, 100); fpcController_.RequiresLeftButtonDown(true); fpcController_.AttachCamera(this->ActiveCamera()); fpcController_.Scalers(0.05f, 0.1f); light_ = MakeSharedPtr<PointLightSource>(); light_->Attrib(0); light_->Color(float3(2, 2, 2)); light_->Falloff(float3(1, 0, 1.0f)); light_->Position(float3(1, 0, -1)); light_->BindUpdateFunc(PointLightSourceUpdate()); light_->AddToSceneManager(); light_proxy_ = MakeSharedPtr<SceneObjectLightSourceProxy>(light_); checked_pointer_cast<SceneObjectLightSourceProxy>(light_proxy_)->Scaling(0.05f, 0.05f, 0.05f); light_proxy_->AddToSceneManager(); checked_pointer_cast<PolygonObject>(polygon_)->LightFalloff(light_->Falloff()); InputEngine& inputEngine(Context::Instance().InputFactoryInstance().InputEngineInstance()); InputActionMap actionMap; actionMap.AddActions(actions, actions + sizeof(actions) / sizeof(actions[0])); action_handler_t input_handler = MakeSharedPtr<input_signal>(); input_handler->connect(KlayGE::bind(&DistanceMapping::InputHandler, this, KlayGE::placeholders::_1, KlayGE::placeholders::_2)); inputEngine.ActionMap(actionMap, input_handler); UIManager::Instance().Load(ResLoader::Instance().Open("DistanceMapping.uiml")); }
void VideoTextureApp::InitObjects() { font_ = SyncLoadFont("gkai00mp.kfont"); this->LookAt(float3(-0.2f, 0.3f, -0.2f), float3(0, 0, 0)); this->Proj(0.01f, 100); fpcController_.AttachCamera(this->ActiveCamera()); fpcController_.Scalers(0.05f, 0.1f); light_ = MakeSharedPtr<PointLightSource>(); light_->Attrib(0); light_->Color(float3(2, 2, 2)); light_->Falloff(float3(1, 0, 1.0f)); light_->Position(float3(0.25f, 0.5f, -1.0f)); light_->AddToSceneManager(); light_proxy_ = MakeSharedPtr<SceneObjectLightSourceProxy>(light_); checked_pointer_cast<SceneObjectLightSourceProxy>(light_proxy_)->Scaling(0.01f, 0.01f, 0.01f); light_proxy_->AddToSceneManager(); InputEngine& inputEngine(Context::Instance().InputFactoryInstance().InputEngineInstance()); InputActionMap actionMap; actionMap.AddActions(actions, actions + sizeof(actions) / sizeof(actions[0])); action_handler_t input_handler = MakeSharedPtr<input_signal>(); input_handler->connect(KlayGE::bind(&VideoTextureApp::InputHandler, this, KlayGE::placeholders::_1, KlayGE::placeholders::_2)); inputEngine.ActionMap(actionMap, input_handler); ground_ = MakeSharedPtr<TeapotObject>(); ground_->AddToSceneManager(); ShowEngine& se = Context::Instance().ShowFactoryInstance().ShowEngineInstance(); se.Load(ResLoader::Instance().Locate("big_buck_bunny.avi")); se.Play(); UIManager::Instance().Load(ResLoader::Instance().Open("VideoTexture.uiml")); }
void SSSSSApp::OnCreate() { KlayGE::function<RenderablePtr()> sponza_model_ml = ASyncLoadModel("ScifiRoom.7z//ScifiRoom.meshml", EAH_GPU_Read | EAH_Immutable); KlayGE::function<RenderablePtr()> sss_model_ml = ASyncLoadModel("Infinite-Level_02.meshml", EAH_GPU_Read | EAH_Immutable, CreateModelFactory<RenderModel>(), CreateMeshFactory<SSSMesh>()); KlayGE::function<TexturePtr()> c_cube_tl = ASyncLoadTexture("Lake_CraterLake03_filtered_c.dds", EAH_GPU_Read | EAH_Immutable); KlayGE::function<TexturePtr()> y_cube_tl = ASyncLoadTexture("Lake_CraterLake03_filtered_y.dds", EAH_GPU_Read | EAH_Immutable); font_ = SyncLoadFont("gkai00mp.kfont"); deferred_rendering_ = Context::Instance().DeferredRenderingLayerInstance(); deferred_rendering_->SSVOEnabled(0, false); this->LookAt(float3(0.5f, 5, -0.5f), float3(0, 5, 0)); this->Proj(0.05f, 200.0f); AmbientLightSourcePtr ambient_light = MakeSharedPtr<AmbientLightSource>(); ambient_light->SkylightTex(y_cube_tl, c_cube_tl); ambient_light->Color(float3(0.3f, 0.3f, 0.3f)); ambient_light->AddToSceneManager(); light_ = MakeSharedPtr<SpotLightSource>(); light_->Attrib(0); light_->Color(float3(5.0f, 5.0f, 5.0f)); light_->Falloff(float3(1, 1, 0)); light_->Position(float3(0, 0, -2)); light_->Direction(float3(0, 0, 1)); light_->OuterAngle(PI / 6); light_->InnerAngle(PI / 8); light_->AddToSceneManager(); light_proxy_ = MakeSharedPtr<SceneObjectLightSourceProxy>(light_); checked_pointer_cast<SceneObjectLightSourceProxy>(light_proxy_)->Scaling(0.1f, 0.1f, 0.1f); light_proxy_->AddToSceneManager(); RenderEngine& re = Context::Instance().RenderFactoryInstance().RenderEngineInstance(); scene_camera_ = re.DefaultFrameBuffer()->GetViewport()->camera; obj_controller_.AttachCamera(*scene_camera_); obj_controller_.Scalers(0.01f, 0.005f); light_camera_ = MakeSharedPtr<Camera>(); light_controller_.AttachCamera(*light_camera_); light_controller_.Scalers(0.01f, 0.005f); light_camera_->ViewParams(light_->SMCamera(0)->EyePos(), light_->SMCamera(0)->LookAt(), light_->SMCamera(0)->UpVec()); light_camera_->ProjParams(light_->SMCamera(0)->FOV(), light_->SMCamera(0)->Aspect(), light_->SMCamera(0)->NearPlane(), light_->SMCamera(0)->FarPlane()); InputEngine& inputEngine(Context::Instance().InputFactoryInstance().InputEngineInstance()); InputActionMap actionMap; actionMap.AddActions(actions, actions + sizeof(actions) / sizeof(actions[0])); action_handler_t input_handler = MakeSharedPtr<input_signal>(); input_handler->connect(KlayGE::bind(&SSSSSApp::InputHandler, this, KlayGE::placeholders::_1, KlayGE::placeholders::_2)); inputEngine.ActionMap(actionMap, input_handler); UIManager::Instance().Load(ResLoader::Instance().Open("SSSSS.uiml")); dialog_params_ = UIManager::Instance().GetDialog("Parameters"); id_sss_ = dialog_params_->IDFromName("SSS"); id_sss_strength_static_ = dialog_params_->IDFromName("SSSStrengthStatic"); id_sss_strength_slider_ = dialog_params_->IDFromName("SSSStrengthSlider"); id_sss_correction_static_ = dialog_params_->IDFromName("SSSCorrectionStatic"); id_sss_correction_slider_ = dialog_params_->IDFromName("SSSCorrectionSlider"); id_translucency_ = dialog_params_->IDFromName("Translucency"); id_translucency_strength_static_ = dialog_params_->IDFromName("TranslucencyStrengthStatic"); id_translucency_strength_slider_ = dialog_params_->IDFromName("TranslucencyStrengthSlider"); dialog_params_->Control<UICheckBox>(id_sss_)->OnChangedEvent().connect(KlayGE::bind(&SSSSSApp::SSSHandler, this, KlayGE::placeholders::_1)); this->SSSHandler(*dialog_params_->Control<UICheckBox>(id_sss_)); dialog_params_->Control<UISlider>(id_sss_strength_slider_)->OnValueChangedEvent().connect(KlayGE::bind(&SSSSSApp::SSSStrengthChangedHandler, this, KlayGE::placeholders::_1)); this->SSSStrengthChangedHandler(*dialog_params_->Control<UISlider>(id_sss_strength_slider_)); dialog_params_->Control<UISlider>(id_sss_correction_slider_)->OnValueChangedEvent().connect(KlayGE::bind(&SSSSSApp::SSSCorrectionChangedHandler, this, KlayGE::placeholders::_1)); this->SSSCorrectionChangedHandler(*dialog_params_->Control<UISlider>(id_sss_correction_slider_)); dialog_params_->Control<UICheckBox>(id_translucency_)->OnChangedEvent().connect(KlayGE::bind(&SSSSSApp::TranslucencyHandler, this, KlayGE::placeholders::_1)); this->TranslucencyHandler(*dialog_params_->Control<UICheckBox>(id_translucency_)); dialog_params_->Control<UISlider>(id_translucency_strength_slider_)->OnValueChangedEvent().connect(KlayGE::bind(&SSSSSApp::TranslucencyStrengthChangedHandler, this, KlayGE::placeholders::_1)); this->TranslucencyStrengthChangedHandler(*dialog_params_->Control<UISlider>(id_translucency_strength_slider_)); SceneObjectPtr subsurface_obj = MakeSharedPtr<SceneObjectHelper>(sss_model_ml, SceneObject::SOA_Cullable, 0); subsurface_obj->ModelMatrix(MathLib::translation(0.0f, 5.0f, 0.0f)); subsurface_obj->AddToSceneManager(); SceneObjectPtr scene_obj = MakeSharedPtr<SceneObjectHelper>(sponza_model_ml, SceneObject::SOA_Cullable, 0); scene_obj->AddToSceneManager(); SceneObjectSkyBoxPtr sky_box = MakeSharedPtr<SceneObjectSkyBox>(); sky_box->CompressedCubeMap(y_cube_tl, c_cube_tl); sky_box->AddToSceneManager(); }
void GlobalIlluminationApp::OnCreate() { this->LookAt(float3(-14.5f, 18, -3), float3(-13.6f, 17.55f, -2.8f)); this->Proj(0.1f, 500.0f); TexturePtr c_cube = ASyncLoadTexture("Lake_CraterLake03_filtered_c.dds", EAH_GPU_Read | EAH_Immutable); TexturePtr y_cube = ASyncLoadTexture("Lake_CraterLake03_filtered_y.dds", EAH_GPU_Read | EAH_Immutable); RenderablePtr scene_model = ASyncLoadModel("sponza_crytek.7z//sponza_crytek.meshml", EAH_GPU_Read | EAH_Immutable); font_ = SyncLoadFont("gkai00mp.kfont"); deferred_rendering_ = Context::Instance().DeferredRenderingLayerInstance(); AmbientLightSourcePtr ambient_light = MakeSharedPtr<AmbientLightSource>(); ambient_light->SkylightTex(y_cube, c_cube); ambient_light->Color(float3(0.1f, 0.1f, 0.1f)); ambient_light->AddToSceneManager(); spot_light_ = MakeSharedPtr<SpotLightSource>(); spot_light_->Attrib(LightSource::LSA_IndirectLighting); spot_light_->Position(float3(0, 12, -4.8f)); spot_light_->Direction(float3(0, 0, 1)); spot_light_->Color(float3(6.0f, 5.88f, 4.38f)); spot_light_->Falloff(float3(1, 0.1f, 0)); spot_light_->OuterAngle(PI / 4); spot_light_->InnerAngle(PI / 6); spot_light_->BindUpdateFunc(SpotLightSourceUpdate()); spot_light_->AddToSceneManager(); spot_light_src_ = MakeSharedPtr<SceneObjectLightSourceProxy>(spot_light_); checked_pointer_cast<SceneObjectLightSourceProxy>(spot_light_src_)->Scaling(0.1f, 0.1f, 0.1f); spot_light_src_->AddToSceneManager(); SceneObjectPtr scene_obj = MakeSharedPtr<SceneObjectHelper>(scene_model, SceneObject::SOA_Cullable); scene_obj->AddToSceneManager(); fpcController_.Scalers(0.05f, 0.5f); InputEngine& inputEngine(Context::Instance().InputFactoryInstance().InputEngineInstance()); InputActionMap actionMap; actionMap.AddActions(actions, actions + sizeof(actions) / sizeof(actions[0])); action_handler_t input_handler = MakeSharedPtr<input_signal>(); input_handler->connect(std::bind(&GlobalIlluminationApp::InputHandler, this, std::placeholders::_1, std::placeholders::_2)); inputEngine.ActionMap(actionMap, input_handler); UIManager::Instance().Load(ResLoader::Instance().Open("GlobalIllumination.uiml")); dialog_ = UIManager::Instance().GetDialogs()[0]; id_illum_combo_ = dialog_->IDFromName("IllumCombo"); id_il_scale_static_ = dialog_->IDFromName("ILScaleStatic"); id_il_scale_slider_ = dialog_->IDFromName("ILScaleSlider"); id_ssgi_ = dialog_->IDFromName("SSGI"); id_ssvo_ = dialog_->IDFromName("SSVO"); id_hdr_ = dialog_->IDFromName("HDR"); id_aa_ = dialog_->IDFromName("AA"); id_cg_ = dialog_->IDFromName("CG"); id_ctrl_camera_ = dialog_->IDFromName("CtrlCamera"); dialog_->Control<UIComboBox>(id_illum_combo_)->OnSelectionChangedEvent().connect(std::bind(&GlobalIlluminationApp::IllumChangedHandler, this, std::placeholders::_1)); this->IllumChangedHandler(*dialog_->Control<UIComboBox>(id_illum_combo_)); dialog_->Control<UISlider>(id_il_scale_slider_)->SetValue(static_cast<int>(il_scale_ * 10)); dialog_->Control<UISlider>(id_il_scale_slider_)->OnValueChangedEvent().connect(std::bind(&GlobalIlluminationApp::ILScaleChangedHandler, this, std::placeholders::_1)); this->ILScaleChangedHandler(*dialog_->Control<UISlider>(id_il_scale_slider_)); dialog_->Control<UICheckBox>(id_ssgi_)->OnChangedEvent().connect(std::bind(&GlobalIlluminationApp::SSGIHandler, this, std::placeholders::_1)); this->SSGIHandler(*dialog_->Control<UICheckBox>(id_ssgi_)); dialog_->Control<UICheckBox>(id_ssvo_)->OnChangedEvent().connect(std::bind(&GlobalIlluminationApp::SSVOHandler, this, std::placeholders::_1)); this->SSVOHandler(*dialog_->Control<UICheckBox>(id_ssvo_)); dialog_->Control<UICheckBox>(id_hdr_)->OnChangedEvent().connect(std::bind(&GlobalIlluminationApp::HDRHandler, this, std::placeholders::_1)); this->HDRHandler(*dialog_->Control<UICheckBox>(id_hdr_)); dialog_->Control<UICheckBox>(id_aa_)->OnChangedEvent().connect(std::bind(&GlobalIlluminationApp::AAHandler, this, std::placeholders::_1)); this->AAHandler(*dialog_->Control<UICheckBox>(id_aa_)); dialog_->Control<UICheckBox>(id_cg_)->OnChangedEvent().connect(std::bind(&GlobalIlluminationApp::ColorGradingHandler, this, std::placeholders::_1)); this->ColorGradingHandler(*dialog_->Control<UICheckBox>(id_cg_)); dialog_->Control<UICheckBox>(id_ctrl_camera_)->OnChangedEvent().connect(std::bind(&GlobalIlluminationApp::CtrlCameraHandler, this, std::placeholders::_1)); sky_box_ = MakeSharedPtr<SceneObjectSkyBox>(); checked_pointer_cast<SceneObjectSkyBox>(sky_box_)->CompressedCubeMap(y_cube, c_cube); sky_box_->AddToSceneManager(); }
void ScreenSpaceReflectionApp::OnCreate() { RenderFactory& rf = Context::Instance().RenderFactoryInstance(); loading_percentage_ = 0; c_cube_ = ASyncLoadTexture("Lake_CraterLake03_filtered_c.dds", EAH_GPU_Read | EAH_Immutable); y_cube_ = ASyncLoadTexture("Lake_CraterLake03_filtered_y.dds", EAH_GPU_Read | EAH_Immutable); teapot_model_ = ASyncLoadModel("teapot.meshml", EAH_GPU_Read | EAH_Immutable, CreateModelFactory<RenderModel>(), CreateMeshFactory<ReflectMesh>()); RenderablePtr dino_model = ASyncLoadModel("dino50.7z//dino50.meshml", EAH_GPU_Read | EAH_Immutable, CreateModelFactory<RenderModel>(), CreateMeshFactory<DinoMesh>()); this->LookAt(float3(2.0f, 2.0f, -5.0f), float3(0.0f, 1.0f, 0.0f), float3(0, 1, 0)); this->Proj(0.1f, 500.0f); tb_controller_.AttachCamera(this->ActiveCamera()); tb_controller_.Scalers(0.003f, 0.05f); screen_camera_path_ = LoadCameraPath(ResLoader::Instance().Open("Reflection.cam_path")); screen_camera_path_->AttachCamera(this->ActiveCamera()); this->ActiveCamera().AddToSceneManager(); AmbientLightSourcePtr ambient_light = MakeSharedPtr<AmbientLightSource>(); ambient_light->SkylightTex(y_cube_, c_cube_); ambient_light->Color(float3(0.1f, 0.1f, 0.1f)); ambient_light->AddToSceneManager(); point_light_ = MakeSharedPtr<PointLightSource>(); point_light_->Attrib(LightSource::LSA_NoShadow); point_light_->Color(float3(1, 1, 1)); point_light_->Position(float3(0, 3, -2)); point_light_->Falloff(float3(1, 0, 0.3f)); point_light_->AddToSceneManager(); SceneObjectPtr scene_obj = MakeSharedPtr<SceneObjectHelper>(dino_model, SceneObject::SOA_Cullable); scene_obj->ModelMatrix(MathLib::scaling(float3(2, 2, 2)) * MathLib::translation(0.0f, 1.0f, -2.5f)); scene_obj->AddToSceneManager(); deferred_rendering_ = Context::Instance().DeferredRenderingLayerInstance(); font_ = SyncLoadFont("gkai00mp.kfont"); sky_box_ = MakeSharedPtr<SceneObjectSkyBox>(); sky_box_->AddToSceneManager(); back_refl_fb_ = rf.MakeFrameBuffer(); InputEngine& inputEngine(Context::Instance().InputFactoryInstance().InputEngineInstance()); InputActionMap actionMap; actionMap.AddActions(actions, actions + sizeof(actions) / sizeof(actions[0])); action_handler_t input_handler = MakeSharedPtr<input_signal>(); input_handler->connect(std::bind(&ScreenSpaceReflectionApp::InputHandler, this, std::placeholders::_1, std::placeholders::_2)); inputEngine.ActionMap(actionMap, input_handler); UIManager::Instance().Load(ResLoader::Instance().Open("Reflection.uiml")); parameter_dialog_ = UIManager::Instance().GetDialog("Reflection"); id_min_sample_num_static_ = parameter_dialog_->IDFromName("min_sample_num_static"); id_min_sample_num_slider_ = parameter_dialog_->IDFromName("min_sample_num_slider"); parameter_dialog_->Control<UISlider>(id_min_sample_num_slider_)->OnValueChangedEvent().connect(std::bind(&ScreenSpaceReflectionApp::MinSampleNumHandler, this, std::placeholders::_1)); this->MinSampleNumHandler(*(parameter_dialog_->Control<UISlider>(id_min_sample_num_slider_))); id_max_sample_num_static_ = parameter_dialog_->IDFromName("max_sample_num_static"); id_max_sample_num_slider_ = parameter_dialog_->IDFromName("max_sample_num_slider"); parameter_dialog_->Control<UISlider>(id_max_sample_num_slider_)->OnValueChangedEvent().connect(std::bind(&ScreenSpaceReflectionApp::MaxSampleNumHandler, this, std::placeholders::_1)); this->MaxSampleNumHandler(*(parameter_dialog_->Control<UISlider>(id_max_sample_num_slider_))); id_enable_reflection_ = parameter_dialog_->IDFromName("enable_reflection"); parameter_dialog_->Control<UICheckBox>(id_enable_reflection_)->OnChangedEvent().connect(std::bind(&ScreenSpaceReflectionApp::EnbleReflectionHandler, this, std::placeholders::_1)); this->EnbleReflectionHandler(*(parameter_dialog_->Control<UICheckBox>(id_enable_reflection_))); }
void PostProcessingApp::OnCreate() { this->LookAt(float3(0, 0.5f, -2), float3(0, 0, 0)); this->Proj(0.1f, 150.0f); TexturePtr c_cube = ASyncLoadTexture("rnl_cross_filtered_c.dds", EAH_GPU_Read | EAH_Immutable); TexturePtr y_cube = ASyncLoadTexture("rnl_cross_filtered_y.dds", EAH_GPU_Read | EAH_Immutable); RenderablePtr scene_model = ASyncLoadModel("dino50.7z//dino50.meshml", EAH_GPU_Read | EAH_Immutable, CreateModelFactory<RenderModel>(), CreateMeshFactory<StaticMesh>()); RenderFactory& rf = Context::Instance().RenderFactoryInstance(); RenderEngine& re = rf.RenderEngineInstance(); font_ = SyncLoadFont("gkai00mp.kfont"); deferred_rendering_ = Context::Instance().DeferredRenderingLayerInstance(); deferred_rendering_->SSVOEnabled(0, false); re.HDREnabled(false); re.PPAAEnabled(0); re.ColorGradingEnabled(false); AmbientLightSourcePtr ambient_light = MakeSharedPtr<AmbientLightSource>(); ambient_light->SkylightTex(y_cube, c_cube); ambient_light->Color(float3(0.1f, 0.1f, 0.1f)); ambient_light->AddToSceneManager(); point_light_ = MakeSharedPtr<PointLightSource>(); point_light_->Attrib(LightSource::LSA_NoShadow); point_light_->Color(float3(18, 18, 18)); point_light_->Position(float3(0, 0, 0)); point_light_->Falloff(float3(1, 0, 1)); point_light_->BindUpdateFunc(PointLightSourceUpdate()); point_light_->AddToSceneManager(); SceneObjectPtr scene_obj = MakeSharedPtr<SceneObjectHelper>(scene_model, SceneObject::SOA_Cullable | SceneObject::SOA_Moveable); scene_obj->BindMainThreadUpdateFunc(ObjectUpdate()); scene_obj->AddToSceneManager(); fpcController_.Scalers(0.05f, 0.1f); InputEngine& inputEngine(Context::Instance().InputFactoryInstance().InputEngineInstance()); InputActionMap actionMap; actionMap.AddActions(actions, actions + sizeof(actions) / sizeof(actions[0])); action_handler_t input_handler = MakeSharedPtr<input_signal>(); input_handler->connect(std::bind(&PostProcessingApp::InputHandler, this, std::placeholders::_1, std::placeholders::_2)); inputEngine.ActionMap(actionMap, input_handler); copy_ = SyncLoadPostProcess("Copy.ppml", "copy"); ascii_arts_ = MakeSharedPtr<AsciiArtsPostProcess>(); cartoon_ = MakeSharedPtr<CartoonPostProcess>(); tiling_ = MakeSharedPtr<TilingPostProcess>(); hdr_ = MakeSharedPtr<HDRPostProcess>(false); night_vision_ = MakeSharedPtr<NightVisionPostProcess>(); sepia_ = SyncLoadPostProcess("Sepia.ppml", "sepia"); cross_stitching_ = SyncLoadPostProcess("CrossStitching.ppml", "cross_stitching"); frosted_glass_ = SyncLoadPostProcess("FrostedGlass.ppml", "frosted_glass"); UIManager::Instance().Load(ResLoader::Instance().Open("PostProcessing.uiml")); dialog_ = UIManager::Instance().GetDialogs()[0]; id_fps_camera_ = dialog_->IDFromName("FPSCamera"); id_copy_ = dialog_->IDFromName("CopyPP"); id_ascii_arts_ = dialog_->IDFromName("AsciiArtsPP"); id_cartoon_ = dialog_->IDFromName("CartoonPP"); id_tiling_ = dialog_->IDFromName("TilingPP"); id_hdr_ = dialog_->IDFromName("HDRPP"); id_night_vision_ = dialog_->IDFromName("NightVisionPP"); id_old_fashion_ = dialog_->IDFromName("SepiaPP"); id_cross_stitching_ = dialog_->IDFromName("CrossStitchingPP"); id_frosted_glass_ = dialog_->IDFromName("FrostedGlassPP"); dialog_->Control<UICheckBox>(id_fps_camera_)->OnChangedEvent().connect(std::bind(&PostProcessingApp::FPSCameraHandler, this, std::placeholders::_1)); dialog_->Control<UIRadioButton>(id_copy_)->OnChangedEvent().connect(std::bind(&PostProcessingApp::CopyHandler, this, std::placeholders::_1)); dialog_->Control<UIRadioButton>(id_ascii_arts_)->OnChangedEvent().connect(std::bind(&PostProcessingApp::AsciiArtsHandler, this, std::placeholders::_1)); dialog_->Control<UIRadioButton>(id_cartoon_)->OnChangedEvent().connect(std::bind(&PostProcessingApp::CartoonHandler, this, std::placeholders::_1)); dialog_->Control<UIRadioButton>(id_tiling_)->OnChangedEvent().connect(std::bind(&PostProcessingApp::TilingHandler, this, std::placeholders::_1)); dialog_->Control<UIRadioButton>(id_hdr_)->OnChangedEvent().connect(std::bind(&PostProcessingApp::HDRHandler, this, std::placeholders::_1)); dialog_->Control<UIRadioButton>(id_night_vision_)->OnChangedEvent().connect(std::bind(&PostProcessingApp::NightVisionHandler, this, std::placeholders::_1)); dialog_->Control<UIRadioButton>(id_old_fashion_)->OnChangedEvent().connect(std::bind(&PostProcessingApp::SepiaHandler, this, std::placeholders::_1)); dialog_->Control<UIRadioButton>(id_cross_stitching_)->OnChangedEvent().connect(std::bind(&PostProcessingApp::CrossStitchingHandler, this, std::placeholders::_1)); dialog_->Control<UIRadioButton>(id_frosted_glass_)->OnChangedEvent().connect(std::bind(&PostProcessingApp::FrostedGlassHandler, this, std::placeholders::_1)); this->CartoonHandler(*dialog_->Control<UIRadioButton>(id_cartoon_)); sky_box_ = MakeSharedPtr<SceneObjectSkyBox>(); checked_pointer_cast<SceneObjectSkyBox>(sky_box_)->CompressedCubeMap(y_cube, c_cube); sky_box_->AddToSceneManager(); color_fb_ = rf.MakeFrameBuffer(); color_fb_->GetViewport()->camera = re.CurFrameBuffer()->GetViewport()->camera; }
void DeferredRenderingApp::OnCreate() { this->LookAt(float3(-14.5f, 18, -3), float3(-13.6f, 17.55f, -2.8f)); this->Proj(0.1f, 500.0f); KlayGE::function<TexturePtr()> c_cube_tl = ASyncLoadTexture("Lake_CraterLake03_filtered_c.dds", EAH_GPU_Read | EAH_Immutable); KlayGE::function<TexturePtr()> y_cube_tl = ASyncLoadTexture("Lake_CraterLake03_filtered_y.dds", EAH_GPU_Read | EAH_Immutable); KlayGE::function<RenderablePtr()> model_ml = ASyncLoadModel("sponza_crytek.7z//sponza_crytek.meshml", EAH_GPU_Read | EAH_Immutable); font_ = SyncLoadFont("gkai00mp.kfont"); deferred_rendering_ = Context::Instance().DeferredRenderingLayerInstance(); AmbientLightSourcePtr ambient_light = MakeSharedPtr<AmbientLightSource>(); ambient_light->SkylightTex(y_cube_tl, c_cube_tl); ambient_light->Color(float3(0.1f, 0.1f, 0.1f)); ambient_light->AddToSceneManager(); spot_light_[0] = MakeSharedPtr<SpotLightSource>(); spot_light_[0]->Attrib(0); spot_light_[0]->Color(float3(1.0f, 0.17f, 0.05f) * 10.0f); spot_light_[0]->Falloff(float3(1, 0.5f, 0)); spot_light_[0]->Position(float3(+14.6f, 3.7f, -4.3f)); spot_light_[0]->Direction(float3(0, 1, 0)); spot_light_[0]->OuterAngle(PI / 2.5f); spot_light_[0]->InnerAngle(PI / 4); spot_light_[0]->BindUpdateFunc(SpotLightSourceUpdate(spot_light_[0]->Color())); spot_light_[0]->AddToSceneManager(); spot_light_[1] = MakeSharedPtr<SpotLightSource>(); spot_light_[1]->Attrib(0); spot_light_[1]->Color(float3(1.0f, 0.17f, 0.05f) * 10.0f); spot_light_[1]->Falloff(float3(1, 0.5f, 0)); spot_light_[1]->Position(float3(-18.6f, 3.7f, +6.5f)); spot_light_[1]->Direction(float3(0, 1, 0)); spot_light_[1]->OuterAngle(PI / 2.5f); spot_light_[1]->InnerAngle(PI / 4); spot_light_[1]->BindUpdateFunc(SpotLightSourceUpdate(spot_light_[1]->Color())); spot_light_[1]->AddToSceneManager(); spot_light_[2] = MakeSharedPtr<SpotLightSource>(); spot_light_[2]->Attrib(LightSource::LSA_IndirectLighting); spot_light_[2]->Color(float3(6.0f, 5.88f, 4.38f) * 2.0f); spot_light_[2]->Position(float3(0.0f, 43.2f, -5.9f)); spot_light_[2]->Direction(float3(0.0f, -1, 0.1f)); spot_light_[2]->Falloff(float3(1, 0.1f, 0)); spot_light_[2]->OuterAngle(PI / 8); spot_light_[2]->InnerAngle(PI / 12); spot_light_[2]->BindUpdateFunc(GISpotLightSourceUpdate()); spot_light_[2]->AddToSceneManager(); spot_light_src_[0] = MakeSharedPtr<SceneObjectLightSourceProxy>(spot_light_[0]); checked_pointer_cast<SceneObjectLightSourceProxy>(spot_light_src_[0])->Scaling(0.1f, 0.1f, 0.1f); spot_light_src_[1] = MakeSharedPtr<SceneObjectLightSourceProxy>(spot_light_[1]); checked_pointer_cast<SceneObjectLightSourceProxy>(spot_light_src_[1])->Scaling(0.1f, 0.1f, 0.1f); spot_light_src_[2] = MakeSharedPtr<SceneObjectLightSourceProxy>(spot_light_[2]); spot_light_src_[2]->AddToSceneManager(); SceneObjectPtr scene_obj = MakeSharedPtr<SceneObjectHelper>(model_ml, SceneObject::SOA_Cullable, 0); scene_obj->AddToSceneManager(); fpcController_.Scalers(0.05f, 0.5f); InputEngine& inputEngine(Context::Instance().InputFactoryInstance().InputEngineInstance()); InputActionMap actionMap; actionMap.AddActions(actions, actions + sizeof(actions) / sizeof(actions[0])); action_handler_t input_handler = MakeSharedPtr<input_signal>(); input_handler->connect(KlayGE::bind(&DeferredRenderingApp::InputHandler, this, KlayGE::placeholders::_1, KlayGE::placeholders::_2)); inputEngine.ActionMap(actionMap, input_handler); UIManager::Instance().Load(ResLoader::Instance().Open("DeferredRendering.uiml")); dialog_ = UIManager::Instance().GetDialogs()[0]; id_buffer_combo_ = dialog_->IDFromName("BufferCombo"); id_illum_combo_ = dialog_->IDFromName("IllumCombo"); id_il_scale_static_ = dialog_->IDFromName("ILScaleStatic"); id_il_scale_slider_ = dialog_->IDFromName("ILScaleSlider"); id_ssvo_ = dialog_->IDFromName("SSVO"); id_hdr_ = dialog_->IDFromName("HDR"); id_aa_ = dialog_->IDFromName("AA"); id_num_lights_static_ = dialog_->IDFromName("NumLightsStatic"); id_num_lights_slider_ = dialog_->IDFromName("NumLightsSlider"); id_ctrl_camera_ = dialog_->IDFromName("CtrlCamera"); #if DEFAULT_DEFERRED != TRIDITIONAL_DEFERRED dialog_->Control<UIComboBox>(id_buffer_combo_)->RemoveItem(10); dialog_->Control<UIComboBox>(id_buffer_combo_)->RemoveItem(9); #endif dialog_->Control<UIComboBox>(id_buffer_combo_)->OnSelectionChangedEvent().connect(KlayGE::bind(&DeferredRenderingApp::BufferChangedHandler, this, KlayGE::placeholders::_1)); this->BufferChangedHandler(*dialog_->Control<UIComboBox>(id_buffer_combo_)); dialog_->Control<UIComboBox>(id_illum_combo_)->OnSelectionChangedEvent().connect(KlayGE::bind(&DeferredRenderingApp::IllumChangedHandler, this, KlayGE::placeholders::_1)); this->IllumChangedHandler(*dialog_->Control<UIComboBox>(id_illum_combo_)); dialog_->Control<UISlider>(id_il_scale_slider_)->SetValue(static_cast<int>(il_scale_ * 10)); dialog_->Control<UISlider>(id_il_scale_slider_)->OnValueChangedEvent().connect(KlayGE::bind(&DeferredRenderingApp::ILScaleChangedHandler, this, KlayGE::placeholders::_1)); this->ILScaleChangedHandler(*dialog_->Control<UISlider>(id_il_scale_slider_)); dialog_->Control<UICheckBox>(id_ssvo_)->OnChangedEvent().connect(KlayGE::bind(&DeferredRenderingApp::SSVOHandler, this, KlayGE::placeholders::_1)); this->SSVOHandler(*dialog_->Control<UICheckBox>(id_ssvo_)); dialog_->Control<UICheckBox>(id_hdr_)->OnChangedEvent().connect(KlayGE::bind(&DeferredRenderingApp::HDRHandler, this, KlayGE::placeholders::_1)); this->HDRHandler(*dialog_->Control<UICheckBox>(id_hdr_)); dialog_->Control<UICheckBox>(id_aa_)->OnChangedEvent().connect(KlayGE::bind(&DeferredRenderingApp::AntiAliasHandler, this, KlayGE::placeholders::_1)); this->AntiAliasHandler(*dialog_->Control<UICheckBox>(id_aa_)); dialog_->Control<UISlider>(id_num_lights_slider_)->OnValueChangedEvent().connect(KlayGE::bind(&DeferredRenderingApp::NumLightsChangedHandler, this, KlayGE::placeholders::_1)); this->NumLightsChangedHandler(*dialog_->Control<UISlider>(id_num_lights_slider_)); dialog_->Control<UICheckBox>(id_ctrl_camera_)->OnChangedEvent().connect(KlayGE::bind(&DeferredRenderingApp::CtrlCameraHandler, this, KlayGE::placeholders::_1)); this->CtrlCameraHandler(*dialog_->Control<UICheckBox>(id_ctrl_camera_)); sky_box_ = MakeSharedPtr<SceneObjectSkyBox>(); checked_pointer_cast<SceneObjectSkyBox>(sky_box_)->CompressedCubeMap(y_cube_tl, c_cube_tl); sky_box_->AddToSceneManager(); ps_ = SyncLoadParticleSystem("Fire.psml"); ps_->Gravity(0.5f); ps_->MediaDensity(0.5f); ps_->AddToSceneManager(); float const SCALE = 3; ps_->ModelMatrix(MathLib::scaling(SCALE, SCALE, SCALE)); ParticleEmitterPtr emitter0 = ps_->Emitter(0); emitter0->ModelMatrix(MathLib::translation(spot_light_[0]->Position() / SCALE)); ParticleEmitterPtr emitter1 = emitter0->Clone(); emitter1->ModelMatrix(MathLib::translation(spot_light_[1]->Position() / SCALE)); ps_->AddEmitter(emitter1); }
uint32_t DetailedSurfaceApp::DoUpdate(uint32_t /*pass*/) { RenderEngine& renderEngine(Context::Instance().RenderFactoryInstance().RenderEngineInstance()); if (loading_percentage_ < 100) { UIDialogPtr const & dialog_loading = UIManager::Instance().GetDialog("Loading"); UIStaticPtr const & msg = dialog_loading->Control<UIStatic>(dialog_loading->IDFromName("Msg")); UIProgressBarPtr const & progress_bar = dialog_loading->Control<UIProgressBar>(dialog_loading->IDFromName("Progress")); if (loading_percentage_ < 20) { dialog_ = UIManager::Instance().GetDialog("DetailedSurface"); dialog_->SetVisible(false); dialog_loading->SetVisible(true); loading_percentage_ = 20; progress_bar->SetValue(loading_percentage_); msg->SetText(L"Loading Geometry"); } else if (loading_percentage_ < 60) { polygon_ = MakeSharedPtr<PolygonObject>(); checked_pointer_cast<PolygonObject>(polygon_)->BindJudaTexture(juda_tex_); juda_tex_->UpdateCache(checked_pointer_cast<PolygonObject>(polygon_)->JudaTexTileIDs(0)); polygon_->AddToSceneManager(); this->LookAt(float3(-0.18f, 0.24f, -0.18f), float3(0, 0.05f, 0)); this->Proj(0.01f, 100); tb_controller_.AttachCamera(this->ActiveCamera()); tb_controller_.Scalers(0.01f, 0.003f); loading_percentage_ = 60; progress_bar->SetValue(loading_percentage_); msg->SetText(L"Loading Light"); } else if (loading_percentage_ < 80) { light_ = MakeSharedPtr<PointLightSource>(); light_->Attrib(0); light_->Color(float3(2, 2, 2)); light_->Falloff(float3(1, 0, 1.0f)); light_->Position(float3(0.25f, 0.5f, -1.0f)); light_->AddToSceneManager(); light_proxy_ = MakeSharedPtr<SceneObjectLightSourceProxy>(light_); checked_pointer_cast<SceneObjectLightSourceProxy>(light_proxy_)->Scaling(0.01f, 0.01f, 0.01f); light_proxy_->AddToSceneManager(); loading_percentage_ = 80; progress_bar->SetValue(loading_percentage_); msg->SetText(L"Initalizing Input System"); } else if (loading_percentage_ < 90) { InputEngine& inputEngine(Context::Instance().InputFactoryInstance().InputEngineInstance()); InputActionMap actionMap; actionMap.AddActions(actions, actions + sizeof(actions) / sizeof(actions[0])); action_handler_t input_handler = MakeSharedPtr<input_signal>(); input_handler->connect(KlayGE::bind(&DetailedSurfaceApp::InputHandler, this, KlayGE::placeholders::_1, KlayGE::placeholders::_2)); inputEngine.ActionMap(actionMap, input_handler); loading_percentage_ = 90; progress_bar->SetValue(loading_percentage_); msg->SetText(L"Initalizing UI"); } else { id_scale_static_ = dialog_->IDFromName("ScaleStatic"); id_scale_slider_ = dialog_->IDFromName("ScaleSlider"); id_detail_type_static_ = dialog_->IDFromName("DetailTypeStatic"); id_detail_type_combo_ = dialog_->IDFromName("DetailTypeCombo"); id_na_length_ = dialog_->IDFromName("NaLength"); id_wireframe_ = dialog_->IDFromName("Wireframe"); dialog_->Control<UISlider>(id_scale_slider_)->SetValue(static_cast<int>(height_scale_ * 100)); dialog_->Control<UISlider>(id_scale_slider_)->OnValueChangedEvent().connect(KlayGE::bind(&DetailedSurfaceApp::ScaleChangedHandler, this, KlayGE::placeholders::_1)); this->ScaleChangedHandler(*dialog_->Control<UISlider>(id_scale_slider_)); dialog_->Control<UIComboBox>(id_detail_type_combo_)->SetSelectedByIndex(2); dialog_->Control<UIComboBox>(id_detail_type_combo_)->OnSelectionChangedEvent().connect(KlayGE::bind(&DetailedSurfaceApp::DetailTypeChangedHandler, this, KlayGE::placeholders::_1)); this->DetailTypeChangedHandler(*dialog_->Control<UIComboBox>(id_detail_type_combo_)); dialog_->Control<UICheckBox>(id_na_length_)->OnChangedEvent().connect(KlayGE::bind(&DetailedSurfaceApp::NaLengthHandler, this, KlayGE::placeholders::_1)); this->NaLengthHandler(*dialog_->Control<UICheckBox>(id_na_length_)); dialog_->Control<UICheckBox>(id_wireframe_)->OnChangedEvent().connect(KlayGE::bind(&DetailedSurfaceApp::WireframeHandler, this, KlayGE::placeholders::_1)); this->WireframeHandler(*dialog_->Control<UICheckBox>(id_wireframe_)); loading_percentage_ = 100; progress_bar->SetValue(loading_percentage_); msg->SetText(L"DONE"); dialog_->SetVisible(true); dialog_loading->SetVisible(false); } renderEngine.CurFrameBuffer()->Clear(FrameBuffer::CBM_Color | FrameBuffer::CBM_Depth, Color(0.0f, 0.0f, 0.0f, 1), 1.0f, 0); return App3DFramework::URV_SkipPostProcess | App3DFramework::URV_Finished; } else { Color clear_clr(0.2f, 0.4f, 0.6f, 1); if (Context::Instance().Config().graphics_cfg.gamma) { clear_clr.r() = 0.029f; clear_clr.g() = 0.133f; clear_clr.b() = 0.325f; } renderEngine.CurFrameBuffer()->Clear(FrameBuffer::CBM_Color | FrameBuffer::CBM_Depth, clear_clr, 1.0f, 0); /*float degree(std::clock() / 700.0f); float3 lightPos(2, 0, 1); float4x4 matRot(MathLib::rotation_y(degree)); lightPos = MathLib::transform_coord(lightPos, matRot);*/ float3 light_pos(0.25f, 0.5f, -1.0f); light_pos = MathLib::transform_coord(light_pos, this->ActiveCamera().InverseViewMatrix()); light_pos = MathLib::normalize(light_pos); light_->Position(light_pos); checked_pointer_cast<PolygonObject>(polygon_)->LightPos(light_->Position()); checked_pointer_cast<PolygonObject>(polygon_)->LightColor(light_->Color()); checked_pointer_cast<PolygonObject>(polygon_)->LightFalloff(light_->Falloff()); return App3DFramework::URV_NeedFlush | App3DFramework::URV_Finished; } }
void PostProcessingApp::InitObjects() { this->LookAt(float3(0, 0.5f, -2), float3(0, 0, 0)); this->Proj(0.1f, 150.0f); loading_percentage_ = 0; c_cube_tl_ = ASyncLoadTexture("rnl_cross_c.dds", EAH_GPU_Read | EAH_Immutable); y_cube_tl_ = ASyncLoadTexture("rnl_cross_y.dds", EAH_GPU_Read | EAH_Immutable); model_ml_ = ASyncLoadModel("dino50.7z//dino50.meshml", EAH_GPU_Read | EAH_Immutable); RenderFactory& rf = Context::Instance().RenderFactoryInstance(); RenderEngine& re = rf.RenderEngineInstance(); font_ = SyncLoadFont("gkai00mp.kfont"); deferred_rendering_ = Context::Instance().DeferredRenderingLayerInstance(); deferred_rendering_->SSVOEnabled(0, false); re.HDREnabled(false); re.PPAAEnabled(0); re.ColorGradingEnabled(false); point_light_ = MakeSharedPtr<PointLightSource>(); point_light_->Attrib(LightSource::LSA_NoShadow); point_light_->Color(float3(18, 18, 18)); point_light_->Position(float3(0, 0, 0)); point_light_->Falloff(float3(1, 0, 1)); point_light_->BindUpdateFunc(PointLightSourceUpdate()); point_light_->AddToSceneManager(); fpcController_.Scalers(0.05f, 0.1f); InputEngine& inputEngine(Context::Instance().InputFactoryInstance().InputEngineInstance()); InputActionMap actionMap; actionMap.AddActions(actions, actions + sizeof(actions) / sizeof(actions[0])); action_handler_t input_handler = MakeSharedPtr<input_signal>(); input_handler->connect(KlayGE::bind(&PostProcessingApp::InputHandler, this, KlayGE::placeholders::_1, KlayGE::placeholders::_2)); inputEngine.ActionMap(actionMap, input_handler); copy_ = SyncLoadPostProcess("Copy.ppml", "copy"); ascii_arts_ = MakeSharedPtr<AsciiArtsPostProcess>(); cartoon_ = MakeSharedPtr<CartoonPostProcess>(); tiling_ = MakeSharedPtr<TilingPostProcess>(); hdr_ = MakeSharedPtr<HDRPostProcess>(false); night_vision_ = MakeSharedPtr<NightVisionPostProcess>(); old_fashion_ = SyncLoadPostProcess("OldFashion.ppml", "old_fashion"); UIManager::Instance().Load(ResLoader::Instance().Open("PostProcessing.uiml")); dialog_ = UIManager::Instance().GetDialogs()[0]; id_fps_camera_ = dialog_->IDFromName("FPSCamera"); id_copy_ = dialog_->IDFromName("CopyPP"); id_ascii_arts_ = dialog_->IDFromName("AsciiArtsPP"); id_cartoon_ = dialog_->IDFromName("CartoonPP"); id_tiling_ = dialog_->IDFromName("TilingPP"); id_hdr_ = dialog_->IDFromName("HDRPP"); id_night_vision_ = dialog_->IDFromName("NightVisionPP"); id_old_fashion_ = dialog_->IDFromName("OldFashionPP"); dialog_->Control<UICheckBox>(id_fps_camera_)->OnChangedEvent().connect(KlayGE::bind(&PostProcessingApp::FPSCameraHandler, this, KlayGE::placeholders::_1)); dialog_->Control<UIRadioButton>(id_copy_)->OnChangedEvent().connect(KlayGE::bind(&PostProcessingApp::CopyHandler, this, KlayGE::placeholders::_1)); dialog_->Control<UIRadioButton>(id_ascii_arts_)->OnChangedEvent().connect(KlayGE::bind(&PostProcessingApp::AsciiArtsHandler, this, KlayGE::placeholders::_1)); dialog_->Control<UIRadioButton>(id_cartoon_)->OnChangedEvent().connect(KlayGE::bind(&PostProcessingApp::CartoonHandler, this, KlayGE::placeholders::_1)); dialog_->Control<UIRadioButton>(id_tiling_)->OnChangedEvent().connect(KlayGE::bind(&PostProcessingApp::TilingHandler, this, KlayGE::placeholders::_1)); dialog_->Control<UIRadioButton>(id_hdr_)->OnChangedEvent().connect(KlayGE::bind(&PostProcessingApp::HDRHandler, this, KlayGE::placeholders::_1)); dialog_->Control<UIRadioButton>(id_night_vision_)->OnChangedEvent().connect(KlayGE::bind(&PostProcessingApp::NightVisionHandler, this, KlayGE::placeholders::_1)); dialog_->Control<UIRadioButton>(id_old_fashion_)->OnChangedEvent().connect(KlayGE::bind(&PostProcessingApp::OldFashionHandler, this, KlayGE::placeholders::_1)); this->CartoonHandler(*dialog_->Control<UIRadioButton>(id_cartoon_)); sky_box_ = MakeSharedPtr<SceneObjectSkyBox>(); sky_box_->AddToSceneManager(); color_fb_ = rf.MakeFrameBuffer(); color_fb_->GetViewport()->camera = re.CurFrameBuffer()->GetViewport()->camera; }
void AreaLightingApp::OnCreate() { this->LookAt(float3(-12.2f, 15.8f, -2.4f), float3(-11.5f, 15.1f, -2.2f)); this->Proj(0.1f, 500.0f); KlayGE::function<TexturePtr()> c_cube_tl = ASyncLoadTexture("Lake_CraterLake03_filtered_c.dds", EAH_GPU_Read | EAH_Immutable); KlayGE::function<TexturePtr()> y_cube_tl = ASyncLoadTexture("Lake_CraterLake03_filtered_y.dds", EAH_GPU_Read | EAH_Immutable); KlayGE::function<RenderablePtr()> model_ml = ASyncLoadModel("sponza_crytek.7z//sponza_crytek.meshml", EAH_GPU_Read | EAH_Immutable); font_ = SyncLoadFont("gkai00mp.kfont"); deferred_rendering_ = Context::Instance().DeferredRenderingLayerInstance(); AmbientLightSourcePtr ambient_light = MakeSharedPtr<AmbientLightSource>(); ambient_light->SkylightTex(y_cube_tl, c_cube_tl); ambient_light->Color(float3(0.1f, 0.1f, 0.1f)); ambient_light->AddToSceneManager(); point_light_ = MakeSharedPtr<PointLightSource>(); point_light_->Attrib(0); point_light_->Color(float3(0.8f, 0.96f, 1.0f) * 40.0f); point_light_->Position(float3(0, 0, 0)); point_light_->Falloff(float3(1, 0, 1)); point_light_->BindUpdateFunc(PointLightSourceUpdate(1 / 1000.0f, float3(0, 10, 0))); point_light_->AddToSceneManager(); point_light_->Enabled(false); point_light_src_ = MakeSharedPtr<SceneObjectLightSourceProxy>(point_light_); checked_pointer_cast<SceneObjectLightSourceProxy>(point_light_src_)->Scaling(0.1f, 0.1f, 0.1f); point_light_src_->AddToSceneManager(); point_light_src_->Visible(false); sphere_area_light_ = MakeSharedPtr<SphereAreaLightSource>(); sphere_area_light_->Attrib(0); sphere_area_light_->Color(point_light_->Color()); sphere_area_light_->Position(point_light_->Position()); sphere_area_light_->Falloff(point_light_->Falloff()); sphere_area_light_->BindUpdateFunc(PointLightSourceUpdate(1 / 1000.0f, float3(0, 10, 0))); sphere_area_light_->AddToSceneManager(); sphere_area_light_->Enabled(false); sphere_area_light_src_ = MakeSharedPtr<SceneObjectLightSourceProxy>(sphere_area_light_); checked_pointer_cast<SceneObjectLightSourceProxy>(sphere_area_light_src_)->Scaling(0.1f, 0.1f, 0.1f); sphere_area_light_src_->AddToSceneManager(); sphere_area_light_src_->Visible(false); tube_area_light_ = MakeSharedPtr<TubeAreaLightSource>(); tube_area_light_->Attrib(0); tube_area_light_->Color(point_light_->Color()); tube_area_light_->Position(point_light_->Position()); tube_area_light_->Falloff(point_light_->Falloff()); tube_area_light_->BindUpdateFunc(PointLightSourceUpdate(1 / 1000.0f, float3(0, 10, 0))); tube_area_light_->AddToSceneManager(); tube_area_light_->Enabled(false); tube_area_light_src_ = MakeSharedPtr<SceneObjectLightSourceProxy>(tube_area_light_); checked_pointer_cast<SceneObjectLightSourceProxy>(tube_area_light_src_)->Scaling(0.1f, 0.1f, 0.1f); tube_area_light_src_->AddToSceneManager(); tube_area_light_src_->Visible(false); SceneObjectPtr scene_obj = MakeSharedPtr<SceneObjectHelper>(model_ml, SceneObject::SOA_Cullable, 0); scene_obj->AddToSceneManager(); for (int i = -5; i < 5; ++ i) { RenderModelPtr sphere_mesh = SyncLoadModel("sphere_high.7z//sphere_high.meshml", EAH_GPU_Read | EAH_Immutable); sphere_mesh->GetMaterial(0)->specular = float3(0.4f, 0.4f, 0.4f); sphere_mesh->GetMaterial(0)->shininess = (i + 6) * 10.0f; SceneObjectPtr sphere_obj = MakeSharedPtr<SceneObjectHelper>(sphere_mesh, SceneObject::SOA_Cullable); sphere_obj->ModelMatrix(MathLib::scaling(10.0f, 10.0f, 10.0f) * MathLib::translation(i + 0.5f, 5.0f, 0.0f)); sphere_obj->AddToSceneManager(); } fpcController_.Scalers(0.05f, 0.5f); InputEngine& inputEngine(Context::Instance().InputFactoryInstance().InputEngineInstance()); InputActionMap actionMap; actionMap.AddActions(actions, actions + sizeof(actions) / sizeof(actions[0])); action_handler_t input_handler = MakeSharedPtr<input_signal>(); input_handler->connect(KlayGE::bind(&AreaLightingApp::InputHandler, this, KlayGE::placeholders::_1, KlayGE::placeholders::_2)); inputEngine.ActionMap(actionMap, input_handler); UIManager::Instance().Load(ResLoader::Instance().Open("AreaLighting.uiml")); dialog_ = UIManager::Instance().GetDialogs()[0]; id_light_type_combo_ = dialog_->IDFromName("LightTypeCombo"); id_radius_static_ = dialog_->IDFromName("RadiusStatic"); id_radius_slider_ = dialog_->IDFromName("RadiusSlider"); id_length_static_ = dialog_->IDFromName("LengthStatic"); id_length_slider_ = dialog_->IDFromName("LengthSlider"); id_ctrl_camera_ = dialog_->IDFromName("CtrlCamera"); dialog_->Control<UIComboBox>(id_light_type_combo_)->OnSelectionChangedEvent().connect(KlayGE::bind(&AreaLightingApp::LightTypeChangedHandler, this, KlayGE::placeholders::_1)); this->LightTypeChangedHandler(*dialog_->Control<UIComboBox>(id_light_type_combo_)); dialog_->Control<UISlider>(id_radius_slider_)->OnValueChangedEvent().connect(KlayGE::bind(&AreaLightingApp::RadiusChangedHandler, this, KlayGE::placeholders::_1)); this->RadiusChangedHandler(*dialog_->Control<UISlider>(id_radius_slider_)); dialog_->Control<UISlider>(id_length_slider_)->OnValueChangedEvent().connect(KlayGE::bind(&AreaLightingApp::LengthChangedHandler, this, KlayGE::placeholders::_1)); this->LengthChangedHandler(*dialog_->Control<UISlider>(id_length_slider_)); dialog_->Control<UICheckBox>(id_ctrl_camera_)->OnChangedEvent().connect(KlayGE::bind(&AreaLightingApp::CtrlCameraHandler, this, KlayGE::placeholders::_1)); this->CtrlCameraHandler(*dialog_->Control<UICheckBox>(id_ctrl_camera_)); sky_box_ = MakeSharedPtr<SceneObjectSkyBox>(); checked_pointer_cast<SceneObjectSkyBox>(sky_box_)->CompressedCubeMap(y_cube_tl, c_cube_tl); sky_box_->AddToSceneManager(); }
void ShadowCubeMap::OnCreate() { loading_percentage_ = 0; lamp_tex_ = ASyncLoadTexture("lamp.dds", EAH_GPU_Read | EAH_Immutable); scene_model_ = ASyncLoadModel("ScifiRoom.7z//ScifiRoom.meshml", EAH_GPU_Read | EAH_Immutable, CreateModelFactory<RenderModel>(), CreateMeshFactory<OccluderMesh>()); teapot_model_ = ASyncLoadModel("teapot.meshml", EAH_GPU_Read | EAH_Immutable, CreateModelFactory<RenderModel>(), CreateMeshFactory<OccluderMesh>()); RenderFactory& rf = Context::Instance().RenderFactoryInstance(); RenderEngine& re = rf.RenderEngineInstance(); RenderDeviceCaps const & caps = re.DeviceCaps(); font_ = SyncLoadFont("gkai00mp.kfont"); this->LookAt(float3(0.0f, 10.0f, -25.0f), float3(0, 10.0f, 0)); this->Proj(0.1f, 200); ElementFormat fmt; if (caps.rendertarget_format_support(EF_D24S8, 1, 0)) { fmt = EF_D24S8; } else { BOOST_ASSERT(caps.rendertarget_format_support(EF_D16, 1, 0)); fmt = EF_D16; } RenderViewPtr depth_view = rf.Make2DDepthStencilRenderView(SHADOW_MAP_SIZE, SHADOW_MAP_SIZE, fmt, 1, 0); if (caps.pack_to_rgba_required) { if (caps.texture_format_support(EF_ABGR8) && caps.rendertarget_format_support(EF_ABGR8, 1, 0)) { fmt = EF_ABGR8; } else { BOOST_ASSERT(caps.texture_format_support(EF_ARGB8) && caps.rendertarget_format_support(EF_ARGB8, 1, 0)); fmt = EF_ARGB8; } } else { fmt = EF_R16F; } shadow_tex_ = rf.MakeTexture2D(SHADOW_MAP_SIZE, SHADOW_MAP_SIZE, 1, 1, fmt, 1, 0, EAH_GPU_Read | EAH_GPU_Write, nullptr); shadow_cube_buffer_ = rf.MakeFrameBuffer(); shadow_cube_buffer_->Attach(FrameBuffer::ATT_Color0, rf.Make2DRenderView(*shadow_tex_, 0, 1, 0)); shadow_cube_buffer_->Attach(FrameBuffer::ATT_DepthStencil, depth_view); shadow_cube_tex_ = rf.MakeTextureCube(SHADOW_MAP_SIZE, 1, 1, shadow_tex_->Format(), 1, 0, EAH_GPU_Read | EAH_GPU_Write, nullptr); if (caps.render_to_texture_array_support) { shadow_cube_one_tex_ = rf.MakeTextureCube(SHADOW_MAP_SIZE, 1, 1, shadow_tex_->Format(), 1, 0, EAH_GPU_Read | EAH_GPU_Write, nullptr); shadow_cube_one_buffer_ = rf.MakeFrameBuffer(); shadow_cube_one_buffer_->GetViewport()->camera->OmniDirectionalMode(true); shadow_cube_one_buffer_->GetViewport()->camera->ProjParams(PI / 2, 1, 0.1f, 500.0f); shadow_cube_one_buffer_->Attach(FrameBuffer::ATT_Color0, rf.MakeCubeRenderView(*shadow_cube_one_tex_, 0, 0)); TexturePtr shadow_one_depth_tex = rf.MakeTextureCube(SHADOW_MAP_SIZE, 1, 1, EF_D24S8, 1, 0, EAH_GPU_Write, nullptr); shadow_cube_one_buffer_->Attach(FrameBuffer::ATT_DepthStencil, rf.MakeCubeDepthStencilRenderView(*shadow_one_depth_tex, 0, 0)); } for (int i = 0; i < 2; ++ i) { shadow_dual_texs_[i] = rf.MakeTexture2D(SHADOW_MAP_SIZE, SHADOW_MAP_SIZE, 1, 1, fmt, 1, 0, EAH_GPU_Read | EAH_GPU_Write, nullptr); shadow_dual_view_[i] = rf.Make2DRenderView(*shadow_dual_texs_[i], 0, 1, 0); shadow_dual_buffers_[i] = rf.MakeFrameBuffer(); shadow_dual_buffers_[i]->GetViewport()->camera->ProjParams(PI, 1, 0.1f, 500.0f); shadow_dual_buffers_[i]->Attach(FrameBuffer::ATT_Color0, shadow_dual_view_[i]); shadow_dual_buffers_[i]->Attach(FrameBuffer::ATT_DepthStencil, depth_view); } shadow_dual_tex_ = rf.MakeTexture2D(SHADOW_MAP_SIZE * 2, SHADOW_MAP_SIZE, 1, 1, fmt, 1, 0, EAH_GPU_Read, nullptr); light_ = MakeSharedPtr<PointLightSource>(); light_->Attrib(0); light_->Color(float3(20, 20, 20)); light_->Falloff(float3(1, 1, 0)); light_->BindUpdateFunc(PointLightSourceUpdate()); light_->AddToSceneManager(); light_proxy_ = MakeSharedPtr<SceneObjectLightSourceProxy>(light_); checked_pointer_cast<SceneObjectLightSourceProxy>(light_proxy_)->Scaling(0.5f, 0.5f, 0.5f); light_proxy_->AddToSceneManager(); for (int i = 0; i < 6; ++ i) { sm_filter_pps_[i] = MakeSharedPtr<LogGaussianBlurPostProcess>(3, true); sm_filter_pps_[i]->InputPin(0, shadow_tex_); sm_filter_pps_[i]->OutputPin(0, shadow_cube_tex_, 0, 0, i); } fpcController_.Scalers(0.05f, 1.0f); InputEngine& inputEngine(Context::Instance().InputFactoryInstance().InputEngineInstance()); InputActionMap actionMap; actionMap.AddActions(actions, actions + sizeof(actions) / sizeof(actions[0])); action_handler_t input_handler = MakeSharedPtr<input_signal>(); input_handler->connect(std::bind(&ShadowCubeMap::InputHandler, this, std::placeholders::_1, std::placeholders::_2)); inputEngine.ActionMap(actionMap, input_handler); UIManager::Instance().Load(ResLoader::Instance().Open("ShadowCubeMap.uiml")); dialog_ = UIManager::Instance().GetDialogs()[0]; id_scale_factor_static_ = dialog_->IDFromName("ScaleFactorStatic"); id_scale_factor_slider_ = dialog_->IDFromName("ScaleFactorSlider"); id_sm_type_static_ = dialog_->IDFromName("SMStatic"); id_sm_type_combo_ = dialog_->IDFromName("SMCombo"); id_ctrl_camera_ = dialog_->IDFromName("CtrlCamera"); dialog_->Control<UISlider>(id_scale_factor_slider_)->OnValueChangedEvent().connect(std::bind(&ShadowCubeMap::ScaleFactorChangedHandler, this, std::placeholders::_1)); dialog_->Control<UIComboBox>(id_sm_type_combo_)->OnSelectionChangedEvent().connect(std::bind(&ShadowCubeMap::SMTypeChangedHandler, this, std::placeholders::_1)); dialog_->Control<UICheckBox>(id_ctrl_camera_)->OnChangedEvent().connect(std::bind(&ShadowCubeMap::CtrlCameraHandler, this, std::placeholders::_1)); this->ScaleFactorChangedHandler(*dialog_->Control<UISlider>(id_scale_factor_slider_)); this->SMTypeChangedHandler(*dialog_->Control<UIComboBox>(id_sm_type_combo_)); if (caps.max_shader_model < ShaderModel(5, 0)) { dialog_->Control<UIComboBox>(id_sm_type_combo_)->RemoveItem(4); } if (caps.max_shader_model < ShaderModel(4, 0)) { dialog_->Control<UIComboBox>(id_sm_type_combo_)->RemoveItem(3); dialog_->Control<UIComboBox>(id_sm_type_combo_)->RemoveItem(2); dialog_->Control<UIComboBox>(id_sm_type_combo_)->RemoveItem(1); } }
void CascadedShadowMapApp::OnCreate() { this->LookAt(float3(-25.72f, 29.65f, 24.57f), float3(-24.93f, 29.09f, 24.32f)); this->Proj(0.05f, 300.0f); light_ctrl_camera_.ViewParams(float3(-50, 50, -50), float3(0, 0, 0), float3(0, 1, 0)); light_controller_.AttachCamera(light_ctrl_camera_); light_controller_.Scalers(0.003f, 0.003f); TexturePtr c_cube = ASyncLoadTexture("Lake_CraterLake03_filtered_c.dds", EAH_GPU_Read | EAH_Immutable); TexturePtr y_cube = ASyncLoadTexture("Lake_CraterLake03_filtered_y.dds", EAH_GPU_Read | EAH_Immutable); RenderablePtr plane_model = ASyncLoadModel("plane.meshml", EAH_GPU_Read | EAH_Immutable, CreateModelFactory<RenderModel>(), CreateMeshFactory<StaticMesh>()); RenderablePtr katapult_model = ASyncLoadModel("katapult.meshml", EAH_GPU_Read | EAH_Immutable); font_ = SyncLoadFont("gkai00mp.kfont"); deferred_rendering_ = Context::Instance().DeferredRenderingLayerInstance(); deferred_rendering_->SSVOEnabled(0, false); AmbientLightSourcePtr ambient_light = MakeSharedPtr<AmbientLightSource>(); ambient_light->SkylightTex(y_cube, c_cube); ambient_light->Color(float3(0.1f, 0.1f, 0.1f)); ambient_light->AddToSceneManager(); sun_light_ = MakeSharedPtr<SunLightSource>(); sun_light_->Attrib(0); sun_light_->Direction(MathLib::normalize(float3(50, -50, 50))); sun_light_->Color(float3(1, 1, 1)); sun_light_->AddToSceneManager(); SceneObjectPtr plane_so = MakeSharedPtr<SceneObjectHelper>(plane_model, SceneObject::SOA_Cullable); plane_so->ModelMatrix(MathLib::scaling(200.0f, 1.0f, 200.0f)); plane_so->AddToSceneManager(); SceneObjectPtr katapult_so = MakeSharedPtr<SceneObjectHelper>(katapult_model, SceneObject::SOA_Cullable); katapult_so->AddToSceneManager(); fpcController_.Scalers(0.05f, 1.0f); InputEngine& inputEngine(Context::Instance().InputFactoryInstance().InputEngineInstance()); InputActionMap actionMap; actionMap.AddActions(actions, actions + sizeof(actions) / sizeof(actions[0])); action_handler_t input_handler = MakeSharedPtr<input_signal>(); input_handler->connect(std::bind(&CascadedShadowMapApp::InputHandler, this, std::placeholders::_1, std::placeholders::_2)); inputEngine.ActionMap(actionMap, input_handler); UIManager::Instance().Load(ResLoader::Instance().Open("CascadedShadowMap.uiml")); dialog_ = UIManager::Instance().GetDialogs()[0]; id_csm_type_combo_ = dialog_->IDFromName("TypeCombo"); id_cascades_combo_ = dialog_->IDFromName("CascadesCombo"); id_pssm_factor_static_ = dialog_->IDFromName("PSSMFactorStatic"); id_pssm_factor_slider_ = dialog_->IDFromName("PSSMFactorSlider"); id_ctrl_camera_ = dialog_->IDFromName("CtrlCamera"); dialog_->Control<UIComboBox>(id_csm_type_combo_)->OnSelectionChangedEvent().connect(std::bind(&CascadedShadowMapApp::CSMTypeChangedHandler, this, std::placeholders::_1)); this->CSMTypeChangedHandler(*dialog_->Control<UIComboBox>(id_csm_type_combo_)); dialog_->Control<UIComboBox>(id_cascades_combo_)->OnSelectionChangedEvent().connect(std::bind(&CascadedShadowMapApp::CascadesChangedHandler, this, std::placeholders::_1)); this->CascadesChangedHandler(*dialog_->Control<UIComboBox>(id_cascades_combo_)); dialog_->Control<UISlider>(id_pssm_factor_slider_)->OnValueChangedEvent().connect(std::bind(&CascadedShadowMapApp::PSSMFactorChangedHandler, this, std::placeholders::_1)); this->PSSMFactorChangedHandler(*dialog_->Control<UISlider>(id_pssm_factor_slider_)); dialog_->Control<UICheckBox>(id_ctrl_camera_)->OnChangedEvent().connect(std::bind(&CascadedShadowMapApp::CtrlCameraHandler, this, std::placeholders::_1)); this->CtrlCameraHandler(*dialog_->Control<UICheckBox>(id_ctrl_camera_)); sky_box_ = MakeSharedPtr<SceneObjectSkyBox>(); checked_pointer_cast<SceneObjectSkyBox>(sky_box_)->CompressedCubeMap(y_cube, c_cube); sky_box_->AddToSceneManager(); RenderDeviceCaps const & caps = Context::Instance().RenderFactoryInstance().RenderEngineInstance().DeviceCaps(); if (caps.max_shader_model < ShaderModel(5, 0)) { dialog_->Control<UIComboBox>(id_csm_type_combo_)->SetSelectedByIndex(0); dialog_->Control<UIComboBox>(id_csm_type_combo_)->SetEnabled(false); } }