Texture content is often in the sRGB format. Details about this format can be found. In general, pixel pipelines assume that colors are linear so that the blending operation can be performed in linear spaces. Because the content in sRGB is gamma, processing in a linear space may lead to incorrect results. When the video card reads the sRGB content, it cancels the Gamma Correction to avoid errors. Then, when the pixel is output, the pixel information is written back to the sRGB format. In this case, operations in all pixel pipelines can be performed in the psychological linear space.
Gamma Correction
In d3d9.
You can specify whether a texture is normal with gamma 2.2 (sRGB). The driver will convert it to a linear gamma for fusion during settexture. Or the sampler will change it to linear data during the query.
You can specify whether the Gamma Correction is converted back to the sRGB space when the pixel pipeline is output to the rendering target.
All other colors (clear color, Material color, vertex color, etc) are assumed to be in linear space. Applications can use pixel coloring er commands to perform Gamma Correction on colors written into the frame cache. The linearity operation is only valid for RGB channels, and the alpha channel is ignored.
Not all surface formats can be linear. Only the format detected by idirect3d9: checkdeviceformat (the parameter is d3dusage_query_srgbread) can be linear. In addition, the sampling status d3dsamp_srgbtexture is ignored. Only the unsigned texture format supports this transformation. The unsigned texture format is a texture format that only contains the r g B and l components. If the channel contains Alpha, it will be ignored. If the mixed format supports sRGB linearity, only the unsigned channel is valid. Ideally, the hardware implements linearity before texture filtering. However, in d3d9, the hardware only allows linearity After texture filtering.
Not all surfaces can be written into sRGB space, only by using d3dusage_query_srgbwriteIdirect3d9: checkdeviceformatOnly the tested surface format can be linear. In addition, the d3drs_srgbwriteenable flag in the rendering state will be ignored. The 8-bit unsigned RGB format for each channel is a suitable format.
Ideally, the hardware will perform frame cache fusion in a linear space. However, the hardware can only be processed after the pixel pipeline is processed and before the frame cache is merged. This means that frame cache fusion in sRGB results in incorrect results. When the rendering target is cleared. D3drs_srgbwriteenable flag is honored. When the hardware supports multi-rendering targets or multi-element textures, only the first rendering target and the first element will be written to the cache.
API changes
API changes
// New sampler state (DWORD) New sampler state // if this is nonzero, the texture is linearized on lookup.
If it is not 0, the texture is linear in the query. D3dsamp_srgbtexture // default False false by default // new render state (DWORD)
The new rendering status d3drs_srgbwriteenable // default false is false by default // new usage flags
New usage flag d3dusage_query_srgbwrited3dusage_query_srgbread
Switch chain in the window
In order to perform the correct fusion operation, it is necessary for applications to save their swap chains in the background buffer in linear space. Because the desktop is usually not linear. Therefore, Gamma Correction must be performed before the background buffer content is displayed.
The application can add an additional buffer from my correction and copy his own correct results from the linear space to the background buffer. When the driver uses gamma correction as a partial display, it can avoid using additional buffers.