Skip to content

Commit

Permalink
Updated DirectXTex, DirectXTK for February 2019
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn committed Feb 9, 2019
1 parent eee44a1 commit deee078
Show file tree
Hide file tree
Showing 34 changed files with 4,262 additions and 3,280 deletions.
2 changes: 1 addition & 1 deletion DirectXTK/DirectXTK_Desktop_2015.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<ClCompile Include="Src\Mouse.cpp" />
<ClCompile Include="Src\NormalMapEffect.cpp" />
<ClCompile Include="Src\PBREffect.cpp" />
<ClCompile Include="Src\PBREffectFactory.cpp" />
<ClCompile Include="Src\pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
Expand Down Expand Up @@ -488,7 +489,6 @@
<FileType>Document</FileType>
</None>
</ItemGroup>
<PropertyGroup Label="Globals" />
<PropertyGroup Label="Globals">
<ProjectGuid>{E0B52AE7-E160-4D32-BF3F-910B785E5A8E}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
Expand Down
3 changes: 3 additions & 0 deletions DirectXTK/DirectXTK_Desktop_2015.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@
<ClCompile Include="Src\DebugEffect.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Src\PBREffectFactory.cpp">
<Filter>Src</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="Src\Shaders\CompileShaders.cmd">
Expand Down
2 changes: 1 addition & 1 deletion DirectXTK/DirectXTK_Desktop_2015_Win10.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<ClCompile Include="Src\Mouse.cpp" />
<ClCompile Include="Src\NormalMapEffect.cpp" />
<ClCompile Include="Src\PBREffect.cpp" />
<ClCompile Include="Src\PBREffectFactory.cpp" />
<ClCompile Include="Src\pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
Expand Down Expand Up @@ -500,7 +501,6 @@
<FileType>Document</FileType>
</None>
</ItemGroup>
<PropertyGroup Label="Globals" />
<PropertyGroup Label="Globals">
<ProjectGuid>{E0B52AE7-E160-4D32-BF3F-910B785E5A8E}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
Expand Down
3 changes: 3 additions & 0 deletions DirectXTK/DirectXTK_Desktop_2015_Win10.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@
<ClCompile Include="Src\DebugEffect.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Src\PBREffectFactory.cpp">
<Filter>Src</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="Src\Shaders\CompileShaders.cmd">
Expand Down
2 changes: 1 addition & 1 deletion DirectXTK/DirectXTK_Desktop_2017.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<ClCompile Include="Src\Mouse.cpp" />
<ClCompile Include="Src\NormalMapEffect.cpp" />
<ClCompile Include="Src\PBREffect.cpp" />
<ClCompile Include="Src\PBREffectFactory.cpp" />
<ClCompile Include="Src\pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
Expand Down Expand Up @@ -488,7 +489,6 @@
<FileType>Document</FileType>
</None>
</ItemGroup>
<PropertyGroup Label="Globals" />
<PropertyGroup Label="Globals">
<ProjectGuid>{E0B52AE7-E160-4D32-BF3F-910B785E5A8E}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
Expand Down
3 changes: 3 additions & 0 deletions DirectXTK/DirectXTK_Desktop_2017.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@
<ClCompile Include="Src\DebugEffect.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Src\PBREffectFactory.cpp">
<Filter>Src</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="Src\Shaders\CompileShaders.cmd">
Expand Down
2 changes: 1 addition & 1 deletion DirectXTK/DirectXTK_Desktop_2017_Win10.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<ClCompile Include="Src\Mouse.cpp" />
<ClCompile Include="Src\NormalMapEffect.cpp" />
<ClCompile Include="Src\PBREffect.cpp" />
<ClCompile Include="Src\PBREffectFactory.cpp" />
<ClCompile Include="Src\pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
Expand Down Expand Up @@ -500,7 +501,6 @@
<FileType>Document</FileType>
</None>
</ItemGroup>
<PropertyGroup Label="Globals" />
<PropertyGroup Label="Globals">
<ProjectGuid>{E0B52AE7-E160-4D32-BF3F-910B785E5A8E}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
Expand Down
3 changes: 3 additions & 0 deletions DirectXTK/DirectXTK_Desktop_2017_Win10.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@
<ClCompile Include="Src\DebugEffect.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Src\PBREffectFactory.cpp">
<Filter>Src</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="Src\Shaders\CompileShaders.cmd">
Expand Down
43 changes: 41 additions & 2 deletions DirectXTK/Inc/Effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ namespace DirectX
const wchar_t* diffuseTexture;
const wchar_t* specularTexture;
const wchar_t* normalTexture;
const wchar_t* emissiveTexture;

EffectInfo() noexcept :
name(nullptr),
Expand All @@ -779,7 +780,8 @@ namespace DirectX
emissiveColor(0, 0, 0),
diffuseTexture(nullptr),
specularTexture(nullptr),
normalTexture(nullptr)
normalTexture(nullptr),
emissiveTexture(nullptr)
{}
};

Expand Down Expand Up @@ -830,6 +832,43 @@ namespace DirectX
};


// Factory for Physically Based Rendering (PBR)
class PBREffectFactory : public IEffectFactory
{
public:
explicit PBREffectFactory(_In_ ID3D11Device* device);
PBREffectFactory(PBREffectFactory&& moveFrom) noexcept;
PBREffectFactory& operator= (PBREffectFactory&& moveFrom) noexcept;

PBREffectFactory(PBREffectFactory const&) = delete;
PBREffectFactory& operator= (PBREffectFactory const&) = delete;

virtual ~PBREffectFactory() override;

// IEffectFactory methods.
virtual std::shared_ptr<IEffect> __cdecl CreateEffect(_In_ const EffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext) override;
virtual void __cdecl CreateTexture(_In_z_ const wchar_t* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView) override;

// Settings.
void __cdecl ReleaseCache();

void __cdecl SetSharing(bool enabled);

void __cdecl EnableForceSRGB(bool forceSRGB);

void __cdecl SetDirectory(_In_opt_z_ const wchar_t* path);

// Properties.
ID3D11Device* GetDevice() const;

private:
// Private implementation.
class Impl;

std::shared_ptr<Impl> pImpl;
};


// Factory for sharing Visual Studio Shader Designer (DGSL) shaders and texture resources
class DGSLEffectFactory : public IEffectFactory
{
Expand All @@ -850,7 +889,7 @@ namespace DirectX
// DGSL methods.
struct DGSLEffectInfo : public EffectInfo
{
static const int BaseTextureOffset = 3;
static const int BaseTextureOffset = 4;

const wchar_t* textures[DGSLEffect::MaxTextures - BaseTextureOffset];
const wchar_t* pixelShader;
Expand Down
12 changes: 12 additions & 0 deletions DirectXTK/Inc/SpriteFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace DirectX

virtual ~SpriteFont();

// Wide-character / UTF-16LE
void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, XMFLOAT2 const& position, FXMVECTOR color = Colors::White, float rotation = 0, XMFLOAT2 const& origin = Float2Zero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const;
void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, XMFLOAT2 const& position, FXMVECTOR color, float rotation, XMFLOAT2 const& origin, XMFLOAT2 const& scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const;
void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, FXMVECTOR position, FXMVECTOR color = Colors::White, float rotation = 0, FXMVECTOR origin = g_XMZero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const;
Expand All @@ -41,6 +42,17 @@ namespace DirectX
RECT __cdecl MeasureDrawBounds(_In_z_ wchar_t const* text, XMFLOAT2 const& position) const;
RECT XM_CALLCONV MeasureDrawBounds(_In_z_ wchar_t const* text, FXMVECTOR position) const;

// UTF-8
void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ char const* text, XMFLOAT2 const& position, FXMVECTOR color = Colors::White, float rotation = 0, XMFLOAT2 const& origin = Float2Zero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const;
void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ char const* text, XMFLOAT2 const& position, FXMVECTOR color, float rotation, XMFLOAT2 const& origin, XMFLOAT2 const& scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const;
void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ char const* text, FXMVECTOR position, FXMVECTOR color = Colors::White, float rotation = 0, FXMVECTOR origin = g_XMZero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const;
void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ char const* text, FXMVECTOR position, FXMVECTOR color, float rotation, FXMVECTOR origin, GXMVECTOR scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const;

XMVECTOR XM_CALLCONV MeasureString(_In_z_ char const* text) const;

RECT __cdecl MeasureDrawBounds(_In_z_ char const* text, XMFLOAT2 const& position) const;
RECT XM_CALLCONV MeasureDrawBounds(_In_z_ char const* text, FXMVECTOR position) const;

// Spacing properties
float __cdecl GetLineSpacing() const;
void __cdecl SetLineSpacing(float spacing);
Expand Down
8 changes: 7 additions & 1 deletion DirectXTK/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DirectXTK - the DirectX Tool Kit for DirectX 11

Copyright (c) Microsoft Corporation. All rights reserved.

November 16, 2018
February 7, 2019

This package contains the "DirectX Tool Kit", a collection of helper classes for
writing Direct3D 11 C++ code for Universal Windows Platform (UWP) apps for
Expand Down Expand Up @@ -113,6 +113,12 @@ RELEASE NOTES
RELEASE HISTORY
---------------

February 7, 2019
Model now supports loading SDKMESH v2 models
PBREffectFactory added to support PBR materials
PBREffect and NormalMapEffect shaders updated to support BC5_UNORM compressed normal maps
SpriteFont: DrawString overloads for UTF-8 chars in addition to UTF-16LE wide chars

November 16, 2018
VS 2017 updated for Windows 10 October 2018 Update SDK (17763)
ARM64 platform configurations added to UWP projects
Expand Down
10 changes: 10 additions & 0 deletions DirectXTK/Src/DGSLEffectFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,16 @@ std::shared_ptr<IEffect> DGSLEffectFactory::Impl::CreateDGSLEffect(DGSLEffectFac
effect->SetTextureEnabled(true);
}

if (info.emissiveTexture && *info.emissiveTexture)
{
ComPtr<ID3D11ShaderResourceView> srv;

factory->CreateTexture(info.emissiveTexture, deviceContext, srv.GetAddressOf());

effect->SetTexture(3, srv.Get());
effect->SetTextureEnabled(true);
}

for (size_t j = 0; j < _countof(info.textures); ++j)
{
if (info.textures[j] && *info.textures[j])
Expand Down
11 changes: 10 additions & 1 deletion DirectXTK/Src/EffectFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,17 @@ std::shared_ptr<IEffect> EffectFactory::Impl::CreateEffect(IEffectFactory* facto
effect->SetTexture(srv.Get());
}

if (info.specularTexture && *info.specularTexture)
if (info.emissiveTexture && *info.emissiveTexture)
{
ComPtr<ID3D11ShaderResourceView> srv;

factory->CreateTexture(info.emissiveTexture, deviceContext, srv.GetAddressOf());

effect->SetTexture2(srv.Get());
}
else if (info.specularTexture && *info.specularTexture)
{
// If there's no emissive texture specified, use the specular texture as the second texture
ComPtr<ID3D11ShaderResourceView> srv;

factory->CreateTexture(info.specularTexture, deviceContext, srv.GetAddressOf());
Expand Down
1 change: 1 addition & 0 deletions DirectXTK/Src/ModelLoadCMO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(ID3D11Device* d3dDevice, co
info.diffuseTexture = m.texture[0].empty() ? nullptr : m.texture[0].c_str();
info.specularTexture = m.texture[1].empty() ? nullptr : m.texture[1].c_str();
info.normalTexture = m.texture[2].empty() ? nullptr : m.texture[2].c_str();
info.emissiveTexture = m.texture[3].empty() ? nullptr : m.texture[3].c_str();
info.pixelShader = m.pixelShader.c_str();

const int offset = DGSLEffectFactory::DGSLEffectInfo::BaseTextureOffset;
Expand Down
74 changes: 67 additions & 7 deletions DirectXTK/Src/ModelLoadSDKMESH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,44 @@ namespace
m.alpha = (info.alpha < 1.f);
}

void LoadMaterial(const DXUT::SDKMESH_MATERIAL_V2& mh,
unsigned int flags,
IEffectFactory& fxFactory,
MaterialRecordSDKMESH& m)
{
wchar_t matName[DXUT::MAX_MATERIAL_NAME] = {};
MultiByteToWideChar(CP_UTF8, 0, mh.Name, -1, matName, DXUT::MAX_MATERIAL_NAME);

wchar_t albetoTexture[DXUT::MAX_TEXTURE_NAME] = {};
MultiByteToWideChar(CP_UTF8, 0, mh.AlbetoTexture, -1, albetoTexture, DXUT::MAX_TEXTURE_NAME);

wchar_t normalName[DXUT::MAX_TEXTURE_NAME] = {};
MultiByteToWideChar(CP_UTF8, 0, mh.NormalTexture, -1, normalName, DXUT::MAX_TEXTURE_NAME);

wchar_t rmaName[DXUT::MAX_TEXTURE_NAME] = {};
MultiByteToWideChar(CP_UTF8, 0, mh.RMATexture, -1, rmaName, DXUT::MAX_TEXTURE_NAME);

wchar_t emissiveName[DXUT::MAX_TEXTURE_NAME] = {};
MultiByteToWideChar(CP_UTF8, 0, mh.EmissiveTexture, -1, emissiveName, DXUT::MAX_TEXTURE_NAME);

EffectFactory::EffectInfo info;
info.name = matName;
info.perVertexColor = false;
info.enableSkinning = false;
info.enableDualTexture = false;
info.enableNormalMaps = true;
info.biasedVertexNormals = (flags & BIASED_VERTEX_NORMALS) != 0;
info.alpha = (!mh.Alpha) ? 1.f : mh.Alpha;

info.diffuseTexture = albetoTexture;
info.specularTexture = rmaName;
info.normalTexture = normalName;
info.emissiveTexture = emissiveName;

m.effect = fxFactory.CreateEffect(info, nullptr);
m.alpha = (info.alpha < 1.f);
}


//--------------------------------------------------------------------------------------
// Direct3D 9 Vertex Declaration to Direct3D 11 Input Layout mapping
Expand Down Expand Up @@ -355,7 +393,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromSDKMESH(ID3D11Device* d3dDevice
if (dataSize < header->HeaderSize)
throw std::exception("End of file");

if (header->Version != DXUT::SDKMESH_FILE_VERSION)
if (header->Version != DXUT::SDKMESH_FILE_VERSION && header->Version != DXUT::SDKMESH_FILE_VERSION_V2)
throw std::exception("Not a supported SDKMESH version");

if (header->IsBigEndian)
Expand Down Expand Up @@ -405,7 +443,17 @@ std::unique_ptr<Model> DirectX::Model::CreateFromSDKMESH(ID3D11Device* d3dDevice
if (dataSize < header->MaterialDataOffset
|| (dataSize < (header->MaterialDataOffset + uint64_t(header->NumMaterials) * sizeof(DXUT::SDKMESH_MATERIAL))))
throw std::exception("End of file");
auto materialArray = reinterpret_cast<const DXUT::SDKMESH_MATERIAL*>(meshData + header->MaterialDataOffset);

const DXUT::SDKMESH_MATERIAL* materialArray = nullptr;
const DXUT::SDKMESH_MATERIAL_V2* materialArray_v2 = nullptr;
if (header->Version == DXUT::SDKMESH_FILE_VERSION_V2)
{
materialArray_v2 = reinterpret_cast<const DXUT::SDKMESH_MATERIAL_V2*>(meshData + header->MaterialDataOffset);
}
else
{
materialArray = reinterpret_cast<const DXUT::SDKMESH_MATERIAL*>(meshData + header->MaterialDataOffset);
}

// Buffer data
uint64_t bufferDataOffset = header->HeaderSize + header->NonBufferDataSize;
Expand Down Expand Up @@ -598,11 +646,23 @@ std::unique_ptr<Model> DirectX::Model::CreateFromSDKMESH(ID3D11Device* d3dDevice
if (!mat.effect)
{
size_t vi = mh.VertexBuffers[0];
LoadMaterial(
materialArray[subset.MaterialID],
materialFlags[vi],
fxFactory,
mat);

if (materialArray_v2)
{
LoadMaterial(
materialArray_v2[subset.MaterialID],
materialFlags[vi],
fxFactory,
mat);
}
else
{
LoadMaterial(
materialArray[subset.MaterialID],
materialFlags[vi],
fxFactory,
mat);
}
}

ComPtr<ID3D11InputLayout> il;
Expand Down
Loading

0 comments on commit deee078

Please sign in to comment.