Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question How to apply different normal map textures to different faces of a voxel

Discussion in 'Editor & General Support' started by Danixadem, Aug 26, 2020.

  1. Danixadem

    Danixadem

    Joined:
    Jul 31, 2018
    Posts:
    16
    I'm making a procedurally generated minecraft-like voxel terrain. Mesh generation and albedo channel texturing is flawless; however I need to apply different normal map textures for different cube faces regarding whether they're neighboring to another cube or not. Materials accepts only single normal map file and doesn't provide a sprite-sheet-editor kind of functionality for normal maps. So I have no idea about how to use selected slices out of normal map file as if they were albedo textures. I couldn't find any related resources about the problem. Any help will be appreciated. Thanks...
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,947
    This doesn't really have to do with Material per se, but it is how most of Unity's builtin shaders work. Materials are basically just a shader + parameters for that shader.

    The process of applying different parts of a texture to different parts of a 3d model is called "UV mapping" and you can do it in 3D modeling software such as Blender. Unity doesn't have builtin tools for this, you are expected to use external tools.
     
  3. Danixadem

    Danixadem

    Joined:
    Jul 31, 2018
    Posts:
    16
    Yes I "UV mapped" for albedo channel texturing and it works fine, however for my project normal maps must be set on the run according to perlin noise values (as for albedo textures). Therefore preset normal maps by a 3D program is not what I need.

    To be more exact about what I need, I shall say I'm looking for a sprite-sheet-like tool or a piece of code for matching the normal map uv coordinates to face mesh data of the voxel
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,947
    You can modify the UV mapping of your mesh at runtime by setting the UV array: https://docs.unity3d.com/ScriptReference/Mesh-uv.html

    This won't get you nice editor tools, but for a simple cube mesh it should be pretty straightforward.
     
  5. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,947
    Oh also I believe the built-in shaders all use the same UV map for albedo as for the normal maps. So you might need to create or find a custom shader that uses a different UV map for albedo and normal maps.
     
  6. Danixadem

    Danixadem

    Joined:
    Jul 31, 2018
    Posts:
    16
    Yes thanks, now I'm getting somewhere about the problem. Any idea about such readily available shader for free?
     
  7. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,947
    Are you using a scriptable render pipeline (URP or HDRP)? I think creating such a shader with Shader Graph would be pretty straightforward.
     
  8. Danixadem

    Danixadem

    Joined:
    Jul 31, 2018
    Posts:
    16
    Not yet, but if it is the way to go, then I'II delve into it soon
     
  9. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,947
    I wouldn't say "it's the way to go", it's just the only way I personally would know how to make such a shader, and the builtin render pipeline doesn't support Shader Graph. But that's because I'm a shader-writing amateur. One could write a shader that does it with code too. You might have some luck tracking down such a shader and getting more opinions on whether this is the right approach by posting over in the graphics subforum.
     
  10. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,947
  11. Danixadem

    Danixadem

    Joined:
    Jul 31, 2018
    Posts:
    16
    thanks mate, I will keep searching for it