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
3
Question by luqui · Nov 19, 2010 at 09:30 AM · performancetexture2dgrid

Fastest way to draw a grid of textures

I'm making a 2D game in which we draw a 200x200 grid of textures -- the pieces on the board. Each cell can only be one of about ten different textures. There are small changes every frame -- a piece dies here, one becomes born there, but most stay where they are. Right now we are drawing it by allocating a GameObject, a textured quad, for each nonempty cell. But when most of the board is filled with pieces, this really starts to be a framerate drag. I'm wondering if there is a better way to do this.

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

2 Replies

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

Answer by tchen · Dec 04, 2010 at 08:02 AM

Subdivide your grid world into groups. 10x10 sized chunks for instance. Render those to texture as their component tiles change. And then from that, render your 400 set of chunks. That's still a lot of draw calls, so I'd probably group them even more. Try 20x20 size chunks?

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
avatar image
3

Answer by duck · Nov 19, 2010 at 10:04 AM

For this kind of thing, normally, you'd probably want to generate grid mesh procedurally in code, where each grid tile is a 2-tri quad with unique vertices (not shared with its neighbours).

You'd then put every texture option on to a single large texture (a.k.a. a "Texture Atlas").

Finally, you'd adjust the UV coordinates for each quad so that it displays the correct portion of the texture atlas - which means it would display the correct tile out of your selection of tiles.

However Unity (like many other game engines) has a maximum limit of 65536 vertices per mesh, and for 200x200 tiles x 4 vertices each, this gives you 160,000 vertices, so this throws a spanner in the works.

If your design is flexible enough to change the grid size down to about 120x120 instead of 200x200, this solution could work for you.

If not, you'll have to start with the above method, but modify it so that it breaks it up into a number of separate meshes so that each individual mesh doesn't exceed the maximum vertices.

Comment
Add comment · Show 2 · 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 luqui · Nov 19, 2010 at 10:24 AM 0
Share

Doesn't adjusting the UV coordinates involve updating the entire mesh, which as I recall is not an entirely cheap operation? We have to change it a little bit every frame.

avatar image Proclyon · Nov 19, 2010 at 10:29 AM 0
Share

Duck's answer segment to code/script/programmatically solve the grid generation can not be overstated enough. When you look at a 2D Grid that's out of bounds. Think about a 3D grid (concept) Where every change extends into the depth of the second 2D grid. 3D can be seen as a ton of 2D lines (CAT scan PET scan) you can mimick this in your split-grid if you know a bit of code and numbers.

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

No one has followed this question yet.

Related Questions

Is operating using GetRawTextureData faster that doing SetPixel/Pixels? 2 Answers

Better performance? GUITextures or Texture2D drawn in function OnGUI? 0 Answers

Dynamic Grid - A design problem. 0 Answers

Draw tilemap with Texture2D.SetPixels: Performance and Memory? 0 Answers

Performance While Loading Map 2 Answers


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