Ogre参考手册(六)3.3 粒子

3.3 粒子Particle

粒子系统脚本可以作为模板,在运行时创建多个粒子系统

粒子系统脚本在初始化时加载,默认为所有公共资源位置(Root::addResourceLocation)下的’.particle’文件。你可以通过ParticleSystemManager::getSingleton().parseAllSources方法加载自定义扩展名的文件类型,或者通过ParticleSystemManager::getSingleton().parseScript解析单个脚本文件

示例:

particle_system Examples/PurpleFountain

{

    material Examples/Flare2

    quota 10000

    billboard_type oriented_self

 

    emitter Point

    {

        emission_rate 75

    }

 

    affector LinearForce

    {

        force_vector 0 -100 0

    }

 

    affector ColourFader

    {

        red -0.25

    }

}

粒子需要全局唯一的名字,如:Examples/PurpleFountain。粒子系统支持一些公共属性和粒子发射器(创建粒子)、影响器(修改粒子)。发射器和影响器的的参数依赖于各发射器和影响器的类型。

3.3.1 属性

quota

粒子系统最多包含粒子数量, 例:quota 10000

 

material

材质,例:material Example/Flare

 

paticle_width / paticle_height

世界坐标系中的粒子宽\高。例:paticle_width 100。

注:当billboard_type为point或perpendicular_self时该属性为固定的,billboard_type为oriented_comon\oriented_set\perpendicular_common时将根据方向矢量(dirction vector)的长度缩放

cull_each

是否独立裁剪。默认情况下粒子系统根据包围盒整体裁剪,某些情况下可以设为true以优化性能。

例:cull_each true

renderer

渲染器。粒子系统通过ParticleRenderer类渲染,类可以通过管理类注册。Ogre提供默认的billboard基础的渲染器。可以通过插件注册其它渲染器,每个指定唯一的名字。

示例:renderer billboard

sorted

默认情况粒子并不排序,可通过设置为true实现更好的渲染效果

local_space

默认情况下粒子发射到世界空间,可通过设置为true修改为本地空间

billboard_type

billboard渲染器属性,默认值point,用法:

billboard_type point|oriented_common|oriented_self|perpendicular_common| perpendicular_self

说明:

point 朝向相机,采用相机的x, y轴(up矢量),适合含糊的球面,如闪光(light flare)

oriented_common 采用common_direction作为公共y轴,并绕该轴旋转以朝向相机。适合暴风雨、星空

oriented_self 采用独自的direction vector作为y轴,适合laser fire、烟火等条带状有着各自朝向的粒子

perpendicular_common采用common_direction作为公共z轴,y轴通过z与common_up_vector计算。这种类型粒子不旋转,因此需要设置双面纹理,避免背面裁剪。适合光环,比perpendicular_self稍快

perpendicular_self 各自独立的方向矢量作为z轴,适合堆积的环,有各自的方向(rings stack)

common_direction  <x y z>

设置oriented_commo、perpendicular_common类型公告牌采用的公共方向矢量(common direction)

common_up_vector  <x y z>

设置perpendicular_common\perpendicular_self类型公告牌采用的公共上矢量(common up vector)

billboard_origin  <top/center/bottom_left/(center)/right>

粒子原点类型,默认为中心

例:billboard_orign top_left ,默认: billboard_orign center

billboard_rotation_type  <vertex/texcoord>

旋转类型,公告牌粒子默认采用纹理旋转作为粒子旋转实现。但这样旋转时原来角部纹理会丢失,在重叠采样(wrap address)或者采用子纹理时角部也会出现不需要纹理。可通过设置为旋转顶点(vertex)解决,但效率稍低

用法: billboard_rotaion_type vertex/texcoord

point_rendering  <true/false>

公告牌默认采用四个顶点的四边形渲染,可设置true采用硬件点渲染(速度并不明显提高),此时受硬件渲染状态控制,并有以下限制:

l  只支持point 类型公告牌

l  粒子显示受所采用材质渲染通道控制:(point_size, point_size_attenuation, point_sprites)

l  受图形卡显示,最大点大小为64-256像素

例:point_rendering true

同时材质通道需开启点精灵渲染:

             point_sprites on

                   point_size_attenuation on 0 10 0

accurate_facing  on/off

默认关闭off,即采用相机朝向的反方向。开启后on将单个计算各公告牌指向相机的方向

iteration_interval <float>

粒子系统默认按帧率更新,可以设置固定更新时间(秒),0表示按帧率更新

示例:iteration_interval 0.01

nonvisible_update_timeout <float>

粒子系统在不可见的情况下默认一直更新以便保持一致,可设置超时时间(秒)以便不可见一段时间后停止更新。默认值0,表示一直更新。 示例:nonvisible_update_timeout 5

emit_emitter_quota <int>

被发射的发射器限额,发射器也可以被发射,这个参数控制被发射器发射的发射器个数

emitter

指定发射器,用法:emitter <type> { … }

例:

emitter Box { … }

3.3.2 发射器emitter

发射器为emitter内嵌指令:emitter <type> { … }, type为发射器类型,区分大小写。Ogre当前支持’Point点、Box盒、Cylinder圆柱、Ellipsod椭球、HollowEllipsoid中空椭球、Ring圆环等几种类型发射器,可以通过插件注册新的发射器类型

3.3.3 发射器公共属性

各种发射器含有以下公共属性,除此之外各发射器还含有自身特殊属性:

name  <name>

发射器名称,当被用于其它发射器时使用

position  <x y z>

发射器相对粒子系统所属场景节点位置

direction  <x y z>

粒子发射方向

angle <degrees>

最大偏离方向角度,180表示全方向发射, 默认 0严格按照发射方向发射粒子

emission_rate  <num>

每秒发射粒子个数

velocity <float>

发射速度,每秒世界坐标单位

velocity_min & velocity_max

发射速度范围,避免相同的发射速度,需要成对设置覆盖velocity

colour

颜色, 用法:colour <r> <g> <b> [<a>]

colour_range_start & colour_range_end

颜色范围

time_to_live <float>

粒子存活时间

time_to_live_min & time_to_live_max

粒子存活时间范围,成对设置

duration <float>

发射器持续活动时间,默认0表示无限长

duration_min & duration_max

发射器持续活动时间范围

repeat_delay <float>

发射器停止后(因duration过期)重新启动时间

repeat_delay_min & repeat_delay_max

重启时间范围

emit_emitter <name>

发射发射器:当前发射的粒子结束时在该位置发射指定名称的发射器,类似于烟花

示例:

particle_system Examples/Fireworks

{

    material Examples/Flare

    quota                      1000

    emit_emitter_quota         10   //最多发射10个发射器:mainEmitter粒子

    // 发射发射器的发射器

    {

        emit_emitter            explosion //发射explosion发射器

        emission_rate           1000

        time_to_live            3

    }

    // 被发射的发射器

    emitter Point

    {

        name                    explosion

        emission_rate           1000

        time_to_live            2

        duration                0.1

        repeat_delay_min        2

        repeat_delay_max        3

}

}

3.3.4 Ogre粒子发射器

Ogre实现了以下粒子发射器。可以通过插件实现新的粒子发射器,可参考:Plugin_ParticleFX项目

Point 点发射器

从单个点发射粒子,没有自己特定的属性

示例: emitter Point { }

Box 箱/盒发射器

从三维大小的盒子任意位置发射粒子,额外属性:

width <units> 宽,默认 100,

height <units> 高,默认100

depth <unit> 高/深, 默认 100

Cylingder 圆柱发射器

与Box相同,含width\height\depth三个自有属性

Ellipsoid 椭球发射器

与Box相同,含width\height\depth三个自有属性

HollowEllipsoid 椭球发射器

与Ellipsoid相同,中空部分不发射粒子,含width\height\depth三个自有属性

同时包含三个属性指明中空的椭球大小:inner_width\ inner_height\ inner_depth

Ring 圆环发射器

与HollowEllipsoid类似相同,区别在于为二维,除width\height外

另包括:inner_width\ inner_height 两个属性

3.3.5 影响器affector

影响器为affector内嵌指令:affector <type> { … }, type为影响器类型,区分大小写。Ogre当前支持LinearForce和ColourFader两种类型影响器,可以通过插件注册新的影响器类型。

影响器没有公共属性

3.3.6 Ogre粒子影响器

Ogre实现了以下影响器。可以通过插件实现新的粒子影响器,可参考:Plugin_ParticleFX项目

LinearForce 线性力

对所有粒子应用线性力矢量,改变粒子的运动速度和方向,用于模仿重力、风等

属性:

force_vector      <x> <y> <z>

力矢量,x y z 大小代表力的大小

force_application <add|average>

力叠加方式:

 add 累加,每秒增加力矢量大小

 average 平均(每次刷新时与当前速度取平均,因为刷新率很高,原始速度按指数递减,粒子瞬间到达力矢量速度,实际上没有用处)

ColourFader 颜色

改变粒子的颜色,包含以下四个属性:

red <float> 每秒改变红色成份

green/blue/alpha < float >

ColourFader2 两阶段颜色变化

改变粒子的颜色,包含以下属性:

red1/green1/blue1/alpha1 第一阶段颜色每秒变化

state_change<float >第二阶段时长(粒子存活结束时间前的state_change时间段为第二阶段,很糟的设计)

red2/green2/blue2/alpha2 第二阶段颜色变化

Scaler  缩放

rate<float>每秒缩放倍数

Rotator 旋转

默认旋转纹理方式旋转粒子

rotation_speed_range_start/end <degress_per_sercond>

每秒旋转度数范围

rotation_range_start/end <degrees>

初始旋转角度数范围

ColourInterpolator 颜色差值

任意指定阶段时间相对长度和颜色值, 最多指定6个阶段(注:各阶段一半的时间用于前一阶段渐变):

time0/1/2/3/4/5 <rate>     

colour0/1/2/3/4/5 <r> <g> <b> [<a>]

例:time0 0.5

      colour0 1 0 0

      time1 0.5

      colour1 0 1 0

ColourImage 一维图片渐变

根据一维的图片渐变粒子颜色,与ColourInterpolator类似:

image <image_name>, 例: image smokecolors.png

DeflectorPlane 反弹平面

粒子碰撞后反弹:

plane_point <x y z>      平面上一点

plane_normal <x y z> 平面法线

bounce <rate> 反射速度比例,0-1.0,默认1

DirectionRandomiser 随机方向

应用随机量影响粒子运动,可以模拟雪花、树叶

randomness 随机量大小

scope    影响粒子比例(0-1.0),默认1.0即全部

keep_velocity 是否保持速度不变,默认false

原文地址:https://www.cnblogs.com/wiki3d/p/4658247.html