一:渲染繪圖管線
- 目的
輸入3D模型—>輸出2D模型 渲染繪圖管線流程
1.頂點處理1.本地座標系 2.世界座標系 3.觀察座標系 4.投影座標系
2.面處理
1.面的組裝 2.面的截取 3.面的剔除
3.光柵化
1.向量--->點的矩陣
4.像素處理
1.輸入:像素的位置,深度,貼圖座標,法線,切線,顏色等 2.輸出:每個像素的顏色,透明度 3.即對每個像素着色的過程
Shader第一種:固定管線着⾊器
- Properties屬性
Shader "MyFixedShader/FixedShader001"
{
Properties
{
// //爲常用的
_MyFloatValue("浮點數",Float) = 0.5 //Float --- 浮點數 --- >常用
_MyRangeValue("範圍浮點數",Range(0,10)) = 5//Range --- 範圍浮點數 ---> 常用
_MyVectorValue("四維數",Vector) = (1,2,2,1)//Vector --- 四維數 --- > 不常用
_MyColorValue("顏色",Color) = (0.1,0.5,1,1)//Color --- 顏色---> 常用
_My2DTextureValue("2D貼圖",2D) = ""{}//2DTexture --- 2D貼圖 ---> 常用
_MyNormalTextureValue("非2D貼圖",Rect) = ""{}//Rect --- 非2D貼圖 ---> 不常用
_MyCubeTextureValue("立方體貼圖",Cube) = ""{}//CubeTexture --- 立方體貼圖 ---> 不常用
/*
書寫格式爲 _屬性名("顯示在面板上的名稱",屬性類型) = 初始值
*/
}
}
- Rander Setup
Shader "MyFixedShader/FixedShader002"
{
Properties
{
_MainColor("主顏色",Color) = (1,1,1,1)
_DiffuseColor("漫反射顏色",Color) = (1,0,0,1)
_AmbientColor("環境光顏色",Color) = (1,0,1,1)
_SeparateSpecularColor("高光顏色",Color) = (1,0,1,1)
_Shininess("光澤度",Range(0,1)) = 0.5
_EmissionColor("自發光顏色",Color) = (1,1,1,1)
}
//子着色器
SubShader
{
Pass
{
Color(0,0,1,1)//固定顏色
Color[_EmissionColor] //顏色變量賦值
Lighting On //打開頂點光照
Lighting Off //關閉頂點光照
SeparateSpecular On //高光 打開鏡面反射
Cull Back //後面多邊剔除
Cull Front //前面多邊剔除
Cull Off //關閉多邊剔除
ZTest (Less | Greater | LEqual | GEqual |Equal | NotEqual | Always)//深度測試
ZWrite On | Off 是否寫入深度緩衝
SeparateSpecular On | Off 是否開啓鏡⾯面反射
Blend SrcAlpha OneMinusSrcAlpha 透明
Material
{
Diffuse(1,0,0,1) //漫反射固定顏色
Diffuse[_DiffuseColor] //漫反射調節顏色
Ambient[_AmbientColor] //環境光反射顏⾊
Specular[_SeparateSpecularColor]//高光顏⾊
Shininess[_Shininess]//光澤度
Emission[_EmissionColor]//自發光顏⾊
}
//Blend 混合
Blend SrcAlpha OneMinusSrcAlpha //Alpha混合
Blend One One //相加
Blend One OneMinusDstColor //⽐比較柔和的相加(SoftAdditive)
Blend DstColor Zero //乘法
Blend DstColor SrcColor //2倍乘法
//AlphaTest
AlphaTest Off //關閉Alpha測試
AlphaTest Greater //大於
AlphaTest GEqual //大於等於
AlphaTest Less //小於
AlphaTest LEqual //小於等於
AlphaTest Equal //等於
AlphaTest NotEqual //不等於
AlphaTest Always //渲染所有像素,等同於關閉Alpha測試—AlphaTest Off
AlphaTest Never //不渲染任何像素
AlphaTest Greater [_FloatValue]
}
}
}
- TextureSetup
Shader "MyFixedShader/FixedShader006"
{
Properties
{
_FirstTexture("FirstTexture",2D)=""{}
_SecondTexture("SecondTexture",2D)=""{}
_LerpColor("LerpColor",Color)=(0,0,0,1)
}
//子着色器
SubShader
{
Pass
{
**//combine**
combine src1 * src2 //暗
combine src1 + src2 //亮
combine src1 - src2 //暗
Double \ Quad //雙倍/四倍
//combine src1 lerp (src2) src3
/*
使⽤用源2的透明度通道值在源3和源1 中進⾏行行差值,注意差值是反向的:當透明度值是1是使⽤用
源1,透明度爲0 時使⽤用源3
*/
SetTexture[_FirstTexture] //設置紋理
{
Combine Primary * Texture
}
SetTexture[_SecondTexture]
{
ConstantColor[_LerpColor]
Combine Previous lerp(constant) Texture
}
**//src**
Primary //是來自光照計算的顏⾊色或是當它綁定時的頂點顏⾊
Texture //是在SetTexture中被定義的 紋理理的顏⾊色
Previous //是上⼀一次 SetTexture的結果
Constant //是被ConstantColor定義的顏⾊色 例如:constantColor(1,1,1,1)
}
}
}
- Tags
Shader "MyFixedShader/FixedShader003"
{
//子着色器
SubShader
{
Tags
{
//Queue 使用時需要關閉ZTest
//Queue級別
"Queue"="Overlay" //覆蓋 4000
"Queue"="Background" //後臺 1000
"Queue"="Geometry" //幾何體(默認的) 2000
"Queue"="Transparent" //透明 3000
}
}
}