How to modify/displace pixel position in a Cg fragment shader?

房东的猫 提交于 2019-12-07 03:11:27

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!