Esempio n. 1
0
	void MultiResSILLayer::ExtractVPLs(CameraPtr const & rsm_camera, LightSourcePtr const & light)
	{
		rsm_texs_[0]->BuildMipSubLevels();
		rsm_texs_[1]->BuildMipSubLevels();
		
		rsm_to_depth_derivate_pp_->Apply();
		
		float4x4 ls_to_es = rsm_camera->InverseViewMatrix() * g_buffer_camera_->ViewMatrix();
		float4x4 const & inv_proj = rsm_camera->InverseProjMatrix();
		LightSource::LightType type = light->Type();

		float4 vpl_params(static_cast<float>(VPL_COUNT), 2.0f, 
			              static_cast<float>(MIN_RSM_MIPMAP_SIZE), static_cast<float>(MIN_RSM_MIPMAP_SIZE * MIN_RSM_MIPMAP_SIZE));

		rsm_to_vpls_pps_[type]->SetParam(0, ls_to_es);
		rsm_to_vpls_pps_[type]->SetParam(1, vpl_params);
		rsm_to_vpls_pps_[type]->SetParam(2, light->Color());
		rsm_to_vpls_pps_[type]->SetParam(3, light->CosOuterInner());
		rsm_to_vpls_pps_[type]->SetParam(4, light->Falloff());
		rsm_to_vpls_pps_[type]->SetParam(5, g_buffer_camera_->InverseViewMatrix());
		float3 upper_left = MathLib::transform_coord(float3(-1, +1, 1), inv_proj);
		float3 upper_right = MathLib::transform_coord(float3(+1, +1, 1), inv_proj);
		float3 lower_left = MathLib::transform_coord(float3(-1, -1, 1), inv_proj);
		rsm_to_vpls_pps_[type]->SetParam(6, upper_left);
		rsm_to_vpls_pps_[type]->SetParam(7, upper_right - upper_left);
		rsm_to_vpls_pps_[type]->SetParam(8, lower_left - upper_left);
		rsm_to_vpls_pps_[type]->SetParam(9, int2(1, 0));
		rsm_to_vpls_pps_[type]->SetParam(10, 0.12f * rsm_camera->FarPlane());
		rsm_to_vpls_pps_[type]->SetParam(11, static_cast<float>(rsm_texs_[0]->NumMipMaps() - 1));

		rsm_to_vpls_pps_[type]->Apply();
	}
Esempio n. 2
0
 void LightManager::addLight(const LightSourcePtr& light) {
     switch(light->type()) {
     case LS_Directional: mDirectionalLights.push_back(light); break;
     case LS_Spot:        mSpotLights.push_back(light); break;
     case LS_Point:       mPointLights.push_back(light); break;
     }
 }
Esempio n. 3
0
    void LightManager::renderShadowMap(GraphicDevice& gd, SceneManager& scene, const LightSourcePtr& ls) {
        const RenderTargetPtr& rt = ls->getShadowMap();
        EffectTechniquePtr techniuqe;
        if(ls->type() == LS_Directional)
            techniuqe = mDepthMapTechnique;
        else
            techniuqe = mEXPDepthMapTechnique;

        mShadowMapRT->attach(ATT_Color0, ls->getShadowMap());
        mShadowMapRT->attach(ATT_DepthStencil, 
                             ls->getDSView());

        mShadowMapRT->attachToRender();

        gd.clear(CM_Color | CM_Depth, color::Transparent, 1.0f, 0);

        Shader* fragmentShader = mDepthMapTechnique->getPass(0)->getFragmentShader().get();
        fragmentShader->setFloatVectorVariable("lightPosition", ls->getPosition());
        
        const CameraPtr& cam = ls->getCamera(0);
        fragmentShader->setFloatVariable("depthPrecision", cam->getFarPlane());

        scene.render(techniuqe, cam->getViewMatrix(), cam->getProjMatrix(), ~SOA_NotCastShadow);

        mShadowMapRT->detachFromRender();
    }
Esempio n. 4
0
	void MultiResSILLayer::VPLsLighting(LightSourcePtr const & light)
	{
		RenderEngine& re = Context::Instance().RenderFactoryInstance().RenderEngineInstance();
		RenderDeviceCaps const & caps = re.DeviceCaps();

		*vpl_view_param_ = g_buffer_camera_->ViewMatrix();
		*vpl_proj_param_ = g_buffer_camera_->ProjMatrix();;
		*vpl_depth_near_far_invfar_param_ = float3(g_buffer_camera_->NearPlane(),
			g_buffer_camera_->FarPlane(), 1 / g_buffer_camera_->FarPlane());

		float3 p = MathLib::transform_coord(light->Position(), g_buffer_camera_->ViewMatrix());
		*vpl_light_pos_es_param_ = float4(p.x(), p.y(), p.z(), 1);
		*vpl_light_color_param_ = light->Color();
		*vpl_light_falloff_param_ = light->Falloff();

		*vpl_gbuffer_tex_param_ = g_buffer_texs_[0];
		*vpl_depth_tex_param_ = g_buffer_depth_tex_;
		
		for (size_t i = 0; i < vpls_lighting_fbs_.size(); ++ i)
		{
			re.BindFrameBuffer(vpls_lighting_fbs_[i]);

			if (caps.instance_id_support)
			{
				re.Render(*vpls_lighting_instance_id_tech_, *rl_vpl_);
			}
			else
			{
				for (int j = 0; j < VPL_COUNT; ++ j)
				{
					*vpl_x_coord_param_ = (j + 0.5f) / VPL_COUNT;
					re.Render(*vpls_lighting_no_instance_id_tech_, *rl_vpl_);
				}
			}
		}
	}
Esempio n. 5
0
 void LightManager::removeLight(const LightSourcePtr& light) {
     switch(light->type()) {
     case LS_Directional: mDirectionalLights.erase(std::remove(mDirectionalLights.begin(),
                                                               mDirectionalLights.end(),
                                                               light),
                                                   mDirectionalLights.end()); break;
     case LS_Spot:        mSpotLights.erase(std::remove(mSpotLights.begin(),
                                                        mSpotLights.end(),
                                                        light),
                                            mSpotLights.end()); break;
     case LS_Point:       mPointLights.erase(std::remove(mPointLights.begin(),
                                                         mPointLights.end(),
                                                         light),
                                             mPointLights.end());
     }
 }
Esempio n. 6
0
	void SceneObjectLightSourceProxy::Init(LightSourcePtr const & light,
			std::function<StaticMeshPtr(RenderModelPtr const &, std::wstring const &)> CreateMeshFactoryFunc)
	{
		std::string mesh_name;
		switch (light->Type())
		{
		case LightSource::LT_Ambient:
			mesh_name = "ambient_light_proxy.meshml";
			break;

		case LightSource::LT_Point:
		case LightSource::LT_SphereArea:
			mesh_name = "point_light_proxy.meshml";
			break;

		case LightSource::LT_Directional:
		case LightSource::LT_Sun:
			mesh_name = "directional_light_proxy.meshml";
			break;

		case LightSource::LT_Spot:
			mesh_name = "spot_light_proxy.meshml";
			break;

		case LightSource::LT_TubeArea:
			mesh_name = "tube_light_proxy.meshml";
			break;

		default:
			BOOST_ASSERT(false);
			break;
		}
		RenderModelPtr light_model = SyncLoadModel(mesh_name.c_str(), EAH_GPU_Read | EAH_Immutable,
			CreateModelFactory<RenderModel>(), CreateMeshFactoryFunc);
		this->Init(light, light_model);
	}