Unigine贴花类及其三种类型贴花Unigine::DecalMesh、Unigine::DecalOrtho和Unigine::DecalProj

关于贴花官方是这个解释的:

decal is a material projection on the surface. In fact, decals perform changing material parameters of the surface on which these decals are projected. It allows you to add a lot of additional details at basically no performance cost. Decals are rendered in buffers (they change buffer textures) and work only with deferred objects. A decal is a perfect object for bullet holes, bloodstains, ashes, etc.

Decals support two materials only: decal_base and decal_terrain_hole_base. While the behavior of decals with the first material applied is similar to detail textures of the material, the second type of decals is intended for creating Decal-Based Terrain Holes.

By using Water Decal option, decals can be displayed on the top of the water surface. This option can be used to create different effects on the water surface: floating branches, leaves, etc.

意思是:

贴花是表面上的一种材质投影。事实上,贴花可以改变贴花表面的材质参数。它允许您添加许多额外的细节,基本上不需要任何性能代价。贴花是在缓冲区中渲染的(它们改变缓冲区纹理),并且只对延迟对象有效。贴花是用来模拟弹孔、血迹、灰烬等的完美对象。

贴花只支持两种材质:decal_base和decal_terrain_hole_base。使用第一种材质的贴花的行为类似于材质的细节纹理,而第二种贴花的目的是创建基于贴花的地形洞。

通过使用水贴花选项,贴花可以显示在水面的顶部。这个选项可以用于在水面上创建不同的效果:浮动的树枝、树叶等。

我的理解一句话:贴花的实质是将任意纹理投影贴到任意表面上。

有三种类型贴花,分别是网格贴花、透视投影贴花和正交投影贴花。分别对应Unigine中Unigine::DecalMesh、Unigine::DecalProj和Unigine::DecalOrtho类。

 

Projected Decal

透视投影贴花,顾名思义即符合透视投影规律,如同一个摄像机:

投影金字塔位置相对于投影面位置的变化,会根据透视的规律改变贴花的大小。

当人眼看到一个场景时,远处的物体看起来比近处的物体要小——这就是所谓的透视。

创建:

static DecalProjPtr create ( float radius, float fov, float aspect, const char * name )

radius:半径-沿Z轴投影金字塔的高度,标准单位长度。实质可以理解为投影的高度,即金字塔(也可理解为摄像机)锥顶到投影面垂直距离。只有这个投影面和待投影面相交时,才会被投影。当然如果交到多个面,都会被投影,离椎体越远投影矩形越大,反之越小。

fov :金字塔视锥体fov角,即垂直方向上夹角,单位为度

aspect:投影面长宽比

name:材质名,必须继承自decal_base或decal_terrain_hole_base

代码创建一个透视投影贴花:

m_ptrDecalProj = Unigine::DecalProj::create(40, 30, 19.0/6.0, "decals_decal_project");

//要从这个材质继承一下,会生成一个新的子材质实例并将之前的材质替换掉,否则材质会被共用
MaterialPtr mat = m_ptrDecalProj->getMaterialInherit();

关于材质和纹理请参考上一篇博客Unigine纹理材质Unigine::Material、Unigine::Texture简介和使用注意事项

 

Orthographic Decal

正交投影贴花,顾名思义为正射投影,不像透视投影投影矩形会随离投影点的远近变化而变化,他的投影面矩形是固定的长和宽。

创建接口:

static DecalOrthoPtr create ( float radius, float width, float height, const char * material )

radius:同样的可以理解为这个投影立方体的高度,只有这个矩形框的底部和待投影面相交才会被投影,如果有多个面相交,相交到的面都会被投影。(我个人喜好理解为投影立方体高)
width:投影面矩形框的宽(我个人喜好理解为投影立方体宽)
height:投影面矩形框的高(我个人喜好理解为投影立方体长)
material:材质名,必须继承自decal_base或decal_terrain_hole_base

 代码创建一个正交投影贴花:

m_ptrDecalOrtro = Unigine::DecalOrtho::create(40, 800, 600, "decals_decal_project");

Unigine::DecalMesh 

网格贴花就是会把纹理投影到指定网格上,不过她只会投影到该网格第一个surface(面)上,这种贴花应用不多,不做过多介绍

 

本文用到的材质定义如下:

<material name="decals_decal_project" parent="decal_base">
		<state name="angle_fade">0</state>
		<texture name="albedo">empty.png</texture>
</material>

贴花默认是只会投到前面相交的面,不会投到背面的面。

 关键是材质中angle_fade这个状态参数,设为0为不做控制,正面背面都会被投

如果设为1就只会偷正面相交面:


 

代码这样写:

	MaterialPtr mat = m_ptrDecalProj->getMaterialInherit();
	mat->setState("angle_fade", 1);

材质文件中这样写:

<material name="decals_decal_project" parent="decal_base">
    <state name="angle_fade">0</state>
    <state name="material_ssao">0</state>
    <parameter name="translucent">1.0</parameter>
    <options cast_world_shadow="0"/>
	<texture name="albedo">empty.png</texture>
</material>

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值