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
2
Question by $$anonymous$$ · Jul 16, 2014 at 01:34 PM · sprite renderer

Sprite Renderer Performance

We are developing a 2D Game with many sprites.

Only the background has 729 sprites. These sprites are semi transparent.

All sprites are in one atlas; so that our draw calls are relatively ok; maximum 20 draw calls due to layering system we use.

Each sprite has 2 vertices; so there are 1458 vertices just for background. Although background is created dynamically it is static.

What would be the best approach to take a snapshot of the background image and use it as a single sprite? If we disable those sprites; FPS increases.

I told background is static; but actually it is moving; but it moves as a whole. It is semi-transparent and actually there is a "real static" background image.

Comment
Add comment · Show 1
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 SmashingSuccess · Dec 21, 2016 at 08:58 PM 0
Share

Do you still have any information regarding this? I'm having a similar problem on my project and your link to documentation no longer works.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by $$anonymous$$ · Jun 11, 2015 at 05:01 PM

We figured out hat this can be solved with http://docs.unity3d.com/Manual/class-RenderTexture.html.

However; with proper sorting; draw calls dramatically reduced to 2-3 calls; so we did not need id.

Edit: Later on we need it for some other performance enhancements :) here how the code looks like:

@SmashingSuccess here is the code:

 public class Photographer : MonoBehaviour
     {
         public Camera MasterCamera;
         public Camera SelfCamera;
         public SpriteRenderer BackgroundDisplayer;
 
         public LevelBuilder CurrentLevelBuilder;
         public LayerMask Layer1;
 
         public void TakeShot()
         {
             SelfCamera.transform.position = MasterCamera.transform.position;
             SelfCamera.orthographicSize = MasterCamera.orthographicSize;
 
             var w = SelfCamera.pixelWidth;
             var h = SelfCamera.pixelHeight;
 
 
             //Background
 
             SelfCamera.cullingMask = Layer1;
             var texture = new RenderTexture(w, h, 0, RenderTextureFormat.ARGB32);
             SelfCamera.targetTexture = texture;
             SelfCamera.Render();
 
             RenderTexture.active = texture;
 
             var textureFormat = TextureFormat.RGB24;
 
             //https://issuetracker.unity3d.com/issues/error-regarding-invalid-textureformat-when-calling-supportstextureformat
 #if UNITY_ANDROID
 // if (SystemInfo.SupportsTextureFormat(TextureFormat.ETC_RGB4))
 // {
 //    textureFormat = TextureFormat.ETC_RGB4;
 // }
 #elif UNIT_IOS
 // if (SystemInfo.SupportsTextureFormat(TextureFormat.PVRTC_RGB4))
 // {
 //    textureFormat = TextureFormat.PVRTC_RGB4;
 // }
 #endif
 
             var virtualPhoto = new Texture2D(w, h, textureFormat, false);
             virtualPhoto.name = "PhotoBackgroundTexture";
             var r = new Rect(0, 0, w, h);
             virtualPhoto.ReadPixels(r, 0, 0); // you get the center section
             virtualPhoto.Apply();
             var bg = Sprite.Create(virtualPhoto, r, new Vector2(0.5f, 0.5f), 100f);
             bg.name = "PhotoBackgroundSprite";
             RenderTexture.active = null;
             BackgroundDisplayer.sprite = bg;
 
             SelfCamera.targetTexture = null;
             Destroy(texture);
 
 
             var scaleNeeded = 100 * (MasterCamera.orthographicSize * 2) / h;
             BackgroundDisplayer.transform.localScale = new Vector3(scaleNeeded, scaleNeeded, scaleNeeded);
 
 
             SelfCamera.enabled = false;
             BackgroundDisplayer.enabled = true;
 
             MasterCamera.clearFlags = CameraClearFlags.SolidColor;
 
             var all = GameObject.FindGameObjectsWithTag("ToBePhotographed");
             for (var i = 0; i < all.Length; i++)
             {
                 Destroy(all[i]);
             }
             Destroy(gameObject);
         }
     }

SelfCamera is responsible to take screenshot. It only renders "Layer1". All other cameras; renders everything except "Layer1". Items who are going to be photographed are tagged with "ToBePhotographed" and are configured to be rendered in "Layer1". After screenshot is taken; they are destroyed..

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

2 People are following this question.

avatar image avatar image

Related Questions

How do you change a sprite's sorting layer in C#? 6 Answers

How to change color property of the Sprite Renderer in C# 1 Answer

changing the scale of sprite changes its position center?,changing scale of 2d sprite 1 Answer

Sprite not showing in spriteRenderer 2 Answers

why blurry effect on moving sprites 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