-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDX12ChunksScene.cpp
415 lines (353 loc) · 16.3 KB
/
DX12ChunksScene.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
#include "scene.hpp"
#include "d3dx12.h"
#include "util.hpp"
#include <wrl/client.h>
using Microsoft::WRL::ComPtr;
extern int WIN_W, WIN_H, SHADOW_RES;
void WaitForPreviousFrame();
extern ID3D12Device* g_device12;
extern ID3D12DescriptorHeap* g_rtv_heap;
extern int g_frame_index;
extern ID3D12Resource* g_rendertargets[];
extern unsigned g_rtv_descriptor_size;
extern ID3D12CommandQueue* g_command_queue;
extern IDXGISwapChain3* g_swapchain;
/*
cbuffer CBPerObject : register(b0) {
float4x4 M;
float4x4 V;
float4x4 P;
};
cbuffer CBPerScene : register(b1) {
float3 dir_light;
float4x4 lightPV;
float4 cam_pos;
}
*/
DX12ChunksScene::DX12ChunksScene() {
// Chunk pass and per-object constant buffer
chunk_pass_normal = new ChunkPass();
chunk_pass_normal->AllocateConstantBuffers(20);
chunk_pass_normal->InitD3D12DefaultPalette();
chunk_pass_depth = new ChunkPass();
chunk_pass_depth->AllocateConstantBuffers(20);
chunk_pass_depth->InitD3D12DefaultPalette();
InitCommandList();
InitResources();
total_secs = 0.0f;
}
void DX12ChunksScene::InitCommandList() {
CE(g_device12->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
IID_PPV_ARGS(&command_allocator)));
CE(g_device12->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT,
command_allocator, nullptr, IID_PPV_ARGS(&command_list)));
CE(command_list->Close());
}
void DX12ChunksScene::InitResources() {
// Projection Matrix
projection_matrix = DirectX::XMMatrixPerspectiveFovLH(
60.0f * 3.14159f / 180.0f,
WIN_W * 1.0f / WIN_H, 0.01f, 499.0f);
// Camera
camera = new Camera();
camera->pos = glm::vec3(0, 0, 80);
camera->lookdir = glm::vec3(0, 0, -1);
camera->up = glm::vec3(0, 1, 0);
// Directional Light
dir_light = new DirectionalLight(glm::vec3(-1, -1, -1), glm::vec3(50, 50, 50));
// Chunk
chunk = new Chunk();
chunk->LoadDefault();
chunk->BuildBuffers(nullptr);
chunk_index = new ChunkGrid("../climb/chr.vox");
chunk_sprite = new ChunkSprite(chunk_index);
// Per-Scene Constant buffer's resource
// 0-255:给所有Chunks共享的Per-Scene Buffer
// 256-511:给Backdrop使用的Per-Object Buffer
CE(g_device12->CreateCommittedResource(
&keep(CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD)),
D3D12_HEAP_FLAG_NONE,
&keep(CD3DX12_RESOURCE_DESC::Buffer(512)),
D3D12_RESOURCE_STATE_GENERIC_READ,
nullptr,
IID_PPV_ARGS(&d_per_scene_cb)));
// CBV descriptor heap
D3D12_DESCRIPTOR_HEAP_DESC cbv_heap_desc{};
cbv_heap_desc.NumDescriptors = 3; // Per-object CB, Per-scene CB, Shadow Map SRV
cbv_heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
cbv_heap_desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
CE(g_device12->CreateDescriptorHeap(&cbv_heap_desc, IID_PPV_ARGS(&cbv_heap)));
cbv_descriptor_size = g_device12->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
// Per Scene CB view
D3D12_CONSTANT_BUFFER_VIEW_DESC per_scene_cbv_desc{};
per_scene_cbv_desc.BufferLocation = d_per_scene_cb->GetGPUVirtualAddress();
per_scene_cbv_desc.SizeInBytes = 512; // Must be a multiple of 256
CD3DX12_CPU_DESCRIPTOR_HANDLE handle1(cbv_heap->GetCPUDescriptorHandleForHeapStart());
g_device12->CreateConstantBufferView(&per_scene_cbv_desc, handle1);
// Per Object CB view (Deprecated, it's now in ChunkPass)
/*handle1.Offset(cbv_descriptor_size);
D3D12_CONSTANT_BUFFER_VIEW_DESC per_obj_cbv_desc{};
per_obj_cbv_desc.BufferLocation = chunk_pass_normal->d_per_object_cbs->GetGPUVirtualAddress();
per_obj_cbv_desc.SizeInBytes = 256;
g_device12->CreateConstantBufferView(&per_obj_cbv_desc, handle1);*/
// Depth buffer
D3D12_CLEAR_VALUE depthOptimizedClearValue = {};
depthOptimizedClearValue.Format = DXGI_FORMAT_D32_FLOAT;
depthOptimizedClearValue.DepthStencil.Depth = 1.0f;
depthOptimizedClearValue.DepthStencil.Stencil = 0;
CE(g_device12->CreateCommittedResource(
&keep(CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT)),
D3D12_HEAP_FLAG_NONE,
&keep(CD3DX12_RESOURCE_DESC::Tex2D(
DXGI_FORMAT_R32_TYPELESS, WIN_W, WIN_H, 1, 0, 1, 0,
D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL)),
D3D12_RESOURCE_STATE_DEPTH_WRITE,
&depthOptimizedClearValue,
IID_PPV_ARGS(&depth_buffer)));
// DSV descriptor heap
D3D12_DESCRIPTOR_HEAP_DESC dsv_heap_desc{};
dsv_heap_desc.NumDescriptors = 2;
dsv_heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV;
dsv_heap_desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
CE(g_device12->CreateDescriptorHeap(&dsv_heap_desc, IID_PPV_ARGS(&dsv_heap)));
dsv_descriptor_size = g_device12->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_DSV);
// DSV
D3D12_DEPTH_STENCIL_VIEW_DESC dsv_desc = { };
dsv_desc.Format = DXGI_FORMAT_D32_FLOAT;
dsv_desc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D;
dsv_desc.Flags = D3D12_DSV_FLAG_NONE;
g_device12->CreateDepthStencilView(depth_buffer, &dsv_desc, dsv_heap->GetCPUDescriptorHandleForHeapStart());
// GBuffer RTV & Shadow Map SRV & RTV
{
D3D12_DESCRIPTOR_HEAP_DESC desc = {
.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV,
.NumDescriptors = 2, // GBuffer 与 ShadowMap
.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE,
};
CE(g_device12->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&rtv_heap)));
D3D12_CLEAR_VALUE zero{};
zero.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
CE(g_device12->CreateCommittedResource(
&keep(CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT)),
D3D12_HEAP_FLAG_NONE,
&keep(CD3DX12_RESOURCE_DESC::Tex2D(
DXGI_FORMAT_R32G32B32A32_FLOAT, WIN_W, WIN_H, 1, 0, 1, 0,
D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET)),
D3D12_RESOURCE_STATE_RENDER_TARGET,
&zero,
IID_PPV_ARGS(&gbuffer)));
CD3DX12_CPU_DESCRIPTOR_HANDLE rtv_handle(rtv_heap->GetCPUDescriptorHandleForHeapStart());
g_device12->CreateRenderTargetView(gbuffer, nullptr, rtv_handle);
D3D12_CLEAR_VALUE shadow_map_clear{};
shadow_map_clear.Format = DXGI_FORMAT_D32_FLOAT;
shadow_map_clear.DepthStencil.Depth = 1.0f;
CE(g_device12->CreateCommittedResource(
&keep(CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT)),
D3D12_HEAP_FLAG_NONE,
&keep(CD3DX12_RESOURCE_DESC::Tex2D(
DXGI_FORMAT_R32_TYPELESS, 512, 512, 1, 0, 1, 0,
D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL)),
D3D12_RESOURCE_STATE_GENERIC_READ,
&shadow_map_clear,
IID_PPV_ARGS(&shadow_map)));
D3D12_SHADER_RESOURCE_VIEW_DESC srv_desc{};
srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
srv_desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
srv_desc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
srv_desc.Texture2D.MostDetailedMip = 0;
srv_desc.Texture2D.MipLevels = 1;
handle1.Offset(cbv_descriptor_size);
g_device12->CreateShaderResourceView(shadow_map, &srv_desc, handle1);
CD3DX12_CPU_DESCRIPTOR_HANDLE handle_dsv(dsv_heap->GetCPUDescriptorHandleForHeapStart());
handle_dsv.Offset(dsv_descriptor_size);
g_device12->CreateDepthStencilView(shadow_map, &dsv_desc, handle_dsv);
}
// Backdrop
const float L = 80.0f, H = -35.0f;
float backdrop_verts[] = { // X, Y, Z, nidx, data, ao
-L, H, L, 4, 44, 0,
L, H, L, 4, 44, 0,
-L, H, -L, 4, 44, 0,
L, H, L, 4, 44, 0,
L, H, -L, 4, 44, 0,
-L, H, -L, 4, 44, 0,
};
CE(g_device12->CreateCommittedResource(
&keep(CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD)),
D3D12_HEAP_FLAG_NONE,
&keep(CD3DX12_RESOURCE_DESC::Buffer(sizeof(backdrop_verts))),
D3D12_RESOURCE_STATE_GENERIC_READ,
nullptr,
IID_PPV_ARGS(&backdrop_vert_buf)));
UINT8* pData;
CD3DX12_RANGE readRange(0, 0);
CE(backdrop_vert_buf->Map(0, &readRange, (void**)&pData));
memcpy(pData, backdrop_verts, sizeof(backdrop_verts));
backdrop_vert_buf->Unmap(0, nullptr);
backdrop_vbv.BufferLocation = backdrop_vert_buf->GetGPUVirtualAddress();
backdrop_vbv.StrideInBytes = sizeof(float) * 6;
backdrop_vbv.SizeInBytes = sizeof(backdrop_verts);
}
void DX12ChunksScene::Render() {
CD3DX12_CPU_DESCRIPTOR_HANDLE handle_rtv(
g_rtv_heap->GetCPUDescriptorHandleForHeapStart(),
g_frame_index, g_rtv_descriptor_size);
CD3DX12_CPU_DESCRIPTOR_HANDLE handle_rtv_gbuffer(
rtv_heap->GetCPUDescriptorHandleForHeapStart(),
0, 0);
CD3DX12_CPU_DESCRIPTOR_HANDLE handle_rtv_shadowmap(
rtv_heap->GetCPUDescriptorHandleForHeapStart(),
1, g_rtv_descriptor_size);
CD3DX12_CPU_DESCRIPTOR_HANDLE handle_dsv(
dsv_heap->GetCPUDescriptorHandleForHeapStart(), 0, dsv_descriptor_size);
CD3DX12_CPU_DESCRIPTOR_HANDLE handle_dsv_shadowmap = handle_dsv;
handle_dsv_shadowmap.Offset(dsv_descriptor_size);
ID3D12DescriptorHeap* ppHeaps[] = { cbv_heap };
CE(command_allocator->Reset());
CE(command_list->Reset(command_allocator, chunk_pass_normal->pipeline_state_depth_only));
command_list->SetGraphicsRootSignature(chunk_pass_normal->root_signature_default_palette);
command_list->ResourceBarrier(1, &keep(CD3DX12_RESOURCE_BARRIER::Transition(
shadow_map,
D3D12_RESOURCE_STATE_GENERIC_READ,
D3D12_RESOURCE_STATE_DEPTH_WRITE)));
command_list->ClearDepthStencilView(handle_dsv_shadowmap, D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr);
// Depth pass
command_list->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
D3D12_VIEWPORT viewport_depth = CD3DX12_VIEWPORT(0.0f, 0.0f, 1.0f * SHADOW_RES, 1.0f * SHADOW_RES, 0.0f, 1.0f);
D3D12_RECT scissor_depth = CD3DX12_RECT(0, 0, long(SHADOW_RES), long(SHADOW_RES));
command_list->RSSetViewports(1, &viewport_depth);
command_list->RSSetScissorRects(1, &scissor_depth);
command_list->OMSetRenderTargets(0, nullptr, FALSE, &handle_dsv_shadowmap);
command_list->SetDescriptorHeaps(_countof(ppHeaps), ppHeaps);
command_list->SetGraphicsRootConstantBufferView(1, d_per_scene_cb->GetGPUVirtualAddress()); // Per-scene CB
{
const int N = int(chunk_pass_depth->chunk_instances.size());
for (int i = 0; i < N; i++) {
Chunk* c = chunk_pass_depth->chunk_instances[i];
D3D12_GPU_VIRTUAL_ADDRESS cbv0_addr = chunk_pass_depth->d_per_object_cbs->GetGPUVirtualAddress() + 256 * i;
command_list->SetGraphicsRootConstantBufferView(0, cbv0_addr); // Per-object CB
command_list->IASetVertexBuffers(0, 1, &(c->d3d12_vertex_buffer_view));
command_list->DrawInstanced(c->tri_count * 3, 1, 0, 0);
}
}
CE(command_list->Close());
g_command_queue->ExecuteCommandLists(1,
(ID3D12CommandList* const*)&command_list);
CE(command_list->Reset(command_allocator, chunk_pass_normal->pipeline_state_default_palette));
command_list->SetGraphicsRootSignature(chunk_pass_normal->root_signature_default_palette);
command_list->ResourceBarrier(1, &keep(CD3DX12_RESOURCE_BARRIER::Transition(
shadow_map,
D3D12_RESOURCE_STATE_DEPTH_WRITE,
D3D12_RESOURCE_STATE_GENERIC_READ)));
float bg_color[] = { 0.8f, 0.8f, 0.8f, 1.0f };
command_list->ResourceBarrier(1, &keep(CD3DX12_RESOURCE_BARRIER::Transition(
g_rendertargets[g_frame_index],
D3D12_RESOURCE_STATE_PRESENT,
D3D12_RESOURCE_STATE_RENDER_TARGET)));
command_list->ClearRenderTargetView(handle_rtv, bg_color, 0, nullptr);
float zero4[] = { 0.0f, 0.0f, 0.0f, 0.0f };
command_list->ClearRenderTargetView(handle_rtv_gbuffer, zero4, 0, nullptr);
command_list->ClearDepthStencilView(handle_dsv, D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr);
command_list->SetDescriptorHeaps(_countof(ppHeaps), ppHeaps);
CD3DX12_GPU_DESCRIPTOR_HANDLE handle_srv(cbv_heap->GetGPUDescriptorHandleForHeapStart(), 1, cbv_descriptor_size);
command_list->SetGraphicsRootDescriptorTable(2, handle_srv);
command_list->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
D3D12_CPU_DESCRIPTOR_HANDLE rtvs[] = {
handle_rtv, handle_rtv_gbuffer
};
D3D12_VIEWPORT viewport = CD3DX12_VIEWPORT(0.0f, 0.0f, 1.0f * WIN_W, 1.0f * WIN_H, 0.0f, 1.0f);
D3D12_RECT scissor = CD3DX12_RECT(0, 0, long(WIN_W), long(WIN_H));
command_list->SetGraphicsRootSignature(chunk_pass_normal->root_signature_default_palette);
command_list->RSSetViewports(1, &viewport);
command_list->RSSetScissorRects(1, &scissor);
command_list->OMSetRenderTargets(2, rtvs, FALSE, &handle_dsv);
command_list->SetGraphicsRootConstantBufferView(1, d_per_scene_cb->GetGPUVirtualAddress()); // Per-scene CB
{
const int N = int(chunk_pass_normal->chunk_instances.size());
for (int i = 0; i < N; i++) {
Chunk* c = chunk_pass_normal->chunk_instances[i];
D3D12_GPU_VIRTUAL_ADDRESS cbv0_addr = chunk_pass_normal->d_per_object_cbs->GetGPUVirtualAddress() + 256 * i;
command_list->SetGraphicsRootConstantBufferView(0, cbv0_addr); // Per-object CB
command_list->IASetVertexBuffers(0, 1, &(c->d3d12_vertex_buffer_view));
command_list->DrawInstanced(c->tri_count * 3, 1, 0, 0);
}
}
// Draw Backdrop
command_list->SetGraphicsRootConstantBufferView(0, d_per_scene_cb->GetGPUVirtualAddress() + 256);
command_list->IASetVertexBuffers(0, 1, &(backdrop_vbv));
command_list->DrawInstanced(6, 1, 0, 0);
command_list->ResourceBarrier(1, &keep(CD3DX12_RESOURCE_BARRIER::Transition(
g_rendertargets[g_frame_index],
D3D12_RESOURCE_STATE_RENDER_TARGET,
D3D12_RESOURCE_STATE_PRESENT)));
CE(command_list->Close());
g_command_queue->ExecuteCommandLists(1,
(ID3D12CommandList* const*)&command_list);
CE(g_swapchain->Present(1, 0));
WaitForPreviousFrame();
}
void DX12ChunksScene::Update(float secs) {
total_secs += secs;
DirectX::XMVECTOR D = dir_light->GetDir_D3D11();
DirectX::XMMATRIX PV = dir_light->GetPV_D3D11();
DirectX::XMVECTOR pos = camera->GetPos_D3D11();
UpdatePerSceneCB(&D, &PV, &pos);
DirectX::XMMATRIX M = DirectX::XMMatrixIdentity();
const float l = Chunk::size;
M *= DirectX::XMMatrixTranslation(-l * 0.5f, -l * 0.5f, l * 0.5f);
DirectX::XMVECTOR rot_axis;
rot_axis.m128_f32[0] = 0.0f;
rot_axis.m128_f32[1] = 1.0f;
rot_axis.m128_f32[2] = 0.0f;
M *= DirectX::XMMatrixRotationAxis(rot_axis, total_secs * 3.14159f / 2.0f); // 绕着物体原点转
M *= DirectX::XMMatrixTranslation(0.0f, -20.0f, 0.0f); // 绕世界坐标转(?)
DirectX::XMMATRIX M0 = M;
DirectX::XMMATRIX V = camera->GetViewMatrix_D3D11();
// Depth-only pass
chunk_pass_depth->StartPass();
DirectX::XMMATRIX P_dirlight = dir_light->GetP_D3D11_DXMath();
DirectX::XMMATRIX V_dirlight = dir_light->GetV_D3D11();
M = M0;
chunk->RecordRenderCommand_D3D12(chunk_pass_depth, M, V_dirlight, P_dirlight);
M *= DirectX::XMMatrixTranslation(0.0f, 40.0f, 0.0f);
chunk->RecordRenderCommand_D3D12(chunk_pass_depth, M, V_dirlight, P_dirlight);
const glm::mat3 orientation = glm::rotate(total_secs * 3.14159f / 2.0f, glm::vec3(0, 1, 0));
chunk_index->RecordRenderCommand_D3D12(chunk_pass_depth,
glm::vec3(30, 0, 0), glm::vec3(1, 1, 1), orientation,
chunk_index->Size() * 0.5f, V_dirlight, P_dirlight);
chunk_sprite->pos = glm::vec3(-30, 0, 0);
chunk_sprite->RotateAroundLocalAxis(glm::vec3(0, 1, 0), secs * 180.0f / 2.0f);
chunk_sprite->RecordRenderCommand_D3D12(chunk_pass_depth, V, P_dirlight);
chunk_pass_depth->EndPass();
// Normal Pass
chunk_pass_normal->StartPass();
M = M0;
chunk->RecordRenderCommand_D3D12(chunk_pass_normal, M, V, projection_matrix);
M *= DirectX::XMMatrixTranslation(0.0f, 40.0f, 0.0f);
chunk->RecordRenderCommand_D3D12(chunk_pass_normal, M, V, projection_matrix);
chunk_index->RecordRenderCommand_D3D12(chunk_pass_normal,
glm::vec3(30, 0, 0), glm::vec3(1, 1, 1), orientation,
chunk_index->Size() * 0.5f, V, projection_matrix);
chunk_sprite->pos = glm::vec3(-30, 0, 0);
chunk_sprite->RotateAroundLocalAxis(glm::vec3(0, 1, 0), secs * 180.0f / 2.0f);
chunk_sprite->RecordRenderCommand_D3D12(chunk_pass_normal, V, projection_matrix);
chunk_pass_normal->EndPass();
}
void DX12ChunksScene::UpdatePerSceneCB(
const DirectX::XMVECTOR* dir_light,
const DirectX::XMMATRIX* lightPV,
const DirectX::XMVECTOR* camPos) {
CD3DX12_RANGE read_range(0, sizeof(PerSceneCB));
char* ptr;
CE(d_per_scene_cb->Map(0, &read_range, (void**)&ptr));
h_per_scene_cb.dir_light = *dir_light;
h_per_scene_cb.lightPV = *lightPV;
h_per_scene_cb.cam_pos = *camPos;
memcpy(ptr, &h_per_scene_cb, sizeof(PerSceneCB));
PerObjectCB backdrop_perobject_cb{};
backdrop_perobject_cb.M = DirectX::XMMatrixIdentity();
backdrop_perobject_cb.V = camera->GetViewMatrix_D3D11();
backdrop_perobject_cb.P = projection_matrix;
memcpy(ptr + 256, &backdrop_perobject_cb, sizeof(PerObjectCB));
d_per_scene_cb->Unmap(0, nullptr);
}