@@ -15,37 +15,47 @@ void Light::Init() {
1515 GameObject::Init ();
1616
1717 if (D3D12* renderer = reinterpret_cast <D3D12*>(this ->m_renderer )) {
18- Transform transform = this ->transform ;
19- XMVECTOR eye = XMVectorSet (
20- transform.location .x ,
21- transform.location .y ,
22- transform.location .z ,
23- 1 .0f
24- );
25-
26- float pitch = XMConvertToRadians (transform.rotation .x );
27- float yaw = XMConvertToRadians (transform.rotation .y );
28-
29- XMVECTOR forward = XMVectorSet (
30- cosf (pitch) * sinf (yaw),
31- -sinf (pitch),
32- -cosf (pitch) * cosf (yaw),
33- 0 .0f
34- );
18+ this ->InitConstantBuffers (renderer);
19+ renderer->m_dsvHeap ->Allocate (1 );
20+ this ->m_nDepthIndex = renderer->m_dsvHeap ->GetLastDescriptorIndex ();
3521
36- XMVECTOR at = XMVectorAdd (eye, forward );
22+ this -> m_shader = new Shader ( " ShadowPass.hlsl " , " VertexMain " , " PixelMain " );
3723
38- XMVECTOR up = XMVectorSet (0 .0f , 1 .0f , 0 .0f , 0 .0f );
39- this ->m_lightBuffer .View = XMMatrixTranspose (XMMatrixLookAtLH (eye, at, up));
40- this ->m_lightBuffer .Projection = XMMatrixTranspose (XMMatrixPerspectiveFovLH (
41- XMConvertToRadians (70 .f ),
42- static_cast <float >(renderer->m_nWidth ) / static_cast <float >(renderer->m_nHeight ),
43- 0 .001f ,
44- 3000 .f ));
4524 }
4625
4726}
4827
28+ void Light::InitConstantBuffers (D3D12* renderer) {
29+ Transform transform = this ->transform ;
30+ XMVECTOR eye = XMVectorSet (
31+ transform.location .x ,
32+ transform.location .y ,
33+ transform.location .z ,
34+ 1 .0f
35+ );
36+
37+ float pitch = XMConvertToRadians (transform.rotation .x );
38+ float yaw = XMConvertToRadians (transform.rotation .y );
39+
40+ XMVECTOR forward = XMVectorSet (
41+ cosf (pitch) * sinf (yaw),
42+ -sinf (pitch),
43+ -cosf (pitch) * cosf (yaw),
44+ 0 .0f
45+ );
46+
47+ XMVECTOR at = XMVectorAdd (eye, forward);
48+
49+ XMVECTOR up = XMVectorSet (0 .0f , 1 .0f , 0 .0f , 0 .0f );
50+ this ->m_lightBuffer .View = XMMatrixTranspose (XMMatrixLookAtLH (eye, at, up));
51+ this ->m_lightBuffer .Projection = XMMatrixTranspose (XMMatrixPerspectiveFovLH (
52+ XMConvertToRadians (70 .f ),
53+ static_cast <float >(renderer->m_nWidth ) / static_cast <float >(renderer->m_nHeight ),
54+ 0 .001f ,
55+ 3000 .f ));
56+ }
57+
58+
4959void Light::Update () {
5060 GameObject::Update ();
5161}
0 commit comments