The demo how to use D3D vertex shader and pixel shaders. The difference between GPU API rendering and shaders one is not so hurge. While using shaders, you need to create vertex declaration instead FVF(flexible Vertex format). And before call DrawIndexedPrimitives, set the vertex shader & pixel shader to GPU. Those shaders are just very short lines of code that could be run on the GPU.
With D3D, we could privide shader source code directly, and D3D API will compile those shaders at running time. Those shader are text, C-like code. So you could provide D3D with text file or a string hold the whole content of the shader code that could be hard coded in the project. A better way to using shader code is compile shader source code into byte code(Precompiled offline), that will save us a bit time cause we do not to compile it any more.
Here some bugs that need to be mentioned here when I write this demo. 1) The correct way to use mul is mul(vector, matrix). If you write like mul(matrix, vector), there was no errors or warning reported during compiling process, but obviously the result is not correct. 2) About CULL_MODE ! What I get from this demo it seems like that: D3DCULL_CCW means you should provide the D3D with counterclockwise vertices, and D3DCULL_CW means you should provide the D3D with clockwise vertices. Otherwise they will be culled as back surfaces. This does not make scene at all. I will check this later.
The full source code could be downloaded from here.
本文详细介绍了如何在Direct3D中使用顶点着色器和像素着色器,包括创建顶点声明、设置着色器到GPU以及编译着色器源代码为字节码等过程。同时,文中还提到了一些常见的错误,如矩阵乘法的正确使用和CULL_MODE的正确理解。

819

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



