void MultiResLayer::CreateDepthDerivativeMipMap(CameraPtr const & vp_camera) { gbuffer_to_depth_derivate_pp_->InputPin(0, g_buffer_rt0_tex_); gbuffer_to_depth_derivate_pp_->InputPin(1, g_buffer_depth_tex_); gbuffer_to_depth_derivate_pp_->OutputPin(0, depth_deriative_tex_); float delta_x = 1.0f / g_buffer_rt0_tex_->Width(0); float delta_y = 1.0f / g_buffer_rt0_tex_->Height(0); float4 delta_offset(delta_x, delta_y, delta_x / 2, delta_y / 2); gbuffer_to_depth_derivate_pp_->SetParam(0, delta_offset); gbuffer_to_depth_derivate_pp_->SetParam(1, float2(vp_camera->FarPlane(), 1.0f / vp_camera->FarPlane())); gbuffer_to_depth_derivate_pp_->Apply(); depth_derivate_mipmap_pp_->InputPin(0, depth_deriative_tex_); for (uint32_t i = 1; i < depth_deriative_tex_->NumMipMaps(); ++ i) { int width = depth_deriative_tex_->Width(i - 1); int height = depth_deriative_tex_->Height(i - 1); delta_x = 1.0f / width; delta_y = 1.0f / height; delta_offset = float4(delta_x, delta_y, delta_x / 2, delta_y / 2); depth_derivate_mipmap_pp_->SetParam(0, delta_offset); depth_derivate_mipmap_pp_->SetParam(1, float2(vp_camera->FarPlane(), 1.0f / vp_camera->FarPlane())); depth_derivate_mipmap_pp_->OutputPin(0, depth_deriative_small_tex_, i - 1); depth_derivate_mipmap_pp_->Apply(); depth_deriative_small_tex_->CopyToSubTexture2D(*depth_deriative_tex_, 0, i, 0, 0, width / 2, height / 2, 0, i - 1, 0, 0, width / 2, height / 2); } }
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(); }
void MultiResLayer::SetSubsplatStencil(CameraPtr const & vp_camera) { *subsplat_depth_deriv_tex_param_ = depth_deriative_tex_; *subsplat_normal_cone_tex_param_ = normal_cone_tex_; *subsplat_depth_normal_threshold_param_ = float2(0.001f * vp_camera->FarPlane(), 0.77f); *subsplat_far_plane_param_ = float2(vp_camera->FarPlane(), 1.0f / vp_camera->FarPlane()); RenderEngine& re = Context::Instance().RenderFactoryInstance().RenderEngineInstance(); for (size_t i = 0; i < multi_res_fbs_.size(); ++ i) { re.BindFrameBuffer(multi_res_fbs_[i]); multi_res_fbs_[i]->Clear(FrameBuffer::CBM_Color | FrameBuffer::CBM_Depth | FrameBuffer::CBM_Stencil, Color(0, 0, 0, 0), 0.0f, 128); *subsplat_cur_lower_level_param_ = int2(static_cast<int>(i), static_cast<int>(i + 1)); *subsplat_is_not_first_last_level_param_ = int2(i > 0, i < multi_res_fbs_.size() - 1); re.Render(*subsplat_stencil_tech_, *rl_quad_); } }