一个更好的Post process结构,三角形代替四边形。

三角形比四边形有着更好的性能,所以利用三角形代替四边形作为post process的框架,下面是细节:


C++ 代码:

// Null VB, IB
pD3dContext->IASetVertexBuffers( 0, 0, NULL, NULL, NULL );
pD3dContext->IASetIndexBuffer( NULL, (DXGI_FORMAT)0, 0 );
pD3dContext->IASetInputLayout( NULL );

// Set Shaders
pD3dContext->VSSetShader( g_pFullScreenVs, NULL, 0 );
pD3dContext->PSSetShader( ... );
pD3dContext->PSSetShaderResources( ... );

pD3dContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );

// Render 3 vertices for the triangle
pD3dContext->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/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值