Good afternoon everyone, I would like to know if I can accomplish the task I need with the help of shaders.
I am now thinking about how to do the following correctly - I need a “controlled” crowd, that is, for each object I set the coordinates (points) along which it must pass, plus everything is an animated character.
I figured out the vertex animation, I bake the animation into a texture and play it with a shader. but at the moment it’s a gameobject with a meshrenderer.
moving a large number of gameobjects is expensive, but I came across examples where objects were moved on the stage without gameobjects, but using a computer shader.
I’m not familiar with the computer shader yet, I’m just starting out, so I would like to know about the possibilities right away, can I implement the following:
all objects must have an id, initially they are in the dictionary, then they must be displayed on the stage using a computer shader (without a gameobject).
These objects will periodically (about once a minute) receive coordinates (points) along which they will have to move.
I should be able to get the coordinates of all objects when requested (for example, once a minute), to update the database
these objects will use vertex animation, so they will be moving animated objects
Is it possible to attach colliders, a rigid body to such objects, or use rays to check a number of objects?
Don’t get me wrong, I don’t want a complete solution, I need to understand if I can implement this at all?
(If not, how can this be achieved?)
project windows, urp, 3d, expected number of animated objects 1000-5000…
Compute shaders run on the GPU (graphics card). They can’t control things like animation, colliders, object hiearchies, etc.* Those things are all done on the CPU.
You might want to look into ECS – new ECS modules can handle navigation, physics, animation, and all sorts of other things, and 5000 objects is easy for it to rip through.
However, I’d recommend first getting it to work with just GameObjects (and do 100 instead of 5000). Keep it simple, figure out all the logic, have something to work from. Then go from there, optimizing the parts you need. If all 5000 are on/close to the screen, you’ll need to simulate them all every frame… but if only 10 are on-screen at once, maybe you can get away with aggressive culling and never worry about ECS or other stuff like that.
Animaton and physics will be the slow parts. Moving 5000 cubes around with GameObjects is totally not a problem, even on mobile.
At least not in Unity. Trying to drive things like object position from the GPU will result in much worse performance than just doing it on the CPU.
but they said that animation cannot be used in entities … or is it possible? or is it necessary to combine objects between entities and without them?
I need to pass information to objects about where to move, while the objects themselves are animated, when they are small and there are a lot of them on the screen, then they turn on vertex animation, when they are large on the screen, then the animator and inverse kinematics work, and each object can be in any the moment to select and manage it manually, well, as I said, there can be several thousand of them.
I found a video demonstrating what I want to do https://www.reddit.com/r/Unity3D/comments/sdvked/100_000_agents_with_compute_shader/
only in my case, you can zoom in until the character is large on the screen and you can take control of it, while the rest will continue to move, but not be drawn because they don’t get into the camera …
I didn’t mean to suggest that you can’t do physics, animation controllers, etc, on the GPU, but rather that Unity won’t help you. You need to implement it all yourself. If you notice in that tech demo…
It’s entirely on a flat plane
The plane is (relatively) small and well-bounded
There are no other objects besides the moving soldiers
There are no physics of any kind other than some very basic point collision
There’s no skinned animation, and all animation is 100% synchronized
There’s no real pathfinding/AI, just moving towards a single point with some flocking
It’s a neat particle simulation, but that’s kinda what it is, just with soldiers for particles and some very basic ability for the player to select/direct a subset.
If a tech demo like that (flat plane, no objects other than your soldiers) is your goal, then fair enough. But turning something like that into a game is a lot of work, and if you want to do it on the GPU, the engine isn’t going to help you at all.