Search Unity

Vertex Color shader not drawing color?

Discussion in 'Shaders' started by XCreation555, Sep 13, 2020.

  1. XCreation555

    XCreation555

    Joined:
    Apr 14, 2019
    Posts:
    1
    I am truly sorry if this has been answered already, but I could not find anything which matched my particular issue. Other "vertex color shader not working" posts had simple issues such as not having the Universal Render Pipeline set in the Graphics settings, or not using a vertex shader, and while I'm sure I'm missing something simple, I don't think it's one of those.

    I have been following Brackeys' tutorial on terrain mesh generation, and everything up to the vertex coloring works. Here is everything about my setup I can show in one image:

    UnityVertexColor.PNG

    AFAICT, the Shader Graph shader TerrainShader should use the vertex color as the mesh's color, and the TerrainShader is assigned to the TerrainTexture, which is assigned to the TerrainGenerator's mesh renderer. The UniversalRenderPipelineAsset is assigned in the Graphics settings (there was no option to use the LWRP as in the tutorial, is this where the problem is?), and you can see in the console output that each vertex does have a different vertex color.


    private void OnDrawGizmos() {
    if (vertices == null) {
    return;
    }
    Vector3 drawPosition = meshFilter.transform.position;
    for (int i = 0; i < vertices.Length; i++) {
    Gizmos.color = mesh.colors[i];
    Gizmos.DrawSphere(drawPosition + vertices[i], .1f);
    }
    }


    I'm using gizmos to draw each mesh vertex's color, and you can see that the colors follow the gradient, but that the actual rendering is white, which is the color of the scene light (when the light's color changes, so does the color of the mesh). What am I doing wrong here? Thank you!
     
  2. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,555
    I notice in your Graphics Settings you haven't added "Shader Graphs/TerrainShader" to Always Included Shaders - this won't matter in the editor, but in builds it most likely will and not adding it there could result in pink or missing render of the terrain. As for why the shader itself doesn't appear to be working ..no idea, looks to me like it should.