I’ve had some luck combining two shaders into one, but I’m still quite a newbie in this area. This one’s got me stumped.
The first shader is a slightly modified one from a free matcap shader pack on the Unity asset store. It’s a surface shader that provides a nice unlit toon effect using a second texture. (It includes a minor modification that allows a crossfade to a flat color.)
// MatCap Shader, (c) 2013 Jean Moreno
Shader "MatCap/Vertex/Textured Lit Flat Shaded"
{
Properties
{
_Color ("Color", Color) = (0,0,0,1)
_CrossFadeAmount ("CrossFade Amount", Range(0,1.0)) = 0.0
_MainTex ("Base (RGB)", 2D) = "white" {}
_MatCap ("MatCap (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
Cull Off
CGPROGRAM
#pragma surface surf Lambert vertex:vert
sampler2D _MainTex;
sampler2D _MatCap;
float4 _Color;
float _CrossFadeAmount;
struct Input
{
half2 uv_MainTex : TEXCOORD0;
float2 matcapUV;
};
void vert (inout appdata_full v, out Input o)
{
o.matcapUV = float2(dot(UNITY_MATRIX_IT_MV[0].xyz,v.normal),dot(UNITY_MATRIX_IT_MV[1].xyz,v.normal)) * 0.5 + 0.5;
}
void surf (Input IN, inout SurfaceOutput o)
{
half4 c = tex2D(_MainTex, IN.uv_MainTex);
half4 mc = tex2D(_MatCap, IN.matcapUV);
half mcStrength = 1 - _CrossFadeAmount;
o.Albedo = ((c.rgb * mc * 2.0) * mcStrength) + (_Color * _CrossFadeAmount);
}
ENDCG
}
Fallback "VertexLit"
}
The second one is a vertex shader found on Unity answers that adjusts vertices based on its position from the camera.
Shader "Custom/Curved" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_QOffset ("Offset", Vector) = (0,0,0,0)
_Dist ("Distance", Float) = 100.0
}
SubShader {
Tags { "RenderType"="Opaque" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _QOffset;
float _Dist;
struct v2f {
float4 pos : SV_POSITION;
float4 uv : TEXCOORD0;
};
v2f vert (appdata_base v)
{
v2f o;
float4 vPos = mul (UNITY_MATRIX_MV, v.vertex);
float zOff = vPos.z/_Dist;
vPos += _QOffset*zOff*zOff;
o.pos = mul (UNITY_MATRIX_P, vPos);
o.uv = v.texcoord;
return o;
}
half4 frag (v2f i) : COLOR
{
half4 col = tex2D(_MainTex, i.uv.xy);
return col;
}
ENDCG
}
}
FallBack "Diffuse"
}
The following is my best stab at combining these. In its current state only matcap is working. The most important bit is line 43, which does nothing, and it’s not clear to me why.
Shader "Custom/Curved Matcap" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_QOffset ("Offset", Vector) = (0,0,0,0)
_Dist ("Distance", Float) = 100.0
_Color ("Color", Color) = (0,0,0,1)
_CrossFadeAmount ("CrossFade Amount", Range(0,1.0)) = 0.0
_MatCap ("MatCap (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
Cull Off
CGPROGRAM
#pragma surface surf Lambert vertex vert
#include "UnityCG.cginc"
sampler2D _MainTex;
sampler2D _MatCap;
float4 _Color;
float _CrossFadeAmount;
float _Dist;
float4 _QOffset;
struct Input
{
half2 uv_MainTex : TEXCOORD0;
float2 matcapUV;
float4 pos : SV_POSITION;
};
void vert (inout appdata_full v, out Input o)
{
o.matcapUV = float2(dot(UNITY_MATRIX_IT_MV[0].xyz,v.normal),dot(UNITY_MATRIX_IT_MV[1].xyz,v.normal)) * 0.5 + 0.5;
float4 vPos = mul (UNITY_MATRIX_MV, v.vertex);
float zOff = vPos.z/_Dist;
vPos += _QOffset*zOff*zOff;
o.pos = mul (UNITY_MATRIX_P, vPos);
}
void surf (Input IN, inout SurfaceOutput o)
{
half4 c = tex2D(_MainTex, IN.uv_MainTex);
half4 mc = tex2D(_MatCap, IN.matcapUV);
half mcStrength = 1 - _CrossFadeAmount;
o.Albedo = ((c.rgb * mc * 2.0) * mcStrength) + (_Color * _CrossFadeAmount);
}
ENDCG
}
FallBack "Diffuse"
}
Thanks for taking a look!