c# 粒子系统_#unitytips:粒子系统性能–剔除

c# 粒子系统

In a previous post, I wrote about the performance considerations when using the various curve modes available in the particle system. This time, we will take a look into particle system culling.

在上一篇 文章中 ,我写了关于使用粒子系统中可用的各种曲线模式时的性能注意事项。 这次,我们将研究粒子系统的剔除。

TL; DR (TL;DR)

    程序模式 (Procedural Mode)

    Internally, each particle system has 2 modes of operating, procedural and non-procedural.

    在内部,每个粒子系统都有2种操作模式,即过程性和非过程性。

    In procedural mode it is possible to know the state of a particle system for any point in time (past and future) whereas a non-procedural system is unpredictable. This means that it is possible to quickly fast forward (and rewind) a procedural system to any point in time.

    在过程模式下,可以在任何时间点(过去和将来)知道粒子系统的状态,而非过程系统是不可预测的。 这意味着可以将流程系统快速快进(或倒带)到任何时间点。

    When a system goes out of the view of any camera, it becomes culled. When this occurs, a procedural system will halt updating.  It will efficiently fast forward to the new point in time when the system becomes visible again. A non-procedural system cannot do this, it must continue updating the system even when invisible due to its unpredictable nature.

    当系统超出任何摄像机的视野时,它将被淘汰。 发生这种情况时,过程系统将停止更新。 当系统再次变得可见时,它将有效地前进到新的时间点。 非过程系统无法做到这一点,即使由于不可预测的性质而看不见,它也必须继续更新系统。

    For example, the following system is predictable.It’s in local space, so the movement of the particle system’s transform does not matter; the particles are not influenced by any external forces such as collisions, triggers and wind. This means we are able to calculate the total bounds that particles will exist within during the lifetime of the system (yellow box) and can safely cull the system when not visible.

    例如,以下系统是可预测的。它在局部空间中,因此粒子系统变换的运动无关紧要; 粒子不受任何外力(例如碰撞,触发和风)的影响。 这意味着我们能够计算出在系统生命周期(黄色框)内粒子将存在的总边界,并且可以在不可见的情况下安全剔除该系统。

    By changing the particle system to world space, it becomes unpredictable. When a particle is spawned it will need to sample the position of the transform at that moment. The position of the transform is unpredictable, its history and future are unknown.,Therefore, the system must continue to update itself even when invisible in order for the particles to be in the correct positions when it becomes visible again.

    通过将粒子系统更改为世界空间,它将变得不可预测。 生成粒子时,需要在该时刻采样转换的位置。 变换的位置是不可预测的,它的历史和未来是未知的。因此,即使在不可见的情况下,系统也必须继续更新自身,以使粒子在再次可见时处于正确的位置。

    By changing the system to world space it becomes unpredictable. There is no way for the system to know the location of the particles without continuing to update itself whilst invisible.

    通过将系统更改为世界空间,它将变得不可预测。 系统无法在不可见的情况下继续更新自身而无法知道粒子的位置。

    什么破坏了程序模式,我怎么知道我已经破坏了它? (What breaks procedural mode, how do I know I have broken it?)

    When a particle system doesn’t support procedural mode, a small icon is displayed in the Inspector. Mousing over this icon will provide a tooltip that lists the reasons why the system no longer supports procedural mode and cannot be culled. It’s also possible to see that non-procedural mode is in use by looking at the bounding bound of the particle system, a continually changing bounds that only encapsulate the particles are a sign that procedural mode isn’t being used.

    当粒子系统不支持程序模式时,将在检查器中显示一个小图标。 将鼠标悬停在此图标上将提供一个工具提示,其中列出了系统不再支持程序模式且无法删除的原因。 通过查看粒子系统的边界,还可以看到正在使用非过程模式,这种不断变化的边界仅封装了粒子,这表明未使用过程模式。

    The following are examples of conditions that break support for procedural mode.

    以下是破坏对过程模式的支持的条件示例。

    Module Property What breaks it?
    Simulation Space World space
    Main Gravity modifier Using curves
    Emission Rate over distance Any non zero value
    External forces enabled true
    Clamp velocity enabled true
    Rotation by speed enabled true
    Collision enabled true
    Trigger enabled true
    Sub Emitters enabled true
    Noise enabled true
    Trails enabled true
    Rotation by lifetime Angular Velocity if using a curve and the curve does not support procedural*
    Velocity over lifetime X, Y, Z If using a curve and the curve does not support procedural*
    Force over lifetime X, Y, Z If using a curve and the curve does not support procedural*
    Force over lifetime Randomise enabled
    模组 属性 什么破了?
    仿真空间 世界空间
    主要 重力修正 使用曲线
    排放 远距离速率 任何非零值
    外力 已启用 真正
    夹紧速度 已启用 真正
    转速旋转 已启用 真正
    碰撞 已启用 真正
    触发 已启用 真正
    子发射器 已启用 真正
    噪声 已启用 真正
    步道 已启用 真正
    终生旋转 角速度 如果使用曲线并且该曲线不支持程序*
    整个生命周期的速度 X,Y,Z 如果使用曲线而该曲线不支持程序*
    终生强制 X,Y,Z 如果使用曲线而该曲线不支持程序*
    终生强制 随机化 已启用

    *A curve can not support procedural mode if it has more than 8 segments. A segment is the number of keys plus an additional key if the curve does not start at 0.0 and another if does not end at 1.0.

    *如果曲线有8个以上的段,则它不支持程序模式。 一个段是键的数量加上一个附加键(如果曲线不是从0.0开始,则为另一个,如果不是以1.0结尾)。

    播放器中的程序模式无效 (Invalidating procedural mode in the player)

    Procedural mode is based on knowing exactly how the system will behave at a specified point in time with no external influences. If a value is changed via script or in the editor during play mode then those assumptions can’t be made and procedural mode is invalidated. This means that even though a system is using all procedurally safe settings, it’s no longer possible to use procedural mode and the system will not be culled anymore.

    程序模式基于准确了解系统在指定时间点的行为而不受外部影响的基础。 如果在播放模式期间通过脚本或在编辑器中更改了值,则无法做出这些假设,并且过程模式无效。 这意味着,即使系统正在使用所有过程安全设置,也将无法再使用过程模式,并且系统也将不再被淘汰。

    Changing a value or Emitting via script will invalidate procedural mode, which you can notice by examining the bounds of the system in the scene. If the bounds are continuously changing then the procedural mode is no longer being used.

    更改值或通过脚本发射将使过程模式无效,您可以通过检查场景中系统的边界来注意到这一点。 如果范围在不断变化,那么将不再使用过程模式。

    Sometimes this can be avoided by using the particle system’s built in features to change properties, instead of using a script.

    有时可以通过使用粒子系统的内置功能来更改属性,而不是使用脚本来避免这种情况。

    Calling Play on a system that has been stopped will reset the system and re-validate procedural mode.

    在已停止的系统上调用Play将重置系统并重新验证程序模式。

    性能实例 (Performance example)

    The performance difference between a procedural and a non-procedural system can be significant. This difference is most noticeable when a system is offscreen. In a scene containing 120 default systems, each simulating 1000 particles, the following performance difference is shown between local space (procedural) and world space (non-procedural). The left area shows the performance when not culled, and the right shows when culled.

    程序系统和非程序系统之间的性能差异可能很大。 当系统处于屏幕外时,这种差异最明显。 在包含120个默认系统(每个系统模拟1000个粒子)的场景中,在局部空间(过程性)和世界空间(非过程性)之间显示了以下性能差异。 左侧区域显示未剔除时的性能,右侧区域显示在剔除时的性能。

    The blue area represents the work performed by the particle system.

    蓝色区域表示粒子系统执行的功。

    • 0
      点赞
    • 1
      收藏
      觉得还不错? 一键收藏
    • 0
      评论
    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

    当前余额3.43前往充值 >
    需支付:10.00
    成就一亿技术人!
    领取后你会自动成为博主和红包主的粉丝 规则
    hope_wisdom
    发出的红包
    实付
    使用余额支付
    点击重新获取
    扫码支付
    钱包余额 0

    抵扣说明:

    1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
    2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

    余额充值