如何修改/替换 Cg 片段着色器中的像素位置?

发布于 2024-12-15 04:15:06 字数 84 浏览 4 评论 0原文

是否可以使用 Cg 修改片段(像素)着色器中的像素坐标?我确信这样的功能在第二代/第三代着色器中可用,但我不知道确切的配置文件是什么,或者如何做到这一点。

Is it possible to modify pixel coordinates in a fragment (pixel) shader using Cg? I'm sure such functionality became available in 2nd/3rd-generation shaders but I don't know what profiles exactly, or how to do it.

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

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

发布评论

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

评论(2

王权女流氓 2024-12-22 04:15:06

不,这是不可能的。

您可以在片段着色器中修改的唯一坐标是 Z,进入 Z 缓冲区。即使这样也会影响性能,因为它会破坏一些优化(例如 Hierarchical Z)。

X 和 Y 位置是在执行片段着色器之前设置的(在光栅化器中)。典型的光栅化器实际上至少生成 2x2 的像素块,并且硬件并不真正单独处理像素,一直到混合阶段。

有些人倾向于模仿这种类型的特征,即生成超出必要数量的像素,并丢弃无关的像素。

不过,您听说过的功能可能是曲面细分。它不是作为片段着色器的一部分完成的,而是管道的独立部分,允许生成额外的几何体。

最终,您可以使用什么技术取决于您想要实现的目标。但是,无论是在 Cg、OpenGL 还是 DirectX 中,各种 API 都从未支持对 X 和 Y 进行全面修改,因为硬件无法做到这一点。

No, it is not possible.

The only coordinate you can modify in a fragment shader is the Z, going into the Z-buffer. And even that has performance implications, as it defeats some optimizations (like Hierarchical Z).

the X and Y positions are set before the fragment shader is ever executed (in the Rasterizer). Typical rasterizers actually generate at the very least 2x2 chunks of pixels, and the hardware does not really handle pixels individually, all the way to the blending stage.

What some people tend to do to mimic that type of feature is to generate more pixels than necessary, and discard the extraneous pixels.

The feature you have heard about could be tesselation though. It is not done as part of the fragment shader, but is a separate part of the pipeline, that allow to generate additional geometry.

Ultimately, what technique you can use depends on what you're trying to achieve. But a blanket modification of X and Y has never been supported by the various APIs out there, be it in Cg, OpenGL or DirectX, because the hardware can't do it.

墨离汐 2024-12-22 04:15:06

您无法实时修改位图的实际像素,但可以替换 U/V 坐标映射,这会更改每个像素的映射点。

将 UV 映射想象为红色和绿色渐变。红色代表X位置映射,绿色代表Y位置映射。如果将这些坐标乘以柏林噪声等,映射就会发生偏移,因此像素也会发生偏移。

You cannot modify the actual pixels of the bitmap in realtime, but you CAN displace the U/V coordinate mapping, which changes the point where each pixel is mapped.

Imagine the UV mapping as a red and green gradient. Red represents X position mapping while green is Y position mapping. If you were to multiply those coordinates by, say, perlin noise, the mapping would be offsetted, and therefore, so would the pixels.

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