VulkanSceneGraph icon indicating copy to clipboard operation
VulkanSceneGraph copied to clipboard

Failed to render HeightMap

Open CHristopher-G-C opened this issue 6 months ago • 8 comments

**Code: { vsg::ref_ptrvsg::TileDatabaseSettings settings; settings->elevationLayer = "http://127.0.0.1:80/wdem/{z}/{x}/{y}.tiff"; settings->elevationScale *= 100.0; settings->elevationLayerCallback = [](vsg::ref_ptrvsg::Data data)->vsg::ref_ptrvsg::Data { if (data.get()) { data->dirty(); } return data; }; } We guess the displacementMap is not working in internal shader-set.

screenshot for dev-branch 2025-6-6 "vsgdynamictexture" Image

**Desktop:

  • OS: Win11
  • Version lasted release and 2025-6-6 cloned main-branch
  • GPU: Nvidia GTX 1660

CHristopher-G-C avatar Jun 07 '25 04:06 CHristopher-G-C

while running, looks like this: Image

CHristopher-G-C avatar Jun 07 '25 04:06 CHristopher-G-C

It not possible to provide any guidance as it's so open ended about what you are doing and what you are expecting.

The vsgdynamictexture example and vsgtiledatabase with vsg::TileDatabase are two diferent approaches that do two different things.

I don't know how you are mixing them or why.

So please could you just roll back to what you are trying to achieve, at a high level, and we can then point you in the right direction.

robertosfield avatar Jun 07 '25 08:06 robertosfield

vsg::TileDatabaseSettings does not work well, we guess the displacementMap is not working in internal shader-set. So I tested the "vsgdynamictexture" example with --hf command line, then i found it not work too...

CHristopher-G-C avatar Jun 07 '25 09:06 CHristopher-G-C

You reply isn't helpful.

What do you mean "TileDatabaseSettings does not work well".

What do you mean by "internal shader-set".

Please provide the exact command line usage you've used with vsgdynamictexture so that others can test out exactly what you are doing.

Also, I asked for information about what you are trying to do at a high level. I don't ask stuff out of curiosity, it's key to giving you the help you actually need.

robertosfield avatar Jun 07 '25 10:06 robertosfield

I run "vsgdynamictexture.exe --hf" , a black rectangle with no height-map shows up. which is not my expect. All We need is make sure "hello_world" example from "vsgTutorial" work with terrain tileset. But this example also not working. I guess these problems is connected. That why i ask them both. my code here:

#include <vsg/all.h>
#include <vsgXchange/all.h>
#include <iostream>

int main(int argc, char * * argv)
{
// Section 1: Create the scene graph
//
    // create options object that is used to guide IO operations
    auto options = vsg::Options::create();
    options->fileCache = vsg::getEnv("VSG_FILE_CACHE");
    options->paths = vsg::getEnvPaths("VSG_FILE_PATH");
    options->add(vsgXchange::all::create());

    vsg::ref_ptr<vsg::TileDatabaseSettings> settings;

    vsg::CommandLine arguments(&argc, argv);
    if (true)
    {
        // setup ready map settings
        settings = vsg::TileDatabaseSettings::create();
        settings->extents = { {-180.0, -90.0, 0.0}, {180.0, 90.0, 1.0} };
        settings->noX = 2;
        settings->noY = 1;
        settings->maxLevel = 5;
        settings->originTopLeft = false;
        settings->lighting = false;
        settings->projection = "EPSG:4326";
        settings->imageLayer = "http://127.0.0.1:80/wdom/{z}/{x}/{y}.png";
        settings->elevationLayer = "http://127.0.0.1:80/wdem/{z}/{x}/{y}.tiff"; // tiff pixel data type is float, unit is meter.
        settings->elevationScale *= 100.0;  // I tried several numbers [1.0, 32768.0].
        settings->imageLayerCallback = [](vsg::ref_ptr<vsg::Data> data)->vsg::ref_ptr<vsg::Data>
        {  // Hit
            if (data.get())
            {
                data->dirty();
            }
            return data;
        };
        settings->elevationLayerCallback = [](vsg::ref_ptr<vsg::Data> data)->vsg::ref_ptr<vsg::Data>
        {  // Not hit
            if (data.get())
            {
                data->dirty();
            }
            return data;
        };
    }

    if (!settings)
    {
        std::cout << "No TileDatabaseSettings assigned." << std::endl;
        return 1;
    }

    // create the scene graph using OpenStreetMap convenience function
    auto scene = vsg::TileDatabase::create();
    scene->settings = settings;// vsg::createOpenStreetMapSettings(options);
    scene->readDatabase(options);

//
// Section 2 : Create and setup the Viewer, Window and compile Vulkan objects
//
    // create the viewer and assign window(s) to it
    auto viewer = vsg::Viewer::create();

    // create window with default traits
    auto windowTraits = vsg::WindowTraits::create();
    auto window = vsg::Window::create(windowTraits);
    viewer->addWindow(window);

    // set up the camera
    double radius = vsg::WGS_84_RADIUS_EQUATOR;
    double nearFarRatio = 0.0001;

    auto lookAt = vsg::LookAt::create(vsg::dvec3(0.0, -radius*4.5, 0.0), vsg::dvec3(0.0, 0.0, 0.0), vsg::dvec3(0.0, 0.0, 1.0));
    auto perspective = vsg::Perspective::create(30.0, static_cast<double>(window->extent2D().width) / static_cast<double>(window->extent2D().height), nearFarRatio*radius, radius * 100.5);
    auto camera = vsg::Camera::create(perspective, lookAt, vsg::ViewportState::create(window->extent2D()));

    // add close handler to respond to pressing the window close window button and pressing escape
    viewer->addEventHandler(vsg::CloseHandler::create(viewer));

    // add a trackball event handler to control the camera view using the mouse
    viewer->addEventHandler(vsg::Trackball::create(camera));

    // create a command graph to render the scene on specified window
    auto commandGraph = vsg::createCommandGraphForView(window, camera, scene);
    viewer->assignRecordAndSubmitTaskAndPresentation({commandGraph});

    // compile all the Vulkan objects and transfer data required to render the scene
    viewer->compile();

//
// Section 3 : execute the frame loop
//
    while (viewer->advanceToNextFrame())
    {
        // pass any events into EventHandlers assigned to the Viewer
        viewer->handleEvents();

        // update the scene graph, such as adding/removing database pager tiles
        viewer->update();

        // record the commands in the scene graph and submit the completed command buffers to the vulkan queue
        viewer->recordAndSubmit();

        // wait for completion of the rendering and present the resulting color buffer to the Window's swap chain.
        viewer->present();
    }
    return 0;
}

CHristopher-G-C avatar Jun 09 '25 01:06 CHristopher-G-C

Over the weekend I testing different VSG/vsgXchange build combinations to see if I could reproduce issues when running vsgtiledatabase --rme and found that when I disabled the build of the vsgXchange::GDAL loader via vsgXchange CMake the terrain would not be loaded.

This failure was silent, so other than flat tiles, there was no other warning reported by the VSG to signify an issue. My best guess is this is what is happening on your system. The .tif DEM loading depends upon vsgXchange::GDAL. Could you check whether you have built vsgXchange against GDAL? ccmake/CMakeSetup will lists the vsgXchange_GDAL status.

I thought I had previously added reporting on failure to load tiles in vsg::tile/TileDatabase but on reviewing the code this didn't make it into VSG master. I have added a vsg::warn(..) message to the vsg::tile implementation to report failure to load the root tile's image, detail texture or elevation/terrain layer. This improvement is checked into VSG master with commit: c6e05a588cd1ee5363576d783f5dfec6c7d23d34

This is what I now see when I disable the vsgXchange::GDAL loader:

$ vsgtiledatabase --rme
Warning: tile::read_root() unable read elevation data, terrainPath = http://readymap.org/readymap/tiles/1.0.0/116/0/0/0.tif
Warning: tile::read_root() unable read elevation data, terrainPath = http://readymap.org/readymap/tiles/1.0.0/116/0/1/0.tif

robertosfield avatar Jun 09 '25 07:06 robertosfield

I have tried two VSG builds: ** VCPKG installed v1.1.10 with .\vcpkg.exe install vsgxchange[*] vulkanscenegraph[*] ... ** vsgFramework with default option and vcpkg integrated. I think all above are built with GDAL. Image

When running vsgtiledatabase --rme, I got errors in console output:

ERROR 1: ZIPDecode:Decoding error at scanline 240, incorrect header check
ERROR 1: TIFFReadEncodedStrip() failed.
ERROR 1: ZIPDecode:Decoding error at scanline 248, incorrect header check
ERROR 1: TIFFReadEncodedStrip() failed.
ERROR 1: ZIPDecode:Decoding error at scanline 224, incorrect header check
ERROR 1: TIFFReadEncodedStrip() failed.
ERROR 1: ZIPDecode:Decoding error at scanline 232, incorrect header check
ERROR 1: TIFFReadEncodedStrip() failed.
ERROR 1: ZIPDecode:Decoding error at scanline 240, incorrect header check
ERROR 1: TIFFReadEncodedStrip() failed.
ERROR 1: ZIPDecode:Decoding error at scanline 248, incorrect header check
ERROR 1: TIFFReadEncodedStrip() failed.
ERROR 1: ZIPDecode:Decoding error at scanline 216, incorrect header check
ERROR 1: TIFFReadEncodedStrip() failed.
ERROR 1: ZIPDecode:Decoding error at scanline 224, incorrect header check
ERROR 1: TIFFReadEncodedStrip() failed.
ERROR 1: ZIPDecode:Decoding error at scanline 232, incorrect header check
ERROR 1: TIFFReadEncodedStrip() failed.
ERROR 1: ZIPDecode:Decoding error at scanline 240, incorrect header check
ERROR 1: TIFFReadEncodedStrip() failed.
ERROR 1: ZIPDecode:Decoding error at scanline 248, incorrect header check
ERROR 1: TIFFReadEncodedStrip() failed.

Changed code lines in 'vsgtiledatabase.cpp':

92:        settings->maxLevel = 5;

94:        settings->imageLayer = "http://127.0.0.1:80/wdom/{z}/{x}/{y}.png";
95:        settings->elevationLayer = "http://127.0.0.1:80/wdem/{z}/{x}/{y}.tiff";

Tiff file properties: (sorry, Issues can't upload tiff file) Image

Render result: Image

THANKS for you response. These tiff files can successfully loaded in cesium on web browser, I can share tiff file if you provide some channel to upload them.

CHristopher-G-C avatar Jun 09 '25 09:06 CHristopher-G-C

I'm not involved in the vcpkg packing of VSG & vsgXchange, and rarely work under Windows, and very busy with development work right now so I have to take a step back and let others pick up on this issue for now.

Compiling VSG and vsgXchange from source might be required. But that's as much as I can help with.

robertosfield avatar Jun 09 '25 09:06 robertosfield