text: #include "render/renderer/pass_shadowmap.h"
  
  #include "core/asset/asset_subsystem.h"
  #include "render/render_subsystem.h"
  #include "render/interface/i_light.h"
  #include "render/rhi/rhi_device.h"
  #include "render/rhi/rhi_command_list.h"
  
  namespace luna
  {
  namespace render
  {
  
  void ShadowRenderPass::Init()
  {
  	RenderPass::Init();
  	ShaderAsset *shader_asset = g_asset_sys->LoadAsset<ShaderAsset>("/assets/built-in/depth.hlsl");
  	TSubPtr<RHIShaderCollection> depth_shader(this);
  	depth_shader = device->CreateShader();
  	depth_shader->Init(shader_asset->GetContent(), "shadow_map");
  
  	LVector<RHIPipelineStateDesc> piplines;
  	RHIPipelineStateDesc desc;
  	desc.CullMode = LUNAR_CULL_MODE_FRONT;
  	desc.DepthClipEnable = true;
  	desc.DepthFunc = RHIComparisionFunc::LUNAR_COMPARISON_FUNC_LESS;
  	desc.DepthTestEnable = true;
  	desc.DepthWriteEnable = true;
  	desc.FillMode = LUNAR_FILL_MODE_SOLID;
  	desc.VS = depth_shader->VS;
  	desc.PS = depth_shader->PS;
  
  	InitPipeline(desc);
  	m_using_mat_shader = false;
  	m_pass_name = "ShadowMap";
  	TSubPtr<RenderTarget> rt(this);
  	rt.SetPtr(TCreateObject<RenderTarget>());
  	rt->SetWidth(4096);
  	rt->SetHeight(4096);
  	rt->SetScreenRt(false);
  	rt->SetIsShaderResource(true);
  	rt->Update();
  	SetRenderTarget(rt.Get());
  }
  
  bool ShadowRenderPass::OnRenderObjDirtyFilter(RenderObject *node)
  {
  	return node->cast_shadow;	
  }
  
  void ShadowRenderPass::OnRenderObjPrepare(RenderObject *obj)
  {
  	RenderPass::OnRenderObjPrepare(obj);
  	IDirectionLight *main_light = g_render_sys->GetMainDirectnalLight();
  	if (main_light)
  	{
  		auto cb = m_origin->VS->GetConstantBuffer("LightBuffer");
  		if (cb)
  		{
  
  			struct
  			{
  				LMatrix4f view;
  				LMatrix4f proj;
  			} buf;
  			buf.view = *main_light->GetViewMatrix();
  			buf.proj = main_light->GetProjectionMatrix();
  			context->UpdateCB(cb, &buf);
  			context->BindCB(cb);
  		}
  	}
  }
  
  }
  }
  