Jump to content

Camera: realtime rendering even with SetRealtime(false)


klepto2
 Share

Go to solution Solved by Josh,

Recommended Posts

ok, this is a weird bug i have encountered while trying to optimze some texture generation.

Sometimes a camera which is set to not render in realtime still renders in realtime.

#include "UltraEngine.h"

using namespace UltraEngine;

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

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

    //Create a world
    auto world = CreateWorld();

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

    //Create light
    auto light = CreateBoxLight(world);
    light->SetRange(-10, 10);
    light->SetRotation(15, 15, 0);
    light->SetColor(2);

    //Create camera
    auto camera = CreateCamera(world);
    camera->SetClearColor(0.125);
    camera->SetPosition(0, 0, -3);
    camera->SetFov(70);

    //Create scenery
    auto box = CreateBox(world);

    auto cone = CreateCone(world);
    cone->SetPosition(1.25, 0, 0);
    cone->SetColor(0, 0, 1);

    auto sphere = CreateSphere(world);
    sphere->SetPosition(-1.25, 0, 0);
    sphere->SetColor(1, 0, 0);

    //Create camera and texture buffer
    auto texbuffer = CreateTextureBuffer(256, 256);
    auto cam2 = CreateCamera(world);
    cam2->SetClearColor(1, 1, 1);
    cam2->SetRenderTarget(texbuffer);
    cam2->SetRealtime(false);

    //Create material
    auto mtl = CreateMaterial();
    auto tex = texbuffer->GetColorAttachment();
    mtl->SetTexture(tex);
    box->SetMaterial(mtl);
    cone->SetMaterial(mtl);
    sphere->SetMaterial(mtl);

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        //Orient the texturebuffer camera
        //Play around with these values and restart the app, sometimes the cam2 is rendered constantly even it is not set to realtime
        cam2->SetPosition(0, 0, 0);
        cam2->Turn(0, 1, 0);
        cam2->Move(0, 0, -2);
        cam2->SetRange(0.1, 1000.0);

        //Press the space key to redraw the texture buffer camera
       // if (window->KeyHit(KEY_SPACE)) cam2->Render();

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

Run this snippet in release mode, mutliple times. You may need to change the cam2 values (position, turn, move or range) in order too get the bug. in most cases you get the desired one time render, but (it seems randomly) you get realtime rendering sometimes as well. In my bigger project my non realtime cameras are updated all the time and i am not calling the render function at all.

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

  • 2 weeks later...
  • Solution

Fixed.

Note that camera->Render() just ensures the camera renders once during the next world render. Calling camera->Render() twice in succession will not make the camera render for two frames.

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

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...