固定管线着色器基础
/设置Shader的路径
Shader "MyFixedShader/FixedShader001"{
//Shader属性(当前材质拥有的属性)
Properties{
//在Shader中写属性名称的时候,一般都会在属性名称前加一个_
//(1)属性名称(“(2)属性在面板的名字”,(3)属性类型)=(4)属性初值
_MyFloat("一个浮点数",Float)=1.5
_MyRange("一个范围浮点数",Range(0.5,5)=3
_MyVector("一个四维数",Vector)=(1,0,0,1)
_MyColor("一个颜色",Color)=(1,0,0,1)
//二阶贴图:贴图的宽高比是2的n次幂 例如256*256,128*128
//二阶贴图在渲染的时候 Tiling表示缩放 offset表示偏移量 相当于UVRect
_My2DTexture("一个2阶贴图",2D)=""{}
_MyRectTexture("一个非二阶贴图",Rect)=""{}
_MyCubeTexture("一个立方体贴图",Cube)=""{}
}
//子着色器,可以有多个,一般只有一个子着色器
//每个子着色器相当于一个渲染方案
//当有多个子着色器的时候,会做出选择,既当这个子着色器不能渲染的时候,会选择下一个
SubShader{
//通道:可以通过多通道的方式渲染正面,反面等
Pass{
}
}
顶点着色器:
1.计算顶点颜色
2.计算灯光
片段着色器
1.纹理采样
官网教程:https://docs.unity3d.com/Manual/SL-SetTexture.html
纹理问题:纹理像素与显示区域不匹配
解决思路:1.
2.映射方式
POINT:就近采样
Bilinear:就近 周围 四个像素平均(上+下+左+右+中)/5
Trilinear:就近 周围8个像素平均
3.Combine
All the src properties can be either one of previous, constant, primary or texture.
- Previous is the the result of the previous SetTexture.表示前一个SetTexture出来以后的像素
- Primary is the color from the lighting calculation or the vertex color if it is bound.表示顶点计算出来
-
- Texture is the color of the texture specified by TextureName in the SetTexture (see above).等于SetTexture当前纹理变量
- Constant is the color specified in ConstantColor.一个固定颜色(1,1,1,1)
combine
src1 lerp
(src2) src3:进行插值混合:让SRC1和src3进行混合。混合方式取决于src2的alpha的值
公式:(1-t)A+tB