Skip to content

Commit 399522f

Browse files
committed
Started with a PBR Pipeline
1 parent 133da5f commit 399522f

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

src/private/Core/Renderer/D3D12.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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();

src/private/Core/Renderer/ScreenQuad.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,27 @@ void ScreenQuad::D3D12Init(D3D12* renderer) {
8080
CD3DX12_DESCRIPTOR_RANGE albedoRange;
8181
CD3DX12_DESCRIPTOR_RANGE normalRange;
8282
CD3DX12_DESCRIPTOR_RANGE positionRange;
83+
CD3DX12_DESCRIPTOR_RANGE materialRange;
8384

8485
albedoRange.Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
8586
normalRange.Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 1);
8687
positionRange.Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 2);
88+
materialRange.Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 3);
8789

8890
CD3DX12_ROOT_PARAMETER albedoParam;
8991
CD3DX12_ROOT_PARAMETER normalParam;
9092
CD3DX12_ROOT_PARAMETER positionParam;
93+
CD3DX12_ROOT_PARAMETER materialParam;
9194
albedoParam.InitAsDescriptorTable(1, &albedoRange, D3D12_SHADER_VISIBILITY_PIXEL);
9295
normalParam.InitAsDescriptorTable(1, &normalRange, D3D12_SHADER_VISIBILITY_PIXEL);
9396
positionParam.InitAsDescriptorTable(1, &positionRange, D3D12_SHADER_VISIBILITY_PIXEL);
97+
materialParam.InitAsDescriptorTable(1, &materialRange, D3D12_SHADER_VISIBILITY_PIXEL);
9498

9599
D3D12_ROOT_PARAMETER rootParams[] = {
96100
albedoParam,
97101
normalParam,
98-
positionParam
102+
positionParam,
103+
materialParam
99104
};
100105

101106
D3D12_ROOT_SIGNATURE_DESC rootDesc = { };
@@ -162,6 +167,7 @@ void ScreenQuad::D3D12Render(D3D12* renderer) {
162167
Descriptor albedoDesc = renderer->m_cbvSrvHeap->GetDescriptor(0);
163168
Descriptor normalDesc = renderer->m_cbvSrvHeap->GetDescriptor(1);
164169
Descriptor positionDesc = renderer->m_cbvSrvHeap->GetDescriptor(2);
170+
Descriptor materialDesc = renderer->m_cbvSrvHeap->GetDescriptor(3);
165171
this->m_list->OMSetRenderTargets(1, &this->m_rtvDescriptor.cpuHandle, FALSE, nullptr);
166172
this->m_list->SetPipelineState(this->m_plState.Get());
167173
this->m_list->ClearRenderTargetView(this->m_rtvDescriptor.cpuHandle, RGBA{ 0.f, 0.f, 0.f, 1.f }, 0, nullptr);
@@ -174,6 +180,7 @@ void ScreenQuad::D3D12Render(D3D12* renderer) {
174180
this->m_list->SetGraphicsRootDescriptorTable(0, albedoDesc.gpuHandle);
175181
this->m_list->SetGraphicsRootDescriptorTable(1, normalDesc.gpuHandle);
176182
this->m_list->SetGraphicsRootDescriptorTable(2, positionDesc.gpuHandle);
183+
this->m_list->SetGraphicsRootDescriptorTable(3, materialDesc.gpuHandle);
177184

178185
this->m_list->DrawIndexedInstanced(this->m_indices.size(), 1, 0, 0, 0);
179186
}

src/public/Core/Renderer/D3D12.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@ class D3D12 : public Renderer {
6565
ComPtr<ID3D12Resource> m_albedoBuff;
6666
ComPtr<ID3D12Resource> m_uvBuff;
6767
ComPtr<ID3D12Resource> m_positionBuff;
68+
ComPtr<ID3D12Resource> m_materialBuff;
6869

6970
UINT m_nAlbedoIndex;
7071
UINT m_nUVIndex;
7172
UINT m_nPositionIndex;
73+
UINT m_nMaterialBuffIndex;
7274

7375
UINT m_nBackBuffers;
7476

0 commit comments

Comments
 (0)