Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Romano · May 30, 2019 at 09:19 AM · cameraaudiosourceparticlesystemparticle

Is there a way to get the number of particles from a single particle system being rendered on a particular camera?

Does anyone know of a way to get the number of particles from a single particle system that are currently being rendered on camera? So the number should exclude particles that are being emitted but not currently being rendered.

This would be useful for something like emitting a swarm of bees from a particle system and having the volume of the sound the bees make relative to how many are on screen. This might ordinarily be done by increasing the volume as you increase the proximity to the particle system, but here I'm looking for a more direct link between the particles you can see and the audio volume.

Thanks very much!

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

Answer by richardkettlewell · May 30, 2019 at 09:43 AM

(Or, if it's just one camera per frame, you could do all the testing and maths in script via GetParticles or the C# job system API, but it might be quite expensive)

Comment
Add comment · Show 3 · 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 Romano · May 30, 2019 at 10:06 AM 0
Share

Thanks for the extensive answers! Can you give me an idea of how this would be done with GetParticles and the C# job system? I had a look at GetParticles, but couldn't see how I'd use it since there's no OnBecameVisible() for non $$anonymous$$onoBehaviours.

avatar image richardkettlewell ♦♦ Romano · May 30, 2019 at 10:25 AM 0
Share

First, you would have to get hold of the camera you want to test against in your script. Then test if particlesystemrenderer.bounds is inside the camera frustum. If it is, call GetParticles. Then, for each particle, build a bounding sphere using particle.position and the max dimension of particle.size.xyz (if using 3d size). Then test that sphere against the camera frustum too.

You can probably google for how to test if boxes and spheres are visible to unity cameras, if you don't already know how, e.g. https://answers.unity.com/questions/8003/how-can-i-know-if-a-gameobject-is-seen-by-a-partic.html links to GeometryUtility.CalculateFrustumPlanes and GeometryUtility.TestPlanesAABB docs pages.

avatar image Romano richardkettlewell ♦♦ · May 30, 2019 at 10:41 AM 0
Share

This is great, thank you very much!

avatar image
0

Answer by richardkettlewell · May 30, 2019 at 09:41 AM

There is nothing built-in for this - we don't do any kind of per-particle visibility checking.

To do it, if you really want to, you would need to:

  • Write a custom shader to detect and count the number of onscreen vertices (InterlockedAdd, if the vertices are within the view, eg projected coords are in the -1 to +1 range)

  • Store the count in a ComputeBuffer (StructuredBuffer)

  • Use the async readback API to efficiently get the number of rendered verts back to the CPU

  • Divide the result by 4, because each billboard particle is made up of 4 vertices

  • Set the volume of the audio based on the result

It's pretty complicated! :)

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

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

Related Questions

How to get a ParticleSystem to play when you can't see it's origin point. 0 Answers

How to stop Particles from rotating with camera? 6 Answers

need to hide areas of large particle system 0 Answers

Two Particle Systems 1 Answer

Unculled particle system rendering 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