@@ -97,42 +97,48 @@ void D3D12::Init(HWND hwnd) {
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 );
9999 this ->CreateTexture (this ->m_nWidth , this ->m_nHeight , 8 , D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET, this ->m_positionBuff );
100+ this ->CreateTexture (this ->m_nWidth , this ->m_nHeight , 8 , D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET, this ->m_materialBuff );
100101
101102 this ->m_albedoBuff ->SetName (L" Albedo" );
102103 this ->m_uvBuff ->SetName (L" Normal" );
103104 this ->m_positionBuff ->SetName (L" Position" );
105+ this ->m_materialBuff ->SetName (L" Material Properties" );
104106
105107 this ->m_nAlbedoIndex = this ->m_rtvHeap ->GetDescriptorCount ();
106108 this ->m_nUVIndex = this ->m_nAlbedoIndex + 1 ;
107109 this ->m_nPositionIndex = this ->m_nUVIndex + 1 ;
110+ this ->m_nMaterialBuffIndex = this ->m_nPositionIndex + 1 ;
108111
109112 D3D12_RENDER_TARGET_VIEW_DESC GBufferDesc = { };
110113 GBufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
111114 GBufferDesc.Texture2D .MipSlice = 1 ;
112115 GBufferDesc.Texture2D .PlaneSlice = 1 ;
113116 GBufferDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DMS;
114117
115- this ->m_rtvHeap ->Allocate (3 );
118+ this ->m_rtvHeap ->Allocate (4 );
116119
117120 Descriptor albedoDesc = this ->m_rtvHeap ->GetDescriptor (this ->m_nAlbedoIndex );
118121 Descriptor UVDesc = this ->m_rtvHeap ->GetDescriptor (this ->m_nUVIndex );
119122 Descriptor positionDesc = this ->m_rtvHeap ->GetDescriptor (this ->m_nPositionIndex );
123+ Descriptor materialDesc = this ->m_rtvHeap ->GetDescriptor (this ->m_nMaterialBuffIndex );
120124
121125 this ->m_dev ->CreateRenderTargetView (this ->m_albedoBuff .Get (), &GBufferDesc, albedoDesc.cpuHandle );
122126 this ->m_dev ->CreateRenderTargetView (this ->m_uvBuff .Get (), &GBufferDesc, UVDesc.cpuHandle );
123127 this ->m_dev ->CreateRenderTargetView (this ->m_positionBuff .Get (), &GBufferDesc, positionDesc.cpuHandle );
128+ this ->m_dev ->CreateRenderTargetView (this ->m_materialBuff .Get (), &GBufferDesc, materialDesc.cpuHandle );
124129
125130 this ->ResourceBarrier (this ->m_albedoBuff .Get (), D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_RENDER_TARGET);
126131 this ->ResourceBarrier (this ->m_uvBuff .Get (), D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_RENDER_TARGET);
127132 this ->ResourceBarrier (this ->m_positionBuff .Get (), D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_RENDER_TARGET);
133+ this ->ResourceBarrier (this ->m_materialBuff .Get (), D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_RENDER_TARGET);
128134
129135 /* Track states */
130136 m_resourceStates[this ->m_albedoBuff .Get ()] = D3D12_RESOURCE_STATE_RENDER_TARGET;
131137 m_resourceStates[this ->m_uvBuff .Get ()] = D3D12_RESOURCE_STATE_RENDER_TARGET;
132138 m_resourceStates[this ->m_positionBuff .Get ()] = D3D12_RESOURCE_STATE_RENDER_TARGET;
133139
134- // We'll allocate 3 for our ScreenQuad.
135- this ->m_cbvSrvHeap = new DescriptorHeap (3 , D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, true );
140+ // We'll allocate the initial value for our ScreenQuad.
141+ this ->m_cbvSrvHeap = new DescriptorHeap (4 , D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, true );
136142
137143 this ->m_screenQuad = new ScreenQuad ();
138144 this ->m_screenQuad ->Init ();
0 commit comments