Ejemplo 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();
	}
Ejemplo n.º 2
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_);
				}
			}
		}
	}