Jump to content

SpiderPig

Members
  • Posts

    2,407
  • Joined

  • Last visited

Posts posted by SpiderPig

  1. I don't know if this is a bug or not actually.  You can see here that the green sphere bounces around a little when it rides over the blue cube and it starts to do the same toward the end of the red.  And should the picked position be offset from the cube like that?  I'm guessing it should be and the offset is the radius value?

    Can we get an Ultra Engine Bug Report forum too?  I could only create this topic in Leadwerks Bug Reports.

    Picking.gif.71838e21a2f6b407eef9bd379fe52f23.gif

    #include "UltraEngine.h"
    
    using namespace UltraEngine;
    
    bool PickFilter(std::shared_ptr<Entity> entity, std::shared_ptr<Object> extra) {
        if (entity->GetCollider() == nullptr) { return false; }
        return true;
    }
    
    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.125);
        camera->SetFov(70);
        camera->SetPosition(0, 2, -3);
        camera->SetRotation(25, 0, 0);
        camera->AddPostEffect(LoadPostEffect("Shaders\\PostEffects\\FXAA.json"));
    
        auto light = CreateDirectionalLight(world);
        light->SetRotation(35, 45, 0);
        light->SetColor(5);
    
        auto floor = CreatePlane(world, 100, 100);
        floor->Move(0, -1, 0);
    
        auto b1 = CreateBox(world, 2.0f);
        b1->SetPosition(-3.0f, 0.0f, 0.0f);
        b1->SetColor(1, 0, 0);
    
        auto b2 = CreateBox(world, 2.0f);
        b2->SetColor(0.0f, 0.0f, 1.0f);
        b2->SetPosition(3.0f, 0.0f, 2.0f);
        b2->SetRotation(0.0f, 45.0f, 0.0f);
    
        auto pivot = CreatePivot(world);
        
        auto rod_scale = 5.0f;
        auto rod = CreateCylinder(world, 0.05f);
        rod->SetCollider(nullptr);
        rod->SetParent(pivot);
        rod->SetRotation(90.0f, 0.0f, 0.0f);
        rod->SetPosition(0.0f, 0.0f, rod_scale / 2.0f);
        rod->SetScale(1.0f, rod_scale, 1.0f);
    
        auto sphere = CreateSphere(world, 0.25f);
        sphere->SetCollider(nullptr);
        sphere->SetParent(pivot);
        sphere->SetColor(0, 1, 0);
        sphere->SetPosition(0.0f, 0.0f, rod_scale);
    
        auto spin_speed = 0.5f;
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            pivot->Turn(0.0f, spin_speed, 0.0f);
    
            auto target_pos = Vec3(0.0f, 0.0f, rod_scale);
            target_pos = TransformPoint(target_pos, Mat4(), pivot->GetMatrix(true).Inverse());
    
            auto pick_info = world->Pick(pivot->GetPosition(true), target_pos, 0.5f, false, PickFilter, nullptr);
            if (pick_info.success) {
                sphere->SetPosition(pick_info.position, true);
            }
            else {
                sphere->SetPosition(target_pos, true);
            }
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }
  2. Not sure exactly what your tying to do.  Are you trying to get the terrain elevation under your physics entity?

    3 hours ago, EirikNesje said:

    Are there any examples on using a list of entities hit by the ray cast or will not the ray cast register the scene as a hit (not an entity) ?

    I don't know of any but you can loop through the entities and find the closest one by getting it's distance to the entity in question.

  3. I wonder what does Ultra need for a PBR material.  Diffuse, Normal, and is it roughness and metalness?  Can the later two be combined into one texture (R&G channels?)

    I decided to do some tests with the default normal and tangents and don't know what's happening here.  I haven't assigned a material to the model.  I thought it might have to do with the fact I haven't given it any textures to work with.

    mesh = CreateMesh(MESH_TRIANGLES, vertices, indices);
    mesh->UpdateNormals();
    //mesh->UpdateTangents();//This makes no difference to the result
    model->Clear();
    model->AddMesh(mesh);
    model->UpdateBounds();
    //model->SetMaterial(mat);

    Spots.thumb.png.d7d2d6d6478f0257ff20ac0bd1297dd7.png

  4. 1 hour ago, Josh said:

    This is how the engine does it, but if you are procedurally generating the texture coordinates, it's a lot easier to reuse those vectors for the binormal/tangent, instead of reconstructing them from the texcoords:

    Thanks that'll help a lot.  I'm using the xyz position as the texcoords and will setup triplaner texturing soon.  Is that what you mean by procedually generated texcoords?  I need to learn more about what the tangent and bitangent actually represent.  Slowly getting a grasp on it I think.

  5. This is pretty much all you have to do for a UI camera.

    auto font = LoadFont("Fonts/arial.ttf");
    auto ui = CreateInterface(world, font, framebuffer->size);
    ui->root->SetColor(0.0f, 0.0f, 0.0f, 0.0f);//Might need this as I think the root panel is not transparent by default?
    
    auto camera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
    camera->SetPosition(float(framebuffer->size.x) * 0.5f, float(framebuffer->size.y) * 0.5f, 0);

    After that any widget you create will be rendered to that ortho camera and will be drawn on top of your scene.

  6. If you post a complete example I can give it a run for you if you like.  There might be something happening under the hood that's causing an issue with changing the camera's real-time and render target settings.  Otherwise I suggest using a second camera and then just delete that after the texture has been rendered too.  See if that works?

    1 hour ago, St0neD0es said:
    Error: Widget::SetTexture can only be used with a 3D interface
    Exception thrown at 0x00007FF70C845396 in SG23_d.exe: 0xC0000005: Access violation reading location 0x0000000000000378.

    Have you set up a UI camera?  This is required for rendering widgets on top of a 3D world.

  7. Just got a geometry shader working to only calculate normals for flat shading.  The only part that I have ever been and continue to be stumped at is the tangent and bitangent.  Am I on the right track using the edges of the triangle or is it more complex than that?

    #version 450
    #extension GL_GOOGLE_include_directive : enable
    #extension GL_ARB_separate_shader_objects : enable
    
    layout (triangles) in;
    layout (triangle_strip, max_vertices = 3) out;
    
    layout(location = 0) in vec4 color[];
    layout(location = 1) in vec3 normal[];
    layout(location = 2) in vec4 texcoords[];
    layout(location = 3) in vec3 tangent[];
    layout(location = 4) in vec3 bitangent[];
    layout(location = 5) flat in uint materialID[];
    layout(location = 6) in vec4 vertexCameraPosition[];
    layout(location = 7) in vec4 vertexWorldPosition[];
    layout(location = 9) in flat uint entityflags[];
    
    layout(location = 0) out vec4 _color;
    layout(location = 1) out vec3 _normal;
    layout(location = 2) out vec4 _texcoords;
    layout(location = 3) out vec3 _tangent;
    layout(location = 4) out vec3 _bitangent;
    layout(location = 5) flat out uint _materialID;
    layout(location = 6) out vec4 _vertexCameraPosition;
    layout(location = 7) out vec4 _vertexWorldPosition;
    layout(location = 9) out flat uint _entityflags;
      
    void main() {
    	vec3 e1 = normalize(gl_in[1].gl_Position.xyz - gl_in[0].gl_Position.xyz);
    	vec3 e2 = normalize(gl_in[2].gl_Position.xyz - gl_in[0].gl_Position.xyz);
    	vec3 norm = normalize(cross(e1, e2));
    
    	for(int v = 0; v < 3; v++){
    		gl_Position = gl_in[v].gl_Position; 
    		_color = color[v];
    		_normal = norm;
    		_tangent = e1;
    		_bitangent = e2;
    		_texcoords = texcoords[v];
    		_materialID = materialID[v];
    		_vertexWorldPosition = vertexWorldPosition[v];
    		_vertexCameraPosition = vertexCameraPosition[v];
    		_entityflags = entityflags[v];
    		EmitVertex();
    	}
        EndPrimitive();
    } 

    Shader.thumb.png.ace10bd77c403b9f66c8c0817a200203.png

  8. Here's some basic code of what I did if it helps.  Widget->SetTexture() is not available yet as Josh said above but once it is it should work just like that.  My code is more complex and spread-out than what I've written here but the general idea is it should render a cube in the centre of the camera and display it on the widget.  You can move the camera any where in the world you want.

    auto texture_buffer = CreateTextureBuffer(128, 128);
    
    auto camera = CreateCamera(world);
    camera->SetRenderLayers(2);
    camera->SetFov(70.0f);
    camera->SetRenderTarget(texture_buffer);
    
    auto cube = CreateBox(world);
    cube->SetRenderLayers(2);
    cube->SetPosition(0.0f, 0.0f, 2.0f);
    
    auto widget = CreatePanel(0, 0, 128, 128, ui->root);
    widget->SetTexture(texture_buffer->GetColorAttachment());

     

    • Thanks 1
    • Upvote 1
  9. I've narrowed down a problem with loading a pixmap in the new DDS format you supported.  I'm using a pixmap as an input mask and the widget should only go red when the mouse is over the white section of the image but it flickers on and off all the time.  Anyway, If you assign this same pixmap to the widget the program will crash.  Pretty sure both problems are one and the same.  If I export my input mask with a transparent section it all works.

    InputMaskImage.png.22623aced5c6a65970d1273bda675f6c.png

    #include "UltraEngine.h"
    
    using namespace UltraEngine;
    
    shared_ptr<Pixmap> input_mask = nullptr;
    
    bool Callback(const Event& event, shared_ptr<Object> extra) {
    
        auto process_input = true;
        auto target_size = event.source->As<Widget>()->ClientSize();
        auto size = input_mask->size;
        auto sx = size.x / target_size.x;
        auto sy = size.y / target_size.y;
        auto x = Clamp(event.position.x * sx, 0, input_mask->size.x - 1);
        auto y = Clamp(event.position.y * sy, 0, input_mask->size.y - 1);
        auto value = Red(input_mask->ReadPixel(x, y));
        process_input = (value == 0 ? false : true);
    
        event.source->As<Widget>()->SetColor(1, 1, 1);
        switch (event.id) {
        case EVENT_MOUSEMOVE: {
    
            if (process_input == true) {
                event.source->As<Widget>()->SetColor(1, 0, 0, 1);
            }
    
        }	break;
        }
    
        return true;
    }
    
    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.125);
        camera->SetFov(70);
        camera->SetPosition(0, 0, -3);
    
        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 w1 = CreatePanel(20, 20, 128, 128, ui->root);
        ListenEvent(EVENT_NONE, w1, Callback);
        w1->SetColor(0, 1, 0);
    
        input_mask = LoadPixmap("InputMask.dds");
        w1->SetPixmap(input_mask);//Crash here
    
        auto p = iVec2();
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            while (PeekEvent()) {
                auto ev = WaitEvent();
                ui->ProcessEvent(ev);
            }
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

    InputMask.zip

  10. Working pretty good now.  There is a noticeable delay (less so in release) when scrolling a lot of widgets.  I'm using SetShape() to position them as I move the wheel.    I tried a smaller example but it looked fine as it wasn't scrolling many widgets.  It looks like when the clipping region encompasses the whole widget they are then hidden?  Either way you might consider this a minor cosmetic issue but I'll mention it none the less.  If you want I can put together a larger example tonight.

    ScrollDelay.gif.8fc5208f32cf6728a93a7cfc04021816.gif

     

  11. Thankyou those issues are fixed.  But now there is another - when a child moves out of bounds and should be hidden completely it seems to pile up.  Here's a shot in my game of what's happening when I scroll some items on the left, and a smaller example is below.  Just move the red panel around with the arrow keys.

    ScrollPileUp.gif.9915477ff3192f911dd9ec0e4b1db4d2.gif

     

    #include "UltraEngine.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.125);
        camera->SetFov(70);
        camera->SetPosition(0, 0, -3);
    
        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 w1 = CreatePanel(20, 20, 128, 128, ui->root);
        w1->SetColor(0, 1, 0);
    
        auto w2 = CreatePanel(0, 0, 1, 1, w1);
        w2->SetColor(1, 0, 0);
    
        auto w3 = CreatePanel(0, 0, 32, 32, w2);
        w3->SetColor(0, 0, 1);
    
        auto p = iVec2();
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            while (PeekEvent()) {
                auto ev = WaitEvent();
                ui->ProcessEvent(ev);
            }
    
            if (window->KeyDown(KEY_UP)) {
                w2->SetShape(p.x, p.y -= 1, 256, 256);
            }
            else if (window->KeyDown(KEY_DOWN)) {
                w2->SetShape(p.x, p.y += 1, 256, 256);
            }
    
            if (window->KeyDown(KEY_LEFT)) {
                w2->SetShape(p.x -= 1, p.y, 256, 256);
            }
            else if (window->KeyDown(KEY_RIGHT)) {
                w2->SetShape(p.x += 1, p.y, 256, 256);
            }
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

  12. 10 minutes ago, Josh said:

    When I right-click the mouse the red panel appears. Maybe your installation is not up to date?

    That's correct but the blue panel remains at 1x1 pixels.  It is 32x32 panel and is offset by -10,-10.  So you should see a 22x22 blue square in the top left corner but it remains as a 1x1 pixel.

  13. I've found part (hopefully all) of the problem.  Setting the shape of the widget is not triggering a refresh of the clipping data.

    I also couldn't get any key input to work.  I only tried a few keys but they're not working since the last update.

    #include "UltraEngine.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.125);
        camera->SetFov(70);
        camera->SetPosition(0, 0, -3);
    
        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 w1 = CreatePanel(20, 20, 128, 128, ui->root);
        w1->SetColor(0, 1, 0);
    
        auto w2 = CreatePanel(0, 0, 1, 1, w1);
        w2->SetColor(1, 0, 0);
    
        auto w3 = CreatePanel(-10, -10, 32, 32, w2);
        w3->SetColor(0, 0, 1);
    
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            while (PeekEvent()) {
                auto ev = WaitEvent();
                ui->ProcessEvent(ev);
            }
    
            if (window->MouseHit(MOUSE_RIGHT)) {
                w2->SetShape(0, 0, 256, 256);
            }
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

  14. I'm trying to find the source of my UI issue, what does widget->clipregion represent?  In one case it is 0,0,1,1.  Does this mean it is only drawing one pixel of that widget and it is the top left corner?

    I read it wrong.  It's 0,0,1,0.

×
×
  • Create New...