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 Nidre · Apr 01, 2013 at 08:16 AM · mobileoptimizationpolygon-countfillrate

Star Field - Lots Of Poly or Transparent Texture

I am developing a space game which will work on Android and iOS devices.We are tying to target as much as devices as we can.While developing it i have faced a simple problem.I have to make decision but since i couldnt test on many devices i dont have a spesific idea that i can accept as correct way on my own. So what im asking is a little bit explanation about which method from the below could be better and why ?

Scenerio:

There will be a 2d low vert simple plane which contains space texture. I need to add stars with a different y position to have a feeling of depth. (I'm using a perspective camera to have this feeling.They look like they are moving in different speeds due to distance)

1st option : adding a stars texture on top of the space texture with a different plane and alpha blend them.That would cause a lot of fillrate due to lots of transparent areas.

2nd option : I would add little meshes in the shape of stars with very less or no transparent.That would mean a single mesh for each star and a lot of polys/verts.

3rd option : Im glad to hear any option of yours :)

Comment
Add comment · Show 12
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 Chronos-L · Apr 01, 2013 at 09:38 AM 1
Share

How about a particle system? Build a particle system with roughly about 300-600 motion-less particles at any given time, set the lifetime to long, do something tweaking etc. You can give this a go, it will takes just 5-10 $$anonymous$$utes to setup a prototype.

avatar image Nidre · Apr 01, 2013 at 09:56 AM 0
Share

That sounds quite similar to the mesh approach since it will also create a lot of meshes for particles.I am not sure but how would that give a better performance then the solutions above ? Don't take me wrong,im just trying to find the most optimum way to do this. So if you think particles are more optimum i would like to hear why in more depth if you can clarify ? :)

avatar image whydoidoit · Apr 01, 2013 at 10:19 AM 0
Share

The particle system will be a single draw call and will handle the batching better than the other automatic options.

avatar image whydoidoit · Apr 01, 2013 at 10:22 AM 1
Share

$$anonymous$$ind you - any form of transparency is a nightmare on iOS/Droid - so perhaps you'd want to use a non-transparent shader - or build your own "combined" star mesh to mean that your code only needed a single draw call. In terms of shaders:

  1. Do not use a cutout shader on mobile - the fragment discard damages optimisation badly

  2. Perhaps as stars are small transparent won't really mean a lot of overdraw - it depends on the order of the shaders (I guess do the stars first!) and the number of them

avatar image Nidre · Apr 01, 2013 at 10:26 AM 0
Share

So if i understood you correctly you suggesting the second option with a optimized shared,am i correct ?(Btw i will share material and texture so it would be 1 draw call anyways)

Show more comments

1 Reply

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

Answer by whydoidoit · Apr 01, 2013 at 10:50 AM

Sure - you make a single mesh - but it's going to contain a whole lot of sets of billboards, one for each star (this is what dynamic batching / static batching is doing for you BTW, but it has limits).

BTW this is very similar to the legacy particle system's renderer - which is why I thought that was a good idea!

If the stars are moving then you will update these billboards (quad made of two triangles) each frame, you will certainly want to rotate them to face the opposite direction to the main camera's forward vector).

Off the top of my head the step would be:

  • Decide on the number of stars - maximum for one mesh would be around 16k

  • Create a mesh object

  • Create an array of Vector3s for the vertices

  • Create an array of Vector2s for the uvs

  • Create an array of ints for the triangles

  • Create the initial points (can stick them all at 0,0,0) for now -

  • map the UVs of the 4 points of each quad.

  • Create the six triangle entries for each quad referring to the 4 vertices

  • Update the mesh

From now on you just need to modify the vertices each frame. Keep the vertices array, update it and then set it back into the mesh each frame.

Then you need to move those vertices to the stars position in the game each frame and rotate them so that they face the negative of the Camera.main.transform.forward. Basically a star would have a position but not a rotation, you could store them in a List or a Vector3[].

Now the hard part - make the quad face the camera at the right position. Your meshes renderer would be set at 0,0,0 and you would have set the bounds for the mesh to be really huge so that it always renders.

For each of your stars you would move the position of the vertices. Actually a simple way of doing that is have a dummy object that you:

   dummyTransform.forward = -Camera.main.transform.forward;

Before your loop setup a vertexIndex to 0 - then for each star:

  dummyTransform.position = startPosition;

And then update the 4 vertices:

              points[vertexIndex++] =  dummyTransform.TransformPoint(topLeft); 
     /* Top R 1 */ points[vertexIndex++] =  dummyTransform.TransformPoint(topRight); 
     /* Bot L 2 */ points[vertexIndex++] =  dummyTransform.TransformPoint(bottomLeft); 
     /* Bot R 3 */ points[vertexIndex++] =  dummyTransform.TransformPoint(bottomRight); 
Comment
Add comment · Show 5 · 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 whydoidoit · Apr 01, 2013 at 10:52 AM 0
Share

Where topLeft etc are the forward facing corners of a billboard in local space.

avatar image whydoidoit · Apr 01, 2013 at 10:54 AM 0
Share

I do that for mobile impostor trees - which are slightly more complex than stars - but a particle system will take a lot of the weight of that for you. If you like the control then write your own - otherwise use a particle system and adjust the particle positions yourself if you want to.

avatar image Nidre · Apr 01, 2013 at 11:04 AM 0
Share

If i understood correctly this would create a very organized,pattern like star field ? But i got your point since we map each star to the meshes there would be $$anonymous$$imal unnecessary transparent pixels which would boost the performance.$$anonymous$$aybe i can work on this idea to create a bit more irregular star field.

avatar image whydoidoit · Apr 01, 2013 at 12:11 PM 0
Share

This would create a series of stars that you could move independently - perhaps I've missed what you are after?

avatar image Nidre · Apr 01, 2013 at 12:22 PM 0
Share

Hmm ok ok i just understood you wrong.Now its clean when u said "This would create a series of stars that you could move independently".

Well i cant choose your comment as correct answer so if you conver it to an answer i would gladly mark it as answer :)

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

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

Related Questions

Setting Material Textures at runtime for the rest of the game 0 Answers

Should i bake the skinned mesh? 1 Answer

Why is my camera motion so jittery? 3 Answers

Why did my render time increase after lowering the vertex count? 2 Answers

Fixing fill rate issue on Android - best approach? 0 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