-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShadowMappingMain.cpp
163 lines (138 loc) · 4.83 KB
/
ShadowMappingMain.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
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
#include "pch.h"
#include "ShadowMappingMain.h"
#include <DirectXColors.h>
#include "DirectXHelper.h"
using namespace ShadowMapping;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::Storage;
// Loads and initializes application assets when the application is loaded.
ShadowMapSampleMain::ShadowMapSampleMain(const std::shared_ptr<DX::DeviceResources>& deviceResources) :
m_deviceResources(deviceResources)
{
// Register to be notified if the device is lost or recreated.
m_deviceResources->RegisterDeviceNotify(this);
m_shadowSceneRenderer = std::unique_ptr<ShadowSceneRenderer>(new ShadowSceneRenderer(m_deviceResources));
m_shadowSceneRenderer->CreateWindowSizeDependentResources();
m_deviceResources->RegisterDeviceNotify(this);
}
ShadowMapSampleMain::~ShadowMapSampleMain()
{
// Deregister device notification.
m_deviceResources->RegisterDeviceNotify(nullptr);
}
// Updates application state when the window size changes (e.g. device orientation change)
void ShadowMapSampleMain::UpdateForWindowSizeChange()
{
m_shadowSceneRenderer->CreateWindowSizeDependentResources();
}
// Updates the application state once per frame.
void ShadowMapSampleMain::Update()
{
// Update scene objects.
m_timer.Tick([&]()
{
m_shadowSceneRenderer->UpdateCamera(); //update Camera
m_shadowSceneRenderer->UpdateLight(); //update Light
m_shadowSceneRenderer->Update(m_timer);
});
}
// Renders the current frame according to the current application state.
// Returns true if the frame was rendered and is ready to be displayed.
bool ShadowMapSampleMain::Render()
{
// Don't try to render anything before the first Update.
if (m_timer.GetFrameCount() == 0)
{
return false;
}
//update MoveParameters if user input
m_shadowSceneRenderer->DirectInput(m_timer);
// Render the scene objects.
m_shadowSceneRenderer->Render();
return true;
}
// Notifies renderers that device resources need to be released.
void ShadowMapSampleMain::OnDeviceLost()
{
m_shadowSceneRenderer->ReleaseDeviceDependentResources();
}
// Notifies renderers that device resources may now be re-created.
void ShadowMapSampleMain::OnDeviceRestored()
{
m_shadowSceneRenderer->CreateDeviceDependentResources();
UpdateForWindowSizeChange();
}
/*
// Saves the current state of the app for suspend and terminate events.
void ShadowMapSampleMain::SaveInternalState(IPropertySet^ state)
{
// Save filtering setting.
bool filtering = GetFiltering();
Platform::String^ filteringKeyName = "SdkSample:EdgeFiltering";
if (state->HasKey(filteringKeyName))
{
state->Remove(filteringKeyName);
}
state->Insert(filteringKeyName, PropertyValue::CreateBoolean(filtering));
// Save shadow buffer dimension setting.
float shadowSize = GetShadowSize();
Platform::String^ shadowKeyName = "SdkSample:ShadowSize";
if (state->HasKey(shadowKeyName))
{
state->Remove(shadowKeyName);
}
state->Insert(shadowKeyName, PropertyValue::CreateSingle(shadowSize));
}
// Loads the current state of the app for resume events.
void ShadowMapSampleMain::LoadInternalState(IPropertySet^ state)
{
// Load filtering setting.
bool filtering = false;
Platform::String^ filteringKeyName = "SdkSample:EdgeFiltering";
if (state->HasKey(filteringKeyName))
{
filtering = safe_cast<IPropertyValue^>(state->Lookup(filteringKeyName))->GetBoolean();
}
SetFiltering(filtering);
// Load shadow buffer dimension setting.
float shadowSize = 1024.f;
Platform::String^ shadowKeyName = "SdkSample:ShadowSize";
if (state->HasKey(shadowKeyName))
{
shadowSize = safe_cast<IPropertyValue^>(state->Lookup(shadowKeyName))->GetSingle();
}
SetShadowSize(shadowSize);
}*/
/*
// Set the filtering type for the shadow map.
void ShadowMapSampleMain::SetFiltering(bool useLinear)
{
m_shadowSceneRenderer->SetFiltering(useLinear);
}
// Get the filtering type for the shadow map.
bool ShadowMapSampleMain::GetFiltering()
{
return m_shadowSceneRenderer->GetFiltering();
}
// Set the shadow buffer dimension.
void ShadowMapSampleMain::SetShadowSize(float size)
{
m_shadowSceneRenderer->SetShadowDimension(size);
}
// Get the shadow buffer dimension.
float ShadowMapSampleMain::GetShadowSize()
{
return m_shadowSceneRenderer->GetShadowDimension();
}
// Get device feature support info for D3D9 shadows.
bool ShadowMapSampleMain::GetD3D9ShadowsSupported()
{
return m_shadowSceneRenderer->GetD3D9ShadowsSupported();
}*/