Managed DirectX 中着色器的基本示例

发布于 2024-08-11 16:39:02 字数 58 浏览 8 评论 0原文

我是新编写的像素着色器并在我的托管 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绿萝 2024-08-18 16:39:02

我假设您知道如何创建设备。

首先,您需要准备着色器本身。

这是一个像素着色器的小示例(它使用像素着色器 1.4,如 ps_1_4 所示;r0 是一个寄存器,被读取为最终结果;v0 是一个存储原色(漫射照明)的寄存器)

ps_1_4
mov r0, v0

:在着色器组装中,必须进行组装。您可以按如下方式执行此操作(请注意,您需要引用 D3DX 库,否则您将看不到 ShaderLoader 类):

Imports Microsoft.DirectX

' other code

Dim graphicsStream As GraphicsStream = Direct3D.ShaderLoader.FromString(shaderText, Nothing, Direct3D.ShaderFlags.None)

' other code.

组装着色器后,您最终可以创建一个 PixelShader 对象,如下所示:

' other code

Dim p As Direct3D.PixelShader = New Direct3D.PixelShader(Device, graphicsStream)

' other code

要应用像素着色器,请使用

' other code

Device.PixelShader = p

' other code

:设备是 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)):

ps_1_4
mov r0, v0

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):

Imports Microsoft.DirectX

' other code

Dim graphicsStream As GraphicsStream = Direct3D.ShaderLoader.FromString(shaderText, Nothing, Direct3D.ShaderFlags.None)

' other code.

After assembling the shader, you can finally create a PixelShader object as follows:

' other code

Dim p As Direct3D.PixelShader = New Direct3D.PixelShader(Device, graphicsStream)

' other code

To apply the pixel shader, use:

' other code

Device.PixelShader = p

' other code

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文