{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/unity-overdraw/",
  "atlas": "https://www.pystone.net/?node=unity-overdraw#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/unity-overdraw.md",
  "context": "https://www.pystone.net/notes/unity-overdraw.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:unity-overdraw",
  "slug": "unity-overdraw",
  "title": "Overdraw",
  "type": "note",
  "visibility": "public",
  "idStability": "rename-stable",
  "author": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "publisher": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "aliases": [],
  "summary": "Overdraw",
  "contentRole": "unspecified",
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "unspecified",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "contentHash": "034104da01d2b49c178ed76dedff491a7ab5468c38776af759ade85e9cc9945e",
  "assets": [],
  "headings": [
    {
      "depth": 1,
      "text": "Overdraw",
      "anchor": "overdraw",
      "citation": "https://www.pystone.net/notes/unity-overdraw/#overdraw"
    },
    {
      "depth": 2,
      "text": "是什么",
      "anchor": "是什么",
      "citation": "https://www.pystone.net/notes/unity-overdraw/#%E6%98%AF%E4%BB%80%E4%B9%88"
    },
    {
      "depth": 2,
      "text": "优化点",
      "anchor": "优化点",
      "citation": "https://www.pystone.net/notes/unity-overdraw/#%E4%BC%98%E5%8C%96%E7%82%B9"
    },
    {
      "depth": 3,
      "text": "针对性优化",
      "anchor": "针对性优化",
      "citation": "https://www.pystone.net/notes/unity-overdraw/#%E9%92%88%E5%AF%B9%E6%80%A7%E4%BC%98%E5%8C%96"
    },
    {
      "depth": 4,
      "text": "文字",
      "anchor": "文字",
      "citation": "https://www.pystone.net/notes/unity-overdraw/#%E6%96%87%E5%AD%97"
    },
    {
      "depth": 4,
      "text": "适配IphoneX",
      "anchor": "适配iphonex",
      "citation": "https://www.pystone.net/notes/unity-overdraw/#%E9%80%82%E9%85%8Diphonex"
    },
    {
      "depth": 4,
      "text": "背景人物mesh",
      "anchor": "背景人物mesh",
      "citation": "https://www.pystone.net/notes/unity-overdraw/#%E8%83%8C%E6%99%AF%E4%BA%BA%E7%89%A9mesh"
    },
    {
      "depth": 4,
      "text": "Mask组件",
      "anchor": "mask组件",
      "citation": "https://www.pystone.net/notes/unity-overdraw/#mask%E7%BB%84%E4%BB%B6"
    },
    {
      "depth": 4,
      "text": "Image的slide属性",
      "anchor": "image的slide属性",
      "citation": "https://www.pystone.net/notes/unity-overdraw/#image%E7%9A%84slide%E5%B1%9E%E6%80%A7"
    }
  ],
  "claims": [],
  "outgoing": [],
  "incoming": [
    {
      "id": "note:game-graphics-and-runtime",
      "title": "游戏图形与运行时",
      "url": "https://www.pystone.net/notes/game-graphics-and-runtime/",
      "atlas": "https://www.pystone.net/?node=game-graphics-and-runtime#knowledge-atlas",
      "label": "游戏图形与运行时",
      "origin": "explicit",
      "humanReviewed": true,
      "context": "Unity中的“Overdraw”导航项",
      "citation": "https://www.pystone.net/notes/game-graphics-and-runtime/#unity"
    }
  ],
  "contentMarkdown": "# Overdraw\n\n> 创建时间：2020/6/15 17:30\n\n## 是什么\n\noverdraw表示一个像素的重新绘制次数，在像素处理中，overdraw是最常见的性能瓶颈之一。\nScene视图的RenderMode->Overdraw。越亮的区域表示overdraw的程度越高，也就越消耗GPU。\n\n> 当然这里的视图只是提供了查看物体遮挡的层数关系，并不是真正的最终屏幕绘制的overdraw。也就是说，可以理解为它显示的是如果没有使用任何深度检验时的overdraw。这种视图是通过把所有对象都渲染成一个透明的轮廓，通过查看透明颜色的累计程度，来判断物体的遮挡。\n\n## 优化点\n\n  * 控制绘制顺序:PC上资源无限，一般都是从后往前绘制，但在移动上，尽量从前往后绘制.在Unity中，那些Shader中被设置为“Geometry”队列的对象总是从前往后绘制的，而其他固定队列（如“Transparent”“Overla”等）的物体，则都是从后往前绘制的。这意味这，我们可以尽量把物体的队列设置为“Geometry” 。尽量减小过度绘制区域:实在需要多层绘制的地方，要尽量减小各部分过度绘制区域，使重合区域小，绘制的像素点也就少一点\n\n  * 注意性能与效果的取舍:UGUI的许多控件有很好的通用性和展示效果，但是可能会耗更多性能\n\n  * 过大的不必要绘制尽量代码实现:例如点击屏幕空白区域返回功能，加透明image会增加很多\n\n  * UI设计上尽可能简单减少重叠\n\n### 针对性优化\n\n#### 文字\n\nOutline实现方式是将Text的四个顶点传过去复制四份，设置四份偏移量实现效果，将偏移量设置很大之后，可以看到一个Text周围有四个相同的Text\n解决方案:\n1.不使用或者使用Shadow(Shadow通过为图像或者文字的Mesh添加顶点实现阴影效果，Outline继承Shadow，在对象四个角上各添加一个Shadow)\n2.使用Textmesh Pro(Unity5.5)需要制作相应的字体文件，对于动态生成的文字效果不好，固定字体很好\n([https://blog.csdn.net/dark00800/article/details/73011343?utm_source=itdadao&utm_medium=referral](https://blog.csdn.net/dark00800/article/details/73011343?utm_source=itdadao&utm_medium=referral))\n3.修改Mesh的UV坐标，提取文字原始UV坐标，扩大文字绘图区域，对文字纹理周围像素点采样，新旧颜色融合\n(<http://gad.qq.com/article/detail/29266>)\n\n#### 适配IphoneX\n\n适配的需要加了层背景，不是iPhoneX失活就可以\n\n#### 背景人物mesh\n\n裁剪小一点更好\n\n#### Mask组件\n\nUnity的Mask组件会增加一层Overdraw，还会多增加4个DrawCall\n解决:\n1.使用RectMask2D代替，缺点是只能用于矩形\n2.对于多边形，用MeshMask，红色为UnityMask，蓝色是MeshMask，UnityMask消耗15个DrawCall，Overdraw2次，MeshMask消耗1个DrawCall，1层OverDraw(<https://www.cnblogs.com/leoin2012/p/6822859.html>)\n\n#### Image的slide属性\n\n对于slide九宫格图片，可以看情况取消fill center属性，那样中心区域会不渲染，中心区域也就镂空，重合面积也会小\n\n1)重合多的地方尽可能不重合\n2)无用的Image\n少量的panel或者单纯的空父物体身上加着image，虽然没有给图片，但是还是会渲染\n3)移动的波浪图片过大过多(修改高度，宽度)\n4)特效粒子效果优化(<http://www.u3dnotes.com/archives/807>)\n粒子效果薄弱的可以使用序列帧动画实现\n\n部分小细节：\n1.slide九宫格图片，取消fill center，中心镂空\n2.mask尽量不用，可以用rect mask2D 代替\n3.不用UI/Effect，包括Shadow，Outline，Position As UV1\n4.不用Image的Tiled类型\n5.不用Pixel Perfect\n6.动静分离，动态的在父物体上加个Canvas\n7.尽量active，不要destroy，也不要设置Alpha=0这样还是会渲染\n8.不用BestFit(代价高，Unity会为该元素用到的所有字号生成图元保存在Altlas中，增加额外生成时间，还会使得字体对应的atlas变大)\n9.特效粒子\n\nRef：\n<https://www.jianshu.com/p/7167c516bd75>\n"
}
