unity3d - Unity - 更改顶点颜色
问题描述
我在更新回调中有以下代码
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 游戏对象作为球体,我在玩场景时看不到颜色有任何变化。请建议
输出是
解决方案
你的代码很好。
大多数内置着色器不显示顶点颜色,因此您必须使用“粒子”着色器之一,或修改/创建自己的着色器。
而已。
.
有什么不对劲,对吧?:D
粒子着色器在 Sphere 等 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
}
}
}
}
}
现在一切都按原样呈现。
推荐阅读
- python - python打包/解包数字指定字节数
- r - 为什么第 7 行只包含零?
- html - 如何在字符串输出中添加条件 html 输入是谷歌搜索查询
- listview - 在 Flutter 中,调用 Navigator.pop(context) 时 ListView.builder 会闪烁刚刚显示的图像,为什么?
- python - 是否可以递归地在 Leetcode 上实现问题 #171?
- html - 如何为我的应用程序存储 JSON 数据
- javascript - 使用 ECB 模式的 CryptoJS AES 加密使用相同的参数产生不同的结果
- visual-studio-code - 如何更改 vscode 侧边栏字体系列
- r - 如何在 Rmarkdown 中更改参考书目样式?
- angular - 测试中的角度路由器链接路由错误