D3D Vertex Shader & Pixel Shader

本文详细介绍了如何在Direct3D中使用顶点着色器和像素着色器,包括创建顶点声明、设置着色器到GPU以及编译着色器源代码为字节码等过程。同时,文中还提到了一些常见的错误,如矩阵乘法的正确使用和CULL_MODE的正确理解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

vs_ps-300x239

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.

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值