Search Unity

How to use vertex shader

Discussion in 'General Graphics' started by meuklight, Jan 27, 2020.

  1. meuklight

    meuklight

    Joined:
    Feb 2, 2016
    Posts:
    12
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
  3. meuklight

    meuklight

    Joined:
    Feb 2, 2016
    Posts:
    12
    Does the use of Addition Vertex Stream on Mesh Renderer affect batching?
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Shouldn't.
     
  5. meuklight

    meuklight

    Joined:
    Feb 2, 2016
    Posts:
    12
    MeshFilter mf = GetComponent<MeshFilter>();
    Color32[] newColors = new Color32[mf.sharedMesh.vertices.Length];
    for (int vertexIndex = 0; vertexIndex < newColors.Length; vertexIndex++)
    {
    newColors[vertexIndex] = newColor;
    }
    Mesh testMesh = mf.sharedMesh;
    testMesh.colors32 = newColors;
    GetComponent<MeshRenderer>().additionalVertexStreams = testMesh;
    testMesh.UploadMeshData(true);

    Can you suggest how to use it, I have been using the above way but color not changing?
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Hmm, seems I was wrong about additionalVertexStreams not breaking batching. I seem to remember it didn't use to, but a quick search brought up a bunch of bugs with the features that have popped up over the last few years. I have a memory of an old tutorial (Unity 4.0 era?) that used it as an early way to do "instanced" meshes (ie: they still got batched, real instancing didn't exist yet), but maybe I'm mis-remember it.

    There's also a comment on twitter from @jbooth complaining about them being broken if you're trying to add vertex colors to a mesh that doesn't already have them. Not sure if that ever got fixed or not.
     
  7. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    There are a number of bugs with additionalVertexStreams. I don't think they got much use. Ideally, we should just be able to save a mesh in the scene, without saving it to disk. That would greatly reduce the need for additionalVertexStreams, as well as fix a ton of workflow issues.
     
    bgolus likes this.