Search Unity

Edit mipmaps

Discussion in 'External Tools' started by ivanmoen, Jun 28, 2009.

  1. ivanmoen

    ivanmoen

    Joined:
    Dec 26, 2008
    Posts:
    102
    Is there any way to edit the mipmaps generated by Unity, or create them manually?
     
  2. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    376
    Unfortunately there is no way to edit the mipmaps, or import pre-authored mipmaps.
     
  3. melmonkey

    melmonkey

    Joined:
    Mar 31, 2009
    Posts:
    373
    Sounds like a request for the Wish List.

    Support for importing DDS files would handle the ability to import mips, support for exporting images as DDS files from unity. including the generated mips, would handle the ability to edit the mips.

    Full I/O support for DDS files would suffice nicely.
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,603
    Unity is no DX engine, its a crossplatform engine, making DDS a little bit troublesome.
     
  5. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,536
    Oh, but Unity already supports that! (since Unity 2.1)

    So DDS files are one way to get in custom mipmaps. Another way would be to manually editing them in a texture import post-process script. This can be quite cumbersome though.

    DDS is just a file format that is documented and very simple. It originated from DirectX, but there's nothing in the file format that makes it unusable elsewhere.
     
  6. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,603
    I see
    I was under the impression (don't ask me why), that not the full set of capabilities it offers are usable outside of DX (where at least from what I've experience so far, especially the NVIDIA provided loader is beeing used)
    But thats potentially related to the fact that I've so far not seen any OGL engine that supports all those things in textures that DDS would have to offer.

    thank you for the clarification
     
  7. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,504
    I don't know anything about Unity...
    But if Unity eat the DDS, the mimapping subject is a Graphical-Card's work, isn't it?

    Basicaly I edit my mimap level with this Nvidia pulgins :

    http://www.nvidia.co.jp/object/photoshop_dds_plugins.html


    Does unity have to access to the DDS information for getting mipmap level or the graphical card do all the work?

    I know some rumor saying, if the graphical card get a Jpg, png, etc file, it will uncompress the picture like a BMP file...
    ... but if the graphical card get a DDS file, the graphical card doesn't need to uncompress the picture data and will take the mimap level on the same way in the dds...

    Does I have wrong? o_O? Does Unity have to do all this work?

    (I'm not a programmer but this is an interesting subject to me ^_^ )
     
  8. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,536
    Unity will read the mip levels from the DDS file. So yes, if you want to use NVIDIA's plugin to do custom mipmaps levels, just save the DDS with mip levels and it will work.
     
  9. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,504
    Thank you, you exactly answer to the question as well! ^_^

    Problem resolved :p
     
  10. the_motionblur

    the_motionblur

    Joined:
    Mar 4, 2008
    Posts:
    1,736
    ... at least for you. ;)
    Mac users still don't get the NVidia tools for Photoshop. And I also still don't know of any (free) comparable Plugin toolset or standalone.


    Good to know that about Unity and DDS files, though :)
     
  11. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,504

    Oh S***... I just remember an important thing... Game will be on iPhone -_____-......

    Then what about the iphone's graphical card? haha...
     
  12. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,504
    Seriously, does it works on iPhone?

    I recently heard some rumor saying the dds was working on PSP for 2 years... the iPhone plateform seems to be similar on the spec...

    Does someone know more about it? :eek:
    "Does the DDS file working correctly on iPhone with the mipmapping level?"

    Thank you by advance! :p
     
  13. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,504
    Alright I just got my answer..

    Modifying the mipmap level on Photoshop, Unity is more intelligent than Maya and will use it...

    But once the iPhone will only accept this kind of texture file :
    http://en.wikipedia.org/wiki/PVRTC

    Then I can't modify the mimpmap level...

    Or maybe... Does someone else know a good tips of that?
     
  14. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,625
    Just a note that Gimp 2.6.8p now includes the DDS plugin, even on Mac OSX. However, I so far have not found a way to actually save my own custom mipmap levels into a single DDS file. It can generate levels for you which is not what I want, and it can do some kind of `volume texture` but I don't think that's the same thing. It seems pretty comprehensive otherwise. It can load mipmap levels into layers but maybe not the other way around? If anyone knows otherwise please let me know.
     
  15. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,504
    Dunno on mac...

    But in Photoshop with Nvida plugin on PC, I can modify mipmap level manually and it will keep it.

    Problem is about Unity.
    And if you work with iphone it will erase your mipmap and create his own.

    I am not sure about it... but maybe Unity generate new mipmap level too from the beginning... We spoke about it last July then...

    But on Unity-iPhone we didn't find any issue to resolve this problem yet.
     
  16. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,603
    the iphone does not support DXT at all so having DDS is of the least use of all actually. The iphone native format would be pvr, for which imagination technologies offers a tool for at least windows to do such stuff (on osx you have apples command line converter) but I doubt Unity loads these pvrs actually
     
  17. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,625
    Hmm. Interesting.

    I think what I'm going to do is make a dummy texture and let Unity mipmap it, then get the mipmaps and write out my own pixels with SetPixels. Hopefully that should work.
     
  18. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,625
    Ok. So now what I want to do is basically generate my own mipmaps within Unity using scripting and drawing operations. I'll be using Texture2D.ReadPixels to grab the initial full-size texture. Then I will render the texture at a scaled down size (using bilinear interpolation or whatever) and grabbing those as mipmap levels. I could grab each of these into individual textures. However, I want to be able to grab directly into the actual mipmaps of a texture, OR be able to very quickly assign a texture to be used as a mipmap at a given level. I do NOT want to use SetPixels() as that involves copying pixels which is not what I want.

    Is there any way to do this or does Unity not have this functionality?

    An additional question.. if I let Unity recalculate the mipmap levels after the initial grab, does it generate those levels using the GPU to scale down and grab, or does it do it all with the CPU/re-uploading of textures like you would do with SetPixels (ie the slow way)?
     
  19. snlehton

    snlehton

    Joined:
    Jun 11, 2010
    Posts:
    95
    Sorry to bring up an old thread. I tried doing this, but it didn't work. I could write the mip map levels if "Generate mip maps" was enabled, but nothing happened. But when I wrote the mipmap level 0, the write went through, but it seems that the mipmaps are generated (again?) after that - so all the mipmap levels got the same modification as the mip map level 0.

    Is there truly a way to have custom mipmap generation or is this feature broken/unavailable?

    Cheers,
    Sampsa
     
  20. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    918
    I would like to add, since this topic is brought back, that I'm also looking for a way to cap the mip map level to 5 max (another voxel engine guy here). I've looked into DDS files, but apparently they aren't going to work for iOS and I'm also using a Mac. And I'm not sure how to handle this via shader. Any help would be appreciated.
     
  21. sfjohansson

    sfjohansson

    Joined:
    Mar 12, 2013
    Posts:
    293
    I just run into this problem too. I had to combine some textures to atlases to reduce draw calls, and that of course creates the mipmap problems...also working on mac and targeting iOS? Wanted to cap the mip map levels at first...any clever solutions around?
     
  22. bdev

    bdev

    Joined:
    Jan 4, 2011
    Posts:
    656
    I've been attempting to do this, and I do not think it to be possible in a broad approach.

    I set it up so that theres a seperate folder next to assets, where the directory names match the file path of the texture, then you would place in 1,2,3,4 ect .png in a folder named after the original file.

    The problem is that theres no way to supply the custom mip levels in OnPreprocessTexture, before conversion to the format (which may not always be modifiable) or the texture being marked as non readable.

    As far as the dds approach, it works but its painful. DDS textures do not have a TextureImporter applied to them, so you have to rely on the format they were saved as, plus no sprite generation and everything is marked as readable which in my case is pointless memory usage. Basically, unity does some magic with DDS textures and you're unable to actually configure them because the .meta has no import settings to modify any modifications to the texture which unity imports are not saved.

    So I deeply hope that one day unity will properly support custom mip maps that work in any format and support marking as non readable/sprite generation.

    The only way to do it right now would be making editor scripts which involve AssetDatabase.Create("Assets/bla.asset", blaTex); after configuring a texture. Again, I do not think it to be possible to set up a asset post processor to do this without limiting the formats used.
     
  23. spakment

    spakment

    Joined:
    Dec 19, 2017
    Posts:
    26
    For anyone else that ends up here, here's a link to a github repo that can manage custom mip map creation, via filenaming. Just add in filenames like this and it'll handle the rest, I can confirm it working with standard shader
    texture.png (the base mip0)
    texture.mip1.png
    texture.mip2.png
    texture.mip3.png

    https://github.com/azixMcAze/Unity-CustomMipMaps