Search Unity

how to use sub mesh mask in mesh output in Visual Effect Graph?

Discussion in 'General Graphics' started by shibi2017, Oct 14, 2019.

  1. shibi2017

    shibi2017

    Joined:
    Jan 18, 2018
    Posts:
    153
    In my hdrp project, I want to use VEG to make some particles fx. And I find sub mesh mask, it seems can make some particle fx with animation(to my understanding).
    But I can't search any information from google, and I download the Unity-Technologies ScriptableRenderPipeline/com.unity.testing.visualeffectgraph in Github, but also nothing helpful.

    Is there anyone used this before? could you please give me some advice or instruction?

    I'm not a native speaker, feel free to ask me if there is anything confused you.
    Welcome to communicate in Chinese.
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    The sub mesh allows you to choose which sub meshes to show/hide.

    As a test, assign a mesh with 2 sub-meshes, and then set the mask to display only the first, then second sub mesh. Then change it to show both. Observe the difference between each change.

    Hopefully this makes it clear for you, good luck!
     
  3. shibi2017

    shibi2017

    Joined:
    Jan 18, 2018
    Posts:
    153
    thank you very much! And I figure it out with your instruction. But I hope we could increase the maximum number of submeshs.
     
  4. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    How do I make a mesh with 2 submeshes?) I literally have no idea! In blender u either output a mesh or several meshes in 1 file.
     
  5. shibi2017

    shibi2017

    Joined:
    Jan 18, 2018
    Posts:
    153
    hi here is a Submesh creator, you can use it inside unity to create submeshes.
     
  6. shibi2017

    shibi2017

    Joined:
    Jan 18, 2018
    Posts:
    153
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5.  
    6. [ExecuteInEditMode]
    7. using UnityEngine;
    8. using UnityEditor;
    9. using System.Collections;
    10. using System.Collections.Generic;
    11.  
    12. [ExecuteInEditMode]
    13. public class SubMeshCreator : MonoBehaviour
    14. {
    15.    public bool create = false;
    16.    private Mesh newMesh;
    17.    void Start()
    18.    {
    19.  
    20.    }
    21.  
    22.  
    23.    void Update()
    24.    {
    25.        if (create)
    26.        {
    27.            create = false;
    28.            Matrix4x4 matrix = transform.worldToLocalMatrix;
    29.  
    30.            //网格数组
    31.            MeshFilter[] meshFilters = this.GetComponentsInChildren<MeshFilter>();
    32.            CombineInstance[] combineInstances = new CombineInstance[meshFilters.Length];
    33.            Debug.Log(meshFilters.Length);
    34.            for (int i = 0; i < meshFilters.Length; ++i)
    35.            {
    36.                combineInstances[i].mesh = meshFilters[i].sharedMesh;
    37.                combineInstances[i].transform = meshFilters[i].transform.localToWorldMatrix * matrix;
    38.            }
    39.  
    40.            //材质数组
    41.            Material[] materials = new Material[meshFilters.Length];
    42.            MeshRenderer[] meshRenders = this.GetComponentsInChildren<MeshRenderer>();
    43.            for (int i = 0; i < meshRenders.Length; ++i)
    44.            {
    45.                materials[i] = meshRenders[i].sharedMaterial;
    46.            }
    47.  
    48.            //新建网格容器
    49.            newMesh = new Mesh();
    50.            newMesh.name = "newMesh";
    51.            //新网格赋值给当前mesh
    52.            MeshFilter mf = this.GetComponent<MeshFilter>();
    53.            mf.mesh = newMesh;
    54.            //合并网格
    55.            newMesh.CombineMeshes(combineInstances, true); //第二个参数的意思,如果为false,则表明有多个材质;如果是true,则表明一个材质。
    56.                                                            //如果是false的话,合并完的Mesh,那么就会有多个submesh,理应对应多个Material。
    57.                                                            //如果是true的话,那么合并完的mesh就只有一个submesh,理应对对应1个Material。
    58.                                                            //材质赋值
    59.            MeshRenderer mr = this.GetComponent<MeshRenderer>();
    60.            mr.sharedMaterials = materials;
    61.  
    62.            SaveAsset(newMesh);
    63.        }
    64.    }
    65.  
    66.  
    67.  
    68.    void SaveAsset(Mesh mesh)
    69.    {
    70.        AssetDatabase.CreateAsset(mesh, "Assets/" + name + ".asset");
    71.    }
    72. }
    73.  
     
    cubrman likes this.