작성 중
인체공학 행렬이 적용된 Bone
생명체의 움직임을 묘사하기 위한 추가 연산이 들어있음
Constant Buffer로 넘기는 Bone Matrix를 현재는 255개를 미리 잡아놓고 사용하지만 필요한만큼만 사용할 수 있도록 변경
Animation만 있는 FBX의 경우 Mesh만 있는 FBX와 Mesh의 개수가 다를 수는 있지만, Bone의 개수는 동일. Bone의 이름이나 Index를 기반으로 두 file merge 작업
FBX Loader에서 처리하는 Animation Matrix연산을 미리 File로 저장해 둘 경우 Loading 과정 불필요
Character의 부위별로 다른 Object 병합 출력(장비 변경)
Character의 Object별로 다양한 Animation 존재 가능
Pixel을 Map의 Vertex와 Matching한 후, Color값을 통해 높이 계산
HRESULT hr = DirectX::CreateWICTextureFromFileEx(
g_dxWindow->GetDevice(), (kHeightMapPath + fileName).c_str(), 0, D3D11_USAGE_STAGING,
0, D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE, 0, DirectX::WIC_LOADER_DEFAULT,
&textureResource, nullptr);
CPU에서 처리해야 하므로 Buffer를 D3D11_USAGE_STAGING, D3D11_CPU_ACCESS_RW로 설정
// Pointer 형식으로 Buffer에 접근
// pData, RowPitch, DepthPitch를 가지고 있음
// RowPitch는 Texture의 Row크기
// DepthPitch는 DepthSlice에서 사용
D3D11_MAPPED_SUBRESOURCE MappedFaceDest;
if (SUCCEEDED(g_dxWindow->GetDeviceContext()->Map(texture2D, D3D11CalcSubresource(0, 0, 1), D3D11_MAP_READ, 0, &MappedFaceDest)))
{
UCHAR* pTexels = (UCHAR*)MappedFaceDest.pData;
minHeight = (float)pTexels[0] / 255.0f;
maxHeight = (float)pTexels[0] / 255.0f;
for (UINT row = 0; row < textureDesc.Height; row++)
{
UINT rowStart = row * MappedFaceDest.RowPitch;
for (UINT col = 0; col < textureDesc.Width; col++)
{
UINT colStart = col * 4;
UINT uRed = pTexels[rowStart + colStart + 0];
float heightData = (float)uRed / 255.0f;
_heightData[row * textureDesc.Width + col] = heightData;
minHeight = fmin(minHeight, heightData);
maxHeight = fmax(maxHeight, heightData);
}
}
g_dxWindow->GetDeviceContext()->Unmap(texture2D, D3D11CalcSubresource(0, 0, 1));
}
DeviceContext::Map(), DeviceContext::Unmap()으로 접근
이후 Face Normal을 통한 Vertex Normal 계산
Object의 Mesh가 모두 동일한 동차변환을 수행한다면 Normal Vector역시 동일한 변환을 수행하면 되지만, Vertex의 일부만 변형된다면 Normal Vector는 다시 계산되야 한다
충돌 연산 없이도 Height Map을 조회하여 Object가 지형 위를 이동하게 만들 수 있음
이 때, 부드러운 이동을 위해 Vertex와 Vertex사이는 보간연산하여 처리
Height Map Texture만을 이용해서 Height를 계산하는건 2D방식으로 간단하지만 지형 한가운데에 구멍이 있다던가 한다면 사용할 수 없음(3D 방식 사용)
셀 안의 정점 V가 어느 폴리곤 삼각형에 포함되는가?
는 이므로 만약 1보다 크다면 아랫폴리곤에 1보다 작다면 윗 폴리곤을 기반으로 보간 연산 수행