Jump to content

Slastraf

Developers
  • Posts

    705
  • Joined

  • Last visited

Blog Comments posted by Slastraf

  1. 12 hours ago, Marcousik said:

    Very interesting ...

    I never thought about this.

    So you are generating the terrain depending on the height map, is that correct?

    Would this run with an open third person cam game typ?

    How do you do that???

     

     

    what do you mean exactly? I never had problems with cam and player.

    I know the terrain is not infinite and over the choosen map size, things become to disappear. BUt 4096x4096 is big enough if performances stay ok, isn't it

    First you need some kind of noise funciton in lua.
    https://github.com/Auburn/FastNoiseLite/releases/download/v1.0.3/FastNoiseLiteGUI-Win64.exe
    this is an example program to make differnent kinds of noises (-> https://github.com/Auburn/FastNoise_CSharp)
    This is perlin lua noise : https://gist.github.com/kymckay/25758d37f8e3872e1636d90ad41fe2ed
    Here an explaination. http://adrianb.io/2014/08/09/perlinnoise.html

    I have already implemented a noise generator in c++. 
    This is the most important part :
     

        int roundedPosX = std::round(playerPos.x/tileSize)-offset;
        int roundedPosY = std::round(playerPos.z/tileSize)-offset;
    
    	// skip calculations if player moved in the same chunk
        if(lastUpdatedPlayerPos.x==roundedPosX&&lastUpdatedPlayerPos.y==roundedPosY)
            return;
        else
            lastUpdatedPlayerPos = Vec2(roundedPosX, roundedPosY);
    
        const siv::PerlinNoise perlin(seed); // new chunk generation
        for(int x = roundedPosX; x<roundedPosX+chunkRows; x++)
        {
            for(int y = roundedPosY; y<roundedPosY+chunkRows; y++)
            {
              /**code skipped here */
                for(int i = 0; i<surface->CountVertices(); i++)
                {
                    Vec3 xy = surface->GetVertexPosition(i);
                  
                    float xPos = (x+(xy.x*.5)); //the vertex position ranges from 
                    float yPos = (y+(xy.z*.5));
    
                    float height = 0.5*perlin.accumulatedOctaveNoise2D(xPos/(frequency), yPos/(frequency), octaves);
                    height += 0.25*perlin.accumulatedOctaveNoise2D(xPos/(frequency)*2, yPos/(frequency)*2, octaves);
                    surface->SetVertexPosition(i, xy+Vec3(0,height,0));
    
                }
              
                surface->Update();
                // enable physics
                //c->chunkModel->SetShape(Shape::PolyMesh(surface));
                   
                c->chunkModel->UpdateAABB(Entity::LocalAABB | Entity::GlobalAABB);
                activeChunks.insert({Vec2(x, y), c});
            }
        }

    It takes the player position , converts it to chunk coordinates and spawns chunks around the player.

    For each vertice of a flat plane base we put the height of the vertice at the height of the perlin noise function. Thats it.
    All other things, e.g. chunks, loading, unloading is up to you because you wanted to make a third person game so you want to load bigger chunks with more vertices so you can look further.
    Honestly if I could go back I would do more reasearch for leadwerks plugins and write these things to the leadwerks internal terrain.
     

    12 hours ago, Marcousik said:

    You would check for the "whiteness" and if it is above a threshold,

    How do you do that???

     

    You look for each point on xz, the noise function returns for example -1 to  1. So if above 0.9 then generate road .

    //edit

     

    • Thanks 1
  2. 8 hours ago, Marcousik said:

    But there are things in an open world that have to remain persistent or your world will become nonsense. Nothing for the player that can be recognized is nothing good.

    Well for one, have an engine that allows you to walk more than 10 minutes into one direction with my character controller without despawning the camera.
    __________
    (alternative answer)
    __________
    There is a huge difference between random generation and procedural because the latter adds many rules to your liking.
    Procedural noise such as Perlin allows you to make height maps. The more "octaves" you add ( 0.5*perlin(frequency)+0.25*perlin(frequency)+) essentially (for i<n do  (i/2)*perlin(frequency) + (i/2*n)*perlin(frequency) ). Octaves = detail

    This looks something like this:
    a.PNG.c790ebee8e6b95c644c0c1887aaba462.PNG

    If you wanted to add roads for instance you can generate a ridged fractal

    b.PNG.5d1f1250895f41ae77bb0c7ba7809371.PNG
    and you see where this is going. You would check for the "whiteness" and if it is above a threshold, generate a road texture. Alternatively, use line detection algorithms.

    Same thing for the textures, but this is a whole different topic.Blender has good content on procedural textures e.g. Eevee procedural textures.
    This looks pretty persistent to me, and if scaled up on a map you have roads and detail. Maybe you can think of rules to generate villages ?
    It would require there to be a "straight" road patch, then make a origin in the center of that road, then generate some houses / npc's along the road and perhaps generate smaller "alleys" from the dot or orthogonal vector of the road.

    • Like 1
  3. 2 minutes ago, Marcousik said:

    Yes nice the problem with adding complexity and features like this is at the end FPS = 10

    For this we need LE 5 or a powerful engine.

    With LE 4.6 you can really make everything but by setting all features together on one map you will encounter big performance problems

    I have gone from 15 fps to 130 fps by optimizing my code about terrain generation and procedural textures.
    Chances are if it runs at 15 fps in LE 4 it will also run at 15 fps in LE 5
    There are many things that cannot be done in LE 4 without many workarounds such as transparency shaders, geometry shaders etc.

    Once the first run-able instance of the new engine is out I will start to write my own plugins for procedural stuff and do the things that right now are hard.
     

  4. 1 hour ago, reepblue said:

    Gonna be real. Once Ultra Engine/App Kit goes Linux, I'll probably be using Linux as my main OS. I already converted my software suite to Free/Open Source Software.

    I also perfer Mint these days as the cinnamon desktop is very close to Modern Windows and doesn't force everything to download as snap.

    This. My current new job will require usage of Linux at some point. It is a lot easier to get all the "stuff" for your environment unlike windows.

  5. You can add multiple gradient noise generators to make different type of height maps. You can also subtract height gradually more  at the edges and make an island generator. 
    In the library I used I used only one perlin noise, with different octaves and frequency of details in it. if you have less frequency hills will get larger on xz and if you have higher octaves you can get more hills and holes.

    //EDIT
    You can also generate Biomes / textures with https://en.wikipedia.org/wiki/Voronoi_diagram Voronoi.
    basically use one texture ant interpolate between them.

    • Like 1
×
×
  • Create New...