Bomberman-OverlordEngine-x64 / BombermanGame / Materials / Shadow / DiffuseMaterial_Shadow_Skinned.cpp
DiffuseMaterial_Shadow_Skinned.cpp
Raw
#include "stdafx.h"
#include "DiffuseMaterial_Shadow_Skinned.h"

DiffuseMaterial_Shadow_Skinned::DiffuseMaterial_Shadow_Skinned():
	Material(L"Effects/Shadow/PosNormTex3D_Shadow_Skinned.fx")
{}

void DiffuseMaterial_Shadow_Skinned::SetDiffuseTexture(const std::wstring& assetFile)
{
	m_pDiffuseTexture = ContentManager::Load<TextureData>(assetFile);
	SetVariable_Texture(L"gDiffuseMap", m_pDiffuseTexture);
}

void DiffuseMaterial_Shadow_Skinned::InitializeEffectVariables()
{
}

void DiffuseMaterial_Shadow_Skinned::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 });

	// 4. Update Bones
	//Retrieve The Animator from the ModelComponent
	ModelAnimator* pAnimator = pModel->GetAnimator();

	//Make sure the animator is not NULL (ASSERT_NULL_)
	ASSERT_NULL_(pAnimator);

	//Retrieve the BoneTransforms from the Animator
	std::vector<XMFLOAT4X4> boneTransforms = pAnimator->GetBoneTransforms();

	//Set the 'gBones' variable of the effect (MatrixArray) > BoneTransforms
	SetVariable_MatrixArray(L"gBones", reinterpret_cast<float*>(boneTransforms.data()), UINT(boneTransforms.size()));

	//Update Shadow Variables
	//const auto pShadowMapRenderer = ShadowMapRenderer::Get();
	//...
}