Question by 
               antoine-_-champion · Jun 15, 2019 at 06:21 PM · 
                shadermeshsubmesh  
              
 
              How to apply shader to all submeshes of a gameobject?
I'm assigning a script component that renders a shader to a gameobject.
The vertex shader is using the normals in order to outline the object. The normals are gathered in the script component:
     var bakedMeshes = new HashSet<Mesh>();
 
     foreach (var meshFilter in GetComponentsInChildren<MeshFilter>()) {
 
       // Skip duplicates
       if (!bakedMeshes.Add(meshFilter.sharedMesh)) {
         continue;
       }
 
       // Serialize smooth normals
       var smoothNormals = SmoothNormals(meshFilter.sharedMesh);
 
       bakeKeys.Add(meshFilter.sharedMesh);
       bakeValues.Add(new ListVector3() { data = smoothNormals });
     }
However, if the GameObject has several submeshes with subsequent materials, the shader is only applied to the first submesh.
I tried to combine all the submeshes in a single mesh before gathering the normals, with the same result.
What can I do in order to apply the shader to the whole GameObject?
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                