Posts

Showing posts with the label flocking

compute shader with skinned mesh flocking instances

This is v. similar to the previous flocking post, only now we use a skinned & animated mesh & it's attached Animator component. Something to note, one instance of the prefab has to be in the scene, or it doesn't work (move it off camera or something). Also - the material that uses the surface shader , must have the GPU instancing enabled! That's what those if-checks are for! The gist of this is - we need to store the vertex animation into another buffer. The compute shader doesn't deal with this data at all - it is only concerned with the position/direction of each instance. It is the surface/vert-frag shader that will deal with it. The only bit the compute shader does increment is the "frame" of animation, which is determined by the speed at which the boid is moving.    C# SCRIPT using System.Collections; using System.Collections.Generic; using UnityEngine; public class SkinnedFlocking : MonoBehaviour {     public struct Boid     {  ...

Compute Shaders , flock with instanced meshes + frag/vert

Instead of getting data back from the GPU buffer, we're gonna use this code- Graphics.DrawMeshInstancedIndirect(boidMesh, 0, boidMaterial, bounds, argsBuffer, 0); - to draw instances of a mesh. Note the argsBuffer - this is a new type of buffer, containing arguments. It is defined  in the C# script and we're only initialising the first 2 entries of the array that we fill the argsBuffer with. It can actually hold a lot more information, but for this example, we only provide it with the index of the mesh and the number of them we want to draw. Argument Buffers seem to be very specific to this type of instanced mesh drawing in Unity. It doesn't seem easy to find information about them...  The compute shader and frag/vert shader are not directly concerned with the argument buffer, it seems that the code above is the only actual reference to the argsBuffer! The compute shader only updates the position/direction of the boids. The frag/vert shader (which is actually a surface shad...