我想根据传递到着色器的数据动态调用缓动。所以用伪代码来说:
var easing = easings[easingId]
var value = easing(point)
Run Code Online (Sandbox Code Playgroud)
我想知道在 GLSL 中完成此任务的最佳方法。我可以以某种方式使用 switch 语句,或者可以将缓动放入数组中并像这样使用它们。或者也许有一种方法可以创建哈希表并像上面的示例一样使用它。
easingsArray = [
cubicIn,
cubicOut,
...
]
uniform easingId
main() {
easing = easingsArray[easingId]
value = easing(point)
}
Run Code Online (Sandbox Code Playgroud)
这将是潜在的阵列方法。另一种方法是 switch 语句。也许还有其他人。想知道推荐的方法是什么。也许我可以以某种方式使用一个结构......