> Vertexes1
> Vertexes2
重要的是要知道这些顶点具有先前未知的值,因为它们是动态的.
我想在这两者之间进行动画过渡(变形).我想出了两种不同的方法:
选项1:
在顶点着色器中设置一个时间均匀,从0到1,我可以这样做:
// InsIDe main() in the vertex shaderfloat originX = position.x;float destinationX = DestinationVertexposition.x;float interpolatedX = originX + (destinationX - originX) * Time;gl_position.x = interpolatedX;
正如您可能看到的,这有一个问题:如何在那里获得“DestinationVertexposition”?
选项2:
在顶点着色器之外进行插值计算,我遍历每个顶点并为插值创建第三个顶点集,并使用它进行渲染:
// Pre render// Use this vertex set to renderInterpolatedVertexesfor (unsigned int i = 0; i < vertexCount; i++) { float originX = Vertexes1[i].x; float destinationX = Vertexes2[i].x; float interpolatedX = originX + (destinationX - originX) * Time; InterpolatedVertexes[i].x = interpolatedX;}
我已经高度简化了这两个代码片段,只是为了让这个想法变得清晰.
现在,从两个选项中,我觉得第一个在性能方面肯定更好,因为在着色器级别发生了一些事情,并且每次更新“时间”时我都不必创建一组新的顶点.
那么,既然已经涵盖了问题的介绍,我将不胜感激以下三点:
>讨论在OpenGL ES 2(iOS)中实现预期结果的更好方法.
>讨论如何通过提供“DestinationVertexposition”或通过某种方式修改想法来正确实现选项1,以更好地实现相同的结果.
>讨论如何实施选项2.
int sourceAttribute = glGetAttribLocation(shader,"sourceVertex");glVertexAttribPointer(sourceAttribute,3,GL_float,GL_FALSE,sourceLocations);int destAttribute = glGetAttribLocation(shader,"destVertex");glVertexAttribPointer(destAttribute,destLocations);
和:
gl_position = vec4(mix(sourceVertex,destVertex,Time),1.0);总结
以上是内存溢出为你收集整理的OpenGL ES 2(iOS)变形/两组顶点之间的动画全部内容,希望文章能够帮你解决OpenGL ES 2(iOS)变形/两组顶点之间的动画所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)