Geometry "In The Spotlight"
2016-09-02
I have a passion for examining the features in new releases and I can’t wait for new versions to come out. And the Blend4Web developers, much to the delight of the users, do treat us with something new every month. The July build 16.07 has introduced an outstanding feature to save system memory by using geometry instancing. So, I have decided to thoroughly examine this option and share what I have discovered with all of you.
So what is geometry instancing… You have a reference object uploaded to the GPU memory. Then, you can use this object to render any number of its copies. This significantly disburdens the hardware.
Geometry instancing in Blend4Web is done by using particle systems. Simply select the Hair mode, add an object you need, and distribute its copies along the surface. The engine will enable instancing automatically, if, of course, your GPU is not too outdated.
The Island of Clones
You can’t have a test without a test scene! I tried to make an island rich with objects, so GPU, CPU and other pieces of hardware would have a hard time processing it.
Fifteen hundred objects, over a million vertices, about 700,000 polygons… that’s without instancing. The browser won’t be happy.
Every reference object contains complex materials that utilize transparency and Normal Map textures, and has quite an impressive number of elements. For example, a tree model consists of nearly 10,000 vertices.
As additional eye candy, shadows, environmental light and other effects were enabled.
Preparing The Test
I’ve picked a fairly average computer with specs slightly above an office workstation as the test platform.
Personally, I have the impression that low-end hardware is better suited for testing games and other real-time applications. For me, even this test platform may still be too powerful, but sadly something weaker was nowhere to be found at the time.
I’ve also made two versions of the scene. The first one was exported with version 16.06 of the SDK, and the second one with version 16.08. Thus, I’ve got two applications, one with support for geometry instancing and one without it. So let’s start the testing!
Test Results
Testing was based on the readings of the Scene Viewer application of the corresponding framework version.
First, I was interested in the number of FPS (frames per second). Geometry instancing shouldn’t really consume a large portion of the GPU computation power, but combined with additional effects (shadows, textures), it led to the following picture.
Under equal launch conditions, without changing camera angles, the application with support for geometry instancing has shown a performance increase by almost twofold. At the numerical level it was 32 FPS compared to 17 previously.
Relatively low FPS numbers have caught my attention and, after doing some research, I’ve discovered that the vast majority of the GPU power is consumed by shadow calculations.
There exist some ingenious algorithms for optimizing shadow rendering depending on various factors, and Blend4Web offers several of them. In this case, I’ve used “straight” visualization that does not change the quality of the shadows depending on the distance. Although, just for the fun of it, I’ve tried to turn the shadows off completely and got the expected 60 to 80 FPS.
The main feature of geometry instancing is, however, RAM conservation. It is especially important for mobile platforms. And it is here where the testing produced downright insane results!
The geometry in the optimized version takes only 6 Mb compared to 292 Mb in the non-optimized version. And from the browser standpoint, the application with instancing support consumes a total of 124 Mb of RAM, while its “competitor” requires no less than 410 Mb.
So, in the end… use instancing everywhere you can, for a web browser’s memory is truly priceless.