Posted on

Linux version updated (with play on Android + fully scriptable GUIs – no code compilation or tooling needed)

Linux version now supports playing scenes on Android and features fully scriptable GUI creation straight to your Android device in < 1 second (no code compilation or tooling required) for fast iteration and prototyping. v0.42.0+ includes a new GUI plugin that contains a GUISystem and GUIComponent that supports immeadiate mode GUIs (defined in script). You can do this in the editor and then view immediately on your Android device and also in code as follows (download for free here):

// Add a GUIComponent to an empty GhostSceneItem and define your GUI
auto object = static_cast<GhostSceneItem*>(firefly::SDK::GetInstance().CreateSceneItem(SceneItemType_GhostSceneItem));
auto gui    = object->AddComponent<GUIComponent>();
auto script = R"(function update(this, time)
                    dummy = nil
                    ext_GUIScript.Begin('A Window', dummy, ext_GUIScript.ImGuiWindowFlags_NoResize | ext_GUIScript.ImGuiWindowFlags_NoMove | ext_GUIScript.ImGuiWindowFlags_NoScrollbar | ext_GUIScript.ImGuiWindowFlags_NoCollapse)
                    if ext_GUIScript.Button('Click Me!') then
                        // do stuff in response to button click
Posted on

Generated games now package up as small as just 3MB

The “Publish to Visual Studio 2017” and “Publish to Android Studio” feature (available in the editor) includes a packaging sub-project that will bundle up the generated game to a shareable zip file package as small as 4MB on Windows or 3MB per-architecture on Android (3MB per architecture, includes armeabi-v7a, x86, arm64-v8a and x86_64 versions that bundle into a 12MB package).

Posted on

Poisson disk sampling

Poisson disk sampling can be used to procedurally sample a region of space. It’s not as messy as random placement or as uniform as grid-based methods. I’ve created a little demonstration project that extends the sampling to cover objects of varying size with no overlap in this repository. An example of the generated distributions (of a 3 layer sampler) is below. Some applications:

  • Sampling an image / regions of an image
  • Procedurally placing objects of varying sizes with no overlap in a simulation / game
Posted on

Mesh Instancing Support Added

With mesh instancing you can draw thousands of copies of a mesh in a single draw call (you can specify an arbitrary number of properties for your instances by attaching per instance data to your mesh to be instanced) without adversely affecting the frame rate. v0.41.8 of the SDK comes with a small demo app (example_Instancing) that demonstrates this feature in the engine and is accessible (along with code) from the editor’s samples browser shown on start up. Here’s a code snippet that illustrates the mesh instancing support:

    // ============================================
    // MESH INSTANCING - grid of boxes
    // ============================================

    // the base mesh we will instance
    auto box = static_cast<PrefabricatedMesh*>(firefly::SDK::GetInstance().CreateSceneItem(SceneItemType_BoxSceneItem));

    // per instance transforms (i.e. position, rotation and scale)
    WIDTH = HEIGHT = DEPTH = 10;
    transforms = new glm::mat4[INSTANCE_COUNT];
    float meshWidth, meshHeight, meshDepth;
    meshWidth = meshHeight = meshDepth = 4.f;
    float xorig = -((WIDTH  * meshWidth)  / 2.f) + (meshWidth  / 2.f);
    float yorig = -((HEIGHT * meshHeight) / 2.f) + (meshHeight / 2.f);
    float zorig = -((DEPTH  * meshDepth)  / 2.f) + (meshDepth  / 2.f);
    int i = 0;
    for(int x = 0; x < WIDTH; x++)
        float xpos = xorig + (x * meshWidth);
        for(int y = 0; y < HEIGHT; y++)
            float ypos = yorig + (y * meshHeight);
            for(int z = 0; z < DEPTH; z++)
                float zpos = zorig + (z * meshDepth);
                transforms[i++] = glm::translate(glm::mat4(1.f), glm::vec3(xpos, ypos, zpos));

    // tell the mesh the instance count

    // create an instance data buffer
    auto instanceData = (VertexBuffer*)SDK::GetInstance().CreateVertexBuffer();

    // pack the per-instance data into the data buffer
    instanceData->InitInstanceDataBuffer(INSTANCE_COUNT * sizeof(glm::mat4), &transforms[0]);

    // specify the data layout (instance data -> shader attribute location mappings)
    auto mesh = box->GetMesh();
        instanceData->SetDataArrayMapping({4, 4, VertexBuffer::DataType::Float, 0, sizeof(glm::mat4), (void*)0});
        instanceData->SetDataArrayMapping({5, 4, VertexBuffer::DataType::Float, 0, sizeof(glm::mat4), (void*)(1 * sizeof(glm::vec4))});
        instanceData->SetDataArrayMapping({6, 4, VertexBuffer::DataType::Float, 0, sizeof(glm::mat4), (void*)(2 * sizeof(glm::vec4))});
        instanceData->SetDataArrayMapping({7, 4, VertexBuffer::DataType::Float, 0, sizeof(glm::mat4), (void*)(3 * sizeof(glm::vec4))});
        instanceData->SetDataArrayDivisor({4, 1});
        instanceData->SetDataArrayDivisor({5, 1});
        instanceData->SetDataArrayDivisor({6, 1});
        instanceData->SetDataArrayDivisor({7, 1});

    // attach the per-instance data buffer to the mesh (it will take ownership of the buffer)
    // nb. only needed if you intend to save the instance data along with the mesh otherwise you can destroy it
    // as it's now managed by the VAO

    // Shader (that supports a per-instance mat4 shader input (attribute) at location 4)
    // nb. vertex_position and vertex_texcoord0 are engine built-in attributes (see shader reference)
    // nb. ProjectionMatrix and ViewMatrix are engine built-in uniforms
    SimpleShader* shader = static_cast<SimpleShader*>(SDK::GetInstance().CreateSceneItem(SceneItemType_SimpleShader));
    shader->SetVertexShader("#version 330 core\n"
                            "layout (location = 0) in vec3 vertex_position;\n"
                            "layout (location = 2) in vec2 vertex_texcoord0;\n"
                            "layout (location = 4) in mat4 instance_matrix;\n"
                            "out vec2 TexCoords;\n"
                            "uniform mat4 ProjectionMatrix;\n"
                            "uniform mat4 ViewMatrix;\n"
                            "void main()\n"
                            "    TexCoords = vertex_texcoord0;\n"
                            "    gl_Position = ProjectionMatrix * ViewMatrix * instance_matrix * vec4(vertex_position, 1.0f);\n"
    shader->SetFragmentShader("#version 330 core\n"
                              "out vec4 FragColor;\n"
                              "in vec2 TexCoords;\n"
                              "uniform sampler2D sampler;\n"
                              "void main()\n"
                              "    FragColor = texture(sampler, TexCoords);\n"
    shader->SetPropertyValueByName("sampler", TextureManager::GetInstance().TextureWithName(GetFireflyDir() + "default_texture.png"));