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

Avaruustaistelupeli (ATP) – an area fight recreation

0
Avaruustaistelupeli (ATP) – an area fight recreation

[ad_1]

The stadium is nearly prepared for the viewers, however sadly giant crowds have a detrimental impact on efficiency. This is principally as a result of two causes: having a skeleton hierarchy for every spectator leads to an enormous variety of dynamic recreation objects, and Unity’s batching doesn’t help skinned meshes. These trigger an enormous CPU load to cope with.

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 instrument 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 could be very specialised for my wants, it’s onerous to share any helpful code simply but. But when you’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 information at that second. In the shader, the vertex index is saved within the built-in variable vertexID. An attention-grabbing discovering is that when you 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 improvement) 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 top, 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 like a horde of lovecraftian monsters; sadly I did not file a video of it. Of course there’s nonetheless tons to do. Instead of repeating similar gestures, every spectator wants particular person variation, so mixing of various animations at totally different speeds per particular person is required; it will in all probability introduce some batching points. I additionally have to bake normals and tangents and resolve smaller points with digital camera frustum culling (in all probability associated to AABB calculation). But not less than I now have a strong base to construct on, already in a position to run 1000’s of animated spectators with no noticeable FPS drop.

I might 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 so forth. I’ll come again to these within the upcoming posts.

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here