Unity Shader - 属性定义 ShaderLab : Properties 和 CG 属性

来源:互联网 发布:python basehttpServer 编辑:程序博客网 时间:2024/06/04 20:14

(1)ShaderLab Properties 可用类型

  • 数值和滑条类型
    • 范围浮点数 Range 例如:_MatRange(“Material Range Val”, Range (-10, 10)) = 1
    • 浮点数 Float 例如:_MatFloat(“Material Float Val”, Float) = 1
    • 整数 Int 例如:_MatInt(“Material Int Val”, Int) = 1
  • 颜色和向量类型
    • 颜色 Color 例如: _MatColor(“Material Color Val”, Color) = (1,1,1,1)
    • 四元素向量 Vector 例如: _MatVector(“Material Vector Val”, Vector) = (1,1,1,1)
  • 图片类型
    • 普通贴图 2D 例如: _Mat2D(“Material 2D Texture Val”, 2D) = “defaulttexture” {}
    • 正方体贴图 Cube 例如: _MatCube(“Material Cube Texture Val”, Cube) = “defaulttexture”{}
    • 3D贴图 3D 例如: _Mat3D(“Material 3D Texture Val”, 3D) = “defaulttexture”{}
  • 矩阵
    • float4x4

这里写图片描述

(2) unity脚本控制属性

public Cubemap m_cubeMap;public Texture3D m_texture3D;void Start (){    Material mat = gameObject.GetComponent<Renderer>().material;    Texture texture2D = transform.GetChild(0).GetComponent<Renderer>().material.mainTexture;    mat.SetFloat("_MatRange", 2);    mat.SetFloat("_MatFloat", 3);    mat.SetInt("_MatInt", 0);    mat.SetColor("_MatColor", Color.black);    mat.SetVector("_MatVector", Vector4.one);    mat.SetTexture("_Mat2D", texture2D);    mat.SetTexture("_MatCube", m_cubeMap);    mat.SetTexture("_Mat3D", m_texture3D);}

(3)CG属性

  • sampler2D _CG2D;
  • float4 _CGFloat4 ;
  • sampler
0 0
原创粉丝点击