Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

tessellation problem

Discussion in 'Shaders' started by tavovallejo, Jan 19, 2017.

  1. tavovallejo

    tavovallejo

    Joined:
    Nov 22, 2014
    Posts:
    26
    Hi. I have a problem with phong tessellation and SkinnedMesh.
    When the scale of a bone is increased (in this case the head) the mesh gets distortion.
    To fix it you have to activate GPU Skinning, but unfortunately it is not working in version 5.5.0

    Could someone give me information on why this problem or some way to solve it.

    Thank you very much.

    5.4 Gpu Skining



    5.5 Gpu Skinning

     

    Attached Files:

    Last edited: Jan 19, 2017
  2. pdq72

    pdq72

    Joined:
    Sep 29, 2013
    Posts:
    43
    I am having the same problem. Did you report this as a bug? Using 5.5.0p3
     
  3. pdq72

    pdq72

    Joined:
    Sep 29, 2013
    Posts:
    43
    Was GPU skinning disabled for Unity 5.5 PC Platform? It no longer corrects this issue as described above.
     
  4. tavovallejo

    tavovallejo

    Joined:
    Nov 22, 2014
    Posts:
    26
    you can fix this on the cpu side by using BakeMesh function, cloning the original mesh and then loop through the normals:

    clonedNormlas=originalNormals / bakedNormals.magnitude;

    where i is the index.

    and then set the cloned mesh as shared mesh of the skinRenderer and set this clonned mesh normals as "clonedNormlas".

    more info:
    https://feedback.unity3d.com/sugges...lization?_ga=1.100289181.248724783.1477350678
     
  5. pdq72

    pdq72

    Joined:
    Sep 29, 2013
    Posts:
    43
    Hi tavovallejo, do you have a code snippet of this? Have worked very little with the BakeMesh function. Thanks.
     
  6. tavovallejo

    tavovallejo

    Joined:
    Nov 22, 2014
    Posts:
    26
    Code (CSharp):
    1.  public class SimpleNormalsMagnitudeFixer : MonoBehaviour
    2.     {
    3.  
    4.         public SkinnedMeshRenderer m_renderer;
    5.  
    6.         Mesh m_baked;
    7.         Mesh m_working;
    8.         Mesh m_original;
    9.  
    10.         Vector3[] m_originalNormals;
    11.         List<Vector3> m_DrawingNormals;
    12.  
    13.         void Awake()
    14.         {
    15.             m_original = m_renderer.sharedMesh;
    16.             m_working = UnityEngine.Object.Instantiate<Mesh>(m_original);
    17.             m_working.MarkDynamic();
    18.  
    19.             //do not know if this is necessary
    20.             m_baked = UnityEngine.Object.Instantiate<Mesh>(m_original);
    21.             m_baked.MarkDynamic();
    22.  
    23.             m_renderer.sharedMesh = m_working;
    24.             m_originalNormals = m_original.normals;
    25.             m_DrawingNormals = new List<Vector3>(m_originalNormals);
    26.         }
    27.  
    28.         void LateUpdate()
    29.         {
    30.             //on every frame gona be slow
    31.  
    32.             //we need to bake the original
    33.             m_renderer.sharedMesh = m_original;
    34.             m_renderer.BakeMesh(m_baked);
    35.             m_renderer.sharedMesh = m_working;
    36.  
    37.             //chage this to GetNormals on 5.6
    38.             var bakedNormals = m_baked.normals;
    39.  
    40.             for(int i = 0; i < m_originalNormals.Length; i++)
    41.             {
    42.                 m_DrawingNormals[i] = m_originalNormals[i] / bakedNormals[i].magnitude;
    43.             }
    44.             m_working.SetNormals(m_DrawingNormals);
    45.         }
    46.  
    47.         void OnDestroy()
    48.         {
    49.             m_renderer.sharedMesh = m_original;
    50.             Destroy(m_baked);
    51.             Destroy(m_working);
    52.         }
    53.     }
    you can see here http://answers.unity3d.com/questions/1197217/can-a-mesh-collider-work-with-an-animated-skinned.html, for guidance on a custom solution, that update only the changed bones instead of updating the entire mesh.
    to me its was very hard and time consuming to archive, but thats what i needed, becouse my bones gonna keep changing scale at runtime
     
    Last edited: Feb 15, 2017
  7. pdq72

    pdq72

    Joined:
    Sep 29, 2013
    Posts:
    43
    Thanks tavovallejo, that did it. I hope they make normal normalization optional for GPU Skinning. I don't understand why this was removed in the first place o_O
     
    Lars-Steenhoff likes this.
  8. mrtenda

    mrtenda

    Joined:
    Jun 6, 2017
    Posts:
    33
    I am having this issue in 2019.2.10f. Has anyone found a solution that does not involve rebaking meshes at runtime (as the solution posted above does)? It feels like this shouldn't be happening in the first place.

    upload_2020-1-30_4-31-33.png
     
    Last edited: Jan 30, 2020
  9. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,726
    Please post a bug report as this thread is really old...
     
  10. mrtenda

    mrtenda

    Joined:
    Jun 6, 2017
    Posts:
    33
    Actually, I just figured it out. My FBX files were exporting from Blender with the scale wrong in such a way that every SkinnedMeshRenderer's Transform would have a default scale of (100,100,100). This seems to cause problems with any shader that uses GPU tessellation.

    I resolved it by exporting from Blender with "Apply Scalings" set to "FBX All", which caused everything to have a (1,1,1) scale in the FBX when I brought it into Unity.

    upload_2020-1-30_6-52-51.png
     
unityunity