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 Fressbrett · Nov 23, 2018 at 12:17 AM · gpusimulationcompute shaderinstances

GPU instancing and collision detection in flocking behaviour simulation

Hello!
I am working on a project that requires me to simulate flocking behaviour.

CPU calculations can't get me far enough

My current approach calculates the flocking using the CPU, which maxes out the amount of possible boids (an object part of the swarm) at around 1500 instances, since each instance has to compare to all other instances in order to create true flocking behavior.
There are some other approaches like Physics.Overlapsphere or using Octrees instead of iterating over a full reference list or making use of ECS.
All of these CPU approaches won't get me over 2k Boids though.... but I need at least 4-5k boids that check collisions or distances to other objects in the scene.

GPU computing for bigger swarms
I have looked into compute shaders for this purpose, there is GPU flocking project out there that makes use of compute shaders and successfully simulates 32k boids at once, which is an insane amount!

However, these simulated instances do not collide or interact with the scene, aka other Monobehaviours. I need my boids to avoid obstacles, which currently works by registering collision and applying an opposite "fear force" onto the steering direction calculation.

My Question
Is it possible to register collisions with those GPU instanced objects? Are there other approaches that would work better, for instance ECS and GPU computing? Any suggestions on how to approach this are appreciated.

Comment
Add comment · Show 2
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 TonicMind · Nov 23, 2018 at 01:13 AM 0
Share

To me it sounds like you're using an O(n^2) algorithm to direct your boids... However you've not posted any code so I can't help much with that. What I would do if I were you is to try a different method. This does sound a lot like the algorithm for flocking presented in a book I've read (the algorithm is limited by it's time complexity). I say so because you mention

"since each instance has to compare to all other instances in order to create true flocking behavior."

Something you might try is to have your boids sense ONLY the immediate area about them and let the flocking happen organically via parameter adjustment ins$$anonymous$$d of iterating through your flodk checking neighbors for flocking directions.

So let's try this in an OOP algorithmic approach:

Define your boid script so that it has a reference to a trigger collider attached to itself. Define an ontriggerentered() method as per the unity API, which steers the boid while it has anything to flock with (ie. It is within the trigger sphere of a given radius) and is part of your flock by checking the layer given to the object which called the ontriggerentered () method.

If you want to tweak the algorithm using this same method but you want to limit it's visual range to some degree forward, you can perform the dot product on each object within the sphere within ontriggerentered(), and if it exceeds a certain value ignore the inject on your flocking behavior.

Work smarter not harder! :)

avatar image Fressbrett TonicMind · Nov 23, 2018 at 05:40 PM 0
Share

This is actually what I am doing currently, but it doesn't really boost performance. The boids move a lot, thus they get in and out of trigger spheres a lot. When using triggers, you have thousands and thousands of trigger calls every movement update. Physics.Overlapshere is the less resource intensive than using triggers. But still, it doesnt get me above my 2k boids. I need to utilize the GPU.

A huge resource saver was to update each boids movement direction only every 0.2 sec, calculate a future position and interpolate in the update to that position.

0 Replies

· Add your reply
  • Sort: 

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

97 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

Related Questions

3D array flattening / unflattening to / from compute shader 1 Answer

How to launch multiple instances of multi-display across local network?,How to run multiple-instances of multi-display? 1 Answer

[Compute Shader] Porting an Image Effect Shader - Kuwahara Filter 2 Answers

Pass ComputeBuffer to another ComputeShader 0 Answers

Custom colliders on the GPU 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