Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Noise crime · Jun 10, 2010 at 04:59 PM · runtimetexturesresizescaledown

Dynamic texture resizing or switching between texture sets of different sizes at runtime

Just wondering if there is any native function in Unity to dynamically resize textures at runtime? Alternatively a simple way to swap out texture assets at runtime?

I need to be able to provide a single build that can work for someone with say 128mb, 256 or the target 512mb+. So depending upon the gpu ram, one of 3 different texture sizes will be used, however I certainly don't want to include all 3 versions of each texture in a single build. Essentially its just like how commercial games run, in which the textures are dynamically/pre-created in scaled down versions, so the game can easily run on different configurations of available ram.

For example back in good old Director I had two methods available. The first was to use a function called 'scaledown' which simply halved the size each time it was called on a texture. The second option was to store all the texture images in a single external cast library and then make two versions, one full size, the other all half size. Then at runtime you could just load the appropriate castlibrary. Actually there is a third, which would be to have all texture images imported as 'linked' and simply change the pathname at runtime.

I can't find a similar function to 'scaledown' and suspect that since Unity doesn't appear to include the source images in a build, it wouldn't be possible?

I guess I could import the textures at runtime, but not sure if I lose some of the benefits of having them in the editor, such as setting values in the inspector?

AssetBundles may work for this, though i'm still looking into them so not sure of their requirements or restrictions.

So i'm wondering how do other developers approach this situation?

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

2 Replies

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

Answer by Noise crime · Jun 11, 2010 at 09:59 PM

Stumbled upon the answer (at least it will do for now) in Edit->Project Settings->Quality inspector, where you can set the 'Texture Quality' to 'full res', 'half-res' etc, with each Quality mode having its own setting.

Yet to test it fully, but should suffice for my needs.

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
2

Answer by Mike 3 · Jun 10, 2010 at 05:06 PM

If you let unity calculate mipmaps, you can just use GetPixels(mipmapLevel) and it'll give you pixels back relating to a texture which is the next power of two down for each level

That way you can easily make a new texture from those pixels

Edit:

You could do something like this to half the original texture, as long as the texture is readable:

Texture2D temp = new Texture2D(originalTexture.width / 2, originalTexture.height / 2);
temp.SetPixels(originalTexture.GetPixels(1));
temp.Apply();
byte[] png = temp.EncodeToPng();
Destroy(temp);
originalTexture.LoadImage(png);

It's a little bit of a roundabout method, but you could wrap it in a function and make it half any texture

Comment
Add comment · Show 2 · 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 Noise crime · Jun 10, 2010 at 05:48 PM 0
Share

Nice answer, though probably impractical as that would mean having all the textures already loaded. I'm looking at possibly in excess of 512mb of textures that are all in view, so on a 256mb card that method would run out of memory? Though its definitely something i'll keep in $$anonymous$$d.

avatar image Mike 3 · Jun 10, 2010 at 06:11 PM 0
Share

Edited the post with an example way to do it - The alternative method would be to just destroy the original texture and use the new one, which wouldn't fill the graphics card up

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

Swapping Textures vs Swapping Meshes 1 Answer

Uploading textures to be used for 3d model at runtime? 0 Answers

How to change Textures after build the game? 2 Answers

How to load multiple textures and sounds 0 Answers

Change size of Mesh at runtime 3 Answers


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