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 user-12539 (google) · May 08, 2011 at 03:33 PM · textureresizecompressionflatquack

Combining textures - Flatten effect.

I'm trying to create a single, "flattened" texture from a set of others. Basically, a new texture is created, and each from the set is drawn onto it, so any transparent parts will show through to the texture behind it.

I keep getting "Can't Resize to a compressed texture format.", but I haven't been able to get rid of that error no matter what I do.

Might anyone have some suggestions?

using UnityEngine; using System.Collections; using System.Collections.Generic;

public class TextureCombineUtility : MonoBehaviour {

 //Call TextureCombineUtility.Flatten([textures]) in order to create a new, single texture from multiple layers.
 public static Texture2D Flatten (Texture2D[] combines) {

     //The new texture.
     Texture2D newTexture = new Texture2D(0,0);

     //Resize the new texture to match the largest texture.
     foreach(Texture2D resizeTex in combines) {
         if(resizeTex.width > newTexture.width) {
             newTexture.Resize(resizeTex.width,newTexture.height);
         }
         if(resizeTex.height > newTexture.height) {
             newTexture.Resize(newTexture.width,resizeTex.height);
         }
     }

     //Resize each layer to match the new texture, and draw the layer onto the new texture.
     int i = 0;
     int l = combines.Length;
     while(i < l) {
         int xx = newTexture.width;
         int yy = newTexture.height;

         Texture2D addTex = new Texture2D(xx,yy,TextureFormat.DXT5,true);
         addTex = combines[i];
         addTex.Resize(xx,yy,TextureFormat.DXT5,true);

         int x = 0;
         int y = 0;
         while(y < yy) {
             while(x < xx) {
                 Color mainPixel = newTexture.GetPixel(x,y);
                 Color newPixel = addTex.GetPixel(x,y);
                 mainPixel = Color.Lerp(mainPixel,newPixel,newPixel.a);
                 newTexture.SetPixel(x,y,mainPixel);

                 ++x;
             }
             ++y;
         }
         ++i;
     }

     return newTexture;
 }

}

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
0
Best Answer

Answer by DaveA · May 08, 2011 at 05:56 PM

Try using TextureFormat.ARGB32 instead of DXT5. Then use Compress at the end

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 user-12539 (google) · May 09, 2011 at 03:06 PM 0
Share

This led to the answer! What was also required was some repairs to my while statements; before ++y, x=0;, and before ++i,y=0;.

Thanks for your help!

avatar image
0

Answer by Sa0Lin · Sep 24, 2012 at 07:42 PM

Hello. I used your script, and made an object with a MeshRenderer and changed it's material's texture to the return value of your Flatten function. I added 5 textures as parameters but the result is a texture created from other 5 textures that i have in the project.

 public Texture2D[] tex;
 
 //added 5 textures that are Imported using Advance setting and compressed using ARBG32, all the same size.
     
 void Start(){
    renderer.material.mainTexture = TextureCombineUtility.Flatten(tex);
 }
 
 //the result is a texture formed by other 5 textures from my project, and those are not passed as the params.
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

1 Person is following this question.

avatar image

Related Questions

How to find what texture compression was forced for build? 1 Answer

Why does texture compression not reduce the size of my levels? 0 Answers

Default Texture Platform/Format settings 2 Answers

Texture Compression 1 Answer

Which texture settings will perform best (in theory) 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