CPU 上的 XNA 插补?
CPU 上的插值
我希望能够在 CPU 上进行插值。
考虑以下示例:
X1 | X2
-------
X3 | X4
X1、X2、X3和X4都是像素(Vector4格式)。它们都有以下坐标。
- X1: {X: 0, Y: 0}
- X2: {X: 1, Y: 0}
- X3: {X: 0, Y: 1}
- X4: {X: 1, Y: 1}
现在,我想成为能够在给定 Vector2 的像素之间进行插值。
假设我想要坐标 {X: 0.348, Y: 0.129} 的颜色。
我如何在像素之间正确插值?
为什么我想这样做
我知道这听起来很疯狂,但这就是我想做的。我正在尝试在 CPU 上模拟 GPU 着色器算法。它适用于柏林噪声发生器。我已经在游戏中通过像素着色器生成了 2D 地形,并且我希望能够(在给定的 X、Y 和 Z 坐标)检查那里是否存在墙壁,使用准确的CPU 上的算法相同。
如果您想更多地了解我正在尝试做什么,请参阅此问题:https://gamedev.stackexchange.com/questions/15667/perlin-noise-copying-the-algorithm-on-the-cpu
编辑
我发布这是错误的地方。它应该位于“gamedev.stackexchange.com”中。无论如何我希望你能得到答案。
Interpolation on the CPU
I would like to be able to do interpolation on the CPU.
Consider the following example:
X1 | X2
-------
X3 | X4
X1, X2, X3 and X4 are all pixels (in Vector4 format). They all have the following coordinates.
- X1: {X: 0, Y: 0}
- X2: {X: 1, Y: 0}
- X3: {X: 0, Y: 1}
- X4: {X: 1, Y: 1}
Now, I want to be able to do interpolation between the pixels given a Vector2.
So let's say I want the color of the coordinates {X: 0.348, Y: 0.129}.
How would I interpolate properly between the pixels?
Why I want to do this
I know this sounds crazy, but it's what I want to do. I am trying to simulate a GPU shader algorithm on the CPU. It's for a Perlin Noise generator. I've already got the 2D terrain generated through a pixel shader that way in the game, and I want to be able to (at a given X, Y and Z coordinate) check if there's a wall present there or not, using the exact same algorithm on the CPU.
If you want to know more about what I am trying to do, see this question: https://gamedev.stackexchange.com/questions/15667/perlin-noise-copying-the-algorithm-on-the-cpu
Edit
I posted this the wrong place. It should have been in "gamedev.stackexchange.com". I hope you have the answer anyway.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在寻找的是双线性插值(维基百科)。
XNA
Lerp
函数执行线性插值 - 即:一个轴。双线性是在两个轴上。幸运的是,这只是在一个轴上进行线性插值(两次:该轴上的每对输入一次),然后对两个结果进行线性插值的问题。所以你会做这样的事情:
What you are looking for is bilinear interpolation (Wikipedia).
The XNA
Lerp
functions do linear interpolation - that is: one axis. Bi-linear is on two axes. Fortunately this is simply a matter of linearly interpolating on one axis (twice: once for each pair of inputs on that axis), and then linearly interpolating the two results.So you'd do something like this: