...
 
Commits (2)
    https://gitcode.net/u014038143/GRSD3D12Sample/-/commit/f61b4ecb01ab5e31fe5d14140b642392e9a8d745 添加23号示例将必须的基本变量进行结构化改造,这样方便后续示例的编写与阅读 2022-08-25T10:14:07+08:00 Gamebaby Rock Sun 41750362@qq.com https://gitcode.net/u014038143/GRSD3D12Sample/-/commit/e50ea21e28f50358c6ef6692a1ff95a85b0d1130 修正了几个今天提交后的警告信息 2022-08-25T21:37:13+08:00 Gamebaby Rock Sun 41750362@qq.com
......@@ -326,7 +326,7 @@ TCHAR g_pszAppPath[MAX_PATH] = {};
WCHAR g_pszTexcuteFileName[MAX_PATH] = {};
ST_GRS_GIF g_stGIF = {};
ComPtr<ID3D12Device4> g_pID3D12Device4;
ComPtr<ID3D12Device4> g_pID3D12Device4;
ComPtr<IWICImagingFactory> g_pIWICFactory;
ComPtr<ID3D12Resource> g_pIRWTexture;
ComPtr<ID3D12DescriptorHeap> g_pICSSRVHeap; // Computer Shader CBV SRV Heap
......@@ -506,7 +506,9 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCm
, IID_PPV_ARGS(&pIAdapter1)));
GRS_SET_DXGI_DEBUGNAME_COMPTR(pIAdapter1);
// 创建D3D12.1的设备
GRS_THROW_IF_FAILED(D3D12CreateDevice(pIAdapter1.Get(), D3D_FEATURE_LEVEL_12_1, IID_PPV_ARGS(&g_pID3D12Device4)));
GRS_THROW_IF_FAILED(D3D12CreateDevice(pIAdapter1.Get()
, D3D_FEATURE_LEVEL_12_1
, IID_PPV_ARGS(&g_pID3D12Device4)));
GRS_SET_D3D12_DEBUGNAME_COMPTR(g_pID3D12Device4);
DXGI_ADAPTER_DESC1 stAdapterDesc = {};
......
......@@ -23,7 +23,7 @@
<ProjectGuid>{B3D520CA-D4E5-4513-8664-4EAC26C10650}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>My13ShowGIFAndResourceStatus</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.20348.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
......
......@@ -232,41 +232,41 @@ enum EM_GRS_RENDER_STATUS
// 渲染子线程参数
struct ST_GRS_THREAD_PARAMS
{
UINT m_nThreadIndex; //序号
DWORD m_dwThisThreadID;
HANDLE m_hThisThread;
DWORD m_dwMainThreadID;
HANDLE m_hMainThread;
HANDLE m_hRunEvent;
HANDLE m_hEventShadowOver;
HANDLE m_hEventRenderOver;
UINT m_nCurrentFrameIndex; //当前渲染后缓冲序号
ULONGLONG m_nStartTime; //当前帧开始时间
UINT m_nThreadIndex; //序号
DWORD m_dwThisThreadID;
HANDLE m_hThisThread;
DWORD m_dwMainThreadID;
HANDLE m_hMainThread;
HANDLE m_hRunEvent;
HANDLE m_hEventShadowOver;
HANDLE m_hEventRenderOver;
UINT m_nCurrentFrameIndex; //当前渲染后缓冲序号
ULONGLONG m_nStartTime; //当前帧开始时间
ULONGLONG m_nCurrentTime; //当前时间
EM_GRS_RENDER_STATUS m_nState; //当前渲染状态 1 渲染阴影 2 正常渲染
EM_GRS_RENDER_STATUS m_nState; //当前渲染状态 1 渲染阴影 2 正常渲染
XMFLOAT4 m_v4ModelPos;
TCHAR m_pszDiffuseFile[MAX_PATH];
TCHAR m_pszNormalFile[MAX_PATH];
XMFLOAT4 m_v4ModelPos;
TCHAR m_pszDiffuseFile[MAX_PATH];
TCHAR m_pszNormalFile[MAX_PATH];
ID3D12Device4* m_pID3D12Device4;
ID3D12Device4* m_pID3D12Device4;
ID3D12CommandAllocator* m_pICmdAllocShadow;
ID3D12GraphicsCommandList* m_pICmdListShadow;
ID3D12CommandAllocator* m_pICmdAlloc;
ID3D12GraphicsCommandList* m_pICmdList;
ID3D12CommandAllocator* m_pICmdAllocShadow;
ID3D12GraphicsCommandList* m_pICmdListShadow;
ID3D12CommandAllocator* m_pICmdAlloc;
ID3D12GraphicsCommandList* m_pICmdList;
ID3D12RootSignature* m_pIRSShadowPass;
ID3D12PipelineState* m_pIPSOShadowPass;
ID3D12RootSignature* m_pIRSSecondPass;
ID3D12PipelineState* m_pIPSOSecondPass;
ID3D12RootSignature* m_pIRSShadowPass;
ID3D12PipelineState* m_pIPSOShadowPass;
ID3D12RootSignature* m_pIRSSecondPass;
ID3D12PipelineState* m_pIPSOSecondPass;
ID3D12DescriptorHeap* m_pISampleHeap;
ID3D12DescriptorHeap* m_pISampleHeap;
ID3D12Resource* m_pITexShadowMap;
ID3D12Resource* m_pICBLights;
ID3D12Resource* m_pITexShadowMap;
ID3D12Resource* m_pICBLights;
};
// 窗口大小
......@@ -274,11 +274,11 @@ int g_iWndWidth = 1024;
int g_iWndHeight = 768;
// 阴影用的深度缓冲的分辨率
int g_iDepthWidth = 1024;
int g_iDepthHeight = 1024;
int g_iDepthWidth = 2048;
int g_iDepthHeight = 2048;
D3D12_VIEWPORT g_stViewPort = { 0.0f, 0.0f, static_cast<float>( g_iWndWidth ), static_cast<float>( g_iWndHeight ) , D3D12_MIN_DEPTH, D3D12_MAX_DEPTH };
D3D12_VIEWPORT g_stDepthViewPort = { 0.0f, 0.0f, static_cast<float>( g_iWndWidth ), static_cast<float>( g_iWndHeight ) , D3D12_MIN_DEPTH, D3D12_MAX_DEPTH };
D3D12_VIEWPORT g_stDepthViewPort = { 0.0f, 0.0f, static_cast<float>(g_iDepthWidth), static_cast<float>(g_iDepthHeight) , D3D12_MIN_DEPTH, D3D12_MAX_DEPTH };
D3D12_RECT g_stScissorRect = { 0, 0, static_cast<LONG>( g_iWndWidth ), static_cast<LONG>( g_iWndHeight ) };
//初始的默认摄像机的位置
......@@ -388,7 +388,7 @@ int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR
ComPtr<ID3D12DescriptorHeap> pISRVHeapQuad;
ComPtr<ID3D12DescriptorHeap> pISampleHeapQuad;
D3D12_VERTEX_BUFFER_VIEW stVBViewQuad = {};
ST_GRS_CB_MVO* pMOV = nullptr;
ST_GRS_CB_MVO* pMOV = nullptr;
SIZE_T szCBMOVBuf = GRS_UPPER( sizeof( ST_GRS_CB_MVO ), 256 );
//--------------------------------------------------------------------------------------------------------
......@@ -519,7 +519,7 @@ int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR
// 创建D3D12.1的设备
GRS_THROW_IF_FAILED( D3D12CreateDevice( pIAdapter1.Get()
, D3D_FEATURE_LEVEL_12_1
, D3D_FEATURE_LEVEL_11_0
, IID_PPV_ARGS( &pID3D12Device4 ) ) );
GRS_SET_D3D12_DEBUGNAME_COMPTR( pID3D12Device4 );
......@@ -643,8 +643,7 @@ int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR
stDepthOptimizedClearValue.Format = emDepthShadowFormat;
stDepthOptimizedClearValue.DepthStencil.Depth = 1.0f;
stDepthOptimizedClearValue.DepthStencil.Stencil = 0;
D3D12_RESOURCE_DESC stDepthShadowResDesc = {};
stDepthShadowResDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
stDepthShadowResDesc.Alignment = 0;
......@@ -916,6 +915,8 @@ int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR
stPSODesc.pRootSignature = pIRSShadowPass.Get();
stPSODesc.PS.BytecodeLength = 0;
stPSODesc.PS.pShaderBytecode = nullptr;
stPSODesc.RasterizerState.FillMode = D3D12_FILL_MODE_SOLID;
stPSODesc.RasterizerState.CullMode = D3D12_CULL_MODE_FRONT;
stPSODesc.RTVFormats[0] = DXGI_FORMAT_UNKNOWN;
stPSODesc.DSVFormat = emDepthShadowFormat;
stPSODesc.NumRenderTargets = 0;
......@@ -926,8 +927,8 @@ int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR
}
// 10、创建渲染UI矩形(渲染阴影视图)用的管线的根签名、管线状态对象、矩形框VB、CB、采样器(堆)、SRV Heap、CBV、SRV
if( TRUE )
{
//--------------------------------------------------------------------------------------------------------------
//创建渲染矩形的根签名对象
D3D12_DESCRIPTOR_RANGE1 stDSPRanges[3] = {};
stDSPRanges[0].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_CBV;
......@@ -1117,7 +1118,7 @@ int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR
// 使用阴影深度2D纹理作为Shader的纹理资源
pID3D12Device4->CreateShaderResourceView( pIDepthShadowBuffer.Get(), &stSRVDesc, stCPUSRVHeapQuad );
//Sample
// Sample
stHeapDesc.NumDescriptors = 1; //只有一个Sample
stHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER;
GRS_THROW_IF_FAILED( pID3D12Device4->CreateDescriptorHeap( &stHeapDesc, IID_PPV_ARGS( &pISampleHeapQuad ) ) );
......@@ -1165,12 +1166,14 @@ int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR
// 设置矩形框的大小,单位同样是像素
xmMVO = XMMatrixMultiply(
XMMatrixScaling( 320.0f, 240.0f, 1.0f )
XMMatrixScaling( 200.0f, 200.0f, 1.0f )
, xmMVO );
// 注意上面的计算顺序,实际最终结果是标准的:
// Scaling * Translation * View * Orthographic = Model * View * Projection
//设置MVO
XMStoreFloat4x4( &pMOV->m_mMVO, xmMVO );
//--------------------------------------------------------------------------------------------------------------
// 创建绘制矩形的捆绑包
......@@ -1196,7 +1199,6 @@ int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR
//Draw Call!!!
pICmdBundlesQuad->DrawInstanced( nQuadVertexCnt, 1, 0, 0 );
pICmdBundlesQuad->Close();
//--------------------------------------------------------------------------------------------------------------
}
......@@ -1243,7 +1245,7 @@ int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR
stClampSamplerDesc.BorderColor[0]
= stClampSamplerDesc.BorderColor[1]
= stClampSamplerDesc.BorderColor[2]
= stClampSamplerDesc.BorderColor[3] = 0;
= stClampSamplerDesc.BorderColor[3] = 1.0f;
stClampSamplerDesc.MinLOD = 0;
stClampSamplerDesc.MaxLOD = D3D12_FLOAT32_MAX;
pID3D12Device4->CreateSampler( &stClampSamplerDesc, stSamplerHandle );
......@@ -1251,9 +1253,13 @@ int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR
// 12、创建全局灯光
{
// 计算透视矩阵(本例中光源 摄像机都使用同一个透视矩阵)
XMStoreFloat4x4( &g_mxProjection, XMMatrixPerspectiveFovLH( XM_PIDIV4, (FLOAT) g_iWndWidth / (FLOAT) g_iWndHeight, fNearPlane, fFarPlane ) );
//XMMatrixShadow()
// 计算透视矩阵
XMStoreFloat4x4( &g_mxProjection
, XMMatrixPerspectiveFovLH( XM_PIDIV4
, (FLOAT) g_iWndWidth / (FLOAT) g_iWndHeight
, fNearPlane
, fFarPlane ) );
stBufferResSesc.Width = szLightBuf; //注意缓冲尺寸设置为256边界对齐大小
GRS_THROW_IF_FAILED( pID3D12Device4->CreateCommittedResource(
&stUploadHeapProps
......@@ -1272,18 +1278,34 @@ int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR
for ( int i = 0; i < GRS_NUM_LIGHTS; i++ )
{
g_pstLights->m_stLights[i].m_v4Position = { 0.0f, 5.0f, -10.0f, 1.0f };
g_pstLights->m_stLights[i].m_v4Direction = { 0.0, 0.0f, 1.0f, 0.0f };
g_pstLights->m_stLights[i].m_v4Falloff = { 80.0f, 1.0f, 0.0f, 1.0f };
g_pstLights->m_stLights[i].m_v4Color = { 0.9f, 0.9f, 0.9f, 1.0f };
g_pstLights->m_stLights[i].m_v4Position = { 0.0f, 10.0f, -5.0f, 0.0f };
g_pstLights->m_stLights[i].m_v4Direction = { 0.0, -1.0f, 1.0f, 0.0f };
g_pstLights->m_stLights[i].m_v4Falloff = { 80.0f, 1.0f, 0.0f, 0.2f };
g_pstLights->m_stLights[i].m_v4Color = { 1.0f, 0.9f, 0.9f, 1.0f };
XMVECTOR eye = XMLoadFloat4( &g_pstLights->m_stLights[i].m_v4Position );
XMVECTOR at = XMVectorAdd( eye, XMLoadFloat4( &g_pstLights->m_stLights[i].m_v4Direction ) );
//XMVECTOR at = XMVectorAdd( eye, XMLoadFloat4( &g_pstLights->m_stLights[i].m_v4Direction ) );
XMVECTOR at = XMVectorSet(0.0, -1.0f, 10.0f, 0.0f);
XMStoreFloat4(&g_pstLights->m_stLights[i].m_v4Direction, XMVectorSubtract(at,eye));
XMVECTOR up = XMVectorSet( 0.0f, 1.0f, 0.0f, 0.0f );
XMStoreFloat4x4( &g_pstLights->m_stLights[i].m_mxView, XMMatrixLookAtLH( eye, at, up ) );
g_pstLights->m_stLights[i].m_mxProjection = g_mxProjection;
XMStoreFloat4x4(&g_pstLights->m_stLights[i].m_mxProjection
, XMMatrixOrthographicOffCenterLH(
0.0f
, static_cast<float>(g_iDepthWidth)
, 0.0f
, static_cast<float>(g_iDepthHeight)
, fNearPlane
, fFarPlane));
//, XMMatrixPerspectiveFovLH(XM_PIDIV2
// , (FLOAT)g_iDepthWidth / (FLOAT)g_iDepthHeight
// , fNearPlane
// , fFarPlane));
}
g_pstLights->m_stLights[1].m_v4Color = { 0.0f, 0.0f, 0.0f, 1.0f };
......@@ -1456,18 +1478,18 @@ int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR
XMStoreFloat4x4( &g_mxWorld, XMMatrixIdentity() );
// 变换光源
for ( int i = 0; i < GRS_NUM_LIGHTS; i++ )
{
XMVECTOR eye = XMLoadFloat4( &g_pstLights->m_stLights[i].m_v4Position );
XMVECTOR at = { 0.0f,0.0f,0.0f,0.0f };
XMVECTOR up = XMVectorSet( 0.0f, 1.0f, 0.0f, 0.0f );
XMStoreFloat4x4( &g_pstLights->m_stLights[i].m_mxView
, XMMatrixLookAtLH( eye, at, up ) );
}
// 渲染阴影 以第一个光源的空间为 视空间
g_mxView = g_pstLights->m_stLights[0].m_mxView;
//// 变换光源
//for ( int i = 0; i < GRS_NUM_LIGHTS; i++ )
//{
// XMVECTOR eye = XMLoadFloat4( &g_pstLights->m_stLights[i].m_v4Position );
// XMVECTOR at = { 0.0f,0.0f,0.0f,0.0f };
// XMVECTOR up = XMVectorSet( 0.0f, 1.0f, 0.0f, 0.0f );
// XMStoreFloat4x4( &g_pstLights->m_stLights[i].m_mxView
// , XMMatrixLookAtLH( eye, at, up ) );
//}
//// 渲染阴影 以第一个光源的空间为 视空间
//g_mxView = g_pstLights->m_stLights[0].m_mxView;
}
GRS_THROW_IF_FAILED( pICmdAllocPre->Reset() );
......@@ -1498,7 +1520,8 @@ int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR
pICmdListPre->RSSetViewports( 1, &g_stDepthViewPort );
pICmdListPre->RSSetScissorRects( 1, &g_stScissorRect );
pICmdListPre->ClearDepthStencilView( stDSVHandle, D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr );
pICmdListPre->ClearDepthStencilView( stDSVHandle
, D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr );
}
arHWaited.RemoveAll();
......
......@@ -153,6 +153,25 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="14-MultiThreadShadow.cpp" />
<FxCompile Include="VS_PS_Render.hlsl">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<FileType>Document</FileType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">5.1</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.1</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">5.1</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">5.1</ShaderModel>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">VSMain</EntryPointName>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Effect</ShaderType>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">VSMain</EntryPointName>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Effect</ShaderType>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">VSMain</EntryPointName>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Effect</ShaderType>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">VSMain</EntryPointName>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Effect</ShaderType>
</FxCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\WindowsCommons\dds.h" />
......@@ -162,9 +181,25 @@
<None Include="Shader\Commons.hlsl">
<FileType>Document</FileType>
</None>
<None Include="Shader\PSMain.hlsl">
<FxCompile Include="Shader\PSMain.hlsl">
<FileType>Document</FileType>
</None>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">PSMain</EntryPointName>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">5.1</ShaderModel>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">PSMain</EntryPointName>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.1</ShaderModel>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">PSMain</EntryPointName>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">5.1</ShaderModel>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">PSMain</EntryPointName>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">5.1</ShaderModel>
</FxCompile>
<None Include="Shader\VSMain.hlsl">
<FileType>Document</FileType>
</None>
......@@ -174,6 +209,18 @@
<FileType>Document</FileType>
</None>
</ItemGroup>
<ItemGroup>
<FxCompile Include="VS_PS_Shadow.hlsl">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">5.1</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.1</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">5.1</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">5.1</ShaderModel>
</FxCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
......
......@@ -43,11 +43,19 @@
<None Include="Shader\Commons.hlsl">
<Filter>Shader</Filter>
</None>
<None Include="Shader\PSMain.hlsl">
<Filter>Shader</Filter>
</None>
<None Include="Shader\VSMain.hlsl">
<Filter>Shader</Filter>
</None>
</ItemGroup>
<ItemGroup>
<FxCompile Include="VS_PS_Shadow.hlsl">
<Filter>Shader</Filter>
</FxCompile>
<FxCompile Include="VS_PS_Render.hlsl">
<Filter>Shader</Filter>
</FxCompile>
<FxCompile Include="Shader\PSMain.hlsl">
<Filter>Shader</Filter>
</FxCompile>
</ItemGroup>
</Project>
\ No newline at end of file
struct PSInput
struct ST_PS_INPUT
{
float4 v4Position : SV_POSITION;
float4 v4WorldPosition : POSITION;
......
......@@ -7,9 +7,9 @@ SamplerState g_SampleWrap : register(s0);
SamplerState g_SampleClamp : register(s1);
#define GRS_NUM_LIGHTS 3
#define GRS_SHADOW_DEPTH_BIAS 0.0005f
#define GRS_SHADOW_DEPTH_BIAS 0.05f
struct LightState
struct ST_LIGHT_STATE
{
float4 v4Position;
float4 v4Direction;
......@@ -19,14 +19,14 @@ struct LightState
float4x4 mxProjection;
};
cbuffer LightBuffer : register(b1)
cbuffer CB_LIGHT_DATA : register(b1)
{
float4 v4AmbientColor;
LightState stLights[GRS_NUM_LIGHTS];
float4 v3AmbientColor;
ST_LIGHT_STATE stLights[GRS_NUM_LIGHTS];
uint bIsSampleShadowMap;
};
struct PSInput
struct ST_PS_INPUT
{
float4 v4Position : SV_POSITION;
float4 v4WorldPosition : POSITION;
......@@ -53,7 +53,7 @@ float3 CalcPerPixelNormal(float2 vTexcoord, float3 vVertNormal, float3 vVertTang
float3 vBumpNormal = (float3)g_t2dNormalMap.Sample(g_SampleWrap, vTexcoord);
// 符号化还原
vBumpNormal = 2.0f * vBumpNormal - 1.0f;
vBumpNormal.z = -vBumpNormal.z;
//vBumpNormal.z = -vBumpNormal.z;
return mul(vBumpNormal, mTangentSpaceToWorldSpace);
}
......@@ -115,21 +115,22 @@ float4 CalcUnshadowedAmountPCF2x2(int lightIndex, float4 vPosWorld)
// 2x2 percentage closer filtering.
float2 vTexelUnits = 1.0f / vShadowMapDims;
float4 vShadowDepths;
vShadowDepths.x = g_t2dShadowMap.Sample(g_SampleClamp, vShadowTexCoord);
vShadowDepths.y = g_t2dShadowMap.Sample(g_SampleClamp, vShadowTexCoord + float2(vTexelUnits.x, 0.0f));
vShadowDepths.z = g_t2dShadowMap.Sample(g_SampleClamp, vShadowTexCoord + float2(0.0f, vTexelUnits.y));
vShadowDepths.w = g_t2dShadowMap.Sample(g_SampleClamp, vShadowTexCoord + vTexelUnits);
vShadowDepths.x = g_t2dShadowMap.Sample(g_SampleClamp, vShadowTexCoord).x;
vShadowDepths.y = g_t2dShadowMap.Sample(g_SampleClamp, vShadowTexCoord + float2(vTexelUnits.x, 0.0f)).x;
vShadowDepths.z = g_t2dShadowMap.Sample(g_SampleClamp, vShadowTexCoord + float2(0.0f, vTexelUnits.y)).x;
vShadowDepths.w = g_t2dShadowMap.Sample(g_SampleClamp, vShadowTexCoord + vTexelUnits).x;
// What weighted fraction of the 4 samples are nearer to the light than this pixel?
float4 vShadowTests = (vShadowDepths >= vLightSpaceDepth) ? 1.0f : 0.0f;
return dot(vBilinearWeights, vShadowTests);
}
float4 PSMain(PSInput input) : SV_TARGET
float4 PSMain(ST_PS_INPUT stPSinput) : SV_TARGET
{
float4 diffuseColor = g_t2dDiffuseMap.Sample(g_SampleWrap, input.v2UV);
float3 pixelNormal = CalcPerPixelNormal(input.v2UV, input.v4Normal, input.v4Tangent);
float4 totalLight = v4AmbientColor;
float4 diffuseColor = g_t2dDiffuseMap.Sample(g_SampleWrap, stPSinput.v2UV);
float3 pixelNormal = CalcPerPixelNormal(stPSinput.v2UV, stPSinput.v4Normal.xyz, stPSinput.v4Tangent.xyz);
float4 totalLight = v3AmbientColor;
for (int i = 0; i < GRS_NUM_LIGHTS; i++)
{
......@@ -137,52 +138,105 @@ float4 PSMain(PSInput input) : SV_TARGET
, stLights[i].v4Direction.xyz
, stLights[i].v4Color
, stLights[i].v4Falloff
, input.v4WorldPosition.xyz
, stPSinput.v4WorldPosition.xyz
, pixelNormal.xyz);
if ( 1 == bIsSampleShadowMap && i == 0 )
{
lightPass *= CalcUnshadowedAmountPCF2x2(i, input.v4WorldPosition);
lightPass *= CalcUnshadowedAmountPCF2x2(i, stPSinput.v4WorldPosition);
}
totalLight += lightPass;
}
//return float4(pixelNormal, 1.0f);
float4 vLightSpacePos = input.v4WorldPosition;
float4 vLightSpacePos = stPSinput.v4WorldPosition;
vLightSpacePos = mul(vLightSpacePos, stLights[0].mxView);
vLightSpacePos = mul(vLightSpacePos, stLights[0].mxProjection);
//return vLightSpacePos;
vLightSpacePos.xyz /= vLightSpacePos.w;
//return vLightSpacePos;
float2 v2LightCoord = 0.5f * vLightSpacePos.xy + 0.5f;
v2LightCoord.y = 1.0f - v2LightCoord.y;
float4 fPixelColor = diffuseColor;
float fDepthValue = g_t2dShadowMap.Sample(g_SampleClamp, v2LightCoord);
vLightSpacePos.z -= 0.05f;
float fDepthValue = g_t2dShadowMap.Sample(g_SampleClamp, v2LightCoord).r;
vLightSpacePos.z -= GRS_SHADOW_DEPTH_BIAS;
//return float4(fDepthValue, fDepthValue, fDepthValue, 1.0f);
if ( vLightSpacePos.z < fDepthValue )
{
fPixelColor += v4AmbientColor;
//float lightIntensity = saturate(-dot(pixelNormal.xyz, stLights[0].v4Direction.xyz));
//if ( lightIntensity > 0.0f )
//{
fPixelColor += v3AmbientColor;
float lightIntensity = saturate(-dot(pixelNormal.xyz, stLights[0].v4Direction.xyz));
if ( lightIntensity > 0.0f )
{
// fPixelColor += (diffuseColor * lightIntensity);
//}
fPixelColor += (diffuseColor * lightIntensity);
}
}
else
{
fPixelColor -= v4AmbientColor;
fPixelColor -= v3AmbientColor;
}
return fPixelColor;
//return fPixelColor;
//return float4(vLightSpacePos.z, vLightSpacePos.z, vLightSpacePos.z, 1.0f);
//return vLightSpacePos;
//
//return CalcUnshadowedAmountPCF2x2(0, input.v4WorldPosition);
//return CalcUnshadowedAmountPCF2x2(0, stPSinput.v4WorldPosition);
//float d = g_t2dShadowMap.Sample(g_SampleClamp, input.v2UV);
//float d = g_t2dShadowMap.Sample(g_SampleClamp, stPSinput.v2UV);
//return float4(d, d, d, 1.0f);
//return (pixelNormal.xyz/length(pixelNormal.xyz),1.0f);
return diffuseColor * saturate(totalLight);
}
float ShadowCalculation(float4 fragPosLightSpace)
{
// 执行透视除法
float4 projCoords = fragPosLightSpace;
projCoords.xyz /= projCoords.w;
// 变换到[0,1]的范围
projCoords = projCoords * 0.5 + 0.5;
// 取得最近点的深度(使用[0,1]范围下的fragPosLight当坐标)
float closestDepth = g_t2dShadowMap.Sample(g_SampleClamp, projCoords.xy).r;
// 取得当前片段在光源视角下的深度
float currentDepth = projCoords.z;
// 检查当前片段是否在阴影中
float shadow = currentDepth > closestDepth ? 1.0f : 0.0f;
return shadow;
}
//float4 PSMain(ST_PS_INPUT stPSin) : SV_TARGET
//{
// float3 v3TexelColor = g_t2dDiffuseMap.Sample(g_SampleWrap,stPSin.m_v2UV).rgb;
// float3 v3Normal = stPSin.m_v4Normal.xyz;
//
// float3 v3LightColor = 1.0f;
// // Ambient
// float3 v3AmbientColor = 0.15f * v3TexelColor;
// // Diffuse
// float3 v3LightDir = normalize(g_v4LightPos.xyz - stPSin.m_v4WorldPosition.xyz);
// float fDiff = max(dot(v3LightDir, v3Normal), 0.0);
// float fDiff = max(dot(v3LightDir, v3Normal), 0.0);
// float3 v3DiffuseColor = fDiff * v3LightColor;
// // Specular
// float3 v3ViewDir = normalize(viewPos - fs_in.FragPos);
// float3 v3ReflectDir = reflect(-v3LightDir, v3Normal);
// float3 v3HalfwayDir = normalize(v3LightDir + v3ViewDir);
// float fSpec = pow(max(dot(v3Normal, v3HalfwayDir), 0.0), 64.0);
// float3 v3SpecularColor = fSpec * v3LightColor;
// // 计算阴影
// float shadow = ShadowCalculation(fs_in.FragPosLightSpace);
// float3 v3PixelColor = (v3AmbientColor + (1.0 - shadow) * (v3DiffuseColor + v3SpecularColor)) * v3TexelColor;
//
// return (v3PixelColor.rgb, 1.0f);
//}
#include "Commons.hlsl"
cbuffer SceneConstantBuffer : register(b0)
cbuffer CB_SCENE_DATA : register(b0)
{
float4x4 g_mxModel;
float4x4 g_mxView;
float4x4 g_mxProjection;
};
PSInput VSMain(float4 v4Position : POSITION, float4 v4Normal : NORMAL, float2 v2UV : TEXCOORD0, float4 v4Tangent : TANGENT)
ST_PS_INPUT VSMain(float4 v4Position : POSITION, float4 v4Normal : NORMAL, float2 v2UV : TEXCOORD0, float4 v4Tangent : TANGENT)
{
PSInput stOutput;
ST_PS_INPUT stOutput;
float4 v4NewPosition = v4Position;
v4Normal.z *= -1.0f;
v4NewPosition = mul(v4NewPosition, g_mxModel);
stOutput.v4WorldPosition = v4NewPosition;
......@@ -25,6 +23,7 @@ PSInput VSMain(float4 v4Position : POSITION, float4 v4Normal : NORMAL, float2 v2
stOutput.v4Position = v4NewPosition;
stOutput.v2UV = v2UV;
stOutput.v4Normal = v4Normal;
stOutput.v4Normal.z *= -1.0f;
stOutput.v4Tangent = v4Tangent;
return stOutput;
......
cbuffer ST_CB_SCENE : register(b0)
{
float4 g_v4LightPos;
float4x4 g_mxModel;
float4x4 g_mxView;
float4x4 g_mxProjection;
float4x4 g_mxVPLight;
};
Texture2D g_t2dDiffuseMap : register(t0);
Texture2D g_t2dNormalMap : register(t1);
Texture2D g_t2dShadowMap : register(t2);
SamplerState g_SampleWrap : register(s0);
SamplerState g_SampleClamp : register(s1);
struct ST_PS_INPUT
{
float4 m_v4Position : SV_POSITION;
float4 m_v4WorldPosition : POSITION0;
float4 m_v4LightSpacePosition : POSITION1;
float2 m_v2UV : TEXCOORD0;
float4 m_v4Normal : NORMAL;
float4 m_v4Tangent : TANGENT;
};
ST_PS_INPUT VSMain(float4 v4Position : POSITION
, float4 v4Normal : NORMAL
, float2 v2UV : TEXCOORD0
, float4 v4Tangent : TANGENT)
{
ST_PS_INPUT stOutput;
float4 v4NewPosition = v4Position;
v4NewPosition = mul(v4NewPosition, g_mxModel);
stOutput.m_v4WorldPosition = v4NewPosition;
stOutput.m_v4LightSpacePosition = mul(v4NewPosition, g_mxVPLight);
v4NewPosition = mul(v4NewPosition, g_mxView);
v4NewPosition = mul(v4NewPosition, g_mxProjection);
stOutput.m_v4Position = v4NewPosition;
stOutput.m_v2UV = v2UV;
stOutput.m_v4Normal = v4Normal;
stOutput.m_v4Normal.z *= -1.0f;
stOutput.m_v4Normal.w = 0.0f;
stOutput.m_v4Normal = normalize(stOutput.m_v4Normal);
stOutput.m_v4Tangent = v4Tangent;
return stOutput;
}
float ShadowCalculation(float4 fragPosLightSpace)
{
// 执行透视除法
float4 projCoords = fragPosLightSpace;
projCoords.xyz /= projCoords.w;
// 变换到[0,1]的范围
projCoords = projCoords * 0.5 + 0.5;
// 取得最近点的深度(使用[0,1]范围下的fragPosLight当坐标)
float closestDepth = g_t2dShadowMap.Sample(g_SampleClamp, projCoords.xy).r;
// 取得当前片段在光源视角下的深度
float currentDepth = projCoords.z;
// 检查当前片段是否在阴影中
float fInShadow = currentDepth > closestDepth ? 1.0f : 0.0f;
return fInShadow;
}
float4 PSMain(ST_PS_INPUT stPSin) : SV_TARGET
{
float3 v3TexelColor = g_t2dDiffuseMap.Sample(g_SampleWrap,stPSin.m_v2UV).rgb;
float3 v3Normal = stPSin.m_v4Normal.xyz;
float3 v3LightColor = 1.0f;
// Ambient
float3 v3AmbientColor = 0.15f * v3TexelColor;
// Diffuse
float3 v3LightDir = normalize(g_v4LightPos.xyz - stPSin.m_v4WorldPosition.xyz);
float fDiff = max(dot(v3LightDir, v3Normal), 0.0);
float3 v3DiffuseColor = fDiff * v3LightColor;
// Specular
float3 v3ViewDir = normalize(viewPos - fs_in.FragPos);
float3 v3ReflectDir = reflect(-v3LightDir, v3Normal);
float3 v3HalfwayDir = normalize(v3LightDir + v3ViewDir);
float fSpec = pow(max(dot(v3Normal, v3HalfwayDir), 0.0), 64.0);
float3 v3SpecularColor = fSpec * v3LightColor;
// 计算阴影
float fInShadow = ShadowCalculation(stPSin.m_v4LightSpacePosition);
float3 v3PixelColor = (v3AmbientColor + (1.0 - fInShadow) * (v3DiffuseColor + v3SpecularColor)) * v3TexelColor;
return (v3PixelColor.rgb, 1.0f);
}
cbuffer ST_CB_LIGHT_MATRIX : register(b0)
{
float4x4 g_mxModel;
float4x4 g_mxLightView;
float4x4 g_mxLightProjection;
};
struct ST_PS_INPUT
{
float4 m_v4Position : SV_POSITION;
};
ST_PS_INPUT VSMain(float4 v4Position : POSITION)
{
ST_PS_INPUT stOutput;
stOutPut.m_v4Position = mul(v4Position, g_mxModel);
stOutPut.m_v4Position = mul(stOutPut.m_v4Position, g_mxLightView);
stOutPut.m_v4Position = mul(stOutPut.m_v4Position, g_mxLightProjection);
return stOutput;
}
......@@ -30,10 +30,10 @@ cbuffer ST_CB_LIGHTS : register( b2 )
// PBR material parameters
cbuffer ST_CB_PBR_MATERIAL : register( b3 )
{
float3 g_v3Albedo; // 反射率
float g_fMetallic; // 金属度
float g_fRoughness; // 粗糙度
float g_fAO; // 环境光遮蔽
float3 g_v3Albedo; // 反射率
float g_fMetallic; // 金属度
float g_fRoughness; // 粗糙度
float g_fAO; // 环境光遮蔽
};
struct PSInput
......
......@@ -179,8 +179,8 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR l
int iHeight = 768;
UINT nFrameIndex = 0;
DXGI_FORMAT emRenderTarget = DXGI_FORMAT_R8G8B8A8_UNORM;
const float faClearColor[] = { 0.0f, 0.2f, 0.4f, 1.0f };
DXGI_FORMAT emRenderTarget = DXGI_FORMAT_R8G8B8A8_UNORM;
const float faClearColor[] = { 0.0f, 0.2f, 0.4f, 1.0f };
UINT nDXGIFactoryFlags = 0U;
UINT nRTVDescriptorSize = 0U;
......
......@@ -671,8 +671,8 @@ void OnSize(UINT width, UINT height, bool minimized)
// 8、更新视口大小和齐次包围盒大小
g_stGPUStatus.m_stViewPort.TopLeftX = 0.0f;
g_stGPUStatus.m_stViewPort.TopLeftY = 0.0f;
g_stGPUStatus.m_stViewPort.Width = g_stGPUStatus.m_iWndWidth;
g_stGPUStatus.m_stViewPort.Height = g_stGPUStatus.m_iWndHeight;
g_stGPUStatus.m_stViewPort.Width = (float)g_stGPUStatus.m_iWndWidth;
g_stGPUStatus.m_stViewPort.Height = (float)g_stGPUStatus.m_iWndHeight;
g_stGPUStatus.m_stScissorRect.left = static_cast<LONG>(g_stGPUStatus.m_stViewPort.TopLeftX);
g_stGPUStatus.m_stScissorRect.right = static_cast<LONG>(g_stGPUStatus.m_stViewPort.TopLeftX + g_stGPUStatus.m_stViewPort.Width);
......
......@@ -682,8 +682,8 @@ void OnSize(UINT width, UINT height, bool minimized)
// 8、更新视口大小和齐次包围盒大小
g_stGPUStatus.m_stViewPort.TopLeftX = 0.0f;
g_stGPUStatus.m_stViewPort.TopLeftY = 0.0f;
g_stGPUStatus.m_stViewPort.Width = g_stGPUStatus.m_iWndWidth;
g_stGPUStatus.m_stViewPort.Height = g_stGPUStatus.m_iWndHeight;
g_stGPUStatus.m_stViewPort.Width = (float)g_stGPUStatus.m_iWndWidth;
g_stGPUStatus.m_stViewPort.Height = (float)g_stGPUStatus.m_iWndHeight;
g_stGPUStatus.m_stScissorRect.left = static_cast<LONG>(g_stGPUStatus.m_stViewPort.TopLeftX);
g_stGPUStatus.m_stScissorRect.right = static_cast<LONG>(g_stGPUStatus.m_stViewPort.TopLeftX + g_stGPUStatus.m_stViewPort.Width);
......
......@@ -792,7 +792,7 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR l
// 填充每实例数据
//创建 Per Instance Data 仅使用Upload隐式堆 iRowCnts行 * iColCnts列个实例
g_stBufferResSesc.Width = iRowCnts * iColCnts * sizeof(ST_GRS_PER_INSTANCE);
g_stBufferResSesc.Width = (UINT64)(iRowCnts * iColCnts * sizeof(ST_GRS_PER_INSTANCE));
GRS_THROW_IF_FAILED(pID3D12Device4->CreateCommittedResource(
&g_stUploadHeapProps
, D3D12_HEAP_FLAG_NONE
......@@ -1153,8 +1153,8 @@ void OnSize(UINT width, UINT height, bool minimized)
// 8、更新视口大小和齐次包围盒大小
g_stGPUStatus.m_stViewPort.TopLeftX = 0.0f;
g_stGPUStatus.m_stViewPort.TopLeftY = 0.0f;
g_stGPUStatus.m_stViewPort.Width = g_stGPUStatus.m_iWndWidth;
g_stGPUStatus.m_stViewPort.Height = g_stGPUStatus.m_iWndHeight;
g_stGPUStatus.m_stViewPort.Width = (float)g_stGPUStatus.m_iWndWidth;
g_stGPUStatus.m_stViewPort.Height = (float)g_stGPUStatus.m_iWndHeight;
g_stGPUStatus.m_stScissorRect.left = static_cast<LONG>(g_stGPUStatus.m_stViewPort.TopLeftX);
g_stGPUStatus.m_stScissorRect.right = static_cast<LONG>(g_stGPUStatus.m_stViewPort.TopLeftX + g_stGPUStatus.m_stViewPort.Width);
......
......@@ -141,6 +141,20 @@
<ItemGroup>
<ClCompile Include="22-MultiInstance-PBR-Sphere.cpp" />
</ItemGroup>
<ItemGroup>
<FxCompile Include="Shader\Multiple_Instances_VS.hlsl">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</FxCompile>
<FxCompile Include="Shader\PBR.hlsl">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</FxCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
......
......@@ -13,10 +13,21 @@
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Shader">
<UniqueIdentifier>{1b8b60ad-f2f5-499a-92e5-746be3b22e49}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="22-MultiInstance-PBR-Sphere.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<FxCompile Include="Shader\Multiple_Instances_VS.hlsl">
<Filter>Shader</Filter>
</FxCompile>
<FxCompile Include="Shader\PBR.hlsl">
<Filter>Shader</Filter>
</FxCompile>
</ItemGroup>
</Project>
\ No newline at end of file
此差异已折叠。
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{a2cbf947-07a7-42d9-a268-3cddd9bcf2ae}</ProjectGuid>
<RootNamespace>My23StructuredEmpty</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="23-Structured_Empty.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="23-Structured_Empty.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
\ No newline at end of file
......@@ -1073,7 +1073,7 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR l
TCHAR pszSkyboxTextureFile[MAX_PATH] = {};
//使用“Assets\\sky_cube.dds”时需要XMMATRIX(1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1)乘以xmView
StringCchPrintf(pszSkyboxTextureFile, MAX_PATH, _T("%sAssets\\Sky_cube_1024.dds"), pszAppPath);
ID3D12Resource* pIResSkyBox = nullptr;
GRS_THROW_IF_FAILED(LoadDDSTextureFromFile(
pID3D12Device4.Get()
......@@ -1596,6 +1596,7 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR l
//球体的捆绑包
pIBundlesEarth->SetGraphicsRootSignature(pIRootSignature.Get());
pIBundlesEarth->SetPipelineState(pIPSOEarth.Get());
ID3D12DescriptorHeap* ppHeapsEarth[] = { pISRVHpEarth.Get(),pISampleHpEarth.Get() };
pIBundlesEarth->SetDescriptorHeaps(_countof(ppHeapsEarth), ppHeapsEarth);
//设置SRV
......
......@@ -336,7 +336,7 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR l
RegisterClassEx(&wcex);
DWORD dwWndStyle = WS_OVERLAPPED | WS_SYSMENU;
RECT rtWnd = { 0, 0, nWndWidth, nWndHeight };
RECT rtWnd = { 0, 0, (LONG)nWndWidth, (LONG)nWndHeight };
AdjustWindowRect(&rtWnd, dwWndStyle, FALSE);
// 计算窗口居中的屏幕坐标
......@@ -1645,7 +1645,7 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR l
stGPUParams[nIDGPUMain].m_pICmdList->ResourceBarrier(1, &stRTVStateTransBarrier);
D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = stGPUParams[nIDGPUMain].m_pIDHRTV->GetCPUDescriptorHandleForHeapStart();
rtvHandle.ptr += (nCurrentFrameIndex * stGPUParams[nIDGPUMain].m_nszRTV);
rtvHandle.ptr += (SIZE_T)(nCurrentFrameIndex * stGPUParams[nIDGPUMain].m_nszRTV);
D3D12_CPU_DESCRIPTOR_HANDLE stDSVHandle = stGPUParams[nIDGPUMain].m_pIDHDSVTex->GetCPUDescriptorHandleForHeapStart();
stGPUParams[nIDGPUMain].m_pICmdList->OMSetRenderTargets(
......
无法预览此类型文件
无法预览此类型文件
无法预览此类型文件
......@@ -6,69 +6,72 @@
//------------------------------------------------------------------------------------------------------------
// 为了调试加入下面的内联函数和宏定义,为每个接口对象设置名称,方便查看调试输出
#if defined(_DEBUG)
inline void GRS_SetD3D12DebugName(ID3D12Object* pObject, LPCWSTR name)
__inline void GRS_SetDXGIDebugName(IDXGIObject* pObject, LPCWSTR name)
{
pObject->SetName(name);
size_t szLen = 0;
StringCchLengthW(name, MAX_PATH, &szLen);
pObject->SetPrivateData(WKPDID_D3DDebugObjectName, static_cast<UINT>(szLen - 1), name);
}
inline void GRS_SetD3D12DebugNameIndexed(ID3D12Object* pObject, LPCWSTR name, UINT index)
__inline void GRS_SetDXGIDebugNameIndexed(IDXGIObject* pObject, LPCWSTR name, UINT index)
{
size_t szLen = 0;
WCHAR _DebugName[MAX_PATH] = {};
if (SUCCEEDED(StringCchPrintfW(_DebugName, _countof(_DebugName), L"%s[%u]", name, index)))
{
pObject->SetName(_DebugName);
StringCchLengthW(_DebugName, _countof(_DebugName), &szLen);
pObject->SetPrivateData(WKPDID_D3DDebugObjectName, static_cast<UINT>(szLen), _DebugName);
}
}
#else
inline void GRS_SetD3D12DebugName(ID3D12Object*, LPCWSTR)
__inline void GRS_SetDXGIDebugName(IDXGIObject*, LPCWSTR)
{
}
inline void GRS_SetD3D12DebugNameIndexed(ID3D12Object*, LPCWSTR, UINT)
__inline void GRS_SetDXGIDebugNameIndexed(IDXGIObject*, LPCWSTR, UINT)
{
}
#endif
#define GRS_SET_D3D12_DEBUGNAME(x) GRS_SetD3D12DebugName(x, L#x)
#define GRS_SET_D3D12_DEBUGNAME_INDEXED(x, n) GRS_SetD3D12DebugNameIndexed(x[n], L#x, n)
#define GRS_SET_DXGI_DEBUGNAME(x) GRS_SetDXGIDebugName(x, L#x)
#define GRS_SET_DXGI_DEBUGNAME_INDEXED(x, n) GRS_SetDXGIDebugNameIndexed(x[n], L#x, n)
#define GRS_SET_D3D12_DEBUGNAME_COMPTR(x) GRS_SetD3D12DebugName(x.Get(), L#x)
#define GRS_SET_D3D12_DEBUGNAME_INDEXED_COMPTR(x, n) GRS_SetD3D12DebugNameIndexed(x[n].Get(), L#x, n)
#define GRS_SET_DXGI_DEBUGNAME_COMPTR(x) GRS_SetDXGIDebugName(x.Get(), L#x)
#define GRS_SET_DXGI_DEBUGNAME_INDEXED_COMPTR(x, n) GRS_SetDXGIDebugNameIndexed(x[n].Get(), L#x, n)
#if defined(_DEBUG)
inline void GRS_SetDXGIDebugName(IDXGIObject* pObject, LPCWSTR name)
__inline void GRS_SetD3D12DebugName(ID3D12Object* pObject, LPCWSTR name)
{
size_t szLen = 0;
StringCchLengthW(name, MAX_PATH, &szLen);
pObject->SetPrivateData(WKPDID_D3DDebugObjectName, static_cast<UINT>(szLen - 1), name);
pObject->SetName(name);
}
inline void GRS_SetDXGIDebugNameIndexed(IDXGIObject* pObject, LPCWSTR name, UINT index)
__inline void GRS_SetD3D12DebugNameIndexed(ID3D12Object* pObject, LPCWSTR name, UINT index)
{
size_t szLen = 0;
WCHAR _DebugName[MAX_PATH] = {};
if (SUCCEEDED(StringCchPrintfW(_DebugName, _countof(_DebugName), L"%s[%u]", name, index)))
{
StringCchLengthW(_DebugName, _countof(_DebugName), &szLen);
pObject->SetPrivateData(WKPDID_D3DDebugObjectName, static_cast<UINT>(szLen), _DebugName);
pObject->SetName(_DebugName);
}
}
#else
inline void GRS_SetDXGIDebugName(IDXGIObject*, LPCWSTR)
__inline void GRS_SetD3D12DebugName(ID3D12Object*, LPCWSTR)
{
}
inline void GRS_SetDXGIDebugNameIndexed(IDXGIObject*, LPCWSTR, UINT)
__inline void GRS_SetD3D12DebugNameIndexed(ID3D12Object*, LPCWSTR, UINT)
{
}
#endif
#define GRS_SET_DXGI_DEBUGNAME(x) GRS_SetDXGIDebugName(x, L#x)
#define GRS_SET_DXGI_DEBUGNAME_INDEXED(x, n) GRS_SetDXGIDebugNameIndexed(x[n], L#x, n)
#define GRS_SET_D3D12_DEBUGNAME(x) GRS_SetD3D12DebugName(x, L#x)
#define GRS_SET_D3D12_DEBUGNAME_INDEXED(x, n) GRS_SetD3D12DebugNameIndexed(x[n], L#x, n)
#define GRS_SET_D3D12_DEBUGNAME_COMPTR(x) GRS_SetD3D12DebugName(x.Get(), L#x)
#define GRS_SET_D3D12_DEBUGNAME_INDEXED_COMPTR(x, n) GRS_SetD3D12DebugNameIndexed(x[n].Get(), L#x, n)
#define GRS_SET_DXGI_DEBUGNAME_COMPTR(x) GRS_SetDXGIDebugName(x.Get(), L#x)
#define GRS_SET_DXGI_DEBUGNAME_INDEXED_COMPTR(x, n) GRS_SetDXGIDebugNameIndexed(x[n].Get(), L#x, n)
//------------------------------------------------------------------------------------------------------------
#pragma once
#include <atlexcept.h>
#ifndef GRS_THROW_IF_FAILED
#define GRS_THROW_IF_FAILED(hr) {HRESULT _hr = (hr);if (FAILED(_hr)){ ATLTRACE("Error: 0x%08x\n",_hr); AtlThrow(_hr); }}
#endif
#define GRS_STRING2(x) #x
#define GRS_STRING(x) GRS_STRING2(x)
//更简洁的向上边界对齐算法 内存管理中常用 请记住
#ifndef GRS_UPPER
......@@ -15,3 +13,9 @@
#ifndef GRS_UPPER_DIV
#define GRS_UPPER_DIV(A,B) ((UINT)(((A)+((B)-1))/(B)))
#endif
#ifndef GRS_THROW_IF_FAILED
#define GRS_THROW_IF_FAILED(hr) {HRESULT _hr = (hr);if (FAILED(_hr)){ ATLTRACE("Error: 0x%08x\n",_hr); AtlThrow(_hr); }}
#endif
#define GRS_SLEEP(dwMilliseconds) ::WaitForSingleObject(::GetCurrentThread(),dwMilliseconds)
\ No newline at end of file
......@@ -4,14 +4,19 @@
#define WIN32_LEAN_AND_MEAN // 从 Windows 头中排除极少使用的资料
#include <windows.h>
#define GRS_ALLOC(sz) ::HeapAlloc(GetProcessHeap(),0,sz)
#define GRS_CALLOC(sz) ::HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sz)
#define GRS_REALLOC(p,sz) ::HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,p,sz)
#define GRS_ALLOC(sz) ::HeapAlloc(GetProcessHeap(),0,sz)
#define GRS_CALLOC(sz) ::HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sz)
#define GRS_REALLOC(p,sz) ::HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,p,sz)
//下面这个表达式可能会引起副作用,p参数尽量使用指针变量,而不是表达式
#define GRS_SAFE_FREE(p) if(nullptr != (p)){::HeapFree(GetProcessHeap(),0,(p));(p)=nullptr;}
#define GRS_FREE(p) GRS_SAFE_FREE(p)
#define GRS_FREE(p) ::HeapFree(GetProcessHeap(),0,p)
#define GRS_SAFE_FREE(p) if(nullptr != (p)){::HeapFree(GetProcessHeap(),0,(p));(p)=nullptr;}
#define GRS_MSIZE(p) ::HeapSize(GetProcessHeap(),0,p)
#define GRS_MVALID(p) ::HeapValidate(GetProcessHeap(),0,p)
#define GRS_MSIZE(p) ::HeapSize(GetProcessHeap(),0,p)
#define GRS_MVALID(p) ::HeapValidate(GetProcessHeap(),0,p)
#ifndef GRS_OPEN_HEAP_LFH
//下面这个宏用于打开堆的LFH特性,以提高性能
#define GRS_OPEN_HEAP_LFH(h) \
ULONG ulLFH = 2;\
HeapSetInformation((h),HeapCompatibilityInformation,&ulLFH ,sizeof(ULONG) ) ;
#endif // !GRS_OPEN_HEAP_LFH
......@@ -45,7 +45,6 @@ __inline BOOL LoadTextureFromMem( ID3D12GraphicsCommandList* pCMDList
stTextureDesc.SampleDesc.Count = 1;
stTextureDesc.SampleDesc.Quality = 0;
GRS_THROW_IF_FAILED( pID3D12Device->CreateCommittedResource(
&stTextureHeapProp
, D3D12_HEAP_FLAG_NONE
......@@ -172,7 +171,7 @@ __inline BOOL LoadTextureFromFile(
BOOL bRet = TRUE;
try
{
BYTE* pbImageData = nullptr;
BYTE* pbImageData = nullptr;
size_t szImageBufferSize = 0;
DXGI_FORMAT emTextureFormat = DXGI_FORMAT_UNKNOWN;
UINT nTextureW = 0;
......
......@@ -47,6 +47,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "21-FullscreenEmpty", "21-Fu
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "22-MultiInstance-PBR-Sphere", "22-MultiInstance-PBR-Sphere\22-MultiInstance-PBR-Sphere.vcxproj", "{CD0784D9-E182-4DF4-90D7-83F5E6193822}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "23-Structured_Empty", "23-Structured_Empty\23-Structured_Empty.vcxproj", "{A2CBF947-07A7-42D9-A268-3CDDD9BCF2AE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
......@@ -321,6 +323,18 @@ Global
{CD0784D9-E182-4DF4-90D7-83F5E6193822}.Release|x64.Build.0 = Release|x64
{CD0784D9-E182-4DF4-90D7-83F5E6193822}.Release|x86.ActiveCfg = Release|Win32
{CD0784D9-E182-4DF4-90D7-83F5E6193822}.Release|x86.Build.0 = Release|Win32
{A2CBF947-07A7-42D9-A268-3CDDD9BCF2AE}.Debug|x64.ActiveCfg = Debug|x64
{A2CBF947-07A7-42D9-A268-3CDDD9BCF2AE}.Debug|x64.Build.0 = Debug|x64
{A2CBF947-07A7-42D9-A268-3CDDD9BCF2AE}.Debug|x86.ActiveCfg = Debug|Win32
{A2CBF947-07A7-42D9-A268-3CDDD9BCF2AE}.Debug|x86.Build.0 = Debug|Win32
{A2CBF947-07A7-42D9-A268-3CDDD9BCF2AE}.Profile|x64.ActiveCfg = Debug|x64
{A2CBF947-07A7-42D9-A268-3CDDD9BCF2AE}.Profile|x64.Build.0 = Debug|x64
{A2CBF947-07A7-42D9-A268-3CDDD9BCF2AE}.Profile|x86.ActiveCfg = Debug|Win32
{A2CBF947-07A7-42D9-A268-3CDDD9BCF2AE}.Profile|x86.Build.0 = Debug|Win32
{A2CBF947-07A7-42D9-A268-3CDDD9BCF2AE}.Release|x64.ActiveCfg = Release|x64
{A2CBF947-07A7-42D9-A268-3CDDD9BCF2AE}.Release|x64.Build.0 = Release|x64
{A2CBF947-07A7-42D9-A268-3CDDD9BCF2AE}.Release|x86.ActiveCfg = Release|Win32
{A2CBF947-07A7-42D9-A268-3CDDD9BCF2AE}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
......@@ -118,3 +118,7 @@ D3D12 ERROR: ID3D12CommandQueue::Present: Resource state (0x800: D3D12_RESOURCE_
1、一口气添加4个项目(19-22),前三个是空的框架性项目,主要是方便大家在此基础上编写自己的示例,主要是逐步加入了Resize和Fullscreen的支持,Fullscreen使用传统的Alt+Enter键来切换,当然你可以用别的方法控制,函数就在那里,等你调用;
2、22号项目是基于点光源PBR渲染的延续,使用了非常重要的多实例以及多插槽(Multi-Instance、Multi-Slot)方法。
2021-12-27
1、在修改14号示例阴影部分时,需要加载DDS纹理,包括颜色纹理和法线纹理的DDS,在另一个例子中使用了更方便的WIC方式来加载DDS,结果发现Cube的DDS和Plane的DDS都无法加载,最后直接用VS2019打开后发现,这两个DDS使用的编码格式是BGRA格式,这样就需要把它们转存为BC3编码格式,目前WIC已经可以支持到最高BC3压缩方式的DDS纹理,这样就比较方便统一纹理的加载方式。所以最终将Cube和Plane的DDS纹理都转码为BC3方式存储。同时BC3编码格式的DDS纹理体积也变小了,另外在Windows资源管理器中也可以预览了,因为Windows资源管理器使用的解码器与WIC使用的解码器是一致的。