{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/uwa-answer-linear-color-space-render-texture-value/",
  "atlas": "https://www.pystone.net/?node=uwa-answer-linear-color-space-render-texture-value#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/uwa-answer-linear-color-space-render-texture-value.md",
  "context": "https://www.pystone.net/notes/uwa-answer-linear-color-space-render-texture-value.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:uwa-answer-linear-color-space-render-texture-value",
  "slug": "uwa-answer-linear-color-space-render-texture-value",
  "title": "unity的颜色线性空间下randTexture单个像素的色值大于shader的输出值的困惑",
  "type": "note",
  "visibility": "public",
  "idStability": "rename-stable",
  "author": {
    "name": "石心.Yong"
  },
  "publisher": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "aliases": [],
  "summary": "unity的颜色线性空间下randTexture单个像素的色值大于shader的输出值的困惑",
  "contentRole": "source",
  "sourceType": "source",
  "sourceMetadata": {
    "author": "石心.Yong"
  },
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "external_source",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "contentHash": "f7870e58183213ff962646a61429f907f935149b7003f2f579dbc4b6fc9ad242",
  "assets": [
    {
      "reference": "assets/5f51b8ba9424416784ef20d7/01.png",
      "url": "/media/e362ba39a10d69082422.png",
      "mediaType": "image/png",
      "contentHash": "e362ba39a10d690824223776962fa7a0f4172a0b3e346eba0bd52edd172e961b",
      "byteLength": 9000,
      "width": 540,
      "height": 83
    }
  ],
  "headings": [
    {
      "depth": 1,
      "text": "unity的颜色线性空间下randTexture单个像素的色值大于shader的输出值的困惑",
      "anchor": "unity的颜色线性空间下randtexture单个像素的色值大于shader的输出值的困惑",
      "citation": "https://www.pystone.net/notes/uwa-answer-linear-color-space-render-texture-value/#unity%E7%9A%84%E9%A2%9C%E8%89%B2%E7%BA%BF%E6%80%A7%E7%A9%BA%E9%97%B4%E4%B8%8Brandtexture%E5%8D%95%E4%B8%AA%E5%83%8F%E7%B4%A0%E7%9A%84%E8%89%B2%E5%80%BC%E5%A4%A7%E4%BA%8Eshader%E7%9A%84%E8%BE%93%E5%87%BA%E5%80%BC%E7%9A%84%E5%9B%B0%E6%83%91"
    },
    {
      "depth": 2,
      "text": "问题",
      "anchor": "问题",
      "citation": "https://www.pystone.net/notes/uwa-answer-linear-color-space-render-texture-value/#%E9%97%AE%E9%A2%98"
    },
    {
      "depth": 2,
      "text": "我的回答",
      "anchor": "我的回答",
      "citation": "https://www.pystone.net/notes/uwa-answer-linear-color-space-render-texture-value/#%E6%88%91%E7%9A%84%E5%9B%9E%E7%AD%94"
    },
    {
      "depth": 2,
      "text": "来源与关系",
      "anchor": "来源与关系",
      "citation": "https://www.pystone.net/notes/uwa-answer-linear-color-space-render-texture-value/#%E6%9D%A5%E6%BA%90%E4%B8%8E%E5%85%B3%E7%B3%BB"
    }
  ],
  "claims": [],
  "outgoing": [
    {
      "id": "note:my-uwa-answers",
      "title": "我的 UWA 问答",
      "url": "https://www.pystone.net/notes/my-uwa-answers/",
      "atlas": "https://www.pystone.net/?node=my-uwa-answers#knowledge-atlas",
      "label": "我的 UWA 问答",
      "origin": "explicit",
      "humanReviewed": true,
      "context": "上位集合：我的 UWA 问答",
      "citation": "https://www.pystone.net/notes/uwa-answer-linear-color-space-render-texture-value/#%E6%9D%A5%E6%BA%90%E4%B8%8E%E5%85%B3%E7%B3%BB"
    }
  ],
  "incoming": [
    {
      "id": "note:my-uwa-answers",
      "title": "我的 UWA 问答",
      "url": "https://www.pystone.net/notes/my-uwa-answers/",
      "atlas": "https://www.pystone.net/?node=my-uwa-answers#knowledge-atlas",
      "label": "我的 UWA 问答",
      "origin": "explicit",
      "humanReviewed": true,
      "context": "2020-09-05：unity的颜色线性空间下randTexture单个像素的色值大于shader的输出值的困惑（GPU、渲染模块、性能优化、终端平台、性能排查工具）",
      "citation": "https://www.pystone.net/notes/my-uwa-answers/#2020"
    },
    {
      "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": "我的UWA问答中的“2020-09-05 - unity的颜色线性空间下randTexture单个像素的色值大于shader的输出值的困惑”导航项",
      "citation": "https://www.pystone.net/notes/game-graphics-and-runtime/#%E6%88%91%E7%9A%84uwa%E9%97%AE%E7%AD%94"
    }
  ],
  "contentMarkdown": "# unity的颜色线性空间下randTexture单个像素的色值大于shader的输出值的困惑\n\n> [!note] 我的 UWA 问答\n> 本文收录我在 UWA 问答发表的公开回答。问题内容归原提问者；回答保留当时语境，技术结论可能受 Unity 版本、平台和项目条件限制。\n\n## 问题\n\n这几天工程在进行粒子特效的性能检测，我们使用了uwa的ParticleEffectProfiler工具进行性能分析。在进行检测的时候发现一个问题，单个广告板的粒子overdraw为5，理论上应该是1的。我自己断点发现，虽然相机的shader片元输出颜色为fixed4(0.1, 0.04, 0.02, 0)，但是在进性像素绘制次数计算的时候颜色的g = 0.2196......导致结算结果错误。后来向uwa反馈后，技术人员告诉我说把颜色空间改为gamma就好了，试验了一下，确实好了。但是我有困惑。\n\n在线性空间下，shader返回的g值为0.04，为什么randerTexture的g值为0.2196.....，线性空间下颜色在显示器上显示的不应搞是0.04^2.2 <0.0016么，为什么会是0.2196....变大的值，难道显示器本身也进行gamam校正么？再有就是untiy颜色的线性空间和gamam空间是个什么样的逻辑，怎么感觉跟我学习的知识反着的，亦或者是我理解不到位。请各位大神帮忙解惑\n\n- 提问者：阿祖的祖\n- 提问时间：2020-09-04 19:47:06\n\n## 我的回答\n\n先简单解释一下，Unity的Color Space为Linear时，会在最后输出阶段，进行的伽马校正（gamma correction），将Linear空间的像素转换为sRGB空间。Gamma Correction会将颜色的亮度变大（补偿），Unity会将补偿后的像素值输出给显示设备（UWA的Effect Scanning工具会输出到RenderTexture上）。\n\n因此，使用UWA当前版本的的特效检测功能，应该把项目的Color Space设置成Gamma。如果是Linear Space，计算得到的Overdraw率会偏高。\n\nGamma Correction( transform the linear values into sRGB)的公式为：\n\n![image.png](assets/5f51b8ba9424416784ef20d7/01.png)\n\nwhere u is R, G, or B\n\n- 回答时间：2020-09-05 02:32:23\n- 最后更新：2020-09-06 01:26:44\n- 采纳状态：未采纳\n\n## 来源与关系\n\n- 上位集合：[[10-计算机、信息技术与工程/05-游戏图形与运行时/我的UWA问答/我的UWA问答|我的 UWA 问答]]\n- UWA 标签：GPU、渲染模块、性能优化、终端平台、性能排查工具\n- 原始问题：[unity的颜色线性空间下randTexture单个像素的色值大于shader的输出值的困惑](https://answer.uwa4d.com/question/5f51b8ba9424416784ef20d7)\n- 源页最后更新：2020-09-05 02:32:23\n"
}
