Ladies, Gentlemen.
After getting PeterG’s help with writing an Overlay shader for an Unmoving Plaid effect (And by help, I mean he did most of the work), the next step for completion is adding unlit and outline toon effects. The best of such shaders I had found is a modified one with an unknown creator:
Overlay:
Shader "Ethios/CharacterEffects" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_SplatMap ( "Splat Map (RGB + A)" , 2D) = "white" {}
_Detail ("Masked Texture", 2D) = "gray" {}
_OutlineColor ("Outline Color", Color) = (0,0,0,1)
_Outline ("Outline width", Range (.002, 0.03)) = .005
}
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert
struct Input {
float2 uv_MainTex;
float2 uv_SplatMap;
float4 screenPos;
};
sampler2D _MainTex;
sampler2D _SplatMap;
sampler2D _Detail;
void surf ( Input IN , inout SurfaceOutput o) {
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
float2 screenUV = (IN.screenPos.xy / IN.screenPos.w);
screenUV *= float2(40,20);
half4 splatCol = tex2D(_SplatMap , IN.uv_SplatMap);
o.Albedo = lerp(o.Albedo, tex2D (_Detail, screenUV).rgb , splatCol.r);
}
ENDCG
}
Fallback "Diffuse"
}
Toon shader:
// Upgrade NOTE: replaced 'glstate.matrix.modelview[0]' with 'UNITY_MATRIX_MV'
// Upgrade NOTE: replaced 'glstate.matrix.mvp' with 'UNITY_MATRIX_MVP'
// Upgrade NOTE: replaced 'glstate.matrix.projection' with 'UNITY_MATRIX_P'
Shader "Toon/Basic Outline 2" {
Properties {
_Color ("Main Color", Color) = (.5,.5,.5,1)
_OutlineColor ("Outline Color", Color) = (0,0,0,1)
_Outline ("Outline width", Range (.002, 0.03)) = .005
_MainTex ("Base (RGB)", 2D) = "white" { }
_ToonShade ("ToonShader Cubemap(RGB)", CUBE) = "" { Texgen CubeNormal }
}
SubShader {
Tags { "RenderType"="Opaque" }
UsePass "Toon/Basic/BASE"
Pass {
Name "OUTLINE"
Tags { "LightMode" = "Always" }
CGPROGRAM
// Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it does not contain a surface program or both vertex and fragment programs.
#pragma exclude_renderers gles
// Upgrade NOTE: excluded shader from Xbox360; has structs without semantics (struct appdata members vertex,normal)
#pragma exclude_renderers xbox360
#pragma vertex vert
struct appdata {
float4 vertex;
float3 normal;
};
struct v2f {
float4 pos : POSITION;
float4 color : COLOR;
float fog : FOGC;
};
uniform float _Outline;
uniform float4 _OutlineColor;
v2f vert(appdata v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
float3 norm = mul ((float3x3)UNITY_MATRIX_MV, v.normal);
norm.x *= UNITY_MATRIX_P[0][0];
norm.y *= UNITY_MATRIX_P[1][1];
o.pos.xy += norm.xy * _Outline;
o.fog = o.pos.z;
o.color = _OutlineColor;
return o;
}
ENDCG
//Color (0,0,0,0)
Cull Front
ZWrite On
ColorMask RGB
Blend SrcAlpha OneMinusSrcAlpha
SetTexture [_MainTex] { combine primary }
}
}
Fallback "Toon/Basic"
}
My first thought was to add the required things into the Properties, and then add the Toon shader’s Subshader bit after the Overlay’s. This resulted in absolutely no change. I then put the Toon’s Subshader before the Overlay’s, which resulted in the outline working and everything, but the rest of the model being completely black.
So if putting the Subshader before didn’t work, and putting it after didn’t work, I assumed that it’s necessary to combine the two, and… Well, I’ve no experience with shaders, so it didn’t work at all. Unity threw out a seemingly completely arbitrary parser error on some random line, the character turned pink, and the properties in the Inspector windows all just vanished.
My greatest failure:
Shader "Ethios/CharacterEffects" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_SplatMap ( "Splat Map (RGB + A)" , 2D) = "white" {}
_Detail ("Masked Texture", 2D) = "gray" {}
_OutlineColor ("Outline Color", Color) = (0,0,0,1)
_Outline ("Outline width", Range (.002, 0.03)) = .005
}
SubShader {
Tags { "RenderType" = "Opaque" }
UsePass "Toon/Basic/BASE"
Pass {
Name "OUTLINE"
Tags { "LightMode" = "Always" }
CGPROGRAM
#pragma surface surf Lambert
#pragma exclude_renderers gles
// Upgrade NOTE: excluded shader from Xbox360; has structs without semantics (struct appdata members vertex,normal)
#pragma exclude_renderers xbox360
#pragma vertex vert
struct appdata {
float4 vertex;
float3 normal;
};
struct v2f {
float4 pos : POSITION;
float4 color : COLOR;
float fog : FOGC;
};
struct Input {
float2 uv_MainTex;
float2 uv_SplatMap;
float4 screenPos;
};
uniform float _Outline;
uniform float4 _OutlineColor;
sampler2D _MainTex;
sampler2D _SplatMap;
sampler2D _Detail;
v2f vert(appdata v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
float3 norm = mul ((float3x3)UNITY_MATRIX_MV, v.normal);
norm.x *= UNITY_MATRIX_P[0][0];
norm.y *= UNITY_MATRIX_P[1][1];
o.pos.xy += norm.xy * _Outline;
o.fog = o.pos.z;
o.color = _OutlineColor;
return o;
}
void surf ( Input IN , inout SurfaceOutput o) {
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
float2 screenUV = (IN.screenPos.xy / IN.screenPos.w);
screenUV *= float2(40,20);
half4 splatCol = tex2D(_SplatMap , IN.uv_SplatMap);
o.Albedo = lerp(o.Albedo, tex2D (_Detail, screenUV).rgb , splatCol.r);
}
ENDCG
//Color (0,0,0,0)
Cull Front
ZWrite On
ColorMask RGB
Blend SrcAlpha OneMinusSrcAlpha
SetTexture [_MainTex] { combine primary }
}
}
Fallback "Diffuse"
}
Could anyone see what I did wrong, aside from everything?