 Hello everyone, welcome to my talk on interacting crowds. I hope you've been enjoying the Blender conference and you still have some energy left because we're gonna look at some battles. When I talk about interacting crowds I'm talking about battle scenes or city scenes where you have large group of individuals that need to interact with each other. I'm developing crowds in 3D which is a crowd simulation add-on and for a crowd simulation when you have to deal with interacting crowds you need to have behavioral rules for the crowd as a whole and you need to have behavioral rules for the individuals for the individuals within the crowd to manage the interactions. In other words you need tools to direct the crowd movement and you need to have tools to direct the individual interactions. Some of you might already know that I've been working on battle scenes and up till last year I've been focusing more on solutions to direct the crowd as a whole and this year I've been focusing a bit more on solutions to direct the individual movements to direct the individual interactions. My goal is to have a bit more realistic battles but I also want to have more control of how the battle should take place. I also want a way to specify the individual battles so I was kind of searching for a way to do that. Before talking about the individual interactions I want to talk a bit about the individual. I added model variables to the add-on and with model variables I can set certain properties on my character on my model. By populating these properties to different agents within the value range specified I can define multiple type of characters and in my case multiple type of soldiers. So I can have a very strong and healthy soldier or a weak and very healthy soldier or a strong but not so healthy soldier and I can define how much strength or damage someone can take or someone can give. Now having these model specific properties and these specific character combining this with a state property, a state property usually says something about the simulation state which apply to all agents but combining that with agent specific state I can very specifically say how I want a certain interaction to happen. How fast would somebody die or would somebody retarget after defeating an enemy. So I had a bit more specific control of how I wanted the individual battles to happen and this gave me the possibility to create a battle scene. This is an example where you see the crowds moving towards each other. I'm just using solutions for the state engine to have these two armies run to each other but for the individual battles like here I'm using the model state variables and to direct how long somebody will live or are they strong enough to continue battle or will they maybe run away. I mean that can also happen. Now let's talk a bit about avoidance algorithms especially rvo2 and in the implicit force. Last year I showed you path following and for path following I used the implicit force algorithm and implicit force worked very well for path following. I could easily avoid trees, lakes and even other agents. So for path following it was a really great solution. However for battle it became a bit of a nightmare. What would happen using false algorithm the implicit force when the two armies would clash the a lot of agents would come to a full stop because well they're fighting. So the velocity of the field the overall velocity would drop and with that the overall force would drop and this would lead to the whole battlefield coming to a full stop. Now this is not something I want to happen with the implicit force. Well you want the battle to keep on going but at a certain moment the whole field would stop so agents running to the battlefield would come to a full stop and it would take several minutes for them to get going. So I wasn't really happy with that with that the implicit force did that. Now there are some ways to deal with it if you run into this issue. One solution I came up with is to treat the agents who come to a full stop as obstacles. The implicit force algorithm treats obstacles different than moving obstacles, moving agents. So by switching moving agents at a point that they clash to becoming an obstacle that helped a lot but it wasn't the only solution that I had to use because even though I would switch them still you would see a drop in force but it would not be as steep as if I wouldn't be doing that and it wouldn't be as slow a full stop as before. Another thing you can use when using these type of avoidance algorithms is to divide the battle field maybe in two or three groups and just use smaller groups of agents and targets to calculate the avoidance and wherever needed use RVO2 if that works for you and otherwise switch to the avoidance algorithm. Looking at the battle scene again for the overall I use the RVO2 avoidance. RVO2 is a bit smoother but for the close-up I use the implicit force because when the crowds become a bit dense RVO2 can't handle that very well and implicit force can. So when they run don't use the implicit because then you get a bit of a slowdown. I use the RVO2 in this case but for the close-up the implicit force algorithms worked very well. Looking here in the battle the avoidance was really great so in this case for the close-up the implicit force works great but not when running towards each other. Another thing I want to discuss with you talk to you about is avoidance and animations. So avoidance algorithms when setting up a simulation like this avoidance can decide that an agent should pick up speed or should slow down while you as an artist want the opposite. You want the agent to slow down or to pick up speed. Avoidance can decide now the agent should turn left or right and you're like no no no I want this agent to keep on running forward. In other words avoidance algorithm can decide something different than what you as an artist want and that's because these type of algorithms they calculate what is best to keep the crowd moving which might be something different a different result than what you as an artist want but this is what avoidance algorithms are created to do best keep the crowd moving and for every agent what is the best solution to keep it moving and sometimes you want something different. So what do you do first when you create a battle scene start with only agents don't use the animations yet start only with agents set up how you want the movement between the agents and if you're happy with how it overall looks then decide which animations you'll need add the animations to your behavior three rerun the simulation again and start tweaking and it might happen that you need a bit more animations which is fine you can add some more but rerun it you tweak you rerun it you tweak you rerun it creating a crowd simulation is quite complex it's not an easy task and it'll yeah you need a lot of tweaking to get a very beautiful nice simulation like you want when tweaking I found it very handy to see which agents were targeting who so who was going to attack who but also who was attacking me so I added a target overlay to see who was gonna fight who the green line shows who I am targeting and the red line shows who who is targeting me and by giving putting adding this overlay I can kind of direct my battle so if I see that the when locking a target I would run that way I was like nah I don't want the agent to go that way I want to go that way so I would move the position a bit within the factory within the agent factory so that the agent would target somebody else and the better look would look a bit differently so by playing with the positions of the agents I would get a different battle and the target overlay helped me to see who was targeting who another thing you can do when tweaking is that all data of the crowd simulation is written back to the NLA editor so you can to the NLA and you can use the NLA editor to tweak your animations as well just keep in mind that when you run the simulation again the NLA will be overwritten so be a bit careful about that now let's talk a bit about blender's playback so when you're tweaking you want to see how your battle goes how your simulation goes especially when you've already added the animations you want to see like okay are the animations aligned if somebody is attacking am I properly defending that sort of tweaks you want to see but with a very small crowd like the one that I've showed you 500 agents just 25 k of vertices with a fairly high end machine I just get a playback speed of one frame per second okay I don't have to convince you that that's not very workable right that is really slow so I was faced with this issue and I wanted to really specifically look into battles and this was super slow so I did a bit of analysis like why is the playback so slow and um and well this graph already shows much time is spent on uploading geometry to the GPU a lot of time is also spent in depth graph and drawing but the majority of time is spent in uploading all the geometry to the GPU so it's like okay knowing this can I somehow spend less times in depth graph can I somehow spend less time in drawing a few per drawing and can I spend less time in uploading geometry to the GPU the answer is yes yes and yes so what happens if you call the depth graph the depth graph generates the same geometry for multiple agents even if they have the same pose so when you see the arm is running well they have the same suit they have the same geometry basically and um when running for example and even when fighting you will have always have agents who have the same pose in that frame and what does depth graph do basically it treats every agent as unique every geometry as unique even though they share the same pose so there is no the duplication done of geometry and with that you can't use instance drawing instance drawing is a feature of GPUs where you can basically upload the same geometry and use it to draw the geometry on different locations by one draw command so now all the geometry was uploaded even though they were the same everything is uploaded to the GPU and that takes a lot of time knowing this for example look at if you look at the scene the green agents they share the same geometry within this frame but even in other frames they will also share the same geometry the same you will always have poses that will be similar so I can share geometry within a single frame I can share geometry within between multiple frames and I haven't even talked about a topology which I can also share so there's a lot of data that I can share I don't need to upload all this data to the GPU so I decided let's write a playback overlay and this this took a bit of time to write because I didn't know the blend the blender GPU API I didn't know Vulkan so which is handy to know a bit so I started playing with blender's GPU API and what I'm basically doing is that I'm using that API to do a bit to do the drawing now so for each pose the result of the depth graph I just cache it I just need a geometry so I cache the the result of the desk depth graph and during playback I'm skipping depth graph I'm skipping the viewport display and I immediately go to the GPU and use instance drawing and with that I get a performance of max 45 frames per second I was like okay so looking at the time the time spent is way much less even in depth graph even in the drawing is much less and really really really less in uploading all the geometry to the GPU just to give you an idea this is how it looks like this is blender's playback so it's waiting waiting and when I activate the playback it does take some time to build up the cache but once the cache is built up I just get 45 frames per second this is what I'm talking about and this is only 500 agents I mean when I'm talking about the YouTube I'm working on a battle scene of a few thousand agents at the moment it takes a while to build up the cache there but I can when the cache is built up I can get the same performance so and this is what you want you just want wow you want you want to see your animations you want to see how the simulation will go not that slow as you see here but but you also want to move around I if I haven't even talked about if I want to move around the viewport everybody's starting stops and I have to wait for two three minutes and then I get one frame per second again it's really too slow especially if this is only 500 agents so and the playback overlay really helped a lot in tweaking the animations and fine tuning every battle I see and how this could move so I became very much more productive when I got this working it took quite a while to develop and to figure out how the blender GPU API worked but once it was there I was very happy and it saves me a lot of time and frustration to be honest what's next I'm working on a city scene and it's the panic in the city where people have to run around in panic yeah I'm currently working on that I was running into the same problems I had with battle so the avoidance is there also again a headache but also the playback overlay I really needed it because this even more people running everywhere it's even more chaotic so I needed to have that in place as well to work to continue working on my city scene currently I'm investigating the use of navigation measures to direct the movement as well the crowd team already uses navigation measures to decide where somebody can walk or cannot walk but now using kind of like weights and I'm still developing that and see how that would work but kind of like using using weights that you can direct or at least tell the crowd that there is a route of preference or there is a route that you shouldn't take or it's the least to take but that people can still take it because in a panic situation you always will have people taking the the less preferred route so this is something I'm currently working on again I can't show anything yet it's still work in progress but if I have something working I usually upload it to the youtube channel and on message on our x the crowd team there is again there is a free version for small crowds if you're just working with small different crowds you can download it for free if you're working with huge crowds it's a paid add-on and if you get a paid if you buy the add-on you get all the battle files and all the soldiers and all animations you can do that and yeah we're working now with creating animations for the city scenes and I hope if that's ready that I can share it with you as well thank you very much