Unity Shader 修改自定义变量的值
Properties { _R("Radius", Range(0,100)) = 1.0
_ColorTex("ColorTex (RGB)", 2D) = "red" {}
}
SubShader { Tags { "RenderType"="Opaque" } LOD 200 Cull off 。。。。 half _R;
sampler2D _ColorTex;
Texture2D colorTxt = new Texture2D(size, size);
Color[] colors = new Color[10]{
Color.black, Color.white,
Color.yellow , Color.gray ,
Color.green , Color.grey ,
Color.blue,Color.red,
Color.magenta,Color.cyan};
for (int j = 0; j != size; j++)
{
for (int i = 0; i != size; ++i)
{
colorTxt.SetPixel(i, j, colors[j]);
}
}
colorTxt.Apply();
gameObject.GetComponent<MeshRenderer>().material.SetFloat("_R", R);
gameObject.GetComponent<MeshRenderer>().material.SetTexture("_ColorTex", colorTxt);