First, we need to pass our billboard object’s datas to GPU.
These three buffer is key factors of this process.
AnimationIndex[] : Animation state index which represent Idle, Run, Attack, Death, Pain.
ObjsPoses[] : All positions of billboard objects.
ObjsDirections[] : All directions of billboard objects.
We can pass these values by binding GL_SHADER_STORAGE_BUFFER.
Since we pass all of our billboard objects data at once and I manage those datas per Herd, we need to indexing these values to identify which object is in which herd.
HerdCount : Total counts of herds
Index : current index of billboard object, which can be obtained with current invocation ID and work group size of compute shader.
gl_GlobalInvocationID.x + gl_GlobalInvocationID.y * gl_NumWorkGroups.x * gl_WorkGroupSize.x;
HerdOffset : offset indexes of herds in 1D array which passed by uniform values. Accumulation was done by count of each herd.
If current invocation index is greater than herd offset, means object is in that herd.
Now we know which object is in which herd, we can get whether collided or not with other object.
We can get current object’s poisition with objsPoses[index], and check current object’s side with using herdIndex, iterate every objects in other side, and check whether collided or not.
Collision check function.
If object collided with enemy object, change to attack state.
Attack Done!
If not, we should check if object is collided with ally side objects.
Same as enemy collision check, but side should be same to check whether ally or not.
If collided with ally, check ally animation status, if it isn’t running, change current object’s state to idle.
If both collision checks failed, change to run animation and move object’s position.
Move Toward function.
Move Done!
Now we setted our billboard object’s animation states in buffer, we need to read them and apply to our object.
Use my buffer.hpp functions,
GetBuffer(int storageIndex) : Return buffer object which corresponding with storage index.
GetData(void* data) : Mapping buffer’s data to *data pointer
Now we have animation state index, angle index
So, we can set our billboard object’s animation.
Set Animation Function, change fbs (Animation) if given state is different with previous state.
Set current using frame buffer with given animation state index, frame buffer angle index
Using current frame buffer’s texture, drawing billboard object.
Looks Good!