I am working on a public art installation with a client where they require characters to subtly shift from a wireframe representation to a toon shaded appearance. I have found multiple posts on this forum about rendering wireframes using mesh filters and some opengl trickery, but it was my idea from the beginning to simply use a texture (which may or may not match the mesh of the character vertex for vertex; ie: imagine a low-poly mesh on a high-poly model, or vice versa).
I figure the best way to accomplish this was to combine the Particles/Additive shader and the Toon/Basic shader in some way utilizing the Blend2Textures.shader on unify: http://www.unifycommunity.com/wiki/index.php?title=Blend_2_Textures. This would allow me to write a script that adjusts the blend value based on the characters distance from the camera. Simple enough, right?
However, the trick comes in fading in the Toon pass over the Transparency pass. Why use separate passes? The Transparency pass requires culling and zwrite to be turned off so you can see the wireframe (or whatever it might be) on the other side of the object. The Toon pass you obviously want culling and zwrite on so that it doesn’t look weird. It also has to be blended somehow, either with a specific Blend mode, or with some alpha adjustment within SetTexture, which I think will ultimately be the way to go. I just don’t know what that is.
The image attached shows the progression from “wireframe” to toon. The additive effect of the translucent toon character with culling off will hopefully be eliminated.
TLDR:
(1) How do I apply a normalized value as a multiplier to my toon shader’s alpha?
(2) How do I do that while keeping my culling/zwrite different?
And of course, here is the code:
Shader "Toon/Blended" {
Properties {
_Blend ("Blend", Range (0, 1) ) = 0.5
_TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
_MainTex ("Underlying Texture", 2D) = "white" {}
_Color ("Toon Tint Color", Color) = (.5,.5,.5,1)
_MainToonTex ("Main Toon Texture", 2D) = "white" {}
_ToonShade ("ToonShader Cubemap(RGB)", CUBE) = "white" { Texgen CubeNormal }
}
SubShader {
Pass {
Blend One One
AlphaTest Greater .01
Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) }
BindChannels {
Bind "Color", color
Bind "Vertex", vertex
Bind "TexCoord", texcoord
}
SetTexture [_MainTex] {
constantColor [_TintColor]
combine constant * primary
}
SetTexture [_MainTex] {
combine texture * previous DOUBLE
}
}
Pass {
Blend One One
ColorMask RGBA
ZWrite On
SetTexture [_MainToonTex] {
constantColor [_Color]
combine texture * constant
}
SetTexture [_ToonShade] {
combine texture * previous DOUBLE, previous
}
}
}
}
