Unity - 更改顶点颜色

问题描述 投票:0回答:1

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

    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

unity3d
1个回答
0
投票

你的代码很好。

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

而已。

.

有些事情不对,对吧? :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
            }
        }

    }
}
}

现在一切都按照应有的方式呈现。

© www.soinside.com 2019 - 2024. All rights reserved.