• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
DwarvesH

Mipmaps gamma correction

8 posts in this topic

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?

0

Share this post


Link to post
Share on other sites

Generate them offline. Saves you all this trouble, gives more control to the artist and allows you to use better filtering (Kaiser).

1

Share this post


Link to post
Share on other sites
Keep in mind that the entire mip tail is only 33% of the original size so you are only saving very little by computing it at run time. You usually also want to compress your textures (that is all mip levels) using dxt1 or something similar, which is also a lot easier if performed offline.
0

Share this post


Link to post
Share on other sites

Doing them offline is the obvious choice. But if I go with precomputed, I would still rather do them live and cache the result, to take into account the exact sRGB LUT of the monitor that the shader version would use. So I'll have to write a generator that takes the full size image as a sRGB input, computes manually the linear sample using centroid sampling (need to determine the exact formula the standard linear uses) and renders that to a quarter size sRGB texture. And repeat the process until I get a 1x1 texture. Ideally, the highest resolution map would be used to sequentially compute each mip level, not the nearest but larger in size to avoid error propagation.

 

Way too much work.

 

Everything I have read says that mipmapping filtering should work with proper gamma. So I am either doing something wrong, the Intel HD sucks or it is yet again a DirectX 9 issue :).

0

Share this post


Link to post
Share on other sites

If you're worried about file sizes what you almost certainly want to do is compress the textures with either DXT1 or DXT5. DXT1 doesn't support alpha, DXT5 does but is double the size. A DXT1 texture is effectively 4 bits per pixel, and stays compressed on the GPU which means it can also improve performance by saving memory bandwidth.

 

Since they are relatively slow to compress, you want to compress them offline using something like squish. If you're really worried about file size they will also benefit from being put in a zip file as the texture compression is only done in blocks of 4x4 pixels for ease of hardware decompression.

 

The only downside is that the compression is lossy so it may not be suitable for some textures. In my experience the compression artefacts are most noticeable on detailed 2D textures.

1

Share this post


Link to post
Share on other sites

My primary concern is gamma correctness.

 

Getting a small boost to load times is at most a welcome yet unlikely bonus.

 

Since I'm concerned with render quality, I won't go with texture compression unless I go over my minimum VRAM requirement. DXT1 has horrible quality and I don't want to bother with YCoCg and its possible gamma ramifications. That is just asking for trouble. And I can't find a 2.1 compiled nvidia texture tools.

 

And combining a high quality SSAA with texture compression seems like a self defeating action quality wise.

 

I did not manage to fine tune my auto mip creation parameters to give good results. And auto miped textures are surprisingly volatile. So I'm going with a content pipeline that enumerates resources, their properties and their origin. It is up to pipeline to determine if the conversion should be done at runtime or loaded from a cache.

 

I tried implementing this using C# and nvidia texturing tools, but the C# bindings are not up to date. The DLL I got after installing 2.0.8 does not export nvttCreateCompressor and nvttDestroyCompressor. I really don't have time to contact the team with that right now.

 

So I'm going with offline generation for now. At least the results are correct. I also managed to call the compressor as a process from code.

0

Share this post


Link to post
Share on other sites

If you are using DX9, there was no directive as to whether linearization should occur post / prefiltering so you may end up with incorrect result depending on how the driver implement the texture fetch and filter.

0

Share this post


Link to post
Share on other sites

Since I'm concerned with render quality, I won't go with texture compression unless I go over my minimum VRAM requirement.

You know that Battlefield 3 and Battlefield 4 use DXT quite heavily (possibly exclusively) right?


And I can't find a 2.1 compiled nvidia texture tools.

My LSDxt DXT Compressor tool is heavily based off the nVidia Texture Tools as far as options go (the compression algorithm is completely new).
It supports most features from nVidia Texture Tools, including Kaiser mipmap filtering and the ability to save in other formats besides DXT* if you do not like the quality of DXT compression.
It also handles gamma correction for you.
It is offline and command-line so you can easily integrate it into your tool-chain.


L. Spiro
1

Share this post


Link to post
Share on other sites

 

Since I'm concerned with render quality, I won't go with texture compression unless I go over my minimum VRAM requirement.

You know that Battlefield 3 and Battlefield 4 use DXT quite heavily (possibly exclusively) right?


And I can't find a 2.1 compiled nvidia texture tools.

My LSDxt DXT Compressor tool is heavily based off the nVidia Texture Tools as far as options go (the compression algorithm is completely new).
It supports most features from nVidia Texture Tools, including Kaiser mipmap filtering and the ability to save in other formats besides DXT* if you do not like the quality of DXT compression.
It also handles gamma correction for you.
It is offline and command-line so you can easily integrate it into your tool-chain.


L. Spiro

 

 

Nice tool you have there! If it works with all those parameters it is a lot better than NVidia texturing tools! For now I have integrated that but I will test yours out too.

 

As for DXT, I'll probably start using it once I go over 1GiB of texture space.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0