Jump to content

SpiderPig

Members
  • Posts

    2,285
  • Joined

  • Last visited

Posts posted by SpiderPig

  1. I'm not sure if I'm actually setting the buffer correctly, but the problem here is it fails to save as a DDS image.

    #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, 10, 0);
    
        auto light = CreateDirectionalLight(world);
        light->SetRotation(35, 35, 0);
    
        auto box = CreateBox(world);
        box->SetPosition(10.0f, 2049.0f, 10.0f);
    
        int size = 1024;
        unsigned short* buffer = new unsigned short[size * size];
        for (int y = 0; y < size; y++) {
            for (int x = 0; x < size; x++) {
                buffer[(y * size) + x] = (unsigned short)Random(USHRT_MAX);
            }
        }
    
        auto data = CreateBuffer(size * size * 2);
        data->Poke(0, (const char*)buffer, size * size * 2);
    
        auto map = CreatePixmap(size, size, TEXTURE_R16, data);
        map->Save("Test.dds");
    
        delete[] buffer;
    
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

    Output:

    Saving texture "Test.dds"
    Error: Unsupported pixel format 76 can't be saved to DDS.
    Error: Failed to save texture "Test.dds".

     

  2. Can I still sample a half float texture like this?

    vec4 color = texture(texture2DSampler[textureID], texcoords.xy);

    Or is there a different function for this?  I don't know what the value of the vec4 would actually be...

  3. I want to save my heightmaps as R16 textures an use them for displacement and other things in shaders.  Are these textures sampled any different to normal RGBA textures?  Does the sample still return a vec4 with values in the range of 0 to 1?

  4. All six sides of the cuboid terrain are cast into their own heightmap so I can now do terrain erosion among other cool stuff.  The six sided map is then used to create the voxel terrain.  Here is the normal map turned into an atlas ready for the GPU.

    NormalAtas_001.thumb.jpg.4587cfc11b32123540c2dfe8c4eac9bf.jpg

    • Like 1
  5. Before starting the towns I had to fix a lot of core things with the voxel terrain.  Now that I've done that I have also fixed a problem in the ray-casting of the SDF causing stepping in the heightmap and thus stepping in the normal map.

    Much nicer.  I think it'd look better if the normal map was 4x bigger to give more detail, but I'll assess that after erosion maps and better texture placement are in use.

    FoundationMap_003.thumb.jpg.fe8fb37a25ddf94f7df5b106a360a8b5.jpg

    • Like 3
  6. 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;
    }

     

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

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

  9. 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
×
×
  • Create New...