Jump to content

MSAA on UI camera hides 3D scene


SpiderPig
 Share

Recommended Posts

The 3D scene vanishes in this example with MSAA enabled.

#include "UltraEngine.h"

using namespace UltraEngine;

int main(int argc, const char* argv[])
{
    //Get the displays
    auto displays = GetDisplays();

    //Create window
    auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0]);

    //Create framebuffer
    auto framebuffer = CreateFramebuffer(window);

    //Create world
    auto world = CreateWorld();

    //Create main camera
    auto camera = CreateCamera(world);
    camera->SetPosition(0, 0, -3);

    //Create a model
    auto box = CreateBox(world);

    //Create a light
    auto light = CreateBoxLight(world);
    light->SetRange(-5, 5);
    light->SetRotation(34, 45, 0);

    //Load a font
    auto font = LoadFont("Fonts/arial.ttf");

    //Create user interface with a semi-transparent background
    auto ui = CreateInterface(world, font, framebuffer->size);
    ui->background->SetColor(0, 0, 0, 0.5);

    //Create widget
    iVec2 sz = ui->background->ClientSize();
    auto button = CreateButton("Button", sz.x / 2 - 75, sz.y / 2 - 15, 150, 30, ui->background);

    //Create camera
    auto orthocamera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
    orthocamera->SetMSAA(4);
    orthocamera->SetClearMode(CLEAR_DEPTH);
    orthocamera->SetPosition(float(framebuffer->size.x) * 0.5f, float(framebuffer->size.y) * 0.5f, 0);

    //UI will only appear in orthographic camera
    orthocamera->SetRenderLayers(2);
    ui->SetRenderLayers(2);

    auto sprite = CreateSprite(world, 64, 64);
    sprite->SetRenderLayers(2);
    sprite->SetPosition(256, 256);

    while (true)
    {
        box->Turn(0, 1, 0);
        sprite->Turn(0, 0, 0.25);

        while (PeekEvent())
        {
            const Event ev = WaitEvent();
            switch (ev.id)
            {
            case EVENT_WINDOWCLOSE:
                if (ev.source == window)
                {
                    return 0;
                }
                break;
            default:
                ui->ProcessEvent(ev);
                break;
            }
        }

        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

 

Link to comment
Share on other sites

The camera cannot render on top of the background, because it has to render to an MSAA texture.

You don't want to use MSAA on GUI cameras for a few reasons.

  • Text is already antialiased.
  • Edges will become blurry.

There may be other situations where you do want to use multiple cameras with MSAA, but this is probably not one of them.

  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Okay.  Here's a better example then.  No Interface, just a rotating sprite.  I'd want to have MSAA working for a camera that renders sprites or any other 3D object on top of a 3D scene.

#include "Engine.h"

using namespace UltraEngine;

int main(int argc, const char* argv[])
{
    //Get the displays
    auto displays = GetDisplays();

    //Create window
    auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0]);

    //Create framebuffer
    auto framebuffer = CreateFramebuffer(window);

    //Create world
    auto world = CreateWorld();

    //Create main camera
    auto camera = CreateCamera(world);
    camera->SetPosition(0, 0, -3);

    //Create a model
    auto box = CreateBox(world);

    //Create a light
    auto light = CreateBoxLight(world);
    light->SetRange(-5, 5);
    light->SetRotation(34, 45, 0);

    //Create camera
    auto orthocamera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
    orthocamera->SetMSAA(4);
    orthocamera->SetClearMode(CLEAR_DEPTH);
    orthocamera->SetPosition(float(framebuffer->size.x) * 0.5f, float(framebuffer->size.y) * 0.5f, 0);
    orthocamera->SetRenderLayers(2);

    auto sprite = CreateSprite(world, 64, 64);
    sprite->SetRenderLayers(2);
    sprite->SetPosition(256, 256);

    while (true)
    {
        box->Turn(0, 1, 0);
        sprite->Turn(0, 0, 0.25);

        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...