To optimize the memory consumtion of the Minko engine, we started by profiling the memory allocations using tools such as the integrated Visual Studio 2013 memory profiler or Massif.
One of the heaviest source of memory allocations was for
std::string objects. It’s not really a surprising considering one of Minko’s biggest feature is dynamic data binding between the engine data – on the CPU – and the shader data – on the GPU. And “dynamic” means we have to create those bindings according to some naming conventions and explicit declarations made in “effect” files using JSON. Read: we use lots of strings.
We use strings for material property names, but also for the camera properties or the geometry vertex attribute names. It makes the engine very flexible and extensible while keeping some important aspects of strict typing using templates. But it uses a lot of memory because each property names is stored multiple times.
Materials for example are highly likely to share most (if not all) of their property names. If you have 10 of those materials, the property name strings will use 10 times too much memory.
To solve this, I’ve implemented the flyweight design pattern.
Continue reading Flyweight design pattern with C++11
Update: my implementation worked well on “native” OpenGL configuration but suffered from a GLSL-to-HLSL bug in the ANGLE shader cross-compiler used by Firefox and Chrome on Windows. It should now be fixed.
Update 2: you can toggle each cascade frustum using “L” and the camera frustum using “C”.
WebGL Cascaded Shadow Mapping demo powered by Minko
- arrow keys: rotate around the scene or zoom in/out
- C: toggle the debug display of the camera frustum
- L: toggle the debug display of each cascade frustum
- A: toggle shadow mapping for the 1st light
- Z: toggle shadow mapping for the 2nd light
Lighting is a very important part of rendering real-time convincing 3D scenes. Minko already provides a quite comprehensive set of components (DirectionalLight, SpotLight, AmbientLight, PointLight) and shaders to implement the Phong reflection model. Yet, without projected shadows, the human eye can hardly grasp the actual layout and depth of the scene.
My goal was to work on directional light projected shadows as part of a broader work to handle sun-light and a dynamic outdoor environment rendering setup (sun flares, sky, weather…).
Full code after the break…
During the last Flash Onlince conference, I had the chance to share the latest work I’ve been involved in at Aerys with the rest of the Minko team. We’ve been working a lot on the next major version because we really want it to be a game changer for 3D on mobiles and the web.
You can read the original announcement for more details. But the big picture is that Minko is going to support WebGL. To introduce this new major feature we’ve created a first technical demonstration:
To help AS3 developers migrating to C++, I’ve decided I’ll start gathering resources here on this very blog. If you are interested you can start by: