Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
2
Question by Tyler 10 · Jul 15, 2011 at 06:58 PM · texture2duvcopypaste

Copy Paste multiple Texture2d's Into New Texture2d

Hey guys, thanks for looking at my question.

I want to take say a shirt from one texture 2d and the skin of another, and copy them onto the same texture at runtime. I see ReadPixels()/SetPixels() in the script reference but I think these will overwrite all the pixels.

Does anyone have experience with merging texture2d's?

I need something like ActionScript 3 has - copyPixels(blendMode etc. . . ). Any ideas? Thanks again for reading!

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

1 Reply

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

Answer by Tyler 10 · Jul 20, 2011 at 05:09 PM

If anyone finds this question while searching I figured it out. I wrote this function to combine textures. I am using this to copy different shirt textures and tattoo textures onto one skin texture. You basically just get the pixels from each map and then set your new map to the combination of the two using the second maps alpha as the lerp % between pixel a and pixel b. The maps need to be read/write enabled and be RGBA32 and the same height and width. You could easily write something generate the mips and all that as well if one was so inclined. Thats all I got gentlemen.

 public static Texture2D CombineTextures(Texture2D aBaseTexture, Texture2D aToCopyTexture)
 {
     int aWidth = aBaseTexture.width;
     int aHeight = aBaseTexture.height;

     Texture2D aReturnTexture = new Texture2D(aWidth, aHeight, TextureFormat.RGBA32, false);
             
     Color[] aBaseTexturePixels = aBaseTexture.GetPixels();
     Color[] aCopyTexturePixels = aToCopyTexture.GetPixels();
     Color[] aColorList = new Color[aBaseTexturePixels.Length];

     int aPixelLength = aBaseTexturePixels.Length;
     
     for(int p = 0; p < aPixelLength; p++)
     {
         aColorList[p] = Color.Lerp(aBaseTexturePixels[p], aCopyTexturePixels[p], aCopyTexturePixels[p].a);
     }
     
     aReturnTexture.SetPixels(aColorList);
     aReturnTexture.Apply(false);
     
     return aReturnTexture;
 }
Comment
Add comment · Show 3 · 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 soulburner · Apr 25, 2012 at 08:06 PM 0
Share

Thanks a lot for sharing!

I wonder, how fast is it...

avatar image Garth-Smith · Apr 11, 2013 at 08:28 PM 0
Share

Thanks for posting the answer. Almost two years later and it's still helpful to see such a good example of how to work with Texture2Ds.

avatar image TutiBueno2 · Oct 01, 2014 at 05:51 AM 0
Share

That was really helpful! Thanks!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Any way to copy and paste GameObjects programatically? 1 Answer

how do i copy and paste a texture? 1 Answer

Unity 3.5 can't display negative tiling in UV? 1 Answer

How can I convert the texture coordinates of the multi-spite to 0-1? 0 Answers

Copy / Paste As New not copying deep 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