@@ -10,7 +10,7 @@ D3D12::D3D12() : Renderer::Renderer() {
1010
1111 this ->m_nAlbedoIndex = 0 ;
1212 this ->m_nUVIndex = 0 ;
13- this ->m_nPositionIndex = 0 ;
13+ this ->m_nEmissiveIndex = 0 ;
1414 this ->sceneMgr = SceneManager::GetInstance ();
1515 this ->m_samplerHeap = nullptr ;
1616 this ->m_editor = Editor::GetInstance ();
@@ -96,18 +96,18 @@ void D3D12::Init(HWND hwnd) {
9696
9797 this ->CreateTexture (this ->m_nWidth , this ->m_nHeight , 8 , D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET, this ->m_albedoBuff );
9898 this ->CreateTexture (this ->m_nWidth , this ->m_nHeight , 8 , D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET, this ->m_uvBuff );
99- this ->CreateTexture (this ->m_nWidth , this ->m_nHeight , 8 , D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET, this ->m_positionBuff );
99+ this ->CreateTexture (this ->m_nWidth , this ->m_nHeight , 8 , D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET, this ->m_emissiveBuff );
100100 this ->CreateTexture (this ->m_nWidth , this ->m_nHeight , 8 , D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET, this ->m_ORMBuff );
101101
102102 this ->m_albedoBuff ->SetName (L" Albedo" );
103103 this ->m_uvBuff ->SetName (L" Normal" );
104- this ->m_positionBuff ->SetName (L" Position " );
104+ this ->m_emissiveBuff ->SetName (L" Emissive " );
105105 this ->m_ORMBuff ->SetName (L" ORM G-Buffer" );
106106
107107 this ->m_nAlbedoIndex = this ->m_rtvHeap ->GetDescriptorCount ();
108108 this ->m_nUVIndex = this ->m_nAlbedoIndex + 1 ;
109- this ->m_nPositionIndex = this ->m_nUVIndex + 1 ;
110- this ->m_nORMIndex = this ->m_nPositionIndex + 1 ;
109+ this ->m_nEmissiveIndex = this ->m_nUVIndex + 1 ;
110+ this ->m_nORMIndex = this ->m_nEmissiveIndex + 1 ;
111111
112112 D3D12_RENDER_TARGET_VIEW_DESC GBufferDesc = { };
113113 GBufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
@@ -119,23 +119,23 @@ void D3D12::Init(HWND hwnd) {
119119
120120 Descriptor albedoDesc = this ->m_rtvHeap ->GetDescriptor (this ->m_nAlbedoIndex );
121121 Descriptor UVDesc = this ->m_rtvHeap ->GetDescriptor (this ->m_nUVIndex );
122- Descriptor positionDesc = this ->m_rtvHeap ->GetDescriptor (this ->m_nPositionIndex );
122+ Descriptor positionDesc = this ->m_rtvHeap ->GetDescriptor (this ->m_nEmissiveIndex );
123123 Descriptor ORMDesc = this ->m_rtvHeap ->GetDescriptor (this ->m_nORMIndex );
124124
125125 this ->m_dev ->CreateRenderTargetView (this ->m_albedoBuff .Get (), &GBufferDesc, albedoDesc.cpuHandle );
126126 this ->m_dev ->CreateRenderTargetView (this ->m_uvBuff .Get (), &GBufferDesc, UVDesc.cpuHandle );
127- this ->m_dev ->CreateRenderTargetView (this ->m_positionBuff .Get (), &GBufferDesc, positionDesc.cpuHandle );
127+ this ->m_dev ->CreateRenderTargetView (this ->m_emissiveBuff .Get (), &GBufferDesc, positionDesc.cpuHandle );
128128 this ->m_dev ->CreateRenderTargetView (this ->m_ORMBuff .Get (), &GBufferDesc, ORMDesc.cpuHandle );
129129
130130 this ->ResourceBarrier (this ->m_albedoBuff .Get (), D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_RENDER_TARGET);
131131 this ->ResourceBarrier (this ->m_uvBuff .Get (), D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_RENDER_TARGET);
132- this ->ResourceBarrier (this ->m_positionBuff .Get (), D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_RENDER_TARGET);
132+ this ->ResourceBarrier (this ->m_emissiveBuff .Get (), D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_RENDER_TARGET);
133133 this ->ResourceBarrier (this ->m_ORMBuff .Get (), D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_RENDER_TARGET);
134134
135135 /* Track states */
136136 m_resourceStates[this ->m_albedoBuff .Get ()] = D3D12_RESOURCE_STATE_RENDER_TARGET;
137137 m_resourceStates[this ->m_uvBuff .Get ()] = D3D12_RESOURCE_STATE_RENDER_TARGET;
138- m_resourceStates[this ->m_positionBuff .Get ()] = D3D12_RESOURCE_STATE_RENDER_TARGET;
138+ m_resourceStates[this ->m_emissiveBuff .Get ()] = D3D12_RESOURCE_STATE_RENDER_TARGET;
139139 m_resourceStates[this ->m_ORMBuff .Get ()] = D3D12_RESOURCE_STATE_RENDER_TARGET;
140140
141141 // We'll allocate the initial value for our ScreenQuad.
@@ -233,18 +233,29 @@ void D3D12::Update() {
233233 ComPtr<ID3D12Resource> actualBuffer = this ->m_backBuffers [this ->m_nActualBackBuffer ];
234234 this ->ResourceBarrier (actualBuffer, D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET);
235235
236+ ID3D12DescriptorHeap* descriptorHeaps[] = {
237+ this ->m_cbvSrvHeap ->m_heap .Get (),
238+ this ->m_samplerHeap ->m_heap .Get ()
239+ };
240+ this ->m_list ->SetDescriptorHeaps (_countof (descriptorHeaps), descriptorHeaps);
241+
242+ this ->m_list ->RSSetViewports (1 , &this ->m_viewport );
243+ this ->m_list ->RSSetScissorRects (1 , &this ->m_scissor );
244+
245+ this ->sceneMgr ->ShadowPass ();
246+
236247 if (this ->m_resourceStates [this ->m_albedoBuff .Get ()] != D3D12_RESOURCE_STATE_RENDER_TARGET) {
237248 this ->ResourceBarrier (this ->m_albedoBuff , D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET);
238249 this ->ResourceBarrier (this ->m_uvBuff , D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET);
239- this ->ResourceBarrier (this ->m_positionBuff , D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET);
250+ this ->ResourceBarrier (this ->m_emissiveBuff , D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET);
240251 this ->ResourceBarrier (this ->m_ORMBuff , D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET);
241252 }
242253
243254
244255 Descriptor albedoDesc = this ->m_rtvHeap ->GetDescriptor (this ->m_nAlbedoIndex );
245256 Descriptor UVDesc = this ->m_rtvHeap ->GetDescriptor (this ->m_nUVIndex );
246257 Descriptor ORMDesc = this ->m_rtvHeap ->GetDescriptor (this ->m_nORMIndex );
247- Descriptor positionDesc = this ->m_rtvHeap ->GetDescriptor (this ->m_nPositionIndex );
258+ Descriptor positionDesc = this ->m_rtvHeap ->GetDescriptor (this ->m_nEmissiveIndex );
248259 Descriptor dsvDesc = this ->m_dsvHeap ->GetDescriptor (0 );
249260 this ->m_list ->ClearRenderTargetView (albedoDesc.cpuHandle , RGBA{ 0 .f , 0 .f , 0 .f , 1 .f }, 0 , nullptr );
250261 this ->m_list ->ClearRenderTargetView (UVDesc.cpuHandle , RGBA{ 0 .f , 0 .f , 0 .f , 1 .f }, 0 , nullptr );
@@ -263,17 +274,12 @@ void D3D12::Update() {
263274 };
264275 this ->m_list ->OMSetRenderTargets (_countof (gbuffers), gbuffers, FALSE , &dsvDesc.cpuHandle );
265276
266- ID3D12DescriptorHeap* descriptorHeaps[] = {
267- this ->m_cbvSrvHeap ->m_heap .Get (),
268- this ->m_samplerHeap ->m_heap .Get ()
269- };
270- this ->m_list ->SetDescriptorHeaps (_countof (descriptorHeaps), descriptorHeaps);
271277
272278 this ->sceneMgr ->Render ();
273279
274280 this ->ResourceBarrier (this ->m_albedoBuff , D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
275281 this ->ResourceBarrier (this ->m_uvBuff , D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
276- this ->ResourceBarrier (this ->m_positionBuff , D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
282+ this ->ResourceBarrier (this ->m_emissiveBuff , D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
277283 this ->ResourceBarrier (this ->m_ORMBuff , D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
278284
279285 Descriptor rtv = this ->m_rtvHeap ->GetDescriptor (this ->m_nActualBackBuffer );
@@ -319,8 +325,6 @@ void D3D12::Update() {
319325
320326 ImGuizmo::SetRect (0 .0f , 0 .0f , static_cast <float >(this ->m_nWidth ), static_cast <float >(this ->m_nHeight ));
321327
322-
323-
324328 this ->m_editor ->Update ();
325329
326330 ImGui::Render ();
0 commit comments