Jump to content

SpiderPig

Developers
  • Posts

    2,272
  • Joined

  • Last visited

Posts posted by SpiderPig

  1. Okay, it's because it's far away from the origin.  This test grid is 2048 vertically up, move around and you can see the dark shapes move with the camera.  I wouldn't have thought this was far enough for floating point problems, but it may be related?

    #include "UltraEngine.h"
    
    using namespace UltraEngine;
    
    Vec3 mousepos = Vec3(0.0f);
    float move_adjustment = 0.1f;
    float move_speed = 1.0f;
    float lookspeed = 0.1f;
    float looksmoothing = 0.5f;
    
    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 light = CreateDirectionalLight(world);
        light->SetRotation(35, 35, 0);
    
        auto box = CreateBox(world);
        box->SetPosition(10.0f, 2049.0f, 10.0f);
    
        auto custom_model = CreateModel(world);
        auto mesh = custom_model->AddMesh();
    
        int size = 256, index = 0;
        for (int z = 0; z < size; z++) {
            for (int x = 0; x < size; x++) {
                mesh->AddVertex(x, 0.0f, z, 0.0f, 1.0f, 0.0f);
    
                if (x != 0 && x != size - 1 && z != 0 && z != size - 1) {
                    mesh->AddPrimitive(index, index - size - 1, index - 1);
                    mesh->AddPrimitive(index, index - size, index - size - 1);
                }
                index++;
            }
        }
    
        custom_model->UpdateBounds();
        custom_model->SetPosition(0.0f, 2048.0f, 0.0f);
        camera->SetPosition(0.0f, 2048.0f, 0.0f);
    
    
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            if (window->KeyHit(KEY_F2) == true) { camera->SetWireframe(!camera->GetWireframe()); }
    
            auto _displaySize = window->GetSize();
            float cx = Round((float)_displaySize.x / 2.0f);
            float cy = Round((float)_displaySize.y / 2.0f);
    
            auto mpos = Vec3(window->GetMousePosition().x, window->GetMousePosition().y, window->GetMousePosition().z);
            window->SetMousePosition(cx, cy);
            mpos = mpos * looksmoothing + mousepos * (1 - looksmoothing);
            auto dx = (mpos.x - cx) * lookspeed;
            auto dy = (mpos.y - cy) * lookspeed;
    
    
            auto camrot = camera->GetRotation();
            camrot.x += dy;
            camrot.y += dx;
            camera->SetRotation(camrot);
            mousepos = mpos;
    
            auto speed = 0.1f;
            if (window->KeyDown(KEY_SHIFT) == true) { speed = speed * 10.0f; }
            if (window->KeyDown(KEY_W) == true) {camera->Move(0, 0, speed);}
            else if (window->KeyDown(KEY_S) == true) { camera->Move(0, 0, -speed); }
            if (window->KeyDown(KEY_A) == true) { camera->Move(-speed, 0, 0); }
            else if (window->KeyDown(KEY_D) == true) { camera->Move(speed, 0, 0); }
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

  2. Well if I actually created a light it might help, eh?

    void Atmosphere::CreateSun()
    {
    	//light_sun = CreateDirectionalLight(world);
    	//light_sun->SetRotation(45, 35, 0, true);
    }

    My dark patch friends are back with the light but no shadows.  Shadows would need valid UV coords yeah?

    Shadows_002.thumb.png.71d9872c7be6013734d9b830a1513df3.png

  3. Here's something I've never mastered.  How to get my large voxel terrain to cast shadows onto itself?  At the very least I want nearby mountains to cast shadows.  Is this a separate pass done in a specific shader?  Or some highly advanced custom code I need to write?

  4. Not 100% convinced the normal map has been generated correctly.  But it's better than nothing.  I think there is some stepping going on, but that's probably the height-map.  I ended up using a sobel operator to calculate the normals.

    FoundationNormalMap_004.thumb.jpg.9e633b610f586a1f109beb353655f534.jpg

    FoundationNormalMap_003.thumb.jpg.fee5423427591f7de5f6a19b9d9a2129.jpg

    • Like 1
  5. I can't help but notice areas like this.  This is exactly what I wanted and got easily with voxels.  This is a strong gravity area right to the edge of the world and will provided a sharp transition between two gravity regions.  The player can tie a rope too a tree and jump off then quickly fall / land safely in another world. :D

    FoundationGravityMap_002.jpg.5207db77392623e4fe0b4966909a82e4.jpg

    • Like 2
  6. Got a little side tracked and generated a gravity map.  Red is 0% gravity and green is 100% with all the smooth interprolation between them as you approach the edge of the world.  This is going to be used in the erosion calculations as well which should give interesting results.  I'll add another element to this too - small pockets of reversed gravity where if you go over those, you'll have to be quick to get back down!  I might also make some 0% gravity areas around mountains as well.  Just for a bit of fun. ;)

    FoundationGravityMap_003.thumb.jpg.7c1a2bb20dcce54219c3b4283fa595bc.jpg

    • Like 1
  7. I re-call this issue ages ago when my project was in Leadwerks.  I reckon it's a bug but you can try this in C++.  I can't remember if you can even call this function like this, but give it a go and see what happens.

    System::CollectGarbage();

     

    • Confused 1
  8. I've been working on the foundation for the terrain.  Currently the voxel terrain samples an SDF field to get the basic shape.  It only ever samples what it needs to render so it is very fast.  But, it posses problems in areas such as procedurally placing foliage, buildings, roads and paths as well as calculating erosion to get nicer looking terrain.  While ray-casting the voxel terrain's octree is super fast I can't use that information to place things due to the fact that in the distance lower LOD levels won't give accurate height information.  As the player moves the terrain will change, leaving trees and buildings in the air.  I could update all these things to match the new terrain heights but that'll involve everything popping and moving around during game which I think won't be nice to look at.

    What I really wanted to do is create a 3D grid of floats for the entire voxel volume and just use that as the map for the entire volume.  But at a size of 2048^3 that is about 3x10^10 bytes.  Which is... something big in gigabytes.  I can't math today. :P

    Subdividing the terrain's octree to store this information (even though it doesn't have to be all rendered at once) will still result in massive amounts of RAM and is just unmanageable.

    So I think the only way is to cast my SDF function into a small set of heightmaps.  From them I can perform erosion, calculate normals maps (pass both of these maps to the shader to get some nice results at lower LOD levels) and use these maps to procedurally populate the world rather than ray-casting the octree all the time.

    As far as stopping the terrain from intersecting buildings and trees in the distance, I'll have to make the LOD algorithm to be smarter and reduce the poly count in areas where it won't matter too much to be noticeable.

    First attempt at ray-casting the SDF field gave more of a mask result.  And it took 10 minutes to calculate! :blink:

    FoundationMap_001.thumb.png.31e11682a6195258e2d7261af607d81c.png

    Got it to work a bit later though.  These are top down shots and it took about 40 seconds to ray-cast this 2048x2048 heightmap.  I'm pretty sure I can split this into workgroups and give it a compute shader.  I will need six heightmaps.  Once for each face of the cuboid terrain.  This results in a manageable 100MB of RAM / GPU Memory usage.  ^_^

    FoundationMap_002.thumb.png.739d5c76c062d9358d06c995ed5f4c98.png

    Now I need to make sure I can cast these heightmaps back into the voxel terrain.  Should be easy though.  ;)

    • Like 1
×
×
  • Create New...