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

► Beast ◄

Discussion in 'Assets and Asset Store' started by Arkhivrag, Feb 3, 2017.

  1. BaltaRed

    BaltaRed

    Joined:
    Oct 14, 2018
    Posts:
    2
    Arkhivrag
    Do you think about creating an HDRP version?
     
  2. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,996
    Currently it is not planned.
    HDRP already has its own tessellation shader.
     
  3. Ignacii

    Ignacii

    Joined:
    May 23, 2013
    Posts:
    121
    Hello. Is triplanar supported now by any chance?
     
  4. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,996
    Yes.
     
    Ignacii and DragonCoder like this.
  5. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,745
    Awesome! Is there an example by chance? :)
     
  6. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,996
    Beast is integrated into Unity's Standard and Lit shaders and have identical rendering features.
    Triplanar effect is available only for tessellation DisplacementMap, and not for other maps.
     
  7. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,745
    Oh that is unfortunate... At least not what I'd have been looking for.
    Think otherwise it'd be the first shader to support good tesselation AND triplanar texturing.
     
    stonstad and Ignacii like this.
  8. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    671
    Arkhivrag, your code for generating smooth normals is catastrophically bad. Each time mesh.vertices or mesh.normals is called, it allocates a new array. Doing this in a loop compounds the issue.

    For detailed terrain or meshes, the difference is .... several minutes of processing time!


    Avoid
    Code (csharp):
    1.  
    2.  private Mesh GenerateSmoothNormals(Mesh sourceMesh)
    3.  {
    4.      if (sourceMesh == null)
    5.      {
    6.          Debug.LogError("GenerateSmoothNormals: 'sourceMesh' mesh is NULL.\n");
    7.          return null;
    8.      }
    9.      if (sourceMesh.normals == null || sourceMesh.normals.Length != sourceMesh.vertexCount)
    10.      {
    11.          Debug.LogError("GenerateSmoothNormals: 'sourceMesh' mesh has no normals.\n");
    12.          return null;
    13.      }
    14.      Mesh newMesh = UnityEngine.Object.Instantiate(sourceMesh);
    15.      newMesh.name = newMesh.name.Replace("(Clone)", string.Empty);
    16.      newMesh.name += " (Smooth Normals)";
    17.      Dictionary<Vector3, Vector3> smoothNormalsHash = new Dictionary<Vector3, Vector3>();
    18.      for (int i = 0; i < newMesh.vertexCount; i++)
    19.      {
    20.          Vector3 key = newMesh.vertices[i];
    21.          if (smoothNormalsHash.ContainsKey(key))
    22.          {
    23.              smoothNormalsHash[key] = (smoothNormalsHash[key] + newMesh.normals[i]).normalized;
    24.          }
    25.          else
    26.          {
    27.              smoothNormalsHash.Add(key, newMesh.normals[i]);
    28.          }
    29.      }
    30.      List<Vector3> smoothNormals = new List<Vector3>(sourceMesh.normals);
    31.      for (int i = 0; i < newMesh.vertexCount; i++)
    32.      {
    33.          smoothNormals[i] = smoothNormalsHash[newMesh.vertices[i]];
    34.      }
    35.      newMesh.SetUVs(3, smoothNormals);
    36.      return newMesh;
    37.  }
    38.  

    Better
    Code (csharp):
    1.  
    2.             Vector3[] vertices = mesh.vertices;
    3.             Vector3[] normals = mesh.normals;
    4.             Dictionary<Vector3, Vector3> smoothNormalsHash = new Dictionary<Vector3, Vector3>();
    5.             for (int k = 0; k < vertices.Length; k++)
    6.             {
    7.                 Vector3 key = vertices[k];
    8.                 if (smoothNormalsHash.ContainsKey(key))
    9.                     smoothNormalsHash[key] = (smoothNormalsHash[key] + normals[k]).normalized;
    10.                 else
    11.                     smoothNormalsHash.Add(key, normals[k]);
    12.             }
    13.             List<Vector3> smoothNormals = new List<Vector3>(normals);
    14.             for (int k = 0; k < vertices.Length; k++)
    15.                 smoothNormals[k] = smoothNormalsHash[vertices[k]];
    16.             mesh.SetUVs(3, smoothNormals);
    17.  
     
    Last edited: May 14, 2024
    hopeful and Ignacii like this.
  9. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    671
    Using a Unity cube with the proposed smooth normals code in UV3, should I expect zero cracks or some cracks? I want to make sure I am fully understanding how to use the shader, and I do see some cracks. Thank you.


    upload_2024-5-13_15-46-12.png
     
  10. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,996
    Thanks for pointing. Fix will be included in new update.


    In your case cracks will be visible, as vertices UVs are still different.
     
    stonstad likes this.
  11. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    671
    Could you explain this to me like I am five? I am not sure I understand the requirement to remove cracks.
     
  12. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,996
    Smoothing normals reduces cracks on the edges of a mesh, but cannot remove them completely.
    Smoothing normals is not requirement, it is just an option.
     
    stonstad likes this.
  13. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    671
    Thanks Arkhivrag. So when we think about geometry like the Unity default cube, is there an approach that would allow it to show displaced tessellation without cracks -- or are 90 degree angles not supported? In other words, if you were me and you wanted to get this to work on a cube (assuming it is possible), what would you do?
     
  14. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    2,996
    To reduce cracks on the edges, vertices there should have the same displacement direction and size:
    Displacement direction is calculated based on the vertex normals and their smoothing is very helpful here, as it guarantees that neighbor vertices have the similar normals.
    Displacement size is read from the Displacement Map texture and vertices need to have the same UV to read the same pixel value from the map.

    For achieving crack-free tessellation specifically for Unity Cube, smooth its normals and use Displacement Map with constant color on perimeter:
    upload_2024-5-14_21-29-31.png
     
    stonstad likes this.
  15. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,745
    To make ot more clear: You need a texture with seemless borders. Just like ypu'd use a seemless Albedo texture for terrain. In the case of meshes however you gotta ensure that your UV coordinates actually result in continuous transitions across the seams.
     
    stonstad likes this.
  16. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    671
    Thank you! Great explanations all around!