#include "stdafx.h" #include "DiffuseMaterial_Shadow.h" DiffuseMaterial_Shadow::DiffuseMaterial_Shadow(): Material(L"Effects/Shadow/PosNormTex3D_Shadow.fx") {} void DiffuseMaterial_Shadow::SetDiffuseTexture(const std::wstring& assetFile) { m_pDiffuseTexture = ContentManager::Load(assetFile); SetVariable_Texture(L"gDiffuseMap", m_pDiffuseTexture); } void DiffuseMaterial_Shadow::InitializeEffectVariables() { } void DiffuseMaterial_Shadow::OnUpdateModelVariables(const SceneContext& sceneContext, const ModelComponent* pModel) const { /* * TODO_W8 * Update The Shader Variables * 1. Update the LightWVP > Used to Transform a vertex into Light clipping space * LightWVP = model_world * light_viewprojection * (light_viewprojection [LightVP] can be acquired from the ShadowMapRenderer) */ const auto pShadowMapRenderer = ShadowMapRenderer::Get(); XMMATRIX lightVP = XMLoadFloat4x4(&pShadowMapRenderer->GetLightVP()); XMMATRIX modelWorld = XMLoadFloat4x4(&pModel->GetTransform()->GetWorld()); XMMATRIX result = XMMatrixMultiply(modelWorld, lightVP); XMFLOAT4X4 lightWorldView_Proj; XMStoreFloat4x4(&lightWorldView_Proj, result); SetVariable_Matrix(L"gWorldViewProj_Light", lightWorldView_Proj); // 2. Update the ShadowMap texture SetVariable_Texture(L"gShadowMap", pShadowMapRenderer->GetShadowMap()); XMFLOAT4 lightDir = sceneContext.pLights->GetDirectionalLight().direction; // 3. Update the Light Direction (retrieve the direction from the LightManager > sceneContext) SetVariable_Vector(L"gLightDirection", XMFLOAT3{ lightDir.x, lightDir.y, lightDir.z }); //Update Shadow Variables //const auto pShadowMapRenderer = ShadowMapRenderer::Get(); //... }