提交 c7ef94ff 编写于 作者: GamebabyRockSun_QQ's avatar GamebabyRockSun_QQ

修正了D3D12显示GIF动画示例中子帧画面渲染未偏移的错误,现在显示各种GIF都正常了

上级 aecfd414
//ˮʻЧShader
struct PSInput
{
float4 m_v4Pos : SV_POSITION;
......
......@@ -335,7 +335,7 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR l
ComPtr<ID3D12Resource> pIVBQuadUpload;
D3D12_VERTEX_BUFFER_VIEW pstVBVQuad;
SIZE_T szSecondPassCB = GRS_UPPER(sizeof(ST_GRS_PEROBJECT_CB), 256);
ST_GRS_PEROBJECT_CB* pstCBSecondPass = nullptr;
ST_GRS_PEROBJECT_CB* pstCBSecondPass = nullptr;
ComPtr<ID3D12Resource> pICBResSecondPass;
ComPtr<ID3D12Resource> pINoiseTexture;
ComPtr<ID3D12Resource> pINoiseTextureUpload;
......
......@@ -264,9 +264,11 @@ struct ST_GRS_FRAME_MVP_BUFFER
struct ST_GRS_GIF_FRAME_PARAM
{
XMFLOAT4 m_c4BkColor;
UINT m_nLeftTop[2];
UINT m_nFrameWH[2];
UINT m_nFrame;
UINT m_nDisposal;
XMFLOAT4 m_c4BkColor;
};
enum EM_GRS_DISPOSAL_METHODS
......@@ -306,7 +308,9 @@ struct ST_GRS_GIF_FRAME
DXGI_FORMAT m_enTextureFormat;
UINT m_nFrameDisposal;
UINT m_nFrameDelay;
ST_GRS_RECT_F m_rtGIFFrame;
UINT m_nLeftTop[2];
UINT m_nFrameWH[2];
//ST_GRS_RECT_F m_rtGIFFrame;
};
//--------------------------------------------------------------------------------------------------
......@@ -393,7 +397,6 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCm
ComPtr<ID3D12Resource> pITextureUpload;
ComPtr<ID3D12DescriptorHeap> pISRVHeap;
ComPtr<ID3D12Resource> pICBGIFFrameInfo; // Computer Shader Const Buffer
SIZE_T szGIFFrameInfo = GRS_UPPER(sizeof(ST_GRS_GIF_FRAME_PARAM), 256);
......@@ -1284,6 +1287,11 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCm
, GRS_ARGB_A(g_stGIF.m_nBkColor));
pstGIFFrameInfo->m_nFrame = g_stGIF.m_nCurrentFrame;
pstGIFFrameInfo->m_nDisposal = stGIFFrame.m_nFrameDisposal;
pstGIFFrameInfo->m_nLeftTop[0] = stGIFFrame.m_nLeftTop[0]; //Frame Image Left
pstGIFFrameInfo->m_nLeftTop[1] = stGIFFrame.m_nLeftTop[1]; //Frame Image Top
pstGIFFrameInfo->m_nFrameWH[0] = stGIFFrame.m_nFrameWH[0]; //Frame Image Width
pstGIFFrameInfo->m_nFrameWH[1] = stGIFFrame.m_nFrameWH[1]; //Frame Image Height
D3D12_SHADER_RESOURCE_VIEW_DESC stSRVDesc = {};
stSRVDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
......@@ -1339,7 +1347,9 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCm
pICSList->SetComputeRootDescriptorTable(2, stSRVGPUHandle);
// Computer!
pICSList->Dispatch(g_stGIF.m_nWidth, g_stGIF.m_nHeight, 1);
// 注意:按子帧大小来发起计算线程
pICSList->Dispatch(stGIFFrame.m_nFrameWH[0], stGIFFrame.m_nFrameWH[1],1);
//pICSList->Dispatch(g_stGIF.m_nWidth, g_stGIF.m_nHeight, 1);
// 开始计算管线运行
D3D12_RESOURCE_BARRIER stRWResEndBarrier = {};
......@@ -1673,7 +1683,7 @@ BOOL LoadGIFFrame(IWICImagingFactory* pIWICFactory, ST_GRS_GIF& g_stGIF, ST_GRS_
{
if (VT_UI2 == stCOMPropValue.vt)
{
stGIFFrame.m_rtGIFFrame.m_fLeft = static_cast<FLOAT>(stCOMPropValue.uiVal);
stGIFFrame.m_nLeftTop[0] = static_cast<UINT>(stCOMPropValue.uiVal);
}
}
PropVariantClear(&stCOMPropValue);
......@@ -1682,7 +1692,7 @@ BOOL LoadGIFFrame(IWICImagingFactory* pIWICFactory, ST_GRS_GIF& g_stGIF, ST_GRS_
{
if (VT_UI2 == stCOMPropValue.vt)
{
stGIFFrame.m_rtGIFFrame.m_fTop = static_cast<FLOAT>(stCOMPropValue.uiVal);
stGIFFrame.m_nLeftTop[1] = static_cast<UINT>(stCOMPropValue.uiVal);
}
}
PropVariantClear(&stCOMPropValue);
......@@ -1691,8 +1701,7 @@ BOOL LoadGIFFrame(IWICImagingFactory* pIWICFactory, ST_GRS_GIF& g_stGIF, ST_GRS_
{
if (VT_UI2 == stCOMPropValue.vt)
{
stGIFFrame.m_rtGIFFrame.m_fRight = static_cast<FLOAT>(stCOMPropValue.uiVal)
+ stGIFFrame.m_rtGIFFrame.m_fLeft;
stGIFFrame.m_nFrameWH[0] = static_cast<UINT>(stCOMPropValue.uiVal);
}
}
PropVariantClear(&stCOMPropValue);
......@@ -1701,8 +1710,7 @@ BOOL LoadGIFFrame(IWICImagingFactory* pIWICFactory, ST_GRS_GIF& g_stGIF, ST_GRS_
{
if (VT_UI2 == stCOMPropValue.vt)
{
stGIFFrame.m_rtGIFFrame.m_fBottom = static_cast<FLOAT>(stCOMPropValue.uiVal)
+ stGIFFrame.m_rtGIFFrame.m_fTop;
stGIFFrame.m_nFrameWH[1] = static_cast<UINT>(stCOMPropValue.uiVal);
}
}
PropVariantClear(&stCOMPropValue);
......@@ -1751,6 +1759,11 @@ BOOL UploadGIFFrame(ID3D12Device4* pID3D12Device4, ID3D12GraphicsCommandList* pI
//获得图片大小(单位:像素)
GRS_THROW_IF_FAILED(stGIFFrame.m_pIWICGIFFrameBMP->GetSize(&nTextureW, &nTextureH));
if (nTextureW != stGIFFrame.m_nFrameWH[0] || nTextureH != stGIFFrame.m_nFrameWH[1])
{//从属性解析出的帧画面大小与转换后的画面大小不一致
throw CGRSCOMException(S_FALSE);
}
//获取图片像素的位大小的BPP(Bits Per Pixel)信息,用以计算图片行数据的真实大小(单位:字节)
ComPtr<IWICComponentInfo> pIWICmntinfo;
WICPixelFormatGUID stGuidTargetFormat = {};
......
cbuffer ST_GRS_GIF_FRAME_PARAM : register(b0)
{
uint m_nFrame;
uint m_nDisposal;
float4 m_c4BkColor;
float4 m_c4BkColor;
uint2 m_nLeftTop;
uint2 m_nFrameWH;
uint m_nFrame;
uint m_nDisposal;
};
// 帧纹理,尺寸就是当前帧画面的大小,注意这个往往不是整个GIF的大小
Texture2D g_tGIFFrame : register(t0);
// 最终代表整个GIF画板纹理,大小就是整个GIF的大小
RWTexture2D<float4> g_tPaint : register(u0);
[numthreads(1, 1, 1)]
void ShowGIFCS( uint3 n3ThdID : SV_DispatchThreadID)
{
if (0 == m_nFrame)
{// 第一帧时用背景色擦除一下先
if ( 0 == m_nFrame )
{// 第一帧时用背景色整个绘制一下先,相当于一个Clear操作
g_tPaint[n3ThdID.xy] = m_c4BkColor;
}
if ( 2 == m_nDisposal )
{//DM_BACKGROUND 用背景色填充整个画面,相当于一个Clear操作,因为命令列表中的ClearUAV命令只能设置一个float值,所以放到这里来清除背景
g_tPaint[n3ThdID.xy] = m_c4BkColor;
// 注意画板的像素坐标需要偏移,画板坐标是:m_nLeftTop.xy + n3ThdID.xy
// m_nLeftTop.xy就是当前帧相对于整个画板左上角的偏移值
// n3ThdID.xy就是当前帧中对应要绘制的像素点坐标
if ( 0 == m_nDisposal )
{//DM_NONE 不清理背景
g_tPaint[ m_nLeftTop.xy + n3ThdID.xy ] = g_tGIFFrame[n3ThdID.xy];
}
else if (0 == m_nDisposal || 1 == m_nDisposal)
{//DM_UNDEFINED or DM_NONE 不清楚背景,直接在原来画面基础上进行Alpha混色绘制
// Simple Alpha Blending
g_tPaint[n3ThdID.xy] = g_tGIFFrame[n3ThdID.xy].w * g_tGIFFrame[n3ThdID.xy]
+ (1.0f - g_tGIFFrame[n3ThdID.xy].w) * g_tPaint[n3ThdID.xy];
else if (1 == m_nDisposal)
{//DM_UNDEFINED 直接在原来画面基础上进行Alpha混色绘制
// 注意g_tGIFFrame[n3ThdID.xy].w只是简单的0或1值,所以没必要进行真正的Alpha混色计算
// 但这里也没有使用IF Else判断,而是用了开销更小的?:三元表达式来进行计算
g_tPaint[ m_nLeftTop.xy + n3ThdID.xy ]
= g_tGIFFrame[n3ThdID.xy].w ? g_tGIFFrame[n3ThdID.xy] : g_tPaint[m_nLeftTop.xy + n3ThdID.xy];
}
else if ( 2 == m_nDisposal )
{// DM_BACKGROUND 用背景色填充画板,然后绘制,相当于用背景色进行Alpha混色,过程同上
g_tPaint[m_nLeftTop.xy + n3ThdID.xy] = g_tGIFFrame[n3ThdID.xy].w ? g_tGIFFrame[n3ThdID.xy] : m_c4BkColor;
}
else if( 3 == m_nDisposal )
{// DM_PREVIOUS 保留前一帧
g_tPaint[ m_nLeftTop.xy + n3ThdID.xy ] = g_tPaint[n3ThdID.xy + m_nLeftTop.xy];
}
}
\ No newline at end of file
......@@ -1463,7 +1463,7 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR l
, XMLoadFloat3(&g_f3HeapUp));
XMMATRIX xmProj = XMMatrixPerspectiveFovLH(XM_PIDIV4
, (FLOAT)iWndWidth / (FLOAT)iWndHeight, 1.0f, 20000.0f);
, (FLOAT)iWndWidth / (FLOAT)iWndHeight, 1.0f, 2000.0f);
//使用“Assets\\sky_cube.dds”时需要XMMATRIX(1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1)乘以xmView
XMMATRIX xmSkyBox = xmView;// XMMatrixMultiply(XMMATRIX(1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1), xmView);
xmSkyBox = XMMatrixMultiply(xmSkyBox, xmProj);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册