-
Notifications
You must be signed in to change notification settings - Fork 226
/
Bokeh12.cpp
635 lines (509 loc) · 20.9 KB
/
Bokeh12.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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
//--------------------------------------------------------------------------------------
// AdvancedESRAM12.cpp
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#include "pch.h"
#include "Bokeh12.h"
extern void ExitSample() noexcept;
using namespace DirectX;
using namespace ATG;
using namespace SimpleMath;
using Microsoft::WRL::ComPtr;
#pragma region Constants & Helpers
namespace
{
//--------------------------------------
// Definitions
static const int PRESET_SCENE_COUNT = 4;
enum DescriptorHeapIndex
{
SRV_Font = 0,
SRV_CtrlFont,
SRV_SceneColor,
SRV_SceneDepth,
SRV_Count
};
enum RTVDescriptorHeapIndex
{
RTV_SceneColor = 0,
RTV_Count
};
enum DSVDescriptorHeapIndex
{
DSV_SceneDepth = 0,
DSV_Count
};
enum TimerIndex
{
TI_Frame,
TI_Scene,
TI_Bokeh,
TI_Copy
};
// Barebones definition of scene objects.
struct ObjectDefinition
{
Matrix world;
size_t modelIndex;
};
//--------------------------------------
// Constants
// Assest paths.
const wchar_t* const s_modelPaths[] =
{
L"scanner.sdkmesh",
L"occcity.sdkmesh",
L"column.sdkmesh",
};
// Barebones definition of a scene.
const ObjectDefinition s_sceneDefinition[] =
{
{ XMMatrixIdentity(), 0 },
{ XMMatrixRotationY(XM_2PI * (1.0f / 6.0f)), 0 },
{ XMMatrixRotationY(XM_2PI * (2.0f / 6.0f)), 0 },
{ XMMatrixRotationY(XM_2PI * (3.0f / 6.0f)), 0 },
{ XMMatrixRotationY(XM_2PI * (4.0f / 6.0f)), 0 },
{ XMMatrixRotationY(XM_2PI * (5.0f / 6.0f)), 0 },
{ XMMatrixIdentity(), 1 },
{ XMMatrixIdentity(), 2 },
};
// Sample Constants
const DXGI_FORMAT c_colorFormat = DXGI_FORMAT_R16G16B16A16_FLOAT;
const DXGI_FORMAT c_depthFormat = DXGI_FORMAT_D32_FLOAT;
//-----------------------------------
// Helper Functions
void AddMod(int& value, int add, int mod)
{
int res = (value + add) % mod;
value = res < 0 ? mod - 1 : res;
}
void IncrMod(int& value, int mod) { AddMod(value, 1, mod); }
void DecrMod(int& value, int mod) { AddMod(value, -1, mod); }
}
#pragma endregion
#pragma region Construction
Sample::Sample() noexcept(false)
: m_displayWidth(0)
, m_displayHeight(0)
, m_frame(0)
, m_presetScene(0)
, m_cameraAngle(0.0f)
, m_cameraElevation(5.0f)
, m_cameraDistance(5.0f)
{
m_deviceResources = std::make_unique<DX::DeviceResources>(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN, 2, DX::DeviceResources::c_Enable4K_UHD);
// performance / quality tradeoff
m_bokehParams.maxCoCSizeNear = 32; // maximum allowed radius
m_bokehParams.maxCoCSizeFar = 32;
m_bokehParams.switchover1[0] = 16; // near/far 1/2 -> 1/4 switchover threshold in pixels (radius)
m_bokehParams.switchover1[1] = 16; // make larger to have higher quality/lower speed
m_bokehParams.switchover2[0] = 16; // near 1/4 -> 1/8
m_bokehParams.switchover2[1] = 16; //
// edges blend
m_bokehParams.initialEnergyScale = 1.72f;
m_bokehParams.useFastShader = true;
SetPredefinedScene(0);
}
// Initialize the Direct3D resources required to run.
void Sample::Initialize(IUnknown* window)
{
m_deviceResources->SetWindow(window);
m_deviceResources->CreateDeviceResources();
CreateDeviceDependentResources();
m_deviceResources->CreateWindowSizeDependentResources();
CreateWindowSizeDependentResources();
}
#pragma endregion
#pragma region Frame Update
// Executes basic render loop.
void Sample::Tick()
{
PIXBeginEvent(PIX_COLOR_DEFAULT, L"Frame %llu", m_frame);
m_timer.Tick([&]()
{
Update(m_timer);
});
Render();
PIXEndEvent();
++m_frame;
}
void Sample::Update(const DX::StepTimer&)
{
using ButtonState = DirectX::GamePad::ButtonStateTracker::ButtonState;
PIXBeginEvent(PIX_COLOR_DEFAULT, L"Update");
auto pad = m_gamePad.GetState(0);
if (pad.IsConnected())
{
m_gamePadButtons.Update(pad);
if (pad.IsViewPressed())
{
ExitSample();
}
m_cameraAngle -= pad.thumbSticks.leftX * 0.2f;
m_cameraElevation = std::max(-10.f, std::min(10.f, m_cameraElevation - pad.thumbSticks.leftY * 0.2f));
m_cameraDistance = std::max(1.f, std::min(10.f, m_cameraDistance - pad.thumbSticks.rightY * 0.2f));
// Focus Length
if (pad.IsDPadLeftPressed())
{
// longest super telephoto Canon F/11 lens is 1.2 meter
// so let's limit it to 200mm because even that can produce blurs of radius of 100+ in the near plane
m_bokehParams.focusLength = std::min(0.2f, m_bokehParams.focusLength + 0.01f);
}
if (pad.IsDPadRightPressed())
{
m_bokehParams.focusLength = std::max(0.025f, m_bokehParams.focusLength - 0.01f);
}
// FNumber
if (pad.IsAPressed())
{
m_bokehParams.FNumber = std::min(64.0f, m_bokehParams.FNumber + 0.1f);
}
if (pad.IsBPressed())
{
m_bokehParams.FNumber = std::max(1.0f, m_bokehParams.FNumber - 0.1f);
}
// Focal Plane
if (pad.IsYPressed())
{
m_bokehParams.focalPlane = std::min(10.0f, m_bokehParams.focalPlane + 0.01f);
}
if (pad.IsXPressed())
{
m_bokehParams.focalPlane = std::max(0.5f, m_bokehParams.focalPlane - 0.01f);
}
// Max Near CoC Size
if (pad.IsLeftShoulderPressed())
{
m_bokehParams.maxCoCSizeNear = std::max(1.0f, m_bokehParams.maxCoCSizeNear - 1.f);
}
if (pad.IsLeftTriggerPressed())
{
m_bokehParams.maxCoCSizeNear = std::min(128.0f, m_bokehParams.maxCoCSizeNear + 1.f);
}
// Max Far CoC Size
if (pad.IsRightShoulderPressed())
{
m_bokehParams.maxCoCSizeFar = std::max(1.0f, m_bokehParams.maxCoCSizeFar - 1.f);
}
if (pad.IsRightTriggerPressed())
{
m_bokehParams.maxCoCSizeFar = std::min(128.0f, m_bokehParams.maxCoCSizeFar + 1.f);
}
// Toggle fast bokeh shader
if (m_gamePadButtons.dpadUp == ButtonState::PRESSED)
{
m_bokehParams.useFastShader = !m_bokehParams.useFastShader;
}
// Iterate through preset parameters & cam position
if (m_gamePadButtons.dpadDown == ButtonState::PRESSED)
{
IncrMod(m_presetScene, PRESET_SCENE_COUNT);
SetPredefinedScene(m_presetScene);
}
}
else
{
m_gamePadButtons.Reset();
}
// Update the scene.
CalculateCameraMatrix();
for (int i = 0; i < m_scene.size(); ++i)
{
Model::UpdateEffectMatrices(m_scene[i].effects, m_scene[i].world, m_matView, m_matProj);
}
PIXEndEvent();
}
#pragma endregion
#pragma region Frame Render
void Sample::Render()
{
// Don't try to render anything before the first Update.
if (m_timer.GetFrameCount() == 0)
{
return;
}
// Prepare the command list to render a new frame.
m_deviceResources->Prepare();
auto commandList = m_deviceResources->GetCommandList();
m_profiler->BeginFrame(commandList);
m_profiler->Start(commandList, TI_Frame);
D3D12_CPU_DESCRIPTOR_HANDLE hRTVScene = m_rtvPile->GetCpuHandle(RTV_SceneColor);
D3D12_CPU_DESCRIPTOR_HANDLE hDSV = m_dsvPile->GetCpuHandle(DSV_SceneDepth);
TransitionResource(commandList, m_sceneColor.Get(), D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_RENDER_TARGET);
TransitionResource(commandList, m_sceneDepth.Get(), D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_DEPTH_WRITE);
commandList->ClearRenderTargetView(hRTVScene, DirectX::Colors::Transparent, 0, nullptr);
commandList->ClearDepthStencilView(hDSV, D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0x0, 0, nullptr);
commandList->OMSetRenderTargets(1, &hRTVScene, false, &hDSV);
D3D12_VIEWPORT viewport = m_deviceResources->GetScreenViewport();
commandList->RSSetViewports(1, &viewport);
D3D12_RECT scissor = m_deviceResources->GetScissorRect();
commandList->RSSetScissorRects(1, &scissor);
//------------------------------
// Scene
{
ScopedPixEvent Scene(commandList, PIX_COLOR_DEFAULT, L"Scene");
m_profiler->Start(commandList, TI_Scene);
// render the city and microscopes
for (int i = 0; i < m_scene.size(); ++i)
{
m_scene[i].model->DrawOpaque(commandList, m_scene[i].effects.begin());
}
m_profiler->Stop(commandList, TI_Scene);
}
//------------------------------
// Bokeh
{
ScopedPixEvent Bokeh(commandList, PIX_COLOR_DEFAULT, L"Bokeh");
m_profiler->Start(commandList, TI_Bokeh);
TransitionResource(commandList, m_sceneDepth.Get(), D3D12_RESOURCE_STATE_DEPTH_WRITE, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
m_bokehDOF->Render(commandList, m_sceneColor.Get(), m_cpuPile->GetCpuHandle(SRV_SceneColor), m_cpuPile->GetCpuHandle(SRV_SceneDepth), hRTVScene, m_matInvProj, m_bokehParams, false);
TransitionResource(commandList, m_sceneDepth.Get(), D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_COMMON);
m_profiler->Stop(commandList, TI_Bokeh);
}
//------------------------------
// Copy
{
ScopedPixEvent Copy(commandList, PIX_COLOR_DEFAULT, L"Copy");
m_profiler->Start(commandList, TI_Copy);
TransitionResource(commandList, m_sceneColor.Get(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
D3D12_CPU_DESCRIPTOR_HANDLE hRTV = m_deviceResources->GetRenderTargetView();
commandList->OMSetRenderTargets(1, &hRTV, true, nullptr);
D3D12_GPU_DESCRIPTOR_HANDLE hSRV = m_srvPile->GetGpuHandle(SRV_SceneColor);
m_copyShader->SetSourceTexture(hSRV, m_sceneColor.Get());
m_copyShader->Process(commandList);
TransitionResource(commandList, m_sceneColor.Get(), D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_COMMON);
m_profiler->Stop(commandList, TI_Copy);
}
//------------------------------
// HUD
{
ScopedPixEvent HUD(commandList, PIX_COLOR_DEFAULT, L"HUD");
// performance printout
const float frameTime = m_profiler->GetAverageMS(TI_Frame);
const float sceneTime = m_profiler->GetAverageMS(TI_Scene);
const float bokehTime = m_profiler->GetAverageMS(TI_Bokeh);
const float copyTime = m_profiler->GetAverageMS(TI_Copy);
auto safe = SimpleMath::Viewport::ComputeTitleSafeArea(m_displayWidth, m_displayHeight);
wchar_t textBuffer[256] = {};
XMFLOAT2 textPos = XMFLOAT2(float(safe.left), float(safe.top));
XMVECTOR textColor = ATG::Colors::Green;
m_hudBatch->Begin(commandList);
m_smallFont->DrawString(m_hudBatch.get(), L"Bokeh Sample", textPos, textColor);
textPos.y += m_smallFont->GetLineSpacing();
_snwprintf_s(textBuffer, _TRUNCATE,
L"Frame CPU: %.2f ms \nFrame GPU: %.2f ms \nScene: %.2f ms \nBokeh: %.2f ms \nFinal copy: %.2f ms",
1000 * m_timer.GetElapsedSeconds(),
frameTime,
sceneTime,
bokehTime,
copyTime);
m_smallFont->DrawString(m_hudBatch.get(), textBuffer, textPos, textColor);
_snwprintf_s(textBuffer, _TRUNCATE,
L"[DPad] Up/Down Fast Bokeh: %s \n\
[DPad] Left/Right Lens: %.2fmm \n\
[A][B] F/%.1f \n\
[X][Y] Focal Plane: %.2fm \n\
[LB][LT] CoC Near: %.1f \n\
[RB][RT] CoC Far: %.1f \n\
[View] Exit",
m_bokehParams.useFastShader ? L"true" : L"false",
m_bokehParams.focusLength * 1000.f,
m_bokehParams.FNumber,
m_bokehParams.focalPlane,
m_bokehParams.maxCoCSizeNear,
m_bokehParams.maxCoCSizeFar);
textPos.y = float(safe.bottom - m_smallFont->GetLineSpacing() * 7);
DX::DrawControllerString(m_hudBatch.get(), m_smallFont.get(), m_ctrlFont.get(), textBuffer, textPos, textColor);
m_hudBatch->End();
m_profiler->Stop(commandList, TI_Frame);
}
m_profiler->EndFrame(commandList);
// Show the new frame.
{
m_deviceResources->Present();
m_graphicsMemory->Commit(m_deviceResources->GetCommandQueue());
}
}
#pragma endregion
#pragma region Message Handlers
// Message handlers
void Sample::OnSuspending()
{
auto queue = m_deviceResources->GetCommandQueue();
queue->SuspendX(0);
}
void Sample::OnResuming()
{
auto queue = m_deviceResources->GetCommandQueue();
queue->ResumeX();
m_timer.ResetElapsedTime();
m_gamePadButtons.Reset();
}
#pragma endregion
#pragma region Direct3D Resources
void Sample::CreateDeviceDependentResources()
{
auto device = m_deviceResources->GetD3DDevice();
m_graphicsMemory = std::make_unique<GraphicsMemory>(device);
m_profiler = std::make_unique<DX::GPUTimer>(device, m_deviceResources->GetCommandQueue());
// State objects
m_commonStates = std::make_unique<DirectX::CommonStates>(device);
// Create heap
m_cpuPile = std::make_unique<DescriptorPile>(device,
128,
DescriptorHeapIndex::SRV_Count);
m_srvPile = std::make_unique<DescriptorPile>(device,
128,
DescriptorHeapIndex::SRV_Count);
m_rtvPile = std::make_unique<DescriptorPile>(device,
D3D12_DESCRIPTOR_HEAP_TYPE_RTV,
D3D12_DESCRIPTOR_HEAP_FLAG_NONE,
128,
RTVDescriptorHeapIndex::RTV_Count);
m_dsvPile = std::make_unique<DescriptorPile>(device,
D3D12_DESCRIPTOR_HEAP_TYPE_DSV,
D3D12_DESCRIPTOR_HEAP_FLAG_NONE,
128,
DSVDescriptorHeapIndex::DSV_Count);
// Load models from disk.
m_models.resize(_countof(s_modelPaths));
for (int i = 0; i < m_models.size(); ++i)
{
m_models[i] = Model::CreateFromSDKMESH(device, s_modelPaths[i]);
}
// Upload textures to GPU.
ResourceUploadBatch resourceUpload(device);
resourceUpload.Begin();
m_bokehDOF = std::make_unique<BokehEffect>(device, c_colorFormat, m_graphicsMemory.get(), resourceUpload);
m_textureFactory = std::make_unique<EffectTextureFactory>(device, resourceUpload, m_srvPile->Heap());
auto texOffsets = std::vector<size_t>(m_models.size());
for (int i = 0; i < m_models.size(); ++i)
{
size_t _;
m_srvPile->AllocateRange(m_models[i]->textureNames.size(), texOffsets[i], _);
m_models[i]->LoadTextures(*m_textureFactory, int(texOffsets[i]));
}
// HUD
auto backBufferRts = RenderTargetState(m_deviceResources->GetBackBufferFormat(), m_deviceResources->GetDepthBufferFormat());
auto spritePSD = SpriteBatchPipelineStateDescription(backBufferRts, &CommonStates::AlphaBlend);
m_hudBatch = std::make_unique<SpriteBatch>(device, resourceUpload, spritePSD);
auto finished = resourceUpload.End(m_deviceResources->GetCommandQueue());
finished.wait();
//-------------------------------------------------------
// Instantiate objects from basic scene definition.
auto effectFactory = EffectFactory(m_srvPile->Heap(), m_commonStates->Heap());
auto objectRTState = RenderTargetState(c_colorFormat, c_depthFormat);
auto objectPSD = EffectPipelineStateDescription(
nullptr,
CommonStates::Opaque,
CommonStates::DepthDefault,
CommonStates::CullCounterClockwise,
objectRTState,
D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE);
m_scene.resize(_countof(s_sceneDefinition));
for (int i = 0; i < m_scene.size(); i++)
{
size_t index = s_sceneDefinition[i].modelIndex;
assert(index < m_models.size());
auto& model = *m_models[index];
m_scene[i].world = s_sceneDefinition[i].world;
m_scene[i].model = &model;
m_scene[i].effects = model.CreateEffects(effectFactory, objectPSD, objectPSD, int(texOffsets[index]));
std::for_each(
m_scene[i].effects.begin(),
m_scene[i].effects.end(),
[&](std::shared_ptr<IEffect>& e)
{
static_cast<BasicEffect*>(e.get())->SetEmissiveColor(XMVectorSet(1.0f, 1.0f, 1.0f, 1.0f));
});
}
auto postRtState = RenderTargetState(m_deviceResources->GetBackBufferFormat(), DXGI_FORMAT_UNKNOWN);
m_copyShader = std::make_unique<BasicPostProcess>(device, postRtState, BasicPostProcess::Copy);
}
// Allocate all memory resources that change on a window SizeChanged event.
void Sample::CreateWindowSizeDependentResources()
{
auto device = m_deviceResources->GetD3DDevice();
const auto size = m_deviceResources->GetOutputSize();
// Calculate display dimensions.
m_displayWidth = size.right - size.left;
m_displayHeight = size.bottom - size.top;
m_bokehDOF->ResizeResources(device, m_displayWidth, m_displayHeight);
// create scene render target
D3D12_CLEAR_VALUE colorClearValue = CD3DX12_CLEAR_VALUE(c_colorFormat, DirectX::Colors::Transparent);
CreateColorTextureAndViews(device, m_displayWidth, m_displayHeight, c_colorFormat, m_sceneColor.ReleaseAndGetAddressOf(), m_rtvPile->GetCpuHandle(RTV_SceneColor), m_cpuPile->GetCpuHandle(SRV_SceneColor), &colorClearValue);
device->CopyDescriptorsSimple(1, m_srvPile->GetCpuHandle(SRV_SceneColor), m_cpuPile->GetCpuHandle(SRV_SceneColor), D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
D3D12_CLEAR_VALUE depthClearValue = CD3DX12_CLEAR_VALUE(c_depthFormat, 1.0f, 0x0);
CreateDepthTextureAndViews(device, m_displayWidth, m_displayHeight, c_depthFormat, m_sceneDepth.ReleaseAndGetAddressOf(), m_dsvPile->GetCpuHandle(DSV_SceneDepth), m_cpuPile->GetCpuHandle(SRV_SceneDepth), &depthClearValue);
device->CopyDescriptorsSimple(1, m_srvPile->GetCpuHandle(SRV_SceneDepth), m_cpuPile->GetCpuHandle(SRV_SceneDepth), D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
// Set hud sprite viewport
m_hudBatch->SetViewport(m_deviceResources->GetScreenViewport());
// Begin uploading texture resources
{
ResourceUploadBatch resourceUpload(device);
resourceUpload.Begin();
m_smallFont = std::make_unique<SpriteFont>(device, resourceUpload,
(size.bottom > 1080) ? L"SegoeUI_36.spritefont" : L"SegoeUI_18.spritefont",
m_srvPile->GetCpuHandle(DescriptorHeapIndex::SRV_Font),
m_srvPile->GetGpuHandle(DescriptorHeapIndex::SRV_Font));
m_ctrlFont = std::make_unique<SpriteFont>(device, resourceUpload,
(size.bottom > 1080) ? L"XboxOneControllerLegend.spritefont" : L"XboxOneControllerLegendSmall.spritefont",
m_srvPile->GetCpuHandle(DescriptorHeapIndex::SRV_CtrlFont),
m_srvPile->GetGpuHandle(DescriptorHeapIndex::SRV_CtrlFont));
auto finished = resourceUpload.End(m_deviceResources->GetCommandQueue());
finished.wait();
}
}
void Sample::SetPredefinedScene(int index)
{
switch (index)
{
default:
// macro scene
case 0:
m_bokehParams.focusLength = 0.075f; // 75 mm lens
m_bokehParams.FNumber = 2.8f; // F/2.8 aperture
m_bokehParams.focalPlane = 0.5f; // focus distance
m_cameraAngle = -0.8f; // radians
m_cameraElevation = 0.8f;
m_cameraDistance = 1.1f;
break;
case 1:
// default scene
m_bokehParams.focusLength = 0.075f; // 75 mm lens
m_bokehParams.FNumber = 2.8f; // F/2.8 aperture
m_bokehParams.focalPlane = 2.5f; // focus distance
m_cameraAngle = -0.8f; // radians
m_cameraElevation = 0.8f;
m_cameraDistance = 2.3f;
break;
// defocused background
case 2:
m_bokehParams.focusLength = 0.075f; // 75 mm lens
m_bokehParams.FNumber = 2.8f; // F/2.8 aperture
m_bokehParams.focalPlane = 1.f; // focus distance
m_cameraAngle = -2.4f; // radians
m_cameraElevation = 0.8f;
m_cameraDistance = 2.5f;
break;
// doll house
case 3:
m_bokehParams.focusLength = 0.175f; // 175 mm lens
m_bokehParams.FNumber = 2.8f; // F/2.8 aperture
m_bokehParams.focalPlane = 2.5f; // focus distance
m_cameraAngle = -1.28f; // radians
m_cameraElevation = 0.8f;
m_cameraDistance = 3.1f;
break;
}
}
void Sample::CalculateCameraMatrix()
{
XMVECTOR eye = XMVectorSet(sinf(m_cameraAngle) * m_cameraDistance, m_cameraElevation, cosf(m_cameraAngle) * m_cameraDistance, 0);
m_matView = XMMatrixLookAtLH(eye, XMVectorSet(0, 0, 0, 0), XMVectorSet(0, 1, 0, 0));
m_matProj = XMMatrixPerspectiveFovLH(XM_PI / 4.f, float(m_displayWidth) / float(m_displayHeight), 0.05f, 100);
m_matInvProj = XMMatrixInverse(nullptr, m_matProj);
}
#pragma endregion