klepto2 Posted August 10, 2023 Share Posted August 10, 2023 (edited) Hi, while i am working on my "Environement / Atmosphere / Weather" - system i'm working a lot with the terrain system and found some bugs and missing functionality from the API. Bugs: The layer system works only when you first assign a material to the terrain. In my opinion, this should not be required and a default terrain material should be set until it is overridden by the user (later planetary implementation or streaming terrain). On further investigation this was just a one time bug for me, but i let it here for reference. #include "UltraEngine.h" #include "Components/CameraControls.hpp" using namespace UltraEngine; int main(int argc, const char* argv[]) { //Get the display list auto displays = GetDisplays(); //Create a window auto window = CreateWindow("Ultra Engine", 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); //Create terrain auto terrain = CreateTerrain(world, 512); terrain->LoadHeightmap("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Terrain/512.r16"); terrain->SetScale(1, 100, 1); //Create base material auto ground = CreateMaterial(); auto diffusemap = LoadTexture("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Materials/Ground/river_small_rocks_diff_4k.dds"); auto normalmap = LoadTexture("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Materials/Ground/river_small_rocks_nor_gl_4k.dds"); ground->SetTexture(diffusemap, TEXTURE_DIFFUSE); ground->SetTexture(normalmap, TEXTURE_NORMAL); terrain->SetMaterial(ground); // Comment out this line and the whole terrain will be black //Create paint material auto rocks = CreateMaterial(); diffusemap = LoadTexture("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Materials/Ground/Rocks_Dirt_Ground_2k.dds"); normalmap = LoadTexture("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Materials/Ground/Rocks_Dirt_Ground_2k_dot3.dds"); auto dispmap = LoadTexture("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Materials/Ground/Rocks_Dirt_Ground_2k_disp.dds"); rocks->SetTexture(diffusemap, TEXTURE_DIFFUSE); rocks->SetTexture(normalmap, TEXTURE_NORMAL); rocks->SetTexture(dispmap, TEXTURE_DISPLACEMENT); int layer = terrain->AddLayer(rocks); terrain->SetLayerTextureMapping(layer, TERRAINMAPPING_VERTICAL); //Apply material based on terrain slope for (int x = 0; x < terrain->resolution.x; ++x) { for (int y = 0; y < terrain->resolution.y; ++y) { float slope = terrain->GetSlope(x, y); if (slope > 15.0f) { float wt = Min((slope - 15.0f) / 10.0f, 1.0f); terrain->SetLayerWeight(layer,x, y, wt); } } } //Camera controls camera->AddComponent<CameraControls>(); //Main loop while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { world->Update(); world->Render(framebuffer); } return 0; } Missing methods: 1. The Fill method is commented out in the header file and my should maybe renamed to FillLayer(int layerid) 2. The methods to set and get the layer scaling are missing, or better: they are in the protected area. 3 All get Methods for LayerProperties should be provided. Currently it is not possible to access things like the Slope / height constraints of a specific layer. Edited August 10, 2023 by klepto2 Addition 1 1 Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
klepto2 Posted August 10, 2023 Author Share Posted August 10, 2023 Also Terrain::GetElevation doesn't take the Terrain-Position into account. Which is understandable as the terrain matrix is fully modifiable (scale, position and rotation), but it should be mentioned in the Docs. 1 Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
Josh Posted September 6, 2023 Share Posted September 6, 2023 When I comment out the base material, the correct behavior is displayed. The SetLayerWeight command by default normalizes the weights, so each tile receives 100% weighting, since there is no other material present: Even if the normalize parameter is set to false (after the update coming later today) there will be no support for blending a material on top of the untextured terrain. There's an intermediate step that normalizes the weights again. My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Solution Josh Posted September 6, 2023 Solution Share Posted September 6, 2023 On 8/10/2023 at 12:54 AM, klepto2 said: 1. The Fill method is commented out in the header file and my should maybe renamed to FillLayer(int layerid) 2. The methods to set and get the layer scaling are missing, or better: they are in the protected area. 3 All get Methods for LayerProperties should be provided. Currently it is not possible to access things like the Slope / height constraints of a specific layer. 1. Added Fill() method as a convenience function. 2. Set/get layer scale are now public (in update later today) 3. These methods are now public. I think that addresses everything in this thread. My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts