Wednesday, November 9, 2022
HomeGame DevelopmentCocos Specialists Share Methods For Decreasing DrawCalls And Different Efficiency Optimization After...

Cocos Specialists Share Methods For Decreasing DrawCalls And Different Efficiency Optimization After iles Launch – Information base


Just lately we launched isles to Steam to let builders see what may be constructed by the engine. On the similar time, as engine builders, we will additionally wish to expertise the entire strategy of growing video games with Cocos Creator to seek out out the shortcomings and ache factors of the engine and supply a reference for future iterations.

After the sport was launched, many builders and gamers advised us their experiences and strategies. This text will share some optimization concepts and strategies in your reference.

Pressured use of discrete graphics playing cards

Many home windows machines have greater than two graphics playing cards. In some instances, the desktop will routinely choose the lower-performance built-in graphics card for the sport to play on. In gaming functions, we might want this system to run one of the best graphics on a regular basis to maintain the sport clean.

Since iles and plenty of PC video games built-in Cocos Creator are primarily based on electron, now we have discovered some options to this problem.

  • Set SHIM_MCCOMPAT=0x800000001 [1] within the atmosphere variable. The next is the beginning.cmd file for iles startup.
set SHIM_MCCOMPAT=0x800000001

cd %~dp0

begin ... ... iles.exe
  • Add electron startup parameters [2].
app.commandLine.appendSwitch('force_high_performance_gpu')

Test that chromium on the pc helps model 101.0.4923.0 [3]. Electron corresponds to model 19.0.0 onwards [4].

To test the graphics card data of the machine after booting and whether or not it makes use of the proper graphics card, we wrote a take a look at program obtainable without spending a dime for reference.

Optimize DrawCall and the variety of faces

Sea floor

The entire sea degree is a big space, and to make sure that the waves transfer extra naturally, extra vertices are wanted. Nonetheless, we don’t wish to use a substantial variety of vertices for the entire sea degree. In concept, we solely want extra element within the close by areas and may have much less element within the outlying areas.

Primarily based on this pondering, we divide the ocean into 9 areas. Solely the center half retains a excessive vertex depend. The encircling fashions use much less vertex depend, however so as to be certain that the vertex animation between areas is completely linked, the vertex depend of the perimeters of the excessive and low fashions additionally must match completely.

Right here is the method we used to function with Blender.

  • Swap the mode to face edit mode, choose a face apart from an edge, right-click and choose un-subdivide.

You may see that there will likely be a lot fewer vertices after the optimization.

Timber

There are lots of timber throughout iles, and the unique tree remains to be modeled with a fairly excessive verticy depend, with about 300 vertices in a tree.

This degree above has nearly 2000 timber and almost 600,000 vertices. We added lod assist to make use of a finer lod up shut and a rougher decrease one at a distance, culling out the rendering of this mannequin at far away.

Making a tough model in Blender is comparatively easy: choose the mannequin, add a Decimate kind modifier, and modify the ratio to cut back the vertices to an appropriate degree.

Then wrote a comparatively easy lod selector, utilizing lod0 if inside 10m of the digicam, lod1 if inside 1000m, something additional away is weeded out. If the artistic workshop edit mode wished to see a bit additional away, set it to inside 3000m and nonetheless see the timber.

Grass

The quantity of grass within the recreation may be very excessive. The bigger the walking-space dimension, the extra grass there’s, like the massive house beneath the place the quantity of grass is definitely within the tens of hundreds.

If we had been to render the grass within the regular mannequin manner, every traversal would devour lots of efficiency. Scene cropping and occasion filling are the hardest-hit areas relating to efficiency consumption.

Right here I wish to take full management of your entire occasion rendering course of for the meadow.

  • Divide the entire scene by space. Every space is 555.
  • When the scene is loaded, the grass is added to the corresponding InstancedBuffer by area (no precise grass nodes are created). These InstancedBuffer will not be modified at runtime after they’re stuffed.
  • The scene solely must be visually cone-culled for areas throughout runtime. The entire thing is way more environment friendly with out the runtime consumption of populating the InstancedBuffer.
  • After testing the grass optimization, the objects all around the seafloor had been optimized utilizing the identical method.

All these optimizations add as much as a big efficiency enchancment, with essentially the most intensive situation having 600,000 vertices earlier than the optimization and with the ability to hold it below 50,000 vertices after the optimization.

Rendering Pipeline

We’ve added some pipeline conditional management nodes to attempt to keep away from pointless rendering processes. Rendering the entire display screen remains to be very efficiency intensive.

Optimized begin scenes

Within the begin scene, the digicam view is mounted. The digicam will solely see the entrance half of the island, and the again half just isn’t seen. You may add a little bit judgment when producing the underside objects. Objects within the again half of the island don’t must be generated. This will scale back the runtime overhead.

Rendering Decision

The rendering decision of the display screen has a big impression on the consumption of GPU calculations. We discovered that some customers with machines that aren’t very nicely geared up however doubtlessly linked to a really high-resolution machine, primarily based on completely different rendering qualities, we managed their most rendering decision

let decision = [1120, 630]
if (renderSetting.realQuality === RenderQulity.Excessive) {   
    decision = [1960, 960]
}
else if (renderSetting.realQuality === RenderQulity.Medium) {
    decision = [1334, 750]
}

Enhancing growth effectivity

Cocos Creator 3.6.0 added an editor preview mode. We are able to run and debug the sport within the editor, which helps enhance growth effectivity. iles upgraded to v3.6.1, and the entire expertise remains to be superb.

Enhancing the gaming expertise

Along with optimizing efficiency, now we have added some recreation content material or modules to reinforce the participant’s gaming expertise.

  1. Added leaderboard with 10,000 api interface calls per day utilizing leancloud free model.

2. Added a chili pepper prop with flaming results, which may velocity up the run when eaten.

3. Added bouncy mushrooms that bounce chicks up into the air.

4. Added floating picket packing containers to simulate water buoyancy for added enjoyable.

5. Keyboard and joystick controls are supported.

6. Optimize the loading course of and add a loading display screen.

Assets Obtain

The supply code presently obtainable on the Cocos Retailer is pre-optimized and constructed on v3.6.0. The optimized supply code, upgraded to v3.6.1, will likely be uploaded as quickly as it’s obtainable.

https://retailer.cocos.com/app/element/4010

iles Obtain Expertise – Steam

Reference Hyperlinks

[1] Setting variable settings

[2] Electron documentation

[3] chromium 101.0.4923.0

[4] Electron model obtain

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments