Skip to content

Commit 982fda6

Browse files
committed
Light: Depth stencil view created
1 parent 8a95eef commit 982fda6

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

src/private/Core/GameObject/Light/Light.cpp

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,61 @@ void Light::Init() {
1616

1717
if (D3D12* renderer = reinterpret_cast<D3D12*>(this->m_renderer)) {
1818
this->InitConstantBuffers(renderer);
19+
20+
this->m_shader = new Shader("ShadowPass.hlsl", "VertexMain", "PixelMain");
1921
renderer->m_dsvHeap->Allocate(1);
2022
this->m_nDepthIndex = renderer->m_dsvHeap->GetLastDescriptorIndex();
2123

22-
this->m_shader = new Shader("ShadowPass.hlsl", "VertexMain", "PixelMain");
24+
D3D12_RESOURCE_DESC depthBuffDesc = { };
25+
depthBuffDesc.Format = DXGI_FORMAT_R24G8_TYPELESS;
26+
depthBuffDesc.SampleDesc.Count = 8;
27+
depthBuffDesc.Width = renderer->m_nWidth;
28+
depthBuffDesc.Height = renderer->m_nHeight;
29+
depthBuffDesc.MipLevels = 1;
30+
depthBuffDesc.DepthOrArraySize = 1;
31+
depthBuffDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
32+
depthBuffDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
33+
34+
D3D12_HEAP_PROPERTIES heapProps = { };
35+
heapProps.Type = D3D12_HEAP_TYPE_DEFAULT;
36+
37+
D3D12_CLEAR_VALUE dsvClear = { };
38+
dsvClear.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
39+
dsvClear.DepthStencil.Depth = 1.f;
40+
dsvClear.DepthStencil.Stencil = 0.f;
41+
42+
ThrowIfFailed(renderer->m_dev->CreateCommittedResource(
43+
&heapProps,
44+
D3D12_HEAP_FLAG_NONE,
45+
&depthBuffDesc,
46+
D3D12_RESOURCE_STATE_DEPTH_WRITE,
47+
&dsvClear,
48+
IID_PPV_ARGS(this->m_depth.GetAddressOf())
49+
));
50+
51+
this->m_depth->SetName(L"Shadow Map");
52+
53+
D3D12_DEPTH_STENCIL_VIEW_DESC dsvDesc = { };
54+
dsvDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
55+
dsvDesc.Flags = D3D12_DSV_FLAG_NONE;
56+
dsvDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2DMS;
2357

58+
Descriptor descriptor = renderer->m_dsvHeap->GetDescriptor(this->m_nDepthIndex);
59+
60+
renderer->m_dev->CreateDepthStencilView(this->m_depth.Get(), &dsvDesc, descriptor.cpuHandle);
2461
}
2562

2663
}
2764

65+
void Light::InitPipeline(D3D12* renderer) {
66+
CD3DX12_DESCRIPTOR_RANGE wvpRange = { };
67+
wvpRange.Init(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 1, 0);
68+
69+
CD3DX12_ROOT_PARAMETER wvpParam;
70+
wvpParam.InitAsConstantBufferView(0, D3D12_SHADER_VISIBILITY_VERTEX);
71+
72+
}
73+
2874
void Light::InitConstantBuffers(D3D12* renderer) {
2975
Transform transform = this->transform;
3076
XMVECTOR eye = XMVectorSet(
@@ -58,4 +104,9 @@ void Light::InitConstantBuffers(D3D12* renderer) {
58104

59105
void Light::Update() {
60106
GameObject::Update();
107+
this->InitConstantBuffers(dynamic_cast<D3D12*>(this->m_renderer));
108+
}
109+
110+
void Light::Render() {
111+
61112
}

src/public/Core/GameObject/Light/Light.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Light : public GameObject {
2626
UINT m_nDepthIndex;
2727

2828
void InitConstantBuffers(D3D12* renderer);
29+
void InitPipeline(D3D12* renderer);
2930

3031
Shader* m_shader;
3132
public:
@@ -38,4 +39,5 @@ class Light : public GameObject {
3839

3940
void Init() override;
4041
void Update() override;
42+
void Render() override;
4143
};

0 commit comments

Comments
 (0)