Managed DirectX 中着色器的基本示例
我是新编写的像素着色器并在我的托管 directx 项目中使用,在那里我可以获得一些基本示例来启动它。
I am new write a pixel shader and use in my managed directx project, where i can get some basic sample to start it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您知道如何创建设备。
首先,您需要准备着色器本身。
这是一个像素着色器的小示例(它使用像素着色器 1.4,如 ps_1_4 所示;r0 是一个寄存器,被读取为最终结果;v0 是一个存储原色(漫射照明)的寄存器)
:在着色器组装中,必须进行组装。您可以按如下方式执行此操作(请注意,您需要引用 D3DX 库,否则您将看不到 ShaderLoader 类):
组装着色器后,您最终可以创建一个 PixelShader 对象,如下所示:
要应用像素着色器,请使用
:设备是 Direct3D 设备。
如果您使用 HLSL,则类似的过程适用于编译着色器。
编辑:
刚刚注意到这是一个一年前的问题。
I'm assuming you know how to create a device.
First, you need to prepare the shader itself.
Here's a little sample pixel shader (which uses pixel shader 1.4, as seen by ps_1_4; r0 is a register that is read as the final result; v0 is a register that stores primary colour (of diffuse lighting)):
This shader, which is in shader assembly, has to be assembled. You can do that as follows (note that you need D3DX library referenced, otherwise you won't see the ShaderLoader class):
After assembling the shader, you can finally create a PixelShader object as follows:
To apply the pixel shader, use:
where Device is the Direct3D Device.
A similar process applies for compiling shaders in case you use HLSL.
Edit:
Just noticed this was an year old question.