是否可以从着色器代码*检索*整数数据?

发布于 2024-10-02 11:22:17 字数 332 浏览 1 评论 0原文

我有一个简单的问题要问.. 这是您在将着色器与 XNA 一起使用时了解的关于着色器的第一件事之一,您可以通过 Effect.Parameters 函数将变量从 C# 传递到着色器代码。例如:

Effect.Parameters["shaderVariable"].SetValue(someValue);

在上面的行中,您将存储在 'someValue' 中的值发送到着色器变量 'shaderVariable' ..

可以我们也做相反的事情吗?例如,您想要调试着色器代码的内部工作原理,并希望将一些数值数据发送回您的 C# 应用程序,那么是否还有类似但相反的关系函数可用?

I have a simple question to ask .. Its one of the first things you learn about shaders when using them with XNA that you can pass on variables from C# to the shader code via the Effect.Parameters function. For example:

Effect.Parameters["shaderVariable"].SetValue(someValue);

In the above line, you're sending the value stored in 'someValue' to the shader variable 'shaderVariable' ..

Can we do the reverse as well ? Like for example, you want to debug the inner workings of a shader code and want to send back some numerical data to your C# application, then is there any similar but opposite relation functional available as well ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

横笛休吹塞上声 2024-10-09 11:22:18

并不真地。问题是像素着色器每个像素执行一次,顶点着色器每个顶点执行一次。因此,当您绘制时,您可能有数百个程序实例可供选择,那么您如何知道要从哪一个实例获取输出值呢?

从着色器获取输出的唯一真正方法是通过它最终输出的图像(除了 GPGPU)。

但是 - 如果您只想进行着色器调试,请使用 PIX 在 DirectX SDK 中。

Not really. The problem is that a pixel shader is executed once per pixel, and a vertex shader once per vertex. So you've got potentially hundreds of instances of your program to pick from, when you draw, so how do you know which one you want to get the output value from?

The only real way to get output from a shader is via the image that it eventually outputs (GPGPU aside).

But - if all you want to do is shader debugging, use PIX in the DirectX SDK.

§普罗旺斯的薰衣草 2024-10-09 11:22:18

图形管线只会向前推进,CPU ->顶点->像素->框架。如果您想要检查像素着色器中的某个值,只需稍微修改着色器,以便它以颜色形式返回该值。例如,您可以返回 texCoord 的 xy 值作为图像中的红色和绿色通道。

The graphics pipeline will only ever go forwards, CPU -> Vertex -> Pixel -> Frame. If you have a value in your pixel shader that you want to examine, just modify your shader slighty so that it returns that value as a color. For example you could return the xy values of a texCoord as the red and green color channels in your image.

得不到的就毁灭 2024-10-09 11:22:18

是的,您可以从着色器获取数据(至少在 XNA 4.0 中),例如:

var projection = <your effect>.Parameters["projection"].GetValueMatrix();

Yes you can get data from the shader (at least in XNA 4.0) eg:

var projection = <your effect>.Parameters["projection"].GetValueMatrix();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文