Unity3d Shader開發(一)Properties

着色器可以定義一個參數列表,可以由開發者在材質檢視面板編輯參數。着色器文件中的Properties塊定義了這些參數:

   

    該文章出自【狗刨學習網】

    語法:

     Properties { 
          Property [Property ...]
           }


    定義屬性塊,其中可包含多個屬性,其定義如下 :


    name ("display name", Range (min, max)) = number


    定義浮點數屬性,在檢視器中可通過一個標註最大最小值的滑條來修改。


    _WaveScale ("Wave scale", Range (0.02,0.15)) = 0.07


    


    name ("display name", Color) = (number,number,number,number)


    定義顏色屬性。


     _RefrColor ("Refraction color", Color) = (.34, .85, .92, 1) // color

      

    name ("display name", 2D) = "name" { options }


     定義2D紋理屬性

    _MainTex ("Base (RGB)", 2D) = "white" {}

      

    name ("display name", Rect) = "name" { options }


   定義長方形(非2次方)紋理屬性


   _DisplayRect("Display Rect",Rect)  ="white"


    


    name ("display name", Cube) = "name" { options }


    定義立方貼圖紋理屬性


    _DisplayCube("Display Cube",Cube)  =""



    


    name ("display name", Float) = number


    定義浮點數屬性


    _DisplayFloat("Display Float",Float)  =20.1



    


    name ("display name", Vector) = (number,number,number,number)


    定義四個向量組成的屬性


    _DisplayVector("Display Vector",Vector)  =(1,1,1,1)



    


細節:


     包含在着色器中的每一個屬性通過name索引(在Unity中, 通常使用下劃線來開始一個着色器屬性的名字)。屬性會將display name顯示在材質檢視器中,還可以通過在等符號後爲每個屬性提供缺省值。


    1.對於Range和Float類型的屬性只能是單精度值。


    2.對於Color和Vector類型的屬性將包含4個由括號圍住的數描述。


    3.對於紋理(2D, Rect, Cube) 缺省值既可以是一個空字符串也可以是某個內置的缺省紋理:"white", "black", "gray" or "bump" 。


隨後在着色器中,屬性值通過[name]來訪問。


  1. Properties {
  2.     // properties for water shader
  3.     // 水着色器的屬性
  4.     _WaveScale ("Wave scale", Range (0.02,0.15)) = 0.07 // sliders
  5.        _ReflDistort ("Reflection distort", Range (0,1.5)) = 0.5
  6.     _RefrDistort ("Refraction distort", Range (0,1.5)) = 0.4
  7.     _RefrColor ("Refraction color", Color)  = (.34, .85, .92, 1) // color
  8.        _ReflectionTex ("Environment Reflection", 2D) = "" {} // textures
  9.        _RefractionTex ("Environment Refraction", 2D) = "" {}
  10.     _Fresnel ("Fresnel (A) ", 2D) = "" {}
  11.     _BumpMap ("Bumpmap (RGB) ", 2D) = "" {}
  12. }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章