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);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM