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 vyndor · Jul 24, 2014 at 03:27 PM · texturetexture2drendertexture

Copy non-rectangle part of one texture to another

How can I save part of one texture to another? I want just set 4 verticies and interpolate inner region to another texture. For now I know how to do it with additional ortographic camera and RenderTexture. Is there any better way?

Thank you.

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

Answer by DajBuzi · Jul 24, 2014 at 07:00 PM

If i understand correctly then you want to cut some pixels from one texture and paste them in to another texture? If so, just use texture.GetPixels(x, y, w, h) to get pixels you need then if the shape isnt squared just shape it through loop, and set pixels that you dont need to new Color(r,g,b, / alpha100% / 1.0f); and then get pixels from your target texture using the same method and check if your copied pixels have 100% alpha if so just do paste them. :o

 void CopyPixels(int x, int y, int w, int h){
     Color[] clrs = From.GetPixels(x, y, w, h);

     Paste(x, y, w, h, clrs);
 }

 void PastePixels(int x, int y, int w, int h, Color[] clrs){
     Color[]change = To.GetPixels(x, y, w, h);
     for(int i = 0; i < change.Length; i++){
         if(clrs[i].a == 1.0f) continue;
         else change[i] == clrs[i]);
     }

     To.SetPixels(x,y,w,h, change);
 }

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 vyndor · Jul 29, 2014 at 11:09 AM 0
Share

If I understand correctly, you advice to interpolate region manually. It seems to be a way more slow than additional ortographic camera and RenderTexture (I assume it will be rendered at GPU). Thanks for reply!

avatar image
0

Answer by BarShiftGames · Jul 16, 2020 at 12:49 AM

@vyndor

Hey I'm looking for a similar thing, copying a non-rectangular area onto another texture so it interpolates the space properly (as in, not an area defined by 90 degree angles, but more like a stretched polygon with 4 sides) and I can't figure out what you mean in your extra final comment about an orthographic camera and a render texture, could you enlighten me hopefully? My project has been stalled for a long time because I can't figure this out.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Texture2D GetPixel returns the same value everywhere 2 Answers

How do I initialize a float texture by script? 1 Answer

Using Texture2DArray as RenderTarget and passing data to fragment shader 2 Answers

GetPixels of RenderTexture 3 Answers

Get RenderTexture 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