简体   繁体   English

使用 WIC 在 DirectX11 中将纹理加载为 RGB 而不是 sRGB

[英]Load texture as RGB not sRGB in DirectX11 using WIC

I'm loading textures using CreateWICTextureFromMemoryEx from DirectXTK .我正在使用CreateWICTextureFromMemoryExCreateWICTextureFromMemoryEx加载纹理。 Everything I load is converted to sRGB .我加载的所有内容都转换为sRGB Is there any way to force WIC to create RGB surface instead?有什么办法可以强制WIC创建RGB表面?

Or maybe there is a way to convert an already loaded texture from sRGB to RGB ?或者也许有一种方法可以将已经加载的纹理从sRGB转换为RGB Back in D3DX there used to be D3DX11_FILTER_SRGB flag for that (from what I understand) but it's not deprecated.回到D3DX ,曾经有D3DX11_FILTER_SRGB标志(据我所知),但它并没有被弃用。

Any help will be very appreciated, thanks!任何帮助将不胜感激,谢谢!

The DirectX Tool Kit loader uses DXGI_FORMAT_*_SRGB when loading WIC images for a few reasons: DirectX Tool Kit加载器在加载 WIC 图像时使用DXGI_FORMAT_*_SRGB有以下几个原因:

  • The WIC metadata for a PNG file contains the sRGB chunk ( /sRGB/RenderingIntent is true) PNG 文件的 WIC 元数据包含 sRGB 块( /sRGB/RenderingIntent为真)

  • The WIC metadata for a JPG indicates sRGB ( /app1/ifd/exif/{ushort=40961} is 1) JPG 的 WIC 元数据表示 sRGB( /app1/ifd/exif/{ushort=40961}为 1)

  • The WIC metadata for a TIFF indicates sRGB ( /ifd/exif/{ushort=40961} is 1) TIFF 的 WIC 元数据表示 sRGB( /ifd/exif/{ushort=40961}为 1)

  • If you pass 'true' as the forceSRGB parameter to the Ex version of the function如果您将“true”作为forceSRGB参数传递给函数的 Ex 版本

So the image is in fact likely in sRGB colorspace.所以图像实际上很可能在 sRGB 色彩空间中。 Therefore, the DXGI_FORMAT_*_SRGB indicates that reads from that texture should be subject to de-gamma to get them into a linear colorspace.因此, DXGI_FORMAT_*_SRGB表示从该纹理读取的内容应该经过去伽马处理,以将它们放入线性色彩空间。 I'm assuming you are not using gamma-correct rendering here?我假设您没有在这里使用伽马校正渲染?

Gamma-correct rendering is achieved by using a DXGI_FORMAT_*_SRGB or HDR (10:10:10:2, 16:16:16:16) backbuffer format. Gamma 校正渲染是通过使用DXGI_FORMAT_*_SRGB或 HDR (10:10:10:2, 16:16:16:16) 后台缓冲区格式实现的。 You also need to use linear colors for Clear .您还需要为Clear使用线性颜色。 See DeviceResources , Gamma-correct rendering , The Importance of Being Linear , and Linear-Space Lighting (ie Gamma) for details.有关详细信息,请参阅DeviceResourcesGamma-correct renderingThe Importance of Being LinearLinear-Space Lighting(即 Gamma)

A quick and easy workaround if you control the texture file would be to use texconv in the DirectXTex library to convert the source image to a DDS .如果你控制的纹理文件的快速和简单的解决办法是使用texconvDirectXTex库源图像转换为DDS You can use various switches like -srgbi or -srgbo to force the SRGB behavior you are after.您可以使用诸如-srgbi-srgbo类的各种开关来强制执行您所追求的 SRGB 行为。

Note that I'm also adding an option to let you ignore the sRGB metadata when using WICTextureLoader for a future release of DirectX Tool Kit .请注意,我还添加了一个选项,让您在将 WICTextureLoader 用于DirectX Tool Kit的未来版本时忽略 sRGB 元数据。 Linear rendering is best, but sometimes it's nice to have the option to avoid the DXGI_FORMAT_*_SRGB format being used.线性渲染是最好的,但有时可以选择避免使用DXGI_FORMAT_*_SRGB格式也不错。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM