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.
本文演示了如何使用D3D API的纹理目标渲染功能,将四边形几何的全部内容渲染到纹理中,然后立方体网格采用该纹理作为其漫反射纹理。介绍了实时编译着色器和预编译着色器的过程,并提供了预编译D3D HLSL着色器的方法。

1332

被折叠的 条评论
为什么被折叠?



