Search Unity

tessellation problem

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

  1. tavovallejo

    tavovallejo

    Joined:
    Nov 22, 2014
    Posts:
    13
    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:
    41
    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:
    41
    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:
    13
    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:
    41
    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:
    13
    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:
    41
    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.