您的位置:首页 > 其它

D3D Vertex Shader & Pixel Shader

2012-08-24 08:34 375 查看




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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: