Jump to content

Terrain Texture Problem


Go to solution Solved by Josh,

Recommended Posts

Posted

Is that the background of the world showing through the geometry, or a texturing problem? Is tessellation enabled? What GPU do you have?

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

Enabling tessellation didn't fix the problem. I used 

camera->SetTessellation(4);

as shown in the example in the documentation. This only made my camera movement jerky.

The Camera clear color is set to 0.125. Changing this made no difference.

The background is the Storm skybox from the Github. I commented this out and made no difference.

I think the problem may lie in my textures.

 

 

  • Like 1
Posted

Okay, I was trying to determine whether it was a pixel shader problem or whether those were cracks in the geometry

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

Update: I thought I found the problem.

I simplified my program to only one texture. I went through each one of my 5 textures until  I found that RockCiff_A is not the same as Rock_Cliff_A.

Eureka! problem solved.

Unfortunately not, I added all the textures back in and the problem persisted.

Further  investigation led me to suspect the weighting I was giving each material was the cause of the problem.

 

Here is my code.

 

  for (int x = 0; x < terrain->resolution.x; ++x) {
        for (int y = 0; y < terrain->resolution.y; ++y) {
            // Sample noise function at this point of the terrain
            const double noise = perlin.normalizedOctave2D((x * 0.01), (y * 0.01), 5);
            terrain->SetElevation(x, y, noise * 100);
            float slope = abs(terrain->GetSlope(x, y));
           
            if (slope < 5) {
                terrain->SetMaterial(x, y, grass, 0.7f);
           }
           else if (slope>5 && slope < 10) {
                terrain->SetMaterial(x, y, rocks, 0.7f);
           }
           else if (slope >10 && slope < 40) {
                terrain->SetMaterial(x, y, cliff, 0.7f);
            }
           else {
                terrain->SetMaterial(x, y, snow, 0.7f);
            }
           
        }

 

 

If the weight is 0.6f or less then no problem.

Terrain.thumb.png.ff658ad98aeb698526917421cae47ae5.png

Once you go over 0.65f then the artifact returns.

I don't fully understand how the weighting works. 

Posted
#include "UltraEngine.h"
#include "ComponentSystem.h"
#include "PerlinNoise.h"


using namespace UltraEngine;

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

    //Create a window
    auto window = CreateWindow("Terrain Experiment", 0, 0, 1920, 1080, 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(1);

    //Set environment maps
    const WString remotepath = "https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets";
    auto specmap = LoadTexture(remotepath + "/Materials/Environment/Storm/specular.dds");
    auto diffmap = LoadTexture(remotepath + "/Materials/Environment/Storm/diffuse.dds");
    world->SetEnvironmentMap(specmap, ENVIRONMENTMAP_BACKGROUND);
    world->SetEnvironmentMap(specmap, ENVIRONMENTMAP_SPECULAR);
    world->SetEnvironmentMap(diffmap, ENVIRONMENTMAP_DIFFUSE);

    auto mtl = CreateMaterial();
    mtl->SetRoughness(0.25);
    mtl->SetMetalness(0.5);

    auto ball = CreateSphere(world);
    ball->SetMaterial(mtl);


    //Create terrain from noise map

    auto terrain = CreateTerrain(world, 512);
    terrain->SetScale(1, 100, 1);

    const siv::PerlinNoise::seed_type seed = 656621u;
    const siv::PerlinNoise perlin{ seed };


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

    //Create grass material

    auto grass = CreateMaterial();
    diffusemap = LoadTexture("Materials/Grass01_albedo.dds");
    normalmap = LoadTexture("Materials/Grass01_normal.dds");
    dispmap = LoadTexture("Materials/Grass01_height.dds");
    grass->SetTexture(diffusemap, TEXTURE_DIFFUSE);
    grass->SetTexture(normalmap, TEXTURE_NORMAL);
    grass->SetTexture(dispmap, TEXTURE_DISPLACEMENT);

    //Create cliff rocks material

    auto cliff = CreateMaterial();
    diffusemap = LoadTexture("Materials/Rock_Cliff_albedo.dds");
    normalmap = LoadTexture("Materials/Rock_Cliff_A_normal.dds");
    dispmap = LoadTexture("Materials/Rock_Cliff_height.dds");
    cliff->SetTexture(diffusemap, TEXTURE_DIFFUSE);
    cliff->SetTexture(normalmap, TEXTURE_NORMAL);
    cliff->SetTexture(dispmap, TEXTURE_DISPLACEMENT);

    //Create snow material

    auto snow = CreateMaterial();
    diffusemap = LoadTexture("Materials/Snow_albedo.dds");
    normalmap = LoadTexture("Materials/Snow_normal.dds");
    dispmap = LoadTexture("Materials/Snow_height.dds");
    snow->SetTexture(diffusemap, TEXTURE_DIFFUSE);
    snow->SetTexture(normalmap, TEXTURE_NORMAL);
    snow->SetTexture(dispmap, TEXTURE_DISPLACEMENT);
    
    // Apply material based on noise function output

    for (int x = 0; x < terrain->resolution.x; ++x) {
        for (int y = 0; y < terrain->resolution.y; ++y) {
            // Sample noise function at this point of the terrain
            const double noise = perlin.normalizedOctave2D((x * 0.01), (y * 0.01), 5);
            terrain->SetElevation(x, y, noise * 100);
            float slope = abs(terrain->GetSlope(x, y));
           
            if (slope < 5) {
                terrain->SetMaterial(x, y, grass, 0.6f);
           }
           else if (slope>5 && slope < 10) {
                terrain->SetMaterial(x, y, rocks, 0.6f);
           }
           else if (slope >10 && slope < 40) {
                terrain->SetMaterial(x, y, cliff, 0.6f);
            }
           else {
                terrain->SetMaterial(x, y, snow, 0.6f);
            }
           
        }
    }


    //Camera controls

    auto actor = CreateActor(camera);
    actor->AddComponent<CameraControls>();

    //Main loop

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

This is my full code.

I use Ryo Suzuki Perlin Noise library from here.

My textures Textures.zip from Textures.com.

The other assets are from UltrEngine Github.

Posted

Okay, I have the same effect, although I had to replace those 0.6 numbers with something higher. Investigating now...

  • Like 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted
1 minute ago, Canardian said:

One thing I noticed in your code: when slope is exactly 5 or 10 you paint snow.

Good catch! However, the artifact still appears with this code:

            if (slope < 5) {
                terrain->SetMaterial(x, y, grass, 1.0f);
            }
            else if (slope < 10) {
                terrain->SetMaterial(x, y, rocks, 1.0f);
            }
            else if (slope < 40) {
                terrain->SetMaterial(x, y, cliff, 1.0f);
            }
            else {
                terrain->SetMaterial(x, y, snow, 1.0f);
            }

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

In fact you don't even need textures, and just two materials will do it:

#include "UltraEngine.h"
#include "ComponentSystem.h"
#include "PerlinNoise.hpp"

using namespace UltraEngine;

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

    //Create a window
    auto window = CreateWindow("Terrain Experiment", 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(1);

    //Set environment maps
    const WString remotepath = "https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets";
    auto specmap = LoadTexture(remotepath + "/Materials/Environment/Storm/specular.dds");
    auto diffmap = LoadTexture(remotepath + "/Materials/Environment/Storm/diffuse.dds");
    world->SetEnvironmentMap(specmap, ENVIRONMENTMAP_BACKGROUND);
    world->SetEnvironmentMap(specmap, ENVIRONMENTMAP_SPECULAR);
    world->SetEnvironmentMap(diffmap, ENVIRONMENTMAP_DIFFUSE);

    //Create terrain from noise map
    auto terrain = CreateTerrain(world, 256);
    terrain->SetScale(1, 100, 1);

    const siv::PerlinNoise::seed_type seed = 656621u;
    const siv::PerlinNoise perlin{ seed };

    //Create base material
    auto ground = CreateMaterial();
    ground->SetColor(0.25, 1, 0.25, 1);
    terrain->SetMaterial(ground);

    auto grass = CreateMaterial();
    grass->SetColor(1, 0.25, 0.25, 1);

    for (int x = 0; x < terrain->resolution.x; ++x) {
        for (int y = 0; y < terrain->resolution.y; ++y) {
            // Sample noise function at this point of the terrain
            const double noise = perlin.normalizedOctave2D((x * 0.01), (y * 0.01), 5);
            terrain->SetElevation(x, y, noise * 100);
            float slope = abs(terrain->GetSlope(x, y));
            if (slope < 5) {
                terrain->SetMaterial(x, y, grass, 1.0f);
            }

        }
    }

    //Camera controls
    auto actor = CreateActor(camera);
    actor->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.

Posted

I'm pretty sure I understand now why this is happening but I need to think about the most optimal solution...

  • Like 1

My job is to make tools you love, with the features you want, and performance you can't live without.

  • Solution
Posted

The fix is up now. It's just a modified shader, so you will need to sync your project files to get it.

  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

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...