Unity Shader基本结构
Unity Shader简单结构
下面的Shader代码是一个比较基础的Shader的伪代码表示 :
Shader "Shader Name" {
Properties {
propertiesName1("display name1", PropertyTypeA) = DefaultValueA
propertiesName2("display name2", PropertyTypeB) = DefaultValueB
}
SubShaderA {
[Tags]
[RenderSetup]
Pass {
CDPROGRAM
#include "xxx.cginc"
ENDCG
}
}
SubShaderB {
//...
}
Fallback ""
}
UnityShader基本属性
Properties
Properties语义块支持的属性类型:
Shader "ShaderName" {
Properties {
_Int("Int", Int) = 2
_Float("Float",Float) = 1.5
_Range("Range", Range(0.0, 5.0)) = 3.0
_Color("Color", Color) = (1, 1, 1, 1)
_Vector("Vector", Vector) = (1, 1, 1, 1)
// Textures
_2D("2D", 2D) = ""{}
_Cube("Cube", Cube) = "White"{}
_3D("3D", 3D) = "black"{}
}
}
Pass
顶点着色器和片元着色器都写在Pass内,