找回密码
 立即注册
查看: 181|回复: 0

Unity GL.Color设置颜色无效

[复制链接]
发表于 2022-12-28 14:19 | 显示全部楼层 |阅读模式
需要设置材质 lineMaterial.SetPass(0);
Material lineMaterial;void CreateLineMaterial()    {        Shader shader = Shader.Find("Hidden/Internal-Colored");        lineMaterial = new Material(shader);        lineMaterial.hideFlags = HideFlags.HideAndDontSave;        //设置参数        lineMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);        lineMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);        //设置参数        lineMaterial.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Off);        //设置参数        lineMaterial.SetInt("_ZWrite", 0);    }    private void Awake()    {        CreateLineMaterial();    }private void OnPostRender()    {        DrawMutilLine();    }void DrawMutilLine()    {        List<Vector3> posList = new List<Vector3>();        posList.Add(new Vector3(0.3f, 0.6f, 0));        posList.Add(new Vector3(1.2f, 1.8f, 0));        posList.Add(new Vector3(0.6f, 2.4f, 0));        posList.Add(new Vector3(1.5f, 2.7f, 0));        if (posList.Count < 2) return;        lineMaterial.SetPass(0);        GL.Begin(GL.LINES);        GL.Color(Color.green);        for (int i = 0; i < posList.Count - 1; i++)        {            GL.Vertex(posList);            GL.Vertex(posList[i + 1]);        }        GL.End();    }
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-5-9 08:05 , Processed in 0.094105 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表