Search Unity

Question Replace portion of texture after assigning material

Discussion in 'Shaders' started by oakesky, Dec 7, 2020.

  1. oakesky

    oakesky

    Joined:
    Sep 30, 2016
    Posts:
    10
    Hey guys,

    I'm trying to modify the texture of the giant terrain mesh in my map. The terrain is a procedurally created mesh and it presently blends an array of textures together based on the elevation (the y coordinate) into one material that is assigned to the mesh after creation. I would like a little more control over this so that rather than picking textures based on the y coordinate it blends in textures based on the x and z coordinate. In other words, after I procedurally generate a height map and build a mesh and assign textures based on elevation, I then want to be able to generate a perlin noise map and stitch together textures based on the values generated off of that noise map and then blend that layer into the textures already in place on the material/mesh.

    I based my scripts on a modified version of Sebastian Lague's tutorial:
    (https://github.com/SebLague/Procedural-Landmass-Generation) (
    )
    In fact, I haven't modified anything from his shader file.

    After reading the above I think that still sounds confusing so I drew a diagram:
    https://drive.google.com/file/d/1gWQ7Pys0LT5wFSHJltPyj4h8K_2bFn2G/view

    My current idea is that I could create one giant texture based off of the noisemap B and pull the texture off of the material assigned to the mesh ( which is the texture based on elevation) and loop through the pixels and blend the two together using setpixels then reassign it to the material.

    Is that even possible? How will that work for performance? Is it a bad idea to do that considering also that I generate new chunks on my map during runtime and will have to do this process fairly quickly.
    Another idea I had would require the shader to decide which texture it is supposed to use by passing in a 2d array, but I'm not very good with programming shaders so I'm trying to avoid this because I'm not sure if that even works?