I've recently been playing around with procedural city and road generation which has of course led to rendering of road surfaces for which I am using a trivially simple programmer art texture:
Source Road Lines Texture |
Uniform Weight Mip Maps, Trilinear Filtering |
lower_mip_texel = (higher_mip_texel1+higher_mip_texel2+higher_mip_texel3+higher_mip_texel4)/4;
very easy, very fast but also very bad at keeping detail. There are many better filters out there with varying quality/performance tradeoffs but I thought it worth trying a quick and simple change to weight the pixels by their approximate luminosity, calculated by simply averaging each source texel's red, green and blue channels clamped to a chosen range:
higher_mip_texel_weight = Clamp((higher_mip_texel_red+higher_mip_texel_green+higher_mip_texel_blue)/3, 50, 255)
lower_mip_texel = (
(higher_mip_texel1*higher_mip_texel_weight1)+
(higher_mip_texel2*higher_mip_texel_weight2)+
(higher_mip_texel3*higher_mip_texel_weight3)+
(higher_mip_texel4*higher_mip_texel_weight4)/
(higher_mip_texel_weight1+higher_mip_texel_weight2+
higher_mip_texel_weight3+higher_mip_texel_weight4);
This then favours brighter texels which will be more visible in the final render. Using this code to generate the mip maps instead of the uniformly weighted filter produced immediately better results:
Luminosity Biased Mip Maps, Trilinear Filtering |
The next step then is to stop using trilinear filtering at runtime and instead switch to anisotropic filtering where the filter kernel shape effectively changes with the aspect of the textured surface on screen so the GPU can for example filter a wider area of the texture in the 'u' axis than it does in the 'v' and has more information for choosing the mip level to read each filter sample from. Returning to the original uniformly weighted mip maps where the lines disappeared so early but switching to anisotropic filtering produces noticible better results than either attempt so far:
Uniform Weight Mip Maps, Anisotropic Filtering |
Luminosity Biased Mip Maps, Anisotropic Filtering |
So why not use anisotropic filtering all the time? well it comes down to compatibility and performance, not all legacy GPUs can support it although most modern cards can and even on cards that do there is a performance cost as the GPU is having to do significantly more work - the effects speak for themselves though and going forward I expect it will become the default setting for most games to avoid over-blurry textures as objects move away from the near plane.
No comments:
Post a Comment
Comments, questions or feedback? Here's your chance...