Skip to content
Cole Campbell edited this page Apr 28, 2018 · 3 revisions

Ultraviolet 2018.04 introduces explicit support for textures, surfaces, and buffers containing sRGB color data. Enabling this support, as well as properly flagging your assets to indicate whether they contain sRGB encoded data, will ensure that your application correctly blends colors during rendering. This is especially important if you are using the FreeType2 plugin for text rendering; FreeType2 fonts will not render correctly unless they are gamma corrected.

Enabling sRGB Support

To enable support for sRGB color data, set the SrgbBuffersEnabled property of your UltravioletConfiguration object to true during context configuration. Additional properties on the configuration object allow you to change the default behavior of the Surface2D, Surface3D, Texture2D, Texture3D, and RenderBuffer2D classes; setting the SrgbDefaultForX property to true, where X is the name of one of the aforementioned classes, will cause Ultraviolet to consider all such instances of that class to be SRGB encoded by default.

In most cases, you will probably want to turn on sRGB support and set SrgbDefaultForTexture2D and SrgbDefaultForRenderBuffer2D to true, while leaving the other properties alone. Almost all common image formats use sRGB encoded color, so it's important to take that into account for textures. However, anything which serves as raw data—a lookup table, a normal map, et cetera—needs to have its raw color values preserved, so sRGB encoding should not be enabled for such assets.

If you do not change the values of any of these properties, then Ultraviolet will continue to render everything exactly as it did in prior versions (which is to say, incorrectly).

In addition to setting the default values for each relevant class, you can also specify whether an individual asset is sRGB-encoded using content metadata files. Loaded Surface2D, Surface3D, Texture2D, and Texture3D assets will all accept a processor metadata property called SrgbEncoded which specifies the encoding: true to sRGB encoded or false for linearly encoded.

If you are instead creating these assets programatically, all of the relevant Create() methods have new overloads which accept an optional parameter that specifies whether the object instance is SRGB encoded. Additionally, the Surface2D and Surface3D classes have settable SrgbEncoded properties; you can change their encodings at any time.

Using sRGB with Existing Classes

You can determine whether the currently-set render target is sRGB encoded using the CurrentRenderTargetIsSrgbEncoded property which has been added to IUltravioletGraphics.

The SpriteBatch class has been updated to understand when it is rendering to an sRGB encoded target; it will attempt to set the SrgbColor uniform of its current shader effect to true, and the built-in shader will automatically convert vertex colors into the linear space.

The BasicEffect class has been given a new property called SrgbColor which will tell its shader to convert its vertex colors into the linear space, but unlike SpriteBatch this property is not set automatically.

The Surface2D, Surface3D, Texure2D, Texture3D, and RenderBuffer2D classes have been given new properties called SrgbEncoded which specify whether sRGB encoding is enabled for that object; for surfaces, this property is settable, and hardware support for sRGB color is not required.

The RenderTarget2D class has a new property called HasSrgbEncodedColorBuffer which is set to true if the target has an attached color buffer which uses sRGB encoding.

Clone this wiki locally