I’m old in Game Development but very new in shader writing. I just want a shader that transform from 1 texture to another. So I did start learning shader writing and wrote my desired shader. But during writing one thing I cannot understand as I am very dumb in shader writing that if I assign fixed4
color with COLOR
semantic in vertex
method then compiler gives the following error.
Shader error in ‘Hamza/TwoTextures’: cannot map expression to vs_4_0 instruction set at line 39 (on glcore)
Compiling Vertex program Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING SHADER_API_DESKTOP UNITY_TEXTURE_ALPHASPLIT_ALLOWED
Here is the not working shader code,
Shader "Hamza/TwoTextures"{
Properties{
[NoScaleOffset]
_Texture1 ("Texture 1",2D) = "white"{}
[NoScaleOffset]
_Texture2 ("Texture 2",2D) = "white"{}
_Mixer ("Mixer", Range(0,1)) = 0
}
SubShader{
Pass{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
sampler2D _Texture1;
sampler2D _Texture2;
float _Mixer;
struct appdata{
fixed4 vertex : POSITION;
fixed2 tex : TEXCOORD0;
};
struct v2f{
fixed4 pos : SV_POSITION;
fixed2 tex : TEXCOORD0;
fixed4 col : COLOR;
};
v2f vert(appdata i){
v2f o;
o.pos = mul(UNITY_MATRIX_MVP,i.vertex);
o.tex = i.tex;
// Giving error on this line
o.col = (tex2D(_Texture1,i.tex) * _Mixer) + (tex2D(_Texture2,i.tex) * (1 - _Mixer));
return o;
}
fixed4 frag(v2f v) : COLOR
{
return v.col;
}
ENDCG
}
}
}
And if I write same expression to throw it as return fixed4
value in fragment
method then everything is working fine.
Here is working shader code,
Shader "Hamza/TwoTextures"{
Properties{
[NoScaleOffset]
_Texture1 ("Texture 1",2D) = "white"{}
[NoScaleOffset]
_Texture2 ("Texture 2",2D) = "white"{}
_Mixer ("Mixer", Range(0,1)) = 0
}
SubShader{
Pass{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
sampler2D _Texture1;
sampler2D _Texture2;
float _Mixer;
struct appdata{
fixed4 vertex : POSITION;
fixed2 tex : TEXCOORD0;
};
struct v2f{
fixed4 pos : SV_POSITION;
fixed2 tex : TEXCOORD0;
};
v2f vert(appdata i){
v2f o;
o.pos = mul(UNITY_MATRIX_MVP,i.vertex);
o.tex = i.tex;
return o;
}
fixed4 frag(v2f i) : COLOR
{
// It is giving me no error
return (tex2D(_Texture1,i.tex) * _Mixer) + (tex2D(_Texture2,i.tex) * (1 - _Mixer));
}
ENDCG
}
}
}
Can anyone explain me that why it is happening? And what is the difference between them?
As I mentioned that I did start learning only two days before. I’m sort of noob in this.