Home Indie Game Avaruustaistelupeli (ATP) – an area fight sport

Avaruustaistelupeli (ATP) – an area fight sport

0
Avaruustaistelupeli (ATP) – an area fight sport

[ad_1]

The stadium is nearly prepared for the viewers, however sadly massive crowds have a detrimental impact on efficiency. This is principally because of two causes: having a skeleton hierarchy for every spectator ends in an enormous variety of dynamic sport objects, and Unity’s batching doesn’t help skinned meshes. These trigger an enormous CPU load to take care of.

Solution is to animate meshes on GPU (in shaders), and use the batchable MeshRenderer as an alternative of its skinned variation. Unity doesn’t have a built-in software for this, so I made one myself. I wrote a tough editor script that reads vertex positions of skinned mesh on every body and shops them right into a texture. A customized shader then repositions vertices in run-time by studying the positions from that texture.

As I used a shader graph and my baker utility class may be very specialised for my wants, it’s arduous to share any helpful code simply but. But for those who’re , I discovered this article and this repository helpful.

As a place to begin, perform AnimationClip.PatternAnimation units the mesh into a correct pose at a given time, and SkinnedMeshRenderer.BakeMesh can be utilized to extract the mesh knowledge at that second. In the shader, the vertex index is saved within the built-in variable vertexID. An attention-grabbing discovering is that for those who retailer every keyframe on a separate texture row, bilinear filtering will routinely deal with the animation mixing (see the article linked above).

Resizing the feel to power-of-two (not essentially required in desktop growth) was a surprisingly complicated job that required an exterior render texture (or I’ve simply missed some too apparent utility perform). Here’s what I’m doing for texture scaling (be aware the feel format that’s wanted for storing detrimental values with first rate precision):

public static void ResizeTexture(Texture2D pTexture, int pWidth, int pHeight) {
    var rt = RenderTexture.GetTemporary(pWidth, pHeight, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Default);
    RenderTexture.energetic = rt;
    Graphics.Blit(pTexture, rt);
    pTexture.Reinitialize(pWidth, pHeight, TextureFormat.RGBAHalf, false);
    pTexture.filterMode = FilterMode.Bilinear;
    pTexture.ReadPixels(new Rect(0f, 0f, pWidth, pHeight), 0, 0);
    pTexture.Apply();
    RenderTexture.ReleaseTemporary(rt);
}

In the tip, animation baking wasn’t almost as complicated as I feared, however resulted in some hilarious glitches. During the primary makes an attempt, fashions distorted closely and made the viewers appear to be a horde of lovecraftian monsters; sadly I did not file a video of it. Of course there’s nonetheless heaps to do. Instead of repeating an identical gestures, every spectator wants particular person variation, so mixing of various animations at completely different speeds per particular person is required; this can in all probability introduce some batching points. I additionally must bake normals and tangents and resolve smaller points with digital camera frustum culling (in all probability associated to AABB calculation). But at the very least I now have a stable base to construct on, already capable of run hundreds of animated spectators and not using a noticeable FPS drop.

I may make a prolonged weblog submit concerning the topic. Perhaps I’ll sooner or later. Writing concerning the course of appears to be slower than the precise implementation, so hopefully somebody finds these useful.

Besides the GPU magic I’ve additionally improved the background of the shipyard, experimented with GUI design and ACES tone mapping (I’ve to spice up up all these baked lights…) and many others. I’ll come again to these within the upcoming posts.

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here