有时候我们希望使用一张烘焙好的Texture作为颜色材质:
却发现由于大量的后期处理,最后得到的并不是我们想要的颜色:
打开PostProcessTonemap.usf可以看到:
half3 FilmColor = FilmPostProcess(LinearColor.rgb);
half3 TonemappedColor;
if (SRGBAwareTarget > 0.5)
{
// skip sRGB conversion if HW conversion will take place.
TonemappedColor = FilmColor;
}
else
{
#if IOS
// Note, iOS native output is raw gamma 2.2 not sRGB!
TonemappedColor = pow(FilmColor.rgb, 1.0 / 2.2);
#else
// Apply conversion to sRGB (this must be an exact sRGB conversion else darks are bad).
TonemappedColor = LinearToSrgbBranchless(FilmColor);
#endif
}
即在Tonemap的时候,先进行了FilmPostProcess,而后又进行了LinearToSrgbBranchless。
经笔者尝试,使用一个后期处理材质,将Blendable Location设为Replacing the Tonemapper,然后只使用LinearToSrgbBranchless即可:
其中,LinearToSrgb即为GammaCorrectionCommon.ush中LinearToSrgbBranchless的代码:
half3 LinearToSrgbBranchless(half3 lin)
{
lin = max(6.10352e-5, lin); // minimum positive non-denormal (fixes black problem on DX11 AMD and NV)
return min(lin * 12.92, pow(max(lin, 0.00313067), 1.0/2.4) * 1.055 - 0.055);
// Possible that mobile GPUs might have native pow() function?
//return min(lin * 12.92, exp2(log2(max(lin, 0.00313067)) * (1.0/2.4) + log2(1.055)) - 0.055);
}
最后效果如下: