Jump to content

SpiderPig

Members
  • Posts

    2,411
  • Joined

  • Last visited

Posts posted by SpiderPig

  1. Creating a text sprite for the first time is slow and is slower the bigger the text size is.  Unsure if this one is "just the way it is" or it can be made faster?  Slower in debug mode of course but still noticeable in release.

    #include "UltraEngine.h"
    #include "ComponentSystem.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 a camera
        auto camera = CreateCamera(world);
        camera->SetClearColor(0.125);
        camera->SetFov(70);
        camera->SetPosition(0, 0, -3);
    
        auto font = LoadFont("Fonts\\arial.ttf");
        auto ui = CreateInterface(world, font, framebuffer->size);
        ui->SetRenderLayers(RENDERLAYER_1);
        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(RENDERLAYER_1);
        ui_camera->SetClearMode(CLEAR_DEPTH);
    
        //Create a light
        auto light = CreateBoxLight(world);
        light->SetRotation(35, 45, 0);
        light->SetRange(-10, 10);
    
        //Create a box
        auto box = CreateBox(world);
        box->SetColor(0, 0, 1);
    
        //Entity component system
        auto actor = CreateActor(box);
        auto component = actor->AddComponent<Mover>();
        component->rotation.y = 45;
    
        shared_ptr<Sprite> sprite;
    
        //Main loop
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            if (window->KeyHit(KEY_C)) { sprite = CreateSprite(world, font, "Hello", 128, TEXT_CENTER);
            sprite->SetRenderLayers(RENDERLAYER_1); }
            if (window->KeyHit(KEY_D)) { sprite = nullptr; }
    
            camera->Move(0, 0, 0.001);
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

  2. I have spent the last few hours bug hunting and have learnt that this is not a good idea -

    class MyClass {
    private:
    	shared_ptr<MyClass> self = nullptr;
          
    public:
    	MyClass();
          ~MyClass();
          
    };
    
    shared_ptr<MyClass> CreateMyClass() {
    	auto myclass = make_shared<MyClass>();
    	myclass->self = myclass;
    
    	return myclass;
    }
          
    //Program
    
    auto myclass = CreateMyClass();
          
    //Do Stuff
          
    myclass = nullptr;//Go Away
    //Nope, I still exist and havn't called my desctructer because your an idiot and
    //have referened me inside me using a shared_ptr.  Maybe you should use enable_shared_from_this?
    
          

    I have been using this method since forever and have never run into this problem.  The class in question had made a sprite but the sprite wasn't deleting when I set the class variable to nullptr.  Turns out this is why.  I can't remember why I gave up with enable_shared_from_this... at least a weak_ptr might work anyway.

  3. This requires a keen eye - with a transparent shader there is a hint of transparency even with alpha set to 1.  Very hard to see the edge of the cube in this shot but you will notice it more when the cube is spinning.  There's a faint hint of the cube behind the green sphere.

    TransparencyIssue.png.829a1e4b9405a2aa5f44b207c18ffd02.png

    #include "UltraEngine.h"
    #include "ComponentSystem.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 a camera
        auto camera = CreateCamera(world);
        camera->SetClearColor(0.125);
        camera->SetFov(70);
        camera->SetPosition(0, 0, -3);
    
        //Create a light
        auto light = CreateBoxLight(world);
        light->SetRotation(35, 45, 0);
        light->SetRange(-10, 10);
    
        //Create a box
        auto box = CreateBox(world);
        box->SetColor(0, 0, 1);
    
        //Entity component system
        auto actor = CreateActor(box);
        auto component = actor->AddComponent<Mover>();
        component->rotation.y = 45;
    
        auto material = CreateMaterial();
        material->SetTransparent(true);
    
        auto s1 = CreateSphere(world);
        s1->SetPosition(-0.5f, 0.0f, -1.0f);
        s1->SetMaterial(material);
        s1->SetColor(1.0f, 0.0f, 0.0f, 0.5f);
    
        auto s2 = CreateSphere(world);
        s2->SetPosition(0.5f, 0.0f, -1.0f);
        s2->SetMaterial(material);
        s2->SetColor(0.0f, 1.0f, 0.0f, 1.0f);
    
        //Main loop
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

    • Thanks 1
  4. I'm not sure how newton heightfield colliders work but for collision patches in my voxel terrain I create a small mesh for the section under the physics object and then call CreateMeshCollider().  Seems to work pretty well but if there's faster method that would the good.

  5. Just thought I'd mention that very rarely I get errors thrown from the thread manager.  They aren't random, they occur seemingly for stupid reasons - for instance this works fine...

    Vec3 offset = Vec3(10.0f, 1.0f, 5.0f);
    float scale = 2.0f;
    vector<shared_ptr<Entity>> entities;
    for (int z = 0; z < 10; z++) {
        for (int x = 0; x < 10; x++) {
            auto e = CreateSphere(world);
            e->SetColor(Random(), Random(), Random());
            e->SetPosition(Vec3((float)x * scale, 0.0f, (float)z * scale) + offset, true);
            e->SetMass(1.0f);
    
            entities.push_back(e);
        }
    }

    But if I change to this, it crashes in the thread manager...

    e->SetPosition(Vec3((float)x * scale + Random() - 0.5f, 0.0f, (float)z * scale + Random() - 0.5f) + offset, true);

    The same code works fine in a new project and in some other projects.   I've had similar cases pop up here an there in my larger projects.  When and If I can pinpoint it further I'll make an example for you Josh.  Right now I'd thought I'd just mention it to see if anyone else has seen something similar yet.

    And now after a few more changes elsewhere the loop works again! :blink:

  6. I wonder if you would consider adding back the user data member for entities like in Leadwerks?  I find that quite useful, more so than the setting of fields and it wouldn't use lua.  Something like this perhaps?  Just a thought.

    shared_ptr<Object> object;
    void SetObject(shared_ptr<Object> object) {
    	this->object = object;
    }
    
    shared_ptr<Object> GetObject() {
    	return object;
    }

     

  7. This example throws an error saying lua51.dll is missing.

    #include "UltraEngine.h"
    #include "ComponentSystem.h"
    
    using namespace UltraEngine;
    
    int main(int argc, const char* argv[])
    {
        auto displays = GetDisplays();
        auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
        auto world = CreateWorld();
    
        auto framebuffer = CreateFramebuffer(window);
    
        auto camera = CreateCamera(world);
        camera->SetClearColor(0, 0, 1);
        camera->SetFov(70);
        camera->SetPosition(0, 2, -3);
    
        auto box = CreateBox(world);
        box->SetField("MyVar", "Hello");
    
        auto what_is_it = box->GetValue<String>("MyVar");
        
    
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

  8. This was working last night.  Now the program crashes without fail when parenting the camera to a pivot.

    #include "UltraEngine.h"
    #include "ComponentSystem.h"
    
    using namespace UltraEngine;
    
    int main(int argc, const char* argv[])
    {
        auto displays = GetDisplays();
        auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
        auto world = CreateWorld();
    
        auto framebuffer = CreateFramebuffer(window);
    
        auto camera = CreateCamera(world);
        camera->SetClearColor(0, 0, 1);
        camera->SetFov(70);
        camera->SetPosition(0, 2, -3);
    
        auto font = LoadFont("Fonts/arial.ttf");
        auto ui = CreateInterface(world, font, framebuffer->size);
        ui->SetRenderLayers(RENDERLAYER_1);
        ui->root->SetColor(0, 0, 0, 0);
    
        auto terrain = CreateTerrain(world, 512, 512);
    
        auto player = CreateCylinder(world);
        player->SetMass(1.0f);
        player->SetPhysicsMode(PHYSICS_PLAYER);
    
        auto cam_pivot = CreatePivot(world);
        cam_pivot->SetParent(player);
    
        camera->SetParent(cam_pivot);
    
    
        auto light = CreateDirectionalLight(world);
        light->SetRotation(35, 45, 0);
        light->SetRange(-10, 10);
    
        auto floor2 = CreateBox(world, 1000.0f, 0.1f, 1000.0f);
    
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            float move = 0.0f, strafe = 0.0f;
            if (window->KeyDown(KEY_W) == true) {
                move = 1.0f;
            }
            else if (window->KeyDown(KEY_S) == true) {
                move = -1.0f;
            }
    
            if (window->KeyDown(KEY_A) == true) {
                strafe = -1.0f;
            }
            else if (window->KeyDown(KEY_D) == true) {
                strafe = 1.0f;
            }
            player->SetInput(0.0f, move, strafe);
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

  9. 2 hours ago, Josh said:

    There are two things going on here. One is that the directional lights was being displayed in both cameras. The other is that the render target dimensions were not being considered when the lighting data was calculated.

    Update

    • Fixed the two problems above

    Confirming fixed, thanks.   I wonder - is there supposed to be a "copy code" button on all these code snippets that are posted?  I currently select the text by dragging with the mouse but vaguely remember a time there may have been this option on them?  Or maybe it's possible to add it? ^_^

  10. Here's an example for you.  The spot light seems to be showing correctly onto layer 2 however to the right of it there's something weird going on.  You can also see the shadow from the spinning cube on layer 0 showing up on layer 2.

     

    ShadowIssue2.thumb.png.beeb8c42af86f22ab31b5ee9c501c84a.png

     

    #include "UltraEngine.h"
    #include "ComponentSystem.h"
    
    using namespace UltraEngine;
    
    int main(int argc, const char* argv[])
    {
        auto displays = GetDisplays();
        auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
        auto world = CreateWorld();
    
        auto framebuffer = CreateFramebuffer(window);
    
        auto camera = CreateCamera(world);
        camera->SetClearColor(0,0,1);
        camera->SetFov(70);
        camera->SetPosition(0, 2, -3);
    
        auto font = LoadFont("Fonts/arial.ttf");
        auto ui = CreateInterface(world, font, framebuffer->size);
        ui->SetRenderLayers(RENDERLAYER_1);
        ui->root->SetColor(0, 0, 0, 0);
    
        auto ui_cam = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
        ui_cam->SetPosition((float)framebuffer->size.x * 0.5f, (float)framebuffer->size.y * 0.5f, 0);
        ui_cam->SetRenderLayers(RENDERLAYER_1);
        ui_cam->SetClearMode(CLEAR_DEPTH);
    
    
        auto tex_buffer = CreateTextureBuffer(512, 512);
        auto cam2 = CreateCamera(world);
        cam2->SetRenderLayers(RENDERLAYER_2);
        cam2->SetClearColor(1, 0, 0);
        cam2->SetRenderTarget(tex_buffer);
        cam2->Move(0, 1, -3);
    
        auto light2 = CreateSpotLight(world);
        light2->SetPosition(1, 2, 0);
        light2->SetRotation(90,0,0);
        light2->SetColor(2);
        light2->SetRenderLayers(RENDERLAYER_2);
    
        auto floor = CreatePlane(world, 10.0f, 10.0f);
        floor->SetRenderLayers(RENDERLAYER_2);
    
        auto b = CreateBox(world);
        b->SetPosition(0, 1, 0);
        b->SetRenderLayers(RENDERLAYER_2);
    
        auto box2 = CreateBox(world);
        box2->SetPosition(0,1,0);
    
        auto mat = CreateMaterial();
        mat->SetTexture(tex_buffer->GetColorAttachment());
    
        auto sprite = CreateSprite(world, 512, 512);
        sprite->SetRenderLayers(RENDERLAYER_1);
        sprite->SetMaterial(mat);
    
    
        auto light = CreateDirectionalLight(world);
        light->SetRotation(35, 45, 0);
        light->SetRange(-10, 10);
    
        auto floor2 = CreateBox(world, 1000.0f, 0.1f, 1000.0f);
    
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            box2->Turn(0, 1, 0);
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

  11. 25 minutes ago, Josh said:

     Update

    • Fixed pivots crashing when render layer set
    • Lights will now use their render layers both for which cameras they appear in, and which objects will appear in their shadow
    • Added SetRenderLayers(const unsigned int) override so you can just specify integer bit flags (1 + 2, 65, etc). I might get rid of the RENDERLAYER_N constants because it's an advanced feature anyways, and anyone who uses Ultra Engine has already proven they are very smart by making the choice to use Ultra Engine.

    Pivot crash is fixed, thanks.  I'm still getting a shadow from a cube in layer 0 cast onto a plane in layer 2 though...

    ShadowOntoLayer1.thumb.png.e2e96d62b90ba4c8c99fa74b64202f37.png

    scene_pivot = CreatePivot(world);
    scene_pivot->SetRenderLayers(RENDERLAYER_2);
    
    floor = CreatePlane(world, 10.0f, 10.0f);
    floor->SetParent(scene_pivot);
    floor->SetRenderLayers(RENDERLAYER_2);
    
    camera_pivot = CreatePivot(world);
    camera_pivot->SetRenderLayers(RENDERLAYER_2);
    
    camera = CreateCamera(world);
    camera->SetRenderLayers(RENDERLAYER_2);
    camera->SetParent(camera_pivot);
    camera->SetFov(70.0f);
    camera->SetClearColor(1,0,0);
    camera->SetHidden(true);

    I can put together a better example tomorrow if you need it.

  12. I see that materialD is an unsigned int but there are several checks to see if it is -1 throughout the shaders.  I assume it's working okay because there is always a default material?

    layout(location = 5) flat in uint materialID;

     

    if (materialID != -1)
    {
    	material = materials[materialID];
    }

     

  13. And now I can manipulate the vertices around a single bone with the shaders.  Here only the toe bone is raised by 1.0f.  It's just a matter of finding a way to identify the bone I want to edit and deciding on the right way to edit them.  It will probably be something like expanding the vertices away from the bone's axis within a certain range and reducing that range to 0 as it nears either end of the bone.  Tomorrow I'll see what I can do.

    CharacterBoneMorphing.thumb.png.848522a9e24f71296346443130c9855d.png

    • Like 3
×
×
  • Create New...