unity3d 管线

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class MeshRenderExample :MonoBehaviour
{

    void Start()
    {
        string shaderText =
        "Shader \"DoubleSided\" {" + 
        "    Properties {"+
        "        _Color (\"Main Color\", Color) = (1,1,1,1)"+
        "        _MainTex (\"Base (RGB)\", 2D) = \"white\" {}"+
                //_BumpMap ("Bump (RGB) Illumin (A)", 2D) = "bump" {}
        "    }"+
        "    SubShader { "+
                //UsePass "Self-Illumin/VertexLit/BASE"
                //UsePass "Bumped Diffuse/PPL"
                
                // Ambient pass
        "        Pass {"+
        "            Name \"BASE\""+
        "            Tags {\"LightMode\" = \"PixelOrNone\"}"+
        "            Color [_PPLAmbient]"+
        "            SetTexture [_BumpMap] {"+
        "                    constantColor (.5,.5,.5)"+
        "                    combine constant lerp (texture) previous"+
        "            }"+
        "            SetTexture [_MainTex] {"+
        "                constantColor [_Color]"+
        "                Combine texture * previous DOUBLE, texture*constant"+
        "            }"+
        "        }"+
                
                // Vertex lights
        "        Pass {"+
        "            Name \"BASE\""+
        "            Tags {\"LightMode\" = \"Vertex\"}"+
        "            Material {"+
        "                Diffuse [_Color]"+
        "                Emission [_PPLAmbient]"+
        "                Shininess [_Shininess]"+
        "                Specular [_SpecColor]"+
        "            }"+
        "            SeparateSpecular On"+
        "                Lighting On"+
        "                    Cull Off"+
        "        SetTexture [_BumpMap] {"+
        "                constantColor (.5,.5,.5)"+
        "                    combine constant lerp (texture) previous"+
        "            }"+
        "            SetTexture [_MainTex] {"+
        "                Combine texture * previous DOUBLE, texture*primary"+
        "            }"+
        "        }"+
        "    }"+
        "    FallBack \"Diffuse\", 1"+
        "}";


        mesh = gameObject.AddComponent<MeshFilter>().mesh;
        MeshRenderer meshRender = gameObject.AddComponent<MeshRenderer>();
        meshRender.material = new Material(shaderText);
//        meshRender.material.shader = Shader.Find("Transparent/Diffuse");
        Debug.Log(meshRender.material.renderQueue.ToString());
        meshRender.material.color =Color.green;

        mesh.Clear();
        list = new List<Vector3>();
        list.Add(new Vector3(-0.5f,0.5f,0f));
        list.Add(new Vector3(0.5f,0.5f,0f));
        list.Add(new Vector3(0.5f,-0.5f,0f));
        list.Add(new Vector3(-0.5f,-0.5f,0f));
        count = list.Count;

        //===================================================
        triangles = new int[3 * (count - 2)];
        vertices = new Vector3[count];
        for (int i = 0; i < count; i++)
        {
            vertices[i] = list[i];    
        }
        int triangles_count = count - 2;
        for (int i = 0; i < triangles_count; i++)
        {
            triangles[3 * i] = 0;
            triangles[3 * i + 1] = i + 2;
            triangles[3 * i + 2] = i + 1;
        }
        mesh.vertices = vertices;
        mesh.triangles = triangles;
    }
    Mesh mesh;

    int[] triangles;    //用于记录绘制三角形所需要的顶点ID顺序
    int count;            //顶点数
    Vector3[] vertices; //用于存储绘制三角形的顶点坐标
    List<Vector3> list;

    void Update()
    {
        if(Input.GetMouseButton(0))
        {
            Debug.Log(Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y,0.8f)));
        }
    }
}

 

转载于:https://www.cnblogs.com/jiangjieqim/p/4655553.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值