Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Applying textures to my custom terrain

Discussion in 'General Graphics' started by Lazy_Evaluation, Aug 28, 2021.

  1. Lazy_Evaluation

    Lazy_Evaluation

    Joined:
    Nov 16, 2019
    Posts:
    15
    Hello! I've coded my first procedural terrain made with noise, some multithreading, random seeds and a subdivision of the map in "chunks", aka custom meshes. I followed most of the tutorials by Sebastian Lague on Youtube, but I don't really like the way he handles the "painting" of the terrain.
    My question is: What is a nice texture system for my terrain (aka custom meshes) where I can modify every texture by the player at runtime (digging, planting grass etc) and choosing every tile by code (not just by height but by biome, position etc)? I also need to save this data and load it back.
    I currently create a texture that just choose his basic color by the height of the tile. Most of the tutorials online shows how to use a shader to do this and paint a texture instead of a color in the terrain, but all the shaders do this automatically by height, and I want to be able to do biomes, different types of grass/textures for a zone, modify the ground's texture with the player etc.
    However it seems like I'm very far from the solution, because I have no clue on how to do this. I have no idea on how to use shaders to do a dynamic and player-influenced terrain texture, so I tried using Texture2D. The main problem is that even small textures with low resolution are really time expensive. Every chunk has its own texture, creating it costs a lot of time (and with a very low resolution! like, 10x10 pixels per square meter), and lower the fps by a lot. And I don't know how to scale down my external texture (e.g. the grass texture), because they are pretty big (images 3000x3000) and I am trying to cut off a square of about 300 square pixels (with "GetPixels) and then applying that to a small section of 10 squared pixels (the tile in the chunk's texture).
    So what I get is something like this: every tiles is scaled really bad into something that recalls the original image, but it sucks.
    T1.PNG
    (The cube is the average dimension of a player: that shows how big are the pixels in the terrain).
    And the effect that I'd like to get is:
    Grass 2.png
    (That's my grass texture.)
    I don't even know how to "melt" two different textures together, to make things smoother in the biome's borders (e.g. grass and sand).
    Tl:dr I'm doing in a wrong way something that is slow and is just a small part of the big problem: i'm completely out of the right path.
    If someone can point me to the right direction I would really appreciate that. I've looked online for tutorials but everyone uses just some assets, or some shader, in a way that's not doable with what I'm doing.
    The basic effect that I'd like to get is something like Valheilm's terrain: a nice and procedural terrain with a nice texture.
    T3.PNG This is my current terrain without any experimental texture. Just tiles with a clean color: green is grass, yellow sand, brwon mountain and blue the sea. Every tile is a pixel in the Texture2D of the chunk (about a 95x95 texture, per chunk. With my texture is a 400x400... per chunk.).

    Trying my system with the grass:
    T2.PNG (that's basically a zoom-out of the previous image).

    It looks kinda okay when you look it from far away, but it doesn't look ok when you're close. And it lags a lot.

    Thanks a lot for every help you can give me! If you can point me to the right direction with tutorials, tips or anything I would really appreciate it.
     
    Last edited: Aug 28, 2021
  2. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    296
    i tried an idea with texture arrays

    Choose
    texture_A from vertex.Red
    texture_B from vertex.Green
    then I just grabbed UV(red) to test the LERP on the choices with a procedural 'quad' (line with 2 segments)

    arrayLerp.gif arrayBlend.png


    aside from the LERP being a simplistic blend artistically it sorta works in theory

    this procedural geos batch (at least as far as I can tell technically) and use 2 texture fetches so should be 'cheap' in terms of pixelA x pixelB in the frag.. i think.

    depending on how you generate or import terrain, you may need a 3rd image that is made at runtime, the Red and Green values become your array index lookup.. as well as computing the borders. (youd really only want to do a LERP on borders and use a simple array material for the pure zones)

    this also get's more complex with corners that have more than 2 textures to blend.
    but this is getting outside of scope for me, i just had an idea about TextureArrays I wanted to test with
     
    Last edited: Aug 28, 2021
  3. Lazy_Evaluation

    Lazy_Evaluation

    Joined:
    Nov 16, 2019
    Posts:
    15
    This seems a nice solution to blend two biomes together but.. I still need a system for my world. Because my texture system is pretty broken (and laggy)...