Jump to content

Kinematic Joint Shadow Glitch


SpiderPig
 Share

Go to solution Solved by Josh,

Recommended Posts

Not a big deal but here it is anyway.  Tap the W key quickly and you will see that the shadow lags and creates a dark spot briefly on the cylinder.

JointShadowDelay.gif.d4dc23634fc76571532263451b844bf7.gif

#include "UltraEngine.h"
using namespace UltraEngine;

int main(int argc, const char* argv[])
{
    auto displays = GetDisplays();
    auto window = CreateWindow("Ultra Engine", 0, 0, 800, 600, displays[0]);
    auto framebuffer = CreateFramebuffer(window);
    auto world = CreateWorld();

    auto camera = CreateCamera(world);
    camera->Move(0, 2, -3);
    camera->SetClearColor(1, 0, 0);

    auto light = CreateDirectionalLight(world);
    light->SetRotation(35, 35, 35);

    auto floor = CreateBox(world, 100.0f, 0.5f, 100.0f);

    auto default_font = LoadFont("Fonts\\arial.ttf");
    auto ui = CreateInterface(world, default_font, framebuffer->size);
    ui->SetRenderLayers(2);
    ui->root->SetColor(0.0f, 0.0f, 0.0f, 0.0f);

    auto ui_camera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
    ui_camera->SetPosition((float)framebuffer->size.x * 0.5f, (float)framebuffer->size.y * 0.5f, 0);
    ui_camera->SetRenderLayers(2);
    ui_camera->SetClearMode(CLEAR_DEPTH);

    auto label = CreateLabel("", 10, 10, 500, 200, ui->root);

    auto m = CreateCylinder(world, 0.5f, 1.8f);
    m->SetMass(1.0f);
    m->SetPosition(0, 2, 0);

    camera->SetParent(m);

    auto joint = CreateKinematicJoint(0.0f, 2.0f, 0.0f, m);
    joint->SetMaxForce(FLT_MAX);

    while (true)
    {
        while (PeekEvent()) {
            ui->ProcessEvent(WaitEvent());
        }

        auto pos = m->GetPosition(true);
        auto rot = m->GetRotation();
        label->SetText("Position : " + String(pos.x) + ", " + String(pos.y) + ", " + String(pos.z) + "\n" +
            "Rotation : " + String(rot.x) + ", " + String(rot.y) + ", " + String(rot.z));

        auto target_pos = pos;
        if (window->KeyDown(KEY_W)) { target_pos.z += 1.0f; }
        if (window->KeyDown(KEY_S)) { target_pos.z -= 1.0f; }

        joint->SetPose(target_pos, Vec3(0,0,0));

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

 

Link to comment
Share on other sites

  • Solution

This is an interesting situation. The simple answer is you are moving too quickly, or rather accelerating too quickly. Instantaneous teleportation of one meter is not realistic.

The more complicated answer is that the engine doesn't know a shadow needs to be updated until the rendering call begins, but at that point it already has the visibility list it is going to use, which does not include the light casting that shadow, since the culling thread didn't include it, since the shadow was not invalidated when the culling process began. Therefore, the renderer has to wait until the next visibility list is received before the shadow gets updated. I suppose a persistent visibility list for each shadow might be a way of dealing with that, but under normal conditions an object will begin accelerating more gradually, which will trigger a shadow update without a big mismatch between the visible geometry and the shadow map info. A persistent list would also have the unwanted side effect of preventing resources from being freed from memory until all shadows are refreshed.

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