I decided to try out run time mipmap creation. Saving files in some other format than DDS, with or without mipmaps results in smaller install and faster load time, since unpacking the file is faster that reading a large file from disk and generating the mipmaps should take virtually zero time if the GPU applies a linear filter. I do hope that his is done on the GPU. Is there any absolute information on this topic? I couldn't find a clear result on Google.
Rendering with gamma correction is fairly easy. All you need to do is make sure that your diffuse textures are read as sRGB textures. All generated non-diffuse textures should be read as normal textures (linear content like normal maps and generated gloss maps). When writing anything but a debug mode for a linear sampler, you should also write to sRGM textures.
This has worked out perfectly until I started generating my mipmaps at run time. Gamma correction must happen before the texture is filtered trilinearly. Yet all my test images failed and looked exactly how you would expect them if the mips were generated and then you sample them with gamma correction.
I tried all the combinations for texture creation flags and bellow in my load texture function you can see the only combination that has resulted in correct rendering:
public Texture LoadTextureMIP(string path, bool gc) {
Usage u = Usage.AutoGenerateMipMap;
Filter f = gc ? Filter.Linear | Filter.SrgbIn : Filter.Linear;
path = Paths.Textures + path;
var a = ImageInformation.FromFile(path);
return Texture.FromFile(Device, path, a.Width, a.Height, 1, u, a.Format, Pool.Managed, f, f, 0);
}
The gc parameter controls if the mips should be generated with gamma correction. I find it counter intuitive that using just Filter.SrgbIn resulted in correct results, so I may be doing something wrong. I was expecting to have to use Filter.SrgbOut too.
There is one caveat though: the textures created by this function can no longer be sampled as sRGB textures. They look too dark, as if they were gamma corrected twice. They must be sampled as linear and written as sRGB.
Which lead me to believe that the textures are now stored in linear format in VRAM. Which makes sense since you read them as sRGB and do not write them as sRGB. Which is a massive no no. There is a good reason for the problem of gamma correction not having the solution of using linear maps. Storing linear maps in 8 bit/channel will result in a loss of needed precision for deep blacks.
So did I butcher my deep black precision in order to get correctly filtered mip levels? Or did I misunderstand the situation. What is the best way to auto-generate mips with perfect gamma behavior.
Or should I just avoid this headache and force the content importer to generate all mips offline?