显示主材质:half4 c = tex2D(_MainTex , uv)
显示颜色:half4 c = tex2D(_MainTex , i.uv) * _Color;
显示纹理贴图:o.Normal = UnpackNormal(tex2D(_Bump, IN.uv_Bump));
显示光照贴图:half3 l = 2.0 * tex2D(_LightMap, i.uvLM).rgb; c.rgb *= l;
旋转UV:移动UV点
缩放:放大或缩小UV点 i.uv * float2(_ColorU, _ColorV)
高光和玻璃:
void surf (Input IN, inout SurfaceOutput o) {
fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = tex.rgb * _Color.rgb;
o.Gloss = tex.a;
o.Alpha = tex.a * _Color.a;
o.Specular = _Shininess;
}
表面着色器不写在Pass里,顶点/片段着色器必须写在Pass里。
Culling & Depth Testing: Cull Back | Front | Off: Back Don’t render polygons facing away from the viewer (default).剔除背面 Front Don’t render polygons facing towards the viewer. Used for turning objects inside-out.剔除正面 Off Disables culling - all faces are drawn. Used for special effects.都绘制 ZWrite On | Off:打开或关闭深度测试 Controls whether pixels from this object are written to the depth buffer (default is On). If you’re drawng solid objects, leave this on. If you’re drawing semitransparent effects, switch to ZWrite Off. ZTest Less(Z小于对象的呗绘制) | Greater(大于) | LEqual (小等于,默认)| GEqual | Equal | NotEqual | Always
Blending:
Blend Off: Turn off blending (this is the default)
Blend SrcFactor DstFactor: Configure and enable blending. The generated color is multiplied by the SrcFactor原因子. The color already on screen is multiplied by DstFactorand the two are added together.原颜色*原因子 + 目标颜色*目标因子。
Alpha testing:通过透明度决定像素是否被渲染
AlphaTest Off 渲染所有像素
AlphaTest comparison AlphaValue
AlphaTest Greater 0.5
SetTexture:设置图片,只能用于表面着色器,可用于图片的叠加、混合。
SetTexture commands have no effect when fragment programs are used;
SetTexture [TexturePropertyName] { Texture Block }
combine src1 * src2: Multiplies src1 and src2 together. The result will be darker than either input.
combine src1 + src2: Adds src1 and src2 together. The result will be lighter than either input.
combine src1 - src2: Subtracts src2 from src1.
combine src1 lerp (src2) src3: Interpolates between src3 and src1, using the alpha of src2. Note that the interpolation is opposite direction: src1 is used when alpha is one, and src3 is used when alpha is zero.使用源2的透明度通道值在源3和源1中进行差值,注意差值是反向的:当透明度值是1是使用源1,透明度为0时使用源3
combine src1 * src2 + src3: Multiplies src1 with the alpha component of src2, then adds src3.
所有源属性都可以是previous, constant, primary or texture其中的一个。
Previous is the the result of the previous SetTexture.
Primary来自光照计算的颜色或是当它绑定时的顶点颜色
Texture is the color of the texture specified by TextureName in the SetTexture (see above).当前对象进行混合
Constant is the color specified in ConstantColor.自定义颜色进行混合
SetTexture [_MainTex] { constantColor [_IlluminCol] combine constant lerp(texture) previous 差值 }
表面着色器:#pragma surface surfaceFunction lightModel [optionalparams]
定义一个“表面着色器函数(surface function)”,输入所需要的UV或数据,并在输出结构中填充SurfaceOutput。SurfaceOutput基本上描述了表面的特性(光照的颜色反射率、法线、散射、镜面等)。
void surf (Input IN, inout SurfaceOutput o) { o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb; }
可以在输入结构中附加一些值:
float3 viewDir - will contain view direction, for computing Parallax effects, rim lighting etc.
float3 viewDir - 视图方向( view direction)值。为了计算视差效果(Parallax effects),边缘光照(rim lighting)等,需要包含视图方向( view direction)值。
float4 with COLOR semantic - will contain interpolated per-vertex color.
float4 with COLOR semantic -每个顶点(per-vertex)颜色的插值。
float4 screenPos - will contain screen space position for reflection effects. Used by WetStreet shader in Dark Unity for example.
float4 screenPos - 屏幕空间中的位置。 为了反射效果,需要包含屏幕空间中的位置信息。比如在Dark Unity中所使用的 WetStreet着色器。
float3 worldPos - will contain world space position.
float3 worldPos - 世界空间中的位置。
float3 worldRefl - will contain world reflection vector if surface shader does not write to o.Normal. See Reflect-Diffuse shader for example.
float3 worldRefl - 世界空间中的反射向量。如果表面着色器(surface shader)不写入法线(o.Normal)参数,将包含这个参数。 请参考这个例子:Reflect-Diffuse 着色器。
float3 worldNormal - will contain world normal vector if surface shader does not write to o.Normal.
float3 worldNormal - 世界空间中的法线向量(normal vector)。如果表面着色器(surface shader)不写入法线(o.Normal)参数,将包含这个参数。
float3 worldRefl; INTERNAL_DATA - will contain world reflection vector if surface shader writes to o.Normal. To get the reflection vector based on per-pixel normal map, use WorldReflectionVector (IN, o.Normal). See Reflect-Bumped shader for example.
float3 worldRefl; INTERNAL_DATA - 世界空间中的反射向量。如果表面着色器(surface shader)不写入法线(o.Normal)参数,将包含这个参数。为了获得基于每个顶点法线贴图( per-pixel normal map)的反射向量(reflection vector)需要使用世界反射向量(WorldReflectionVector (IN, o.Normal))。请参考这个例子: Reflect-Bumped着色器。
float3 worldNormal; INTERNAL_DATA - will contain world normal vector if surface shader writes to o.Normal. To get the normal vector based on per-pixel normal map, use WorldNormalVector (IN, o.Normal).
float3 worldNormal; INTERNAL_DATA -世界空间中的法线向量(normal vector)。如果表面着色器(surface shader)不写入法线(o.Normal)参数,将包含这个参数。为了获得基于每个顶点法线贴图( per-pixel normal map)的法线向量(normal vector)需要使用世界法线向量(WorldNormalVector (IN, o.Normal))。
原文地址:https://www.cnblogs.com/wang-jin-fu/p/8279707.html