Unity-更改顶点颜色

时间:2018-09-08 14:20:41

标签: unity3d

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

    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;

在场景中,我将3D游戏对象作为球体,玩场景时我没有看到颜色的任何变化。请建议

输出为

enter image description here

1 个答案:

答案 0 :(得分:0)

您的代码很好。

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

就是这样。

有什么不对吗? :D

由于3D网格的渲染效果较差,粒子着色器在3D网格上看起来效果不佳。

您必须创建第二个较小的对象,并分配一些东西来阻塞/隐藏主对象中的空白空间。

例如:

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
            }
        }

    }
}
}

现在所有内容都会按原样呈现。

相关问题