Search Unity

Infinite Terrain Horizon

Discussion in 'World Building' started by Baalhug, Feb 19, 2019.

  1. Baalhug

    Baalhug

    Joined:
    Aug 12, 2013
    Posts:
    32
    Hello all. I've been creating an infinite terrain system where from perlin noise I create a grid of terrain objects (primitive planes, not integrated terrains) which are generated around the player as he moves. I've faced and solved a lot of problems like seamless border tiles because of the normals, mirror mesh creation in negative coordinates with perlin noise function, and a lot of optimization to avoid delays when recalculating new terrain on move (no gameobject.find functions, split work in coroutines, etc). I'm using a skybox with a custom shader based on Unity's procedural skybox shader.

    So everything is working good but I have hit a wall I can't go through: when player climbs a high mountain the line of the horizon in my skybox is far above the horizon created by the terrain, specially in the borders without mountains, or low borders of terrain. I've been researching a lot these past 2 weeks and I found multiple solutions but none of them seems to solve the problem entirely. I'm gonna list the workarounds with pro/cons:

    - Generating more terrains.
    If I preserve the max height of terrain at 1,000 and the generated terrains reach 20,000 in all directions, at the top of the highest mountains we get a low angle of sight (1/20) and the results are quite nice with a powerfull processor. 20,000 units in all direction means at runtime I have around 25,000 objects only for terrain, and 90% of it is too far from the player 90% of time to even see it. If you did the maths, yes, terrain objects are quite small, which helps a lot in runtime generation. But 160 tiles each side start to be too heavy to process specially for a regular mobile. So this solution is not my favourite.

    - Fog.
    I really dislike fog, it makes everything looks like a heavy day of summer when atmosphere is full of steam. I haven't go deep in this direction after tweeking around unity's fog system. The most remote mountains look grey and solid and this don't solve the problem in the horizon, which is still far above those solid grey mountain silhouettes. Maybe other fog systems like volumetric fog could do the job but again I can't depend on more processing power.

    - Skyline.
    This is an interesting idea because it seems very cheap for the client machine to process while keeping the quality on graphics. I've seen solutions like Horizon[ON] in Unity Store but this is not focused on infinite terrains because what you clearly see at some distance is completely different as you approach, actually mountains grow in the middle.
    I've been thinking in a way to draw a skyline based in perlin noise on distant tiles not rendered but it is impossible as I have to calculate everything from the edge of terrain up to the horizon and that's basically the same cost as first approach: generating all that terrain.

    - Shader.
    There are shaders (used mostly on runner games) which visually "bend" the objects as they are further away from camera. The problems of this approach are mainly 2: the result is not very realistic and you have to apply that shader to every object in scene so it may interfere with other shaders (like my custom multiple texture based on terrain generation shaders). Plus I must "round" the skybox for it to fit with the curved horizon.
    I've been thinking on another shader which "lowers" the horizon line based on player's camera height. Actually the custom shader I'm using for the sky sphere is based on the Unity's integrated procedural skybox shader, and it has some options to tweak with but I can't get any decent results, basically I can't lower skyline or horizon's position and keep shader working, though my skills in shaders are really basic, and anyway this approach means I have to try manually until i find a height value for the horizon based on height of camera which looks decent enough.

    Now the questions:
    Do you know a different technique to solve this problem? Do you know a different approach to the techniques mentioned to solve it?

    Any help would be really apreciated.

    I have attached a capture where you can see horizon line above terrain line with some fog applied and another one with double the size of terrain (double in length, square in area).
    terrain.png terrain ext.png
    Lastly another capture where you can see the sun rising over the skybox horizon which gives the impression of an island.
    terrain sun.png
     
    Last edited: Feb 19, 2019