SceneKit中的自定义顶点属性 [英] Custom vertex attributes in SceneKit

查看:102
本文介绍了SceneKit中的自定义顶点属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SceneKit生成一些自定义几何体。这工作正常,但我很难找到一种方法来包含自定义顶点属性。具体来说,我希望每个顶点包含一个额外的SCNVector3。



我发现很多例子都使用shaderModifiers来包含依赖于自定义统一值的GLSL / Metal代码,但是避难所遇到了包含顶点属性的方法。这是可能的SceneKit,还是我的思考倒退?

解决方案

似乎没有办法访问自定义几何着色器修饰符中的源。也就是说,如果您的数据适合 float4 ,您可以通过 SCNGeometrySourceSemanticColor 传递该数据。





最后,以下着色器修饰符读取 _geometry.color 的值,并确保将其重置为纯白色,以便存储的数据不会不会影响对象的最终颜色。

  float offset = _geometry.color.x *(sin(1.2 * u_time + (_geometry.position.x + _geometry.position.z)* 4.0)+ 0.5)* 0.02; 
_geometry.position.x + = offset;
_geometry.color.xyz = vec3(1.0);


I'm using SceneKit to generate some custom geometry. This is working fine, but I'm struggling to find a way to include custom vertex attributes. Specifically, I'm looking to include an additional SCNVector3 per vertex.

I've found plenty of examples which make use of shaderModifiers to include GLSL/Metal code that relies upon custom uniform values, but haven't come across a way of including vertex attributes. Is this possible with SceneKit, or is my thinking backwards?

解决方案

there doesn't seem to be a way to access custom geometry sources in shader modifiers. That said, if your data fits into a float4 you can pass that data through SCNGeometrySourceSemanticColor.

The Fox sample code uses the same technique to animate blades of grass. The displacement amount is baked into grayscale vertex colors as shown in the picture below.

Finally the following shader modifier reads the value of _geometry.color and makes sure to reset it to pure white so that the stored data doesn't affect the final color of the object.

 float offset = _geometry.color.x * (sin(1.2 * u_time + (_geometry.position.x+ _geometry.position.z)*4.0) + 0.5) * 0.02;
_geometry.position.x += offset;
_geometry.color.xyz = vec3(1.0);

这篇关于SceneKit中的自定义顶点属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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