在unity5.0存在一个bug就是在一个pass中settexture只能使用4次,超过了就会报错
而这个问题在4.x 或者5.22以上是不存在的
所以这是开这篇文章的原因
还有bug包括
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "AutoLight.cginc"
顺序翻掉会报没有任何提示的错误
另外说下固定管线里 Primary这个量,从网上其他地方解释来看时是来自光照计算的颜色或是当它绑定时的顶点颜色,
但是这个量没有光照就是顶点颜色,这个信息可以被存储在fbx里,但是没法保存在obj里
比如下面是我用maya测试的
下面是转换方面的
SetTexture [Tex]//相当于直接复制图片
这个相当于 fixed4 texcol = tex2D (_MainTex, i.uv);//就是直接显示图片
SetTexture [Mask]//这部看起没变化 只是将这张图的alpha通道给了上次的结果
{
combine previous, texture
}
这个相当于顶点片段着色器里的把Mask纹理的alpha通道提取出来赋予previous这张贴图
SetTexture [Tex]//这部分相当于alpha遮罩
{
combine texture lerp(previous) previous
}
这个相当于顶点片段着色器里的tex1*(1- Mask.a) + tex2*(Mask.a);
combine texture * previous
combine texture + previous
则是和顶点片段着色器里的相同
Combine previous * primary
相当于tex1*i.color
i.color就是顶点颜色
至于固定管线里的DOUBLE QUAD就相当于 *2 *4那种程度吧
当然还有种更简单方式可以把shader在不同版本间切换而很少产生bug,就是编译compile自动生成顶点着色器,
当然这种方式不懂shader的比较难修改,其实如果懂shader的这种方式更方便
当然有些地方还是手动改更能熟悉shader
下面是一个显示顶点颜色的shader
Shader "Debug/Vertex color" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
//#include "UnityCG.cginc"
//float4 _MainTex_ST;
sampler2D _MainTex;
half _Glossiness;
half _Metallic;
fixed4 _Color;
// vertex input: position, color
struct appdata {
float4 vertex : POSITION;
fixed4 color : COLOR;
float4 texcoord : TEXCOORD0;
};
struct v2f {
float4 pos : SV_POSITION;
fixed4 color : COLOR;
float4 uv : TEXCOORD0;
//float2 uv : TEXCOORD0;
};
v2f vert (appdata v) {
v2f o;
o.pos = mul( UNITY_MATRIX_MVP, v.vertex );
o.color = v.color;
o.uv = float4( v.texcoord.xy, 0, 0 );
// o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 MainTex = tex2D (_MainTex, i.uv);
fixed4 temp = i.color + MainTex;
return temp;
}
ENDCG
}
}
}
显示顶点颜色的顶点片段着色器具体可以参考这里
http://docs.unity3d.com/Manual/SL-VertexProgramInputs.html
表面shader参考这里
http://docs.unity3d.com/Manual/SL-SurfaceShaderExamples.html
固定管线方式参考这里
http://docs.unity3d.com/Manual/SL-SetTexture.html
http://docs.unity3d.com/Manual/ShaderTut1.html