• 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 dorpeleg · Apr 12, 2013 at 01:00 PM · texturerandomtexture2dgenerationface

Random 2D Face Generator

Hello everyone.

I want to have a 2D Face Generator that will generate a face from a couple of different textures.

Something like: select a random face texture, then select a random hair texture, then select a random beard texture etc.

And eventually display it with GUI.DrawTexture.

My problem is not the code.

I'm worried about performance if I use about 5 GUI.DrawTexture just to draw the face.

Is there a way I can select my random texture and then combine them before display? (so I can use only one GUI.DrawTexture)

Thanks!

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

Answer by robertbu · Apr 12, 2013 at 03:55 PM

You could use GetPixels()/GetPixels32() and SetPixels()/SetPixels32() to create a new texture that combines the textures, but I think you are borrowing trouble where isn't any. When I have questions like this one, I usually write a bit of code that stresses the area I'm concerned about. So write some code that instead of displaying 5 textures, displays 25 textures. Deploy it on the target platform and see about performance.

Comment
Add comment · Show 13 · 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 dorpeleg · Apr 12, 2013 at 04:02 PM 0
Share

It's never gonna be 25 (not in the near future anyways), so no need to over stresses it.

It's just that I already have like 700+ draw calls while in game and I want to try to save as many as possible.

I'm actually not sure if 700 is a lot, but I think it is :P

avatar image robertbu · Apr 12, 2013 at 04:17 PM 0
Share

700 is a bunch of draw calls but the proof is always running the app on the target platform. You may want to take a look at a more general solution for your game...a texture atlas comes to $$anonymous$$d. A texture atlas would reduce your face drawing to a single draw call and could be used to help batch other draw calls.

avatar image Owen-Reynolds · Apr 12, 2013 at 04:19 PM 0
Share

The point is, say you test with 5 textures, and think "hmmm...it sort of seems maybe laggy; if I spin it this way feels sluggish, or am I imagining it... ."

There's a good chance that if you test with 25 noise textures, if will run perfectly fine. Then you'll have zero nagging doubts over whether you should have used only 4, or whether you can afford an extra scar texture.

Likewise, if 25 runs like molasses, you'll know for sure you weren't imagining that slowdown with 5, and every texture does count.

avatar image dorpeleg · Apr 12, 2013 at 04:22 PM 0
Share

@robertbu "texture atlas" as in one texture to hold the pictures and then somehow only show the one you want?

I'm thinking about doing that regardless, I should help.

But back to the topic, you $$anonymous$$d showing me some example code of how to use the GetPixels()/GetPixels32() and SetPixels()/SetPixels32()?

Just in case i'll decide to use it :)

@Owen Reynolds "if I spin it this way feels sluggish" that's how I feel about it... so I'm just checking for other options.

avatar image robertbu · Apr 12, 2013 at 04:57 PM 0
Share

In Unity, if two object are simple enough (i.e. have fewer than 900 vertex attributes), and if they share exactly the same material, they Unity can (and usually does) batch the call together. It can make a substantial performance improvement. You can read more about batching:

http://docs.unity3d.com/Documentation/$$anonymous$$anual/DrawCallBatching.html

The problem is that if a two materials are not the same if they have different textures. A way around this is to use a texture atlas. That is two object share the material including texture, but each displays a different part of the texture using the UV coordinates in the model.

So in the case of your faces, you could display the five different layers on five different planes, but since you would be using a texture atlas, the five planes would be batched together and only require one draw call.

Third-party tools make building projects using atlases simpler than doing them by hand.

Show more comments

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Apply a particle effect to a texture 0 Answers

How to make a custom GUITexture at runtime? 2 Answers

Why is NativeArray always shorter than the number of pixels in the texture? 1 Answer

GUITexture dimensions constrained to Power of 2? 0 Answers

Texture rotation by renderer.material.SetMatrix 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