unity怎么控制mesh randerer的unity ui淡入淡出

Skinned Mesh Renderer vs Mesh Renderer - Unity Answers
Navigation
Unity account
You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio.
Skinned Mesh Renderer vs Mesh Renderer
I have a project in Unity Pro iOS Pro. I plan to have a large number of characters in a scene (at least 100). Each character is around 150 poly. The character is rigged and uses a SkinnedMeshRenderer.
For performance reasons, I would like to use non-rigged characters and use a puppet setup instead.
Will I notice anything considerable?
Best Answer
It depends.
SkinnedMeshRenderer is more heavy on CPU (skinning). Doing separate MeshRenderers for each part is more heavy on GPU (drawcall count).
It's a bit hard to say. At least you have to say what is your target hardware. But simple test would tell you more than any theoretical assumptions. Maybe you're game will be bound by fill-rate instead.
Considering your target of 100+ meshes on screen (wich is going to be a hard task considering iOS hardware), I would go with the non-rigged characters, using a Mesh Renderer instead of the Skinned Mesh Renderer, as you would be then able to batch them and save some Draw Calls and FillRate.
Still a heavy task to be accomplished.
I have an asset in the Asset Store && which can combine skinned meshes at and MeshRenderer meshes at the same time into a single combined skinned mesh. You can specify how many meshes are allowed at each level of detail. For example imagine a mob of 200 characters with three levels of detail:
LOD0 = 4000 vert skinned mesh, LOD1 = 800 vert skinned mesh, LOD2 = 100 vert MeshRender mesh
You can specify a maximium number of meshes at each level of detail:
5 at LOD0, 10 at LOD1, unlimited at LOD2,
The LOD manager keeps the mob adjusted so that the characters closest to the camera are always the highest poly version. The selected meshes are baked into combined meshes so would only have a few drawcalls. See a video of it here (skinned mesh demo is 6:30 into video):
Hint: You can notify a user about this post by typing @username
Attachments: Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
13 People are following this question.Unity3D Mesh小课堂(四)MeshRenderer的material和sharedMaterial - 博客频道 - CSDN.NET
凯奥斯的注释
新作《注释的108种编写技巧》正在创作中……(误)
分类:Unity3D Mesh
(网格渲染器)从(网格过滤器)获得几何形状,并根据进行渲染,而渲染所需要的贴图信息就来自与。
而MeshRenderer的Material类型的变量有两个:material和sharedMaterial。二者之间有什么联系呢?我们做个试验。
首先创建两个Cube,CubeA和CubeB,并新建一个Material材质球,把两个Cube里MeshRenderer的第一个Material改成这个新建的材质。然后新建一个代码文件,把代码加到CubeA上,在start方法里面加入以下代码:
MeshRenderer mr = GetComponent&MeshRenderer& ();
mr.material.color = Color.
点击运行我们看到只有CubeA颜色变了。
MeshRenderer mr = GetComponent&MeshRenderer& ();
mr.sharedMaterial.color = Color.
就会发现,CubeA和CubeB的颜色都变了,并且我们新建的Material(材质球)的颜色也变了。
由此我们可以知道:
sharedMaterial是公用的Material,所有用到这个材质的MeshRendered都会引用这个Material。改变sharedMaterial的属性也会改变mat文件。
material是独立的Material,改变material的属性不会影响到其他对象,也不会影响mat文件。
但是,看问题不应该浮于表面。
我们继续做实验,删掉之前的代码加入下面这段:
MeshRenderer mr = GetComponent&MeshRenderer& ();
Material smat = mr.sharedM
Material mat = mr.
Debug.Log (smat == mr.sharedMaterial);
Debug.Log (mat == mr.sharedMaterial);
Debug.Log (mat == mr.material);
打印结果分别为False,True,True。
我们知道sharedMaterial和material并不是变量,而是属性(property),属性有set和get方法,当给属性赋值时会隐式的调用set方法,当获取属性值得时候会隐式的调用get方法。在这里我们把material的值变量假设为_material,而sharedMaterial的值变量假设为_sharedMaterial。
Material _
Material _sharedM
由此,我们就可以得出结论:
material的get方法里面,会判断_material跟_sharedMaterial是否相同,如果相同,返回_material,如果不同,会新建一个_sharedMaterial的拷贝,并赋值给_material和_sharedMaterial。大概是下面这样的逻辑:
public Material material {
if (_sharedMaterial == _material) {
_material = new Material (_sharedMaterial);
_sharedMaterial = _
我们继续做实验,重新写入下段代码:
MeshRenderer mr = GetComponent&MeshRenderer& ();
Material newMat = new Material (Shader.Find (&Standard&));
mr.material = newM
Debug.Log (newMat == mr.sharedMaterial);
Debug.Log (newMat == mr.material);
Material tmpMat = mr.
Debug.Log (newMat == tmpMat);
Debug.Log (tmpMat == mr.sharedMaterial);
打印结果分别为True,False,False,True。
由此,我们可以得出结论:
material的set方法里面会把传入的值赋给_sharedMaterial,并且会再新建一个_sharedMaterial的拷贝,并赋值给_material。(因为值不同,所以get的时候又会新建一个Material。)
public Material material {
if (_sharedMaterial == _material) {
_material = new Material (_sharedMaterial);
_sharedMaterial =
_material = new Material (_sharedMaterial);
}至于SharedMaterial的get和set方法,似乎并不会修改变量的值,只是单纯的取值赋值而已。
最后总结一下二者的使用时机:
当只修改材质的参数的时候,使用material属性,确保其他对象不会受影响。
当需要修改材质的时候,直接赋值给sharedMaterial,否则赋值给material会产生内存泄露。
ecidevilin
排名:第16978名
(23)(11)(27)(18)(1)(2)(19)(5)(11)(1)(1)(3)SkinnedMeshRenderer 蒙皮网格渲染器_unity3d游戏脚本制作教程-游戏蛮牛出品
Unity 脚本手册
SkinnedMeshRenderer 蒙皮网格渲染器
Inherits from
The Skinned Mesh filter
蒙皮网格过滤器。
Variables变量
The bones used to skin the mesh.
用于蒙皮网格的骨骼列表。
The maximum number of bones affecting a single vertex
影响单个点的最大骨骼数量。
The mesh used for skinning
用于蒙皮的网格
If enabled, geometry normals will be updated with the bone animation.
如果开启,几何体法线将随着骨骼动画更新。
If enabled, the Skinned Mesh will be updated when offscreen. If disabled, this also disables updating animations.
如果启用,蒙皮网格将在离开屏幕的时候更新。如果禁用,也将禁用动画更新。
AABB of this Skinned Mesh in its local space.
在本地坐标空间这个蒙皮网格的AABB。
Inherited members继承成员
Inherited Variables继承变量
Has this renderer been statically batched with any other renderers?
这个渲染器有被任何其他渲染器静态批处理?
Matrix that transforms a point from world space into local space (Read Only).
矩阵(Matrix)世界空间坐标的点转换成自身空间坐标的点(只读)。
Matrix that transforms a point from local space into world space (Read Only).
矩阵(Matrix)自身空间坐标的点转换成世界空间坐标的点(只读)。
Makes the rendered 3D object visible if enabled.
如果启用,使被渲染的物体可见。这是一个物体隐藏显示的开关。
Does this object cast shadows?
这个物体是否投射阴影?
Does this object receive shadows?
这个物体是否接收阴影?
The material of this object.
物体的材质。
The shared material of this object.
物体的共享材质。
All the shared materials of this object.
物体的全部共享材质。
All the materials of this object.
物体的全部材质。
The bounding volume of the renderer (Read Only).
渲染器的边界框(只读)。
The index of the lightmap applied to this renderer.
应用到该渲染器的光照贴图的索引。
The tiling & offset used for lightmap.
用于光照贴图的平铺和偏移值。
Is this renderer visible in any camera? (Read Only)
这个渲染器在任何摄像机可见(只读)?
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(Read Only). (null if there is none attached)
附加到(游戏物体)(只读)(如无附加则为空)。
attached to this
(Read Only). (null if there is none attached)
附加到(游戏物体)(只读)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
The game object this component is attached to. A component is always attached to a game object.
组件附加的游戏物体。一个组件总是被附加到一个游戏物体。
The tag of this game object.
游戏物体的标签。
The name of the object. //物体的名字
Should the object be hidden, saved with the scene or modifiable by the user?
物体是否被隐藏、保存在场景中或被用户修改?
Inherited Functions继承函数
Returns the component of Type type if the game object has one attached, null if it doesn't.
如果游戏物体有一个附加,则返回Type类型的组件,如果没有则为null。shader实例(二十五)unity创建网格mesh
上一节学习天空盒的原理,就想在unity上层实现跟unity自带一样的天空盒,发现有个技术点不太了解,六个pass的shader怎么被代码识别,并显示在cube的六个面上呢?可能底层是将六张图合成然后再通过坐标去取uv信息,也可能是gpu通过顺序依次给cube的六个面进行渲染。不管什么方式都得去绘制cube对吧,所以就找到绘制cube的api进行学习。
这是unity圣典的API :
下面用一个绘制面片的例子记录实现过程,以便以后能快速的查阅,先看效果:
红色框的地方就是mesh,但是这个mesh并不是美术给的,也不是来自unity自带的,而是通过代码创建的。
一个面4个顶点,2个三角形,6个链接三角形的参数(3个参数为一个三角形),上图是正方向,新创建的shader需加上cull
off才可以看到此面。
代码和过程如下:
using&UnityE
using&System.C
public&class&XXMesh&:&MonoBehaviour&
&&&&public&Vector3[]&m_
&&&&public&Vector2[]&m_
&&&&public&Color[]&m_
&&&&public&Vector3[]&m_
&&&&public&int[]&m_
&&&&private&Mesh&
&&&&void&Start()
&&&&&&&&mesh&=&new&Mesh();
&&&&&&&&m_vertices&=&new&Vector3[4]
&&&&&&&&&&&&new&Vector3(0,&0,&0),&//&左下
&&&&&&&&&&&&new&Vector3(1,&0,&0),&//&右下
&&&&&&&&&&&&new&Vector3(0,&1,&0),&//&左上
&&&&&&&&&&&&new&Vector3(1,&1,&0),&//&右上
&&&&&&&&};
&&&&&&&&m_uv&=&new&Vector2[4]&//&顶点映射的uv位置
&&&&&&&&&&&&new&Vector3(0,&0),&//&顶点0的纹理坐标
&&&&&&&&&&&&new&Vector3(1,&0),
&&&&&&&&&&&&new&Vector3(0,&1),
&&&&&&&&&&&&new&Vector3(1,&1),
&&&&&&&&};
&&&&&&&&m_triangles&=&new&int[6]&//&两个三角面的连接
&&&&&&&&&&&&0,1,2,//&通过顶点012连接形成的三角面
&&&&&&&&&&&&1,3,2,//&通过顶点132连接形成的三角面
&&&&&&&&};
&&&&void&Update&()&
&&&&&&&//&清除mesh信息,下面可以做相应的mesh动画
&&&&&&&&mesh.Clear();&&
&&&&&&&&mesh.vertices&=&m_
&&&&&&&&mesh.uv&=&m_
&&&&&&&&mesh.colors&=&m_
&&&&&&&&mesh.normals&=&m_
&&&&&&&&mesh.triangles&=&m_
&&&&&&&&mesh.RecalculateNormals();
&&&&&&&&GetComponent().mesh&=&
在这里没有给颜色和法线赋值,这个看需求都可以进行操作。学shader有一段时间了,只是现在才知道可以动态创建mesh,简直弱爆了,哈哈.......知道了就好,以后还得多学习争取更好的运用吧。
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

我要回帖

更多关于 unity3d 模型淡入淡出 的文章

 

随机推荐