ccruiの博客

ccruiの博客

解决Unity中RenderTexture转texture2d画面变暗的问题

128
2022-12-26

问题截图

问题原因

在Unity中使用线性色彩空间的时候,由于editor创建RenderTexture的时候默认的sRGB是false的,所以导致所输出的内容是没有经过gamma矫正的,会导致生成的png变暗。

解决办法

不通过editor创建,使用代码动态的构建

RenderTexture rt = new RenderTexture((int)rect.width, (int)rect.height, 0);

或者使用

RenderTexture rt = new RenderTexture(rt.width, rt.height, rt.depth, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);

参考文章:https://blog.csdn.net/hakukou/article/details/123247360