Jump to content

Terrain is not using tessellation


klepto2
 Share

Go to solution Solved by Josh,

Recommended Posts

Confirmed:

#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);
    camera->SetTessellation(4.0);
    //camera->SetDepthPrepass(false);
    //camera->SetWireframe(true);

    //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", 100);

    //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);

    //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);
    rocks->SetDisplacement(4, -2);

    //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->SetMaterial(x, y, rocks, 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;
}

 

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

  • Solution

Fixed!

I'm seeing a lot of stair-stepping on the example above. It looks like it is occurring at a higher frequency than the heightmap data itself...

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

Since the latest update (terrain-normals) it seems the terrainsystem is broken. 

this sample (https://www.ultraengine.com/learn/Terrain_SetMaterial?lang=cpp) shows no terrain at all.  (only when you comment out the LoadHeightmap the terrain shows up)

And in my code it shows with LoadHeightmap (using a png instead of r16) but still the terrain is flat.

 

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

If you do this it will work:

    //Create terrain
    auto terrain = CreateTerrain(world, 512);
    terrain->LoadHeightmap("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Terrain/512.r16", 100);
    //terrain->SetScale(1, 100, 1);

However, I think I am going to change this behavior....

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

Or to make it work as before, you can set  the default back to 1.0 instead of 1000.0.

With 1.0 it works as expected: 

 terrain->LoadHeightmap("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Terrain/1024.r16",1);
    terrain->SetScale(1, 100, 1);

 

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

well, not in every case :

image.thumb.png.2bfe692372a8dc3cfcb15e8db5863342.png

Source of the heightmap: https://johnflower.org/heightmap/mt-ruapehu-mt-ngauruhoe

and the code how i apply the height:

terrain->SetScale(tscale, scale, tscale);
    auto pixmap = LoadPixmap("Heightmaps/hm_nz.png");
    pixmap = pixmap->Resize(terrain->resolution.x, terrain->resolution.y);
    float low_p = 1.0;

    for (int x = 0; x < terrain->resolution.x; x++)
        for (int y = 0; y < terrain->resolution.y; y++)
        {
           auto h = pixmap->Sample(iVec2(x, y)).r;
           terrain->SetHeight(x, y,h);
           //auto h = terrain->GetHeight(x, y);
           if (h < low_p)
               low_p = h;
        }
   
    terrain->SetPosition(0.0, -1.0 * (low_p * scale), 0.0);

 

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

thats why i said, not in every case ;) 

In my opinion pixmap is pixmap, if a user wants to use other formats than r16, then why not. Just make a disclaimer, that low precision can lead to artifacts.

  • Like 1
  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

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.

 Share

×
×
  • Create New...