(关于将缓冲区作为输入传递回来的问题,要更具体:我正在两个缓冲区之间进行搅拌,每个缓冲区都具有相同的设置和着色器,每个缓冲区的输出都是对另一个的输入 - 因此,有效地让着色器的输出是其输入之一。)
当其中的一部分,我希望矢量数据随着时间的流逝而“淡入零” - 但我希望它以“弹性”方式这样做:不仅跌至零,而且要过冲一点,加速到停下来,然后朝相反的方向返回,越来越少一些 - 否则,直到它恢复为零。
我正在工作的基础知识:我正在渲染我的矢量数据,我可以执行“淡入淡入零至零”的非弹性。但是我试图实施“弹性”迄今已被挫败。尽管我有几个不同的不正确结果,但在大多数情况下,我似乎得到了矢量data的超级效果
tofar:始终在相反的方向上击中最大允许的值,因此永远不会降低,更不用说安顿了。
这似乎意味着我的加速度不足以克服生成的“速度” - 但是改变加速标量只是减慢了整体效果,而不会改变结果。 :/ 简而言之,简而言之,我正在存储两个向量:我感兴趣的实际数据,以及一个“速度”向量,代表“实际数据”如何落后于零。 帧帧,速度向量具有加速度,按照实际数据的距离缩放,然后将速度向量应用于实际数据。两者都有用于当前帧的三角洲时间。
然后生成当前帧的新数据,并在输出的适当区域内应用(中间是一个小的,模糊的圆圈)。最终,“实际数据”和“速度矢量”都呈现为纹理,准备成为下一帧的输入。
下面是着色器的伪代码:
// The vector-data and the data for the "speed" of that vector-data
// are stored in textures
// Read in the data rendered by the previous frame, and convert
// to a vector (much as with a normal-map)
previousPixel = texture(previousBufferTexture + offset)
previousVectorValue = vec2(previousPixel.x * 2 - 1, previousPixel.y * 2 - 1)
// Do the same with the "speed"-data
previousDirectionOfMotionPixel = texture(previousDirectionOfMotionTexture + offset)
previousDirectionOfMotion = vec2(previousDirectionOfMotionPixel.x * 2 - 1, previousDirectionOfMotionPixel.y * 2 - 1)
// Apply one frame's worth of acceleration to the "speed"-vector
//
// The "min" function is used to prevent high delta-ts--especially
// on startup--from magnifying small values to produce "springiness"
// where there should be little to none.
previousDirectionOfMotion -= previousVectorValue * min(1, deltaTime * 300)
// Then apply the "speed"-vector to the actual data.
//
// Again, the "min" function is intended to thwart over-large delta-ts
previousVectorValue += previousDirectionOfMotion * min(0.05, 4 * deltaTime)
// Now, generate data for the new frame
// This part I'm confident is as intended, so I'm glossing over it.
// The "selector"-value just restricts its application (see below)
// to a small region of the output.
newVectorData, newVectorSelector = generateNewValue()
// Combine the new data with the old data, using the selector
finalVectorData = newVectorData * newVectorSelector + previousVectorValue * (1 - newVectorSelector)
// Convert vector-values to colour-values--again, much as with a normal-map.
//
// I'm actually doing this in the render-lines (see below) on my end, but
// doing it has I have it here should be clearer.
vectorDataRenderResult = (finalVectorData + 1) * 0.5
directionOfMotionRenderResult = (previousDirectionOfMotion + 1) * 0.5
// And finally, render the colour-values out.
color1 = (vectorDataRenderResult, 0, 1)
color2 = (directionOfMotionRenderResult, 0, 1)
是因为我尝试了:从头到尾,我已经弄乱了应用于速度和速度的标量;我尝试固定速度;而且我尝试以各种方式使用“最小”功能,包括更改应用的minima。
最后,似乎答案是两个因素的组合:
首先,在值可能具有的幅度上应用了一些限制。
I.E。通过使用“ min”函数来防止值上升过高
this将其应用于主矢量和“运动方向”矢量
第二,其应用“摩擦”力的应用,它反对主向量并因此削弱了其价值。