• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
5
Question by capnbishop · Jan 17, 2010 at 07:58 PM · graphicstexture2d

How do I generate mipmaps at runtime?

How do I generate mipmaps at runtime for a texture which is loaded using the WWW class? I can load this texture at runtime and apply it to a material, but mipmaps aren't automatically generated. Does Unity have a runtime function to do this, or will I have to create my own script to generate mipmaps using SetPixels?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
10
Best Answer

Answer by duck · Jan 17, 2010 at 09:40 PM

Having skimmed the docs, I can't see a built in method to do this. Perhaps you could make use of the fact that "Apply()" auto-generates mipmaps by default.

Try myTexture.Apply(); on its own after getting the texture first. If that doesn't work you could venture into 'ugly hack' territory by trying this to force a draw using SetPixels which would then hopefully make 'apply' do its thing (just a guess, untested & may not work!):

myTexture.SetPixels( myTexture.GetPixels(0,0,myTexture.width,myTexture.height) );
myTexture.Apply();

If that doesn't work, it may be that there's something different about WWW.texture, and perhaps you have to use WWW.LoadImageIntoTexture to load the image into an existing Texture2D rather than just using WWW.texture directly (and perhaps even try the above things on the texture afterwards).

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image capnbishop · Jan 17, 2010 at 11:58 PM 1
Share

Using Texture2D.SetPixels(Texture2D.GetPixels()) works great. Thank you.

avatar image capnbishop · Jan 18, 2010 at 12:01 AM 1
Share

Specifically, this must be done on a fresh texture, so the actual code will end up looking a little more like this:

var tex1 = www.texture; var tex2 = new Texture2D(tex1.width, tex1.height); tex2.SetPixels(tex1.GetPixels()); tex2.Apply(true);

avatar image bcsanches · May 06, 2011 at 01:37 AM 0
Share

Also here it only works when creating a new texture.

avatar image pld · Aug 27, 2016 at 01:39 AM 0
Share

Eric5h5's answer is now the best answer.

avatar image
7

Answer by Eric5h5 · Jan 17, 2010 at 09:42 PM

Create a texture first that has mipmaps, then use WWW.LoadImageIntoTexture.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image pld · Aug 27, 2016 at 01:52 AM 0
Share

Note that the texture you create must have mipmapCount >= 2. So if you create a 1x1 dummy texture with mips and pass it to WWW.LoadImageIntoTexture, you will be sad.

avatar image
2

Answer by gwfuserPS · Sep 14, 2015 at 11:41 PM

Set the 4th parameter to true it will enable the mipmap.

Texture2D(int width, int height, TextureFormat format, bool mipmap, bool linear)

http://docs.unity3d.com/ScriptReference/Texture2D-ctor.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Texture2D.PackTextures causing seams in atlas? 0 Answers

Convert System.Drawing.Bitmap to Texture2D 0 Answers

technique used to simulate oil in game "feed me oil" 0 Answers

Alternative for Graphics.CopyTexture() ? 0 Answers

What are possible causes and solutions to randomly garbled textures on standalone builds? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges