Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
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
RenderBuffer2D classes; setting the
SrgbDefaultForX property to
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
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
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
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
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.
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.
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.
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.