Jump to content

Recommended Posts

Posted

Hi,

I create my terrain using just code, following the documentation's example (c++).
However I get visual bugs, when I travel close, I get a black hole (seems like LOD breaks at some point).
Secondarily, the material shader seems to have broken.

I think it is enough to reproduce it by jus trunning this code .https://www.leadwerks.com/learn/CreateTerrain?lang=cpp

Also, take a look at the screenshot where a 2k texture should be rendered, only a very low res texture is rendered.image.thumb.png.45f290ec6e339fa41966d9593e8d657d.png


This is how the terrian looks like without height and just one material with a texture:
 image.thumb.png.eddf41a184ee1c07c7068262972385a7.png

The code I used for the second screenshot:

 

auto world = GetEntity()->GetWorld();

if (!world)
    return;

constexpr int terrainResolution = 512;
constexpr float terrainWorldSize = 4096;
constexpr float terrainHeightMeters = 90.0f;

terrain = CreateTerrain(
    world,
    terrainResolution,
    terrainResolution,
    terrainResolution
);

terrain->SetScale(
    terrainWorldSize / static_cast<float>(terrainResolution - 1),
    terrainHeightMeters,
    terrainWorldSize / static_cast<float>(terrainResolution - 1)
);

auto ground = CreateMaterial();

auto diffuseMap = LoadTexture(
    "https://raw.githubusercontent.com/Leadwerks/Documentation/master/"
    "Assets/Materials/Ground/river_small_rocks_diff_2k.dds"
);

auto normalMap = LoadTexture(
    "https://raw.githubusercontent.com/Leadwerks/Documentation/master/"
    "Assets/Materials/Ground/river_small_rocks_nor_gl_2k.dds"
);

ground->SetTexture(diffuseMap, TEXTURE_BASE);
ground->SetTexture(normalMap, TEXTURE_NORMAL);

terrain->SetMaterial(ground);
I

I could not reproduce this bug by using the Leadwerks editor, where it looks fine.
The code I mostly copied is from the documentation : https://www.leadwerks.com/learn/CreateTerrain?lang=cpp
 

Posted

When you call CreateTerrain I would leave the fourth parameter undefined to let the engine choose a size:

terrain = CreateTerrain(
    world,
    terrainResolution,
    terrainResolution
);

For a 512x512 terrain it will default to 64.

You can adjust the terrain clipmap size per-camera, and the terrain base map size to increase the resolution:

camera->SetTerrainClipmaps(2048, 16.0f, 4);
terrain->SetBasemapSize(4096);

When I run the code below, based on your partial sample above, this is what I see:

image.thumb.png.8be0f72474abdf3d9adf98572fcac389.png

Here is the code. Please run this and tell me if you see a problem, and what GPU you have:

#include "Leadwerks.h"
#include "ComponentSystem.h"

using namespace Leadwerks;

int main(int argc, const char* argv[])
{
    //Get the display list
    auto displays = GetDisplays();

    //Create a window
    auto window = CreateWindow("Leadwerks", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);

    //Create a world
    auto world = CreateWorld();
    world->SetAmbientLight(0);

    //Create a framebuffer
    auto framebuffer = CreateFramebuffer(window);

    //Create a camera
    auto camera = CreateCamera(world);
    camera->SetFov(70);
    camera->SetPosition(0, 50, 0);
    camera->SetRotation(45, 0, 0);
    camera->SetClearColor(0.125);

    //Sunlight
    auto light = CreateDirectionalLight(world);
    light->SetRotation(45, 35, 0);
    light->SetColor(2);

    constexpr int terrainResolution = 512;
    constexpr float terrainWorldSize = 4096;
    constexpr float terrainHeightMeters = 90.0f;

    auto terrain = CreateTerrain(
        world,
        terrainResolution,
        terrainResolution
    );

    terrain->SetScale(
        terrainWorldSize / static_cast<float>(terrainResolution - 1),
        terrainHeightMeters,
        terrainWorldSize / static_cast<float>(terrainResolution - 1)
    );

    auto ground = CreateMaterial();

    auto diffuseMap = LoadTexture(
        "https://raw.githubusercontent.com/Leadwerks/Documentation/master/"
        "Assets/Materials/Ground/river_small_rocks_diff_2k.dds"
    );

    auto normalMap = LoadTexture(
        "https://raw.githubusercontent.com/Leadwerks/Documentation/master/"
        "Assets/Materials/Ground/river_small_rocks_nor_gl_2k.dds"
    );

    ground->SetTexture(diffuseMap, TEXTURE_BASE);
    ground->SetTexture(normalMap, TEXTURE_NORMAL);

    terrain->SetMaterial(ground);

    // Increase terrain texture resolution
    camera->SetTerrainClipmaps(2048, 16.0f, 4);
    terrain->SetBasemapSize(4096);

    //Camera controls
    camera->AddComponent<CameraControls>();

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

 

Let's build cool stuff and have fun. :)

Posted
camera->SetTerrainClipmaps()

is not inside the Documentation. When I use different values I get very different results. See below.

    camera->SetTerrainClipmaps(740, 16.0f, 4);

image.thumb.png.adb269a958a01423c5f026238edc1189.png
I only get a normal looking result if I reduce the resolution to 740p.
If I keep it as you suggested, I only get one texture:

terrain->SetBasemapSize(4096);
camera->SetTerrainClipmaps(2048, 16.0f, 4);

image.thumb.png.94d817ce412bae21f16d063295941107.png

Regardless of terrain basemap size, this happens.
 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...