Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
11 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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

4 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
3

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
avatar image
0

Answer by denevraut · May 25 at 02:54 PM

I found this solution for me, all the others gave me errors (unity 2019.2)

Hope it can help you !

 var dstTex = Texture2D(srcWidth, srcHeight, srcFormat, true);
 Graphics.CopyTexture(srcTex, 0, 0, 0, 0, srcWidth, srcHeight, dstTex, 0, 0, 0, 0);
 dstTex.apply(true); 

References:

https://docs.unity3d.com/2019.2/Documentation/ScriptReference/Graphics.CopyTexture.html

Graphics.CopyTexture(Texture src, int srcElement, int srcMip, int srcX, int srcY, int srcWidth, int srcHeight,

Texture dst, int dstElement, int dstMip, int dstX, int dstY);

https://docs.unity3d.com/2019.2/Documentation/ScriptReference/Texture2D-ctor.html

Texture2D(int width, int height, TextureFormat textureFormat, bool mipChain);

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Crunch compressed textures are not supported with CopyTexture 0 Answers

Unity3D texture2d error help 0 Answers

Graphics.CopyTexture and location fo textures 0 Answers

How can I draw a part of a texture on a another texture with transparency? 2 Answers

Shaders: How heavy is tex2D()? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges