Unity3d 统一-更改顶点颜色

Unity3d 统一-更改顶点颜色,unity3d,Unity3d,我在更新回调中有以下代码 Mesh m = GetComponent<MeshFilter>().sharedMesh; Color[] newColors = new Color[m.vertices.Length]; for (int vertexIndex = 0; vertexIndex < newColors.Length; vertexIndex++) { newColors[vertexIndex] = new Co

我在更新回调中有以下代码

    Mesh m = GetComponent<MeshFilter>().sharedMesh;
    Color[] newColors = new Color[m.vertices.Length];
    for (int vertexIndex = 0; vertexIndex < newColors.Length; vertexIndex++)
    {
        newColors[vertexIndex] = new Color(Random.value, Random.value, Random.value, 1.0f);

    }
    m.colors = newColors;
Mesh m=GetComponent().sharedMesh;
颜色[]新颜色=新颜色[m.vertices.Length];
对于(int-vertexIndex=0;vertexIndex
在场景中,我将3D游戏对象作为球体,在播放场景时,我看不到颜色的任何变化。请建议

输出为

您的代码很好

大多数内置着色器不显示顶点颜色,因此必须使用一个“粒子”着色器,或者修改/创建自己的着色器

就这样

有些不对劲,对吧D

粒子着色器在3D网格(如球体)上看起来很糟糕,因为它的alpha层渲染很差

您必须创建第二个稍微小一点的对象,并指定一些东西来阻止/隐藏主对象中的空白

例如:

Shader "Custom/VertexLitBlendedWithZ" {
Properties {
    _EmisColor ("Emissive Color", Color) = (.2,.2,.2,0)
    _MainTex ("Particle Texture", 2D) = "white" {}
}

Category {
    Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
    Blend SrcAlpha OneMinusSrcAlpha
    Cull Off ZWrite On Fog { Color (0,0,0,0) }

    Lighting On
    Material { Emission [_EmisColor] }
    ColorMaterial AmbientAndDiffuse

    SubShader {
        Pass {
            SetTexture [_MainTex] {
                combine texture * primary
            }
        }

    }
}
}

现在一切都按它应该的方式呈现。

嗨,丹尼尔,我是unity的新手,你能分享完整的代码或步骤让我进行实验吗。我在three.js中做了一些顶点着色的实验,你可以看看我的门户,我正在尝试在unity mesh中应用顶点着色。如果你还没有,您应该阅读unity文档中的材质:创建、指定给网格和使用自定义着色器。这些知识无处不在,没有必要在这里写下所有的步骤。剩下的就是我上面的答案。如果您有任何疑问,请随时提问。希望我的回答对你有用。祝你好运