Hello! In my 2d game I need to use 2 shaders: first one for pixel snapping and second one for lighting.
Here is my shaders:
PixelSnap
Shader "PixelSnap"
{
Properties
{
_MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Main Color", Color) = (1,1,1,1)
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
}
Cull Off
Lighting Off
ZWrite Off
ZTest Always
Fog { Mode Off }
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;
fixed4 _Color;
struct appdata_t
{
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
v2f vert(appdata_t IN)
{
v2f OUT;
OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
OUT.texcoord = TRANSFORM_TEX(IN.texcoord, _MainTex);
// Snapping params
float hpcX = _ScreenParams.x * 0.5;
float hpcY = _ScreenParams.y * 0.5;
#ifdef UNITY_HALF_TEXEL_OFFSET
float hpcOX = -0.5;
float hpcOY = 0.5;
#else
float hpcOX = 0;
float hpcOY = 0;
#endif
// Snap
float pos = floor((OUT.vertex.x / OUT.vertex.w) * hpcX + 0.5) + hpcOX;
OUT.vertex.x = pos / hpcX * OUT.vertex.w;
pos = floor((OUT.vertex.y / OUT.vertex.w) * hpcY + 0.5) + hpcOY;
OUT.vertex.y = pos / hpcY * OUT.vertex.w;
return OUT;
}
fixed4 frag(v2f IN) : COLOR
{
return tex2D( _MainTex, IN.texcoord) * _Color;
}
ENDCG
}
}
}
Shader "Sprite Lamp/new"
{
Properties
{
_MainTex ("Diffuse Texture", 2D) = "white" {}
_BumpMap ("Normal Map (no depth)", 2D) = "bump" {}
_AOMap ("Ambient Occlusion", 2D) = "white" {}
_AOIntensity ("Occlusion Intensity", Range(0, 1.0)) = 0.5
_SpecMap ("Specular Map", 2D) = "white" {}
_SpecIntensity ("Specular Intensity", Range(0, 1.0)) = 0.5
_Color ("Tint", Color) = (1,1,1,1)
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
}
LOD 300
Cull Off
Lighting Off
ZWrite Off
ZTest Always
Fog { Mode Off }
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma surface surf BlinnPhong vertex:vert
sampler2D _MainTex;
sampler2D _BumpMap;
sampler2D _AOMap;
sampler2D _SpecMap;
fixed4 _Color;
uniform float _AOIntensity = 0;
uniform float _SpecIntensity = 0;
struct Input
{
float2 uv_MainTex;
float2 uv_BumpMap;
float2 uv_AOMap;
float2 uv_SpecMap;
fixed4 color;
};
void vert (inout appdata_full v, out Input o)
{
v.normal = float3(0,0,-1);
UNITY_INITIALIZE_OUTPUT(Input, o);
o.color = v.color * _Color;
}
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * IN.color;
fixed4 a = tex2D(_AOMap, IN.uv_AOMap);
fixed4 s = tex2D(_SpecMap, IN.uv_SpecMap);
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
o.Albedo = c.rgb * c.a;
o.Albedo *= (1.0 - _AOIntensity) + (a.r * _AOIntensity);
o.Albedo *= (1.0 - _SpecIntensity) + (s.r * _SpecIntensity);
o.Alpha = c.a;
}
ENDCG
Fallback "Specular"
}
I need to combine this two shaders but as I figured out they are different types. One is “Vertex and Fragment” and second is “Surface”. Tell me someone… Can I combine this two shaders together? I tried to place them one by one in one Subshader but it is not working…