D3D Render To Texture Target

render_to_target-300x237

This demo shows how to apply the render to texture target feature with D3D API. The whole content of the Quad geometry was rendered into a texture, and after a cube mesh take this texture as it’s diffuse texture.

 

Render to Target is a very useful technology. Dynamic shadow maps, dynamic cube maps, some real time mirror effect, all kind of post-process effects and so on. All of them are based on this tech.

 

Pre-compile vertex shader & pixel shader. We could compile shaders at the running time, but pre-compile shaders into byte code files should be a much better way. On the one hand, this could save us some running time; on the other side, complied byte code shaders is not so easy to read and it is very hard to crack. This could be used to protect our assets especially when we deliver with a game.

 

To pre-compile D3D HLSL shaders, you coudl refer to “fxc.exe” (This tool should be located under the DirectX install directory). For more details about how to compile shaders, you could check it’s command line help.

1) To compile a pixel shader with optimization on:

fxc /T ps_2_0 /E Main /Fo Quad.ps.bin Quad.ps

2) To compile a pixel shader with debug option on:

fxc /Od /Zi /T ps_2_0 /E Main Quad.ps.bin Quad.ps

3) You could compile the vertex shaders with the very similar command line, but replace “ps_2_0” with “vs_2_0” and give the vertex shader source file. like following:

fxc /T vs_2_0 /E Main /Fo Quad.vs.bin Quad.vs

 

The process of using real time compiling shaders and process of pre-compiled shaders is almost the same.

1) To use real time compiling shaders:

Call “D3DXCompileShaderFromFile()” first to create the shader buffer. With the shader buffer filled already, call “CreatePixelShader” or “CreateVeratexShader” directly.

2) To use pre-compiled shaders:

Here things become more easier. Load the shader byte code binary file content into memory, then call “CreatePixelShader” or “CreateVertexShader” directly.

 

The full source code could be download from here.

转载于:https://www.cnblogs.com/open-coder/archive/2012/08/24/2653587.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值