如何在Cg片段着色器中修改/替换像素位置? [英] How to modify/displace pixel position in a Cg fragment shader?

查看:271
本文介绍了如何在Cg片段着色器中修改/替换像素位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用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.

推荐答案

否,这不可能.

您只能在片段着色器中修改的坐标是Z,进入Z缓冲区.甚至还会影响性能,因为它会破坏某些优化(例如Hierarchical Z).

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

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

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.

最终,可以使用哪种技术取决于您要实现的目标.但是,由于硬件无法做到,因此各种CAPI,OpenGL或DirectX中的API都不支持对X和Y进行全面修改.

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.

这篇关于如何在Cg片段着色器中修改/替换像素位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆