Slastraf Posted August 22 Posted August 22 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. This is how the terrian looks like without height and just one material with a texture: 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 Quote
Josh Posted August 25 Posted August 25 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: 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; } Quote Let's build cool stuff and have fun.
Slastraf Posted September 1 Author Posted September 1 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); 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); Regardless of terrain basemap size, this happens. Quote
Recommended Posts
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.