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

Question How to get heightmap from alpha channel in shader graph?

Discussion in 'Shaders' started by Hatemsla, Sep 1, 2023.

  1. Hatemsla

    Hatemsla

    Joined:
    Oct 17, 2021
    Posts:
    61
    I have a texture in which the rgb contains a map of normals, and in the alpha channel a map of heights. In the official documentation, I read that in order to use the elevation map, you need to use the Parallax Mapping node, my problem is that this node accepts Texture 2d as input.
    My current shader:
    upload_2023-9-1_20-57-20.png
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,362
    You could just add the alpha value to the vertex position (with a multiplier etc to make it pop out more or less), right?
    Which documentation are you referencing here?
     
  3. Hatemsla

    Hatemsla

    Joined:
    Oct 17, 2021
    Posts:
    61
    I rely on this documentation
    Parallax Mapping Node | Shader Graph | 14.0.8 (unity3d.com)
    The bottom line is that I already have a ready-made elevation map, will simply adding the value from the alpha channel to the vertex position work correctly?
     
  4. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,362
    Depends what you need Exactly. Just try it.
    Never worked with parralex before, as I had no need for it
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,221
    Why is this a problem? You have the NormalHeight Texture2D node right there going into the texture sampler node. Plug it into the Parallax node too, and then use the output of the parallax node as the UV input for all other Sampler nodes.

    If you have a highly tessellated mesh, you can add the height map * vertex normal * some multiplier to the vertex position, but it’ll only offset the vertices the mesh has. Parallax node fakes the look of there being a height difference without actually modifying the mesh.
     
    DevDunk likes this.
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,221
  7. Hatemsla

    Hatemsla

    Joined:
    Oct 17, 2021
    Posts:
    61
    Do I understand correctly that such a solution will create a height map based on a normal map? Otherwise, I don't quite understand how Parallax Mapping finds out that it needs to take a height map from the alpha channel.

    EDIT: I saw that the parallax mapping has a sample channel elevation map.