本文共 1030 字,大约阅读时间需要 3 分钟。
三角形比四边形有着更好的性能,所以利用三角形代替四边形作为post process的框架,下面是细节:
C++ 代码:
// Null VB, IBpD3dContext->IASetVertexBuffers( 0, 0, NULL, NULL, NULL );pD3dContext->IASetIndexBuffer( NULL, (DXGI_FORMAT)0, 0 );pD3dContext->IASetInputLayout( NULL );// Set ShaderspD3dContext->VSSetShader( g_pFullScreenVs, NULL, 0 );pD3dContext->PSSetShader( ... );pD3dContext->PSSetShaderResources( ... );pD3dContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );// Render 3 vertices for the trianglepD3dContext->Draw(3, 0);
HLSL 代码:
VSOutput VSFullScreen(uint id:SV_VERTEXID){ VSOutput output; // generate clip space position output.pos.x = (float)(id/2)*4.0 -1.0; output.pos.y = (float)(id%2)*4.0 -1.0; output.pos.z = 0.0; output.pos.w = 1.0; // texture coordinates output.tex.x = (float)(id/2)*2.0; output.tex.y = 1.0 - (float)(id%2)*2.0; // color output.color = float4(1,1,1,1); return output;}
对于GCN架构,可以提高10%左右的性能,具体分析见下文:
http://michaldrobot.com/2014/04/01/gcn-execution-patterns-in-full-screen-passes/
转载地址:http://uhwqb.baihongyu.com/