Unity2018.1中对粒子系统进行了重大改进,包括功能、性能很多方面,快来看看吧!
GPU网格实例化
粒子系统现在支持GPU实例化来渲染网格。粒子系统使用Procedural Instancing,可以在此处详细解释:https://docs.unity3d.com/Manual/GPUInstancing.html
实例化支持已添加到“Particle Standard Shaders”中,并将在所有新内容中默认启用。旧版内容升级到Unity 2018.1后,可以使用Renderer模块中的复选框启用GPU实例化。
还可以将粒子实例化功能添加到自定义的着色器中。这是一个简单的例子:
Shader "Instanced/ParticleMeshesCustom" { Properties { _MainTex("Albedo", 2D) = "white" {} [Toggle(_FLIPBOOK_BLENDING)] _FlipbookBlending("Flipbook Blending", Int) = 0 } SubShader { Tags{ "RenderType" = "Opaque" } LOD 100 Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma multi_compile __ _FLIPBOOK_BLENDING #pragma multi_compile_instancing #pragma instancing_options procedural:vertInstancingSetup #include "UnityCG.cginc" #include "UnityStandardParticleInstancing.cginc" struct appdata { float4 vertex : POSITION; fixed4 color : COLOR; float2 texcoord : TEXCOORD0; UNITY_VERTEX_INPUT_INSTANCE_ID }; struct v2f { float4 vertex : SV_POSITION; fixed4 color : COLOR; float2 texcoord : TEXCOORD0; #ifdef _FLIPBOOK_BLENDING float3 texcoord2AndBlend : TEXCOORD1; #endif }; sampler2D _MainTex; float4 _MainTex_ST; fixed4 readTexture(sampler2D tex, v2f IN) { fixed4 color = tex2D(tex, IN.texcoord); #ifdef _FLIPBOOK_BLENDING fixed4 color2 = tex2D(tex, IN.texcoord2AndBlend.xy); color = lerp(color, color2, IN.texcoord2AndBlend.z); #endif return color; } v2f vert(appdata v) { v2f o; UNITY_SETUP_INSTANCE_ID(v); o.color = v.color; o.texcoord = v.texcoord; vertInstancingColor(o.color); #ifdef _FLIPBOOK_BLENDING vertInstancingUVs(v.texcoord, o.texcoord, o.texcoord2AndBlend); #else vertInstancingUVs(v.texcoord, o.texcoord); #endif o.vertex = UnityObjectToClipPos(v.vertex); return o; } fixed4 frag(v2f i) : SV_Target { half4 albedo = readTexture(_MainTex, i); return i.color * albedo; } ENDCG } } }
使用Instancing可以渲染更多的粒子网格,并且CPU性能更好。
这里有10,000个球体网格,使用旧的非实例化技术,10fps:
这里有100,000个球面网格,使用新的实例技术,可以达到100fps:
轨道粒子速度
Unity 2018.1为Velocity over Lifetime模块添加了一些新选项,使您可以使粒子相对于定义的中心点移动。默认情况下,中心与transform对齐,但可以在模块内修改。可以使用Orbital
参数使粒子绕中心点行进,并使用Radial
参数离开/朝向中心点。
纹理形状模块
Shape模块中的所有形状类型现在都支持纹理。纹理可用于:
- 控制粒子颜色
- 控制粒子alpha
- 根据设置的的阈值和纹理通道丢弃粒子
子发射器
在Unity 2018.1中有两种新的产生子发射器的方法。第一种是通过触发模块,其工作方式类似于子碰撞模块产生子发射器的方式。只需在子发射器模块中选择触发器作为子发射器类型,然后当触发器模块内部满足条件时(例如粒子进入碰撞体积),相应的子发射器将被触发。
触发子发射器的第二种新方法是通过脚本。添加了一个名为TriggerSubEmitter 的新API ,可用于为单个粒子,粒子列表或所有粒子触发子发射器。在子发射器模块中,您可以选择Manual
作为生成类型,该生成类型告诉粒子系统该发射器只能通过脚本中的调用触发。也可以使用现有的类型(例如Collision 或Death ),并通过脚本为这些子发射器添加其他触发器。
旧粒子系统退役
继续维护旧粒子系统成了每个Unity版本的开发负担。新引擎功能(如VR和多线程渲染)需要花费更多时间来确保引擎的兼容性。当添加新的引擎功能时,需要花很多时间维护传统粒子系统代码。
这促使Unity开发团队采取下一步措施来淘汰旧粒子系统。因此,在Unity 2018.1中将删除它的Script Bindings。
自Unity 5.4以来,旧粒子系统已被完全弃用,Unity官方的统计显示几乎不存在使用情况。Unity团队的目标是到Unity 2018.3完全删除Legacy Particle System。
如果这会影响到你,你有一些选择:
- 将遗留粒子系统迁移到Shuriken
- 使用自动更新脚本来尝试自动转换(https://forum.unity.com/threads/release-legacy-particle-system-updater.510879/)
- 通过(https://forum.unity.com/threads/legacy-particle-system-deprecation.420351/)寻求帮助。
加权切线(动画曲线)
动画团队已加入对加权切线的支持,以支持Unity中的所有曲线编辑。这意味着你也可以在粒子系统中使用这个新功能!