{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/unity-rendering-order/",
  "atlas": "https://www.pystone.net/?node=unity-rendering-order#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/unity-rendering-order.md",
  "context": "https://www.pystone.net/notes/unity-rendering-order.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:unity-rendering-order",
  "slug": "unity-rendering-order",
  "title": "Unity的渲染顺序",
  "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": "Unity的渲染顺序",
  "contentRole": "unspecified",
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "unspecified",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "contentHash": "991312b670a4b40e99dbfbee3f3b6e9dcb3ef15f54db6e57d50b2e277acb1cc9",
  "assets": [
    {
      "reference": "assets/1617976734905.png",
      "url": "/media/3cd092dfb9eff2efc0ef.png",
      "mediaType": "image/png",
      "contentHash": "3cd092dfb9eff2efc0ef57eeb960fb17234d9e752ace2b38b359c3d77e196bdd",
      "byteLength": 246372,
      "width": 958,
      "height": 607
    },
    {
      "reference": "assets/1617962792081.png",
      "url": "/media/a9f5966d1450416e983d.png",
      "mediaType": "image/png",
      "contentHash": "a9f5966d1450416e983d1cb68cbe97a5f7ae694178a92132e0e2d14b055bf171",
      "byteLength": 20609,
      "width": 377,
      "height": 299
    },
    {
      "reference": "assets/1617962839947.png",
      "url": "/media/dc84e813cff5762c4645.png",
      "mediaType": "image/png",
      "contentHash": "dc84e813cff5762c464504a5c5b1ef4e78ad3e3c65a7b2895ac0ab1e5ca3c08e",
      "byteLength": 17903,
      "width": 381,
      "height": 227
    },
    {
      "reference": "assets/1617962903268.png",
      "url": "/media/2c6ce4daed3ecf42334c.png",
      "mediaType": "image/png",
      "contentHash": "2c6ce4daed3ecf42334c70bbd82450da71458201a0ac224c92022a6ec0961876",
      "byteLength": 9984,
      "width": 246,
      "height": 232
    },
    {
      "reference": "assets/1617975393846.png",
      "url": "/media/1efa5214fbba79ca8896.png",
      "mediaType": "image/png",
      "contentHash": "1efa5214fbba79ca88965f1e92c415c2f7b1007144e76fab6ca363d0f07028db",
      "byteLength": 8467,
      "width": 325,
      "height": 162
    },
    {
      "reference": "assets/1617976086216.png",
      "url": "/media/a27801d519efa6609b94.png",
      "mediaType": "image/png",
      "contentHash": "a27801d519efa6609b94c796e975ae3b49ca3085120b4ef2f734cf53694b8a8c",
      "byteLength": 12237,
      "width": 427,
      "height": 134
    },
    {
      "reference": "assets/1617976104615.png",
      "url": "/media/7f66927a24b98cba36b2.png",
      "mediaType": "image/png",
      "contentHash": "7f66927a24b98cba36b20809a371d2fdd00c66de3426fd76ee8d1104ec44b0f4",
      "byteLength": 28373,
      "width": 397,
      "height": 372
    },
    {
      "reference": "assets/1617976537790.png",
      "url": "/media/0547efcfbcca078d3fd6.png",
      "mediaType": "image/png",
      "contentHash": "0547efcfbcca078d3fd651fd8f4ff5803f4ffa13d9f85fdf3a7f0da0b1991eee",
      "byteLength": 8332,
      "width": 300,
      "height": 83
    }
  ],
  "headings": [
    {
      "depth": 1,
      "text": "Unity的渲染顺序",
      "anchor": "unity的渲染顺序",
      "citation": "https://www.pystone.net/notes/unity-rendering-order/#unity%E7%9A%84%E6%B8%B2%E6%9F%93%E9%A1%BA%E5%BA%8F"
    },
    {
      "depth": 2,
      "text": "决定渲染顺序的因素",
      "anchor": "决定渲染顺序的因素",
      "citation": "https://www.pystone.net/notes/unity-rendering-order/#%E5%86%B3%E5%AE%9A%E6%B8%B2%E6%9F%93%E9%A1%BA%E5%BA%8F%E7%9A%84%E5%9B%A0%E7%B4%A0"
    },
    {
      "depth": 3,
      "text": "Camera Depth",
      "anchor": "camera-depth",
      "citation": "https://www.pystone.net/notes/unity-rendering-order/#camera-depth"
    },
    {
      "depth": 3,
      "text": "Opaque-Skybox-Transparent",
      "anchor": "opaque-skybox-transparent",
      "citation": "https://www.pystone.net/notes/unity-rendering-order/#opaque-skybox-transparent"
    },
    {
      "depth": 3,
      "text": "Sorting Layers + Order in Layer",
      "anchor": "sorting-layers-order-in-layer",
      "citation": "https://www.pystone.net/notes/unity-rendering-order/#sorting-layers-order-in-layer"
    },
    {
      "depth": 3,
      "text": "RenderQueue",
      "anchor": "renderqueue",
      "citation": "https://www.pystone.net/notes/unity-rendering-order/#renderqueue"
    },
    {
      "depth": 3,
      "text": "Sorting Fudge",
      "anchor": "sorting-fudge",
      "citation": "https://www.pystone.net/notes/unity-rendering-order/#sorting-fudge"
    },
    {
      "depth": 3,
      "text": "深度排序",
      "anchor": "深度排序",
      "citation": "https://www.pystone.net/notes/unity-rendering-order/#%E6%B7%B1%E5%BA%A6%E6%8E%92%E5%BA%8F"
    },
    {
      "depth": 2,
      "text": "实践建议",
      "anchor": "实践建议",
      "citation": "https://www.pystone.net/notes/unity-rendering-order/#%E5%AE%9E%E8%B7%B5%E5%BB%BA%E8%AE%AE"
    },
    {
      "depth": 3,
      "text": "明确分层",
      "anchor": "明确分层",
      "citation": "https://www.pystone.net/notes/unity-rendering-order/#%E6%98%8E%E7%A1%AE%E5%88%86%E5%B1%82"
    },
    {
      "depth": 2,
      "text": "Ref",
      "anchor": "ref",
      "citation": "https://www.pystone.net/notes/unity-rendering-order/#ref"
    }
  ],
  "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中的“Unity的渲染顺序”导航项",
      "citation": "https://www.pystone.net/notes/game-graphics-and-runtime/#unity"
    }
  ],
  "contentMarkdown": "# Unity的渲染顺序\n\n> 创建时间：2021/4/9 17:52\n\n## 决定渲染顺序的因素\n\n![Alt text](assets/1617976734905.png)\n\n### Camera Depth\n\n按照Camera的Depth值从低到高的顺序，逐个Camera进行渲染。\n\n![Alt text](assets/1617962792081.png)\n\n每个Camera绘制的内容可以在CullingMask当中设置——设置绘制哪些Layers的物体\n\n![Alt text](assets/1617962839947.png)\n\n物体的Layer可以在Inspector面板进行设置。\n\n![Alt text](assets/1617962903268.png)\n\n### Opaque-Skybox-Transparent\n\nQueue<=2500 - Opaque\nQueue>=2501 - Transparent\n\n### Sorting Layers + Order in Layer\n\n可在Project Settings->Tags and Layers->SortingLayers中添加Layer。\n\n![Alt text](assets/1617975393846.png)\n\n在ParticleSystem、Sprite等Unity动态生成网格的Component中设置Sorting Layer与Order in Layer，来决定物体绘制的顺序，绘制时按从小到大排序。\n\n![Alt text](assets/1617976086216.png)\n\n![Alt text](assets/1617976104615.png)\n\n### RenderQueue\n\nRenderQueure是Material的一个属性。\n按照渲染队列，从低到高绘制。\n\nBackground (1000) - rendered before any others. You’d typically use this for things that really need to be in the background.\n\nGeometry (default) (2000) - this is used for most objects. Opaque geometry uses this queue.\n\nAlphaTest (2450) - alpha tested geometry uses this queue. It’s a separate queue from Geometry one since it’s more efficient to render alpha-tested objects after all solid ones are drawn.\n\nTransparent (3000) - this render queue is rendered after Geometry and AlphaTest, in back-to-front order. Anything alpha-blended (i.e. shaders that don’t write to depth buffer) should go here (glass, particle effects).\n\nOverlay (4000) - this render queue is meant for overlay effects. Anything rendered last should go here (e.g. lens flares, UI).\n\n### Sorting Fudge\n\nParticle System组件还有一个属性：Sorting Fudge，在其他值都相同时，这个值会影响绘制的先后顺序，值比较高的先绘制。\n\n![Alt text](assets/1617976537790.png)\n\n### 深度排序\n\n按照 **包围盒** 中心点的深度进行排序\n\n  * 不透明物体 - 由近到远（从前向后）\n\n  * 透明物体 - 由远到近（从后向前）\n\n## 实践建议\n\n### 明确分层\n\n例如UI上的半透明（特效、面片）始终在3D场景之上，则一般分多个相机来绘制。\n大片填充率的物件，例如地形，天空等，一般为提高深度命中，都会选择在延后批次绘制。\nDraw character before the terrain.\n\n## Ref\n\n<https://zhuanlan.zhihu.com/p/55762351>\n"
}
