OpenGL ES顶点着色器中的动态大小的数组;用于混合形状/变形目标 [英] Dynamically sized arrays in OpenGL ES vertex shader; used for blend shapes/morph targets

查看:1676
本文介绍了OpenGL ES顶点着色器中的动态大小的数组;用于混合形状/变形目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要做一个Opengl ES实现的混合形状/变形目标,我不知道我最好的方式做到这一点。我面临的问题是,我想要的顶点数据的插值发生在GPU上,但我还希望混合形状的数量是任意的。



,我不想让我的顶点着色器看起来像这样:
OpenGL(C ++)中的Glitchy面部变体目标动画。这个实现的问题是要混合的网格的数量在着色器中是静态的。我将处理具有不同数量的混合形状的多个网格关联到他们,我不想为每个如果可能的创建单独的着色器。为大约20个混合形状的网格创建硬编码着色器也将看起来相当难看。



所以我正在想使用某种动态数组来保存所有的数据。但是,我不确定是否可以在顶点着色器中分配动态大小的数组。在具有数组输入的顶点着色器中,op的大小设置为常量。我可以考虑创建我的数组的唯一方法是使用一个统一的变量来保持大小,但我猜测不会编译,因为数组不能分配一个未知的变量。



所以我试图找到的是一个很好的方式来存储我的数据(混合形状,权重,顶点,法线的数量),并在运行时访问我的顶点着色器,所以我可以有效地内插



有关如何完成此任务的任何想法吗?

b $ b忘记提及它的OpenGL ES

解决方案

你正在寻找的是着色器存储缓冲区对象(SSBO的),他们基本上可以让你做你想做的事情。 p>

但需要注意的是:它们仅适用于GL4.x类硬件,特别是4.3+。这是每年越来越少的问题,但如果计算机的GPU超过5岁,它可能不工作。



如果你'处理OpenGL ES,你仍然(可能)有统一缓冲区对象,只需要OpenGL 3.x硬件。他们比SSBO有更多的限制(规格只保证65kb的数据,甚至现代硬件通常不会提供超过那些空间),但它更有可能与您的硬件兼容。



在绝对最坏的情况下,你也可以使用纹理作为缓冲区,你可以写任意数据,然后重新解释着色器上的数据。这是非常hacky,但它会绕过UBO的空间限制,并可能几乎在任何级别与您的硬件兼容。


I'm about to do an Opengl ES implementation of blend shapes/morph targets and I'm not quite sure about the best way for me to do this. The problems I am facing is that I want the interpolation of the vertex data to occur on the GPU but I also want the number of blend shapes to be arbitrary.

To clarify, I do not want my vertex shader to look like this: Glitchy Facial Morph Target Animation in OpenGL (C++). The problem with this implementation is that the number of meshes to blend between is static in the shader. I am going to process multiple meshes that have different numbers of blend shapes associated to them and I dont want to create separate shader for each if possible. Creating hard-coded shaders for meshes with around 20 blend shapes will also look quite ugly imo.

So I was thinking of using some kind of dynamic array to hold all the data. However, I'm uncertain if you can allocate dynamically sized arrays in the vertex shader? In Vertex shader with array inputs the op has the size set to a constant. The only way I could think about creating my array is the use a uniform variable to hold the size but I'm guessing that won't compile since the array cannot be allocated with an unknown variable.

So what I'm trying to find is a good way to store my data(number of blend shapes, weights, vertices, normals) and to access them during runtime in my vertex shader so I can effectively interpolate on the GPU.

Any ideas on how to accomplish this?

EDIT Forgot to mention its for OpenGL ES

解决方案

What you're looking for is Shader Storage Buffer Objects (SSBO's) and they'll basically let you do exactly what you're trying to do.

Big caveat though: they're only available on GL4.x class hardware, specifically 4.3+. This is becoming less and less of a problem each year, but if the computer's GPU is more than 5 years old, it may not work.

If you're dealing with OpenGL ES, you'll still (probably) have Uniform Buffer Objects which only require OpenGL 3.x hardware. They're a lot more limited than SSBOs (spec only guarantees 65kb of data, and even modern hardware doesn't typically give space beyond that) but it's much more likely to be compatible with your hardware.

In an absolute worst-case scenario, you could also use textures as buffers that you write arbitrary data to, then reinterpret the data on the shader. It's very hacky, but it'll bypass the space restrictions of UBO's, and will probably be compatible with your hardware at almost any level.

这篇关于OpenGL ES顶点着色器中的动态大小的数组;用于混合形状/变形目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆