如何使用 directX 11 计算着色器显示某些内容?

发布于 2024-09-08 10:06:09 字数 71 浏览 2 评论 0原文

我想从我的 directX 11 计算着色器写入纹理。但是我不知道如何将其显示在屏幕上,也不知道应该使用哪种缓冲区来执行此操作。

I am wanting to write to a texture from my directX 11 compute shader. However I have no idea how to display this onto the screen nor am I sure what sort of buffer I should be using to do this.

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

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

发布评论

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

评论(1

青瓷清茶倾城歌 2024-09-15 10:06:09

欢迎来到 stackoverflow :)

要选择的资源类型是 RWTexture2D因为您可以通过交换链直接在屏幕上打印它。
您可以查看 DirectX SDK OIT 示例:

他们声明了一个 RWTexture2D。它们在 OIT_CS.hlslSortAndRenderCS 函数中访问的frameBuffer。

// convert the color to floats
float4 color[3];
color[0].r = (r0 >> 0  & 0xFF) / 255.0f;
color[0].g = (r0 >> 8  & 0xFF) / 255.0f;
color[0].b = (r0 >> 16 & 0xFF) / 255.0f;
color[0].a = (r0 >> 24 & 0xFF) / 255.0f;

color[1].r = (r1 >> 0  & 0xFF) / 255.0f;
color[1].g = (r1 >> 8  & 0xFF) / 255.0f;
color[1].b = (r1 >> 16 & 0xFF) / 255.0f;
color[1].a = (r1 >> 24 & 0xFF) / 255.0f;

color[2].r = (r2 >> 0  & 0xFF) / 255.0f;
color[2].g = (r2 >> 8  & 0xFF) / 255.0f;
color[2].b = (r2 >> 16 & 0xFF) / 255.0f;
color[2].a = (r2 >> 24 & 0xFF) / 255.0f;

float4 result = lerp(lerp(lerp(0, color[2], color[2].a), color[1], color[1].a), color[0], color[0].a);
result.a = 1.0f;
frameBuffer[nDTid.xy] = result;

正如你所看到的,它们有 r0r1r2 uint 值,这些值实际上是 RGBA 颜色(一个字节每个通道),他们使用移位和掩码提取每个通道并将其标准化。

当然,如果您已经有 float4 值,则不需要这样做。
然后他们做那些 lerps(用于插值)。同样,您不需要这样做。
您感兴趣的是,它们使用数组表示法和坐标的 uint2 来访问 frameBuffer

welcome on stackoverflow :)

The type of resource to choose is RWTexture2D<float4> since you can print this directly on screen via a swapchain.
You can look at the DirectX SDK OIT sample:

They have declared a RWTexture2D<float4> frameBuffer that they access in the function SortAndRenderCS of OIT_CS.hlsl.

// convert the color to floats
float4 color[3];
color[0].r = (r0 >> 0  & 0xFF) / 255.0f;
color[0].g = (r0 >> 8  & 0xFF) / 255.0f;
color[0].b = (r0 >> 16 & 0xFF) / 255.0f;
color[0].a = (r0 >> 24 & 0xFF) / 255.0f;

color[1].r = (r1 >> 0  & 0xFF) / 255.0f;
color[1].g = (r1 >> 8  & 0xFF) / 255.0f;
color[1].b = (r1 >> 16 & 0xFF) / 255.0f;
color[1].a = (r1 >> 24 & 0xFF) / 255.0f;

color[2].r = (r2 >> 0  & 0xFF) / 255.0f;
color[2].g = (r2 >> 8  & 0xFF) / 255.0f;
color[2].b = (r2 >> 16 & 0xFF) / 255.0f;
color[2].a = (r2 >> 24 & 0xFF) / 255.0f;

float4 result = lerp(lerp(lerp(0, color[2], color[2].a), color[1], color[1].a), color[0], color[0].a);
result.a = 1.0f;
frameBuffer[nDTid.xy] = result;

As you can see they have r0, r1 and r2 uint values that are actually RGBA colors (a byte for each channel), they extract each channel using shifts and masks and normalized it.

You don't need to do that if you have already float4 values of course.
Then they do those lerps (for interpolation). Again you shouldn't need to do that.
What interest you is that they access frameBuffer using array notation and an uint2 for coordinates.

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