1. Anders Ruud
  2. love
  3. Issues

Issues

Issue #446 resolved

MipMaps

Anonymous created an issue

Would it be possible to have mipmap support? The game I'm working on can zoom in and out quite a bit and I'm getting aliasing issues. I started implementing a solution to do it by hand but it's such a chore when any graphics card could do it for me a lot faster.

I would be nice to not have to have the mips in the source image files but instead have a call on the ImageData or Image along the lines of image:genMipMaps().

If it's easier a method like image:setMipMap(index, imageData) call where you have to down sample the images by hand and set them would be workable.

Comments (7)

  1. Seppi

    In the forums, there is a thread that references mipmaps: https://love2d.org/forums/viewtopic.php?f=4&t=1454

    imo, this would be a rather nifty library, but considering love does not handle mip mapping, bartbes's response of

    You can do a feature request, it seems it is easy to implement.
    

    seems rather to the point.

    Although, if you feel that the community could really use a library like this, you ought to consider writing a library for this, and adding it to https://love2d.org/wiki/Category:Libraries!

  2. Bart van Strien

    Did you try the nearest neighbor filtering mode yet, if you're getting scaling issues?

    Personally, I'm not sure there's a benefit to mipmaps, but maybe someone can convince me otherwise.

  3. Anonymous

    The benefit is in avoiding aliasing and also some minor performance improvement due to better texture cache usage. Nearest neighbour filtering does help a little but only in slightly smoothing aliasing artefacts, not removing them. Trying scaling an image with lots of high frequencies in it and it looks awful.

    I was thinking of writing a library but it won't play nicely with pixel effects (it would probably need to be implemented via a pixel effects itself). Also all rendering hardware these days can support it, seems perverse to implement it by hand.

    Tbh I might try and get a build to work on my machine again (failed due to not finding freetype2.lib, renaming the freetype lib didn't work IIRC) and try and submit a patch.

  4. Boolsheet

    I thought about mipmaps in LÖVE too and the following questions popped into my head:

    • What restrictions come with mipmaps? (OpenGL version(s), clamping, NPOT width and height, to POT padded images, ...)
    • Do the advantages outweigh the disadvantages of those restrictions?
    • How will it fit into the LÖVE API? Mipmapping is a rather technical term and while it is found in other graphics APIs, it binds the LÖVE API to the OpenGL behaviour. This may be unavoidable in some cases, but we should think about it anyway.
    • Can anyone think of something in LÖVE that might interfere with mipmaps?
  5. Alex Szpakowski

    While mipmapping is a fairly technical term, it's pretty API-agnostic (you'll find the same terminology for the same techniques in Direct3D, for example.) I also can't think of a friendly name that conveys the right sort of meaning.

    I have created a fork of LÖVE which has mipmapping support. You can find it here: https://bitbucket.org/slime73/love-mipmap

    Image:setFilter now takes an optional third argument (mipmap filtering mode, either "nearest" or "linear"). Mipmaps are auto-generated if not present when a mipmap filter is set. Image:setFilter called without a third argument will disable mipmapping.

    Due to driver/GPU issues on some older video cards when generating mipmaps for NPOT textures, my implementation will create an error if mipmap filtering is enabled on a NPOT image. Because of this, love.graphics.setDefaultImageFilter has not been changed to accept a mipmap filter argument - you can only enable mipmapping after the image has been created.

    A new Image method has also been added: Image:setMipmapSharpness(sharpvalue). A positive value means the GPU will use a larger-sized (less blurry) mipmap than normal when downscaling, and vice versa for a negative value. It is 0.0 by default. Internally, this sets the texture LOD bias of the image to the negated value of the sharpness.

    Performance improvements when drawing downscaled images with mipmap filtering are very impressive, especially when using an integrated GPU. Here's a screenshot comparison of a test .love using my Intel HD 3000 (the image was downscaled from 512x512). Performance was increased even further when the mipmap sharpness was 0, however the image appeared slightly blurrier.

    I have attached the test .love above (it requires a build of my fork.) Left/right changes the mipmap filtering mode, and up/down changes the mipmap sharpness value.

    Performance improvements with mipmapping are even greater when using a single repeating quad instead of a spritebatch or separate images.

  6. Log in to comment