Skip to content

Commit

Permalink
Added CMO support for DX12
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn committed Oct 14, 2021
1 parent bb7b56f commit b98e078
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 7 deletions.
2 changes: 2 additions & 0 deletions DirectXTKModelViewer_Desktop_2017_Win10.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,11 @@
<ItemGroup>
<Image Include="Atrium_diffuseIBL.dds" />
<Image Include="Atrium_specularIBL.dds" />
<Image Include="default.dds" />
<Image Include="directx.ico" />
<Image Include="Garage_diffuseIBL.dds" />
<Image Include="Garage_specularIBL.dds" />
<Image Include="smoothMap.dds" />
<Image Include="SunSubMixer_diffuseIBL.dds" />
<Image Include="SunSubMixer_specularIBL.dds" />
</ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions DirectXTKModelViewer_Desktop_2017_Win10.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
<Image Include="SunSubMixer_specularIBL.dds">
<Filter>Assets</Filter>
</Image>
<Image Include="default.dds">
<Filter>Assets</Filter>
</Image>
<Image Include="smoothMap.dds">
<Filter>Assets</Filter>
</Image>
</ItemGroup>
<ItemGroup>
<Manifest Include="settings.manifest">
Expand Down
2 changes: 2 additions & 0 deletions DirectXTKModelViewer_GDK_2017.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,10 @@
<ItemGroup>
<Image Include="Atrium_diffuseIBL.dds" />
<Image Include="Atrium_specularIBL.dds" />
<Image Include="default.dds" />
<Image Include="Garage_diffuseIBL.dds" />
<Image Include="Garage_specularIBL.dds" />
<Image Include="smoothMap.dds" />
<Image Include="SunSubMixer_diffuseIBL.dds" />
<Image Include="SunSubMixer_specularIBL.dds" />
</ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions DirectXTKModelViewer_GDK_2017.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,11 @@
<Image Include="SunSubMixer_specularIBL.dds">
<Filter>Assets</Filter>
</Image>
<Image Include="default.dds">
<Filter>Assets</Filter>
</Image>
<Image Include="smoothMap.dds">
<Filter>Assets</Filter>
</Image>
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions DirectXTKModelViewer_XDK_2017.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,12 @@
<ItemGroup>
<Image Include="Atrium_diffuseIBL.dds" />
<Image Include="Atrium_specularIBL.dds" />
<Image Include="default.dds" />
<Image Include="Garage_diffuseIBL.dds" />
<Image Include="Garage_specularIBL.dds" />
<Image Include="Logo.png" />
<Image Include="SmallLogo.png" />
<Image Include="smoothMap.dds" />
<Image Include="SplashScreen.png" />
<Image Include="StoreLogo.png" />
<Image Include="SunSubMixer_diffuseIBL.dds" />
Expand Down
6 changes: 6 additions & 0 deletions DirectXTKModelViewer_XDK_2017.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
<Image Include="SunSubMixer_specularIBL.dds">
<Filter>Assets</Filter>
</Image>
<Image Include="default.dds">
<Filter>Assets</Filter>
</Image>
<Image Include="smoothMap.dds">
<Filter>Assets</Filter>
</Image>
</ItemGroup>
<ItemGroup>
<None Include="comic.spritefont">
Expand Down
55 changes: 49 additions & 6 deletions Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Game::Game() noexcept(false) :
*m_szModelName = 0;
*m_szStatus = 0;
*m_szError = 0;

m_defaultTextureName = L"default.dds";
}

Game::~Game()
Expand Down Expand Up @@ -1000,6 +1002,16 @@ void Game::CreateDeviceDependentResources()
CreateShaderResourceView(device, m_irradianceIBL[j].Get(), m_resourceDescriptors->GetCpuHandle(Descriptors::IrradianceIBL1 + j), true);
}

#ifndef XBOX
wchar_t defaultTex[_MAX_PATH] = {};
DX::FindMediaFile(defaultTex, _MAX_PATH, m_defaultTextureName.c_str());

wchar_t defaultTexPath[_MAX_PATH] = {};
GetFullPathName(defaultTex, MAX_PATH, defaultTexPath, nullptr);

m_defaultTextureName = defaultTexPath;
#endif

auto uploadResourcesFinished = resourceUpload.End(m_deviceResources->GetCommandQueue());

m_deviceResources->WaitForGpu();
Expand Down Expand Up @@ -1128,6 +1140,7 @@ void Game::LoadModel()

bool isvbo = false;
bool issdkmesh2 = false;
bool iscmo = false;
try
{
if (_wcsicmp(ext, L".sdkmesh") == 0)
Expand All @@ -1143,7 +1156,12 @@ void Game::LoadModel()
}
}

m_model = Model::CreateFromSDKMESH(device, modelBin.data(), modelBin.size());
m_model = Model::CreateFromSDKMESH(device, modelBin.data(), modelBin.size(), ModelLoader_DisableSkinning);
}
else if (_wcsicmp(ext, L".cmo") == 0)
{
iscmo = true;
m_model = Model::CreateFromCMO(device, m_szModelName);
}
else if (_wcsicmp(ext, L".vbo") == 0)
{
Expand All @@ -1168,6 +1186,27 @@ void Game::LoadModel()

if (m_model)
{
// First check for 'missing' textures
int defaultTex = -1;

for (auto& it : m_model->materials)
{
if (it.enableSkinning || it.enableNormalMaps)
{
if (it.diffuseTextureIndex == -1)
{
if (defaultTex == -1)
{
defaultTex = static_cast<int>(m_model->textureNames.size());
m_model->textureNames.push_back(m_defaultTextureName);
}

it.diffuseTextureIndex = defaultTex;
it.samplerIndex = static_cast<int>(CommonStates::SamplerIndex::AnisotropicWrap);
}
}
}

ResourceUploadBatch resourceUpload(device);

resourceUpload.Begin();
Expand Down Expand Up @@ -1245,24 +1284,28 @@ void Game::LoadModel()
}
else
{
const auto& cull = iscmo ? CommonStates::CullCounterClockwise : CommonStates::CullClockwise;

EffectPipelineStateDescription pd(
nullptr,
CommonStates::Opaque,
CommonStates::DepthDefault,
CommonStates::CullClockwise,
cull,
hdrState);

EffectPipelineStateDescription pdAlpha(
nullptr,
CommonStates::AlphaBlend,
CommonStates::DepthDefault,
CommonStates::CullClockwise,
cull,
hdrState);

m_modelClockwise = m_model->CreateEffects(*fxFactory, pd, pdAlpha, txtOffset);

pd.rasterizerDesc = CommonStates::CullCounterClockwise;
pdAlpha.rasterizerDesc = CommonStates::CullCounterClockwise;
const auto& cull2 = iscmo ? CommonStates::CullClockwise : CommonStates::CullCounterClockwise;

pd.rasterizerDesc = cull2;
pdAlpha.rasterizerDesc = cull2;

m_modelCounterClockwise = m_model->CreateEffects(*fxFactory, pd, pdAlpha, txtOffset);

Expand Down Expand Up @@ -1517,7 +1560,7 @@ void Game::EnumerateModelFiles()

WIN32_FIND_DATA ffdata = {};

static const wchar_t* exts[] = { L"D:\\*.sdkmesh", L"D:\\*.vbo" };
static const wchar_t* exts[] = { L"D:\\*.sdkmesh", L"D:\\*.cmo", L"D:\\*.vbo" };

for (size_t j = 0; j < _countof(exts); ++j)
{
Expand Down
2 changes: 2 additions & 0 deletions Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ class Game
Microsoft::WRL::ComPtr<ID3D12Resource> m_radianceIBL[s_nIBL];
Microsoft::WRL::ComPtr<ID3D12Resource> m_irradianceIBL[s_nIBL];

std::wstring m_defaultTextureName;

enum Descriptors
{
ConsolasFont,
Expand Down
2 changes: 1 addition & 1 deletion Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
ofn.lpstrFile = szFile;
ofn.lpstrFile[0] = 0;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = L"DirectX SDK Mesh (SDKMESH)\0*.sdkmesh\0Vertex Buffer Object (VBO)\0*.vbo\0All Files\0*.*\0";
ofn.lpstrFilter = L"DirectX SDK Mesh (SDKMESH)\0*.sdkmesh\0Visual Studio Mesh (CMO)\0*.cmo\0Vertex Buffer Object (VBO)\0*.vbo\0All Files\0*.*\0";
ofn.nFilterIndex = s_filterIndex;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (GetOpenFileName(&ofn))
Expand Down
Binary file added default.dds
Binary file not shown.
Binary file added smoothMap.dds
Binary file not shown.

0 comments on commit b98e078

Please sign in to comment.